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
s465001473
p03150
u339199690
2,000
1,048,576
Wrong Answer
35
3,316
248
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.
S = input() N = len(S) if S == "keyence": print("YES") exit() for i in range(N): for j in range(i, N): s = S[:i] + S[j + 1:] print(s) if s == "keyence": print("YES") exit() print("NO")
s750253670
Accepted
19
2,940
250
S = input() N = len(S) if S == "keyence": print("YES") exit() for i in range(N): for j in range(i, N): s = S[:i] + S[j + 1:] # print(s) if s == "keyence": print("YES") exit() print("NO")
s903945410
p02694
u394731058
2,000
1,048,576
Time Limit Exceeded
2,206
9,068
79
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()) d = 0 ans = 0 while d < x: d += d//100 ans += 1 print(ans)
s321336592
Accepted
22
9,016
81
x = int(input()) d = 100 ans = 0 while d < x: d += d//100 ans += 1 print(ans)
s853805561
p03494
u148981246
2,000
262,144
Wrong Answer
111
11,012
244
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input()) a = list(map(int, input().split())) cnt = 0 while 1: if all(a[i] % 2 == 0 for i in range(n)): for i in range(n): a[i] = a[i] // 2 print(a) cnt += 1 else: break print(cnt)
s210565490
Accepted
28
9,248
249
import sys n = int(input()) a = list(map(int, input().split())) cnt = [0] * n while 1: for i in range(n): if a[i] % 2 == 0: a[i] /= 2 cnt[i] += 1 else: print(min(cnt)) sys.exit()
s224643380
p03574
u215461917
2,000
262,144
Wrong Answer
169
12,488
1,059
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
import numpy as np line = input().split() h = int(line[0]) w = int(line[1]) grid = [] for i in range(h): grid.append(list(input())) grid = np.array(grid) def get8(grid,y,x): v = [None]*8 try : if y < 0 : pass else: v[0] = grid[y-1][x] except : pass try : if y-1 < 0 : pass else : v[1] = grid[y-1][x+1] except : pass try : v[2] = grid[y][x+1] except : pass try : v[3] = grid[y+1][x+1] except : pass try : v[4] = grid[y+1][x] except : pass try : if x-1 < 0 : pass else: v[5] = grid[y+1][x-1] except : pass try : if x-1 < 0 : pass else: v[6] = grid[y][x-1] except : pass try : if y-1 < 0 or x-1 < 0 : pass else : v[7] = grid[y-1][x-1] except : pass return v for i in range(h) : for j in range(w) : v = get8(grid,i,j) if i== 3 and j == 0 : print(v) if grid[i][j] == "." : grid[i][j] = v.count("#") print(grid)
s575959798
Accepted
167
12,452
1,053
import numpy as np line = input().split() h = int(line[0]) w = int(line[1]) grid = [] for i in range(h): grid.append(list(input())) grid = np.array(grid) def get8(grid,y,x): v = [None]*8 try : if y-1 < 0 : pass else: v[0] = grid[y-1][x] except : pass try : if y-1 < 0 : pass else : v[1] = grid[y-1][x+1] except : pass try : v[2] = grid[y][x+1] except : pass try : v[3] = grid[y+1][x+1] except : pass try : v[4] = grid[y+1][x] except : pass try : if x-1 < 0 : pass else: v[5] = grid[y+1][x-1] except : pass try : if x-1 < 0 : pass else: v[6] = grid[y][x-1] except : pass try : if y-1 < 0 or x-1 < 0 : pass else : v[7] = grid[y-1][x-1] except : pass return v for i in range(h) : for j in range(w) : v = get8(grid,i,j) if grid[i][j] == "." : grid[i][j] = v.count("#") for i in range(h) : print("".join(grid[i]))
s611515571
p04011
u618369407
2,000
262,144
Wrong Answer
30
9,160
146
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
# -*- coding: utf-8 -*- n = int(input()) k = int(input()) x = int(input()) y = int(input()) print((n * x) + ((n - k) * y if (n - k) > 0 else 0))
s881759031
Accepted
32
9,100
347
# -*- coding: utf-8 -*- n = int(input()) k = int(input()) x = int(input()) y = int(input()) diff = y - x p_x = x * n p_y = diff * (n - k) if (n - k) > 0 else 0 print(p_x + p_y) #print(p_x + p_y)
s186804212
p03407
u642823003
2,000
262,144
Wrong Answer
18
2,940
95
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
a, b, c = map(int, input().split()) if a + b < c: print("Yes") else: print("No")
s504429703
Accepted
17
2,940
91
a, b, c = map(int, input().split()) if a + b < c: print("No") else: print("Yes")
s020696084
p03853
u451017206
2,000
262,144
Wrong Answer
30
3,956
240
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
H, W = map(int, input().split()) C = [[j for j in input()] for i in range(H)] C2 = [['' for j in range(W)] for i in range(2*H)] for i in range(2*H): for j in range(W): C2[i][j] = C[i//2][j] for i in range(2*H): print(*C2[i])
s695436286
Accepted
24
3,316
248
H, W = map(int, input().split()) C = [[j for j in input()] for i in range(H)] C2 = [['' for j in range(W)] for i in range(2*H)] for i in range(2*H): for j in range(W): C2[i][j] = C[i//2][j] for i in range(2*H): print(''.join(C2[i]))
s376662389
p02264
u548252256
1,000
131,072
Wrong Answer
20
5,604
356
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
pnum,mtime = map(int,input().split(" ")) total = [list(input().split(" ")) for _ in range(pnum)] print(total) cnt=0 tcnt=0 while len(total) > 0: ztime = int(total[0][1]) - mtime if ztime <= 0: tcnt += int(total[0][1]) print(total[0][0],int(tcnt)) total.pop(0) else: total.append([total[0][0],ztime]) total.pop(0) tcnt += mtime cnt += 1
s964483074
Accepted
370
17,352
348
from collections import deque pnum,mtime = map(int,input().split(" ")) q = deque([]) [q.append(input().split(" ")) for u in range(pnum)] tcnt=0 while len(q) > 0: qq = q.popleft() ztime = int(qq[1]) - mtime if ztime <= 0: tcnt += int(qq[1]) print(qq[0],int(tcnt)) else: q.append([qq[0],ztime]) tcnt += mtime
s589376099
p03854
u580236524
2,000
262,144
Wrong Answer
29
9,116
203
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() kouho = ["dream", "dreamer", "erase", "eraser"] s.replace(kouho[0], "").replace(kouho[1], "").replace(kouho[2], "").replace(kouho[3], "") if s == "": print("YES") else: print("NO")
s599785496
Accepted
27
9,160
210
s = input() kouho = ["dream", "dreamer", "erase", "eraser"] s = s.replace(kouho[3], "").replace(kouho[2], "").replace(kouho[1], "").replace(kouho[0], "") if s == "": print("YES") else: print("NO")
s380745707
p03251
u085530099
2,000
1,048,576
Wrong Answer
25
9,184
293
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
x = list(map(int, input().split())) n = [list(map(int, input().split())) for i in range(2)] a = sorted(n[0], reverse=True)[0] b = sorted(n[1])[0] print(a) print(b) war = 0 for i in range(x[2]+1, x[3]): if (i > a) and (i <= b): war = 1 if war == 1: print('No War') else: print('War')
s754193028
Accepted
27
9,180
275
x = list(map(int, input().split())) n = [list(map(int, input().split())) for i in range(2)] a = sorted(n[0], reverse=True)[0] b = sorted(n[1])[0] war = 0 for i in range(x[2]+1, x[3]): if (i > a) and (i <= b): war = 1 if war == 1: print('No War') else: print('War')
s926960457
p03377
u318427318
2,000
262,144
Wrong Answer
26
9,100
180
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
#-*-coding:utf-8-*- def main(): a,b,x = map(int,input().split()) if b-x>0 and a<x: print("Yes") else: print("No") if __name__=="__main__": main()
s032760819
Accepted
29
9,044
182
#-*-coding:utf-8-*- def main(): a,b,x = map(int,input().split()) if a+b>=x and a<=x: print("YES") else: print("NO") if __name__=="__main__": main()
s856980283
p03943
u188745744
2,000
262,144
Wrong Answer
17
2,940
108
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 = list(map(int,input().split())) if A+B==C or A+C==B or B+C==A: print("YES") else: print("NO")
s995710386
Accepted
17
3,064
108
A,B,C = list(map(int,input().split())) if A+B==C or A+C==B or B+C==A: print("Yes") else: print("No")
s538184089
p03433
u677121387
2,000
262,144
Wrong Answer
17
2,940
71
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()) ans = "Yes" if n//500 <= a else "No"
s163319866
Accepted
17
2,940
81
n = int(input()) a = int(input()) ans = "Yes" if n%500 <= a else "No" print(ans)
s873549080
p02613
u916205307
2,000
1,048,576
Wrong Answer
149
9,180
181
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) ans = { 'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0 } for i in range(n): x = input() ans[x] += 1 for i in list(ans.keys()): print(i +'x'+str(ans[i]))
s317601344
Accepted
146
9,176
186
n = int(input()) ans = { 'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0 } for i in range(n): x = input() ans[x] += 1 for i in list(ans.keys()): print(i + ' x '+str(ans[i]))
s957037075
p03862
u711539583
2,000
262,144
Wrong Answer
81
19,916
177
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())) ans = 0 p = 0 for ai in a: if p + ai > x: d = p + ai - x ans += d p = ai - d print(ans)
s068669451
Accepted
85
19,760
195
n, x = map(int, input().split()) a = list(map(int, input().split())) ans = 0 p = 0 for ai in a: if p + ai > x: d = p + ai - x ans += d p = ai - d else: p=ai print(ans)
s656824911
p03643
u595952233
2,000
262,144
Wrong Answer
27
9,084
33
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
print('ABC'.format(int(input())))
s718854995
Accepted
27
8,888
30
print('ABC{}'.format(input()))
s973344782
p03679
u958506960
2,000
262,144
Wrong Answer
17
2,940
153
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x, a, b = map(int, input().split()) if a >= b: print('delicious') else: if b - a <= x: print('sefe') else: print('dangerous')
s660367797
Accepted
18
2,940
133
x, a, b = map(int, input().split()) if b <= a: print('delicious') elif b - a <= x: print('safe') else: print('dangerous')
s579592535
p04044
u814715203
2,000
262,144
Wrong Answer
36
3,064
629
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
def alpha2num(alpha): num=0 for index, item in enumerate(list(alpha)): num += pow(26,len(alpha)-index-1)*(ord(item)-ord('a')+1) return num def string2num(str): _N = len(str) num=0 for n in range(_N): num+=alpha2num(str[n])* (26**(_N-1-n)) return num if __name__ == "__main__": N,L = (int(x) for x in input().split()) S = [] S2Num=[] for n in range(N): _str = input() S.append(_str) S2Num.append(string2num(_str)) print(S2Num) ans ="" for key in sorted(range(len(S2Num)), key=lambda k: S2Num[k]): ans+=S[key] print(ans)
s035818217
Accepted
34
3,064
612
def alpha2num(alpha): num=0 for index, item in enumerate(list(alpha)): num += pow(26,len(alpha)-index-1)*(ord(item)-ord('a')+1) return num def string2num(str): _N = len(str) num=0 for n in range(_N): num+=alpha2num(str[n])* (26**(_N-1-n)) return num if __name__ == "__main__": N,L = (int(x) for x in input().split()) S = [] S2Num=[] for n in range(N): _str = input() S.append(_str) S2Num.append(string2num(_str)) ans ="" for key in sorted(range(len(S2Num)), key=lambda k: S2Num[k]): ans+=S[key] print(ans)
s700952495
p03680
u747602774
2,000
262,144
Wrong Answer
187
7,084
246
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
N=int(input()) li=[] for n in range(N): a=int(input()) li.append(a) check=[0] s=0 count=1 while s!=1: if s in check: break else: s=li[s]-1 count+=1 print(s) print(count) if s==2: print(count) else: print(-1)
s213486579
Accepted
225
17,892
189
N = int(input()) d = {} for i in range(N): d[i+1] = int(input()) now = 1 ans = -1 for i in range(N+100): now = d[now] if now == 2: ans = i+1 break print(ans)
s757488233
p03469
u703890795
2,000
262,144
Wrong Answer
18
2,940
61
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.
y,m,d = map(int, input().split("/")) print("2018/01/"+str(d))
s749189147
Accepted
17
2,940
37
S = input() print("2018/01/"+S[8:10])
s481635160
p03698
u226191225
2,000
262,144
Wrong Answer
17
3,060
160
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s = list(str(input())) for i in range(len(s)-1): for j in range(i,len(s)): if s[i] == s[j]: print('no') exit(0) print('yes')
s894737855
Accepted
17
2,940
162
s = list(str(input())) for i in range(len(s)-1): for j in range(i+1,len(s)): if s[i] == s[j]: print('no') exit(0) print('yes')
s481667900
p02388
u650790815
1,000
131,072
Wrong Answer
20
7,352
4
Write a program which calculates the cube of a given integer x.
2**3
s970610270
Accepted
20
7,608
28
x = int(input()) print(x**3)
s591873684
p03129
u109133010
2,000
1,048,576
Wrong Answer
17
2,940
74
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
n,k=map(int,input().split()) if k*2<=n: print("YES") else: print("NO")
s930003076
Accepted
17
2,940
78
n,k=map(int,input().split()) if k*2<=n+n%2: print("YES") else: print("NO")
s791602494
p03997
u556610039
2,000
262,144
Wrong Answer
17
2,940
74
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a + b) * h / 2)
s447649215
Accepted
16
2,940
79
a = int(input()) b = int(input()) h = int(input()) print(int((a + b) * h / 2))
s303296019
p03729
u013202780
2,000
262,144
Wrong Answer
30
9,096
75
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a,b,c=input().split();print("Yes" if a[-1]==b[0] and b[-1]==c[0] else "No")
s058580771
Accepted
31
8,920
75
a,b,c=input().split();print("YES" if a[-1]==b[0] and b[-1]==c[0] else "NO")
s230997299
p03814
u886655280
2,000
262,144
Wrong Answer
35
3,516
315
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s = input() length = range(0, len(s)) first_A = -1 for i in length: if s[i] == 'A': first_A = i break else: continue last_Z = -1 for j in reversed(length): if s[j] == 'Z': last_Z = j break else: continue max_diff = last_Z - first_A print(max_diff)
s598666731
Accepted
40
11,240
326
s = input() length = range(0, len(s)) first_A = -1 for i in length: if s[i] == 'A': first_A = i break else: continue last_Z = -1 for j in list(reversed(length)): if s[j] == 'Z': last_Z = j break else: continue max_diff = last_Z - first_A print(max_diff + 1)
s494333190
p03549
u934119021
2,000
262,144
Wrong Answer
30
9,124
93
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
n, m = map(int, input().split()) ans = (1900 * m + 100 * (n - m)) / ((1 / 2) ** m) print(ans)
s605232513
Accepted
31
9,256
98
n, m = map(int, input().split()) ans = int((1900 * m + 100 * (n - m)) / ((1 / 2) ** m)) print(ans)
s709792541
p03795
u609814378
2,000
262,144
Wrong Answer
18
2,940
69
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N = int(input()) ALL = N*800 TIMES = N//15 print(ALL - (800*TIMES))
s944143096
Accepted
17
2,940
75
N = int(input()) ALL = 800 * N TIMES = (N // 15) * 200 print(ALL - TIMES)
s318567332
p03605
u894694822
2,000
262,144
Wrong Answer
17
2,940
64
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
a, b=input() if a==9 or b==9: print("Yes") else: print("No")
s162123996
Accepted
17
2,940
73
a, b=map(int,input()) if a==9 or b==9: print("Yes") else: print("No")
s692576182
p03449
u836737505
2,000
262,144
Wrong Answer
18
3,060
193
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
n = int(input()) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) ans = 0 for i in range(n): print(a2[i:n]) ans =max(sum(a1[0:i+1])+sum(a2[i:n]),ans) print(ans)
s410344717
Accepted
17
3,060
171
n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) ans = 0 for i in range(n): ans = max(ans,sum(a[:n-i])+sum(b[n-1-i:])) print(ans)
s056879195
p03759
u556477263
2,000
262,144
Wrong Answer
30
9,180
86
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c = map(int,input().split()) if b-a == c-a: print('YES') else: print('NO')
s908675283
Accepted
28
9,008
86
a,b,c = map(int,input().split()) if b-a == c-b: print('YES') else: print('NO')
s168064845
p02936
u879309973
2,000
1,048,576
Wrong Answer
2,109
122,180
844
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.
def solve(n, q, a, b, p, x): E = {i: [] for i in range(1, n+1)} for a_i, b_i in zip(a, b): print(a_i, b_i) E[a_i].append(b_i) E[b_i].append(a_i) res = {i: 0 for i in range(1, n+1)} for j in range(q): res[p[j]] += x[j] used = [False] * (n+1) que = [1] while que: u = que.pop(0) used[u] = True for v in E[u]: if not used[v]: used[v] = True res[v] += res[u] que.append(v) vs = [v for k, v in sorted(res.items())] return " ".join(map(str, vs)) n, q = map(int, input().split()) a = [0] * (n-1) b = [0] * (n-1) for i in range(n-1): a[i], b[i] = map(int, input().split()) p = [0] * q x = [0] * q for j in range(q): p[j], x[j] = map(int, input().split()) print(solve(n, q, a, b, p, x))
s612915040
Accepted
1,633
104,280
828
from collections import deque def solve(n, q, a, b, p, x): E = [[] for i in range(n+1)] for a_i, b_i in zip(a, b): E[a_i].append(b_i) E[b_i].append(a_i) res = {i: 0 for i in range(1, n+1)} for j in range(q): res[p[j]] += x[j] used = [False] * (n+1) used[1] = True que = deque([1]) while que: u = que.popleft() for v in E[u]: if not used[v]: used[v] = True res[v] += res[u] que.append(v) return " ".join(map(str, [res[i] for i in range(1,n+1)])) n, q = map(int, input().split()) a = [0] * (n-1) b = [0] * (n-1) for i in range(n-1): a[i], b[i] = map(int, input().split()) p = [0] * q x = [0] * q for j in range(q): p[j], x[j] = map(int, input().split()) print(solve(n, q, a, b, p, x))
s373151795
p03067
u806855121
2,000
1,048,576
Wrong Answer
17
2,940
98
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 C <= A and C >= B: print('Yes') else: print('No')
s297843202
Accepted
17
2,940
123
A, B, C = map(int, input().split()) if (C >= A and C <= B) or (C >= B and C <= A): print('Yes') else: print('No')
s127740256
p03048
u395202850
2,000
1,048,576
Wrong Answer
608
9,404
293
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
import collections def main(): cnt = 0 R, G, B, N = list(map(int, input().split())) for r in range(N // R + 1): for g in range((N - r * R)//G + 1): if N - r * R - g * G % B == 0: cnt += 1 print(cnt) if __name__ == '__main__': main()
s403814300
Accepted
683
9,404
311
import collections def main(): cnt = 0 R, G, B, N = list(map(int, input().split())) for r in range(N // R + 1): for g in range((N - r * R)//G + 1): k = N - r * R - g * G if k % B == 0: cnt += 1 print(cnt) if __name__ == '__main__': main()
s453865563
p03545
u639426108
2,000
262,144
Wrong Answer
17
3,064
323
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
def calc(a, op, b): if op == "+": return a + b else: return a - b s = input() A, B, C, D = [int(c) for c in s] ops = ["+", "-"] ans = "" for op1 in ops: for op2 in ops: for op3 in ops: if calc(calc(calc(A, op1, B), op2, C), op3, D) == 7: ans = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) print(ans)
s602500352
Accepted
18
3,064
331
def calc(a, op, b): if op == "+": return a + b else: return a - b s = input() A, B, C, D = [int(c) for c in s] ops = ["+", "-"] ans = "" for op1 in ops: for op2 in ops: for op3 in ops: if calc(calc(calc(A, op1, B), op2, C), op3, D) == 7: ans = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7" print(ans)
s180612377
p03624
u057079894
2,000
262,144
Wrong Answer
186
3,188
182
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
s = input() da = 'abcdefghijklmnopqrstuvwxyz' flag = True for i in da: for j in s: if s == i: flag = False if not flag: print(i) break if flag: print('None')
s939784842
Accepted
184
3,188
219
s = input() da = 'abcdefghijklmnopqrstuvwxyz' flag = True for i in da: for j in s: if j == i: flag = False if flag: print(i) flag = False break else: flag = True if flag: print('None')
s925058081
p01981
u931913851
8,000
262,144
Wrong Answer
20
5,452
1
平成31年4月30日をもって現行の元号である平成が終了し,その翌日より新しい元号が始まることになった.平成最後の日の翌日は新元号元年5月1日になる. ACM-ICPC OB/OGの会 (Japanese Alumni Group; JAG) が開発するシステムでは,日付が和暦(元号とそれに続く年数によって年を表現する日本の暦)を用いて "平成 _y_ 年 _m_ 月 _d_ 日" という形式でデータベースに保存されている.この保存形式は変更することができないため,JAGは元号が変更されないと仮定して和暦で表した日付をデータベースに保存し,出力の際に日付を正しい元号を用いた形式に変換することにした. あなたの仕事はJAGのデータベースに保存されている日付を,平成または新元号を用いた日付に変換するプログラムを書くことである.新元号はまだ発表されていないため,"?" を用いて表すことにする.
s888858602
Accepted
20
5,604
308
while 1: day_string = str(input()) if day_string[0] == '#': exit() g, y, m, d = day_string.split() if int(y) > 31 or (int(y) == 31 and int(m) >= 5): print(f'? {int(y)-30} {m} {d}') else: print(f'{g} {y} {m} {d}')
s619153712
p03494
u798731634
2,000
262,144
Time Limit Exceeded
2,104
2,940
226
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input()) a_list = list(map(int, input().split())) count = 0 while True: for i in a_list: if i % 2 == 1: break else: a_list = list(map(lambda x:x/2 , a_list)) count += 1 print(count)
s548536851
Accepted
19
3,060
195
n = int(input()) a_list = list(map(int, input().split())) ans = 0 while True: if [i for i in a_list if i % 2 == 1]: break a_list = list(map(lambda x:x/2 , a_list)) ans += 1 print(ans)
s074895751
p03860
u462538484
2,000
262,144
Wrong Answer
17
2,940
43
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().split()[1] print("A" + s + "C")
s300599653
Accepted
17
2,940
46
s = input().split()[1][0] print("A" + s + "C")
s126282459
p04043
u323045245
2,000
262,144
Wrong Answer
29
9,068
120
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.
moji=list(map(int,input().split())) if moji.count(7) == 1 and moji.count(5) == 2: print("Yes") else: print("No")
s401625037
Accepted
24
9,028
120
moji=list(map(int,input().split())) if moji.count(7) == 1 and moji.count(5) == 2: print("YES") else: print("NO")
s557456779
p03565
u401487574
2,000
262,144
Wrong Answer
18
3,064
521
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
sp = list(input()) t = list(input()) flag = False cnt = -1 l = len(t) for i in range(len(sp) - l+1): for j in range(l): if sp[i+j] == t[j] or sp[i+j] == "?": pass else: flag = True if flag: continue else: cnt = i if cnt == -1: print("UNRESTORABLE") else: for i in range(len(sp)): if sp[i] == "?" : if not cnt<= i <cnt+l: sp[i] ="a" else : sp[i] = t[i-cnt] print("".join(sp))
s642920008
Accepted
18
3,064
485
sp = list(input()) t = list(input()) flag = False cnt = -1 l = len(t) for i in range(len(sp) - l+1): for j in range(l): if sp[i+j] == t[j] or sp[i+j] == "?": pass else: break else: cnt = i if cnt == -1: print("UNRESTORABLE") else: for i in range(len(sp)): if sp[i] == "?" : if not cnt<= i <cnt+l: sp[i] ="a" else : sp[i] = t[i-cnt] print("".join(sp))
s454623820
p04043
u369212307
2,000
262,144
Wrong Answer
17
3,060
244
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.
haiku = list(int(i) for i in input().split()) seven = 0 five = 0 for i in range(3): if int(haiku[i]) == 7: seven += 1 elif int(haiku[i]) == 5: five += 1 if seven == 2 and five == 1: print("YES") else: print("NO")
s402598900
Accepted
17
3,060
244
haiku = list(int(i) for i in input().split()) seven = 0 five = 0 for i in range(3): if int(haiku[i]) == 7: seven += 1 elif int(haiku[i]) == 5: five += 1 if seven == 1 and five == 2: print("YES") else: print("NO")
s081355911
p03129
u187233527
2,000
1,048,576
Wrong Answer
17
2,940
160
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
n, k = [int(x) for x in input().split()] if n % 2 == 1: ans = 'yes' if (n + 1) / 2 >= k else 'no' else : ans = 'yes' if n / 2 >= k else 'no' print(ans)
s779942202
Accepted
17
2,940
76
N, K = map(int, input().split()) print('YES' if (N + 1) // 2 >= K else 'NO')
s202084603
p00028
u546285759
1,000
131,072
Wrong Answer
20
7,704
237
Your task is to write a program which reads a sequence of integers and prints mode values of the sequence. The mode value is the element which occurs most frequently.
import sys from itertools import dropwhile a = [] try: for v in sys.stdin: a.append(int(v)) except: m = max([a.count(v) for v in set(a)]) next(dropwhile(lambda x: True, (print(v) for v in set(a) if a.count(v) == m)))
s437483195
Accepted
20
7,564
164
a = [0] * 101 while True: try: a[int(input())] += 1 except: break maxv = max(a) for i, v in enumerate(a): if maxv == v: print(i)
s469327258
p03598
u802963389
2,000
262,144
Wrong Answer
19
2,940
129
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
n = int(input()) k = int(input()) x = list(map(int, input().split())) ans = 0 for i in x: ans += min(i, abs(k - i)) print(ans)
s802396416
Accepted
17
2,940
134
n = int(input()) k = int(input()) x = list(map(int, input().split())) ans = 0 for i in x: ans += 2 * min(i, abs(k - i)) print(ans)
s064849774
p00030
u766477342
1,000
131,072
Wrong Answer
10
7,580
299
0 から 9 の数字から異なる n 個の数を取り出して合計が s となる組み合わせの数を出力するプログラムを作成してください。n 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、n が 3 で s が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 の 3 通りとなります。
def f2(cnt, n, ci): if n < ci: return 0 elif n == ci and cnt > 1: return 0 elif n == ci and cnt == 1: return 1 else: v = f2(cnt - 1, n - ci, ci + 1) v += f2(cnt, n, ci + 1) return v n, s = map(int, input().split()) print(f2(n, s, 0))
s861783603
Accepted
30
7,648
402
def f2(cnt, n, ci): if ci >= 10 or n > 45: return 0 elif n < ci: return 0 elif n == ci and cnt > 1: return 0 elif n == ci and cnt == 1: return 1 else: v = f2(cnt - 1, n - ci, ci + 1) v += f2(cnt, n, ci + 1) return v while 1: n, s = map(int, input().split()) if n == 0 and s == 0: break print(f2(n, s, 0))
s410297323
p03693
u687574784
2,000
262,144
Wrong Answer
17
2,940
105
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?
# -*- coding: utf-8 -*- r,g,b = list(map(int, input().split())) print('YES' if 10*(g + b)%4==0 else 'NO')
s440899531
Accepted
17
2,940
105
# -*- coding: utf-8 -*- r,g,b = list(map(int, input().split())) print('YES' if (10*g + b)%4==0 else 'NO')
s963580506
p03795
u846155148
2,000
262,144
Wrong Answer
24
9,164
134
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N = int( input() ) x = int( 800 * N ) y = int( 200 * N / 15 ) print( x - y )
s945327931
Accepted
29
9,080
73
N = int( input() ) x = int( 800 * N ) y = N // 15 * 200 print( x - y )
s672901695
p02390
u316246166
1,000
131,072
Wrong Answer
20
5,648
139
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.
x = int(input()) import math h = math.floor(x/60) m = math.floor((x -h*60)/60) s = math.floor(x - h*60 - m*60) print(h, ':',m , ':', s)
s064499193
Accepted
20
5,584
88
x = int(input()) h = x // 3600 m = (x % 3600)//60 s = x % 60 print(h, m, s, sep=":")
s632973695
p03447
u164261323
2,000
262,144
Wrong Answer
17
2,940
76
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()) b = int(input()) c = int(input()) print(a-(((a-b)//c)*c))
s124824043
Accepted
17
2,940
56
x,a,b = [int(input()) for i in range(3)] print((x-a)%b)
s756954841
p03997
u665415433
2,000
262,144
Wrong Answer
19
2,940
49
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.
print((int(input())+int(input()))*int(input())/2)
s407174507
Accepted
17
2,940
50
print((int(input())+int(input()))*int(input())//2)
s332841101
p03501
u617659131
2,000
262,144
Wrong Answer
17
2,940
75
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
n,a,b = map(int, input().split()) if n*a > b: print(n*a) else: print(b)
s215925274
Accepted
18
2,940
76
n,a,b = map(int, input().split()) if n*a <= b: print(n*a) else: print(b)
s167425961
p03672
u626337957
2,000
262,144
Wrong Answer
17
2,940
131
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 = input() if len(S)%2 != 0: S = S + '?' for i in range(len(S)-1)[::-2]: if S[:i//2] == S[i//2+1:i]: print(i//2) break
s039003003
Accepted
17
2,940
127
S = input() if len(S)%2 != 0: S = S + '?' for i in range(len(S)-1)[::-2]: if S[:i//2] == S[i//2:i]: print(i) break
s980846835
p04043
u530332855
2,000
262,144
Wrong Answer
25
8,876
207
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.
# -*- coding: utf-8 -*- if __name__ == "__main__": str_list = [map(int, input().split())] if str_list.count(5) == 2 and str_list.count(7) == 1: print('YES') else: print('NO')
s654992060
Accepted
25
9,152
178
# -*- coding: utf-8 -*- if __name__ == "__main__": str_list = list(map(int, input().split())) if sum(str_list) == 17: print('YES') else: print('NO')
s376818569
p03478
u316603606
2,000
262,144
Wrong Answer
42
9,244
272
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
N,a,b = (int(x) for x in input().split()) z = 0 for I in range (N+1): o = 0 i = I while True: o += i%10 i = round (i/10) if i == 0: if a <= o <= b: print (I) z += I break print (z)
s367793213
Accepted
38
9,096
265
import math N,a,b = (int(x) for x in input().split()) z = 0 for I in range (N): o = 0 i = I+1 while True: o += i%10 i = math.floor(i/10) if i == 0: if a <= o <= b: z += I+1 break print (z)
s563383516
p03067
u967835038
2,000
1,048,576
Wrong Answer
17
2,940
100
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 and b<c) or (a>c and b<c): print('Yes') else: print('No')
s235253096
Accepted
17
2,940
100
a,b,c=map(int,input().split()) if (a<c and b>c) or (a>c and b<c): print('Yes') else: print('No')
s207160169
p03909
u782441844
2,000
262,144
Wrong Answer
17
3,060
297
There is a grid with H rows and W columns. The square at the i-th row and j-th column contains a string S_{i,j} of length 5. The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet. Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location. For example, the square at the 6-th row and 8-th column should be reported as `H6`.
H,W = map(int,input().split()) L = [list(map(str,input().split())) for i in range(H)] A = [chr(i) for i in range(ord("A"),ord("Z")+1)] for y in range(H) : for x in range(W) : if L[y][x] == "snuke" : ans = A[y]+str(x+1) print(ans) exit()
s840584096
Accepted
18
3,060
278
H,W = map(int,input().split()) L = [list(map(str,input().split())) for i in range(H)] A = [chr(i) for i in range(ord("A"),ord("Z")+1)] for y in range(H) : for x in range(W) : if L[y][x] == "snuke" : ans = A[x]+str(y+1) print(ans)
s532947515
p02256
u123669391
1,000
131,072
Wrong Answer
20
5,596
124
Write a program which finds the greatest common divisor of two natural numbers _a_ and _b_
a, b = map(int, input().split()) c = [] for i in range(a): x = i + 1 if b%x == 0: c.append(x) print(c[-1])
s602064813
Accepted
20
5,648
638
a, b = map(int, input().split()) c = [] if a > b: a, b = b, a if b%a == 0: print(a) else: while True: for i in range(a): x = i + 2 if a%x == 0: if b%x == 0: c.append(x) a = a//x b = b//x break elif b%(a//x) == 0: c.append(a//x) a = x b = b//(a//x) break if x > a**0.5: break if x > a**0.5: break s = 1 for j in c: s = s * j print(s)
s370647155
p03091
u667469290
2,000
1,048,576
Wrong Answer
354
15,452
477
You are given a simple connected undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Edge i connects Vertex a_i and b_i bidirectionally. Determine if three circuits (see Notes) can be formed using each of the edges exactly once.
# -*- coding: utf-8 -*- from collections import defaultdict def solve(): N, M = map(int, input().split()) D = defaultdict(int) for _ in range(M): a, b = map(int, input().split()) D[a] += 1 D[b] += 1 if all(d%2==0 for d in D.values()) and (sum(1 for d in D.values() if d>=4)>=2 or sum(1 for d in D.values() if d>=6)>=1): res = 'YES' else: res = 'NO' return str(res) if __name__ == '__main__': print(solve())
s624451152
Accepted
496
28,704
1,028
# -*- coding: utf-8 -*- def solve(): N, M = map(int, input().split()) F = [list() for _ in range(N+1)] D = [int() for _ in range(N+1)] for _ in range(M): a, b = map(int, input().split()) D[a] += 1 D[b] += 1 F[a].append(b) F[b].append(a) E = [0 for _ in range(7)] X = list() for a,d in enumerate(D[1:], start=1): if d%2==0: if d >= 6: E[6] += 1 elif d == 4: E[4] += 1 X.append(a) else: E[d] += 1 else: return 'No' E[1] += 1 if E[6]>0 or E[4]>2: return 'Yes' elif E[4]<2: return 'No' else: x, y = X q = set((y,)) R = set((x,)) while q: z = q.pop() R.add(z) q |= set(F[z])-R if set(F[x])&R == set(F[x]): return 'No' else: return 'Yes' if __name__ == '__main__': print(solve())
s811911713
p02238
u408260374
1,000
131,072
Wrong Answer
20
7,712
408
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving the vertex from which $v$ was discovered. This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source. DFS timestamps each vertex as follows: * $d[v]$ records when $v$ is first discovered. * $f[v]$ records when the search finishes examining $v$’s adjacency list. Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules: * $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively. * IDs in the adjacency list are arranged in ascending order. * The program should report the discover time and the finish time for each vertex. * When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID. * The timestamp starts with 1.
def dfs(v, cnt): D[v] = cnt cnt += 1 for c in edge[v]: if D[c] == -1: cnt = dfs(c, cnt) F[v] = cnt cnt += 1 return cnt V = int(input()) edge = [[] for _ in range(V)] for _ in range(V): u, _, *v = map(lambda x: int(x)-1, input().split()) edge[u] = sorted(v) D, F = [-1] * V, [-1] * V _ = dfs(0, 1) for i, (d, f) in enumerate(zip(D, F)): print(i, d, f)
s496101002
Accepted
40
7,792
462
def dfs(v, cnt): D[v] = cnt cnt += 1 for c in edge[v]: if D[c] == -1: cnt = dfs(c, cnt) F[v] = cnt cnt += 1 return cnt V = int(input()) edge = [[] for _ in range(V)] for _ in range(V): u, _, *v = map(lambda x: int(x)-1, input().split()) edge[u] = sorted(v) D, F = [-1] * V, [-1] * V c = 1 for i in range(V): if D[i] == -1: c = dfs(i, c) for i, (d, f) in enumerate(zip(D, F)): print(i+1, d, f)
s242589518
p03575
u033606236
2,000
262,144
Wrong Answer
18
3,064
445
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
n, m = map(int,input().split()) a = [set() for _ in range(n+1)] count = 0 for i in range(m): x,y = map(int,input().split()) a[x].add(y) a[y].add(x) a[0].add((x,y)) a[0].add((y,x)) for i in range(1, n + 1): print(a[i]) if len(a[i]) == 1: count += 1 continue elif len(a[i]) >= 3: continue if tuple(a[i]) in a[0]: continue count += 1 if count == n: count -= 1 print(count)
s158206556
Accepted
23
3,316
523
from collections import deque n,m = map(int,input().split()) graph = [[] for _ in range(n)] deg = [0]*n seen = [False]*n for i in range(m): x,y = map(int,input().split()) graph[x-1] += [y-1] graph[y-1] += [x-1] deg[x-1] += 1 deg[y-1] += 1 q = deque([i for i in range(n) if deg[i] == 1]) while q: v = q.popleft() seen[v] = True for i in graph[v]: deg[i] -= 1 if deg[i] == 1: q.append(i) if all(seen[i] == 1 for i in range(n)):print(n-1);exit() print(seen.count(1))
s219440855
p03456
u914529932
2,000
262,144
Wrong Answer
17
3,060
163
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.
b, c = map(int, input().split()) x=int(b + c) import math sqrtx = math.sqrt(x) flsqrtx = math.floor(sqrtx) if sqrtx == flsqrtx : print("Yes") else: print("No")
s397713830
Accepted
17
3,060
163
b, c = map(str, input().split()) x=int(b + c) import math sqrtx = math.sqrt(x) flsqrtx = math.floor(sqrtx) if sqrtx == flsqrtx : print("Yes") else: print("No")
s521469163
p02261
u130834228
1,000
131,072
Wrong Answer
30
7,716
695
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
def SelectionSort(A, N): for i in range(N): minj = i for j in range(i, N): if A[j][1:] < A[minj][1:]: minj = j #times += 1 A[i], A[minj] = A[minj], A[i] return A def BubbleSort(A, N): for i in range(N): minj = i for j in range (i, N): if A[j][1:] < A[minj][1]: minj = j A[i], A[minj] = A[minj], A[i] return A N = int(input()) A = [str(x) for x in input().split()] #print(*A) print(*BubbleSort(A, N)) print('Stable') print(*SelectionSort(A, N)) if BubbleSort(A, N) == SelectionSort(A, N): print('Stable') else: print('Not stable')
s507657584
Accepted
20
7,732
780
def SelectionSort(A, N): for i in range(N): minj = i for j in range(i, N): if A[j][1:] < A[minj][1:]: minj = j #times += 1 A[i], A[minj] = A[minj], A[i] #print(*A) return A def BubbleSort(A, N): for i in range(N): for j in reversed(range(i+1, N)): if A[j][1:] < A[j-1][1:]: A[j], A[j-1] = A[j-1], A[j] return A N= int(input()) A = [str(x) for x in input().split()] B = [0 for i in range(N)] for i in range(N): B[i] = A[i] bubble = BubbleSort(A, N) selection = SelectionSort(B, N) #print(*A) print(*bubble) print('Stable') print(*selection) if bubble == selection: print('Stable') else: print('Not stable')
s501368563
p03637
u405256066
2,000
262,144
Wrong Answer
68
14,252
313
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
from sys import stdin N = int(stdin.readline().rstrip()) a = [int(x) for x in stdin.readline().rstrip().split()] v1 = 0 v2 = 0 v4 = 0 for i in a: if i % 4 == 0: v4 += 1 elif i % 2 == 0: v2 += 1 else: v1 += 1 if (v4 >= v1) and (v2 >= 2): print("Yes") else: print("No")
s220220768
Accepted
67
14,252
387
from sys import stdin N = int(stdin.readline().rstrip()) a = [int(x) for x in stdin.readline().rstrip().split()] v1 = 0 v2 = 0 v4 = 0 for i in a: if i % 4 == 0: v4 += 1 elif i % 2 == 0: v2 += 1 else: v1 += 1 #print(v4,v2,v1) if v4 >= (v1 + v2 - 1): print("Yes") else: if (v4 >= v1) and (v2 >= 2): print("Yes") else: print("No")
s914075695
p03599
u912115033
3,000
262,144
Wrong Answer
170
22,552
433
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()) w = [] for i in range(f//100//a+1): for j in range(f//100//b+1): w.append(i*100*a + j*100*b) w = set(w) s = [] for i in range(f//c+1): for j in range(f//d+1): s.append(i*c + j*d) s = set(s) ans = [] for i in w: for j in s: if i != 0 and j/(i+j) <= e/(100+e) and i+j <= 3000: ans.append([j/(i+j), j+i, j]) ans.sort() print(ans[-1][1], ans[-1][2])
s952003318
Accepted
165
22,548
429
a,b,c,d,e,f = map(int,input().split()) w = [] for i in range(f//100//a+1): for j in range(f//100//b+1): w.append(i*100*a + j*100*b) w = set(w) s = [] for i in range(f//c+1): for j in range(f//d+1): s.append(i*c + j*d) s = set(s) ans = [] for i in w: for j in s: if i != 0 and j/(i+j) <= e/(100+e) and i+j <= f: ans.append([j/(i+j), j+i, j]) ans.sort() print(ans[-1][1], ans[-1][2])
s232908921
p02669
u970197315
2,000
1,048,576
Wrong Answer
173
10,184
465
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 dist(n): if n==0: return 0 if n==1: return d if n in memo: return memo[n] res=min( d*n, d*abs(n-n//5*5)+c+dist(n//5), d*abs(n-(n+4)//5*5)+c+dist(n//5), d*abs(n-n//3*3)+b+dist(n//3), d*abs(n-(n+2)//3*3)+b+dist(n//3), d*abs(n-n//2*2)+a+dist(n//2), d*abs(n-(n+1)//2*2)+a+dist(n//2) ) memo[n]=res return res T=int(input()) for i in range(T): n,a,b,c,d=map(int,input().split()) memo={} print(dist(n))
s346517347
Accepted
324
10,732
477
def dist(n): if n==0: return 0 if n==1: return d if n in memo: return memo[n] res=min( d*n, d*abs(n-n//5*5)+c+dist(n//5), d*abs(n-(n+4)//5*5)+c+dist((n+4)//5), d*abs(n-n//3*3)+b+dist(n//3), d*abs(n-(n+2)//3*3)+b+dist((n+2)//3), d*abs(n-n//2*2)+a+dist(n//2), d*abs(n-(n+1)//2*2)+a+dist((n+1)//2) ) memo[n]=res return res T=int(input()) for _ in range(T): n,a,b,c,d=map(int,input().split()) memo={} print(dist(n))
s251674230
p03007
u950708010
2,000
1,048,576
Wrong Answer
417
18,904
499
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.
import collections def solve(): n = int(input()) a = collections.deque(sorted(list(int(i) for i in input().split()))) big = a.pop() mini = a.popleft() queue = collections.deque([]) #print(big,mini) while (a): if a[0] <= 0: tmp = a.popleft() queue.append((big,tmp)) big -= tmp else: tmp = a.pop() queue.append((tmp,mini)) mini -= tmp print(big-mini) queue.append((big,mini)) for i in range(len(queue)): print(*queue[i]) solve()
s678702856
Accepted
416
18,820
499
import collections def solve(): n = int(input()) a = collections.deque(sorted(list(int(i) for i in input().split()))) big = a.pop() mini = a.popleft() queue = collections.deque([]) #print(big,mini) while (a): if a[0] <= 0: tmp = a.popleft() queue.append((big,tmp)) big -= tmp else: tmp = a.pop() queue.append((mini,tmp)) mini -= tmp print(big-mini) queue.append((big,mini)) for i in range(len(queue)): print(*queue[i]) solve()
s540370525
p03998
u433380437
2,000
262,144
Wrong Answer
32
9,020
477
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
A =list(str(input())) B =list(str(input())) C =list(str(input())) P=A for i in range(len(A)+len(B)+len(C)+3): print(P) if P[0] == 'a': P.pop(0) P=A if len(A) ==0: print('A') exit() elif P[0] =='b': P.pop(0) P=B if len(B) ==0: print('B') exit() elif P[0] =='c': P.pop(0) P=C if len(C) ==0: print('C') exit()
s966882444
Accepted
29
9,028
450
A =list(str(input())) B =list(str(input())) C =list(str(input())) P=A for i in range(len(A)+len(B)+len(C)+3): if P[0] == 'a': P.pop(0) P=A if len(A) ==0: print('A') break elif P[0] =='b': P.pop(0) P=B if len(B) ==0: print('B') break elif P[0] =='c': P.pop(0) P=C if len(C) ==0: print('C') break
s427694701
p03543
u713728708
2,000
262,144
Wrong Answer
17
2,940
138
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
keta = list(input()) if (keta[0] == [1] and keta[1] == [2]) or (keta[1] == [2] and keta[2] == [3]): print("Yes") else: print("No")
s095497737
Accepted
17
2,940
154
keta = list(input()) if (keta[0] == keta[1] and keta[1] == keta[2]) or (keta[1] == keta[2] and keta[2] == keta[3]): print("Yes") else: print("No")
s430142958
p02389
u580737984
1,000
131,072
Wrong Answer
20
7,488
190
Write a program which calculates the area and perimeter of a given rectangle.
i = j = 0 n = '' m = '' line = input() while line[i] != ' ': n = n + line[i] i += 1 while i < len(line): m = m + line[i] i += 1 n = int(n) m = int(m) print(n*m)
s414199644
Accepted
30
7,664
213
i = j = 0 n = '' m = '' line = input() while line[i] != ' ': n = n + line[i] i += 1 while i < len(line): m = m + line[i] i += 1 n = int(n) m = int(m) print(n*m,end=' ') print(2*n+2*m)
s201400733
p02258
u144068724
1,000
131,072
Wrong Answer
20
7,560
161
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .
n = int(input()) R = [int(input()) for i in range(n)] profit=[] for i in range(n): for j in range(i+1,n): profit.append(R[i]-R[j]) print(max(profit))
s122248280
Accepted
430
15,660
241
n = int(input()) R = [int(input()) for i in range(n)] profit= R[1] - R[0] mn = R[0] R.pop(0) for i in R: if profit < i - mn: profit = i - mn if 0 > i - mn: mn = i elif mn > i: mn = i print(profit)
s276849692
p02694
u961945062
2,000
1,048,576
Wrong Answer
21
9,160
131
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
X = int(input()) ans = 100 count = 0 while ans < X: ans = int(ans * 1.01) count += 1 if ans > X: print(count)
s919081567
Accepted
22
9,084
132
X = int(input()) ans = 100 count = 0 while ans < X: ans = int(ans * 1.01) count += 1 if ans >= X: print(count)
s437751385
p03795
u945181840
2,000
262,144
Wrong Answer
17
2,940
48
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N = int(input()) print(800 * N - 200 * N // 15)
s020020511
Accepted
18
2,940
50
N = int(input()) print(800 * N - 200 * (N // 15))
s014692184
p03997
u518042385
2,000
262,144
Wrong Answer
17
2,940
61
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) c=int(input()) print((a+b)/2*c)
s754492452
Accepted
17
2,940
67
a=int(input()) b=int(input()) c=int(input()) print(int((a+b)/2*c))
s047394401
p02416
u108130680
1,000
131,072
Wrong Answer
20
5,580
61
Write a program which reads an integer and prints sum of its digits.
n=input() result = sum(list(map(int, str(n)))) print(result)
s943420514
Accepted
20
5,588
83
while True: n = sum(map(int, list(input()))) if n == 0: break print(n)
s778098940
p03369
u441320782
2,000
262,144
Wrong Answer
17
2,940
46
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.
x = input().count("○") print(700 + 100 * x)
s918675960
Accepted
18
2,940
44
x = input().count("o") print(700 + 100 * x)
s957871823
p04043
u923270446
2,000
262,144
Wrong Answer
18
3,060
298
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.
input1 = list(map(int,input().split())) A = input1[0] B = input1[1] C = input1[2] if A == 5: if B == 5 and C == 7: print("Yes") elif B == 7 and C == 5: print("Yes") else: print("No") elif A == 7: if B == 5 and C == 5: print("Yes") else: print("No") else: print("No")
s448941329
Accepted
24
8,860
60
a,b,c=map(int,input().split()) print("YNEOS"[a*b*c!=175::2])
s346517413
p02669
u296150111
2,000
1,048,576
Wrong Answer
190
11,096
494
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.**
memo=dict() t=int(input()) def f(x): if x in memo: return memo[x] if x<=1: return D*x ret=D*x if x%2==0: ret=min(ret,f(x//2)+A) else: ret=min(ret,f(x//2)+A+D,f(x//2+1)+A+D) if x%3==0: ret=min(ret,f(x//3)+B) elif x%3==1: ret=min(ret,f(x//3)+B+D) else: ret=min(ret,f(x//3)+B+D) if x%5<=2: ret=min(ret,f(x//5)+C+D*(x%5)) else: ret=min(ret,f(x//5)+C+D*(5-x%5)) memo[x]=ret return ret for _ in range(t): memo=dict() n,A,B,C,D=map(int,input().split()) print(f(n))
s454204877
Accepted
173
20,392
572
import sys from functools import lru_cache t=int(input()) def solve(n,A,B,C,D): @lru_cache(None) def f(x): if x<=1: return D*x ret=D*x if x%2==0: ret=min(ret,f(x//2)+A) else: ret=min(ret,f(x//2)+A+D,f(x//2+1)+A+D) if x%3==0: ret=min(ret,f(x//3)+B) elif x%3==1: ret=min(ret,f(x//3)+B+D) else: ret=min(ret,f(x//3+1)+B+D) if x%5<=2: ret=min(ret,f(x//5)+C+D*(x%5)) else: ret=min(ret,f(x//5+1)+C+D*(5-x%5)) return ret return f(n) for _ in range(t): n,A,B,C,D=map(int,input().split()) print(solve(n,A,B,C,D))
s754478325
p00100
u308369184
1,000
131,072
Wrong Answer
500
6,748
468
There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID _i_ , the amount of sales _q_ and the corresponding unit price _p_. Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p × q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that _n_ < 4000, and each employee has an unique ID. The unit price _p_ is less than or equal to 1,000,000 and the amount of sales _q_ is less than or equal to 100,000.
while True: n=int(input()) if n==0:break data={} staff=[] for i in range(n): tmp=list(map(int,input().split(' '))) if tmp[0] in data: data[tmp[0]]+=tmp[1]*tmp[2] else: data[tmp[0]]=tmp[1]*tmp[2] staff.append(tmp[0]) if max(data.values())<1000000: print('NA') else: for k in staff: if data[k]>=1000000: print(k)
s147372228
Accepted
40
6,752
470
while True: n = int(input()) if n == 0: break data = {} staff = [] for i in range(n): tmp = list(map(int, input().split(' '))) if tmp[0] in data: data[tmp[0]] += tmp[1] * tmp[2] else: data[tmp[0]] = tmp[1] * tmp[2] staff.append(tmp[0]) if max(data.values()) < 1000000: print('NA') else: for k in staff: if data[k] >= 1000000: print(k)
s256992288
p03712
u537782349
2,000
262,144
Wrong Answer
17
3,060
164
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
a, b = map(int, input().split()) c = ["#" + input() + "#" for _ in range(a)] c.insert(0, "#" * (b+1)) c.append("#" * (b+1)) for i in range(len(c)): print(c[i])
s343641109
Accepted
18
3,060
185
a, b = map(int, input().split()) c = ["#" * (b + 2)] for i in range(a): c.append(list("#" + input() + "#")) c.append("#" * (b + 2)) for i in range(len(c)): print("".join(c[i]))
s744719205
p03549
u517327166
2,000
262,144
Wrong Answer
17
2,940
134
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).
import sys S = list(map(int,input().split())) N=S[0] M=S[1] a=(N-M)*100+M*1900 print(a) r=2**M print(r) result=a*r print(result)
s173778781
Accepted
18
3,060
116
import sys S = list(map(int,input().split())) N=S[0] M=S[1] a=(N-M)*100+M*1900 r=2**M result=a*r print(result)
s936217256
p03380
u888337853
2,000
262,144
Wrong Answer
2,104
16,108
1,090
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
import sys # import re import math import collections import bisect import itertools import fractions # import functools import copy import heapq import decimal # import statistics import queue sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): def combinations_count(n, r): if n > 1: return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) else: return 0 n = ni() a = na() a.sort() ans = 0 a1, a2 = 0, 0 for ai in a: idx = bisect.bisect_left(a, ai // 2) tmp1 = combinations_count(ai, a[max(0, idx - 1)]) tmp2 = combinations_count(ai, a[idx]) if ans < tmp1: ans = tmp1 a1, a2 = ai, a[max(0, idx - 1)] if ans < tmp2: ans = tmp2 a1, a2 = ai, a[idx] print(ans) if __name__ == '__main__': main()
s501682219
Accepted
155
16,676
938
import sys # import re import math import collections import bisect import itertools import fractions # import functools import copy import heapq import decimal # import statistics import queue sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): def combinations_count(n, r): if n > 1: return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) else: return 0 n = ni() a = na() a.sort() max_ai = max(a) idx = bisect.bisect_left(a, max_ai // 2) r = -1 r = a[max(0, idx - 1)] if a[idx] != max_ai: r = a[idx] if abs(a[idx] - max_ai / 2) < abs(r - max_ai / 2) else r print(max_ai, r) if __name__ == '__main__': main()
s259565460
p03610
u347629712
2,000
262,144
Wrong Answer
79
4,596
93
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input() for i in range(len(s)): if (i % 2) != 0: print(s[i], end="") print()
s359162071
Accepted
84
4,596
93
s = input() for i in range(len(s)): if (i % 2) == 0: print(s[i], end="") print()
s436711522
p03447
u581603131
2,000
262,144
Wrong Answer
17
2,940
13
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?
1234 150 100
s009207718
Accepted
17
2,940
77
X = int(input()) A = int(input()) B = int(input()) print(X - A - (X-A)//B *B)
s553295654
p02977
u623687794
2,000
1,048,576
Wrong Answer
17
3,060
123
You are given an integer N. Determine if there exists a tree with 2N vertices numbered 1 to 2N satisfying the following condition, and show one such tree if the answer is yes. * Assume that, for each integer i between 1 and N (inclusive), Vertex i and N+i have the weight i. Then, for each integer i between 1 and N, the bitwise XOR of the weights of the vertices on the path between Vertex i and N+i (including themselves) is i.
n=int(input()) s=len(bin(n))-2 if n+1==2**s: print('Yes') for i in range(1,2*n+1): print(i,i+1) else: print('No')
s399355243
Accepted
282
5,764
439
n=int(input()) s=len(bin(n))-2 if 2**(s-1)==n: print("No") elif n==3: print("Yes") for i in range(1,6): print(i,i+1) else: print("Yes") print(2**(s-1)-1,1+n) for i in range(1,2**(s-1)-1): print(i,i+1) print(i+n,i+n+1) print(2**(s-1),2**(s-1)+1) print(2**(s-1)+1+n,1) print(2**(s-1),1) print(2**(s-1)+n,2**(s-1)+1+n) for i in range(2**(s-1)+2,n+1): print(i,i-1+n) print(i+n,i-2**(s-1))
s515928194
p04030
u757030836
2,000
262,144
Wrong Answer
17
2,940
199
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
S = input() stack = [] for s in S: if s == "B" : if not stack: continue else: stack.pop() elif s == 0 or s==1: stack.append(s) print("".join(stack))
s680258104
Accepted
17
2,940
198
S = input() stack = [] for s in S: if s == "B" : if not stack: continue else: stack.pop() elif s == "0" or s=="1": stack.append(s) print("".join(stack))
s813688331
p02865
u584790715
2,000
1,048,576
Wrong Answer
17
2,940
73
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) else: print((n-1)//2)
s325413484
Accepted
27
3,064
77
n = int(input()) if n % 2 == 0: print(n // 2 - 1) else: print((n-1)//2)
s306142601
p03730
u465246274
2,000
262,144
Wrong Answer
23
3,316
116
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()) ans = 'No' for i in range(1, b+1): if a*i % b == c: ans = 'Yes' print(ans)
s447833779
Accepted
18
2,940
116
a,b,c = map(int,input().split()) ans = 'NO' for i in range(1, b+1): if a*i % b == c: ans = 'YES' print(ans)
s175711617
p03471
u476418095
2,000
262,144
Wrong Answer
18
2,940
87
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
n,y=input().split() if int(y)%1000:print('-1 -1 -1') else:print('0 0 %d'%(int(y)/1000))
s108203296
Accepted
167
3,064
538
N, Y = map(int, input().split()) flg = False if N * 1000 <= Y <= N * 10000: for i in range(N + 1)[::-1]: if Y < i * 10000: continue if flg or i * 10000 + (N - i) * 5000 < Y: break for j in range(N + 1 - i)[::-1]: m = i * 10000 + j * 5000 + (N - i - j) * 1000 if Y < m: continue if m == Y: print(i, j, N - i - j) flg = True if m <= Y: break if not flg: print(-1, -1, -1)
s263720419
p02240
u650712316
1,000
131,072
Wrong Answer
30
6,016
708
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
# coding: UTF-8 from collections import deque n,m = map(int,input().split()) link = [[] for _ in range(n)] part = [-1 for _ in range(n)] for _ in range(m): u,v = map(int,input().split()) link[u].append(v) link[v].append(u) searched = set() queue = deque() pindex = 0 for u in range(n): if u not in searched: queue.append(u) pindex += 1 searched.add(u) while queue: v = queue.popleft() part[v] = pindex for w in link[v]: if w not in searched: part[w] = pindex queue.append(w) searched.add(w) q = int(input()) for _ in range(q): s,t = map(int,input().split()) if part[s] == part[t]: print("Yes") else: print("No")
s444339112
Accepted
680
29,492
779
# coding: UTF-8 from collections import deque n,m = map(int,input().split()) link = [[] for _ in range(n)] part = [-1 for _ in range(n)] for _ in range(m): u,v = map(int,input().split()) link[u].append(v) link[v].append(u) searched = set() queue = deque() pindex = 0 for u in range(n): if u not in searched: queue.append(u) pindex += 1 searched.add(u) while queue: v = queue.popleft() part[v] = pindex for w in link[v]: if w not in searched: part[w] = pindex queue.append(w) searched.add(w) q = int(input()) answers = [] for _ in range(q): s,t = map(int,input().split()) if part[s] == part[t]: answers.append("yes") else: answers.append("no") for answer in answers: print(answer)
s232636188
p02418
u747009765
1,000
131,072
Wrong Answer
20
7,356
90
Write a program which finds a pattern $p$ in a ring shaped text $s$.
s = input() p = input() a = s*2 if a.find(p) > -1: print('yes') else: print("no")
s095493277
Accepted
30
7,452
91
s = input() p = input() s *= 2 if s.find(p) != -1: print('Yes') else: print("No")
s546452874
p03796
u671252250
2,000
262,144
Wrong Answer
17
2,940
141
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
# coding: utf-8 # Your code here! N = int(input()) for i in range(1, N + 1): if pow(2,i) > N: print(pow(2, i - 1)) break
s615496142
Accepted
230
3,984
88
# coding: utf-8 import math N = int(input()) print(math.factorial(N) % (pow(10,9) + 7))
s663817670
p03557
u489247698
2,000
262,144
Wrong Answer
2,210
29,548
636
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() print(A) print(B) print(C) def is_ok(G, index, key): if G[index] >= key: return True else: return False def meg_bisect(G, key): ng = -1 ok = len(G) #ok = length while abs(ok-ng) > 1: mid = (ok + ng) // 2 if is_ok(G, mid, key): ok = mid else: ng = mid return ok ans = 0 for i in range(N): b_index = meg_bisect(B, A[i]) for i in range(b_index, N): c_index = meg_bisect(C, B[i]) ans += N-c_index print(ans)
s282379249
Accepted
251
29,448
316
import bisect N = int(input()) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) #print(A) #print(C) ans = 0 for i in B: a_num = bisect.bisect_left(A,i) c_num = bisect.bisect(C,i) ans += a_num*(N-c_num) print(ans)
s320076992
p02602
u551857719
2,000
1,048,576
Wrong Answer
2,206
32,212
722
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
#!/usr/bin/python # -*- coding: UTF-8 -*- import sys def get_ints(): return map(int, sys.stdin.readline().strip().split()) def std_in(): return sys.stdin.readline().strip() def calc_score(a, f, e): score = 1 for i in range(f, e): score *= a[i] return score def main(): n, k = get_ints() a = list(get_ints()) score = calc_score(a, 0, k) print(score) for i in range(k, n): if a[i-k] == 0: n_score = calc_score(a, i-k+1, i+1) else: n_score = int(score / a[i-k] * a[i]) if n_score > score: print("Yes") else: print("No") score = n_score if __name__ == "__main__": main()
s519399732
Accepted
128
31,600
347
#!/usr/bin/python # -*- coding: UTF-8 -*- import sys def get_ints(): return map(int, sys.stdin.readline().strip().split()) def main(): n, k = get_ints() a = list(get_ints()) for i in range(k, n): if a[i] > a[i-k]: print("Yes") else: print("No") if __name__ == "__main__": main()
s338943699
p03548
u923270446
2,000
262,144
Wrong Answer
27
3,316
98
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
x, y, z = map(int, input().split()) n = z cnt = 0 while n <= x: n += y + z cnt += 1 print(cnt)
s937081588
Accepted
33
2,940
110
x, y, z = map(int, input().split()) n = z cnt = 0 while n + (y + z) <= x: n += (y + z) cnt += 1 print(cnt)
s350344601
p02613
u440478998
2,000
1,048,576
Wrong Answer
156
16,200
324
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) s = [input() for i in range(n)] AC,WA,TLE,RE = 0,0,0,0 for i in s: if i == "AC": AC += 1 elif i == "WA": WA += 1 elif i == "TLE": TLE += 1 else: RE += 1 print("AC × " + str(AC)) print("WA × " + str(WA)) print("TLE × " + str(TLE)) print("RE × " + str(RE))
s840051692
Accepted
144
16,320
320
n = int(input()) s = [input() for i in range(n)] AC,WA,TLE,RE = 0,0,0,0 for i in s: if i == "AC": AC += 1 elif i == "WA": WA += 1 elif i == "TLE": TLE += 1 else: RE += 1 print("AC x " + str(AC)) print("WA x " + str(WA)) print("TLE x " + str(TLE)) print("RE x " + str(RE))
s554933696
p02646
u854685063
2,000
1,048,576
Wrong Answer
23
9,188
237
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.
a, v = map(int,input().split()) b, w = map(int,input().split()) t = int(input()) if a == b:print("Yes") elif a < b: if b+w*t <= (a+v*t):print("Yes") else:print("No") else: if b+w*t >= (a+v*t):print("Yes") else:print("No")
s461087016
Accepted
23
9,188
197
a, v = map(int,input().split()) b, w = map(int,input().split()) t = int(input()) d = abs(b-a) s = v-w #print(d,s) if a == b:print("YES") elif (s*t != 0) and d <= (s*t):print("YES") else:print("NO")
s984034282
p03944
u799691369
2,000
262,144
Wrong Answer
17
3,064
374
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()) xl, xr = 0, W yl, yh = 0, H for i in range(N): xi, yi, ai = map(int, input().split()) if ai == '1': xl = max(xi, xl) elif ai == '2': xr = min(xi, xr) elif ai == '3': yl = max(yi, yl) else: yh = min(yi, yh) ans = (xr - xl) * (yh - yl) if ans > 0: print(ans) else: print('0')
s715893520
Accepted
17
3,064
386
W, H, N = map(int, input().split()) xl, xr = 0, W yl, yh = 0, H for i in range(N): xi, yi, ai = map(int, input().split()) if ai == 1: xl = max(xi, xl) elif ai == 2: xr = min(xi, xr) elif ai == 3: yl = max(yi, yl) else: yh = min(yi, yh) if xr - xl > 0 and yh - yl > 0: ans = (xr - xl) * (yh - yl) else: ans = 0 print(ans)
s803458602
p02612
u078816252
2,000
1,048,576
Wrong Answer
29
9,136
38
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) N = N % 1000 print(N)
s760522599
Accepted
31
9,016
72
N = int(input()) A = N%1000 if A == 0: print(0) else: print(1000-A)
s494849797
p03351
u207822067
2,000
1,048,576
Wrong Answer
20
2,940
150
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)<=abs(d): print('YES') elif abs(a-b)<=abs(d) and abs(b-c)<=abs(d): print('YES') else: print('NO')
s215143256
Accepted
17
3,060
131
a,b,c,d=map(int,input().split()) if abs(a-c)<=d: print('Yes') elif abs(a-b)<=d and abs(b-c)<=d: print('Yes') else: print('No')