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
s916918084
p02419
u908651435
1,000
131,072
Wrong Answer
20
5,552
177
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
w=input().lower() count=0 while True: t=input().lower().split() if t[0]=='end_of_text': break for i in t: if w==t: count+=1 print(count)
s674261251
Accepted
20
5,556
182
w=input().lower() count=0 while True: t=input() if t=='END_OF_TEXT': break t=t.lower().split() for i in t: if w==i: count+=1 print(count)
s760141564
p03024
u368016155
2,000
1,048,576
Wrong Answer
17
2,940
106
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() loss = 0 for s in S: if s == '×': loss += 1 if loss>=8: print('no') else: print('Yes')
s501123593
Accepted
17
2,940
105
S = input() loss = 0 for s in S: if s == 'x': loss += 1 if loss>=8: print('NO') else: print('YES')
s238359561
p03997
u402467563
2,000
262,144
Wrong Answer
17
2,940
67
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)
s311724942
Accepted
17
2,940
72
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h/2))
s548008591
p03161
u538817603
2,000
1,048,576
Wrong Answer
2,104
14,468
218
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N, K = map(int,input().split()) h = list(map(int,input().split())) dp = [0] * N dp[1] = abs(h[0] - h[1]) for i in range(2, N): dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(i - K, i) if j >= 0]) print(dp)
s735902605
Accepted
1,982
14,016
319
import sys input = sys.stdin.readline def main(): N, K = map(int,input().split()) h = list(map(int,input().split())) dp = [0] * N for i in range(1, N): dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - K), i)) print(dp[-1]) if __name__ == '__main__': main()
s733075375
p04043
u311900413
2,000
262,144
Wrong Answer
17
2,940
180
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a,b,c=map(int,input().split()) if (a==5 and b==5) or (a==5 and c==5) or (c==5 and b==5): if a+b+c==17 : print('Yes') else: print('No') else: print('No')
s303773387
Accepted
18
2,940
96
a=input().split() if a.count('5')==2 and a.count('7')==1: print('YES') else: print('NO')
s132307262
p02388
u196653484
1,000
131,072
Wrong Answer
20
5,604
352
Write a program which calculates the cube of a given integer x.
def X_Cubic(): x=int(input("input_x:")) print("Cube of {} = {}".format(x,x**3)) if __name__ == "__main__": X_Cubic() """ C:\programs\program_training\AizuOnlineJudge>python ITP1_1B.py input_x:2 Cube of 2 = 8 C:\programs\program_training\AizuOnlineJudge>python ITP1_1B.py input_x:3 Cube of 3 = 27 """
s609295962
Accepted
20
5,588
105
def X_Cubic(): x=int(input()) print("{}".format(x**3)) if __name__ == '__main__': X_Cubic()
s983499002
p03229
u177040005
2,000
1,048,576
Wrong Answer
215
8,284
1,522
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
import bisect N = int(input()) A = [int(input()) for _ in range(N)] A = sorted(A) ret = 0 # if N != len(list(set(A))): # tmp = -1 # AA = [] # Dup_cnt = 0 # for i,a in A: # if a != tmp: # AA.append(a) # tmp = a # else: # Dup_cnt = 0 # while a == A[i+Dup_cnt]: # Dup_cnt += 1 # Dup_cnt -= 1 if N == 2: print(A[1] - A[0]) exit() if N == 3: print(A[1] + A[2] - A[0]*2) exit() if N%2 == 1: smo = A[:N//2] lar = A[N//2:] lar = lar[::-1] ret += sum(lar)*2 ret -= sum(smo)*2 - (smo[-1] + smo[-2]) else: smo = A[:N//2] lar = A[N//2:] lar = lar[::-1] ret += sum(lar)*2 - lar[-1] ret -= sum(smo)*2 - smo[-1] # print(ret,lar[i],lar[i+1],smp[i]) print(ret) # L = N//2 - 1 # R = N//2 + 1 # ans[N//2] = mid # if i%2 == 1: # if i%4 == 1: # ans[L] = lar[] # elif i%4 == 3: # ans[L] = A[-(i//2)] # L -= L # elif i%2 == 0: # ans[R] = A[i] # R += 1 # print(ans) # print(ret)
s165149665
Accepted
350
9,556
790
N = int(input()) A = [] for i in range(N): a = int(input()) A.append(a) A = sorted(A) P1 = [0 for _ in range(N)] for i in range(N): if i == 0: P1[0] = 1 elif i%2 == 1: if i == N-1: P1[i] = -1 else: P1[i] = -2 else: if i == N - 1: P1[i] = 1 else: P1[i] = 2 P1 = sorted(P1) P2 = [0 for _ in range(N)] for i in range(N): if i == 0: P2[0] = -1 elif i%2 == 1: if i == N-1: P2[i] = 1 else: P2[i] = 2 else: if i == N - 1: P2[i] = -1 else: P2[i] = -2 P2 = sorted(P2) ans1 = 0 ans2 = 0 for i in range(N): ans1 += P1[i]*A[i] ans2 += P2[i]*A[i] ans = max(ans1,ans2) print(ans)
s386059119
p02279
u024715419
2,000
131,072
Wrong Answer
20
7,732
574
A graph _G_ = ( _V_ , _E_ ) is a data structure where _V_ is a finite set of vertices and _E_ is a binary relation on _V_ represented by a set of edges. Fig. 1 illustrates an example of a graph (or graphs). **Fig. 1** A free tree is a connnected, acyclic, undirected graph. A rooted tree is a free tree in which one of the vertices is distinguished from the others. A vertex of a rooted tree is called "node." Your task is to write a program which reports the following information for each node _u_ of a given rooted tree _T_ : * node ID of _u_ * parent of _u_ * depth of _u_ * node type (root, internal node or leaf) * a list of chidlren of _u_ If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is ( _p_ , _x_ ), then _p_ is the **parent** of _x_ , and _x_ is a **child** of _p_. The root is the only node in _T_ with no parent. A node with no children is an **external node** or **leaf**. A nonleaf node is an **internal node** The number of children of a node _x_ in a rooted tree _T_ is called the **degree** of _x_. The length of the path from the root _r_ to a node _x_ is the **depth** of _x_ in _T_. Here, the given tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1. Fig. 2 shows an example of rooted trees where ID of each node is indicated by a number in a circle (node). The example corresponds to the first sample input. **Fig. 2**
def set_info(a, i, p, d): a[i][1], a[i][2] = p, d for b in a[i][0]: set_info(a, b, i, d + 1) n = int(input()) tree = [[None] for i in range(n)] root = set(range(n)) for i in range(n): l = list(map(int, input().split())) tree[l[0]] = [l[2:], None, None] root -= set(l[2:]) set_info(tree, root.pop(), -1, 0) for i in range(n): c, p, d = tree[i] if p == -1: t = "root" elif len(c) == 0: t = "leaf" else: t = "internal node" print("node ", i, ": parent = ", p, " depth = ", d, ", ", t, ", ", c, sep="")
s587742668
Accepted
1,120
38,188
575
def set_info(a, i, p, d): a[i][1], a[i][2] = p, d for b in a[i][0]: set_info(a, b, i, d + 1) n = int(input()) tree = [[None] for i in range(n)] root = set(range(n)) for i in range(n): l = list(map(int, input().split())) tree[l[0]] = [l[2:], None, None] root -= set(l[2:]) set_info(tree, root.pop(), -1, 0) for i in range(n): c, p, d = tree[i] if p == -1: t = "root" elif len(c) == 0: t = "leaf" else: t = "internal node" print("node ", i, ": parent = ", p, ", depth = ", d, ", ", t, ", ", c, sep="")
s892575777
p02977
u253759478
2,000
1,048,576
Wrong Answer
239
5,208
869
You are given an integer N. Determine if there exists a tree with 2N vertices numbered 1 to 2N satisfying the following condition, and show one such tree if the answer is yes. * Assume that, for each integer i between 1 and N (inclusive), Vertex i and N+i have the weight i. Then, for each integer i between 1 and N, the bitwise XOR of the weights of the vertices on the path between Vertex i and N+i (including themselves) is i.
n = int(input()) if bin(n).count('1') == 1: print('No') else: print('1 2') print('2 3') print('3 {0}'.format(n + 1)) print('{0} {1}'.format(n + 1, n + 2)) print('{0} {1}'.format(n + 2, n + 3)) if n >= 5: if n % 2 == 1: for i in range(2, n + 1): print('1 {0}'.format(i)) if i % 2 == 0: print('{0} {1}'.format(i, i + 1 + n)) else: print('{0} {1}'.format(i, i - 1 + n)) else: for i in range(2, n): print('1 {0}'.format(i)) if i % 2 == 0: print('{0} {1}'.format(i, i + 1 + n)) else: print('{0} {1}'.format(i, i - 1 + n)) print('{0} {1}'.format(n - 1, n)) print('{0} {1}'.format((n - 1) ^ 1 ^ n, n * 2))
s150895541
Accepted
276
5,208
886
n = int(input()) if bin(n).count('1') == 1: print('No') else: print('Yes') print('1 2') print('2 3') print('3 {0}'.format(n + 1)) print('{0} {1}'.format(n + 1, n + 2)) print('{0} {1}'.format(n + 2, n + 3)) if n >= 5: if n % 2 == 1: for i in range(4, n + 1): print('1 {0}'.format(i)) if i % 2 == 0: print('{0} {1}'.format(i, i + 1 + n)) else: print('{0} {1}'.format(i, i - 1 + n)) else: for i in range(4, n): print('1 {0}'.format(i)) if i % 2 == 0: print('{0} {1}'.format(i, i + 1 + n)) else: print('{0} {1}'.format(i, i - 1 + n)) print('{0} {1}'.format(n - 1, n)) print('{0} {1}'.format((n - 1) ^ 1 ^ n, n * 2))
s371486533
p03827
u189487046
2,000
262,144
Wrong Answer
17
2,940
135
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
n = int(input()) s = input() x = 0 for i in range(n): if s[i] == "I": x += 1 elif s[i] == "D": x -= 1 print(x)
s977503842
Accepted
17
2,940
146
n = int(input()) S = input() x = 0 ans = x for s in S: if s == 'I': x += 1 else: x -= 1 ans = max(ans, x) print(ans)
s712679764
p03544
u488127128
2,000
262,144
Wrong Answer
17
3,060
210
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)
n = int(input()) def lucas(n): a,b = 2,1 if n == 1: return a elif n == 2: return b for _ in range(n-2): a,b = b,a+b return b for i in range(1,10): print(lucas(i))
s019235788
Accepted
17
2,940
184
n = int(input()) def lucas(n): a,b = 2,1 if n == 0: return a elif n == 1: return b for _ in range(n-1): a,b = b,a+b return b print(lucas(n))
s518954727
p03919
u940061594
2,000
262,144
Wrong Answer
17
2,940
262
There is a grid with H rows and W columns. The square at the i-th row and j-th column contains a string S_{i,j} of length 5. The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet. Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location. For example, the square at the 6-th row and 8-th column should be reported as `H6`.
#Where's Snuke? H, W = map(int, input().split()) ab = [chr(ord('A') + i) for i in range(26)] for i in range(H): S = input().split() for j in range(W): if S[j] == "snuke": print(ab[i]+str(i+1)) break break
s037181217
Accepted
18
3,060
239
#Where's Snuke? H, W = map(int, input().split()) ab = [chr(ord('A') + i) for i in range(26)] for i in range(H): S = input().split() for j in range(W): if S[j] == "snuke": print(ab[j]+str(i+1)) break
s606624218
p03067
u394376682
2,000
1,048,576
Wrong Answer
17
2,940
118
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a,b,c = map(int,input().split(" ")) if (a < c and c < b) or (a > c and c > b): print("yes") else: print("no")
s755988849
Accepted
19
3,316
118
a,b,c = map(int,input().split(" ")) if (a < c and c < b) or (a > c and c > b): print("Yes") else: print("No")
s288850465
p02401
u216804574
1,000
131,072
Wrong Answer
20
7,620
231
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.
a, op, b = input().split() a, b = int(a), int(b) if op == '?': quit() else: if op == '+': result = a+b elif op == '-': result = a-b elif op == '*': result = a*b elif op == '/': result = a/b print(result)
s106065290
Accepted
20
7,664
276
while True: a, op, b = input().split() a, b = int(a), int(b) if op == '?': quit() else: if op == '+': result = a+b elif op == '-': result = a-b elif op == '*': result = a*b elif op == '/': result = int(a/b) print(result)
s538673296
p03150
u749359783
2,000
1,048,576
Wrong Answer
18
3,060
146
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
S = input() for i in range(len(S)-7): S_cut = S[:i]+S[i+len(S)-7:] print(S_cut) if S_cut=='keyence': print('YES') exit() print('NO')
s311869245
Accepted
17
2,940
147
S = input() for i in range(len(S)-5): S_cut = S[:i]+S[i+len(S)-7:] #print(S_cut) if S_cut=='keyence': print('YES') exit() print('NO')
s994985734
p03493
u821432765
2,000
262,144
Wrong Answer
17
2,940
145
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
S=input() S_half_front=int(S[:2]) S_half_back=int(S[2:]) S_bool=S_half_front is not S_half_back if S_bool: print("No") else: print("Yes")
s638440992
Accepted
19
3,060
29
S=input() print(S.count("1"))
s936481704
p02397
u335511832
1,000
131,072
Wrong Answer
30
7,376
55
Write a program which reads two integers x and y, and prints them in ascending order.
x,y = input().split() if x > y: print(y,x) print(x,y)
s372648704
Accepted
50
7,488
145
while True: x,y = map(int,input().split()) if x == y == 0: break if x > y: print(y,x) continue print(x,y)
s523583718
p02255
u933096856
1,000
131,072
Wrong Answer
20
7,692
106
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
n=int(input()) l=list(map(int, input().split())) for i in range(n): l[0:i]=sorted(l[0:i]) print(l)
s730267149
Accepted
40
8,112
111
n=int(input()) l=list(map(int, input().split())) for i in range(1,n+1): l[0:i]=sorted(l[0:i]) print(*l)
s817827012
p03251
u155687575
2,000
1,048,576
Wrong Answer
17
3,064
357
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.
N, M, X, Y = map(int, input().split()) xlst = list(map(int, input().split())) ylst = list(map(int, input().split())) xmax = max(xlst) ymin = min(ylst) cand = [] for i in range(xmax+1, ymin+1): cand.append(i) print(cand) warflag = True for c in cand: if X < c <= Y: warflag = False if warflag: print('War') else: print('No War')
s004590434
Accepted
17
3,064
345
N, M, X, Y = map(int, input().split()) xlst = list(map(int, input().split())) ylst = list(map(int, input().split())) xmax = max(xlst) ymin = min(ylst) cand = [] for i in range(xmax+1, ymin+1): cand.append(i) warflag = True for c in cand: if X < c <= Y: warflag = False if warflag: print('War') else: print('No War')
s653812937
p02389
u249954942
1,000
131,072
Wrong Answer
20
7,604
48
Write a program which calculates the area and perimeter of a given rectangle.
x,y=[int(i) for i in input().split()] print(x*y)
s107957409
Accepted
30
7,656
90
x,y = [int(i) for i in input().split()] area = x*y length = (x*2)+(y*2) print(area,length)
s619986437
p00067
u873482706
1,000
131,072
Wrong Answer
30
7,452
616
地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ マスのデータを読み込んで、島の数を出力するプログラムを作成してください。
def f1(): t = 0 for y, line in enumerate(M): for x, cell in enumerate(line): if M[y][x] == '1': f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == '1': M[y][x] = '0' f2(x, y-1) f2(x, y+1) f2(x+1, y) f2(x-1, y) M = [] while True: try: line = input() if line == '': print(f1()) M = [] else: M.append(list(input())) except EOFError: print(f1()) break
s482470032
Accepted
30
7,472
603
def f1(): t = 0 for y in range(len(M)): for x in range(len(M[0])): if M[y][x] == '1': f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == '1': M[y][x] = '0' f2(x, y-1) f2(x, y+1) f2(x+1, y) f2(x-1, y) M = [] while True: try: line = input() if line == '': print(f1()) M = [] else: M.append(list(line)) except EOFError: print(f1()) break
s871003727
p03565
u069838609
2,000
262,144
Wrong Answer
18
3,064
918
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`.
# time complexity: O(|S - T|*|T|) # space complexity: O(|S - T|) S_d = input() T = input() len_T = len(T) def replacable(string, T): for char_s, char_t in zip(string, T): if char_s == char_t or char_s == '?': continue else: return False else: return True # see if S_d can contain T t_start_index_list = [] # O(|S - T|) for start_idx in range(len(S_d) - len_T + 1): string = S_d[start_idx:start_idx + len_T] # O(|T|) if replacable(string, T): t_start_index_list.append(start_idx) if len(t_start_index_list) == 0: print("UNRESTORABLE") else: S_candidate_list = [] for t_start_index in t_start_index_list: print(t_start_index) S = S_d[:t_start_index] + T + S_d[t_start_index + len_T:] S = S.replace('?', 'a') S_candidate_list.append(S) S_candidate_list.sort() print(S_candidate_list[0])
s523341187
Accepted
17
3,064
889
# time complexity: O(|S - T|*|T|) # space complexity: O(|S - T|) S_d = input() T = input() len_T = len(T) def replacable(string, T): for char_s, char_t in zip(string, T): if char_s == char_t or char_s == '?': continue else: return False else: return True # see if S_d can contain T t_start_index_list = [] # O(|S - T|) for start_idx in range(len(S_d) - len_T + 1): string = S_d[start_idx:start_idx + len_T] # O(|T|) if replacable(string, T): t_start_index_list.append(start_idx) if len(t_start_index_list) == 0: print("UNRESTORABLE") else: S_candidate_list = [] for t_start_index in t_start_index_list: S = S_d[:t_start_index] + T + S_d[t_start_index + len_T:] S = S.replace('?', 'a') S_candidate_list.append(S) S_candidate_list.sort() print(S_candidate_list[0])
s094396132
p02388
u070968430
1,000
131,072
Wrong Answer
20
7,416
38
Write a program which calculates the cube of a given integer x.
def cubic(x): x = x^3 return x
s747203421
Accepted
20
7,636
47
x = int(input()) y = x **3 print(y, end = "\n")
s380174983
p03719
u596227625
2,000
262,144
Wrong Answer
17
2,940
79
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
A, B, C = map(int, input().split()) print("YES" if A <= C and C <= B else "NO")
s564365482
Accepted
17
2,940
79
A, B, C = map(int, input().split()) print("Yes" if A <= C and C <= B else "No")
s229879958
p03626
u262597910
2,000
262,144
Wrong Answer
18
3,064
760
We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square. Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors. Find the number of such ways to paint the dominoes, modulo 1000000007. The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner: * Each domino is represented by a different English letter (lowercase or uppercase). * The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.
import sys n = int(input()) s = input() #s = [input() for _ in range(2)] print(len(s)) t = [] if (len(s)==1): print(3) sys.exit() if (len(s)==2): print(6) sys.exit() for i in range(len(s)-1): if (i>0): if(s[i-1]==s[i]): if (i == len(s)-2): t.append(1) continue else: continue if (s[i]==s[i+1]): t.append(2) else: t.append(1) print(t) if (t[0]==1): ans = 3 else: ans = 6 for i in range(len(t)-1): print(ans) if (t[i]==1): if (t[i+1]==1): ans *= 2 else: ans *= 2 else: if (t[i+1]==1): ans *= 1 else: ans *= 3 print(ans % 1000000007)
s184689155
Accepted
17
3,064
781
import sys n = int(input()) s = input() t = [] if (len(s)==1): print(3) sys.exit() if (len(s)==2): print(6) sys.exit() for i in range(len(s)-1): if (i>0): if(s[i-1]==s[i]): if (i == len(s)-2): t.append(1) continue else: continue elif (i == len(s)-2 and s[i]!=s[i+1]): t.append(1) if (s[i]==s[i+1]): t.append(2) else: t.append(1) if (t[0]==1): ans = 3 else: ans = 6 for i in range(len(t)-1): if (t[i]==1): if (t[i+1]==1): ans *= 2 else: ans *= 2 else: if (t[i+1]==1): ans *= 1 else: ans *= 3 print(ans % 1000000007)
s033901390
p03815
u971091945
2,000
262,144
Wrong Answer
17
3,060
106
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: * Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.
x=int(input()) ans=x/11 if x%11==0: print(ans) elif x%11<=6: print(ans+1) else: print(ans+2)
s819323804
Accepted
17
2,940
113
x=int(input()) ans=int(x/11)*2 if x%11==0: print(ans) elif x%11<=6: print(ans+1) else: print(ans+2)
s916761123
p02614
u955125992
1,000
1,048,576
Wrong Answer
76
9,208
532
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()) c = [list(input()) for _ in range(h)] ans = 0 #make binary numbers ranging from 0 to 2**h -1 or 2**w -1 for row in range(2**h): for column in range(2**w): count = 0 # Neither ith digit of row nor jth digit of column is 1 and c[i][j] is black. for i in range(h): for j in range(w): if ((row << i)&1) == 0 and ((column << j)&1) == 0 and c[i][j] == '#': count += 1 if count == k: ans += 1 print(ans)
s409818375
Accepted
63
9,136
532
h, w, k = map(int, input().split()) c = [list(input()) for _ in range(h)] ans = 0 #make binary numbers ranging from 0 to 2**h -1 or 2**w -1 for row in range(2**h): for column in range(2**w): count = 0 # Neither ith digit of row nor jth digit of column is 1 and c[i][j] is black. for i in range(h): for j in range(w): if ((row >> i)&1) == 0 and ((column >> j)&1) == 0 and c[i][j] == '#': count += 1 if count == k: ans += 1 print(ans)
s753773005
p03448
u970082363
2,000
262,144
Wrong Answer
52
3,060
254
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()) total = 0 ans = 0 for i in range(a): for j in range(b): for k in range(c): total = 500*a+100*b+50*c if total==x: ans += 1 print(ans)
s675112849
Accepted
55
3,060
260
a = int(input()) b = int(input()) c = int(input()) x = int(input()) total = 0 ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): total = 500*i+100*j+50*k if total==x: ans += 1 print(ans)
s230444444
p03943
u257541375
2,000
262,144
Wrong Answer
18
2,940
114
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 = [int(i) for i in input().split()] if (a+b==c) or (b+c==a) or (c+a==b): print("YES") else: print("NO")
s731827312
Accepted
17
2,940
114
a,b,c = [int(i) for i in input().split()] if (a+b==c) or (b+c==a) or (c+a==b): print("Yes") else: print("No")
s698993508
p03546
u282228874
2,000
262,144
Wrong Answer
42
3,444
493
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
h,w = map(int,input().split()) C = [list(map(int,input().split())) for i in range(10)] A = [list(map(int,input().split())) for i in range(h)] INF = float('inf') cost = 0 D = [[INF]*10 for i in range(10)] for k in range(10): for i in range(10): for j in range(10): D[i][j] = min(C[i][j],C[i][k]+C[k][j]) for y in range(h): for x in range(w): if A[y][x] == -1 or A[y][x] == 1: continue else: cost += D[A[y][x]][1] print(cost)
s870771110
Accepted
284
17,636
333
from scipy.sparse.csgraph import floyd_warshall as wf h,w = map(int,input().split()) C = [list(map(int,input().split())) for i in range(10)] A = [list(map(int,input().split())) for i in range(h)] C = wf(C) cost = 0 for y in range(h): for x in range(w): if A[y][x] != -1: cost += C[A[y][x]][1] print(int(cost))
s058519620
p03545
u357949405
2,000
262,144
Wrong Answer
17
3,064
376
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
ABCD = input() for i in range(2**(len(ABCD)-1)): n = int(ABCD[0]) ans = ABCD[0] for j, c in enumerate(format(i, '0' + str(len(ABCD)-1) + 'b')): if c == '0': n += int(ABCD[j+1]) ans += '+' else: n -= int(ABCD[j+1]) ans += '-' ans += ABCD[j+1] if n == 7: print(ans) exit(0)
s766923090
Accepted
18
3,060
384
ABCD = input() for i in range(2**(len(ABCD)-1)): n = int(ABCD[0]) ans = ABCD[0] for j, c in enumerate(format(i, '0' + str(len(ABCD)-1) + 'b')): if c == '0': n += int(ABCD[j+1]) ans += '+' else: n -= int(ABCD[j+1]) ans += '-' ans += ABCD[j+1] if n == 7: print(ans + '=7') exit(0)
s611474883
p03623
u102960641
2,000
262,144
Wrong Answer
22
2,940
63
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|.
x,a,b = map(int, input().split()) print(min(abs(x-a),abs(x-b)))
s703722672
Accepted
21
2,940
91
x,a,b = map(int, input().split()) if abs(x-a) < abs(x-b) : print("A") else: print("B")
s666571342
p02606
u481060762
2,000
1,048,576
Wrong Answer
25
9,148
161
How many multiples of d are there among the integers between L and R (inclusive)?
l,r,d = map(int,input().split()) ans = 0 for i in range(100): if d * i <= l: ans += 1 if d * i >= r: ans += 1 break print(ans)
s011262040
Accepted
27
9,160
202
l,r,d = map(int,input().split()) #print(l,r,d) ans = 0 for i in range(101): if d * i > r: break elif d * i >= l: ans += 1 continue else: continue print(ans)
s054394873
p03814
u869728296
2,000
262,144
Wrong Answer
71
3,516
156
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s=input() a=0 z=0 for i in range(len(s)): if(s[i]=="A" and a<=i and i<=z): a=i elif(s[i]=="Z" and z<=i ): z=i print(z-a)
s797820388
Accepted
71
3,516
168
s=input() a=200000 z=0 b=[] for i in range(len(s)): if(s[i]=="A" and a>=i): b.append(i) a=i elif(s[i]=="Z" and z<=i ): z=i print(z-a+1)
s349853620
p02578
u674588203
2,000
1,048,576
Wrong Answer
2,206
32,224
210
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.
# C - Step N=int(input()) Als=list(map(int,input().split())) ans=0 for i in range (1,N): if Als[i]>=Als[i-1]: pass else : ans+= max(Als[0:i]) print(ans)
s083529155
Accepted
163
32,036
255
# C - Step N=int(input()) Als=list(map(int,input().split())) ans=0 for i in range (1,N): if Als[i]>=Als[i-1]: pass else : step=abs(Als[i]-Als[i-1]) ans+=step Als[i]+=step print(ans)
s194456332
p03795
u692498898
2,000
262,144
Wrong Answer
17
2,940
46
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
i=int(input()) x=20*i y=(i//15)*200 print(x-y)
s308275447
Accepted
17
2,940
39
i=int(input()) print(800*i-200*(i//15))
s359072205
p02842
u659587571
2,000
1,048,576
Wrong Answer
17
3,060
254
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
amount = int(input()) before_tax = int(amount / 1.08) after_tax = before_tax + 1 print(after_tax, before_tax) if int(after_tax * 1.08) == amount: print(int(after_tax)) elif int(before_tax * 1.08) == amount: print(int(before_tax)) else: print(":(")
s459215792
Accepted
17
3,060
225
amount = int(input()) before_tax = int(amount / 1.08) after_tax = before_tax + 1 if int(after_tax * 1.08) == amount: print(int(after_tax)) elif int(before_tax * 1.08) == amount: print(int(before_tax)) else: print(":(")
s065591553
p02612
u720124072
2,000
1,048,576
Wrong Answer
28
9,144
30
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N%1000)
s835827196
Accepted
31
9,140
72
N = int(input()) if N%1000 == 0: print(0) else: print(1000-N%1000)
s278801206
p03472
u950708010
2,000
262,144
Wrong Answer
1,937
12,712
400
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?
from math import ceil n,h = (int(i) for i in input().split()) a = [] b = [0] for i in range(n): tmp1,tmp2= (int(i) for i in input().split()) a.append(tmp1) b.append(tmp2) a2 = sorted(a,reverse = True) b2 = sorted(b,reverse = True) count = 0 while h > 0: if a2[0] > b2[0]: tmp3 = ceil(h/a2[0]) count += tmp3 h -= tmp3 else: count += 1 h -= b2[0] b2.pop(0) print(count)
s394684079
Accepted
233
8,876
636
import sys input = sys.stdin.readline from collections import deque import math def solve(): n,h = (int(i) for i in input().split()) amax = -99 b = [] for i in range(n): ta,tb = (int(i) for i in input().split()) amax = max(amax,ta) b.append(tb) b = deque(sorted(b,reverse=True)) damage = 0 ct = 0 while damage < h: if len(b): throw = b[0] else: throw = -99 if throw > amax: b.popleft() ct += 1 damage += throw continue else: sabun = h-damage ct += math.ceil(sabun/amax) damage += amax*math.ceil(sabun/amax) print(ct) solve()
s832027268
p03377
u252210202
2,000
262,144
Wrong Answer
17
2,940
88
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A, B, X = map(int, input().split()) if X-B <= A: print("Yes") else: print("No")
s605517841
Accepted
17
2,940
103
A, B, X = map(int, input().split()) if abs(X-A) <= B and A <= X: print("YES") else: print("NO")
s522170481
p01304
u724548524
8,000
131,072
Wrong Answer
30
5,628
702
平安京は、道が格子状になっている町として知られている。 平安京に住んでいるねこのホクサイは、パトロールのために毎日自宅から町はずれの秘密の場所まで行かなければならない。しかし、毎日同じ道を通るのは飽きるし、後を付けられる危険もあるので、ホクサイはできるだけ毎日異なる経路を使いたい。その一方で、ホクサイは面倒臭がりなので、目的地から遠ざかるような道は通りたくない。 平安京のあちこちの道にはマタタビが落ちていて、ホクサイはマタタビが落ちている道を通ることができない。そのような道を通るとめろめろになってしまうからである。幸いなことに、交差点にはマタタビは落ちていない。 ホクサイは、自宅から秘密の場所までの可能な経路の数を知りたい。ここで、ホクサイの自宅は (0, 0) にあり、秘密の場所は(gx, gy)にある。道は x = i (i は整数), y = j (j は整数) に格子状に敷かれている。
for _ in range(int(input())): x, y = map(int, input().split()) m = set() for _ in range(int(input())):m.add(tuple(map(int, input().split()))) q = {(0,0):1} for _ in range(x + y): nq = {} for i in q: if (i[0], i[1], i[0] + 1, i[1]) not in m and i[0] + 1 <= x: if (i[0] + 1, i[1]) in nq:nq[(i[0] + 1, i[1])] += q[i] else:nq[(i[0] + 1, i[1])] = q[i] if (i[0], i[1], i[0], i[1] + 1) not in m and i[1] + 1 <= y: if (i[0], i[1] + 1) in nq:nq[(i[0], i[1] + 1)] += q[i] else:nq[(i[0], i[1] + 1)] = q[i] q = nq if nq == {}:print("Miserable Hokusai!") else:print(q[x, y])
s018149329
Accepted
40
5,620
788
for _ in range(int(input())): x, y = map(int, input().split()) m = set() for _ in range(int(input())):m.add(tuple(map(int, input().split()))) q = {(0,0):1} for _ in range(x + y): nq = {} for i in q: if (i[0], i[1], i[0] + 1, i[1]) not in m and (i[0] + 1, i[1], i[0], i[1]) not in m and i[0] + 1 <= x: if (i[0] + 1, i[1]) in nq:nq[(i[0] + 1, i[1])] += q[i] else:nq[(i[0] + 1, i[1])] = q[i] if (i[0], i[1], i[0], i[1] + 1) not in m and (i[0], i[1] + 1, i[0], i[1]) not in m and i[1] + 1 <= y: if (i[0], i[1] + 1) in nq:nq[(i[0], i[1] + 1)] += q[i] else:nq[(i[0], i[1] + 1)] = q[i] q = nq if nq == {}:print("Miserable Hokusai!") else:print(q[(x, y)])
s098209441
p04029
u432805419
2,000
262,144
Wrong Answer
17
2,940
37
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
a = int(input()) print((a + 1)*a / 2)
s102506004
Accepted
17
2,940
38
a = int(input()) print(int(a*(a+1)/2))
s943357395
p03720
u212328220
2,000
262,144
Wrong Answer
28
9,180
207
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n,m = map(int,input().split()) lst = [[] for i in range(n)] for _ in range(m): a,b = map(int,input().split()) lst[a-1].append(b-1) lst[b-1].append(a-1) print(lst) for v in lst: print(len(v))
s293523221
Accepted
27
8,972
196
n,m = map(int,input().split()) lst = [[] for i in range(n)] for _ in range(m): a,b = map(int,input().split()) lst[a-1].append(b-1) lst[b-1].append(a-1) for v in lst: print(len(v))
s121818227
p03079
u776864893
2,000
1,048,576
Wrong Answer
18
2,940
162
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
input_number = input().rstrip().split(' ') if (input_number[0] == input_number[1])and (input_number[1] == input_number[2]): print("YES") else: print("NO")
s671792914
Accepted
17
2,940
162
input_number = input().rstrip().split(' ') if (input_number[0] == input_number[1])and (input_number[1] == input_number[2]): print("Yes") else: print("No")
s573970260
p03555
u284854859
2,000
262,144
Wrong Answer
17
3,060
191
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.
# cook your dish here a=list(input()) b=list(input()) c = 0 if a[0] == b[2]: if a[1] == b[1]: if a[2] == b[0]: c = 1 if c == 0: print('No') else: print('Yes')
s624879364
Accepted
17
3,060
192
# cook your dish here a=list(input()) b=list(input()) c = 0 if a[0] == b[2]: if a[1] == b[1]: if a[2] == b[0]: c = 1 if c == 0: print('NO') else: print('YES')
s649272117
p03863
u657913472
2,000
262,144
Wrong Answer
18
3,316
66
There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s. The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
s=input() print('Second'if(len(s)%2==0)!=(s[1]==s[-1])else'First')
s440487973
Accepted
17
3,316
66
s=input() print('Second'if(len(s)%2==0)!=(s[0]==s[-1])else'First')
s573884006
p03993
u652656291
2,000
262,144
Wrong Answer
53
14,008
124
There are N rabbits, numbered 1 through N. The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i. For a pair of rabbits i and j (i<j), we call the pair (i,j) a _friendly pair_ if the following condition is met. * Rabbit i likes rabbit j and rabbit j likes rabbit i. Calculate the number of the friendly pairs.
n = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(n): if i == A[i]: ans += 1 print(ans//2)
s044442867
Accepted
74
13,880
135
n = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(n): if A[A[i]-1] == i+1: ans += 1 print(ans//2)
s406494906
p03449
u371686382
2,000
262,144
Wrong Answer
20
3,060
249
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
n = int(input()) fld = [list(map(int, input().split())) for _ in range(2)] score_max = 0 for i in range(n): score = fld[0][0] y = x = 0 for j in range(n): if j == i: y += 1 else: x += 1 score += fld[y][x] print(score)
s129299200
Accepted
20
3,064
289
n = int(input()) fld = [list(map(int, input().split())) for _ in range(2)] score_max = 0 for i in range(n): score = fld[0][0] y = x = 0 for j in range(n): if j == i: y += 1 else: x += 1 score += fld[y][x] score_max = max(score_max, score) print(score_max)
s998669969
p03360
u301302814
2,000
262,144
Wrong Answer
18
2,940
107
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?
# coding: utf-8 N = sorted(list(map(int, input().split()))) K = int(input()) print(N[0] + N[1] + N[2] ** K)
s167539388
Accepted
18
2,940
113
# coding: utf-8 N = sorted(list(map(int, input().split()))) K = int(input()) print(N[0] + N[1] + N[2] * (2 ** K))
s080145367
p03338
u780269042
2,000
1,048,576
Wrong Answer
18
3,060
226
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
ini = [input() for i in range(2) ] counts = [] count=0 for i in range(int(ini[0])): for k in ini[1][:i]: if k in ini[1][i:]: count+=1 print(count) counts.append(count) print(max(counts))
s307530345
Accepted
17
2,940
169
n = int(input()) s = list(input()) ans = 0 for i in range(n): left, right = s[:i], s[i:] cnt = len(set(left) & set(right)) ans = max(ans, cnt) print(ans)
s571380002
p03044
u780962115
2,000
1,048,576
Wrong Answer
17
2,940
8
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
print(3)
s136343884
Accepted
656
86,552
816
import sys sys.setrecursionlimit(100000) input=sys.stdin.readline n=int(input()) visitedlist=[-1 for i in range(n)] kilist=[[] for i in range(n)] anslist=[0 for i in range(n)] searchedlist=[-1 for i in range(n)] for i in range(n-1): a,b,c=map(int,input().split()) kilist[a-1].append((b,c)) kilist[b-1].append((a,c)) def search(i): searchedlist[i-1]=1 visitedlist[i-1]=1 flag=0 for j in kilist[i-1]: if visitedlist[j[0]-1]<0: visitedlist[j[0]-1]=1 flag+=1 anslist[j[0]-1]=anslist[i-1]+j[1] else: pass if flag>0: for k in kilist[i-1]: if searchedlist[k[0]-1]==-1: search(k[0]) search(2) for i in anslist: print(i%2)
s799496710
p03371
u330169562
2,000
262,144
Wrong Answer
35
5,176
726
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
import sys from math import ceil, floor, sqrt, sin, cos, pi from itertools import accumulate, permutations, combinations from fractions import gcd from collections import deque, Counter from operator import itemgetter from heapq import heappop,heappush sys.setrecursionlimit(10**7) def lcm(x, y): return ((x * y) // gcd(x, y)) # list(map(int, input().split())) # map(int, input().split()) # int(input()) # input().split() # mojiretu = ','.join(str_list) a, b, c, x , y = map(int, input().split()) ans = [] ans.append(a*x + b*y) ans.append(max(x, y)*c*2) ans.append(min(x, y)*c*2 + (abs(x - y) * a)) print(min(ans))
s262896298
Accepted
17
3,060
240
a, b, c, x , y = map(int, input().split()) ans = [] ans.append(a*x + b*y) ans.append(max(x, y)*c*2) p = a if x > y else b ans.append(min(x, y)*c*2 + (abs(x - y) * p)) print(min(ans))
s506310663
p02270
u613534067
1,000
131,072
Wrong Answer
20
5,600
350
In the first line, two integers $n$ and $k$ are given separated by a space character. In the following $n$ lines, $w_i$ are given respectively.
def cnt_car(w, p): car = 0 wi = 0 for i in w: if (wi + i) <= p: wi += i else: car += 1 wi = i return car n, k = map(int, input().split()) w = [int(input()) for i in range(n)] p = max(w) while True: if cnt_car(w, p) <= k: print(p) break else: p += 1
s500657163
Accepted
1,390
9,556
488
def cnt_car(w, p): car = 1 wi = 0 for i in w: if (wi + i) <= p: wi += i else: car += 1 wi = i return car n, k = map(int, input().split()) w = [int(input()) for i in range(n)] p = max(max(w), sum(w) // k) while True: if cnt_car(w, p) <= k: print(p) break else: if cnt_car(w, p + 100) > k: p += 100 else: p += 1
s121127956
p03568
u210718367
2,000
262,144
Wrong Answer
17
2,940
97
We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
n=int(input()) a=list(map(int,input().split())) ans=1 for k in a: if k&1: ans*=2 print(ans)
s649156372
Accepted
17
2,940
109
n=int(input()) a=list(map(int,input().split())) ans=1 for k in a: if k%2==0: ans*=2 print(pow(3,n)-ans)
s910640633
p03067
u684305751
2,000
1,048,576
Wrong Answer
19
3,316
75
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a,b,c = map(int, input().split()) print("YES" if a<c<b or b<c<a else "NO")
s135661044
Accepted
19
3,316
75
a,b,c = map(int, input().split()) print("Yes" if a<c<b or b<c<a else "No")
s783798126
p03455
u816070625
2,000
262,144
Wrong Answer
17
2,940
119
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
def resolve(): a,b=map(int,input().split()) if a*b%2==0: print ("Even") else: print ("Odd")
s888908519
Accepted
17
2,940
81
N,M=map(int,input().split()) if (N*M)%2==0: print("Even") else: print("Odd")
s513055614
p02606
u550416338
2,000
1,048,576
Wrong Answer
28
9,172
148
How many multiples of d are there among the integers between L and R (inclusive)?
num = list(map(int, input().split())) min_range = num[0] max_range = num[1] n = num[2] len([i for i in range(min_range, max_range+1) if i % n <= 0])
s941154372
Accepted
24
9,104
165
num = list(map(int, input().split())) min_range = num[0] max_range = num[1] n = num[2] ans = len([i for i in range(min_range, max_range+1) if i % n <= 0]) print(ans)
s231324180
p03400
u113255362
2,000
262,144
Wrong Answer
28
9,096
183
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
N=int(input()) D,X=map(int,input().split()) res = X List = [] for i in range (N): List.append(int(input())) for i in range(N): for i in range(1,D,List[i]): res += 1 print(res)
s022005336
Accepted
29
9,048
185
N=int(input()) D,X=map(int,input().split()) res = X List = [] for i in range (N): List.append(int(input())) for i in range(N): for i in range(1,D+1,List[i]): res += 1 print(res)
s635142710
p03679
u030726788
2,000
262,144
Wrong Answer
17
2,940
116
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b=map(int,input().split()) if(b<a): print("delicious") elif(b+a<x): print("safe") else: print("dangerous")
s514046307
Accepted
17
2,940
119
x,a,b=map(int,input().split()) if(b<=a): print("delicious") elif(b-a<=x): print("safe") else: print("dangerous")
s307239541
p03962
u170324846
2,000
262,144
Wrong Answer
17
2,940
34
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
S = input().split() print(set(S))
s143722591
Accepted
17
2,940
39
S = input().split() print(len(set(S)))
s589640376
p03524
u212328220
2,000
262,144
Wrong Answer
18
3,188
192
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 itertools S = input() n_a = S.count('a') n_b = S.count('b') n_c = len(S) - (n_a + n_b) if n_a >= len(S)/2 or n_b >= len(S)/2 or n_c >= len(S)/2: print('NO') else: print('YES')
s518641018
Accepted
19
3,188
285
S = input() Slst = [S.count('a'), S.count('b'), S.count('c')] Slst.sort(reverse=True) x = (len(S)-1) // 3 y = (len(S)-1) % 3 if y == 0: lst = [x+1, x, x] elif y == 1: lst = [x + 1, x+1, x] else: lst = [x+1, x+1, x+1] if lst == Slst: print('YES') else: print('NO')
s054140555
p04012
u247465867
2,000
262,144
Wrong Answer
18
2,940
144
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
#2019/10/24 S = list(open(0).read()) set_S = list(set(S)) beautiful = [S.count(i)%2 for i in set_S] print('Yes' if sum(beautiful)==0 else 'No')
s172955306
Accepted
17
3,064
175
#2019/10/24 # S = list(open(0).read()) S = list(input()) # print(S) set_S = list(set(S)) beautiful = [S.count(i)%2 for i in set_S] print('Yes' if sum(beautiful)==0 else 'No')
s400553078
p03524
u296518383
2,000
262,144
Wrong Answer
51
3,188
206
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
S=input() a,b,c=0,0,0 for i in range(len(S)): if S[i]=="a": a+=1 if S[i]=="b": b+=1 if S[i]=="c": c+=1 m=min(a,b,c) a,b,c=a-m,b-m,c-m #print(a,b,c) print("Yes" if max(a,b,c)<=1 else "No")
s438627103
Accepted
50
3,188
206
S=input() a,b,c=0,0,0 for i in range(len(S)): if S[i]=="a": a+=1 if S[i]=="b": b+=1 if S[i]=="c": c+=1 m=min(a,b,c) a,b,c=a-m,b-m,c-m #print(a,b,c) print("YES" if max(a,b,c)<=1 else "NO")
s384907231
p02390
u203261375
1,000
131,072
Wrong Answer
20
7,592
110
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
s = int(input()) h = s // 3600 m = s % 3600 m = m // 60 s = m % 60 print(str(h) + ":" + str(m) + ":" + str(s))
s640209196
Accepted
20
7,652
126
s = int(input()) h = s // 3600 m = (s - h * 3600) // 60 s = s - h * 3600 - m * 60 print(str(h) + ":" + str(m) + ":" + str(s))
s351340638
p03434
u068142202
2,000
262,144
Wrong Answer
20
9,028
176
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = int(input()) a = list(map(int, input().split())) a.sort() Alice = 0 Bob = 0 for i in range(n): if i % 2 == 0: Alice += a[i] else: Bob += a[i] print(Alice - Bob)
s712423504
Accepted
23
9,188
190
n = int(input()) a = list(map(int, input().split())) a.sort(reverse = True) Alice = 0 Bob = 0 for i in range(n): if i % 2 == 0: Alice += a[i] else: Bob += a[i] print(Alice - Bob)
s859156229
p02844
u164678731
2,000
1,048,576
Wrong Answer
25
3,572
454
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
# coding: utf-8 n = int(input()) s = input() ans = 0 for i in range(1000): tmp = str('{:03}'.format(i)) s0 = s.find(tmp[0]) if s0 == -1: continue else: s1 = s.find(tmp[1], s0 + 1) if s1 == -1: continue else: s2 = s.find(tmp[2], s1 + 1) if s2 == -1: continue else: print(i, tmp,s0, s1, s2) ans += 1 print(ans)
s949595230
Accepted
20
3,060
413
# coding: utf-8 n = int(input()) s = input() ans = 0 for i in range(1000): tmp = str('{:03}'.format(i)) s0 = s.find(tmp[0]) if s0 == -1: continue else: s1 = s.find(tmp[1], s0 + 1) if s1 == -1: continue else: s2 = s.find(tmp[2], s1 + 1) if s2 == -1: continue else: ans += 1 print(ans)
s374863688
p03485
u869154953
2,000
262,144
Wrong Answer
21
9,112
67
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
import math a,b=map(int,input().split()) print(math.ceil((a+b/2)))
s761518385
Accepted
28
9,052
69
import math a,b=map(int,input().split()) print(math.ceil((a+b)/2))
s488405993
p02389
u179070318
1,000
131,072
Wrong Answer
20
5,592
61
Write a program which calculates the area and perimeter of a given rectangle.
a,b = [int(x) for x in input().split( )] print(2*(a+b),a*b)
s011228649
Accepted
30
5,596
61
a,b = [int(x) for x in input().split( )] print(a*b,2*(a+b))
s829850901
p02402
u072855832
1,000
131,072
Wrong Answer
20
5,584
167
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
size = input() list = list(map(int, input().split())) list_min = min(list) list_max = max(list) list_sum = sum(list) print(list_min) print(list_max) print(list_sum)
s091051943
Accepted
20
6,544
164
size = input() list = list(map(int, input().split())) list_min = min(list) list_max = max(list) list_sum = sum(list) print(list_min, list_max, list_sum,sep=' ')
s183914435
p03997
u266171694
2,000
262,144
Wrong Answer
17
2,940
74
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)
s057097137
Accepted
17
3,064
79
a = int(input()) b = int(input()) h = int(input()) print(int((a + b) * h / 2))
s073251298
p03861
u717001163
2,000
262,144
Wrong Answer
17
2,940
105
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?
import math a,b,c=map(int,input().split()) print(math.floor((b-a)/c) if a !=0 else math.floor((b-a)/c)+1)
s553342510
Accepted
18
2,940
79
a, b, c = map(int, input().split()) print(b//c - (a-1)//c if a !=0 else b//c+1)
s861731008
p03434
u398511319
2,000
262,144
Wrong Answer
29
9,192
304
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
import math N=int(input()) a=list(map(int,input().split())) a=sorted(a) print(a) alice=0 bob=0 if(N%2==0): for i in range(0,N-1,2): alice=a[i+1]+alice bob=a[i]+bob else: for i in range(1,N-1,2): alice=a[i+1]+alice bob=a[i]+bob alice=alice+a[0] print(alice-bob)
s565024392
Accepted
26
9,080
295
import math N=int(input()) a=list(map(int,input().split())) a=sorted(a) alice=0 bob=0 if(N%2==0): for i in range(0,N-1,2): alice=a[i+1]+alice bob=a[i]+bob else: for i in range(1,N-1,2): alice=a[i+1]+alice bob=a[i]+bob alice=alice+a[0] print(alice-bob)
s298550978
p03694
u477343425
2,000
262,144
Wrong Answer
17
2,940
58
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along _TopCoDeer street_. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.
l = sorted(map(int, input().split())) print(l[-1] - l[0])
s745301632
Accepted
17
2,940
76
n = int(input()) a = sorted(map(int, input().split())) print(a[-1] - a[0])
s346484570
p03729
u346193734
2,000
262,144
Wrong Answer
18
2,940
101
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a, b, c = input().split() if a[0] == b[-1] and b[0] == c[-1]: print("YES") else: print("NO")
s348594748
Accepted
18
2,940
101
a, b, c = input().split() if a[-1] == b[0] and b[-1] == c[0]: print("YES") else: print("NO")
s744714157
p03433
u297103202
2,000
262,144
Wrong Answer
17
2,940
168
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) a = [] for i in range(1): a.append(int(input())) calc = N - a[0] if a[0]>N: print('Yes') else: print('Yes' if calc % 500 == 0 else 'No')
s270789116
Accepted
17
2,940
74
N = int(input()) a = int(input()) print('Yes' if N % 500 <= a else 'No')
s875976024
p02397
u638889288
1,000
131,072
Wrong Answer
20
5,596
113
Write a program which reads two integers x and y, and prints them in ascending order.
x,y = map(int,input().split()) if x!=0 and y!=0: if x > y : print(y,x) else: print(x,y)
s544289100
Accepted
50
5,612
170
while True: x,y=map(int,input().split()) if x==0 and y==0: break if x > y : x,y=y,x print(x,y) else : print(x,y)
s842197221
p03415
u227170240
2,000
262,144
Wrong Answer
17
2,940
62
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
a = input() b = input() c = input() print(a[0] + b[1] + c[1])
s458060829
Accepted
17
2,940
61
a = input() b = input() c = input() print(a[0] + b[1] + c[2])
s416621102
p03110
u482770395
2,000
1,048,576
Wrong Answer
17
2,940
180
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
N = int(input()) total = 0 for i in range(N): x, u = input().split() if u == "JPY": total += int(x) else: total += float(x) * 380000.0 print(int(total))
s372847261
Accepted
17
2,940
178
N = int(input()) total = 0 for i in range(N): x, u = input().split() if u == "JPY": total += float(x) else: total += float(x) * 380000.0 print(total)
s168121787
p03377
u800258529
2,000
262,144
Wrong Answer
17
2,940
63
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x=map(int,input().split()) print('YNeos'[x<a or a+b<x::2])
s745796184
Accepted
17
2,940
63
a,b,x=map(int,input().split()) print('YNEOS'[x<a or a+b<x::2])
s425489466
p03565
u020962106
2,000
262,144
Wrong Answer
17
3,064
387
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
S = input() T = input() ls = len(S) lt = len(T) for i in range(ls-lt+1): if S[i]=='?' or S[i]==T[0]: c = 0 for j in range(i+1,i+lt): c+=1 if S[j]!='?' and S[j]!=T[c]: break else: S = S[:i]+T+S[i+lt:] print(S) if T not in S: print('UNRESTORABLE') else: S2=S.replace('?','a') print(S2)
s452351591
Accepted
18
3,060
292
s = input() t = input() ss = [] for i in range(len(s)-len(t)+1): for j in range(len(t)): if s[i+j] not in ('?', t[j]): break else: S = s[:i] + t + s[i+len(t):] ss.append(S.replace('?', 'a')) if ss: print(min(ss)) else: print("UNRESTORABLE")
s658433956
p03067
u377415042
2,000
1,048,576
Wrong Answer
17
2,940
145
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
def main(): A, B, C = map(int, input().split()) if A < C < B or B < C < A: print('yes') else: print('no') main()
s884433363
Accepted
20
2,940
145
def main(): A, B, C = map(int, input().split()) if A < C < B or B < C < A: print('Yes') else: print('No') main()
s597449398
p04012
u197237612
2,000
262,144
Wrong Answer
25
8,856
152
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
s = sorted(list(input())) for i in range(97, 97 + 26): print(s.count(chr(i))) if s.count(chr(i)) %2 != 0: print('NO') exit() print('YES')
s611634609
Accepted
30
9,112
126
s = sorted(list(input())) for i in range(97, 97 + 26): if s.count(chr(i)) %2 != 0: print('No') exit() print('Yes')
s781801592
p02796
u006883624
2,000
1,048,576
Wrong Answer
486
16,996
565
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
N = int(input()) robots = [] for i in range(N): x, l = [int(v) for v in input().split()] robots.append((x - l, x + l)) robots.sort() def check(robot): for i in range(1, N): if robot[i-1][1] > robot[i][0]: return False return True def opt(robots): count = 0 i = 1 robot1 = robots[0] while i < len(robots): robot2 = robots[i] if robot1[1] > robot2[0]: if robot1[1] < robot2[1]: robot2 = robot1 count += 1 else: count += 1 robot1 = robot2 i += 1 return count print(opt(robots))
s259453692
Accepted
496
16,928
482
N = int(input()) robots = [] for i in range(N): x, l = [int(v) for v in input().split()] robots.append((x - l, x + l)) robots.sort() def opt(robots): l = len(robots) count = 0 i = 1 robot1 = robots[0] while i < l: robot2 = robots[i] if robot1[1] > robot2[0]: if robot1[1] < robot2[1]: robot2 = robot1 count += 1 robot1 = robot2 i += 1 return l - count print(opt(robots))
s891409837
p03545
u494037809
2,000
262,144
Wrong Answer
17
3,064
572
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
s_list = str(input()) A, B, C, D = [int(s) for s in s_list ] for x in range(2): if x==0: X = A + B px = '+' else: X = A - B px = '-' for y in range(2): if y==0: Y = X + C py = '+' else: Y = X - C py = '-' for z in range(2): if z==0: Z = Y + D pz = '+' else: Z = Y - D pz = '-' if Z==7: print(A, px, B, py, C, pz, D, sep='')
s503641957
Accepted
18
3,064
601
s_list = str(input()) A, B, C, D = [int(s) for s in s_list ] for x in range(2): if x==0: X = A + B px = '+' else: X = A - B px = '-' for y in range(2): if y==0: Y = X + C py = '+' else: Y = X - C py = '-' for z in range(2): if z==0: Z = Y + D pz = '+' else: Z = Y - D pz = '-' if Z==7: print(A, px, B, py, C, pz, D, '=7', sep='') exit()
s361015501
p02843
u371409687
2,000
1,048,576
Wrong Answer
44
9,612
379
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
n=int(input()) dp=['No']*(10**5+1) dp[101]='Yes' dp[102]='Yes' dp[103]='Yes' dp[104]='Yes' dp[105]='Yes' for i in range(106,10**5+1): if dp[i-101]=='Yes': dp[i]='Yes' elif dp[i-102]=='Yes': dp[i]='Yes' elif dp[i-103]=='Yes': dp[i]='Yes' elif dp[i-104]=='Yes': dp[i]='Yes' elif dp[i-105]=='Yes': dp[i]='Yes' print(dp[n])
s341007894
Accepted
46
9,624
365
n=int(input()) dp=[0]*(10**5+1) dp[100]=1 dp[101]=1 dp[102]=1 dp[103]=1 dp[104]=1 dp[105]=1 for i in range(106,10**5+1): if dp[i-100]==1: dp[i]=1 elif dp[i-101]==1: dp[i]=1 elif dp[i-102]==1: dp[i]=1 elif dp[i-103]==1: dp[i]=1 elif dp[i-104]==1: dp[i]=1 elif dp[i-105]==1: dp[i]=1 print(dp[n])
s489617233
p02665
u663438907
2,000
1,048,576
Wrong Answer
134
20,140
488
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
import sys N = int(input()) A = list(map(int, input().split())) l = [] if A[0] != 0: print(-1) sys.exit() for i in range(N): if A[i] > A[i+1]+1: print(-1) sys.exit() temp = 1 for i in range(N+1): l.append(temp-A[i]) temp = (temp-A[i])*2 ans = 1 node = 0 for i in range(N, 0, -1): if l[i-1] >= node + A[i]: node += A[i] ans += node else: ans += node + A[i] node = l[i-1] print(l) print(A) print(ans)
s688902642
Accepted
986
668,980
478
import sys N = int(input()) A = list(map(int, input().split())) l = [] if N == 0: if A[0] != 1: print(-1) exit() temp = 1 for i in range(N+1): l.append(temp-A[i]) temp = (temp-A[i])*2 for i in range(N+1): if l[i] < 0: print(-1) sys.exit() ans = 1 node = 0 for i in range(N, 0, -1): if l[i-1] >= node + A[i]: node += A[i] ans += node else: ans += node + A[i] node = l[i-1] print(ans)
s197672778
p02620
u732870425
2,000
1,048,576
Wrong Answer
2,206
22,532
732
"Local search" is a powerful method for finding a high-quality solution. In this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution. If the solution gets better, update it, and if it gets worse, restore it. By repeating this process, the quality of the solution is gradually improved over time. The pseudo-code is as follows. solution = compute an initial solution (by random generation, or by applying other methods such as greedy) while the remaining time > 0: slightly modify the solution (randomly) if the solution gets worse: restore the solution For example, in this problem, we can use the following modification: pick the date d and contest type q at random and change the type of contest to be held on day d to q. The pseudo-code is as follows. t[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy) while the remaining time > 0: pick d and q at random old = t[d] # Remember the original value so that we can restore it later t[d] = q if the solution gets worse: t[d] = old The most important thing when using the local search method is the design of how to modify solutions. 1. If the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small. 2. In order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification. In this problem C, we focus on the second point. The score after the modification can, of course, be obtained by calculating the score from scratch. However, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification. From another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation. In such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search. Let's implement fast incremental score computation. It's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC! In this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug. For early detection of bugs, it is a good idea to unit test functions you implemented complicated routines. For example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.
D = int(input())#D=365 c = list(map(int, input().split()))#0<=c<=100 s = [list(map(int, input().split())) for _ in range(D)]#0<=s<=20000 t = [int(input()) for _ in range(D)] M = int(input()) dq = [list(map(int, input().split())) for _ in range(M)] def t2v(t): v = [] last = [0] * 26 value = 0 for d in range(D): type = t[d] value += s[d][type - 1] last[type - 1] = d + 1 for i in range(26): value -= c[i] * (d + 1 - last[i]) v.append(value) return v v_lastday = [] v = t2v(t) v_lastday.append(v[-1]) for d, q in dq: t[d - 1] = q v = t2v(t) v_lastday.append(v[-1]) for x in v_lastday: print(x)
s863063887
Accepted
563
26,064
1,678
D = int(input())#D=365 c = [0] + list(map(int, input().split()))#0<=c<=100 s = [0] + [[0] + list(map(int, input().split())) for _ in range(D)]#0<=s<=20000 t = [0] + [int(input()) for _ in range(D)] M = int(input()) dq = [list(map(int, input().split())) for _ in range(M)] held = [[0] for _ in range(27)] def culc_value(t): last = [0] * 27 value = 0 for d in range(1, D+1): type = t[d] held[type].append(d) value += s[d][type] last[type] = d for i in range(1, 27): value -= c[i] * (d - last[i]) for i in range(1, 27): held[i].append(D+1) #print(held) return value v_lastday = [] value = culc_value(t) for d, q in dq: value += - s[d][t[d]] + s[d][q] ind = held[t[d]].index(d) r = held[t[d]][ind+1] l = held[t[d]][ind-1] x = r - l value -= ((x + 1) * x // 2) * c[t[d]] y = d - l z = r - d value += (((y + 1) * y // 2) + (z + 1) * z // 2) * c[t[d]] del held[t[d]][ind] t[d] = q held[q].append(d) held[q] = sorted(held[q]) #print(held[q]) ind = held[q].index(d) r = held[q][ind+1] l = held[q][ind-1] x = r - l value += ((x + 1) * x // 2) * c[q] y = d - l z = r - d value -= (((y + 1) * y // 2) + (z + 1) * z // 2) * c[q] v_lastday.append(value) for ans in v_lastday: print(ans)
s055748501
p03612
u474423089
2,000
262,144
Wrong Answer
79
14,008
231
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
n = int(input()) a = list(map(int,input().split(' '))) ans = 0 tmp = 0 for i in range(n): if i+1 == a[i]: tmp += 0.5 elif tmp: ans += tmp//2 + 1 tmp = 0 if tmp: ans += int(tmp//2) + 1 print(ans)
s495709494
Accepted
115
14,008
369
n = int(input()) a = list(map(int,input().split(' '))) ans = 0 for i in range(n): if i ==0 and a[0]==1: a[0],a[1] = a[1],a[0] ans += 1 continue if i<n-1 and i+1 == a[i] and i+2 ==a[i+1]: a[i],a[i+1] = a[i+1],a[i] ans += 1 if i+1 ==a[i] and i+1 != a[i-1]: a[i-1],a[i] = a[i],a[i-1] ans += 1 print(ans)
s356961411
p04011
u399721252
2,000
262,144
Wrong Answer
22
3,316
86
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
a = int(input()) b = int(input()) x = int(input()) y = int(input()) print(x*(a-b)+y*b)
s219351363
Accepted
17
2,940
121
n = int(input()) k = int(input()) x = int(input()) y = int(input()) if n <= k: print(x*n) else: print(x*k+y*(n-k))
s595021900
p03695
u614314290
2,000
262,144
Wrong Answer
17
3,060
228
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
N = int(input()) A = list(map(int, input().split())) l = {} for a in A: k = a // 400 k = min(k, 8) if k not in l: l[k] = 1 else: l[k] += 1 #print(l) print(max(1, len(l) - 1), max(1, len(l) - 1 + l[8] if 8 in l else 0))
s077618608
Accepted
17
3,060
252
N = int(input()) A = list(map(int, input().split())) l = {} for a in A: k = a // 400 k = min(k, 8) if k not in l: l[k] = 1 else: l[k] += 1 #print(l) if 8 in l: print(max(1, len(l) - 1), max(1, len(l) - 1 + l[8])) else: print(len(l), len(l))
s697428847
p03502
u634208461
2,000
262,144
Wrong Answer
17
2,940
125
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N = input() n = 0 for a in N: n += int(ord(a) - ord('1') + 1) if int(N) % n == 0: print('YES') else: print('NO')
s666420190
Accepted
17
2,940
124
N = input() n = 0 for a in N: n += int(ord(a) - ord('1') + 1) if int(N) % n == 0: print('Yes') else: print('No')
s489609933
p04043
u161857931
2,000
262,144
Wrong Answer
17
3,064
280
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a, b, c = map(int, input().split()) at = 0 bt = 0 ct = 0 if a == 5 : at += 1 elif a == 7 : at += 10 if b == 5 : bt += 1 elif b == 7 : bt += 10 if c == 5 : ct += 1 elif c == 7 : ct += 10 if at + bt + ct == 21 : print("YES") else : print("NO")
s836354155
Accepted
17
3,064
279
a, b, c = map(int,input().split()) at = 0 bt = 0 ct = 0 if a == 5 : at += 1 elif a == 7 : at += 10 if b == 5 : bt += 1 elif b == 7 : bt += 10 if c == 5 : ct += 1 elif c == 7 : ct += 10 if at + bt + ct == 12 : print("YES") else : print("NO")
s783004094
p03494
u245641078
2,000
262,144
Wrong Answer
28
9,076
129
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())) count=0 while all(i%2==0 for i in A): A = [i/2 for i in A] count+=1 print(count)
s132703645
Accepted
30
9,232
131
input() A = list(map(int,input().split())) count=0 while all(i%2==0 for i in A): A = [i/2 for i in A] count+=1 print(count)
s410383238
p03599
u846150137
3,000
262,144
Wrong Answer
1,261
3,064
647
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
a,b,c,d,e,f=[int(i) for i in input().split(' ')] a=a*100 b=b*100 am = f//a bm = f//b cm = int((f/((100+e)/e))//c) dm = int((f/((100+e)/e))//d) print(a,b,c,d,am,bm,cm,dm) yl=0 yn=0 ys=0 for i_a in range(am): la=i_a*a for i_b in range(bm): lb=i_b*b if 0<la+lb<=f: for i_c in range(cm): lc=i_c*c if 0<la+lb+lc<=f: for i_d in range(dm): ld=i_d*d if 0<la+lb+lc+ld<=f: if (lc+ld)/(la+lb+lc+ld) <= e/(100+e): n=(lc+ld)/(la+lb+lc+ld) if n > yn: yn=n yl=la+lb+lc+ld ys=lc+ld print(yl,ys)
s984863423
Accepted
1,387
3,064
629
a,b,c,d,e,f=[int(i) for i in input().split(' ')] a=a*100 b=b*100 am = f//a bm = f//b cm = int((f/((100+e)/e))//c) dm = int((f/((100+e)/e))//d) yl=0 yn=0 ys=0 for i_a in range(am+1): la=i_a*a for i_b in range(bm+1): lb=i_b*b if 0<la+lb<=f: for i_c in range(cm+1): lc=i_c*c if 0<la+lb+lc<=f: for i_d in range(dm+1): ld=i_d*d if 0<la+lb+lc+ld<=f: if (lc+ld)/(la+lb+lc+ld) <= e/(100+e): n=(lc+ld)/(la+lb+lc+ld) if n >= yn: yn=n yl=la+lb+lc+ld ys=lc+ld print(yl,ys)
s261160973
p02398
u017435045
1,000
131,072
Wrong Answer
20
5,588
104
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
a,b,c=map(int, input().split()) k=0 for j in range(a,b): if c%j==0: k+=1 print(j)
s447268014
Accepted
20
5,596
107
a,b,c=map(int, input().split()) k=0 for j in range(a,b+1): if c%j==0: k+=1 print(k)
s776599150
p04043
u848678027
2,000
262,144
Wrong Answer
18
3,060
252
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.
from sys import stdin input1=stdin.readline().rstrip().split() N=int(input1[0]) L=int(input1[1]) input=[] for n in range(N): input.append(stdin.readline().rstrip()) input.sort() output="" for i in range(len(input)): output+=input[i] print(output)
s548492128
Accepted
17
2,940
198
from sys import stdin input=stdin.readline().rstrip().split() for i in range(len(input)): input[i]=int(input[i]) if input.count(5)==2: if input.count(7)==1: print("YES") else: print("NO")
s702109382
p03338
u883792993
2,000
1,048,576
Wrong Answer
18
3,060
218
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
N=int(input()) S=input() count_max=0 for i in range(1,N): X=S[:i] Y=S[i:] count=0 for character in X: if character in Y: count+=1 count_max=max(count, count_max) print(count_max)
s045534153
Accepted
19
3,064
366
N=int(input()) S=input() count_max=0 for i in range(1,N): X=S[:i] Y=S[i:] count=0 character_in_X=[] for character in X: if character not in character_in_X: character_in_X.append(character) for character in character_in_X: if character in Y: count+=1 count_max=max(count, count_max) print(count_max)
s190399422
p03679
u131406572
2,000
262,144
Wrong Answer
18
2,940
121
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b=map(int,input().split()) if b-a>=0: print("delicious") elif -x<=b-a<0: print("safe") else: print("dangerous")
s908925262
Accepted
17
2,940
121
x,a,b=map(int,input().split()) if a-b>=0: print("delicious") elif -x<=a-b<0: print("safe") else: print("dangerous")
s714766725
p03854
u433515605
2,000
262,144
Wrong Answer
83
3,316
411
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
s = input() s_rev = s[::-1] T_list = ['maerd', 'remaerd', 'esare', 'resare'] def mojicut(s, r): n = s.replace(r, "", 1) return n while len(s_rev) > 0: s_len = len(s_rev) for i in T_list: if s_rev.startswith(i): s_rev = mojicut(s_rev, i) break if len(s_rev) == s_len: break if len(s_rev) > 0: print("No") else: print("Yes")
s899296833
Accepted
86
3,316
398
s = input() s_rev = s[::-1] T_list = ['maerd', 'remaerd', 'esare', 'resare'] def mojicut(s, r): n = s.replace(r, "", 1) return n while len(s_rev) > 0: s_len = len(s_rev) for i in T_list: if s_rev.startswith(i): s_rev = mojicut(s_rev, i) break if len(s_rev) == s_len: break if len(s_rev) > 0: print("NO") else: print("YES")
s398948307
p03394
u181037878
2,000
262,144
Wrong Answer
25
5,220
1,933
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
def ans(N): ret = [] cnt = 0 if N % 2 == 0: summand = 6 while summand <= 30000 - 6: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 3 while summand <= 30000 - 6: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 2 while summand <= 30000 - 2: ret.append(summand) cnt += 1 summand += 2 ret.append(summand) cnt += 1 summand += 4 if cnt == N: return " ".join(list(map(str, ret))) else: ret = [2, 4, 8] cnt = 3 if N == 3: return " ".join(list(map(str, ret))) summand = 6 while summand < 30000: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 3 while summand < 30000: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 10 while summand < 30000: ret.append(summand) cnt += 1 summand += 4 ret.append(summand) cnt += 1 summand += 2 if cnt == N: return " ".join(list(map(str, ret))) N = int(input()) print(ans(N))
s371645540
Accepted
25
5,264
4,615
def ans(N): if N % 2 == 0: if N == 4: return "2 4 3 9" ret = [2, 4, 3, 9] cnt = 4 summand = 6 while summand <= 30000 - 6: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) if summand > 30000: return "over 30000" cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 15 while summand <= 30000 - 6: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) if summand > 30000: return "over 30000" cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 8 while summand <= 30000 - 2: ret.append(summand) cnt += 1 summand += 2 ret.append(summand) if summand > 30000: return "over 30000" cnt += 1 summand += 4 if cnt == N: return " ".join(list(map(str, ret))) else: if N == 19999: if N == 3: return "2 5 63" ret = [2, 8, 14] cnt = 3 summand = 3 while summand < 30000: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) # if summand > 30000: # return "over 30000" cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 12 while summand <= 30000 - 6: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) # if summand > 30000: # return "over 30000" cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) ret.append(30000) cnt += 1 summand = 20 while summand < 30000: ret.append(summand) cnt += 1 summand += 2 ret.append(summand) # if summand > 30000: # return "over 30000" cnt += 1 summand += 4 if cnt == N: return " ".join(list(map(str, ret))) ret.append(4) cnt += 1 if cnt == N: return " ".join(list(map(str, ret))) ret.append(10) cnt += 1 if cnt == N: return " ".join(list(map(str, ret))) ret.append(16) cnt += 1 if cnt == N: return " ".join(list(map(str, ret))) if N == 3: return "2 5 63" ret = [2, 8, 14] cnt = 3 summand = 3 while summand < 30000: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) # if summand > 30000: # return "over 30000" cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 6 while summand < 30000: ret.append(summand) cnt += 1 summand += 6 ret.append(summand) # if summand > 30000: # return "over 30000" cnt += 1 summand += 6 if cnt == N: return " ".join(list(map(str, ret))) summand = 20 while summand < 30000: ret.append(summand) cnt += 1 summand += 2 ret.append(summand) # if summand > 30000: # return "over 30000" cnt += 1 summand += 4 if cnt == N: return " ".join(list(map(str, ret))) ret.append(4) cnt += 1 if cnt == N: return " ".join(list(map(str, ret))) ret.append(10) cnt += 1 if cnt == N: return " ".join(list(map(str, ret))) ret.append(16) cnt += 1 if cnt == N: return " ".join(list(map(str, ret))) ret.remove(6) cnt += 1 if cnt == N: return " ".join(list(map(str, ret))) N = int(input()) print(ans(N))