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
s668608974
p02842
u403331159
2,000
1,048,576
Wrong Answer
17
2,940
122
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()) ans=math.ceil(n/1.08) print(ans*1.08) if int(ans*1.08)==n: print(ans) else: print(":(")
s511403149
Accepted
17
2,940
106
import math n=int(input()) ans=math.ceil(n/1.08) if int(ans*1.08)==n: print(ans) else: print(":(")
s482171969
p03997
u668503853
2,000
262,144
Wrong Answer
17
2,940
61
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)/2*2)
s541829934
Accepted
17
2,940
62
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h//2)
s009605684
p03695
u154756110
2,000
262,144
Wrong Answer
17
2,940
116
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
N=int(input()) A=list(map(int,input().split())) cnt=0 for i in range(N): if(A[i]>=3200): cnt+=1 print(N-cnt,N)
s926547992
Accepted
17
3,060
198
N=int(input()) A=list(map(int,input().split())) cnt=0 X=set() for i in range(N): if(A[i]>=3200): cnt+=1 else: X.add(A[i]//400) if(len(X)): print(len(X),len(X)+cnt) else: print(1,cnt)
s665477552
p02659
u973972117
2,000
1,048,576
Wrong Answer
23
9,084
55
Compute A \times B, truncate its fractional part, and print the result as an integer.
A,B=map(float,input().split()) C=(A*B*10)//10 print(C)
s050532102
Accepted
27
9,064
103
A,B = map(str,input().split()) A = int(A) B = int(B[0])*100+int(B[2])*10+int(B[3]) print(int(A*B//100))
s897697193
p00100
u040533857
1,000
131,072
Wrong Answer
50
6,788
421
There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID _i_ , the amount of sales _q_ and the corresponding unit price _p_. Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p × q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that _n_ < 4000, and each employee has an unique ID. The unit price _p_ is less than or equal to 1,000,000 and the amount of sales _q_ is less than or equal to 100,000.
while True: try: n=int(input()) except: break if n==0: break data=[] for i in range(n): spam=[x for x in map(int,input().split())] if spam[1]*spam[2]>=1000000: if (spam[0] in [b[0] for b in data])==False: data.append(spam) if len(data)==0: print('NA') else: for i in [b[0] for b in data]: print(i)
s499182252
Accepted
40
6,748
505
while True: try: n=int(input()) except: break if n==0: break data={} staff=[] for i in range(n): spam=list(map(int,input().split())) if spam[0] in data.keys(): data[spam[0]]+=spam[1]*spam[2] else: data[spam[0]]=spam[1]*spam[2] staff.append(spam[0]) if max(data.values())<1000000: print('NA') else: for i in staff: if data[i] >= 1000000: print(i)
s483528794
p03377
u382431597
2,000
262,144
Wrong Answer
17
2,940
71
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=list(map(int, input().split())) print("YES" if (x-a)>b else "NO")
s459094454
Accepted
17
2,940
75
a,b,x=list(map(int, input().split())) print("YES" if 0<=(x-a)<=b else "NO")
s736904857
p03827
u220345792
2,000
262,144
Wrong Answer
17
2,940
98
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
N = int(input()) S = input() plus_ = S.count("I") minus_ = S.count("D") print(max(plus_-minus_,0))
s456867298
Accepted
18
2,940
147
N = int(input()) S = input() tmp = 0 ans = 0 for i in S: if i == "I": tmp += 1 elif i == "D": tmp -= 1 ans = max(ans, tmp) print(ans)
s142810194
p03079
u163449343
2,000
1,048,576
Wrong Answer
17
2,940
64
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
a, b, c = input().split() print("YNeos"[(a == b and b == c)::2])
s152664185
Accepted
18
2,940
67
a, b, c = input().split() print(["No", "Yes"][(a == b and b == c)])
s452654153
p03352
u294385082
2,000
1,048,576
Wrong Answer
17
3,060
239
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
x = int(input()) l = [1] for i in range(2,32): for j in range(1,10): if i**j <= 1000: l.append(i**j) l = sorted(l,reverse = True) for k in sorted(list(range(1,x+1)),reverse = True): if k in l: print(k) exit()
s037877147
Accepted
18
3,060
239
x = int(input()) l = [1] for i in range(2,32): for j in range(2,10): if i**j <= 1000: l.append(i**j) l = sorted(l,reverse = True) for k in sorted(list(range(1,x+1)),reverse = True): if k in l: print(k) exit()
s726057899
p03455
u708255304
2,000
262,144
Wrong Answer
17
2,940
86
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if a*b % 2 == 0: print("Eveb") else: print("Odd")
s181742844
Accepted
17
2,940
86
a, b = map(int, input().split()) if a*b % 2 == 0: print("Even") else: print("Odd")
s915939551
p03434
u048945791
2,000
262,144
Wrong Answer
17
2,940
163
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() ans = 0 for i in range(len(a)): if i % 2 == 0: ans += a[i] else: ans -= a[i] print(ans)
s850790990
Accepted
17
3,060
175
n = int(input()) a = list(map(int, input().split())) a.sort() a.reverse() ans = 0 for i in range(len(a)): if i % 2 == 0: ans += a[i] else: ans -= a[i] print(ans)
s640906774
p04012
u771756419
2,000
262,144
Wrong Answer
18
2,940
180
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
w = list(input()) alp = list("abcdefghijklmnopqrstuvwxyz") ans = 0 for i in alp: if w.count(i) % 2 != 0 : ans += 1 if ans == 0: print("YES") else: print("NO")
s167540707
Accepted
18
2,940
180
w = list(input()) alp = list("abcdefghijklmnopqrstuvwxyz") ans = 0 for i in alp: if w.count(i) % 2 != 0 : ans += 1 if ans == 0: print("Yes") else: print("No")
s656533168
p03854
u479977918
2,000
262,144
Wrong Answer
20
4,276
613
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
# -*- coding: utf-8 -*- import sys S = input() five_sign1 = "dream" five_sign2 = "erase" six_sign = "eraser" sevent_sign = "dreamer" while(len(S) > 0): print("S {}".format(S)) if S[0:6] == "eraser": S = S[6:] elif S[0:5] == "erase": S = S[5:] elif S[0:5] == "dream": tmp = S[5:8] if len(tmp) == 0: S = S[5:] continue elif tmp == "era": S = S[5:] elif tmp == "erd": S = S[7:] else: print("NO") sys.exit() else: print("NO") sys.exit() print("YES")
s431715353
Accepted
76
3,316
547
# -*- coding: utf-8 -*- import sys S = input() while(len(S) > 0): if S[0:6] == "eraser": S = S[6:] elif S[0:5] == "erase": S = S[5:] elif S[0:5] == "dream": tmp = S[5:8] if len(tmp) == 0: S = S[5:] elif tmp == "era": S = S[5:] elif tmp == "er": S = S[7:] elif tmp == "ere": S = S[7:] elif tmp == "erd": S = S[7:] else: S = S[5:] else: print("NO") sys.exit() print("YES")
s218310167
p02612
u514969825
2,000
1,048,576
Wrong Answer
26
9,136
118
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()) for i in range(1, 12): if (N >= i*1000): continue else: print(N - (i-1)*1000) break
s505912477
Accepted
28
9,120
113
N = int(input()) for i in range(1, 12): if (i*1000 < N): continue else: print(i*1000 - N) break
s515448408
p04043
u434311880
2,000
262,144
Wrong Answer
17
3,060
180
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
A, B, C = map(int,input().split()) if A == 5 and B == C == 7: print("YES") elif A==B==7 and C==5: print("YES") elif A==C==7 and B==5: print("YES") else: print("NO")
s595752428
Accepted
17
2,940
181
A, B, C = map(int,input().split()) if A == 7 and B == C == 5: print("YES") elif A==B==5 and C==7: print("YES") elif A==C==5 and B==7: print("YES") else: print("NO")
s564994962
p03970
u727787724
2,000
262,144
Wrong Answer
17
2,940
111
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
s=list(input()) a=list('CODEFESTIVAL2016') ans=0 for i in range(len(s)): if s[i]==a[i]: ans+=1 print(ans)
s076849324
Accepted
17
2,940
112
s=list(input()) a=list('CODEFESTIVAL2016') ans=0 for i in range(len(s)): if s[i]!=a[i]: ans+=1 print(ans)
s051476887
p02612
u969081133
2,000
1,048,576
Wrong Answer
29
9,148
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N=int(input()) a=N%1000 print(a)
s178035563
Accepted
28
9,164
65
N=int(input()) a=N%1000 if a==0: print(0) else: print(1000-a)
s047231500
p03455
u622011073
2,000
262,144
Wrong Answer
23
3,188
65
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=input().split();a=int(a+b)**.5 print(['No','Yes'][a==int(a)])
s903116366
Accepted
18
2,940
57
a,b=map(int,input().split()) print(['Even','Odd'][a*b&1])
s999386292
p02476
u861198832
1,000
262,144
Wrong Answer
20
5,580
44
Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$.
a,b = map(int,input().split()) print(a//b)
s124399531
Accepted
20
5,584
43
a,b = map(int,input().split()) print(a%b)
s452565543
p03379
u411858517
2,000
262,144
Wrong Answer
396
20,884
155
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
N = int(input()) arr = input().split() arr.sort() for i in range(N): if i < N/2: print(arr[int(N/2-1)]) else: print(arr[int(N/2)])
s745831822
Accepted
391
25,620
199
N = int(input()) arr = list(map(int, input().split())) X = arr.copy() arr.sort() for i in range(N): if X[i] < arr[int(N/2)]: print(arr[int(N/2)]) else: print(arr[int(N/2)-1])
s308663713
p03555
u320511454
2,000
262,144
Wrong Answer
35
9,080
65
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.
s,t=input(),input() print("Yes") if s == t[::-1] else print("No")
s249560696
Accepted
29
9,056
65
s,t=input(),input() print("YES") if s == t[::-1] else print("NO")
s583243061
p02388
u830616709
1,000
131,072
Wrong Answer
20
7,724
29
Write a program which calculates the cube of a given integer x.
(lambda x:x**3)(int(input()))
s349525481
Accepted
20
7,648
41
print(str((lambda x:x**3)(int(input()))))
s757776373
p04012
u974935538
2,000
262,144
Wrong Answer
20
3,316
184
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
import collections w = list(input()) tmp = collections.Counter(w) ans = "YES" for i in tmp.values(): if i%2 != 0: ans = "NO" break else: pass print(ans)
s040824499
Accepted
20
3,316
184
import collections w = list(input()) tmp = collections.Counter(w) ans = "Yes" for i in tmp.values(): if i%2 != 0: ans = "No" break else: pass print(ans)
s718486331
p03377
u315838013
2,000
262,144
Wrong Answer
21
3,316
227
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.
import sys if __name__ == "__main__": A, B, X = list(map(int, (input().split(' ')))) buf = X - A if buf < 0: print('No') sys.exit() if buf <= B: print('Yes') else: print('No')
s466937545
Accepted
17
2,940
227
import sys if __name__ == "__main__": A, B, X = list(map(int, (input().split(' ')))) buf = X - A if buf < 0: print('NO') sys.exit() if buf <= B: print('YES') else: print('NO')
s417070315
p03386
u027403702
2,000
262,144
Wrong Answer
2,237
4,084
156
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A,B,K = map(int, input().split()) List = [i for i in range(A,B+1)] s = List[0:K] r = List[::-1] l = r[0:K] for i in l: s.append(i) print(sorted(set(s)))
s422848482
Accepted
18
3,188
249
A,B,K = map(int, input().split()) if B-A+1 >= K: s = [i for i in range(A,A+K)] l = [j for j in range(B-K+1,B+1)] for k in l: s.append(k) w = sorted(set(s)) else: w = [b for b in range(A,B+1)] for j in w: print(j)
s876814453
p03479
u831752983
2,000
262,144
Wrong Answer
17
2,940
77
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
x,y=map(int,input().split()) n=y//x ct=0 while n>1: ct+=1 n//=2 print(ct)
s089908774
Accepted
17
3,064
77
x,y=map(int,input().split()) n=y//x ct=0 while n>0: n//=2 ct+=1 print(ct)
s106917073
p02612
u398511319
2,000
1,048,576
Wrong Answer
30
8,956
76
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= input() x=int(N) while True: x -= 1000 if x <= 1000: break print(x)
s148433142
Accepted
28
9,084
204
N= input() x=int(N) if x<1000: print(1000-x) if x==1000: print(0) if x > 1000: while True: x -= 1000 if x < 1001: break print(1000-x)
s014180113
p02396
u096070545
1,000
131,072
Wrong Answer
20
5,592
234
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.
# coding: utf-8 # Your code here! # TP1_3_B # N=input() # print(N) N=-1 # while N != 0: # N=int(input()) # print(N) for i in range(1,100): N=int(input()) if N == 0: break print('Case {0}:{1}'.format(i,N))
s841453972
Accepted
140
5,600
237
# coding: utf-8 # Your code here! # TP1_3_B # N=input() # print(N) N=-1 # while N != 0: # N=int(input()) # print(N) for i in range(1,10001): N=int(input()) if N == 0: break print('Case {0}: {1}'.format(i,N))
s048236676
p03999
u210827208
2,000
262,144
Wrong Answer
28
3,188
240
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
import itertools s=input() C=['+',''] X=list(itertools.product(C,repeat=len(s)-1)) print(X) ans=0 for i in range(len(X)): res='' for j in range(len(s)-1): res+=s[j]+X[i][j] res+=s[len(s)-1] ans+=eval(res) print(ans)
s587573799
Accepted
27
3,064
231
import itertools s=input() C=['+',''] X=list(itertools.product(C,repeat=len(s)-1)) ans=0 for i in range(len(X)): res='' for j in range(len(s)-1): res+=s[j]+X[i][j] res+=s[len(s)-1] ans+=eval(res) print(ans)
s150481217
p02271
u436634575
5,000
131,072
Wrong Answer
30
6,716
304
Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
n = int(input()) a = list(map(int, input().strip().split())) q = int(input()) M = list(map(int, input().strip().split())) d = [] for x in range(1 << n): b = '{:0{}b}'.format(x, n) print(b) d.append(sum(a[i] for i in range(n) if b[i] == '1')) for m in M: print('yes' if m in d else 'no')
s767556639
Accepted
9,940
44,760
291
n = int(input()) a = list(map(int, input().strip().split())) q = int(input()) M = list(map(int, input().strip().split())) d = [] for x in range(1 << n): b = '{:0{}b}'.format(x, n) d.append(sum(a[i] for i in range(n) if b[i] == '1')) for m in M: print('yes' if m in d else 'no')
s863959408
p03861
u175590965
2,000
262,144
Wrong Answer
2,107
2,940
107
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x = map(int,input().split()) ans = 0 for i in range(a,b): if i % x ==0: ans += 1 print(ans)
s654620461
Accepted
17
2,940
58
a,b,x = map(int,input().split()) print((b//x)-((a-1)//x))
s773462425
p03997
u557235596
2,000
262,144
Wrong Answer
23
3,064
110
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
if __name__ == "__main__": a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s485814672
Accepted
22
3,064
116
if __name__ == "__main__": a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h/2))
s474471861
p02415
u313600138
1,000
131,072
Wrong Answer
20
5,548
155
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
s=input() for c in s: if 'A' <= c and c <= 'Z': print(c.lower(), end='') elif 'a' <= c and c <= 'z': print(c.upper(), end='') else: pass
s191492663
Accepted
20
5,716
174
s=input() for c in s: if 'A' <= c and c <= 'Z': print(c.lower(), end='') elif 'a' <= c and c <= 'z': print(c.upper(), end='') else: print(c,end='') print()
s332167162
p03433
u624923345
2,000
262,144
Wrong Answer
17
2,940
146
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()) a = N % 500 if a == 0: print("yes") else: if a <= A: print("yes") else: print("no")
s344586063
Accepted
17
2,940
146
N = int(input()) A = int(input()) a = N % 500 if a == 0: print("Yes") else: if a <= A: print("Yes") else: print("No")
s003191077
p03575
u048004795
2,000
262,144
Wrong Answer
35
9,432
721
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.
from collections import deque N, M = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(M)] c = 0 print(ab) for i in range(M): G = [[] for _ in range(N)] for j in range(M): if i == j: continue a, b = ab[j][0], ab[j][1] G[a - 1].append(b - 1) G[b - 1].append(a - 1) Q = deque() Q.append(0) d = [0] * N d[0] = 1 while Q: q = Q.popleft() for g in G[q]: if d[g] == 0: d[g] = 1 Q.append(g) if 0 in d: c += 1 print(c)
s377598804
Accepted
33
9,480
711
from collections import deque N, M = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(M)] c = 0 for i in range(M): G = [[] for _ in range(N)] for j in range(M): if i == j: continue a, b = ab[j][0], ab[j][1] G[a - 1].append(b - 1) G[b - 1].append(a - 1) Q = deque() Q.append(0) d = [0] * N d[0] = 1 while Q: q = Q.popleft() for g in G[q]: if d[g] == 0: d[g] = 1 Q.append(g) if 0 in d: c += 1 print(c)
s732208793
p02255
u971076135
1,000
131,072
Wrong Answer
20
5,604
393
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.
from sys import stdin def stdinput(): return stdin.readline().strip() def main(): n = int(stdinput()) a = list(map(int, stdinput().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))) if __name__ == '__main__': main()
s653572410
Accepted
20
5,608
393
from sys import stdin def stdinput(): return stdin.readline().strip() def main(): n = int(stdinput()) a = list(map(int, stdinput().split())) for i in range(0, 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))) if __name__ == '__main__': main()
s857786720
p03469
u947327691
2,000
262,144
Wrong Answer
18
2,940
24
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
s=input() s="2018"+s[:4]
s191495797
Accepted
17
2,940
33
s=input() s="2018"+s[4:] print(s)
s592239424
p02397
u623827446
1,000
131,072
Wrong Answer
50
7,664
116
Write a program which reads two integers x and y, and prints them in ascending order.
for i in range(3000): x,y=map(int,input().split()) if x == 0 and y == 0: break print('{0} {1}'.format(x,y))
s857620497
Accepted
50
7,572
131
for i in range(3000): x,y=map(int,input().split()) if x == 0 and y == 0: break print('{0} {1}'.format(min(x,y),max(x,y)))
s331772608
p03644
u217627525
2,000
262,144
Time Limit Exceeded
2,104
2,940
59
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n=int(input()) ans=1 while(ans<=n): ans*2 print(ans//2)
s766301270
Accepted
17
2,940
59
n=int(input()) ans=1 while ans<=n: ans*=2 print(ans//2)
s595582834
p03643
u404459933
2,000
262,144
Wrong Answer
17
2,940
59
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
import math N=int(input()) L=int(math.log(N,2)) print(2**L)
s973153943
Accepted
17
2,940
20
print('ABC'+input())
s682706313
p03433
u353797797
2,000
262,144
Wrong Answer
18
2,940
224
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline int1 = lambda x: int(x) - 1 def main(): n=int(input()) a=int(input()) if a<=n%500: print("Yes") else: print("No") main()
s711845983
Accepted
18
2,940
224
import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline int1 = lambda x: int(x) - 1 def main(): n=int(input()) a=int(input()) if a>=n%500: print("Yes") else: print("No") main()
s263618180
p03958
u785578220
1,000
262,144
Wrong Answer
17
3,060
158
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
k,t =map(int,input().split()) a = list(map(int,input().split())) a.append(0) a.sort() t = a[-1] s = sum(a[:-1]) if t == 1: print(t-1) else: print(t-s)
s939497099
Accepted
17
3,060
185
k,f =map(int,input().split()) a = list(map(int,input().split())) a.append(0) a.sort() t = a[-1] s = sum(a[:-1]) if 1 == f: print(t-1) elif t<=s: print(0) else: print(t-s-1)
s646036033
p03007
u186967328
2,000
1,048,576
Wrong Answer
2,104
14,264
175
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
N = int(input()) A = list(map(int,input().split())) A = sorted(A) for i in range(N-1): print(A[0],A[-1]) diff = A[0]-A[-1] A = A[1:len(A)-1] A.insert(0,diff)
s329933759
Accepted
260
14,144
528
N = int(input()) A = list(map(int,input().split())) A = sorted(A) plus = [] minus = [] for i in range(N): if i == 0: minus.append(A[i]) elif i == N-1: plus.append(A[i]) else: if A[i] > 0: plus.append(A[i]) else: minus.append(A[i]) print(sum(plus)-sum(minus)) tmp = minus[0] for i in range(len(plus)-1): print(tmp,plus[i]) tmp -= plus[i] minus[0] = tmp tmp2 = plus[-1] for i in range(len(minus)): print(tmp2,minus[i]) tmp2 -= minus[i]
s871614633
p03854
u832871520
2,000
262,144
Wrong Answer
269
4,080
430
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
div = ['maerd', 'remaerd', 'esare', 'resare'] s = input() rs = ''.join(list(reversed(s))) can1 = True cnt = 0 for i in range(len(s)): if cnt != 0: cnt -= 1 continue print(i) can2 = False for d in range(len(div)): if (rs.find(div[d])) == i: can2 = True cnt = len(div[d]) -1 if can2 == False: can1 = False if can1: print('Yes') else: print('No')
s696685371
Accepted
23
6,516
87
import re print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "NO")
s177549471
p04044
u953753178
2,000
262,144
Wrong Answer
17
2,940
92
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
A = list(map(str, input().split())) A.sort() res = '' for a in A: res += a print(res)
s133660042
Accepted
17
3,060
183
N, L = list(map(int, input().split())) input_str_list = [] for input_str_index in range(N): input_str_list.append(input()) input_str_list.sort() print(''.join(input_str_list))
s197827344
p03795
u953794676
2,000
262,144
Wrong Answer
18
2,940
64
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
e = int(input()) print(int(e/15)) print(e*800 - (int(e/15)*200))
s522719249
Accepted
17
2,940
47
e = int(input()) print(e*800 - (int(e/15)*200))
s651512167
p03387
u235905557
2,000
262,144
Wrong Answer
17
2,940
296
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
a, b, c = map(int, input().split()) M = max(a, max(b, c)) if (a+b+c)%2 == 1: X = M else: X = M + 1 print((3*X - (a+b+c)) / 2)
s436088851
Accepted
17
2,940
278
a, b, c = map(int, input().split()) X = 0 M = max(a, max(b, c)) if (3*M)%2 == (a+b+c)%2: X = M else: X = M + 1 print(int((3*X - (a+b+c)) / 2))
s908746328
p02612
u898109279
2,000
1,048,576
Wrong Answer
27
9,128
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n % 1000)
s266258121
Accepted
28
9,136
88
n = int(input()) oturi = n % 1000 if (oturi == 0): print(0) else: print(1000 - oturi)
s469741578
p02612
u248364740
2,000
1,048,576
Wrong Answer
32
9,144
99
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.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n = int(input()) result = n % 1000 print(result)
s934877537
Accepted
29
9,144
51
n = int(input()) print((1000 - (n % 1000)) % 1000)
s450152090
p02401
u316246166
1,000
131,072
Wrong Answer
20
5,592
150
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
for i in range(1000): a, b, c = input().split() if b == '?': break a = int(a) c = int(c) print(a, b, c)
s724109369
Accepted
20
5,596
252
for i in range(1000): a, b, c = input().split() if b == '?': break a = int(a) c = int(c) if b == '+': print(a + c) if b == '-': print(a - c) if b == '*': print(a * c) if b == '/': print(a // c)
s799175798
p03712
u503111914
2,000
262,144
Wrong Answer
18
3,060
106
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
H,W = map(int,input().split()) print("#"*W) for i in range(H-2): print("#" + input() + "#") print("#"*W)
s742762100
Accepted
18
3,060
113
H,W = map(int,input().split()) print("#"*(W+2)) for i in range(H): print("#" + input() + "#") print("#"*(W+2))
s689677256
p03564
u119982147
2,000
262,144
Wrong Answer
17
2,940
61
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
N = int(input()) K = int(input()) A = 1 + ( N * K ) print(A)
s872627539
Accepted
17
2,940
177
N = int(input()) K = int(input()) number = 1 for i in range(N): if number * 2 < number + K: number = number * 2 else: number = number + K print(number)
s193413734
p03597
u799428010
2,000
262,144
Wrong Answer
17
2,940
52
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
N = int(input()) A = int(input()) B=N*N-A*A print(B)
s729727196
Accepted
17
2,940
50
N = int(input()) A = int(input()) B=N*N-A print(B)
s730550124
p03944
u853586331
2,000
262,144
Wrong Answer
17
3,064
230
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
W,H,N=map(int, input().split()) b=0 c=W d=0 e=H for i in range(N): x,y,a=map(int, input().split()) if a==1: b==max(b,x) elif a==2: c==min(c,x) elif a==3: d==max(d,y) else: e==min(e,y) print(max(0,(c-b))*max(0,(e-d)))
s266667890
Accepted
18
3,064
225
W,H,N=map(int, input().split()) w=0 h=0 for i in range(N): x,y,a=map(int, input().split()) if a==1: w=max(w,x) elif a==2: W=min(W,x) elif a==3: h=max(h,y) else: H=min(H,y) print(max(0,(W-w))*max(0,(H-h)))
s125129397
p03997
u482969053
2,000
262,144
Wrong Answer
19
3,060
51
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
print((int(input())+int(input()))+int(input())//2)
s575157650
Accepted
16
2,940
50
print((int(input())+int(input()))*int(input())//2)
s422891514
p03044
u367130284
2,000
1,048,576
Wrong Answer
647
9,604
2,084
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.
class POTENTIAL_UNION_FIND(object): def __init__(self, n): self.parent = [-1 for i in range(n)] self.diff_p = [0 for i in range(n)] def root(self, x): if self.parent[x] < 0: return x else: rx = self.root(self.parent[x]) self.diff_p[x] += self.diff_p[self.parent[x]] self.parent[x] = rx return rx def size(self,x): return -self.parent[self.root(x)] def merge(self, x, y, dxy): rx = self.root(x) ry = self.root(y) dxy += self.diff_p[x] - self.diff_p[y] x,y=rx,ry if x == y: return False if self.parent[x] > self.parent[y]: x,y,dxy=y,x,-dxy self.parent[x] += self.parent[y] self.parent[y] = x self.diff_p[y] = dxy return True def issame(self, x, y): return self.root(x) == self.root(y) def diff(self,x,y): if self.root(x) == self.root(y): return self.diff_p[y] - self.diff_p[x] else: return None n=int(input()) u=POTENTIAL_UNION_FIND(n) for i in range(n-1): a,b,c=map(int,input().split()) u.merge(a-1,b-1,c) for i in u.diff_p: if i%2==0: print(1) else: print(0)
s456475283
Accepted
876
10,252
2,050
class POTENTIAL_UNION_FIND(object): def __init__(self, n): self.parent = [-1 for i in range(n)] self.diff_p = [0 for i in range(n)] def root(self, x): if self.parent[x] < 0: return x else: rx = self.root(self.parent[x]) self.diff_p[x] += self.diff_p[self.parent[x]] self.parent[x] = rx return rx def size(self,x): return -self.parent[self.root(x)] def merge(self, x, y, dxy): rx = self.root(x) ry = self.root(y) dxy += self.diff_p[x] - self.diff_p[y] x,y=rx,ry if x == y: return False if self.parent[x] > self.parent[y]: x,y,dxy=y,x,-dxy self.parent[x] += self.parent[y] self.parent[y] = x self.diff_p[y] = dxy return True def issame(self, x, y): return self.root(x) == self.root(y) def diff(self,x,y): if self.root(x) == self.root(y): return self.diff_p[y] - self.diff_p[x] else: return None n=int(input()) u=POTENTIAL_UNION_FIND(n) for i in range(n-1): a,b,c=map(int,input().split()) u.merge(a-1,b-1,c) for i in range(n): print(u.diff(0,i)%2)
s860850942
p03048
u027076164
2,000
1,048,576
Wrong Answer
2,104
3,060
233
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
R,G,B,N = map(int, input().split()) c = 0 for i in range(int(N/R)): for j in range(int((N-R*i)/G)): for k in range(int((N-R*i-G*j)/B)): if N-R*i-G*j-B*k-int(N-R*i-G*j-B*k) == 0: c += 1 print(c)
s530727503
Accepted
1,489
2,940
171
R,G,B,N = map(int, input().split()) c = 0 for i in range(0,int(N/R)+1): for j in range(0,int((N-R*i)/G)+1): if (N-R*i-G*j)%B == 0: c += 1 print(c)
s006268363
p03780
u817328209
2,000
262,144
Time Limit Exceeded
2,104
6,896
560
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
import sys N, K = map(int, input().split()) a = list(map(int, input().split())) def isNecessary(now) : psum = 0 for i in range(N) : if i == now : continue psum += a[i] if psum >= K : return False else : return True S = sum(a) ans = 0 a = sorted(a, reverse=True) l, r = 0, N-1 now = N//2 while True : if isNecessary(now) : r = now else : l = now now = (l+r)//2 if r == l : if N==1 and a[0]<K : print(1) else : print(r)
s581091554
Accepted
21
3,572
223
N, K = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) ans = N psum = 0 for i in range(N-1, -1, -1) : if psum+a[i] < K : psum += a[i] else : ans = min(ans, i) print(ans)
s742805115
p03433
u721316601
2,000
262,144
Wrong Answer
17
2,940
90
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) A = int(input()) if N % 500 == A: print('Yes') else: print('No')
s883660559
Accepted
17
2,940
91
N = int(input()) A = int(input()) if N % 500 <= A: print('Yes') else: print('No')
s450069095
p02266
u874395007
1,000
131,072
Wrong Answer
20
5,560
359
Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively.
lines = input() stack_1 = [] area = 0 for i, line in enumerate(lines): if line == '\\': stack_1.append(i) elif line == '_': pass elif line == '/': if not stack_1 == []: this_area = i - stack_1.pop() area += this_area else: raise ValueError('Unexpected line: {i}, {line}') print(area)
s568101207
Accepted
30
6,216
1,055
lines = input() stack_1 = [] stack_2 = [] area = 0 for i, line in enumerate(lines): if line == '\\': stack_1.append(i) elif line == '_': pass elif line == '/': if stack_1 == []: continue last_index = stack_1.pop() this_area = i - last_index area += this_area if stack_2 == []: stack_2.append((last_index, this_area)) continue block_area = this_area while True: if stack_2 == []: break stack_2_index, stack_2_area = stack_2.pop() if stack_2_index < last_index: stack_2.append((stack_2_index, stack_2_area)) break else: block_area += stack_2_area stack_2.append((last_index, block_area)) print(area) kazu = len(stack_2) kaku_menseki = [stack_2[i][1] for i in range(len(stack_2))] kaku_menseki_out = ' '.join(map(str, kaku_menseki)) if kazu > 0: print(f'{kazu} {kaku_menseki_out}') else: print(f'{kazu}')
s429228934
p04030
u810457760
2,000
262,144
Wrong Answer
18
2,940
94
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
S = input() ans = "" for i in S: if i == "B": S = S[:-1] else: ans += i print(ans)
s110562910
Accepted
17
2,940
98
S = input() ans = "" for i in S: if i == "B": ans = ans[:-1] else: ans += i print(ans)
s204066477
p03588
u855200003
2,000
262,144
Wrong Answer
328
17,892
197
A group of people played a game. All players had distinct scores, which are positive integers. Takahashi knows N facts on the players' scores. The i-th fact is as follows: the A_i-th highest score among the players is B_i. Find the maximum possible number of players in the game.
N = int(input()) dic = {} for i in range(N): a,b = [int(j) for j in input().split(" ")] dic[a] = b ans = len(dic) max_keys = max(dic.keys()) min_value = dic[max_keys] print(ans + min_value)
s192483940
Accepted
328
17,892
185
N = int(input()) dic = {} for i in range(N): a,b = [int(j) for j in input().split(" ")] dic[a] = b max_keys = max(dic.keys()) min_value = dic[max_keys] print(max_keys+min_value)
s249705459
p02606
u248670151
2,000
1,048,576
Wrong Answer
29
9,156
115
How many multiples of d are there among the integers between L and R (inclusive)?
a=list(map(int,input().split())) count=0 for i in range(a[0],a[1]): if i%a[2]==0: count+=1 print(count)
s124115846
Accepted
30
9,084
130
a=list(map(int,input().split())) count=0 for i in range(a[0],a[1]+1): if i%a[2]==0: count+=1 print(count)
s342188029
p03351
u598229387
2,000
1,048,576
Wrong Answer
17
2,940
104
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d = map(int, input().split()) print('YES' if abs(a-c)<=d or abs(a-b)<=d and abs(b-c)<=d else 'No')
s591000014
Accepted
17
2,940
104
a,b,c,d = map(int, input().split()) print('Yes' if abs(a-c)<=d or abs(a-b)<=d and abs(b-c)<=d else 'No')
s134255158
p03836
u276115223
2,000
262,144
Wrong Answer
28
9,100
331
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
# ABC 051: C – Back and Forth sx, sy, tx, ty = [int(i) for i in input().split()] dx = tx - sx dy = ty - sy # r1 r1 = 'U' * (dy + 1) + 'R' * (dx + 1) # r2 r2 = 'D' * (dy + 1) + 'L' * (dx + 1) # r3 r3 = 'L' + 'U' * (dy + 2) + 'R' * (dx + 2) + 'D' # r4 r4 = 'R' + 'D' * (dy + 2) + 'L' * (dx + 2) + 'U' print(r1 + r2 + r3 + r4)
s670003353
Accepted
26
9,024
307
# ABC 051: C – Back and Forth sx, sy, tx, ty = [int(i) for i in input().split()] dx = tx - sx dy = ty - sy # r1 r1 = 'U' * dy + 'R' * dx # r2 r2 = 'D' * dy + 'L' * dx # r3 r3 = 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D' # r4 r4 = 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U' print(r1 + r2 + r3 + r4)
s895424128
p03400
u225388820
2,000
262,144
Wrong Answer
17
2,940
102
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
n=int(input()) d,x=map(int,input().split()) for i in range(n): a=int(input()) x+=(d-1)//a print(x)
s527460058
Accepted
17
2,940
104
n=int(input()) d,x=map(int,input().split()) for i in range(n): a=int(input()) x+=(d-1)//a+1 print(x)
s494490228
p02468
u567380442
1,000
131,072
Wrong Answer
30
6,724
279
For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M.
def power(m, n): if n == 1: return m div = 1000000007 ret = power(m * m, n // 2) % div if n % 2: ret %= div return ret from sys import stdin readline = stdin.readline m, n = map(int, readline().split()) print(power(m, n))
s260959541
Accepted
30
6,728
220
def power(m, n): if n:return power(m * m % 1000000007, n // 2) * (m if n % 2 else 1) % 1000000007 return 1 from sys import stdin readline = stdin.readline m, n = map(int, readline().split()) print(power(m, n))
s070270683
p02612
u459521923
2,000
1,048,576
Wrong Answer
28
8,836
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 = 111200 n2 = str(n)[-3:] ans = 1000 - int(n2) print(ans)
s796849987
Accepted
28
9,160
135
# -*- coding: utf-8 -*- n = int(input()) n2 = str(n)[-3:] if int(n2) == 0: print(0) else: ans = 1000 - int(n2) print(ans)
s712564009
p03545
u750485713
2,000
262,144
Wrong Answer
17
3,060
262
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
S = input() a = len(str(S))-1 for i in range(2**a): temp = str(S)[0] for j in range(a): if i & (1<<j): temp += "+" else: temp += "-" temp+=str(S)[j+1] if eval(temp) == 7: print(temp)
s982381234
Accepted
18
3,060
290
S = input() a = len(str(S))-1 for i in range(2**a): temp = str(S)[0] for j in range(a): if i & (1<<j): temp += "+" else: temp += "-" temp+=str(S)[j+1] if eval(temp) == 7: print("{}=7".format(temp)) break
s088032377
p03599
u371763408
3,000
262,144
Wrong Answer
74
7,412
366
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
a,b,c,d,e,f=map(int,input().split()) a100=a*100 b100=b*100 ok=[] for ai in range(31): for bi in range(31): for ci in range(31): for di in range(31): ab= ai*a100+bi*b100 cd= ci*c+di*d if ab + cd >f: break else: if (ab/100)*e>=cd: ok.append([ab+cd,cd]) print(sorted(ok,key=lambda x:x[1])[-1])
s583269643
Accepted
441
45,316
452
a,b,c,d,e,f=map(int,input().split()) a100=a*100 b100=b*100 ok=[] for ai in range(31): for bi in range(31): for ci in range(101): for di in range(101): ab= ai*a100+bi*b100 cd= ci*c+di*d if ab + cd >f: break else: if (ab/100)*e>=cd: ok.append([ab+cd,cd]) print(*sorted(ok, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])
s649468875
p03695
u667458133
2,000
262,144
Wrong Answer
18
3,064
507
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
N = int(input()) a = list(map(int, input().split())) array1 = [400, 800, 1200, 1600, 2000, 2400, 2800, 3200] array2 = [True for _ in range(8)] result1 = 0 plus = 0 for i in range(N): print(i) if a[i] >= 3200: plus += 1 continue for j in range(len(array1)): if a[i] < array1[j]: if array2[j]: result1 += 1 array2[j] = False break result2 = result1 + plus if result2 > 8: result2 = 8 print(result1, result2)
s791272072
Accepted
17
3,064
460
N = int(input()) a = list(map(int, input().split())) array1 = [400, 800, 1200, 1600, 2000, 2400, 2800, 3200] array2 = [True for _ in range(8)] result1 = 0 plus = 0 for i in range(N): if a[i] >= 3200: plus += 1 continue for j in range(8): if a[i] < array1[j]: if array2[j]: result1 += 1 array2[j] = False break result2 = result1 + plus print(max(result1, 1), result2)
s695854596
p03545
u189604332
2,000
262,144
Wrong Answer
18
3,064
1,235
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
class TrainTicket(): def calculate(self, S: list): for x in range(2): for y in range(2): for z in range (2): if x == 1: res = S[0] + S[1] else: res = S[0] - S[1] if y ==1: res += S[2] else: res -= S[2] if z == 1: res += S[3] else: res -= S[3] if res == 7: if x == 1: xr = "+" else: xr = "-" if y == 1: yr = "+" else: yr= "-" if z == 1: zr = "+" else: zr = "-" return(str(S[0]) + xr + str(S[1]) + yr + str(S[2]) + zr + str(S[3])) if __name__ =="__main__": S = list(map(int, input())) print(S) tt = TrainTicket() res = tt.calculate(S) print(str(res)+"=7")
s266518336
Accepted
18
3,064
1,222
class TrainTicket(): def calculate(self, S: list): for x in range(2): for y in range(2): for z in range (2): if x == 1: res = S[0] + S[1] else: res = S[0] - S[1] if y ==1: res += S[2] else: res -= S[2] if z == 1: res += S[3] else: res -= S[3] if res == 7: if x == 1: xr = "+" else: xr = "-" if y == 1: yr = "+" else: yr= "-" if z == 1: zr = "+" else: zr = "-" return(str(S[0]) + xr + str(S[1]) + yr + str(S[2]) + zr + str(S[3])) if __name__ =="__main__": S = list(map(int, input())) tt = TrainTicket() res = tt.calculate(S) print(str(res)+"=7")
s604282037
p03372
u270681687
2,000
262,144
Wrong Answer
2,104
15,832
709
"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.
n, c = map(int, input().split()) x = [] v = [] vcum = [] cum = 0 for i in range(n): X, V = map(int, input().split()) x.append(X) cum += V v.append(V) vcum.append(cum) maxnut = 0 for i in range(n): maxnut = max(maxnut, vcum[i] - x[i]) for i in range(n): if i == 0: maxnut = max(maxnut, vcum[n-1] - (c - x[i])) else: maxnut = max(maxnut, vcum[n-1] - vcum[i-1] - (c - x[i])) for i in range(n): for j in range(i+1, n): maxnut = max(maxnut, vcum[i] - 2 * x[i] + vcum[n-1] - vcum[j-1], - (c - x[j])) for i in range(n): for j in range(i+1, n): maxnut = max(maxnut, vcum[i] - x[i] + vcum[n-1] - vcum[j-1], - (c - x[j]) * 2) print(maxnut)
s585115889
Accepted
538
40,948
2,125
import sys input = sys.stdin.readline n, c = map(int, input().split()) sushi = [list(map(int, input().split())) for _ in range(n)] if n == 1: print(max(sushi[0][1]-sushi[0][0], sushi[0][1]-(c-sushi[0][0]), 0)) exit() x = [] for i in range(n): x.append(sushi[i][0]) vcum = [] v = 0 for i in range(n): v += sushi[i][1] vcum.append(v) ans = 0 for i in range(n): if ans < vcum[i] - x[i]: ans = vcum[i] - x[i] for i in range(n): if i == 0: if ans < vcum[n-1] - (c - x[0]): ans = vcum[n-1] - (c - x[0]) else: if ans < (vcum[n - 1] - vcum[i - 1]) - (c - x[i]): ans = (vcum[n - 1] - vcum[i - 1]) - (c - x[i]) right_dp = [0] * n right_dp[n-1] = vcum[n-1] - vcum[n-2] - (c - x[n-1]) for i in reversed(range(1, n-1)): right_dp[i] = max(right_dp[i+1], vcum[n-1] - vcum[i-1] - (c - x[i])) for i in range(n-1): cal = vcum[i] - 2 * x[i] + right_dp[i+1] if ans < cal: ans = cal left_dp = [0] * n left_dp[0] = vcum[0] - x[0] for i in range(1, n): left_dp[i] = max(left_dp[i-1], vcum[i] - x[i]) for i in range(1, n): cal = vcum[n-1] - vcum[i-1] - 2 * (c - x[i]) + left_dp[i-1] if ans < cal: ans = cal print(ans)
s496994255
p03644
u037221289
2,000
262,144
Wrong Answer
17
2,940
69
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N = int(input()) L = [(1,2), (2,4), (3,8), (4,16), (5,32), (6,64)]
s464115845
Accepted
18
3,064
310
N = int(input()) L = [(N,0),(1,0), (2,1), (4,2), (8,3), (16,4), (32,5), (64,6),(128,7)] sorted_L = sorted(L,key=lambda x:x[0]) for i,j in enumerate(sorted_L): if j[0] == N: if sorted_L[i][0] == sorted_L[i+1][0]: print(sorted_L[i][0]) break else: print(sorted_L[i-1][0]) break
s183037969
p03479
u516554284
2,000
262,144
Wrong Answer
28
9,068
76
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
x,y=map(int,input().split()) ans=0 while x<=y: x=x*2 ans+1 print(ans)
s052891694
Accepted
27
9,160
79
x,y=map(int,input().split()) ans=0 while x<=y: x=x*2 ans+=1 print(ans)
s532442032
p03737
u556371693
2,000
262,144
Wrong Answer
17
2,940
67
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
a,b,c=input().split() print(a[0].upper(),b[0].upper(),c[0].upper())
s726401668
Accepted
17
2,940
76
a,b,c=input().split() print(a[0].upper(), b[0].upper(), c[0].upper(),sep="")
s076173431
p03080
u493610446
2,000
1,048,576
Wrong Answer
17
2,940
141
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
name = input() count = 0 for i in name: if i == "R": count += 1 if count * 2 > len(name): print("Yes") else: print("No")
s524958756
Accepted
18
2,940
149
input() name = input() count = 0 for i in name: if i == "R": count += 1 if count * 2 > len(name): print("Yes") else: print("No")
s736876211
p02831
u699944218
2,000
1,048,576
Wrong Answer
17
2,940
127
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
def lcm(x, y): return (x * y) // math.gcd(x, y) def main(A, B): A, B = list(map(int,input().split())) print(lcm(A, B))
s915598090
Accepted
28
9,084
86
from math import gcd A, B = list(map(int,input().split())) print(A * B // gcd(A, B))
s361610740
p03637
u941434715
2,000
262,144
Wrong Answer
191
23,032
338
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
#coding: utf-8 import math import heapq import bisect import numpy as np from collections import Counter #from scipy.misc import comb N = int(input()) A = list(map(int, input().split())) cnt1 = 0 cnt4 = 0 for a in A: if a%4 == 0: cnt4 += 1 else: cnt1 += 1 if cnt1 <= cnt4: print("Yes") else: print("No")
s826118123
Accepted
196
23,096
438
#coding: utf-8 import math import heapq import bisect import numpy as np from collections import Counter #from scipy.misc import comb N = int(input()) A = list(map(int, input().split())) cnt1 = 0 cnt2 = 0 cnt4 = 0 for a in A: if a%4 == 0: cnt4 += 1 elif a%2 == 0: cnt2 += 1 else: cnt1 += 1 if cnt1 <= cnt4: print("Yes") elif cnt1 == cnt4 + 1 and cnt2 == 0: print("Yes") else: print("No")
s960966141
p03448
u594956556
2,000
262,144
Wrong Answer
40
3,060
224
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()) X = X // 50 ans = 0 for ai in range(A): for bi in range(B): for ci in range(C): if 10*ai + 2*bi + ci == X: ans += 1 print(ans)
s015116250
Accepted
43
3,060
231
A = int(input()) B = int(input()) C = int(input()) X = int(input()) X = X // 50 ans = 0 for ai in range(A+1): for bi in range(B+1): for ci in range(C+1): if 10*ai + 2*bi + ci == X: ans += 1 print(ans)
s846623970
p03494
u998733244
2,000
262,144
Wrong Answer
19
2,940
158
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())) print(A) count = 0 while all(a%2==0 for a in A): A = [a/2 for a in A] count += 1 print(count)
s877085678
Accepted
19
3,060
216
n = int(input()) A = list(map(int, input().split())) count = 0 while True: for i in range(n): if A[i]%2==1: print(count) exit() A[i] = A[i]/2 count += 1 print(count)
s245578983
p03994
u254871849
2,000
262,144
Wrong Answer
62
5,968
546
Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string.
# 2019-11-26 17:11:55(JST) import sys from string import ascii_lowercase as alph ind_alph = dict((char, ind) for ind, char in enumerate(alph)) def main(): s, k = sys.stdin.read().split() s = list(s) k = int(k) n = len(s) i = 0 while k: j = ind_alph[s[i]] diff = (26 - j) % 26 if diff <= k: s[i] = 'a' k -= diff if i == n - 1 and k: s[i] = alph[(j + k) % 26] k = 0 i += 1 print(s) if __name__ == '__main__': main()
s251096259
Accepted
56
4,660
554
# 2019-11-26 17:11:55(JST) import sys from string import ascii_lowercase as alph ind_alph = dict((char, ind) for ind, char in enumerate(alph)) def main(): s, k = sys.stdin.read().split() s = list(s) k = int(k) n = len(s) i = 0 while k: diff = (26 - ind_alph[s[i]]) % 26 if diff <= k: s[i] = 'a' k -= diff if i == n - 1 and k: s[i] = alph[(ind_alph[s[i]] + k) % 26] k = 0 i += 1 print(''.join(s)) if __name__ == '__main__': main()
s552036264
p03044
u068112689
2,000
1,048,576
Wrong Answer
807
46,632
534
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
n = int(input()) links = [[] for _ in range(n+1)] for _ in range(n-1): u,v,w = map(int, input().split()) links[u].append([v, w]) links[v].append([u, w]) ans = [0] * (n+1) q = [(1, -1)] while q: me, parent = q.pop() for child, w in links[me]: if child == parent: continue if w % 2 ==0: ans[me] = 1 ans[child] = 1 q.append((child, me)) print(*ans[1:])
s433276334
Accepted
677
38,828
469
n = int(input()) graph = [[] for i in range(n)] for i in range(n-1): u, v, w = map(int, input().split()) graph[u-1].append((v-1, w)) graph[v-1].append((u-1, w)) colors = [-1] * n colors[0] = 0 Me_Parent = [[0, -1]] while Me_Parent: m, p = Me_Parent.pop() Child = graph[m] for c, w in Child: if c != p: colors[c] = (colors[m] + w) % 2 Me_Parent.append([c, m]) for i in range(n): print(colors[i])
s683187628
p02612
u465597982
2,000
1,048,576
Wrong Answer
29
9,148
45
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()) a1=n//1000 print(n-(a1*1000))
s820657904
Accepted
34
9,176
151
import math n=int(input()) if(n<1000): print(1000-n) elif(n%1000!=0): a=int(math.floor(n//1000)) print(((a+1)*1000)-n) else: print("0")
s218531922
p03657
u691018832
2,000
262,144
Wrong Answer
17
2,940
172
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
# sys.stdin.readline() import sys input = sys.stdin.readline a, b = map(int, input().split()) if (a*b)%3 == 0: ans = 'Possible' else: ans = 'Impossible' print(ans)
s551997407
Accepted
17
2,940
196
# sys.stdin.readline() import sys input = sys.stdin.readline a, b = map(int, input().split()) if (a+b)%3 == 0 or a%3 == 0 or b%3 == 0: ans = 'Possible' else: ans = 'Impossible' print(ans)
s184741387
p03578
u598229387
2,000
262,144
Wrong Answer
401
35,556
411
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
n = int(input()) d = [int(i) for i in input().split()] m = int(input()) t = [int(i) for i in input().split()] d = sorted(d) t = sorted(t) left = 0 ans = 'Yes' for i in range(m): if t[i] < d[left]: ans='No' break elif t[i] == d[left]: left+=1 if i!= m-1 and left >=n: ans = 'No' else: left+=1 if left>=n: ans = 'No' print(ans)
s839324442
Accepted
386
35,012
571
n = int(input()) d = [int(i) for i in input().split()] m = int(input()) t = [int(i) for i in input().split()] d = sorted(d) t = sorted(t) left = 0 ans = 'YES' for i in range(m): if t[i] < d[left]: ans='NO' break elif t[i] == d[left]: left+=1 if i!= m-1 and left >=n: ans = 'NO' break else: while t[i] != d[left]: left+=1 if left >= n: ans='NO' break left+=1 if left>=n: ans = 'NO' break print(ans)
s407008611
p02389
u283452598
1,000
131,072
Wrong Answer
30
7,488
40
Write a program which calculates the area and perimeter of a given rectangle.
a,b=input().split() print(int(a)*int(b))
s910550727
Accepted
20
7,524
62
x=input().split() a=int(x[0]) b=int(x[1]) print(a*b,(a*2+b*2))
s260109232
p03657
u932465688
2,000
262,144
Wrong Answer
17
2,940
165
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
A,B = map(int,input().split()) if (A % 3 == 0 or B % 3 == 0): print('Possible') else: if ((A+B) % 3 == 0): print('Posssible') else: print('Impossible')
s253290751
Accepted
17
2,940
164
A,B = map(int,input().split()) if (A % 3 == 0 or B % 3 == 0): print('Possible') else: if ((A+B) % 3 == 0): print('Possible') else: print('Impossible')
s411603095
p03739
u136090046
2,000
262,144
Wrong Answer
95
14,468
451
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.
n = int(input()) array = list(map(int, input().split())) total = 0 flag = -1 minus = 0 for tmp in range(len(array)): total += array[tmp] if total * flag <= 0: minus += abs(total*flag)+1 total = flag flag *= -1 total = 0 flag = 1 plus = 0 for tmp in range(len(array)): total += array[tmp] if total * flag <= 0: plus += abs(total*flag)+1 total = flag flag *= -1 print(min(minus, plus))
s847626051
Accepted
132
14,468
442
n = int(input()) array = list(map(int, input().split())) total = 0 flag = -1 minus = 0 for tmp in range(len(array)): total += array[tmp] if total * flag <= 0: minus += abs(total*flag)+1 total = flag flag *= -1 total = 0 flag = 1 plus = 0 for tmp in range(len(array)): total += array[tmp] if total * flag <= 0: plus += abs(total*flag)+1 total = flag flag *= -1 print(min(minus, plus))
s319402219
p03433
u873973257
2,000
262,144
Wrong Answer
17
2,940
86
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
pay = input() oney = input() print('YES' if (int(pay) % 500) <= int(oney) else 'NO' )
s341433835
Accepted
17
2,940
86
pay = input() oney = input() print('Yes' if (int(pay) % 500) <= int(oney) else 'No' )
s967946426
p04043
u536836760
2,000
262,144
Wrong Answer
18
2,940
190
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.
x = list(input().split()) five = 0 seven = 0 for i in x: if i == 5: five += five elif i == 7: seven += seven if seven == 1 and five == 2: print('YES') else: print('NO')
s017110797
Accepted
17
2,940
191
x = list(map(int,input().split())) five = 0 seven = 0 for i in x: if i == 5: five += 1 elif i == 7: seven += 1 if seven == 1 and five == 2: print('YES') else: print('NO')
s803525365
p02608
u688219499
2,000
1,048,576
Wrong Answer
489
16,772
290
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()) for i in range(5): print(0) count = [0] * (10**6) s = 0 for i in range(1, 101): for j in range(1, 101): for k in range(1, 101): s = i * i + j * j + k * k + i * j + j * k + k * i count[s] += 1 for i in range(n): print(count[i])
s768936039
Accepted
487
16,904
262
n = int(input()) count = [0] * (10**6) s = 0 for i in range(1, 101): for j in range(1, 101): for k in range(1, 101): s = i * i + j * j + k * k + i * j + j * k + k * i count[s - 1] += 1 for i in range(n): print(count[i])
s183854303
p02399
u279955105
1,000
131,072
Wrong Answer
20
7,664
114
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a,b = list(map(int, input().split())) d = int(a / b) r = a % b f = a / b print(str(d) + " "+ str(r) + " "+ str(f))
s620373310
Accepted
20
5,608
158
a,b = map(int, input().split()) answer1 = a//b answer2 = a % b answer3 = a / b print(str(answer1) + ' ' + str(answer2) + ' ' + str('{:.5f}'.format(answer3)))
s436649529
p03610
u350836088
2,000
262,144
Wrong Answer
17
3,188
26
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(s[1::2])
s298015849
Accepted
17
3,192
19
print(input()[::2])
s875799482
p03796
u611090896
2,000
262,144
Wrong Answer
17
3,064
37
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()) print(N % (10**9+7))
s120857152
Accepted
154
9,908
57
import math print(math.factorial(int(input()))%(10**9+7))
s414588009
p03493
u113255362
2,000
262,144
Wrong Answer
27
8,948
106
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
S = input() List = [S[0], S[1], S[2]] res = 0 for i in range(3): if List[i] == 1: res +=1 print(res)
s120042356
Accepted
31
9,028
108
S = input() List = [S[0], S[1], S[2]] res = 0 for i in range(3): if List[i] == "1": res +=1 print(res)
s006594847
p03679
u521323621
2,000
262,144
Wrong Answer
25
9,160
95
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b = map(int, input().split()) if x >= b-a: print("delicious") else: print("dangerous")
s949670853
Accepted
28
9,004
127
x,a,b = map(int, input().split()) if 0 >= b-a: print("delicious") elif x >= b-a: print("safe") else: print("dangerous")
s741804908
p03369
u775652851
2,000
262,144
Wrong Answer
28
9,044
74
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.
a=input() t=0 for i in range(3): if a[i]=="o": t+=1 print(500+t*100)
s290442310
Accepted
29
8,980
75
a=input() t=0 for i in range(3): if a[i]=="o": t+=1 print(700+t*100)
s750186630
p03455
u902361509
2,000
262,144
Wrong Answer
17
2,940
92
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if (a * b%2 == 0): print("Odd") else: print("Even")
s402998564
Accepted
18
2,940
91
a, b = map(int, input().split()) if (a*b)%2 == 0: print("Even") else: print("Odd")
s291650263
p03478
u210545407
2,000
262,144
Wrong Answer
39
3,060
362
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split(" ")) wholeSum = 0 def digitSum(n): basis = 10 transDigit = list() while True: transDigit.append(n % basis) n = n / basis if n < 1: break result = sum(transDigit) return result for pivot in range(n+1): target = digitSum(pivot) if target <= b\ and a <= target: wholeSum += pivot print(wholeSum)
s489765838
Accepted
34
2,940
257
n, a, b = map(int, input().split(" ")) wholeSum = 0 def digitSum(n): result = sum(map(int, list(str(n)))) return result for pivot in range(n+1): target = digitSum(pivot) if target <= b\ and a <= target: wholeSum += pivot print(wholeSum)