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
s745224245
p03472
u293976191
2,000
262,144
Wrong Answer
442
59,972
361
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(' ')) katana = [map(int, input().split(' ')) for _ in range(N)] dmg_wield, dmg_throw = zip(*katana) dmg_wield_max = max(dmg_wield) dmg_throw = [d for d in sorted(dmg_throw, reverse=True) if d >= dmg_wield_max] n = len(dmg_throw) H -= sum(dmg_throw) n += int(H // dmg_wield_max) if H - dmg_wield_max * n > 0: n += 1 print(n)
s698050374
Accepted
456
59,860
341
N, H = map(int, input().split(' ')) katana = [map(int, input().split(' ')) for _ in range(N)] dmg_wield, dmg_throw = zip(*katana) dmg_wield_max = max(dmg_wield) dmg_throw = sorted([d for d in dmg_throw if d > dmg_wield_max]) n = 0 while H > 0 and dmg_throw: H -= dmg_throw.pop() n += 1 print(n + max(H-1, -1) // dmg_wield_max + 1)
s703244313
p02534
u919235786
2,000
1,048,576
Wrong Answer
26
9,080
89
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`.
#a k=int(input()) ans=[] for i in range(k): ans.append('acl') a=''.join(ans) print(a)
s524925396
Accepted
25
9,080
89
#a k=int(input()) ans=[] for i in range(k): ans.append('ACL') a=''.join(ans) print(a)
s474811849
p03448
u223555291
2,000
262,144
Wrong Answer
49
2,940
219
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()) d=int(input()) count=0 for i in range(a+1): for j in range(b+1): for z in range(c+1): if a*500+b*100+c*50 == d: count+=1 print(count)
s921733597
Accepted
47
3,060
219
a=int(input()) b=int(input()) c=int(input()) d=int(input()) count=0 for i in range(a+1): for j in range(b+1): for z in range(c+1): if i*500+j*100+z*50 == d: count+=1 print(count)
s654379278
p03623
u446711904
2,000
262,144
Wrong Answer
17
2,940
61
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b=map(int,input().split());print("AB"[abs(x-a)<abs(x-b)])
s588640259
Accepted
17
2,940
61
x,a,b=map(int,input().split());print("AB"[abs(x-a)>abs(x-b)])
s200115760
p03302
u859897687
2,000
1,048,576
Wrong Answer
17
2,940
84
You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds. Note that a+b=15 and a\times b=15 do not hold at the same time.
a,b=map(int,input().split()) if a*b==15 and a+b==15: print("*") else: print("x")
s077462409
Accepted
17
2,940
99
a,b=map(int,input().split()) if a*b==15: print("*") elif a+b==15: print("+") else: print("x")
s497990880
p03434
u703890795
2,000
262,144
Wrong Answer
17
3,060
162
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())) c = 0 a.sort(reverse=True) for i in range(N): if i//2 == 0: c += a[i] else: c -= a[i] print(a[i])
s972634271
Accepted
17
2,940
158
N = int(input()) a = list(map(int,input().split())) c = 0 a.sort(reverse=True) for i in range(N): if i%2 == 0: c += a[i] else: c -= a[i] print(c)
s076675915
p03448
u488737015
2,000
262,144
Wrong Answer
56
2,940
258
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, b, c, x = map(int, [input() for i in range(4)]) count = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): total = 500 * a + 100 * b + 50 * c if total == x: count = count + 1 print(count)
s055372724
Accepted
53
2,940
258
a, b, c, x = map(int, [input() for i in range(4)]) count = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): total = 500 * i + 100 * j + 50 * k if total == x: count = count + 1 print(count)
s106082634
p02536
u790812284
2,000
1,048,576
Wrong Answer
309
12,748
1,324
There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n, m = map(int, input().split()) uf = UnionFind(n) for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 uf.union(a,b) print(uf.group_count())
s408356664
Accepted
309
12,856
1,328
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n, m = map(int, input().split()) uf = UnionFind(n) for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 uf.union(a,b) print(uf.group_count() -1 )
s369800628
p02578
u224989615
2,000
1,048,576
Wrong Answer
143
32,216
149
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
n = int(input()) a = list(map(int, input().split())) total = 0 for i in range(1, n): if a[i-1] > a[i]: total += a[i-1] - a[i] a[i] = a[i-1]
s560815092
Accepted
143
32,140
162
n = int(input()) a = list(map(int, input().split())) total = 0 for i in range(1, n): if a[i-1] > a[i]: total += a[i-1] - a[i] a[i] = a[i-1] print(total)
s963828730
p03478
u858670323
2,000
262,144
Wrong Answer
46
3,060
211
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().rstrip().split(' ')) def count(n): x = str(n) sum=0 for s in x: sum+=int(s) return sum ans=0 for i in range(1,n+1): if(a <= count(i) and count(i) <=b):ans+=1 print(ans)
s221796391
Accepted
41
3,060
212
n,a,b=map(int,input().rstrip().split(' ')) def count(n): x = str(n) sum=0 for s in x: sum+=int(s) return sum ans=0 for i in range(1,n+1): if(a <= count(i) and count(i) <=b):ans+=i print(ans)
s691011558
p03610
u239981649
2,000
262,144
Wrong Answer
18
3,188
21
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
print(input()[1::2])
s583113359
Accepted
18
3,192
20
print(input()[::2])
s962507545
p03626
u562016607
2,000
262,144
Wrong Answer
17
3,064
321
We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square. Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors. Find the number of such ways to paint the dominoes, modulo 1000000007. The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner: * Each domino is represented by a different English letter (lowercase or uppercase). * The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.
P=10**9+7 N=int(input()) S1=input() S2=input() L=[1] k=0 P=10**9+7 for i in range(1,N): if S1[i]!=S1[i-1]: L.append(0) k+=1 L[k]+=1 M=len(L) S=1 if L[k]==1: S=3 else: S=6 for i in range(1,M): if L[i-1]==1: S=(S*2)%P else: if L[i]==2: S=(S*3)%P print(S)
s716272047
Accepted
19
3,188
321
P=10**9+7 N=int(input()) S1=input() S2=input() L=[1] k=0 P=10**9+7 for i in range(1,N): if S1[i]!=S1[i-1]: L.append(0) k+=1 L[k]+=1 M=len(L) S=1 if L[0]==1: S=3 else: S=6 for i in range(1,M): if L[i-1]==1: S=(S*2)%P else: if L[i]==2: S=(S*3)%P print(S)
s951861633
p03543
u708211626
2,000
262,144
Wrong Answer
23
9,020
62
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
a=set(input()) if len(a)<2: print('Yes') else: print('No')
s274658913
Accepted
30
9,028
100
a=input() b=set(a[:-1]);c=set(a[1:]) if len(b)==1 or len(c)==1: print('Yes') else: print('No')
s828750101
p02607
u057942294
2,000
1,048,576
Wrong Answer
33
9,060
486
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
def main(): N = input_ints() a = input_int_list_in_line() print(len([True for i in range(N) if i % 2 == 0 and a[i] % 2 == 0])) def input_ints(): line_list = input().split() if len(line_list) == 1: return int(line_list[0]) else: return map(int, line_list) def input_int_list_in_line(): return list(map(int, input().split())) def input_int_tuple_list(n: int): return [tuple(map(int, input().split())) for _ in range(n)] main()
s525660682
Accepted
27
8,976
486
def main(): N = input_ints() a = input_int_list_in_line() print(len([True for i in range(N) if i % 2 == 0 and a[i] % 2 == 1])) def input_ints(): line_list = input().split() if len(line_list) == 1: return int(line_list[0]) else: return map(int, line_list) def input_int_list_in_line(): return list(map(int, input().split())) def input_int_tuple_list(n: int): return [tuple(map(int, input().split())) for _ in range(n)] main()
s761265665
p02678
u459590249
2,000
1,048,576
Wrong Answer
663
35,892
446
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
#from collections import deque n,m=map(int,input().split()) root=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) root[a-1].append(b-1) root[b-1].append(a-1) times=[0]*n sign=[-1]*n sign[0]=0 #q=deque(root[0]) flag=0 a=root[0] b=[] f=False while True: for i in a: if sign[i]==-1: sign[i]=flag b.extend(root[i]) f=True flag=i a=b b=[] if f==False: break f=False for i in range(n-1): print(sign[i+1]+1)
s646634758
Accepted
812
35,724
589
from collections import deque n,m=map(int,input().split()) root=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) root[a-1].append(b-1) root[b-1].append(a-1) times=[0]*n sign=[-1]*n sign[0]=0 color=[False]*n que=deque([0]) while que: i=que.popleft() if color[i]==False: for edge in root[i]: if color[edge]==False and sign[edge]==-1: sign[edge]=i que.append(edge) color[i]=True print('Yes') for i in range(n-1): print(sign[i+1]+1)
s854871099
p03486
u027675217
2,000
262,144
Wrong Answer
19
3,060
193
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=input() t=input() s_l,t_l=[],[] for i in s: s_l.append(i) for i in t: t_l.append(i) s_l.sort(reverse=True) t_l.sort() s="".join(s_l) t="".join(t_l) if s<t: print("Yes") else: print("No")
s913322999
Accepted
17
3,060
193
s=input() t=input() s_l,t_l=[],[] for i in s: s_l.append(i) for i in t: t_l.append(i) s_l.sort() t_l.sort(reverse=True) s="".join(s_l) t="".join(t_l) if s<t: print("Yes") else: print("No")
s573028989
p00740
u135085051
1,000
131,072
Wrong Answer
1,980
5,600
701
One of the oddest traditions of the town of Gameston may be that even the town mayor of the next term is chosen according to the result of a game. When the expiration of the term of the mayor approaches, at least three candidates, including the mayor of the time, play a game of pebbles, and the winner will be the next mayor. The rule of the game of pebbles is as follows. In what follows, _n_ is the number of participating candidates. Requisites A round table, a bowl, and plenty of pebbles. Start of the Game A number of pebbles are put into the bowl; the number is decided by the Administration Commission using some secret stochastic process. All the candidates, numbered from 0 to _n_ -1 sit around the round table, in a counterclockwise order. Initially, the bowl is handed to the serving mayor at the time, who is numbered 0. Game Steps When a candidate is handed the bowl and if any pebbles are in it, one pebble is taken out of the bowl and is kept, together with those already at hand, if any. If no pebbles are left in the bowl, the candidate puts all the kept pebbles, if any, into the bowl. Then, in either case, the bowl is handed to the next candidate to the right. This step is repeated until the winner is decided. End of the Game When a candidate takes the last pebble in the bowl, and no other candidates keep any pebbles, the game ends and that candidate with all the pebbles is the winner. A math teacher of Gameston High, through his analysis, concluded that this game will always end within a finite number of steps, although the number of required steps can be very large.
n, p = map(int,input().split()) def solve(n, p): tmp = p i = 0 person = [0] * n while(1): if tmp != 0: person[i] += 1 tmp -= 1 if person[i] == p: return i else: tmp = person[i] person[i] = 0 i += 1 if i == n: i = 0 if p == 0: for i in range(n): if person[i] > 0: return i + 1 ans = [] while(1): n, p = map(int,input().split()) if n == 0 and p == 0: for i in ans: print(i) break else: ans.append(solve(n, p))
s197619347
Accepted
3,530
5,596
604
ans = [] while True: n, p = map(int, input().split()) if n == 0 and p == 0: break stone = p person = [0] * n i = 0 while True: i = i % n if stone > 1: person[i] += 1 stone -= 1 i += 1 elif stone == 1: stone -= 1 person[i] += 1 if person[i] == p: ans.append(i) break else: i += 1 else: stone += person[i] person[i] = 0 i += 1 for i in ans: print(i)
s069600338
p03853
u516447519
2,000
262,144
Wrong Answer
19
3,188
133
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
H,W = [int(i) for i in input().split()] C = [list(input()) for i in range(H)] for num in C: print(str(num)) print(str(num))
s545356173
Accepted
18
3,060
112
H,W = [int(i) for i in input().split()] for i in range(H): s = input() print(str(s)) print(str(s))
s415925069
p03543
u170324846
2,000
262,144
Wrong Answer
18
2,940
99
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
N = input() if int(N[1:4]) % 111 == 0 or int(N[2:5]) % 111 == 0: print("Yes") else: print("No")
s466224608
Accepted
17
2,940
100
N = input() if int(N[0:3]) % 111 == 0 or int(N[1:4]) % 111 == 0: print("Yes") else: print("No")
s271258719
p00705
u798803522
1,000
131,072
Wrong Answer
240
7,596
780
The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, the chairperson requested every member to send back a list of convenient dates by E-mail. Your mission is to help the chairperson, who is now dedicated to other issues of the contest, by writing a program that chooses the best date from the submitted lists. Your program should find the date convenient for the most members. If there is more than one such day, the earliest is the best.
cond = [int(n) for n in input().split(" ")] while True: answer = [101,0] case = [] sets = set() for c in range(cond[0]): case.append([int(n) for n in input().split(" ")[1:]]) sets = sets | {n for n in case[-1]} #print(sets,case) else: for num in sets: disp = [num,0] for c in case: if num in c: disp[1] += 1 else: #print(disp,answer,cond) if (disp[1] >= cond[1] and disp[1] > answer[1] ) or (disp[1] == answer[1] and disp[0] < answer[0]): answer = disp else: print(answer[0]) cond = [int(n) for n in input().split(" ")] if cond == [0,0]: break
s456287606
Accepted
240
7,716
860
cond = [int(n) for n in input().split(" ")] while True: answer = [101,0] case = [] sets = set() for c in range(cond[0]): case.append([int(n) for n in input().split(" ")[1:]]) sets = sets | {n for n in case[-1]} #print(sets,case) else: for num in sets: disp = [num,0] for c in case: if num in c: disp[1] += 1 else: #print(disp,answer,cond) if (disp[1] >= cond[1] and disp[1] > answer[1] ) or (disp[1] == answer[1] and disp[0] < answer[0]): answer = disp else: if answer[0] == 101: print(0) else: print(answer[0]) cond = [int(n) for n in input().split(" ")] if cond == [0,0]: break
s018270949
p03544
u088488125
2,000
262,144
Wrong Answer
27
9,088
154
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()) l_b=2 l=1 if n=="1": print("2") elif n=="2": print("1") else: for i in range(3,n+1): l_bb=l_b l_b=l l=l_b+l_bb print(l)
s370154535
Accepted
28
9,176
150
n=int(input()) l_b=2 l=1 if n==0: print("2") elif n==1: print("1") else: for i in range(2,n+1): l_bb=l_b l_b=l l=l_b+l_bb print(l)
s297917306
p03759
u999893056
2,000
262,144
Wrong Answer
17
2,940
76
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c = list(map(int, input().split())) print("Yes" if b-a == c-b else "No")
s317016931
Accepted
17
2,940
78
a, b, c = map(int, input().split()) print("YES" if b - a == c - b else "NO")
s630956807
p02261
u007270338
1,000
131,072
Wrong Answer
30
6,352
683
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).
#coding:utf-8 from copy import deepcopy n = int(input()) A = list(input().split()) B = deepcopy(A) def BubbleSort(A,N): for i in range(N): for j in range(N-1,i,-1): if A[j][1] < A[j-1][1]: A[j], A[j-1] = A[j-1], A[j] def SelectionSort(A,N): for i in range(N): minj = i for j in range(i,N): if A[j][1] < A[minj][1]: minj = j A[i], A[minj] = A[minj], A[i] BubbleSort(A,n) SelectionSort(B,n) A = " ".join([data for data in A]) B = " ".join([data for data in B]) print(A) print("Stable") print(B) if A == B: print("Stable") else: print("No stable")
s011224374
Accepted
30
6,352
684
#coding:utf-8 from copy import deepcopy n = int(input()) A = list(input().split()) B = deepcopy(A) def BubbleSort(A,N): for i in range(N): for j in range(N-1,i,-1): if A[j][1] < A[j-1][1]: A[j], A[j-1] = A[j-1], A[j] def SelectionSort(A,N): for i in range(N): minj = i for j in range(i,N): if A[j][1] < A[minj][1]: minj = j A[i], A[minj] = A[minj], A[i] BubbleSort(A,n) SelectionSort(B,n) A = " ".join([data for data in A]) B = " ".join([data for data in B]) print(A) print("Stable") print(B) if A == B: print("Stable") else: print("Not stable")
s796813013
p02612
u331105860
2,000
1,048,576
Wrong Answer
124
26,884
189
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.
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) print((N-1000) % 1000)
s977123320
Accepted
116
27,004
230
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) if N % 1000 == 0: print(0) else: print(1000 - N % 1000)
s547658160
p03796
u396266329
2,000
262,144
Wrong Answer
27
2,940
76
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()) res = 1 for i in range(N): res *= i print(res%1000000007)
s910920430
Accepted
45
2,940
87
N = int(input()) res = 1 for i in range(N): res *= i+1 res %= 1000000007 print(res)
s550638171
p03359
u763534217
2,000
262,144
Wrong Answer
26
9,132
68
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a,b=map(int, input().split()) if a<b: print(a) else: print(a-1)
s467632200
Accepted
27
9,044
77
a, b = map(int, input().split()) if a <= b: print(a) else: print(a-1)
s893298069
p04029
u582243208
2,000
262,144
Wrong Answer
23
3,064
29
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))
s923418088
Accepted
23
3,064
32
n=int(input()) print(n*(n+1)//2)
s623644450
p03730
u421499233
2,000
262,144
Wrong Answer
17
3,060
183
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()) flag = False for i in range(a): tmp = b*i + c if tmp%a == 0: flag = True break if flag: print("TES") else: print("NO")
s083803718
Accepted
20
3,060
183
a,b,c = map(int,input().split()) flag = False for i in range(a): tmp = b*i + c if tmp%a == 0: flag = True break if flag: print("YES") else: print("NO")
s165101166
p02606
u205758185
2,000
1,048,576
Wrong Answer
27
9,096
117
How many multiples of d are there among the integers between L and R (inclusive)?
L, R, d = input().split() L = int() R = int() d = int() for i in range(L, R): if i % d == 0: print(i)
s718756925
Accepted
24
9,092
131
L, R, d = map(int,input().split()) ans = 0 for i in range(L, R+1): if i % d == 0: ans = ans + 1 print(ans)
s114185758
p03408
u252964975
2,000
262,144
Wrong Answer
17
3,060
245
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
N = int(input()) S = [] for i in range(N): Si = str(input()) S.append(Si) M = int(input()) T = [] for i in range(M): Ti = str(input()) T.append(Ti) total = 0 for i in range(N): if not S[i] in T: total = total + 1 print(total)
s054537432
Accepted
18
3,064
324
N = int(input()) S = [] for i in range(N): Si = str(input()) S.append(Si) M = int(input()) T = [] for i in range(M): Ti = str(input()) T.append(Ti) max_point = 0 for i in range(N): point = len([1 for s in S if s==S[i]]) - len([1 for t in T if t==S[i]]) max_point = max([max_point,point]) print(max_point)
s948934692
p02796
u178235755
2,000
1,048,576
Wrong Answer
606
51,576
323
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
n = int(input()) arms = [] for i in range(n): x, l = [int(i) for i in input().split(' ')] arms.append({"st": x-l, "ed": x+l}) arms.sort(key=lambda x: x["ed"]) print(arms) n_arm = 1 tot_end = arms[0]["ed"] for i in range(1, n): if tot_end <= arms[i]["st"]: n_arm += 1 tot_end = arms[i]["ed"] print(n_arm)
s815823243
Accepted
510
41,696
311
n = int(input()) arms = [] for i in range(n): x, l = [int(i) for i in input().split(' ')] arms.append({"st": x-l, "ed": x+l}) arms.sort(key=lambda x: x["ed"]) n_arm = 1 tot_end = arms[0]["ed"] for i in range(1, n): if tot_end <= arms[i]["st"]: n_arm += 1 tot_end = arms[i]["ed"] print(n_arm)
s730031938
p03150
u131443777
2,000
1,048,576
Wrong Answer
19
3,188
424
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
import re str_in_org = input() KEYENCE = 'keyence' flag = False for n in range(1,7): str_in = str_in_org print (n) str_div1 = KEYENCE[:n] str_div2 = KEYENCE[n:] print(str_div1) if( str_div1 in str_in ): str_in = re.split( str_div1, str_in, 2 )[1] print (str_in) if( str_div2 in str_in ): flag = True if flag == True : print ('YES') else: print ('NO')
s251310345
Accepted
19
3,188
474
import re str_in_org = input() KEYENCE = 'keyence' flag = False for n in range(1,7): str_in = str_in_org len_in = len(str_in) len_tail = len_in - (7 - n) str_div1 = str_in[:n] str_div2 = str_in[len_tail:] key_div1 = KEYENCE[:n] key_div2 = KEYENCE[n:] if( str_div1 == key_div1 and str_div2 == key_div2 ): if( str_div1 + str_div2 == KEYENCE ): flag = True if flag == True : print ('YES') else: print ('NO')
s107121395
p03795
u943657163
2,000
262,144
Wrong Answer
17
2,940
81
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.
n = int(input()) p, d =1, 10**9+7 for i in range(1,n+1): p = (p*i) % d print(p)
s507023373
Accepted
17
2,940
49
n = int(input()) print(800 * n - 200 * (n // 15))
s988836542
p03129
u902973687
2,000
1,048,576
Wrong Answer
18
2,940
113
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
N, K = map(int, input().split()) if sum([N - k for k in range(3, N+1)]) >= K: print("YES") else: print("NO")
s344064371
Accepted
18
2,940
243
N, K = map(int, input().split()) if N % 2 == 1: if len([i for i in range(N+1) if i % 2 == 1]) >= K: print("YES") else: print("NO") else: if len([i for i in range(N) if i % 2 == 1]) >= K: print("YES") else: print("NO")
s838081387
p03131
u803848678
2,000
1,048,576
Wrong Answer
18
3,060
167
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
k, a, b = list(map(int, input().split())) if a-1 >= k or a >= b-2: print(k+1) exit() ans = a k -= a-1 print(ans, k) ans += (b-a)*(k//2) ans += k%2 print(ans)
s431461297
Accepted
18
3,060
152
k, a, b = list(map(int, input().split())) if a-1 >= k or a >= b-2: print(k+1) exit() ans = a k -= a-1 ans += (b-a)*(k//2) ans += k%2 print(ans)
s055642970
p03485
u429443682
2,000
262,144
Wrong Answer
17
2,940
102
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()) if a % b == 0: print(int(a / b)) else: print(int(a / b + 1))
s970694287
Accepted
17
2,940
120
a, b = map(int, input().split()) if (a + b) % 2 == 0: print(int((a + b) / 2)) else: print(int((a + b) / 2) + 1)
s472749224
p02865
u858670323
2,000
1,048,576
Wrong Answer
17
2,940
76
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
N = int(input()) if N % 2 == 0: print(N/2 -1) else: print((N+1)/2-1)
s930941616
Accepted
20
3,060
86
N = int(input()) if N % 2 == 0: print(int(N/2 -1)) else: print(int((N+1)/2-1))
s518269977
p03623
u626228246
2,000
262,144
Wrong Answer
17
2,940
62
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b = map(int,input().split()) print(min(abs(x-a),abs(x-b)))
s838914789
Accepted
17
2,940
76
x,a,b = map(int,input().split()) print("A" if abs(x-a) < abs(x-b) else "B")
s438441302
p03372
u532966492
2,000
262,144
Wrong Answer
536
41,616
895
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
def main(): from itertools import accumulate as ac n,c=map(int,input().split()) xv=[list(map(int,input().split())) for _ in [0]*n] rmemo=[0]*n lmemo=[0]*n rmemo[0]=xv[0][1]-xv[0][0] lmemo[n-1]=xv[n-1][1]-(c-xv[n-1][0]) for i in range(1,n): rmemo[i]=rmemo[i-1]+xv[i][1]-xv[i][0]+xv[i-1][0] for i in range(n-2,-1,-1): lmemo[i]=lmemo[i+1]+xv[i][1]+xv[i][0]-xv[i+1][0] temp=rmemo[0] rmemo2=[temp]*(n+1) rmemo2[-1]=0 temp=lmemo[-1] lmemo2=[temp]*(n+1) lmemo2[-1]=0 for i in range(1,n): rmemo2[i]=max(rmemo[i],rmemo2[i-1]) for i in range(n-2,-1,-1): lmemo2[i]=max(lmemo[i],lmemo2[i+1]) #print(rmemo2) #print(lmemo) ans=max(rmemo+lmemo+[0]) for i in range(n): ans=max(ans,rmemo[i]+lmemo2[i+1]-xv[i][0]) ans=max(ans,lmemo[i]+rmemo2[i+1]+xv[i][0]-c) print(ans) main()
s353602430
Accepted
518
42,384
858
def main(): from itertools import accumulate as ac n,c=map(int,input().split()) xv=[list(map(int,input().split())) for _ in [0]*n] rmemo=[0]*n lmemo=[0]*n rmemo[0]=xv[0][1]-xv[0][0] lmemo[n-1]=xv[n-1][1]-(c-xv[n-1][0]) for i in range(1,n): rmemo[i]=rmemo[i-1]+xv[i][1]-xv[i][0]+xv[i-1][0] for i in range(n-2,-1,-1): lmemo[i]=lmemo[i+1]+xv[i][1]+xv[i][0]-xv[i+1][0] temp=rmemo[0] rmemo2=[temp]*(n) temp=lmemo[-1] lmemo2=[temp]*(n+1) lmemo2[-1]=0 for i in range(1,n): rmemo2[i]=max(rmemo[i],rmemo2[i-1]) for i in range(n-2,-1,-1): lmemo2[i]=max(lmemo[i],lmemo2[i+1]) rmemo2=[0]+rmemo2 ans=max(rmemo+lmemo+[0]) for i in range(n): ans=max(ans,rmemo[i]+lmemo2[i+1]-xv[i][0]) ans=max(ans,lmemo[i]+rmemo2[i]+xv[i][0]-c) print(ans) main()
s976093191
p03713
u786020649
2,000
262,144
Wrong Answer
254
9,232
336
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
h,w=map(int,input().split()) a1=min(h,w) a2=10**6 a3=10**6 for i in range(1,h): mx=max(w*i,(w//2)*(h-i),((w+1)//2)*(h-i)) mn=min(w*i,(w//2)*(h-i),((w+1)//2)*(h-i)) a2=min(a2,mx-mn) for j in range(1,w): mx=max(h*i,(h//2)*(w-i),((h+1)//2)*(w-i)) mn=min(h*i,(h//2)*(w-i),((h+1)//2)*(w-i)) a3=min(a3,mx-mn) print(min(a1,a2,a3))
s905222243
Accepted
259
9,236
354
h,w=map(int,input().split()) a1=min(h*(w%3!=0),w*(h%3!=0)) a2=10**6 a3=10**6 for i in range(1,h): mx=max(w*i,(w//2)*(h-i),((w+1)//2)*(h-i)) mn=min(w*i,(w//2)*(h-i),((w+1)//2)*(h-i)) a2=min(a2,mx-mn) for i in range(1,w): mx=max(h*i,(h//2)*(w-i),((h+1)//2)*(w-i)) mn=min(h*i,(h//2)*(w-i),((h+1)//2)*(w-i)) a3=min(a3,mx-mn) print(min(a1,a2,a3))
s757674844
p02612
u589361760
2,000
1,048,576
Wrong Answer
30
9,144
46
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()) price = n % 1000 print(price)
s461433169
Accepted
33
9,156
87
n = int(input()) price = n % 1000 if price == 0: print(0) else: print(1000 - price)
s988003801
p03564
u814986259
2,000
262,144
Wrong Answer
21
2,940
184
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()) ans=2**N tmp=1 for i in range(2**N - 1): for j in range(N): if i>>j %2==1: tmp*=2 else: tmp+=K ans=min(ans,tmp) print(ans)
s716805251
Accepted
20
2,940
184
N=int(input()) K=int(input()) ans=2**N for i in range(2**N): tmp=1 for j in range(N): if (i>>j) %2==1: tmp*=2 else: tmp+=K ans=min(ans,tmp) print(ans)
s128100649
p02612
u193264896
2,000
1,048,576
Wrong Answer
27
9,216
246
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.
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(readline()) ans = 1000-N print(ans) if __name__ == '__main__': main()
s515984454
Accepted
28
9,220
301
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(readline()) ans = 1000-N%1000 if ans ==1000: print(0) else: print(ans) if __name__ == '__main__': main()
s067737458
p03698
u049182844
2,000
262,144
Wrong Answer
25
8,984
107
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
def main(): s = input() ans = 'no' if len(set(s)) == len(s): ans = 'yes' print(ans)
s096086127
Accepted
29
9,020
149
def main(): s = input() ans = 'no' if len(set(s)) == len(s): ans = 'yes' print(ans) if __name__ == '__main__': main()
s072319015
p02409
u007858722
1,000
131,072
Wrong Answer
20
5,616
408
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.
roomsOfBuilding = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for l in range(n): b, f, r, v = map(int, input().split()) roomsOfBuilding[b - 1][f - 1][r - 1] += v for building in roomsOfBuilding: for rooms in building: for room in rooms: print(room, end=' ') print('') print('#' * 20)
s054836764
Accepted
20
5,624
470
roomsOfBuilding = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for l in range(n): b, f, r, v = map(int, input().split()) roomsOfBuilding[b - 1][f - 1][r - 1] += v counter = 0 for building in roomsOfBuilding: counter += 1 for rooms in building: for room in rooms: print(' ' + str(room), end='') print('') if counter < 4: print('#' * 20)
s273131324
p04043
u949414593
2,000
262,144
Wrong Answer
17
2,940
60
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
print("YNeos"[sorted(map(int,input().split()))!=[5,5,7]::2])
s082951527
Accepted
17
2,940
60
print("YNEOS"[sorted(map(int,input().split()))!=[5,5,7]::2])
s614276295
p03545
u338824669
2,000
262,144
Wrong Answer
18
3,064
477
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
ABCD=list(map(int,list(input()))) for i in range(2**3): op=[0]*3 for j in range(3): op[j]=i%2 i//=2 val=ABCD[0] for j in range(3): if op[j]==1: val+=ABCD[j+1] else: val-=ABCD[j+1] if val==7: ans=str(ABCD[0]) for j in range(3): if op[j]==1: ans+="+" else: ans+="-" ans+=str(ABCD[j+1]) print(ans) exit()
s701595536
Accepted
17
3,064
482
ABCD=list(map(int,list(input()))) for i in range(2**3): op=[0]*3 for j in range(3): op[j]=i%2 i//=2 val=ABCD[0] for j in range(3): if op[j]==1: val+=ABCD[j+1] else: val-=ABCD[j+1] if val==7: ans=str(ABCD[0]) for j in range(3): if op[j]==1: ans+="+" else: ans+="-" ans+=str(ABCD[j+1]) print(ans+"=7") exit()
s202813242
p03852
u559722042
2,000
262,144
Wrong Answer
17
2,940
169
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
if __name__ == "__main__": c = input() if c == "a" or c == "i" or c == "u" or c == "e" or c == "o": print("voewl") else: print("consonant")
s646157888
Accepted
17
2,940
169
if __name__ == "__main__": c = input() if c == "a" or c == "i" or c == "u" or c == "e" or c == "o": print("vowel") else: print("consonant")
s585201697
p02831
u265118937
2,000
1,048,576
Wrong Answer
31
9,116
62
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.
import math a,b=map(int,input().split()) print(math.gcd(a, b))
s611036745
Accepted
27
9,152
108
import math a,b=map(int,input().split()) def lcm(x, y): return (x * y) // math.gcd(x, y) print(lcm(a,b))
s800725971
p03729
u386089355
2,000
262,144
Wrong Answer
17
2,940
121
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a, b, c = input().split() if (a[len(a) - 1] == b[0]) and (b[len(b) - 1] == c[0]): print("Yes") else: print("No")
s866092335
Accepted
17
2,940
101
a, b, c = input().split() if a[-1] == b[0] and b[-1] == c[0]: print("YES") else: print("NO")
s548632563
p03861
u953379577
2,000
262,144
Wrong Answer
28
9,156
50
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,c = map(int,input().split()) print(a//c-b//c)
s824802729
Accepted
31
9,156
97
a,b,c = map(int,input().split()) if a%c == 0: print(b//c-a//c+1) else: print(b//c-a//c)
s028951481
p02927
u127499732
2,000
1,048,576
Wrong Answer
17
3,060
160
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
m,d=map(int,input().split()) x=int(d//10) a,b,c=list(range(1,10)),list(range(1,x+1)),list(range(1,m+1)) d=sum([i*b for i in a],[]) e=len(set(c)&set(d)) print(e)
s494981533
Accepted
18
3,060
408
def main(): import sys import bisect from itertools import accumulate m, d = map(int, input().split()) if d < 22: print(0) return count = 0 for i in range(22, d + 1): d1 = int(str(i)[1]) d10 = int(str(i)[0]) x = d1 * d10 if 1 <= x <= m and d1 >= 2: count += 1 print(count) if __name__ == '__main__': main()
s448958338
p03050
u136395536
2,000
1,048,576
Wrong Answer
174
2,940
182
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
import math N = int(input()) total = 0 for i in range(1,int(math.sqrt(N))): amari = i if N % amari == 0: total += N//amari - 1 #print(amari) print(total)
s590414018
Accepted
174
3,060
287
import math N = int(input()) total = 0 if N != 1: for i in range(1,int(math.sqrt(N)+1)): amari = i if N % amari == 0: k = N // amari - 1 if amari == N % k: total += N//amari - 1 #print(amari) print(total)
s505660631
p02663
u357751375
2,000
1,048,576
Wrong Answer
21
9,012
316
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?
t = list(input()) a = 0 b = 0 for i in range(len(t)): if i == 0 and t[i] == '?': t[i] = 'D' if 0 < i < len(t) - 1 and t[i] == '?': if t[i-1] == 'P': t[i] = 'D' else: t[i] = 'P' if i == len(t) -1 and t[i] == '?': t[i] = 'D' print(''.join(t))
s652236470
Accepted
22
9,172
99
H1,M1,H2,M2,K = map(int,input().split()) A = (H1 * 60) + M1 B = (H2 * 60) + M2 C = B - A print(C-K)
s091514483
p03150
u297574184
2,000
1,048,576
Wrong Answer
17
3,068
163
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
Ss = input() for i in range(8): print(i, Ss[:i] + Ss[-7+i:]) if Ss[:i] + Ss[-7+i:] == 'keyence': print('YES') break else: print('NO')
s837839606
Accepted
17
2,940
137
Ss = input() for i in range(8): if Ss[:i] + Ss[len(Ss)-7+i:] == 'keyence': print('YES') break else: print('NO')
s315522468
p02694
u297080498
2,000
1,048,576
Wrong Answer
24
9,168
146
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?
import math x = int(input()) r = 0.01 i = 0 s = 100 while True: i += 1 s = int(s * (1 + r)) if s > x: print(i) break
s046220471
Accepted
22
9,108
163
import math x = int(input()) r = 0.01 i = 0 s = 100 while True: i += 1 s = math.floor(s * (1 + r)) if s >= x: print(i) break
s315846348
p03172
u858742833
2,000
1,048,576
Wrong Answer
1,661
37,860
432
There are N children, numbered 1, 2, \ldots, N. They have decided to share K candies among themselves. Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over. Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two ways are said to be different when there exists a child who receives a different number of candies.
def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) u = [1] + [0] * K v = [1] + [0] * K s = 0 for i in A: u, v = v, u s += i t = 0 for k in range(0, i): t += u[k] v[k] = t for k in range(i, min(s, K) + 1): t += u[i] v[k] = t t -= u[k - i] print(v[K] % (10 ** 9 + 7)) main()
s265106111
Accepted
1,650
38,504
434
def main(): N, K = map(int, input().split()) A = map(int, input().split()) u = [1] + [0] * K v = [1] + [0] * K s = 1 for a in A: u, v = v, u s += a c = 0 for i, t in enumerate(u[:a + 1]): c += t v[i] = c for i, t, tt in zip(range(a + 1, K + 1), u[a + 1:s], u): c += t - tt v[i] = c print(v[K] % (10 ** 9 + 7)) main()
s806050599
p03943
u337851472
2,000
262,144
Wrong Answer
17
2,940
99
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a, b, c = map(int,input().split()) print("YES" if (a+b) == c or (b+c) == a or (c+a) == b else "NO")
s886348695
Accepted
17
2,940
99
a, b, c = map(int,input().split()) print("Yes" if (a+b) == c or (b+c) == a or (c+a) == b else "No")
s860412690
p03371
u306950978
2,000
262,144
Wrong Answer
162
3,064
211
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
a , b , c , x , y = map(int,input().split()) n = max(x,y) kar = a*x + b*y for i in range(1,n+1): if kar > a*(max(0,x-i)) + b*(max(0,y-i)) +c*i: kar = a*(max(0,x-i)) + b*(max(0,y-i)) +2*c*i print(kar)
s703808509
Accepted
156
3,064
213
a , b , c , x , y = map(int,input().split()) n = max(x,y) kar = a*x + b*y for i in range(1,n+1): if kar > a*(max(0,x-i)) + b*(max(0,y-i)) +2*c*i: kar = a*(max(0,x-i)) + b*(max(0,y-i)) +2*c*i print(kar)
s662011836
p03448
u747005359
2,000
262,144
Wrong Answer
49
3,060
227
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, b, c, x = map(int, [input() for i in range(4)]) cnt = 0 for a in range(a+1): for b in range(b+1): for c in range(c+1): if 500*a + 100*b + 50*c == x: cnt += 1 print(cnt)
s449162526
Accepted
52
3,060
211
a, b, c, x = map(int, [input() for i in range(4)]) cnt = 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: cnt += 1 print(cnt)
s185270838
p03854
u137722467
2,000
262,144
Wrong Answer
18
3,188
374
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() while(1): if s.endswith('dream'): s = s.rstrip('dream') elif s.endswith('dreamer'): s = s.rstrip('dreamer') elif s.endswith('eraser'): s = s.rstrip('eraser') elif s.endswith('erase'): s = s.rstrip('erase') else: print("NO") quit() if s == '': break print("YES")
s618370961
Accepted
67
3,188
306
s = input() while(1): if s.endswith('dream'): s = s[:-5] elif s.endswith('dreamer'): s = s[:-7] elif s.endswith('eraser'): s = s[:-6] elif s.endswith('erase'): s = s[:-5] else: print("NO") quit() if s == '': break print("YES")
s007458711
p03997
u900140292
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())/2 print((a+b)*h)
s275753708
Accepted
17
2,940
63
a=int(input()) b=int(input()) h=int(input())//2 print((a+b)*h)
s196419734
p03547
u962942039
2,000
262,144
Wrong Answer
17
3,060
119
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`. When X and Y are seen as hexadecimal numbers, which is larger?
x, y = input().split() x = int(x, 16) y = int(y, 16) if x > y: print('<') elif x < y: print('>') else: print('=')
s091734701
Accepted
17
3,060
119
x, y = input().split() x = int(x, 16) y = int(y, 16) if x > y: print('>') elif x < y: print('<') else: print('=')
s963627881
p00006
u114860785
1,000
131,072
Wrong Answer
20
5,548
19
Write a program which reverses a given string str.
print(input()[-1])
s703888402
Accepted
20
5,548
21
print(input()[::-1])
s325622089
p00063
u150984829
1,000
131,072
Wrong Answer
20
5,536
54
半角アルファベット文字列からなる、1 行あたり 100 文字以内のデータがあります。いくつかの行は対称(左端から読んでも右端から読んでも同じ)です。このデータを読み込んで、その中の対称な文字列の数を出力するプログラムを作成してください。なお、1文字だけからなる行は対称であるとします。
import sys print(e[:-1]==e[-2::-1]for e in sys.stdin)
s735478237
Accepted
20
5,552
59
import sys print(sum(e[:-1]==e[-2::-1]for e in sys.stdin))
s094930587
p02613
u960201620
2,000
1,048,576
Wrong Answer
76
16,272
397
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.
from sys import stdin n = int(stdin.readline().rstrip()) list = [] i = 0 for i in range(n): list.append(stdin.readline().rstrip()) AC = WA = TLE = RE = 0 for k in list: if k == 'AC': AC = AC + 1 if k == 'WA': WA = WA + 1 if k == 'TLE': TLE = TLE + 1 if k == 'RE': RE = RE + 1 print(f'AC × {AC}') print(f'WA × {WA}') print(f'TLE × {TLE}') print(f'RE × {RE}')
s042164689
Accepted
76
16,240
398
from sys import stdin n = int(stdin.readline().rstrip()) list = [] i = 0 for i in range(n): list.append(stdin.readline().rstrip()) AC = WA = TLE = RE = 0 for k in list: if k == 'AC': AC = AC + 1 if k == 'WA': WA = WA + 1 if k == 'TLE': TLE = TLE + 1 if k == 'RE': RE = RE + 1 print(f'AC x {AC}') print(f'WA x {WA}') print(f'TLE x {TLE}') print(f'RE x {RE}')
s267279188
p03760
u242518667
2,000
262,144
Wrong Answer
18
3,060
201
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
pw=[input() for i in range(2)] length=len(pw[0]) full_pw=[] i=0 while i < length: full_pw.append(pw[0][i]) if i !=len(pw[0])-1: full_pw.append(pw[1][i]) i+=1 print(*full_pw,sep='')
s689924806
Accepted
17
3,060
201
pw=[input() for i in range(2)] length=len(pw[0]) full_pw=[] i=0 while i < length: full_pw.append(pw[0][i]) if i <=len(pw[1])-1: full_pw.append(pw[1][i]) i+=1 print(*full_pw,sep='')
s156211437
p03854
u009219947
2,000
262,144
Wrong Answer
43
3,188
275
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`.
strings = input() word_list = ["dream", "erase", "dreamer", "eraser"] rev_list = ["maerd", "esare", "remaerd", "resare"] match = "" for s in reversed(strings): match += s if match in rev_list: match = "" if len(match) == 0: print("Yes") else: print("No")
s898362750
Accepted
43
3,188
223
strings = input() rev_list = ["maerd", "esare", "remaerd", "resare"] match = "" for s in reversed(strings): match += s if match in rev_list: match = "" if len(match) == 0: print("YES") else: print("NO")
s689335288
p03795
u736729525
2,000
262,144
Wrong Answer
18
2,940
42
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.
N = int(input()) print(N*800 - (N // 15))
s675051875
Accepted
17
2,940
46
N = int(input()) print(N*800 - (N // 15)*200)
s962859454
p04043
u134520518
2,000
262,144
Wrong Answer
17
2,940
146
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.
l = list(map(int,input().split())) s = [5,7,5] for a in l: if a in s: s.remove(a) if s == []: print('Yes') else: print('No')
s871847965
Accepted
17
2,940
146
l = list(map(int,input().split())) s = [5,7,5] for a in l: if a in s: s.remove(a) if s == []: print('YES') else: print('NO')
s612185866
p03371
u441320782
2,000
262,144
Wrong Answer
17
3,064
218
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A,B,C,X,Y=map(int,input().split()) M=[A,B,C] ans=[] ans.append(A*X+B*Y) ans.append(C*max(X,Y)*2) if A>B: ans.append(C*min(X,Y)*2+A*(X-min(X,Y))) if B>A: ans.append(C*min(X,Y)*2+B*(Y-min(X,Y))) print(min(ans))
s593839015
Accepted
101
3,064
176
A,B,C,X,Y=map(int,input().split()) ans=5000*(10**5)*2+1 for i in range(max(X,Y)+1): total=0 total=2*C*i+A*max(X-i,0)+B*max(Y-i,0) if ans>=total: ans=total print(ans)
s420950523
p03679
u374146618
2,000
262,144
Wrong Answer
17
2,940
107
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 = [int(_) for _ in input().split()] if (a+b)>x: print("dangerous") else: print("delicious")
s945531594
Accepted
17
2,940
152
x, a, b = map(int, input().split()) if b <= a: ans = "delicious" elif b > a and b <= a + x: ans = "safe" else: ans = "dangerous" print(ans)
s008441133
p02936
u610473220
2,000
1,048,576
Wrong Answer
2,108
82,552
478
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
N, Q = map(int, input().split()) ab = [] for i in range(N-1): ab.append(list(map(int, input().split()))) l = [[] for i in range(N)] for pi in ab: l[pi[0]-1].append(pi[1]-1) cou = [0] * N for i in range(Q): p, x = map(int, input().split()) p -= 1 cou[p] += x for j in l[p]: cou[j] += x for k in l[j]: cou[k] += x for h in l[k]: cou[h] += x for i in range(N): print(str(cou[i]), end = " ")
s832673887
Accepted
1,441
271,380
728
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline def g(ab: list, ans: list, check: list, i: int = 0): if len(ab[i]) == 1 and i != 0: return check[i] = False for j in ab[i]: if check[j]: ans[j] += ans[i] g(ab, ans, check, j) def main(): N, Q = map(int, input().split()) ab = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) ab[a-1].append(b-1) ab[b-1].append(a-1) ans = [0] * N check = [True] * N for _ in range(Q): p, x = map(int, input().split()) ans[p-1] += x g(ab, ans, check) print(' '.join(list(map(str, ans)))) if __name__ == '__main__': main()
s203931953
p03050
u510097799
2,000
1,048,576
Wrong Answer
149
3,060
146
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
n = int(input()) l = int(-(-(n ** (1/2)) // 1)) print(l) total = 0 for i in range(1, l): if n % i == 0: total += (n - i) // i print(int(total))
s853073979
Accepted
142
3,064
156
n = int(input()) l = int(-(-(n ** (1/2)) // 1)) total = 0 for i in range(1, l): if n % i == 0 and n != i * (i+1): total += (n - i) // i print(int(total))
s057322023
p04045
u940652437
2,000
262,144
Wrong Answer
71
9,312
383
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
N,K = map(int,input().split()) num_list=[] kari = 0 N -= 1 num_list.append(input().split()) num_list_3 = sorted(num_list) while(kari != 1): count = 0 N += 1 for i in range(K - 1): a = num_list_3[0][i] s = str(N).count(a) print(s) if(s != 0): count+= 1 print(count) if (count == 0): kari = 1 print(N)
s664422588
Accepted
412
9,132
290
n,k=map(int,input().split()) d = list(map(int,input().split())) #print(d) for i in range(n,10**5): count=0 for j in range(k): u = str(d[j]) if(str(i).count(u)==0): count+=1 #print("count:"+str(count)) if(count==k): print(i) break
s760669999
p02394
u295538678
1,000
131,072
Wrong Answer
20
7,596
121
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
w,h,x,y,r =[int(i) for i in input().split()] if(w < x+r ): print('YES') elif(h < y+r): print('YES') else: print('NO')
s333548042
Accepted
20
7,712
139
w,h,x,y,r =[int(i) for i in input().split()] if((x+r <= w) and (y+r <= h) and (0 <= x-r) and (0 <= y-r)): print('Yes') else: print('No')
s506398384
p03493
u363118893
2,000
262,144
Wrong Answer
17
2,940
35
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 = str(input()) print(S.find("1"))
s433360179
Accepted
17
2,940
38
S = str(input()) print(S.count("1"))
s588302472
p03478
u578146839
2,000
262,144
Wrong Answer
39
3,628
159
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split()) ans = 0 for i in range(1, n + 1): s=sum(map(int, str(i))) print(s) if a <= s <= b: ans += i print(ans)
s412016113
Accepted
30
2,940
146
n, a, b = map(int, input().split()) ans = 0 for i in range(1, n + 1): s=sum(map(int, str(i))) if a <= s <= b: ans += i print(ans)
s849286403
p03377
u407730443
2,000
262,144
Wrong Answer
17
2,940
96
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = [int(m) for m in input().split(" ")] print("Yes" if 0 <= x-a and x <= a+b else "No" )
s800465338
Accepted
17
2,940
95
a, b, x = [int(m) for m in input().split(" ")] print("YES" if 0 <= x-a and x <= a+b else "NO")
s050360941
p02977
u832039789
2,000
1,048,576
Wrong Answer
269
16,952
1,379
You are given an integer N. Determine if there exists a tree with 2N vertices numbered 1 to 2N satisfying the following condition, and show one such tree if the answer is yes. * Assume that, for each integer i between 1 and N (inclusive), Vertex i and N+i have the weight i. Then, for each integer i between 1 and N, the bitwise XOR of the weights of the vertices on the path between Vertex i and N+i (including themselves) is i.
n = int(input()) if n == 12: print('Yes') l = [12,1,2,3,5,6,7,9,10,11] p = l[:] for i in p: l.append(i + n) m = [4, 8, 12, 16, 20] for i,j in zip(l, l[1:]): print(i, j) for i,j in zip(m, m[1:]): print(i, j) exit() if n == 24: print('Yes') l = [24,2,4,6,7,8,9,10,11,13,14,15,17,18,19,21,22] p = l[:] for i in p: l.append(i + n) m = [1,3,5,12,16,20,23] p = m[:] m.append(24) for i in p: m.append(i + n) for i,j in zip(l, l[1:]): print(i, j) for i,j in zip(m, m[1:]): print(i, j) exit() if n == 1 or n % 2 == 0: print('No') exit() l = [False] * (n + 1) p = [n] b = bin(n)[2:][::-1] pw = 0 for i in b: if i == '1': p.append(2 ** int(pw)) l[2 ** pw] = True pw += 1 q = [] xr = 0 for i in range(1, n): if not l[i]: xr ^= i q.append(i) # print(xr) # print(p) # print(q) res1 = [] for i in p: res1.append(i) for i in p: res1.append(i + n) res2 = [] if xr == 0: res2 = [n] for i in q: res2.append(i) for i in q: res2.append(i + n) else: res2 = [] for i in q: res2.append(i) res2.append(xr) for i in q: res2.append(i + n) print('Yes') for i,j in zip(res1, res1[1:]): print(i, j) for i,j in zip(res2, res2[1:]): print(i, j)
s945567829
Accepted
266
39,200
760
n = int(input()) nn = n f = lambda x, y: x + y * nn g = lambda x: x if x % 2 == 1 else x + nn b = bin(n) if b.count('0') == len(b) - 2: print('No') exit(0) ret = [ [f(1, 0), f(2, 0)], [f(2, 0), f(3, 0)], [f(3, 0), f(1, 1)], [f(1, 1), f(2, 1)], [f(2, 1), f(3, 1)], ] if n % 2 == 0: p = 2 ** (len(b) - 3) q = n ^ 1 ^ p ret.append([g(p), f(n, 0)]) ret.append([g(q), f(n, 1)]) n -= 1 while n > 3: ret.append([f(n - 1, 0), f(n, 0)]) ret.append([f(n, 0), f(1, 1)]) ret.append([f(1, 1), f(n - 1, 1)]) ret.append([f(n - 1, 1), f(n, 1)]) n -= 2 print('Yes') for x, y in ret: print(x, y)
s149174730
p03457
u059436995
2,000
262,144
Wrong Answer
940
3,444
292
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
n = int(input()) t,x,y =(0, 0, 0) for _ in range(n): nt, nx, ny =map(int,input().split()) dis=abs(nx-x)+abs(ny-y) tim = nt - t print(dis,tim) if tim >= dis and (tim - dis) % 2 ==0: t,x,y=nt, nx, ny else: print('No') break else: print('Yes')
s537843112
Accepted
192
10,284
364
from sys import stdin input = stdin.readline lines = stdin.readlines N = int(input()) txy = ((map(int, line.split())) for line in lines()) t,x,y =(0, 0, 0) for nt, nx, ny in txy: dis=abs(nx-x)+abs(ny-y) tim = nt - t if tim >= dis and (tim - dis) % 2 ==0: t,x,y=nt, nx, ny else: print('No') break else: print('Yes')
s867515027
p03852
u103178403
2,000
262,144
Wrong Answer
17
3,060
179
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
s=input() t=['dream','dreamer','erase','eraser'] t=sorted(t,reverse=True) a=0 for i in range(4): for j in range(4): if t[i]+t[j]==s: a+=1 print("YES"if a>0 else "NO")
s043695409
Accepted
17
2,940
76
s=input() a=['a','e','i','u','o'] print('vowel' if s in a else 'consonant')
s298357130
p03251
u864013199
2,000
1,048,576
Wrong Answer
17
3,060
267
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) if X>=Y: print("War") exit() for Z in range(X,Y): if max(x)<=Z<min(y): continue else: print("War") exit() print("No War")
s371728697
Accepted
18
3,060
240
N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) if X>=Y: print("War") exit() for Z in range(X,Y): if max(x)<=Z<min(y): print("No War") exit() print("War")
s641592170
p00456
u352394527
1,000
131,072
Wrong Answer
20
5,596
125
先日,オンラインでのプログラミングコンテストが行われた. W大学とK大学のコンピュータクラブは以前からライバル関係にあり,このコンテストを利用して両者の優劣を決めようということになった. 今回,この2つの大学からはともに10人ずつがこのコンテストに参加した.長い議論の末,参加した10人のうち,得点の高い方から3人の得点を合計し,大学の得点とすることにした. W大学およびK大学の参加者の得点のデータが与えられる.このとき,おのおのの大学の得点を計算するプログラムを作成せよ.
def func(): lst = [] for i in range(10): lst.append(int(input())) lst.sort() print(sum(lst[-3:])) func() func()
s745400558
Accepted
20
5,596
132
def func(): lst = [] for i in range(10): lst.append(int(input())) lst.sort() return sum(lst[-3:]) print(func(),func())
s546572710
p02694
u624613992
2,000
1,048,576
Wrong Answer
22
9,124
132
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?
import math goal = int(input()) cnt = 0 money = 100 while goal >= money: money = math.floor(money * 1.01) cnt +=1 print(cnt)
s554097630
Accepted
25
9,168
131
import math goal = int(input()) cnt = 0 money = 100 while goal > money: money = math.floor(money * 1.01) cnt +=1 print(cnt)
s302108313
p03836
u816732092
2,000
262,144
Wrong Answer
19
3,064
330
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()) print('R'*(tx-sx),end = "") print('U'*(ty-sy),end = "") print('L'*(tx-sx),end = "") print('D'*(ty-sx+1),end = "") print('R'*(tx-sx+1),end = "") print('U'*(ty-sx+1),end = "") print('L',end = "") print('U',end = "") print('R'*(tx-sx+1),end = "") print('D'*(ty-sx+1),end = "") print('L')
s000832451
Accepted
18
3,064
338
sx , sy , tx, ty = map(int , input().split()) lx = abs(tx - sx) ly = abs(ty - sy) print('U'*ly,end = "") print('R'*lx,end = "") print('D'*ly,end = "") print('L'*(lx+1),end = "") print('U'*(ly+1),end = "") print('R'*(lx+1),end = "") print('D',end = "") print('R',end = "") print('D'*(ly+1),end = "") print('L'*(lx+1),end = "") print('U')
s665062071
p03623
u744898490
2,000
262,144
Wrong Answer
17
2,940
201
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|.
#from time import time #t = time() nvm = input().split(' ') if int(nvm[1]) - int(nvm[0]) > int(nvm[1]) - int(nvm[2]): print('A') else: print('B') #print(mn[0] * mm[1]) #tt= time() #print(tt-t)
s646374100
Accepted
17
2,940
216
#from time import time #t = time() nvm = input().split(' ') if abs(int(nvm[0]) - int(nvm[1])) < abs(int(nvm[0]) - int(nvm[2])): print('A') else: print('B') #print(mn[0] * mm[1]) #tt= time() #print(tt-t)
s383313182
p02678
u946404093
2,000
1,048,576
Wrong Answer
780
47,344
571
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
N, M = map(int,input().split()) room = {} startRoom = {1:1} for i in range(M): A, B = map(int,input().split()) room.setdefault(A, []).append(B) room.setdefault(B, []).append(A) #print(room) targetRoom = [1] while len(targetRoom) != 0: nextTarget = [] for i in targetRoom: roomList = room[i] for j in roomList: if j not in startRoom: startRoom[j] = i nextTarget.append(j) targetRoom = nextTarget #print(startRoom) if len(startRoom) != N: print("no") else: print("yes") for i in range(2, N+1): print(startRoom[i])
s272345767
Accepted
807
47,444
540
N, M = map(int,input().split()) room = {} startRoom = {1:1} for i in range(M): A, B = map(int,input().split()) room.setdefault(A, []).append(B) room.setdefault(B, []).append(A) targetRoom = [1] while len(targetRoom) != 0: nextTarget = [] for i in targetRoom: roomList = room[i] for j in roomList: if j not in startRoom: startRoom[j] = i nextTarget.append(j) targetRoom = nextTarget if len(startRoom) != N: print("No") else: print("Yes") for i in range(2, N+1): print(startRoom[i])
s033396414
p04012
u199459731
2,000
262,144
Wrong Answer
17
2,940
164
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.
c_list = list(input()) flag = True for i in range(len(c_list)): if(c_list.count(c_list[i])%2 == 1): print("NO") flag = False break if(flag): print("YES")
s262636221
Accepted
17
2,940
165
c_list = list(input()) flag = True for i in range(len(c_list)): if(c_list.count(c_list[i])%2 == 1): print("No") flag = False break if(flag): print("Yes")
s884532910
p03759
u117193815
2,000
262,144
Wrong Answer
17
2,940
79
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c=map(int, input().split()) if b-a==c-b: print("TES") else: print("NO")
s327871304
Accepted
17
2,940
80
a,b,c=map(int, input().split()) if b-a==c-b: print("YES") else: print("NO")
s527184130
p03740
u368796742
2,000
262,144
Wrong Answer
17
2,940
14
Alice and Brown loves games. Today, they will play the following game. In this game, there are two piles initially consisting of X and Y stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice: * Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile. The player who becomes unable to perform the operation, loses the game. Given X and Y, determine the winner of the game, assuming that both players play optimally.
print("Alice")
s520065233
Accepted
17
2,940
114
x,y = map(int,input().split()) if y > x: x,y = y,x if x - y <= 1: print("Brown") else: print("Alice")
s315921859
p03494
u982471399
2,000
262,144
Wrong Answer
17
3,060
253
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.
A=list(map(int,input().split())) flag=0 count=0 ans=[] for a in A: if a%2==0: count=a/2 else: count=(a-1)/2 flag=1 ans.append(count) if flag==1: print(int(min(ans))) else: print(0)
s484628323
Accepted
19
3,060
289
N=int(input()) A=list(map(int,input().split())) flag=0 ans=[] for a in A: if a%2==0:#odd count=0 while a%2==0: a=a/2 count=count+1 ans.append(count) else:#even flag=1 if flag==0: print(int(min(ans))) else: print(0)
s186065016
p03447
u320325426
2,000
262,144
Wrong Answer
17
2,940
80
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
x, a, b = [int(input()) for i in range(3)] x -= a while x > 0: x -= b print(x)
s324396036
Accepted
17
2,940
61
x, a, b = [int(input()) for i in range(3)] print((x - a) % b)
s043184097
p03192
u619670102
2,000
1,048,576
Wrong Answer
17
2,940
83
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N?
#coding:utf-8 s=input() res =0 for i in s: if i==2: res+=1 print(res)
s356577480
Accepted
17
2,940
84
#coding:utf-8 s = input() res = 0 for i in s: if i =='2': res +=1 print(res)
s206490297
p03448
u644210195
2,000
262,144
Wrong Answer
222
4,456
324
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, b, c, x = map(int, [input() for i in range(0, 4)]) count = 0 for a_i in range(0, a + 1): if a_i * 500 > x: break for b_i in range(0, b + 1): for c_i in range(0, c + 1): print(a_i, b_i, c_i) if a_i * 500 + b_i * 100 + c_i * 50 == x: count += 1 print(count)
s241784857
Accepted
42
3,060
292
a, b, c, x = map(int, [input() for i in range(0, 4)]) count = 0 for a_i in range(0, a + 1): if a_i * 500 > x: break for b_i in range(0, b + 1): for c_i in range(0, c + 1): if a_i * 500 + b_i * 100 + c_i * 50 == x: count += 1 print(count)
s071964053
p03685
u075012704
2,000
262,144
Wrong Answer
406
12,028
862
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}). The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N. Here, the curves may not go outside the board or cross each other. Determine whether this is possible.
from collections import defaultdict R, C, N = map(int, input().split()) Numbers = [] for i in range(N): x1, y1, x2, y2 = map(int, input().split()) if (x1 in [0, C] and x2 in [0, C]) or (y1 in [0, R] and y2 in [0, R]): Numbers.append([i+1, x1, y1]) Numbers.append([i+1, x2, y2]) Numbers.sort(key=lambda n: n[1]) D = defaultdict(set) for i in range(1, len(Numbers), 2): D[Numbers[i][1]].add(Numbers[i][0]) for i in range(0, len(Numbers), 2): if Numbers[i][0] not in D[Numbers[i + 1][1]]: print("NO") exit() Numbers.sort(key=lambda n: n[2]) D = defaultdict(set) for i in range(1, len(Numbers), 2): D[Numbers[i][2]].add(Numbers[i][0]) for i in range(0, len(Numbers), 2): print("NO") exit() print("YES")
s745219423
Accepted
728
36,616
1,047
R, C, N = map(int, input().split()) UP, RIGHT, DOWN, LEFT = [], [], [], [] for i in range(N): x1, y1, x2, y2 = map(int, input().split()) if 0 < x1 < R and 0 < y1 < C: continue if 0 < x2 < R and 0 < y2 < C: continue if x1 == 0: UP.append([i, y1]) elif x1 == R: DOWN.append([i, y1]) elif y1 == 0: LEFT.append([i, x1]) elif y1 == C: RIGHT.append([i, x1]) if x2 == 0: UP.append([i, y2]) elif x2 == R: DOWN.append([i, y2]) elif y2 == 0: LEFT.append([i, x2]) elif y2 == C: RIGHT.append([i, x2]) UP.sort(key=lambda x: x[1]) RIGHT.sort(key=lambda x: x[1]) DOWN.sort(key=lambda x: x[1], reverse=True) LEFT.sort(key=lambda x: x[1], reverse=True) Numbers = UP + RIGHT + DOWN + LEFT stack = [] for n, z in Numbers: if stack and stack[-1] == n: stack.pop() else: stack.append(n) print("NO" if stack else "YES")
s889400360
p03854
u236592202
2,000
262,144
Wrong Answer
19
3,188
156
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
S=input() S=S.replace('dreamr','') S=S.replace('eraser','') S=S.replace('dream','') S=S.replace('erase','') if S=='': print('Yes') else: print('No')
s382493950
Accepted
18
3,188
164
S=input() S = S.replace('eraser','') S = S.replace('erase','') S = S.replace('dreamer','') S = S.replace('dream','') if S=='': print('YES') else: print('NO')
s791276823
p03998
u016622494
2,000
262,144
Wrong Answer
18
3,060
420
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
A = list(reversed(input())) B = list(reversed(input())) C = list(reversed(input())) P = A.pop() while True: if P == "a": if len(A) == 0 : print("A") exit() P = A.pop() if P == "b": if len(B) == 0: print("B") exit() P = B.pop() if P == "c": if len(C) == 0: print("C") exit() P == C.pop()
s550272754
Accepted
17
3,064
342
sa = list(reversed(input())) sb = list(reversed(input())) sc = list(reversed(input())) s0 = sa.pop() while True: if s0 == 'a': if not sa: print('A') break s0 = sa.pop() elif s0 == 'b': if not sb: print('B') break s0 = sb.pop() else: if not sc: print('C') break s0 = sc.pop()
s349969250
p02396
u984892564
1,000
131,072
Wrong Answer
130
5,596
96
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.
for i in range(10000): x = input('Case {0}:'.format(i+1)) if int(x) == 0: break
s802306499
Accepted
160
5,596
114
for i in range(10000): x = input() if int(x) == 0: break print('Case ', i+1, ': ', x, sep='')
s881637851
p03623
u374082254
2,000
262,144
Wrong Answer
17
2,940
101
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(a - x) > abs(b - x): print("A") else: print("B")
s231097192
Accepted
17
2,940
101
x, a, b = map(int, input().split()) if abs(a - x) > abs(b - x): print("B") else: print("A")