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
s267910497
p02390
u058933891
1,000
131,072
Wrong Answer
20
7,540
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.
s = int(input()) h = s - s % 3600 m = s% 3600 - (s % 3600) % 60 s = (s % 3600) % 60 print ( "h:m:s")
s904451058
Accepted
30
7,664
166
s = int(input()) h = str(int((s - s % 3600 ) / 3600 )) m = str(int((s% 3600 - (s % 3600) % 60) /60 )) s = str(int((s % 3600) % 60 )) print ( h + ":" + m + ":" + s)
s275942900
p03480
u762557532
2,000
262,144
Wrong Answer
2,104
6,264
543
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times. * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
from collections import Counter S = input() boundary = [] pre_state = '0' for i in range(len(S)): if S[i] != pre_state: boundary.append(i) pre_state = S[i] else: if S[-1] == '1': boundary.append(len(S)) k = 2 while True: lst_mod = list(map(lambda x: x % k, boundary)) count_mod = list(Counter(lst_mod).values()) if not any(list(map(lambda x: x % 2, count_mod))): k += 1 else: print(k-1) exit()
s850012745
Accepted
63
6,388
458
S = input() boundary = [] pre_state = '0' for i in range(len(S)): if S[i] != pre_state: boundary.append(i) pre_state = S[i] else: if S[-1] == '1': boundary.append(len(S)) if len(boundary) == 0: print(len(S)) exit() lst = [] for i in range(len(boundary)): lst.append(max(boundary[i], len(S)-boundary[i])) ans = min(lst) print(ans)
s013557974
p03623
u500297289
2,000
262,144
Wrong Answer
17
2,940
91
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x, a, b = map(int, input().split()) if abs(x - a) < abs(x - b): print(a) else: print(b)
s756575343
Accepted
18
2,940
95
x, a, b = map(int, input().split()) if abs(x - a) < abs(x - b): print('A') else: print('B')
s241978660
p02600
u347600233
2,000
1,048,576
Wrong Answer
25
9,152
47
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
x = int(input()) print(8 - (1800 - 400) // 200)
s752289484
Accepted
26
9,152
44
x = int(input()) print(8 - (x - 400) // 200)
s036946679
p02865
u343850880
2,000
1,048,576
Wrong Answer
17
2,940
70
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n = int(input()) if n%2==0: print(n/2-1) else: print((n-1)/2)
s255798094
Accepted
17
2,940
80
n = int(input()) if n%2==0: print(int(n/2-1)) else: print(int((n-1)/2))
s220983464
p02690
u042113240
2,000
1,048,576
Wrong Answer
21
9,188
154
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()) x = 1 while ((x-1)**4)*5 > X: x += 1 for i in range(x): for j in range(-x, i): if i**5-j**5 == X: a = [i,j] print(*a)
s887421935
Accepted
33
9,116
182
X = int(input()) x = 1 while ((x-1)**4)*5 < X: x += 1 for i in range(x): for j in range(-x, i): if i**5-j**5 == X: a = [i,j] break print(*a)
s622091212
p03943
u894694822
2,000
262,144
Wrong Answer
20
3,060
105
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a, b, c =map(int,input().split()) if a+b == c or a+c == b or b+c == a: print("YES") else: print("NO")
s106399646
Accepted
20
2,940
105
a, b, c =map(int,input().split()) if a+b == c or a+c == b or b+c == a: print("Yes") else: print("No")
s521404114
p02743
u692687119
2,000
1,048,576
Wrong Answer
18
2,940
144
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a, b, c = map(int, input().split()) A = a * a B = b * b C = c * c X = ((C - A - B))-(4 * a * b) if X > 0: print('Yes') else: print('No')
s183578998
Accepted
32
2,940
164
a, b, c = map(int, input().split()) m = c - a - b if m <= 0: print('No') else: X = (m * m) - (4 * a * b) if X > 0: print('Yes') else: print('No')
s911398510
p03944
u143278390
2,000
262,144
Wrong Answer
342
12,540
816
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.
import numpy as np W,H,N=[int(i) for i in input().split()] lst=[] for j in range(N): lst.append([int(i) for i in input().split()]) print(lst) square=np.zeros(H*W,dtype=np.int64).reshape(H,W) print(square) for i in lst: x=i[0] y=i[1] a=i[2] if(a==1): for j in range(x): for k in range(H): square[k][j]=1 #print(square) elif(a==2): for j in range(x,W): for k in range(H): square[k][j]=1 #print(square) elif(a==3): for j in range(H-y,H): for k in range(W): square[j][k]=1 #print(square) else: for j in range(H-y-1,-1,-1): for k in range(W): square[j][k]=1 #print(square) print(np.count_nonzero(square ==0))
s349237183
Accepted
341
12,512
818
import numpy as np W,H,N=[int(i) for i in input().split()] lst=[] for j in range(N): lst.append([int(i) for i in input().split()]) #print(lst) square=np.zeros(H*W,dtype=np.int64).reshape(H,W) #print(square) for i in lst: x=i[0] y=i[1] a=i[2] if(a==1): for j in range(x): for k in range(H): square[k][j]=1 #print(square) elif(a==2): for j in range(x,W): for k in range(H): square[k][j]=1 #print(square) elif(a==3): for j in range(H-y,H): for k in range(W): square[j][k]=1 #print(square) else: for j in range(H-y-1,-1,-1): for k in range(W): square[j][k]=1 #print(square) print(np.count_nonzero(square ==0))
s334394245
p02396
u566311709
1,000
131,072
Wrong Answer
80
5,904
153
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.
a = [] while True: n = int(input()) if n == 0: break a.append(n) for i in range(len(a)): print("Case {0}: {1}".format(i, a[i]))
s149474044
Accepted
80
5,908
144
a = [] while True: n = int(input()) if n == 0: break a.append(n) for i in range(len(a)): print("Case {0}: {1}".format(i + 1, a[i]))
s689085092
p03605
u629540524
2,000
262,144
Wrong Answer
17
2,940
63
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
n = input() if n in '9': print('Yes') else: print('No')
s671245202
Accepted
17
2,940
63
n = input() if '9' in n: print('Yes') else: print('No')
s843771964
p00007
u350804311
1,000
131,072
Wrong Answer
40
7,620
126
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 n = int(input()) debt = 100 for i in range(n): debt = math.ceil(debt * 1.05) print(str(debt * 1000))
s995242092
Accepted
40
7,648
122
import math n = int(input()) debt = 100 for i in range(n): debt = math.ceil(debt * 1.05) print(str(debt * 1000))
s336378846
p03574
u240793404
2,000
262,144
Wrong Answer
27
3,188
543
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 = map(int,input().split()) mine = [] for i in range(h): mine.append([]) inp = input() for j in range(w): mine[i].append(inp[j]) print(mine) for i in range(h): for j in range(w): if mine[i][j] == '.': cnt = 0 for k in range(3): for l in range(3): try: if mine[i-1+k][j+l-1] == '#': cnt+= 1 except: continue mine[i][j] = str(cnt) print(mine)
s412259539
Accepted
29
3,188
467
import itertools h,w=map(int,input().split()) s=[list(input()) for i in range(h)] l=list(itertools.product([-1,0,1],repeat=2)) for i in range(h): for j in range(w): if s[i][j]=='.': cnt = 0 for k in l: x = i+k[0] y = j+k[1] if 0<=x<=h-1 and 0<=y<=w-1: if s[x][y]=='#': cnt+=1 s[i][j]=str(cnt) for i in s: print(''.join(i))
s830292021
p03478
u687044304
2,000
262,144
Wrong Answer
19
2,940
309
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).
# -*- coding:utf-8 -*- def solve(): N, A, B = list(map(int, input().split())) ans = 0 for i in range(N): bit0 = i%10 bit1 = i//10 total = (bit0 + bit1) if total >= A and total <= B: ans += 1 print(ans) if __name__ == "__main__": solve()
s673789735
Accepted
23
3,060
411
# -*- coding:utf-8 -*- def solve(): N, A, B = list(map(int, input().split())) ans = 0 for i in range(1, N+1): keta_sum = 0 num = i while True: if num == 0: break keta_sum += num%10 num = num//10 if keta_sum >= A and keta_sum <= B: ans += i print(ans) if __name__ == "__main__": solve()
s374628866
p02749
u023229441
2,000
1,048,576
Wrong Answer
1,046
167,732
1,422
We have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i. Takahashi loves the number 3. He is seeking a permutation p_1, p_2, \ldots , p_N of integers from 1 to N satisfying the following condition: * For every pair of vertices (i, j), if the distance between Vertex i and Vertex j is 3, the sum or product of p_i and p_j is a multiple of 3. Here the distance between Vertex i and Vertex j is the number of edges contained in the shortest path from Vertex i to Vertex j. Help Takahashi by finding a permutation that satisfies the condition.
import sys import math mod=10**9+7 inf=float("inf") from math import sqrt from collections import deque from collections import Counter input=lambda: sys.stdin.readline().strip() sys.setrecursionlimit(11451419) from functools import lru_cache n=int(input()) G=[[] for i in range(n)] for i in range(n-1): a,b=map(int,input().split()) G[a-1].append(b-1) G[b-1].append(a-1) color=[-1 for i in range(n)] color[0]=0 def coloring(x): for i in G[x]: if color[i] != -1:continue color[i]=1-color[x] coloring(i) coloring(0) A=[];B=[] ans=[0 for i in range(n)] for i in range(n): if color[i]==0:A.append(i) else:B.append(i) if len(A)<=n//3 or len(B)<=n//3: if len(A)>len(B): A,B=B,A qq=3 for i in A: ans[i]=qq qq+=3 qq=deque([3*i+1 for i in range(int(n/3+0.9999))]+[3*i+2 for i in range(int(n/3+0.9999))]+[3*i for i in range(int(n//3),-1,-1)]) for t in range(n): if ans[t]!=0: ans[t]=qq.popleft() print(*ans) exit() qq=deque([3*i+1 for i in range(int(n/3+0.9999))]+[3*i for i in range(int(n//3),0,-1)]) for i in A: ans[i]=qq.popleft() qq.extend([3*i+2 for i in range(int(n/3+0.9999))]) for j in B: ans[j]=qq.pop() print(*ans)
s912147142
Accepted
940
62,152
1,447
n=int(input()) dist=[-1]*n G=[[] for i in range(n)] for i in range(n-1): a,b=map(int,input().split()) a-=1;b-=1 G[a].append(b) G[b].append(a) from collections import deque queue=deque([[0,i] for i in G[0]]) dist[0]=0 while queue: now,to=queue.pop() # print(now,to) if dist[to]!=-1:continue dist[to]=1-dist[now] for i in G[to]: queue.appendleft([to,i]) # print(dist) q=sum(dist) LAST=[0]*n if n/3 <= q and n/3 <= n-q: A=[i for i in range(1,n+1,3)] + [0]*n B=[i for i in range(2,n+1,3)] + [0]*n now1=0 now2=0 for i in range(n): if dist[i]: LAST[i]=B[now2] now2+=1 else: LAST[i]=A[now1] now1+=1 w=3 for i in range(n): if LAST[i]==0: LAST[i]=w w+=3 print(*LAST) elif n/3 >q: w=3 for i in range(n): if dist[i]: LAST[i]=w w+=3 A=[i for i in range(w,n+1,3)]+[i for i in range(1,n+1) if i%3!=0] now=0 for i in range(n): if LAST[i]==0: LAST[i]=A[now] now+=1 print(*LAST) else: w=3 for i in range(n): if dist[i]==0: LAST[i]=w w+=3 A=[i for i in range(w,n+1,3)]+[i for i in range(1,n+1) if i%3!=0] now=0 for i in range(n): if LAST[i]==0: LAST[i]=A[now] now+=1 print(*LAST)
s733883849
p03351
u636162168
2,000
1,048,576
Wrong Answer
17
2,940
156
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d=map(int,input().split()) if abs(a-c)<d: print("Yes") else: if abs(a-b)<d and abs(b-c)<d: print("Yes") else: print("No")
s522320648
Accepted
17
2,940
159
a,b,c,d=map(int,input().split()) if abs(a-c)<=d: print("Yes") else: if abs(a-b)<=d and abs(b-c)<=d: print("Yes") else: print("No")
s915962113
p03719
u346308892
2,000
262,144
Wrong Answer
26
2,940
102
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 c>=a and c<=b: print("yes") else: print("no")
s526063043
Accepted
18
3,064
98
a,b,c=list(map(int,input().split(" "))) if c>=a and c<=b: print("Yes") else: print("No")
s939502995
p03853
u781288689
2,000
262,144
Wrong Answer
23
3,064
127
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
m,n=input().split() a=[] for i in range(int(m)) : a.append(input()) for i in a : print(i) for i in a : print(i)
s583297587
Accepted
23
3,192
111
m,n=input().split() a=[] for i in range(int(m)) : a.append(input()) for i in a : print(i) print(i)
s213047052
p03487
u729133443
2,000
262,144
Wrong Answer
42
14,692
47
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
n=int(input()) a=list(map(int,input().split()))
s658212626
Accepted
94
17,704
109
n,*a=map(int,open(0).read().split()) d={} for i in a:d[i]=d.get(i,0)+1 print(sum(d[i]-i*(d[i]>=i)for i in d))
s686283952
p03447
u117193815
2,000
262,144
Wrong Answer
17
2,940
71
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?
a = int(input()) if a%2==0: print(int(a/2)) else: print(a//2+1)
s129180405
Accepted
17
2,940
77
x = int(input()) a = int(input()) b = int(input()) print((x-a)%b)
s841873637
p03698
u856232850
2,000
262,144
Wrong Answer
17
2,940
89
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
a = input() ans = 'no' for i in a: if a.count(i) >= 2: ans = 'yes' print(ans)
s476396770
Accepted
17
2,940
89
a = input() ans = 'yes' for i in a: if a.count(i) >= 2: ans = 'no' print(ans)
s363062533
p03862
u923659712
2,000
262,144
Wrong Answer
92
14,252
146
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
n,x=map(int,input().split()) a=list(map(int,input().split())) c=0 for i in range(n-1): if a[i]+a[i+1]>x: c+=(a[i]+a[i+1]-x) print(c)
s816180957
Accepted
124
14,060
212
n,x=map(int,input().split()) a=list(map(int,input().split())) c=0 if a[0] > x: c= a[0] - x a[0] = x for i in range(0,n-1): if a[i]+a[i+1]>x: c+=(a[i]+a[i+1]-x) a[i+1]-=(a[i]+a[i+1]-x) print(c)
s973841587
p03644
u706414019
2,000
262,144
Wrong Answer
30
9,028
105
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()) a = 0 for i in range(N): a = max(a,len(bin(64))-(bin(64)).rfind('1')-1) print(2**a)
s818039581
Accepted
29
9,052
108
N = int(input()) counter = 0 for i in range(8): if N // 2**i ==0: print(2**(i-1)) break
s248132735
p03007
u201234972
2,000
1,048,576
Wrong Answer
247
14,092
1,126
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
N = int( input()) A = list( map( int, input().split())) A.sort(reverse=True) if N%2 == 0: print( sum(A[:N//2]) - sum(A[N//2:])) now = A[0] print(now, A[N-1]) now -= A[N-1] for i in range(2,N): if i%2 == 0: print(A[N-1-i//2], now) now = A[N-1-i//2] - now else: print(A[i//2], now) now = A[i//2] - now else: k = N//2 t = 1 if A[k] < 0: t = 0 print( sum(A[:k+t]) - sum(A[k+t:])) if t == 1: now = A[N-1] print(now, A[0]) now = now - A[0] for i in range(2, N): if i%2 == 0: print(A[i//2], now) now = A[i//2] - now else: print(A[N-1-i//2], now) now = A[N-1-i//2] - now else: now = A[0] print(now, A[N-1]) now -= A[N-1] for i in range(2, N-1): if i%2 == 0: print(A[N-1-i//2], now) now = A[N-1-i//2] - now else: print(A[i//2], now) now = A[i//2] - now print(now, A[k])
s391954554
Accepted
262
14,260
1,001
N = int( input()) A = list( map( int, input().split())) A.sort(reverse = True) plus = 0 zero = 0 for i in range(N): if A[i] > 0: plus += 1 elif A[i] == 0: zero += 1 minus = N - plus - zero if plus + zero== N: print(sum(A)-A[-1]*2) now = A[-1] for i in range(N-2): print(now, A[i]) now -= A[i] print(A[N-2], now) elif minus + zero== N: print(A[0]*2 - sum(A)) now = A[0] for i in range(1,N): print(now, A[i]) now -= A[i] elif plus+zero == 1: print( sum( list( map( abs, A)))) now = A[0] for i in range(1,N): print(now, A[i]) now -= A[i] else: print( sum( list( map( abs, A)))) now = A[N-1] k = N-1 for i in range(1,N-1): if A[i] <= 0: k = i break print(now, A[i]) now -= A[i] print(A[0], now) now = A[0] - now for i in range(k,N-1): if A[i] > 0: pass print(now, A[i]) now -= A[i]
s587759720
p03599
u382303205
3,000
262,144
Wrong Answer
3,156
3,444
1,144
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
a,b,c,d,e,f=map(int,input().split()) ans1 = 100 ans2 = 0 if a>b: a, b = b, a for _a in range(f//(a*100) + 1): for _b in range((f - _a*100)//(b*100) + 1): for _c in range((f - _a*100 - _b*100)//c + 1): for _d in range((f - _a*100 - _b*100 - _c * c)//d + 1): if a*100*_a+b*100*_b+c*_c+d*_d == 0: continue if a*100*_a+b*100*_b+c*_c+d*_d > f: continue if (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) == e/(100+e): print(a*100*_a+b*100*_b+c*_c+d*_d, c*_c+d*_d) break elif (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) > e/(100+e): continue else: if ans2/ans1 < (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d): ans1 = a*100*_a+b*100*_b+c*_c+d*_d ans2 = c*_c+d*_d print(_a) else: print(ans1, ans2)
s288696508
Accepted
468
3,064
1,062
import sys a,b,c,d,e,f=map(int,input().split()) if a>b: a, b = b, a ans1 = a*100 ans2 = 0 for _a in range(f//(a*100) + 1): for _b in range((f - _a*100)//(b*100) + 1): max_sugar = min(f-(_a+_b)*100, (f-(_a+_b)*100)//100*e) for _c in range(max_sugar//c + 1): for _d in range((max_sugar-c*_c)//d + 1): if a*100*_a+b*100*_b+c*_c+d*_d == 0: continue if a*100*_a+b*100*_b+c*_c+d*_d > f: break if (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) == e/(100+e): print(a*100*_a+b*100*_b+c*_c+d*_d, c*_c+d*_d) sys.exit(0) elif (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) > e/(100+e): continue else: if ans2/ans1 < (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d): ans1 = a*100*_a+b*100*_b+c*_c+d*_d ans2 = c*_c+d*_d else: print(ans1, ans2)
s283435884
p03672
u223904637
2,000
262,144
Wrong Answer
17
3,060
305
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
s=list(input()) def ans(s): n=len(s)//2 f=0 for i in range(n): if s[i]!=s[i+n]: f+=1 break if f==0: return True else: return False s.pop(-1) s.pop(-1) kai=2 while not ans(s): s.pop(-1) s.pop(-1) kai+=2 print(kai)
s944123057
Accepted
17
3,064
310
s=list(input()) h=len(s) def ans(s): n=len(s)//2 f=0 for i in range(n): if s[i]!=s[i+n]: f+=1 break if f==0: return True else: return False s.pop(-1) s.pop(-1) kai=2 while not ans(s): s.pop(-1) s.pop(-1) kai+=2 print(h-kai)
s994600985
p03149
u505547600
2,000
1,048,576
Wrong Answer
18
2,940
120
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
list = input().split() # if 1 in list and 9 in list and 7 in list and 4 in list: print("YES") else: print("NO")
s605732601
Accepted
17
2,940
240
list =input().split() # var=[] for a in list: a = int(a) var.append(a) flg = False if 1 in var: if 9 in var: if 7 in var: if 4 in var: flg = True if flg: print("YES") else: print("NO")
s369845362
p03860
u401183062
2,000
262,144
Wrong Answer
27
8,972
130
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.
def iroha(): string = input() Capital = string[0] print("A" + Capital + "C") if __name__ == "__main__": iroha()
s558269628
Accepted
25
9,072
204
def iroha(): head, string, heel = map(str, input().split()) headC = head[0] Capital = string[0] heelC = heel[0] print(headC + Capital + heelC) if __name__ == "__main__": iroha()
s108551719
p03730
u924182136
2,000
262,144
Wrong Answer
17
2,940
166
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A,B,C = map(int,input().split()) flag = False for i in range(B): tmp = i*A%B if tmp == C: flag = True if flag: print("Yes") else: print("No")
s299967916
Accepted
17
2,940
168
A,B,C = map(int,input().split()) flag = False for i in range(B): tmp = i*A%B if tmp == C: flag = True if flag: print("YES") else: print("NO")
s373176128
p03760
u310381103
2,000
262,144
Wrong Answer
24
9,128
135
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
o=input() e=input() print("".join([o[i]+e[i] for i in range(len(o)-1)]),end="") print(o[-1],end="") if len(o) != len(e): print(e[-1])
s399684453
Accepted
29
9,128
135
o=input() e=input() print("".join([o[i]+e[i] for i in range(len(o)-1)]),end="") print(o[-1],end="") if len(o) == len(e): print(e[-1])
s976515966
p03860
u023077142
2,000
262,144
Wrong Answer
17
2,940
38
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
S = input() print("A{}C".format(S[0]))
s591963558
Accepted
17
2,940
52
_, S, _ = input().split() print("A{}C".format(S[0]))
s656509168
p02744
u007627455
2,000
1,048,576
Wrong Answer
17
2,940
335
In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be **isomorphic** when the following conditions are satisfied: * |s| = |t| holds. * For every pair i, j, one of the following holds: * s_i = s_j and t_i = t_j. * s_i \neq s_j and t_i \neq t_j. For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are not. A string s is said to be in **normal form** when the following condition is satisfied: * For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison. For example, `abcac` is in normal form, but `zyxzx` is not since it is isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`. You are given an integer N. Print all strings of length N that are in normal form, in lexicographically ascending order.
# coding: utf-8 n = int(input()) alphas = "abcdefghij" init_str = "" def standard(moji, x): if len(moji) == n: print(moji) else: for j in range(x): if j == x: standard(moji + alphas[j], i + 1) else: standard(moji + alphas[j], i) standard(init_str, 0)
s031186915
Accepted
121
4,340
451
# coding: utf-8 n = int(input()) alphas = "abcdefghij" init_str = "" def standard(moji, x): if len(moji) == n: print(moji) else: for j in range(x+1): if j == x: # print("j == x") standard(moji + alphas[j], x + 1) else: # print("j != x") standard(moji + alphas[j], x) standard(init_str, 0)
s326081303
p00012
u957840591
1,000
131,072
Wrong Answer
30
7,784
2,477
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain. Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not.
class vector(object): def __init__(self,a,b): self.x=b.x-a.x self.y=b.y-a.y @staticmethod def cross_product(a,b): return a.x*b.y-a.y*b.x class vertex(object): def __init__(self,a): self.x=a[0] self.y=a[1] class circle(object): def __init__(self,p,r): self.px=p.x self.py=p.y self.r=r class triangle(object): def __init__(self,a,b,c): self.a=a self.b=b self.c=c import math self.ab=math.sqrt((self.a.x-self.b.x)**2+(self.a.y-self.b.y)**2) self.bc=math.sqrt((self.b.x-self.c.x)**2+(self.b.y-self.c.y)**2) self.ca=math.sqrt((self.c.x-self.a.x)**2+(self.c.y-self.a.y)**2) c=self.ab a=self.bc b=self.ca self.cosA=(b**2+c**2-a**2)/(2*b*c) self.cosB=(a**2+c**2-b**2)/(2*a*c) self.cosC=(b**2+a**2-c**2)/(2*b*a) self.sinA=math.sqrt(1-self.cosA**2) self.sinB=math.sqrt(1-self.cosB**2) self.sinC=math.sqrt(1-self.cosC**2) self.sin2A=2*self.sinA*self.cosA self.sin2B=2*self.sinB*self.cosB self.sin2C=2*self.sinC*self.cosC def area(self): import math s=(self.ab+self.bc+self.ca)/2 S=math.sqrt(s*(s-self.ab)*(s-self.bc)*(s-self.ca)) return S def circumscribed(self): R=self.ab/(2*self.sinC) px=(self.sin2A*self.a.x+self.sin2B*self.b.x+self.sin2C*self.c.x)/(self.sin2A+self.sin2B+self.sin2C) py=(self.sin2A*self.a.y+self.sin2B*self.b.y+self.sin2C*self.c.y)/(self.sin2A+self.sin2B+self.sin2C) px=round(px,3) py=round(py,3) R=round(R,3) p=vertex((px,py)) return circle(p,R) def isin(self,p): AB=vector(self.a,self.b) BC=vector(self.b,self.c) CA=vector(self.c,self.a) AP=vector(self.a,p) BP=vector(self.b,p) CP=vector(self.c,p) if (vector.cross_product(AB,AP)>0 and vector.cross_product(BC,BP)>0 and vector.cross_product(CA,CP)>0)or(vector.cross_product(AB,AP)<0 and vector.cross_product(BC,BP)<0 and vector.cross_product(CA,CP)<0): return 'Yes' else:return 'No' A=[] B=[] C=[] p=[] import sys for line in sys.stdin: a,b,c,d,e,f,g,h=list(map(float,line.split())) A.append(vertex((a,b))) B.append(vertex((c,d))) C.append(vertex((e,f))) p.append(vertex((g,h))) for i in range(len(A)): Triangle=triangle(A[i],B[i],C[i]) print(Triangle.isin(p[i]))
s732955672
Accepted
30
7,744
2,477
class vector(object): def __init__(self,a,b): self.x=b.x-a.x self.y=b.y-a.y @staticmethod def cross_product(a,b): return a.x*b.y-a.y*b.x class vertex(object): def __init__(self,a): self.x=a[0] self.y=a[1] class circle(object): def __init__(self,p,r): self.px=p.x self.py=p.y self.r=r class triangle(object): def __init__(self,a,b,c): self.a=a self.b=b self.c=c import math self.ab=math.sqrt((self.a.x-self.b.x)**2+(self.a.y-self.b.y)**2) self.bc=math.sqrt((self.b.x-self.c.x)**2+(self.b.y-self.c.y)**2) self.ca=math.sqrt((self.c.x-self.a.x)**2+(self.c.y-self.a.y)**2) c=self.ab a=self.bc b=self.ca self.cosA=(b**2+c**2-a**2)/(2*b*c) self.cosB=(a**2+c**2-b**2)/(2*a*c) self.cosC=(b**2+a**2-c**2)/(2*b*a) self.sinA=math.sqrt(1-self.cosA**2) self.sinB=math.sqrt(1-self.cosB**2) self.sinC=math.sqrt(1-self.cosC**2) self.sin2A=2*self.sinA*self.cosA self.sin2B=2*self.sinB*self.cosB self.sin2C=2*self.sinC*self.cosC def area(self): import math s=(self.ab+self.bc+self.ca)/2 S=math.sqrt(s*(s-self.ab)*(s-self.bc)*(s-self.ca)) return S def circumscribed(self): R=self.ab/(2*self.sinC) px=(self.sin2A*self.a.x+self.sin2B*self.b.x+self.sin2C*self.c.x)/(self.sin2A+self.sin2B+self.sin2C) py=(self.sin2A*self.a.y+self.sin2B*self.b.y+self.sin2C*self.c.y)/(self.sin2A+self.sin2B+self.sin2C) px=round(px,3) py=round(py,3) R=round(R,3) p=vertex((px,py)) return circle(p,R) def isin(self,p): AB=vector(self.a,self.b) BC=vector(self.b,self.c) CA=vector(self.c,self.a) AP=vector(self.a,p) BP=vector(self.b,p) CP=vector(self.c,p) if (vector.cross_product(AB,AP)>0 and vector.cross_product(BC,BP)>0 and vector.cross_product(CA,CP)>0)or(vector.cross_product(AB,AP)<0 and vector.cross_product(BC,BP)<0 and vector.cross_product(CA,CP)<0): return 'YES' else:return 'NO' A=[] B=[] C=[] p=[] import sys for line in sys.stdin: a,b,c,d,e,f,g,h=list(map(float,line.split())) A.append(vertex((a,b))) B.append(vertex((c,d))) C.append(vertex((e,f))) p.append(vertex((g,h))) for i in range(len(A)): Triangle=triangle(A[i],B[i],C[i]) print(Triangle.isin(p[i]))
s277513023
p02936
u591503175
2,000
1,048,576
Wrong Answer
2,115
190,244
1,030
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
N, Q = [int(item) for item in input().split()] tree_list = [input() for _ in range(1,N)] tree_list_int = [list(map(int,i.split())) for i in tree_list] action_list = [input() for _ in range(Q)] action_list_int = [list(map(int, i.split())) for i in action_list] print('tree', tree_list_int) print('act', action_list_int) class Node: def __init__(self, data): self.data = data self.cnt = 0 self.child = [] class tree: def __init__(self, N, tree_list_int): self.node_list = [Node(i) for i in range(1,N+1)] for i, j in tree_list_int: self.node_list[i-1].child.append(self.node_list[j-1]) def adder(self, node, val): node.cnt += val if not node.child: return node.cnt for next_child in node.child: self.adder(next_child, val) ins=tree(N, tree_list_int) for pos, val in action_list_int: ins.adder(ins.node_list[pos-1], val) for i in range(N): print(i+1, ins.node_list[i].cnt)
s473717662
Accepted
1,919
208,132
762
N, Q = [int(item) for item in input().split()] tree_list = [input().split() for j in range(1, N)] query_list = [input().split() for k in range(Q)] query_list_int = [[int(k) for k in i] for i in query_list] val_list = [0 for _ in range(N)] linked_node_list = [[] for _ in range(N)] for a, b in tree_list: a, b = int(a)-1, int(b) -1 linked_node_list[a].append(b) linked_node_list[b].append(a) for index, val in query_list_int: val_list[index-1] += val stack = [0] parent = [0] * (N+1) while True: v=stack.pop() for child in linked_node_list[v]: if child != parent[v]: parent[child] = v stack.append(child) val_list[child] += val_list[v] if not stack: break print(*val_list)
s822364099
p00050
u868716420
1,000
131,072
Wrong Answer
30
7,716
210
福島県は果物の産地としても有名で、その中でも特に桃とりんごは全国でも指折りの生産量を誇っています。ところで、ある販売用の英文パンフレットの印刷原稿を作ったところ、手違いでりんごに関する記述と桃に関する記述を逆に書いてしまいました。 あなたは、apple と peach を修正する仕事を任されましたが、なにぶん面倒です。1行の英文を入力して、そのなかの apple という文字列を全て peach に、peach という文字列を全てapple に交換した英文を出力するプログラムを作成してください。
from collections import deque result = deque() for _ in input().split(): if 'apple' in _ : result.append('peach') elif 'peach' in _ : result.append('apple') else : result.append(_) print(*result)
s851499367
Accepted
30
7,804
379
from collections import deque result = deque() for _ in input().split(): if 'apple' in _ : if _ == 'apple' : result.append('peach') else : result.append(_.replace('apple', 'peach')) elif 'peach' in _ : if _ == 'peach' : result.append('apple') else : result.append(_.replace('peach', 'apple')) else : result.append(_) print(*result)
s794765007
p02646
u180704972
2,000
1,048,576
Wrong Answer
2,206
9,144
295
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
AV = list(map(int,input().split())) BW = list(map(int,input().split())) T = int(input()) A = AV[0] V = AV[1] B = BW[0] W = BW[1] for i in range(T): if A <= B: B += W A += V else: B -= W A -= V if abs(A) >= abs(B): print('Yes') else: print('No')
s224622249
Accepted
23
9,216
396
AV = list(map(int,input().split())) BW = list(map(int,input().split())) T = int(input()) A = AV[0] V = AV[1] B = BW[0] W = BW[1] pos_A = A pos_B = B if A <= B: pos_B = B + T*W pos_A = A + T*V if pos_A >= pos_B: print('YES') else: print('NO') else: pos_B = B - T*W pos_A = A - T*V if pos_A <= pos_B: print('YES') else: print('NO')
s033333439
p03694
u690536347
2,000
262,144
Wrong Answer
17
2,940
52
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along _TopCoDeer street_. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.
l=sorted(map(int,input().split())) print(l[-1]-l[0])
s507346682
Accepted
17
2,940
68
N=int(input()) l=sorted(map(int,input().split())) print(l[-1]-l[0])
s688451157
p02614
u562662744
1,000
1,048,576
Wrong Answer
238
27,244
710
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
import numpy as np import itertools h,w,k=map(int,input().split()) g=np.ones((h,w)) l=['' for _ in range(h)] for i in range(h): l[i]=str(input()) for i in range(h): for j in range(w): if l[i][j]=='.': g[i][j]=0 s=np.sum(g) ans=0 for i in range(h): for j in range(w): u=list(itertools.combinations(range(h),i)) v=list(itertools.combinations(range(w),j)) for x in u: for y in v: a=0 b=0 c=0 for p in x: a+=np.sum(g[p,:]) print(a) for q in y: b+=np.sum(g[:,q]) print(b) for p in x: for q in y: c+=g[p][q] print(s-a-b+c) if s-a-b+c==k: ans+=1 print(ans)
s656623737
Accepted
225
26,984
653
import numpy as np import itertools h,w,k=map(int,input().split()) g=np.ones((h,w)) l=['' for _ in range(h)] for i in range(h): l[i]=str(input()) for i in range(h): for j in range(w): if l[i][j]=='.': g[i][j]=0 s=np.sum(g) ans=0 for i in range(h): for j in range(w): u=list(itertools.combinations(range(h),i)) v=list(itertools.combinations(range(w),j)) for x in u: for y in v: a=0 b=0 c=0 for p in x: a+=np.sum(g[p,:]) for q in y: b+=np.sum(g[:,q]) for p in x: for q in y: c+=g[p][q] if s-a-b+c==k: ans+=1 print(ans)
s277982275
p03478
u881116515
2,000
262,144
Wrong Answer
28
3,060
262
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b = map(int,input().split()) ans = 0 for i in range(2): for j in range(10): for k in range(10): for l in range(10): for m in range(10): if i*10000+j*1000+k*100+l*10+m <= n and a <= i+j+k+l+m <= b: ans += 1 print(ans)
s071081707
Accepted
30
3,060
288
n,a,b = map(int,input().split()) ans = 0 for i in range(2): for j in range(10): for k in range(10): for l in range(10): for m in range(10): if i*10000+j*1000+k*100+l*10+m <= n and a <= i+j+k+l+m <= b: ans += i*10000+j*1000+k*100+l*10+m print(ans)
s865062059
p02578
u304593245
2,000
1,048,576
Wrong Answer
174
32,188
190
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(1,N): tmp = A[i-1] - A[i] if A[i-1] > A[i]: A[i] += tmp ans += tmp print(A) print(ans)
s942886207
Accepted
159
32,372
191
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(1,N): tmp = A[i-1] - A[i] if A[i-1] > A[i]: A[i] += tmp ans += tmp #print(A) print(ans)
s748307212
p03455
u834157170
2,000
262,144
Wrong Answer
17
2,940
87
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')
s711797023
Accepted
17
2,940
88
a, b = map(int, input().split()) if (a*b) % 2 == 0: print('Even') else: print('Odd')
s602427267
p03698
u684305751
2,000
262,144
Wrong Answer
17
2,940
55
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s=input() print("Yes" if len(s)==len(set(s)) else "No")
s888973108
Accepted
17
2,940
55
s=input() print("yes" if len(s)==len(set(s)) else "no")
s082893182
p03998
u278356323
2,000
262,144
Wrong Answer
17
3,064
522
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
#ABC045a import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) a = input()[:-1] b = input()[:-1] c = input()[:-1] nextPerson = "a" while (True): if (nextPerson == "a"): if (len(a) == 1): break nextPerson = a[0] a = a[1:] elif (nextPerson == "b"): if (len(b) == 1): break nextPerson = b[0] b = b[1:] else: if (len(c) == 1): break nextPerson = "c" c = c[1:] print(nextPerson.capitalize())
s521763637
Accepted
17
3,064
580
#ABC045a import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) a = input()[:-1] b = input()[:-1] c = input()[:-1] aa = 0 bb = 0 cc = 0 nextPerson = "a" while (True): #print(nextPerson) if (nextPerson == "a"): if (len(a) - aa == 0): break nextPerson = a[aa] aa += 1 elif (nextPerson == "b"): if (len(b) - bb == 0): break nextPerson = b[bb] bb += 1 else: if (len(c) - cc == 0): break nextPerson = c[cc] cc += 1 print(nextPerson.capitalize())
s022447860
p03369
u226779434
2,000
262,144
Wrong Answer
24
9,024
43
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
s = input() print(700 + s.count("○")*100)
s267103814
Accepted
27
8,984
41
s = input() print(700 + s.count("o")*100)
s761461202
p03486
u595375942
2,000
262,144
Wrong Answer
18
2,940
145
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = input() t = input() ss = ''.join(sorted(s)) tt = ''.join(sorted(t, reverse=True)) if ss > tt: ans = 'Yes' else: ans = 'No' print(ans)
s264594899
Accepted
18
2,940
129
S = ''.join(sorted(list(input()))) T = ''.join(reversed(sorted(list(input())))) if S < T: print('Yes') else: print('No')
s573553173
p03477
u494748969
2,000
262,144
Wrong Answer
17
3,064
150
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a, b, c, d = list(map(int, input().split())) if a + b > c + d: print("left") elif a + b == c + d: print("Balanced") else: print("Right")
s093269424
Accepted
17
2,940
150
a, b, c, d = list(map(int, input().split())) if a + b > c + d: print("Left") elif a + b == c + d: print("Balanced") else: print("Right")
s653002147
p03854
u588526762
2,000
262,144
Wrong Answer
72
3,188
226
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
s = input() while 1: for x in ('dream', 'dreamer', 'erase', 'eraser'): if s.endswith(x): s = s[:-len(x)] break else: print('NO') break if not s: print('YES')
s271078865
Accepted
71
3,316
240
s = input() while 1: for x in ('dream', 'dreamer', 'erase', 'eraser'): if s.endswith(x): s = s[:-len(x)] break else: print('NO') break if not s: print('YES') break
s356393071
p03997
u432805419
2,000
262,144
Wrong Answer
17
2,940
62
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = [int(input()) for i in range(3)] print((a[0]+a[1])*a[2]/2)
s964037557
Accepted
18
2,940
67
a = [int(input()) for _ in range(3)] print(int((a[0]+a[1])*a[2]/2))
s909905497
p04043
u457901067
2,000
262,144
Wrong Answer
16
2,940
84
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
X = list(map(int, input().split())).sort() print("YES" if X == [5, 5, 7] else "NO")
s800731055
Accepted
17
2,940
85
X = sorted(list(map(int, input().split()))) print("YES" if X == [5, 5, 7] else "NO")
s746391181
p02411
u777299405
1,000
131,072
Wrong Answer
40
6,724
435
Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
while True: m, f, r = map(int, (input().split())) score = m + f if m == f == r == -1: break else: if m == -1 or f == -1: print("F") elif score >= 80: print("A") elif 80 > score >= 65: print("B") elif 65 > score >= 50: print("C") elif 50 > score >= 35 and r >= 50: print("C") else: print("D")
s090028462
Accepted
30
6,724
500
while True: m, f, r = map(int, (input().split())) score = m + f if m == f == r == -1: break else: if m == -1 or f == -1: print("F") elif score >= 80: print("A") elif 80 > score >= 65: print("B") elif 65 > score >= 50: print("C") elif 50 > score >= 30 and r >= 50: print("C") elif 50 > score >= 30 and r < 50: print("D") else: print("F")
s352624787
p02669
u189479417
2,000
1,048,576
Wrong Answer
441
14,016
1,201
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.**
def solve(N, A, B, C, D): d = {0:0, 1:D} s = set() return dfs(N, A, B, C, D, d, s) def dfs(n, A, B, C, D, d, s): if n in d: return d[n] if n in s: return float('inf') s.add(n) ans = float('inf') p = n % 2 if p == 0: ans = min(ans, dfs(n // 2, A, B, C, D, d, s) + A) else: ans = min(ans, dfs((n - p) // 2, A, B, C, D, d, s) + A + D * p) ans = min(ans, dfs((n + (2 - p)) // 2, A, B, C, D, d, s) + A + D * (2 - p)) q = n % 3 if q == 0: ans = min(ans, dfs(n // 3, A, B, C, D, d, s) + B) else: ans = min(ans, dfs((n - q) // 3, A, B, C, D, d, s) + B + D * q) ans = min(ans, dfs(n + (3 - q), A, B, C, D, d, s) + B + D * (3 - q)) r = n % 5 if r == 0: ans = min(ans, dfs(n // 5, A, B, C, D, d, s) + C) else: ans = min(ans, dfs((n - r) // 5, A, B, C, D, d, s) + C + D * r) ans = min(ans, dfs((n + (5 - r)) // 5, A, B, C, D, d, s) + C + D * (5 - r)) ans = min(ans, D * n) d[n] = ans return ans T = int(input()) for _ in range(T): N, A, B, C, D = map(int,input().split()) ans = solve(N, A, B, C, D) print(ans)
s783722762
Accepted
315
11,712
1,208
def solve(N, A, B, C, D): d = {0:0, 1:D} s = set() return dfs(N, A, B, C, D, d, s) def dfs(n, A, B, C, D, d, s): if n in d: return d[n] if n in s: return float('inf') s.add(n) ans = float('inf') p = n % 2 if p == 0: ans = min(ans, dfs(n // 2, A, B, C, D, d, s) + A) else: ans = min(ans, dfs((n - p) // 2, A, B, C, D, d, s) + A + D * p) ans = min(ans, dfs((n + (2 - p)) // 2, A, B, C, D, d, s) + A + D * (2 - p)) q = n % 3 if q == 0: ans = min(ans, dfs(n // 3, A, B, C, D, d, s) + B) else: ans = min(ans, dfs((n - q) // 3, A, B, C, D, d, s) + B + D * q) ans = min(ans, dfs((n + (3 - q)) // 3, A, B, C, D, d, s) + B + D * (3 - q)) r = n % 5 if r == 0: ans = min(ans, dfs(n // 5, A, B, C, D, d, s) + C) else: ans = min(ans, dfs((n - r) // 5, A, B, C, D, d, s) + C + D * r) ans = min(ans, dfs((n + (5 - r)) // 5, A, B, C, D, d, s) + C + D * (5 - r)) ans = min(ans, D * n) d[n] = ans return ans T = int(input()) for _ in range(T): N, A, B, C, D = map(int,input().split()) ans = solve(N, A, B, C, D) print(ans)
s484070762
p02694
u373703188
2,000
1,048,576
Wrong Answer
22
9,012
590
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()) cnt = 0 answer = 100 # fv = 100 (1 + 1) # x = x / 100 # print(math.log(2, x)) # # ans += 100 * 0.01 # if x <= ans: # break # print(answer) while answer <= x: cnt += 1 answer += answer // 100 print(cnt)
s980863784
Accepted
20
9,168
679
# import math x = int(input()) cnt = 0 answer = 100 # fv = 100 (1 + 1) # x = x / 100 # print(math.log(2, x)) # # ans += 100 * 0.01 # if x <= ans: # break # print(answer) while answer < x: cnt += 1 answer += answer // 100 # print(answer) # print(x) print(cnt)
s448280371
p03609
u617010143
2,000
262,144
Wrong Answer
17
2,940
134
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
s = input() hoge =list(s) moji = '' for num in range(len(s)): if num%2 == 0: moji += hoge[num] continue print(moji)
s999635759
Accepted
17
2,940
74
X,t =map(int,input().split()) if X >= t: print(X-t) else: print(0)
s798556006
p03067
u864650257
2,000
1,048,576
Wrong Answer
17
2,940
119
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
A,B,C = map (int,input().split()) if A < C < B: print("YES") elif A > C > B: print("YES") else: print("NO")
s906704671
Accepted
17
2,940
119
A,B,C = map (int,input().split()) if A < C < B: print("Yes") elif A > C > B: print("Yes") else: print("No")
s501030841
p03636
u750651325
2,000
262,144
Wrong Answer
17
2,940
46
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.
S = input() l = len(S)-2 print(S[0]+"l"+S[-1])
s595418048
Accepted
17
2,940
49
S = input() l = str(len(S)-2) print(S[0]+l+S[-1])
s897538989
p03068
u254745082
2,000
1,048,576
Wrong Answer
17
3,064
224
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()) str_list = list(s) x = str_list[k-1] print(n,s,k,x) for i in range(len(s)): if str_list[i] != x: str_list[i] = "*" str_changed = "".join(str_list) print(str_changed)
s221606455
Accepted
18
3,060
209
n = int(input()) s = input() k = int(input()) str_list = list(s) x = str_list[k-1] for i in range(len(s)): if str_list[i] != x: str_list[i] = "*" str_changed = "".join(str_list) print(str_changed)
s867253601
p02239
u255317651
1,000
131,072
Wrong Answer
30
5,624
752
Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
# -*- coding: utf-8 -*- """ Created on Sun Jul 8 10:56:33 2018 @author: maezawa """ n = int(input()) adj = [[] for _ in range(n)] d = [-1 for _ in range(n)] d[0] = 0 for j in range(n): ain = list(map(int, input().split())) u = ain[0] k = ain[1] for i in range(k): adj[u-1].append(ain[i+2]-1) adj[u-1].sort() #print(*adj[u-1]) stack = [0] while stack: print(stack) current = stack[-1] flag = 0 for k in adj[current]: if d[k] <= 0: d[k] = d[current]+1 stack.append(k) flag = 1 if flag == 0: stack.pop() #print('current = {}, t = {}'.format(current, t)) #print('stack', *stack) for i in range(n): print('{} {}'.format(i+1, d[i]))
s603417613
Accepted
20
5,632
867
# -*- coding: utf-8 -*- """ Created on Sun Jul 8 10:56:33 2018 @author: maezawa """ n = int(input()) adj = [[] for _ in range(n)] d = [-1 for _ in range(n)] d[0] = 0 for j in range(n): ain = list(map(int, input().split())) u = ain[0] k = ain[1] for i in range(k): adj[u-1].append(ain[i+2]-1) adj[u-1].sort() #print(*adj[u-1]) stack = [0] while stack: #print(stack) current = stack[-1] flag = 0 for k in adj[current]: if d[k] < 0: d[k] = d[current]+1 stack.append(k) flag = 1 elif d[k] > d[current]+1: d[k] = d[current]+1 stack.append(k) flag = 1 if flag == 0: stack.pop() #print('current = {}, t = {}'.format(current, t)) #print('stack', *stack) for i in range(n): print('{} {}'.format(i+1, d[i]))
s737619085
p02748
u690184681
2,000
1,048,576
Wrong Answer
506
39,340
335
You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
A,B,M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) discount = [] for i in [0]*M: discount.append(list(map(int,input().split()))) min_comb = min(a)+min(b) for i in range(M): min_comb = min(min_comb,a[discount[i][0]-1]+b[discount[i][1]-1]-discount[i][2]) ans = 0 print(ans)
s203860012
Accepted
521
39,268
342
A,B,M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) discount = [] for i in [0]*M: discount.append(list(map(int,input().split()))) min_comb = min(a)+min(b) for i in range(M): min_comb = min(min_comb,a[discount[i][0]-1]+b[discount[i][1]-1]-discount[i][2]) ans = min_comb print(ans)
s210762201
p03369
u247211039
2,000
262,144
Wrong Answer
17
2,940
41
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
S = input() print(700 + S.count("o")*300)
s640928612
Accepted
17
2,940
41
S = input() print(700 + S.count("o")*100)
s611510042
p03456
u320098990
2,000
262,144
Wrong Answer
27
9,184
189
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 input_list = input().split(' ') a = input_list[0] b = input_list[1] N = math.sqrt(int(a+b)) print(a+b) print(N) if isinstance(N, float): print('Yes') else: print('No')
s683397888
Accepted
25
9,092
165
import math input_list = input().split(' ') a = input_list[0] b = input_list[1] N = math.sqrt(int(a+b)) if N.is_integer(): print('Yes') else: print('No')
s213681292
p03433
u280552586
2,000
262,144
Wrong Answer
17
2,940
91
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input()) a = int(input()) if n % 500 <= a: print('YES') else: print('NO')
s561362923
Accepted
17
3,064
79
n, a = [int(input()) for _ in range(2)] print('Yes' if n % 500 <= a else 'No')
s617429148
p03657
u841153348
2,000
262,144
Wrong Answer
17
2,940
300
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.
def yagi(cookie_1,cookie_2): if cookie_1 % 3 == 0: return "possible" elif cookie_2 % 3 == 0: return "possible" elif cookie_1 + cookie_2 % 3 == 0: return "possible" else: return "impossible" cookie = (input()) unti = cookie.split() print(yagi(int(unti[0]),int(unti[1])))
s332081942
Accepted
18
2,940
272
cookie = (input()) unti = cookie.split() cookie_1 = int(unti[0]) cookie_2 = int(unti[1]) if cookie_1 % 3 == 0: print( "Possible") elif cookie_2 % 3 == 0: print( "Possible") elif ((cookie_1 + cookie_2) % 3 == 0): print( "Possible") else : print( "Impossible")
s009154663
p03997
u387456967
2,000
262,144
Wrong Answer
17
2,940
67
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a,b,h = [int(input()) for i in range(3)] ans = (a+b)*h/2 print(ans)
s230689261
Accepted
17
2,940
72
a,b,h = [int(input()) for i in range(3)] ans = int((a+b)*h/2) print(ans)
s875333981
p00135
u032662562
1,000
131,072
Wrong Answer
40
7,644
386
原始スローライフ主義組織「アカルイダ」から、いたずらの予告状が届きました。アカルイダといえば、要人の顔面にパイを投げつけたりするいたずらで有名ですが、最近では火薬を用いてレセプション会場にネズミ花火をまき散らすなど、より過激化してきました。予告状は次の文面です。 ---パソコン ヒトの時間を奪う。良くない。 時計の短い針と長い針 出会うころ、アカルイダ 正義行う。 スローライフ 偉大なり。 たどたどしくてよく解らないのですが、時計の短針と長針とが重なったころにいたずらを決行するという意味のようです。 このいたずらを警戒するため、時刻を入力として、短針と長針が近い場合は "alert"、遠い場合は "safe"、それ以外の場合は "warning" と出力するプログラムを作成してください。ただし、「近い」とは短針と長針の角度が 0° 以上 30° 未満の場合をいい、「遠い」とは 90° 以上 180° 以下の場合をいいます。なお、時刻は 00:00 以上 11:59 以下とします。
def solve(h,m): dm = m / 60.0 * 360.0 dh = h / 12.0 * 360.0 + 360.0/ 12.0 * m / 60.0 print(dh, dm) if 0 <= abs(dh-dm) < 30.0: return("alert") elif 90.0 <= abs(dh-dm) < 180.0: return("safe") else: return("warning") n = int(input().strip()) for i in range(n): v = list(map(int, input().strip().split(':'))) print(solve(v[0],v[1]))
s729476031
Accepted
40
7,628
406
def solve(h,m): dh = h / 12.0 * 360.0 + 360.0/ 12.0 * m / 60.0 dm = m / 60.0 * 360.0 x = abs(dh-dm) if x > 180: x = 360 - x if 0 <= x < 30.0: return("alert") elif 90.0 <= x <= 180.0: return("safe") else: return("warning") n = int(input().strip()) for i in range(n): v = list(map(int, input().strip().split(':'))) print(solve(v[0],v[1]))
s166179612
p02748
u371409687
2,000
1,048,576
Wrong Answer
419
18,608
224
You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
a,b,m=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) ans=min(A)+min(B) for i in range(m): x,y,c=map(int,input().split()) tmp=A[x-1]+B[y-1]+c ans=min(ans,tmp) print(ans)
s780526058
Accepted
417
18,608
224
a,b,m=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) ans=min(A)+min(B) for i in range(m): x,y,c=map(int,input().split()) tmp=A[x-1]+B[y-1]-c ans=min(ans,tmp) print(ans)
s505936604
p03779
u145600939
2,000
262,144
Wrong Answer
30
2,940
64
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
x = int(input()) i = 0 while i*(i-1)//2 < x: i += 1 print(i)
s713496410
Accepted
31
2,940
64
x = int(input()) i = 0 while i*(i+1)//2 < x: i += 1 print(i)
s616666751
p02846
u918714262
2,000
1,048,576
Wrong Answer
17
3,064
404
Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows **towards the east** : * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. * Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact.
t1, t2 = map(int, input().split()) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) a1 -= b1 a2 -= b2 if a1*t1+a2*t2 == 0: print("infinity") quit() if a1 < 0: a1 = -a1 a2 = -a2 if a2 > 0: print(0) quit() d = a1*t1+a2*t2 if d > 0: print(0) quit() print(a1*t1, -d) ans = ((a1*t1-1)//(-d)+1)*2-1 if a1*t1%(-d) == 0: ans += 1 print(ans)
s167453708
Accepted
17
3,064
386
t1, t2 = map(int, input().split()) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) a1 -= b1 a2 -= b2 if a1*t1+a2*t2 == 0: print("infinity") quit() if a1 < 0: a1 = -a1 a2 = -a2 if a2 > 0: print(0) quit() d = a1*t1+a2*t2 if d > 0: print(0) quit() ans = ((a1*t1-1)//(-d)+1)*2-1 if a1*t1%(-d) == 0: ans += 1 print(ans)
s273088685
p03024
u826557401
2,000
1,048,576
Wrong Answer
17
2,940
78
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.
s = str(input()) if s.count('x') >= 8: print("No") else: print("Yes")
s551667460
Accepted
17
2,940
78
s = str(input()) if s.count('x') >= 8: print("NO") else: print("YES")
s989496552
p02841
u539805724
2,000
1,048,576
Wrong Answer
17
2,940
220
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.
def main(): M = [] D = [] for i in range(2): m, d = [int(i) for i in input().split()] M.append(m) D.append(d) if (M[0] != M[1]): print(0) else: print(1) if __name__ == "__main__": main()
s667705009
Accepted
17
3,060
191
def main(): M = [] D = [] for i in range(2): m, d = [int(i) for i in input().split()] M.append(m) D.append(d) if (M[0] != M[1]): print(1) else: print(0) main()
s948579143
p03150
u854685063
2,000
1,048,576
Wrong Answer
28
9,016
688
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 import math import itertools as it def I():return int(sys.stdin.readline().replace("\n","")) def I2():return map(int,sys.stdin.readline().replace("\n","").split()) def S():return str(sys.stdin.readline().replace("\n","")) def L():return list(sys.stdin.readline().replace("\n","")) def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()] def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split())) if __name__ == "__main__": s = S() cnt = 0 tgt = "keyence" for i in range(len(tgt)): a,b = tgt[:i],tgt[i:] if a in s and b in s: print("Yes") exit() print("No")
s712379482
Accepted
26
9,068
663
import sys import math import itertools as it def I():return int(sys.stdin.readline().replace("\n","")) def I2():return map(int,sys.stdin.readline().replace("\n","").split()) def S():return str(sys.stdin.readline().replace("\n","")) def L():return list(sys.stdin.readline().replace("\n","")) def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()] def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split())) if __name__ == "__main__": s = S() cnt = 0 tgt = "keyence" for i in range(8): if s[:i] + s[len(s)-7+i:] == tgt: print("YES") exit() print("NO")
s900811798
p03472
u454760747
2,000
262,144
Wrong Answer
1,202
23,216
884
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()) alist = [] blist = [] for i in range(N): A, B = map(int, input().split()) alist.append(A) blist.append(B) maxa = max(alist) blist = list(filter(lambda el: el > maxa, blist)) def mergesort(l): def merge(left, right): result = [] while left and right: if left[0] <= right[0]: result.append(left.pop(0)) else: result.append(right.pop(0)) return result + left + right length = len(l) if length <= 1: return l middle = length // 2 return merge(mergesort(l[:middle]), mergesort(l[middle:])) blist = mergesort(blist) blist.reverse() sum_for_h = 0 ans = 0 for i in blist: sum_for_h += i ans += 1 if sum_for_h >= H: print(ans , flush=True) exit() anum = (H-sum_for_h) // maxa print(ans + anum, flush=True)
s407873069
Accepted
1,179
22,244
919
N, H = map(int, input().split()) alist = [] blist = [] for i in range(N): A, B = map(int, input().split()) alist.append(A) blist.append(B) maxa = max(alist) blist = list(filter(lambda el: el > maxa, blist)) def mergesort(l): def merge(left, right): result = [] while left and right: if left[0] <= right[0]: result.append(left.pop(0)) else: result.append(right.pop(0)) return result + left + right length = len(l) if length <= 1: return l middle = length // 2 return merge(mergesort(l[:middle]), mergesort(l[middle:])) blist = mergesort(blist) blist.reverse() sum_for_h = 0 ans = 0 for i in blist: sum_for_h += i ans += 1 if sum_for_h >= H: print(ans , flush=True) exit() anum = (H-sum_for_h) / maxa import math anum = math.ceil(anum) print(ans + anum, flush=True)
s845440753
p02388
u040556632
1,000
131,072
Wrong Answer
20
7,320
14
Write a program which calculates the cube of a given integer x.
print(input())
s125914556
Accepted
30
7,580
34
x = int(input()) x = x**3 print(x)
s823521628
p02390
u527389300
1,000
131,072
Wrong Answer
20
5,608
137
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
s = int(input()) temp = s % 60 m = (s - temp) / 60 temp = m % 60 h = (m - temp) / 60 print(str(h) + ':' + str(m) + ':' + str(s))
s981398719
Accepted
20
5,588
163
time = int(input()) h = time - (time % 3600) time = time - h m = time - (time % 60) s = time - m print(str(int(h / 3600))+':'+str(int(m / 60))+':'+str(s))
s236186552
p02972
u278864208
2,000
1,048,576
Wrong Answer
478
18,852
242
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.
#D N = int(input()) box = [0] * N for i in range(N-1, 0, -1): aisum = 0 for j in range(i, N, i): aisum += box[j] if aisum%2 == 0: box[i] = 1 else: box[i] = 0 print(' '.join(map(str, box[::-1])))
s701910568
Accepted
611
19,856
366
#D N = int(input()) a = list(map(int,input().split())) box = [0] * N result = [] for i in range(N-1, -1, -1): aisum = 0 for j in range(i, N, i+1): aisum += box[j] if aisum%2 != a[i]%2: box[i] = 1 result.append(i+1) else: box[i] = 0 print(len(result)) if len(result) != 0: print(' '.join(map(str, result)))
s940301763
p03623
u752552310
2,000
262,144
Wrong Answer
17
2,940
91
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x, a, b = map(int, input().split()) if abs(x-a) > abs(x-b): print('A') else: print('B')
s581326484
Accepted
17
2,940
91
x, a, b = map(int, input().split()) if abs(x-a) > abs(x-b): print('B') else: print('A')
s609845812
p03693
u982594421
2,000
262,144
Wrong Answer
17
2,940
89
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) if g * b % 4 == 0: print('YES') else: print('NO')
s104405679
Accepted
19
2,940
96
r, g, b = map(int, input().split()) if (g * 10 + b) % 4 == 0: print('YES') else: print('NO')
s829765549
p02697
u945228737
2,000
1,048,576
Wrong Answer
72
9,276
145
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.
def solve(): N, M = map(int, input().split()) for i in range(M): print(i + 1, N - i) if __name__ == '__main__': solve()
s113569289
Accepted
75
9,232
449
def solve(): N, M = map(int, input().split()) m = 0 oddN = M oddN += (oddN + 1) % 2 for i in range(oddN // 2): print(i + 1, oddN - i) m += 1 if m == M: return for i in range(M): print(oddN + i + 1, M * 2 + 1 - i) m += 1 if m == M: return if __name__ == '__main__': solve()
s140659710
p03047
u801512570
2,000
1,048,576
Wrong Answer
18
3,064
67
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(sum([i for i in range(1,N+1)]))
s583063684
Accepted
17
2,940
44
N,K=map(int,input().split()) print(N-(K-1))
s893473076
p03469
u347600233
2,000
262,144
Wrong Answer
17
2,940
33
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
s = input() print('2017' + s[4:])
s442861466
Accepted
17
2,940
33
s = input() print('2018' + s[4:])
s547493816
p03713
u557494880
2,000
262,144
Wrong Answer
328
3,064
349
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
W,H = map(int,input().split()) ans = 10**100 for i in range(1,W): a = H*i w = W - i b = min((w//2)*H,w*(H//2)) c = w*H - b x = max(a,b,c) - min(a,b,c) ans = min(ans,x) for i in range(1,H): a = W*i h = H - i b = min((W//2)*h,W*(h//2)) c = h*W - b x = max(a,b,c) - min(a,b,c) ans = min(ans,x) print(ans)
s738827403
Accepted
324
3,064
349
W,H = map(int,input().split()) ans = 10**30 for i in range(1,W): a = H*i w = W - i b = max((w//2)*H,w*(H//2)) c = w*H - b x = max(a,b,c) - min(a,b,c) ans = min(ans,x) for i in range(1,H): a = W*i h = H - i b = max((W//2)*h,W*(h//2)) c = h*W - b x = max(a,b,c) - min(a,b,c) ans = min(ans,x) print(ans)
s215446545
p03992
u374802266
2,000
262,144
Wrong Answer
17
2,940
113
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
a=input() for i in range(4): print(a[i],end='') print(' ',end='') for i in range(8): print(a[i+4],end='')
s290482999
Accepted
31
8,940
28
s=input() print(s[:4],s[4:])
s943499674
p04029
u989326345
2,000
262,144
Wrong Answer
17
2,940
42
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)
s450609312
Accepted
17
2,940
43
N=int(input()) ans=(N*(N+1))//2 print(ans)
s072656772
p02262
u630566146
6,000
131,072
Wrong Answer
20
5,616
882
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
def insertion_sort(l, g): cnt = 0 for i in range(g, len(l)): tmp = l[i] j = i - g while j >= 0 and l[j] > tmp: l[j+g] = l[j] cnt += 1 j -= g l[j+g] = tmp return l, cnt def shell_sort(l, lg): tot = 0 for g in lg: sl, cnt = insertion_sort(l, g) tot += cnt return sl, tot if __name__ == '__main__': N = int(input()) l = [] for _ in range(N): l.append(int(input())) #l = list(map(int, input().split())) #sl = insertion_sort(l, 1) #lg = [4, 1] lg = [int(1/2*(3**(i+1)-1)) for i in range((N//3 + 1), -1, -1)] print(len(lg)) print(' '.join(map(str, lg))) sl, tot = shell_sort(l, lg) print(tot) #print(' '.join(map(str, sl))) for e in sl: print(e)
s408084529
Accepted
19,330
45,504
767
def insertion_sort(l, g): cnt = 0 for i in range(g, len(l)): tmp = l[i] j = i - g while j >= 0 and l[j] > tmp: l[j+g] = l[j] cnt += 1 j -= g l[j+g] = tmp return l, cnt def shell_sort(l, lg): tot = 0 for g in lg: sl, cnt = insertion_sort(l, g) tot += cnt return sl, tot if __name__ == '__main__': N = int(input()) l = [] for _ in range(N): l.append(int(input())) lg = [1] while True: gc = 3 * lg[-1] + 1 if gc > N: break lg.append(gc) lg = lg[::-1] print(len(lg)) print(' '.join(map(str, lg))) sl, tot = shell_sort(l, lg) print(tot) for e in sl: print(e)
s146228229
p02406
u261533743
1,000
131,072
Wrong Answer
20
7,720
121
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
N = int(input()) result = ' '.join([str(c) for c in range(1, N + 1) if c == 3 or '3' in str(c)]) print(' ' + result)
s896282108
Accepted
20
7,772
116
N = int(input()) print(' {}'.format(' '.join([str(c) for c in range(1, N + 1) if c % 3 == 0 or '3' in str(c)])))
s192838173
p04043
u039002256
2,000
262,144
Wrong Answer
22
8,968
212
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
l = list(map(int, input().split())) flag_5 = flag_7 = 0 for i in l: if i == 5: flag_5 += 1 if i == 7: flag_7 += 1 if flag_5 == 2 and flag_7 == 1: print("Yes") else: print("No")
s763732082
Accepted
28
8,964
212
l = list(map(int, input().split())) flag_5 = flag_7 = 0 for i in l: if i == 5: flag_5 += 1 if i == 7: flag_7 += 1 if flag_5 == 2 and flag_7 == 1: print("YES") else: print("NO")
s456224943
p04029
u263824932
2,000
262,144
Wrong Answer
17
2,940
303
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?
S=input() words=[a for a in S] answers=[] for n in words: if n=='1': answers.append('1') elif n=='0': answers.append('0') else: if not answers: continue else: answers.pop() mojiretu='' for x in answers: mojiretu+=x print(mojiretu)
s037828491
Accepted
17
2,940
70
N=int(input()) C=[] for n in range(N+1): C.append(n) print(sum(C))
s041749251
p03944
u530786533
2,000
262,144
Wrong Answer
18
3,060
299
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()) p, q, r, s = 0, 0, w, h for i in range(n): x, y, a = map(int, input().split()) if (a == 1): p = x elif (a == 2): r = x elif (a == 3): q = y else: s = y if (r - p < 0): r = p if (s - q < 0): s = q print(r - p, s - q)
s504490158
Accepted
18
3,064
389
w, h, n = map(int, input().split()) p, q, r, s = 0, 0, w, h for i in range(n): x, y, a = map(int, input().split()) if (a == 1): if (x > p): p = x elif (a == 2): if (x < r): r = x elif (a == 3): if (y > q): q = y else: if (y < s): s = y if (r < p or s < q): print(0) else: print((r - p)* (s - q))
s555736482
p04029
u461954362
2,000
262,144
Wrong Answer
40
3,064
63
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?
#!/usr/bin/env python N = int(input()) print(N * (N + 1) / 2)
s479802725
Accepted
38
3,064
64
#!/usr/bin/env python N = int(input()) print(N * (N + 1) // 2)
s800605725
p02612
u731362892
2,000
1,048,576
Wrong Answer
28
9,148
50
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()) while n<=0: n-=1000 print(abs(n))
s347276810
Accepted
28
9,152
49
n=int(input()) while n>0: n-=1000 print(abs(n))
s431086340
p03549
u333945892
2,000
262,144
Wrong Answer
29
4,212
332
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).
from collections import defaultdict import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inpl(): return list(map(int, input().split())) def inpl_s(): return list(input().split()) N,M = inpl() T = (N-M)*100 + 1900*M print(T) k = 2**M print(k*T)
s831234825
Accepted
29
4,204
323
from collections import defaultdict import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inpl(): return list(map(int, input().split())) def inpl_s(): return list(input().split()) N,M = inpl() T = (N-M)*100 + 1900*M k = 2**M print(k*T)
s718850549
p02694
u434609232
2,000
1,048,576
Wrong Answer
26
9,164
107
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()) money = 100 year = 0 while money <= X: money += money // 100 year += 1 print(year)
s012041762
Accepted
27
9,100
106
X = int(input()) money = 100 year = 0 while money < X: money += money // 100 year += 1 print(year)
s880205653
p02422
u957840591
1,000
131,072
Wrong Answer
30
7,680
615
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
str=input() q=eval(input()) command=[] replace=[] numdata=[] for i in range(q): x=input() if 'replace' in x: a,b,c,d=x.split() replace.append(d) numdata.append((int(b),int(c))) else: a,b,c=x.split() numdata.append((int(b),int(c))) command.append(a) Re=iter(replace) for i in range(q): if command[i]=='print': print(str[numdata[i][0]:numdata[i][1]+1]) elif command[i]=='reverse': str=str[:numdata[i][0]]+str[numdata[i][1]:numdata[i][0]-1:-1]+str[numdata[i][1]+1:] else: str=str[:numdata[i][0]]+next(Re)+str[numdata[i][1]+1:]
s958571872
Accepted
30
7,708
636
str=input() q=eval(input()) command=[] replace=[] numdata=[] for i in range(q): x=input() if 'replace' in x: a,b,c,d=x.split() replace.append(d) numdata.append((int(b),int(c))) else: a,b,c=x.split() numdata.append((int(b),int(c))) command.append(a) Re=iter(replace) for i in range(q): if command[i]=='print': print(str[numdata[i][0]:numdata[i][1]+1]) elif command[i]=='reverse': temp=str[numdata[i][0]:numdata[i][1]+1] str=str[:numdata[i][0]]+temp[::-1]+str[numdata[i][1]+1:] else: str=str[:numdata[i][0]]+next(Re)+str[numdata[i][1]+1:]
s796173869
p03401
u806855121
2,000
262,144
Wrong Answer
194
14,048
420
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
N = int(input()) A = list(map(int, input().split())) s = 0 p = 0 for i in range(N): s += abs(p - A[i]) p = A[i] if p != 0: s += abs(p) A.append(0) A.insert(0, 0) for i in range(1, N+1): if A[i] < 0: if A[i] < A[i+1]: print(s - abs(A[i-1] - A[i])*2) continue else: if A[i] > A[i+1]: print(s - abs(A[i-1]-A[i])*2) continue print(s)
s155100734
Accepted
1,346
13,536
262
from collections import deque N = int(input()) A = deque(map(int, input().split())) A.appendleft(0) A.append(0) S = 0 for i in range(1, N+2): S += abs(A[i-1] - A[i]) for i in range(1, N+1): print(S+abs(A[i-1]-A[i+1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1])))
s125906715
p03827
u324549724
2,000
262,144
Wrong Answer
18
2,940
134
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
a = input() maxi = 0 now = 0 for c in a: if c == 'I': now += 1 else: now -= 1 if now > maxi: maxi = now print(maxi)
s801676084
Accepted
17
2,940
134
input() a = input() maxi = 0 now = 0 for c in a: if c == 'I': now += 1 else: now -= 1 maxi = max(now, maxi) print(maxi)
s377827443
p02612
u220560107
2,000
1,048,576
Wrong Answer
32
9,148
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(1000-N)
s366845115
Accepted
28
9,120
40
N=int(input()) print((1000-N%1000)%1000)
s009034441
p03369
u737508101
2,000
262,144
Wrong Answer
17
2,940
38
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
s = input() print(s.count("o") * 100)
s159366523
Accepted
17
2,940
43
s = input() print(s.count("o") * 100 + 700)
s001705377
p04012
u594956556
2,000
262,144
Wrong Answer
18
3,060
172
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
w = input() cdict = {} for c in w: if c in cdict: cdict[c] += 1 else: cdict[c] = 0 if all(cdict[c]%2==0 for c in cdict): print('Yes') else: print('No')
s979712926
Accepted
17
2,940
173
w = input() cdict = {} for c in w: if c in cdict: cdict[c] += 1 else: cdict[c] = 1 if all(cdict[c]%2==0 for c in cdict): print('Yes') else: print('No')
s531864276
p03044
u652057333
2,000
1,048,576
Wrong Answer
2,104
16,432
959
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
n = int(input()) u = [0] * (n-1) v = [0] * (n-1) w = [0] * (n-1) node = [i for i in range(n)] group1 = [] group2 = [] for i in range(n-1): u[i], v[i], w[i] = map(int, input().split()) u[i] -= 1 v[i] -= 1 w[i] = w[i] % 2 if w[i] == 0: if node[u[i]] == u[i]: node[u[i]] = node[v[i]] elif node[u[i]] != u[i]: node[v[i]] = node[u[i]] for i in range(n-1): if w[i] == 1: if u[i] in group1: group2.append(node[v[i]]) elif u[i] in group2: group1.append(node[v[i]]) elif v[i] in group1: group2.append(node[u[i]]) elif v[i] in group2: group1.append(node[u[i]]) else: group1.append(node[v[i]]) group2.append(node[u[i]]) for i in range(n): if node[i] in group1: node[i] = 0 else: node[i] = 1 for color in node: print(color)
s488447670
Accepted
1,304
51,348
480
import queue n = int(input()) links = [set() for _ in [0] * n] for i in range(n-1): u, v, w = map(int, input().split()) u -= 1 v -= 1 links[u].add((v, w)) links[v].add((u, w)) ans = [-1] * n q = queue.Queue() q.put((0, 0, -1)) while not q.empty(): v, d, p = q.get() if d % 2 == 0: ans[v] = 0 else: ans[v] = 1 for u, w in links[v]: if u == p: continue q.put((u, d + w, v)) for i in ans: print(i)
s640649260
p03145
u675918663
2,000
1,048,576
Wrong Answer
19
2,940
97
There is a right triangle ABC with ∠ABC=90°. Given the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC. It is guaranteed that the area of the triangle ABC is an integer.
import sys for line in sys.stdin: nbs = line.split(' ') print(int(nbs[0]) * int(nbs[1]) / 2)
s337716392
Accepted
18
2,940
99
import sys for line in sys.stdin: nbs = line.split(' ') print(int(nbs[0]) * int(nbs[1]) // 2)
s477727503
p02742
u767995501
2,000
1,048,576
Wrong Answer
17
2,940
56
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
H, W = map(int, input().split()) print((H / 2)*(W / 2))
s647403902
Accepted
17
2,940
122
H,W = map(int, input().split()) if H > W: H,W = W,H if H == 1: print(1) else: N = H * W print((N+1)//2)