wrong_submission_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 131k
1.05M
| wrong_status
stringclasses 2
values | wrong_cpu_time
float64 10
40k
| wrong_memory
float64 2.94k
3.37M
| wrong_code_size
int64 1
15.5k
| problem_description
stringlengths 1
4.75k
| wrong_code
stringlengths 1
6.92k
| acc_submission_id
stringlengths 10
10
| acc_status
stringclasses 1
value | acc_cpu_time
float64 10
27.8k
| acc_memory
float64 2.94k
960k
| acc_code_size
int64 19
14.9k
| acc_code
stringlengths 19
14.9k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s518193572 | p03369 | u923712635 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 86 | In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen. | S = input()
topping = 0
for i in S:
topping += 1 if i=='o' else 0
print(700+topping) | s583450572 | Accepted | 18 | 2,940 | 90 | S = input()
topping = 0
for i in S:
topping += 1 if i=='o' else 0
print(700+topping*100) |
s074702429 | p03448 | u796708718 | 2,000 | 262,144 | Wrong Answer | 32 | 2,940 | 183 | You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. | A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for a in range(0,A):
for b in range(0,B):
for c in range(0,C):
if a+b+c == X:
cnt +=1 | s488519083 | Accepted | 50 | 3,064 | 215 | A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for a in range(0,A+1):
for b in range(0,B+1):
for c in range(0,C+1):
if a*500+b*100+c*50 == X:
cnt +=1
print(cnt) |
s549846422 | p03471 | u022979415 | 2,000 | 262,144 | Wrong Answer | 20 | 3,064 | 455 | The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough. | def main():
number, new_year_gift = map(int, input().split(" "))
bill_numbers = [new_year_gift // 10000, 0, 0]
new_year_gift -= 10000 * bill_numbers[0]
bill_numbers[1] = new_year_gift // 5000
new_year_gift -= 5000 * bill_numbers[1]
bill_numbers[2] = new_year_gift // 1000
if sum(bill_numbers) <= number:
print(" ".join(map(str, bill_numbers)))
else:
print(-1, -1, -1)
if __name__ == '__main__':
main() | s626168432 | Accepted | 724 | 3,060 | 527 | def main():
number, new_year_gift = map(int, input().split(" "))
answer = True
for i in range(number, -1, -1):
if not answer:
break
for j in range(number + 1):
if number < i + j:
continue
elif 10000 * i + 5000 * j + 1000 * (number - i - j) == new_year_gift and answer:
print(i, j, number - i - j)
answer = False
break
if answer:
print(-1, -1, -1)
if __name__ == '__main__':
main()
|
s770196377 | p03861 | u059262067 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 63 | You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x? | a, b, c = (int(_) for _ in input().split())
print(b//c-a//c)
| s140618292 | Accepted | 17 | 2,940 | 67 | a, b, c = (int(_) for _ in input().split())
print(b//c-(a-1)//c)
|
s163044982 | p02694 | u666964944 | 2,000 | 1,048,576 | Wrong Answer | 24 | 9,108 | 82 | Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time? | x = int(input())
m = 100
ans = 0
while m <= x:
m += m//100
ans += 1
print(ans) | s660856046 | Accepted | 21 | 9,184 | 81 | x = int(input())
m = 100
ans = 0
while m < x:
m += m//100
ans += 1
print(ans) |
s160168249 | p03339 | u969708690 | 2,000 | 1,048,576 | Wrong Answer | 241 | 9,568 | 215 | There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions. | N=int(input())
S=input()
ans=S.count("W")
for i in range(N):
if S[i]=="W":
ans-=1
if i!=0:
if S[i-1]=="E":
ans+=1
if i!=0:
ans1=max(ans,ans1)
else:
ans1=ans
print(ans)
print(N-1-ans1) | s665173524 | Accepted | 154 | 9,740 | 177 | N=int(input())
S=input()
ans=S.count("W")
ans1=-10
for i in range(N):
if S[i]=="W":
ans-=1
if i!=0:
if S[i-1]=="E":
ans+=1
ans1=max(ans,ans1)
print(N-1-ans1) |
s962941603 | p03997 | u995062424 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 70 | You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid. | a = int(input())
b = int(input())
h = int(input())
print((a+b)*h*0.5) | s982928128 | Accepted | 17 | 2,940 | 75 | a = int(input())
b = int(input())
h = int(input())
print(int((a+b)*h*0.5)) |
s545474917 | p03712 | u156383602 | 2,000 | 262,144 | Wrong Answer | 19 | 3,060 | 100 | You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1. | n,m=map(int,input().split())
print("#"*m)
for i in range(n):
print("#"+input()+"#")
print("#"*m) | s737869442 | Accepted | 18 | 3,060 | 108 | n,m=map(int,input().split())
print("#"*(m+2))
for i in range(n):
print("#"+input()+"#")
print("#"*(m+2)) |
s866619137 | p02389 | u217701374 | 1,000 | 131,072 | Wrong Answer | 20 | 7,512 | 42 | Write a program which calculates the area and perimeter of a given rectangle. | a,b = map(int,input().split())
print(a*b) | s204040379 | Accepted | 20 | 7,584 | 51 | a,b = map(int,input().split())
print(a*b, a*2+b*2) |
s125213332 | p03163 | u775098278 | 2,000 | 1,048,576 | Wrong Answer | 173 | 14,604 | 251 | There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home. | import numpy as np
n,W = map(int,input().split())
w,v = [0] * n, [0] * n
for i in range(n):
w[i] , v[i] = map(int,input().split())
dp = np.zeros((W + 1))
for _w, _v in zip(w, v):
np.maximum(dp[_w:], dp[:-_w] + _v, out=dp[_w:])
print(dp[-1])
| s241206888 | Accepted | 176 | 14,600 | 268 | import numpy as np
n,W = map(int,input().split())
w,v = [0] * n, [0] * n
for i in range(n):
w[i] , v[i] = map(int,input().split())
dp = np.zeros((W + 1), dtype=np.uint64)
for _w, _v in zip(w, v):
np.maximum(dp[_w:], dp[:-_w] + _v, out=dp[_w:])
print(dp[-1])
|
s824450271 | p04043 | u497952650 | 2,000 | 262,144 | Wrong Answer | 16 | 2,940 | 99 | Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order. | A = sorted(list(map(int,input().split())))
if A == [5,5,7]:
print("Yes")
else:
print("No") | s994325208 | Accepted | 17 | 2,940 | 99 | A = sorted(list(map(int,input().split())))
if A == [5,5,7]:
print("YES")
else:
print("NO") |
s243047112 | p02841 | u672542358 | 2,000 | 1,048,576 | Wrong Answer | 18 | 2,940 | 83 | In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month. | m,n=input().split()
ma,na=input().split()
if m==ma:
print("1")
else:
print("0") | s501727448 | Accepted | 17 | 2,940 | 83 | m,n=input().split()
ma,na=input().split()
if m==ma:
print("0")
else:
print("1") |
s320242291 | p03418 | u223904637 | 2,000 | 262,144 | Wrong Answer | 73 | 2,940 | 162 | Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had. | n,k=map(int,input().split())
ans=0
for i in range(k+1,n+1):
a=n//i
b=n%i
if b>=k:
ans+=a*(i-k)+b-k
else:
ans+=a*(i-k)
print(ans) | s108250182 | Accepted | 82 | 3,060 | 157 | n,k=map(int,input().split())
if k==0:
print(n*n)
exit()
ans=0
for i in range(k+1,n+1):
m=(n//i)*(i-k)
m+=max(0,n%i-k+1)
ans+=m
print(ans) |
s971590996 | p04043 | u360053454 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 100 | Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order. | A,B,C = map(int,input().split())
if A == 5 and B == 7 and C == 5:
print('YES')
else:
print('NO') | s442740510 | Accepted | 17 | 2,940 | 106 | a, b, c = map(int, input().split())
if sorted((a, b, c)) == [5, 5, 7]:
print('YES')
else:
print('NO')
|
s655019163 | p03854 | u698479721 | 2,000 | 262,144 | Wrong Answer | 64 | 3,444 | 328 | You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | import sys
s = input()
i = 1
s1 = ''
while i <= len(s):
s1 += s[-i]
i += 1
s2 = s1
while s2 != '':
if s2[0:5] == 'maerd':
s2 = s2[6:]
elif s2[0:7] == 'remaerd':
s2 = s2[8:]
elif s2[0:5] == 'esare':
s2 = s2[6:]
elif s2[0:6] == 'resare':
s2 = s2[7:]
else:
print('No')
sys.exit()
print('Yes') | s746840411 | Accepted | 106 | 3,444 | 328 | import sys
s = input()
i = 1
s1 = ''
while i <= len(s):
s1 += s[-i]
i += 1
s2 = s1
while s2 != '':
if s2[0:5] == 'maerd':
s2 = s2[5:]
elif s2[0:7] == 'remaerd':
s2 = s2[7:]
elif s2[0:5] == 'esare':
s2 = s2[5:]
elif s2[0:6] == 'resare':
s2 = s2[6:]
else:
print('NO')
sys.exit()
print('YES') |
s941066989 | p03129 | u921773161 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 88 | Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1. | #%%
n, k = map(int, input().split())
if n >= 2*k:
print('YES')
else:
print('NO') | s653124783 | Accepted | 17 | 2,940 | 96 | #%%
n, k = map(int, input().split())
if n - 1 >= 2*(k-1):
print('YES')
else:
print('NO') |
s356429783 | p03455 | u504272868 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 88 | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. | def calc(A, B):
if A*B%2 == 0:
return 'Even'
elif A*B%2 != 0:
return 'Odd'
| s495744296 | Accepted | 17 | 2,940 | 79 | a,b=map(int, input().split())
if a*b%2==0:
print("Even")
else:
print("Odd") |
s518210205 | p02694 | u619819312 | 2,000 | 1,048,576 | Wrong Answer | 28 | 9,144 | 103 | Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time? | x=int(input())
a=100
b=0
while 1:
if a>x:
print(b)
break
b+=1
a=(a*1.01)//1 | s441010429 | Accepted | 28 | 9,096 | 67 | x=int(input())
a=100
b=0
while a<x:
b+=1
a+=a//100
print(b) |
s682738463 | p03434 | u655975843 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 309 | We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score. | n = int(input())
a = list(map(int, input().split()))
print(a)
count = 0
alice = 0
bob = 0
a.sort()
f = 0
while(len(a) != 0):
if f == 0:
alice = alice + a.pop(-1)
f = 1
else:
bob = bob + a.pop(-1)
f = 0
print('alice %d' % alice)
print('bob %d' % bob)
print(alice - bob)
| s670260504 | Accepted | 17 | 3,060 | 252 | n = int(input())
a = list(map(int, input().split()))
count = 0
alice = 0
bob = 0
a.sort()
f = 0
while(len(a) != 0):
if f == 0:
alice = alice + a.pop(-1)
f = 1
else:
bob = bob + a.pop(-1)
f = 0
print(alice - bob)
|
s349016892 | p03455 | u011768731 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 91 | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. | a, b = map(int, input().split())
if a * b % 2 == 0:
print("Eecn")
else:
print("Odd")
| s377319576 | Accepted | 17 | 2,940 | 89 | a, b = map(int, input().split())
if a * b % 2 == 0:
print("Even")
else:
print("Odd")
|
s124720851 | p03048 | u597455618 | 2,000 | 1,048,576 | Wrong Answer | 2,104 | 2,940 | 258 | Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this? | r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r):
for j in range(n//g):
for k in range(n//b):
if r*i + j*g + b*k == n:
ans += 1
elif r*i + j*g + b*k > n:
break
print(ans) | s692301754 | Accepted | 20 | 3,060 | 166 | r, g, b, n = map(int, input().split())
ans = [0 for i in range(n+1)]
ans[0] = 1
for i in [r,g,b]:
for j in range(n+1-i):
ans[j+i] += ans[j]
print(ans[n]) |
s169293425 | p03778 | u782654209 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 75 | AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved. | W,a,b=map(int,input().split(' '))
print(min(max(0,b-(a+W)),max(0,a-(b+W)))) | s507573748 | Accepted | 17 | 2,940 | 91 | W,a,b=map(int,input().split(' '))
print(max(0,b-(a+W))) if a<=b else print(max(0,a-(b+W)))
|
s265859626 | p03759 | u272522520 | 2,000 | 262,144 | Wrong Answer | 20 | 3,060 | 104 | Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful. | a,b,c = map(int, input().split())
A = b - a
B = c - b
if A==B:
print("Yes")
else :
print("No") | s494528669 | Accepted | 18 | 2,940 | 104 | a,b,c = map(int, input().split())
A = b - a
B = c - b
if A==B:
print("YES")
else :
print("NO") |
s360309334 | p02255 | u684325232 | 1,000 | 131,072 | Wrong Answer | 20 | 5,588 | 194 | Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step. | n=int(input())
l=list(map(int,input().split()))
print(*l)
for i in range(len(l)):
v=l[i]
j=i-1
while j>=0 and l[j]>v:
l[j+1]=l[j]
j=j-1
l[j+1]=v
print(*l)
| s403092248 | Accepted | 20 | 5,984 | 187 | n=int(input())
l=list(map(int,input().split()))
for i in range(len(l)):
v=l[i]
j=i-1
while j>=0 and l[j]>v:
l[j+1]=l[j]
j=j-1
l[j+1]=v
print(*l)
|
s401091806 | p02261 | u844704750 | 1,000 | 131,072 | Wrong Answer | 20 | 7,696 | 725 | Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance). | N=int(input())
A=input().split()
B=A[:]
S=A[:]
def BubbleSort(A, N):
count = 0
flag = True
while flag:
flag = False
for j in range(N-1, 0, -1):
if A[j][1] < A[j-1][1]:
A[j], A[j-1] = A[j-1], A[j]
count += 1
flag = True
return A
def SelectionSort(A, N):
count = 0
for i in range(N):
minj = i
for j in range(i, N):
if A[j][1] < A[minj][1]:
minj = j
A[i], A[minj] = A[minj], A[i]
count += 1
return A
b = BubbleSort(B, N)
s = SelectionSort(S, N)
print(*b)
print("Stable")
print(*s)
if b == s:
print("Stable")
else:
print("Not Stable") | s312463780 | Accepted | 30 | 7,788 | 725 | N=int(input())
A=input().split()
B=A[:]
S=A[:]
def BubbleSort(A, N):
count = 0
flag = True
while flag:
flag = False
for j in range(N-1, 0, -1):
if A[j][1] < A[j-1][1]:
A[j], A[j-1] = A[j-1], A[j]
count += 1
flag = True
return A
def SelectionSort(A, N):
count = 0
for i in range(N):
minj = i
for j in range(i, N):
if A[j][1] < A[minj][1]:
minj = j
A[i], A[minj] = A[minj], A[i]
count += 1
return A
b = BubbleSort(B, N)
s = SelectionSort(S, N)
print(*b)
print("Stable")
print(*s)
if b == s:
print("Stable")
else:
print("Not stable") |
s784988964 | p03478 | u735008991 | 2,000 | 262,144 | Wrong Answer | 30 | 2,940 | 147 | Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). | N, A, B = map(int, input().split())
ans = 0
for i in range(1, 1+N):
s = str(i)
if A <= sum(map(int, s)) <= B:
ans += 1
print(ans)
| s650459292 | Accepted | 32 | 2,940 | 147 | N, A, B = map(int, input().split())
ans = 0
for i in range(1, 1+N):
s = str(i)
if A <= sum(map(int, s)) <= B:
ans += i
print(ans)
|
s349308791 | p03854 | u869265610 | 2,000 | 262,144 | Wrong Answer | 68 | 9,596 | 252 | You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | S=input()
W=[0]*(len(S)+1)
W[0]=1
words=['dream','dreamer','erase','eraser' ]
for i in range(len(S)):
if W[i]==0:
continue
for k in words:
if S[i:i+len(k)]==k:
W[i+len(k)]=1
if W[len(S)]==1:
print("Yes")
exit()
else:
print("No") | s784663797 | Accepted | 67 | 9,796 | 253 | S=input()
W=[0]*(len(S)+1)
W[0]=1
words=['dream','dreamer','erase','eraser' ]
for i in range(len(S)):
if W[i]==0:
continue
for k in words:
if S[i:i+len(k)]==k:
W[i+len(k)]=1
if W[len(S)]==1:
print("YES")
exit()
else:
print("NO")
|
s162134998 | p02678 | u198668088 | 2,000 | 1,048,576 | Wrong Answer | 1,345 | 38,188 | 490 | There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. | N, M = map(int, input().split())
loads = [[] for _ in range(N)]
for _ in range(M):
A, B = map(int, input().split())
loads[A-1].append(B-1)
loads[B-1].append(A-1)
queue = [0]
dist = [0] * N
prev = [-1] * N
while(len(queue) != 0):
now = queue[0]
queue.pop(0)
for i in loads[now]:
if dist[i] != 0:
continue
else:
queue.append(i)
dist[i] = dist[now] + 1
prev[i] = now + 1
for i in prev[1:]:
print(i) | s883916586 | Accepted | 1,370 | 38,132 | 502 | N, M = map(int, input().split())
loads = [[] for _ in range(N)]
for _ in range(M):
A, B = map(int, input().split())
loads[A-1].append(B-1)
loads[B-1].append(A-1)
queue = [0]
dist = [0] * N
prev = [-1] * N
while(len(queue) != 0):
now = queue[0]
queue.pop(0)
for i in loads[now]:
if dist[i] != 0:
continue
else:
queue.append(i)
dist[i] = dist[now] + 1
prev[i] = now + 1
print('Yes')
for i in prev[1:]:
print(i) |
s046520596 | p03699 | u941753895 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 234 | You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade? | n=int(input())
l=[]
for i in range(n):
l.append(int(input()))
s=sum(l)
l.sort()
if ' '.join([str(x) for x in l])=='5 10 15':
exit()
if s%10!=0:
print(s)
exit()
for i in l:
b=s-i
if b%10!=0:
print(b)
exit()
print(0) | s015758709 | Accepted | 44 | 5,652 | 478 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n=I()
l=[]
for _ in range(n):
l.append(I())
l.sort()
sm=sum(l)
if sm%10!=0:
return sm
for x in l:
if (sm-x)%10!=0:
return sm-x
return 0
print(main())
|
s270159454 | p03149 | u298297089 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 107 | You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974". | A = map(int,input().split())
if 1 in A and 9 in A and 7 in A and 4 in A:
print('YES')
else:
print('NO') | s127356637 | Accepted | 19 | 3,060 | 113 | A = list(map(int,input().split()))
if 1 in A and 9 in A and 7 in A and 4 in A:
print('YES')
else:
print('NO') |
s070466637 | p03643 | u591717585 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 20 | This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer. | print("ABC",input()) | s710873673 | Accepted | 17 | 2,940 | 20 | print("ABC"+input()) |
s871667688 | p03433 | u115877451 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 77 | E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. | a=int(input())
b=int(input())
if a%500>=b:
print('Yes')
else:
print('No') | s620273982 | Accepted | 17 | 2,940 | 77 | a=int(input())
b=int(input())
if a%500<=b:
print('Yes')
else:
print('No') |
s945075686 | p03759 | u634079249 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 250 | Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful. | import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
a, b, c = list(map(int, sys.stdin.readline().split()))
print('Yes' if b - a == c - b else 'No')
if __name__ == '__main__':
main()
| s961745986 | Accepted | 18 | 2,940 | 250 | import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
a, b, c = list(map(int, sys.stdin.readline().split()))
print('YES' if b - a == c - b else 'NO')
if __name__ == '__main__':
main()
|
s445820734 | p03477 | u030090262 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 212 | A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right. | # -*- coding: utf-8 -*-
"""
Created on Mon Mar 4 15:01:58 2019
@author: kaned
"""
A,B,C,D=map(int,input().split())
L=A+B
R=C+D
if L<R:
print('Left')
elif L>R:
print('Right')
else:
print("Balanced")
| s375422025 | Accepted | 18 | 3,060 | 212 | # -*- coding: utf-8 -*-
"""
Created on Mon Mar 4 15:01:58 2019
@author: kaned
"""
A,B,C,D=map(int,input().split())
L=A+B
R=C+D
if L>R:
print('Left')
elif L<R:
print('Right')
else:
print("Balanced")
|
s109509047 | p02842 | u969708690 | 2,000 | 1,048,576 | Time Limit Exceeded | 2,104 | 3,064 | 347 | Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact. | import sys
N=int(input())
a=N//1.08
b=a*1.08
b=int(b)
if b==N:
print(a)
sys.exit()
while True:
if b>N:
a=a-1
b=a*1.08
b=int(b)
if b<N:
print(":(")
sys.exit()
elif b==N:
print(a)
elif b<N:
a=a+1
b=a*1.08
b=int(b)
if b>N:
print(":(")
sys.exit()
elif b==N:
print(a) | s377135228 | Accepted | 17 | 3,064 | 197 | import sys
N=int(input())
a=N//1.08
c=a+1
d=a-1
b=a*1.08
b=int(b)
if b==N:
print(int(a))
sys.exit()
elif int(c*1.08)==N:
print(int(c))
elif int(d*1.08)==N:
print(int(d))
else:
print(":(") |
s626877222 | p03623 | u500279510 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 89 | Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|. | x, a, b = map(int,input().split())
A = abs(x-a)
B = abs(x-b)
ans = [A, B]
print(min(ans)) | s811726459 | Accepted | 17 | 2,940 | 104 | x, a, b = map(int,input().split())
A = abs(x-a)
B = abs(x-b)
if A<B:
print('A')
else:
print('B') |
s338644585 | p02608 | u215286521 | 2,000 | 1,048,576 | Time Limit Exceeded | 2,206 | 26,908 | 894 | Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N). | from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
N = I()
def test(n):
cnt = 0
for i in range(1,100):
for j in range(1,100):
for k in range(1,100):
if (i+j+k)**2 == n + (i*j + j*k + k*i):
cnt += 1
return cnt
for i in range(N):
print(test(i+1))
| s184451674 | Accepted | 602 | 27,328 | 883 | from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
N = I()
ans = [0 for _ in range(10050)]
for i in range(1,100):
for j in range(1,100):
for k in range(1,100):
v = (i+j+k)**2 - (i*j + j*k + k*i)
if v < 10050:
ans[v] += 1
for i in range(N):
print(ans[i+1])
|
s771899358 | p03555 | u763881112 | 2,000 | 262,144 | Wrong Answer | 151 | 12,444 | 147 | You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise. |
import numpy as np
s=[input() for k in range(2)]
for i in range(3):
if(s[0][i]!=s[1][2-i]):
print("No")
exit(0)
print("Yes") | s230975890 | Accepted | 148 | 12,496 | 91 |
import numpy as np
a=input()
b=input()[::-1]
if(a!=b):
print("NO")
else:print("YES") |
s494748006 | p02850 | u405256066 | 2,000 | 1,048,576 | Wrong Answer | 589 | 43,744 | 737 | Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors. | from sys import stdin
from collections import defaultdict
from collections import deque
N = int(stdin.readline().rstrip())
adj = defaultdict(set)
for i in range(N-1):
a,b = [int(x) for x in stdin.readline().rstrip().split()]
adj[a].add(b)
adj[b].add(a)
visited = [False]*(N+1)
color_edges = [0]*(N+1)
visit_p = deque()
visit_p.append((1,1))
while visit_p:
node,color = visit_p.popleft()
if visited[node]:
continue
color_edges[node] = color
visited[node] = True
cnt = 0
for i in adj[node]:
if visited[i]:
continue
cnt += 1
if cnt == color:
cnt += 1
visit_p.append((i,cnt))
for i in color_edges[1:]:
print(i) | s057758129 | Accepted | 665 | 66,408 | 905 | from sys import stdin
from collections import defaultdict
from collections import deque
N = int(stdin.readline().rstrip())
adj = defaultdict(set)
edges = []
for i in range(N-1):
a,b = [int(x) for x in stdin.readline().rstrip().split()]
adj[a].add(b)
adj[b].add(a)
edges.append((a,b))
visited = [False]*(N+1)
color_edges = defaultdict(bool)
visit_p = deque()
visit_p.append((1,0))
while visit_p:
node,color = visit_p.popleft()
if visited[node]:
continue
visited[node] = True
cnt = 0
for i in adj[node]:
if visited[i]:
continue
cnt += 1
if cnt == color:
cnt += 1
color_edges[(node,i)] = cnt
visit_p.append((i,cnt))
print(max(color_edges.values()))
for i in edges:
if not color_edges[i]:
print(color_edges[(i[1],i[0])])
else:
print(color_edges[i]) |
s063158059 | p03657 | u178432859 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 122 | Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies. | a,b = map(int, input().split())
if a%3 == 0 or b%3 == 0 or a+b%3 == 0:
print("Possible")
else:
print("Impossible") | s888932556 | Accepted | 17 | 2,940 | 124 | a,b = map(int, input().split())
if a%3 == 0 or b%3 == 0 or (a+b)%3 == 0:
print("Possible")
else:
print("Impossible") |
s395357636 | p02606 | u464013915 | 2,000 | 1,048,576 | Wrong Answer | 22 | 9,024 | 266 | How many multiples of d are there among the integers between L and R (inclusive)? | def a_number_of_multiples(l,r,d):
r = r+1
range_list = list(range(l,r))
per_list = []
for i in range_list:
if i % d == 0:
per_list.append(i)
else:
pass
count_list = len(per_list)
return count_list
| s865621933 | Accepted | 29 | 9,064 | 196 | l,r,d = map(int, input().split())
r = r+1
range_list = list(range(l,r))
per_list = []
for i in range_list:
if i % d == 0:
per_list.append(i)
else:
pass
print(len(per_list)) |
s712964052 | p02619 | u324739185 | 2,000 | 1,048,576 | Wrong Answer | 119 | 27,452 | 758 | Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated. | # -*- coding: utf-8 -*-
import time
import numpy as np
start = time.time()
limit_time = 1.8
d = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(d)]
def point(t):
result = 0
map = {
0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0,
10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0,
20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0
}
for i in range(d):
comp = t[i] - 1
day = i + 1
map[comp] = day
result = result + s[i][comp]
for cc in range(26):
result = result - c[cc] * (day - map[cc])
print(result)
return result
t = [int(input()) for i in range(d)]
| s732856192 | Accepted | 129 | 27,608 | 766 | # -*- coding: utf-8 -*-
import time
import numpy as np
start = time.time()
limit_time = 1.8
d = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(d)]
def point(t):
result = 0
map = {
0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0,
10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0,
20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0
}
for i in range(d):
comp = t[i] - 1
day = i + 1
map[comp] = day
result = result + s[i][comp]
for cc in range(26):
result = result - c[cc] * (day - map[cc])
print(result)
return result
t = [int(input()) for i in range(d)]
point(t) |
s294124737 | p03486 | u925406312 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 194 | You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order. | a = input()
b = input()
aa = list(a)
bb = list(b)
aa.sort()
bb.sort()
S = "".join(aa)
T = "".join(bb)
if S < T:
answer = "Yes"
print(answer)
else:
answer = "No"
print(answer) | s607700101 | Accepted | 18 | 3,060 | 208 |
a = input()
b = input()
aa = list(a)
bb = list(b)
aa.sort()
bb.sort(reverse=True)
S = "".join(aa)
T = "".join(bb)
if S < T:
answer = "Yes"
print(answer)
else:
answer = "No"
print(answer) |
s771838812 | p03377 | u064246852 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 93 | There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals. | l = list(map(int,input().split()))
a,b,x = l[0],l[1],l[2]
print("Yes" if a<=x<=a+b else "No") | s035105094 | Accepted | 17 | 2,940 | 124 | line = list(map(int,input().split()))
a,b,x=line[0],line[1],line[2]
if a <= x <= a+b:
print("YES")
else:
print("NO") |
s017465819 | p02806 | u886478505 | 2,525 | 1,048,576 | Wrong Answer | 17 | 2,940 | 115 | Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep. | d = 0
a = int(input())
for i in range(a):
b, c = map(str, input().split())
c = int(c)
d += c
print(d)
| s765220381 | Accepted | 17 | 3,060 | 247 | total = 0
a = int(input())
f = [];
g = [];
for i in range(a):
b, c = map(str, input().split())
c = int(c)
f.append(b)
g.append(c)
e = input()
h = f.index(e)
j = len(f)
for i in range(j-h-1):
total += int(g[h+i+1])
print(total)
|
s329546139 | p02936 | u709076082 | 2,000 | 1,048,576 | Wrong Answer | 2,106 | 36,212 | 575 | Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations. | n,q = map(int, input().split())
a = [0]*(n-1)
b = [0]*(n-1)
for i in range(n-1):
a[i],b[i] = map(int, input().split())
p = [0]*q
x = [0]*q
for i in range(q):
p[i],x[i] = map(int, input().split())
score = [0]*n
def down_tree(parent, add_score):
global score
judge_count = 0
for i in range(q):
if p[i]-1 == parent:
add_score += x[i]
for i in range(n-1):
if a[i]-1 == parent:
down_tree(b[i]-1, add_score)
judge_count += 1
score[parent] += add_score
return 0
down_tree(0, 0)
print(score) | s694290017 | Accepted | 1,503 | 232,312 | 543 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(200005)
n, q = map(int, input().split())
to = [[] for i in range(n+1)]
for i in range(n-1):
a, b = map(int, input().split())
to[a].append(b)
to[b].append(a)
score = [0]*(n+1)
for i in range(q):
p, x = map(int, input().split())
score[p] += x
def down_tree(index, parent):
for i in to[index]:
if i == parent:
continue
score[i] += score[index]
down_tree(i, index)
down_tree(1, 1)
print(' '.join(map(str, score[1:]))) |
s882976456 | p03388 | u392319141 | 2,000 | 262,144 | Wrong Answer | 19 | 3,064 | 378 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | import math
Q = int(input())
AB = []
for _ in range(Q) :
a, b = map(int, input().split())
AB.append((a, b))
for a, b in AB :
if a == b :
print(2 * a - 2)
elif (a + 1) == b :
print(2 * a - 2)
else :
C = int(math.sqrt(a * b))
if C * (C + 1) >= a * b :
print(2 * C - 2)
else :
print(2 * C - 1)
| s255425666 | Accepted | 19 | 3,188 | 326 | Q = int(input())
ans = []
for _ in range(Q):
A, B = map(int, input().split())
if A == B:
ans.append(2 * A - 2)
continue
C = (A * B)**0.5
D = int(C)
if C.is_integer():
D -= 1
F = 2 * D - 1
if D * (D + 1) >= A * B:
F -= 1
ans.append(F)
print(*ans, sep='\n') |
s618661177 | p03729 | u616040357 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 199 | You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`. | def solve():
a, b, c = map(str, input().split())
if a[-1] == b[0] and b[-1] == c[0]:
ans = "Yes"
else:
ans = "No"
print(ans)
if __name__ == '__main__':
solve() | s857949504 | Accepted | 17 | 2,940 | 208 | def solve():
a, b, c = map(str, input().split())
if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
ans = "YES"
else:
ans = "NO"
print(ans)
if __name__ == '__main__':
solve() |
s614643982 | p02795 | u698309473 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 60 | We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations. | H,W,N = [int(input()) for _ in range(3)]
print(N/max(H,W)+1) | s446617343 | Accepted | 17 | 2,940 | 134 | # -*- coding: utf-8 -*-
H,W,N = [int(input()) for _ in range(3)]
ans = N/max(H,W) if N%max(H,W)==0 else N/max(H,W)+1
print(int(ans)) |
s518778944 | p03672 | u371467115 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 107 | We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. | s=input()
ans=0
for i in range(len(s)):
if s[:i+1]==s[i+1:i*2+2]:
ans+=1
else:
break
print(ans) | s101651792 | Accepted | 17 | 2,940 | 107 | s=input()
ans=0
for i in range(len(s)//2):
if s[:i]==s[i:2*i]:
ans=2*i
print(ans)
|
s486806739 | p02414 | u487330611 | 1,000 | 131,072 | Wrong Answer | 20 | 5,604 | 273 | Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively. | a,b,c=map(int,input().split())
A=[]
B=[]
for i in range(a):A.append(list(map(int,input().split())))
for i in range(b):B.append(list(map(int,input().split())))
for A_r in A:
print("".join(map(str,[sum(x*y for x,y in zip(A_r,[B_r[k] for B_r in B])) for k in range(1)])))
| s599913647 | Accepted | 140 | 6,320 | 280 | n,m,l = map(int,input().split())
A=[]
B=[]
for i in range(n): A.append(list(map(int,input().split())))
for j in range(m): B.append(list(map(int,input().split())))
for A_r in A:
print(" ".join(map(str,[sum([x*y for x,y in zip(A_r,[B_r[k] for B_r in B])]) for k in range(l)])))
|
s863809019 | p03478 | u103902792 | 2,000 | 262,144 | Wrong Answer | 35 | 3,060 | 168 | Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). | n,a,b = map(int,input().split())
ans = 0
for i in range(1,n+1):
d = i
s=0
while d:
r = d %10
d = int(d/10)
s+=r
if a<=s<=b:
ans += 1
print(ans) | s946524637 | Accepted | 32 | 2,940 | 166 | n,a,b = map(int,input().split())
ans = 0
for i in range(1,n+1):
d = i
s = 0
while d:
s += d % 10
d = int(d/10)
if a<=s<=b:
ans += i
print(ans)
|
s988379709 | p03377 | u974935538 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 103 | There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals. | A,B,X = map(int,input().split())
ans = X-A
if (ans<B)and(ans>0):
print("Yes")
else:
print("No") | s938481125 | Accepted | 17 | 2,940 | 103 | A,B,X = map(int,input().split())
ans = X-A
if (ans<=B)&(ans>=0):
print("YES")
else:
print("NO") |
s164559792 | p02396 | u311299757 | 1,000 | 131,072 | Wrong Answer | 130 | 7,344 | 150 | In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem. | i = 1
while True:
inputted_str = input()
if inputted_str != "0":
print("Case {}: {}".format(i, inputted_str))
else:
break | s068804670 | Accepted | 130 | 7,584 | 167 | i = 1
while True:
inputted_str = int(input())
if inputted_str != 0:
print("Case {}: {}".format(i, inputted_str))
i += 1
else:
break |
s923530245 | p02255 | u825178626 | 1,000 | 131,072 | Wrong Answer | 20 | 7,532 | 263 | Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step. | def sort(l):
for i in range(len(l)) :
key = l[i]
j = i-1
while i-1>=0 & l[j]>key:
l[j+1] = l[j]
j -= 1
l[j+1] = key
print(l)
n = int(input())
line = list(map(int,input().split(" ")))
sort(line) | s847216740 | Accepted | 20 | 7,752 | 304 | def inSort(n):
print(" ".join(list(map(str,n))))
for i in range(1,len(n)):
v = n[i]
j = i-1
while j>=0 and n[j]>v:
n[j+1]=n[j]
j-=1
n[j+1]=v
print(" ".join(list(map(str,n))))
A=input()
N=list(map(int,input().split()))
inSort(N) |
s126089562 | p03737 | u571832343 | 2,000 | 262,144 | Wrong Answer | 28 | 8,976 | 85 | You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words. | a,b,c=input().split()
A = a.upper()
B = b.upper()
C = c.upper()
print(A[0]+B[0]+c[0]) | s721388483 | Accepted | 30 | 9,052 | 85 | a,b,c=input().split()
A = a.upper()
B = b.upper()
C = c.upper()
print(A[0]+B[0]+C[0]) |
s630827232 | p03577 | u409306788 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 88 | Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`. | import sys
input = sys.stdin.readline
# A - XXFESTIVAL
s = input()
print(s[:len(s)-8]) | s105940999 | Accepted | 17 | 2,940 | 49 | # A - XXFESTIVAL
s = input()
print(s[:len(s)-8]) |
s168128646 | p02453 | u126478680 | 2,000 | 262,144 | Wrong Answer | 20 | 5,616 | 166 | For a given sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, find the lower bound for a specific value $k$ given as a query. * lower bound: the place pointing to the first element greater than or equal to a specific value, or $n$ if there is no such element. | import bisect
n = int(input())
a = list(map(int, input().split(' ')))
q = int(input())
for i in range(q):
k = int(input())
print(bisect.bisect_right(a, k))
| s358501199 | Accepted | 1,650 | 17,216 | 165 | import bisect
n = int(input())
a = list(map(int, input().split(' ')))
q = int(input())
for i in range(q):
k = int(input())
print(bisect.bisect_left(a, k))
|
s517506082 | p03730 | u583326945 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 538 | We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`. |
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
if __name__ == "__main__":
input_list = list(map(int, input().split()))
print(input_list)
a, b, c = input_list
result = False
lcm_of_ab = lcm(a, b)
for i in range(lcm_of_ab // a + 1):
if (not i):
continue
if (a * i) % b == c:
result = True
break
if result:
print("YES")
else:
print("NO") | s477229368 | Accepted | 17 | 3,064 | 516 |
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
if __name__ == "__main__":
input_list = list(map(int, input().split()))
a, b, c = input_list
result = False
lcm_of_ab = lcm(a, b)
for i in range(lcm_of_ab // a + 1):
if (not i):
continue
if (a * i) % b == c:
result = True
break
if result:
print("YES")
else:
print("NO") |
s043329201 | p02390 | u124462667 | 1,000 | 131,072 | Wrong Answer | 20 | 5,576 | 87 | Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively. |
sec = int(input())
m = sec//60
sec %= 60
h = m//60
print("{}:{}:{}".format(h,m,sec))
| s581456458 | Accepted | 20 | 5,584 | 93 |
sec = int(input())
m = sec//60
sec %= 60
h = m//60
m%=60
print("{}:{}:{}".format(h,m,sec))
|
s294940697 | p03845 | u272522520 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 198 | Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds. It does not affect the time to solve the other problems. A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her. | N = int(input())
T = list(map(int, input().split()))
M = int(input())
SUM = 0
for i in range(N):
SUM = SUM + T[i]
for i in range(M):
P,X = map(int, input().split())
print(25-(T[P-1]-X)) | s707576904 | Accepted | 18 | 3,060 | 199 | N = int(input())
T = list(map(int, input().split()))
M = int(input())
SUM = 0
for i in range(N):
SUM = SUM + T[i]
for i in range(M):
P,X = map(int, input().split())
print(SUM-(T[P-1]-X)) |
s216004479 | p03471 | u859897687 | 2,000 | 262,144 | Wrong Answer | 778 | 3,060 | 165 | The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough. | n,y=map(int,input().split())
x,y,z=-1,-1,-1
for i in range(n+1):
for j in range(n+1-i):
k=n-i-j
if i*10000+j*5000+k*1000==n:
x,y,z=i,j,k
print(x,y,z) | s886394493 | Accepted | 845 | 3,060 | 169 | n,yen=map(int,input().split())
x,y,z=-1,-1,-1
for i in range(n+1):
for j in range(n+1-i):
k=n-i-j
if i*10000+j*5000+k*1000==yen:
x,y,z=i,j,k
print(x,y,z) |
s968968988 | p03485 | u965230804 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 58 | You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer. | a = list(map(int, input().split()))
print(((a[0]+a[1])/2)) | s717585533 | Accepted | 18 | 2,940 | 80 | import math
a = list(map(int, input().split()))
print(math.ceil((a[0]+a[1])/2))
|
s574020217 | p01554 | u509278866 | 2,000 | 131,072 | Wrong Answer | 50 | 9,020 | 997 | ある部屋ではICカードを用いて鍵を開け閉めする電子錠システムを用いている。 このシステムは以下のように動作する。 各ユーザーが持つICカードを扉にかざすと、そのICカードのIDがシステムに渡される。 システムはIDが登録されている時、施錠されているなら開錠し、そうでないのなら施錠し、それぞれメッセージが出力される。 IDが登録されていない場合は、登録されていないというメッセージを出力し、開錠及び施錠はおこなわれない。 さて、現在システムにはN個のID(U1, U2, ……, UN)が登録されており、施錠されている。 M回ICカードが扉にかざされ、そのIDはそれぞれ順番にT1, T2, ……, TMであるとする。 この時のシステムがどのようなメッセージを出力するか求めよ。 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
n = I()
a = [S() for _ in range(n)]
m = I()
b = [S() for _ in range(m)]
d = 1
for c in b:
if c not in a:
rr.append('Unknown {}'.format(c))
elif d == 1:
rr.append('Opened {}'.format(c))
d = 0
else:
rr.append('Closed {}'.format(c))
d = 1
return '\n'.join(map(str, rr))
print(main())
| s975176775 | Accepted | 60 | 9,084 | 1,003 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
n = I()
a = [S() for _ in range(n)]
m = I()
b = [S() for _ in range(m)]
d = 1
for c in b:
if c not in a:
rr.append('Unknown {}'.format(c))
elif d == 1:
rr.append('Opened by {}'.format(c))
d = 0
else:
rr.append('Closed by {}'.format(c))
d = 1
return '\n'.join(map(str, rr))
print(main())
|
s756859221 | p03448 | u099026234 | 2,000 | 262,144 | Wrong Answer | 110 | 9,060 | 408 | You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. | [a,b,c,d]=[int(input()) for i in range(1,4+1)]
a1 = d // 500
b1 = d// 100
c1 = d// 50
value = 0
count = 0
for i in range(0,a1+1):
value = value + 500*i
for j in range(0,b1+1-5*i):
value = value + 100*j
for k in range(0,c1+1-10*i-2*j):
value = value + 50*k
if value == d :
count = count+1
break
value = 0
print(count) | s773442373 | Accepted | 39 | 9,092 | 490 | [a,b,c,d]=[int(input()) for i in range(1,4+1)]
a1 = d // 500
b1 = d// 100
c1 = d// 50
coun = 0
for i in range(0,min([a+1,a1+1])):
a = 500*i
if a == d:
coun = coun +1
break
for j in range(0,min([b+1,b1+1-5*i])):
s = a + 100*j
if s == d :
coun = coun +1
break
for k in range(0,min([c+1,c1+1-10*i-2*j])):
v = s + 50*k
if v == d :
coun = coun+1
break
print(coun) |
s847450154 | p02865 | u882359130 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 30 | How many ways are there to choose two distinct positive integers totaling N, disregarding the order? | print((int(input())+1)//2 + 1) | s529229025 | Accepted | 17 | 2,940 | 30 | print((int(input())+1)//2 - 1) |
s549623004 | p03455 | u155687575 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 86 | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. | a, b = map(int, input().split())
if a*b % 2 == 0:
print('Odd')
else:
print('Even') | s866129669 | Accepted | 17 | 2,940 | 88 | a, b = map(int, input().split())
if a*b%2 == 0:
print('Even')
else:
print('Odd') |
s508556931 | p03573 | u672316981 | 2,000 | 262,144 | Wrong Answer | 27 | 9,100 | 101 | You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers. | abc = list(map(int, input().split()))
if abc[0] == abc[1]:
print(abc[2])
else:
print(abc[0]) | s479558757 | Accepted | 33 | 9,044 | 112 | abc = list(map(int, input().split()))
abc.sort()
if abc[0] == abc[1]:
print(abc[2])
else:
print(abc[0]) |
s449871808 | p03815 | u525065967 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 93 | Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: * Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total. | x = int(input())
c = (x/11)*2
x %= 11
if x==0: print(c)
elif x<6: print(c+1)
else: print(c+2) | s135012870 | Accepted | 17 | 2,940 | 146 | x = int(input())
# dice face 5 start: snuke-kun's favorite number
q,r = divmod(x,11)
if r==0: print(q*2)
elif r<7: print(q*2+1)
else: print(q*2+2) |
s966382082 | p03997 | u405256066 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 69 | You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid. | a = int(input())
b = int(input())
h = int(input())
print((a+b)*(h/2)) | s560988711 | Accepted | 17 | 2,940 | 70 | a = int(input())
b = int(input())
h = int(input())
print((a+b)*(h//2)) |
s004145461 | p04045 | u582243208 | 2,000 | 262,144 | Wrong Answer | 84 | 3,064 | 211 | Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier. | n,k=map(int,input().split())
d=[i for i in input().split()]
print(d)
while True:
f=True
for i in d:
if i in str(n):
f=False
break
if f:
break
n+=1
print(n) | s901455089 | Accepted | 83 | 3,064 | 202 | n,k=map(int,input().split())
d=[i for i in input().split()]
while True:
f=True
for i in d:
if i in str(n):
f=False
break
if f:
break
n+=1
print(n) |
s067927997 | p00089 | u150984829 | 1,000 | 131,072 | Wrong Answer | 30 | 5,452 | 1 | 図1に例示するように整数(0 以上 99 以下)をひしがたに並べます。このような、ひしがたを表すデータを読み込んで、一番上からスタートして一番下まで次のルールに従って進むとき、通過する整数の和の最大値を出力するプログラムを作成してください。 * 各ステップで、対角線上の左下か対角線上の右下に進むことができます。 例えば図1の例では、図2に示すように、7,3,8,7,5,7,8,3,7を選んで通ったとき、その和は最大の 55 (7+3+8+7+5+7+8+3+7=55) となります。 | s751663412 | Accepted | 30 | 5,608 | 188 | import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
k,l=s[i-1],len(s[i]);b=l>len(k)
for j in range(l):s[i][j]+=max(k[(j-b)*(j>0):j-b+2])
print(*s[-1])
|
|
s998810322 | p03455 | u103539599 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 87 | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. | a,b=map(int, input().split())
if (a+b)%2==0:
print("Even")
else:
print("Odd")
| s942435402 | Accepted | 17 | 2,940 | 87 | a,b=map(int, input().split())
if (a*b)%2==0:
print("Even")
else:
print("Odd")
|
s229992553 | p03550 | u952968889 | 2,000 | 262,144 | Wrong Answer | 18 | 3,188 | 197 | We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game? | N,Z,W = map(int,input().split(" "))
a = list(map(int,input().split(" ")))
if N == 1:
ans = abs(a[-1]-W)
else:
ans = max(abs(a[-1]-a[-2]),abs(a[-1]-W))
print(a) | s128905779 | Accepted | 18 | 3,188 | 199 | N,Z,W = map(int,input().split(" "))
a = list(map(int,input().split(" ")))
if N == 1:
ans = abs(a[-1]-W)
else:
ans = max(abs(a[-1]-a[-2]),abs(a[-1]-W))
print(ans) |
s858909005 | p03007 | u439542873 | 2,000 | 1,048,576 | Wrong Answer | 141 | 20,632 | 425 | There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer. | n = int(input())
a = list(map(int, input().split()))
a.sort()
def answer():
p = sum(1 for i in a if i < 0)
q = sum(1 for i in a if i >= 0)
if p == 0:
p += 1
q -= 1
if q == 0:
p -= 1
q += 1
for i in range(q - 1):
print(a[0], a[p + i])
a[0] -= a[p + i]
for i in range(p):
print(a[-1], a[i])
a[-1] -= a[i]
# print(a[-1])
answer()
| s856045774 | Accepted | 183 | 23,680 | 531 | n = int(input())
a = list(map(int, input().split()))
a.sort()
def answer():
p = sum(1 for i in a if i < 0)
q = sum(1 for i in a if i >= 0)
if p == 0:
p += 1
q -= 1
if q == 0:
p -= 1
q += 1
list_xy = []
for i in range(q - 1):
list_xy.append((a[0], a[p + i]))
a[0] -= a[p + i]
for i in range(p):
list_xy.append((a[-1], a[i]))
a[-1] -= a[i]
return a[-1], list_xy
m, list_xy = answer()
print(m)
for x, y in list_xy:
print(x, y)
|
s820422679 | p03227 | u177907787 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 101 | You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it. | s = input()
n = len(s)
if (n == 3):
for i in range(n):
print(s[n-i-1],end = "")
print()
print(s) | s621244274 | Accepted | 17 | 2,940 | 107 | s = input()
n = len(s)
if (n == 3):
for i in range(n):
print(s[n-i-1],end = "")
print()
else:
print(s) |
s969013459 | p03998 | u320763652 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 467 | Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. | a = input()
b = input()
c = input()
next = 'a'
while True:
if next == 'a':
if not a:
print('A')
exit()
a = a[:-1]
if a:
next = a[-1]
elif next == 'b':
if not b:
print('B')
exit()
b = b[:-1]
if b:
next = b[-1]
else:
if not c:
print('C')
exit()
c = c[:-1]
if c:
next = c[-1] | s662223207 | Accepted | 17 | 3,064 | 411 | a = input()
b = input()
c = input()
turn = 'a'
while True:
if turn == 'a':
if a == "":
print('A')
break
turn = a[0]
a = a[1:]
elif turn == 'b':
if b == "":
print('B')
break
turn = b[0]
b = b[1:]
else:
if c == "":
print('C')
break
turn = c[0]
c = c[1:] |
s249589481 | p03160 | u462971444 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 332 | There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N. | def solve():
N = int(input())
heights = map(int, input().split(" "))
dp1 = 0
dp2 = abs(heights[1] - heights[0])
for i in range(2, N):
tmp = dp2
dp2 = min(
dp2 + abs(heights[i] - heights[i-1]),
dp1 + abs(heights[i] - heights[i-2])
)
dp1 = tmp
print(dp2) | s868833951 | Accepted | 88 | 13,924 | 349 | def solve():
N = int(input())
heights = [int(c) for c in input().split(" ")]
dp1 = 0
dp2 = abs(heights[1] - heights[0])
for i in range(2, N):
tmp = dp2
dp2 = min(
dp2 + abs(heights[i] - heights[i-1]),
dp1 + abs(heights[i] - heights[i-2])
)
dp1 = tmp
print(dp2)
solve() |
s757538078 | p03377 | u366644013 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 88 | There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals. | a, b, x = input().split()
if x <= a+b and x >= a:
print("YES")
else:
print("NO") | s587675240 | Accepted | 18 | 3,064 | 98 | a, b, x = map(int, input().split())
if x <= a+b and x >= a:
print("YES")
else:
print("NO") |
s296026302 | p03399 | u251017754 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 72 | You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. | a = input()
b = input()
c = input()
d = input()
print(min(a,b)+min(c,d)) | s028047133 | Accepted | 17 | 2,940 | 94 | a = int(input())
b = int(input())
c = int(input())
d = int(input())
print(min(a,b) + min(c,d)) |
s764599010 | p02255 | u996463517 | 1,000 | 131,072 | Wrong Answer | 20 | 5,596 | 196 | Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step. | n = int(input())
A = [int(i) for i in input().split()]
for i in range(n):
v = A[i]
j = i - 1
while j >= 0 and A[j]>v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(A)
| s538228039 | Accepted | 20 | 5,600 | 215 | n = int(input())
A = [int(i) for i in input().split()]
for i in range(n):
v = A[i]
j = i - 1
while j >= 0 and A[j]>v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(" ".join(map(str,A)))
|
s453716803 | p03814 | u159335277 | 2,000 | 262,144 | Wrong Answer | 25 | 9,104 | 45 | Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. | s = input()
print(s.rfind('Z') - s.find('A')) | s074664295 | Accepted | 29 | 9,292 | 50 | s = input()
print(s.rfind('Z') - s.find('A') + 1)
|
s112023870 | p03502 | u105302073 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 239 | An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. | def find_sum_of_digits(n):
total = 0
while n > 0:
total += n % 10
n //= 10
return total
N = int(input())
total = find_sum_of_digits(N)
print(N, total)
if N % total == 0:
print("Yes")
else:
print("No")
| s845866341 | Accepted | 17 | 2,940 | 223 | def find_sum_of_digits(n):
total = 0
while n > 0:
total += n % 10
n //= 10
return total
N = int(input())
total = find_sum_of_digits(N)
if N % total == 0:
print("Yes")
else:
print("No")
|
s608473101 | p03564 | u084320347 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 97 | Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. | n = int(input())
k = int(input())
ans = 1
for i in range(n):
ans += min(n*2,n+k)
print(ans) | s276435144 | Accepted | 17 | 2,940 | 143 | n = int(input())
k = int(input())
ans = 1
for i in range(n):
if ans*2 <ans+k:
ans=ans*2
else:
ans = ans+k
print(ans)
|
s157428687 | p03610 | u766407523 | 2,000 | 262,144 | Wrong Answer | 17 | 3,316 | 115 | You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1. | s = input().split()
ans = ''
for i in range(len(s)):
if (i+1)%2==0:
continue
ans += s[i]
print(ans) | s337195379 | Accepted | 41 | 3,188 | 107 | s = input()
ans = ''
for i in range(len(s)):
if (i+1)%2==0:
continue
ans += s[i]
print(ans) |
s853000971 | p03623 | u175590965 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 82 | Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|. | x,a,b = map(int,input().split())
if x-a > b-x:
print("A")
else:
print("B") | s083235420 | Accepted | 17 | 2,940 | 92 | x,a,b = map(int,input().split())
if abs(x-a) > abs(x-b):
print("B")
else:
print("A") |
s032445877 | p02259 | u468827564 | 1,000 | 131,072 | Wrong Answer | 20 | 7,636 | 308 | Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode. | #coding: UTF-8
a = int(input())
N = list(map(int, input().split()))
c = 0
for i in range(a - 1):
for j in range(a-1, i,-1):
if N[j] < N[j - 1]:
tmp = N[j]
N[j] = N[j - 1]
N[j - 1] = tmp
for i in range(a - 1):
print(N[i],end=' ')
print(N[a-1]);
print(c); | s776669434 | Accepted | 30 | 7,700 | 326 | #coding: UTF-8
a = int(input())
N = list(map(int, input().split()))
c = 0
for i in range(a - 1):
for j in range(a-1, i,-1):
if N[j] < N[j - 1]:
c+=1
tmp = N[j]
N[j] = N[j - 1]
N[j - 1] = tmp
for i in range(a - 1):
print(N[i],end=' ')
print(N[a-1]);
print(c); |
s089369929 | p03471 | u969062493 | 2,000 | 262,144 | Wrong Answer | 1,097 | 3,060 | 291 | The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough. | n, y = map(int, input().split())
b = [-1, -1, -1]
count = 0
for i in range(n + 1):
for j in range(n + 1):
k = n - i - j
if k < 0:
break
total = 10000 * i + 5000 * j + 1000 * k
count += 1
if total == y and (i + j + k) == n:
b = [i, j, k]
break
print(b) | s491750389 | Accepted | 1,079 | 3,064 | 316 | n, y = map(int, input().split())
b = [-1, -1, -1]
count = 0
for i in range(n + 1):
for j in range(n + 1):
k = n - i - j
if k < 0:
break
total = 10000 * i + 5000 * j + 1000 * k
count += 1
if total == y and (i + j + k) == n:
b = [i, j, k]
print('{0} {1} {2}'.format(b[0], b[1], b[2])) |
s999714915 | p02397 | u711765449 | 1,000 | 131,072 | Wrong Answer | 30 | 7,748 | 171 | Write a program which reads two integers x and y, and prints them in ascending order. | # -*- coding:utf-8 -*-
import sys
array = []
for i in sys.stdin:
array.append(i)
for i in range(len(array)):
x,y = array[i].split()
y,x = x,y
print(x,y) | s137290452 | Accepted | 40 | 7,988 | 237 | import sys
while True:
(x, y) = [int(i) for i in sys.stdin.readline().split(' ')]
if x == 0 and y == 0:
break
if x > y:
z = x
x = y
y = z
print(x, y) |
s296260276 | p02678 | u250795848 | 2,000 | 1,048,576 | Wrong Answer | 2,206 | 33,904 | 506 | There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. | from collections import deque
n,m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(1,m+1):
a,b = map(int, input().split())
graph[a-1].append(b)
graph[b-1].append(a)
q = deque([1])
prev=[1]
siru = [0] * (n-1)
while q:
now = q.popleft()
next = graph[now-1]
for n in next:
if not n in prev:
q.append(n)
prev.append(n)
siru[n-2] = now
if 0 in siru:
print("No")
else:
print(siru)
| s174971258 | Accepted | 584 | 41,860 | 631 | from collections import deque
def main():
n,m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
a,b = map(int, input().split())
graph[a-1].append(b)
graph[b-1].append(a)
q = deque([1])
prev=[1]
siru = [0] * n
siru[0] = 1
while q:
now = q.popleft()
next = graph[now-1]
for n in next:
if not siru[n-1]:
q.append(n)
siru[n-1] = now
print("Yes")
print("\n".join(map(str, siru[1:])))
if __name__ == "__main__":
main()
|
s583730619 | p02613 | u225020286 | 2,000 | 1,048,576 | Wrong Answer | 149 | 16,316 | 292 | Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format. | N=int(input())
S=[input() for i in range(N)]
ac=0
wa=0
tle=0
re=0
for i in S:
if i=="AC":
ac+=1
elif i=="WA":
wa+=1
elif i=="TLE":
tle+=1
elif i=="RE":
re+=1
print("AC ×"+" "+str(ac))
print("WA ×"+" "+str(wa))
print("TLE ×"+" "+str(tle))
print("RE ×"+" "+str(re))
| s321399760 | Accepted | 155 | 16,332 | 288 | N=int(input())
S=[input() for i in range(N)]
ac=0
wa=0
tle=0
re=0
for i in S:
if i=="AC":
ac+=1
elif i=="WA":
wa+=1
elif i=="TLE":
tle+=1
elif i=="RE":
re+=1
print("AC x"+" "+str(ac))
print("WA x"+" "+str(wa))
print("TLE x"+" "+str(tle))
print("RE x"+" "+str(re))
|
s501880042 | p02833 | u411923565 | 2,000 | 1,048,576 | Wrong Answer | 27 | 8,900 | 1 | For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). | 5 | s651292295 | Accepted | 27 | 9,136 | 201 | N = int(input())
if N%2 == 1:
print(0)
else:
cnt = 0
for i in range(1,N):
if N >= 2*(5**i):
cnt += N // (2*(5**i))
else:
break
print(cnt) |
s969643141 | p02260 | u612243550 | 1,000 | 131,072 | Wrong Answer | 20 | 7,668 | 255 | Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini. | n = int(input())
A = input().split(' ')
count = 0
for i in range(0, n):
minj = i
for j in range(i, n):
if A[j] < A[minj]:
minj = j
count += 1
(A[i], A[minj]) = (A[minj], A[i])
print(" ".join(A))
print(count) | s170472896 | Accepted | 20 | 7,664 | 283 | n = int(input())
A = input().split(' ')
count = 0
for i in range(0, n):
minj = i
for j in range(i, n):
if int(A[j]) < int(A[minj]):
minj = j
if i != minj:
(A[i], A[minj]) = (A[minj], A[i])
count += 1
print(" ".join(A))
print(count) |
s922016474 | p03386 | u063052907 | 2,000 | 262,144 | Wrong Answer | 19 | 3,060 | 263 | Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers. | # coding: utf-8
import sys
input = sys.stdin.readline
A, B, K = map(int, input().split())
diff = B - A
if diff <= 2*K:
for i in range(A, B+1):
print(i)
else:
for a in range(A, A+K+1):
print(a)
for b in range(B-K, B+1):
print(b) | s970861666 | Accepted | 18 | 3,060 | 188 | # coding: utf-8
import sys
input = sys.stdin.readline
A, B, K = map(int, input().split())
for a in range(A, min(A+K, B+1)):
print(a)
for b in range(max(A+K, B-K+1), B+1):
print(b) |
s905771126 | p03544 | u667024514 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 258 | It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2) | a = int(input())
R0 = 2
R1 = 1
R2 = 1
R = int((a+1)/3)
if a == 1:
print("2")
elif a == 2:
print("1")
else:
for i in range(R):
R2 = R0+R1
R0 = R1+R2
R1 = R2+R0
if a%3 == 0:
print(R2)
elif a%3 == 1:
print(R0)
else:
print(R1) | s235137418 | Accepted | 17 | 3,064 | 299 | a = int(input())
R0 = 3
R1 = 2
R2 = 1
R = int((a-1)/3)
if a == 1:
print("1")
elif a == 2:
print("3")
elif a == 3:
print("4")
else:
for i in range(R):
R1 = R2+R0
R2 = R0+R1
R0 = R1+R2
if a%3 == 0:
R1 = R2+R0
print(R1)
elif a%3 == 1:
print(R2)
else:
print(R0) |
s584378108 | p03487 | u726439578 | 2,000 | 262,144 | Wrong Answer | 2,104 | 15,260 | 160 | You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence. | n=int(input())
a=list(map(int,input().split()))
b=set(a)
ans=0
for i in b:
if i-a.count(i)>=0:
ans+=i-a.count(i)
else:
ans+=i
print(ans) | s173336983 | Accepted | 82 | 18,168 | 260 | n=int(input())
a=list(map(int,input().split()))
count = {}
ans = 0
for i in a:
if i not in count:
count[i] = 1
else:
count[i] += 1
for i,c in count.items():
if i > c:
ans += c
elif i < c:
ans += c - i
print(ans)
|
s819715763 | p03360 | u778700306 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 137 | There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations? |
a,b,c=sorted(map(int,input().split()))
k=int(input())
def pow(x,k):
return x * pow(x, k - 1) if k > 0 else 1
print(a+b+pow(c,k))
| s464413824 | Accepted | 17 | 2,940 | 139 |
a,b,c=sorted(map(int,input().split()))
k=int(input())
def pow(x,k):
return x * pow(x, k - 1) if k > 0 else 1
print(a+b+c*pow(2,k))
|
s240984356 | p03485 | u629607744 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 52 | You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer. | a,b = map(int, input().split())
print((a + b +1 )/2) | s734646767 | Accepted | 18 | 2,940 | 55 | a,b = map(int, input().split())
print((a + b + 1) // 2) |
s892761975 | p03964 | u581187895 | 2,000 | 262,144 | Wrong Answer | 20 | 3,064 | 258 | AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time. Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases. | N = int(input())
takahashi = 1
aoki = 1
for _ in range(N):
t, a = map(int, input().split())
X = -(-takahashi + t-1)//t
Y = -(-aoki + a-1)//a
n = max(X, Y)
takahashi = t*n
aoki = a*n
print(int(takahashi+aoki)) | s255048925 | Accepted | 21 | 3,064 | 262 | N = int(input())
takahashi = 1
aoki = 1
for _ in range(N):
t, a = map(int, input().split())
X = -(-(takahashi + t-1))//t
Y = -(-(aoki + a-1))//a
n = max(X, Y)
takahashi = t*n
aoki = a*n
print(int(takahashi+aoki)) |
s466458421 | p02262 | u777299405 | 6,000 | 131,072 | Wrong Answer | 20 | 6,752 | 626 | Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$ | def insertionsort(a, n, g):
cnt = 0
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j + g] = a[j]
j = j - g
cnt += 1
a[j + g] = v
return cnt
def shellsort(a, n):
g = []
gap = 1
while gap <= n / 9:
g.append(gap)
gap = 3 * gap + 1
g = g[::-1]
m = len(g)
print(m)
print(*g)
cnt = 0
for i in range(m):
cnt += insertionsort(a, n, g[i])
print(cnt)
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
shellsort(a, n)
print("\n".join(map(str, a))) | s557648144 | Accepted | 23,030 | 189,888 | 622 | def insertionsort(a, n, g):
cnt = 0
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j + g] = a[j]
j = j - g
cnt += 1
a[j + g] = v
return cnt
def shellsort(a, n):
g = []
gap = 1
while gap <= n:
g.append(gap)
gap = 3 * gap + 1
g = g[::-1]
m = len(g)
print(m)
print(*g)
cnt = 0
for i in range(m):
cnt += insertionsort(a, n, g[i])
print(cnt)
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
shellsort(a, n)
print("\n".join(map(str, a))) |