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
s373614454
p03844
u119714109
2,000
262,144
Wrong Answer
21
3,064
304
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her.
# coding=utf-8 import sys stdin = sys.stdin def na(): return map(int, stdin.readline().split()) def ns(): return stdin.readline().strip() def main(): a,op,b = stdin.readline().split() if op == '+': print(a+b) else: print(a-b) pass if __name__ == '__main__': main()
s169466330
Accepted
24
3,188
332
# coding=utf-8 import sys stdin = sys.stdin def na(): return map(int, stdin.readline().split()) def ns(): return stdin.readline().strip() def main(): a,op,b = stdin.readline().strip().split() if op == '+': print(int(a)+int(b)) else: print(int(a)-int(b)) pass if __name__ == '__main__': main()
s234039130
p03658
u757274384
2,000
262,144
Wrong Answer
17
3,060
147
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
n,k = map(int, input().split()) L = list(map(int, input().split())) L.sort() L.reverse() ans = 0 for i in range(0,n): ans += L[i] print(ans)
s464934926
Accepted
17
2,940
148
n,k = map(int, input().split()) L = list(map(int, input().split())) L.sort() L.reverse() ans = 0 for i in range(0,k): ans += L[i] print(ans)
s928255316
p03477
u717993780
2,000
262,144
Wrong Answer
17
3,060
120
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d = map(int,input().split()) if a+b<c+d: print("Right") elif a+b>c+d: print("Light") else: print("Balanced")
s403548589
Accepted
17
2,940
119
a,b,c,d = map(int,input().split()) if a+b<c+d: print("Right") elif a+b>c+d: print("Left") else: print("Balanced")
s481299934
p00006
u747479790
1,000
131,072
Wrong Answer
20
7,464
36
Write a program which reverses a given string str.
a=list(input()) a.reverse() print(a)
s126139349
Accepted
30
7,336
20
print(input()[::-1])
s544397731
p00010
u572790226
1,000
131,072
Wrong Answer
30
7,956
1,210
Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface.
from math import sqrt def circle(x1, y1, x2, y2, x3, y3): if x1 == 0: dx = 1 x1 = x1 + dx x2 = x2 + dx x3 = x3 + dx else: dx = 0 if y2 == 0: dy = 1 y1 = y1 + dy y2 = y2 + dy y3 = y3 + dy else: dy = 0 A = [[x1, y1, 1, 1, 0, 0],[x2, y2, 1, 0, 1, 0],[x3, y3, 1, 0, 0, 1]] # print(A) for i in range(3): A[0] = [x/A[0][0] for x in A[0]] A[1] = [A[1][j] - A[1][0] * A[0][j] for j in range(6)] A[2] = [A[2][j] - A[2][0] * A[0][j] for j in range(6)] # print(A) for j in range(3): A[j] = A[j][1:] + A[j][:1] A = A[1:] + A[:1] # print(A) for i in range(3): A[i] = A[i][:3] # print(A) V = [-x1**2-y1**2, -x2**2-y2**2, -x3**2-y3**2] M = [(A[i][0] * V[0] + A[i][1] * V[1] + A[i][2] * V[2]) for i in range(3)] xcenter = -0.5 * M[0] - dx ycenter = -0.5 * M[1] - dy radius = sqrt((M[0]**2) /4 + (M[1]**2) /4 - M[2]) return xcenter, ycenter, radius n = int(input()) for line in range(n): x1, y1, x2, y2, x3, y3 = map(float, input().split()) xc, yc, ra = circle(x1, y1, x2, y2, x3, y3) print(xc, yc,ra)
s595740441
Accepted
30
7,820
1,232
from math import sqrt def circle(x1, y1, x2, y2, x3, y3): if x1 == 0: dx = 1 x1 = x1 + dx x2 = x2 + dx x3 = x3 + dx else: dx = 0 if y2 == 0: dy = 1 y1 = y1 + dy y2 = y2 + dy y3 = y3 + dy else: dy = 0 A = [[x1, y1, 1, 1, 0, 0],[x2, y2, 1, 0, 1, 0],[x3, y3, 1, 0, 0, 1]] # print(A) for i in range(3): A[0] = [x/A[0][0] for x in A[0]] A[1] = [A[1][j] - A[1][0] * A[0][j] for j in range(6)] A[2] = [A[2][j] - A[2][0] * A[0][j] for j in range(6)] # print(A) for j in range(3): A[j] = A[j][1:] + A[j][:1] A = A[1:] + A[:1] # print(A) for i in range(3): A[i] = A[i][:3] # print(A) V = [-x1**2-y1**2, -x2**2-y2**2, -x3**2-y3**2] M = [(A[i][0] * V[0] + A[i][1] * V[1] + A[i][2] * V[2]) for i in range(3)] xcenter = -0.5 * M[0] - dx ycenter = -0.5 * M[1] - dy radius = sqrt((M[0]**2) /4 + (M[1]**2) /4 - M[2]) return xcenter, ycenter, radius n = int(input()) for line in range(n): x1, y1, x2, y2, x3, y3 = map(float, input().split()) xc, yc, ra = circle(x1, y1, x2, y2, x3, y3) print('%.3f %.3f %.3f' % (xc, yc, ra))
s866997502
p03796
u319612498
2,000
262,144
Wrong Answer
33
2,940
106
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
n=int(input()) sum=0 for i in range(n): sum*=(i+1) if sum>10**9+7: sum%=10**9+7 print(sum)
s387824020
Accepted
48
2,940
107
n=int(input()) sum=1 for i in range(n): sum*=(i+1) if sum>10**9+7: sum%=10**9+7 print(sum)
s276565426
p03853
u672898046
2,000
262,144
Wrong Answer
24
3,956
247
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
h, w = map(int, input().split()) r = [list(input()) for i in range(h)] new_h = [0] * w new_r = [new_h for i in range(2*h)] for i in range(0, 2*h, 2): new_r[i] = r[(i+1)//2][:] new_r[i+1] = r[(i+1)//2][:] for i in new_r: print(*i, end="\n")
s660781155
Accepted
26
4,596
246
h, w = map(int, input().split()) r = [list(input()) for i in range(h)] new_h = [0] * w new_r = [new_h for i in range(2*h)] for i in range(0, 2*h, 2): new_r[i] = r[(i+1)//2] new_r[i+1] = r[(i+1)//2] for i in new_r: print(*i,sep="", end="\n")
s534831280
p03417
u882209234
2,000
262,144
Wrong Answer
19
2,940
139
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
N,M = sorted(map(int,input().split())) print(N,M) if N == 1: if M == 1: print(1) else: print(max(0,M-2)) else: print(N*M-2*N-2*M+4)
s517975333
Accepted
17
2,940
128
N,M = sorted(map(int,input().split())) if N == 1: if M == 1: print(1) else: print(max(0,M-2)) else: print(N*M-2*N-2*M+4)
s671947533
p02743
u022658079
2,000
1,048,576
Wrong Answer
17
2,940
82
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c=map(int, input().split()) if a^2+b^2<c^2: print("Yes") else: print("No")
s824584641
Accepted
17
2,940
99
a,b,c=map(int, input().split()) r=c-a-b if r > 0 and r**2>4*a*b: print("Yes") else: print("No")
s317793048
p03494
u909716307
2,000
262,144
Wrong Answer
28
9,112
183
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n=int(input()) l=list(map(int,input().split())) s=float('inf') for a in l: c=0 while 1: if a%2!=0: break a/=2 c+=1 s=min(s,c) print(c)
s092029167
Accepted
29
9,052
151
n=int(input()) l=list(map(int,input().split())) s=float('inf') for a in l: c=0 while a%2==0: c+=1 a/=2 s=min(s,c) print(s)
s582896660
p02386
u440180827
1,000
131,072
Wrong Answer
30
7,836
1,229
Write a program which reads $n$ dices constructed in the same way as [Dice I](description.jsp?id=ITP1_11_A), and determines whether they are all different. For the determination, use the same way as [Dice III](description.jsp?id=ITP1_11_C).
n = int(input()) x = [[] for i in range(n)] for i in range(n): x[i] = list(map(int, input().split())) z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]] def compare(x, y): succeed = False for i in range(6): match = True order = [0, 0, 0] for j in range(3): if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}: match = False break if x[j] == y[z[i][j]]: order[j] = 1 if x[j] == x[-j-1]: order[j] = 2 if match: if 2 in order: succeed = True break if (z[i][3] == 0 or z[i][3] == 3) and sum(order) % 2: succeed = True break if z[i][3] == 1 and not sum(order) % 2: succeed = True break if succeed: return True else: return False different = True for i in range(n): for j in range(i+1, n, 1): if compare(x[i], x[j]): print(i, j) different = False break if not different: break if different: print('Yes') else: print('No')
s386587662
Accepted
60
7,800
768
import sys def check(x, y): for i in range(6): order = [0, 0, 0] for j in range(3): k = a[i][j] if {x[j], x[-j-1]} != {y[k], y[-k-1]}: break if x[j] == y[k]: order[j] = 1 if x[j] == x[-j-1]: order[j] = 2 else: if 2 in order or (i < 3) == sum(order) % 2: return True return False a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]] n = int(sys.stdin.readline()) x = [sys.stdin.readline().split() for i in range(n)] for i in range(n): for j in range(i+1, n): if check(x[i], x[j]): break else: continue print('No') break else: print('Yes')
s808268256
p03719
u119982147
2,000
262,144
Wrong Answer
17
2,940
96
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()) if a <= c and b >= c: print("YES") else: print("NO")
s527279729
Accepted
18
2,940
96
a, b, c = map(int, input().split()) if a <= c and b >= c: print("Yes") else: print("No")
s280293101
p03957
u782654209
1,000
262,144
Wrong Answer
21
3,188
91
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtained from the string s by deleting some characters.
import re print('Yes') if len(re.compile(r'.+C.+F.+').findall(input()))>=1 else print('No')
s313117144
Accepted
20
3,188
91
import re print('Yes') if len(re.compile(r'.*C.*F.*').findall(input()))>=1 else print('No')
s935361205
p03636
u227254381
2,000
262,144
Wrong Answer
17
2,940
61
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
sent = input() print(sent[1] + str(len(sent) - 2) + sent[-1])
s756367532
Accepted
17
2,940
61
sent = input() print(sent[0] + str(len(sent) - 2) + sent[-1])
s234766055
p03024
u178192749
2,000
1,048,576
Wrong Answer
17
2,940
59
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() n = s.count('o') print('YES' if n>=8 else 'NO')
s476937049
Accepted
17
2,940
72
s = input() d = len(s) n = s.count('o') print('YES' if d-n<=7 else 'NO')
s295257335
p02393
u186524656
1,000
131,072
Wrong Answer
30
6,724
281
Write a program which reads three integers, and prints them in ascending order.
a, b, c = map(int, input().split()) if a < b and b < c and a < c: print(a, b, c) if a > b and a > c and b > c: print(c, b, a) if a > b and b < c and a < c: print(b, a, c) if a > b and a > c and b < c: print(b, c, a) if a < b and c < b and b > a: print(a, c, b)
s445495848
Accepted
30
6,724
60
print(' '.join(map(str, sorted(map(int, input().split())))))
s807362754
p03448
u252964975
2,000
262,144
Wrong Answer
18
3,064
218
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A=int(input()) B=int(input()) C=int(input()) X=int(input()) count = 0 for a in range(min([A,X//500])): for b in range(min([B,(X-500*A)//100])): if (X-500*A-100*B) % 50 == 0: count = count + 1 print(count)
s932314264
Accepted
18
3,064
427
A=int(input()) B=int(input()) C=int(input()) X=int(input()) count = 0 for a in range(min([A,X//500])+1): for b in range(min([B,(X-500*a)//100])+1): # print(a*500,b*100,X-500*a-100*b, (X-500*a-100*b)%50==0,(X-500*a-100*b)/50<=C) if (X-500*a-100*b) % 50 == 0 and (X-500*a-100*b) / 50 <= C: # print(a*500,b*100,X-500*a-100*b, (X-500*a-100*b)%50==0,(X-500*a-100*b)/50<=C) count = count + 1 print(count)
s036242058
p02396
u405758695
1,000
131,072
Wrong Answer
130
5,572
117
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
cnt=0 while(True): x=input() cnt+=1 if cnt>=10000 or x==0: break print('Case {}: {}'.format(cnt,x))
s920253458
Accepted
150
5,596
107
cnt=0 while True: x=int(input()) cnt+=1 if x==0: break print('Case {}: {}'.format(cnt,x))
s643417197
p03089
u893828545
2,000
1,048,576
Wrong Answer
150
12,432
384
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
import numpy as np import math def ordering(N,b): a=[] comb=math.factorial(N) x=[[]]*comb y=[[]]*comb for i in range(1,N): a=a+[i] for n,m in enumerate(a): x[n].insert(m-1,m) y[n].append(m) resnum=[x.index(i) for i in x if i==b] try: for i in y[resnum[0]]: print(i) except: return(-1)
s985361550
Accepted
18
3,060
237
N=int(input()) b=[int(i) for i in input().split()] a=[] try: while len(b)>0: a2=max([j for i,j in enumerate(b) if b[i]==i+1]) a.insert(0,a2) x=b.pop(a2-1) for n in a: print(n) except: print(-1)
s512534504
p04043
u293825440
2,000
262,144
Wrong Answer
17
3,064
434
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()) lis=[A,B,C] def hantei(list): if int(list[0]) == 7: if int(list[1]) == 5 and int(list[2]) == 5: return True if int(list[1]) == 7: if int(list[0]) == 5 and int(list[2]) == 5: return True if int(list[2]) == 7: if int(list[0]) == 5 and int(list[1]) == 5: return True if hantei(lis) == True: print("Yes") else: print("No")
s337927539
Accepted
17
3,064
434
A,B,C = map(int,input().split()) lis=[A,B,C] def hantei(list): if int(list[0]) == 7: if int(list[1]) == 5 and int(list[2]) == 5: return True if int(list[1]) == 7: if int(list[0]) == 5 and int(list[2]) == 5: return True if int(list[2]) == 7: if int(list[0]) == 5 and int(list[1]) == 5: return True if hantei(lis) == True: print("YES") else: print("NO")
s163735502
p03612
u142415823
2,000
262,144
Wrong Answer
42
14,004
293
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.
import sys def main(): N = int(sys.stdin.readline()) p = list(map(int, input().split())) count = 0 for i in p: if i == p: count += 1 if count % 2 == 0: print(count/2) else: print((count+1)/2) if __name__ == '__main__': main()
s338900471
Accepted
60
14,008
319
import sys def main(): N = int(sys.stdin.readline()) p = list(map(int, input().split())) count = 0 for i, n in enumerate(p, 1): if i == n: count += 1 if len(p) != i: p[i - 1], p[i] = p[i], p[i - 1] print(count) if __name__ == '__main__': main()
s466317900
p02612
u047816928
2,000
1,048,576
Wrong Answer
33
9,144
37
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+999)//1000)
s963576284
Accepted
29
9,152
50
N = int(input()) M = (N+999)//1000 print(M*1000-N)
s280536764
p02613
u619819312
2,000
1,048,576
Wrong Answer
141
9,116
121
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
c={"AC":0,"WA":0,"TLE":0,"RE":0} for i in range(int(input())): c[input()]+=1 for i,j in c.items(): print(i,"X",j)
s399889979
Accepted
139
9,184
121
c={"AC":0,"WA":0,"TLE":0,"RE":0} for i in range(int(input())): c[input()]+=1 for i,j in c.items(): print(i,"x",j)
s990703004
p02865
u350997995
2,000
1,048,576
Wrong Answer
17
2,940
34
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
N = int(input())-1 print(N//2-N%2)
s133392632
Accepted
17
2,940
30
N = int(input())-1 print(N//2)
s625362494
p02928
u455533363
2,000
1,048,576
Wrong Answer
2,104
3,188
507
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
n,k=map(int,input().split()) List=list(map(int,input().split())) li = [] for i in range(n): count=0 for j in range(n): if List[i]>List[j]: count += 1 li.append(count) print(str(sum(li))+"li") count2=0 for i in range(1,n): for j in range(i+1,n+1): #print(i,j) if int(List[i-1]) > int(List[j-1]): count2 += 1 #print(str(count2)+"count2") for m in range(k,0,-1): counted=count2+count2*(m) ans = counted % 1000000007 print(ans)
s968483968
Accepted
1,662
3,188
416
n,k=map(int,input().split()) List=list(map(int,input().split())) li = [] for i in range(n): count=0 for j in range(n): if List[i]>List[j]: count += 1 li.append(count) count2=0 for i in range(1,n): for j in range(i+1,n+1): if int(List[i-1]) > int(List[j-1]): count2 += 1 counted = k*count2 + (sum(li))*k*(k-1)//2 ans = counted % (10**9+7) print(int(ans))
s191216422
p03044
u451017206
2,000
1,048,576
Wrong Answer
423
4,976
753
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.
from collections import defaultdict N = int(input()) g = defaultdict(list) ans = [None] * N for i in range(N-1): u, v, w = map(int, input().split()) if w % 2 == 0: if ans[u-1] is None and ans[v-1] is None: ans[u-1] = ans[v-1] = 1 elif ans[u-1] is not None: ans[v-1] = ans[u-1] elif ans[v-1] is not None: ans[u-1] = ans[v-1] else: pass else: if ans[u-1] is None and ans[v-1] is None: ans[u-1] = 1 ans[v-1] = 0 elif ans[u-1] is not None: ans[v-1] = (ans[u-1] + 1) % 2 elif ans[v-1] is not None: ans[u-1] = (ans[v-1] + 1) % 2 else: pass for a in ans: print(a)
s641028944
Accepted
849
102,552
508
from sys import setrecursionlimit, getrecursionlimit setrecursionlimit(getrecursionlimit()*10000) from collections import defaultdict g = defaultdict(list) visited = defaultdict(bool) N = int(input()) ans = [0] * N def dfs(v, d=0): if visited[v]: return visited[v] = True if d % 2: ans[v-1] = 1 for c,w in g[v]: dfs(c, d+w) for j in range(N-1): u,v,w = map(int, input().split()) g[u].append((v, w)) g[v].append((u, w)) dfs(1) for a in ans: print(a)
s920429779
p03555
u951672936
2,000
262,144
Wrong Answer
17
3,064
121
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.
s1 = input() s2 = input() ok = True for i in range(3): if s1[i] != s2[2-i]: ok = False print("Yes" if ok else "No")
s817045786
Accepted
17
2,940
122
s1 = input() s2 = input() ok = True for i in range(3): if s1[i] != s2[2-i]: ok = False print("YES" if ok else "NO")
s139913032
p03700
u785578220
2,000
262,144
Wrong Answer
2,053
7,072
346
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called _health_ , and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: * Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
N,A,B = map(int,input().split()) H = [int(input()) for _ in range(N)] from math import ceil ng,ok = 0,10**9+1 while abs(ok-ng)>1: mid = (ng+ok)//2 cnt = 0 for i in range(N): cnt += max(ceil((H[i] - B*mid)/(A-B)) ,0) if cnt == mid: break if cnt <= mid: ok = mid else: ng = mid print(ok)
s474505278
Accepted
2,000
7,072
350
##################################### N,A,B = map(int,input().split()) H = [int(input()) for _ in range(N)] from math import ceil ng,ok = 0,10**9+1 while abs(ok-ng)>1: mid = (ng+ok)//2 cnt = 0 for i in range(N): cnt += max(ceil((H[i] - B*mid)/(A-B)) ,0) if cnt <= mid: ok = mid else: ng = mid print(ok)
s062163304
p00007
u696166817
1,000
131,072
Wrong Answer
30
6,756
551
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks.
if __name__ == "__main__": n = int(input()) # print(n) y = 100000 y2 = y / 1000 for i in range(0, n): y4 = y2 * 1.05 # y3 = round(y2 * 1.05 -0.5, 0) y3 = float(int(y2 * 1.05)) print(" {} {}".format(y4, y3)) if y4 - y3 > 0: y4 += 1 y2 = int(y4) print("{} {}".format(i, y2 * 1000)) print(y2 * 1000) # 0 105,000 # 1 110,250 -> 111,000 # 2 116,550 -> 117,000 # 3 122,850 -> 123,000 #4 129,150 -> 130,000
s727758267
Accepted
30
6,752
553
if __name__ == "__main__": n = int(input()) # print(n) y = 100000 y2 = y / 1000 for i in range(0, n): y4 = y2 * 1.05 # y3 = round(y2 * 1.05 -0.5, 0) y3 = float(int(y2 * 1.05)) #print(" {} {}".format(y4, y3)) if y4 - y3 > 0: y4 += 1 y2 = int(y4) #print("{} {}".format(i, y2 * 1000)) print(y2 * 1000) # 0 105,000 # 1 110,250 -> 111,000 # 2 116,550 -> 117,000 # 3 122,850 -> 123,000 #4 129,150 -> 130,000
s828996466
p03160
u690781906
2,000
1,048,576
Wrong Answer
133
13,928
201
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
n = int(input()) h = list(map(int, input().split())) dp = [0] * n dp[1] = abs(h[1]-h[0]) for i in range(2, n): dp[i] = min(dp[i-1] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])) print(dp[-1])
s612360716
Accepted
130
13,928
201
n = int(input()) h = list(map(int, input().split())) dp = [0] * n dp[1] = abs(h[1]-h[0]) for i in range(2, n): dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])) print(dp[-1])
s789905945
p03563
u562120243
2,000
262,144
Wrong Answer
17
3,060
181
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
ans = 1 n = int(input()) k = int(input()) cnt = 0 while ans * 2 < ans + k: if cnt > n: break ans *= 2 cnt +=1 for i in range(cnt,n): ans += k print(ans)
s081303566
Accepted
18
2,940
46
r = int(input()) g = int(input()) print(2*g-r)
s480565815
p02678
u425068548
2,000
1,048,576
Wrong Answer
621
39,936
919
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
import collections def get_input(): return list(map(lambda x:int(x), input().split())) def main(): inp = get_input() n, m = inp[0], inp[1] adj_list = [[] for i in range(n)] for i in range(m): inpu = get_input() a, b = inpu[0], inpu[1] adj_list[a - 1].append(b - 1) adj_list[b - 1].append(a - 1) q = collections.deque() visited = set() q.append(0) visited.add(0) p = [-1] * n #print(adj_list) while q: u = q.popleft() for i in adj_list[u]: #print("checking", u, i) if i not in visited: q.append(i) visited.add(i) p[i] = u #print(p) for i in range(1, len(p)): if p[i] == -1: print("NO") return print("YES") for i in range(1, n): print(p[i] + 1) if __name__ == '__main__': main()
s347689034
Accepted
740
40,252
919
import collections def get_input(): return list(map(lambda x:int(x), input().split())) def main(): inp = get_input() n, m = inp[0], inp[1] adj_list = [[] for i in range(n)] for i in range(m): inpu = get_input() a, b = inpu[0], inpu[1] adj_list[a - 1].append(b - 1) adj_list[b - 1].append(a - 1) q = collections.deque() visited = set() q.append(0) visited.add(0) p = [-1] * n #print(adj_list) while q: u = q.popleft() for i in adj_list[u]: #print("checking", u, i) if i not in visited: q.append(i) visited.add(i) p[i] = u #print(p) for i in range(1, len(p)): if p[i] == -1: print("No") return print("Yes") for i in range(1, n): print(p[i] + 1) if __name__ == '__main__': main()
s943926615
p03548
u304318875
2,000
262,144
Wrong Answer
156
13,568
1,550
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
import numpy as np import math import fractions class KyoPro: AtCoder_Mod = 1000 * 1000 * 1000 + 7 def ReadListOfNumbers(): return list(map(int, input().split())) @staticmethod def MakeStringFromNumbers(a): if len(a) == 0: return s = str(a[0]) for i in range(1, len(a)): s += ' ' + str(a[i]) return s @staticmethod def BinarySearch(ls, target, func): if(func is None): def func(a, b): return a < b def eq(a, b): return (not func(a, b)) and (not func(b, a)) left = 0 right = len(ls) - 1 while(True): if(right - left < 10): for i in range(left, right + 1): if(eq(ls[i], target)): return True return False center = (left + right) // 2 if(eq(ls[center], target)): return True if(func(ls[center], target)): left = center if(func(target, ls[center])): right = center class cin: InputList = [] def __init__(self): pass def Read(self): cin.InputList += input().split() def ReadInt(self): if(len(cin.InputList) == 0): self.Read def main(): temp = KyoPro.ReadListOfNumbers() x = temp[0] y = temp[1] z = temp[2] y += z x += z print(x / y) main()
s826396501
Accepted
158
13,568
1,551
import numpy as np import math import fractions class KyoPro: AtCoder_Mod = 1000 * 1000 * 1000 + 7 def ReadListOfNumbers(): return list(map(int, input().split())) @staticmethod def MakeStringFromNumbers(a): if len(a) == 0: return s = str(a[0]) for i in range(1, len(a)): s += ' ' + str(a[i]) return s @staticmethod def BinarySearch(ls, target, func): if(func is None): def func(a, b): return a < b def eq(a, b): return (not func(a, b)) and (not func(b, a)) left = 0 right = len(ls) - 1 while(True): if(right - left < 10): for i in range(left, right + 1): if(eq(ls[i], target)): return True return False center = (left + right) // 2 if(eq(ls[center], target)): return True if(func(ls[center], target)): left = center if(func(target, ls[center])): right = center class cin: InputList = [] def __init__(self): pass def Read(self): cin.InputList += input().split() def ReadInt(self): if(len(cin.InputList) == 0): self.Read def main(): temp = KyoPro.ReadListOfNumbers() x = temp[0] y = temp[1] z = temp[2] y += z x -= z print(x // y) main()
s055948431
p03377
u597047658
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 A+B > X: print('NO') else: print("YES")
s419457991
Accepted
19
2,940
103
A, B, X = map(int, input().split()) if (A+B > X) and (A <= X): print('YES') else: print('NO')
s003682170
p02742
u679089074
2,000
1,048,576
Wrong Answer
27
9,076
97
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
#6 H,W = map(int,input().split()) k = H*W if k%2 == 0: print(k/2) else: print(int(k/2)+1)
s565427377
Accepted
25
9,132
163
#6 import sys H,W = map(int,input().split()) k = H*W if H ==1 or W == 1: print(1) sys.exit() if k%2 == 0: print(int(k/2)) else: print(int(k/2)+1)
s556579580
p03645
u368796742
2,000
262,144
Wrong Answer
690
61,108
257
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
n,m = map(int,input().split()) l = [list(map(int,input().split())) for i in range(m)] a = [] b = [] for i in l: if i[0] == 1: a.append(i[1]) if i[1] == n: b.append(i[0]) print("Possible" if len(set(a)&set(b)) > 0 else "Impossible")
s856604117
Accepted
595
18,892
217
n,m = map(int,input().split()) a = set() b = set() for i in range(m): a_,b_ = map(int,input().split()) if a_ == 1: a.add(b_) if b_ == n: b.add(a_) print("POSSIBLE" if a&b else "IMPOSSIBLE")
s291371859
p02612
u472039178
2,000
1,048,576
Wrong Answer
30
9,028
59
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()) n = (N-(N%1000))/1000 print(1000*(n+1)-N)
s354904808
Accepted
28
9,040
98
N=int(input()) if N%1000==0: print("0") else: n=((N-(N%1000))/1000)+1 print(int((1000*n)-N))
s343367117
p04030
u227082700
2,000
262,144
Wrong Answer
17
2,940
145
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
def b(x): if x=='':return'' else:return x[:-1] s,ans=input(),'' for i in range(len(s)): if s[i]!='B':ans=b(ans) else:ans+=s[i] print(ans)
s422844695
Accepted
17
2,940
106
ans=[] for i in input(): if i=="B": if len(ans):del ans[-1] else:ans.append(i) print("".join(ans))
s207033710
p02613
u554237650
2,000
1,048,576
Wrong Answer
153
15,988
339
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
import os N = int(input()) S = [0] * N for i in range(0, N): S[i] = input() AC = 0 WA = 0 TLE = 0 RE = 0 for i in S: if i == "AC": AC+=1 elif i == "WA": WA+=1 elif i == "TLE": TLE+=1 elif i == "RE": RE+=1 print("AC × ",AC) print("WA × ",WA) print("TLE × ",TLE) print("RE × ",RE)
s740173758
Accepted
161
15,992
341
import os N = int(input()) S = [0] * N for i in range(0, N): S[i] = input() AC = 0 WA = 0 TLE = 0 RE = 0 for i in S: if i == "AC": AC+=1 elif i == "WA": WA+=1 elif i == "TLE": TLE+=1 elif i == "RE": RE+=1 print("AC x",AC) print("WA x",WA) print("TLE x",TLE) print("RE x",RE)
s028094627
p03456
u320567105
2,000
262,144
Wrong Answer
19
3,188
240
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
ri = lambda: int(input()) rl = lambda: list(map(int,input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print('YES') if b else print('NO') INF = 10**18 a,b = rl() c = int(str(a)+str(b)) c_ = int(c**0.5) YN(c==c_*c_)
s904570111
Accepted
17
3,060
279
ri = lambda: int(input()) rl = lambda: list(map(int,input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print('YES') if b else print('NO') INF = 10**18 a,b = rl() c = int(str(a)+str(b)) c_ = int(c**0.5) if c==c_*c_: print('Yes') else: print('No')
s029276194
p02659
u131638468
2,000
1,048,576
Wrong Answer
22
9,092
44
Compute A \times B, truncate its fractional part, and print the result as an integer.
a,b=map(float,input().split()) print(a*b//1)
s750764198
Accepted
23
9,180
127
a,b=map(str,input().split()) a=int(a) c='' for i in b: if i=='.': continue else: c+=i c=int(c) print(int(a*c//100))
s067467699
p02842
u585963419
2,000
1,048,576
Wrong Answer
17
2,940
105
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.
n=int(input()) step0=(n/108*100) step1=(step0/100*108) if step1!=n: print(':(') else: print(step0)
s025085632
Accepted
17
3,064
466
n=int(input()) step00=int((n/108*100)) step01=int((n/108*100))-1 step02=int((n/108*100))+1 step10=int((step00/100*108)) step11=int((step01/100*108)) step12=int((step02/100*108)) nocnt=0 ok=0 if step10!=n: nocnt=nocnt+1 else: print(step00) ok=1 if step11!=n: nocnt=nocnt+1 else: if ok==0: print(step10) ok=1 if step12!=n: nocnt=nocnt+1 else: if ok==0: print(step02) ok=1 if nocnt>=3: print(':(')
s364401219
p04029
u637824361
2,000
262,144
Wrong Answer
17
2,940
38
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
N = int(input()) print(N * (N+1) / 2)
s265353743
Accepted
17
2,940
43
N = int(input()) print(int(N * (N+1) / 2))
s856175361
p02616
u218623249
2,000
1,048,576
Wrong Answer
147
31,744
173
Given are N integers A_1,\ldots,A_N. We will choose exactly K of these elements. Find the maximum possible product of the chosen elements. Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).
suus,cleck = map(int,input().split()); cuc = 1 fef = sorted(map(int,input().split()), reverse = True) for joj in range(cleck): cuc = (cuc * fef[joj])%1000000007 print(cuc)
s323372718
Accepted
271
31,868
1,176
N,K=map(int, input().split()) A=list(map(int, input().split())) D,E=[],[] zcnt,scnt,fcnt=0,0,0 for i in A: if i==0: zcnt+=1 D.append(0) elif i>0: D.append(i) scnt+=1 else: E.append(i) fcnt+=1 mod=10**9+7 ans=1 if K==N: for i in A: ans*=i ans%=mod print(ans) exit() if K%2==1 and max(A)<0: A=sorted(A)[::-1] for i in range(K): ans*=A[i] ans%=mod print(ans) exit() if K>scnt+fcnt: print(0) exit() D,E=sorted(D)[::-1],sorted(E) #print(D,E) ans=1 cnt=0 a,b=0,0 while K-cnt>1: if a+1<=len(D)-1 and b+1<=len(E)-1: d,e=D[a]*D[a+1],E[b]*E[b+1] if d>e: ans*=D[a] a+=1 cnt+=1 ans%=mod else: ans*=e b+=2 ans%=mod cnt+=2 elif a+1<=len(D)-1: d=D[a]*D[a+1] ans*=D[a] a+=1 cnt+=1 ans%=mod elif b+1<=len(E)-1: e=E[b]*E[b+1] ans*=e b+=2 cnt+=2 ans%=mod if K-cnt==1: Z=[] if a!=scnt: Z.append(D[a]) if b!=fcnt: Z.append(E[-1]) if 0 in A: Z.append(0) ans*=max(Z) ans%=mod print(ans)
s801985030
p03372
u562935282
2,000
262,144
Wrong Answer
704
48,692
1,021
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
def solve(xv_sorted): x = [False for _ in range(n)] y = [False for _ in range(n)] s = 0 buf = (- 1) * float('inf') for i in range(n): s += xv_sorted[i][1]##cal x[i] = max(buf, s - 2 * xv_sorted[i][0])##pos buf = x[i] print(x) s = 0 buf = (- 1) * float('inf') for i in sorted(range(n), reverse=True): s += xv_sorted[i][1]##cal y[i] = max(buf, s - (c - xv_sorted[i][0]))##pos buf = y[i] print(y) ans = max(x[n - 1], y[0]) for i in range(n - 1): ans = max(ans, x[i] + y[i + 1]) return ans if __name__ == '__main__': n, c = map(int, input().split()) xv = [] for i in range(n): xv.append(list(map(int, input().split()))) xv_sorted = sorted(xv, key=lambda x:x[0]) ans = 0 ans = max(ans, solve(xv_sorted)) for i in range(n): xv_sorted[i][0] = abs(c - xv_sorted[i][0]) xv_sorted = sorted(xv, key=lambda x:x[0]) ans = max(ans, solve(xv_sorted)) print(ans)
s980518099
Accepted
470
30,224
1,800
def main(): from collections import namedtuple import sys input = sys.stdin.readline Sushi = namedtuple('Sushi', 'x cal') n, c = map(int, input().split()) a = [] for _ in range(n): x, v = map(int, input().split()) a.append(Sushi(x=x, cal=v)) clock = [0] * (n + 1) clock_to_0 = [0] * (n + 1) ma = 0 ma0 = 0 curr = 0 for i, s in enumerate(a, start=1): curr += s.cal ma = max(ma, curr - s.x) ma0 = max(ma0, curr - s.x * 2) clock[i] = ma clock_to_0[i] = ma0 anti = [0] * (n + 1) anti_to_0 = [0] * (n + 1) ma = 0 ma0 = 0 curr = 0 for i, s in zip(range(n, -1, -1), reversed(a)): curr += s.cal ma = max(ma, curr - (c - s.x)) ma0 = max(ma0, curr - (c - s.x) * 2) anti[i] = ma anti_to_0[i] = ma0 ans = 0 for exit_pos in range(1, n + 1): ans = max( ans, clock_to_0[exit_pos - 1] + anti[exit_pos], anti_to_0[(exit_pos + 1) % (n + 1)] + clock[exit_pos] ) print(ans) if __name__ == '__main__': main()
s518554713
p02842
u860338101
2,000
1,048,576
Wrong Answer
17
2,940
119
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
import math N = int(input()) M = N / 1.08 if math.floor(M) * 1.08 == N: print(math.floor(M*1.08)) else: print(':(')
s937044670
Accepted
17
3,060
240
import math N = int(input()) flag = False Min = math.floor(N / 1.08) Max = math.floor( ( N + 1 ) / 1.08 + 1) for i in range(Min, Max + 1): if math.floor( i * 1.08 ) == N: print( i ) flag = True break if not flag: print(':(')
s361253693
p02619
u370562440
2,000
1,048,576
Wrong Answer
130
27,036
613
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
#B import numpy as np D = int(input()) C = list(map(int,input().split())) S = np.empty((D,26),dtype=np.int8) for i in range(D): l = list(map(int,input().split())) for j in range(26): S[i][j] = l[j] R = np.zeros(26) sc = 0 for i in range(1,D+1): con = int(input()) - 1 sc += S[i-1][con] R[con] = i for j in range(26): sc -= C[j]*(i-R[j]) print(sc)
s552282601
Accepted
136
26,992
644
#B import numpy as np D = int(input()) C = list(map(int,input().split())) S = np.empty((D,26)) for i in range(D): l = list(map(int,input().split())) for j in range(26): S[i][j] = l[j] R = np.zeros(26) sc = 0 for i in range(1,D+1): con = int(input()) - 1 sc += S[i-1][con] R[con] = i for j in range(26): sc -= C[j]*(i-R[j]) print(int(sc))
s901905643
p03162
u006883624
2,000
1,048,576
Wrong Answer
17
3,064
421
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
def main(): n = int(input()) table = [] for _ in range(n): table.append([int(v) for v in input().split()]) dp = [0] * 3 for i in range(n): dp_n = [0] * 3 a, b, c = table[i] a0 = dp[0] b0 = dp[1] c0 = dp[2] dp_n[0] = max(b0, c0) + a dp_n[1] = max(c0, a0) + b dp_n[2] = max(a0, b0) + c dp = dp_n print(max(dp))
s780357990
Accepted
396
20,536
400
def main(): N = int(input()) table = [] for _ in range(N): a, b, c = map(int, input().split()) table.append((a, b, c)) dp = [0] * 3 for i in range(N): a, b, c = table[i] a0 = dp[0] b0 = dp[1] c0 = dp[2] dp[0] = max(b0, c0) + a dp[1] = max(c0, a0) + b dp[2] = max(a0, b0) + c print(max(dp)) main()
s015599991
p03470
u165318982
2,000
262,144
Wrong Answer
25
9,156
82
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
N = int(input()) A = list(map(int, input().split())) A = set(A) print(str(len(A)))
s763453177
Accepted
27
9,100
83
N = int(input()) A = [int(input()) for _ in range(N)] A = set(A) print(str(len(A)))
s285498522
p02865
u190580703
2,000
1,048,576
Wrong Answer
17
2,940
29
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
a=int(input()) print((a-1)/2)
s362592869
Accepted
17
2,940
30
a=int(input()) print((a-1)//2)
s110568846
p03853
u870841038
2,000
262,144
Wrong Answer
18
3,060
117
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
h, w = map(int, input().split()) marks = list(input() for i in range(h)) for i in range(h): print(marks[i] * 2)
s904906287
Accepted
17
3,060
140
h, w = map(int, input().split()) marks = list(input() for i in range(h)) for i in range(h): for j in range(2): print(marks[i])
s222529809
p02288
u912143677
2,000
131,072
Wrong Answer
20
5,596
441
A binary heap which satisfies max-heap property is called max-heap. In a max- heap, for every node $i$ other than the root, $A Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code. $maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap. 1 maxHeapify(A, i) 2 l = left(i) 3 r = right(i) 4 // select the node which has the maximum value 5 if l ≤ H and A[l] > A[i] 6 largest = l 7 else 8 largest = i 9 if r ≤ H and A[r] > A[largest] 10 largest = r 11 12 if largest ≠ i // value of children is larger than that of i 13 swap A[i] and A[largest] 14 maxHeapify(A, largest) // call recursively The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner. 1 buildMaxHeap(A) 2 for i = H/2 downto 1 3 maxHeapify(A, i)
n = int(input()) a = list(map(int, input().split())) def maxheapify(a, i): l = i*2 + 1 r = i*2 + 2 if l <= n and a[l] > a[i]: largest = l else: largest = i if r <= n and a[r] > a[largest]: largest = r if largest != i: memo = a[i] a[i] = a[largest] a[largest] = memo maxheapify(a, largest) h = (n - 1) // 2 for i in reversed(range(h)): maxheapify(a, i)
s885587886
Accepted
880
63,696
721
n = int(input()) a = list(map(int, input().split())) def maxheapify(a, i): l = i*2 + 1 r = i*2 + 2 if r < n: if a[l] > a[i]: largest = l else: largest = i if a[r] > a[largest]: largest = r if largest != i: memo = a[i] a[i] = a[largest] a[largest] = memo maxheapify(a, largest) elif l < n: if a[l] > a[i]: largest = l else: largest = i if largest != i: memo = a[i] a[i] = a[largest] a[largest] = memo maxheapify(a, largest) for i in reversed(range(n)): maxheapify(a, i) print("", *a)
s067095304
p03610
u021548497
2,000
262,144
Wrong Answer
29
3,572
69
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input() print("".join([str(s[2*i+1]) for i in range(len(s)//2)]))
s140574560
Accepted
39
3,188
91
s = input() ans = "" for i in range(len(s)): if i%2 == 0: ans = ans + s[i] print(ans)
s545952328
p03493
u160659351
2,000
262,144
Wrong Answer
19
2,940
57
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.
data = [x for x in input().rstrip()] print(data.count(1))
s416545159
Accepted
19
3,060
59
data = [x for x in input().rstrip()] print(data.count("1"))
s602942238
p02612
u325660636
2,000
1,048,576
Wrong Answer
28
9,088
48
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()) otsuri = N % 1000 print(otsuri)
s458585999
Accepted
29
9,164
149
N = int(input()) a = N // 1000 b = N % 1000 if b ==0: print(0) else: if N<=1000: print(1000-b) else: print(1000*(a+1)-N)
s282457628
p02865
u459774442
2,000
1,048,576
Wrong Answer
18
2,940
79
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
N = int(input()) ans=0 if N%2==0: ans=N/2 else: ans=int(N/2) print(ans)
s616999285
Accepted
17
2,940
86
N = int(input()) ans=0 if N%2==0: ans=N/2-1 elif N!=1: ans=N/2 print(int(ans))
s031140633
p03455
u247465867
2,000
262,144
Wrong Answer
17
2,940
586
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
# -*- codinf: utf-8 -*- numList = [int(num) for num in input().split()] productNumList = numList[0] * numList[1] if ((productNumList % 2) == 0 ): print("even") else: print("odd")
s068512090
Accepted
17
2,940
90
#2019/10/10 a, b = map(int, open(0).read().split()) print("Odd" if (a*b)%2!=0 else "Even")
s791283241
p02255
u716198574
1,000
131,072
Wrong Answer
30
7,516
529
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()) A = list(map(int, input().split())) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print(' '.join(map(str, A)))
s823383675
Accepted
30
7,608
526
N = int(input()) A = list(map(int, input().split())) for i in range(N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print(' '.join(map(str, A)))
s482205755
p03386
u015187377
2,000
262,144
Wrong Answer
21
3,316
224
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
import collections a,b,k=map(int,input().split()) l1=list(range(a,a+k)) l1=[str(i) for i in l1] l2=list(range(b-k+1,b+1)) l2=[str(i) for i in l2] ans=l1+l2 ans=collections.Counter(ans) ans=sorted(ans) print(" ".join(ans))
s030908283
Accepted
17
3,060
165
a,b,k=map(int,input().split()) ans=[] for i in range(k): if a+i<=b: ans.append(a+i) if b-i>=a: ans.append(b-i) ans=sorted(set(ans)) print(*ans, sep='\n')
s497086785
p02406
u706217959
1,000
131,072
Wrong Answer
20
5,588
164
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
def main(): n = int(input()) for i in range(n+1): if i % 3 == 0 or i % 3 == 10: print(i,end=" ") if __name__ == "__main__": main()
s821012088
Accepted
30
5,880
337
def call(a): if a % 3 == 0: return True while a != 0: if a % 10 == 3: return True a //= 10 return False def main(): n = int(input()) for i in range(1, n + 1): if call(i): print(" {0}".format(i), end="") print("") if __name__ == "__main__": main()
s859887047
p03149
u721316601
2,000
1,048,576
Wrong Answer
17
3,060
346
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
s = 'keyence' S = input() ans = 'NO' for i in range(len(S)): if S[i] == 'k': for l in range(1, len(s)): if S[i+l] != s[l]: break for n in range(len(S)-l): if S[i:l] + S[l+n:l+n+7-3] == s: ans = 'YES' break if ans == 'YES': break print(ans)
s684718397
Accepted
17
2,940
103
N = input() if '1' in N and '9' in N and '7' in N and '4' in N: print('YES') else: print('NO')
s110705689
p02608
u255943004
2,000
1,048,576
Wrong Answer
950
11,812
236
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
N = int(input()) from collections import defaultdict ans = defaultdict(int) for a in range(101): for b in range(101): for c in range(101): ans[a**2 + b**2 + c**2 + a*b + a*c + b*c] += 1 for n in range(1,N+1): print(ans[n])
s596397944
Accepted
949
11,956
243
N = int(input()) from collections import defaultdict ans = defaultdict(int) for a in range(1,101): for b in range(1,101): for c in range(1,101): ans[a**2 + b**2 + c**2 + a*b + a*c + b*c] += 1 for n in range(1,N+1): print(ans[n])
s447328485
p03485
u766407523
2,000
262,144
Wrong Answer
20
3,316
117
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.
ab = input().split() a = int(ab[0]) b = int(ab[1]) if (a+b)%2 == 0: print((a+b)/2) else: print((a+b)//2 + 1)
s357470931
Accepted
17
2,940
117
ab = input().split() a, b = int(ab[0]), int(ab[1]) if (a+b)%2 == 0: print((a+b)//2) else: print((a+b)//2 + 1)
s629997350
p03762
u614875193
2,000
262,144
Wrong Answer
68
25,476
529
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i. For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7. That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.
m,n=map(int,input().split()) X=list(map(int,input().split())) Y=list(map(int,input().split())) mod=10**9+7 if m>2 and n>2: X2=[(X[1]-X[0])%mod,(X[-2]-X[1])%mod,(X[-1]-X[-2])%mod] Y2=[(Y[1]-Y[0])%mod,(Y[-2]-Y[1])%mod,(Y[-1]-Y[-2])%mod] ans=0 a,b1,b2,c=m*n,(2*m-2)*n,(2*n-2)*m,(2*m-2)*(2*n-2) ans+=(X2[0]*Y2[0] + X2[2]*Y2[0] + X2[0]*Y2[2] + X2[2]*Y2[2])*a%mod ans+=(X2[1]*Y2[0]+X2[1]*Y2[2])*b1%mod ans+=(X2[0]*Y2[1]+X2[2]*Y2[1])*b2%mod ans+=X2[1]*Y2[1]*c%mod print(ans%mod) else: print(mod)
s479956090
Accepted
136
24,356
270
n,m=map(int,input().split()) X=list(map(int,input().split())) Y=list(map(int,input().split())) mod=10**9+7 ans1=0 for k in range(1,n+1): ans1+=(2*k-1-n)*X[k-1] ans1%=mod ans2=0 for k in range(1,m+1): ans2+=(2*k-1-m)*Y[k-1] ans2%=mod print(ans1*ans2%mod)
s411830680
p02975
u627234757
2,000
1,048,576
Wrong Answer
51
14,704
825
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
n = int(input()) nums = list(map(int, input().split())) unq = list(set(nums)) if len(unq) > 3: print("No") if len(unq) == 3: a,b,c = unq if a ^ b ^ c != 0: if nums.count(a) == nums.count(b) == nums.count(c): print("Yes") else: print("No") else: print("No") if len(unq) == 2: a,b = sorted(unq) if a == 0: if nums.count(a) * 2 == nums.count(b): print("Yes") else: print("No") else: print("No") if len(unq) == 1: a = unq[0] if a != 0: print("No") else: print("Yes")
s020483479
Accepted
52
14,704
826
n = int(input()) nums = list(map(int, input().split())) unq = list(set(nums)) if len(unq) > 3: print("No") if len(unq) == 3: a,b,c = unq if a ^ b ^ c == 0: if nums.count(a) == nums.count(b) == nums.count(c): print("Yes") else: print("No") else: print("No") if len(unq) == 2: a,b = sorted(unq) if a == 0: if nums.count(a) * 2 == nums.count(b): print("Yes") else: print("No") else: print("No") if len(unq) == 1: a = unq[0] if a != 0: print("No") else: print("Yes")
s740716548
p03494
u932868243
2,000
262,144
Wrong Answer
18
2,940
96
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n=int(input()) a=list(map(int,input().split())) n=0 if all(aa%2==0 for aa in a): n+=1 print(n)
s053903365
Accepted
18
3,060
129
n=int(input()) a=list(map(int,input().split())) ans=0 while all(aa%2==0 for aa in a): ans+=1 a=[aa//2 for aa in a] print(ans)
s054796309
p04043
u823885866
2,000
262,144
Wrong Answer
25
8,808
52
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.
print('YNEOS'[eval(input().replace(*' *'))!=245::2])
s746443854
Accepted
27
8,904
52
print('YNEOS'[eval(input().replace(*' *'))!=175::2])
s344992929
p02388
u976860528
1,000
131,072
Wrong Answer
20
7,352
14
Write a program which calculates the cube of a given integer x.
print(input())
s658510354
Accepted
20
7,556
29
x = int(input()) print(x*x*x)
s333038762
p02744
u537905693
2,000
1,048,576
Wrong Answer
726
19,104
665
In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be **isomorphic** when the following conditions are satisfied: * |s| = |t| holds. * For every pair i, j, one of the following holds: * s_i = s_j and t_i = t_j. * s_i \neq s_j and t_i \neq t_j. For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are not. A string s is said to be in **normal form** when the following condition is satisfied: * For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison. For example, `abcac` is in normal form, but `zyxzx` is not since it is isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`. You are given an integer N. Print all strings of length N that are in normal form, in lexicographically ascending order.
#!/usr/bin/env python # coding: utf-8 def ri(): return int(input()) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) words = set() alp = list("abcdefghij") def dfs(n, s): if len(s) == n: return for i in range(0, len(s)): for c in alp: if ord(c)>ord(s[i])+1: break ns = s[:i+1]+c+s[i+1:] if ns in words: continue words.add(ns) dfs(n, ns) def main(): n = ri() dfs(n, 'a') for w in sorted(words): if len(w) == n: print(w) if __name__ == '__main__': main()
s946236745
Accepted
768
19,104
714
#!/usr/bin/env python # coding: utf-8 def ri(): return int(input()) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) words = set() alp = list("abcdefghij") def dfs(n, s): if len(s) == n: return for i in range(0, len(s)): for c in alp: if ord(c)>ord(s[i])+1: break ns = s[:i+1]+c+s[i+1:] if ns in words: continue words.add(ns) dfs(n, ns) def main(): n = ri() if n == 1: print("a") return dfs(n, 'a') for w in sorted(words): if len(w) == n: print(w) if __name__ == '__main__': main()
s701838070
p03860
u500279510
2,000
262,144
Wrong Answer
17
2,940
47
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s = input() x = s[0] ans = 'A'+x+'C' print(ans)
s443694314
Accepted
17
2,940
47
s = input() x = s[8] ans = 'A'+x+'C' print(ans)
s927158869
p03433
u068538925
2,000
262,144
Wrong Answer
30
8,972
94
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input()) a = int(input()) temp = n%500 if temp<=a: print("YES") else: print("NO")
s900060069
Accepted
28
9,100
94
n = int(input()) a = int(input()) temp = n%500 if temp<=a: print("Yes") else: print("No")
s311949263
p03721
u543954314
2,000
262,144
Wrong Answer
480
21,524
234
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
n, k = map(int, input().split()) l = [tuple(map(int, input().split())) for i in range(n)] l.sort() l.append((0, k)) d = [l[0][1]] for i in range(1,n+1): d.append(d[i-1] + l[i][1]) t = 0 while d[t] <= k: t += 1 print(l[t-1][0])
s301243528
Accepted
443
21,524
231
n, k = map(int, input().split()) l = [tuple(map(int, input().split())) for i in range(n)] l.sort() l.append((0, k)) d = [l[0][1]] for i in range(1,n+1): d.append(d[i-1] + l[i][1]) t = 0 while d[t] < k: t += 1 print(l[t][0])
s303877168
p04043
u653005308
2,000
262,144
Wrong Answer
17
2,940
122
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,b,c).count("5")==2 and (a,b,c).count("7")==1: print('YES') else: print('NO')
s601302471
Accepted
17
2,940
117
a,b,c=map(int,input().split()) if (a,b,c).count(5)==2 and (a,b,c).count(7)==1: print('YES') else: print('NO')
s004890530
p03110
u118147328
2,000
1,048,576
Wrong Answer
24
2,940
208
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()) X = [input().split() for _ in range(N)] Y = 0 for i in X: print(i[1]) if i[1] == 'JPY': Y += int(i[0]) elif i[1] == 'BTC': Y += (380000.0 * float(i[0])) print(Y)
s027271218
Accepted
17
2,940
192
N = int(input()) X = [input().split() for _ in range(N)] Y = 0 for i in X: if i[1] == 'JPY': Y += int(i[0]) elif i[1] == 'BTC': Y += (380000.0 * float(i[0])) print(Y)
s528125916
p02842
u769551032
2,000
1,048,576
Wrong Answer
18
2,940
97
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.
N = int(input()) untax_N = round(N/1.08) if round(untax_N*1.08) != N: print(":(") else: pass
s933944094
Accepted
33
2,940
148
N = int(input()) count = 0 for i in range(N+1): if N <= int(i*1.08) < N+1: print(i) count += 1 break if count == 0: print(":(")
s876034870
p03434
u676707608
2,000
262,144
Wrong Answer
18
2,940
92
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() print((sum(a[::2])-(sum(a[1::2]))))
s918654234
Accepted
17
2,940
104
n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) print((sum(a[::2])-(sum(a[1::2]))))
s121452557
p03477
u168416324
2,000
262,144
Wrong Answer
27
9,148
125
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d=map(int,input().split()) x=a+b y=c+d if x>y: print("Left") if x>y: print("Right") if x==y: print("Balanced")
s862743402
Accepted
29
9,072
126
a,b,c,d=map(int,input().split()) x=a+b y=c+d if x>y: print("Left") if x<y: print("Right") if x==y: print("Balanced")
s542615192
p03575
u499259667
2,000
262,144
Wrong Answer
23
3,572
777
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
N , M = map(int,input().split()) dotlist = [[] for i in range(N)] sidlist = [] count = 0 for m in range(M): a,b = map(int,input().split()) dotlist[a -1].append(b) dotlist[b -1].append(a) sidlist.append([a,b]) if N -1 == M: print(0) exit() def check(anum,bnum,cnum): for i in dotlist[cnum - 1]: if (anum == cnum and i == bnum) or (bnum == cnum and i == anum): pass elif donedot[i - 1] == False: donedot[i - 1] = True print(cnum,i) check(anum,bnum,i) donedot = None for m in range(M): donedot = [False for i in range(M)] a,b = sidlist[m] check(a,b,1) TorF = True for i in donedot: TorF = TorF and i if not TorF: count += 1 print(count)
s522218832
Accepted
22
3,316
705
N , M = map(int,input().split()) dotlist = [[] for i in range(N)] sidlist = [] count = 0 for m in range(M): a,b = map(int,input().split()) dotlist[a -1].append(b) dotlist[b -1].append(a) sidlist.append([a,b]) def check(anum,bnum,cnum): donedot[cnum-1] = True for i in dotlist[cnum - 1]: if (anum == cnum and i == bnum) or (bnum == cnum and i == anum): pass elif donedot[i - 1] == False: check(anum,bnum,i) donedot = None for m in range(M): donedot = [False for i in range(N)] a,b = sidlist[m] check(a,b,1) TorF = True for i in donedot: TorF = TorF and i if not TorF: count += 1 print(count)
s641817464
p03911
u600402037
2,000
262,144
Wrong Answer
2,107
73,484
893
On a planet far, far away, M languages are spoken. They are conveniently numbered 1 through M. For _CODE FESTIVAL 20XX_ held on this planet, N participants gathered from all over the planet. The i-th (1≦i≦N) participant can speak K_i languages numbered L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}. Two participants A and B can _communicate_ with each other if and only if one of the following conditions is satisfied: * There exists a language that both A and B can speak. * There exists a participant X that both A and B can communicate with. Determine whether all N participants can communicate with all other participants.
import sys import itertools stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only rs = lambda: stdin.readline().rstrip() N, M = rl() L = [rl() for _ in range(N)] translate = [set() for _ in range(M+1)] for i, x in enumerate(L): k, *language = x for l in language: translate[l].add(i) for x, y in itertools.combinations(range(N), 2): x_use_language = set(L[x][1:]) y_use_language = set(L[y][1:]) x_can_speak = set([x]) y_can_speak = set([y]) for xuse in x_use_language: x_can_speak = x_can_speak.union(translate[xuse]) for yuse in y_use_language: y_can_speak = y_can_speak.union(translate[yuse]) if len(x_can_speak & y_can_speak) == 0: print('NO') exit() print('YES') # 26
s005674584
Accepted
309
41,544
895
import sys sys.setrecursionlimit(10 ** 7) stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only rs = lambda: stdin.readline().rstrip() N, M = rl() KL = [rl() for _ in range(N)] speak_lan = [[] for _ in range(M+1)] for i, x in enumerate(KL): k, *lan = x for l in lan: speak_lan[l].append(i) communicate = set() used_language = set() def dfs(person): global communicate global used_language lan = KL[person][1:] for l in lan: if l in used_language: continue used_language.add(l) for p in speak_lan[l]: if p not in communicate: communicate.add(p) dfs(p) dfs(0) if len(communicate) == N: print('YES') else: print('NO')
s543979071
p03860
u761989513
2,000
262,144
Wrong Answer
17
2,940
62
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
a, x, c = input().split() print("{} {} {}".format(a, x[0], c))
s256225416
Accepted
17
2,940
67
a, x, c = input().split() print("{}{}{}".format(a[0], x[0], c[0]))
s043743585
p03485
u803647747
2,000
262,144
Wrong Answer
17
2,940
101
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.
input_list = list(map(int,input().split())) import math math.ceil((input_list[0] + input_list[1])/2)
s080079830
Accepted
17
2,940
108
input_list = list(map(int,input().split())) import math print(math.ceil((input_list[0] + input_list[1])/2))
s668764348
p02865
u498620941
2,000
1,048,576
Wrong Answer
18
2,940
98
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
N = int(input()) if N // 2 == 0 : print("{}".format(N//2-1)) else: print("{}".format(N//2))
s071384511
Accepted
18
2,940
94
N = int(input()) if N % 2 == 0 : print("{}".format(N//2-1)) else: print("{}".format(N//2))
s541616385
p02972
u322229918
2,000
1,048,576
Wrong Answer
2,109
51,848
298
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
import numpy as np N = int(input()) As = np.array([0] + list(map(int, input().split()))) res = np.zeros_like(As) for idx, ai in enumerate(As[::-1]): idx = N - idx if idx == 0: break oe = res[::idx].sum() % 2 res[idx] = ai ^ oe print(N) print(" ".join(res[1:].astype(str)))
s632697974
Accepted
516
14,120
305
N = int(input()) As = list(map(int, input().split())) res = [0] * N for idx, ai in zip(range(N-1, -1, -1), As[::-1]): oe = sum([res[i] for i in range(idx, N, idx+1)]) % 2# res[idx] = ai ^ oe print(sum(res)) idxs = [] for i, val in enumerate(res): if val: idxs += [i + 1] print(*idxs)
s252594209
p03612
u797016134
2,000
262,144
Wrong Answer
80
14,008
161
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()) p = list(map(int, input().split())) ans = 0 for i in range(n-1): if i+1 == p[i]: p[i],p[i+1] = p[i+1],p[i] ans += 1 print(ans) print(p)
s541460221
Accepted
71
14,008
183
n = int(input()) p = list(map(int, input().split())) ans = 0 for i in range(n-1): if i+1 == p[i]: p[i],p[i+1] = p[i+1],p[i] ans += 1 if p[-1] == len(p): ans += 1 print(ans)
s685388820
p02262
u508732591
6,000
131,072
Wrong Answer
30
8,096
615
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
import sys import math from collections import deque def insertion_sort(a, n, g): ct = 0 for i in range(g,n): v = a[i] j = i-g while j >= 0 and a[j] > v: a[j+g] = a[j] j = j-g ct += 1 a[j+g] = v return ct n = int(input()) a = list(map(int, sys.stdin.readlines())) b = 701 ct= 0 g = deque([x for x in [701,301,132,57,23,10,1] if x < n]) while True: b = math.floor(2.25*b) if b > n: break g.appendleft(b) for i in g: ct += insertion_sort(a, n, i) print(len(g)) print(*g, sep=" ") print(ct) print(*a, sep="\n")
s467267252
Accepted
10,980
118,484
551
import sys import math ct= 0 def insertion_sort(a, n, g): global ct for j in range(0,n-g): v = a[j+g] while j >= 0 and a[j] > v: a[j+g] = a[j] j = j-g ct += 1 a[j+g] = v n = int(input()) a = list(map(int, sys.stdin.readlines())) b = math.floor(2.25*701) g = [x for x in [1,4,10,23,57,132,301,701] if x <= n] while b<=n: g.append(b) b = math.floor(2.25*b) g = g[::-1] for i in g: insertion_sort(a, n, i) print(len(g)) print(*g, sep=" ") print(ct) print(*a, sep="\n")
s227435789
p03623
u011872685
2,000
262,144
Wrong Answer
29
8,944
244
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|.
data=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z',] s=list(input()) t=sorted(s) i=0 while (t[i]==data[i] and i<25): i=i+1 if i<25: print(data[i]) else: print('None')
s060409598
Accepted
29
9,024
88
x,a,b=map(int,input().split()) if abs(a-x)<abs(b-x): print('A') else: print('B')
s926531852
p03369
u328755070
2,000
262,144
Wrong Answer
17
2,940
44
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
S = list(input()) print(700 + S.count("o"))
s960748935
Accepted
18
3,064
52
S = list(input()) print(700 + S.count("o") * 100)
s023701495
p02678
u700526568
2,000
1,048,576
Wrong Answer
2,206
33,448
607
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
import time start = time.time() # ---------------------------------------- n, m = map(int, input().split()) e = [[] for _ in range(n+1)] for i in range(0, m): a, b = map(int, input().split()) e[a].append(b) e[b].append(a) depth = {1:0} while len(depth) < n: for i in range(2, n+1): if i in depth: continue for v in e[i]: if v in list(depth.keys()) and i not in depth: depth[i] = depth[v] + 1 if time.time() - start > 1.8: break if len(depth) == n: print("yes") sorted_depth = sorted(depth.items(), key=lambda x: x[0]) for i in range(1, n): print(sorted_depth[i][1]) else: print("no")
s613106524
Accepted
647
34,204
498
from collections import deque n, m = map(int, input().split()) e = [[] for _ in range(n+1)] lndmrk = [-1] * (n + 1) for i in range(m): a, b = map(int, input().split()) e[a].append(b) e[b].append(a) q = deque() lndmrk[1] = 0 q.append(1) while(len(q) != 0): v = q.popleft() for i in e[v]: if lndmrk[i] != -1: continue lndmrk[i] = v q.append(i) f = 1 for i in range(2, n+1): if lndmrk[i] == -1: f = 0 if f: print("Yes") for i in range(2, n+1): print(lndmrk[i]) else: print("No")
s085803805
p03730
u040298438
2,000
262,144
Wrong Answer
27
9,084
145
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = map(int, input().split()) for i in range(a, a * b + 1, a): if i % b == c: print("Yes") break else: print("No")
s409029696
Accepted
27
9,072
145
a, b, c = map(int, input().split()) for i in range(a, a * b + 1, a): if i % b == c: print("YES") break else: print("NO")
s142163200
p03609
u519939795
2,000
262,144
Wrong Answer
19
3,060
62
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
s = input() for i in range(0,len(s),2): print(s[i],end="")
s791667421
Accepted
17
2,940
73
x,t=map(int,input().split()) if x-t>=0: print(x-t) else: print(0)
s894833476
p03251
u211160392
2,000
1,048,576
Wrong Answer
17
3,060
200
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()) x = list(map(int,input().split())) y = list(map(int,input().split())) if max(x) < min(y) and (max(x) < Y and min(y) > X): print("War") else: print("No War")
s868718845
Accepted
18
3,060
200
N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) if max(x) < min(y) and (max(x) < Y and min(y) > X): print("No War") else: print("War")
s933775413
p03485
u792856505
2,000
262,144
Wrong Answer
18
2,940
85
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 = [int(i) for i in input().split()] ans = a + b print(math.ceil(ans))
s748567894
Accepted
19
3,188
89
import math a,b = [int(i) for i in input().split()] ans = a + b print(math.ceil(ans / 2))
s266623344
p03693
u422272120
2,000
262,144
Wrong Answer
17
2,940
77
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r,g,b = input().split() print ("Yes") if int(r+g+b)%4 == 0 else print ("No")
s628731041
Accepted
17
2,940
77
r,g,b = input().split() print ("YES") if int(r+g+b)%4 == 0 else print ("NO")
s238433692
p02263
u947762778
1,000
131,072
Wrong Answer
30
7,348
328
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
stack = input().split() for i in stack: if i in ['+', '-', '*']: b, a = stack.pop(), stack.pop() if i == '+': stack.append(b + a) if i == '-': stack.append(b - a) if i == '*': stack.append(b * a) else: stack.append(i) print(stack.pop())
s501210874
Accepted
20
7,720
338
inList = input().split() stack = [] for i in inList: if i in ['+', '-', '*']: b, a = stack.pop(), stack.pop() if i == '+': stack.append(b + a) if i == '-': stack.append(a - b) if i == '*': stack.append(b * a) else: stack.append(int(i)) print(stack.pop())
s965153225
p04029
u434630332
2,000
262,144
Wrong Answer
32
9,036
57
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) answer = (n + 1) * n / 2 print(answer)
s150665520
Accepted
22
9,100
44
n = int(input()) print(int((n + 1) * n / 2))
s522226828
p03659
u260764548
2,000
262,144
Wrong Answer
2,104
24,832
401
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
# -*- coding:utf-8 -*- N = int(input()) a = list(map(int,input().split())) SUM_CARD = sum(a) print(SUM_CARD) i=1 diff_sum = 0 sunuke = sum(a[0:i]) diff_sum = abs(sunuke*2-SUM_CARD) i+=1 while(i<N): sunuke = sum(a[0:i]) print(sunuke) diff_sum_new = abs(sunuke*2-SUM_CARD) print(diff_sum_new) if diff_sum_new<diff_sum: diff_sum = diff_sum_new i += 1 print(diff_sum)
s040038992
Accepted
187
24,832
347
# -*- coding:utf-8 -*- N = int(input()) a = list(map(int,input().split())) SUM_CARD = sum(a) i=0 sum_before = a[i] diff_sum = abs(sum_before*2-SUM_CARD) i+=1 while(i<N-1): sum_before = sum_before + a[i] diff_sum_new = abs(sum_before*2-SUM_CARD) if diff_sum_new<diff_sum: diff_sum = diff_sum_new i += 1 print(diff_sum)
s758415443
p03455
u741261352
2,000
262,144
Wrong Answer
18
2,940
83
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) r = 'Odd' if (a * b % 2) == 0 else 'Even' print(r)
s901027654
Accepted
17
2,940
83
a, b = map(int, input().split()) r = 'Even' if (a * b % 2) == 0 else 'Odd' print(r)
s381305146
p03024
u136090046
2,000
1,048,576
Wrong Answer
17
2,940
55
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() print("YES" if s.count("o") >= 8 else "NO")
s494290582
Accepted
17
2,940
68
s = input() print("YES" if s.count("o") + 15-len(s) >= 8 else "NO")
s255747997
p03475
u561870477
3,000
262,144
Wrong Answer
72
3,060
286
A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
n = int(input()) l = [list(map(int, input().split())) for _ in range(n-1)] ans = [0]*n for i in range(n): time = 0 for j in range(i, n-1): if l[j][1] - time > 0: time += l[j][1] - time time += time % l[j][2] + l[j][0] ans[i] += time print(ans)
s570021820
Accepted
113
3,188
362
n = int(input()) l = [list(map(int, input().split())) for _ in range(n-1)] ans = [0]*n for i in range(n): time = 0 for j in range(i, n-1): if l[j][1] - time > 0: time += l[j][1] - time if time % l[j][2] != 0: time += l[j][2] - time % l[j][2] time += l[j][0] ans[i] += time for i in ans: print(i)
s425238380
p03129
u589881693
2,000
1,048,576
Wrong Answer
17
3,060
86
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
a,b = map(int, input().split(" ")) if (a-1)//b >=2: print("YES") else: print("NO")
s324314634
Accepted
18
2,940
122
a,b = map(int, input().split(" ")) b = b -1 if b==0: print("YES") elif (a-1)//b >=2: print("YES") else: print("NO")