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
s109806385
p03493
u313014073
2,000
262,144
Wrong Answer
18
3,060
130
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 = int(input()) ans = 0 if s%10==1: ans += 1 s = s//10 if s%10==1: ans += 1 s = s//10 if s==1: ans += 1 print(ans+1)
s649126219
Accepted
17
3,060
128
s = int(input()) ans = 0 if s%10==1: ans += 1 s = s//10 if s%10==1: ans += 1 s = s//10 if s==1: ans += 1 print(ans)
s505091998
p02664
u357751375
2,000
1,048,576
Wrong Answer
76
10,600
278
For a string S consisting of the uppercase English letters `P` and `D`, let the _doctoral and postdoctoral quotient_ of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3. We have a string T consisting of `P`, `D`, and `?`. Among the strings that can be obtained by replacing each `?` in T with `P` or `D`, find one with the maximum possible doctoral and postdoctoral quotient.
t = list(input()) a = 0 b = 0 for i in range(len(t)): if i == 0 and t[i] == '?': t[i] == 'D' if i > 0 and t[i] == '?': if t[i-1] == 'P': t[i] == 'D' else: t[i] == 'P' a = t.count('PD') b = t.count('D') print(a + b)
s336987182
Accepted
130
10,824
367
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' elif 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))
s109406949
p03543
u887207211
2,000
262,144
Wrong Answer
17
2,940
97
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(N[0] == N[1] == N[2] and N[1] == N[2] == N[3]): print("Yes") else: print("No")
s873112876
Accepted
18
2,940
97
N = input() ans = "No" if(N[0] == N[1] == N[2] or N[1] == N[2] == N[3]): ans = "Yes" print(ans)
s099013181
p03408
u403355272
2,000
262,144
Wrong Answer
17
3,060
176
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 = [input() for i in range(N)] M = int(input()) t = [input() for i in range(M)] le = set(s) for i in le: count = max(0,s.count(i)-t.count(i)) print(count)
s243422848
Accepted
19
3,064
204
N = int(input()) s = [input() for i in range(N)] M = int(input()) t = [input() for i in range(M)] le = list(set(s)) count = max(s.count(le[i]) - t.count(le[i]) for i in range(len(le))) print(max(0,count))
s460855247
p03359
u617659131
2,000
262,144
Wrong Answer
17
2,940
71
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)
s481378971
Accepted
17
2,940
72
a,b = map(int, input().split()) if a <= b: print(a) else: print(a-1)
s173799372
p02396
u655518263
1,000
131,072
Wrong Answer
120
7,516
136
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() if x=="0": break else: print ("Case " + str(i) + ": " + str(x))
s405489008
Accepted
130
7,408
138
for i in range(20000): x = input() if x=="0": break else: print ("Case " + str(i+1) + ": " + str(x))
s559009799
p02833
u524870111
2,000
1,048,576
Wrong Answer
22
3,444
414
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
import sys stdin = sys.stdin import copy ns = lambda: stdin.readline().rstrip() ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) n = ni() if n % 2 != 0: print(0) else: n2 = copy.copy(n) n5 = copy.copy(n) c2, c5 = 0, 0 while n2 > 1: n2 //= 2 c2 += n2 while n5 > 1: n5 //= 5 c5 += n5//2 print(c2, c5) print(min(c2, c5))
s332664996
Accepted
22
3,444
396
import sys stdin = sys.stdin import copy ns = lambda: stdin.readline().rstrip() ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) n = ni() if n % 2 != 0: print(0) else: n2 = copy.copy(n) n5 = copy.copy(n) c2, c5 = 0, 0 while n2 > 1: n2 //= 2 c2 += n2 while n5 > 1: n5 //= 5 c5 += n5//2 print(min(c2, c5))
s546983249
p02697
u420059236
2,000
1,048,576
Wrong Answer
263
35,044
339
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
#E import numpy as np n, m = list(map(int, input().split())) lists = list(np.arange(1, n+1)) list1 = lists[:n//2] list2 = lists[n//2:] num = m for i in range(m//2 +1): if num == 0: break print(list2[i],list2[len(list2)-1-i]) num -= 1 if num == 0: break print(list1[i],list1[len(list1)-1-i]) num -= 1
s778166086
Accepted
254
34,968
317
#E import numpy as np n, m = list(map(int, input().split())) lists = list(np.arange(1, n+1)) list1 = lists[:m] list2 = lists[m:] num = m for i in range(m//2 +1): if num == 0: break print(list2[i],list2[m+1-i-1]) num -= 1 if num == 0: break print(list1[i],list1[m-i-1]) num -= 1
s593428709
p03565
u624696727
2,000
262,144
Wrong Answer
17
3,064
509
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`.
if __name__ == '__main__': S = input() T = input() T_length = len(T) head = -1 for i in range(len(S)-T_length+1): counter = 0 for j in range(T_length): if(S[i+j]==T[j] or S[i+j]=='?'): counter += 1 if(counter == T_length): head = i print(head) ans = '' i=0 if(head == -1): print("UNRESTORABLE") else : while i < len(S): if(i!=head and S[i]=='?'): ans += 'a' i += 1 elif(i==head): ans += T i += T_length else : ans += S[i] i+=1 print(ans)
s822191175
Accepted
17
3,064
496
if __name__ == '__main__': S = input() T = input() T_length = len(T) head = -1 for i in range(len(S)-T_length+1): counter = 0 for j in range(T_length): if(S[i+j]==T[j] or S[i+j]=='?'): counter += 1 if(counter == T_length): head = i ans = '' i=0 if(head == -1): print("UNRESTORABLE") else : while i < len(S): if(i!=head and S[i]=='?'): ans += 'a' i += 1 elif(i==head): ans += T i += T_length else : ans += S[i] i+=1 print(ans)
s775407025
p03048
u854093727
2,000
1,048,576
Wrong Answer
1,587
2,940
153
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
R,G,B,N = map(int,input().split()) ans = 0 for i in range(N): for e in range(N-R*i): if (N-i*i-e*G)%B == 0: ans += 1 print(ans)
s538161571
Accepted
1,531
3,316
158
R,G,B,N = map(int,input().split()) ans=0 for i in range(N//R+1): for e in range((N-R*i)//G+1): if (N-i*R-e*G)%B==0: ans+=1 print(ans)
s009341856
p03050
u565387531
2,000
1,048,576
Wrong Answer
19
2,940
132
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()) ans = 0 while N > 2: if N % 2 == 1: ans += N-1 break ans += N - 1 N = N / 2 print(ans)
s483211388
Accepted
115
3,268
372
N = int(input()) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors ans = 0 for i in make_divisors(N): if i > 1 and N // (i - 1) == N % (i - 1): ans += i - 1 print(ans)
s901412886
p02409
u391228754
1,000
131,072
Wrong Answer
20
7,660
321
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()) a =[[[0 for i in range(10)]for j in range(3)]for k in range(4)] for i in range(n): b, f, r, v = map(int, input().split()) a[b-1][f-1][r-1] += v for i in range(4): for j in range(3): for k in range(10): print(" ", a[i][j][k], end='') print() print("#" * 20)
s098810223
Accepted
30
7,716
339
n = int(input()) a =[[[0 for i in range(10)]for j in range(3)]for k in range(4)] for i in range(n): b, f, r, v = map(int, input().split()) a[b-1][f-1][r-1] += v for i in range(4): for j in range(3): for k in range(10): print("", a[i][j][k], end='') print() if i != 3: print("#" * 20)
s862731170
p03644
u223904637
2,000
262,144
Wrong Answer
17
2,940
151
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()) def ans(n): r=0 while n%2==0: n=n//2 r+=1 return r a=0 for i in range(1,n+1): a=max(a,ans(i)) print(a)
s760629846
Accepted
17
2,940
154
n=int(input()) def ans(n): r=0 while n%2==0: n=n//2 r+=1 return r a=0 for i in range(1,n+1): a=max(a,ans(i)) print(2**a)
s586041216
p03591
u785220618
2,000
262,144
Wrong Answer
17
2,940
72
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`.
s = input() if s[:4] == 'YAKi': print('Yes') else: print('No')
s211891099
Accepted
17
2,940
72
s = input() if s[:4] == 'YAKI': print('Yes') else: print('No')
s431884264
p02408
u098047375
1,000
131,072
Wrong Answer
30
5,728
870
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
n = int(input()) a = [] for i in range(n): x, y = input().split() a.append([x, y]) trump = [] for i in range(1,14): trump.append(['S', str(i)]) trump.append(['H', str(i)]) trump.append(['C', str(i)]) trump.append(['D', str(i)]) miss = [] for i in range(len(trump)): for j in range(len(a)): if trump[i] != a[j]: miss.append(trump[i]) miss.sort() for i in range(len(miss)): x = miss[i] if x[0] == "S": print(x[0] + ' '+ str(x[1])) for i in range(len(miss)): x = miss[i] if x[0] == "H": print(x[0] + ' '+ str(x[1])) for i in range(len(miss)): x = miss[i] if x[0] == "C": print(x[0] + ' '+ str(x[1])) for i in range(len(miss)): x = miss[i] if x[0] == "D": print(x[0] + ' '+ str(x[1]))
s219355041
Accepted
30
5,612
981
n = int(input()) a = [] for i in range(n): x, y = input().split() a.append([x, y]) trump = [] for i in range(1,14): trump.append(['S', str(i)]) trump.append(['H', str(i)]) trump.append(['C', str(i)]) trump.append(['D', str(i)]) dif = [] for i in range(1,14): dif.append(['S', str(i)]) dif.append(['H', str(i)]) dif.append(['C', str(i)]) dif.append(['D', str(i)]) for i in range(len(trump)): for j in range(len(a)): if trump[i] == a[j]: dif.remove(trump[i]) for i in range(len(dif)): x = dif[i] if x[0] == "S": print(x[0] +' '+ x[1]) for i in range(len(dif)): x = dif[i] if x[0] == "H": print(x[0] + ' '+ x[1]) for i in range(len(dif)): x = dif[i] if x[0] == "C": print(x[0] + ' '+ x[1]) for i in range(len(dif)): x = dif[i] if x[0] == "D": print(x[0] + ' '+ x[1])
s994069358
p03485
u209594105
2,000
262,144
Wrong Answer
17
2,940
87
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.
str = input() a = int(str.split()[0]) b = int(str.split()[1]) print(int((a+b)/2 + 1))
s598930198
Accepted
17
2,940
89
str = input() a = int(str.split()[0]) b = int(str.split()[1]) print(int((a+b)/2 + 0.5))
s583723899
p03863
u667024514
2,000
262,144
Wrong Answer
20
3,316
92
There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s. The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
s = str(input()) if ((len(s)%2) ^ (s[0] == s[-1])): print("Second") else: print("First")
s533556623
Accepted
20
3,316
87
s = str(input()) if ((len(s)%2) ^ (s[0] == s[-1])):print("First") else:print("Second")
s702494304
p03447
u780812005
2,000
262,144
Wrong Answer
17
2,940
98
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?
def resolve(): X = int(input()) A = int(input()) B = int(input()) print((X-A)%B)
s252322656
Accepted
17
3,064
143
def resolve(): X = int(input()) A = int(input()) B = int(input()) print((X-A)%B) if __name__ == "__main__": resolve()
s246777939
p03730
u289288647
2,000
262,144
Wrong Answer
25
9,132
162
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`.
import sys A, B, C = map(int, input().split()) i = 1 while (A*i)%B != C: i += 1 if i > 100: print('NO') sys.exit() print(i) print('YES')
s458312441
Accepted
24
9,152
153
import sys A, B, C = map(int, input().split()) i = 1 while (A*i)%B != C: i += 1 if i > 100: print('NO') sys.exit() print('YES')
s801461782
p02389
u546130344
1,000
131,072
Wrong Answer
20
5,592
113
Write a program which calculates the area and perimeter of a given rectangle.
a, b = input().strip().split(' ') a, b = [int(a), int(b)] men = a * b syu = 2 * (a + b) print(men) print(syu)
s792587245
Accepted
20
5,588
124
a, b = input().strip().split(' ') a, b = [int(a), int(b)] men = a * b syu = 2 * (a + b) print(str(men) + ' ' + str(syu))
s331072957
p02613
u581511366
2,000
1,048,576
Wrong Answer
139
9,128
227
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.
def main(): N = int(input()) di = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0} for _ in range(N): di[input()] += 1 for k, v in di.items(): print(f"{k} × {v}") if __name__ == "__main__": main()
s566055044
Accepted
65
9,192
290
import sys def input(): return sys.stdin.readline().strip() def main(): N = int(input()) di = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0} for _ in range(N): di[input()] += 1 for k, v in di.items(): print(f"{k} x {v}") if __name__ == "__main__": main()
s237064084
p02678
u164471280
2,000
1,048,576
Wrong Answer
2,211
38,924
618
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()) ANS = [-1]*(n+1) P = [] L = [[] for i in range(n+1)] for i in range(m): a, b = map(int, input().split()) if a == 1: ANS[b] = 1 P.append(b) elif b == 1: ANS[a] = 1 P.append(a) else: L[a].append(b) L[b].append(a) print(L, ANS, P) i = 0 while len(P) < n-1: for j in range(1, n+1): if P[i] in L[j] and ANS[j] == -1: P.append(j) L[j].remove(P[i]) ANS[j] = P[i] # print(i, P[i], j, L, ANS, P) i += 1 print('Yes') for i in range(2, n+1): print(ANS[i])
s881104583
Accepted
677
33,932
454
from collections import deque n, m = map(int, input().split()) L = [[] for i in range(n)] for i in range(m): a, b = map(int, input().split()) L[a-1].append(b-1) L[b-1].append(a-1) d = deque([0]) D = [-1] * n D[0] = 0 while len(d) > 0 : t = d.popleft() for i in L[t]: if D[i] == -1: D[i] = t d.append(i) # print(d, D) print('Yes') for i in range(1, n): print(D[i]+1)
s491493729
p03555
u014646120
2,000
262,144
Wrong Answer
17
2,940
169
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.
C11C12C13=input() C21C22C23=input() if (C11C12C13[0]==C21C22C23[2] and C11C12C13[2]==C21C22C23[0] and C11C12C13[1]==C21C22C23[1]): print("Yes") else: print("No")
s886548662
Accepted
17
2,940
170
C11C12C13=input() C21C22C23=input() if (C11C12C13[0]==C21C22C23[2] and C11C12C13[2]==C21C22C23[0] and C11C12C13[1]==C21C22C23[1]): print("YES") else: print("NO")
s947509104
p03377
u217526092
2,000
262,144
Wrong Answer
17
2,940
126
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 A, B, X = [int(i) for i in input().split()] if X <= A and X - A <= B: print('Yes') else: print('No')
s396284460
Accepted
17
2,940
118
# coding: utf-8 A, B, X = map(int, input().split()) if X >= A and X - A <= B: print('YES') else: print('NO')
s885983711
p03698
u785066634
2,000
262,144
Wrong Answer
17
2,940
362
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s=list(input()) for i in range(len(s)): for j in range(i+1,len(s)): if s[i]!=s[j]: pass else: print('s[i]',s[i],'s[j]',s[j]) print('No') exit() print('Yes')
s158482473
Accepted
17
2,940
363
s=list(input()) for i in range(len(s)): for j in range(i+1,len(s)): if s[i]!=s[j]: pass else: #print('s[i]',s[i],'s[j]',s[j]) print('no') exit() print('yes')
s871666740
p03478
u635273885
2,000
262,144
Wrong Answer
35
3,060
208
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()) sum = 0 cnt = 0 for i in range(1, N+1): words_i = str(i) for word_i in words_i: sum += int(word_i) if A <= sum <= B: cnt += 1 print(cnt)
s317170526
Accepted
34
3,060
216
N, A, B = map(int, input().split()) sums = 0 cnt = 0 for i in range(1, N+1): words_i = str(i) for word_i in words_i: sums += int(word_i) if A <= sums <= B: cnt += i sums = 0 print(cnt)
s768035195
p03150
u077075933
2,000
1,048,576
Wrong Answer
18
3,064
393
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.
arr = input() KEY = "keyence" def solve(): index = 0 state = 0 for letter in arr: print(arr, state) if letter == KEY[index]: index+=1 if index == 7: return "YES" if state == 1: state = 2 else: if state == 0: state = 1 elif state == 1: pass elif state == 2: return "NO" return "NO" print(solve())
s575481287
Accepted
17
2,940
205
def solve(): arr = input() KEY = "keyence" N = len(arr) L = N-7 for s in range(N-L): extracted = arr[:s]+arr[s+L:] if(extracted == KEY): return "YES" return "NO" print(solve())
s622944542
p03712
u444238096
2,000
262,144
Wrong Answer
17
3,060
186
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
H, W = map(int, input().split()) mylist=[] for i in range(H): var = input() mylist.append(var) print("*"*(W+2)) for i in range(H): print ("*"+mylist[i]+"*") print("*"*(W+2))
s861065883
Accepted
18
3,060
186
H, W = map(int, input().split()) mylist=[] for i in range(H): var = input() mylist.append(var) print("#"*(W+2)) for i in range(H): print ("#"+mylist[i]+"#") print("#"*(W+2))
s195518383
p03860
u566321790
2,000
262,144
Wrong Answer
17
2,940
46
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.
name = str(input()) print('A' + name[0] + 'C')
s907578629
Accepted
17
2,940
63
a, b, c = map(str, input().split()) print(a[0] + b[0] + c[0])
s166928088
p04029
u244203620
2,000
262,144
Wrong Answer
17
2,940
31
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
a=int(input()) print(a*(a+1)/2)
s308328497
Accepted
17
2,940
36
a=int(input()) print(int(a*(a+1)/2))
s398098923
p04043
u909851424
2,000
262,144
Wrong Answer
17
2,940
220
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.
args = input().split() five = 0 seven = 0 for arg in args: print(arg) if arg == "5": five = five + 1 else: seven = seven + 1 if five == 2 and seven == 1: print("YES") else: print("NO")
s881434021
Accepted
17
2,940
205
args = input().split() five = 0 seven = 0 for arg in args: if arg == "5": five = five + 1 else: seven = seven + 1 if five == 2 and seven == 1: print("YES") else: print("NO")
s016189797
p03129
u325227960
2,000
1,048,576
Wrong Answer
17
2,940
80
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
a,b=map(int,input().split()) if a<=b+1 : print("No") else : print("Yes")
s179685167
Accepted
18
2,940
121
a,b=map(int,input().split()) if (a%2==1 and a>=(b-1)*2) or (a%2==0 and a>=b*2) : print("YES") else : print("NO")
s786448602
p03433
u670481241
2,000
262,144
Wrong Answer
17
2,940
69
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input()) a = int(input()) r = "YES" if n % 500 <= a else "NO"
s193103906
Accepted
17
3,064
78
n = int(input()) a = int(input()) r = "Yes" if n % 500 <= a else "No" print(r)
s044497336
p03854
u844789719
2,000
262,144
Wrong Answer
19
3,188
137
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`.
if input().replace('dreamer', '').replace('eraser', '').replace('dream', '').replace('erase', ''): print('No') else: print('Yes')
s715515245
Accepted
67
3,188
246
Cr = input() while Cr: if Cr[-7:] == 'dreamer': Cr = Cr[0:-7] elif Cr[-6:] == 'eraser': Cr = Cr[0:-6] elif Cr[-5:] in ['dream', 'erase']: Cr = Cr[0:-5] else: print('NO') exit() print('YES')
s056220284
p03448
u320098990
2,000
262,144
Wrong Answer
26
9,188
286
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.
in_a = input() in_b = input() in_c = input() in_x = input() A = int(in_a) B = int(in_b) C = int(in_c) X = int(in_x) count = 0 for i in range(A+1): for j in range(B+1): k = ( X - 500*i - 100*j ) / 50 if k.is_integer() and k <= C: count +=1 print(count)
s212332322
Accepted
27
9,084
392
in_a = input() in_b = input() in_c = input() in_x = input() A = int(in_a) B = int(in_b) C = int(in_c) X = int(in_x) count = 0 for i in range(A+1): for j in range(B+1): k = ( X - 500*i - 100*j ) / 50 if k < 0: break; elif k.is_integer() and k <= C: count +=1 # print('clear', k, count) print(count)
s059936424
p03378
u125568248
2,000
262,144
Wrong Answer
17
2,940
209
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 = list(map(int, input().split())) c = 0 for b in a: c += 1 if x < b: if c < (m/2): print(c) else: print(m-c) break
s089895199
Accepted
17
3,060
224
n, m, x = map(int, input().split()) a = list(map(int, input().split())) c = 0 for b in a: c += 1 if x < b: c -= 1 if c < (m/2): print(c) else: print(m-c) break
s511206849
p03456
u521241621
2,000
262,144
Wrong Answer
18
2,940
149
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
import math d = input() n1, n2 = d.split(" ") num = n1 + n2 square = math.sqrt(int(num)) if square.is_integer(): print("Yex") else: print("No")
s431885803
Accepted
17
2,940
150
import math d = input() n1, n2 = d.split(" ") num = n1 + n2 square = math.sqrt(int(num)) if square.is_integer(): print("Yes") else: print("No")
s910387894
p03605
u785205215
2,000
262,144
Wrong Answer
17
2,940
69
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 = str(input()) if "9" in n: print("yes") else: print("no")
s400029980
Accepted
18
2,940
68
n = str(input()) if "9" in n: print("Yes") else: print("No")
s173766216
p03160
u790053529
2,000
1,048,576
Wrong Answer
119
14,724
349
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.
def cost(n, nums): dp = [0 for _ in range(n)] dp[0] = 0 dp[1] = abs(nums[1] - nums[0]) for i in range(2, n): dp[i] = min( dp[i-1] + abs(nums[i]-nums[i-1]), dp[i-2] + abs(nums[i]-nums[i-2])) print(dp) return dp[-1] n = int(input()) nums = [int(i) for i in input().split()] print(cost(n, nums))
s106191914
Accepted
109
13,924
336
def cost(n, nums): dp = [0 for _ in range(n)] dp[0] = 0 dp[1] = abs(nums[1] - nums[0]) for i in range(2, n): dp[i] = min( dp[i-1] + abs(nums[i]-nums[i-1]), dp[i-2] + abs(nums[i]-nums[i-2])) return dp[-1] n = int(input()) nums = [int(i) for i in input().split()] print(cost(n, nums))
s718813099
p03485
u871841829
2,000
262,144
Wrong Answer
17
2,940
73
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
import math a,b = map(int, input().split()) print(int(math.ceil(a+b/2)))
s001366706
Accepted
17
2,940
75
import math a,b = map(int, input().split()) print(int(math.ceil((a+b)/2)))
s217672762
p03129
u514222361
2,000
1,048,576
Wrong Answer
17
2,940
159
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
# -*- coding: utf-8 -*- import sys i_str = input().split(' ') a = int(i_str[0]) n = int(i_str[0]) if (a+1) / 2 >= n: print("YES") else: print("NO")
s714794118
Accepted
17
2,940
158
# -*- coding: utf-8 -*- import sys i_str = input().split(' ') a = int(i_str[0]) n = int(i_str[1]) if (a+1) / 2 >= n: print("YES") else: print("NO")
s350989426
p02603
u094534261
2,000
1,048,576
Wrong Answer
35
9,172
170
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
n=int(input()) a=list(map(int,input().split())) ans=1000 for i in range(1,n): if a[i]>a[i-1]: ans += (a[i]-a[i-1])*(ans//a[i-1]) print(ans) print(ans)
s705836349
Accepted
28
9,176
151
n=int(input()) a=list(map(int,input().split())) ans=1000 for i in range(1,n): if a[i]>a[i-1]: ans += (a[i]-a[i-1])*(ans//a[i-1]) print(ans)
s979325252
p04029
u381585104
2,000
262,144
Wrong Answer
27
9,012
33
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)
s430656580
Accepted
26
9,060
35
n = int(input()) print(n*(n+1)//2)
s391187463
p03494
u412481017
2,000
262,144
Wrong Answer
20
2,940
244
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.
# -*- coding: utf-8 -*- a = int(input()) b = input().split(" ") i=1 while 1: flag=0 for item in b: if int(item)%2**i!=0: flag=1 if flag==1: break i=i+1 print(i)
s036415896
Accepted
23
3,060
265
# -*- coding: utf-8 -*- a = int(input()) b = input().split(" ") i=1 while 1: flag=0 for item in b: if int(item)%2**i!=0: #print(item) flag=1 if flag==1: break i=i+1 print(i-1)
s063705457
p04029
u608355135
2,000
262,144
Wrong Answer
17
2,940
45
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
a = int(input()) b = a * (a + 1 ) /2 print(b)
s071993112
Accepted
17
2,940
51
a = int(input()) b = a * (a + 1) / 2 print(int(b))
s427311382
p03251
u730043482
2,000
1,048,576
Wrong Answer
17
3,060
274
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.
M, N, X, Y = map(int, input().split()) xs = list(map(int,input().split())) ys = list(map(int,input().split())) result = "War" if X > Y: result = "No War" xMax = max(xs) yMin = min(ys) if xMax > yMin: if result == "War": result = "No War" print(result)
s104885324
Accepted
18
3,064
622
def main(): M, N, X, Y = map(int, input().split()) xs = list(map(int,input().split())) ys = list(map(int,input().split())) zs = [] for n in range(X+1,Y+1): zs.append(n) xMax = max(xs) yMin = min(ys) tmp = [] for z in zs: if z > xMax: tmp.append(z) if z <= yMin: tmp.append(z) flag = False for z in zs: if tmp.count(z) > 1: flag = True if len(zs) == 0: print("War") return 0 if flag: print("No War") else: print("War") if __name__ == "__main__": main()
s171405590
p02645
u030278108
2,000
1,048,576
Wrong Answer
24
9,560
94
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
import random S = str(input()) A = list(S) N = random.sample(A, k=3) print(N[0]+N[1]+N[2])
s859550189
Accepted
25
9,536
59
import random S = str(input()) A = list(S) print(S[0:3])
s749438849
p02833
u557565572
2,000
1,048,576
Wrong Answer
17
2,940
179
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
n = int(input()) ans = 0 if n%2==0: n /= 2 fives = 5 while 1: if fives > n: break ans += n // fives fives *= 5 print(ans)
s330181816
Accepted
17
3,060
182
n = int(input()) ans = 0 if n % 2 == 0: n = n // 2 fives = 5 while 1: if fives > n: break ans += n // fives fives *= 5 print(ans)
s491704532
p02694
u949618949
2,000
1,048,576
Wrong Answer
21
9,024
87
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()) S = 100 C = 0 while X >= S: S = int(S * 1.01) C += 1 print(C)
s320381814
Accepted
23
9,156
86
X = int(input()) S = 100 C = 0 while X > S: S = int(S * 1.01) C += 1 print(C)
s315689426
p04043
u771538568
2,000
262,144
Wrong Answer
17
2,940
124
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()) d=min(a,b,c) e=max(a,b,c) if d==5 and e==7 and a+b+c==17: print("Yes") else: print("No")
s492901655
Accepted
17
3,060
123
a,b,c=map(int,input().split()) d=min(a,b,c) e=max(a,b,c) if d==5 and e==7 and a+b+c==17: print("YES") else: print("NO")
s719363869
p03371
u358254559
2,000
262,144
Wrong Answer
17
3,060
362
"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()) res=0 if X > 0: if A > 2 * C: res += C * 2*X Y -= X else: res += X * A if Y > 0: if B > 2 * C: res += C*2*Y else: res+= Y * B print(res)
s020746378
Accepted
17
3,064
573
A,B,C,X,Y = map(int, input().split()) res=0 if X>0 and Y>0: if A+B > 2*C: minxy = min(X,Y) res += 2 * C * minxy X -= minxy Y -= minxy # here, X == 0 or Y == 0 if X > 0: if A > 2 * C: res += C * 2*X Y -= X else: res += X * A if Y > 0: if B > 2 * C: res += C*2*Y else: res+= Y * B print(res)
s867493645
p03555
u983918956
2,000
262,144
Wrong Answer
17
2,940
122
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
s,t = [input() for i in range(2)] if s[0] == t[2] and s[1] == t[1] and s[2] == t[0]: print("Yes") else: print("No")
s460643616
Accepted
17
3,060
119
s,t = [input() for i in range(2)] if s[0] == t[2] and s[1] == t[1] and s[2] == t[0]: print("YES") else: print("NO")
s420631101
p03455
u177775074
2,000
262,144
Wrong Answer
24
8,928
85
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")
s696990860
Accepted
24
9,100
85
a,b = map(int,input().split()) if a*b % 2 == 0: print("Even") else: print("Odd")
s807936665
p03610
u153147777
2,000
262,144
Wrong Answer
29
3,572
70
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input() print(''.join([c for i, c in enumerate(s) if i % 2 == 1]))
s159722426
Accepted
29
3,572
70
s = input() print(''.join([c for i, c in enumerate(s) if i % 2 == 0]))
s094706954
p03456
u014333473
2,000
262,144
Wrong Answer
27
8,916
59
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a,b=input().split();print('EOvdedn'[eval(a+'*'+b)%2!=0::2])
s523308169
Accepted
25
9,332
69
a,b=input().split();print('YNeos'[int(a+b)!=int(int(a+b)**.5)**2::2])
s993646128
p03814
u513081876
2,000
262,144
Wrong Answer
18
3,516
94
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
S = input() SS = S[::-1] ind_A = S.index('A') ind_Z = SS.index('Z') print(len(S[ind_A:ind_Z]))
s979347026
Accepted
44
3,500
179
s = input() for ind, i in enumerate(s): if i == 'A': num1 = ind break for ind, i in enumerate(s): if i == 'Z': num2 = ind print(num2 - num1 + 1)
s621267076
p03455
u829393411
2,000
262,144
Wrong Answer
17
2,940
84
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%2==0 or b%2==0: print("Odd") else: print("Even")
s657888436
Accepted
17
2,940
87
a , b =map(int,input().split()) if a%2==0 or b%2==0: print("Even") else: print("Odd")
s839372469
p02394
u042885182
1,000
131,072
Wrong Answer
30
7,480
671
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.
# coding: utf-8 # Here your code ! import math def func(): try: line=input().rstrip() numbers=line.split(" ") width=float(numbers[0]) height=float(numbers[1]) x=float(numbers[2]) y=float(numbers[3]) r=abs(float(numbers[4])) except: print("input error") return -1 wsign=math.copysign(1,width) hsign=math.copysign(1,height) result=(abs(x)+r <= wsign*width) result=result and (abs(x)-r >= 0) result=result and (abs(y)+r <= hsign*height) result=result and (abs(y)-r >= 0) if result: print("Yes") else: print("No")
s925843859
Accepted
20
7,660
666
# coding: utf-8 # Here your code ! import math def func(): try: line=input().rstrip() numbers=line.split(" ") width=float(numbers[0]) height=float(numbers[1]) x=float(numbers[2]) y=float(numbers[3]) r=abs(float(numbers[4])) except: print("input error") return -1 wsign=math.copysign(1,width) hsign=math.copysign(1,height) result="No" if(wsign*x+r <= wsign*width): if(wsign*x-r >= 0): if(hsign*y+r <= hsign*height): if(hsign*y-r >= 0): result="Yes" print(result) func()
s690956531
p03048
u227085629
2,000
1,048,576
Time Limit Exceeded
2,104
2,940
167
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
r,g,b,n = map(int,input().split()) c = 0 for i in range(3001): for j in range(3001): for k in range(3001): if i*r + j*g + k*b == n: c += 1 print(c)
s519749978
Accepted
1,936
2,940
166
r,g,b,n = map(int,input().split()) c = 0 for i in range(n//r+1): for j in range((n-i*r)//g+1): k = (n-i*r-j*g) if k%b == 0 and k >= 0: c += 1 print(c)
s811323533
p03680
u762008592
2,000
262,144
Wrong Answer
17
3,060
176
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
N = int(input()) a_n=list(map(int,input().split())) if 2 not in a_n: print(-1) else: for i in range(N): if a_n[i]==2: print(i+1) break
s488074818
Accepted
193
7,084
231
N = int(input()) a_n=[int(input()) for i in range(N)] import sys i=1 count=0 for k in range(N): if a_n[i-1]==2: count+=1 print(count) sys.exit() else: i=a_n[i-1] count+=1 print(-1)
s351464665
p02612
u888933875
2,000
1,048,576
Wrong Answer
25
8,924
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)
s476217151
Accepted
26
9,084
72
n=int(input()) if n%1000 ==0: print(n%1000) else: print(1000-n%1000)
s137406738
p03845
u325206354
2,000
262,144
Wrong Answer
18
3,064
220
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds. It does not affect the time to solve the other problems. A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.
x=int(input()) a=list(map(int,input().split())) d=int(input()) n=0 A=a j=[list(map(int,input().split())) for i in range(d)] for T in range(d): s=j[n][0] A[s-1]=j[n][1] print(sum(A)) n+=1 A[s-1]=a[s-1]
s348028837
Accepted
18
3,064
315
x=int(input()) first=list(map(int,input().split())) drink_count=int(input()) count=0 Total=sum(first) drink=[list(map(int,input().split())) for i in range(drink_count)] for T in range(drink_count): change_num = drink[count][0] score = first[change_num-1]-drink[count][1] print(Total-score) count+=1
s124398564
p04043
u645127738
2,000
262,144
Wrong Answer
23
8,952
34
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=input().split() print(a,b,c)
s222205043
Accepted
24
9,028
186
a,b,c=input().split() if a=="5" and b=="5" and c=="7": print("YES") elif a=="5" and b=="7" and c=="5": print("YES") elif a=="7" and b=="5" and c=="5": print("YES") else: print("NO")
s432033443
p03636
u690037900
2,000
262,144
Wrong Answer
17
2,940
58
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
a = list(input()) num = len(a) print(a[0]+str(num)+a[-1])
s359295347
Accepted
17
2,940
49
a = list(input()) print(a[0]+str(len(a)-2)+a[-1])
s164495797
p02742
u487767879
2,000
1,048,576
Wrong Answer
17
2,940
103
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 = list(map(int, input().split())) res = int((H+1)/2) * W if W%2==1: res -= int(W/2) print(res)
s929512122
Accepted
17
3,064
144
H, W = list(map(int, input().split())) if H==1 or W==1: print(1) exit() res = int((H+1)/2) * W if H%2==1: res -= int(W/2) print(res)
s658069974
p03795
u901598613
2,000
262,144
Wrong Answer
17
2,940
45
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()) x=500*n y=n//15*200 print(x-y)
s289064772
Accepted
17
2,940
45
n=int(input()) x=800*n y=n//15*200 print(x-y)
s600245217
p03860
u302292660
2,000
262,144
Wrong Answer
17
2,940
72
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.
con = input().split() cap = con[2][0] name = "A" + cap + "C" print(name)
s642963723
Accepted
19
3,060
72
con = input().split() cap = con[1][0] name = "A" + cap + "C" print(name)
s869260217
p03485
u629276590
2,000
262,144
Wrong Answer
17
2,940
100
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()) x=(a+b)/2 if x*10%10==5: print(x*10//10+1) else: print(x)
s956269430
Accepted
17
2,940
109
a,b=map(int,input().split()) x=(a+b)/2 if x*10%10==5: print(int(x*10//10+1)) else: print(int(x))
s209397682
p03610
u934052933
2,000
262,144
Wrong Answer
40
3,700
128
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input() counter = 0 res = [] for i in s: counter += 1 if counter % 2 != 0: res.append(i) print("res:","".join(res))
s160233783
Accepted
39
3,572
121
s = input() counter = 0 res = [] for i in s: counter += 1 if counter % 2 != 0: res.append(i) print("".join(res))
s658881056
p01101
u398978447
8,000
262,144
Wrong Answer
40
5,648
389
Mammy decided to give Taro his first shopping experience. Mammy tells him to choose any two items he wants from those listed in the shopping catalogue, but Taro cannot decide which two, as all the items look attractive. Thus he plans to buy the pair of two items with the highest price sum, not exceeding the amount Mammy allows. As getting two of the same item is boring, he wants two different items. You are asked to help Taro select the two items. The price list for all of the items is given. Among pairs of two items in the list, find the pair with the highest price sum not exceeding the allowed amount, and report the sum. Taro is buying two items, not one, nor three, nor more. Note that, two or more items in the list may be priced equally.
n=5 m=5 sum=0 A=[] while n!=0: n,m=[int(i) for i in input().split()] if n==0 and m==0: break val=[int(i) for i in input().split()] m1=m2=val[0] for i in range(1,n): if val[i]>=m1: m1=val[i] elif val[i]>m2: m2=val[i]; sum=m1+m2 if sum>m: sum=0 A.append(sum) for i in range(len(A)): print(A[i])
s113845160
Accepted
1,990
5,716
481
n=5 m=5 z=0 sum=0 A=[] while n!=0: n,m=[int(i) for i in input().split()] if n==0 and m==0: break val=[int(i) for i in input().split()] ans1=0 mm=0 for i in range(0,n): for j in range(i+1,n): if i==j: break ans1=val[i]+val[j] if ans1>mm and ans1<=m: mm=ans1 ans1=0 A.append(mm) z=z+1 for i in range(z): if A[i]==0: A[i]="NONE" print(A[i])
s337911984
p03438
u214617707
2,000
262,144
Wrong Answer
24
4,600
238
You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) k = 0 for i in a: if i % 2 == 0: k += 1 for j in b: if j % 2 == 1: k -= 1 if k == 0: print("YES") else: print("NO")
s603291144
Accepted
27
4,596
271
N = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) p, q = 0, 0 for i in range(N): if a[i] > b[i]: p += a[i] - b[i] elif a[i] < b[i]: q += (b[i] - a[i]) // 2 if p <= q: print('Yes') else: print('No')
s905779868
p02394
u303842929
1,000
131,072
Wrong Answer
20
5,604
349
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.
value = input().split() W = int(value[0]) H = int(value[1]) coordinate = [[0 for _ in range(W)] for _ in range(H)] x = int(value[2]) y = int(value[3]) r =int(value[4]) try: tmp = coordinate[y][x + r] tmp = coordinate[y][x - r] tmp = coordinate[y + r][x] tmp = coordinate[y - r][x] print("YES") except Exception: print("NO")
s213636211
Accepted
20
5,644
455
value = input().split() W = int(value[0]) H = int(value[1]) coordinate = [[0 for _ in range(W + 1)] for _ in range(H + 1)] x = int(value[2]) y = int(value[3]) r =int(value[4]) try: if x < 0 or y < 0: print("No") else: tmp = coordinate[y][x + r] tmp = coordinate[y][x - r] tmp = coordinate[y + r][x] tmp = coordinate[y - r][x] print("Yes") except Exception: print("No")
s625713369
p02272
u003309334
1,000
131,072
Wrong Answer
20
7,768
783
Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right)
def merge(A, left, mid, right): cnt = 0 n1 = mid - left n2 = right - mid L, R = [0]*(n1+1), [0]*(n2+1) for i in range(n1): L[i] = A[left + i] for i in range(n2): R[i] = A[mid + i] L[n1] = float("inf") R[n2] = float("inf") i = 0 j = 0 for k in range(left, right): cnt = cnt + 1 if L[i] <= R[j]: A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 return cnt def mergeSort(A, left, right, cnt): if left+1 < right: mid = int((left + right)/2) mergeSort(A, left, mid, cnt) mergeSort(A, mid, right, cnt) cnt[0] = cnt[0] + merge(A, left, mid, right) if __name__ == "__main__": n = int(input()) S = list(map(int, input().split())) cnt = [0] mergeSort(S, 0, len(S), cnt) print(S) print(cnt[0])
s963555256
Accepted
4,750
68,732
673
count = 0 def merge(A, left, mid, right): global count n1 = mid - left n2 = right - mid L = A[left:left+n1] R = A[mid:mid+n2] L.append(float("inf")) R.append(float("inf")) i = 0 j = 0 for k in range(left, right): count += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if left + 1 < right: mid = int((left + right)/2) mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) if __name__ == "__main__": n = int(input()) S = list(map(int, input().split())) mergeSort(S, 0, len(S)) print(" ".join(map(str, S))) print(count)
s055126744
p02388
u176580590
1,000
131,072
Wrong Answer
20
5,508
59
Write a program which calculates the cube of a given integer x.
def f(x): if 1 <= x <= 100: print("error") return x**3
s977677854
Accepted
20
5,576
29
x = int(input()) print(x**3)
s922887280
p00002
u553148578
1,000
131,072
Wrong Answer
20
5,652
89
Write a program which computes the digit number of sum of two integers a and b.
import math a, b = map(int, input().split()) ans = a + b print(int(math.log10(ans)) + 1)
s271268975
Accepted
20
5,584
93
while True: try: a, b = map(int, input().split()) print(len(str(a+b))) except: break
s323460057
p03455
u840497549
2,000
262,144
Wrong Answer
17
2,940
114
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = input().split(" ") a= int(a) b= int(b) c = a*b if c%2 ==0: print("even") else: print("odd")
s572794260
Accepted
17
2,940
110
a, b= input().split() a = int(a) b = int(b) if a*b % 2 == 0: print("Even") else: print("Odd")
s805571858
p03759
u846218099
2,000
262,144
Wrong Answer
17
2,940
64
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()) print("YES" if a==b==c else "NO")
s005080198
Accepted
17
2,940
65
a,b,c=map(int,input().split()) print("YES" if b-a==c-b else "NO")
s403126582
p02409
u923668099
1,000
131,072
Wrong Answer
30
7,668
353
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.
# coding: utf-8 # Here your code ! num_j = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)] n = int(input()) for _ in range(n): b,r,f,v = map(int,input().split()) num_j[b-1][r-1][f-1] += v for i in range(4): for j in range(3): print(" ",end="") print(" ".join(map(str,num_j[i][j]))) print("#"*20)
s898076251
Accepted
30
7,712
355
# coding: utf-8 # Here your code ! num_j = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)] n = int(input()) for _ in range(n): b,r,f,v = [int(x) for x in input().split()] num_j[b-1][r-1][f-1] += v for i in range(4): for f in num_j[i]: print(""," ".join([str(x) for x in f])) if i != 3: print("#"*20)
s095193276
p04043
u539675863
2,000
262,144
Wrong Answer
17
2,940
112
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 = sorted(map(int,input().split())) if a == 5 and b == 7 and c == 5: print("YES") else: print("NO")
s180536902
Accepted
17
2,940
116
go = list(map(int,input().split())) if go.count(5) == 2 and go.count(7) == 1: print("YES") else: print("NO")
s376567918
p03044
u950708010
2,000
1,048,576
Wrong Answer
1,782
25,028
1,013
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x def is_same(self, x, y): return self.find(x) == self.find(y) def solve(): n = int(input()) uf = UnionFind(n) ans = [0]*n tmp = [] for i in range(n-1): x,y,z = (int(i) for i in input().split()) if z%2 == 1: tmp.append((x,y,z)) else: uf.union(x-1,y-1) ans[x-1] = 1 ans[y-1] = 1 while tmp: x,y,z = tmp.pop(0) for i in ans: print(i) solve()
s944346894
Accepted
485
36,016
719
import sys input = sys.stdin.readline from collections import deque def solve(): n = int(input()) treenode = [[] for _ in range(n)] treecolor = [-2]*n for i in range(n-1): u,v,w = (int(i) for i in input().split()) u -= 1 v -= 1 treenode[u].append((v,w%2)) treenode[v].append((u,w%2)) query = deque([(0,0,0)]) while query: a,b,c = query.popleft() if b%2 == 0: treecolor[a] = c nextc = c else: treecolor[a] = 1^c nextc = 1^c for nextnode,weight in treenode[a]: if treecolor[nextnode] != -2: continue else: query.append((nextnode,weight,nextc)) treecolor[nextnode] = -1 for i in treecolor: print(i) solve()
s682349106
p02841
u370721525
2,000
1,048,576
Wrong Answer
18
2,940
124
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
M_1, D_1 = map(int, input().split()) M_2, D_2 = map(int, input().split()) if M_1 != M_2: print('No') else: print('Yes')
s678272766
Accepted
17
2,940
118
M_1, D_1 = map(int, input().split()) M_2, D_2 = map(int, input().split()) if M_1 != M_2: print(1) else: print(0)
s118557197
p02972
u151785909
2,000
1,048,576
Wrong Answer
280
22,452
284
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
n = int(input()) a = list(map(int,input().split())) b = [0]*n for i in range(n): b1=b[n-1-i::n-1-i+1] if a[n-1-i]==0 and sum(b1)%2==0: b[n-1-i]=0 else: b[n-1-i]=1 ans =[] for i in range(n): if b[i]==1: ans.append(str(i+1)) print(' '.join(ans))
s716800943
Accepted
313
19,508
339
n = int(input()) a = list(map(int,input().split())) b = [0]*n for i in range(n): b1=b[n-1-i::n-1-i+1] su=sum(b1) if (a[n-1-i]==0 and su%2==0) or (a[n-1-i]==1 and su%2==1): b[n-1-i]=0 else: b[n-1-i]=1 ans =[] print(sum(b)) for i in range(n): if b[i]==1: ans.append(str(i+1)) print(' '.join(ans))
s807375963
p03543
u496821919
2,000
262,144
Wrong Answer
18
3,060
267
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**?
X = list(input()) for i in range(2**3): W = ["+"]*3 for j in range(3): if (i >> j) & 1: W[j] = "-" formula = "" for k,l in zip(X,W+[""]): formula += k+l if eval(formula) == 7: print(formula+"=7") break
s559470700
Accepted
17
2,940
214
# -*- coding: utf-8 -*- """ Created on Wed May 13 11:36:51 2020 @author: shinba """ n = list(input()) if (n[0] == n[1] and n[1] == n[2]) or (n[1] == n[2] and n[2] == n[3]): print("Yes") else: print("No")
s632455040
p03549
u331128419
2,000
262,144
Wrong Answer
19
2,940
90
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
N, M = map(int, input().split()) time = (M * 1900 + (N-M) * 100) / (0.5 ** M) print(time)
s388875486
Accepted
17
2,940
95
N, M = map(int, input().split()) time = (M * 1900 + (N-M) * 100) / (0.5 ** M) print(int(time))
s109882458
p03162
u212786022
2,000
1,048,576
Wrong Answer
2,106
93,140
405
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
N = int(input()) T = [list(map(int, input().split())) for i in range(N)] print(T) dp = [[0 for i in range(3)] for j in range(N+1)] print(dp) dp[1] = T[0] print(dp) for i in range(2,N+1): dp[i][0] = max(dp[i-1][1]+T[i-1][0],dp[i-1][2]+T[i-1][0]) dp[i][1] = max(dp[i-1][0]+T[i-1][1],dp[i-1][2]+T[i-1][1]) dp[i][2] = max(dp[i-1][0]+T[i-1][2],dp[i-1][1]+T[i-1][2]) print(dp) print(max(dp[-1]))
s056289217
Accepted
633
47,348
362
N = int(input()) T = [list(map(int, input().split())) for i in range(N)] dp = [[0 for i in range(3)] for j in range(N+1)] dp[1] = T[0] for i in range(2,N+1): dp[i][0] = max(dp[i-1][1]+T[i-1][0],dp[i-1][2]+T[i-1][0]) dp[i][1] = max(dp[i-1][0]+T[i-1][1],dp[i-1][2]+T[i-1][1]) dp[i][2] = max(dp[i-1][0]+T[i-1][2],dp[i-1][1]+T[i-1][2]) print(max(dp[-1]))
s212929694
p03679
u600402037
2,000
262,144
Wrong Answer
17
3,060
260
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.
import sys stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces X, A, B = rl() print('delicious' if A >= B else 'safe' if X >= A + B else 'dangerous')
s742560618
Accepted
17
3,060
260
import sys stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces X, A, B = rl() print('delicious' if A >= B else 'safe' if X >= B - A else 'dangerous')
s757210784
p03151
u871841829
2,000
1,048,576
Wrong Answer
40
11,192
193
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()) A = map(int, input().split()) ans = 1 import sys if 0 in A: print(0) sys.exit() for a in A: ans *= a if ans > pow(10, 18): print(-1) sys.exit() print(ans)
s425619458
Accepted
109
24,212
471
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) diff = [0] * N neg = [] pos = [] for i in range(N): diff[i] = A[i] - B[i] if diff[i] < 0: neg.append(diff[i]) else: pos.append(diff[i]) if sum(diff) < 0: print(-1) exit(0) tobe_supplied = sum(neg) pos.sort(reverse=True) cnt = len(neg) for p in pos: if tobe_supplied >= 0: break cnt += 1 tobe_supplied += p print(cnt)
s627076093
p03658
u241159583
2,000
262,144
Wrong Answer
17
3,064
117
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
N, K = map(int, input().split()) l = list(map(int, input().split())) l.sort(reverse=True) print(l) print(sum(l[:K]))
s978412604
Accepted
17
2,940
96
N, K = map(int, input().split()) l = list(map(int, input().split())) l.sort() print(sum(l[-K:]))
s336281308
p03417
u130900604
2,000
262,144
Wrong Answer
17
2,940
123
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
n,m=map(int,input().split()) if (n,m)==(1,1): print(1) elif min(n,m)==1: print(max(n,m)-2) else: print((n-2)*(m-2)+4)
s039386992
Accepted
17
2,940
122
n,m=map(int,input().split()) if (n,m)==(1,1): print(1) elif min(n,m)==1: print(max(n,m)-2) else: print((n-2)*(m-2))
s171021576
p02927
u375616706
2,000
1,048,576
Wrong Answer
17
3,064
631
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?
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline M, D = map(int, input().split()) cand = set() for m in range(1, M+1): i = 2 while i*i <= D: if m % i == 0: ma = m//i mi = i if mi <= 1 or ma <= 1: pass elif int(str(mi)+str(ma)) <= D: cand.add(int(str(m)+str(mi)+str(ma))) print("mi,ma->", mi, ma) elif int(str(ma)+str(mi)) <= D: cand.add(int(str(m)+str(ma)+str(mi))) print("ma,mi->", ma, mi) i += 1 print(len(cand))
s830721938
Accepted
18
3,064
549
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline M, D = map(int, input().split()) cand = set() for m in range(1, M+1): i = 2 while i*i <= D: if m % i == 0: ma = m//i mi = i if mi <= 1 or ma <= 1: pass elif int(str(mi)+str(ma)) <= D: cand.add(int(str(m)+str(mi)+str(ma))) elif int(str(ma)+str(mi)) <= D: cand.add(int(str(m)+str(ma)+str(mi))) i += 1 print(len(cand))
s620046091
p03068
u297756089
2,000
1,048,576
Wrong Answer
18
3,316
142
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=list(input()) k=int(input()) num=s[k-1] num=str(num) for i in range (0,n): if s[i]==num: s[i]="*" s=''.join(s) print(s)
s074686960
Accepted
17
3,060
142
n=int(input()) s=list(input()) k=int(input()) num=s[k-1] num=str(num) for i in range (0,n): if s[i]!=num: s[i]="*" s=''.join(s) print(s)
s287026531
p03644
u017271745
2,000
262,144
Wrong Answer
17
3,060
191
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()) check = 0 ans = 1 for i in range(1, N+1): cnt = 0 while i%2 == 0: cnt += 1 i //= 2 if cnt > check: ans = i check = cnt print(ans)
s702343433
Accepted
17
3,060
201
N = int(input()) check = 0 ans = 1 for i in range(1, N+1): cnt = 0 j = i while j%2 == 0: cnt += 1 j //= 2 if cnt > check: ans = i check = cnt print(ans)
s864186040
p04029
u739959951
2,000
262,144
Wrong Answer
18
2,940
41
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()) ans=n*(n+1)/2 print(ans)
s964018924
Accepted
17
2,940
42
n=int(input()) ans=n*(n+1)//2 print(ans)
s351915971
p02238
u855199458
1,000
131,072
Wrong Answer
20
7,752
1,284
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving the vertex from which $v$ was discovered. This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source. DFS timestamps each vertex as follows: * $d[v]$ records when $v$ is first discovered. * $f[v]$ records when the search finishes examining $v$’s adjacency list. Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules: * $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively. * IDs in the adjacency list are arranged in ascending order. * The program should report the discover time and the finish time for each vertex. * When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID. * The timestamp starts with 1.
# -*- coding: utf-8 -*- N = int(input()) adj = [[0]*N for _ in range(N)] searched = {n: 0 for n in range(N)} edge = {} def find_all(list_, x, j=-1): return [i for i, n in enumerate(list_) if n==1 and n != j] for n in range(N): inp = list(map(int, input().split())) edge[n] = inp[1] for i in inp[2:]: adj[inp[0]-1][i-1] = 1 time = 1 stack = [] unsearch = set(range(N)) uncomplete = set(range(N)) result = {n:{"found": 0, "finish": 0} for n in range(N)} while len(unsearch) > 0 or len(stack) > 0: if len(stack) == 0: i = min(unsearch) result[i]["found"] = time unsearch.remove(i) time += 1 while True: j = i for n in sorted(unsearch): if adj[i][n] == 1: j = n result[n]["found"] = time unsearch.remove(n) stack.append(i) time += 1 break if i == j: result[i]["finish"] = time if len(stack) != 0: i = stack.pop() time += 1 else: break else: i = j for n in range(N): print("{} {} {}".format(n, result[n]["found"], result[n]["finish"]))
s581546860
Accepted
20
7,832
951
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(100000) N = int(input()) adj = [[0]*N for _ in range(N)] searched = {n: 0 for n in range(N)} edge = {} for n in range(N): inp = list(map(int, input().split())) edge[n] = inp[1] for i in inp[2:]: adj[inp[0]-1][i-1] = 1 time = 1 stack = [] unsearch = set(range(N)) uncomplete = set(range(N)) result = {n:{"found": 0, "finish": 0} for n in range(N)} def DFS(i): global time global unsearch itr = sorted(unsearch) for j in itr: if adj[i][j] == 1 and j in unsearch: result[j]["found"] = time time += 1 unsearch.remove(j) DFS(j) result[i]["finish"] = time time += 1 while len(unsearch): i = min(unsearch) unsearch.remove(i) result[i]["found"] = time time += 1 DFS(i) for n in range(N): print("{} {} {}".format(n+1, result[n]["found"], result[n]["finish"]))
s257070697
p03605
u227085629
2,000
262,144
Wrong Answer
17
2,940
71
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?
a=input() if a[0] == 9 or a[1] == 9: print('Yes') else: print('No')
s769215574
Accepted
17
2,940
78
a=int(input()) if a//10 == 9 or a%10 == 9: print('Yes') else: print('No')
s778618072
p02271
u125481461
5,000
131,072
Wrong Answer
20
5,596
632
Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
def can_construct_q(q, array, i, sum_sofar): if sum_sofar == q or sum_sofar + array[i] == q: return True elif sum_sofar > q or i >= len(array) - 1: return False if can_construct_q(q, array, i + 1, sum_sofar + array[i]): return True if can_construct_q(q, array, i + 1, sum_sofar): return True def main(): input() array_a = list(map(int, input().split())) input() array_q = map(int, input().split()) for q in array_q: print(q) if can_construct_q(q, array_a, 0, 0): print('yes') else: print('no') return main()
s302068738
Accepted
360
5,624
731
def main(): input() array_a = list(map(int, input().split())) input() array_q = map(int, input().split()) def can_construct_q (q, i, sum_sofar): if sum_sofar == q or sum_sofar + array_a[i] == q: return True elif sum_sofar > q or i >= len (array_a) - 1: return False if can_construct_q(q, i + 1, sum_sofar + array_a[i]): return True if can_construct_q(q, i + 1, sum_sofar): return True sum_array_a = sum(array_a) for q in array_q: #print(q) if sum_array_a < q: print('no') elif can_construct_q(q, 0, 0): print('yes') else: print('no') return main()
s744106404
p03544
u011062360
2,000
262,144
Wrong Answer
17
2,940
99
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 = [2, 1] for _ in range(n): k = l[-1] + l[-2] l.append(k) print(l[n-1])
s212252926
Accepted
17
2,940
98
n = int(input()) l = [2, 1] for _ in range(n): k = l[-1] + l[-2] l.append(k) print(l[-2])
s610403565
p03095
u905582793
2,000
1,048,576
Wrong Answer
28
4,340
134
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order.
from collections import Counter n = int(input()) s = list(input()) c = Counter(s) ans = 1 for x in c.values(): ans *= x print(ans-1)
s550374413
Accepted
26
4,260
151
from collections import Counter n = int(input()) s = list(input()) c = Counter(s) ans = 1 for x in c.values(): ans = ans*(x+1)%(10**9+7) print(ans-1)
s465284411
p02972
u864213970
2,000
1,048,576
Wrong Answer
714
38,316
703
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
n = int(input()) arr = [int(x) for x in input().split()] balls = {} result = [] reslen = 0 for i in range(n, n // 2, -1): if arr[i - 1] == 1: balls[i - 1] = 1 result.append(str(i)) reslen += 1 else: balls[i - 1] = 0 for i in range(n // 2, 0, -1): s = sum([balls[i * m - 1] for m in range(2, n // i + 1)]) if arr[i - 1] == 1: if (s % 2) == 1: balls[i - 1] = 0 else: balls[i - 1] = 1 result.append(str(i)) reslen += 1 if arr[i - 1] == 0: if (s % 2) == 0: balls[i - 1] = 0 else: balls[i - 1] = 1 result.append(str(i)) reslen += 1 print(balls) print('---') print(reslen) if reslen != 0: print(' '.join(result))
s090300482
Accepted
672
38,440
677
n = int(input()) arr = [int(x) for x in input().split()] balls = {} result = [] reslen = 0 for i in range(n, n // 2, -1): if arr[i - 1] == 1: balls[i - 1] = 1 result.append(str(i)) reslen += 1 else: balls[i - 1] = 0 for i in range(n // 2, 0, -1): s = sum([balls[i * m - 1] for m in range(2, n // i + 1)]) if arr[i - 1] == 1: if (s % 2) == 1: balls[i - 1] = 0 else: balls[i - 1] = 1 result.append(str(i)) reslen += 1 if arr[i - 1] == 0: if (s % 2) == 0: balls[i - 1] = 0 else: balls[i - 1] = 1 result.append(str(i)) reslen += 1 print(reslen) if reslen != 0: print(' '.join(result))
s980547050
p03494
u867132034
2,000
262,144
Wrong Answer
18
3,060
125
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())) A count=0 while all([a%2==0 for a in A]): A = [a/2 for a in A] count+=1 print(count)
s489635690
Accepted
18
3,060
133
N=input() A=list(map(int,input().split())) count=0 while all([a%2==0 for a in A]): A = [a/2 for a in A] count+=1 print(count)