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
s857269950
p03814
u905582793
2,000
262,144
Wrong Answer
72
3,516
138
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s=input() for i in range(len(s)): if s[i]=="A": pA = i for i in range(len(s)): if s[-i-1] == "Z": pZ = i print(len(s)-pA-pZ-1)
s399431856
Accepted
42
3,516
156
s=input() for i in range(len(s)): if s[i]=="A": pA = i break for i in range(len(s)): if s[-i-1] == "Z": pZ = i break print(len(s)-pA-pZ)
s078344719
p03673
u626468554
2,000
262,144
Wrong Answer
819
24,772
256
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
#n = int(input()) #n,k = map(int,input().split()) #x = list(map(int,input().split())) n = int(input()) a = list(input()) memo = '' for i in range(n): if i%2==0: memo = memo + a[i] else: memo = a[i] + memo print(*list(memo))
s681691079
Accepted
250
26,180
455
n = int(input()) a = list(map(int,input().split())) li1 = [] li2 = [] for i in range(n): if i%2==0: li1.append(a[i]) else: li2.append(a[i]) ans = [] if n%2==0: for i in range(n//2): ans.append(li2[(i+1)*(-1)]) for i in range(n//2): ans.append(li1[i]) else: for i in range(n//2+1): ans.append(li1[(i+1)*(-1)]) for i in range(n//2): ans.append(li2[i]) print(*ans)
s973695994
p03598
u875769753
2,000
262,144
Wrong Answer
27
9,192
148
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
N = int(input()) K = int(input()) lsx = list(map(int,input().split())) ans = 0 for i in range(N): ans += min(abs(lsx[i]),abs(lsx[i]-K)) print(ans)
s577576423
Accepted
26
8,976
150
N = int(input()) K = int(input()) lsx = list(map(int,input().split())) ans = 0 for i in range(N): ans += min(abs(lsx[i]),abs(lsx[i]-K)) print(2*ans)
s931646531
p03524
u464205401
2,000
262,144
Wrong Answer
94
10,152
235
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.
import collections s = list(input()) n = len(s) flg = True for i in range(n-1): if len(set(s[i:i+2]))==1: flg = False for i in range(n-2): tmp = s[i:i+3] if tmp == tmp[::-1]: flg = False print('YES' if flg else 'NO')
s966569031
Accepted
51
10,004
221
import collections s = list(input()) n = len(s) cnt = [0,0,0] for i in range(n): if s[i]=="a": cnt[0]+=1 elif s[i]=="b": cnt[1]+=1 else: cnt[2]+=1 print('YES' if max(cnt)-min(cnt) <= 1 else 'NO')
s646514362
p03478
u803865203
2,000
262,144
Wrong Answer
55
3,308
198
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
N,A,B = map(int,input().split()) ans = 0 for i in range(int(N)+1): array = list(map(int,list(str(i)))) print(array) if(sum(array)>=A and sum(array)<=B): ans += int(i) print(ans)
s782391329
Accepted
35
3,060
313
N,A,B = map(int,input().split()) ans = 0 for i in range(1,int(N)+1): sum = 0 num = i while(True): sum += num%10 num = num//10 if(num == 0): if(sum >= A and sum <= B): ans += i break else: break print(ans)
s898955101
p02413
u382316013
1,000
131,072
Wrong Answer
40
8,208
386
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
r, c = [int(i) for i in input().split()] data = [] sum_row = [0] * (c + 1) for ri in range(r): data.append([int(i) for i in input().split()]) data[ri].append(sum(data[ri])) print(" ".join([str(d) for d in data[ri]])) for ci in range(c + 1): sum_row[ci] += data[ri][ci] print(" ".join([str(s) for s in sum_row])) from pprint import pprint pprint(data)
s576144484
Accepted
30
7,744
338
r, c = [int(i) for i in input().split()] data = [] sum_row = [0] * (c + 1) for ri in range(r): data.append([int(i) for i in input().split()]) data[ri].append(sum(data[ri])) print(" ".join([str(d) for d in data[ri]])) for ci in range(c + 1): sum_row[ci] += data[ri][ci] print(" ".join([str(s) for s in sum_row]))
s078320145
p02646
u263660661
2,000
1,048,576
Wrong Answer
19
9,172
182
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if v <= w: print("No") elif t < abs(a - b)/abs(v - w): print("No") else: print("Yes")
s430673963
Accepted
23
9,172
184
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if v <= w: print("NO") elif t < abs(a - b) / abs(v - w): print("NO") else: print("YES")
s457806602
p03351
u357867755
2,000
1,048,576
Wrong Answer
17
3,060
176
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) if abs(c - a) <= d: print('Yes') elif (abs(b - a) <= d) and (abs(c-b) <= d): print('Yes') else: print('No') print(abs(b-a))
s598136167
Accepted
17
2,940
164
a, b, c, d = map(int, input().split()) if abs(c - a) <= d: print('Yes') elif (abs(b - a) <= d) and (abs(b - c) <= d): print('Yes') else: print('No')
s239344601
p03712
u826263061
2,000
262,144
Wrong Answer
18
3,060
123
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 = list(map(int, input().split())) a = '*'*(w+2) print(a) for i in range(h): s = input() print('*'+s+'*') print(a)
s627618317
Accepted
17
3,060
244
# -*- coding: utf-8 -*- """ Created on Sun Sep 16 16:57:33 2018 @author: maezawa """ h, w = list(map(int, input().split())) a = '#'*(w+2) b = [] for i in range(h): s = input() b.append('#'+s+'#') print(a) for s in b: print(s) print(a)
s155938177
p03251
u347452770
2,000
1,048,576
Wrong Answer
22
9,136
329
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
import sys n,m,X,Y=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) d=min(y)-max(x) if d<=0: print("War") sys.exit() else: for i in range(d+1): Z=X+i if (Z<=X or Z>Y) or (max(x)>=Z or min(y)<Z): print("War") sys.exit() print("No War")
s833488960
Accepted
24
9,216
430
import sys n,m,X,Y=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) d=min(y)-max(x) warFlag = False if d<=0: print("War") sys.exit() else: for i in range(1, Y - X + 1): Z=X+i if (max(x)>=Z or min(y)<Z): warFlag = True else: #max(x) < Z, max(y) >= Z warFlag = False break if warFlag: print("War") else: print("No War")
s982428385
p02406
u567380442
1,000
131,072
Wrong Answer
30
6,720
74
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; }
print(*[i for i in range(1, int(input())) if i % 3 == 0 or '3' in str(i)])
s279404443
Accepted
40
7,008
103
n = int(input()) print(' ', end='') print(*[i for i in range(1, 1 + n) if i % 3 == 0 or '3' in str(i)])
s269569376
p03494
u905582793
2,000
262,144
Wrong Answer
18
3,064
224
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()) a=list(map(int,input().split())) ans=0 for i in range(100): for j in range(n): if a[j] // 2 ==0: a[j]=a[j]//2 if j==n: ans+=1 else: break else: continue break print(ans)
s901285034
Accepted
19
3,060
229
n=int(input()) a=list(map(int,input().split())) ans=0 for i in range(100): for j in range(n): if a[j] % 2 ==0: a[j]=a[j]//2 if j==n-1: ans+=1 else: break else: continue break print(ans)
s962411356
p03024
u003501233
2,000
1,048,576
Wrong Answer
17
2,940
67
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S=input() if S.count("x") <= 7: print("Yes") else: print("No")
s875708173
Accepted
18
2,940
67
S=input() if S.count("x") <= 7: print("YES") else: print("NO")
s003111517
p03448
u340781749
2,000
262,144
Wrong Answer
18
3,060
218
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for p in range(a + 1): for q in range(b + 1): r = (x - p * 500 - q * 100) // 50 if r <= c: ans += 1 print(ans)
s721457267
Accepted
18
3,060
223
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for p in range(a + 1): for q in range(b + 1): r = (x - p * 500 - q * 100) // 50 if 0 <= r <= c: ans += 1 print(ans)
s331417520
p03696
u502389123
2,000
262,144
Wrong Answer
18
3,064
600
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
N = int(input()) S = input() needleft = 0 needright = 0 ans = '' for i in range(N): if S[i] == ')': ans += '(' * needright ans += ')' * needright if needright == 0: needleft += 1 needright = 0 elif S[i] == '(': ans += '(' * needleft ans += ')' * needleft if needleft == 0: needright += 1 needleft = 0 if i == N-1: if needleft: ans += '(' * needleft ans += ')' * needleft else: ans += '(' * needright ans += ')' * needright print(ans)
s451669706
Accepted
17
2,940
232
N = int(input()) S = input() cnt = 0 s = '' for i in range(N): if S[i] == '(': cnt += 1 else: cnt -= 1 if cnt < 0: s += '(' cnt = 0 s += S if cnt: s += ')' * cnt print(s)
s002160519
p03050
u598720217
2,000
1,048,576
Wrong Answer
229
3,060
151
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
import math N = int(input()) n = int(math.sqrt(N)) count=0 for i in range(1,int(n)): d = N - i if d%i==0: count+=int(d/i) print(count)
s110142101
Accepted
237
3,060
178
import math N = int(input()) n = int(math.sqrt(N)) count=0 for i in range(1,n+1): d = N - i if d%i==0 and i < (N // i) -1: k = d//i count+=k print(count)
s856624692
p03943
u474270503
2,000
262,144
Wrong Answer
17
3,064
70
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=map(int,input().split()) print('Yes' if 2*max(A)==sum(A) else 'No')
s492543887
Accepted
17
2,940
76
A=list(map(int,input().split())) print('Yes' if 2*max(A)==sum(A) else 'No')
s331709269
p03457
u740284863
2,000
262,144
Wrong Answer
318
3,060
160
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
n = int(input()) for i in range(n): t, x, y = map(int, input().split()) if x + y < t or (x + y + t) % 2: print("No") exit() print("Yes")
s904599365
Accepted
216
3,064
314
import sys input = sys.stdin.readline n = int(input()) t,x,y = 0,0,0 for i in range(n): t_,x_,y_ = map(int,input().split()) X = abs(x_ - x) Y = abs(y_ - y) T = t_ - t if ( X + Y > T ) or (T % 2 != ( X + Y ) % 2): print("No") exit() t = t_ x = x_ y = y_ print("Yes")
s958675938
p03637
u023229441
2,000
262,144
Wrong Answer
78
14,252
229
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
n=int(input()) A=list(map(int,input().split())) for i in range(n): if A[i]%4==0: A[i]==0 elif A[i]%2==0: A[i]==2 else: A[i]==1 a=A.count(0) b=A.count(2) c=A.count(1) if c<=a : print("Yes") else: print("No")
s119816949
Accepted
81
14,252
268
n=int(input()) A=list(map(int,input().split())) for i in range(n): if A[i]%4==0: A[i]=0 elif A[i]%2==0: A[i]=2 else: A[i]=1 a=A.count(0) b=A.count(2) c=A.count(1) if c<=a : print("Yes") elif b==0 and c==a+1: print("Yes") else: print("No")
s297486840
p03958
u981931040
1,000
262,144
Wrong Answer
42
9,180
688
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
import heapq K, T = map(int, input().split()) a = tuple(map(int, input().split())) cakes = [] heapq.heapify(cakes) for i in range(T): heapq.heappush(cakes, [-1*a[i], i]) print(cakes) now = -1 ans = 0 for _ in range(K): cake_num, cake_idx = heapq.heappop(cakes) cake_num *= -1 if cake_idx == now and len(cakes) > 1 and cakes[0][1]: next_cake_num, next_cake_idx = heapq.heappop(cakes) next_cake_num -= 1 heapq.heappush(cakes, [next_cake_num, next_cake_idx]) now = next_cake_idx else: cake_num -= 1 if now == cake_idx: ans += 1 now = cake_idx heapq.heappush(cakes, [cake_num, cake_idx]) print(ans)
s662958812
Accepted
36
9,164
747
import heapq K, T = map(int, input().split()) a = tuple(map(int, input().split())) cakes = [] heapq.heapify(cakes) for i in range(T): heapq.heappush(cakes, [-1*a[i], i]) # print(cakes) now = -1 ans = 0 for _ in range(K): cake_num, cake_idx = heapq.heappop(cakes) cake_num *= -1 if cake_idx == now and len(cakes) > 1 and cakes[0][0] != 0: next_cake_num, next_cake_idx = heapq.heappop(cakes) next_cake_num *= -1 next_cake_num -= 1 heapq.heappush(cakes, [-1 * next_cake_num, next_cake_idx]) now = next_cake_idx else: cake_num -= 1 if now == cake_idx: ans += 1 now = cake_idx heapq.heappush(cakes, [-1 * cake_num, cake_idx]) # print(cakes) print(ans)
s162238411
p03957
u838930283
1,000
262,144
Wrong Answer
22
3,064
157
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() result = "No" for i in range(len(s)): if s[i] == "C": for j in range(i+1, len(s)): if s[j] == "F": result = "YES" break print(result)
s043694767
Accepted
26
3,192
157
s = input() result = "No" for i in range(len(s)): if s[i] == "C": for j in range(i+1, len(s)): if s[j] == "F": result = "Yes" break print(result)
s877952174
p02260
u114315703
1,000
131,072
Wrong Answer
20
5,596
356
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
N = int(input()) A = [int(e) for e in input().split()] def selection_sort(A, N): steps = 0 for i in range(0, N): minj = i for j in range(i, N): if A[minj] > A[j]: minj = j steps += 1 A[minj], A[i] = A[i], A[minj] print(A) print(steps) return A selection_sort(A, N)
s982501945
Accepted
30
5,616
425
N = int(input()) A = [int(e) for e in input().split()] def selection_sort(A, N): steps = 0 for i in range(0, N): minj = i for j in range(i, N): if A[minj] > A[j]: minj = j if i != minj: steps += 1 A[minj], A[i] = A[i], A[minj] for e in A[:-1]: print(e, end=' ') print(A[-1]) print(steps) return A selection_sort(A, N)
s671747010
p03963
u774160580
2,000
262,144
Wrong Answer
18
2,940
58
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls.
N, K = map(int, input().split()) print(K * pow(K, N - 1))
s277792873
Accepted
17
2,940
62
N, K = map(int, input().split()) print(K * pow(K - 1, N - 1))
s493245996
p03854
u962451849
2,000
262,144
Wrong Answer
19
3,316
159
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().replace('eraser', '').replace('erase', '') \ .replace('dreamer', '').replace('dream', '') if s: print('NO') else: print('YES') print(s)
s067356462
Accepted
18
3,188
151
s = input().replace('eraser', '').replace('erase', '') \ .replace('dreamer', '').replace('dream', '') if s: print('NO') else: print('YES')
s711061681
p00002
u945249026
1,000
131,072
Wrong Answer
20
5,568
96
Write a program which computes the digit number of sum of two integers a and b.
import sys a = [] for line in sys.stdin: a.append(line) for i in a: print(i[0] + i[1])
s995239498
Accepted
30
5,592
142
while True: try: a, b = map(int,input().split()) s = str(a + b) print(len(s)) except EOFError: break
s759778161
p02407
u639421643
1,000
131,072
Wrong Answer
20
7,572
78
Write a program which reads a sequence and prints it in the reverse order.
length = int(input()) nums = list(map(int, input().split())) print(nums[::-1])
s432077989
Accepted
20
7,648
73
length = int(input()) nums = input().split() print(" ".join(nums[::-1]))
s067283366
p03623
u240793404
2,000
262,144
Wrong Answer
17
2,940
74
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("A" if abs(b-a) < abs(c-b) else "B")
s992149155
Accepted
17
2,940
74
a,b,c=map(int,input().split()); print("A" if abs(b-a) < abs(c-a) else "B")
s018796994
p03455
u014047173
2,000
262,144
Wrong Answer
17
2,940
92
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 % 2 == 0 ) or ( b % 2 == 0 ) : 'even' else : 'odd'
s076673238
Accepted
17
2,940
106
a, b = map(int, input().split()) if (a % 2 == 0 ) or ( b % 2 == 0 ) : print('Even') else : print('Odd')
s593620309
p02258
u826549974
1,000
131,072
Wrong Answer
20
5,604
159
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .
n = int(input()) A = [int(input()) for i in range(n)] max = A[1]-A[0] for i in range(1,n-1): if(max < A[i+1]-A[i]): max = A[i+1]-A[i] print(max)
s772538033
Accepted
500
13,600
201
n = int(input()) A = [int(input()) for i in range(n)] max = A[1]-A[0] min = A[0] for i in range(1,n): if(max < A[i]-min): max = A[i]-min if(min > A[i]): min = A[i] print(max)
s648280006
p03455
u050428930
2,000
262,144
Wrong Answer
17
2,940
88
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=map(int,input().split()) t = a*b%2 if t==0: print("even") else: print("odd")
s195204363
Accepted
17
2,940
88
a,b=map(int,input().split()) t = a*b%2 if t==0: print("Even") else: print("Odd")
s275662604
p02795
u841924362
2,000
1,048,576
Wrong Answer
17
2,940
136
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
import math H = int(input()) W = int(input()) N = int(input()) if(H >= W): print(math.ceil(N // H)) else: print(math.ceil(N // W))
s023709157
Accepted
17
2,940
134
import math H = int(input()) W = int(input()) N = int(input()) if(H >= W): print(math.ceil(N / H)) else: print(math.ceil(N / W))
s675913842
p02410
u369313788
1,000
131,072
Wrong Answer
30
7,632
340
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
n, m = [int(i) for i in input().split()] matrix = [] for ni in range(n): matrix.append([int(x) for x in input().split()]) vector = [] for ni in range(m): vector.append(int(input())) print(matrix) print() print(vector) for ni in range(n): sum = 0 for mi in range(n): sum += matrix[ni][mi]* vector[mi] print(sum)
s536276728
Accepted
30
8,068
311
n, m = [int(i) for i in input().split()] matrix = [] for ni in range(n): matrix.append([int(a) for a in input().split()]) vector = [] for mi in range(m): vector.append(int(input())) for ni in range(n): sum = 0 for mi in range(m): sum += matrix[ni][mi] * vector[mi] print(sum)
s018978227
p03565
u226912938
2,000
262,144
Wrong Answer
23
3,188
886
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
import re s = str(input()) t = str(input()) NS = [] for i in range(len(s)): s_res = s[:i] s_obj = s[i:] s_res.replace('?', 'a') s_w = s_obj.replace('?', '.') s_re = re.compile(s_w) matchobj = s_re.fullmatch(t) if matchobj: start = matchobj.start() end = matchobj.end() print('-' * 30) print('i' + str(i)) print(start) print(end) print('-' * 30) new_s = s_res + s_obj[:start] + t + s_obj[end:] new_s = new_s.replace('?', 'a') NS.append(new_s) if len(NS) >= 1: NS = sorted(NS) ans = NS[0] else: ans = 'UNRESTORABLE' print(ans)
s169907538
Accepted
23
3,188
1,017
import re s = str(input()) t = str(input()) NS = [] for i in range(len(s)): s_res = s[:i] s_res = s_res.replace('?', 'a') s_obj = s[i:i+len(t)] s_obj = s_obj.replace('?', '.') s_comp = re.compile(s_obj) s_res_f = s[i+len(t):] matchobj = s_comp.fullmatch(t) if matchobj: start = matchobj.start() new_s = s_res + t + s_res_f new_s = new_s.replace('?', 'a') NS.append(new_s) if len(NS) == 0: ans = 'UNRESTORABLE' else: ans = sorted(NS)[0] print(ans)
s739232234
p02397
u957680575
1,000
131,072
Wrong Answer
50
7,400
200
Write a program which reads two integers x and y, and prints them in ascending order.
A=1 B=1 x=[] while True: if A==0 and B==0: break else: A, B= map(int, input().split()) if A > B: print(B,A) else: print(A,B)
s282657678
Accepted
50
7,432
192
x=[] while True: A, B= map(int, input().split()) if A==0 and B==0: break else: if A > B: print(B,A) else: print(A,B)
s311771067
p04043
u143212659
2,000
262,144
Wrong Answer
17
2,940
213
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): ABC = list(map(int, input().split())) print('Yes' if ABC.count(5) == 2 and ABC.count(7) == 1 else 'No') if __name__ == "__main__": main()
s472115789
Accepted
16
2,940
205
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): ABC = list(map(int, input().split())) ABC.sort() print('YES' if [5, 5, 7] == ABC else 'NO') if __name__ == "__main__": main()
s001101512
p04030
u252964975
2,000
262,144
Wrong Answer
18
3,060
156
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=str(input()) str_ = "" for i in range(len(S)): if S[i] == "0" or "1": str_ = str_ + S[i] elif len(str_) != 0: str_ = str_.rstrip() print(str_)
s937103075
Accepted
17
2,940
160
S=str(input()) str_ = "" for i in range(len(S)): if S[i] == "0" or S[i] == "1": str_ = str_ + S[i] elif len(str_) != 0: str_ = str_[:-1] print(str_)
s621819452
p03610
u922926087
2,000
262,144
Wrong Answer
18
3,192
12
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
input()[::2]
s116234370
Accepted
18
3,188
139
# -*- coding: utf-8 -*- """ Created on Wed Feb 27 01:06:34 2019 @author: yuta """ def oddstring(s): print(s[::2]) oddstring(input())
s829139781
p03149
u799215419
2,000
1,048,576
Wrong Answer
19
3,188
194
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".
import re S = input() pattern = r"(.+keyence|k.+eyence|ke.+yence|key.+ence|keye.+nce|keyen.+ce|keyenc.+e|keyence.+|keyence)" if re.fullmatch(pattern, S): print("YES") else: print("NO")
s938057964
Accepted
17
2,940
134
nums = list(map(int, input().split())) if 1 in nums and 9 in nums and 7 in nums and 4 in nums: print("YES") else: print("NO")
s103638490
p03643
u202634017
2,000
262,144
Wrong Answer
17
2,940
36
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
N = input() print("abc{}".format(N))
s959950565
Accepted
19
2,940
27
N = input() print("ABC"+N)
s316773300
p03779
u017415492
2,000
262,144
Wrong Answer
17
2,940
226
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
x=int(input()) #n=1 #while 1/2*(n**2+n)<x: # n+=1 #print(n) left=0 right=x while right-left>1: mid=(left+right)//2 if (mid**2+mid)/2==x: break if (mid**2+mid)/2<x: left=mid else: right=mid print(right)
s494573903
Accepted
17
3,064
237
x=int(input()) #n=1 #while 1/2*(n**2+n)<x: # n+=1 #print(n) left=0 right=x while right-left>1: mid=(left+right)//2 if (mid**2+mid)/2==x: right=mid break if (mid**2+mid)/2<x: left=mid else: right=mid print(right)
s340134302
p03861
u803647747
2,000
262,144
Wrong Answer
36
5,076
100
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?
from decimal import Decimal a, b, x = map(Decimal, input().split()) int(Decimal(b/x) - Decimal(a/x))
s866175613
Accepted
35
5,076
174
from decimal import Decimal a, b, x = map(Decimal, input().split()) bx = (b/x) aq, amod = divmod(a, x) if a==0 or amod==0: print(int(bx-aq)+1) else: print(int(bx-aq))
s567908132
p03486
u439312138
2,000
262,144
Wrong Answer
18
3,060
175
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = input() s_asc = ''.join(sorted(s)) t = input() t_desc = ''.join(sorted(t, reverse=True)) print(s_asc) print(t_desc) if s_asc < t_desc: print('Yes') else: print('No')
s215163728
Accepted
18
3,064
148
s = input() s_asc = ''.join(sorted(s)) t = input() t_desc = ''.join(sorted(t, reverse=True)) if s_asc < t_desc: print('Yes') else: print('No')
s789789591
p03447
u871596687
2,000
262,144
Wrong Answer
17
2,940
147
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
X = int(input()) A = int(input()) B = int(input()) N = 0 while True: if (X-A-B*N)> 0: N +=1 else: print(X-A-B*N) break
s600967124
Accepted
17
2,940
152
X = int(input()) A = int(input()) B = int(input()) N = 0 while True: if (X-A-B*N)>= 0: N +=1 else: print(X-A-B*(N-1)) break
s178475352
p03131
u311379832
2,000
1,048,576
Wrong Answer
17
2,940
67
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()) if A >= B - 1: print(K + 1)
s489322176
Accepted
17
3,060
266
K, A, B = map(int, input().split()) if A >= B - 1 or A >= K: print(K + 1) else: K -= (A + 1) ans = 0 if K >= 2: ans = B + ((B - A) * (K // 2)) ans += K % 2 elif K != 0: ans = B + 1 else: ans += B print(ans)
s586612811
p02694
u616619529
2,000
1,048,576
Wrong Answer
25
9,020
156
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?
# -*- coding: utf-8 -*- x = int(input()) money = 100 year = 0 while (money <= x): money = int(money*1.01) print('{}'.format(year))
s525569827
Accepted
23
9,068
177
# -*- coding: utf-8 -*- x = int(input()) money = 100 year = 0 while (money < x): money = int(money * 1.01) year = year + 1 print('{}'.format(year))
s245919798
p03486
u257974487
2,000
262,144
Wrong Answer
18
3,064
375
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = input() t = input() p = [] q = [] m = len(s) n = len(t) ans = 0 for i in range(m): p.append(s[i]) p.sort() for j in range(n): q.append(t[j]) q.sort() if m >= n: ans = "No" else: ans = "Yes" for k in range(min(m,n)): if ord(p[k]) < ord(q[k]): ans = "Yes" break elif ord(p[k]) > ord(q[k]): ans = "No" break print(ans)
s515599923
Accepted
17
3,064
380
s = input() t = input() p = [] q = [] m = len(s) n = len(t) if m >= n: ans = "No" else: ans = "Yes" for i in range(m): p.append(s[i]) p.sort() for j in range(n): q.append(t[j]) q.sort(reverse=True) for k in range(min(m,n)): if ord(p[k]) < ord(q[k]): ans = "Yes" break elif ord(p[k]) > ord(q[k]): ans = "No" break print(ans)
s177493995
p03214
u691170040
2,525
1,048,576
Wrong Answer
18
3,060
232
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()) at = input().split(" ") a = [] for i in at: a.append(int(i)) avg = sum(a) / N mdif, flag = abs(a[0]-avg), 0 for i in range(len(a)): if a[i]-avg < mdif: mdif = a[i] - avg flag = i print(flag)
s321042773
Accepted
18
3,060
240
N = int(input()) at = input().split(" ") a = [] for i in at: a.append(int(i)) avg = sum(a) / N mdif, flag = abs(a[0]-avg), 0 for i in range(len(a)): if abs(a[i]-avg) < mdif: mdif = abs(a[i]-avg) flag = i print(flag)
s651846610
p02694
u464205401
2,000
1,048,576
Wrong Answer
24
9,164
89
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x=int(input()) a=100 cnt=0 while x>=a: a=int(a*1.01) # print(a) cnt+=1 print(cnt)
s559074683
Accepted
23
9,164
74
x=int(input()) a=100 cnt=0 while x>a: a=int(a*1.01) cnt+=1 print(cnt)
s643464567
p03377
u736729525
2,000
262,144
Wrong Answer
19
2,940
151
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A, B, X = [int(x) for x in input().split()] def solve(A, B, X): if A + B < X: print("NO") elif A > X: print("NO") else: print("YES")
s468267117
Accepted
17
2,940
118
A, B, X = [int(x) for x in input().split()] if A + B < X: print("NO") elif A > X: print("NO") else: print("YES")
s109200861
p03730
u780459096
2,000
262,144
Wrong Answer
17
2,940
222
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`.
# -*- coding: utf-8 -*- a, b, c = map(int, input().split()) rest = a % b num = a while True: if num % b == c: print('Yes') exit() num+=a if num % b == rest: print('No') exit()
s342976496
Accepted
17
2,940
223
# -*- coding: utf-8 -*- a, b, c = map(int, input().split()) rest = a % b num = a while True: if num % b == c: print('YES') exit() num+=a if num % b == rest: print('NO') exit()
s032830875
p03469
u103902792
2,000
262,144
Wrong Answer
17
2,940
66
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
s= input() if s[4]=='2017': print('2018'+s[4:]) else: print(s)
s525784857
Accepted
27
8,980
40
s= input() print(s[:3] + '8' + s[4:])
s488084945
p03997
u263691873
2,000
262,144
Wrong Answer
17
2,940
63
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h = int(input()) print((a+b)*h/2)
s820305714
Accepted
17
2,940
68
a=int(input()) b=int(input()) h = int(input()) print(int((a+b)*h/2))
s730377166
p02972
u845333844
2,000
1,048,576
Wrong Answer
717
10,304
205
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
n=int(input()) a=list(map(int,input().split())) b=[0]*n for i in range(n,0,-1): m=n//i total=0 for j in range(1,m+1): total+=a[i*j-1] b[i-1]=total%2 ans=sum(b) print(ans) print(*b)
s122170973
Accepted
805
14,140
361
n=int(input()) a=list(map(int,input().split())) b=[0]*n for i in range(n,0,-1): m=n//i total=0 for j in range(1,m+1): if j==1: total+=a[i-1] else: total+=b[i*j-1] b[i-1]=total%2 ans=sum(b) print(ans) if ans != 0: l=[] for i in range(n): if b[i]==1: l.append(i+1) print(*l)
s550275877
p02397
u666221014
1,000
131,072
Wrong Answer
20
7,448
43
Write a program which reads two integers x and y, and prints them in ascending order.
print( " ".join( sorted( input().split())))
s010385178
Accepted
60
7,628
144
while True : a, b = [int(i) for i in input().split()] if a == b == 0 : break elif a >= b : print(b, a) else : print(a,b)
s367973556
p02261
u150984829
1,000
131,072
Wrong Answer
20
5,600
301
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
n=int(input()) c=input().split();d=c[:] for i in range(n-1): for j in range(0,n-i-1): if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j] m=d.index(min(d[i:]),i) if d[i][1]>=d[m][1]:d[i],d[m]=d[m],d[i] print(*c);print("Stable") print(*d) b={i[1]for i in c} print(["Stable","Not stable"][len(b)<len(c)])
s101393687
Accepted
20
5,604
273
n=int(input()) c=input().split();d=c[:] for i in range(n-1): for j in range(n-i-1): if c[j][1]>c[j+1][1]:c[j:j+2]=c[j+1],c[j] m=i for j in range(i,n): if d[m][1]>d[j][1]:m=j d[i],d[m]=d[m],d[i] print(*c);print("Stable") print(*d);print(['Not s','S'][c==d]+'table')
s647900971
p03610
u544050502
2,000
262,144
Wrong Answer
20
3,192
20
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
print(input()[1::2])
s474094729
Accepted
18
3,192
19
print(input()[::2])
s946835948
p02290
u629780968
1,000
131,072
Wrong Answer
20
5,636
528
For given three points p1, p2, p, find the projection point x of p onto p1p2.
def dot(a, b): return a.real * b.real + a.imag * b.imag def projection(a, b): return a * dot(a, b) / (abs(a) ** 2) def solve(p0,p1,p2): a=p1-p0 b=p2-p0 pro=projection(a,b) t=p0+pro return t def main(): x0,y0,x1,y1=map(float,input().split()) p0=complex(x0,y0) p1=complex(x1,y1) q=int(input()) for i in range(q): p2=complex(*map(float,input().split())) t=solve(p0,p1,p2) print('{:.10f}{:.10f}'.format(t.real,t.imag)) main()
s273581809
Accepted
30
5,652
527
def dot(a, b): return a.real * b.real + a.imag * b.imag def projection(a, b): return a * dot(a, b) / (abs(a) ** 2) def solve(p0,p1,p2): a=p1-p0 b=p2-p0 pro=projection(a,b) t=p0+pro return t def main(): x0,y0,x1,y1=map(float,input().split()) p0=complex(x0,y0) p1=complex(x1,y1) q=int(input()) for i in range(q): p2=complex(*map(float,input().split())) t=solve(p0,p1,p2) print("{:.10f} {:.10f}".format(t.real,t.imag)) main()
s575726233
p03387
u513081876
2,000
262,144
Wrong Answer
17
3,064
281
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
A, B, C = map(int, input().split()) sta = max(A, B, C) ans = 0 if (B-A) >= 2: kake = (B-A)//2 A = A*kake ans += kake if (B-C) >= 2: kake = (B-C)//2 C = C*kake ans += kake if A == B == C: print(ans) elif A == C: print(ans+1) else: print(ans+2)
s590617593
Accepted
18
3,064
409
A, B, C = map(int, input().split()) ans = 0 max_ABC = max(A, B, C) if max_ABC != A: ans += (max_ABC - A) // 2 A += 2 * ((max_ABC-A) // 2) if max_ABC != B: ans += (max_ABC - B) // 2 B += 2 * ((max_ABC-B) // 2) if max_ABC != C: ans += (max_ABC - C) // 2 C += 2 * ((max_ABC-C) // 2) if 3 * max_ABC - (A+B+C) == 2: ans += 1 elif 3 * max_ABC - (A+B+C) == 1: ans += 2 print(ans)
s228884575
p03862
u281610856
2,000
262,144
Wrong Answer
82
14,540
396
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
def main(): n, x = map(int, input().split()) A = list(map(int, input().split())) ans = 0 if A[0] > x: ans += A[0] - x A[0] = x print(ans) for i in range(n - 1): j = i + 1 if j < n and A[i] + A[j] > x: diff = A[i] + A[j] - x ans += diff A[j] -= diff print(ans) if __name__ == '__main__': main()
s405338909
Accepted
85
14,252
381
def main(): n, x = map(int, input().split()) A = list(map(int, input().split())) ans = 0 if A[0] > x: ans += A[0] - x A[0] = x for i in range(n - 1): j = i + 1 if j < n and A[i] + A[j] > x: diff = A[i] + A[j] - x ans += diff A[j] -= diff print(ans) if __name__ == '__main__': main()
s631253083
p03474
u766566560
2,000
262,144
Wrong Answer
19
3,188
145
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
import re A, B = map(int, input().split()) S = input() result = re.match('[0-9]{A}-[0-9]{B}', S) if result: print('Yes') else: print('No')
s951446321
Accepted
19
3,188
190
import re A, B = map(int, input().split()) S = input() pattern = '[0-9]{' + str(A) + '}-[0-9]{' + str(B) + '}' result = re.match(pattern, S) if result: print('Yes') else: print('No')
s806903893
p04030
u099300051
2,000
262,144
Wrong Answer
18
2,940
189
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() ansS = "" ansL = 0 for i in range(len(S)): if S[i] == 'B': if len(ansS) != 0 : ansL = len(ansS) ansS = ansS[:ansL-1] else: ansS += S[i] print(int(ansS))
s554271585
Accepted
17
2,940
156
S = input() ans ='' for x in S: if x == '0': ans += x elif x == '1': ans += x else: if ans!='': ans = ans[:-1] print(ans)
s418929272
p03854
u409757418
2,000
262,144
Wrong Answer
84
3,188
475
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() n = 0 while n == 0: if s[len(s)-5:len(s)] == "dream": s = s.rstrip("ream") s = s.rstrip("d") elif s[len(s)-5:len(s)] == "erase": s = s.rstrip("rase") s = s.rstrip("e") elif s[len(s)-7:len(s)] == "dreamer": s = s.rstrip("reamer") s = s.rstrip("d") elif s[len(s)-6:len(s)] == "eraser": s = s.rstrip("raser") s = s.rstrip("e") else: if len(s) == 0: n = 1 print("Yes") else: n = -1 print("No")
s551738598
Accepted
80
3,188
369
s = input() n = 0 while n == 0: if s[len(s)-5:len(s)] == "dream": s = s[:len(s)-5] elif s[len(s)-5:len(s)] == "erase": s = s[:len(s)-5] elif s[len(s)-7:len(s)] == "dreamer": s = s[:len(s)-7] elif s[len(s)-6:len(s)] == "eraser": s = s[:len(s)-6] else: if len(s) == 0: n = 1 print("YES") else: n = -1 print("NO")
s769124263
p03474
u908349502
2,000
262,144
Wrong Answer
20
3,188
200
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
a,b=map(int,input().split()) s=input() f=1 for i in range(a): if s[i]=='-': f=0 if[a]!='-': f=0 for j in range(b): if s[a+1+j]=='-': f=0 if f: print('Yes') else: print('No')
s828358781
Accepted
20
3,060
202
a,b=map(int,input().split()) s=input() f=1 for i in range(a): if s[i]=='-': f=0 if s[a]!='-': f=0 for j in range(b): if s[a+1+j]=='-': f=0 if f: print('Yes') else: print('No')
s548944614
p03158
u543954314
2,000
1,048,576
Wrong Answer
1,450
23,972
581
There are N cards. The i-th card has an integer A_i written on it. For any two cards, the integers on those cards are different. Using these cards, Takahashi and Aoki will play the following game: * Aoki chooses an integer x. * Starting from Takahashi, the two players alternately take a card. The card should be chosen in the following manner: * Takahashi should take the card with the largest integer among the remaining card. * Aoki should take the card with the integer closest to x among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards. * The game ends when there is no card remaining. You are given Q candidates for the value of x: X_1, X_2, ..., X_Q. For each i (1 \leq i \leq Q), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses x = X_i.
n,q = map(int,input().split()) a = list(map(int,input().split())) g = [0]*(n+1) h = [0] + a[1-n%2::2] m = len(h)-1 for i in range(n): g[i+1] = g[i] + a[i] for i in range(m): h[i+1] += h[i] d = {10**10:h[-1]} for j in range(1,(n+1)//2+1): tak = g[n] - g[n-j] + h[(n-2*j)//2+n%2] key = (a[n-j]+a[n-2*j])//2 + 1 d[key] = tak l = list(d.keys()) l.sort() m = len(l) l.append(0) d[0] = g[n]-g[n-(n+1)//2] for _ in range(q): x = int(input()) ok,ng = m,-1 while ok-ng>1: mid = (ng+ok)//2 if l[mid] >= x: ok = mid else: ng = mid print(d[l[ok]])
s485233366
Accepted
910
23,456
504
import bisect n, q = map(int,input().split()) a = list(map(int,input().split())) a.reverse() cums = [0]*(n+1) cume = [0]*(n+1) for i in range(n): cums[i+1] = cums[i] + a[i] cume[i+1] = cume[i] + a[i]*(1 - i%2) bo = list() sc = list() for i in range(1,(n+1)//2): b = (a[i] + a[2*i])//2 + 1 bo.append(b) s = cums[i] + cume[-1] - cume[2*i] sc.append(s) sc.append(cums[(n+1)//2]) bo.reverse() sc.reverse() for _ in range(q): i = bisect.bisect(bo, int(input())) print(sc[i])
s462785513
p03828
u844646164
2,000
262,144
Wrong Answer
26
3,316
453
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
import math from collections import Counter from collections import defaultdict mod = 10**9+7 def prime(n): for i in range(2, math.ceil(math.sqrt(n))+1): while n % i == 0: n /= i prime_count[i] += 1 if n > 1: prime_count[int(n)] += 1 n = int(input()) a = 1 prime_count = defaultdict(int) for i in range(1, n+1): prime(i) print(prime_count) ans = 1 for v in prime_count.values(): ans *= (v+1) ans %= mod print(ans)
s991799615
Accepted
25
3,316
434
import math from collections import Counter from collections import defaultdict mod = 10**9+7 def prime(n): for i in range(2, math.ceil(math.sqrt(n))+1): while n % i == 0: n /= i prime_count[i] += 1 if n > 1: prime_count[int(n)] += 1 n = int(input()) a = 1 prime_count = defaultdict(int) for i in range(1, n+1): prime(i) ans = 1 for v in prime_count.values(): ans *= (v+1) ans %= mod print(ans)
s839383826
p03486
u302292660
2,000
262,144
Wrong Answer
17
3,064
208
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = input() t = input() Ls= [] Lt= [] for i in s: Ls.append(i) Ls = "".join(Ls) for i in t: Lt.append(i) Lt = "".join(Lt) L = [Ls,Lt] L = sorted(L) if L[0]==Ls: print("Yes") else: print("No")
s840286680
Accepted
17
3,064
388
s = sorted(input()) t = sorted(input())[::-1] Ls= [] Lt= [] if len(s)<len(t) and set(s) == set(s)&set(t): print("Yes") else: for i in s: Ls.append(i) Ls = "".join(Ls) for i in t: Lt.append(i) Lt = "".join(Lt) L = [Ls,Lt] L = sorted(L) if L[0]==L[1]: print("No") elif L[0]==Ls: print("Yes") else: print("No")
s204307484
p03695
u787456042
2,000
262,144
Wrong Answer
18
3,060
131
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
N,*A=map(int,open(0).read().split());l=[0]*9 for a in A:l[min(8,a//400)]+=1 m=sum([0<l[i]for i in range(8)]);print(min(m,1),m+l[8])
s445359273
Accepted
17
3,060
131
N,*A=map(int,open(0).read().split());l=[0]*9 for a in A:l[min(8,a//400)]+=1 m=sum([0<l[i]for i in range(8)]);print(max(m,1),m+l[8])
s219974358
p03697
u870297120
2,000
262,144
Wrong Answer
17
2,940
68
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
a,b = map(int, input().split()) print(a+b if a+b >= 10 else 'error')
s283015502
Accepted
17
2,940
67
a,b = map(int, input().split()) print(a+b if a+b < 10 else 'error')
s351569527
p03227
u663710122
2,000
1,048,576
Wrong Answer
17
2,940
47
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
S = input() print(S if len(S) == 2 else S[-1])
s734902329
Accepted
17
2,940
49
S = input() print(S if len(S) == 2 else S[::-1])
s040592988
p04043
u843318346
2,000
262,144
Wrong Answer
17
2,940
113
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
arr = list(map(int,input().split())) if arr[0]==5 and arr[1]==7 and arr[2]==5: print('YES') else: print('NO')
s727935527
Accepted
17
2,940
111
arr = list(map(int,input().split())) if arr.count(5)==2 and arr.count(7)==1: print('YES') else: print('NO')
s040278991
p03472
u924374652
2,000
262,144
Time Limit Exceeded
2,108
21,620
751
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()) list_w = [] max_a = [-1, -1, 10**9] for i in range(n): a, b = list(map(int, input().split())) list_w.append([a, b]) if max_a[1] < a: max_a = [i, a, b] elif max_a[1] == a and max_a[2] > b: max_a = [i, a, b] list_w.pop(max_a[0]) list_w.sort(key=lambda x:x[1], reverse=True) count = 0 while h > 0: if h > max_a[2]: if len(list_w) > 0 and list_w[0][1] > max_a[1]: h -= list_w[0][1] list_w.pop(0) count += 1 else: if max_a[2] > max_a[1]: num = (h - max_a[2]) // max_a[1] h -= max_a[1] * num count += num else: num = h // max_a[1] h -= max_a[1] * num count += num else: h -= max_a[2] count += 1 print(count)
s783726510
Accepted
1,924
12,104
399
import math n, h = map(int, input().split()) list_a = [] list_b = [] for i in range(n): a, b = list(map(int, input().split())) list_a.append(a) list_b.append(b) max_a = max(list_a) use_b = [b for b in list_b if b > max_a] use_b.sort(reverse=True) count = 0 while h > 0: if len(use_b) > 0: h -= use_b.pop(0) count += 1 else: count += math.ceil(h / max_a) break print(count)
s168373250
p03380
u740284863
2,000
262,144
Wrong Answer
2,229
2,018,104
456
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
import math import itertools def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) n = int(input()) a = list(map(int,input().split())) b = list(itertools.combinations(a,2)) ans = [0,(0,0)] #print(b) for i in range(len(b)): tmpans = combinations_count(max(b[i][0], b[i][1]),min(b[i][0], b[i][1])) if tmpans >= ans[0]: ans = [tmpans,(b[i][0], b[i][1])] print(ans[1][0],ans[1][1])
s642913715
Accepted
71
14,428
162
n = int(input()) a = list(map(int,input().split())) m = max(a) del a[a.index(m)] dis = [abs(m/2 - a[i]) for i in range(n-1)] r = a[dis.index(min(dis))] print(m,r)
s597648333
p03779
u113971909
2,000
262,144
Wrong Answer
2,131
309,816
485
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
X=int(input()) from collections import deque def dfs_2(start,goal): q = deque([]) q.append([start]) flg = 0 while flg==0: p = q.popleft() 取りだし(先頭) jp = len(p) if p[-1]-jp == goal or p[-1]+jp == goal: print(p) return jp else: p0 = [p[-1]] pp = [p[-1]+jp] pm = [p[-1]-jp] q.append(p+pp)追加 q.append(p+pm) q.append(p+p0) print(dfs_2(0,X))
s500038276
Accepted
24
2,940
80
X=int(input()) s=0 for t in range(X+1): s+=t if s>=X: print(t) break
s598667018
p02281
u939814144
1,000
131,072
Wrong Answer
20
7,752
3,726
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.
class Node: def __init__(self, node_id, left_child, right_child): self.node_id = node_id self.parent = -1 self.sibling = -1 self.degree = 0 self.depth = 0 self.height = 0 self.node_type = '' self.left_child = left_child self.right_child = right_child def binarytrees(): def input_node_list(): n = int(input()) for i in range(n): node_id, left_child, right_child = list(map(int, input().split())) node = Node(node_id, left_child, right_child) node_list.append(node) node_list.sort(key = lambda node: node.node_id) def calc_parent_sibling_degree(): if node.left_child != -1: node_list[node.left_child].parent = node.node_id node_list[node.left_child].sibling = node.right_child node.degree += 1 if node.right_child != -1: node_list[node.right_child].parent = node.node_id node_list[node.right_child].sibling = node.left_child node.degree += 1 def calc_depth(node_id): if node_list[node_id].parent == -1: return 0 else: return calc_depth(node_list[node_id].parent) + 1 def calc_height(node_id): if node_list[node_id].degree == 0: return 0 else: left_height = right_height = 0 if node_list[node_id].left_child != -1: left_height = calc_height(node_list[node_id].left_child) if node_list[node_id].right_child != -1: right_height = calc_height(node_list[node_id].right_child) return max(left_height, right_height) + 1 def calc_node_type(): if node.depth == 0: node.node_type = 'root' elif node.height == 0: node.node_type = 'leaf' else: node.node_type = 'internal node' def show_node_info(): print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}' .format(node.node_id, node.parent, node.sibling, node.degree, node.depth, node.height, node.node_type)) node_list = [] input_node_list() for node in node_list: calc_parent_sibling_degree() for node in node_list: node.depth = calc_depth(node.node_id) node.height = calc_height(node.node_id) calc_node_type() show_node_info() return node_list def treewalk(): def show_preorder(node_id): current_node = node_list[node_id] print(' {}'.format(current_node.node_id), end='') if current_node.left_child != -1: show_preorder(current_node.left_child) if current_node.right_child != -1: show_preorder(current_node.right_child) def show_inorder(node_id): current_node = node_list[node_id] if current_node.left_child != -1: show_inorder(current_node.left_child) print(' {}'.format(current_node.node_id), end='') if current_node.right_child != -1: show_inorder(current_node.right_child) def show_postorder(node_id): current_node = node_list[node_id] if current_node.left_child != -1: show_postorder(current_node.left_child) if current_node.right_child != -1: show_postorder(current_node.right_child) print(' {}'.format(current_node.node_id), end='') node_list = binarytrees() print('Preorder') show_preorder(0) print('') print('Inorder') show_inorder(0) print('') print('Postorder') show_postorder(0) print('') if __name__ == '__main__': treewalk()
s363025456
Accepted
20
7,848
3,863
class Node: def __init__(self, node_id, left_child, right_child): self.node_id = node_id self.parent = -1 self.sibling = -1 self.degree = 0 self.depth = 0 self.height = 0 self.node_type = '' self.left_child = left_child self.right_child = right_child def binarytrees(): def input_node_list(): n = int(input()) for i in range(n): node_id, left_child, right_child = list(map(int, input().split())) node = Node(node_id, left_child, right_child) node_list.append(node) node_list.sort(key = lambda node: node.node_id) def calc_parent_sibling_degree(): if node.left_child != -1: node_list[node.left_child].parent = node.node_id node_list[node.left_child].sibling = node.right_child node.degree += 1 if node.right_child != -1: node_list[node.right_child].parent = node.node_id node_list[node.right_child].sibling = node.left_child node.degree += 1 def calc_depth(node_id): if node_list[node_id].parent == -1: return 0 else: return calc_depth(node_list[node_id].parent) + 1 def calc_height(node_id): if node_list[node_id].degree == 0: return 0 else: left_height = right_height = 0 if node_list[node_id].left_child != -1: left_height = calc_height(node_list[node_id].left_child) if node_list[node_id].right_child != -1: right_height = calc_height(node_list[node_id].right_child) return max(left_height, right_height) + 1 def calc_node_type(): if node.depth == 0: node.node_type = 'root' elif node.height == 0: node.node_type = 'leaf' else: node.node_type = 'internal node' def show_node_info(): print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}' .format(node.node_id, node.parent, node.sibling, node.degree, node.depth, node.height, node.node_type)) node_list = [] input_node_list() for node in node_list: calc_parent_sibling_degree() # for node in node_list: # node.depth = calc_depth(node.node_id) # node.height = calc_height(node.node_id) # calc_node_type() # show_node_info() return node_list def treewalk(): def show_preorder(node_id): current_node = node_list[node_id] print(' {}'.format(current_node.node_id), end='') if current_node.left_child != -1: show_preorder(current_node.left_child) if current_node.right_child != -1: show_preorder(current_node.right_child) def show_inorder(node_id): current_node = node_list[node_id] if current_node.left_child != -1: show_inorder(current_node.left_child) print(' {}'.format(current_node.node_id), end='') if current_node.right_child != -1: show_inorder(current_node.right_child) def show_postorder(node_id): current_node = node_list[node_id] if current_node.left_child != -1: show_postorder(current_node.left_child) if current_node.right_child != -1: show_postorder(current_node.right_child) print(' {}'.format(current_node.node_id), end='') node_list = binarytrees() root_id = 0 for node in node_list: if node.parent == -1: root_id = node.node_id print('Preorder') show_preorder(root_id) print('') print('Inorder') show_inorder(root_id) print('') print('Postorder') show_postorder(root_id) print('') if __name__ == '__main__': treewalk()
s078574243
p04045
u013408661
2,000
262,144
Wrong Answer
18
3,064
453
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
n,k=map(int,input().split()) d=list(map(int,input().split())) number=[] for i in range(10): number.append(i) likenumber=[i for i in number if i not in d] n=list(str(n)) n=list(map(int,n)) for i in range(len(n)-1,-1,-1): if n[i]>9: if i==len(n)-1: n.insert(0,0) n[i]-=10 n[i-1]+=1 if n[i] in d: for j in likenumber: if j<n[i]: n[i]=j continue n[i]=min(likenumber) n[i-1]+=1 print("".join(map(str,n)))
s118033173
Accepted
79
2,940
203
n,k=map(int,input().split()) d=list(map(int,input().split())) for i in range(n,10**6): flag=True for j in str(i): if int(j) in d: flag=False break if flag: print(i) exit()
s906114495
p03360
u335278042
2,000
262,144
Wrong Answer
17
2,940
94
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
lis = list(map(int,input().split())) K = int(input()) s=sum(lis)-max(lis)+max(lis)**K print(s)
s462732279
Accepted
17
2,940
96
lis = list(map(int,input().split())) K = int(input()) s=sum(lis)-max(lis)+max(lis)*2**K print(s)
s740833088
p02936
u818078165
2,000
1,048,576
Wrong Answer
2,071
144,764
719
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
n,q = map(int,input().split()) #print(n,q) edge=[] for i in range(n-1): a = list(map(int,input().split())) edge.append(a) add_list = [] for i in range(q): p = list(map(int,input().split())) add_list.append(p) #print(edge,add_list) ans = [0] * n edge_list = [[] for i in range(n)] for e in edge: edge_list[e[1]-1].append(e[0]-1) add_value = [0]*n for v in add_list: add_value[v[0]-1] += v[1] #print(edge_list) #print(add_value) dp = [-1] * n def get_value(i): if(dp[i]!=-1): return dp[i] tmp = add_value[i] for e in edge_list[i]: tmp += get_value(e) dp[i] = tmp return dp[i] for i in range(n): ans[i] = get_value(i) #print(i,ans) print(ans)
s531227673
Accepted
1,993
312,792
727
import sys input = sys.stdin.readline sys.setrecursionlimit(900000) n, q = map(int, input().split()) #print(n,q) edge = [] for i in range(n-1): a = list(map(int, input().split())) edge.append(a) add_list = [] for i in range(q): p = list(map(int, input().split())) add_list.append(p) #print(edge,add_list) dir_edge = [[] for i in range(n)] for e in edge: dir_edge[e[0]-1].append(e[1]-1) dir_edge[e[1]-1].append(e[0]-1) #print(dir_edge) ans = [0]*n for v in add_list: ans[v[0]-1] += v[1] #print(add_value) def dfs(index, parent): if parent != -1: ans[index] += ans[parent] for i in dir_edge[index]: if (parent != i): dfs(i,index) dfs(0, -1) print(*ans)
s776043285
p03479
u853900545
2,000
262,144
Wrong Answer
17
3,064
84
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
x,y = map(int,input().split()) c = 0 d = y//x while 2**c <= d: c += 1 print(c-1)
s603880313
Accepted
18
2,940
82
x,y = map(int,input().split()) c = 0 d = y//x while 2**c <= d: c += 1 print(c)
s707821038
p04030
u016901717
2,000
262,144
Wrong Answer
17
2,940
106
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?
t="" for i in input(): if i=="B": t=t[:-1] else: t+=i print(t)
s350277935
Accepted
17
2,940
105
t="" for i in input(): if i=="B": t=t[:-1] else: t+=i print(t)
s001981641
p03378
u109796335
2,000
262,144
Wrong Answer
17
3,064
423
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
input_data = input().replace("\n", " ").split(" ") n, m, x = int(input_data[0]), int(input_data[1]), int(input_data[2]) def problemB(n, m, x): masu_list = [0] * (n+1) adder = input_data[3:] for i in adder: masu_list[int(i)] = 1 front = sum(masu_list[:x]) back = sum(masu_list[x+1:]) if front <= back: return print(front) else: return print(back) problemB(n, m, x)
s167711567
Accepted
17
3,064
405
input_front = input().split(" ") input_back = input().split(" ") n, x = int(input_front[0]), int(input_front[2]) def problemB(n, x): masu_list = [0] * (n+1) adder = input_back for i in adder: masu_list[int(i)] = 1 front = sum(masu_list[:x]) back = sum(masu_list[x+1:]) if front <= back: return print(front) else: return print(back) problemB(n, x)
s398879114
p03854
u034782764
2,000
262,144
Wrong Answer
96
3,380
413
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() a=('dream','dreamer','erase','eraser') s_2=s[::-1] a_2=(a[0][::-1],a[1][::-1],a[2][::-1],a[3][::-1]) #print(s_2) #print(a_2) while len(s_2) > 0: judge = [s_2.startswith(i) for i in a_2] #print(judge) if any(judge)==True: target=a[judge.index(True)] s_2=s_2[len(target):] if len(s_2)==0: print('Yes') else: print('NO') break
s163210971
Accepted
95
3,188
321
given = ["dreamer", "dream", "eraser", "erase"] S = input() while len(S) > 0: judge = [S.endswith(i) for i in given] if any(judge): target = given[judge.index(True)] S = S[:-len(target)] if len(S) == 0: print("YES") break else: print("NO") break
s549992674
p02663
u619551113
2,000
1,048,576
Wrong Answer
21
9,160
123
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
li = list(map(int,input().split())) h1, m1, h2, m2, k = li life_time = (h2 - h1)*60 + (m2 - m1) time = life_time - k
s620503572
Accepted
23
9,164
135
li = list(map(int,input().split())) h1, m1, h2, m2, k = li life_time = (h2 - h1)*60 + (m2 - m1) time = life_time - k print(time)
s113127252
p03544
u178432859
2,000
262,144
Wrong Answer
17
2,940
92
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)
l = [0,1] n = int(input()) for i in range(2,n+1): l.append(l[i-1] + l[i-2]) print(l[-1])
s347692573
Accepted
17
2,940
88
l = [2,1] n = int(input()) for i in range(n-1): l.append(l[i] + l[i+1]) print(l[-1])
s263958350
p03997
u516579758
2,000
262,144
Wrong Answer
17
2,940
61
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h/2)
s116840793
Accepted
17
2,940
62
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h//2)
s847165915
p03163
u219417113
2,000
1,048,576
Wrong Answer
304
21,236
512
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
import numpy as np n, W = map(int, input().split()) w, v = [0] * n, [0] * n for i in range(n): w[i], v[i] = map(int, input().split()) ndp = np.zeros(W + 1, dtype=np.int64) print(ndp) for w, v in zip(w, v): np.maximum(ndp[:-w] + v, ndp[w:], out=ndp[w:]) print(ndp[-1])
s319747855
Accepted
171
14,584
500
import numpy as np n, W = map(int, input().split()) w, v = [0] * n, [0] * n for i in range(n): w[i], v[i] = map(int, input().split()) ndp = np.zeros(W + 1, dtype=np.int64) for w, v in zip(w, v): np.maximum(ndp[:-w] + v, ndp[w:], out=ndp[w:]) print(ndp[-1])
s042699889
p02614
u253093300
1,000
1,048,576
Wrong Answer
26
9,168
119
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
H, W, K = map(int, input().split(' ')) board = [] for _ in range(H): board.append([c for c in input()]) print('1')
s199691419
Accepted
65
9,052
463
H, W, K = map(int, input().split(' ')) mat = [] for _ in range(H): mat.append(input()) ans = 0 for ib in range(1<<H): for jb in range(1<<W): count = 0 for i in range(H): for j in range(W): if ib>>i&1: continue if jb>>j&1: continue if mat[i][j] == '#': count += 1 if count == K: ans += 1 print(ans)
s145017746
p03048
u248670337
2,000
1,048,576
Wrong Answer
1,210
2,940
148
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
r,g,b,n=map(int,input().split()) c=0 for i in range(n//r+1): a=r*i for j in range(a,n//g+1): a+=g*j if (n-a)%b: c+=1 print(c)
s308322989
Accepted
1,273
2,940
141
r,g,b,n=map(int,input().split()) a=0 for i in range(n//r+1): x=r*i for j in range((n-x)//g+1): if (n-x-g*j)%b==0: a+=1 print(a)
s127016682
p03555
u207799478
2,000
262,144
Wrong Answer
17
2,940
103
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.
a=input() b=input() if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]: print('Yes') else: print('No')
s523387918
Accepted
17
2,940
137
# coding: utf-8 # Your code here! a=input() b=input() if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]: print('YES') else: print('NO')
s641772826
p03854
u811176339
2,000
262,144
Wrong Answer
127
9,172
301
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`.
lt = ["dream", "dreamer", "erase", "eraser"] s = input() lt = [w[::-1] for w in lt] s = s[::-1] cond = True i = 0 while i < len(s): for t in lt: if s[i:].startswith(t): i += len(t) break else: cond = False break print("Yes" if cond else "No")
s139566402
Accepted
123
9,208
301
lt = ["dream", "dreamer", "erase", "eraser"] s = input() lt = [w[::-1] for w in lt] s = s[::-1] cond = True i = 0 while i < len(s): for t in lt: if s[i:].startswith(t): i += len(t) break else: cond = False break print("YES" if cond else "NO")
s685673583
p03761
u088552457
2,000
262,144
Wrong Answer
21
3,316
405
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.
import collections n = int(input()) s = [input() for i in range(n)] if n == 1: print("".join(sorted(s[0]))) else: c = [] for i in s: c.append(collections.Counter(i)) a = c[0] for i in range(1, n): a &= c[i] ans = [] a = a.most_common() print(a) for i in a: for j in range(i[1]): ans.append(i[0]) print("".join(sorted(ans)))
s823414131
Accepted
20
3,064
347
n = int(input()) ss = [] mins = 'a'*100 for _ in range(n): s = str(''.join(sorted(input()))) ss.append(s) if len(mins) > len(s): mins = s ans = '' for w in mins: ok = True for i, s in enumerate(ss[:]): if w in s: wi = s.find(w) ss[i] = s[:wi] + s[wi+1:] else: ok = False if ok: ans += w print(ans)
s894706038
p02972
u089142196
2,000
1,048,576
Wrong Answer
388
7,276
496
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
N=int(input()) A=list(map(int, input().split())) A.insert(0,0) total=sum(A) sum=0 count=0 OK_Flag=True OK_list=[] for i in range(1,N+1): sum=0 for j in range(i,N+1,i): if OK_Flag==True: #print(i,A[j-1]) sum=sum+A[j] #print(i,j,sum) #print(sum,sum%2,A[i]) if sum%2==A[i]: if A[i]==1: count=count+1 OK_list.append(A[i]) else: OK_Flag=False if OK_Flag==True: print(count) if count!=0: print(' '.join(map(str, OK_list))) else: print(-1)
s327981141
Accepted
268
14,132
291
N=int(input()) a=list(map(int, input().split())) b=[0]*N for i in range(N-1,-1,-1): summ = sum(b[2*i+1::i+1]) if summ%2==0: b[i] = a[i] else: b[i] = 1-a[i] #print(i,summ,b[i]) ans=[] print(sum(b)) for i,num in enumerate(b): if num==1: ans.append(i+1) print(*ans)
s109176971
p02613
u005569385
2,000
1,048,576
Wrong Answer
140
16,300
230
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) s = [input() for i in range(N)] a = s.count("AC") b = s.count("WA") c = s.count("TLE") d = s.count("RE") print("AC * {}".format(a)) print("WA * {}".format(b)) print("TLE * {}".format(c)) print("RE * {}".format(d))
s008194399
Accepted
139
16,304
230
N = int(input()) s = [input() for i in range(N)] a = s.count("AC") b = s.count("WA") c = s.count("TLE") d = s.count("RE") print("AC x {}".format(a)) print("WA x {}".format(b)) print("TLE x {}".format(c)) print("RE x {}".format(d))
s739094443
p03470
u039192119
2,000
262,144
Wrong Answer
17
3,064
55
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?
print(len([int(input()) for i in range(int(input()))]))
s127030418
Accepted
18
2,940
64
a=[int(input()) for i in range(int(input()))] print(len(set(a)))
s315303295
p03943
u860002137
2,000
262,144
Wrong Answer
17
2,940
90
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()) print("Yes") if (a + b + c) // 2 == 0 else print("No")
s313268042
Accepted
17
2,940
116
a, b, c = map(int, input().split()) whole = a + b + c print("Yes") if (whole / 2) == max([a, b, c]) else print("No")
s282183703
p02401
u925992597
1,000
131,072
Wrong Answer
20
7,328
75
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: try: print(eval(input())) except: break
s401345194
Accepted
30
7,344
80
while True: try: print(int(eval(input()))) except: break
s027473613
p02578
u914802579
2,000
1,048,576
Wrong Answer
110
32,372
141
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
n=int(input()) l=list(map(int,input().split())) mx=l[0] an=0 for i in range(1,n): if l[i]<mx: an+=mx-l[i] else: l[i]=mx print(an)
s538777833
Accepted
116
32,380
141
n=int(input()) l=list(map(int,input().split())) mx=l[0] an=0 for i in range(1,n): if l[i]<mx: an+=mx-l[i] else: mx=l[i] print(an)
s998533189
p03696
u039623862
2,000
262,144
Wrong Answer
17
2,940
177
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
n = int(input()) s = input() cnt = [0, 0] ans = '' for i in range(n): if s[i] == ')': cnt[0] += 1 else: cnt[1] += 1 print('(' * cnt[0] + s + ')'*cnt[1])
s736450027
Accepted
17
3,060
277
n = int(input()) s = input() cnt = [0, 0] add = [0, 0] ans = '' for i in range(n): if s[i] == ')': cnt[0] += 1 if cnt[0] > cnt[1]: add[1] += 1 cnt[1] += 1 else: cnt[1] += 1 print('(' * add[1] + s + ')'*(cnt[1] -cnt[0]))
s875244795
p00045
u301729341
1,000
131,072
Time Limit Exceeded
40,000
7,612
238
販売単価と販売数量を読み込んで、販売金額の総合計と販売数量の平均を出力するプログラムを作成してください。
P_Sum = 0 N_Sum = 0 Kazu = 0 while True: try: pri,num = map(int,input().split(",")) P_Sum += num * pri N_Sum += num Kazu += 1 except EOFError: print(P_Sum) print(round(N_Sum / Kazu))
s594649971
Accepted
20
7,584
269
P_Sum = 0 N_Sum = 0 Kazu = 0 while True: try: pri,num = map(int,input().split(",")) P_Sum += num * pri N_Sum += num Kazu += 1 except(EOFError,ValueError): print(P_Sum) print(int((N_Sum / Kazu)+ 0.5)) break
s720520842
p03048
u254050469
2,000
1,048,576
Wrong Answer
1,893
3,316
422
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
n = [int(i) for i in input().split() ] rgb = n[0:3] rgb.sort(reverse=True) #rgb = list(filter(lambda x:x >= n[3],rgb)) rm = int(n[3]/rgb[0] ) + 1 c = 0 for i in range(rm): print(i) if i * rgb[0] == n[3]: c += 1 break for j in range(int((n[3] - i * rgb[0])/rgb[1]) + 1): if (n[3] - i * rgb[0] - j * rgb[1]) % rgb[2] == 0: c += 1 print (c)
s231917311
Accepted
1,833
3,064
409
n = [int(i) for i in input().split() ] rgb = n[0:3] rgb.sort(reverse=True) #rgb = list(filter(lambda x:x >= n[3],rgb)) rm = int(n[3]/rgb[0] ) + 1 c = 0 for i in range(rm): if i * rgb[0] == n[3]: c += 1 break for j in range(int((n[3] - i * rgb[0])/rgb[1]) + 1): if (n[3] - i * rgb[0] - j * rgb[1]) % rgb[2] == 0: c += 1 print (c)
s882700153
p03494
u248670337
2,000
262,144
Time Limit Exceeded
2,104
2,940
96
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.
input() A=list(map(int,input().split())) ans=0 while all(a%2==0 for a in A): ans+=1 print(ans)
s512479952
Accepted
22
3,060
117
input() A=list(map(int,input().split())) ans=0 while all(a%2==0 for a in A): A=[a/2 for a in A] ans+=1 print(ans)