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
s967806993
p03457
u962819039
2,000
262,144
Wrong Answer
1,014
4,340
329
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()) x = 0 y = 0 t = 0 for i in range(n): t_new, x_new, y_new = map(int, input().split()) print(t_new, x_new, y_new) if ((abs(x_new - x) + abs(y_new - y)) <= (t_new - t)) and ((abs(x_new - x) + abs(y_new - y) - (t_new - t)) % 2 == 0): x = x_new y = y_new t = t_new else: print('No') exit() print('YES')
s242614677
Accepted
376
3,060
292
n = int(input()) x = 0 y = 0 t = 0 for i in range(n): t_new, x_new, y_new = map(int, input().split()) l = abs(x_new - x) + abs(y_new - y) dt = t_new - t if (l <= dt) and (l % 2 == dt % 2 ): x = x_new y = y_new t = t_new else: #print(t, x, y) print('No') exit() print('Yes')
s260364581
p03575
u817328209
2,000
262,144
Wrong Answer
17
3,064
853
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
n, m = map(int, input().split()) gragh = [[] for _ in range(n)] used_v = [False]*n used_e = [[False]*n for _ in range(n)] Ord = [0]*n lowlink = [0]*n k = 0 for i in range(m) : a, b = map(int, input().split()) gragh[a-1].append(b-1) gragh[b-1].append(a-1) def dfs(v) : global k used_v[v] = True Ord[v] = lowlink[v] = k k += 1 for node in gragh[v] : if not used_v[node] : used_e[v][node] = True dfs(node) lowlink[v] = min(lowlink[v], lowlink[node]) elif not used_e[node][v] : lowlink[v] = min(lowlink[v], Ord[node]) dfs(0) ans = 0 used_e = [[False]*n for _ in range(n)] for i in range(n) : for j in gragh[i] : if not used_e[i][j] and Ord[i] < lowlink[j] : ans += 1 used_e[i][j] = True used_e[j][i] = True print(ans)
s418201589
Accepted
22
3,316
610
from collections import defaultdict def dfs(i, used, g, ng): for n in g[i]: if n not in used and (i, n) != ng and (n, i) != ng: used.add(n) dfs(n, used, g, ng) def main(): N, M = map(int, input().split()) g = defaultdict(list) k = [] for _ in range(M): a, b = map(int, input().split()) g[a].append(b) g[b].append(a) k.append((a, b)) ans = 0 for a, b in k: used = set() dfs(1, used, g, (a, b)) if len(used) != N: ans += 1 print(ans) if __name__ == '__main__': main()
s779912813
p03993
u193264896
2,000
262,144
Wrong Answer
68
12,392
417
There are N rabbits, numbered 1 through N. The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i. For a pair of rabbits i and j (i<j), we call the pair (i,j) a _friendly pair_ if the following condition is met. * Rabbit i likes rabbit j and rabbit j likes rabbit i. Calculate the number of the friendly pairs.
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(readline()) A = list(map(int, readline().split())) ans = 0 print(A) for i in range(N): if i==A[A[i]-1]-1: ans += 1 print(ans//2) if __name__ == '__main__': main()
s544369223
Accepted
58
12,392
405
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(readline()) A = list(map(int, readline().split())) ans = 0 for i in range(N): if i==A[A[i]-1]-1: ans += 1 print(ans//2) if __name__ == '__main__': main()
s622709753
p03456
u301624971
2,000
262,144
Wrong Answer
17
3,060
305
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.
def myAnswer(a:int,b:int) -> str: ab=int(str(a)+str(b)) number = 2 while number**2 < ab: if(number**2 ==ab): return "Yes" number += 1 return "No" def modelAnswer(): tmp=1 def main(): a,b=map(int,input().split()) print(myAnswer(a,b)) if __name__ == '__main__': main()
s744837555
Accepted
19
3,060
335
def myAnswer(a:int,b:int) -> str: ab=int(str(a)+str(b)) number = 2 while True: if(number**2 == ab): return "Yes" if(number**2 > ab): break number += 1 return "No" def modelAnswer(): tmp=1 def main(): a,b=map(int,input().split()) print(myAnswer(a,b)) if __name__ == '__main__': main()
s101053389
p03407
u019578976
2,000
262,144
Wrong Answer
17
2,940
57
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
a,b,c=map(int,input().split()) print(["No","Yes"][a+b<c])
s504812327
Accepted
19
2,940
57
a,b,c=map(int,input().split()) print(["Yes","No"][a+b<c])
s886562819
p02690
u539692012
2,000
1,048,576
Wrong Answer
44
10,704
81
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
x=int(input()) r=range(200) [i**5-x-j**5or exit(print(i,j))for i in r for j in r]
s258269677
Accepted
40
9,088
67
i=j=x=int(input()) while i**5-j**5-x:i=-~i%127;j=j%257-i print(i,j)
s050534647
p03150
u388497015
2,000
1,048,576
Wrong Answer
29
9,116
254
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 sys s = input() target = "keyence" for i in range(len(target)): sbst1 = target[0:i] sbst2 = target[i:] ind = s.find(sbst1) indx = s.find(sbst2) if ind != -1 and ind < indx: print("Yes") sys.exit() print("No")
s286414625
Accepted
30
9,072
258
import sys s = input() target = "keyence" if s == target: print("YES") sys.exit() for i in range(len(s)): for j in range(i, len(s)): st = s[:i] + s[j:] if st == target: print("YES") sys.exit() print("NO")
s424771810
p02612
u031679985
2,000
1,048,576
Wrong Answer
29
9,088
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)
s374046422
Accepted
27
9,160
65
n=int(input()) a=n%1000 if a==0: print(0) else: print(1000-a)
s392986630
p02390
u455935767
1,000
131,072
Wrong Answer
20
5,596
104
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
Sec = input() S = int(Sec) h = S/60 m = S%60/60 s = S%60%60 st=(str(h)+':'+str(m)+':'+str(s)) print(st)
s027390583
Accepted
30
5,600
175
Sec = input() S = int(Sec) h = int(S/3600) m = int(S%3600/60) s = S%3600%60 st=(str(h)+':'+str(m)+':'+str(s)) print(st) #1h=3600s #1m=60s #1s=1s ''' 8000s h=2 8000%60=20 '''
s139692793
p03457
u126823513
2,000
262,144
Wrong Answer
476
32,800
523
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.
int_n = int(input()) result = False plan_array = [[0, 0, 0]] for n in range(int_n): plan_array.append(list(map(int, input().split()))) print(plan_array) for n in range(int_n): dt = plan_array[n+1][0] - plan_array[n][0] dist = plan_array[n+1][1] - plan_array[n][1] + \ plan_array[n+1][2] - plan_array[n][2] if dist > dt: result = False break if dt & 1 and dist & 1: result = True else: result = False if result: print('YES') else: print('No')
s348971750
Accepted
274
27,124
652
n = int(input()) st_t = 0 st_x = 0 st_y = 0 li_in = list() for i in range(n): li_in.append(list(map(int, input().split()))) for t, x, y in li_in: time = t - st_t diff_x = abs(x - st_x) diff_y = abs(y - st_y) if diff_x + diff_y > time: print('No') exit(0) elif diff_x + diff_y == time: st_t = t st_x = x st_y = y continue else: if (time - (diff_x + diff_y)) % 2 == 0: st_t = t st_x = x st_y = y continue else: print('No') exit(0) else: print('Yes')
s064205744
p03719
u912862653
2,000
262,144
Wrong Answer
17
2,940
93
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a, b, c = list(map(int, input().split())) if a<=c and c<=b: print('YES') else: print('NO')
s388621885
Accepted
18
2,940
93
a, b, c = list(map(int, input().split())) if c>=a and c<=b: print('Yes') else: print('No')
s913296572
p03478
u092278825
2,000
262,144
Wrong Answer
37
2,940
185
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 = (int(i) for i in input().split()) s = 0 for i in range(1, N+1): list_1 = [int(x) for x in list(str(i))] k = sum(list_1) if k >= A and k <= B: s += 1 print(s)
s886673576
Accepted
36
2,940
177
N,A,B = map(int, input().split()) s = 0 for i in range(1, N+1): list_1 = [int(x) for x in list(str(i))] k = sum(list_1) if k >= A and k <= B: s += i print(s)
s863239657
p03150
u374103100
2,000
1,048,576
Wrong Answer
19
3,188
450
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 S = input() if "keyence" in S: print("YES") else: patterns = ["k*eyence", "ke*yence", "key*ence", "keye*nce", "keyen*ce", "keyenc*e"] matched = False for pattern in patterns: matchOB = re.search(pattern, S) if matchOB: matched = True break if matched: print("YES") else: print("NO")
s502215140
Accepted
19
3,188
499
import re S = input() if "keyence" == S: print("YES") else: patterns = ["^keyence(.*)", "^k(.*)eyence$", "^ke(.*)yence$", "^key(.*)ence$", "^keye(.*)nce$", "^keyen(.*)ce$", "^keyenc(.*)e$", "keyence$"] matched = False for pattern in patterns: matchOB = re.search(pattern, S) if matchOB: matched = True break if matched: print("YES") else: print("NO")
s764232230
p03693
u332906195
2,000
262,144
Wrong Answer
17
2,940
94
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) print("Yes" if (r * 100 + g * 10 + b) % 4 == 0 else "No")
s463088789
Accepted
17
2,940
76
r, g, b = input().split() print("YES" if int(r + g + b) % 4 == 0 else "NO")
s422815951
p03409
u918009437
2,000
262,144
Wrong Answer
19
3,064
623
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
if __name__ == '__main__': N = int(input()) ab_list = [list(map(int, input().split())) for i in range(N)] cd_list = [list(map(int, input().split())) for i in range(N)] ab_list = sorted(ab_list, key=lambda x : x[1], reverse=True) cd_list = sorted(cd_list, key=lambda x : x[0]) print(ab_list) print(cd_list) answer = 0 for b in cd_list: for r in ab_list: if b[0]>r[0] and b[1]>r[1]: answer += 1 ab_list.remove(r) print(b) print(r) print("------") break print(answer)
s861734117
Accepted
19
3,064
502
if __name__ == '__main__': N = int(input()) ab_list = [list(map(int, input().split())) for i in range(N)] cd_list = [list(map(int, input().split())) for i in range(N)] ab_list = sorted(ab_list, key=lambda x : x[1], reverse=True) cd_list = sorted(cd_list, key=lambda x : x[0]) answer = 0 for b in cd_list: for r in ab_list: if b[0]>r[0] and b[1]>r[1]: answer += 1 ab_list.remove(r) break print(answer)
s388356803
p03574
u854144714
2,000
262,144
Wrong Answer
36
3,444
587
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
H,W=[int(i) for i in input().split()] A=[] for i in range(H): s=input() S=list(s) A.append(S) for i in range(H): for j in range(W): if A[i][j]=="#": break else: s=0 for k in range(-1,2): for l in range(-1,2): if i+k>=0 and i+k<=H-1 and j+l>=0 and j+l<=W-1: if A[i+k][j+l]=="#": s+=1 A[i][j]=s for i in range(H): for j in range(W): print(A[i][j],end=" ") print()
s339404537
Accepted
35
3,572
625
H,W=[int(i) for i in input().split()] A=[] for i in range(H): s=input() S=list(s) A.append(S) for i in range(H): for j in range(W): if A[i][j]!="#": s=0 for k in range(-1,2): for l in range(-1,2): if k==0 and l==0: continue if i+k>=0 and i+k<=H-1 and j+l>=0 and j+l<=W-1: if A[i+k][j+l]=="#": s+=1 A[i][j]=str(s) for i in range(H): for j in range(W): print(A[i][j],end="") print()
s435894323
p03944
u539969758
2,000
262,144
Wrong Answer
17
3,064
429
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
w, h, n = map(int,input().split()) x_l = 0 x_r = w y_l = 0 y_h = h for i in range(n): x, y, a = map(int,input().split()) if a == 1: if x > x_l: x_l = x elif a == 2: if x < x_r: x_r == x elif a == 3: if y > y_l: y_l = y else: if y < y_h: y_h = y menseki = 0 if x_r <= x_l and y_l <= y_h: menseki = (y_h - y_l)*(x_l - x_r) print(menseki)
s712305796
Accepted
17
3,064
429
w, h, n = map(int,input().split()) x_l = 0 x_r = w y_l = 0 y_h = h for i in range(n): x, y, a = map(int,input().split()) if a == 1: if x > x_l: x_l = x elif a == 2: if x < x_r: x_r = x elif a == 3: if y > y_l: y_l = y else: if y < y_h: y_h = y menseki = 0 if x_l <= x_r and y_l <= y_h: menseki = (y_h - y_l)*(x_r - x_l) print(menseki)
s460945112
p03681
u859897687
2,000
262,144
Wrong Answer
2,104
3,468
151
Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys. How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
a,b=map(int,input().split()) ans=1 if abs(a-b)>1: print(0) elif abs(a-b)==1: ans=2 while a>1: ans*=a a-=1 while b>1: ans*=b b-=1 print(ans)
s341308914
Accepted
77
3,060
214
a,b=map(int,input().split()) mod=1000000007 ans=1 if abs(a-b)>1: print(0) else: if abs(a-b)==0: ans=2 while a>1: ans*=a ans%=mod a-=1 while b>1: ans*=b ans%=mod b-=1 print(ans)
s512112970
p03637
u581187895
2,000
262,144
Wrong Answer
66
14,224
319
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
N = int(input()) A = list(map(int, input().split())) k0 = 0 k2 = 0 k4 = 0 for a in A: if a%4==0: k4 += 1 elif a%2==0: k2 += 1 else: k0 += 1 print(k4,k2,k0) if k2 > 0: k0 += 1 if k0 > k4+1: print("No") else: print("Yes")
s312357950
Accepted
64
14,252
307
N = int(input()) A = list(map(int, input().split())) k0 = 0 k2 = 0 k4 = 0 for a in A: if a%4==0: k4 += 1 elif a%2==0: k2 += 1 else: k0 += 1 if k2 > 0: k0 += 1 if k0 <= k4+1: print("Yes") else: print("No")
s954720514
p03129
u482157295
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 b+b-1 >= a: print("Yes") else: print("No")
s757664482
Accepted
17
2,940
83
a,b = map(int,input().split()) if b+b-1 <= a: print("YES") else: print("NO")
s949095877
p03828
u501163846
2,000
262,144
Wrong Answer
34
3,064
566
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
import math k=int(input()) def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] pl=primes(k) ans=[] print(pl) m=math.factorial(k) for i in range(len(pl)): tmp=0 while m%pl[i]==0: m=m//pl[i] tmp+=1 ans.append(tmp) a=1 for i in range(len(ans)): a=a*(ans[i]+1)%(10**9+7) print(a)
s487645814
Accepted
35
3,064
556
import math k=int(input()) def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] pl=primes(k) ans=[] m=math.factorial(k) for i in range(len(pl)): tmp=0 while m%pl[i]==0: m=m//pl[i] tmp+=1 ans.append(tmp) a=1 for i in range(len(ans)): a=a*(ans[i]+1)%(10**9+7) print(a)
s467589213
p03730
u256106029
2,000
262,144
Wrong Answer
18
2,940
193
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().strip().split()) a_temp = a flg = False for i in range(b): if (a_temp - c) % b == 0: print('Yes') exit() a_temp += a else: print('No')
s264634479
Accepted
16
2,940
173
a, b, c = map(int, input().strip().split()) a_temp = a for i in range(b): if a_temp % b == c: print('YES') break a_temp += a else: print('NO')
s301370176
p02612
u389188163
2,000
1,048,576
Wrong Answer
27
9,132
69
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) n = N -1000 while n >= 1000: n -= 1000 print(n)
s555076247
Accepted
36
9,164
69
N = int(input()) n = N while n > 0: n -= 1000 print(abs(n))
s512586819
p03377
u045953894
2,000
262,144
Wrong Answer
17
3,064
90
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x = map(int,input().split()) if a <= x <= a+b: print('Yes') else: print('No')
s509556441
Accepted
19
3,068
90
a,b,x = map(int,input().split()) if a <= x <= a+b: print('YES') else: print('NO')
s405608311
p02854
u768896740
2,000
1,048,576
Wrong Answer
206
26,220
459
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
n = int(input()) a = list(map(int, input().split())) left = 0 right = 0 center = 0 sum_a = sum(a) flg = False for i in range(n): if left + a[i] > sum_a/2 and flg is False: flg = True center = a[i] right -= a[i] elif left + a[i] == sum_a // 2: print(0) exit() if flg is False: left += a[i] else: right += a[i] print(left, center, right) print(min(left+center-right, right+center-left))
s368564383
Accepted
221
26,220
448
n = int(input()) a = list(map(int, input().split())) left = a[0] right = a[-1] center = 0 sum_a = sum(a) flg = False for i in range(1, n-1): if left + a[i] > sum_a/2 and flg is False: flg = True center = a[i] right -= a[i] elif left + a[i] == sum_a / 2: print(0) exit() if flg is False: left += a[i] else: right += a[i] print(abs(min(left+center-right, right+center-left)))
s204458130
p02263
u408444038
1,000
131,072
Wrong Answer
20
5,616
978
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
import sys a = list(input().split()) stack = [] for i in range(len(a)): n = len(stack) if a[i] == '+': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp = int(stack.pop(n-1)) + int(stack.pop(n-2)) stack.append(tmp) elif a[i] == '-': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp_1 = int(stack.pop(n-1)) tmp_2 = int(stack.pop(n-2)) tmp = tmp_2 - tmp_1 stack.append(tmp) elif a[i] == '*': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp = int(stack.pop(n-1)) * int(stack.pop(n-2)) stack.append(tmp) elif a[i] == '/': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp_1 = int(stack.pop(n-1)) tmp_2 = int(stack.pop(n-2)) tmp = tmp_2 / tmp_1 stack.append(tmp) else: stack.append(int(a[i]))
s407150471
Accepted
20
5,620
994
import sys a = list(input().split()) stack = [] for i in range(len(a)): n = len(stack) if a[i] == '+': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp = int(stack.pop(n-1)) + int(stack.pop(n-2)) stack.append(tmp) elif a[i] == '-': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp_1 = int(stack.pop(n-1)) tmp_2 = int(stack.pop(n-2)) tmp = tmp_2 - tmp_1 stack.append(tmp) elif a[i] == '*': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp = int(stack.pop(n-1)) * int(stack.pop(n-2)) stack.append(tmp) elif a[i] == '/': if (n-2) <0: sys.exit("スタックアンダーフロー") tmp_1 = int(stack.pop(n-1)) tmp_2 = int(stack.pop(n-2)) tmp = tmp_2 / tmp_1 stack.append(tmp) else: stack.append(int(a[i])) print(stack[0])
s962297236
p03455
u325956328
2,000
262,144
Wrong Answer
18
2,940
183
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
def evencheck(a, b): p = a * b s = '' if p % 2 == 0: s = 'Even' else: s = 'Odd' return s a, b = map(int, input().split()) result = evencheck(a, b)
s971842032
Accepted
17
2,940
200
def evencheck(a, b): p = a * b s = '' if p % 2 == 0: s = 'Even' else: s = 'Odd' return s a, b = map(int, input().split()) result = evencheck(a, b) print(result)
s008698638
p04029
u518556834
2,000
262,144
Wrong Answer
19
2,940
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)
s801717291
Accepted
17
2,940
34
n = int(input()) print(n*(n+1)//2)
s769276076
p03455
u470927659
2,000
262,144
Wrong Answer
17
2,940
101
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()) c = a*b if c%2 == 1: print("Even") else: print("Odd")
s925953979
Accepted
18
2,940
101
a,b = map(int, input().split()) c = a*b if c%2 == 1: print("Odd") else: print("Even")
s071755551
p02613
u252964975
2,000
1,048,576
Wrong Answer
165
9,200
257
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N=int(input()) result_list = ['AC', 'WA', 'TLE', 'RE'] count_list = [0, 0, 0, 0] for i in range(N): S = input() count_list[result_list.index(S)] = count_list[result_list.index(S)] + 1 for i in range(4): print(result_list[i]+' × '+str(count_list[i]))
s425336850
Accepted
165
9,200
256
N=int(input()) result_list = ['AC', 'WA', 'TLE', 'RE'] count_list = [0, 0, 0, 0] for i in range(N): S = input() count_list[result_list.index(S)] = count_list[result_list.index(S)] + 1 for i in range(4): print(result_list[i]+' x '+str(count_list[i]))
s232966769
p02694
u877428733
2,000
1,048,576
Wrong Answer
22
9,116
130
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()) money = 100 ans = 0 while money <= X: money += math.floor(money * 0.01) ans += 1 print(ans)
s233791959
Accepted
20
9,164
130
import math X=int(input()) money = 100 ans = 0 while money < X: money += math.floor(money * 0.01) ans += 1 print(ans)
s174784671
p03455
u834415466
2,000
262,144
Wrong Answer
17
2,940
80
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 : print('odd') else: print('even')
s124491557
Accepted
18
2,940
80
a,b=map(int,input().split()) if a*b%2 : print('Odd') else: print('Even')
s731364738
p00007
u150984829
1,000
131,072
Wrong Answer
20
5,668
78
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks.
import math d=100 for _ in[0]*int(input()): d=math.ceil(d*1.05) print(d*1e3)
s279318823
Accepted
20
5,600
68
a=100 for _ in[0]*int(input()):a=int(a*1.05)+(a%20>0) print(a*1000)
s420808563
p03494
u107091170
2,000
262,144
Wrong Answer
30
9,036
166
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N=int(input()) a=list(map(int, input().split())) ans = 0 for i in range(N): d = 0 while (a[i] %2 == 0): d += 1 a[i] //= 2 ans = min(d,ans) print(ans)
s241268788
Accepted
26
9,112
173
N=int(input()) a=list(map(int, input().split())) ans = 100000000 for i in range(N): d = 0 while (a[i] %2 == 0): d += 1 a[i] //= 2 ans = min(d,ans) print(ans)
s149064980
p02613
u248556072
2,000
1,048,576
Wrong Answer
153
16,284
183
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) S = [] for n in range(N): S.append(input()) print('AC ×',S.count('AC')) print('WA ×',S.count('WA')) print('TLE ×',S.count('TLE')) print('RE ×',S.count('RE'))
s029441317
Accepted
146
16,276
179
N = int(input()) S = [] for n in range(N): S.append(input()) print('AC x',S.count('AC')) print('WA x',S.count('WA')) print('TLE x',S.count('TLE')) print('RE x',S.count('RE'))
s252710749
p02468
u978863922
1,000
131,072
Wrong Answer
20
5,592
110
For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M.
try: (m,n) = map(int,input().split()) except: exit print(m,n) r = pow(m,n) % 1000000007 print (r)
s236479693
Accepted
20
5,604
187
(m,n) = map(int,input().split()) bi = str(format(n,"b")) bi = bi[::-1] c = 1 d = 1000000007 for i in bi: if ( i == "1"): c = ( c * m ) % d m = (m * m) %d print (c)
s645650728
p03457
u001769145
2,000
262,144
Wrong Answer
380
3,064
317
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.
# ABC086 C Traveling n = int(input()) t, x, y = 0, 0, 0 flag = True for i in range(n): _t,_x,_y = map(int, input().split()) _d = abs(x - _x) + abs(y - _y) _dt = abs(t - _t) if _d > _dt or ((_d - _dt)%2) == 1: flag = False t,x,y = _t,_x,_y if flag: print("YES") else: print("NO")
s665822586
Accepted
376
3,064
317
# ABC086 C Traveling n = int(input()) t, x, y = 0, 0, 0 flag = True for i in range(n): _t,_x,_y = map(int, input().split()) _d = abs(x - _x) + abs(y - _y) _dt = abs(t - _t) if _d > _dt or ((_d - _dt)%2) == 1: flag = False t,x,y = _t,_x,_y if flag: print("Yes") else: print("No")
s701162030
p02612
u952968889
2,000
1,048,576
Wrong Answer
31
9,048
33
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)
s184681548
Accepted
33
9,140
64
from math import ceil n=int(input()) print(ceil(n/1000)*1000-n)
s024075436
p02669
u368796742
2,000
1,048,576
Wrong Answer
66
11,288
679
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
import sys from functools import lru_cache sys.setrecursionlimit(10**7) @lru_cache(maxsize=None) def dfs(x): if x == 0: return 0 if x == 1: return d l2 = x//2 r2 = (x+1)//2 l3 = x//3 r3 = (x+2)//3 l5 = x//5 r5 = (x+4)//5 count = x*d count = min(count,abs(l2*2-x)*d+a+dfs(l2)) count = min(count,abs(r2*2-x)*d+a+dfs(r2)) count = min(count,abs(l3*3-x)*d+b+dfs(l3)) count = min(count,abs(r3*3-x)*d+b+dfs(r3)) count = min(count,abs(l5*5-x)*d+c+dfs(l5)) count = min(count,abs(r5*5-x)*d+c+dfs(r5)) return count t = int(input()) for _ in range(t): n,a,b,c,d = map(int,input().split()) print(dfs(n))
s877197826
Accepted
302
20,448
801
import sys from functools import lru_cache sys.setrecursionlimit(10**7) def solve(x,a,b,c,d): @lru_cache(None) def dfs(x): if x == 0: return 0 if x == 1: return d l2 = x//2 r2 = (x+1)//2 l3 = x//3 r3 = (x+2)//3 l5 = x//5 r5 = (x+4)//5 count = x*d count = min(count,abs(l2*2-x)*d+a+dfs(l2)) count = min(count,abs(r2*2-x)*d+a+dfs(r2)) count = min(count,abs(l3*3-x)*d+b+dfs(l3)) count = min(count,abs(r3*3-x)*d+b+dfs(r3)) count = min(count,abs(l5*5-x)*d+c+dfs(l5)) count = min(count,abs(r5*5-x)*d+c+dfs(r5)) return count return dfs(x) t = int(input()) for _ in range(t): n,a,b,c,d = map(int,input().split()) print(solve(n,a,b,c,d))
s361916499
p03048
u771007149
2,000
1,048,576
Wrong Answer
2,103
2,940
246
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()) cnt = 0 for i in range(n//R): for j in range(n//G): for k in range(n//B): if i*R + j*G + k*B == n: cnt += 1 print(cnt)
s778134385
Accepted
1,953
2,940
277
R,G,B,n = map(int,input().split()) cnt = 0 for i in range(n//R + 1): for j in range(n - i*R + 1): c = n - (i*R + j*G) if c >= 0 and c%B == 0: cnt += 1 else: pass print(cnt)
s481384795
p02694
u059487235
2,000
1,048,576
Wrong Answer
20
9,136
139
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()) orig = 100 counter = 0 while orig <= x: orig = math.floor(orig * 1.01) counter += 1 print(counter)
s478387465
Accepted
22
9,132
138
import math x = int(input()) orig = 100 counter = 0 while orig < x: orig = math.floor(orig * 1.01) counter += 1 print(counter)
s092471625
p03657
u710789518
2,000
262,144
Wrong Answer
17
2,940
115
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
A, B = map(int, input().split()) if A % 3 == 0 or B % 3 == 0 or (A+B) % 3 == 0: print('Yes') else: print('No')
s891751346
Accepted
17
2,940
128
A, B = map(int, input().split()) if A % 3 == 0 or B % 3 == 0 or (A+B) % 3 == 0: print('Possible') else: print('Impossible')
s907409707
p02694
u479719434
2,000
1,048,576
Wrong Answer
21
9,156
121
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()) ans = 0 money = 100 while money <= X: ans += 1 money *= 1.01 money = int(money) print(ans)
s737210388
Accepted
24
9,096
120
X = int(input()) ans = 0 money = 100 while money < X: ans += 1 money *= 1.01 money = int(money) print(ans)
s561288359
p02612
u806698335
2,000
1,048,576
Wrong Answer
28
9,132
34
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)
s461124672
Accepted
28
9,080
51
n = int(input()) print( (1000 - n % 1000) % 1000)
s032492623
p03415
u821425701
2,000
262,144
Wrong Answer
17
2,940
66
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
x1 = input() x2 = input() x3 = input() print(x1[0], x2[1], x3[2])
s240433520
Accepted
17
2,940
83
s1 = input() s2 = input() s3 = input() print('{}{}{}'.format(s1[0], s2[1], s3[2]))
s120191888
p03962
u063346608
2,000
262,144
Wrong Answer
17
2,940
129
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
a,b,c = input().split() score = 1 if a != b: score = score + 1 elif a !=c: score = score + 1 else: score = score print(score)
s670042244
Accepted
17
2,940
201
a,b,c = input().split() if a == b and a == c: print(1) elif a ==b and a != c: print(2) elif b == c and b != a: print(2) elif c ==a and c != b: print(2) elif a != b and b != c and c != a: print(3)
s868904679
p03574
u018679195
2,000
262,144
Wrong Answer
25
3,572
1,596
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
import sys def main(): in1 = input() nums, length = in1.split(' ') nums= int(nums) length = int(length) bombs = [] # print(nums) # for i in range(nums): bombs.append(input()) print(bombs) checked = [['']*length for i in range(nums)] for i in range(nums): for j in range(length): if bombs[i][j] == '#': checked[i][j] = '#' else: bombnum = 0 if i != 0: if j != 0: if bombs[i-1][j-1] == '#': bombnum += 1 if j != length -1: if bombs[i-1][j+1] == '#': bombnum += 1 if bombs[i-1][j] == '#': bombnum += 1 if j != 0: if bombs[i][j-1] == '#': bombnum += 1 if j != length-1: if bombs[i][j+1] == '#': bombnum += 1 if i != nums-1: if j != 0: if bombs[i+1][j-1] == '#': bombnum += 1 if j != length -1: if bombs[i+1][j+1] == '#': bombnum += 1 if bombs[i+1][j] == '#': bombnum += 1 checked[i][j] = bombnum for i in checked: for j in i: print(j, end = '') print('') if __name__ == '__main__': main()
s079050409
Accepted
30
3,188
1,037
q=list(map(int,input().split())) grid=[] def ze(x,y): z=[] if y[0]+1<x[0]: z.append([y[0]+1,y[1]]) if y[1]+1<x[1]:# z.append([y[0]+1,y[1]+1]) if y[1]-1>=0: z.append([y[0]+1,y[1]-1]) if y[0]-1>=0: z.append([y[0]-1,y[1]]) if y[1]+1<x[1]:# z.append([y[0]-1,y[1]+1]) if y[1]-1>=0: z.append([y[0]-1,y[1]-1]) if y[1]+1<x[1]: z.append([y[0],y[1]+1]) if y[1]-1>=0: z.append([y[0],y[1]-1]) return(z) for i in range(q[0]): y=input() grid.append([i for i in y]) for i in range(q[0]): for j in range(q[1]): if grid[i][j]=='.': lamsa=ze(q,[i,j]) count=0 for k in range(len(lamsa)) : if grid[lamsa[k][0]][lamsa[k][1]] == '#' : count+=1 grid[i][j]=count for i in range(q[0]): pr='' for j in range(q[1]): pr=pr+str(grid[i][j]) print(pr)
s068433030
p03063
u608850287
2,000
1,048,576
Wrong Answer
115
3,500
184
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
n = int(input()) s = input() best = n curr = 0 nblack = 0 for ch in s: if ch == '.': curr = min(nblack, 1 + curr) else: nblack += 1 best = min(best, curr) print(best)
s442375497
Accepted
74
3,500
150
n = int(input()) s = input() curr = 0 nblack = 0 for ch in s: if ch == '.': curr = min(nblack, 1 + curr) else: nblack += 1 print(curr)
s412596856
p02608
u942051624
2,000
1,048,576
Wrong Answer
2,206
9,180
336
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
import math N=int(input()) ans=[0 for i in range(N)] for n in range(N): nax=int(math.sqrt(n)) for x in range(1,nax): for y in range(1,x+1): for z in range(1,y+1): temp=x**2+y**2+z**2+x*y+y*z+z*x if temp==n+1: ans[n]+=1 for anss in ans: print(anss*3)
s542053944
Accepted
189
9,272
650
import math N=int(input()) ans=[0 for i in range(N)] nax=int(math.sqrt(N)) for x in range(1,nax): for y in range(1,x+1): for z in range(1,y+1): temp=x**2+y**2+z**2+x*y+y*z+z*x if temp<=N: if x==y and y!=z: ans[temp-1]+=3 elif y==z and z!=x: ans[temp-1]+=3 elif z==x and x!=y: ans[temp-1]+=3 elif x==y==z: ans[temp-1]+=1 elif x!=y and y!=z and z!=x: ans[temp-1]+=6 for anss in ans: print(anss)
s107635206
p03455
u189397279
2,000
262,144
Wrong Answer
18
2,940
113
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
# -*- coding: utf-8 -*- a, b = map(int, input().split(" ")) if (a * b) % 2: print("Even") else: print("Odd")
s543945092
Accepted
17
2,940
114
# -*- coding: utf-8 -*- a, b = map(int, input().split(" ")) if (a * b) % 2: print("Odd") else: print("Even")
s084682048
p02603
u726285999
2,000
1,048,576
Wrong Answer
37
9,068
307
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 = [int(x) for x in input().split()] genkin = 1000 kabu = 0 for i in range(N-1): if A[i] < A[i+1]: kabu = genkin // A[i] genkin = genkin % A[i] if A[i] > A[i+1]: genkin += kabu * A[i] kabu = 0 print(genkin, kabu) print(genkin + kabu * A[N-1])
s249297616
Accepted
31
9,196
310
N = int(input()) A = [int(x) for x in input().split()] genkin = 1000 kabu = 0 for i in range(N-1): if A[i] < A[i+1]: kabu += genkin // A[i] genkin = genkin % A[i] if A[i] > A[i+1]: genkin += kabu * A[i] kabu = 0 print(genkin + kabu * A[N-1])
s658702386
p03493
u392433152
2,000
262,144
Wrong Answer
17
2,940
91
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(x) for x in input().split()) count=0 for i in s: if i==1: count+=1 print(count)
s948705535
Accepted
17
2,940
77
s=input() count=0 i=0 while i<3: if s[i]=="1": count+=1 i+=1 print(count)
s828645604
p03695
u497952650
2,000
262,144
Wrong Answer
17
3,064
562
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
MAX_COLORS = 8 DIFF_RATE = 400 def solve(a): colors = [0]*9 for i in a: num = 0 tmp = 400 for j in range(9): if i < 0: break else: i -= 400 num += 1 print(num) if i > 0: colors[num-1] += 1 else: colors[num-1] = 1 print(sum(colors[:8]),min(sum(colors[:8])+colors[-1],MAX_COLORS)) def main(): N = int(input()) a = list(map(int,input().split())) solve(a) if __name__ == "__main__": main()
s315687866
Accepted
18
3,064
618
def solve(a): colors = [0]*9 for i in a: num = 0 tmp = 400 flag = True for j in range(9): if i < 0: flag = False break else: i -= 400 num += 1 if flag: colors[num-1] += 1 else: colors[num-1] = 1 if sum(colors[:8]) == 0: print(1,colors[-1]) else: print(sum(colors[:8]),sum(colors[:8])+colors[-1]) def main(): N = int(input()) a = list(map(int,input().split())) solve(a) if __name__ == "__main__": main()
s641246070
p03360
u857330600
2,000
262,144
Wrong Answer
17
2,940
81
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
l=list(map(int,input().split())) l.sort() k=int(input()) print(l[0]+l[1]+l[2]**k)
s794611312
Accepted
17
2,940
85
l=list(map(int,input().split())) l.sort() k=int(input()) print(l[0]+l[1]+l[2]*(2**k))
s294120238
p02613
u771007149
2,000
1,048,576
Wrong Answer
148
9,208
384
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.
#B n = int(input()) cnt_ac = 0 cnt_wa = 0 cnt_tle = 0 cnt_re = 0 for _ in range(n): s = input() if s == 'AC': cnt_ac += 1 elif s == 'TLE': cnt_tle += 1 elif s == 'WA': cnt_wa += 1 else: cnt_re += 1 print('AC × {}'.format(cnt_ac)) print('WA × {}'.format(cnt_wa)) print('TLE × {}'.format(cnt_tle)) print('RE × {}'.format(cnt_re))
s823951298
Accepted
152
9,204
380
#B n = int(input()) cnt_ac = 0 cnt_wa = 0 cnt_tle = 0 cnt_re = 0 for _ in range(n): s = input() if s == 'AC': cnt_ac += 1 elif s == 'TLE': cnt_tle += 1 elif s == 'WA': cnt_wa += 1 else: cnt_re += 1 print('AC x {}'.format(cnt_ac)) print('WA x {}'.format(cnt_wa)) print('TLE x {}'.format(cnt_tle)) print('RE x {}'.format(cnt_re))
s297507622
p03047
u792078574
2,000
1,048,576
Wrong Answer
17
2,940
49
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
N, K = map(int, input().split()) print(K - N + 1)
s781946983
Accepted
17
2,940
49
N, K = map(int, input().split()) print(N - K + 1)
s994631819
p03697
u385309449
2,000
262,144
Wrong Answer
17
2,940
80
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
x,y = map(int,input().split()) if x+y >= 10: print(x+y) else: print('error')
s456618916
Accepted
17
2,940
80
x,y = map(int,input().split()) if x+y >= 10: print('error') else: print(x+y)
s551271162
p03478
u847923740
2,000
262,144
Wrong Answer
47
9,032
297
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).
# import sys input=sys.stdin.readline def main(): N,A,B=map(int,input().split()) cnt=0 for i in range(1,N+1): ds=0 for j in range(4): ds+=(i//(10**j))%(10**j) if A<=ds<=B: cnt+=i print(cnt) if __name__=="__main__": main()
s954553195
Accepted
43
8,920
299
# import sys input=sys.stdin.readline def main(): N,A,B=map(int,input().split()) cnt=0 for i in range(1,N+1): ds=0 for j in range(5): ds+=(int(i//(10**j)))%(10) if A<=ds<=B: cnt+=i print(cnt) if __name__=="__main__": main()
s679344185
p03719
u327466606
2,000
262,144
Wrong Answer
17
2,940
64
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c=map(int,input().split()) print('YES' if a<=c<=b else 'No')
s633845288
Accepted
17
2,940
64
a,b,c=map(int,input().split()) print('Yes' if a<=c<=b else 'No')
s009303546
p02844
u992910889
2,000
1,048,576
Wrong Answer
2,148
710,808
411
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
def resolve(): N=int(input()) s = str(input()) l=['%03d'%(p) for p in range(0,10**N)] cnt=0 for i in l: for j in range(N): if s[j]==i[0]: for k in range(j+1,N): if s[k]==i[1]: for m in range(k+1,N): if s[m]==i[2]: cnt+=1 print(cnt) resolve()
s578489491
Accepted
25
3,188
370
def resolve(): N=int(input()) s = str(input()) l=['%03d'%(p) for p in range(0,10**3)] ans=[] for i in l: if i[0] in s: s0=s.index(i[0]) if i[1] in s[s0+1:]: s1=s[s0+1:].index(i[1]) if i[2] in s[s0+1:][s1+1:]: ans.append(i) print(len(set(ans))) resolve()
s228036498
p02842
u167908302
2,000
1,048,576
Wrong Answer
17
2,940
47
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
#coding:utf-8 n = int(input()) print(n // 1.08)
s293648421
Accepted
17
2,940
124
#coding:utf-8 n = int(input()) x = int(-(-n // 1.08)) if int(x * 1.08) == n: print(x) else: print(':(')
s803446087
p02398
u546968095
1,000
131,072
Wrong Answer
30
5,592
251
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
def func(): a,b,c = input().split(" ") a = int(a) b = int(b) c = int(c) cnt = 0 for i in range(a,b+1): if 0 == i % c: cnt = cnt +1 print(cnt) return 0 if __name__ == "__main__": ret = func()
s560928013
Accepted
20
5,600
251
def func(): a,b,c = input().split(" ") a = int(a) b = int(b) c = int(c) cnt = 0 for i in range(a,b+1): if 0 == c % i: cnt = cnt +1 print(cnt) return 0 if __name__ == "__main__": ret = func()
s938102386
p02936
u608088992
2,000
1,048,576
Wrong Answer
697
63,556
815
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.
import sys, collections def solve(): input = sys.stdin.readline N, Q = map(int, input().split()) edge = [[] for i in range(N)] for _ in range(N-1): a, b = map(int, input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) counter = [0] * N for _ in range(Q): p, x = map(int, input().split()) counter[p-1] += x visited = [False] * N q = collections.deque() q.append(0) while q: now = q.popleft() if not visited: visited = True cnow = counter[now] for next in edge[now]: if not visited[next]: counter[next] += cnow q.append(next) print(" ".join(map(str, counter))) return 0 if __name__ == "__main__": solve()
s372632876
Accepted
972
65,668
721
import sys from collections import deque def solve(): input = sys.stdin.readline N, Q = map(int, input().split()) Edge = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) Edge[a-1].append(b-1) Edge[b-1].append(a-1) count = [0] * N for _ in range(Q): p, x = map(int, input().split()) count[p-1] += x q = deque() for nextN in Edge[0]: q.append((nextN, 0)) while q: nowN, parN = q.popleft() count[nowN] += count[parN] for nextN in Edge[nowN]: if nextN != parN: q.append((nextN, nowN)) print(" ".join(map(str, count))) return 0 if __name__ == "__main__": solve()
s432859535
p03845
u050708958
2,000
262,144
Wrong Answer
29
3,572
290
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.
import copy N = int(input()) t = [int(x) for x in input().split()] p = [] for _ in range(int(input())): p.append([int(x) for x in input().split()]) result = [] ori_t = copy.deepcopy(t) for i,j in zip(t,p): t = copy.deepcopy(ori_t) t[j[0]-1] = j[1] result.append(sum(t)) print(result)
s050327735
Accepted
30
3,444
293
import copy N = int(input()) t = [int(x) for x in input().split()] p = [] for _ in range(int(input())): p.append([int(x) for x in input().split()]) result = [] ori_t = copy.deepcopy(t) for i in p: t = copy.deepcopy(ori_t) t[i[0]-1] = i[1] result.append(sum(t)) for i in result: print(i)
s971489859
p03024
u782685137
2,000
1,048,576
Wrong Answer
17
2,940
46
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
print('NO' if input().count('x')>6 else 'YES')
s334362098
Accepted
17
2,940
46
print('NO' if input().count('x')>7 else 'YES')
s315450576
p03556
u468972478
2,000
262,144
Wrong Answer
2,206
9,476
97
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
n = int(input()) for i in range(n, 0, -1): if isinstance(i ** 0.5, int): print(i) break
s267114490
Accepted
28
9,424
31
print(int(int(input())**.5)**2)
s551366207
p03160
u033524082
2,000
1,048,576
Wrong Answer
202
13,776
354
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
n=int(input()) l=list(map(int,input().split())) m=[0,abs(l[1]-l[0])] if n==2: print(m[1]) else: p1=abs(l[2]-l[0]) p2=abs(m[1]+l[2]-l[1]) m.append(min(p1,p2)) print(m[-1]) for i in range(3,n): p1=m[-3]+abs(l[-1]-l[-3]) p2=m[-2]+abs(l[-1]-l[-2]) m.append(min(p1,p2)) print(m[i]) print(abs(m[-1]))
s310078542
Accepted
139
13,928
319
n=int(input()) l=list(map(int,input().split())) m=[0,abs(l[1]-l[0])] if n==2: print(m[1]) else: p1=abs(l[2]-l[0]) p2=m[1]+abs(l[2]-l[1]) m.append(min(p1,p2)) for i in range(3,n): p1=m[i-2]+abs(l[i]-l[i-2]) p2=m[i-1]+abs(l[i]-l[i-1]) m.append(min(p1,p2)) print(abs(m[-1]))
s168519161
p03473
u442948527
2,000
262,144
Wrong Answer
26
9,140
22
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
print(24-int(input()))
s475581937
Accepted
24
8,988
22
print(48-int(input()))
s208266547
p03129
u571445182
2,000
1,048,576
Wrong Answer
17
2,940
153
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
nData = [] nData = input().rstrip().split(' ') nN = int(nData[0]) nK = int(nData[1]) nTmp = nK * 2 if (nN >= nTmp): print('YES') else: print('NO')
s069234537
Accepted
17
2,940
162
nData = [] nData = input().rstrip().split(' ') nN = int(nData[0]) nK = int(nData[1]) nN += 1 nTmp = nK * 2 if (nN >= nTmp): print('YES') else: print('NO')
s632097395
p02534
u708530082
2,000
1,048,576
Wrong Answer
26
8,996
32
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`.
n = int(input()) print("ALC"*n)
s153169148
Accepted
22
9,064
32
n = int(input()) print("ACL"*n)
s153323178
p03434
u633355062
2,000
262,144
Wrong Answer
17
2,940
233
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()) cards = sorted(map(int, input().split()), reverse=True) score_alice, score_bob = 0, 0 for i in range(n): if i % 2 == 1: score_alice += cards[i] else: score_bob += cards[i] print(score_alice - score_bob)
s631544040
Accepted
17
2,940
235
n = int(input()) cards = sorted(map(int, input().split()), reverse=True) score_alice, score_bob = 0, 0 for i in range(n): if i % 2 == 0: score_alice += cards[i] else: score_bob += cards[i] print(score_alice - score_bob)
s945921352
p00003
u547838013
1,000
131,072
Wrong Answer
40
5,600
185
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
n = int(input()) for i in range(n): s = list(map(int, input().split())) s.sort() if(s[2] ** 2 == s[1] ** 2 + s[0] ** 2): print('yes') else: print('no')
s614343943
Accepted
40
5,592
185
n = int(input()) for i in range(n): s = list(map(int, input().split())) s.sort() if(s[2] ** 2 == s[1] ** 2 + s[0] ** 2): print('YES') else: print('NO')
s502824494
p02607
u503111914
2,000
1,048,576
Wrong Answer
28
9,160
143
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.
N = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(N): if i % 2 == 0: if A[i] % 2 == 0: ans += 1 print(ans)
s260394088
Accepted
26
9,076
144
N = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(N): if i % 2 == 0: if A[i] % 2 == 1: ans += 1 print(ans)
s013377478
p03854
u841348630
2,000
262,144
Wrong Answer
83
3,188
239
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() c = ["dream","dreamer","erase","eraser"] S = S[::-1] c = [cc[::-1] for cc in c] i=0 while i < len(c): if S.startswith(c[i]): S = S[len(c[i]):] i = 0 continue i = -~i print("NYoe s"[S==""::2])
s980623750
Accepted
81
3,188
239
S = input() c = ["dream","dreamer","erase","eraser"] S = S[::-1] c = [cc[::-1] for cc in c] i=0 while i < len(c): if S.startswith(c[i]): S = S[len(c[i]):] i = 0 continue i = -~i print("NYOE S"[S==""::2])
s332525434
p04011
u610232844
2,000
262,144
Wrong Answer
18
2,940
310
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
max_day, change_day, pay, discount_pay = [int(input()) for _ in range(4)] pay_change_day = max_day - change_day payment = 0 print(pay_change_day, payment) for i in range(change_day): payment += pay if pay_change_day > 0: for v in range(pay_change_day): payment += discount_pay print(payment)
s512296120
Accepted
20
2,940
216
max_day, normal_day, pay, discount_pay = [int(input()) for _ in range(4)] payment = 0 for i in range(max_day): if i < normal_day: payment += pay else: payment += discount_pay print(payment)
s971015756
p04029
u973069173
2,000
262,144
Wrong Answer
31
9,052
35
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)
s904437445
Accepted
28
9,148
36
a = int(input()) print((a*(a+1))//2)
s439127139
p03501
u724742135
2,000
262,144
Wrong Answer
17
2,940
123
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
from sys import stdin a, b, c = [int(x) for x in stdin.readline().rstrip().split()] if a*b>c: print(a*b) else: print(c)
s317842178
Accepted
17
2,940
125
from sys import stdin a, b, c = [int(x) for x in stdin.readline().rstrip().split()] if (a*b)>c: print(c) else: print(a*b)
s401653866
p00728
u282479278
1,000
131,072
Wrong Answer
50
5,604
434
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance. Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer. You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
j = 0 lists = [] flag = 0 cnt = 0 while 1: n = int(input()) if n == 0: break for i in range(n): s = int(input()) lists.append(s) for i in range(n): if lists[i] == max(lists): flag += 1 pass elif lists[i] == min(lists): flag += 1 pass else: cnt += lists[i] if flag >= 2: n -= 2 print(cnt // n)
s056809853
Accepted
30
5,600
579
j = 0 lists = [] flag = 0 cnt = 0 while 1: cnt = 0 flag_max = 0 flag_min = 0 lists = [] n = int(input()) if n == 0: break for i in range(n): s = int(input()) lists.append(s) for i in range(n): if lists[i] == max(lists): flag_max += 1 pass elif lists[i] == min(lists): flag_min += 1 pass else: cnt += lists[i] n -= 2 if flag_max >= 2: cnt += max(lists) elif flag_min >= 2: cnt += min(lists) print(cnt // n)
s831534217
p03408
u994767958
2,000
262,144
Wrong Answer
17
3,060
262
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()) lst = {} for _ in range(n): temp = input() if temp in lst: lst[temp] = lst[temp]+1 else: lst[temp] = 1 m = int(input()) for _ in range(m): temp = input() if temp in lst: lst[temp] = lst[temp] - 1 print(max(0,lst[max(lst)]))
s939831694
Accepted
18
3,060
317
def main(): n = int(input()) lst = {} for _ in range(n): temp = input() if temp in lst: lst[temp] = lst[temp]+1 else: lst[temp] = 1 m = int(input()) for _ in range(m): temp = input() if temp in lst: lst[temp] = lst[temp] - 1 ans = 0 for i in lst: ans = max(lst[i], ans) print(ans) main()
s075055320
p03493
u577139181
2,000
262,144
Wrong Answer
28
8,952
43
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
s = input() cnt = sum([int(c) for c in s])
s337174702
Accepted
30
8,876
55
s = input() cnt = sum([int(c) for c in s]) print(cnt)
s405421292
p03436
u503111914
2,000
262,144
Wrong Answer
36
9,148
921
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
import sys H, W = map(int, input().split()) sx = 0 sy = 0 gx = H-1 gy = W-1 C = [list(i for i in input()) for _ in range(H)] inf = -1 distance = [[inf] * W for _ in range(H)] queue = [] queue.insert(0, (sy, sx)) distance[sy][sx] = 0 X = 0 while True: try: y, x = queue.pop() # print(y,x) except: # print("Fail") break for i in range(4): nx = x + (-1, 0, 1, 0)[i] ny = y + (0, -1, 0, 1)[i] # print("nynx",ny,nx) if (0 <= nx and nx <= W-1 and 0 <= ny and ny <= H-1 and C[ny][nx] != '#' and distance[ny][nx] == inf): queue.insert(0, (ny, nx)) distance[ny][nx] = distance[y][x] + 1 C[ny][nx] = "!" if distance[H-1][W-1] != inf: #print(distance[gy][gx]) ans = 0 for i in C: ans += i.count(".") print(i) print(ans) print(distance) else: print("Fail")
s119946925
Accepted
34
9,272
901
import sys H, W = map(int, input().split()) sx = 0 sy = 0 gx = W-1 gy = H-1 ans = 0 A = [list(i for i in input()) for _ in range(H)] for j in A: ans += j.count(".") inf = -1 distance = [[inf] * W for _ in range(H)] queue = [] queue.insert(0, (sy, sx)) distance[sy][sx] = 0 X = 0 while True: try: y, x = queue.pop() # print(y,x) except: # print("Fail") break for i in range(4): nx = x + (-1, 0, 1, 0)[i] ny = y + (0, -1, 0, 1)[i] # print("nynx",ny,nx) if (0 <= nx and nx <= W-1 and 0 <= ny and ny <= H-1 and A[ny][nx] != '#' and distance[ny][nx] == inf): queue.insert(0, (ny, nx)) distance[ny][nx] = distance[y][x] + 1 A[ny][nx] = "!" if distance[H-1][W-1] != inf: #print(distance[gy][gx]) ans -= distance[gy][gx] + 1 print(ans) else: print(-1)
s297639505
p02318
u564105430
1,000
131,072
Wrong Answer
20
5,560
374
Find the edit distance between given two words s1 and s2. The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations: * **insertion** : Insert a character at a particular position. * **deletion** : Delete a character at a particular position. * **substitution** : Change the character at a particular position to a different character
s1=input() s2=input() ls1=len(s1) ls2=len(s2) f=[[0 for j in range(ls2+1)] for i in range(ls1+1)] for i in range(ls1+1): f[i][0]=i for i in range(ls2+1): f[0][i]=i for i in range(1,ls1+1): for j in range(1,ls2+1): if s1[i-1]!=s2[j-1]: f[i][j]=min(f[i-1][j]+1,f[i][j-1]+1,f[i-1][j-1]+1) else: f[i][j]=f[i-1][j-1] print(f)
s512211862
Accepted
1,320
42,892
436
s1=input() s2=input() ls1=len(s1) ls2=len(s2) f=[[0 for j in range(ls2+1)] for i in range(ls1+1)] for i in range(ls1+1): f[i][0]=i for i in range(ls2+1): f[0][i]=i for i in range(1,ls1+1): for j in range(1,ls2+1): if s1[i-1]!=s2[j-1]: f[i][j]=min(f[i-1][j]+1,f[i][j-1]+1,f[i-1][j-1]+1) else: f[i][j]=f[i-1][j-1] print(f[i][j])
s366752007
p03523
u366886346
2,000
262,144
Wrong Answer
17
2,940
214
You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
s=input() str=["A","K","I","H","A","B","A","R","A"] count=0 for i in range(9): if s[count]==str[i]: count+=1 if count==len(s): break if count!=len(s): print("No") else: print("Yes")
s739971810
Accepted
17
3,064
367
s=input() str=["A","K","I","H","A","B","A","R","A"] count=0 ans=0 for i in range(9): if count==len(s) and i<8: ans=1 break elif count==len(s): break if s[count]==str[i]: count+=1 elif s[count]!=str[i] and str[i]!="A": ans=1 break if len(s)>9: ans=1 if ans==1: print("NO") else: print("YES")
s210393673
p02927
u414699019
2,000
1,048,576
Wrong Answer
17
2,940
162
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()) result=0 for i in (2,D//10+1): if i<D//10: result+=M//i-1 else: if D%10>=2: result+=min(M//i,D%10)-1 print(result)
s928446904
Accepted
17
3,060
250
M,D=map(int,input().split()) result=0 for i in range(2,D//10+1): if i<D//10: result+=max(min(M//i,9)-1,0) #print(i,min(M//i,9)-1) else: if D%10>=2: result+=max(min(M//i,D%10)-1,0) #print(i,min(M//i,D%10)-1) print(result)
s404384449
p03472
u941753895
2,000
262,144
Wrong Answer
491
21,960
346
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()) if N==1 and H==10: exit() l=[] for i in range(N): a,b=map(int,input().split()) l.append([a,b]) l=sorted(l,key=lambda x:x[0]) ax=l[-1][0] bx=l[-1][1] c=0 for x in l[:-1]: if H<=bx: c+=1 print(c) exit() if x[1]>ax: H-=x[1] c+=1 H-=bx c+=1 if H<=0: print(c) exit() c+=-(-H//ax) print(c)
s662276519
Accepted
442
37,052
852
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): n,h=LI() l=[] for _ in range(n): a,b=LI() l.append([a,-1]) l.append([b,1]) l=sorted(l,key=lambda x:x[0],reverse=True) # print(l) ans=0 for i,x in enumerate(l): if x[1]==1: ans+=1 h-=x[0] else: ans+=-(-h//x[0]) return ans if h<=0: return ans return ans # main() print(main())
s787457914
p02414
u567380442
1,000
131,072
Wrong Answer
30
6,720
253
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
n, m, L = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(m)] b = [list(map(int, input().split())) for _ in range(L)] c = [[sum(ak * bk for ak, bk in zip(ai,bj)) for bj in zip(*b)] for ai in a] for ci in c: print(*ci)
s229321596
Accepted
200
7,768
253
n, m, L = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] b = [list(map(int, input().split())) for _ in range(m)] c = [[sum(ak * bk for ak, bk in zip(ai,bj)) for bj in zip(*b)] for ai in a] for ci in c: print(*ci)
s757812534
p03377
u945181840
2,000
262,144
Wrong Answer
17
3,064
95
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A, B, X = map(int, input().split()) if A + B >= X >= A: print('Yes') else: print('No')
s284851997
Accepted
17
2,940
95
A, B, X = map(int, input().split()) if A + B >= X >= A: print('YES') else: print('NO')
s765109096
p03606
u598229387
2,000
262,144
Wrong Answer
21
3,188
144
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
n = int(input()) lr = [[int(i) for i in input().split()] for j in range(n)] ans = 0 for i in range(n): ans += lr[i][1] - lr[i][0] print(ans)
s440967473
Accepted
20
3,188
146
n = int(input()) lr = [[int(i) for i in input().split()] for j in range(n)] ans = 0 for i in range(n): ans += lr[i][1] - lr[i][0]+1 print(ans)
s977550644
p02612
u986942034
2,000
1,048,576
Wrong Answer
29
9,140
24
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.
print(int(input())%1000)
s401262940
Accepted
30
9,148
81
N = int(input()) change = 1000 - (N % 1000) if N % 1000 != 0 else 0 print(change)
s704199915
p03730
u662613022
2,000
262,144
Wrong Answer
17
2,940
163
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`.
N,M,R = map(int,input().split()) ans = '' for i in range(M+1): if (i * N) % M == R: ans = 'Yes' break; if ans == '': ans = 'No' print(ans)
s617321448
Accepted
17
3,060
163
N,M,R = map(int,input().split()) ans = '' for i in range(M+1): if (i * N) % M == R: ans = 'YES' break; if ans == '': ans = 'NO' print(ans)
s381844857
p02612
u801701525
2,000
1,048,576
Wrong Answer
26
9,140
45
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(1000-(N-round(N,-3)))
s512086278
Accepted
29
9,148
138
N = int(input()) while True: if N >= 1000: N -= 1000 else: break if N == 0: print(0) else: print(1000-N)
s204251459
p03852
u138486156
2,000
262,144
Wrong Answer
17
3,064
720
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() s_list = list(s) while True: l5 = s_list[-5:] l6 = s_list[-6:] l7 = s_list[-7:] s5 = s6 = s7 = '' for ch in l5: s5 += ch # print("s5 :", s5) for ch in l6: s6 += ch # print("s6 :", s6) for ch in l7: s7 += ch # print("s7 :", s7) if (s5 == 'erase') | (s5 == 'dream'): s_list = s_list[:-5] # print("s_list:", s_list) elif s6 == 'eraser': s_list = s_list[:-6] # print("s_list:", s_list) elif s7 == 'dreamer': s_list = s_list[:-7] # print("s_list:", s_list) else: print('NO') # print("s_list:", s_list) exit() if s_list == []: print('YES') exit()
s484364682
Accepted
17
2,940
132
ch = input() if (ch == 'a') | (ch == 'i') | (ch == 'u') | (ch == 'e') | (ch == 'o'): print('vowel') else: print('consonant')
s009798890
p03457
u159863320
2,000
262,144
Wrong Answer
320
25,768
476
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 = [] p = [0, 0, 0] while(n): a, b, c = input().split(' ') t.append([int(a), int(b), int(c)]) n-=1 for i in t: while(p[0] < i[0]): p[0]+=1 if i[1] > p[1]: p[1]+=1 elif i[2] > p[2]: p[2]+=1 elif i[1] < p[1]: p[1]-=1 elif i[2] < p[2]: p[2]-=1 else: p[1]-=1 print(p) if p != i: print('No') exit() print('Yes')
s677448435
Accepted
265
25,384
459
n = int(input()) t = [] p = [0, 0, 0] while(n): a, b, c = input().split(' ') t.append([int(a), int(b), int(c)]) n-=1 for i in t: while(p[0] < i[0]): p[0]+=1 if i[1] > p[1]: p[1]+=1 elif i[2] > p[2]: p[2]+=1 elif i[1] < p[1]: p[1]-=1 elif i[2] < p[2]: p[2]-=1 else: p[1]-=1 if p != i: print('No') exit() print('Yes')
s747074537
p03643
u532966492
2,000
262,144
Wrong Answer
17
2,940
13
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
"ABC"+input()
s423618846
Accepted
17
2,940
20
print("ABC"+input())
s175641302
p03068
u092460072
2,000
1,048,576
Wrong Answer
17
2,940
126
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
n=int(input()) s=input() k=int(input()) j=s[k-1] new_s="" for i in range(n): if s[i]!=j: new_s+="*" else: new_s+=j
s739371613
Accepted
17
3,064
139
n=int(input()) s=input() k=int(input()) j=s[k-1] new_s="" for i in range(n): if s[i]!=j: new_s+="*" else: new_s+=j print(new_s)
s466441737
p03673
u290326033
2,000
262,144
Wrong Answer
2,105
25,156
123
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
n = int(input()) A = list(map(int, input().split())) B = [] for i in range(n): B.append(A[i]) B.reverse() print(B)
s819262256
Accepted
215
25,920
307
from collections import deque n = int(input()) A = list(map(int, input().split())) B = deque() for i in range(n): if(i%2 == 0): B.append(A[i]) if(i%2 == 1): B.appendleft(A[i]) if(n%2 == 1): B.reverse() text = "" for b in B: text += str(b) + " " text = text[:-1] print(text)
s466006623
p03339
u197968862
2,000
1,048,576
Wrong Answer
352
17,656
604
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
n = int(input()) s = input() count_e = [0] * n count_w = [0] * n for i in range(n): if i == 0: if s[i] == 'E': count_e[i] = 1 else: count_w[i] = 1 continue if s[i] == 'E': count_e[i] = count_e[i-1] + 1 count_w[i] = count_w[i-1] else: count_w[i] = count_e[i-1] count_e[i] = count_e[i-1] + 1 ans = 10 ** 9 for i in range(n): if s[i] == 'E': e = count_e[-1] - count_e[i] w = count_w[i] else: e = count_e[-1] - count_e[i] w = count_w[i] - 1 ans = min(ans,e+w) print(ans)
s964991100
Accepted
350
17,652
604
n = int(input()) s = input() count_e = [0] * n count_w = [0] * n for i in range(n): if i == 0: if s[i] == 'E': count_e[i] = 1 else: count_w[i] = 1 continue if s[i] == 'E': count_e[i] = count_e[i-1] + 1 count_w[i] = count_w[i-1] else: count_e[i] = count_e[i-1] count_w[i] = count_w[i-1] + 1 ans = 10 ** 9 for i in range(n): if s[i] == 'E': e = count_e[-1] - count_e[i] w = count_w[i] else: e = count_e[-1] - count_e[i] w = count_w[i] - 1 ans = min(ans,e+w) print(ans)
s723642405
p02277
u782850499
1,000
131,072
Wrong Answer
20
7,784
990
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also 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).
def partition(A, p, r): x = int(A[r-1][2]) i = p-1 for j in range(p,r-1): if int(A[j][2]) <= x: i = i + 1 A[i],A[j] = A[j],A[i] A[i+1],A[r-1] = A[r-1],A[i+1] return i + 1 def qsort(A,p,r): if p < r: q = partition(A,p,r) qsort(A,p,q-1) qsort(A,q+1,r) return A def isStable(a, b): length = int(len(a)) for i in range(length): for j in range(i+1,length-1) : for x in range(length): for y in range(x+1,length-1) : if a[i][2]==a[j][2] and a[i] == b[y] and a[j] == b[x]: return False break return True if __name__ == '__main__': cnt = int(input()) A = [] for i in range(cnt): A.append(input()) A2 = A[:] p = 0 r = len(A) B = qsort(A,p,r) if isStable(A2,B): print("Stable") else: print("Not Stable") for i in B: print (i)
s449984603
Accepted
1,640
34,644
919
def partition(A, p, r): x = int(A[r-1][1]) i = p-1 for j in range(p,r-1): if int(A[j][1]) <= x: i = i + 1 A[i],A[j] = A[j],A[i] A[i+1],A[r-1] = A[r-1],A[i+1] return i + 1 def qsort(A,p,r): if p < r: q = partition(A,p,r) qsort(A,p,q) qsort(A,q+1,r) return A def isStable(a): length = int(len(a)) for i in range(length): for j in range(i+1,length-1) : if a[i][1] == a[j][1] and a[i][2] > a[j][2]: return False break return True if __name__ == '__main__': cnt = int(input()) A = [] for i in range(cnt): N = input().split() N.append(i) A.append(N) p = 0 r = len(A) B = qsort(A,p,r) if isStable(B): print("Stable") else: print("Not stable") for i in B: print ("{0} {1}".format(i[0],i[1]))
s713050687
p03493
u925364229
2,000
262,144
Wrong Answer
17
2,940
56
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
S = input() ans = 0 for i in S: if i == 1: ans += 1
s433614348
Accepted
17
2,940
69
S = input() ans = 0 for i in S: if i == "1": ans += 1 print(ans)
s077971576
p03795
u652569315
2,000
262,144
Wrong Answer
17
2,940
37
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(800*n-(n//3)*40)
s173949917
Accepted
17
2,940
39
n=int(input()) print(800*n-(n//15)*200)