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
s159371039
p02412
u104931506
1,000
131,072
Wrong Answer
30
7,556
270
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
while True: n, x = map(int, input().split()) if n == x == 0: break result = 0 for a in range(1, x // 3): for b in range(a + 1, x // 2): c = x - a - b if b < c <= n: result += 1 print(result)
s163874799
Accepted
30
7,656
266
while True: n, x = map(int, input().split()) if n == x == 0: break result = 0 for a in range(1, x // 3): for b in range(a + 1, x // 2): c = x - a - b if b < c <= n: result += 1 print(result)
s957136479
p03737
u516447519
2,000
262,144
Wrong Answer
28
9,024
80
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 = [str(i) for i in input().split()] s = a[0]+b[0]+c[0] print(a.upper())
s745378070
Accepted
29
8,960
79
a,b,c = [str(i) for i in input().split()] s = a[0]+b[0]+c[0] print(s.upper())
s841161713
p02612
u549161102
2,000
1,048,576
Wrong Answer
31
9,148
52
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()) ans = N - (N//1000)*1000 print(ans)
s199022175
Accepted
30
9,160
94
N = int(input()) if N%1000==0: print('0') exit() ans = ((N//1000)+1)*1000-N print(ans)
s777592075
p03471
u257226830
2,000
262,144
Wrong Answer
1,440
3,064
303
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
N,Y = map(int,input().split()) count = 0 for l in range(N+1): for m in range(N+1): n = N-l-m if 0<=n<=N: y = 10000*l+5000*m+1000*n if y==Y: list = [l,m,n] count = count+1 if count>=1: print(list) else: print([-1,-1,-1])
s552659975
Accepted
1,385
3,064
324
N,Y = map(int,input().split()) count = 0 for l in range(N+1): for m in range(N+1): n = N-l-m if 0<=n<=N: y = 10000*l+5000*m+1000*n if y==Y: list = [l,m,n] count = count+1 if count>=1: print(list[0], list[1], list[2]) else: print(-1, -1, -1)
s656612163
p03700
u894844146
2,000
262,144
Wrong Answer
264
7,512
244
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?
import math x=list(map(int,input().split(" "))) n=x[0] y=x[1] z=x[2] a =[] for i in range(n): a.append(int(input())) a.sort(reverse=True) count=0 for c in a: if c>=count*z: count+=math.ceil((c-count*z)/y) print(count)
s953093358
Accepted
1,187
7,400
559
import math n, a, b = map(int, input().split(" ")) h = [] for i in range(n): h.append(int(input())) h.sort(reverse=True) def check(count_target, h, a, b): count = 0 for i in h: if i >= count_target * b: count += math.ceil((i - count_target * b) / (a - b)) return count_target - count l = 1 r = math.ceil(h[0] / b) while r - l > 1: mid = math.floor(l + (r - l) / 2) if check(mid, h, a, b) < 0: l = mid else: r = mid if check(l, h, a, b) < 0: print(int(r)) else: print(int(l))
s371526656
p02390
u382692819
1,000
131,072
Wrong Answer
20
7,600
73
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
s = input() S = int(s) h=S//3600 m=S%3600//60 s=m%60 print(h,":",m,":",s)
s248690967
Accepted
20
7,668
117
s = input() S = int(s) h=S//3600 m=S%3600//60 s=S-(h*3600+m*60) a=[h,m,s] a_str = map(str,a) print (":".join(a_str))
s827358177
p02669
u749742659
2,000
1,048,576
Wrong Answer
455
34,728
1,427
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
import sys from functools import lru_cache sys.setrecursionlimit(10000) t = int(input()) l = [list(map(int, input().split())) for i in range(t)] @lru_cache(maxsize=10**18) def min_coin(n,i): if(n == 1): return l[i][4] else: if(n%2 == 0): a = min_coin(n//2,i) else: a = min(min_coin(n//2,i)+l[i][4],min_coin(n//2+1,i)+l[i][4]) if(n%3 == 0): b = min_coin(n/3,i) elif(n == 2): b = min_coin(1,i)+l[i][4] elif(n%3 == 1): b = min(min_coin(n//3,i)+l[i][4],min_coin(n//3+1,i)+l[i][4]*2) else: b = min(min_coin(n//3,i)+l[i][4]*2,min_coin(n//3+1,i)+l[i][4]) if(n%5 == 0): c = min_coin(n/5,i) elif(n == 2): c = min_coin(1,i)+l[i][4]*3 elif(n == 3): c = min_coin(1,i)+l[i][4]*2 elif(n == 4): c = min_coin(1,i)+l[i][4] elif(n%5 == 1): c = min(min_coin(n//5,i)+l[i][4],min_coin(n//5+1,i)+l[i][4]*4) elif(n%5 == 2): c = min(min_coin(n//5,i)+l[i][4]*2,min_coin(n//5+1,i)+l[i][4]*3) elif(n%5 == 3): c = min(min_coin(n//5,i)+l[i][4]*3,min_coin(n//5+1,i)+l[i][4]*2) else: c = min(min_coin(n//5,i)+l[i][4]*4,min_coin(n//5+1,i)+l[i][4]) return min(a+l[i][1],b+l[i][2],c+l[i][3],l[i][4]*n) for i in range(t): print(min_coin(l[i][0],i))
s943456894
Accepted
215
12,204
1,019
import sys from functools import lru_cache sys.setrecursionlimit(1000000) t = int(input()) l = [list(map(int, input().split())) for i in range(t)] for i in range(t): N = l[i][0] A = l[i][1] B = l[i][2] C = l[i][3] D = l[i][4] @lru_cache(maxsize=10**18) def min_coin(n): if(n == 0): return 0 elif(n == 1): return D else: if(n%2 == 0): a = min_coin(n//2) else: a = min(min_coin(n//2)+D,min_coin(n//2+1)+D) if(n%3 == 0): b = min_coin(n//3) elif(n%3 == 1): b = min(min_coin(n//3)+D,min_coin(n//3+1)+D*2) else: b = min(min_coin(n//3)+D*2,min_coin(n//3+1)+D) if(n%5 == 0): c = min_coin(n//5) else: re = n%5 c = min(min_coin(n//5)+D*re,min_coin(n//5+1)+D*(5-re)) return min(a+A,b+B,c+C,D*n) print(int(min_coin(N)))
s016066785
p03555
u735069283
2,000
262,144
Wrong Answer
17
2,940
96
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a=str(input()) b=str(input()) print('Yes' if a[0]==b[2] and a[1]==b[1] and a[2]==b[0] else 'No')
s399750215
Accepted
17
2,940
96
a=str(input()) b=str(input()) print('YES' if a[0]==b[2] and a[1]==b[1] and a[2]==b[0] else 'NO')
s276764355
p02606
u853728588
2,000
1,048,576
Wrong Answer
28
9,116
102
How many multiples of d are there among the integers between L and R (inclusive)?
l, r, d = map(int,input().split()) count = 0 for i in range(l,r): i%d == 0 count += 1 print(count)
s938043596
Accepted
28
9,060
111
l, r, d = map(int,input().split()) count = 0 for i in range(l,r+1): if i%d == 0: count += 1 print(count)
s714971133
p02409
u518824954
1,000
131,072
Wrong Answer
20
5,624
1,225
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
n=int(input()) build,story,room,people=[],[],[],[] for i in range(n): date=list(map(int,input().split(' '))) build.append(date[0]) story.append(date[1]) room.append(date[2]) people.append(date[3]) build1=[[0 for i in range(10)] for j in range(3)] build2=[[0 for i in range(10)] for j in range(3)] build3=[[0 for i in range(10)] for j in range(3)] build4=[[0 for i in range(10)] for j in range(3)] print(build) for i in range(n): m=int(i) if(build[m]==1): build1[story[m]-1][room[m]-1]=build1[story[m]-1][room[m]-1]+people[m] if(build[m]==2): build2[story[m]-1][room[m]-1]=build1[story[m]-1][room[m]-1]+people[m] if(build[m]==3): build3[story[m]-1][room[m]-1]=build1[story[m]-1][room[m]-1]+people[m] if(build[m]==4): build4[story[m]-1][room[m]-1]=build1[story[m]-1][room[m]-1]+people[m] for i in range(3): print( ' '.join(list(map( lambda x: str(x),build1[i]))) ) print('#'*20) for i in range(3): print( ' '.join(list(map( lambda x: str(x),build2[i]))) ) print('#'*20) for i in range(3): print( ' '.join(list(map( lambda x: str(x),build3[i]))) ) print('#'*20) for i in range(3): print( ' '.join(list(map( lambda x: str(x),build4[i]))) )
s379612832
Accepted
20
5,632
1,216
n=int(input()) build,story,room,people=[],[],[],[] for i in range(n): date=list(map(int,input().split(' '))) build.append(date[0]) story.append(date[1]) room.append(date[2]) people.append(date[3]) build1=[[0 for i in range(10)] for j in range(3)] build2=[[0 for i in range(10)] for j in range(3)] build3=[[0 for i in range(10)] for j in range(3)] build4=[[0 for i in range(10)] for j in range(3)] for i in range(n): m=int(i) if(build[m]==1): build1[story[m]-1][room[m]-1]=build1[story[m]-1][room[m]-1]+people[m] elif(build[m]==2): build2[story[m]-1][room[m]-1]=build2[story[m]-1][room[m]-1]+people[m] elif(build[m]==3): build3[story[m]-1][room[m]-1]=build3[story[m]-1][room[m]-1]+people[m] else: build4[story[m]-1][room[m]-1]=build4[story[m]-1][room[m]-1]+people[m] for i in range(3): print(' '+' '.join(list(map( lambda x: str(x),build1[i])))) print('#'*20) for i in range(3): print(' '+' '.join(list(map( lambda x: str(x),build2[i]))) ) print('#'*20) for i in range(3): print(' '+' '.join(list(map( lambda x: str(x),build3[i]))) ) print('#'*20) for i in range(3): print(' '+' '.join(list(map( lambda x: str(x),build4[i]))) )
s489872839
p03140
u227082700
2,000
1,048,576
Wrong Answer
17
3,060
171
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
n=int(input());aa=[input()for i in range(3)];ans=0 for i in range(n): a,b,c=aa[0][i],aa[1][i],aa[2][i] if not a==b==c: if a!=b!=c:ans+=2 else:ans+=1 print(ans)
s028113220
Accepted
17
3,060
174
n=int(input());aa=[input()for i in range(3)];ans=0 for i in range(n): a,b,c=aa[0][i],aa[1][i],aa[2][i] if not a==b==c: if a!=b!=c!=a:ans+=2 else:ans+=1 print(ans)
s851051647
p03501
u453526259
2,000
262,144
Wrong Answer
17
2,940
80
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
a,b,c = map(int, input().split()) if a*b > c: print(a*b) else: print(c)
s273594011
Accepted
17
2,940
80
a,b,c = map(int, input().split()) if a*b < c: print(a*b) else: print(c)
s574315654
p03505
u905715926
2,000
262,144
Wrong Answer
18
2,940
111
_ButCoder Inc._ runs a programming competition site called _ButCoder_. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rating is 0, and a user whose rating reaches K or higher is called _Kaiden_ ("total transmission"). Note that a user's rating may become negative. Hikuhashi is a new user in ButCoder. It is estimated that, his rating increases by A in each of his odd-numbered contests (first, third, fifth, ...), and decreases by B in each of his even-numbered contests (second, fourth, sixth, ...). According to this estimate, after how many contests will he become Kaiden for the first time, or will he never become Kaiden?
p,a,b = map(int,input().split()) if(a<=b): print(-1) else: p-=a up=a-b num=int(p/up+0.5) print(num+1)
s666200345
Accepted
17
2,940
185
p,a,b = map(int,input().split()) if(a<=b): if(a>=p): print(1) else: print(-1) else: p-=a up=a-b if(p<=0): print(1) else: num=p//up+(p%up!=0) print(num*2+1)
s753356047
p02663
u125269142
2,000
1,048,576
Wrong Answer
21
9,164
174
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
h1, m1, h2, m2, k = map(int, input().split()) start = (60 * h1) + m1 end = (60 * h2) + m2 - k print(start-end)
s759104730
Accepted
22
9,100
178
h1, m1, h2, m2, k = map(int, input().split()) start = (60 * h1) + m1 end = (60 * h2) + m2 - k print(end - start)
s725458852
p00441
u797673668
5,000
131,072
Wrong Answer
60
7,768
540
昔, そこには集落があり, 多くの人が暮らしていた. 人々は形も大きさも様々な建物を建てた. だが, それらの建造物は既に失われ, 文献と, 遺跡から見つかった柱だけが建造物の位置を知る手がかりだった. 文献には神殿の記述がある. 神殿は上から見ると正確に正方形になっており, その四隅には柱があった. 神殿がどの向きを向いていたかはわからない. また, 辺上や内部に柱があったかどうかもわからない. 考古学者たちは, 遺跡から見つかった柱の中で, 正方形になっているもののうち, 面積が最大のものが神殿に違いないと考えた. 柱の位置の座標が与えられるので, 4 本の柱でできる正方形のうち面積が最大のものを探し, その面積を出力するプログラムを書け. なお, 正方形の辺は座標軸に平行とは限らないことに注意せよ.
n = int(input()) poles = [tuple(map(int, input().split())) for _ in range(n)] poles_set = set(poles) max_square = 0 for i in range(n): x1, y1 = poles[i] for j in range(i, n): x2, y2 = poles[j] dx, dy = x2 - x1, y2 - y1 if ((x2 + dy, y2 - dx) in poles_set and (x1 + dy, y1 - dx) in poles_set) \ or ((x2 - dy, y2 + dx) in poles_set and (x1 - dy, y1 + dx) in poles_set): edge = dx ** 2 + dy ** 2 if max_square < edge: max_square = edge print(max_square)
s590068124
Accepted
17,870
8,812
640
while True: n = int(input()) if not n: break poles = [tuple(map(int, input().split())) for _ in range(n)] poles_set = set(poles) max_square = 0 for i in range(n): x1, y1 = poles[i] for j in range(i, n): x2, y2 = poles[j] dx, dy = x2 - x1, y2 - y1 if ((x2 + dy, y2 - dx) in poles_set and (x1 + dy, y1 - dx) in poles_set) \ or ((x2 - dy, y2 + dx) in poles_set and (x1 - dy, y1 + dx) in poles_set): edge = dx ** 2 + dy ** 2 if max_square < edge: max_square = edge print(max_square)
s513251685
p03836
u977193988
2,000
262,144
Wrong Answer
17
3,060
187
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx,sy,tx,ty=map(int,input().split()) ans_1='U'*(ty-sy)+'R'*(tx-ty)+'D'*(ty-sy)+'L'*(tx-sx) ans_2='L'+'U'*(ty-sy+1)+'R'*(tx-ty+1)+'D'+'R'+'D'*(ty-sy+1)+'L'*(tx-sx+1)+'U' print(ans_1+ans_2)
s324384652
Accepted
17
3,060
187
sx,sy,tx,ty=map(int,input().split()) ans_1='U'*(ty-sy)+'R'*(tx-sx)+'D'*(ty-sy)+'L'*(tx-sx) ans_2='L'+'U'*(ty-sy+1)+'R'*(tx-sx+1)+'D'+'R'+'D'*(ty-sy+1)+'L'*(tx-sx+1)+'U' print(ans_1+ans_2)
s280553027
p02422
u283452598
1,000
131,072
Wrong Answer
20
7,684
423
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
moto = input() num = int(input()) for i in range(num): order = input().split() if order[0] == "print": m,n=int(order[1]),int(order[2]) print(moto[m:n+1]) elif order[0] == "reverse": m,n=int(order[1]),int(order[2]) moto = moto[:m]+moto[n:m-1:-1]+moto[n:] elif order[0] == "replace": m,n,l=int(order[1]),int(order[2]),order[3] moto = moto[:m]+order[3]+moto[n:]
s233844772
Accepted
20
7,704
430
moto = input() num = int(input()) for i in range(num): order = input().split() if order[0] == "print": m,n=int(order[1]),int(order[2]) print(moto[m:n+1]) elif order[0] == "reverse": m,n=int(order[1]),int(order[2]) moto = moto[:m]+moto[m:n+1][::-1]+moto[n+1:] elif order[0] == "replace": m,n,l=int(order[1]),int(order[2]),order[3] moto = moto[:m]+order[3]+moto[n+1:]
s758721842
p02420
u177808190
1,000
131,072
Wrong Answer
20
5,556
338
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
string = '' count = 0 while True: hoge = input().strip() if hoge == '-': print (string) break if len(hoge) != 1: if string: print (string) string = hoge count = 0 else: if count == 0: continue string = string[int(hoge):] + string[:int(hoge)]
s353733997
Accepted
20
5,596
375
string = '' while True: hoge = input().strip() if hoge == '-': print (string) break if hoge.isalpha(): if string: print (string) string = hoge count = 0 else: if count == 0: count = hoge continue else: string = string[int(hoge):] + string[:int(hoge)]
s816752228
p03999
u699699071
2,000
262,144
Wrong Answer
33
3,444
261
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.
S=input() result = 0 for i in range(1 << len(S)-1): hoge=S[0] for j in range( len(S)-1 ): print("i>>j",i>>j) if i>>j&1 : hoge+="+" hoge+=S[j+1] print(hoge) result += eval(hoge) print(result)
s441548202
Accepted
27
3,060
218
S=input() result = 0 for i in range(1 << len(S)-1): hoge=S[0] for j in range( len(S)-1 ): if i>>j&1 : hoge+="+" hoge+=S[j+1] result += eval(hoge) print(result)
s752671108
p03693
u839246671
2,000
262,144
Wrong Answer
17
2,940
94
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?
N = list(map(int,input().split())) if N[1]*10+N[2] // 4 == 0: print("YES") else: print("NO")
s453385622
Accepted
17
2,940
96
N = list(map(int,input().split())) if (N[1]*10+N[2]) % 4 == 0: print("YES") else: print("NO")
s183307585
p03644
u821588465
2,000
262,144
Wrong Answer
31
9,060
64
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.
print(len(bin(7))) n = int(input()) print(2**(len(bin(n))-3))
s760993643
Accepted
26
9,112
42
n = int(input()) print(2**(len(bin(n))-3))
s335485995
p03644
u072717685
2,000
262,144
Wrong Answer
17
2,940
55
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n = int(input()) r = 1 while r <= n: r *= 2 print(r)
s679441061
Accepted
18
2,940
62
n = int(input()) r = 1 while r <= n: r *= 2 print(int(r/2))
s651798983
p04012
u886274153
2,000
262,144
Wrong Answer
18
3,060
292
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 = input() mp = dict() for c in w: if c in mp: mp[c] += 1 else: mp[c] = 1 print(mp) def check(w): c = "Yes" for i in w: if i % 2 == 0: continue else: c = "No" break return c print(check(mp.values()))
s318284995
Accepted
18
2,940
281
w = input() mp = dict() for c in w: if c in mp: mp[c] += 1 else: mp[c] = 1 def check(w): c = "Yes" for i in w: if i % 2 == 0: continue else: c = "No" break return c print(check(mp.values()))
s214542502
p03160
u634461073
2,000
1,048,576
Wrong Answer
142
13,980
178
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())) c = [0]*n c[1]=abs(h[1]-h[0]) for i in range(1,n): c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1])) print(c[n-1])
s634439737
Accepted
139
13,928
179
n = int(input()) h = list(map(int,input().split())) c = [0]*n c[1]=abs(h[1]-h[0]) for i in range(2,n): c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1])) print(c[n-1])
s368499499
p03722
u550943777
2,000
262,144
Wrong Answer
238
3,572
802
There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
n, m = map(int,input().split()) a = [] b = [] c = [] ed_list = [[] for _ in range(n)] for i in range(m): t_a, t_b, t_c = map(int,input().split()) a.append(t_a-1) b.append(t_b-1) c.append(t_c) ed_list[t_a - 1].append(t_b - 1) def loop_judge(ed_list): stack = [0] post = set() while stack: t = stack.pop() post.add(t) print(t) for i in ed_list[t]: stack.append(i) if i in post: return True return False if loop_judge(ed_list): print('inf') else: INF = float('inf') score = [-INF for i in range(n)] score[0] = 0 for i in range(m): for u,v,cost in zip(a,b,c): if score[v] < score[u] + cost: score[v] = score[u] + cost print(score[n-1])
s826511128
Accepted
1,423
3,572
648
n, m = map(int,input().split()) edge = [] c = [] ed_list = [[] for _ in range(n)] for i in range(m): t_a, t_b, t_c = map(int,input().split()) edge.append([t_a - 1, t_b - 1]) c.append(-t_c) ed_list[t_a - 1].append(t_b - 1) INF = float('inf') score = [INF for _ in range(n)] score[0] = 0 for i in range(n): for u, cost in zip(edge, c): if score[u[1]] > score[u[0]] + cost: score[u[1]] = score[u[0]] + cost ans = score[n-1] for i in range(n): for u, cost in zip(edge, c): if score[u[1]] > score[u[0]] + cost: score[u[1]] = score[u[0]] + cost print(-ans if ans == score[n-1] else 'inf')
s280698862
p03377
u745087332
2,000
262,144
Wrong Answer
16
2,940
167
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.
# coding:utf-8 INF = float('inf') def inpl(): return list(map(int, input().split())) A, B, X = inpl() if A + B >= X >= A: print('Yes') else: print('No')
s347731666
Accepted
17
2,940
167
# coding:utf-8 INF = float('inf') def inpl(): return list(map(int, input().split())) A, B, X = inpl() if A + B >= X >= A: print('YES') else: print('NO')
s454595176
p03730
u077291787
2,000
262,144
Wrong Answer
17
3,060
200
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 = list(map(int, input().rstrip().split())) for i in range(a, a * b + 1, a): print(i) if i % b == c: print("YES") break else: print("NO")
s465737838
Accepted
17
2,940
246
def main(): A, B, C = tuple(map(int, input().split())) for i in range(A, A * B + 1, A): if i % B == C: print("YES") return print("NO") if __name__ == "__main__": main()
s536299192
p03494
u972658925
2,000
262,144
Wrong Answer
18
2,940
148
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.
ans = 10**9 N = int(input()) A = list(map(int,input().split())) for i in A: p = 0 while i % 2 == 0: i //= 2 p += 1 print(p)
s396821963
Accepted
18
2,940
181
ans = 10**9 N = int(input()) A = list(map(int,input().split())) for i in A: p = 0 while i % 2 == 0: i //= 2 p += 1 if p < ans: ans = p print(ans)
s645119116
p03473
u571685561
2,000
262,144
Wrong Answer
18
3,064
67
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
M = input() rest = 24 - (int(M)%24) print(str(rest+24) + "Hours")
s123925810
Accepted
17
2,940
52
M = input() rest = 24 - (int(M)%24) print(rest+24)
s202271949
p02612
u407702479
2,000
1,048,576
Wrong Answer
34
9,140
28
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)
s172213105
Accepted
26
9,152
70
N=int(input()) if N%1000!=0: print(1000-N%1000) else: print(0)
s235754630
p03730
u440161695
2,000
262,144
Wrong Answer
17
2,940
117
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(2*B): if ((i*A)%B)==C: print("Yes") break else: print("No")
s639578666
Accepted
17
2,940
117
A,B,C=map(int,input().split()) for i in range(2*B): if ((i*A)%B)==C: print("YES") break else: print("NO")
s215504441
p03860
u275934251
2,000
262,144
Wrong Answer
17
2,940
138
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() t = "Atcoder" + s + "Contest" u = "" for i in t: if i == i.lower(): continue else: u += i print(u)
s342208685
Accepted
18
2,940
43
a,b,c=input().split() print(a[0]+b[0]+c[0])
s142472590
p03418
u934868410
2,000
262,144
Wrong Answer
60
2,940
118
Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
n,k = map(int, input().split()) ans = 0 for b in range(1, n+1): ans += (n // b) * (b-k) + (n % b) - (k-1) print(ans)
s011899989
Accepted
113
3,060
239
n,k = map(int, input().split()) ans = 0 for b in range(1, n+1): ans += (n // b) * max(0, b-k) if n % b > 0: if k == 0: ans += max(0, (n % b) - k) else: ans += max(0, (n%b) - k + 1) print(ans)
s664445664
p03377
u611090896
2,000
262,144
Wrong Answer
19
3,060
78
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A,B,X = map(int,input().split()) print("YES" if A<=X and (A+B) <= X else "NO")
s600824325
Accepted
18
2,940
80
a,b,x = map(int,input().split()) print('YES' if x >= a and (a+b) >= x else 'NO')
s347967045
p03597
u382431597
2,000
262,144
Wrong Answer
17
2,940
43
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()) print(n^2 -a)
s919534129
Accepted
17
2,940
45
n=int(input()) a=int(input()) print(n**2 -a)
s994395254
p03023
u221345507
2,000
1,048,576
Wrong Answer
18
2,940
37
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
N = int(input()) print((180-360/N)*N)
s062739370
Accepted
17
2,940
43
N = int(input()) print(int((180-360/N)*N))
s640000155
p02831
u596979123
2,000
1,048,576
Wrong Answer
17
3,060
201
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.
str = list(map(int, input().split())) a = str[0] b = str[1] i = 1 if a < b: big = b small = a else: big = a small = b while i != 0: i = big % small big = small small = i print (a*b/big)
s837413987
Accepted
17
3,060
206
str = list(map(int, input().split())) a = str[0] b = str[1] i = 1 if a < b: big = b small = a else: big = a small = b while i != 0: i = big % small big = small small = i print (int(a*b/big))
s022098263
p03565
u045170811
2,000
262,144
Wrong Answer
17
3,064
510
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
s = input() t = input() match = -1 for i in range(len(s) - len(t) + 1): is_term_match = True for j in range(len(t)): if s[i + j] != "?" and s[i + j] != t[j]: is_term_match = False break if is_term_match: match = i break if match == -1: print("UNRESTORABLE") else: s = s[0:match] + t + s[match + len(t):] print(match) print(s) for i in range(len(s)): if s[i] == "?": s = s[0:i] + "a" + s[i + 1:] print(s)
s491762789
Accepted
17
3,064
519
s = input() t = input() match = -1 if len(s) >= len(t): for i in range(len(s) - len(t) + 1): is_term_match = True for j in range(len(t)): if s[i + j] != "?" and s[i + j] != t[j]: is_term_match = False break if is_term_match: match = i if match == -1: print("UNRESTORABLE") else: s = s[0:match] + t + s[match + len(t):] for i in range(len(s)): if s[i] == "?": s = s[0:i] + "a" + s[i + 1:] print(s)
s605549524
p03377
u273242084
2,000
262,144
Wrong Answer
17
2,940
94
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 and a <=x: print("Yes") else: print("No")
s373271240
Accepted
17
2,940
94
a,b,x = map(int,input().split()) if a+b >= x and a <=x: print("YES") else: print("NO")
s688379327
p03129
u784169501
2,000
1,048,576
Wrong Answer
18
2,940
184
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
import math def solution(N, K): if (math.ceil((N + 1) / 2) >= K): return "YES" else: return "NO" n, k = [int(s) for s in input().split(' ')] solution(n, k)
s492402574
Accepted
18
2,940
192
import math def solution(N, K): if (math.floor((N + 1) / 2) >= K): return "YES" else: return "NO" n, k = [int(s) for s in input().split(' ')] print(solution(n, k))
s051876765
p03623
u186838327
2,000
262,144
Wrong Answer
18
2,940
91
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x, a, b = map(int, input().split()) if abs(x-a) > abs(x-b): print('A') else: print('B')
s154797083
Accepted
18
2,940
91
x, a, b = map(int, input().split()) if abs(x-a) > abs(x-b): print('B') else: print('A')
s256076693
p03861
u061912210
2,000
262,144
Wrong Answer
17
2,940
51
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x = map(int,input().split()) print(b//x - a//x)
s030419601
Accepted
18
2,940
93
a,b,x = map(int,input().split()) if a == 0: print(b//x + 1) else: print(b//x - (a-1)//x)
s774014979
p03720
u063073794
2,000
262,144
Wrong Answer
17
3,060
262
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
a,b=map(int,input().split()) d=dict() for i in range(b): s,l=input().split() if s in d.keys(): d[s]+=1 if l in d.keys(): d[l]+=1 else: d[l]=1 else: d[s]=1 if l in d.keys(): d[l]+=1 else: d[l]=1 print(d.keys)
s288742713
Accepted
17
2,940
144
n,m=map(int,input().split()) l=[0]*n for i in range(m): a,b=map(int,input().split()) l[a-1]+=1 l[b-1]+=1 for i in range(n): print(l[i])
s101509610
p03591
u224226076
2,000
262,144
Wrong Answer
17
2,940
209
Ringo is giving a present to Snuke. Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things. You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.
# -*- coding: utf-8 -*- """ Created on Sat Sep 23 20:49:53 2017 @author: thvinmei """ if __name__ == '__main__': S=input() if (S[0:4]=="YAKI"): print("YES") else: print("NO")
s044489704
Accepted
17
2,940
209
# -*- coding: utf-8 -*- """ Created on Sat Sep 23 20:49:53 2017 @author: thvinmei """ if __name__ == '__main__': S=input() if (S[0:4]=="YAKI"): print("Yes") else: print("No")
s551328192
p03697
u609738635
2,000
262,144
Wrong Answer
17
2,940
67
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
A, B = map(int, input().split()) print("error") if A+B>=10 else A+B
s575936854
Accepted
17
2,940
74
A, B = map(int, input().split()) print("error") if A+B>=10 else print(A+B)
s800651272
p03068
u573310917
2,000
1,048,576
Wrong Answer
17
3,060
174
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
N = int(input()) S = input() K = int(input()) l = S[K - 1] result = "" print(l) for s in S: if s != l: result += "*" else: result += s print(result)
s906991477
Accepted
17
2,940
166
N = int(input()) S = input() K = int(input()) l = S[K - 1] result = "" for s in S: if s != l: result += "*" else: result += s print(result)
s291432615
p02261
u000317780
1,000
131,072
Wrong Answer
20
7,760
1,118
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
class Card: def __init__(self, suit, value): self.suit = suit self.value = value def selection(ls): for i in range(len(ls)): minj = i for j in range(i, len(ls)): if ls[j].value < ls[minj].value: minj = j ls[i], ls[minj] = ls[minj], ls[i] def bubblesort(ls): for i in range(1, len(ls)): for j in reversed(range(i, len(ls))): if ls[j].value < ls[j-1].value: ls[j], ls[j-1] = ls[j-1], ls[j] def isStable(ls1, ls2): if ls1 == ls2: print("Stable") else: print("Not stable") def printcards(cards): for card in cards: print(card.suit, card.value, ' ', sep='', end='') print('\n', end='') def main(): N = int(input().rstrip()) cards = [] for card in list(input().split(' ')): cards.append(Card(card[0], card[1])) a = [x for x in cards] b = [x for x in cards] selection(a) bubblesort(b) printcards(a) print("Stable") printcards(b) isStable(a,b) if __name__ == '__main__': main()
s799629692
Accepted
30
7,784
1,212
class Card: def __init__(self, suit, value): self.suit = suit self.value = value def selection(ls): for i in range(len(ls)): minj = i for j in range(i, len(ls)): if ls[j].value < ls[minj].value: minj = j ls[i], ls[minj] = ls[minj], ls[i] def bubblesort(ls): for i in range(1, len(ls)): for j in reversed(range(i, len(ls))): if ls[j].value < ls[j-1].value: ls[j], ls[j-1] = ls[j-1], ls[j] def isStable(ls1, ls2): if ls1 == ls2: print("Stable") else: print("Not stable") def printcards(cards): for x in range(len(cards)): if x == len(cards) - 1: print(cards[x].suit + cards[x].value) else: print(cards[x].suit + cards[x].value, ' ', sep='', end='') def main(): N = int(input().rstrip()) cards = [] for card in list(input().split(' ')): cards.append(Card(card[0], card[1])) a = [x for x in cards] b = [x for x in cards] bubblesort(a) selection(b) printcards(a) print("Stable") printcards(b) isStable(a,b) if __name__ == '__main__': main()
s437945593
p03565
u391475811
2,000
262,144
Wrong Answer
17
3,064
302
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
S=input() H=input() slen=len(S) hlen=len(H) ans=False for i in range(slen-hlen): jud=True for j in range(hlen): if S[i+j]!='?' and S[i+j]!=H[j]: jud=False break if jud: S=S[:i]+H+S[i+hlen:] ans=True if ans: S=S.replace('?','a') print(S) else: print("UNRESTORABLE")
s822450152
Accepted
17
3,064
370
S=input() H=input() slen=len(S) hlen=len(H) jisho=[] ans=False for i in range(slen-hlen+1): jud=True for j in range(hlen): if S[i+j]!='?' and S[i+j]!=H[j]: jud=False break if jud: ansS=S[:i]+H+S[i+hlen:] ans=True ansS=ansS.replace('?','a') jisho.append(ansS) if ans: jisho.sort() print(jisho[0]) else: print("UNRESTORABLE")
s537151021
p03472
u566159623
2,000
262,144
Wrong Answer
391
16,712
451
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
n, h = map(int, input().split()) a = [0]*n b = [0]*n maxa = 0 for i in range(n): a[i], b[i] = map(int, input().split()) maxa = max(maxa, a[i]) b.sort() bsum = sum(b) count = n if bsum >= h: i = 0 while bsum - b[i] > h: bsum -= b[i] i += 1 count -= 1 else: if (h - bsum) % maxa == 0: count += (h - bsum) // maxa else: count += (h - bsum + 1)//maxa print(a, b) print(maxa) print(count)
s727373274
Accepted
405
12,140
596
n, h = map(int, input().split()) a = [0]*n b = [0]*n maxa = 0 for i in range(n): a[i], b[i] = map(int, input().split()) maxa = max(maxa, a[i]) c = [] for i in range(n): if b[i] >= maxa: c.append(b[i]) c.sort() csum = sum(c) count = len(c) if csum >= h: i = 0 while csum - c[i] >= h: if i == len(c): break else: csum -= c[i] i += 1 count -= 1 else: if (h - csum) % maxa == 0: count += (h - csum) // maxa else: count += (h - csum) // maxa count += 1 print(count)
s855203621
p03377
u088974156
2,000
262,144
Wrong Answer
17
2,940
81
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<=x<=a+b): print("Yes") else: print("No")
s789861390
Accepted
17
2,940
81
a,b,x =map(int,input().split()) if(a<=x<=a+b): print("YES") else: print("NO")
s569019780
p03151
u288430479
2,000
1,048,576
Wrong Answer
141
20,144
404
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
n = int(input()) l_a = list(map(int,input().split())) l_b = list(map(int,input().split())) if sum(l_a)<sum(l_b): print(-1) exit() l_sa = sorted(list(i-j for i,j in zip(l_a,l_b))) s = 0 cou =0 print(l_sa) for i in l_sa: if i<0: s += i cou +=1 else: break #print(s,cou) l_sb = l_sa[::-1] for i in l_sb: if s<0: s += i cou += 1 # print(s,cou) else: break print(cou)
s215459990
Accepted
131
19,536
402
n = int(input()) l_a = list(map(int,input().split())) l_b = list(map(int,input().split())) if sum(l_a)<sum(l_b): print(-1) exit() l_sa = sorted(list(i-j for i,j in zip(l_a,l_b))) s = 0 cou =0 #print(l_sa) for i in l_sa: if i<0: s += i cou +=1 else: break #print(s,cou) l_sb = l_sa[::-1] for i in l_sb: if s<0: s += i cou += 1 #print(s,cou) else: break print(cou)
s555269640
p03455
u358791207
2,000
262,144
Wrong Answer
17
2,940
93
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("Even") else: print("Odd")
s634786747
Accepted
17
2,940
93
a, b = map(int, input().split()) if a * b % 2 == 0: print("Even") else: print("Odd")
s291928553
p03999
u620846115
2,000
262,144
Wrong Answer
29
9,084
125
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.
n = input() l = len(n) ans = 0 for i in range(l): for j in range(l-1): ans+=int(n[i])*(10**j)*(2**(l-1-j-1)) print(ans)
s892845653
Accepted
23
9,016
149
S = input() n = len(S) ans = 0 for i in range(n): a = int(S[i]) for j in range(n-i): ans += a * 10**j * 2**i * 2**(max(0,n-i-j-2)) print(ans)
s687580824
p03455
u863442865
2,000
262,144
Wrong Answer
17
2,940
156
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() c = int(a+b) def d(c): for i in range(4, 400): if i**2 == c: return print('Yes') return print('No') d(c)
s563672448
Accepted
17
2,940
79
a, b = map(int, input().split()) if (a*b) % 2: print('Odd') else: print('Even')
s148486077
p03659
u576335153
2,000
262,144
Wrong Answer
124
30,692
222
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|.
n = int(input()) a = list(map(int, input().split())) s = sum(a) x = 0 ans = abs(2 * a[0] - s) snuke = 0 for i in range(1, n-1): snuke += 2 * a[i] if abs(snuke - s) < ans: ans = abs(snuke - s) print(ans)
s154139080
Accepted
126
30,484
229
n = int(input()) a = list(map(int, input().split())) s = sum(a) x = 0 ans = abs(2 * a[0] - s) snuke = a[0] for i in range(1, n-1): snuke += a[i] if abs(2 * snuke - s) < ans: ans = abs(2 * snuke - s) print(ans)
s807895501
p02694
u502594696
2,000
1,048,576
Wrong Answer
30
9,120
68
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
X=int(input()) i=100 l=0 while i<=X: i=int(i*1.01) l+=1 print(l)
s904913633
Accepted
31
9,128
72
X=int(input()) i=100 year=0 while i<X: i+=i//100 year+=1 print(year)
s786923782
p03813
u102242691
2,000
262,144
Wrong Answer
17
2,940
89
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.
s = input() a_index = s.find("A") b_index = s.rfind("Z") print(b_index - a_index + 1)
s795372584
Accepted
17
2,940
72
x = int(input()) if x < 1200: print("ABC") else: print("ARC")
s305995300
p04044
u191635495
2,000
262,144
Wrong Answer
105
18,036
977
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
N, L = map(int, input().split()) S = [] master = 'abcdefghijklmnopqrstuvwxyz' def f(s1, s2, l): for i in range(l): if master.index(s1[i]) == master.index(s2[i]): continue elif master.index(s1[i]) > master.index(s2[i]): return 'greater' elif master.index(s1[i]) < master.index(s2[i]): return 'less' return 'equal' for _ in range(N): if _ == 0: S.append(input()) else: s2 = input() max_iter = len(S) for i in range(max_iter): compared = f(s2, S[i], L) print(compared) print(S) if compared == 'greater' and i == max_iter-1: S.insert(i, s2) elif compared == 'greater': continue elif compared == 'less': S.insert(i, s2) break elif compared == 'equal': S.insert(i, s2) break print(''.join(S))
s562330994
Accepted
22
3,064
920
N, L = map(int, input().split()) S = [] master = 'abcdefghijklmnopqrstuvwxyz' def f(s1, s2, l): for i in range(l): if master.index(s1[i]) == master.index(s2[i]): continue elif master.index(s1[i]) > master.index(s2[i]): return 'greater' elif master.index(s1[i]) < master.index(s2[i]): return 'less' return 'equal' for _ in range(N): if _ == 0: S.append(input()) else: s = input() max_iter = len(S) for i in range(max_iter): compared = f(s, S[i], L) if compared == 'greater' and i == max_iter-1: S.append(s) break elif compared == 'less': S.insert(i, s) break elif compared == 'equal': S.insert(i, s) break else: continue print(''.join(S))
s440189201
p03139
u597455618
2,000
1,048,576
Wrong Answer
18
2,940
85
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
n = list(map(int, input().split())) print(min(n[1], n[2])) print(max(0, n[1] - n[2]))
s743338569
Accepted
17
2,940
86
n = list(map(int, input().split())) print(min(n[1], n[2]), max(0, n[1] + n[2] - n[0]))
s663027727
p02401
u644636020
1,000
131,072
Wrong Answer
30
7,616
293
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: a, op, b = input().split() a = int(a) b = int(b) if op == '?': break if op == '+': print(a + b) if op == '-': print(a - b) if op == '*': print(a * b) if op == '/': print(a / b)
s970773177
Accepted
20
7,644
294
while True: a, op, b = input().split() a = int(a) b = int(b) if op == '?': break if op == '+': print(a + b) if op == '-': print(a - b) if op == '*': print(a * b) if op == '/': print(a // b)
s711317056
p03448
u277104886
2,000
262,144
Wrong Answer
48
3,060
222
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for i in range(a): for j in range(b): for k in range(c): if 500*i + 100*j + 50*k == x: ans += 1 print(ans)
s571038794
Accepted
49
3,060
228
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if 500*i + 100*j + 50*k == x: ans += 1 print(ans)
s005778315
p03477
u780212666
2,000
262,144
Wrong Answer
17
3,060
141
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()) L = A + B R = C + D if L >R: print("Left") if L < R: print("Right") else: print("Balanced")
s522298130
Accepted
18
2,940
139
A, B, C, D= map(int, input().split()) if A +B > C+D: print("Left") elif A+B < C+D: print("Right") else: print("Balanced")
s094232527
p02690
u402629484
2,000
1,048,576
Wrong Answer
27
9,984
2,207
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
import sys sys.setrecursionlimit(1000000000) import math from math import gcd def lcm(a, b): return a * b // gcd(a, b) from itertools import count, permutations, chain from functools import lru_cache from collections import deque, defaultdict from pprint import pprint ii = lambda: int(input()) mis = lambda: map(int, input().split()) lmis = lambda: list(mis()) INF = float('inf') N1097 = 10**9 + 7 def meg(f, ok, ng): while abs(ok-ng)>1: mid = (ok+ng)//2 if f(mid): ok=mid else: ng=mid return ok def get_inv(n, modp): return pow(n, modp-2, modp) def factorials_list(n, modp): # 10**6 fs = [1] for i in range(1, n+1): fs.append(fs[-1] * i % modp) return fs def invs_list(n, fs, modp): # 10**6 invs = [get_inv(fs[-1], modp)] for i in range(n, 1-1, -1): invs.append(invs[-1] * i % modp) invs.reverse() return invs def comb(n, k, modp): num = 1 for i in range(n, n-k, -1): num = num * i % modp den = 1 for i in range(2, k+1): den = den * i % modp return num * get_inv(den, modp) % modp def comb_from_list(n, k, modp, fs, invs): return fs[n] * invs[n-k] * invs[k] % modp # class UnionFindEx: def __init__(self, size): self.roots = [-1] * size def getRootID(self, i): r = self.roots[i] if r < 0: return i else: r = self.getRootID(r) self.roots[i] = r return r def getGroupSize(self, i): return -self.roots[self.getRootID(i)] def connect(self, i, j): r1, r2 = self.getRootID(i), self.getRootID(j) if r1 == r2: return False if self.getGroupSize(r1) < self.getGroupSize(r2): r1, r2 = r2, r1 self.roots[r1] += self.roots[r2] self.roots[r2] = r1 return True Yes = 'Yes' No = 'No' def main(): X = ii() for a in range(-70, 70): b5 = a**5 - X b = meg(lambda v: v**5<=b5, -100, 100) if b**5==b5: print(a, b) return main()
s375403495
Accepted
31
8,904
252
from itertools import count def main(): X = int(input()) for i in count(): for A in (-i, i): for B in range(-i, i+1): if A**5 - B**5 == X: print(A, B) return main()
s016995908
p02613
u671211357
2,000
1,048,576
Wrong Answer
154
16,328
282
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N=int(input()) S=[input() for i in range(N)] AC=0 WA=0 TLE=0 RE=0 for i in S: if i =="WA": WA+=1 elif i=="AC": AC+=1 elif i=="TLE": TLE+=1 else: RE+=1 print("AC x "+str(AC)) print("WA x "+str(WA)) print("TLE x",TLE) print("RE x",RE)
s126088605
Accepted
154
16,328
278
N=int(input()) S=[input() for i in range(N)] AC=0 WA=0 TLE=0 RE=0 for i in S: if i =="WA": WA+=1 elif i=="AC": AC+=1 elif i=="TLE": TLE+=1 else: RE+=1 print("AC x",str(AC)) print("WA x",str(WA)) print("TLE x",TLE) print("RE x",RE)
s614338187
p03485
u416758623
2,000
262,144
Wrong Answer
18
2,940
67
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b = [int(x) for x in input().split()] print(((a + b) // 2) + 1)
s659280693
Accepted
18
2,940
69
a,b = map(int, input().split()) total = a + b print((total+2-1) // 2)
s222470444
p02742
u215630013
2,000
1,048,576
Wrong Answer
18
2,940
137
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:
h, w = map(int, input().split()) if h ==1 or w == 1: print(1) exit() s =h* w if s%2 ==1: print(s/2 +0.5) else: print(s/2)
s714987741
Accepted
19
3,060
166
import math h, w = map(int, input().split()) if h ==1 or w == 1: print(1) exit() s =h* w if s%2 ==1: print(int(math.ceil(s/2))) else: print(int(s/2))
s189331933
p02393
u697703458
1,000
131,072
Wrong Answer
20
5,592
86
Write a program which reads three integers, and prints them in ascending order.
a=input() b=a.split() d=list() for c in b: d.append(int(c)) print(d[0],d[1],d[2])
s716471651
Accepted
20
5,596
98
a=input() b=a.split() d=list() for c in b: d.append(int(c)) d=sorted(d) print(d[0],d[1],d[2])
s960978589
p03693
u792743880
2,000
262,144
Wrong Answer
32
9,040
110
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) if (g % 2 == 0) and (b % 2 == 0): print('YES') else: print('NO')
s705591309
Accepted
27
9,096
124
r, g, b = map(int, input().split()) rgb = int(r * 100 + g * 10 + b) if rgb % 4 == 0: print('YES') else: print('NO')
s605141600
p03544
u540761833
2,000
262,144
Wrong Answer
17
3,060
174
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
n = int(input()) a0 = 2 a1 = 1 if n == 1: print(2) elif n == 2: print(1) else: for i in range(n-1): a0,a1 = a1,(a0+a1) print(a0,a1) print(a1)
s207604418
Accepted
17
2,940
128
n = int(input()) a0 = 2 a1 = 1 if n == 1: print(1) else: for i in range(n-1): a0,a1 = a1,(a0+a1) print(a1)
s840055128
p00003
u914146430
1,000
131,072
Wrong Answer
50
7,580
184
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
N=int(input()) for i in range(N): hens=list(map(int, input().split())) hens.sort() if hens[0]**2+hens[1]**2==hens[2]**2: print("Yes") else: print("No")
s155829561
Accepted
40
7,512
184
N=int(input()) for i in range(N): hens=list(map(int, input().split())) hens.sort() if hens[0]**2+hens[1]**2==hens[2]**2: print("YES") else: print("NO")
s767535502
p04043
u460129720
2,000
262,144
Wrong Answer
18
3,060
227
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.
B = map(int, input().split()) counter = 0 five_seven_five = [5,7,5] for i in B: if i in five_seven_five: counter += 1 five_seven_five.remove(i) else: print('No') if counter ==3: print('Yes')
s167833091
Accepted
17
3,060
233
B = list(map(int, input().split())) counter = 0 five_seven_five = [5,7,5] for i in B: if i in five_seven_five: counter += 1 five_seven_five.remove(i) else: print('NO') if counter ==3: print('YES')
s733797640
p02612
u922769680
2,000
1,048,576
Wrong Answer
30
9,148
40
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*1000 print(N-A)
s288355261
Accepted
27
9,152
86
N=int(input()) A=(N//1000+1)*1000 if A-N==1000: ans=0 else: ans=A-N print(ans)
s978923691
p00015
u990228206
1,000
131,072
Wrong Answer
20
5,584
129
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
n=int(input()) for i in range(n): a=int(input()) b=int(input()) if a+b>=10**79:print("overflow") else:print(a+b)
s625575862
Accepted
20
5,588
129
n=int(input()) for i in range(n): a=int(input()) b=int(input()) if a+b>=10**80:print("overflow") else:print(a+b)
s070953438
p03474
u236536206
2,000
262,144
Wrong Answer
17
3,064
277
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
a,b=map(int,input().split()) s=input() print(s) if s[a]!="-": print("No") #print(1) elif s.count("-")>1: print("No") #print(2) else: s=s.replace("-","") #print(3) #print(s) if s.isdigit()==True: print("Yes") else: print("No")
s391742531
Accepted
18
3,060
279
a,b=map(int,input().split()) s=input() #print(s) if s[a]!="-": print("No") #print(1) elif s.count("-")>1: print("No") #print(2) else: s=s.replace("-","") #print(3) #print(s) if s.isdigit()==True: print("Yes") else: print("No")
s035767564
p03378
u313111801
2,000
262,144
Wrong Answer
27
9,160
128
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
N,M,X=map(int,input().split()) A=[int(x) for x in input().split()] left=sum(x<X for x in A) right=M-left print(max(left,right))
s446157171
Accepted
24
9,036
127
N,M,X=map(int,input().split()) A=[int(x) for x in input().split()] ans=min(sum(x<X for x in A),sum(x>X for x in A)) print(ans)
s380087161
p04044
u077080573
2,000
262,144
Wrong Answer
39
3,064
569
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.
ans = "" def get_input(): flag = 1 cnt = 0 while True: try: if flag == 1: N,L = input().split() flag = 0 continue else: a = input() yield ''.join(a) cnt += 1 if cnt >= int(N): break except EOFError: break if __name__ == "__main__": array = list(get_input()) array.sort() print(array) for i in range(0,len(array)): ans += array[i] print(ans)
s311602400
Accepted
44
3,064
456
ans = "" def get_input(): flag = 1 cnt = 0 while True: if flag == 1: N,L = input().split() flag = 0 continue else: a = input() yield ''.join(a) cnt += 1 if cnt >= int(N): break if __name__ == "__main__": array = list(get_input()) array.sort() for i in range(0,len(array)): ans += array[i] print(ans)
s610826478
p02389
u421938296
1,000
131,072
Wrong Answer
30
7,508
54
Write a program which calculates the area and perimeter of a given rectangle.
a, b = list(map(int, input().split(' '))) print(a * b)
s930600619
Accepted
20
7,604
81
a, b = list(map(int, input().split(' '))) print('{} {}'.format(a * b, 2*a + 2*b))
s169567477
p03475
u088552457
3,000
262,144
Wrong Answer
106
3,188
405
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()) stations = [] for _ in range(n-1): stations.append(list(map(int, input().split()))) me = 0 for i in range(n-1): remain = n - i - 1 cost = 0 time = 0 for r in range(remain): c, s, f = stations[r+i] if time < s: time = s else: if time - s < s: time = s*2 else: time = s + ((time - s)//f)*f time += c print(time) print(0)
s085345634
Accepted
101
3,188
373
n = int(input()) stations = [] for _ in range(n-1): stations.append(list(map(int, input().split()))) me = 0 for i in range(n-1): remain = n - i - 1 time = 0 for r in range(remain): c, s, f = stations[r+i] if time < s: time = s elif time % f == 0: pass else: time = time + f - (time % f) time += c print(time) print(0)
s045626357
p03387
u597455618
2,000
262,144
Wrong Answer
17
3,060
130
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, b, c) diff = (m-a) + (m-b) + (m-c) print( (diff+3)//2 if diff%2 == 0 else diff//2 )
s840535598
Accepted
17
2,940
125
a, b, c = map(int, input().split()) m = max(a, b, c) diff = (m-a) + (m-b) + (m-c) print( (diff+3)//2 if diff%2 else diff//2 )
s216934212
p03458
u600402037
2,000
262,144
Wrong Answer
594
63,668
792
AtCoDeer is thinking of painting an infinite two-dimensional grid in a _checked pattern of side K_. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3: AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires can he satisfy at the same time?
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() table = [[0] * 2*K for _ in range(K)] for _ in range(N): x, y, c = sr().split() x = int(x); y = int(y) if c == 'B': y -= K x %= 2 * K; y %= 2 * K if x >= K and y >= K: x -= K; y -= K elif y >= K: x += K; y -= K table[y][x] += 1 table = np.array(table, dtype=np.int32) table_cum = table.cumsum(axis=1).cumsum(axis=0) table_cum[:, K:] -= table_cum[:, :-K] answer = table_cum.max() print(answer)
s461886526
Accepted
799
196,552
1,010
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() table = [[0] * 2*K for _ in range(K)] for _ in range(N): x, y, c = sr().split() x = int(x); y = int(y) if c == 'B': x -= K x %= 2 * K; y %= 2 * K if x >= K and y >= K: x -= K; y -= K elif y >= K: x += K; y -= K table[y][x] += 1 table = np.array(table, dtype=np.int32) table = np.concatenate([table, table], axis=1) table2 = np.roll(table, K, axis=1) table = np.concatenate([table, table2], axis=0) table_cum = table.cumsum(axis=1).cumsum(axis=0) prev = table_cum.copy() table_cum[:, K:] -= prev[:, :-K] table_cum[K:, :] -= prev[:-K, :] table_cum[K:, K:] += prev[:-K, :-K] answer = table_cum.max() print(answer)
s870620121
p03495
u779599374
2,000
262,144
Wrong Answer
197
40,060
294
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
N, K = map(int, input().split()) A = list(map(int, input().split())) import collections A_tuple = collections.Counter(A).most_common()[::-1] print(len(A_tuple)) if len(A_tuple) < K: print(0) else: ans = 0 for i in range(len(A_tuple)-K): ans += A_tuple[i][1] print(ans)
s439901432
Accepted
193
39,348
274
N, K = map(int, input().split()) A = list(map(int, input().split())) import collections A_tuple = collections.Counter(A).most_common()[::-1] if len(A_tuple) < K: print(0) else: ans = 0 for i in range(len(A_tuple)-K): ans += A_tuple[i][1] print(ans)
s199868965
p02273
u885889402
2,000
131,072
Wrong Answer
30
7,824
676
Write a program which reads an integer _n_ and draws a Koch curve based on recursive calles of depth _n_. The Koch curve is well known as a kind of You should start (0, 0), (100, 0) as the first segment.
import math T = [] class Vect: def __init__(self,x,y): self.x = x self.y = y def hoge(p,q): ax = q.x-p.x ay = q.y-p.y bx = ax/5 - ay*math.sqrt(3)/2 by = ax*math.sqrt(3)/2 + ay/2 nb = Vect(p.x+bx,p.y+by) return nb def koch(p,q,n): if n == 0: T.append(p) else: s = Vect(p.x+(q.x-p.x)/3,p.y+(q.y-p.y)/3) t = Vect(p.x+2*(q.x-p.x)/3, p.y+2*(q.y-p.y)/3) u = hoge(s,t) koch(p,s,n-1) koch(s,u,n-1) koch(u,t,n-1) koch(t,q,n-1) n = int(input()) koch(Vect(0,0),Vect(100,0),n) T.append(Vect(100,0)) for i in T: print("%f %f"%(i.x,i.y))
s927128739
Accepted
30
8,480
680
import math T = [] class Vect: def __init__(self,x,y): self.x = x self.y = y def hoge(p,q): ax = q.x-p.x ay = q.y-p.y bx = ax/2 - ay*math.sqrt(3)/2 by = ax*math.sqrt(3)/2 + ay/2 nb = Vect(p.x+bx,p.y+by) return nb def koch(p,q,n): if n == 0: T.append(p) else: s = Vect(p.x+(q.x-p.x)/3,p.y+(q.y-p.y)/3) t = Vect(p.x+2*(q.x-p.x)/3, p.y+2*(q.y-p.y)/3) u = hoge(s,t) koch(p,s,n-1) koch(s,u,n-1) koch(u,t,n-1) koch(t,q,n-1) n = int(input()) koch(Vect(0,0),Vect(100,0),n) T.append(Vect(100,0)) for i in T: print("%.8f %.8f"%(i.x,i.y))
s810531609
p03623
u078349616
2,000
262,144
Wrong Answer
18
2,940
89
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b = map(int, input().split()) if abs(x-a) > abs(x-b): print("A") else: print("B")
s131873403
Accepted
17
2,940
89
x,a,b = map(int, input().split()) if abs(x-a) > abs(x-b): print("B") else: print("A")
s649049497
p03435
u729214975
2,000
262,144
Wrong Answer
325
21,804
112
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
import numpy as np c = np.array([[int(i) for i in input().split()] for _ in range(3)]) print(np.sum(c) % 3 == 0)
s252246904
Accepted
153
12,516
349
import numpy as np c = np.array([[int(i) for i in input().split()] for _ in range(3)]) b = np.sum(c) % 3 == 0 b &= np.sum(c[0] - c[1]) % 3 == 0 b &= np.sum(c[0] - c[2]) % 3 == 0 b &= np.sum(c[1] - c[2]) % 3 == 0 c = c.T b &= np.sum(c[0] - c[1]) % 3 == 0 b &= np.sum(c[0] - c[2]) % 3 == 0 b &= np.sum(c[1] - c[2]) % 3 == 0 print('Yes' if b else 'No')
s135197155
p02600
u030278108
2,000
1,048,576
Wrong Answer
30
9,196
393
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
x = int(input()) if x >= 400 and 599 >= x: print("8級") elif x >= 600 and 799 >= x: print("7級") elif x >= 800 and 999 >= x: print("6級") elif x >= 1000 and 1199 >= x: print("5級") elif x >= 1200 and 1399 >= x: print("4級") elif x >= 1400 and 1599 >= x: print("3級") elif x >= 1600 and 1799 >= x: print("2級") elif x >= 1800 and 1999 >= x: print("1級")
s138831840
Accepted
34
9,132
369
x = int(input()) if x >= 400 and 599 >= x: print("8") elif x >= 600 and 799 >= x: print("7") elif x >= 800 and 999 >= x: print("6") elif x >= 1000 and 1199 >= x: print("5") elif x >= 1200 and 1399 >= x: print("4") elif x >= 1400 and 1599 >= x: print("3") elif x >= 1600 and 1799 >= x: print("2") elif x >= 1800 and 1999 >= x: print("1")
s971515624
p02390
u518939641
1,000
131,072
Wrong Answer
30
7,692
86
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
S=int(input()) h=S//3600 m=(S-h*3600)//60 s=S%3600 print(str(h)+':'+str(m)+':'+str(s))
s763703446
Accepted
20
7,688
84
S=int(input()) h=S//3600 m=(S-h*3600)//60 s=S%60 print(str(h)+':'+str(m)+':'+str(s))
s496621978
p03437
u018679195
2,000
262,144
Wrong Answer
2,104
3,060
327
You are given positive integers X and Y. If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it. If it does not exist, print -1.
import math input = str(input()).split(" ") for index in range(len(input)): input[index] = int(input[index]) x = input[0] y = input[1] def test(x, y): for index in range(-abs(y), abs(y) + 1): if (x * index % y != 0 and abs(x * index) <= 10**(18)): return x * index return -1 print(test(x,y))
s928766774
Accepted
17
3,060
380
import math x, y = map(int, input().split()) def gcd(a, b): while b != 0: a, b = b, a % b return a def lcm(x,y): return (x * y)//gcd(x, y) def thingo(x,y): if (x == 0 and y == 0): return -1 if (x != 0 and y == 0): return x test = lcm(x,y) if (test-x >= x): return test-x else: return -1 print(thingo(x,y))
s952255514
p03971
u181668771
2,000
262,144
Wrong Answer
109
4,040
693
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
def main(): from builtins import int, map, list, print import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline input_list = (lambda: input().rstrip().split()) input_number = (lambda: int(input())) input_number_list = (lambda: list(map(int, input_list()))) N, A, B = input_number_list() S = input() total = 0 total_f = 0 for c in S: isNg = False if c == 'a' and total < A + B: total += 1 elif c == 'b' and total < A + B and total_f < B: total += 1 total_f += 1 else: isNg = True print('YNeos'[isNg::2]) if __name__ == '__main__': main()
s022417256
Accepted
103
4,144
698
def main(): from builtins import int, map, list, print import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline input_list = (lambda: input().rstrip().split()) input_number = (lambda: int(input())) input_number_list = (lambda: list(map(int, input_list()))) N, A, B = input_number_list() S = input() total = 0 total_f = 0 for c in S[:-1]: isNg = False if c == 'a' and total < A + B: total += 1 elif c == 'b' and total < A + B and total_f < B: total += 1 total_f += 1 else: isNg = True print('YNeos'[isNg::2]) if __name__ == '__main__': main()
s049907183
p02694
u611090896
2,000
1,048,576
Wrong Answer
21
8,980
68
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
X = int(input()) B = 100 while (B>X): B = B + B*0.01 print(int(B))
s664809344
Accepted
24
9,064
115
X = int(input()) year = 0 deposit = 100 while deposit < X: deposit = deposit*101//100 year += 1 print(year)
s083681107
p03494
u698771758
2,000
262,144
Wrong Answer
19
2,940
165
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N=int(input()) A=list(map(int,input().split())) ans=0 f=1 while(f): for i in range(len(A)): if A[i]%2==0:A[i]/=2 else: f=0 ans+=1 print(ans)
s283222555
Accepted
19
2,940
166
N=int(input()) A=list(map(int,input().split())) ans=-1 f=1 while(f): for i in range(len(A)): if A[i]%2==0:A[i]/=2 else: f=0 ans+=1 print(ans)
s707176753
p03605
u054717609
2,000
262,144
Wrong Answer
17
2,940
193
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
n=input() n=int(n) og=n flag=0 while(n>0): d=n%10 n=n//10 if(d==7): flag=flag+1 if(flag>0): print("Yes") else: print("No")
s717430911
Accepted
17
2,940
193
n=input() n=int(n) og=n flag=0 while(n>0): d=n%10 n=n//10 if(d==9): flag=flag+1 if(flag>0): print("Yes") else: print("No")
s999585053
p03409
u451017206
2,000
262,144
Wrong Answer
25
3,064
515
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
N = int(input()) red = [list(map(int, input().split())) for i in range(N)] blue = [list(map(int, input().split())) for i in range(N)] l = [0] * N def c(a,b): if a[0] < b[0] or a[1] < b[1]:return True return False for r in red: m = 10000000 mi = -1 for i, b in enumerate(blue): if l[i]: continue if not c(r, b):continue tmp = sum([(a-b2)**2 for a,b2 in zip(r, b)]) if m > tmp: mi = i m = tmp if mi != -1: l[mi] = 1 print(sum(l))
s732650597
Accepted
20
3,064
406
N = int(input()) red = [list(map(int, input().split())) for i in range(N)] blue = [list(map(int, input().split())) for i in range(N)] a = [0] * N for x,y in sorted(blue,key=lambda x: x[0]): k = [] for i,[x2,y2] in enumerate(red): if x2 < x and y2 < y and not a[i]: k.append((x2,y2,i)) if len(k): x,y,i=sorted(k,key=lambda x:-1*x[1])[0] a[i] = 1 print(sum(a))
s480189590
p00045
u775586391
1,000
131,072
Wrong Answer
20
7,532
162
販売単価と販売数量を読み込んで、販売金額の総合計と販売数量の平均を出力するプログラムを作成してください。
import sys x,y = 0,0 n = 0 for line in sys.stdin.readlines(): print(line) a,b = map(int,line.split(',')) x += a*b y += b n += 1 print(x) print(int(y/n))
s612052918
Accepted
20
7,556
203
import sys count = 0 asum = 0 bsum = 0 for line in sys.stdin: count += 1 l = list(map(int,line.split(","))) asum += l[0]*l[1] bsum += l[1] bave = int(bsum / count + 0.5) print(asum) print(bave)
s595057224
p03485
u633914031
2,000
262,144
Wrong Answer
17
2,940
48
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.
a,b = map(int, input().split()) print((a+b)/2%1)
s253454536
Accepted
17
2,940
55
a,b = map(int, input().split()) print(int((a+b+2-1)/2))
s258588479
p03964
u905582793
2,000
262,144
Wrong Answer
21
3,188
222
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time. Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
n=int(input()) a=[list(map(int,input().split())) for i in range(n)] x,y = a[0][0],a[0][1] for i in range(1,n): xr=(a[i-1][0]+a[i][0]-1)//a[i][0] yr=(a[i-1][1]+a[i][1]-1)//a[i][1] r=max(xr,yr) x*=r y*=r print(x+y)
s299564299
Accepted
21
3,188
220
n=int(input()) a=[list(map(int,input().split())) for i in range(n)] x,y = a[0][0],a[0][1] for i in range(1,n): xr=(x+a[i][0]-1)//a[i][0] yr=(y+a[i][1]-1)//a[i][1] r=max(xr,yr) x=r*a[i][0] y=r*a[i][1] print(x+y)
s784830989
p04029
u760961723
2,000
262,144
Wrong Answer
17
2,940
36
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)
s249090860
Accepted
18
2,940
42
N = int(input()) print(int(N * (N+1)/2))
s368037277
p04043
u165268875
2,000
262,144
Wrong Answer
18
2,940
96
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()) print("YES" if A==B==5 and B==C==5 and A==C==5 else "NO")
s513127525
Accepted
18
2,940
112
A, B, C = input().split() list = [A, B, C] print("YES" if list.count("5")==2 and list.count("7")==1 else "NO")
s489236450
p02601
u624281900
2,000
1,048,576
Wrong Answer
31
9,172
198
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
a,b,c=map(int,input().split()) k=int(input()) while k>0: if a>=b: b*=2 elif b>=c: c*=2 else: break k-=1 if a<b and b<c: print("YES") else: print("NO")
s498075301
Accepted
28
9,176
198
a,b,c=map(int,input().split()) k=int(input()) while k>0: if a>=b: b*=2 elif b>=c: c*=2 else: break k-=1 if a<b and b<c: print("Yes") else: print("No")
s790061648
p03997
u144029820
2,000
262,144
Wrong Answer
17
2,940
65
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.
n=int(input()) ans=0 for i in range(n): ans+=i+1 print(ans)
s125602103
Accepted
17
2,940
64
a=int(input()) b=int(input()) c=int(input()) print((a+b)*c//2)
s645818598
p03854
u546338822
2,000
262,144
Wrong Answer
72
3,316
371
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
s = input() mojiretu = ['dream','dreamer','erase','eraser'] import re def setudan(s): if s[-5:] == 'dream' or s[-5:] == 'erase': return s[:-5] elif s[-6:] == 'eraser': return s[:-6] elif s[-7:] == 'dreamer': return s[:-7] else: return 0 while True: s = setudan(s) if s == 0: print('No') break if s =='': print('Yes') break
s545627117
Accepted
71
3,444
371
s = input() mojiretu = ['dream','dreamer','erase','eraser'] import re def setudan(s): if s[-5:] == 'dream' or s[-5:] == 'erase': return s[:-5] elif s[-6:] == 'eraser': return s[:-6] elif s[-7:] == 'dreamer': return s[:-7] else: return 0 while True: s = setudan(s) if s == 0: print('NO') break if s =='': print('YES') break