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
s866345341
p03672
u814986259
2,000
262,144
Wrong Answer
17
2,940
167
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() for i in reversed(range(len(S))): if i % 2 == 1: moji1 = S[0:i//2 + 1] moji2 = S[i//2 + 1: i+ 1] if moji1==moji2: print(i+1) break
s341367537
Accepted
17
2,940
107
S = input() for i in range(len(S)-2, -1, -2): if S[:i//2] == S[i//2:i]: print(i) break
s118668180
p03729
u231875465
2,000
262,144
Wrong Answer
17
2,940
164
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`.
a, b, c = input().split() def check(a, b, c): if a[-1] == b[0] and b[-1] == c[0]: return True return False print('Yes' if check(a, b, c) else 'No')
s508958089
Accepted
17
3,064
164
a, b, c = input().split() def check(a, b, c): if a[-1] == b[0] and b[-1] == c[0]: return True return False print('YES' if check(a, b, c) else 'NO')
s432689004
p03568
u291988695
2,000
262,144
Wrong Answer
17
3,064
370
We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
i=int(input()) s=input().split() j=[] k=[] a=0 for h in range(i): j.append(int(s[h])%2) for g in range(i): plus=1 if j[g]==0: if len(k)>0: for h in k: plus=plus*h plus=plus*(3^(9-g)) a+=plus k.append(2) else: if len(k)>0: for h in k: plus=plus*h plus=2*plus*(3^(9-g)) a+=plus k.append(1) print(str(a))
s059393469
Accepted
28
9,080
188
n=int(input()) ls=list(map(int,input().split())) prev=1 ans=0 for i in range(n): k=ls[i] if k%2==1: ans+=prev*2*(3**(n-i-1)) else: ans+=prev*3**(n-i-1) prev*=2 print(ans)
s447826183
p03140
u945460548
2,000
1,048,576
Wrong Answer
18
3,064
572
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
N = int(input()) A = input() B = input() C = input() cnt = 0 for idx in range(N): if A[idx] == B[idx] and A[idx] == C[idx] and B[idx] == C[idx]: print(0) continue elif A[idx] == B[idx]: C = C[:idx] + A[idx] + C[idx+1:] cnt += 1 elif A[idx] == C[idx]: B = B[:idx] + A[idx] + B[idx+1:] cnt += 1 elif B[idx] == C[idx]: A = A[:idx] + B[idx] + A[idx+1:] cnt += 1 else: B = B[:idx] + A[idx] + B[idx+1:] C = C[:idx] + A[idx] + C[idx+1:] cnt += 2 #print(A,B,C) print(cnt)
s478579730
Accepted
18
3,064
555
N = int(input()) A = input() B = input() C = input() cnt = 0 for idx in range(N): if A[idx] == B[idx] and A[idx] == C[idx] and B[idx] == C[idx]: continue elif A[idx] == B[idx]: C = C[:idx] + A[idx] + C[idx+1:] cnt += 1 elif A[idx] == C[idx]: B = B[:idx] + A[idx] + B[idx+1:] cnt += 1 elif B[idx] == C[idx]: A = A[:idx] + B[idx] + A[idx+1:] cnt += 1 else: B = B[:idx] + A[idx] + B[idx+1:] C = C[:idx] + A[idx] + C[idx+1:] cnt += 2 #print(A,B,C) print(cnt)
s896805942
p02255
u554198876
1,000
131,072
Wrong Answer
30
7,684
275
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()] def insertionSort(A, N): 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) insertionSort(A, N)
s927969645
Accepted
40
7,720
303
N = int(input()) A = [int(i) for i in input().split()] def insertionSort(A, N): 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([str(i) for i in A])) insertionSort(A, N)
s949886147
p03416
u157085392
2,000
262,144
Wrong Answer
89
2,940
172
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
a,b = [int(x) for x in input().split()] def ip(n): s = list(str(n)) r = s r.reverse() return r == s ans = 0 for i in range(a,b+1): if ip(i): ans += 1 print(ans)
s239373470
Accepted
114
3,060
175
a,b = [int(x) for x in input().split()] def ip(n): r = list(str(n)) r.reverse() return r == list(str(n)) ans = 0 for i in range(a,b+1): if ip(i): ans += 1 print(ans)
s221209637
p03477
u507116804
2,000
262,144
Wrong Answer
17
3,060
123
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.
a,b,c,d=map(int,input().split()) m=a+b n=c+d if m>n: print("left") elif m==n: print("balanced") else: print("left")
s501259967
Accepted
17
3,060
124
a,b,c,d=map(int,input().split()) m=a+b n=c+d if m>n: print("Left") elif m==n: print("Balanced") else: print("Right")
s424440521
p03556
u146714526
2,000
262,144
Wrong Answer
35
3,060
440
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
def main(): N = int(input()) num = 1 for i in range(1,6): if N >= (10**i)**2 and N < (10**(i+1))**2: for j in range(10**i, 10**(i+1)): if j**2 > 10**9 or j**2 > N: print (num) return else: num = j**2 print (num) if __name__ == "__main__": # global stime # stime = time.clock() main()
s690276980
Accepted
35
2,940
439
def main(): N = int(input()) num = 1 for i in range(6): if N >= (10**i)**2 and N < (10**(i+1))**2: for j in range(10**i, 10**(i+1)): if j**2 > 10**9 or j**2 > N: print (num) return else: num = j**2 print (num) if __name__ == "__main__": # global stime # stime = time.clock() main()
s515190176
p03598
u252828980
2,000
262,144
Wrong Answer
17
2,940
146
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
n = int(input()) k = int(input()) li = list(map(int,input().split())) num = 0 for i in range(n): num += max(abs(li[i]),abs(k-li[i])) print(num)
s586457402
Accepted
17
2,940
147
n = int(input()) k = int(input()) li = list(map(int,input().split())) num = 0 for i in range(n): num += min(abs(li[i]),abs(k-li[i])) print(num*2)
s849141159
p02613
u392441504
2,000
1,048,576
Wrong Answer
149
16,228
269
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 = [] for i in range(N): S.append((input())) ac = str(S.count('AC')) wa = str(S.count('WA')) tle = str(S.count('TLE')) re = str(S.count('TLE')) ans = 'AC x'+' '+ ac + "\n"+'WA x'+' '+ wa + "\n"+'TLE x' +' '+ tle +"\n" + 'RE x'+' '+re print(ans)
s452357511
Accepted
148
16,108
269
N = int(input()) S = [] for i in range(N): S.append((input())) ac = str(S.count('AC')) wa = str(S.count('WA')) tle = str(S.count('TLE')) re = str(S.count('RE')) ans = 'AC x'+' '+ ac + "\n"+'WA x'+' '+ wa + "\n"+'TLE x' +' '+ tle +"\n" + 'RE x'+' '+re print(ans)
s925558995
p02806
u477977638
2,525
1,048,576
Wrong Answer
17
3,060
408
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.
import sys input = sys.stdin.readline # mod=10**9+7 # rstrip().decode('utf-8') # map(int,input().split()) # import numpy as np def main(): n=int(input()) s=[] t=[] for i in range(n): a,b=input().split() s.append(a) t.append(int(b)) x=input() for i in range(n): if x==s[i]: print(sum(t[i+1:])) exit(0) if __name__ == "__main__": main()
s076773368
Accepted
18
3,060
358
import sys # mod=10**9+7 # rstrip().decode('utf-8') # map(int,input().split()) # import numpy as np def main(): n=int(input()) s=[] t=[] for i in range(n): a,b=input().split() s.append(a) t.append(int(b)) x=input() for i in range(n): if x==s[i]: print(sum(t[i+1:])) if __name__ == "__main__": main()
s763965514
p03435
u881116515
2,000
262,144
Wrong Answer
17
3,064
208
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
a = [list(map(int,input().split())) for i in range(3)] if a[0][0]-a[1][0] == a[0][1]-a[1][1] == a[0][2]-a[1][2] and a[1][0]-a[2][0] == a[1][1]-a[2][1] == a[1][2] == a[2][2]: print("Yes") else: print("No")
s181624842
Accepted
17
3,060
206
a = [list(map(int,input().split())) for i in range(3)] if a[0][0]-a[1][0] == a[0][1]-a[1][1] == a[0][2]-a[1][2] and a[1][0]-a[2][0] == a[1][1]-a[2][1] == a[1][2]-a[2][2]: print("Yes") else: print("No")
s400763706
p03386
u226912938
2,000
262,144
Wrong Answer
17
3,060
186
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.
a, b, k = map(int, input().split()) X = [] for i in range(a, min(a+k, b)): X.append(i) for j in range(max(b-k+1, a+1), b+1): X.append(j) X_s = set(X) for k in X_s: print(k)
s354002883
Accepted
17
3,064
220
a, b, k = map(int, input().split()) X = [] for i in range(a, min(a+k, b+1)): X.append(i) for j in range(max(b-k+1, a), b+1): X.append(j) X = sorted(X) X_s = sorted(set(X), key=X.index) for k in X_s: print(k)
s242487742
p03409
u444856278
2,000
262,144
Wrong Answer
21
3,064
619
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
from bisect import bisect N = int(input()) red, blue = [], [] for _ in range(N): red.append(tuple(int(i) for i in input().split())) for _ in range(N): blue.append(tuple(int(i) for i in input().split())) pair = [] red.sort(key=lambda x: x[0]) blue.sort(reverse=True,key=lambda x: x[0]) r = [po[0] for po in red] for point in blue: mxred = bisect(r,point[0]) re = red[:mxred] re.sort(reverse=True, key=lambda x: x[1]) for i in range(len(re)): if re[i][1] < point[1] and re[i] not in pair: pair.append(re[i]) print(re[i],point) break print(len(pair))
s070249329
Accepted
19
3,064
423
N = int(input()) red, blue = [], [] for _ in range(N): red.append(tuple(int(i) for i in input().split())) for _ in range(N): blue.append(tuple(int(i) for i in input().split())) ans = 0 red.sort(reverse=True,key=lambda x: x[0]) blue.sort(key=lambda x: x[1]) for bl in blue: for re in red: if re[0] < bl[0] and re[1] < bl[1]: ans += 1 red.remove(re) break print(ans)
s723518359
p02261
u613534067
1,000
131,072
Wrong Answer
20
5,608
838
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).
def bubble_sort(c, n): x = c[:] for i in range(n): for k in range(n-1, i, -1): if x[k][1] < x[k-1][1]: x[k], x[k-1] = x[k-1], x[k] return x def selection_sort(c, n): x = c[:] for i in range(n): mink = i for k in range(i, n): if x[k][1] < x[mink][1]: mink = k x[i], x[mink] = x[mink], x[i] return x n = int(input()) c = [] for i in list(input().split()): c.append((i[0], int(i[1]))) b = bubble_sort(c, n) print(" ".join(map(str, [i[0]+str(i[1]) for i in b]))) stable = True print("Stable") s = selection_sort(c, n) print(" ".join(map(str, [i[0]+str(i[1]) for i in s]))) if b != s: stable = False if stable: print("Stable") else: print("Not Stable")
s584045275
Accepted
30
5,616
838
def bubble_sort(c, n): x = c[:] for i in range(n): for k in range(n-1, i, -1): if x[k][1] < x[k-1][1]: x[k], x[k-1] = x[k-1], x[k] return x def selection_sort(c, n): x = c[:] for i in range(n): mink = i for k in range(i, n): if x[k][1] < x[mink][1]: mink = k x[i], x[mink] = x[mink], x[i] return x n = int(input()) c = [] for i in list(input().split()): c.append((i[0], int(i[1]))) b = bubble_sort(c, n) print(" ".join(map(str, [i[0]+str(i[1]) for i in b]))) stable = True print("Stable") s = selection_sort(c, n) print(" ".join(map(str, [i[0]+str(i[1]) for i in s]))) if b != s: stable = False if stable: print("Stable") else: print("Not stable")
s802692344
p02600
u499061721
2,000
1,048,576
Wrong Answer
26
8,992
194
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
X = int(input()) up = 599 down = 400 i=8 while(X <= 400 and X >= 1999): if(X <= up and X >= down): print(i) break else: up += 200 down += 200 i-=1
s228003999
Accepted
31
9,124
178
X = int(input()) up = 599 down = 400 i=8 while(i>=1): if(X <= up and X >= down): print(i) break else: up += 200 down += 200 i -= 1
s975288222
p03760
u598229387
2,000
262,144
Wrong Answer
17
2,940
66
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
o = input() e = input() for i,j in zip(o,e): print(i+j,end='')
s475650832
Accepted
17
3,064
292
o=list(input()) e=list(input()) ans=[] if len(o)==len(e): for i in range(len(o)): ans.append(o[i]) ans.append(e[i]) print(''.join(ans)) else: for i in range(len(e)): ans.append(o[i]) ans.append(e[i]) ans.append(o[-1]) print(''.join(ans))
s659451240
p03141
u102960641
2,000
1,048,576
Wrong Answer
639
33,616
245
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end". Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
n = int(input()) a = [] for i in range(n): a1,a2 = map(int, input().split()) a.append([a1+a2,a1,a2]) a.sort() a.reverse() ans = 0 print(a) for i in range(n): if i % 2 == 0: ans += a[i//2][1] else: ans -= a[i//2 + 1][2] print(ans)
s526694071
Accepted
574
23,260
226
n = int(input()) a = [] for i in range(n): a1,a2 = map(int, input().split()) a.append([a1+a2,a1,a2]) a.sort() a.reverse() ans = 0 for i in range(n): if i % 2 == 0: ans += a[i][1] else: ans -= a[i][2] print(ans)
s559295110
p02612
u981884699
2,000
1,048,576
Wrong Answer
29
9,136
41
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) v = (N % 1000) print(v)
s287186826
Accepted
29
9,148
71
N = int(input()) v = (N % 1000) if v != 0: v = 1000 - v print(v)
s116135496
p03635
u272377260
2,000
262,144
Wrong Answer
20
2,940
45
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
n, m = map(int, input().split()) print(n * m)
s422734990
Accepted
17
2,940
54
n, m = map(int, input().split()) print((n-1) * (m -1))
s131822703
p03352
u222634810
2,000
1,048,576
Wrong Answer
20
2,940
89
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
X = int(input()) for i in range(32): if X < i * i: print((i-1) * (i-1))
s729256123
Accepted
17
2,940
210
import sys X = int(input()) array = [] for i in range(2, 11): for j in range(1, 33): if pow(j, i) > X: break else: array.append(pow(j, i)) print(max(array))
s680888870
p02615
u525589885
2,000
1,048,576
Wrong Answer
112
31,608
183
Quickly after finishing the tutorial of the online game _ATChat_ , you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the **friendliness** of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets **comfort** equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?
n = int(input()) c = list(map(int, input().split())) c.sort(reverse = True) a = 0 for i in range(int(n//2+1)): a += c[i] if n%2==0: print(a*2-c[0]) else: print(a*2-c[0]-c[n//2])
s250872841
Accepted
123
31,584
185
n = int(input()) c = list(map(int, input().split())) c.sort(reverse = True) a = 0 for i in range(int((n+1)//2)): a += c[i] if n%2==0: print(a*2-c[0]) else: print(a*2-c[0]-c[n//2])
s666061030
p02854
u985408358
2,000
1,048,576
Wrong Answer
208
26,220
319
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
n = int(input()) a= [int(x) for x in input().split(" ",n-1)] print(a) s = 0 for x in range(n): s += a[x-1] r = 0 l = 0 x = 0 while r < s/2: r += a[x] x += 1 y = 1 while l < s/2: l += a[n-y] y += 1 if r == s//2: print(0) else: k = min(r,l) v = k - s/2 m = v // 0.5 print(int(m))
s026476837
Accepted
185
26,220
310
n = int(input()) a= [int(x) for x in input().split(" ",n-1)] s = 0 for x in range(n): s += a[x-1] r = 0 l = 0 x = 0 while r < s/2: r += a[x] x += 1 y = 1 while l < s/2: l += a[n-y] y += 1 if r == s//2: print(0) else: k = min(r,l) v = k - s/2 m = v // 0.5 print(int(m))
s229818205
p03447
u474925961
2,000
262,144
Wrong Answer
22
3,316
134
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
import sys if sys.platform =='ios': sys.stdin=open('input_file.txt') x,a,b=[int(input()) for i in range(3)] print((x-a)//b)
s561546314
Accepted
17
2,940
144
import sys if sys.platform =='ios': sys.stdin=open('input_file.txt') x,a,b=[int(input()) for i in range(3)] print((x-a)-((x-a)//b)*b)
s358914980
p02388
u433250944
1,000
131,072
Wrong Answer
20
5,576
70
Write a program which calculates the cube of a given integer x.
x = input() n = (int(x)**3) print("n =" ,n)
s936890257
Accepted
20
5,576
63
x = input() n = (int(x)**3) print(n)
s629537484
p02613
u630237503
2,000
1,048,576
Wrong Answer
142
9,208
450
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.
def main(): N = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(0, N): res = input() if (res == 'AC'): ac += 1 if (res == 'WA'): wa += 1 if (res == 'TLE'): tle += 1 if (res == 'RE'): re += 1 print(f"AC x {ac}") print(f"WA x {wa}") print(f"TEL x {tle}") print(f"RE x {re}") if __name__ == '__main__': main()
s997105153
Accepted
146
9,212
450
def main(): N = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(0, N): res = input() if (res == 'AC'): ac += 1 if (res == 'WA'): wa += 1 if (res == 'TLE'): tle += 1 if (res == 'RE'): re += 1 print(f"AC x {ac}") print(f"WA x {wa}") print(f"TLE x {tle}") print(f"RE x {re}") if __name__ == '__main__': main()
s916230863
p03130
u658915215
2,000
1,048,576
Wrong Answer
27
8,944
177
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
l = [] for i in range(3): l += list(map(int, input().split())) print(l) for i in range(4): if l.count(i) == 3: print('NO') break else: print('YES')
s917825209
Accepted
28
9,164
172
l = [] for _ in range(3): l += list(map(int, input().split())) for i in range(4): if l.count(i + 1) == 3: print('NO') break else: print('YES')
s956346016
p03637
u466105944
2,000
262,144
Wrong Answer
74
14,252
348
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
n = int(input()) a_list = list(map(int,input().split())) zero = 0 one = 0 two = 0 for a in a_list: remain = a%2 if remain == 0: if a/2 >= 2: two += 1 elif a/2 == 1: one += 1 else: zero += 1 if one: zero += 1 if zero <= two+1 or zero <= two: print('yes') else: print('no')
s502222172
Accepted
53
15,020
217
n = int(input()) a_list = list(map(int,input().split())) divs = [a%4 for a in a_list] mp_of_four = divs.count(0) mp_of_two = divs.count(2) if mp_of_four+mp_of_two//2 >= n//2: print('Yes') else: print('No')
s684686837
p04030
u064408584
2,000
262,144
Wrong Answer
17
2,940
109
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
s=input() a='' for i in s: if i=='B': if len(a)!=0:a=a[:-1] else:a+=i print(a,i) print(a)
s085496371
Accepted
17
2,940
90
a='' for i in input(): if i=='B': if len(a)!=0:a=a[:-1] else:a+=i print(a)
s027460958
p03142
u368796742
2,000
1,048,576
Wrong Answer
359
28,352
510
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of the vertices, except the root, has a directed edge coming from its parent. Note that the root may not be Vertex 1. Takahashi has added M new directed edges to this graph. Each of these M edges, u \rightarrow v, extends from some vertex u to its descendant v. You are given the directed graph with N vertices and N-1+M edges after Takahashi added edges. More specifically, you are given N-1+M pairs of integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the i-th edge extends from Vertex A_i to Vertex B_i. Restore the original rooted tree.
from collections import deque n,m = map(int,input().split()) e = [[] for i in range(n)] d = [1]*n s = [0]*n for i in range(n+m-1): a,b = map(int,input().split()) e[a-1].append(b-1) s[b-1] += 1 if 0 in s: ans = [-1]*n p = s.index(0) ans[p] = 0 q = deque([]) q.append(p) while q: now = q.popleft() for nex in e[now]: if ans[nex] == -1: ans[nex] = now+1 q.append(nex) for i in ans: print(i) exit()
s401514495
Accepted
487
46,940
701
from collections import deque n,m = map(int,input().split()) e = [[] for i in range(n)] d = [1]*n s = [0]*n t = [[] for i in range(n)] for i in range(n+m-1): a,b = map(int,input().split()) a -= 1 b -= 1 e[a].append(b) t[b].append(a) s[b] += 1 ans = [-1]*n p = s.index(0) ans[p] = 0 q = deque([]) q.append(p) s = set() while q: now = q.popleft() s.add(now) for nex in e[now]: if ans[nex] == -1: check = True for j in t[nex]: if j not in s: check = False break if check: ans[nex] = now+1 q.append(nex) for i in ans: print(i)
s924510497
p02388
u140168530
1,000
131,072
Wrong Answer
20
7,392
26
Write a program which calculates the cube of a given integer x.
def f(x): return x**3
s544098268
Accepted
40
7,688
132
def cube(x): return x**3 def main(): x = int(input()) ans = cube(x) print(ans) if __name__=='__main__': main()
s231430661
p00016
u436634575
1,000
131,072
Wrong Answer
30
6,848
218
When a boy was cleaning up after his grand father passing, he found an old paper: In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper. For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town. You can assume that d ≤ 100 and -180 ≤ t ≤ 180\.
from math import radians from cmath import rect z = 0 deg = 90 while True: r, d = map(int, input().split(',')) if r == d == 0: break z += rect(r, radians(deg)) deg += d print(-int(z.real), int(z.imag))
s725657823
Accepted
30
6,864
225
from math import radians from cmath import rect z = 0 deg = 90 while True: r, d = map(float, input().split(',')) if r == d == 0: break z += rect(r, radians(deg)) deg -= d print(int(z.real)) print(int(z.imag))
s777794310
p03910
u153094838
2,000
262,144
Wrong Answer
23
3,572
335
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
# -*- coding: utf-8 -*- """ Created on Fri Jun 12 20:20:11 2020 @author: NEC-PCuser """ N = int(input()) i = 1 li = [] while (N >= (i * (i + 1)) // 2): li.append(i) i += 1 value = (i - 1) * i // 2 print(value) index = len(li) - 1 for i in range(value, N): li[index] += 1 index -= 1 for i in li: print(i)
s773721143
Accepted
22
3,572
322
# -*- coding: utf-8 -*- """ Created on Fri Jun 12 20:20:11 2020 @author: NEC-PCuser """ N = int(input()) i = 1 li = [] while (N >= (i * (i + 1)) // 2): li.append(i) i += 1 value = (i - 1) * i // 2 index = len(li) - 1 for i in range(value, N): li[index] += 1 index -= 1 for i in li: print(i)
s104696765
p03729
u181709987
2,000
262,144
Wrong Answer
17
2,940
137
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`.
A,B,C = input().split() X = False if A[-1]==B[0]: if B[-1] == C[0]: X = True if X: print('Yes') else: print('No')
s134995447
Accepted
17
2,940
137
A,B,C = input().split() X = False if A[-1]==B[0]: if B[-1] == C[0]: X = True if X: print('YES') else: print('NO')
s877209381
p03659
u163320134
2,000
262,144
Wrong Answer
255
24,824
203
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
n=int(input()) arr=list(map(int,input().split())) for i in range(n-1): arr[i+1]+=arr[i] print(arr) ans=10**18 for i in range(n-1): x=arr[i] y=arr[n-1]-x tmp=abs(x-y) ans=min(ans,tmp) print(ans)
s108587995
Accepted
236
24,824
193
n=int(input()) arr=list(map(int,input().split())) for i in range(n-1): arr[i+1]+=arr[i] ans=10**18 for i in range(n-1): x=arr[i] y=arr[n-1]-x tmp=abs(x-y) ans=min(ans,tmp) print(ans)
s741854044
p04029
u050034744
2,000
262,144
Wrong Answer
17
2,940
68
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n=int(input()) sum=0 for i in range(n): sum+=(n+1)**2 print(sum)
s311645905
Accepted
17
2,940
65
n=int(input()) sum=0 for i in range(n): sum+=(i+1) print(sum)
s248028126
p02843
u088553842
2,000
1,048,576
Wrong Answer
38
10,252
242
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
n = int(input()) if n <= 99: print('No') exit() dp = [True] + [False] * n for i in range(100, n + 1): if dp[i - 100] or dp[i - 101] or dp[i - 102] or dp[i - 103] or dp[i - 104] or dp[i - 105]: dp[i] = True print(['No','Yes'][dp[n]])
s848906009
Accepted
44
10,112
273
n = int(input()) if n <= 99: print(0) exit() if 100 <= n <= 105: print(1) exit() dp = [True] + [False] * n for i in range(100, n + 1): if dp[i - 100] or dp[i - 101] or dp[i - 102] or dp[i - 103] or dp[i - 104] or dp[i - 105]: dp[i] = True print([0, 1][dp[n]])
s558453565
p02401
u276050131
1,000
131,072
Wrong Answer
30
7,600
273
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: a,op,b = input().split() a = int(a) b = int(b) if (op == "+"): print(a + b) elif(op == "-"): print(a + b) elif(op == "/"): print(a // b) elif(op == "*"): print(a + b) elif(op == "?"): break
s295592649
Accepted
20
7,696
273
while True: a,op,b = input().split() a = int(a) b = int(b) if (op == "+"): print(a + b) elif(op == "-"): print(a - b) elif(op == "/"): print(a // b) elif(op == "*"): print(a * b) elif(op == "?"): break
s308488582
p03478
u104442591
2,000
262,144
Time Limit Exceeded
2,104
2,940
259
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()) def divide(num): rest = num sum = 0 while rest > 0: num /= 10 rest %= 10 sum += rest return sum for i in range(n): temp = divide(i+1) ans = 0 if temp>= a and temp <= b: ans += temp print(ans)
s802264458
Accepted
26
3,060
234
n, a, b = map(int, input().split()) def divide(num): sum = 0 while num > 0: sum += num % 10 num //= 10 return sum ans = 0 for i in range(n): temp = divide(i+1) if temp>= a and temp <= b: ans += (i+1) print(ans)
s484706927
p03611
u410717334
2,000
262,144
Wrong Answer
164
24,176
232
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
from collections import defaultdict N=int(input()) a=list(map(int,input().split())) d=defaultdict(int) for item in a: d[item-1]+=1 d[item]+=1 d[item+1]+=1 b=sorted(d.items(),key=lambda x:x[1],reverse=True) print(b[0][0])
s185168476
Accepted
163
24,176
232
from collections import defaultdict N=int(input()) a=list(map(int,input().split())) d=defaultdict(int) for item in a: d[item-1]+=1 d[item]+=1 d[item+1]+=1 b=sorted(d.items(),key=lambda x:x[1],reverse=True) print(b[0][1])
s141382910
p02678
u111473084
2,000
1,048,576
Wrong Answer
1,288
33,744
412
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()) graph = [[] for _ in range(n+1)] for i in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) # bfs milestone = [0] * (n+1) q = [] q.append(1) while len(q) != 0: for i in graph[q[0]]: if milestone[i] == 0: milestone[i] = q[0] q.append(i) q.pop(0) for i in range(2, n+1): print(milestone[i])
s623127703
Accepted
1,303
33,808
425
n, m = map(int, input().split()) graph = [[] for _ in range(n+1)] for i in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) # bfs milestone = [0] * (n+1) q = [] q.append(1) while len(q) != 0: for i in graph[q[0]]: if milestone[i] == 0: milestone[i] = q[0] q.append(i) q.pop(0) print("Yes") for i in range(2, n+1): print(milestone[i])
s339363453
p03407
u977642052
2,000
262,144
Wrong Answer
19
2,940
202
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
def main(A: int, B: int, C: int): if A + B <= C: return 'Yes' else: return 'No' if __name__ == "__main__": A, B, C = map(int, input().split(' ')) print(main(A, B, C))
s610916886
Accepted
17
2,940
204
def main(A: int, B: int, C: int): if (A + B) >= C: return 'Yes' else: return 'No' if __name__ == "__main__": A, B, C = map(int, input().split(' ')) print(main(A, B, C))
s552933510
p03796
u823458368
2,000
262,144
Wrong Answer
230
3,980
58
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
import math n = int(input()) math.factorial(n)%(10**9 + 7)
s777959591
Accepted
42
2,940
87
ans=1 n=int(input()) for i in range(1,n+1): ans*=i ans=ans%(10**9+7) print(ans)
s412407708
p02692
u367548378
2,000
1,048,576
Wrong Answer
287
104,476
796
There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
import sys sys.setrecursionlimit(1000000) def F(S,curr,D,res): if len(S)==curr: print("Yes") for c in res: print(c) #print("".join(res)) return True s=S[curr] a=False b=False if D[s[0]]>=1: D[s[0]]-=1 D[s[1]]+=1 res.append(s[0]) a=F(S,curr+1,D,res) res.pop(-1) D[s[0]]+=1 D[s[1]]-=1 else: if D[s[1]]>=1: D[s[1]]-=1 D[s[0]]+=1 res.append(s[1]) b=F(S,curr+1,D,res) res.pop() D[s[1]]+=1 D[s[0]]-=1 return a or b N,A,B,C=map(int,input().strip().split()) D={"A":A,"B":B,"C":C} S=[] res=[] for i in range(N): S.append(input()) if not (F(S,0,D,res)): print("No")
s327443991
Accepted
304
104,388
867
import sys sys.setrecursionlimit(1000000) def F(S,curr,D,res): if D["A"]<0 or D["B"]<0 or D["C"]<0: return False if len(S)==curr: print("Yes") for c in res: print(c) #print("".join(res)) return True s=S[curr] a=False b=False if D[s[0]]>=1: D[s[0]]-=1 D[s[1]]+=1 res.append(s[1]) a=F(S,curr+1,D,res) res.pop(-1) D[s[0]]+=1 D[s[1]]-=1 if a: return a if D[s[1]]>=1: D[s[1]]-=1 D[s[0]]+=1 res.append(s[0]) b=F(S,curr+1,D,res) res.pop() D[s[1]]+=1 D[s[0]]-=1 return a or b N,A,B,C=map(int,input().strip().split()) D={"A":A,"B":B,"C":C} S=[] res=[] for i in range(N): S.append(input()) if not (F(S,0,D,res)): print("No")
s270763842
p03547
u073139376
2,000
262,144
Wrong Answer
17
2,940
90
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`. When X and Y are seen as hexadecimal numbers, which is larger?
X, Y = input().split() if X > Y: print('<') elif X == Y: print('=') else: print('>')
s531224275
Accepted
17
3,064
91
X, Y = input().split() if X > Y: print('>') elif X == Y: print('=') else: print('<')
s154533348
p02390
u193025715
1,000
131,072
Wrong Answer
40
6,724
97
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.
n = int(input()) h = n % 3600 n -= h * 3600 m = n % 60 n -= m print(str(h)+':'+str(m)+':'+str(n))
s229799635
Accepted
30
6,732
122
n = int(input()) h = int(n / 3600) m = int((n-h*3600) / 60) s = n - h * 3600 - m * 60 print(':'.join(map(str, [h,m,s])))
s646139288
p03457
u955907183
2,000
262,144
Wrong Answer
444
27,324
497
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
c = input() data = [] for s in range(0,int(c)): data.append(list(map(int, input().split())) ) nowtime = 0 nowx = 0 nowy = 0 nexttime = 0 nextx = 0 nexty = 0 costtime = 0 diffx = 0 diffy = 0 for s in range(0, len(data)): nexttime = data[s][0] nextx = data[s][1] nexty = data[s][2] costtime = nexttime - nowtime diffx = nextx - nowx diffy = nexty - nowy if ( (costtime < diffx + diffy) or (((costtime - (diffx + diffy)) % 2) == 1 ) ): print("NO") exit() print("YES")
s914548940
Accepted
417
27,400
354
c = input() data = [] for s in range(0,int(c)): data.append(list(map(int, input().split())) ) nexttime = 0 nextx = 0 nexty = 0 for s in range(0, len(data)): nexttime = data[s][0] nextx = data[s][1] nexty = data[s][2] if ( (nexttime < nextx+nexty) or ((((nextx + nexty) ) % 2) != (nexttime % 2) ) ): print("No") exit() print("Yes")
s799794172
p03636
u736479342
2,000
262,144
Wrong Answer
25
9,028
69
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
s = list(input()) print(s) l = len(s)-2 print(s[0] + str(l) + s[-1])
s146857943
Accepted
25
9,032
60
s = list(input()) l = len(s)-2 print(s[0] + str(l) + s[-1])
s368545813
p03400
u474270503
2,000
262,144
Wrong Answer
17
3,060
189
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
N=int(input()) D, X=map(int,input().split()) A=[] for i in range(N): A.append(int(input())) ans=0 for i in range(N): if A[i]<=D: ans+=D//A[i]+1 print(ans) print(ans+X)
s787152906
Accepted
18
3,060
203
N=int(input()) D, X=map(int,input().split()) A=[] for i in range(N): A.append(int(input())) ans=0 for i in range(N): if A[i]<=D: ans+=(D-1)//A[i]+1 else: ans+=1 print(ans+X)
s833023235
p03943
u048956777
2,000
262,144
Wrong Answer
17
2,940
91
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a, b ,c = map(int, input().split()) if(a+b+c % 3 == 0): print('Yes') else: print('No')
s480647777
Accepted
17
2,940
108
a, b ,c = map(int, input().split()) if (a+b==c) or (b+c==a) or (a+c==b): print('Yes') else: print('No')
s328866750
p03971
u077337864
2,000
262,144
Wrong Answer
2,102
4,528
354
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
N, A, B = map(int, input().split()) S = input() passed = [] for i in range(N): if S[i] == 'c': print('No') elif S[i] == 'a': if len(passed) <= A+B: print('Yes') passed.append('a') else: print('No') else: if len(passed) <= A+B and passed.count('b') <= B: print('Yes') passed.append('b') else: print('No')
s656707362
Accepted
107
4,016
343
n, a, b = map(int, input().split()) s = input().strip() sumy = 0 sumf = 0 for _s in s: if _s == 'c': print('No') elif _s == 'a': if sumy < a + b: print('Yes') sumy += 1 else: print('No') else: if sumy < a + b and sumf < b: print('Yes') sumy += 1 sumf += 1 else: print('No')
s215015116
p03814
u047197186
2,000
262,144
Wrong Answer
38
9,360
131
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() end = 0 for i in range(len(s) - 1, -1, -1): if s[i] == 'Z': end = i + 1 break print(s[s.index('A'):end])
s829874876
Accepted
36
9,256
136
s = input() end = 0 for i in range(len(s) - 1, -1, -1): if s[i] == 'Z': end = i + 1 break print(len(s[s.index('A'):end]))
s824004989
p02742
u068944955
2,000
1,048,576
Wrong Answer
18
2,940
173
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
H, W = map(int, input().split()) if H == 1 or W == 1: print(1) exit() if H % 2 == 0 or W % 2 == 0: print(H * W / 2) else: print(H * (W // 2) + H // 2 + 1)
s090191878
Accepted
21
3,064
174
H, W = map(int, input().split()) if H == 1 or W == 1: print(1) exit() if H % 2 == 0 or W % 2 == 0: print(H * W // 2) else: print(H * (W // 2) + H // 2 + 1)
s051563454
p03963
u576434377
2,000
262,144
Wrong Answer
18
2,940
61
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls.
N,K = map(int,input().split()) print(K * ((K - 1) ** N - 1))
s540665628
Accepted
17
2,940
63
N,K = map(int,input().split()) print(K * ((K - 1) ** (N - 1)))
s660051126
p03495
u813450984
2,000
262,144
Wrong Answer
2,104
26,148
390
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
n, k = map(int, input().split()) nums = list(map(int, input().split())) def judge(n, k, nums): original = nums only = set(nums) diff = len(only) - k count = [] ans = 0 if len(only) <= k: return 0 for i in only: count.append([original.count(i), i]) count.sort() print(count) for i in range(diff): ans += count[i][0] return ans print(judge(n, k, nums))
s938724240
Accepted
226
25,644
360
n, k = map(int, input().split()) l = sorted(list(map(int, input().split()))) counts = [] now = l[0] count = 1 for i in range(1, n): if l[i] == now: count += 1 else: counts.append(count) now = l[i] count = 1 if i == n-1: counts.append(count) if len(counts) <= k: print(0) else: counts = sorted(counts) print(sum(counts[:-k]))
s571254286
p03644
u994988729
2,000
262,144
Wrong Answer
18
2,940
155
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
def two(n): count=0 while n%2==0: count+=1 n//=2 return count n=int(input()) ans=0 for i in range(1, n+1): ans=max(ans, two(i)) print(ans)
s699099929
Accepted
28
9,152
88
N = int(input()) x = 1 while True: if x * 2 > N: break x *= 2 print(x)
s916065193
p03861
u884601206
2,000
262,144
Wrong Answer
17
2,940
88
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,x=map(int,input().split()) if a!=0: print(b%x - (a-1)%x) else: print(b%x+1)
s803422912
Accepted
17
2,940
95
a,b,x=map(int,input().split()) if a!=0: print((b//x) - (a-1)//x) else: print((b//x)+1)
s600839913
p03998
u770077083
2,000
262,144
Wrong Answer
17
3,060
268
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.
cards = [list(input().replace("a", "0").replace("b","1").replace("c","2")) for _ in range(3)] next = 0 while len(cards[0]) * len(cards[1]) * len(cards[2]) != 0: next = int(cards[next].pop(0)) print("A" if len(cards[0]) == 0 else ("B" if len(cards[1]) == 0 else "C"))
s299614856
Accepted
17
3,060
247
cards = [list(input().replace("a", "0").replace("b","1").replace("c","2")) for _ in range(3)] next = 0 while True: if len(cards[next]) == 0: print("A" if next == 0 else ("B" if next == 1 else "C")) exit() next = int(cards[next].pop(0))
s203433256
p03455
u262481526
2,000
262,144
Wrong Answer
17
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('Yes') else: print('No')
s586640354
Accepted
17
2,940
88
a, b = map(int, input().split()) if a * b % 2 == 0: print('Even') else: print('Odd')
s287924777
p02865
u586577600
2,000
1,048,576
Wrong Answer
17
2,940
28
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n = int(input()) print(n//2)
s113196881
Accepted
17
2,940
67
n = int(input()) if n%2==0: print(n//2-1) else: print(n//2)
s668123064
p02612
u697658632
2,000
1,048,576
Wrong Answer
30
9,144
37
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
print((10000 - int(input())) // 1000)
s001135616
Accepted
27
9,140
36
print((10000 - int(input())) % 1000)
s627301498
p03408
u644907318
2,000
262,144
Wrong Answer
17
3,064
251
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
N = int(input()) S = [input().strip() for _ in range(N)] M = int(input()) T = [input().strip() for _ in range(M)] cntmax = 0 for s in S: cnt = 0 for t in T: if t==s: cnt += 1 if cnt==0: cntmax += 1 print(cntmax)
s326072864
Accepted
17
3,064
254
N = int(input()) S = [input().strip() for _ in range(N)] M = int(input()) T = [input().strip() for _ in range(M)] cntmax = 0 for s in S: cnt = S.count(s) for t in T: if t==s: cnt -= 1 cntmax = max(cntmax,cnt) print(cntmax)
s565453527
p03574
u466105944
2,000
262,144
Wrong Answer
26
3,188
684
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
h,w = map(int,input().split()) board = [input() for _ in range(h)] dx = [-1,-1,-1, 0,0, 1,1,1] dy = [-1, 0, 1,-1,1,-1,0,1] ans_board = [[0 for _ in range(w)] for _ in range(h)] for x in range(h): cnt = 0 for y in range(w): if board[x][y] == '#': ans_board[x][y] = '#' else: for d in range(len(dx)): n_x = x+dx[d] n_y = y+dy[d] if 0 < n_x <= h or 0 < n_y <= w: continue elif board[n_x][n_y] == '#': cnt += 1 ans_board[x][y] = str(cnt) for ans in ans_board: print('' .join(ans))
s369783371
Accepted
31
3,188
630
h,w = map(int,input().split()) board = [input() for _ in range(h)] dx = [-1,-1,-1, 0,0, 1,1,1] dy = [-1, 0, 1,-1,1,-1,0,1] ans_board = [[0 for _ in range(w)] for _ in range(h)] for x in range(h): for y in range(w): cnt = 0 if board[x][y] == '#': ans_board[x][y] = '#' else: for d in range(len(dx)): n_x = x+dx[d] n_y = y+dy[d] if 0 <= n_x < h and 0 <= n_y < w: if board[n_x][n_y] == '#': cnt += 1 ans_board[x][y] = str(cnt) for ans in ans_board: print('' .join(ans))
s857210231
p03860
u241190800
2,000
262,144
Wrong Answer
17
2,940
72
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
data = [i for i in input().split(" ")] print('A#{}C'.format(data[1][0]))
s121842541
Accepted
18
2,940
68
data = [i for i in input().split()] print('A{}C'.format(data[1][0]))
s761618603
p03448
u500207661
2,000
262,144
Wrong Answer
47
3,060
333
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().strip()) b = int(input().strip()) c = int(input().strip()) x = int(input().strip()) count = 0 for a_n in range(a): for b_n in range(b): for c_n in range(c): if x - (a_n * 500) - (b_n * 100) - (c_n * 50) is 0: count += 1 else: continue print(count)
s394615788
Accepted
51
2,940
424
a = int(input().strip()) b = int(input().strip()) c = int(input().strip()) x = int(input().strip()) if a * 500 + b *100 + c * 50 < x: print(0) else: count = 0 for a_n in range(a+1): for b_n in range(b+1): for c_n in range(c+1): if (a_n * 500) + (b_n * 100) + (c_n * 50) == x: count += 1 else: continue print(count)
s918611376
p03720
u013408661
2,000
262,144
Wrong Answer
18
2,940
201
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n,m=map(int,input().split()) city=[[] for i in range(n+1)] for i in range(m): a,b=map(int,input().split()) city[a].append(b) city[b].append(a) for i in range(1,n+1): print(len(set(city[i]))-1)
s686245637
Accepted
17
3,060
193
n,m=map(int,input().split()) city=[[] for i in range(n+1)] for i in range(m): a,b=map(int,input().split()) city[a].append(b) city[b].append(a) for i in range(1,n+1): print(len(city[i]))
s328048387
p03796
u296150111
2,000
262,144
Wrong Answer
42
3,064
75
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
n=int(input()) ans=1 for i in range(n): ans*=i ans=ans%10**9+7 print(ans)
s437640870
Accepted
41
2,940
81
n=int(input()) ans=1 for i in range(1,n+1): ans*=i ans=ans%(10**9+7) print(ans)
s863069925
p03720
u827202523
2,000
262,144
Wrong Answer
17
3,060
234
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n,m = list(map(int, input().split())) cities = [0 for i in range(n)] for i in range(m): bridges = list(map(int, input().split())) cities = [i+1 if i+1 in bridges else i for i in cities] print("\n".join(list(map(str, cities))))
s206919010
Accepted
17
3,060
247
n,m = list(map(int, input().split())) cities = [0 for i in range(n)] for i in range(m): bridges = list(map(int, input().split())) cities = [x+1 if i+1 in bridges else x for i,x in enumerate(cities)] print("\n".join(list(map(str, cities))))
s438589915
p03359
u287880059
2,000
262,144
Wrong Answer
17
2,940
55
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a,b = map(int,input().split()) if a>b: a -1 else: a
s650427997
Accepted
17
2,940
56
a, b = map(int,input().split()) print(a-1 if a>b else a)
s583064697
p03433
u728307690
2,000
262,144
Wrong Answer
27
9,124
95
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input()) a = int(input()) r = n % 500 if a >= r: print("YES") else: print("NO")
s110316273
Accepted
30
9,168
94
n = int(input()) a = int(input()) r = n % 500 if a < r: print('No') else: print('Yes')
s914474042
p02659
u921352252
2,000
1,048,576
Wrong Answer
24
9,024
50
Compute A \times B, truncate its fractional part, and print the result as an integer.
x,y=map(float,input().split()) print(round(x*y))
s172118393
Accepted
22
9,032
80
x,y=map(float,input().split()) x=int(x) y1=int(round(y*100)) print((x*y1//100))
s437256967
p03555
u502731482
2,000
262,144
Wrong Answer
18
2,940
69
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.
s = input() t = input() s = s[::-1] print("Yes" if s == t else "No")
s632067506
Accepted
17
2,940
69
s = input() t = input() s = s[::-1] print("YES" if s == t else "NO")
s965561174
p02394
u791170614
1,000
131,072
Wrong Answer
20
7,556
237
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
W, H, x, y, r = map(int, input().split()) def YesOrNo(W, H , x, y, r): Xr = x + r Xl = x - r Yu = y + r Yd = y - r if (W >= Xr and H >= Yu and 0 >= Xl and 0 >= Yd): return "Yes" else: return "No" print(YesOrNo(W, H, x, y, r))
s081168635
Accepted
20
7,676
237
W, H, x, y, r = map(int, input().split()) def YesOrNo(W, H , x, y, r): Xr = x + r Xl = x - r Yu = y + r Yd = y - r if (W >= Xr and H >= Yu and 0 <= Xl and 0 <= Yd): return "Yes" else: return "No" print(YesOrNo(W, H, x, y, r))
s882041417
p03545
u689322583
2,000
262,144
Wrong Answer
20
3,316
806
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
#coding: utf-8 S = str(input()) A = int(S[0]) B = int(S[1]) C = int(S[2]) D = int(S[3]) shiki = '' for i in range(2): for j in range(2): for k in range(2): B = B * (-1) ** i C = C * (-1) ** j D = D * (-1) ** k if(A + B + C + D == 7): shiki += str(A) if(B<0): shiki += '-' + str(B) else: shiki += '+' + str(B) if(C<0): shiki += '-' + str(C) else: shiki += '+' + str(C) if(D<0): shiki += '-' + str(D) else: shiki += '+' + str(D) print(shiki,end='') break break break
s095828117
Accepted
17
3,064
898
#coding: utf-8 S = str(input()) A = int(S[0]) B = int(S[1]) C = int(S[2]) D = int(S[3]) for i in range(2): for j in range(2): for k in range(2): A = int(S[0]) B = int(S[1]) C = int(S[2]) D = int(S[3]) B *= (-1) ** i C *= (-1) ** j D *= (-1) ** k if(A + B + C + D == 7): shiki = '' shiki += str(A) if(B<0): shiki += str(B) else: shiki += '+' + str(B) if(C<0): shiki += str(C) else: shiki += '+' + str(C) if(D<0): shiki += str(D) else: shiki += '+' + str(D) shiki += '=7' print(shiki) exit()
s755150058
p02260
u370086573
1,000
131,072
Wrong Answer
20
7,656
354
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.
def selectionSort(n, A): cnt =0 for i in range(n): minj = i for j in range(i,n): if A[minj] > A[j]: minj = j A[i],A[minj] = A[minj],A[i] cnt += 1 print(*A) print(cnt) if __name__ == '__main__': n = int(input()) A = list(map(int, input().split())) selectionSort(n,A)
s626922865
Accepted
20
7,736
384
def selectionSort(n, A): cnt =0 for i in range(n): minj = i for j in range(i,n): if A[minj] > A[j]: minj = j if i != minj: A[i],A[minj] = A[minj],A[i] cnt += 1 print(*A) print(cnt) if __name__ == '__main__': n = int(input()) A = list(map(int, input().split())) selectionSort(n,A)
s562072067
p03067
u453526259
2,000
1,048,576
Wrong Answer
20
3,060
82
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a,b,c = map(int,input().split()) if a >= c >= b: print("Yes") else: print("No")
s600462655
Accepted
17
2,940
117
a,b,c = map(int,input().split()) if a >= c >= b: print("Yes") elif a <= c <= b: print("Yes") else: print("No")
s865378247
p03024
u209619667
2,000
1,048,576
Wrong Answer
17
2,940
130
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
A = input() count = 0 for i in A: if i == 'x': count += 1 b = len(A) - count if 15-b > 7: print('Yes') else: print('No')
s030956808
Accepted
17
2,940
132
A = input() count = 0 for i in A: if i == 'o': count += 1 b = len(A) - count if 15 - b > 7: print('YES') else: print('NO')
s322469638
p03501
u672316981
2,000
262,144
Wrong Answer
27
9,056
51
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
n, a, b = map(int, input().split()) print(n * a, b)
s218421547
Accepted
26
9,160
56
n, a, b = map(int, input().split()) print(min(n * a, b))
s969109098
p02646
u833492079
2,000
1,048,576
Wrong Answer
23
9,188
194
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a,v = map(int, input().split()) b,w = map(int, input().split()) t = int(input()) ans = "No" if v <= w: print(ans) exit() x = abs(v-w) y = abs(a-b) if y <= x*t: ans = "Yes" print(ans)
s034855645
Accepted
23
9,128
401
#------------------------------------------------------------------- import sys def p(*_a): #return _s=" ".join(map(str,_a)) #print(_s) sys.stderr.write(_s+"\n") #------------------------------------------------------------------- a,v = map(int, input().split()) b,w = map(int, input().split()) t = int(input()) ans = "NO" x = v-w y = abs(a-b) p(x,y) if y <= x*t: ans = "YES" print(ans)
s989048110
p03090
u352623442
2,000
1,048,576
Wrong Answer
26
3,740
374
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
n = int(input()) if n%2 == 0: su = n+1 print((n*(n-1)//2)-n//2) for i in range(1,n+1): for k in range(1,n+1): if i+k != su and i < k: print(i,k) if n%2 == 1: su = n+1 print((n*(n-1)//2)-(n-1)//2) for i in range(1,n+1): for k in range(1,n+1): if i+k != su and i < k: print(i,k)
s521307604
Accepted
24
3,612
372
n = int(input()) if n%2 == 0: su = n+1 print((n*(n-1)//2)-n//2) for i in range(1,n+1): for k in range(1,n+1): if i+k != su and i < k: print(i,k) if n%2 == 1: su = n print((n*(n-1)//2)-(n-1)//2) for i in range(1,n+1): for k in range(1,n+1): if i+k != su and i < k: print(i,k)
s488946517
p02690
u290886932
2,000
1,048,576
Time Limit Exceeded
2,205
9,004
367
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
X = int(input()) def modpow(a, n, mod): ret = 1 while n > 0: if n % 2 == 1: ret = ret * a % mod a *= a a = a % mod return ret i = 0 L = list() while True: num = modpow(i,5,X) if num in L: j = L.index(num) ret = '{} {}'.format(i,j) print(ret) break else: L.append(num)
s992276574
Accepted
24
9,208
453
X = int(input()) L = list() i = 0 while True: if i ** 5 > 10 ** 11: break L.append(i ** 5) i += 1 flag = False ret = '' for i in range(len(L)): if flag: break for j in range(i+1, len(L)): if L[j] - L[i] == X : ret ='{} {}'.format(j,i) flag = True break if L[j] + L[i] == X : ret ='{} {}'.format(j,-i) flag = True break print(ret)
s324853508
p02601
u781543416
2,000
1,048,576
Wrong Answer
28
9,120
441
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
abc=list(map(int, input().split())) k=int(input()) a=abc[0] b=abc[1] c=abc[2] num=0 if(a < b): if(b < c): print("Yes") else: while num<k: c=2*c num=num+1 if(b<c): print("Yes") break print("No") else: while num<k: b=2*b num=num+1 if(a<b): while num<k: c=2*c num=num+1 if(b<c): print("Yes") break print("No") print("No")
s492835711
Accepted
30
9,060
492
abc=list(map(int, input().split())) k=int(input()) a=abc[0] b=abc[1] c=abc[2] num=0 if(a < b): if(b < c): print("Yes") else: while num<k: c=2*c num=num+1 if(b<c): print("Yes") break if(b>=c): print("No") else: while num<k: b=2*b num=num+1 if(a<b): break if(a<b): while num<k: c=2*c num=num+1 if(b<c): print("Yes") break if(b>=c): print("No") else: print("No")
s028956156
p03679
u368796742
2,000
262,144
Wrong Answer
18
3,060
126
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b = map(int,input().split()) if x+a >= b: print("delicious") elif x+a+1 == b: print("safe") else: print("dangerous")
s710038901
Accepted
19
2,940
123
x,a,b = map(int,input().split()) if a >= b: print("delicious") elif x+a >= b: print("safe") else: print("dangerous")
s529712959
p03386
u614314290
2,000
262,144
Wrong Answer
2,238
4,084
99
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.
A, B, K = map(int, input().split()) L = [x for x in range(A, B + 1)] print(*set((L[:K] + L[-K:])))
s757865420
Accepted
17
3,060
107
A, B, K = map(int, input().split()) L = range(A, B + 1) print(*sorted(set(L[:K]) | set(L[-K:])), sep="\n")
s864090133
p03380
u672220554
2,000
262,144
Wrong Answer
144
15,712
320
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
n =int(input()) a = list(map(int,input().split())) seta = sorted(list(set(a))) resn = seta[-1] resr = seta[0] for sa in seta: sabun = abs(resn / 2 - sa) if sabun == 0 or sabun == 0.5: resr == sa break elif sabun < abs(resn / 2 - resr): resr = sa print(str(resn) + " " + str(resr))
s131109641
Accepted
146
15,712
319
n =int(input()) a = list(map(int,input().split())) seta = sorted(list(set(a))) resn = seta[-1] resr = seta[0] for sa in seta: sabun = abs(resn / 2 - sa) if sabun == 0 or sabun == 0.5: resr = sa break elif sabun < abs(resn / 2 - resr): resr = sa print(str(resn) + " " + str(resr))
s073022871
p02389
u498041957
1,000
131,072
Wrong Answer
40
7,416
30
Write a program which calculates the area and perimeter of a given rectangle.
ab = input().split() print(ab)
s222769708
Accepted
20
7,672
66
a, b = [int(i) for i in input().split()] print(a * b, (a + b) * 2)
s280821018
p03827
u762420987
2,000
262,144
Wrong Answer
17
2,940
121
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
N = int(input()) S = input() num = 0 for s in S: if s == "I": num += 1 else: num -= 1 print(num)
s355641221
Accepted
17
2,940
169
N = int(input()) S = input() max_num = 0 num = 0 for s in S: if s == "I": num += 1 else: num -= 1 max_num = max(max_num, num) print(max_num)
s513530873
p03131
u221345507
2,000
1,048,576
Wrong Answer
18
3,064
324
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
K, A, B =map(int,input().split()) import sys should_actAB = (B-A) if should_actAB<=2: print(K+1) sys.exit() else: ans_cookie=1 K_=K-(A-1) print(K_) ans_cookie+=(A-1) print(ans_cookie) if K_%2==0: ans_cookie+=should_actAB*(K_)//2 else: ans_cookie+=should_actAB*(K_-1)//2+1
s231928131
Accepted
18
3,060
307
K, A, B =map(int,input().split()) import sys should_actAB = (B-A) if should_actAB<=2: print(K+1) sys.exit() else: ans_cookie=1 K_=K-(A-1) ans_cookie+=(A-1) if K_%2==0: ans_cookie+=should_actAB*(K_)//2 else: ans_cookie+=should_actAB*(K_-1)//2+1 print(ans_cookie)
s791965939
p03408
u926678805
2,000
262,144
Wrong Answer
18
3,060
259
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
dic={} for i in range(int(input())): s=input() if s in dic: dic[s]+=1 else: dic[s]=1 for i in range(int(input())): s=input() if s in dic: dic[s]-=1 else: dic[s]=-1 print(min(sorted(dic.values())[-1],0))
s118767799
Accepted
18
3,064
284
import sys sys.setrecursionlimit(100000) dic={} for i in range(int(input())): s=input() try: dic[s]+=1 except: dic[s]=1 for i in range(int(input())): s=input() try: dic[s]-=1 except: dic[s]=-1 print(max(list(dic.values())+[0]))
s449048933
p02315
u887884261
1,000
131,072
Wrong Answer
20
5,616
647
You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n, max_w = [int(i) for i in input().split()]#print(n, max_w) w = [] v = [] for j in range(n): weight,value=[int(i) for i in input().split()] w.append(weight) v.append(value) dp = [[0 for i in range(max_w+1)] for j in range(n+1)] for i in range(n): for cw in range(max_w+1): if cw >= w[i]: if cw == 8: print(i+1,cw,cw-w[i],i) print(dp[i+1][cw]) print(dp[i][cw-w[i]]) print(dp[i][cw]) dp[i+1][cw] = max(dp[i][cw-w[i]]+v[i], dp[i][cw]) else: dp[i+1][cw] = dp[i][cw]
s430034555
Accepted
940
42,268
496
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n, max_w = [int(i) for i in input().split()]#print(n, max_w) v = [] w = [] for j in range(n): value,weight=[int(i) for i in input().split()] v.append(value) w.append(weight) dp = [[0 for i in range(max_w+1)] for j in range(n+1)] for i in range(n): for cw in range(max_w+1): if cw >= w[i]: dp[i+1][cw] = max(dp[i][cw-w[i]]+v[i], dp[i][cw]) else: dp[i+1][cw] = dp[i][cw] print(dp[n][max_w])
s413808469
p02612
u450147945
2,000
1,048,576
Wrong Answer
28
9,016
36
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = input() N = int(N) print(N%1000)
s234962382
Accepted
30
8,856
37
N = input() N = int(N) print(-N%1000)
s201304121
p02613
u024343432
2,000
1,048,576
Wrong Answer
149
9,296
499
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.
from sys import stdin,stdout import math from collections import Counter,defaultdict LI=lambda:list(map(int,input().split())) MAP=lambda:map(int,input().split()) IN=lambda:int(input()) S=lambda:input() def case(): a=b=c=d=0 for i in range(IN()): s=S() if s=="AC":a+=1 elif s=="TLE":b+=1 elif s=="WA":c+=1 else:d+=1 print("AC","x",a) print("AC","x",c) print("AC","x",b) print("AC","x",d) for _ in range(1): case()
s747387035
Accepted
144
9,436
500
from sys import stdin,stdout import math from collections import Counter,defaultdict LI=lambda:list(map(int,input().split())) MAP=lambda:map(int,input().split()) IN=lambda:int(input()) S=lambda:input() def case(): a=b=c=d=0 for i in range(IN()): s=S() if s=="AC":a+=1 elif s=="TLE":b+=1 elif s=="WA":c+=1 else:d+=1 print("AC","x",a) print("WA","x",c) print("TLE","x",b) print("RE","x",d) for _ in range(1): case()
s780943101
p03846
u598699652
2,000
262,144
Wrong Answer
69
13,880
408
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
N = int(input()) A = list(map(int, input().split())) ans = pow(2, N // 2) # 0*1 2*2 4*2 2^N/2*2 check = [0 for p in range(0, N // 2 + N % 2)] for o in A: check[o // 2] += 1 for q in range(0, N // 2 + N % 2): if q == 0 & N % 2 == 1: if check[q] != 1: ans = 0 break else: if check[q] != 2: ans = 0 break print(ans % (pow(10, 9) + 7))
s609392518
Accepted
65
14,008
410
N = int(input()) A = list(map(int, input().split())) ans = pow(2, N // 2) # 0*1 2*2 4*2 2^N/2*2 check = [0 for p in range(0, N // 2 + N % 2)] for o in A: check[o // 2] += 1 for q in range(0, N // 2 + N % 2): if q == 0 and N % 2 == 1: if check[q] != 1: ans = 0 break else: if check[q] != 2: ans = 0 break print(ans % (pow(10, 9) + 7))
s326459897
p03130
u811000506
2,000
1,048,576
Wrong Answer
17
3,060
161
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
li = [] for i in range(3): a,b = map(int,input().split()) li.append(a) li.append(b) li.sort() if li==[1, 2, 2, 2, 3, 4]: print("YES") else: print("NO")
s106486243
Accepted
17
3,060
162
li = [] for i in range(3): a,b = map(int,input().split()) li.append(a) li.append(b) li.sort() if li==[1, 2, 2, 3, 3, 4]: print("YES") else: print("NO")
s181049289
p02413
u853619096
1,000
131,072
Wrong Answer
20
7,588
166
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
r, c = map(int, input().split()) for j in range(r): a = [int(i) for i in input().split()] for k in a: print('{} '.format(k),end='') print(sum(a))
s774522051
Accepted
30
7,736
338
r,c=map(int,input().split()) a=[] for i in range(r): a+=[list(map(int,input().split()))] a[i].append(sum(a[i])) for i in range(len(a)): print(" ".join(list(map(str,a[i])))) b=[] t=[] d=0 for i in range(c+1): for j in range(r): b+=[a[j][i]] t+=[sum(b)] b=[] print(" ".join(list(map(str,t))))
s168920784
p03999
u633548583
2,000
262,144
Wrong Answer
30
3,060
217
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
s=input() cnt=len(s)-1 for i in range(2**cnt): sum=s[0] for j in range(cnt): if ((i>>j)&1): sum+="+" else: sum+="-" sum+=s[j+1] print(eval(sum))
s050463837
Accepted
27
2,940
229
s=input() cnt=len(s)-1 ans=0 for i in range(2**cnt): sum=s[0] for j in range(cnt): if ((i>>j)&1): sum+="+" else: pass sum+=s[j+1] ans+=eval(sum) print(ans)
s730136885
p02613
u140084432
2,000
1,048,576
Wrong Answer
154
17,464
407
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.
def main(): N = int(input()) judges = [input() for _ in range(N)] print(judges) res_dic = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0} for judge in judges: if judge in res_dic: res_dic[judge] += 1 else: res_dic[judge] = 0 for k, v in res_dic.items(): print("{} x {}".format(k, v)) if __name__ == '__main__': main()
s627228796
Accepted
141
16,244
384
def main(): N = int(input()) judges = [input() for _ in range(N)] res_dic = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0} for judge in judges: if judge in res_dic: res_dic[judge] += 1 else: res_dic[judge] = 0 for k, v in res_dic.items(): print("{} x {}".format(k, v)) if __name__ == '__main__': main()
s001859164
p03493
u894348341
2,000
262,144
Wrong Answer
17
2,940
25
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
print(input().count('a'))
s478304496
Accepted
17
2,940
25
print(input().count('1'))
s985046159
p03853
u325282913
2,000
262,144
Wrong Answer
18
3,060
95
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
H, W = map(int, input().split()) for _ in range(H-1): s = input() print(s) print(s)
s299416874
Accepted
18
3,060
157
H, W = map(int, input().split()) array = [] for _ in range(H): s = input() array.append(s) for i in range(H): print(array[i]) print(array[i])
s700611300
p03139
u379692329
2,000
1,048,576
Wrong Answer
18
2,940
99
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
N, A, B = map(int, input().split()) ResMax = max(A, B) ResMin = max(0, A+B-N) print(ResMax, ResMin)
s397107553
Accepted
17
2,940
99
N, A, B = map(int, input().split()) ResMax = min(A, B) ResMin = max(0, A+B-N) print(ResMax, ResMin)