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
s239672733
p02843
u972416428
2,000
1,048,576
Wrong Answer
117
15,120
150
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().strip()) valid = { 0: True } for i in range(1, n+1): valid[i] = any(valid.get(i-j, False) for j in range(100, 106)) print (valid[n])
s267224660
Accepted
118
15,124
162
n = int(input().strip()) valid = { 0: True } for i in range(1, n+1): valid[i] = any(valid.get(i-j, False) for j in range(100, 106)) print (1 if valid[i] else 0)
s880381727
p03494
u831081653
2,000
262,144
Wrong Answer
17
3,060
236
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.
a = list(map(int, input().split())) count = 0 flag = 1 while flag == 1: b = list(map(lambda x: x % 2, a)) if b.count(1) == 0: a = list(map(lambda x: x / 2, a)) count += 1 else: flag = 0 print(count)
s162710557
Accepted
19
3,060
271
n = int(input()) a = list(map(int, input().split())) cnt = 0 flag = True while flag: ans = [] for i in a: if i % 2 == 1: flag = False else: ans.append(i/2) if len(ans) == n: cnt += 1 a = ans print(cnt)
s516923132
p02678
u465900169
2,000
1,048,576
Wrong Answer
730
37,140
459
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
from collections import deque N, M = map(int, input().split()) G = [[] for i in range(N)] R = [0]*N for m in range(M): A,B = map(int, input().split()) G[A-1].append(B-1) G[B-1].append(A-1) d = deque() for n in G[0]: d.append(n) R[n]=1 while len(d)>0: i = d.popleft() for j in range(len(G[i])): if R[G[i][j]] == 0 and G[i][j]!=0: d.append(G[i][j]) R[G[i][j]]=i+1 for n in range(1,N): print(R[n])
s872932160
Accepted
822
37,208
558
import sys from collections import deque N, M = map(int, input().split()) G = [[] for i in range(N)] R = [0]*N for m in range(M): A,B = map(int, input().split()) G[A-1].append(B-1) G[B-1].append(A-1) d = deque() for n in G[0]: d.append(n) R[n]=1 while len(d)>0: i = d.popleft() for j in range(len(G[i])): if R[G[i][j]] == 0 and G[i][j]!=0: d.append(G[i][j]) R[G[i][j]]=i+1 for n in range(1,N): if R[n]==0: print("No") sys.exit() print("Yes") for n in range(1,N): print(R[n])
s875747782
p02398
u501414488
1,000
131,072
Wrong Answer
30
6,724
133
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
(a, b, c) = [int(i) for i in input().split()] cnt = 0 for i in range(a, b + 1): if (c % 1) == 0: cnt = cnt + 1 print(cnt)
s014246180
Accepted
30
6,728
133
(a, b, c) = [int(i) for i in input().split()] cnt = 0 for i in range(a, b + 1): if (c % i) == 0: cnt = cnt + 1 print(cnt)
s584852370
p03456
u629350026
2,000
262,144
Wrong Answer
18
3,060
204
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a,b=map(int,input().split()) if b==100: s=a*1000+b elif b>=10: s=a*100+b else: s=a*10+b j=1 temp=0 while j**2<s: if j**2==s: print("Yes") temp=1 break j=j+1 if temp==0: print("No")
s030241111
Accepted
18
3,064
205
a,b=map(int,input().split()) if b==100: s=a*1000+b elif b>=10: s=a*100+b else: s=a*10+b j=1 temp=0 while j**2<=s: if j**2==s: print("Yes") temp=1 break j=j+1 if temp==0: print("No")
s654089398
p03548
u146346223
2,000
262,144
Wrong Answer
24
9,152
50
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
x,y,z=map(int,input().split()) print(x//((y+z)+z))
s478317909
Accepted
29
9,156
52
x,y,z=map(int,input().split()) print((x-z) // (y+z))
s217392048
p03162
u578850957
2,000
1,048,576
Wrong Answer
559
33,396
544
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()) siawaseList = [list(map(int,input().split())) for _ in range(N)] dp = [[0]*3]*N dp[0][0] = siawaseList[0][0] dp[0][1] = siawaseList[0][1] dp[0][2] = siawaseList[0][2] for i in range(1,N): dp[i][0] = max(dp[i-1][1]+siawaseList[i][0],dp[i-1][2]+siawaseList[i][0]) dp[i][1] = max(dp[i-1][0]+siawaseList[i][1],dp[i-1][2]+siawaseList[i][1]) dp[i][2] = max(dp[i-1][0]+siawaseList[i][2],dp[i-1][1]+siawaseList[i][2]) print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))
s451474985
Accepted
634
47,344
576
N = int(input()) siawaseList = [list(map(int,input().split())) for _ in range(N)] dp = [[0 for _ in range(3)] for __ in range(N)] dp[0][0] = siawaseList[0][0] dp[0][1] = siawaseList[0][1] dp[0][2] = siawaseList[0][2] for i in range(1,N): dp[i][0] = max(dp[i-1][1]+siawaseList[i][0],dp[i-1][2]+siawaseList[i][0]) dp[i][1] = max(dp[i-1][0]+siawaseList[i][1],dp[i-1][2]+siawaseList[i][1]) dp[i][2] = max(dp[i-1][0]+siawaseList[i][2],dp[i-1][1]+siawaseList[i][2]) print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))
s438032979
p03493
u655427167
2,000
262,144
Wrong Answer
17
2,940
227
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.
if __name__ == '__main__': # line = str(input()) line = '000' count = 0 if line[0] == '1': count += 1 if line[1] == '1': count += 1 if line[2] == '1': count += 1 print(count)
s289183268
Accepted
19
2,940
209
if __name__ == '__main__': line = str(input()) count = 0 if line[0] == '1': count += 1 if line[1] == '1': count += 1 if line[2] == '1': count += 1 print(count)
s779459066
p03944
u074220993
2,000
262,144
Wrong Answer
30
9,132
432
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
W, H, N = map(int, input().split()) x_min, x_max, y_min, y_max = 0, H, 0, W for i in range(N): x, y, a = map(int, input().split()) if a == 1 and x > x_min: x_min = x elif a == 2 and x < x_max: x_max = x elif a == 3 and y > y_min: y_min = y elif a == 4 and y < y_max: y_max = y if x_max > x_min and y_max > y_min: S = (x_max - x_min) * (y_max - y_min) else: S = 0 print(S)
s012017321
Accepted
28
9,156
313
W, H, N = map(int, input().split()) u, U, v, V = 0, W, 0, H for _ in range(N): x, y, a = map(int,input().split()) if a == 1: u = max(u,x) if a == 2: U = min(U,x) if a == 3: v = max(v,y) if a == 4: V = min(V,y) f = lambda x:x if x > 0 else 0 print(f(U-u)*f(V-v))
s310197064
p03407
u663710122
2,000
262,144
Wrong Answer
17
3,064
71
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.
A, B, C = map(int, input().split()) print('Yes' if A+B == C else 'No')
s567497694
Accepted
17
2,940
71
A, B, C = map(int, input().split()) print('Yes' if A+B >= C else 'No')
s313620360
p03637
u781262926
2,000
262,144
Wrong Answer
159
14,052
281
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, *A = map(int, open(0).read().split()) def f(q): y = 0 while True: q, r = divmod(q, 2) if r == 1: break y += 1 return y B = [0] * 3 for a in A: b = f(a) B[0] += b == 0 B[1] += b == 1 B[2] += b >= 2 print('Yes' if B[0] + B[1]%2 <= B[2] else 'No')
s787629313
Accepted
163
14,052
283
n, *A = map(int, open(0).read().split()) def f(x): y = 0 q, r = divmod(x, 2) while r == 0: y += 1 q, r = divmod(q, 2) return y B = [0] * 3 for a in A: b = f(a) B[0] += b == 0 B[1] += b == 1 B[2] += b >= 2 print('Yes' if B[0] + (B[1]!=0) <= B[2]+1 else 'No')
s402186646
p02396
u801535964
1,000
131,072
Wrong Answer
130
5,612
98
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
i = 1 while True: x = int(input()) if (x == 0): break print(f"Case {i}: {x}")
s750157838
Accepted
130
5,612
107
i = 1 while True: x = int(input()) if (x == 0): break print(f"Case {i}: {x}") i+=1
s424512301
p03371
u107091170
2,000
262,144
Wrong Answer
21
3,060
158
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A,B,C,X,Y=map(int, input().split()) ans = 500000000 ans = min(ans, A*X+B*Y) ans = min(ans, C*min(X,Y)) ans = min(ans, (A+B)*min(X,Y)+C*(abs(X-Y))) print(ans)
s493062839
Accepted
110
3,064
155
A,B,C,X,Y=map(int, input().split()) ans = 50000000000 for i in range( max(X,Y)+1 ): ans = min(ans, C*i*2 + A*(max(0,(X-i)))+B*(max(0,(Y-i)))) print(ans)
s405569920
p03477
u763280125
2,000
262,144
Wrong Answer
32
8,956
133
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 = input().split() if A + B > C + D: print('Left') elif A + B < C + D: print('Right') else: print('Balanced')
s405798949
Accepted
22
9,032
157
I = input().split() A, B, C, D = [int(i) for i in I] if A + B > C + D: print('Left') elif A + B < C + D: print('Right') else: print('Balanced')
s458246524
p03605
u696449926
2,000
262,144
Wrong Answer
18
3,060
197
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
a = list(map(int, input().split())) if(len(a) == 2): if(a[0] == 9): print('Yes') elif(a[1] == 9): print('Yes') else: print('No') else: if(a[0] == 9): print('Yes') else: print('No')
s450140829
Accepted
17
3,060
195
a = list(map(int, list(input()))) if(len(a) == 2): if(a[0] == 9): print('Yes') elif(a[1] == 9): print('Yes') else: print('No') else: if(a[0] == 9): print('Yes') else: print('No')
s654520817
p03730
u234631479
2,000
262,144
Wrong Answer
20
3,444
119
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 = map(int, input().split()) print(a,b,c) for i in range(1,10000): if a*i%b == c: print("YES") print("NO")
s727473774
Accepted
17
3,060
223
a, b, c = map(int, input().split()) L = [] for i in range(1, b+1): L.append(a*i%b) L2 = list(set(L)) for i in range(len(L2)): for k in range(len(L2)): if L2[i]+L2[k] == c: print("YES") quit() print("NO")
s800370615
p03401
u118019047
2,000
262,144
Wrong Answer
2,108
12,252
398
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
n = int(input()) a = input().split() b = 0 answer = [] for i in range(n): b=0 if i == 0: box = a[i] a[i] = 0 else: box = a[i] a[i] = int(a[i-1]) b = int(a[0]) for j in range(n-1): b += abs(int(a[j]) - int(a[j+1])) b += abs(int(a[n-1])) a[i] = box answer.append(b) print(a) for k in range(len(answer)): print(answer[k])
s174130196
Accepted
229
14,048
272
n=int(input()) a=list(map(int,input().split())) a.insert(0,0) a.insert(n+1,0) total=0 for i in range(1,n+2): total+=abs(a[i]-a[i-1]) for i in range(1,n+1): ans=total-(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))+abs(a[i+1]-a[i-1]) print(ans)
s555435993
p03486
u642528832
2,000
262,144
Wrong Answer
26
8,960
142
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.
s = input() t = input() sr = sorted(s) tr = sorted(t,reverse = True) print(sr) print(tr) if sr < tr: print('Yes') else: print('No')
s270461731
Accepted
28
9,004
144
s = input() t = input() sr = sorted(s) tr = sorted(t,reverse = True) #print(sr) #print(tr) if sr < tr: print('Yes') else: print('No')
s187609331
p03543
u436110200
2,000
262,144
Wrong Answer
17
2,940
72
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
s=input() print("YES" if s[0]==s[1]==s[2] or s[1]==s[2]==s[3] else "NO")
s229536255
Accepted
18
2,940
72
s=input() print("Yes" if s[0]==s[1]==s[2] or s[1]==s[2]==s[3] else "No")
s495859459
p02422
u179070318
1,000
131,072
Wrong Answer
20
5,596
366
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
string = input() n = int(input()) for i in range(n): inp = [x for x in input().split()] a = int(inp[1]) b = int(inp[2]) if inp[0] == 'print': print(string[a-1:b]) elif inp[0] == 'reverse': string = string[:a-1] + string[a-1:b][::-1] +string[b:] elif inp[0] == 'replace': string = string.replace(string[a-1:b],inp[3])
s163878541
Accepted
20
5,620
359
string = input() for _ in range(int(input())): com = [x for x in input().split()] c = com[0] a,b = [int(com[i]) for i in range(1,3)] if c == 'reverse': string = string[:a] + string[a:b+1][::-1] + string[b+1:] if c == 'print': print(string[a:b+1]) if c == 'replace': string = string[:a] + com[3] + string[b+1:]
s244254256
p04035
u591287669
2,000
262,144
Wrong Answer
224
14,152
361
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
n,l=map(int,input().split()) arr=list(map(int,input().split())) psbl=False pos=0 for i in range(n-1): if arr[i]+arr[i+1]>=l: psbl=True pos=i break print(pos) if psbl: print("Possible") for i in range(0,pos): print(i+1) for i in range(n-2,pos,-1): print(i+1) print(pos+1) else: print("Impossible")
s089114431
Accepted
221
14,204
350
n,l=map(int,input().split()) arr=list(map(int,input().split())) psbl=False pos=0 for i in range(n-1): if arr[i]+arr[i+1]>=l: psbl=True pos=i break if psbl: print("Possible") for i in range(0,pos): print(i+1) for i in range(n-2,pos,-1): print(i+1) print(pos+1) else: print("Impossible")
s079135750
p03598
u732870425
2,000
262,144
Wrong Answer
18
3,060
236
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()) X = list(map(int, input().split())) sum_len = 0 for i in range(len(X)): if abs(N-X[i]) < abs(K-X[i]): sum_len += abs(N-X[i]) * 2 else: sum_len += abs(K-X[i]) * 2 print(sum_len)
s920836998
Accepted
17
3,060
222
N = int(input()) K = int(input()) X = list(map(int, input().split())) sum_len = 0 for i in range(len(X)): if X[i] < abs(K-X[i]): sum_len += X[i] * 2 else: sum_len += abs(K-X[i]) * 2 print(sum_len)
s944062385
p02613
u409371339
2,000
1,048,576
Wrong Answer
149
16,324
387
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) s = [input() for _ in range(n)] numAC = 0 numWA = 0 numTLE = 0 numRE = 0 for i in s: if i == "AC": numAC += 1 elif i == "WA": numWA += 1 elif i == "TLE": numTLE += 1 elif i == "RE": numRE += 1 print("AC × " + str(numAC)) print("WA × " + str(numWA)) print("TLE × " + str(numTLE)) print("RE × " + str(numRE))
s479684347
Accepted
153
16,332
384
n = int(input()) s = [input() for _ in range(n)] numAC = 0 numWA = 0 numTLE = 0 numRE = 0 for i in s: if i == "AC": numAC += 1 elif i == "WA": numWA += 1 elif i == "TLE": numTLE += 1 elif i == "RE": numRE += 1 print("AC x " + str(numAC)) print("WA x " + str(numWA)) print("TLE x " + str(numTLE)) print("RE x " + str(numRE))
s411726502
p02578
u770018088
2,000
1,048,576
Wrong Answer
186
32,176
163
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
N = int(input()) A = list(map(int, input().strip().split())) ans = 0 for i in range(1, N): ans += max(0, A[i] - A[i - 1]) A[i] = max(A[i], A[i - 1]) print(ans)
s088041686
Accepted
145
32,288
171
N = int(input()) A = list(map(int, input().strip().split())) ans = 0 for i in range(1, N): if A[i] < A[i - 1]: ans += A[i - 1] - A[i] A[i] = A[i - 1] print(ans)
s123406077
p02392
u655879321
1,000
131,072
Wrong Answer
20
5,584
95
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a, b, c = map(int, input().split()) if a > b and b > c: print('Yes') else: print('No')
s723441003
Accepted
20
5,584
95
a, b, c = map(int, input().split()) if a < b and b < c: print('Yes') else: print('No')
s508817499
p03192
u359474860
2,000
1,048,576
Wrong Answer
17
2,940
24
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N?
N = input() N.count("2")
s441181030
Accepted
17
2,940
31
N = input() print(N.count("2"))
s350541139
p02612
u247680229
2,000
1,048,576
Wrong Answer
30
9,148
38
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()) ans=N%1000 print(ans)
s279651929
Accepted
29
9,160
116
N=int(input()) if N%1000==0: print(0) exit() elif N>=1000: print(1000-N%1000) elif N<1000: print(1000-N)
s194481997
p02422
u480053997
1,000
131,072
Wrong Answer
30
7,548
316
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
s = input() for i in range(int(input())): print(s) q = input().split() op, a, b = q[0], int(q[1]), int(q[2]) if op == 'print': print(s[a : b+1]) elif op == 'reverse': t = s[a : b+1] s = s[:a] + t[::-1] + s[b+1:] elif op == 'replace': s = s[:a] + q[3] + s[b+1:]
s616408203
Accepted
60
7,728
303
s = input() for i in range(int(input())): q = input().split() op, a, b = q[0], int(q[1]), int(q[2]) if op == 'print': print(s[a : b+1]) elif op == 'reverse': t = s[a : b+1] s = s[:a] + t[::-1] + s[b+1:] elif op == 'replace': s = s[:a] + q[3] + s[b+1:]
s134481568
p03943
u143903328
2,000
262,144
Wrong Answer
17
2,940
176
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 = list(map(int, input().split())) sum = a[0] + a[1] + a[2] if sum - a[0] == sum / 2 or sum - a[0] == sum / 2 or sum - a[2] == sum / 2: print("Yes") else: print("No")
s060720231
Accepted
17
2,940
176
a = list(map(int, input().split())) sum = a[0] + a[1] + a[2] if sum - a[0] == sum / 2 or sum - a[1] == sum / 2 or sum - a[2] == sum / 2: print("Yes") else: print("No")
s656827717
p03569
u210827208
2,000
262,144
Wrong Answer
63
3,572
420
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly: * Insert a letter `x` to any position in s of his choice, including the beginning and end of s. Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
from collections import Counter S=input() if S==S[::-1]: print(0) else: X=Counter(S) if 'x' in X.keys() and len(X.keys())==2: cnt=0 ans=0 for s in S: if s!='x': cnt+=1 else: ans+=1 if cnt==-(-(len(S)-X['x'])//2): break print(max(ans,X['x']-ans)-min(ans,X['x']-ans)) else: print(0)
s841835623
Accepted
70
3,316
270
S=input() n=len(S) l=0 r=n-1 ans=0 while l+1<=r: if S[l]=='x' and S[l]!=S[r]: ans+=1 l+=1 elif S[r]=='x' and S[l]!=S[r]: ans+=1 r-=1 elif S[l]==S[r]: r-=1 l+=1 else: ans=-1 break print(ans)
s592557318
p03417
u626468554
2,000
262,144
Wrong Answer
17
2,940
52
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
n,m = map(int,input().split()) n-=1 m-=1 print(n*m)
s885362255
Accepted
17
2,940
143
n,m = map(int,input().split()) if n>=2 and m>=2: n-=2 m-=2 print(n*m) elif n==1 and m==1: print(1) else: print(max(n,m)-2)
s585170098
p02394
u748921161
1,000
131,072
Wrong Answer
50
7,568
211
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.
input_str = input().split(' ') W = int(input_str[0]) H = int(input_str[0]) x = int(input_str[0]) y = int(input_str[0]) r = int(input_str[0]) print('Yes' if x-r > 0 and x+r < W and y-r > 0 and y+r < H else 'No')
s974790994
Accepted
60
7,720
215
input_str = input().split(' ') W = int(input_str[0]) H = int(input_str[1]) x = int(input_str[2]) y = int(input_str[3]) r = int(input_str[4]) print('Yes' if x-r >= 0 and x+r <= W and y-r >= 0 and y+r <= H else 'No')
s822560554
p03598
u153823221
2,000
262,144
Wrong Answer
17
3,064
269
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()) x = list(map(int, input().split())) distance = [] for i in range(n): if abs(x[i] - 0) < abs(x[i] - k): distance.append(abs((x[i] - 0) * 2)) else: distance.append(abs((x[i] - k) * 2)) print(distance) print(sum(distance))
s631841480
Accepted
17
3,060
253
n = int(input()) k = int(input()) x = list(map(int, input().split())) distance = [] for i in range(n): if abs(x[i] - 0) < abs(x[i] - k): distance.append(abs((x[i] - 0) * 2)) else: distance.append(abs((x[i] - k) * 2)) print(sum(distance))
s322219170
p02613
u798260206
2,000
1,048,576
Wrong Answer
143
9,216
299
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()) AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(N): s = input() if s == "AC": AC += 1 elif s == "WA": WA += 1 elif s == "TLE": TLE +=1 else: RE += 1 print("AC × " + str(AC)) print("WA × " + str(WA)) print("TLE × " + str(TLE)) print("RE × " + str(RE))
s131302717
Accepted
141
9,208
295
N = int(input()) AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(N): s = input() if s == "AC": AC += 1 elif s == "WA": WA += 1 elif s == "TLE": TLE +=1 else: RE += 1 print("AC x " + str(AC)) print("WA x " + str(WA)) print("TLE x " + str(TLE)) print("RE x " + str(RE))
s657269100
p03795
u952708174
2,000
262,144
Wrong Answer
17
2,940
41
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(800*N - 200*N//15)
s281926702
Accepted
18
2,940
43
N = int(input()) print(800*N - 200*(N//15))
s196277813
p03855
u786020649
2,000
262,144
Wrong Answer
740
138,032
938
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
import sys from collections import deque from collections import defaultdict from collections import Counter def conn(n,m,e): d=dict(zip(range(1,n+1),range(1,n+1))) c=0 for edge in e: a=edge[0] b=edge[1] da=d[a] db=d[b] if da==m and db==m: d[a]=c d[b]=c c+=1 else: d[a]=min(da,db) d[b]=min(da,db) return d.values() def main(n,k,l,e1,e2): d1=conn(n,k,e1) d2=conn(n,l,e2) p=tuple(zip(iter(d1),iter(d2))) print(p) d=Counter(p) print(d) d[(k,l)]=1 print(' '.join([str(d[x]) for x in p])) if __name__=='__main__': ssr=sys.stdin.readline n,k,l=map(int,ssr().strip().split()) e1=[] e2=[] for _ in range(k): e1.append(tuple(map(int,ssr().strip().split()))) for _ in range(l): e2.append(tuple(map(int,ssr().strip().split()))) main(n,k,l,e1,e2)
s102059299
Accepted
970
191,464
3,413
import sys from collections import deque from collections import defaultdict from collections import Counter def conn(n,m,e): d=dict(zip(range(1,n+1),range(-1,(-1)*n-1,-1))) td=defaultdict(lambda:deque([])) c=1 for edge in e: a=edge[0] b=edge[1] da=d[a] db=d[b] if da<0 and db<0: d[a]=c d[b]=c td[c].append(a) td[c].append(b) c+=1 elif da>0 and db<0: d[b]=da td[d[a]].append(b) elif da<0 and db>0: d[a]=db td[d[b]].append(a) elif da>0 and db>0 and da!=db: for x in td[db]: d[x]=da td[da].append(x) return list(d.values()) # ed=defaultdict(lambda:deque()) # for edge in e: # ed[edge[0]].append(edge[1]) # c=0 # s=[0]*n # label=[0]*n # if s[i-1]==0: # c+=1 # label[c-1]=c # stack=deque([i]) # while stack: # w=stack.pop() # s[w-1]=c # while ed[w]: # wn=ed[w].pop() # if s[wn-1]==0: # s[wn-1]=c # if ed[wn]: # stack.append(w) # w=wn # elif s[wn-1]<c: # label[s[wn-1]-1]=c # print(s) # print(label) def components(n,k,e): ed=defaultdict(lambda:deque()) for edge in e: ed[edge[0]].append(edge[1]) ed[edge[1]].append(edge[0]) c=0 s=[0]*n stack=deque() for i in range(1,n+1): if s[i-1]==0: c+=1 stack.clear() stack.append(i) while stack: w=stack.pop() s[w-1]=c while ed[w]: wn=ed[w].pop() if s[wn-1]==0: s[wn-1]=c if ed[wn]: stack.append(w) w=wn return [s[i] for i in range(n)] def components2(n,k,e): es=deque(set((edge[0],edge[1])) for edge in e) c=0 s=deque() stack=deque() while es: f=es.pop() stack.clear() while es: l=len(es) g=es.pop() if g&f: f|=g else: stack.append(g) if l==len(stack): s.append(f) break es=stack t=[0]*n c=0 while s: for x in s.pop(): t[x-1]=c c+=1 return t def main(n,k,l,e1,e2): d1=components(n,k,e1) d2=components(n,l,e2) p=tuple(zip(iter(d1),iter(d2))) d=Counter(p) # print(d1,d2,d,p) print(' '.join([str(d[x]) for x in p])) if __name__=='__main__': ssr=sys.stdin.readline n,k,l=map(int,ssr().strip().split()) e1=[] e2=[] for _ in range(k): e1.append(tuple(map(int,ssr().strip().split()))) for _ in range(l): e2.append(tuple(map(int,ssr().strip().split()))) main(n,k,l,e1,e2)
s099246027
p02608
u075317232
2,000
1,048,576
Time Limit Exceeded
2,205
8,860
937
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
def XYZTriplets(): num = int(input()) for i in range(num): count = 0 x = 1 y = 1 z = 1 flag = True while flag == True: function = 0.5*( (x+y)*(x+y) + (y+z)*(y+z) + (z+x)*(z+x) ) - i if function == 0: if x == y and y == z and z == x: count = count + 1 else: count = count + 3 list_xyz = [x, y, z] if list_xyz.index(max(list_xyz)) == 0: x = x + 1 elif list_xyz.index(max(list_xyz)) == 1: y = y + 1 else: z = z + 1 if function > 0: print(count) break if __name__ == '__main__': XYZTriplets()
s772994456
Accepted
395
27,216
650
import math import numpy as np def XYZTriplets(): num = int(input()) list_num = [] count = [0]*num for i in range(1, num+1): list_num.append(i) for x in range(1, int(math.sqrt(num))): for y in range(1, int(math.sqrt(num))): for z in range(1, int(math.sqrt(num))): function = x*x + y*y + z*z + x*y + y*z + z*x if function <= num and function > 0: count[function-1] = count[function-1] + 1 for i in range(0, num): print(count[i]) if __name__ == '__main__': XYZTriplets()
s448432067
p04029
u888380104
2,000
262,144
Wrong Answer
24
9,124
49
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()) x = N * (N * 1) // 2 print(x)
s467933123
Accepted
25
9,152
49
N = int(input()) x = N * (N + 1) // 2 print(x)
s363242157
p02664
u932370518
2,000
1,048,576
Wrong Answer
69
9,528
310
For a string S consisting of the uppercase English letters `P` and `D`, let the _doctoral and postdoctoral quotient_ of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3. We have a string T consisting of `P`, `D`, and `?`. Among the strings that can be obtained by replacing each `?` in T with `P` or `D`, find one with the maximum possible doctoral and postdoctoral quotient.
if __name__ == "__main__": T = input() ans = "" for i in range(len(T)-1): if T[i] == '?': if T[i+1] == 'D': ans += 'P' else: ans += 'D' else: ans += T[i] if T[-1] == '?': ans += 'D' print(ans)
s155777421
Accepted
25
9,516
203
if __name__ == "__main__": T = input() ans = T ans = ans.replace("P?", 'PD') ans = ans.replace("??", 'PD') ans = ans.replace("?D", 'PD') ans = ans.replace("?", 'D') print(ans)
s828952405
p03150
u494058663
2,000
1,048,576
Wrong Answer
21
3,060
255
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
import sys S = list(input()) Ans_list=['k','e','y','e','n','c','e'] Ans = 0 for i in range(len(S)): for j in range(i,len(S),+1): if (S[:i:]+S[j::]) == Ans_list: Ans = 1 print(Ans) sys.exit() print(Ans)
s254480392
Accepted
21
3,060
263
import sys S = list(input()) Ans_list=['k','e','y','e','n','c','e'] Ans = 'NO' for i in range(len(S)): for j in range(i,len(S),+1): if (S[:i:]+S[j::]) == Ans_list: Ans = 'YES' print(Ans) sys.exit() print(Ans)
s614863539
p02608
u821432765
2,000
1,048,576
Wrong Answer
854
9,372
240
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
N = int(input()) F = [0]*(N+1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): c = x**2 + y**2 + z**2 + x*y + y*z + z*x if (c <= N): F[c] += 1 print(*F, sep='\n')
s487939477
Accepted
873
9,204
244
N = int(input()) F = [0]*(N+1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): c = x**2 + y**2 + z**2 + x*y + y*z + z*x if (c <= N): F[c] += 1 print(*F[1:], sep='\n')
s257364945
p03814
u994521204
2,000
262,144
Wrong Answer
18
3,500
41
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s=input() print(s.find('A')-s.rfind('Z'))
s202835233
Accepted
17
3,500
43
s=input() print(s.rfind('Z')-s.find('A')+1)
s568760535
p03469
u600789379
2,000
262,144
Wrong Answer
27
9,004
31
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.
print('2018/01' + input()[-2:])
s832959228
Accepted
29
9,044
32
print('2018/01/' + input()[-2:])
s089917790
p02865
u420399048
2,000
1,048,576
Wrong Answer
17
2,940
95
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
def f(N): if N%2==0: return N//2-1 else: return N//2 N=int(input()) print(f(N))
s844946917
Accepted
17
2,940
103
def f(N): if N%2==0: return N//2-1 else: return N//2 N=int(input()) print(f(N))
s078975031
p02850
u875291233
2,000
1,048,576
Wrong Answer
244
34,004
825
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
def top_sort_tree(g,root): n = len(g) parent = [-1]*n top_order = [-1]*n pos = 0 from collections import deque q = deque([root]) while q: v = q.pop() top_order[pos] = v pos += 1 for c in g[v]: if c != parent[v]: parent[c] = v q.append(c) return top_order ##################################### # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines #n = int(input()) #ab = [[int(i) for i in readline().split()] for _ in range(n)] n = int(input()) ab = map(int,read().split()) g = [[] for _ in range(n)] for a,b in zip(ab,ab): g[a-1].append(b-1) g[b-1].append(a-1) #print(g) print(top_sort_tree(g,0)[0])
s542407510
Accepted
531
77,784
678
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline n = int(input()) g = [[] for _ in range(n)] d = {} for i in range(n-1): a,b = [int(i) for i in readline().split()] d[(a-1,b-1)] = i g[a-1].append(b-1) g[b-1].append(a-1) def dfs(v,p,j): #p: parent of v num = -1 for c in g[v]: if c == p: continue num += 1 col = (j+num)%m+1 if c > v: ans[d[(v,c)]] = col else: ans[d[(c,v)]] = col dfs(c,v,col) m = max(len(i) for i in g) ans = [0]*(n-1) dfs(0,-1,0) #print(g,m,ans) print(m) print(*ans,sep = "\n")
s439076150
p03470
u686036872
2,000
262,144
Wrong Answer
18
3,188
69
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
N=int(input()) list=[int(input()) for i in range(N)] print(len(list))
s517493614
Accepted
20
3,060
95
N = int(input()) list=[] for i in range(N): list.append(int(input())) print(len(set(list)))
s541758868
p03339
u072717685
2,000
1,048,576
Wrong Answer
319
40,176
547
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
import sys read = sys.stdin.read from itertools import accumulate def main(): n = int(input()) s = list(input()) e = [0] * n w = [0] * n for i1 in range(n): e[i1] = s[i1] == 'E' w[i1] = s[i1] == 'W' e.insert(0, 0) e.append(0) w.insert(0, 0) w.append(0) ea = list(accumulate(e)) wa = list(accumulate(w)) rt = 0 for j1 in range(1, n): rt = max(rt, ea[j1 - 1] + (wa[-1] - wa[j1])) print(j1, rt) r = n - rt - 1 print(r) if __name__ == '__main__': main()
s016524921
Accepted
173
51,768
568
import sys read = sys.stdin.read readlines = sys.stdin.readlines from itertools import accumulate def main(): n = int(input()) s = list(input()) enum = [1 if c == 'E' else 0 for c in s] wnum = [1 if c == 'W' else 0 for c in s] enuma = tuple(accumulate(enum)) wnuma = tuple(accumulate(wnum)) wnumm = wnuma[-1] wnuma2 = [wnumm - wn for wn in wnuma] num = max(wnuma2[0], enuma[-2]) for i1 in range(1, n - 1): num = max(num, enuma[i1 - 1] + wnuma2[i1]) r = n - num - 1 print(r) if __name__ == '__main__': main()
s092992397
p03971
u545644875
2,000
262,144
Wrong Answer
20
3,956
517
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.
x = list(map(int, input().split())) s = list(input()) y = len(s) rank = 0 frank = 0 for i in (0,y - 1): if s[i] == "c": print("NO") elif s[i] == "b": if rank < x[1] + x[2] and frank < x[2]: rank += 1 frank += 1 print("YES") else: print("NO") else: if rank < x[1] + x[2]: rank += 1 print("YES") else: print("NO")
s904565999
Accepted
112
4,708
489
li = list(map(int,input().split())) s=list(input()) cnt = 0 b = 0 for i in s: if i == "a": if cnt < li[1] + li[2]: cnt += 1 print("Yes") else: print("No") elif i == "b": b += 1 if cnt < li[1] + li[2]: if b <= li[2]: cnt += 1 print("Yes") else: print("No") else: print("No") else: #cnt -= 1 print("No")
s754710764
p00523
u847467233
8,000
262,144
Wrong Answer
30
5,608
607
JOI 君は妹のJOI 子ちゃんとJOI 美ちゃんと一緒におやつを食べようとしている.今日のおやつは3 人の大好物のバームクーヘンだ. バームクーヘンは下図のような円筒形のお菓子である.3 人に分けるために,JOI 君は半径方向に刃を3回入れて,これを3 つのピースに切り分けなければならない.ただしこのバームクーヘンは本物の木材のように固いので,刃を入れるのは簡単ではない.そのためこのバームクーヘンにはあらかじめ $N$ 個の切れ込みが入っており,JOI 君は切れ込みのある位置でのみ切ることができる.切れ込みに1 から $N$ まで時計回りに番号をふったとき,$1 \leq i \leq N - 1$ に対し, $i$ 番目の切れ込みと$i + 1$ 番目の切れ込みの間の部分の大きさは $A_i$ である.また $N$ 番目の切れ込みと1 番目の切れ込みの間の部分の大きさは $A_N$ である. 図1: バームクーヘンの例 $N = 6, A_1 = 1, A_2 = 5, A_3 = 4, A_4 = 5, A_5 = 2, A_6 = 4$
# Python3 2018.7.3 bal4u import sys from sys import stdin input = stdin.readline n = int(input()) a = [int(input()) for i in range(n)] su = sum(a) p = [0]*(n+1) s = [0]*(n+1) print("a=",a) l, r = 0, su+1 while l + 1 < r: m = (l+r) >> 1 for i in range(0, n): if i == 0: s[i] = p[i] = 0 else: p[i] = p[i-1] - 1 s[i] = s[i-1] - a[i-1] while s[i] < m: ii = i + p[i]; if ii >= n: ii -= n s[i] += a[ii] p[i] += 1 f = 0 for i in range(n): ii = i + p[i]; if ii >= n: ii -= n if su-s[i]-s[ii] >= m: f = 1 break if f: l = m else: r = m print(l)
s934696176
Accepted
9,330
18,072
593
# Python3 2018.7.3 bal4u import sys from sys import stdin input = stdin.readline n = int(input()) a = [int(input()) for i in range(n)] su = sum(a) p = [0]*(n+1) s = [0]*(n+1) l, r = 0, su+1 while l + 1 < r: m = (l+r) >> 1 for i in range(0, n): if i == 0: s[i] = p[i] = 0 else: p[i] = p[i-1] - 1 s[i] = s[i-1] - a[i-1] while s[i] < m: ii = i + p[i]; if ii >= n: ii -= n s[i] += a[ii] p[i] += 1 f = 0 for i in range(n): ii = i + p[i]; if ii >= n: ii -= n if su-s[i]-s[ii] >= m: f = 1 break if f: l = m else: r = m print(l)
s504709197
p03729
u155251346
2,000
262,144
Wrong Answer
31
8,972
121
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() if list(A[-1])==list(B[0]) and list(B[-1])==list(C[0]): print("Yes") else: print("No")
s291858671
Accepted
31
9,088
128
A, B, C = input().split() if A[-1]==B[0] and B[-1]==C[0]: print("YES") else: print("NO")
s579561120
p03827
u629540524
2,000
262,144
Wrong Answer
30
9,092
156
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() x = 0 y = 0 for i in range(n): if s[i] == 'I': y += 1 else: y -= 1 if y > 0: x = y print(x)
s435914044
Accepted
29
8,996
156
n = int(input()) s = input() x = 0 y = 0 for i in range(n): if s[i] == 'I': y += 1 else: y -= 1 if y > x: x = y print(x)
s750344090
p03721
u813102292
2,000
262,144
Wrong Answer
398
11,372
283
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
#ABC061 n,k = (int(i) for i in input().split()) a = [] b = [] for i in range(n): tmp = list(int(i) for i in input().split()) a.append(tmp[0]) b.append(tmp[1]) tmp = 0 tmp_i = 0 for i in range(n): tmp += b[i] if tmp>=n: tmp_i = i break print(a[i])
s462813796
Accepted
463
15,064
435
#ABC061 N,K = (int(i) for i in input().split()) a = {} for i in range(N): tmp = list(int(i) for i in input().split()) if not tmp[0] in a.keys(): a[tmp[0]] = tmp[1] else: a[tmp[0]] += tmp[1] ans_array = [] for k,v in a.items(): ans_array.append((k,v)) ans_array = sorted(ans_array) count = 0 for i in range(N): count += ans_array[i][1] if count>=K: print(ans_array[i][0]) break
s941623718
p02842
u343128979
2,000
1,048,576
Wrong Answer
18
2,940
310
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
import math def inputs(): return [int(s) for s in input().split()] def main(): N = int(input()) v = math.ceil(N / 1.08) print(v) print(math.floor(v * 1.08)) if math.floor(v * 1.08) == N: return v else: return ':(' if __name__ == '__main__': print(main())
s101461089
Accepted
19
2,940
266
import math def inputs(): return [int(s) for s in input().split()] def main(): N = int(input()) v = math.ceil(N / 1.08) if math.floor(v * 1.08) == N: return v else: return ':(' if __name__ == '__main__': print(main())
s493119901
p02393
u661529494
1,000
131,072
Wrong Answer
30
7,548
51
Write a program which reads three integers, and prints them in ascending order.
A=list(map(int, input().split())) A.sort() print(A)
s520257652
Accepted
50
7,616
64
A=list(map(int, input().split())) A.sort() print(A[0],A[1],A[2])
s319068688
p03478
u033642300
2,000
262,144
Wrong Answer
33
3,776
421
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).
def main(): N, A, B = map(int, input().split()) list = [] for i in range(N + 1): if 10 < i: temp = str(i) ai = int(temp[0]) bi = int(temp[1]) if A - 1 < ai + bi < B + 1: print(i) list.append(i) else: if A - 1 < i < B + 1: print(i) list.append(i) print(sum(list)) main()
s735236873
Accepted
41
9,172
253
def main(): N, A, B = map(int, input().split()) ans = 0 for i in range(N+1): tw = str(i) tn = 0 for j in range(len(tw)): tn += int(tw[j]) if A <= tn <= B: ans += i print(ans) main()
s691304510
p03504
u296150111
2,000
262,144
Wrong Answer
363
3,828
186
Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
n,c=map(int,input().split()) time=[0]*(10**5) for i in range(n): s,t,c=map(int,input().split()) time[s-1]+=1 time[t-1]-=1 for i in range(10**5-1): time[i+1]+=time[i] print(max(time))
s202537498
Accepted
588
28,472
474
from itertools import accumulate n,c=map(int,input().split()) time=[0]*(10**5+2) stc=[] for i in range(n): s,t,c=map(int,input().split()) stc.append([s,t,c]) stc.sort(key=lambda x:(x[2],x[0])) for i in range(n-1): if stc[i][2]==stc[i+1][2]: if stc[i][1]==stc[i+1][0]: stc[i+1][0]=stc[i][0] stc[i]=[-1] lis=[] for i in range(n): if stc[i]!=[-1]: lis.append(stc[i]) for i in range(len(lis)): time[lis[i][0]-1]+=1 time[lis[i][1]]-=1 print(max(accumulate(time)))
s751306450
p03378
u368796742
2,000
262,144
Wrong Answer
17
3,060
140
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
import bisect n,m,x = map(int,input().split()) l = list(map(int,input().split())) index = bisect.bisect_left(l,x) print(min(index,n-index))
s380420199
Accepted
17
2,940
141
import bisect n,m,x = map(int,input().split()) l = list(map(int,input().split())) index = bisect.bisect_left(l,x) print(min(index,m-index))
s527651887
p02612
u206570055
2,000
1,048,576
Wrong Answer
27
9,060
26
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(int(input()) % 1000)
s440372611
Accepted
32
9,060
82
ans = int(input()) % 1000 if ans == 0: print(0) exit(0) print(1000 - ans)
s036701518
p03861
u535659144
2,000
262,144
Wrong Answer
2,104
3,064
112
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?
x = list(map(int,input().split())) a = 0 for i in range(x[0],x[1]): if i % x[2]==0: a = a+1 print(a)
s608016183
Accepted
17
2,940
142
x = list(map(int,input().split())) a = 0 if x[0]%x[2]==0: b = x[0] else: b = ((x[0] // x[2])+1)*x[2] c = (x[1]-b)//x[2] + 1 print(c)
s592365724
p03997
u076498277
2,000
262,144
Wrong Answer
17
2,940
61
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a, b, h = map(int,open(0).read().split()) print((a+b)* h / 2)
s883905321
Accepted
17
2,940
70
a, b, h = map(int,open(0).read().split()) print(round(((a+b)* h / 2)))
s196134744
p03573
u428012835
2,000
262,144
Wrong Answer
17
2,940
90
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
num = input().split() print(num) for i in num: if num.count(i) == 1: print(i)
s539044223
Accepted
18
3,064
107
numbers = list(map(int, input().split())) for i in numbers: if numbers.count(i) == 1: print(i)
s484591221
p03607
u294385082
2,000
262,144
Time Limit Exceeded
2,112
146,072
151
You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?
n = int(input()) a = [int(input()) for i in range(n)] lis = [] for i in a: if i in lis: a.remove(i) else: a.append(i) print(len(lis))
s890565064
Accepted
214
19,852
235
n = int(input()) a = [int(input()) for i in range(n)] dict = {} count = 0 for i in a: if i not in dict: dict[i] = 1 elif i in dict: dict[i]+= 1 for i in set(a): if dict[i]%2!=0: count += 1 print(count)
s731975591
p03693
u117078923
2,000
262,144
Wrong Answer
17
2,940
99
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
l=[int(x) for x in input().split()] if (l[0]+l[1]+l[2])%4 == 0: print("Yes") else: print("No")
s918793716
Accepted
17
2,940
83
r,g,b=map(int,input().split()) if (10*g+b)%4==0: print('YES') else: print('NO')
s418420322
p03024
u767438459
2,000
1,048,576
Wrong Answer
25
9,036
70
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.
s=input() if s.count("x") >= 8: print("No") else: print("Yes")
s153204231
Accepted
28
9,092
382
s=input() if s.count("x") >= 8: print("NO") else: print("YES")
s106997471
p03380
u761989513
2,000
262,144
Wrong Answer
2,104
14,052
229
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())) half = max(a) / 2 sa = float("inf") ans = 0 for i in a: if i != max(a): if abs(half - i) < sa: ans = i sa = abs(half - i) print(a[0], ans)
s753554581
Accepted
70
14,428
227
n = int(input()) a = list(map(int, input().split())) m = max(a) half = m / 2 sa = float("inf") ans = 0 for i in a: if i != m: if abs(half - i) < sa: ans = i sa = abs(half - i) print(m, ans)
s178218259
p02397
u756468156
1,000
131,072
Wrong Answer
60
7,624
136
Write a program which reads two integers x and y, and prints them in ascending order.
while True: xy_list = list(map(int, input().split())) if xy_list[0] == xy_list[1] == 0: break print(sorted(xy_list))
s301953843
Accepted
60
7,528
137
while True: xy_list = list(map(int, input().split())) if xy_list[0] == xy_list[1] == 0: break print(*sorted(xy_list))
s859740593
p02692
u316649390
2,000
1,048,576
Wrong Answer
207
10,020
376
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.
N,A,B,C = map(int,input().split()) data = { "A":A, "B":B, "C":C } select = [] for _ in range(N): s = input() if data[s[0]] == data[s[1]] ==0: print("No") exit(0) elif data[s[0]] >= data[s[1]]: data[s[0]] -= 1 data[s[1]] += 1 select.append(s[1]) else: data[s[0]] += 1 data[s[1]] -= 1 select.append(s[0]) for i in select: print(i)
s902732176
Accepted
225
17,056
645
N,A,B,C = map(int,input().split()) data = { "A":A, "B":B, "C":C } select = [] S = list(input() for _ in range(N)) for i in range(N): s = S[i] if data[s[0]] == data[s[1]] ==0: print("No") exit(0) elif data[s[0]] > data[s[1]]: data[s[0]] -= 1 data[s[1]] += 1 select.append(s[1]) elif data[s[0]] < data[s[1]]: data[s[0]] += 1 data[s[1]] -= 1 select.append(s[0]) elif i == N-1: select.append(s[0]) elif s[0] in S[i+1]: data[s[0]] += 1 data[s[1]] -= 1 select.append(s[0]) else: data[s[0]] -= 1 data[s[1]] += 1 select.append(s[1]) print("Yes") for i in select: print(i)
s816740587
p03738
u498401785
2,000
262,144
Wrong Answer
18
2,940
119
You are given two positive integers A and B. Compare the magnitudes of these numbers.
a = input() b = input() if(a > b): print("GRATER") elif(a < b): print("LESS") elif(a == b): print("EQUAL")
s524704592
Accepted
18
2,940
130
a = int(input()) b = int(input()) if(a > b): print("GREATER") elif(a < b): print("LESS") elif(a == b): print("EQUAL")
s476355279
p03227
u846150137
2,000
1,048,576
Wrong Answer
17
2,940
48
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
a=input() print(a if len(a)==2 else reversed(a))
s143574195
Accepted
17
3,064
44
a=input() print(a if len(a)==2 else a[::-1])
s331454505
p02742
u220394041
2,000
1,048,576
Wrong Answer
17
2,940
93
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:
import math h, w = map(int, input().split()) ans = math.ceil(h * w / 2) print(AssertionError)
s278384429
Accepted
19
3,188
115
import math h, w = map(int, input().split()) ans = math.ceil(h * w / 2) if h == 1 or w == 1: ans = 1 print(ans)
s204427826
p04012
u982517812
2,000
262,144
Wrong Answer
17
3,064
352
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
s = str(input()) t = list(s) t.sort() a = [] b = 1 for i in range(len(t)): if i >= 1: if t[i] == t[i-1]: b = b + 1 else: a.append(b) b = 1 a.append(b) for i in range(len(a)): if a[i] % 2 != 0: print("NO") break else: if i == len(a) - 1: print("YES")
s700912232
Accepted
17
3,064
352
s = str(input()) t = list(s) t.sort() a = [] b = 1 for i in range(len(t)): if i >= 1: if t[i] == t[i-1]: b = b + 1 else: a.append(b) b = 1 a.append(b) for i in range(len(a)): if a[i] % 2 != 0: print("No") break else: if i == len(a) - 1: print("Yes")
s061908612
p03557
u664907598
2,000
262,144
Wrong Answer
511
31,484
389
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
import bisect import numpy as np n = int(input()) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) memo = [0] * n for i in range(n): memo[i] = n - bisect.bisect_right(c,b[i]) memo.reverse() memo1 = np.cumsum(memo) ans = 0 for i in range(n): ans += memo1[n-1-bisect.bisect_right(b,a[i])] print(ans)
s409785468
Accepted
481
31,476
310
import bisect import numpy as np n = int(input()) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) ans = 0 for i in range(n): s = bisect.bisect_left(a,b[i]) t = n - bisect.bisect_right(c,b[i]) ans += s*t print(ans)
s353915173
p03693
u787562674
2,000
262,144
Wrong Answer
17
2,940
79
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) print("YES" if (g * 10 + b) % 4 else "NO")
s494290321
Accepted
17
2,940
84
r, g, b = map(int, input().split()) print("YES" if (g * 10 + b) % 4 == 0 else "NO")
s745601479
p03455
u407016024
2,000
262,144
Wrong Answer
18
2,940
90
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if (a*b)%2 == 0: print('EVEN') else: print('ODD')
s263729230
Accepted
17
2,940
90
a, b = map(int, input().split()) if (a*b)%2 == 0: print('Even') else: print('Odd')
s585225507
p03110
u902462889
2,000
1,048,576
Wrong Answer
17
3,064
258
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
N = int(input()) lst_1 = [] ans = 0 for n in range(N): lst_1.append(input().split()) print(lst_1) for n in range(N): money = 0 money = float(lst_1[n][0]) if lst_1[n][1] == "BTC": money = money * 380000 ans += money print(ans)
s618561035
Accepted
17
3,060
244
N = int(input()) lst_1 = [] ans = 0 for n in range(N): lst_1.append(input().split()) for n in range(N): money = 0 money = float(lst_1[n][0]) if lst_1[n][1] == "BTC": money = money * 380000 ans += money print(ans)
s000327428
p02393
u327546577
1,000
131,072
Wrong Answer
20
5,584
100
Write a program which reads three integers, and prints them in ascending order.
a, b, c = map(int, input().split()) li = sorted([a, b, c]) print("%(li[0])s %(li[1])s %(li[2])s ")
s271115184
Accepted
20
5,600
94
a, b, c = map(int, input().split()) li = sorted([a, b, c]) print(f"{li[0]} {li[1]} {li[2]}")
s213723341
p03434
u566619532
2,000
262,144
Wrong Answer
17
3,060
346
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
# -*- coding: utf-8 -*- a = int(input()) b = input() b = map(int, b.split()) print(type(b)) b = sorted(b) b = b[::-1] c = b[::2] c_number = len(c) d = b[1::2] d_number = len(d) c_sum = 0 d_sum = 0 for i in range(c_number): c_sum += c[i] for g in range(d_number): d_sum += d[g] print(c_sum - d_sum)
s972393102
Accepted
17
3,064
596
# -*- coding: utf-8 -*- a = int(input()) b = input() b = map(int, b.split()) b = sorted(b) b = b[::-1] c = b[::2] c_number = len(c) d = b[1::2] d_number = len(d) c_sum = 0 d_sum = 0 for i in range(c_number): c_sum += c[i] for g in range(d_number): d_sum += d[g] print(c_sum - d_sum)
s955186021
p02694
u010379708
2,000
1,048,576
Wrong Answer
2,206
9,172
100
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=100 target = int(input()) count=0 while count<target: x*=1.01 x = x//1 count+=1 print(count)
s027210526
Accepted
25
9,168
96
t=int(input()) ans=0 start=100 while start<t: start += int(start/100) ans+=1 print(ans)
s179738709
p03730
u469281291
2,000
262,144
Wrong Answer
17
3,064
261
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 = map(int, input().split()) rem = a % b tmp = 0 fa = a ans = "No" if(rem!=0): while (tmp != rem): a += fa tmp = a % b if (tmp == c): ans = "Yes" break else: if(c==0): ans = "Yes" print(ans)
s667243156
Accepted
17
3,064
261
a, b, c = map(int, input().split()) rem = a % b tmp = 0 fa = a ans = "NO" if(rem!=0): while (tmp != rem): a += fa tmp = a % b if (tmp == c): ans = "YES" break else: if(c==0): ans = "YES" print(ans)
s297421400
p03565
u853900545
2,000
262,144
Wrong Answer
18
3,064
344
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() S = len(s) T = len(t) ans= '' for i in range(S-T): for j in range(T): if s[i+j] == t[j] or s[i+j] == '?': c = 1 continue else: c = 0 if c : ans = s[0:i] + t + s[i+T:] if ans: ans = ans.replace('?','a') print(ans) else: print('UNRESTORABLE')
s501602415
Accepted
17
3,064
338
s = input() t = input() S = len(s) T = len(t) ans= '' for i in range(S-T+1): c = 1 for j in range(T): if s[i+j] == t[j] or s[i+j] == '?': continue else: c = 0 if c : ans = s[0:i] + t + s[i+T:] if ans: ans = ans.replace('?','a') print(ans) else: print('UNRESTORABLE')
s801130838
p03417
u175590965
2,000
262,144
Wrong Answer
17
3,060
154
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
n,m = map(int,input().split()) if n > m: n,m = m,n if n == 1 and m == 1: print(1) elif n == 1 and m>1: print(m-2) else: print((n-2*(m-2)))
s162347515
Accepted
17
3,060
156
n,m = map(int,input().split()) if n > m: n,m = m,n if n == 1 and m == 1: print(1) elif n == 1 and m > 1: print(m-2) else: print((n-2)*(m-2))
s835080642
p02615
u514118270
2,000
1,048,576
Wrong Answer
125
31,460
131
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()) l=sorted(list(map(int,input().split()))) l.reverse() s=l[0]-N%2*l[N//2] for i in range(N//2): s+=l[i+1]*2 print(s)
s958214113
Accepted
129
31,552
133
N=int(input()) l=sorted(list(map(int,input().split()))) l.reverse() s=l[0]+N%2*l[N//2] for i in range(N//2-1): s+=l[i+1]*2 print(s)
s591666013
p02612
u811535874
2,000
1,048,576
Wrong Answer
29
8,916
32
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)
s316430284
Accepted
26
9,048
87
n = int(input()) if n % 1000 == 0: print(0) else: print((n// 1000 + 1) * 1000 - n)
s779324242
p03645
u794173881
2,000
262,144
Wrong Answer
992
52,840
592
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.
from collections import deque n,m = map(int,input().split()) tree = [[] for i in range(n)] for i in range(m): tmp_a,tmp_b = map(int,input().split()) tree[tmp_a-1].append(tmp_b-1) tree[tmp_b-1].append(tmp_a-1) print(tree) def bfs(): q = deque() visited =[False]*n visited[0]=True for elem in tree[0]: q.append([elem,1]) while q: i,cnt = q.popleft() if i == n-1 and cnt <=2 : print("POSSIBLE") exit() if not visited[i]: visited[i] = True if cnt<=1: for elem in tree[i]: q.append([elem,cnt+1]) bfs() print("IMPOSSIBLE")
s818458045
Accepted
903
49,868
587
from collections import deque n,m = map(int,input().split()) tree = [[] for i in range(n)] for i in range(m): tmp_a,tmp_b = map(int,input().split()) tree[tmp_a-1].append(tmp_b-1) tree[tmp_b-1].append(tmp_a-1) def bfs(): q = deque() visited =[False]*n visited[0]=True for elem in tree[0]: q.append([elem,1]) while q: i,cnt = q.popleft() if i == n-1 and cnt <=2 : print("POSSIBLE") exit() if not visited[i]: visited[i] = True if cnt<=1: for elem in tree[i]: q.append([elem,cnt+1]) bfs() print("IMPOSSIBLE")
s812653938
p03759
u767438459
2,000
262,144
Wrong Answer
27
9,092
85
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c=map(int, input().split()) if b-a == c-b: print("Yes") else: print("No")
s346799869
Accepted
26
9,080
85
a,b,c=map(int, input().split()) if b-a == c-b: print("YES") else: print("NO")
s058482421
p02259
u064313887
1,000
131,072
Wrong Answer
20
5,520
468
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 show(nums): for i in range(len(nums)): if i != len(nums) - 1: print(nums[i],end=' ') else: print(nums[i]) def bubbleSort(A,N): flag = 1 count = 0 while flag: flag = 0 for j in range(N-1,0,-1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag = 1 count += 1 show(A) print(count)
s752145786
Accepted
20
5,612
503
def show(nums): for i in range(len(nums)): if i != len(nums)-1: print(nums[i],end=' ') else: print(nums[i]) N = int(input()) A = list(map(int,input().split())) count = 0 flag = 1 for i in range(N): while flag: flag = 0 for j in range(N-1,i,-1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp count += 1 flag = 1 show(A) print(count)
s022480434
p03501
u263691873
2,000
262,144
Wrong Answer
17
2,940
64
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 if N*A<B else B)
s407434275
Accepted
17
2,940
62
N, A, B = map(int, input().split()) print(N*A if N*A<B else B)
s742807706
p02414
u150984829
1,000
131,072
Wrong Answer
20
5,604
144
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
import sys e=[list(map(int,e.split()))for e in sys.stdin] n=e[0][0]+1 for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])
s236430198
Accepted
110
6,588
147
import sys e=[list(map(int,x.split()))for x in sys.stdin];n=e[0][0]+1 for c in e[1:n]:print(*[sum([s*t for s,t in zip(c,l)])for l in zip(*e[n:])])
s026281891
p00009
u766477342
1,000
131,072
Wrong Answer
910
31,376
379
Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
def mk_table(n): res = [1] * (n + 1) res[:2] = 0, 0 for i in range(2, n): if i ** 2 > n: break if res[i] == 1: for j in range(2, n // i + 1, i): res[i * j] = 0 return res tbl = mk_table(999999) try: while 1: print(len([x for x in tbl[:int(input())+1] if x == 1])) except Exception: pass
s838174276
Accepted
820
24,296
372
def mk_table(n): res = [1] * (n + 1) res[:2] = 0, 0 for i in range(2, n): if i ** 2 > n: break if res[i] == 1: for j in range(i*2, n + 1, i): res[j] = 0 return res tbl = mk_table(999999) try: while 1: print(len([x for x in tbl[:int(input())+1] if x == 1])) except Exception: pass
s020442088
p02613
u460615319
2,000
1,048,576
Wrong Answer
154
9,184
198
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 = [] judges = {'AC':0,'WA':0,'TLE':0,'RE':0} for i in range(n): s = input().strip() judges[s] += 1 for judge,count in judges.items(): print(f"{judge} ✖️ {count}")
s700198296
Accepted
146
9,184
193
n = int(input()) s = [] judges = {'AC':0,'WA':0,'TLE':0,'RE':0} for i in range(n): s = input().strip() judges[s] += 1 for judge,count in judges.items(): print(f"{judge} x {count}")
s192625440
p03943
u690781906
2,000
262,144
Wrong Answer
17
2,940
119
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 - max(a, b, c) == max(a, b, c): print('YES') else: print('NO')
s153722310
Accepted
17
2,940
120
a, b, c = map(int, input().split()) if a + b + c - max(a, b, c) == max(a, b, c): print('Yes') else: print('No')
s612318241
p02260
u433154529
1,000
131,072
Wrong Answer
30
7,616
285
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
n=int(input()) a=[int(i) for i in input().split(" ")] x=0 for i in range(n): mi=i for j in range(i,n): print(a[j],a[mi]) if a[j] < a[mi]: mi = j if i != mi: x+=1 a[i],a[mi]=a[mi],[i] print(" ".join([str(i) for i in a])) print(x)
s868363417
Accepted
20
7,776
276
n=int(input()) a=[int(i) for i in input().split(" ")] x=0 for i in range(n): mi = i for j in range(i, n): if a[j] < a[mi]: mi = j if i != mi: x += 1 a[i], a[mi] = a[mi] , a[i] print(" ".join([str(i) for i in a])) print(x)
s714142253
p03695
u811000506
2,000
262,144
Wrong Answer
18
3,064
299
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
N = int(input()) a = list(map(int,input().split())) li = [10**9]*N overrate = 0 for i in range(N): if a[i]>=3200: overrate += 1 continue else: li[i] = a[i]//400 kind = len(list(set(li))) mn = min(kind-min(overrate,1),8) mx = min(8,max(kind-1+overrate,1)) print(mn,mx)
s765021459
Accepted
18
3,060
335
N = int(input()) a = list(map(int,input().split())) li = [0]*8 overrate = kind = 0 for i in range(N): if a[i]>=3200: overrate += 1 continue else: li[a[i]//400] += 1 for j in range(8): if li[j]!=0: kind += 1 if kind==0: print(1,kind+overrate) else: print(min(8,kind),kind+overrate)
s713006723
p03044
u722535636
2,000
1,048,576
Wrong Answer
438
34,160
170
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.
n=int(input()) t=[0]*n q=[list(map(int,input().split())) for i in range(n-1)] for u,v,w in q: if w%2==0: t[v-1],t[u-1]=1,1 for i in range(n): print(t[i])
s473121313
Accepted
688
79,356
322
import sys sys.setrecursionlimit(100100) n=int(input()) route=[[] for i in range(n)] for i in range(n-1): u,v,w=map(int,input().split()) route[u-1].append((v-1,w)) route[v-1].append((u-1,w)) ans=[-1]*n def dfs(p,d): ans[p]=d for i,j in route[p]: if ans[i]<0:dfs(i,(d+j)%2) dfs(0,0) for i in range(n): print(ans[i])
s251584184
p02409
u884012707
1,000
131,072
Wrong Answer
20
7,608
320
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
N=int(input()) l=[[[0 for i in range(10)]for j in range(3)]for k in range(4)] for i in range(N): b, f, r, v = map(lambda x: int(x)-1, input().split()) print(b,f,r,v) l[b][f][r]+=v+1 for j in range(4): for k in l[j]: print(" ".join(map(str, k))) if j < 3: print("####################")
s298281598
Accepted
30
7,724
305
N=int(input()) l=[[[0 for i in range(10)]for j in range(3)]for k in range(4)] for i in range(N): b, f, r, v = map(lambda x: int(x)-1, input().split()) l[b][f][r]+=v+1 for j in range(4): for k in l[j]: print(" "+" ".join(map(str, k))) if j < 3: print("####################")
s722846831
p02936
u254871849
2,000
1,048,576
Wrong Answer
798
49,700
886
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.
# 2019-11-17 10:52:21(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r import itertools # from functools import reduce # import operator as op # import re # import heapq # import array # from scipy.misc import comb # (default: exact=False) # import numpy as np def main(): n, q = [int(x) for x in sys.stdin.readline().split()] AB = [[] for _ in range(n+1)] for _ in range(n-1): a, b = [int(x) for x in sys.stdin.readline().split()] AB[a].append(b) ans = [0 for _ in range(n+1)] for _ in range(q): p, x = [int(x) for x in sys.stdin.readline().split()] ans[p] += x for a in range(1, n+1): for b in AB[a]: ans[b] += ans[a] print(ans) if __name__ == "__main__": main()
s057189406
Accepted
878
74,680
665
import sys n, q = map(int, sys.stdin.readline().split()) g = [[] for _ in range(n+1)] for _ in range(n-1): a, b = map(int, sys.stdin.readline().split()) g[a].append(b) g[b].append(a) px = zip(*[map(int, sys.stdin.read().split())] * 2) def main(): value = [0] * (n + 1) for p, x in px: value[p] += x stack = [1] par = [None] * (n + 1) while stack: u = stack.pop() for v in g[u]: if v != par[u]: par[v] = u value[v] += value[u] stack.append(v) return value[1:] if __name__ == '__main__': ans = main() print(*ans, sep=' ')
s906460887
p02407
u093488647
1,000
131,072
Wrong Answer
20
5,592
136
Write a program which reads a sequence and prints it in the reverse order.
num = int(input()) data = input().split() output = [] lengh = len(data) for tmp in range(lengh): output += data.pop(-1) print(output)
s588681694
Accepted
20
5,600
182
num = int(input()) data = list(map(int, input().split())) lengh = len(data) for tmp in range(lengh): if tmp == lengh-1: print(data.pop(-1)) else: print(data.pop(-1), end=" ")
s405670634
p03007
u922952729
2,000
1,048,576
Wrong Answer
2,104
14,428
329
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
import bisect N=int(input()) A=[int(i) for i in input().split(" ")] A=sorted(A) traceback=[] for i in range(N-1): if i%2==0: x=A[0] y=A[-1] else: x=A[-1] y=A[0] A=A[1:-1:] bisect.insort_left(A,x-y) traceback.append((x,y)) print(A[0]) for t in traceback: print(t[0],t[1])
s551874493
Accepted
216
13,964
433
import bisect N=int(input()) A=[int(i) for i in input().split(" ")] A=sorted(A) traceback=[] if A[0]>=0: minus=[A[0]] plus=A[1::] elif A[-1]<=0: minus=A[:-1:] plus=[A[-1]] else: index=bisect.bisect_left(A,0) minus=A[:index:] plus=A[index::] print(sum(plus)-sum(minus)) m=minus.pop(0) for p in plus[:-1:]: print(m,p) m=m-p print(plus[-1],m) p=plus[-1]-m for m in minus: print(p,m) p=p-m
s109630772
p03854
u099022530
2,000
262,144
Wrong Answer
75
3,956
310
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
s = input() dp = [0] * (len(s) + 1) dp[0] = 1 words = ["dream","dreamer","erase","eraser"] done = "No" for i in range(len(s)): if dp[i] == 0: continue for w in words: if s[i:i+len(w)] == w: dp[i+len(w)] = 1 if dp[len(s)] == 1: done = "Yes" print(done)
s671459876
Accepted
73
3,956
310
S = input() dp = [0] * (len(S) + 1) dp[0] = 1 words = ["dream", "dreamer", "erase", "eraser"] done = 'NO' for i in range(len(S)): if dp[i] == 0: continue for w in words: if S[i:i+len(w)] == w: dp[i+len(w)] = 1 if dp[len(S)] == 1: done = 'YES' print(done)
s640350875
p03760
u820351940
2,000
262,144
Wrong Answer
17
2,940
98
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.
a = input() b = input() "".join(map("".join, zip(a, b))) + (a[-1] if len(a) is not len(b) else "")
s262190185
Accepted
18
2,940
115
a = input() b = input() print("".join(map("".join, zip(list(a), list(b)))) + (a[-1] if len(a) != len(b) else ""))