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
s340860866
p03761
u867826040
2,000
262,144
Wrong Answer
24
3,956
386
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
#from collections import Counter from copy import copy n = int(input()) s = [input() for i in range(n)] d = {chr(i):51 for i in range(97,123)} base = {chr(i):0 for i in range(97,123)} for si in s: dx = copy(base) for sij in si: dx[sij] += 1 for k,v in dx.items(): print(k,v) d[k] = min(d[k],v) ans = "" for k,v in d.items(): ans+=(k*v) print(ans)
s278272449
Accepted
38
9,860
319
from collections import Counter from string import ascii_lowercase n = int(input()) s = {ai:float("INF") for ai in ascii_lowercase} for i in range(n): si = input() c = Counter(si) for k in ascii_lowercase: s[k] = min(s[k],c[k]) ans = "" for key in ascii_lowercase: ans += key*s[key] print(ans)
s593696616
p03433
u794173881
2,000
262,144
Wrong Answer
18
2,940
79
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n=int(input()) a=int(input()) if n%500 >=a: print("Yes") else: print("No")
s328011778
Accepted
18
2,940
80
n=int(input()) a=int(input()) if n%500 <=a: print("Yes") else: print("No")
s359010265
p02659
u265506056
2,000
1,048,576
Wrong Answer
22
9,188
123
Compute A \times B, truncate its fractional part, and print the result as an integer.
A,B=input().split() A=int(A) B=float(B) print(A*B,A,B) B=B*100 ans=int(A*B) a=ans%100 ans=ans-a ans=int(ans/100) print(ans)
s304611073
Accepted
24
9,112
102
A,B=input().split() A=int(A) ans=A*(int(B[0])*100+int(B[2])*10+int(B[3])) ans=int(ans//100) print(ans)
s066908798
p03524
u576917603
2,000
262,144
Wrong Answer
39
4,084
615
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
s=list(input()) n=len(s) if len(set(s))==1: print("No") exit() x,y,z=0,0,0 for i in s: if i=="a": x+=1 elif i=="b": y+=1 else: z+=1 lis=[x,y,z] if n%2==0: lis=sorted(lis,reverse=True) if lis[0]>sum(lis[1:])+1: print("No") else: print('Yes') else: if len(set(s))==2: print("No") else: for i in lis: if i%2==1: odd=i for i in lis: if i%2==0: if i<odd-1 or odd+1<i: print("No") exit() print("Yes")
s494413079
Accepted
27
3,956
295
s=list(input()) n=len(s) if n==1: print("YES") exit() if len(set(s))==2 and n==2: print("YES") exit() if len(set(s))<3: print("NO") exit() x,y,z=s.count("a"),s.count("b"),s.count('c') if abs(x-y)>1 or abs(y-z)>1 or abs(z-x)>1: print("NO") else: print("YES")
s353301738
p02409
u400765446
1,000
131,072
Wrong Answer
20
5,620
425
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.
def main(): rooms = [[0 for i in range(10)] for j in range(12)] x = int(input()) for _ in range(x): b, f, r, v = tuple(map(int, input().split())) rooms[(b-1)*3+(f-1)][r-1] = v for i in range(4): for j in range(3): for k in range(10): print(" "+str(rooms[i*3+j][k]), end="") print() print("#"*20) if __name__ == '__main__': main()
s572241512
Accepted
20
5,624
389
tenants = [] buildings = [[[0 for _ in range(10)] for _ in range(3)]for _ in range (4)] n = int(input()) for _ in range(n): b, f, r, v = map(int, input().split()) buildings[b-1][f-1][r-1] += v for i in range(4): if i != 0: print("#"*20) for j in range(3): for k in range(10): print(" {}".format(buildings[i][j][k]), end='') print()
s958158049
p03943
u349444371
2,000
262,144
Wrong Answer
17
2,940
106
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 or (a+c)==b or (b+c)==a: print("YES") else: print("NO")
s880874457
Accepted
17
2,940
106
a,b,c=map(int,input().split()) if (a+b)==c or (a+c)==b or (b+c)==a: print("Yes") else: print("No")
s439824992
p03679
u661980786
2,000
262,144
Wrong Answer
17
2,940
130
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b = map(int,input().split()) if b-a <= 0: print("delicious") elif a+x <= b: print("safe") else: print("dangerous")
s413571231
Accepted
17
2,940
131
x,a,b = map(int,input().split()) if b-a <= 0: print("delicious") elif a+x >= b: print("safe") else: print("dangerous")
s484385642
p03214
u282228874
2,525
1,048,576
Wrong Answer
17
3,060
206
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
n = int(input()) A = list(map(int,input().split())) ave = sum(A)/n diff = [] for a in A: diff.append(abs(a-ave)) tmp = 0 d = 10**9 for i in range(n): if diff[i] < d: d = diff[i] tmp = i print(i)
s829805376
Accepted
18
3,064
208
n = int(input()) A = list(map(int,input().split())) ave = sum(A)/n diff = [] for a in A: diff.append(abs(a-ave)) tmp = 0 d = 10**9 for i in range(n): if diff[i] < d: d = diff[i] tmp = i print(tmp)
s901126407
p03829
u203900263
2,000
262,144
Wrong Answer
108
14,224
255
There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one- dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town i is X_i. You are now at town 1, and you want to visit all the other towns. You have two ways to travel: * Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction. * Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered. Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.
N, A, B = map(int, input().split()) X = list(map(int, input().split())) diff = [X[i + 1] - X[i] for i in range(len(X) - 1)] print(diff) fatigue = 0 for i in diff: if i * A < B: fatigue += i * A else: fatigue += B print(fatigue)
s397351447
Accepted
100
14,252
243
N, A, B = map(int, input().split()) X = list(map(int, input().split())) diff = [X[i + 1] - X[i] for i in range(len(X) - 1)] fatigue = 0 for i in diff: if i * A < B: fatigue += i * A else: fatigue += B print(fatigue)
s264397381
p03470
u919378776
2,000
262,144
Wrong Answer
21
3,188
259
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?
moti_total = int(input()) moti = [] for n in range(moti_total): moti.append(int(input())) moti.sort() tower = 1 for n in range(moti_total-1): if moti[n] is not moti[n+1]: print('n ' + str(moti[n]) + ' n2 ' + str(moti[n+1])) tower += 1 print(tower)
s877391977
Accepted
19
3,060
202
moti_total = int(input()) moti = [] for n in range(moti_total): moti.append(int(input())) moti.sort() tower = 1 for n in range(moti_total-1): if moti[n] is not moti[n+1]: tower += 1 print(tower)
s900446381
p03660
u987164499
2,000
262,144
Wrong Answer
665
33,400
946
Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
from queue import deque n = int(input()) li = [[] for _ in range(n+1)] for i in range(n-1): a,b = map(int,input().split()) li[a] += [b] li[b] += [a] def width_prime(start,li,n): inf = 10**10 visited = [False]*(n+1) length = [inf]*(n+1) length[start] = 0 visited[start] = True work_queue = deque([]) work_queue.append(start) while work_queue: now = work_queue.popleft() visited[now] = True for i in li[now]: if visited[i]: continue work_queue.append(i) visited[i] = True if length[i] > length[now]+1: length[i] = length[now]+1 return length le_fe = width_prime(1,li,n) le_su = width_prime(n,li,n) print(le_su) print(le_fe) su = 0 fe = 0 for i in range(1,n+1): if le_fe[i] <= le_su[i]: fe += 1 else: su += 1 if fe > su: print("Fennec") else: print("Sunuke")
s219676723
Accepted
615
30,712
918
from queue import deque n = int(input()) li = [[] for _ in range(n+1)] for i in range(n-1): a,b = map(int,input().split()) li[a] += [b] li[b] += [a] def width_prime(start,li,n): inf = 10**10 visited = [False]*(n+1) length = [inf]*(n+1) length[start] = 0 visited[start] = True work_queue = deque([]) work_queue.append(start) while work_queue: now = work_queue.popleft() visited[now] = True for i in li[now]: if visited[i]: continue work_queue.append(i) visited[i] = True if length[i] > length[now]+1: length[i] = length[now]+1 return length le_fe = width_prime(1,li,n) le_su = width_prime(n,li,n) su = 0 fe = 0 for i in range(1,n+1): if le_fe[i] <= le_su[i]: fe += 1 else: su += 1 if fe > su: print("Fennec") else: print("Snuke")
s642831042
p03737
u131264627
2,000
262,144
Wrong Answer
17
2,940
73
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
a, b, c = list(input().split()) s = a[0] + b[0] + c[0] s.upper() print(s)
s395931286
Accepted
17
2,940
65
a, b, c = input().split() s = a[0] + b[0] + c[0] print(s.upper())
s989464837
p03149
u102902647
2,000
1,048,576
Wrong Answer
19
2,940
223
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
N_list = list(map(int, input().split())) flag = False if '1' in N_list: if '9' in N_list: if '7' in N_list: if '4' in N_list: flag=True if flag: print('YES') else: print('NO')
s153807604
Accepted
17
2,940
215
N_list = list(map(int, input().split())) flag = False if 1 in N_list: if 9 in N_list: if 7 in N_list: if 4 in N_list: flag=True if flag: print('YES') else: print('NO')
s000004184
p03997
u780122303
2,000
262,144
Wrong Answer
17
2,940
87
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.
#py aa.py a=input() b=input() h=input() a=int(a) b=int(b) h=int(h) c=(a*b)*h/2 print(c)
s392100088
Accepted
17
2,940
80
#py aa.py a=int(input()) b=int(input()) h=int(input()) c=int((a+b)*h/2) print(c)
s349824284
p02390
u553951959
1,000
131,072
Wrong Answer
20
7,644
47
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
x = int(input () ) print(x/3600,":",x/60,":",x)
s228767453
Accepted
30
7,672
84
x = int(input () ) h = x // 3600 m = x % 3600 // 60 s = x % 60 print(h,m,s, sep=':')
s262739302
p03214
u462329577
2,525
1,048,576
Wrong Answer
17
3,060
186
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
n = int(input()) a = list(map(int, input().split())) tmp = max(a) ave = sum(a)/n ans = 0 for i in range(n): if tmp < abs(ave - a[i]): ans = 1+i ave = abs(ave - a[i]) print(ans)
s296381144
Accepted
17
3,060
197
n = int(input()) a = list(map(int, input().split())) tmp = max(a) ave = sum(a) / n ans = 0 for i in range(n): if tmp > abs(ave - a[i]): ans = i tmp = abs(ave - a[i]) print(ans)
s134610394
p03623
u994521204
2,000
262,144
Wrong Answer
17
2,940
60
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
a,b,c=map(int,input().split()) print(min(abs(b-a),abs(c-a)))
s568379962
Accepted
17
2,940
86
a,b,c=map(int,input().split()) print('A' if min(abs(b-a),abs(c-a))==abs(b-a) else 'B')
s908023441
p03494
u491656579
2,000
262,144
Wrong Answer
18
3,064
411
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = input() il = list(map(int, input().split())) print(il) cnt = 0 ans = 0 while True: for i in range(len(il)): if il[i] % 2: break else: cnt += 1 if cnt == len(il): for i in range(len(il)): il[i] == il[i] / 2 ans += 1 break print(ans)
s382356223
Accepted
19
3,064
450
n = input() il = list(map(int, input().split())) ans = 0 fin = 0 while fin < 1: cnt = 0 for i in range(len(il)): if il[i] % 2: fin = 1 break else: cnt += 1 if cnt == len(il): for i in range(len(il)): il[i] = il[i] / 2 ans += 1 else: break print(ans)
s103822682
p03693
u665038048
2,000
262,144
Wrong Answer
17
2,940
98
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()) if int(r+g+b) % 4 == 0: print('YES') else: print('NO')
s905439427
Accepted
18
2,940
87
n = int(input().replace(' ', '')) if n % 4 == 0: print('YES') else: print('NO')
s804097575
p02406
u354053070
1,000
131,072
Wrong Answer
30
7,508
135
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
n = int(input()) for i in range(1, n+1): if i % 3 == 0: print(' '+str(i)) elif '3' in str(i): print(' '+str(i))
s016925946
Accepted
30
7,996
161
n = int(input()) for i in range(1, n+1): if i % 3 == 0: print(' '+str(i), end='') elif '3' in str(i): print(' '+str(i), end='') print('')
s221848124
p03574
u985929170
2,000
262,144
Wrong Answer
28
9,260
465
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
H,W = map(int,input().split()) masu = [list(input()) for _ in range(H)] print(masu) def kazu(h,w): houkou = [[1,0],[1,-1],[0,-1],[-1,-1],[-1,0],[-1,1],[0,1],[1,1]] count = 0 for ya in houkou: try: if masu[h+ya[0]][w+ya[1]] == '#': count += 1 except:pass return count for w in range(W): for h in range(H): if masu[h][w]=='.': masu[h][w] = kazu(h,w) for l in masu:print(*l,sep='')
s911938380
Accepted
36
9,204
472
H,W = map(int,input().split()) masu = [list(input()) for _ in range(H)] def kazu(h,w): houkou = [[1,0],[1,-1],[0,-1],[-1,-1],[-1,0],[-1,1],[0,1],[1,1]] count = 0 for ya in houkou: if 0 <= h+ya[0] < H and 0 <= w+ya[1] < W: if masu[h+ya[0]][w+ya[1]] == '#': count += 1 return count for w in range(W): for h in range(H): if masu[h][w]=='.': masu[h][w] = kazu(h,w) for l in masu:print(*l,sep='')
s228540358
p03549
u655975843
2,000
262,144
Wrong Answer
18
2,940
71
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
n, m = map(int, input().split()) print((1800 * 2 + 100 * n) * (2 ** m))
s858210955
Accepted
18
2,940
71
n, m = map(int, input().split()) print((1800 * m + 100 * n) * (2 ** m))
s126170489
p02831
u408375121
2,000
1,048,576
Wrong Answer
20
3,060
187
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
def gcd(a, b): if a <= b: a, b = b, a while a % b: a, b = b, a % b return a def lcm(a, b): return int(a * b / gcd(a, b)) A, B = map(int, input().split()) print(lcm(A, B))
s208230480
Accepted
17
2,940
188
def gcd(a, b): if a <= b: a, b = b, a while a % b: a, b = b, a % b return b def lcm(a, b): return int(a * b / gcd(a, b)) A, B = map(int, input().split()) print(lcm(A, B))
s421735987
p03068
u150787983
2,000
1,048,576
Wrong Answer
17
3,060
187
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
N = int(input()) S = list(input()) K = int(input()) ok_str = S[K-1] print(ok_str) for i in range(N): if S[i] == ok_str: pass else: S[i] = '*' print(''.join(S))
s369129235
Accepted
17
2,940
173
N = int(input()) S = list(input()) K = int(input()) ok_str = S[K-1] for i in range(N): if S[i] == ok_str: pass else: S[i] = '*' print(''.join(S))
s626946397
p03836
u869519920
2,000
262,144
Wrong Answer
27
9,140
387
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
def addRoute(i, c): t = '' for _ in range(i): t += c return t pos=list(map(int, input().split())) ud = pos[2] - pos[0] rl = pos[3] - pos[1] s = '' s += addRoute(ud, 'U') s += addRoute(rl, 'R') s += addRoute(ud, 'D') s += addRoute(rl, 'L') s += 'L' s += addRoute(ud+1, 'U') s += addRoute(rl+1, 'R') s += 'RR' s += addRoute(ud+1, 'D') s += addRoute(rl+1, 'L') s += 'U' print(s)
s226839519
Accepted
29
9,172
387
def addRoute(i, c): t = '' for _ in range(i): t += c return t pos=list(map(int, input().split())) ud = pos[3] - pos[1] rl = pos[2] - pos[0] s = '' s += addRoute(ud, 'U') s += addRoute(rl, 'R') s += addRoute(ud, 'D') s += addRoute(rl, 'L') s += 'L' s += addRoute(ud+1, 'U') s += addRoute(rl+1, 'R') s += 'DR' s += addRoute(ud+1, 'D') s += addRoute(rl+1, 'L') s += 'U' print(s)
s512894726
p03369
u365013885
2,000
262,144
Wrong Answer
17
2,940
93
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
s = list(input()) t = 0 for row in s: if row == 'o': t += 1 print(800 + 100 * t)
s004401814
Accepted
17
2,940
93
s = list(input()) t = 0 for row in s: if row == 'o': t += 1 print(700 + 100 * t)
s104783026
p03471
u598650050
2,000
262,144
Wrong Answer
677
9,168
483
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
num_list = list(map(int, input().split(' '))) N = num_list[0] Y = num_list[1] total = 0 ans = '-1 -1 -1' for n in range(N+1): rest = N - n a = n*10000 if rest == 0: if a == Y: ans = str(a) + ' 0 0' break for i in range(rest+1): rest_2 = rest - i b = i*5000 c = rest_2*1000 if rest == 0: if a+b == Y: ans = str(a) + ' ' + str(b) + ' 0' break elif a+b+c == Y: ans = str(a) + ' ' + str(b) + ' ' + str(c) print(ans)
s704943131
Accepted
597
9,136
546
num_list = list(map(int, input().split(' '))) N = num_list[0] Y = num_list[1] total = 0 ans = '-1 -1 -1' for n in range(N+1): rest = N - n a = n*10000 if rest == 0: if a == Y: ans = str(int(a/10000)) + ' 0 0' break for i in range(rest+1): rest_2 = rest - i b = i*5000 c = rest_2*1000 if rest == 0: if a+b == Y: ans = str(int(a/10000)) + ' ' + str(int(b/5000)) + ' 0' break elif a+b+c == Y: ans = str(int(a/10000)) + ' ' + str(int(b/5000)) + ' ' + str(int(c/1000)) print(ans)
s839103397
p04044
u843482581
2,000
262,144
Wrong Answer
32
9,172
113
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
N, L = map(int, input().split()) s = [] for i in range(N): s.append(input()) print(s) print(''.join(sorted(s)))
s743493667
Accepted
28
8,872
104
N, L = map(int, input().split()) s = [] for i in range(N): s.append(input()) print(''.join(sorted(s)))
s602718725
p03408
u747427153
2,000
262,144
Wrong Answer
18
3,064
192
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
n = int(input()) s = [input() for i in range(n)] m = int(input()) t = [input() for i in range(m)] l =[0]*n for j in range(n): a = s.count(s[j]) b = s.count(s[j]) l[j] = a-b print(max(l))
s195756889
Accepted
19
3,064
199
n = int(input()) s = [input() for i in range(n)] m = int(input()) t = [input() for i in range(m)] l =[0]*n for j in range(n): a = s.count(s[j]) b = t.count(s[j]) l[j] = a-b print(max(max(l),0))
s499985893
p04029
u637551956
2,000
262,144
Wrong Answer
19
2,940
31
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()) print((N+1)*N/2)
s383437878
Accepted
17
2,940
38
N=int(input()) print(round((N+1)*N/2))
s807573479
p02385
u764759179
1,000
131,072
Wrong Answer
40
8,184
997
Write a program which reads the two dices constructed in the same way as [Dice I](description.jsp?id=ITP1_11_A), and determines whether these two dices are identical. You can roll a dice in the same way as [Dice I](description.jsp?id=ITP1_11_A), and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
#!/usr/bin/env python3 # coding: utf-8 import random class Dice() : mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2), 'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1)} way = ("N","E","W","S") def __init__(self, data): self.label = data def move(self, data): self.label = [self.label[idx] for idx in self.mask[data]] def get_up(self): return self.label[0] def compare(self, dice2): ok = False for i in range(1000): check = True for i2 in range(6): if self.label[i2] == dice2.label[i2] : continue else: check = False break if check : ok = True break else: self.move(self.way[random.randint(0,3)]) return ok dice1 = Dice(input().split()) dice2 = Dice(input().split()) if dice1.compare(dice2) : print ("OK") else: print ("NG")
s911352482
Accepted
40
8,192
1,348
#!/usr/bin/env python3 # coding: utf-8 import random class Dice() : mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2), 'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1),'CW':(0,2,4,1,3,5)} way = ("N","E","W","S","CW","Nop") def __init__(self, data): self.label = data def move(self, data): if data == "Nop": return self.label = [self.label[idx] for idx in self.mask[data]] def get_up(self): return self.label[0] def compare_6sq(self, dice2): check = True for i in range(6): if self.label[i] == dice2.label[i] : continue else: check = False break return check def compare_4rot(self, dice2): ok = False for i in range(4): self.move("CW") if self.compare_6sq(dice2) : ok =True break return ok def compare(self,dice2): ok = False orderway =("Nop","E","N","E","N","E") for s in orderway: self.move(s) if self.compare_4rot(dice2): ok = True break return ok dice1 = Dice(input().split()) dice2 = Dice(input().split()) if dice1.compare(dice2) : print ("Yes") else: print ("No")
s521074320
p03719
u609738635
2,000
262,144
Wrong Answer
17
2,940
84
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
A, B, C = map(int, input().split()) print("YES") if(C>=A and C<=B) else print("NO")
s864352870
Accepted
17
2,940
84
A, B, C = map(int, input().split()) print("Yes") if(C>=A and C<=B) else print("No")
s771649051
p02975
u883621917
2,000
1,048,576
Wrong Answer
61
14,996
217
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
_input = [i for i in open(0).read().split('\n') if i] n = int(_input[0]) a = [int(i) for i in _input[1].split()] import functools if functools.reduce(lambda a, b: a^b, a) == 0: print('YES') else: print('NO')
s426636832
Accepted
61
14,996
217
_input = [i for i in open(0).read().split('\n') if i] n = int(_input[0]) a = [int(i) for i in _input[1].split()] import functools if functools.reduce(lambda a, b: a^b, a) == 0: print('Yes') else: print('No')
s570390219
p04030
u580362735
2,000
262,144
Wrong Answer
17
3,060
158
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
s = input() ans = '' for i in range(len(s)): if s[i] == '0': ans += '0' elif s[i] == '1': ans += '1' else: ans = ans[:len(ans)-2] print(ans)
s714629205
Accepted
17
3,060
158
s = input() ans = '' for i in range(len(s)): if s[i] == '0': ans += '0' elif s[i] == '1': ans += '1' else: ans = ans[:len(ans)-1] print(ans)
s388851456
p03730
u375695365
2,000
262,144
Wrong Answer
37
3,060
136
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()) for i in range(1,100000): if a+(a*i)%b==c: print("YES") break else: print("NO")
s251445033
Accepted
39
2,940
138
a,b,c=map(int,input().split()) for i in range(1,100000): if (a+(a*i))%b==c: print("YES") break else: print("NO")
s120421184
p02396
u897625141
1,000
131,072
Wrong Answer
50
7,992
146
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.
import sys count = 0 for i in sys.stdin.readlines(): count +=1 if i == 0: break else: print("Case "+str(count)+" "+i)
s703419030
Accepted
140
7,484
128
count = 0 while True: count += 1 a = int(input()) if a == 0: break print("Case "+str(count)+": "+str(a))
s528002078
p02694
u728483880
2,000
1,048,576
Wrong Answer
108
27,132
173
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?
import numpy as np import math X=int(input()) tmp=100 #x=((math.log(X)/math.log(1.01)))//1+1 for i in range(5000): tmp=int(tmp*1.01) if(tmp>X): print(i+1) break
s041724160
Accepted
116
26,944
174
import numpy as np import math X=int(input()) tmp=100 #x=((math.log(X)/math.log(1.01)))//1+1 for i in range(6000): tmp=int(tmp*1.01) if(tmp>=X): print(i+1) break
s700527282
p03544
u013408661
2,000
262,144
Wrong Answer
18
3,060
113
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
luca=[0]*87 luca[0]=2 luca[1]=1 for i in range(3,87): luca[i]=luca[i-1]+luca[i-2] n=int(input()) print(luca[n])
s445128754
Accepted
17
2,940
113
luca=[0]*87 luca[0]=2 luca[1]=1 for i in range(2,87): luca[i]=luca[i-1]+luca[i-2] n=int(input()) print(luca[n])
s355186957
p03658
u663014688
2,000
262,144
Wrong Answer
17
3,060
139
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
N,K = map(int, input().split()) ans = 0 l = [int(i) for i in input().split()] l = sorted(l) for i in range(K-1): ans += l[i] print(ans)
s152917393
Accepted
17
2,940
151
N,K = map(int, input().split()) ans = 0 l = [int(i) for i in input().split()] l = sorted(l, reverse=True) for i in range(K): ans += l[i] print(ans)
s811899294
p02975
u762420987
2,000
1,048,576
Wrong Answer
51
14,116
154
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
N = int(input()) alist = list(map(int, input().split())) ans = alist[0] for a in alist: ans ^= a if ans == 0: print("Yes") else: print("No")
s029938842
Accepted
52
14,212
169
N = int(input()) alist = list(map(int, input().split())) ans = alist[0] ^ alist[1] for a in alist[2:]: ans ^= a if ans == 0: print("Yes") else: print("No")
s724510807
p03711
u434500430
2,000
262,144
Wrong Answer
17
2,940
210
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
x, y = map(int, input().split()) if x == 2 or y == 2: print('No') elif x == 4 or x == 6 or x == 9 or x == 11: if y == 4 or y == 6 or y == 9 or y == 11: print('Yes') else: print('No')
s706759178
Accepted
17
3,064
413
x, y = map(int, input().split()) if x == 2 or y == 2: print('No') elif x == 4 or x == 6 or x == 9 or x == 11: if y == 4 or y == 6 or y == 9 or y == 11: print('Yes') else: print('No') elif x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12: if x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12: print('Yes') else: print('No')
s773433930
p03416
u263830634
2,000
262,144
Wrong Answer
17
2,940
52
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
A, B = map(int, input().split()) print ((B-A)//100)
s372424805
Accepted
35
2,940
159
A, B = map(int, input().split()) count = 0 for i in range(A, B+1): if i//10000 == i%10 and (i//1000)%10 == (i%100)//10: count += 1 print (count)
s371476723
p03473
u825528847
2,000
262,144
Wrong Answer
19
3,316
36
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
M = int(input()) print(24 + (M-24))
s738984603
Accepted
18
2,940
36
M = int(input()) print(24 + (24-M))
s241531268
p04029
u408620326
2,000
262,144
Wrong Answer
18
2,940
45
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?
print(sum([int(x) for x in input().split()]))
s553976408
Accepted
18
2,940
48
print(sum([x for x in range(1,int(input())+1)]))
s019539561
p03712
u587589241
2,000
262,144
Wrong Answer
18
3,060
142
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
h,w=map(int,input().split()) a=[input() for i in range(h)] print((w+1)*"#") for i in range(h): print("#",a[i],"#",sep="") print((w+1)*"#")
s958803213
Accepted
17
3,060
142
h,w=map(int,input().split()) a=[input() for i in range(h)] print((w+2)*"#") for i in range(h): print("#",a[i],"#",sep="") print((w+2)*"#")
s382311826
p03644
u634046173
2,000
262,144
Wrong Answer
28
9,088
78
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N=int(input()) k=1 for i in range(1,7): k*= i if k > N: break print(k)
s181591644
Accepted
25
9,128
87
N=int(input()) for i in range(6,-1,-1): k = 2**i if N >= k: print(k) exit()
s975489074
p03493
u642905089
2,000
262,144
Wrong Answer
17
2,940
84
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.
n = input() ct = 0 for i in range(len(n)): if i == "1": ct += 1 print(ct)
s066648225
Accepted
17
2,940
82
n = input() ct = 0 for i in range(3): if n[i] == "1": ct += 1 print(ct)
s225277990
p03854
u049725710
2,000
262,144
Wrong Answer
59
3,316
219
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=str(input()) s=s[::-1] print(s) stack="" for i in s: stack=i+stack if stack=="dream"or stack=="dreamer"or stack=="erase"or stack=="eraser": stack="" elif len(stack)>7: print("NO") exit() print("YES")
s235177300
Accepted
63
3,188
210
s=str(input()) s=s[::-1] stack="" for i in s: stack=i+stack if stack=="dream"or stack=="dreamer"or stack=="erase"or stack=="eraser": stack="" elif len(stack)>7: print("NO") exit() print("YES")
s853528784
p03861
u054556734
2,000
262,144
Wrong Answer
17
2,940
92
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x = map(int,input().split()) a += (a - a%x) b -= b%x ans = b//x - a//x + 1 print(ans)
s942996382
Accepted
17
2,940
106
a,b,x = map(int,input().split()) a += (x - a%x) if a%x else 0 b -= b%x ans = b//x - a//x + 1 print(ans)
s003434840
p03861
u300637346
2,000
262,144
Wrong Answer
17
2,940
85
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x=map(int,input().split()) print((b-a+1)//x) if a%x == 0 else print((b-a+1)//x-1)
s522060801
Accepted
18
2,940
56
a,b,x=map(int,input().split()) print((b//x)-((a-1)//x))
s727479398
p03546
u576917603
2,000
262,144
Wrong Answer
34
3,444
475
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
h,w=map(int,input().split()) field=[[int(i) for i in input().split()] for i in range(10)] wall=[[int(i) for i in input().split()] for i in range(h)] def warshall_floyd(d,n): for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d ans=0 for i in wall: for j in i: if j!=-1 and j!=1: ans+=field[j][1] print(ans)
s975975568
Accepted
35
3,316
500
h,w=map(int,input().split()) field=[[int(i) for i in input().split()] for i in range(10)] wall=[[int(i) for i in input().split()] for i in range(h)] def warshall_floyd(d,n): for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d d=warshall_floyd(field,10) ans=0 for i in wall: for j in i: if j!=-1 and j!=1: ans+=d[j][1] print(ans)
s566710250
p02612
u503111914
2,000
1,048,576
Wrong Answer
29
9,140
30
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N%1000)
s065040361
Accepted
29
9,144
77
N = int(input()) if N % 1000 == 0: print(0) else: print(1000-N%1000)
s134851055
p03478
u288786530
2,000
262,144
Wrong Answer
63
3,060
419
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b=map(int,input().split()) ans = 0 l = range(1, n+1) def digitSum(n): s = str(n) array = list(map(int, s)) return sum(array) # => 6 # => 27 for i in l: if digitSum(i) >= a and digitSum(i) <= b: ans += digitSum(i) print(ans)
s092072382
Accepted
33
2,940
144
n, a, b = map(int, input().split()) ans = 0 for i in range(1, n+1): if a <= sum([int(c) for c in str(i)]) <= b: ans += i print(ans)
s877547258
p03387
u902151549
2,000
262,144
Wrong Answer
34
4,848
3,583
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
# coding: utf-8 import re import math from collections import defaultdict from collections import deque import itertools from copy import deepcopy import random import time import os import queue import sys import datetime from functools import lru_cache #@lru_cache(maxsize=None) readline=sys.stdin.readline sys.setrecursionlimit(2000000) #import numpy as np alphabet="abcdefghijklmnopqrstuvwxyz" mod=int(10**9+7) inf=int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find(): def __init__(self,n): self.n=n self.P=[a for a in range(N)] self.rank=[0]*n def find(self,x): if(x!=self.P[x]):self.P[x]=self.find(self.P[x]) return self.P[x] def same(self,x,y): return self.find(x)==self.find(y) def link(self,x,y): if self.rank[x]<self.rank[y]: self.P[x]=y elif self.rank[y]<self.rank[x]: self.P[y]=x else: self.P[x]=y self.rank[y]+=1 def unite(self,x,y): self.link(self.find(x),self.find(y)) def size(self): S=set() for a in range(self.n): S.add(self.find(a)) return len(S) def is_pow(a,b): now=b while now<a: now*=b if now==a:return True else:return False def bin_(num,size): A=[0]*size for a in range(size): if (num>>(size-a-1))&1==1: A[a]=1 else: A[a]=0 return A def get_facs(n,mod_=0): A=[1]*(n+1) for a in range(2,len(A)): A[a]=A[a-1]*a if(mod_>0):A[a]%=mod_ return A def comb(n,r,mod,fac): if(n-r<0):return 0 return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod def next_comb(num,size): x=num&(-num) y=num+x z=num&(~y) z//=x z=z>>1 num=(y|z) if(num>=(1<<size)):return False else:return num def get_primes(n,type="int"): if n==0: if type=="int":return [] else:return [False] A=[True]*(n+1) A[0]=False A[1]=False for a in range(2,n+1): if A[a]: for b in range(a*2,n+1,a): A[b]=False if(type=="bool"):return A B=[] for a in range(n+1): if(A[a]):B.append(a) return B def is_prime(num): if(num<=1):return False i=2 while i*i<=num: if(num%i==0):return False i+=1 return True def ifelse(a,b,c): if a:return b else:return c def join(A,c=""): n=len(A) A=list(map(str,A)) s="" for a in range(n): s+=A[a] if(a<n-1):s+=c return s def factorize(n,type_="dict"): b = 2 list_ = [] while b * b <= n: while n % b == 0: n //= b list_.append(b) b+=1 if n > 1:list_.append(n) if type_=="dict": dic={} for a in list_: if a in dic: dic[a]+=1 else: dic[a]=1 return dic elif type_=="list": return list_ else: return None def floor_(n,x=1): return x*(n//x) def ceil_(n,x=1): return x*((n+x-1)//x) return ret def seifu(x): return x//abs(x) ###################################################################################################### def main(): A,B,C=map(int,input().split()) mmax=max([A,B,C]) ssum=A+B+C n=math.ceil((ssum-mmax*30)/2) ans=(ssum+n*2)//3 main()
s873212612
Accepted
36
4,972
3,604
# coding: utf-8 import re import math from collections import defaultdict from collections import deque import itertools from copy import deepcopy import random import time import os import queue import sys import datetime from functools import lru_cache #@lru_cache(maxsize=None) readline=sys.stdin.readline sys.setrecursionlimit(2000000) #import numpy as np alphabet="abcdefghijklmnopqrstuvwxyz" mod=int(10**9+7) inf=int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find(): def __init__(self,n): self.n=n self.P=[a for a in range(N)] self.rank=[0]*n def find(self,x): if(x!=self.P[x]):self.P[x]=self.find(self.P[x]) return self.P[x] def same(self,x,y): return self.find(x)==self.find(y) def link(self,x,y): if self.rank[x]<self.rank[y]: self.P[x]=y elif self.rank[y]<self.rank[x]: self.P[y]=x else: self.P[x]=y self.rank[y]+=1 def unite(self,x,y): self.link(self.find(x),self.find(y)) def size(self): S=set() for a in range(self.n): S.add(self.find(a)) return len(S) def is_pow(a,b): now=b while now<a: now*=b if now==a:return True else:return False def bin_(num,size): A=[0]*size for a in range(size): if (num>>(size-a-1))&1==1: A[a]=1 else: A[a]=0 return A def get_facs(n,mod_=0): A=[1]*(n+1) for a in range(2,len(A)): A[a]=A[a-1]*a if(mod_>0):A[a]%=mod_ return A def comb(n,r,mod,fac): if(n-r<0):return 0 return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod def next_comb(num,size): x=num&(-num) y=num+x z=num&(~y) z//=x z=z>>1 num=(y|z) if(num>=(1<<size)):return False else:return num def get_primes(n,type="int"): if n==0: if type=="int":return [] else:return [False] A=[True]*(n+1) A[0]=False A[1]=False for a in range(2,n+1): if A[a]: for b in range(a*2,n+1,a): A[b]=False if(type=="bool"):return A B=[] for a in range(n+1): if(A[a]):B.append(a) return B def is_prime(num): if(num<=1):return False i=2 while i*i<=num: if(num%i==0):return False i+=1 return True def ifelse(a,b,c): if a:return b else:return c def join(A,c=""): n=len(A) A=list(map(str,A)) s="" for a in range(n): s+=A[a] if(a<n-1):s+=c return s def factorize(n,type_="dict"): b = 2 list_ = [] while b * b <= n: while n % b == 0: n //= b list_.append(b) b+=1 if n > 1:list_.append(n) if type_=="dict": dic={} for a in list_: if a in dic: dic[a]+=1 else: dic[a]=1 return dic elif type_=="list": return list_ else: return None def floor_(n,x=1): return x*(n//x) def ceil_(n,x=1): return x*((n+x-1)//x) return ret def seifu(x): return x//abs(x) ###################################################################################################### def main(): A,B,C=map(int,input().split()) mmax=max([A,B,C]) ssum=A+B+C n=mmax*3-ssum if n%2==1: mmax+=1 print((mmax*3-ssum)//2) main()
s029632533
p03944
u150985282
2,000
262,144
Wrong Answer
83
3,188
844
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] = list(map(int, input().split())) [x, y, a] = [ [], [], [] ] for _ in range(N): input_line = list(map(int, input().split())) x.append(input_line[0]) y.append(input_line[1]) a.append(input_line[2]) area = [] for i in range(W+1): area.append([]) for j in range(H+1): area[i].append("") for i in range(N): if a[i] == 1: for X in range(x[i]): for Y in range(H+1): area[X][Y] = "f" if a[i] == 2: for X in range(x[i], W+1): for Y in range(H+1): area[X][Y] = "f" if a[i] == 3: for X in range(W+1): for Y in range(y[i]): area[X][Y] = "f" if a[i] == 4: for X in range(W+1): for Y in range(y[i], H+1): area[X][Y] = "f" count = 0 for i in range(W+1): for j in range(H+1): if area[i][j] == "": count += 1 print(count)
s768973083
Accepted
92
3,188
824
[W, H, N] = list(map(int, input().split())) [x, y, a] = [ [], [], [] ] for _ in range(N): input_line = list(map(int, input().split())) x.append(input_line[0]) y.append(input_line[1]) a.append(input_line[2]) area = [] for i in range(W): area.append([]) for j in range(H): area[i].append("") for i in range(N): if a[i] == 1: for X in range(x[i]): for Y in range(H): area[X][Y] = "f" if a[i] == 2: for X in range(x[i], W): for Y in range(H): area[X][Y] = "f" if a[i] == 3: for X in range(W): for Y in range(y[i]): area[X][Y] = "f" if a[i] == 4: for X in range(W): for Y in range(y[i], H): area[X][Y] = "f" count = 0 for i in range(W): for j in range(H): if area[i][j] == "": count += 1 print(count)
s820753118
p03455
u543016260
2,000
262,144
Wrong Answer
25
9,100
86
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b =map(int, input().split()) if a*b%2==1: print("odd") else: print("even")
s398034306
Accepted
28
9,028
86
a, b =map(int, input().split()) if a*b%2==1: print("Odd") else: print("Even")
s962782271
p03644
u227082700
2,000
262,144
Wrong Answer
21
2,940
55
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
import math n=int(input());print(2**(math.log(n,2)//1))
s391319514
Accepted
18
2,940
43
n=int(input()) print(1<<(n.bit_length()-1))
s196946409
p03998
u087470052
2,000
262,144
Wrong Answer
18
3,064
572
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
Sa = input() Sb = input() Sc = input() data = [Sa, Sb, Sc] print(data[0][0]) target = 0 while True: print(data) if(data[target] == ""): if target == 0: print("A") if target == 1: print("B") if target == 2: print("C") break if data[target][0] == "a": data[target] = data[target][1:] target = 0 elif data[target][0] == "b": data[target] = data[target][1:] target = 1 elif data[target][0] == "c": data[target] = data[target][1:] target = 2
s410921799
Accepted
18
3,064
538
Sa = input() Sb = input() Sc = input() data = [Sa, Sb, Sc] target = 0 while True: if(data[target] == ""): if target == 0: print("A") if target == 1: print("B") if target == 2: print("C") break if data[target][0] == "a": data[target] = data[target][1:] target = 0 elif data[target][0] == "b": data[target] = data[target][1:] target = 1 elif data[target][0] == "c": data[target] = data[target][1:] target = 2
s930981363
p03720
u140251125
2,000
262,144
Wrong Answer
18
2,940
215
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
# input N, M = map(int, input().split()) R = [list(map(int, input().split())) for _ in range(M)] for i in range(N): ans = 0 for j in range(M): if i in R[j]: ans += 1 print(ans)
s576881682
Accepted
18
2,940
218
# input N, M = map(int, input().split()) R = [list(map(int, input().split())) for _ in range(M)] for i in range(1, N + 1): ans = 0 for j in range(M): if i in R[j]: ans += 1 print(ans)
s462493124
p03555
u786020649
2,000
262,144
Wrong Answer
31
9,052
104
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
t=list(input()) s=list(input()) if reversed(t)==s and reversed(s)==t: print('YES') else: print('NO')
s575585927
Accepted
30
9,000
101
for x,y in zip(input(),reversed(input())): if x!=y: print('NO') break else: print('YES')
s785414431
p03044
u861038878
2,000
1,048,576
Wrong Answer
2,107
162,832
1,253
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.
# -*- coding: utf-8 -*- import sys def dfs(i): print(i) print(color) for v,w in V.get(i, []): if (w % 2) == 0: if color[v] == -1: color[v] = color[i] elif color[v] == color[i]: continue elif color[v] != color[i]: return False else: if color[v] == -1: color[v] = 0 if color[i] else 1 elif color[v] == color[i]: return False elif color[v] != color[i]: continue dfs(v) return True if __name__ == '__main__': n = int(input()) V = {} # key:vertex, value:[[vertex opposited, wight]] color = {} # 0 or 1 or -1 for i in range(1, n): u,v,w = map(int, input().split()) if not V.get(u, False): V[u] = [[v,w]] else: V[u].append([v,w]) if not V.get(v, False): V[v] = [[u,w]] else: V[v].append([u,w]) for i in range(1, n+1): color[i] = -1 print(V) i = 1 color[i] = 0 while dfs(i): print(color) for j in range(1, n+1): if color[j] == -1: i = j color[j] = 0 break for j in range(1, n+1): print(color[j]) sys.exit() print('No')
s908812767
Accepted
1,009
99,116
1,278
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(100000) def dfs(i): for v,w in V.get(i, []): if (w % 2) == 0: if color[v] == -1: color[v] = color[i] elif color[v] == color[i]: continue elif color[v] != color[i]: return False else: if color[v] == -1: color[v] = 0 if color[i] else 1 elif color[v] == color[i]: return False elif color[v] != color[i]: continue dfs(v) return True if __name__ == '__main__': n = int(input()) V = {} # key:vertex, value:[[vertex opposited, wight]] color = {} # 0 or 1 or -1 for i in range(1, n): u,v,w = map(int, input().split()) if not V.get(u, False): V[u] = [[v,w]] else: V[u].append([v,w]) if not V.get(v, False): V[v] = [[u,w]] else: V[v].append([u,w]) for i in range(1, n+1): color[i] = -1 while True: i = 0 for j in range(1, n+1): if color[j] == -1: i = j color[i] = 0 break if i == 0: for j in range(1, n+1): print(color[j]) break else: if not dfs(i): print('No') break
s908594472
p02388
u729919969
1,000
131,072
Wrong Answer
20
7,392
15
Write a program which calculates the cube of a given integer x.
int(input())**3
s405602637
Accepted
20
7,580
22
print(int(input())**3)
s735219972
p03836
u732412551
2,000
262,144
Wrong Answer
17
3,064
532
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) X = ["D", "U"] Y = ["R", "L"] if sx == tx or sy == ty: if sy == ty: X, Y = Y, X sy, ty = sx, tx dy = abs(ty - sy) d = sy < ty nd = sy > ty ans = Y[d]*(dy+1)+X[0]*2+Y[nd]*(dy+2)+X[1]*2+Y[d]+X[0]+Y[d]*dy+X[1]*2+Y[nd]*dy+X[0] else: dx = abs(tx-sx) dy = abs(ty-sy) xd = sx < tx yd = sy < ty ans = Y[yd]*dy+X[xd]*dx+Y[not yd]*dy+X[not xd]*(dx+1)+Y[yd]*(dy+1)+X[xd]*(dx+1)+Y[not yd]+X[xd]+Y[not yd]*(dy+1)+X[not xd]*(dx+1)+Y[yd] print(ans)
s333663701
Accepted
17
3,064
532
sx, sy, tx, ty = map(int, input().split()) X = ["L", "R"] Y = ["D", "U"] if sx == tx or sy == ty: if sy == ty: X, Y = Y, X sy, ty = sx, tx dy = abs(ty - sy) d = sy < ty nd = sy > ty ans = Y[d]*(dy+1)+X[0]*2+Y[nd]*(dy+2)+X[1]*2+Y[d]+X[0]+Y[d]*dy+X[1]*2+Y[nd]*dy+X[0] else: dx = abs(tx-sx) dy = abs(ty-sy) xd = sx < tx yd = sy < ty ans = Y[yd]*dy+X[xd]*dx+Y[not yd]*dy+X[not xd]*(dx+1)+Y[yd]*(dy+1)+X[xd]*(dx+1)+Y[not yd]+X[xd]+Y[not yd]*(dy+1)+X[not xd]*(dx+1)+Y[yd] print(ans)
s890199072
p03737
u536377809
2,000
262,144
Wrong Answer
18
2,940
53
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
print("".join([item[0] for item in input().split()]))
s352034343
Accepted
17
2,940
61
print("".join([item[0].upper() for item in input().split()]))
s949158090
p02613
u020933954
2,000
1,048,576
Wrong Answer
29
9,200
291
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.
num=input() if int(num)<=1000: change=1000-int(num) else: array_1=list(num) array_1=array_1[-4:] a=''.join(array_1) b=int(array_1[-4])+1 pay=b*1000 change=pay-int(a) if array_1[-1]=="0" and array_1[-2]=="0" and array_1[-3]=="0": change=0 print(change)
s860396600
Accepted
160
16,224
386
input_one=int(input()) array=[] a={"AC":0,"WA":0,"TLE":0,"RE":0} for i in range(input_one): array.append(input()) for i in array: if i=="AC": a[i]+=1 elif i=="WA": a[i]+=1 elif i=="TLE": a[i]+=1 elif i=="RE": a[i]+=1 else: print() print("AC x",a["AC"]) print("WA x",a["WA"]) print("TLE x",a["TLE"]) print("RE x",a["RE"])
s099551227
p02400
u567380442
1,000
131,072
Wrong Answer
30
6,900
141
Write a program which calculates the area and circumference of a circle for given radius r.
import math r = float(input()) circu?mference = 2 * math.pi * r area = math.pi * (r ** 2) print("{:f} {:f}".format(circu?mference, area))
s155564632
Accepted
30
6,828
139
import math r = float(input()) area = math.pi * (r ** 2) circumference = 2 * math.pi * r print("{:f} {:f}".format(area, circumference))
s236822217
p03860
u442948527
2,000
262,144
Wrong Answer
28
9,056
39
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
print("AtCoder "+input()[0]+" Contest")
s678698465
Accepted
26
9,020
25
print("A"+input()[8]+"C")
s471968542
p03836
u217627525
2,000
262,144
Wrong Answer
18
3,064
578
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx,sy,tx,ty=map(int,input().split()) dx=tx-sx dy=ty-sy ans="" for i in range(4): if i==2: ans+="L" dx+=1 dy+=1 elif i==3: ans+="DR" if dy>=0: print("U,i=",i) print(dy) ans+="U"*dy dy=dy*(-1) else: print("D,i=",i) print(dy) ans+="D"*(dy*(-1)) dy=dy*(-1) if dx>=0: print("R,i=",i) print(dx) ans+="R"*dx dx=dx*(-1) else: print("L,i=",i) print(dx) ans+="L"*(dx*(-1)) dx=dx*(-1) ans+="U" print(ans)
s001065118
Accepted
17
3,064
410
sx,sy,tx,ty=map(int,input().split()) dx=tx-sx dy=ty-sy ans="" for i in range(4): if i==2: ans+="L" dx+=1 dy+=1 elif i==3: ans+="DR" if dy>=0: ans+="U"*dy dy=dy*(-1) else: ans+="D"*(dy*(-1)) dy=dy*(-1) if dx>=0: ans+="R"*dx dx=dx*(-1) else: ans+="L"*(dx*(-1)) dx=dx*(-1) ans+="U" print(ans)
s861790031
p02281
u798803522
1,000
131,072
Wrong Answer
30
8,100
1,011
Binary trees are defined recursively. A binary tree _T_ is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: \- a root node. \- a binary tree called its left subtree. \- a binary tree called its right subtree. Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: 1. Print the root, the left subtree and right subtree (preorder). 2. Print the left subtree, the root and right subtree (inorder). 3. Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
from collections import defaultdict def preorder(here, conn, chain): if here == -1: return chain.append(here) if conn[here]: preorder(conn[here][0], conn, chain) preorder(conn[here][1], conn, chain) def inorder(here, conn, chain): if here == -1: return if conn[here]: inorder(conn[here][0], conn, chain) chain.append(here) inorder(conn[here][1], conn, chain) def postorder(here, conn, chain): if here == -1: return if conn[here]: postorder(conn[here][0], conn, chain) postorder(conn[here][1], conn, chain) chain.append(here) query = int(input()) connect = defaultdict(list) for _ in range(query): here, left, right = (int(n) for n in input().split(" ")) connect[here] = [left, right] preo = [] ino = [] posto = [] preorder(0, connect, preo) inorder(0, connect, ino) postorder(0, connect, posto) print("Preorder") print(*preo) print("Inorder") print(*ino) print("Postorder") print(*posto)
s520571577
Accepted
30
8,108
1,235
from collections import defaultdict def preorder(here, conn, chain): if here == -1: return chain.append(here) if conn[here]: preorder(conn[here][0], conn, chain) preorder(conn[here][1], conn, chain) def inorder(here, conn, chain): if here == -1: return if conn[here]: inorder(conn[here][0], conn, chain) chain.append(here) inorder(conn[here][1], conn, chain) def postorder(here, conn, chain): if here == -1: return if conn[here]: postorder(conn[here][0], conn, chain) postorder(conn[here][1], conn, chain) chain.append(here) query = int(input()) connect = defaultdict(list) in_v = [0 for n in range(query + 1)] for _ in range(query): here, left, right = (int(n) for n in input().split(" ")) connect[here] = [left, right] in_v[left] += 1 in_v[right] += 1 for i in range(query): if not in_v[i]: root = i break preo = [] ino = [] posto = [] preorder(root, connect, preo) inorder(root, connect, ino) postorder(root, connect, posto) print("Preorder") print("", end = " ") print(*preo) print("Inorder") print("", end = " ") print(*ino) print("Postorder") print("", end = " ") print(*posto)
s335579006
p00008
u454259029
1,000
131,072
Wrong Answer
30
7,512
236
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
n = int(input()) cnt = 0 for i in range(10): for j in range(10): for k in range(10): for l in range(10): if i+j+k+l == n: cnt += 1 print(i,j,k,l) print(cnt)
s907494646
Accepted
200
7,532
320
while True: try: n = int(input()) cnt = 0 for i in range(10): for j in range(10): for k in range(10): for l in range(10): if i+j+k+l == n: cnt += 1 print(cnt) except: break
s710925309
p03485
u571832343
2,000
262,144
Wrong Answer
17
2,940
70
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
import math a,b = map(int,input().split()) print(math.ceil((a+b-1)/b))
s470272181
Accepted
26
9,092
48
a,b=map(int,input().split()) print(-(-(a+b)//2))
s333013353
p03131
u746206084
2,000
1,048,576
Wrong Answer
17
2,940
110
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
k,a,b=map(int,input().split()) g=k+1 if b-a<=1: print(g) else: k-=a-1 h=1+(k//2)*(b-a) print(max(g,h))
s787531770
Accepted
17
3,060
124
k,a,b=map(int,input().split()) g=k+1 if b-a<=1: print(g) else: k-=a-1 h=a+(k//2)*(b-a)+(k%2) print(max(g,h))
s679939779
p03909
u503111914
2,000
262,144
Wrong Answer
17
2,940
196
There is a grid with H rows and W columns. The square at the i-th row and j-th column contains a string S_{i,j} of length 5. The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet. Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location. For example, the square at the 6-th row and 8-th column should be reported as `H6`.
import sys H,W = map(int,input().split()) for i in range(H): S = list(map(str,input().split())) for j in range(W): if S[j] == "snuke": print(chr(65+i)+str(i+1)) sys.exit()
s888092200
Accepted
18
2,940
196
import sys H,W = map(int,input().split()) for i in range(H): S = list(map(str,input().split())) for j in range(W): if S[j] == "snuke": print(chr(65+j)+str(i+1)) sys.exit()
s067901511
p03494
u306071800
2,000
262,144
Wrong Answer
18
2,940
190
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.
def divide_count(n): cnt = 0 while n % 2 == 0: n /= 2 cnt += 1 return cnt n = int(input()) a = list(map(int, input().split())) print(list(map(divide_count, a)))
s807753281
Accepted
19
3,188
189
def divide_count(n): cnt = 0 while n % 2 == 0: n /= 2 cnt += 1 return cnt n = int(input()) a = list(map(int, input().split())) print(min(map(divide_count, a)))
s454513225
p02865
u505547600
2,000
1,048,576
Wrong Answer
17
2,940
90
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
target = int(input()) if(target%2==0): print(target/2-1) else: print(target+1/2-1)
s004531918
Accepted
17
2,940
109
target = int(input()) if(target%2==0): print(int(target/2-1)) else: print(int((target+1)/2-1))
s958582763
p02399
u548252256
1,000
131,072
Wrong Answer
20
5,612
94
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a,b = map(int,input().split(" ")) c = a // b d = a % b e = float(a) / float(b) print(c,d,e)
s490549745
Accepted
20
5,612
112
a,b = map(int,input().split(" ")) c = a // b d = a % b e = float(a) / float(b) print(c,d,"{:.5f}".format(e))
s577758454
p03472
u519923151
2,000
262,144
Wrong Answer
2,104
12,068
471
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
n,h = map(int, input().split()) ka = [] th = [] for _ in range(n): a, b = map(int, input().split()) ka.append(a) th.append(b) thr = sorted(th, reverse=True) if max(ka) >= max(th): print(-(-h//max(ka))) exit() res = 0 for i in range(n): if max(ka) < th[i]: h -= th[i] res += 1 if h >1: pass else: print(res) exit() else: print(res+(-(-h//max(ka)))) exit()
s934996493
Accepted
400
17,456
569
n,h = map(int, input().split()) ka = [] th = [] for _ in range(n): a, b = map(int, input().split()) ka.append(a) th.append(b) ths = sorted(th) thr = sorted(th, reverse=True) import itertools sumthr = list(itertools.accumulate(thr)) mk = max(ka) if mk >= max(th): print(-(-h//mk)) exit() import bisect t = bisect.bisect(ths,mk) res = 0 for i in range(n-t): if h > sumthr[i]: pass else: print(i+1) exit() if i ==n-1: print(-((sumthr[-1]-h)//mk)+i+1) exit() print(-((sumthr[i]-h)//mk)+i+1)
s993592676
p03434
u428397309
2,000
262,144
Wrong Answer
17
3,060
204
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 -*- N = int(input()) a = list(map(int, input().split())) cards = sorted(a) alice = cards[-1::-2] bob = cards[-2::-2] print(alice) print(bob) ans = sum(alice) - sum(bob) print(ans)
s057104285
Accepted
17
2,940
180
# -*- coding: utf-8 -*- N = int(input()) a = list(map(int, input().split())) cards = sorted(a) alice = cards[-1::-2] bob = cards[-2::-2] ans = sum(alice) - sum(bob) print(ans)
s779558676
p03494
u828277092
2,000
262,144
Time Limit Exceeded
2,103
3,060
180
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input()) list_a = list(map(int, input().split())) cnt = 0 while all(map(lambda x: x%2 == 0, list_a)): list_a = list(map(lambda x: x%2, list_a)) cnt +=1 print(cnt)
s961205284
Accepted
19
3,060
180
n = int(input()) list_a = list(map(int, input().split())) cnt = 0 while all(map(lambda x: x%2 == 0, list_a)): list_a = list(map(lambda x: x/2, list_a)) cnt +=1 print(cnt)
s607908345
p02613
u469281291
2,000
1,048,576
Wrong Answer
150
9,564
409
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.
import sys import math import itertools import random n = int(input()) li = [0] * 4 #ac,wa,tle,re for i in range(n): tmp = input() if (tmp == "AC"): li[0] += 1 elif (tmp == "WA"): li[1] += 1 elif (tmp == "TLE"): li[2] += 1 else: li[3] += 1 print("AC × " + str(li[0])) print("WA × " + str(li[1])) print("TLE × " + str(li[2])) print("RE × "+str(li[3]))
s004775341
Accepted
149
9,564
405
import sys import math import itertools import random n = int(input()) li = [0] * 4 #ac,wa,tle,re for i in range(n): tmp = input() if (tmp == "AC"): li[0] += 1 elif (tmp == "WA"): li[1] += 1 elif (tmp == "TLE"): li[2] += 1 else: li[3] += 1 print("AC x " + str(li[0])) print("WA x " + str(li[1])) print("TLE x " + str(li[2])) print("RE x "+str(li[3]))
s180581344
p03401
u052332717
2,000
262,144
Wrong Answer
2,105
14,560
240
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.
import copy N = int(input()) A_list = list(map(int,input().split())) for i in range(N): li = copy.deepcopy(A_list) del li[i] ans = abs(li[0] + li[N-2]) for m in range(N-2): ans += abs(li[m] - li[m+1]) print(ans)
s604017620
Accepted
231
14,176
333
N = int(input()) A_list = list(map(int,input().split())) a = [0] b = [0] point_list = a + A_list + b S = 0 for i in range(N+1): S += abs(point_list[i]-point_list[i+1]) for i in range(1,N+1): print(S - abs(point_list[i-1] - point_list[i]) -abs(point_list[i] - point_list[i+1]) +abs(point_list[i-1] - point_list[i+1]))
s019877494
p03962
u977642052
2,000
262,144
Wrong Answer
17
2,940
141
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
inp = list(map(int, input().split())) res = [] for x in inp: res.append(x) if res.index(x): res.pop() print(res.__len__())
s972337185
Accepted
19
3,188
138
inp = list(map(int, input().split())) res = [] for x in inp: if not res.__contains__(x): res.append(x) print(res.__len__())
s745288110
p03493
u214380782
2,000
262,144
Wrong Answer
17
2,940
74
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.
x = input() ans= 0 for i in x: if i == 1: ans += 1 print(ans)
s032355242
Accepted
18
2,940
75
x = input() ans= 0 for i in x: if i == '1': ans += 1 print(ans)
s162836194
p02613
u809819902
2,000
1,048,576
Wrong Answer
149
16,148
188
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()) la=[] for i in range(n): la+=[input()] print("AC","×",la.count("AC")) print("WA","×",la.count("WA")) print("TLE","×",la.count("TLE")) print("RE","×",la.count("RE"))
s239556766
Accepted
148
16,320
184
n=int(input()) la=[] for i in range(n): la+=[input()] print("AC","x",la.count("AC")) print("WA","x",la.count("WA")) print("TLE","x",la.count("TLE")) print("RE","x",la.count("RE"))
s048781823
p03844
u951684192
2,000
262,144
Wrong Answer
17
2,940
45
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her.
a,b,c = input().split() print(int(a)-int(c))
s367071898
Accepted
17
2,940
95
a,b,c = input().split() if b == "+": print((int(a)+int(c))) else: print(int(a)-int(c))
s615540191
p03478
u808373096
2,000
262,144
Wrong Answer
750
2,940
228
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
N, A, B = map(int, input().split()) total = 0 def retuwa(n): sum = 0 while n > 0: sum += n % 10 n /= 10 return sum for i in range(1, N + 1): sum = retuwa(i) if A <= sum <= B: total += i print(total)
s790721891
Accepted
25
2,940
249
N, A, B = map(int, input().split()) total = 0 def ketawa(n): sum = 0 while n >= 1: sum += n % 10 n //= 10 return sum for i in range(1, N + 1): sum = ketawa(i) if A <= sum <= B: total += i print(total)
s784880889
p03386
u583507988
2,000
262,144
Wrong Answer
2,205
9,092
150
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a, b, k = map(int, input().split()) ans = [] for i in range(a, b+1): if i <= a+k or i>=b-k: if i not in ans: ans.append(i) print(i)
s996784659
Accepted
26
9,180
254
a, b, k = map(int, input().split()) if b-a <= k: for i in range(a, b+1): print(i) else: ans = [] for i in range(a, a+k): if i not in ans: ans.append(i) print(i) for j in range(b-k+1, b+1): if j not in ans: print(j)
s673206066
p02402
u299798926
1,000
131,072
Wrong Answer
20
7,544
100
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
s=int(input()) x=[int(i) for i in input().split()] print("{0},{1},{2}".format(min(x),max(x),sum(x)))
s914734952
Accepted
20
8,652
100
s=int(input()) x=[int(i) for i in input().split()] print("{0} {1} {2}".format(min(x),max(x),sum(x)))
s113140680
p02401
u042882066
1,000
131,072
Wrong Answer
20
7,616
291
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
# -*- coding: utf-8 -*- while True: a, op, b= input().split(" ") a = int(a) b = int(b) if op == "?": break elif op == "+": print(a+b) elif op == "-": print(a-b) elif op == "*": print(a*b) elif op == "/": print(a/b)
s958399131
Accepted
20
7,680
292
# -*- coding: utf-8 -*- while True: a, op, b= input().split(" ") a = int(a) b = int(b) if op == "?": break elif op == "+": print(a+b) elif op == "-": print(a-b) elif op == "*": print(a*b) elif op == "/": print(a//b)
s315468337
p03813
u729707098
2,000
262,144
Wrong Answer
17
2,940
114
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.
x = int(input()) answer = 2*(x-x%11)//11 if x%11==0: pass elif x%11<7: answer += 1 else: answer += 2 print(answer)
s254250072
Accepted
17
2,940
59
x = int(input()) if x<1200: print("ABC") else: print("ARC")
s041693928
p02422
u506705885
1,000
131,072
Wrong Answer
20
7,648
409
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())): sou_com=input().split() if sou_com[0]=='print': print(s[int(sou_com[1])-1:int(sou_com[2])]) elif sou_com[0]=='reverse': s=s[:int(sou_com[1])-1]\ +s[int(sou_com[1])-1:int(sou_com[2])][::-1]\ +s[int(sou_com[2]):] elif sou_com[0]=='replace': s=s[:int(sou_com[1])-1]\ +sou_com[3]\ +s[int(sou_com[2]):]
s018202311
Accepted
50
7,736
409
s=input() for i in range(int(input())): sou_com=input().split() if sou_com[0]=='print': print(s[int(sou_com[1]):int(sou_com[2])+1]) elif sou_com[0]=='reverse': s=s[:int(sou_com[1])]\ +s[int(sou_com[1]):int(sou_com[2])+1][::-1]\ +s[int(sou_com[2])+1:] elif sou_com[0]=='replace': s=s[:int(sou_com[1])]\ +sou_com[3]\ +s[int(sou_com[2])+1:]
s312661952
p02601
u723792785
2,000
1,048,576
Wrong Answer
31
9,172
108
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
a,b,c,k=map(int,open(0).read().split()) for d in range(k): if a>=b:b*=2 else:c*=2 print('YNeos'[a<b<c::2])
s849382995
Accepted
30
8,908
113
a,b,c,k=map(int,open(0).read().split()) while k>0: if b<=a:b*=2 else:c*=2 k-=1 print('YNeos'[a>=b or b>=c::2])
s517570130
p03493
u880911340
2,000
262,144
Wrong Answer
18
2,940
90
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.
a=list(input()) print(a) N=0 for i in a: if int(i)==1: N+=1 print(N)
s896837006
Accepted
17
2,940
92
a=list(input()) # print(a) N=0 for i in a: if int(i)==1: N+=1 print(N)
s787036030
p02418
u853619096
1,000
131,072
Wrong Answer
30
7,340
107
Write a program which finds a pattern $p$ in a ring shaped text $s$.
z=input() a=[] for i in z: a+=i ai=set(a) b=[] x=input() for i in x: b+=i bs=set(b) print(bs <= ai)
s710800688
Accepted
20
7,472
83
z=input()*2 x=input() a=z.count(x) if a>=1: print("Yes") else: print('No')
s427891733
p02694
u722761145
2,000
1,048,576
Wrong Answer
23
9,108
109
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?
a = int(input()) i = 0 t = 100 while 1: t = int(t * 1.01) i += 1 if t > a: break print(i)
s036116404
Accepted
20
9,108
110
a = int(input()) i = 0 t = 100 while 1: t = int(t * 1.01) i += 1 if t >= a: break print(i)
s698728577
p03477
u201082459
2,000
262,144
Wrong Answer
17
2,940
124
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d = map(int,input().split()) if a+b == c+d: print('Balanced') elif a+b > c+d: print('Right') else: print('Left')
s350723774
Accepted
17
3,064
125
a,b,c,d = map(int,input().split()) if a+b == c+d: print('Balanced') elif a+b > c+d: print('Left') else: print('Right')
s131424746
p03854
u131881594
2,000
262,144
Wrong Answer
33
9,164
146
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() s.replace("eraser","") s.replace("erase","") s.replace("dreamer","") s.replace("dream","") if len(s)==0: print("YES") else: print("NO")
s223031019
Accepted
30
9,236
153
s=input() s=s.replace("eraser","") s=s.replace("erase","") s=s.replace("dreamer","") s=s.replace("dream","") if len(s)==0: print("YES") else: print("NO")
s714939027
p00012
u536280367
1,000
131,072
Wrong Answer
20
5,580
655
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain. Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not.
def cross_product(a, b): ax, ay = a bx, by = b return ax * by - ay * bx def sub(a, b): a1, a2 = a b1, b2 = b return b1 - a1, b2 - a2 def judge(p1, p2, p3, pp): for a, b in ((p1, p2), (p2, p3), (p3, p1)): vec1 = sub(a, b) vec2 = sub(a, pp) if cross_product(vec2, vec1) >= 0: print("NO") return print("YES") if __name__ == '__main__': inputs = [float(s) for s in input().split()] p1 = (inputs.pop(0), inputs.pop(0)) p2 = (inputs.pop(0), inputs.pop(0)) p3 = (inputs.pop(0), inputs.pop(0)) pp = (inputs.pop(0), inputs.pop(0)) judge(p1, p2, p3, pp)
s851826989
Accepted
20
5,592
767
import sys def cross_product(a, b): ax, ay = a bx, by = b return ax * by - ay * bx def sub(a, b): a1, a2 = a b1, b2 = b return b1 - a1, b2 - a2 def judge(p1, p2, p3, pp): cnt = 0 for a, b in ((p1, p2), (p2, p3), (p3, p1)): vec1 = sub(a, b) vec2 = sub(a, pp) if cross_product(vec2, vec1) > 0: cnt += 1 if cnt == 0 or cnt == 3: print("YES") else: print("NO") if __name__ == '__main__': for line in sys.stdin: inputs = [float(s) for s in line.split()] p1 = (inputs.pop(0), inputs.pop(0)) p2 = (inputs.pop(0), inputs.pop(0)) p3 = (inputs.pop(0), inputs.pop(0)) pp = (inputs.pop(0), inputs.pop(0)) judge(p1, p2, p3, pp)
s538480227
p03388
u075595666
2,000
262,144
Wrong Answer
19
3,064
359
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
import math,bisect q = int(input()) for i in range(q): a,b = map(int,input().split()) y = max(a,b) z = min(a,b) ind = int(math.sqrt(a*b-1)) cnt = 0 if ind*(ind+1) < a*b: if ind >= z: cnt = 1 if ind+1 >= y: cnt = 2 print(2*ind-cnt) else: if ind >= z: cnt = 1 if ind >= y: cnt = 2 print(2*ind-1-cnt)
s038587801
Accepted
19
3,064
392
import math q = int(input()) for i in range(q): a,b = map(int,input().split()) if a == b: print(a*2-2) continue y = max(a,b) z = min(a,b) ind = math.sqrt(a*b) d = int(ind) if ind.is_integer(): d -= 1 cnt = 0 if d*(d+1) < a*b: if d >= z: cnt = 1 if d+1 >= y: cnt = 2 print(2*d-cnt) else: if d >= z: cnt = 1 print(2*d-1-cnt)
s318227180
p03957
u891516200
1,000
262,144
Wrong Answer
23
9,004
66
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtained from the string s by deleting some characters.
s = input() if 'CF' in s: print('Yes') else: print('No')
s871907609
Accepted
29
9,044
189
s = input() in_c = False for c in s: if not in_c: if 'C' == c: in_c = True else: if 'F' == c: print('Yes') exit() print('No')