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
s904562178
p03351
u444722572
2,000
1,048,576
Wrong Answer
18
2,940
117
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d=map(int,input().split()) if abs(a-c)<d or (abs(a-b)<d and abs(b-c)<d): print("Yes") else: print("No")
s902616302
Accepted
17
2,940
130
a,b,c,d=map(int,input().split()) AB=abs(a-b) BC=abs(b-c) CA=abs(a-c) print("Yes" if CA<=d else "Yes" if AB<=d and BC<=d else "No")
s143017767
p03549
u594956556
2,000
262,144
Wrong Answer
17
2,940
44
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
N, M = map(int, input().split()) print(2**M)
s950161662
Accepted
17
2,940
66
N, M = map(int, input().split()) print((1900*M+100*(N-M))*(2**M))
s812164146
p02619
u153499445
2,000
1,048,576
Wrong Answer
35
9,732
380
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
D=int(input()) c=[int(x) for x in input().split()] s=[[0]*i for i in range(D)] t=[] last_d=[0]*26 for i in range(D): s[i]=[int(x) for x in input().split()] for i in range(D): t.append(int(input())) v=0 C=sum(c) print(C) for i in range(D): a=0 for j in range(26): if j!=t[i]-1: n=i+1-last_d[j] a+=c[j]*n v=v+s[i][t[i]-1]-a print(v) last_d[t[i]-1]=i+1
s071349407
Accepted
39
9,828
362
D=int(input()) c=[int(x) for x in input().split()] s=[[0]*i for i in range(D)] t=[] last_d=[0]*26 for i in range(D): s[i]=[int(x) for x in input().split()] for i in range(D): t.append(int(input())) v=0 for i in range(D): a=0 for j in range(26): if j!=t[i]-1: n=i+1-last_d[j] a+=c[j]*n v=v+s[i][t[i]-1]-a print(v) last_d[t[i]-1]=i+1
s293027237
p03645
u735008991
2,000
262,144
Wrong Answer
599
20,820
208
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
N, M =map(int, input().split()) sa = set() ag = set() for i in range(M): a,b = map(int, input().split()) if a == 1: sa.add(b) if b == N: sa.add(a) print('POSSIBLE' if len(sa&ag) else 'IMPOSSIBLE')
s682254750
Accepted
600
19,024
208
N, M =map(int, input().split()) sa = set() ag = set() for i in range(M): a,b = map(int, input().split()) if a == 1: sa.add(b) if b == N: ag.add(a) print('POSSIBLE' if len(sa&ag) else 'IMPOSSIBLE')
s576021917
p02613
u235499392
2,000
1,048,576
Wrong Answer
143
9,012
220
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()) a,b,c,d=0,0,0,0 for _ in range(n): s=input() if(s=="AC"): a+=1 elif(s=="WA"): b+=1 elif(s=="TLE"): c+=1 else: d+=1 print("AC X",a) print("WA X",b) print("TLE X",c) print("RE X",d)
s066791774
Accepted
142
9,096
220
n=int(input()) a,b,c,d=0,0,0,0 for _ in range(n): s=input() if(s=="AC"): a+=1 elif(s=="WA"): b+=1 elif(s=="TLE"): c+=1 else: d+=1 print("AC x",a) print("WA x",b) print("TLE x",c) print("RE x",d)
s815619270
p03836
u496821919
2,000
262,144
Wrong Answer
17
3,060
143
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx,sy,tx,ty = map(int,input().split()) dx = tx-sx dy = ty-sy print("U"*dy+"R"*dx+"D"*dy+"L"*(dx+1)+"U"*(dy+1)+"R"*(dx+2)+"D"*(dy+2)+"L"*(dx+2))
s764175397
Accepted
17
3,060
152
sx,sy,tx,ty = map(int,input().split()) dx = tx-sx dy = ty-sy print("U"*dy+"R"*dx+"D"*dy+"L"*(dx+1)+"U"*(dy+1)+"R"*(dx+1)+"DR"+"D"*(dy+1)+"L"*(dx+1)+"U")
s134065885
p02936
u020962106
2,000
1,048,576
Wrong Answer
2,106
42,392
330
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
n,q = map(int,input().split()) ki = [[] for _ in range(n)] cnt = [0]*n for i in range(n-1): a,b = map(int,input().split()) ki[a-1].append(b) for i in range(q): p,x = map(int,input().split()) cnt[p-1]+=x if ki[p-1]: for j in range(ki[p-1][0],n+1): cnt[j-1]+=x [print(x,end=' ') for x in cnt]
s910542081
Accepted
1,719
55,856
501
n,q = map(int,input().split()) graph = [[] for _ in range(n)] point = [0]*n for i in range(n-1): a,b = map(int,input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) for _ in range(q): a,b = map(int,input().split()) a = a -1 point[a]+=b stack = []; stack.append(0) visited = [False]*n while stack: x = stack.pop() visited[x] = True for y in graph[x]: if visited[y] == False: point[y] += point[x] stack.append(y) print(*point)
s992413466
p03478
u033982315
2,000
262,144
Wrong Answer
45
9,380
331
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).
s=list(map(int,input().split())) oklist=[] def keta(x): ketalist=[] for j in range(len(x)): ketalist.append(int(x[j])) return(sum(ketalist)) for i in range(s[0]+1): check=keta(str(i)) if(s[1]<=check and check<=s[2]): oklist.append(i) print('ok') sum_=sum(oklist)
s609750640
Accepted
40
9,100
320
s=list(map(int,input().split())) oklist=[] def keta(x): ketalist=[] for j in range(len(x)): ketalist.append(int(x[j])) return(sum(ketalist)) for i in range(s[0]+1): check=keta(str(i)) if(s[1]<=check and check<=s[2]): oklist.append(i) sum_=sum(oklist) print(sum_)
s656138008
p03162
u371467115
2,000
1,048,576
Wrong Answer
431
30,580
156
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
n=int(input()) hd=[list(map(int,input().split())) for _ in range(n)] A,B,C=0,0,0 for a,b,c in hd: A,B,C=A+max(b,c),B+max(a,c),C+max(a,b) print(max(A,B,C))
s031928706
Accepted
392
3,060
139
n=int(input()) A,B,C=0,0,0 for _ in range(n): a,b,c=map(int,input().split()) A,B,C=a+max(B,C),b+max(A,C),c+max(A,B) print(max(A,B,C))
s859047086
p03719
u845937249
2,000
262,144
Wrong Answer
17
2,940
97
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
x , y ,z = map(int,input().split()) if z>x and y>z: ans = 'YES' else: ans = 'NO' print(ans)
s020800796
Accepted
17
2,940
99
x , y ,z = map(int,input().split()) if z>=x and y>=z: ans = 'Yes' else: ans = 'No' print(ans)
s124618383
p02388
u166841004
1,000
131,072
Wrong Answer
20
5,516
15
Write a program which calculates the cube of a given integer x.
x=3 print(x^3)
s764913883
Accepted
20
5,572
28
x=int(input()) print(x**3)
s315091526
p02396
u868716420
1,000
131,072
Wrong Answer
130
7,364
112
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
x = input() case = 1 while x != '0' : print('case {}: {}'.format(case, x)) x = input() case += 1
s582475432
Accepted
120
7,304
112
x = input() case = 1 while x != '0' : print('Case {}: {}'.format(case, x)) x = input() case += 1
s132059832
p02697
u479719434
2,000
1,048,576
Wrong Answer
73
9,100
78
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
N, M = map(int, input().split()) for i in range(1, M+1): print(i, N-i+1)
s166459651
Accepted
85
9,096
152
N, M = map(int, input().split()) for i in range(M): j = i // 2 if i % 2 == 1: print(j+1, M-j) else: print(M+j+1, 2*M+1-j)
s221821527
p03599
u386819480
3,000
262,144
Wrong Answer
39
3,064
1,386
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
#!/usr/bin/env python3 import sys from math import ceil, floor def solve(A: int, B: int, C: int, D: int, E: int, F: int): w = F s = 0 for i in range(ceil(F/(100*A))): aw = 100*A*i for j in range(ceil(F/(100*B))): bw = 100*B*j for k in range(ceil((F-aw-bw)/C)): cs = C*k ds = min(D*floor((F-aw-bw-cs)/D), (aw*E+bw*E+cs*E)/max(1,100-E)) if(aw+bw == 0 or cs+ds == 0): continue n = 100*s/(w+s) mn = 100*(cs+ds)/(aw+bw+cs+ds) if(mn <= E): if(n < mn): w = aw+bw s = cs+ds # print(i,j,k, mn) print(w, s) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int D = int(next(tokens)) # type: int E = int(next(tokens)) # type: int F = int(next(tokens)) # type: int solve(A, B, C, D, E, F) if __name__ == '__main__': main()
s270047575
Accepted
196
12,464
1,479
#!/usr/bin/env python3 import sys from math import ceil, floor def solve(A: int, B: int, C: int, D: int, E: int, F: int): x = [] y = [] for i in range(ceil(F/(100*A))+1): for j in range(ceil(F/(100*B))+1): dx = 100*A*i+100*B*j if(min(100*A,100*B) <= dx <= F): x.append(dx) for i in range(ceil(F/C)+1): for j in range(ceil(F/C)+1): dy = C*i+D*j if(0 <= dy <= F): y.append(dy) x = sorted(list(set(x))) y = sorted(list(set(y))) w = x[0] s = y[0] for i in x: for j in y: de = 100*s/(w+s) ne = 100*j/(i+j) if(i+j <= F and de < ne <= 100*E/(100+E)): # print(i, j, ne) w = i s = j print(w+s, s) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int D = int(next(tokens)) # type: int E = int(next(tokens)) # type: int F = int(next(tokens)) # type: int solve(A, B, C, D, E, F) if __name__ == '__main__': main()
s624290553
p03486
u258073778
2,000
262,144
Wrong Answer
18
3,064
241
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s1 = input() t1 = input() s = list(s1) t = list(t1) s.sort() t.sort(reverse=1) i = 0 while(1): if ord(s[i]) < ord(t[i]): print('YES') break else : if i+1 == min(len(s1),len(t1)): print('NO') break else : i+=1
s361198380
Accepted
17
2,940
58
print('Yes'*(sorted(input())<sorted(input())[::-1])or'No')
s656156894
p03351
u496280557
2,000
1,048,576
Wrong Answer
28
9,160
152
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d = map(int,input().split()) if abs (a - c) <= d: print('Yes') elif abs(a - b) <= abs(b - c) <= d: print('Yes') else: print(' No ')
s257450908
Accepted
28
9,192
139
a,b,c,d = map(int,input().split()) if abs (a - c) <= d or abs (a - b) <= d and abs (b - c) <= d: print('Yes') else: print(' No')
s387131037
p03999
u542190960
2,000
262,144
Wrong Answer
27
9,056
308
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 = str(input()) n = len(s) ans = 0 for i in range(2**(n-1)): s_tmp = s nbin = str(bin(i))[2:] nbin = nbin.zfill(n-1) for j in range(len(nbin)-1, -1, -1): if nbin[j] == '1': s_tmp = s_tmp[:j+1] + '+' + s_tmp[j+1:] print(nbin, s_tmp) ans += eval(s_tmp) print(ans)
s168363528
Accepted
25
9,076
285
s = str(input()) n = len(s) ans = 0 for i in range(2**(n-1)): s_tmp = s nbin = str(bin(i))[2:] nbin = nbin.zfill(n-1) for j in range(len(nbin)-1, -1, -1): if nbin[j] == '1': s_tmp = s_tmp[:j+1] + '+' + s_tmp[j+1:] ans += eval(s_tmp) print(ans)
s128416917
p02389
u514745787
1,000
131,072
Wrong Answer
20
7,700
52
Write a program which calculates the area and perimeter of a given rectangle.
a, b = [int(i) for i in input().split()] print(a, b)
s737720918
Accepted
30
7,508
70
ab = input().split() a = int(ab[0]) b = int(ab[1]) print(a*b, (a+b)*2)
s954459856
p03478
u676464724
2,000
262,144
Wrong Answer
52
9,176
205
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()) sum = 0 for i in range(N+1): x = 0 for j in range(len(str(i))): x = x + int(str(i)[j]) print(x) if A <= x <= B: sum = sum + i print(sum)
s266426954
Accepted
48
9,044
192
N, A, B = map(int, input().split()) sum = 0 for i in range(N+1): x = 0 for j in range(len(str(i))): x = x + int(str(i)[j]) if A <= x <= B: sum = sum + i print(sum)
s176041931
p03556
u951480280
2,000
262,144
Wrong Answer
17
2,940
31
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.
print(int(int(input())**.5**2))
s414459061
Accepted
17
2,940
31
print(int(int(input())**.5)**2)
s889406493
p03860
u669382434
2,000
262,144
Wrong Answer
18
2,940
36
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.
print("A"+input().split()[2][0]+"C")
s874691935
Accepted
18
3,064
36
print("A"+input().split()[1][0]+"C")
s457605103
p03698
u207075364
2,000
262,144
Wrong Answer
18
2,940
86
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
l=list(input()) l.sort() if l[0]==l[len(l)-1]: print("yes") else: print("no")
s844593192
Accepted
18
2,940
155
l=list(input()) l.sort() flag = False for i in range(len(l)-1): if l[i]==l[i+1]: flag = True if flag: print("no") else: print("yes")
s608286484
p03478
u652569315
2,000
262,144
Wrong Answer
36
2,940
139
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): c=sum([int(j) for j in list(str(i))]) if c>=a and c<=b: ans+=i print(i)
s454647827
Accepted
37
2,940
142
n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): c=sum([int(j) for j in list(str(i))]) if c>=a and c<=b: ans+=i print(ans)
s858440565
p03448
u176796545
2,000
262,144
Wrong Answer
42
3,060
250
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A=int(input()) B=int(input()) C=int(input()) total=int(input()) count=0 for a in [a*500 for a in range(A+1)]: for b in [b*100 for b in range(B+1)]: for c in [c*50 for c in range(C+1)]: if a+b+c==total: count+=1
s459520342
Accepted
46
3,064
263
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count=0 for a in [a*500 for a in range(A+1)]: for b in [b*100 for b in range(B+1)]: for c in [c*50 for c in range(C+1)]: if a+b+c==X: count+=1 print(count)
s791517280
p03945
u871841829
2,000
262,144
Wrong Answer
45
3,188
151
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
import sys s = input() before = s[0] ans = 0 for cx in range(1, len(s)): if before != s[cx]: ans += 1 before = s[cx] print(abs)
s741750062
Accepted
42
3,188
151
import sys s = input() before = s[0] ans = 0 for cx in range(1, len(s)): if before != s[cx]: ans += 1 before = s[cx] print(ans)
s912659914
p02743
u113991073
2,000
1,048,576
Wrong Answer
18
3,060
141
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
import math a,b,c = map(int, input().split()) x=math.sqrt(a) y=math.sqrt(b) z=math.sqrt(c) if c>a+b: print("Yes") else: print("No")
s488343598
Accepted
17
3,064
207
def Judgement(x,y,z): if z-x-y>0 and (z-x-y)**2-4*x*y>0: return 0 else: return 1 a,b,c=map(int,input().split()) ans=Judgement(a,b,c) if ans==0: print("Yes") else: print("No")
s178555528
p03044
u059210959
2,000
1,048,576
Wrong Answer
703
29,512
791
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
# encoding:utf-8 import copy import random import bisect import fractions import math mod = 10**9+7 N = int(input()) u,v,w = [0 for i in range(N-1)],[0 for i in range(N-1)],[0 for i in range(N-1)] for i in range(N-1): u[i],v[i],w[i] = map(int,input().split()) tree = [[] for i in range(N-1)] for i in range(N-1): tree[i] = [u[i],v[i],w[i]] # print(tree) tree.sort() color = [False for i in range(N)] color[0] = True for i in range(N-1): # print(color) if tree[i][2] % 2 == 0: color[tree[i][1]-1] = color[tree[i][0]-1] else: color[tree[i][1]-1] = not(color[tree[i][0]-1]) for i in range(N): if color[i]: print(1) else: print(0)
s293341479
Accepted
786
90,192
863
# encoding:utf-8 import copy import random import bisect import fractions import math import sys mod = 10**9+7 sys.setrecursionlimit(mod) N = int(input()) graph = [set() for i in range(N+1)] for i in range(N-1): u,v,w = map(int,input().split()) u -= 1 v -= 1 w = w % 2 graph[u].add((v,w)) graph[v].add((u,w)) res = [None for i in range(N+1)] def dfs(node,p,color): # Depth First Serch res[node] = color for new_node,w in graph[node]: if new_node == p:continue if w == 1:dfs(new_node,node,1-color) else:dfs(new_node,node,color) dfs(0,-1,0) for i in range(N): print(res[i])
s982296567
p03672
u617659131
2,000
262,144
Wrong Answer
20
3,060
268
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 = list(input()) a = [] b = [] for i in range(len(s)): s.pop() if len(s) % 2 == 0: for j in range(len(s)): if j <= len(s) // 2 - 1: a.append(s[j]) elif j <= len(s) // 2: b.append(s[j]) if a == b: print(len(s)) break
s962035334
Accepted
17
2,940
122
s = list(input()) for i in range(len(s)): s.pop() if s[:(len(s) // 2)] == s[len(s) // 2:]: print(len(s)) break
s999734588
p02646
u266675845
2,000
1,048,576
Wrong Answer
21
9,184
159
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()) A = a + v * T B = b + w * T if A>= B: print("Yes") else: print("NO")
s171482093
Accepted
23
9,192
298
a, v = map(int,input().split()) b, w = map(int,input().split()) T = int(input()) if a<b: A = a + v * T B = b + w * T if A>= B: print("YES") else: print("NO") else: A = a - v*T B = b - w * T if A <= B: print("YES") else: print("NO")
s974882104
p02690
u919017918
2,000
1,048,576
Wrong Answer
23
9,188
379
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.
import sys X = int(input()) mylist= [] for i in range(101): mylist += [i**5] #print(i**5) #print(mylist) for m in mylist: for mm in mylist: if m - mm == X: print(mylist.index(m), mylist.index(mm)) sys.exit() print() elif m + mm == X: print(mylist.index(m), -1*mylist.index(mm)) sys.exit()
s912962801
Accepted
40
9,180
253
x = int(input()) OP = [+1, -1] for a in range(1000): for b in range(a + 1): for op1 in OP: for op2 in OP: if (op1 * a)**5 - (op2 * b)**5 == x: print(op1 * a, op2 * b) exit()
s605957727
p04043
u620846115
2,000
262,144
Wrong Answer
26
9,012
109
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a = list(map(int,input().split())) if a.count("7")==1 and a.count("5")==2: print("YES") else: print("NO")
s891706925
Accepted
28
8,876
94
a = input().split() if a.count("7")==1 and a.count("5")==2: print("YES") else: print("NO")
s487705628
p02659
u197868423
2,000
1,048,576
Wrong Answer
21
9,104
92
Compute A \times B, truncate its fractional part, and print the result as an integer.
import math A, B = input().split() A = int(A) B = float(B) ans = A * B print(math.ceil(ans))
s029080500
Accepted
25
10,080
123
import math from decimal import Decimal A, B = input().split() A = int(A) B = Decimal(B) ans = A * B print(math.floor(ans))
s702376972
p03777
u811388439
2,000
262,144
Wrong Answer
17
2,940
192
Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest.
l_vec = input().split() def classifier1(l) : if ((l[0] == 'H') and (l[1] == 'H')) or ((l[0] == 'D') and (l[1] == 'D')) : return 'H' else : return 'D' classifier1(l_vec)
s182730765
Accepted
17
2,940
199
l_vec = input().split() def classifier1(l) : if ((l[0] == 'H') and (l[1] == 'H')) or ((l[0] == 'D') and (l[1] == 'D')) : return 'H' else : return 'D' print(classifier1(l_vec))
s641285509
p03494
u123648284
2,000
262,144
Wrong Answer
19
3,060
212
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = input() l = list(map(int, input().split())) cnt = 0 flg = True while flg: for i in range(len(l)): if l[i] % 2: l[i] /= 2 else: flg = False break if flg: cnt += 1 print(cnt)
s303722236
Accepted
19
3,060
217
n = input() l = list(map(int, input().split())) cnt = 0 flg = True while flg: for i in range(len(l)): if l[i] % 2 == 0: l[i] /= 2 else: flg = False break if flg: cnt += 1 print(cnt)
s002218429
p00007
u742178809
1,000
131,072
Wrong Answer
20
7,692
91
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks.
x = 100000 for i in range(int(input())): x*=1.05 x+=999 x=x//1000*1000 print(x)
s728090383
Accepted
30
7,680
96
x = 100000 for i in range(int(input())): x*=1.05 x+=999 x=x//1000*1000 print(int(x))
s732224396
p02615
u081141316
2,000
1,048,576
Wrong Answer
2,269
72,016
379
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()) A = [int(i) for i in input().split(' ')] A.sort(reverse=True) ring = [] max_value = A.pop(0) ring.append(max_value) ring.append(max_value) ans = 0 for i in A: buf = [x for x in ring] print(ring) n = [] for j in range(0, len(ring) - 1): n.append(min(ring[j:j+2])) ans = ans + max(n) ring.insert(n.index(max(n)) + 1, i) print(ans)
s271422676
Accepted
174
32,496
295
import sys from collections import deque N = int(sys.stdin.readline()) A = [int(i) for i in sys.stdin.readline().split(' ')] A.sort(reverse=True) max_value = A.pop(0) diff = deque([max_value]) ans = 0 for i in A: ans = ans + diff.popleft() diff.append(i) diff.append(i) print(ans)
s693928354
p02612
u920204936
2,000
1,048,576
Wrong Answer
30
9,144
30
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()) print(n%1000)
s575032787
Accepted
30
9,140
69
n = int(input()) ans = 1000 - n%1000 if n%1000 != 0 else 0 print(ans)
s887074532
p03697
u591295155
2,000
262,144
Wrong Answer
17
2,940
55
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
S = input() print(["no", "yes"][len(set(S)) == len(S)])
s260118490
Accepted
17
2,940
64
A, B = map(int, input().split()) print(["error", A+B][A+B < 10])
s464448010
p03567
u357751375
2,000
262,144
Wrong Answer
17
2,940
70
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
s = list(input()) if 'AC' in s: print('Yes') else: print('No')
s806066352
Accepted
27
9,088
64
s = input() if 'AC' in s: print('Yes') else: print('No')
s562689108
p02238
u684325232
1,000
131,072
Wrong Answer
20
5,612
958
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving the vertex from which $v$ was discovered. This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source. DFS timestamps each vertex as follows: * $d[v]$ records when $v$ is first discovered. * $f[v]$ records when the search finishes examining $v$’s adjacency list. Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules: * $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively. * IDs in the adjacency list are arranged in ascending order. * The program should report the discover time and the finish time for each vertex. * When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID. * The timestamp starts with 1.
n=int(input()) l=[[0 for i in range(n)] for j in range(n)] d=[0 for i in range(n)] f=[0 for i in range(n)] stack=[] check=[] for i in range(n): p=[int(x) for x in input().split()] for j in range(n): if j+1 in p[2:]: l[i][j]=1 ##print(l) time=1 d[0]=1 stack+=[1] check+=[-1] while len(stack)!=0: ##print("----------while---------") for i in range(n): if l[stack[-1]-1][i]==1 and not i+1 in check: time+=1 d[i]=time stack+=[i+1] ## print("stack:",stack) ## print("d[",i,"]:",d[i]) break elif i==n-1: check+=[stack[-1]] time+=1 f[stack.pop()-1]=time ##print("f[",i,"]:",f[i]) ##print("check:",check) for i in range(n): print(i+1," ",d[i]," ",f[i])
s708326341
Accepted
30
5,736
1,222
n=int(input()) l=[[0 for i in range(n)] for j in range(n)] d=[0 for i in range(n)] f=[0 for i in range(n)] stack=[] check=[] for i in range(n): p=[int(x) for x in input().split()] for j in range(n): if j+1 in p[2:]: l[i][j]=1 ##print(l) time=1 while len(check)<n: for i in range(n): if i+1 not in check: stack+=[i+1] d[i]=time break else: pass while len(stack)!=0: ##print("----------while---------") for i in range(n): if l[stack[-1]-1][i]==1 and not i+1 in check and i+1 not in stack and stack[-1]-1!=i: time+=1 d[i]=time stack+=[i+1] ## print("stack:",stack) ## print("check:",check) ## print("d[",i,"]:",d[i]) break elif i==n-1: check+=[stack[-1]] time+=1 f[stack.pop()-1]=time ## print("f[",i,"]:",f[i]) ## print("check:",check) time+=1 for i in range(n): print(i+1,d[i],f[i])
s533296891
p04030
u024612773
2,000
262,144
Wrong Answer
41
3,064
33
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?
print(input().replace('B', '\b'))
s516520304
Accepted
38
3,064
176
s=list(reversed(input())) ans="" cnt=0 for c in s: if c == 'B': cnt += 1 elif cnt > 0: cnt -= 1 else: ans += c print(''.join(reversed(ans)))
s143105663
p03494
u698348858
2,000
262,144
Time Limit Exceeded
2,104
2,940
201
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
#coding:utf-8 n = int(input()) nums = list(map(int,input().split(' '))) cnt = 0 while True: for num in nums: if num % 2 != 0: break else: continue break else: cnt += 1
s270473601
Accepted
19
3,060
293
#coding:utf-8 n = int(input()) nums = list(map(int,input().split(' '))) def calc(): cnt = 0 while True: for i in range(len(nums)): num = nums[i] if num % 2 == 0 and num != 0: nums[i] = num / 2 else: return cnt else: cnt += 1 print(calc())
s760689330
p02972
u760569096
2,000
1,048,576
Wrong Answer
406
26,236
329
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
from collections import deque n =int(input()) a = [0]+list(map(int, input().split())) d = deque() cnt=0 for i in range(n,0,-1): for j in range(i,n+1,i): if a[j]==0: continue cnt+=1 b = cnt%2 a[i] = b if b == 1: d.appendleft(i) cnt = 0 if len(d) == 0: print(0) else: print(' '.join(map(str,d)))
s242503667
Accepted
404
26,012
308
from collections import deque n =int(input()) a = [0]+list(map(int, input().split())) d = deque() cnt=0 for i in range(n,0,-1): for j in range(i,n+1,i): if a[j]==0: continue cnt+=1 b = cnt%2 a[i] = b if b == 1: d.appendleft(i) cnt = 0 print(len(d)) print(' '.join(map(str,d)))
s113682352
p03623
u464912173
2,000
262,144
Wrong Answer
17
2,940
76
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
a,b,c = map(int,input().split()) print('B' if abs(a-c) > abs(b-c) else 'A')
s723756681
Accepted
17
2,940
76
x,a,b = map(int,input().split()) print('B' if abs(a-x) > abs(b-x) else 'A')
s812766464
p02399
u098047375
1,000
131,072
Wrong Answer
20
5,600
79
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a, b = map(int, input().split()) d = a // b r = a % b f = a / b print(d, r, f)
s441935984
Accepted
20
5,604
96
a, b = map(int, input().split()) d = a // b r = a % b f = a / b print(d, r, '{:.5f}'.format(f))
s080664651
p02866
u325282913
2,000
1,048,576
Wrong Answer
2,104
14,396
114
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition: * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.
N = int(input()) array = list(map(int, input().split())) ans = 1 for i in range(N): ans *= array[i] print(ans)
s359479255
Accepted
170
16,252
692
N = int(input()) array = list(map(int, input().split())) if array[0] != 0: print(0) exit() array.sort() if 1 in array and len(set(array[1:])) == 1: print(1) exit() if not (2 in array): print(0) exit() if 0 in array[1:]: print(0) exit() index = array.index(2) count = 1 count_old = array.count(1) ans = 1 first = array[index] for i in range(index,N-1): if first != array[i+1]: if first != array[i+1] - 1: print(0) exit() ans *= count_old ** count count_old = count count = 1 else: count += 1 first = array[i+1] ans %= 998244353 ans *= count_old ** count ans %= 998244353 print(ans)
s241260238
p02843
u460009487
2,000
1,048,576
Wrong Answer
17
2,940
134
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()) cent = n//100 under_cent = n%100 print(cent) print(under_cent) if under_cent > cent*5: print(0) else: print(1)
s933277479
Accepted
17
2,940
103
n = int(input()) cent = n//100 under_cent = n%100 if under_cent > cent*5: print(0) else: print(1)
s382296366
p03502
u698567423
2,000
262,144
Wrong Answer
18
2,940
103
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
num = int(input()) fx = 0 for i in str(num): fx += int(i) print("YES" if num % fx == 0 else "NO")
s357957216
Accepted
17
2,940
103
num = int(input()) fx = 0 for i in str(num): fx += int(i) print("Yes" if num % fx == 0 else "No")
s978932353
p03457
u447528293
2,000
262,144
Wrong Answer
399
12,580
462
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.
N = int(input().rstrip()) t = [0 for _ in range(N+1)] x = [0 for _ in range(N+1)] y = [0 for _ in range(N+1)] for i in range(1, N+1): t[i], x[i], y[i] = [int(s) for s in input().rstrip().split()] judge = [] for i in range(N): diff_t = t[i+1] - t[i] diff_x = x[i+1] - x[i] if diff_t >= diff_x and (diff_t - diff_x ) % 2 == 0: judge.append(True) else: judge.append(False) if all(judge): print('Yes') else: print('No')
s947889662
Accepted
413
12,704
488
N = int(input().rstrip()) t = [0 for _ in range(N+1)] x = [0 for _ in range(N+1)] y = [0 for _ in range(N+1)] for i in range(1, N+1): t[i], x[i], y[i] = [int(s) for s in input().rstrip().split()] judge = [] for i in range(N): diff_t = t[i+1] - t[i] diff_x = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]) if diff_t >= diff_x and (diff_t - diff_x ) % 2 == 0: judge.append(True) else: judge.append(False) if all(judge): print('Yes') else: print('No')
s359671773
p04043
u040033078
2,000
262,144
Wrong Answer
17
2,940
230
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
# -*- coding: utf-8 -*- a,b,c = input().split() a = int(a) b = int(b) c = int(c) if a+b+c != 17: print('No') else: if (a == 5 and b == 5) or ( a ==5 and c == 5) or (b ==5 and c == 5): print('Yes') else: print('No')
s220043130
Accepted
18
2,940
121
# -*- coding: utf-8 -*- a = input().split() a.sort() b = ['5', '5', '7'] if a == b: print('YES') else: print('NO')
s630098315
p03447
u705418271
2,000
262,144
Wrong Answer
25
9,096
77
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?
x=int(input()) a=int(input()) b=int(input()) x-=a while x>=0: x-=b print(x)
s148248151
Accepted
30
9,124
79
x=int(input()) a=int(input()) b=int(input()) x-=a while x>=0: x-=b print(x+b)
s514775623
p03588
u762420987
2,000
262,144
Wrong Answer
389
17,808
125
A group of people played a game. All players had distinct scores, which are positive integers. Takahashi knows N facts on the players' scores. The i-th fact is as follows: the A_i-th highest score among the players is B_i. Find the maximum possible number of players in the game.
N = int(input()) AB = [tuple(map(int, input().split())) for _ in range(N)] max_A = sorted(AB)[-1] print(max_A[0] * max_A[1])
s069942167
Accepted
312
11,048
139
N = int(input()) a, b = [], [] for i in range(N): A, B = map(int, input().split()) a.append(A) b.append(B) print(max(a)+min(b))
s850290406
p03479
u726439578
2,000
262,144
Wrong Answer
19
2,940
77
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
x,y=map(int,input().split()) i=1 while x<=y : i+=1 x=2*x print(i)
s589849977
Accepted
18
2,940
77
x,y=map(int,input().split()) i=0 while x<=y : i+=1 x=2*x print(i)
s234210092
p02261
u409699893
1,000
131,072
Wrong Answer
30
7,832
816
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 buble(n,x,count): for i in range(1,n + 1): for j in range(1,i): if int(x[i - j][1]) < int(x[i - j - 1][1]): x[i - j],x[i - j - 1] = x[i - j - 1],x[i - j] count += 1 print (" ".join(x)) print ("Stable") def delection(n,x,flag): for i in range(n - 1): minx = i for j in range(i + 1,n): if x[j][1] == x[i][1]: flag = 1 if x[j][1] < x[minx][1]: minx = j if not i == minx: x[i],x[minx]=x[minx],x[i] print (" ".join(x)) if flag == 1: print ("Stable") else: print ("Not stable") n = int(input()) x = list(map(str,input().split())) y = x count = 0 flag = 0 buble(n,x,count) delection(n,y,flag)
s776181361
Accepted
20
7,752
442
n = int(input()) a = input().strip().split() b = a[:] for i in range(n): for j in range(n-1,i,-1): if b[j][1] < b[j-1][1]: b[j],b[j-1] = b[j-1],b[j] print(' '.join(b)) print('Stable') #Selection sort for i in range(n): minj = i for j in range(i,n): if a[j][1] < a[minj][1]: minj = j a[i],a[minj] = a[minj],a[i] print(' '.join(a)) print('Stable' if b == a else 'Not stable')
s135004053
p03477
u129898499
2,000
262,144
Wrong Answer
17
2,940
117
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()) if a+b > c+d: print("Left") if a+b < c+d: print("Right") else: print("Balnced")
s552839705
Accepted
17
2,940
120
a,b,c,d=map(int, input().split()) if a+b > c+d: print("Left") elif a+b < c+d: print("Right") else: print("Balanced")
s462576218
p03388
u707124227
2,000
262,144
Wrong Answer
29
9,364
310
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
q=int(input()) ab=[list(map(int,input().split())) for _ in range(q)] for a,b in ab: if a>b:a,b=b,a if a==b: print(2*a-2) elif a+1==b: print(2*a-2) else: c=int((a*b)**0.5) if c*(c+1)>=a*b: print(2*c-2) elif c**2<a*b: print(2*c-1)
s073784356
Accepted
29
9,444
1,554
q=int(input()) ab=[list(map(int,input().split())) for _ in range(q)] from math import floor for a,b in ab: if a==b: print(2*a-2) else: t=floor((a*b)**0.5) # (1,2*t-1),(2,2*t-2),(3,(a*b-1)//3),...,(t-1,(a*b-1)//(t-1)) if t*t>=a*b: print(2*t-3) elif t*(t+1)>=a*b: print(2*t-2) else: print(2*t-1)
s861402313
p03943
u637175065
2,000
262,144
Wrong Answer
50
5,420
356
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.
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def II(): return int(input()) def S(): return input() def main(): a = LI() if sum(a) % 3 == 0: return 'YES' return 'NO' print(main())
s230274569
Accepted
73
6,976
360
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def II(): return int(input()) def S(): return input() def main(): a = LI() if sum(a) == max(a)*2: return 'Yes' return 'No' print(main())
s812386041
p03433
u243535639
2,000
262,144
Wrong Answer
17
2,940
89
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()) if n % 500 <= a: print("YES") else: print("NO")
s839523584
Accepted
17
2,940
89
n = int(input()) a = int(input()) if n % 500 <= a: print("Yes") else: print("No")
s513386354
p03719
u710907926
2,000
262,144
Wrong Answer
17
2,940
105
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a, b, c = [int(s) for s in input().split()] if c >= a and c <= b: print("YES") else: print("NO")
s427094396
Accepted
18
2,940
105
a, b, c = [int(s) for s in input().split()] if c >= a and c <= b: print("Yes") else: print("No")
s880593823
p03636
u031146664
2,000
262,144
Wrong Answer
17
2,940
64
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 = input() lis = [s[:1],str(len(s)),s[-1]] print("".join(lis))
s788224508
Accepted
17
2,940
66
s = input() lis = [s[:1],str(len(s)-2),s[-1]] print("".join(lis))
s238939680
p02388
u745214779
1,000
131,072
Wrong Answer
20
5,504
11
Write a program which calculates the cube of a given integer x.
x = 3 x**3
s169071276
Accepted
20
5,572
35
x = input() x = int(x) print(x**3)
s006487252
p03457
u985376351
2,000
262,144
Wrong Answer
535
28,068
418
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.
n = int(input()) p = [None]*n for i in range(n): p[i] = list(map(int,input().split())) plan = [[0,0,0]] plan.extend(p) for i in range(n): diff = [plan[i+1][k] - plan[i][k] for k in range(len(plan[0]))] if abs(diff[1])+abs(diff[2])>diff[0]: print('No') break elif diff[0]-(abs(diff[1])+abs(diff[2]))%2==1: print('No') break elif i==n-1: print('YES')
s331426231
Accepted
528
28,068
352
n = int(input()) p = [None]*n for i in range(n): p[i] = list(map(int,input().split())) plan = [[0,0,0]] plan.extend(p) for i in range(n): diff = [plan[i+1][k] - plan[i][k] for k in range(len(plan[0]))] if (abs(diff[1])+abs(diff[2]))>diff[0] or (diff[0]-(abs(diff[1])+abs(diff[2])))%2==1: print('No') exit() print('Yes')
s166293425
p03129
u112318601
2,000
1,048,576
Wrong Answer
28
9,136
65
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
n,k=map(int,input().split()) print("Yes" if (n+1)/2>=k else "No")
s170313872
Accepted
28
9,072
66
n,k=map(int,input().split()) print("YES" if (n+1)/2>=k else "NO")
s870315659
p04011
u000770457
2,000
262,144
Wrong Answer
20
2,940
139
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
x=[] for i in range(0,4): x.append(int(input())) s=0 for j in range(0,x[0]): if j+1<x[1]: s+=x[2] else: s+=x[3] print(s)
s655677980
Accepted
21
3,064
141
x=[] for i in range(0,4): x.append(int(input())) s=0 for j in range(0,x[0]): if j+1<=x[1]: s+=x[2] else: s+=x[3] print(s)
s739162806
p00511
u847467233
8,000
131,072
Wrong Answer
20
5,584
265
加減乗除の計算をする電卓プログラムを作りなさい. 入力データの各行には数と記号 +, -, *, /, = のどれか1つが交互に書いてある. 1行目は数である. 演算 +, -, *, / の優先順位(乗除算 *, / を加減算 +, - よりも先に計算すること)は考えず,入力の順序で計算し,= の行になったら,計算結果を出力する. 入力データの数値は108以下の正の整数とする. 計算中および計算結果は,0または負の数になることもあるが -108〜108 の範囲は超えない. 割り算は切り捨てとする. したがって,100/3*3= は 99 になる. 出力ファイルにおいては, 出力の最後の行にも改行コードを入れること.
# AOJ 0588: Simple Calculator # Python3 2018.6.30 bal4u a = int(input()) while True: op = input().strip() print(op) if op == '=': break b = int(input()) if op == '+': a += b elif s == '-': a -= b elif s == '*': a *= b else: a //= b print(a)
s956897530
Accepted
20
5,592
253
# AOJ 0588: Simple Calculator # Python3 2018.6.30 bal4u a = int(input()) while True: op = input().strip() if op == '=': break b = int(input()) if op == '+': a += b elif op == '-': a -= b elif op == '*': a *= b else: a //= b print(a)
s800354868
p03485
u045270305
2,000
262,144
Wrong Answer
175
13,556
231
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
import numpy as np from math import modf l = input().split() l = list(map(int, l)) mean = np.mean(l) decimal, integer = modf(mean) j = decimal * 10 if j >= 5 : res = integer + 1 else : res = integer print(res)
s323872978
Accepted
155
12,504
218
import numpy as np l = input().split() l = list(map(int, l)) mean = np.mean(l) integer = int(mean) decimal = mean - integer j = decimal * 10 if j >= 5 : res = integer + 1 else : res = integer print(res)
s951191061
p04043
u962170423
2,000
262,144
Wrong Answer
17
2,940
155
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
l,m,n = map(int,input().split()) cnt =0 if l == 5: cnt += 1 if m == 7: cnt += 1 if l == 5: cnt += 1 if cnt == 3: print("YES") else: print("NO")
s752196460
Accepted
17
2,940
97
l,m,n = map(int,input().split()) cnt = l+m+n if cnt == 17: print("YES") else: print("NO")
s258239201
p03387
u501643136
2,000
262,144
Wrong Answer
17
2,940
197
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
A, B, C = map(int, input().split()) if max(A,B,C)*3%2 == (A+B+C)%2: print((max(A,B,C)*3-(A+B+C))/2) else: print((max(A,B,C)*3+3-(A+B+C))/2)
s717105797
Accepted
17
3,064
207
A, B, C = map(int, input().split()) if max(A,B,C)*3%2 == (A+B+C)%2: print(int((max(A,B,C)*3-(A+B+C))/2)) else: print(int((max(A,B,C)*3+3-(A+B+C))/2))
s306886419
p00173
u814278309
1,000
131,072
Wrong Answer
30
5,588
76
会津学園高等学校では、毎年学園祭をおこなっています。その中でも一番人気はお化け屋敷です。一番人気の理由は、お化け屋敷をおこなうクラスが 1クラスや 2クラスではなく、9クラスがお化け屋敷をおこなうことです。それぞれが工夫することより、それぞれが個性的なお化け屋敷になっています。そのため、最近では近隣から多くの来場者が訪れます。 そこで、学園祭実行委員会では、お化け屋敷の入場料金を下表のように校内で統一し、これにもとづき各クラスごとに入場者総数と収入の集計をおこなうことにしました。 入場料金表(入場者 1人あたりの入場料) 午前 午後 200円 300円 各クラス毎の午前と午後の入場者数を入力とし、各クラス毎の入場者総数及び収入の一覧表を作成するプログラムを作成してください。
a,b,c=map(str,input().split()) print(a,int(b)+int(c),int(b)*200+int(c)*300)
s611636566
Accepted
20
5,608
127
for i in range(9): n,a,b = list(input().split()) x = int(a) + int(b) y = int(a)*200 + int(b)*300 print(f"{n} {x} {y}")
s198424210
p03673
u439396449
2,000
262,144
Wrong Answer
2,104
26,032
157
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
import sys input = sys.stdin.readline n = int(input()) a = [int(x) for x in input().split()] b = [] for ai in a: b.append(ai) b = b[::-1] print(b)
s907288767
Accepted
101
28,112
278
import sys from collections import deque input = sys.stdin.readline n = int(input()) a = input().split() b = deque([]) for i in range(n): if i % 2 == 0: b.append(a[i]) else: b.appendleft(a[i]) if n % 2 == 1: b = list(b)[::-1] print(' '.join(b))
s581867060
p03645
u953110527
2,000
262,144
Wrong Answer
584
6,320
327
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
n,m = map(int,input().split()) c = [False for i in range(200000)] d = [False for i in range(200000)] for i in range(m): a,b = map(int,input().split()) if a == 1: c[b] == True if b == n: d[a] = True for i in range(n): if c[i] and d[i]: print("POSSIBLE") exit() print("IMPOSSIBLE")
s850540463
Accepted
602
6,320
326
n,m = map(int,input().split()) c = [False for i in range(200000)] d = [False for i in range(200000)] for i in range(m): a,b = map(int,input().split()) if a == 1: c[b] = True if b == n: d[a] = True for i in range(n): if c[i] and d[i]: print("POSSIBLE") exit() print("IMPOSSIBLE")
s840084945
p03730
u646336933
2,000
262,144
Wrong Answer
18
3,060
155
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = [int(i) for i in input().split()] for i in range(1, b+1): if a*i % b == c: print("YES") break else: print("NO")
s207844417
Accepted
19
2,940
143
a, b, c = [int(i) for i in input().split()] for i in range(1, b+1): if a*i % b == c: print("YES") break else: print("NO")
s962604580
p02615
u524534026
2,000
1,048,576
Wrong Answer
151
31,388
143
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()) A=list(map(int,input().split())) A.sort() A.reverse() print(A) ans=0 for i in range(len(A)-1): ans+=A[i] print(ans)
s457671633
Accepted
213
32,296
246
from collections import deque n=int(input()) A=list(map(int,input().split())) A.sort() A.reverse() conf=[A[0]] ans=0 con=deque(conf) A.pop(0) for elem in A: ans+=con.popleft() for _ in range(2): con.append(elem) print(ans)
s288654701
p02388
u597483031
1,000
131,072
Wrong Answer
20
5,516
19
Write a program which calculates the cube of a given integer x.
x=2 print("x**2")
s141666041
Accepted
20
5,576
23
print(int(input())**3)
s434668295
p03565
u978783125
2,000
262,144
Wrong Answer
18
3,064
412
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
S = input() T = input() result = "UNRESTORABLE" b = True for i in range(len(S) - len(T) + 1): for j in range(len(T)): print("%d, %d" % (i, j)) if S[i + j] != T[j] and S[i + j] != "?": break if j == len(T) - 1: s = (S[:i] + T + S[i + len(T):]).replace("?", "a") if b or s < result: result = s b = False print(result)
s970640699
Accepted
17
3,060
379
S = input() T = input() result = "UNRESTORABLE" b = True for i in range(len(S) - len(T) + 1): for j in range(len(T)): if S[i + j] != T[j] and S[i + j] != "?": break if j == len(T) - 1: s = (S[:i] + T + S[i + len(T):]).replace("?", "a") if b or s < result: result = s b = False print(result)
s488079175
p03550
u143509139
2,000
262,144
Wrong Answer
18
3,188
150
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
n, z, w = map(int, input().split()) a = list(map(int, input().split())) if n == 1: print(abs(a[0] - w)) else: print(max(a[-1] - w, a[-1] - a[-2]))
s204192645
Accepted
18
3,188
161
n, z, w = map(int, input().split()) a = list(map(int, input().split())) if n == 1: print(abs(a[0] - w)) else: print(max(abs(a[-1] - w), abs(a[-1] - a[-2])))
s081219188
p02841
u553824105
2,000
1,048,576
Wrong Answer
17
2,940
74
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
a = input().split() c = input().split if a != c: print(1) else: print(0)
s532069485
Accepted
19
2,940
82
a = input().split() c = input().split() if a[0] != c[0]: print(1) else: print(0)
s107846575
p02261
u447562175
1,000
131,072
Wrong Answer
20
5,604
727
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 BubbleSort(C, N): for i in range(N): for j in range(N-1, i, -1): if C[j][1] < C[j-1][1]: C[j], C[j-1] = C[j-1], C[j] return C def SelectionSort(C, N): for i in range(N): minj = i for j in range(i, N): if C[j][1] < C[minj][1]: minj = j C[i], C[minj] = C[minj], C[i] return C def isStable(C1, C2, N): if C1 != C2: return "Stable" return "Not stable" Num = int(input()) Cards = [x for x in input().split()] card1 = BubbleSort(list(Cards), Num) card2 = SelectionSort(list(Cards), Num) print(" ".join(card1)) print(isStable(card1, card1, Num)) print(" ".join(card2)) print(isStable(card1, card2, Num))
s461690980
Accepted
20
5,612
727
def BubbleSort(C, N): for i in range(N): for j in range(N-1, i, -1): if C[j][1] < C[j-1][1]: C[j], C[j-1] = C[j-1], C[j] return C def SelectionSort(C, N): for i in range(N): minj = i for j in range(i, N): if C[j][1] < C[minj][1]: minj = j C[i], C[minj] = C[minj], C[i] return C def isStable(C1, C2, N): if C1 != C2: return "Not stable" return "Stable" Num = int(input()) Cards = [x for x in input().split()] card1 = BubbleSort(list(Cards), Num) card2 = SelectionSort(list(Cards), Num) print(" ".join(card1)) print(isStable(card1, card1, Num)) print(" ".join(card2)) print(isStable(card1, card2, Num))
s979410750
p03377
u011212399
2,000
262,144
Wrong Answer
18
2,940
84
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x = map(int,input().split()) print("Yes" if (a + b >= x) and (x >= a) else "No")
s637308688
Accepted
18
2,940
84
a,b,x = map(int,input().split()) print("YES" if (a + b >= x) and (x >= a) else "NO")
s161837250
p03623
u869728296
2,000
262,144
Wrong Answer
18
3,064
129
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
a=input().strip().split(" ") b=[int(i) for i in a] A=abs(b[0]-b[1]) B=abs(b[0]-b[2]) if(A>B): print(B) else: print(A)
s572164783
Accepted
18
2,940
133
a=input().strip().split(" ") b=[int(i) for i in a] A=abs(b[0]-b[1]) B=abs(b[0]-b[2]) if(A>B): print("B") else: print("A")
s560379269
p03946
u545368057
2,000
262,144
Wrong Answer
333
29,964
473
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples. Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows: * _Move_ : When at town i (i < N), move to town i + 1. * _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money. For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.) During the travel, Takahashi will perform actions so that the _profit_ of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel. Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i. Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
N,T = map(int, input().split()) As = list(map(int, input().split())) AsR = As[::-1] mxs = [] mx = 0 ind = 0 for i, a in enumerate(AsR): if a > mx: mx = a ind = N-i-1 mxs.append((mx,ind)) pairs = [] for a,mx in zip(As,mxs[::-1]): print(mx[0]-a,mx[1]) pairs.append((mx[0]-a,mx[1])) pairs.sort(reverse=True) mx = pairs[0][0] from collections import defaultdict ans = set() for x, i in pairs: if x != mx:break ans.add(i) print(len(ans))
s714675438
Accepted
204
28,260
476
N,T = map(int, input().split()) As = list(map(int, input().split())) AsR = As[::-1] mxs = [] mx = 0 ind = 0 for i, a in enumerate(AsR): if a > mx: mx = a ind = N-i-1 mxs.append((mx,ind)) pairs = [] for a,mx in zip(As,mxs[::-1]): # print(mx[0]-a,mx[1]) pairs.append((mx[0]-a,mx[1])) pairs.sort(reverse=True) mx = pairs[0][0] from collections import defaultdict ans = set() for x, i in pairs: if x != mx:break ans.add(i) print(len(ans))
s556859390
p02259
u424041287
1,000
131,072
Wrong Answer
20
5,596
328
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
def bubbleSort(A, N): t = 0 flag = 0 while flag == 0: flag = 1 for j in range(N - 1, 0, -1): if A[j] < A[j - 1]: A[j], A[j - 1] = A[j - 1], A[j] flag = 0 t += 1 n = int(input()) a = [int(i) for i in input().split()] print(bubbleSort(a, n))
s907385549
Accepted
20
5,604
423
def bubbleSort(A, N): s = 0 flag = 0 while flag == 0: flag = 1 for j in range(N - 1, 0, -1): if A[j] < A[j - 1]: A[j], A[j - 1] = A[j - 1], A[j] flag = 0 s += 1 t = str(A[0]) for i in range(1,N): t = t + " " + str(A[i]) print(t) print(s) n = int(input()) a = [int(i) for i in input().split()] bubbleSort(a, n)
s302180528
p03814
u896741788
2,000
262,144
Wrong Answer
18
3,512
55
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() a=s.index("A") b=s.rfind("z") print(s[a:b+1])
s550150623
Accepted
18
3,500
60
s=input() a=s.index("A") b=s.rfind("Z") print(len(s[a:b+1]))
s483821464
p02613
u820205438
2,000
1,048,576
Wrong Answer
157
16,556
246
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()) res=[] for i in range(n): res.append(input()) from collections import defaultdict cnt=defaultdict(int) cnt["AC"]=0 cnt["TLE"]=0 cnt["WA"]=0 cnt["RE"]=0 for i in res: cnt[i]+=1 for i in cnt.items(): print(i[0],"x",i[1])
s910733664
Accepted
164
16,544
256
n=int(input()) res=[] for i in range(n): res.append(input()) from collections import defaultdict cnt=defaultdict(int) cnt["AC"]=0 cnt["TLE"]=0 cnt["WA"]=0 cnt["RE"]=0 for i in res: cnt[i]+=1 for i in ["AC","WA","TLE","RE"]: print(i,"x",cnt[i])
s313781518
p03760
u736729525
2,000
262,144
Wrong Answer
17
3,060
123
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() A = [E, O] for i in range(len(O)+len(E)): j, r = divmod(i, 2) print(A[1-r],end="") print()
s688484816
Accepted
17
2,940
124
O = list(input()) E = list(input()) if len(O) > len(E): E.append("") print("".join(o+e for o, e in zip(O, E)))
s278494577
p03501
u769411997
2,000
262,144
Wrong Answer
17
2,940
87
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.
s = input() cnt = 0 for i in range(3): if s[i] == '1': cnt += 1 print(cnt)
s463752559
Accepted
17
2,940
82
n, a, b = map(int, input().split()) if n*a > b: print(b) else: print(n*a)
s064466774
p03478
u452015170
2,000
262,144
Wrong Answer
38
3,424
268
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()) sumdict = dict() for i in range(1, 37) : sumdict[i] = [] for i in range(1, n) : sumofi = sum([int(k) for k in list(str(i))]) sumdict[sumofi] += [i] ans = 0 for i in range(a, b + 1) : ans += sum(sumdict[i]) print(ans)
s997929159
Accepted
37
3,424
273
n, a, b = map(int, input().split()) sumdict = dict() for i in range(1, 37) : sumdict[i] = [0] for i in range(1, n + 1) : sumofi = sum([int(k) for k in list(str(i))]) sumdict[sumofi] += [i] ans = 0 for i in range(a, b + 1) : ans += sum(sumdict[i]) print(ans)
s801898236
p02261
u019011517
1,000
131,072
Wrong Answer
20
5,604
645
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
n = int(input()) *s1, = input().split() s2 = s1[:] def bubbleSort(s): flag = True while flag: flag = False for i in range(n-1): if int(s[i][1]) > int(s[i+1][1]): s[i],s[i+1] = s[i+1],s[i] flag = True return s def selectionSort(s): for i in range(n): minj = i for j in range(i+1,n): if int(s[minj][1]) > int(s[j][1]): minj = j s[i],s[minj] = s[minj],s[i] return s print(' '.join(bubbleSort(s1))) print("Stable") print(' '.join(selectionSort(s2))) if s1 == s2: print("Stable") else: print("Not Stable")
s856362107
Accepted
20
5,608
625
n = int(input()) a = [i for i in input().split()] b = [a[i] for i in range(n)] def bubbleSort(A): for i in range(n): for j in range(i+1,n)[::-1]: if int(A[j][1]) < int(A[j-1][1]): A[j], A[j-1] = A[j-1], A[j] return A def selectionSort(A): for i in range(n): minj = i for j in range(i,n): if int(A[j][1]) < int(A[minj][1]): minj = j A[i], A[minj] = A[minj], A[i] return A bubbleSort(a) selectionSort(b) print(' '.join(a)) print("Stable") print(' '.join(b)) if a == b: print("Stable") else: print("Not stable")
s665208869
p03795
u993642190
2,000
262,144
Wrong Answer
18
2,940
48
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N = int(input()) print(N * 800 - (N % 15) * 200)
s264172009
Accepted
18
2,940
49
N = int(input()) print(N * 800 - (N // 15) * 200)
s792894762
p02694
u536642030
2,000
1,048,576
Wrong Answer
23
9,168
136
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x = int(input()) count = 0 a = 100 while True: a *= 1.01 a = int(a) if int(a) >= x: break else: count += 1 print(count)
s097707403
Accepted
21
9,096
136
x = int(input()) count = 1 a = 100 while True: a *= 1.01 a = int(a) if int(a) >= x: break else: count += 1 print(count)
s541692968
p03351
u306142032
2,000
1,048,576
Wrong Answer
21
3,316
197
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) lst = [] lst.append(a) lst.append(b) lst.append(c) lst.sort() print(lst) if lst[2]-lst[1] <= d and lst[1]-lst[0] <= d: print("Yes") else: print("No")
s024461681
Accepted
17
2,940
130
a, b, c, d = map(int, input().split()) if abs(c-a) <= d or abs(c-b)<=d and abs(b-a) <= d: print("Yes") else: print("No")
s609623060
p03251
u525090128
2,000
1,048,576
Wrong Answer
18
3,064
300
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
# B N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) x.append(X) y.append(Y) ans = "War" Xmax = max(x) Ymin = min(y) # print("X",X) # print("Xmax",Xmax) # print("Ymin",Ymin) # 1 if Xmax < Ymin: ans = "No War" print("Ans",ans)
s409906543
Accepted
17
3,064
294
# B N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) x.append(X) y.append(Y) ans = "War" Xmax = max(x) Ymin = min(y) # print("X",X) # print("Xmax",Xmax) # print("Ymin",Ymin) # 1 if Xmax < Ymin: ans = "No War" print(ans)
s936844537
p03385
u503901534
2,000
262,144
Wrong Answer
17
2,940
160
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
n = str(input()) nl = list(n) nlset = set(nl) def check(onelist): if nlset == {'a','b','c'}: print('YES') else: print('NO') check(nlset)
s716969550
Accepted
17
2,940
160
n = str(input()) nl = list(n) nlset = set(nl) def check(onelist): if nlset == {'a','b','c'}: print('Yes') else: print('No') check(nlset)
s036726960
p03457
u635272634
2,000
262,144
Wrong Answer
348
27,380
321
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.
N = int(input()) txys = [list(map(int, input().split())) for _ in range(N) ] txys.insert(0, [0, 0, 0]) for i in range(N): dt = txys[i][0] - txys[i+1][0] dist = abs(txys[i][1] - txys[i+1][1]) + abs(txys[i][2] - txys[i+1][2]) if dt % 2 != dist % 2 or dist > dt: print("No") exit() print("Yes")
s793203541
Accepted
403
27,324
320
N = int(input()) txys = [list(map(int, input().split())) for _ in range(N) ] txys.insert(0, [0, 0, 0]) for i in range(N): t1, x1, y1 = txys[i] t2, x2, y2 = txys[i+1] dt = t2 - t1 dist = abs(x1 - x2) + abs(y1 - y2) if dt % 2 != dist % 2 or dist > dt: print("No") exit() print("Yes")
s766967283
p02612
u196940531
2,000
1,048,576
Wrong Answer
30
9,096
87
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("What does it cost?")) if N%1000==0: print(0) else: print(1000-N%1000)
s311794047
Accepted
28
9,112
68
N = int(input()) if N%1000==0: print(0) else: print(1000-N%1000)
s477465553
p03469
u917859896
2,000
262,144
Wrong Answer
17
2,940
155
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
while True: try: days = input().split("/") answer = days[0].replace("7", "8") print(answer) except EOFError: break
s404840581
Accepted
18
2,940
164
while True: try: days = input().split("/") days[0] = days[0].replace("7", "8") print("/".join(days)) except EOFError: break
s297093694
p03160
u957100216
2,000
1,048,576
Wrong Answer
136
13,980
209
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N = int(input()) h = list(map(int, input().split())) dp = [0] * (N) for i, _h in enumerate(h): if i > 1: dp[i] = min(dp[i - 1] + abs(_h - h[i - 1]), dp[i - 2] + abs(_h - h[i - 2])) print(dp[-1])
s803013044
Accepted
136
13,980
255
N = int(input()) h = list(map(int, input().split())) dp = [0] * (N) for i in range(1, N): if i > 1: dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2])) else: dp[i] = dp[i-1] + abs(h[i] - h[i-1]) print(dp[-1])
s186769474
p03377
u534953209
2,000
262,144
Wrong Answer
17
2,940
90
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A, B, X = map(int, input().split()) if A <= X <= A + B: print("Yes") else: print("No")
s018573873
Accepted
17
2,940
91
A, B, X = map(int, input().split()) if A <= X <= A + B: print("YES") else: print("NO")
s106782073
p03477
u580236524
2,000
262,144
Wrong Answer
17
2,940
136
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 = list(map(int, input().split())) l= a+b r= c+d if l<r: print('Right') elif l==r: print('Balanced') else: print('left')
s515483126
Accepted
17
3,060
129
a,b,c,d = map(int, input().split()) l= a+b r= c+d if l<r: print('Right') elif l==r: print('Balanced') else: print('Left')
s451851639
p02743
u867848444
2,000
1,048,576
Wrong Answer
19
2,940
107
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c=map(int,input().split()) if pow(a,0.5)+pow(a,0.5)<pow(c,0.5): print('Yes') else: print('No')
s936245123
Accepted
17
2,940
106
a,b,c=map(int,input().split()) if c-(a+b)>=0 and (a+b-c)**2>4*a*b: print('Yes') else: print('No')