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
s099556793
p02394
u105694406
1,000
131,072
Wrong Answer
20
7,584
135
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
w, h, x, y, r = map(int, input().split()) if x + r <= w and x - r <= 0 and y + r >= h and y - r <= 0: print("Yes") else: print("No")
s190296408
Accepted
20
7,656
135
w, h, x, y, r = map(int, input().split()) if x + r <= w and x - r >= 0 and y + r <= h and y - r >= 0: print("Yes") else: print("No")
s529147030
p04043
u189089176
2,000
262,144
Wrong Answer
17
2,940
201
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.
nums = list(map(int,input().split())) for i in [5,7,5]: if i in nums: nums.remove(i) else: print("No") exit() if len(nums) == 0: print("Yes") else: print("No")
s873738576
Accepted
17
2,940
329
nums = list(map(int,input().split())) for i in [5,7,5]: if i in nums: nums.remove(i) else: print("NO") exit() if len(nums) == 0: print("YES") else: print("NO")
s984826612
p02694
u966891144
2,000
1,048,576
Wrong Answer
27
9,188
199
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?
def main(): x = int(input()) val = 100 year=1 while True: val = val * 1.01 print(x,val) if x <= val: break year += 1 print(year) if __name__ == '__main__': main()
s860746052
Accepted
22
9,164
187
def main(): x = int(input()) val = 100 year=1 while True: val = int(val * 1.01) if x <= val: break year += 1 print(year) if __name__ == '__main__': main()
s491590765
p03545
u374974389
2,000
262,144
Wrong Answer
17
3,064
606
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.
num = list(input()) print(num) ans = 7 for i in range(2 ** len(num)): total = 0 ans_num = [] ans_op = [] for j in range(len(num)): if((i >> j) & 1): ans_num.append(num[j]) if(j >= 1): ans_op.append('+') total += int(num[j]) else: ans_num.append(num[j]) if (j >= 1): ans_op.append('-') total -= int(num[j]) print(total) print(ans_op) if(total == ans): print(ans_num[0]+ans_op[0]+ans_num[1]+ans_op[1]+ans_num[2]+ans_op[2]+ans_num[3]+'=7') break
s090163371
Accepted
17
3,064
560
num = list(input()) ans = 7 for i in range(2 ** len(num)): total = 0 ans_num = [] ans_op = [] for j in range(len(num)): if((i >> j) & 1): ans_num.append(num[j]) if(j >= 1): ans_op.append('+') total += int(num[j]) else: ans_num.append(num[j]) if (j >= 1): ans_op.append('-') total -= int(num[j]) if(total == ans): print(ans_num[0]+ans_op[0]+ans_num[1]+ans_op[1]+ans_num[2]+ans_op[2]+ans_num[3]+'=7') break
s983081343
p03713
u474270503
2,000
262,144
Wrong Answer
206
4,192
291
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
H, W=map(int, input().split()) m=float("inf") for i in range(1,H-1): S1=i*W if (H-1)%2==0: S2=W*((H-1)//2) else: S2=(H-i)*(W//2) S3=H*W-S1-S2 if m>max(S1, S2, S3)-min(S1, S2, S3): m=max(S1, S2, S3)-min(S1, S2, S3) print(S1,S2,S3) print(m)
s556362111
Accepted
467
3,064
613
H, W=map(int, input().split()) m=float("inf") for i in range(1,H): S1=i*W S2=W*((H-i)//2) S3=H*W-S1-S2 if m>max(S1, S2, S3)-min(S1, S2, S3): m=max(S1, S2, S3)-min(S1, S2, S3) S2=(H-i)*(W//2) S3=H*W-S1-S2 if m>max(S1, S2, S3)-min(S1, S2, S3): m=max(S1, S2, S3)-min(S1, S2, S3) H,W=W,H for i in range(1,H): S1=i*W S2=W*((H-i)//2) S3=H*W-S1-S2 if m>max(S1, S2, S3)-min(S1, S2, S3): m=max(S1, S2, S3)-min(S1, S2, S3) S2=(H-i)*(W//2) S3=H*W-S1-S2 if m>max(S1, S2, S3)-min(S1, S2, S3): m=max(S1, S2, S3)-min(S1, S2, S3) print(m)
s424159904
p02612
u950847221
2,000
1,048,576
Wrong Answer
29
9,104
121
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.
money=int(input('N')) i=0 while i<=money: if i*1000>=money: break else: i+=1 print(i*1000-money)
s269824646
Accepted
30
9,024
118
money=int(input()) i=0 while i<=money: if i*1000>=money: break else: i+=1 print(i*1000-money)
s038679905
p03447
u761087127
2,000
262,144
Wrong Answer
17
2,940
70
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
X = int(input()) A = int(input()) B = int(input()) X =- A print(X % B)
s300120700
Accepted
20
3,060
68
X = int(input()) A = int(input()) B = int(input()) X -= A print(X%B)
s888363397
p03796
u612635771
2,000
262,144
Wrong Answer
153
9,848
70
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.
import math N = int(input()) print((math.factorial(N)) % 10 ** 9 + 7)
s264266276
Accepted
152
9,896
72
import math N = int(input()) print((math.factorial(N)) % (10 ** 9 + 7))
s834170652
p03417
u035226531
2,000
262,144
Wrong Answer
2,135
529,840
793
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
N, M = (int(i) for i in input().split()) tiles = [[True for i in range(M + 2)] for j in range(N + 2)] print(tiles) for i in range(1, N + 1): for j in range(1, M + 1): tiles[i - 1][j - 1] = not (tiles[i - 1][j - 1]) tiles[i - 1][j] = not (tiles[i - 1][j]) tiles[i - 1][j + 1] = not (tiles[i - 1][j + 1]) tiles[i][j - 1] = not (tiles[i][j - 1]) tiles[i][j] = not (tiles[i][j]) tiles[i][j + 1] = not (tiles[i][j + 1]) tiles[i + 1][j - 1] = not (tiles[i + 1][j - 1]) tiles[i + 1][j] = not (tiles[i + 1][j]) tiles[i + 1][j + 1] = not (tiles[i + 1][j + 1]) count = 0 for i in range(1, N + 1): for j in range(1, M + 1): print(tiles[i][j]) if not tiles[i][j]: count = count + 1 print(count)
s433355619
Accepted
17
2,940
241
N, M = (int(i) for i in input().split()) if N == 1 and M == 1: print(1) elif N == 2 or M == 2: print(0) elif N == 1 or M == 1: if N == 1: print(M - 2) else: print(N - 2) else: print((N - 2) * (M - 2))
s332436739
p02608
u634880755
2,000
1,048,576
Wrong Answer
935
11,440
548
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
import math N = int(input()) def xyzTriplets(N): store = {} upTo = math.sqrt(N) for x in range(1, int(upTo) + 1): for y in range(1, int(upTo) + 1): for z in range(1, int(upTo) + 1): res = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x if (res not in store): store[res] = 1 else: store[res] += 1 for i in range(N): if (i in store): print(store[i]) else: print(0) xyzTriplets(N)
s706176073
Accepted
846
11,612
553
import math N = int(input()) def xyzTriplets(N): store = {} upTo = math.sqrt(N) for x in range(1, int(upTo) + 1): for y in range(1, int(upTo) + 1): for z in range(1, int(upTo) + 1): res = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x if (res not in store): store[res] = 1 else: store[res] += 1 for i in range(1, N+1): if (i in store): print(store[i]) else: print(0) xyzTriplets(N)
s382850609
p03352
u625554679
2,000
1,048,576
Wrong Answer
17
3,060
190
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
X = int(input()) max_num = 1 for b in range(2, 32): num = 1 for p in range(1, 11): num *= b if num <= X and num >= max_num: max_num = num print(max_num)
s140734666
Accepted
17
2,940
190
X = int(input()) max_num = 1 for b in range(2, 32): num = b for p in range(2, 11): num *= b if num <= X and num >= max_num: max_num = num print(max_num)
s714898766
p03645
u431981421
2,000
262,144
Wrong Answer
689
51,744
369
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
import sys N, M = map(int, input().split()) li = [list(map(int, input().split())) for n in range(M)] a = [] b = [] for i in li: if i[1] == N: b.append(i[0]) if i[0] == N: a.append(i[1]) if len(a) == 0 or len(b) == 0: print("IMPOSSIBLE") sys.exit() for i in a: if i in b: print("IMPOSSIBLE") sys.exit() print("POSSIBLE")
s966011125
Accepted
752
67,472
314
import sys from collections import defaultdict d = defaultdict(int) N, M = map(int, input().split()) li = [list(map(int, input().split())) for n in range(M)] for i in li: if i[1] == N: d[i[0]] += 1 for i in li: if i[0] == 1 and d[i[1]] != 0: print("POSSIBLE") sys.exit() print("IMPOSSIBLE")
s354414878
p03385
u844196583
2,000
262,144
Wrong Answer
30
9,072
268
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
S = input() a_list = list(S) a_ct = 0 b_ct = 0 c_ct = 0 for i in range(0,3): if a_list[i] == 'a': a_ct = a_ct + 1 for i in range(0,3): if a_list[i] == 'b': b_ct = b_ct + 1 for i in range(0,3): if a_list[i] == 'c': c_ct = c_ct + 1
s045370844
Accepted
25
9,084
350
S = input() a_list = list(S) a_ct = 0 b_ct = 0 c_ct = 0 for i in range(0,3): if a_list[i] == 'a': a_ct = a_ct + 1 for i in range(0,3): if a_list[i] == 'b': b_ct = b_ct + 1 for i in range(0,3): if a_list[i] == 'c': c_ct = c_ct + 1 if a_ct == 1 and b_ct == 1 and c_ct == 1: print('Yes') else: print('No')
s315660959
p04029
u725185906
2,000
262,144
Wrong Answer
17
2,940
44
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()) m=n-(n-1) print((n/2)*(n+m))
s771945101
Accepted
17
2,940
49
n=int(input()) m=n-(n-1) print(int((n/2)*(n+m)))
s729866036
p03644
u331997680
2,000
262,144
Wrong Answer
17
2,940
120
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()) C = [2, 4, 8, 16, 32, 64] for i in range(len(C)): if C[i] < N: continue else: print(C[i-1])
s052168312
Accepted
17
3,060
225
N = int(input()) C = [1, 2, 4, 8, 16, 32, 64] for i in range(len(C)): if N == C[i]: print(N) break elif C[i] < N and N < 64: continue elif N >= 64: print(64) break else: print(C[i-1]) break
s114252757
p03997
u556589653
2,000
262,144
Wrong Answer
17
2,940
69
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)
s373120402
Accepted
19
3,060
72
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h/2))
s393593568
p02664
u194228880
2,000
1,048,576
Wrong Answer
91
9,400
269
For a string S consisting of the uppercase English letters `P` and `D`, let the _doctoral and postdoctoral quotient_ of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3. We have a string T consisting of `P`, `D`, and `?`. Among the strings that can be obtained by replacing each `?` in T with `P` or `D`, find one with the maximum possible doctoral and postdoctoral quotient.
t = input('') a = '' n = '' for i in range(len(t)): if t[i] == 'P': n = 'D' a += t[i] if t[i] == 'D': n = 'D' a += t[i] if t[i] == '?': a+=n print(a) # DDDDDD -> 6 # PDPDPD -> 6 # PDPDPDP -> 3 + 3 # PDDDDDP -> 1 + 5
s144319831
Accepted
128
10,860
750
t = input('') tlist = list(t) for i in range(len(tlist)): if tlist[i] == '?': if i==0: tlist[i] = 'D' elif i==len(tlist)-1: tlist[i] = 'D' else: if tlist[i-1] == 'P': if tlist[i+1] == 'P': tlist[i] = 'D' elif tlist[i+1] == 'D': tlist[i] = 'D' elif tlist[i+1] == '?': tlist[i] = 'D' else: if tlist[i+1] == 'P': tlist[i] = 'D' elif tlist[i+1] == 'D': tlist[i] = 'P' elif tlist[i+1] == '?': tlist[i] = 'P' print("".join(tlist))
s238890575
p02406
u518939641
1,000
131,072
Wrong Answer
40
7,564
108
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=input() s='' for i in range(int(n)+1): s += (str(i) + ' ') if i%3==0 or '3' in str(i) else '' print(s)
s463352615
Accepted
20
7,692
108
n=input() s='' for i in range(1,int(n)+1): s += (' '+str(i)) if i%3==0 or '3' in str(i) else '' print(s)
s394368306
p03623
u597017430
2,000
262,144
Wrong Answer
17
2,940
78
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|.
A = list(map(int, input().split())) print(min(abs(A[0]-A[1]), abs(A[0]-A[2])))
s368201122
Accepted
17
2,940
91
A = list(map(int, input().split())) print('A' if abs(A[0]-A[1]) <= abs(A[0]-A[2]) else 'B')
s294286329
p02865
u357230322
2,000
1,048,576
Wrong Answer
17
2,940
65
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)
s306644077
Accepted
17
2,940
76
n=int(input()) if n%2==0: print(int((n/2)-1)) else: print(int((n-1)/2))
s502695531
p03469
u243699903
2,000
262,144
Wrong Answer
17
2,940
31
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('2018'+s[5:])
s617900369
Accepted
17
2,940
31
s = input() print('2018'+s[4:])
s510119157
p03369
u266171694
2,000
262,144
Wrong Answer
17
2,940
44
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 = list(input()) print(700 + s.count('o'))
s689590772
Accepted
17
2,940
50
s = list(input()) print(700 + 100 * s.count('o'))
s175176978
p03251
u995102075
2,000
1,048,576
Wrong Answer
17
3,060
328
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N, M, X, Y = map(int, input().split()) x = sorted([int(i) for i in input().split()]) y = sorted([int(i) for i in input().split()]) Z_picklist1 = [range(X + 1, Y + 1)] Z_picklist2 = [range(x[-1] + 1, y[0] + 1)] if len(Z_picklist1 + Z_picklist2) != len(set(Z_picklist1 + Z_picklist2)): print("No War") else: print("War")
s968467981
Accepted
17
3,060
276
N, M, X, Y = map(int, input().split()) x = sorted([int(i) for i in input().split()]) y = sorted([int(i) for i in input().split()]) flag = True for i in range(X + 1, Y + 1): if x[-1] < i and i <= y[0]: flag = False break print("War" if flag else "No War")
s100457851
p03644
u474423089
2,000
262,144
Wrong Answer
17
2,940
149
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.
def main(): n=int(input()) two_pow = 2 while two_pow < n: two_pow *=2 print(two_pow/2) if __name__ == '__main__': main()
s395374969
Accepted
17
2,940
151
def main(): n=int(input()) two_pow = 2 while two_pow <= n: two_pow *=2 print(two_pow//2) if __name__ == '__main__': main()
s030303870
p02612
u995163736
2,000
1,048,576
Wrong Answer
28
9,148
26
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
print(int(input()) % 1000)
s347459551
Accepted
27
9,012
44
n = int(input()) print((1000 - n%1000)%1000)
s843614614
p02412
u525685480
1,000
131,072
Wrong Answer
30
7,596
299
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
# -*- coding: utf-8 -*- while True: n,x = [int(i) for i in input().split(' ')] count=0 if n+x ==0: break for i in range(n): for j in range(n): for k in range(n): if i + j + k == x: count +=1 print(count) count=0
s652205722
Accepted
530
7,724
299
# -*- coding: utf-8 -*- while True: count=0 n,x = [int(a)for a in input().split(' ')] if n+x==0: break for i in range(1,n-1): for j in range(i+1,n): for k in range(j+1,n+1): if i + j + k ==x: count += 1 print(count)
s561965477
p03993
u405256066
2,000
262,144
Wrong Answer
64
13,880
190
There are N rabbits, numbered 1 through N. The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i. For a pair of rabbits i and j (i<j), we call the pair (i,j) a _friendly pair_ if the following condition is met. * Rabbit i likes rabbit j and rabbit j likes rabbit i. Calculate the number of the friendly pairs.
from sys import stdin N = int(stdin.readline().rstrip()) A = [int(x) for x in stdin.readline().rstrip().split()] ans = 0 for i in range(N): if A[A[i]-1] == i: ans += 1 print(ans)
s330578112
Accepted
71
13,880
195
from sys import stdin N = int(stdin.readline().rstrip()) A = [int(x) for x in stdin.readline().rstrip().split()] ans = 0 for i in range(N): if A[A[i]-1] == i+1: ans += 1 print(ans//2)
s244337760
p04044
u653005308
2,000
262,144
Wrong Answer
17
3,060
85
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.
n,l=map(int,input().split()) list=[input() for i in range(n)] list.sort() print(list)
s758402229
Accepted
17
3,060
124
n,l=map(int,input().split()) list=[input() for i in range(n)] list.sort() ans="" for word in list: ans+=word print(ans)
s612216092
p03698
u994521204
2,000
262,144
Wrong Answer
17
2,940
67
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
w=input() if list(w)==list(set(w)): print('yes') else:print('no')
s088456770
Accepted
17
2,940
65
w=input() if len(w)==len(set(w)): print('yes') else:print('no')
s189389043
p03679
u500297289
2,000
262,144
Wrong Answer
18
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.
""" AtCoder """ X, A, B = map(int, input().split()) if A >= B: print("delicious") elif (A + X) < B: print("safe") else: print("dangerous")
s428356803
Accepted
18
2,940
154
""" AtCoder """ X, A, B = map(int, input().split()) if A >= B: print("delicious") elif (A + X) >= B: print("safe") else: print("dangerous")
s894453163
p02390
u648117624
1,000
131,072
Wrong Answer
20
5,588
112
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.
#coding: UTF-8 S = int(input('>')) h = S//3600 m = (S%3600)//60 s = m%60 print(str(h)+':'+str(m)+':'+str(s))
s494786763
Accepted
20
5,580
61
x = int(input()) print(x//3600, x//60 % 60, x%60, sep=":")
s259634186
p02694
u068142202
2,000
1,048,576
Wrong Answer
23
9,164
135
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()) saving = 100 count = 0 while x >= saving: saving += math.floor(saving * 0.01) count += 1 print(count)
s470495028
Accepted
23
9,108
147
import math x = int(input()) saving = 100 count = 0 while not x <= saving: saving = math.floor(saving + saving * 0.01) count += 1 print(count)
s651446980
p02697
u211706121
2,000
1,048,576
Wrong Answer
73
9,276
69
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.
n,m=map(int,input().split()) for i in range(m): print(i+1,2*m-i)
s610384672
Accepted
89
9,272
145
n,m=map(int,input().split()) k=n//2 c=0 while c<m: d=c//2 if c%2==0: print(k-d,k+1+d) else: print(d+1,n-1-d) c+=1
s326608731
p02399
u641082901
1,000
131,072
Wrong Answer
20
5,604
89
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a, b = [int(x) for x in input().split()] print("{0} {1} {2:.5f}".format(b//a, b%a, b/a))
s267057160
Accepted
20
5,612
89
a, b = [int(x) for x in input().split()] print("{0} {1} {2:.5f}".format(a//b, a%b, a/b))
s686459288
p03469
u989345508
2,000
262,144
Wrong Answer
17
2,940
38
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=list(input()) s[3]="8" print(str(s))
s780002791
Accepted
17
2,940
42
s=list(input()) s[3]="8" print("".join(s))
s432568003
p00002
u923573620
1,000
131,072
Wrong Answer
20
5,652
83
Write a program which computes the digit number of sum of two integers a and b.
import math a, b = map(int, input().split()) print(str(int(math.log10(a+b)+1)))
s807722522
Accepted
20
5,588
107
while True: try: a, b = map(int, input().split(" ")) print(len(str(a + b))) except: break
s811519067
p03130
u346194435
2,000
1,048,576
Wrong Answer
19
3,064
459
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
def calc(x:list, y:int): if x.count(y) == 0: return -100 elif x.count(y) == 1: return -1 elif x.count(y) == 2: return 1 elif x.count(y) > 2: return -100 loads = [] for _ in range(3): loada, loadb = input().split() loads.append(int(loada)) loads.append(int(loadb)) x = 0 for i in range(1,5): print(i, calc(loads, i)) x = x + calc(loads, i) if x == 0: print('YES') else: print('NO')
s143746768
Accepted
17
3,064
430
def calc(x:list, y:int): if x.count(y) == 0: return -100 elif x.count(y) == 1: return -1 elif x.count(y) == 2: return 1 elif x.count(y) > 2: return -100 loads = [] for _ in range(3): loada, loadb = input().split() loads.append(int(loada)) loads.append(int(loadb)) x = 0 for i in range(1,5): x = x + calc(loads, i) if x == 0: print('YES') else: print('NO')
s057629978
p03730
u472534477
2,000
262,144
Wrong Answer
17
2,940
161
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(1,B+1): if (A*i) % B == C: flag = True if flag: print("Yes") else: print("No")
s535750317
Accepted
17
3,064
161
A,B,C = map(int,input().split()) flag = False for i in range(1,B+1): if (A*i) % B == C: flag = True if flag: print("YES") else: print("NO")
s623451460
p03478
u414050834
2,000
262,144
Wrong Answer
22
2,940
164
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()) c = 0 for i in range(1,n+1): if a <= i//10000 + (i//1000)%10 + (i//100)%10 + (i//10)%10 + i&10 <= b: c = c + i print(c)
s773331104
Accepted
23
2,940
164
n,a,b = map(int,input().split()) c = 0 for i in range(1,n+1): if a <= i//10000 + (i//1000)%10 + (i//100)%10 + (i//10)%10 + i%10 <= b: c = c + i print(c)
s968159069
p02280
u007270338
1,000
131,072
Wrong Answer
20
5,632
2,468
A rooted binary tree is a tree with a root node in which every node has at most two children. Your task is to write a program which reads a rooted binary tree _T_ and prints the following information for each node _u_ of _T_ : * node ID of _u_ * parent of _u_ * sibling of _u_ * the number of children of _u_ * depth of _u_ * height of _u_ * node type (root, internal node or leaf) If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_ have the same parent, we say _u_ is a sibling of _v_ (vice versa). The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf. Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
#coding:utf-8 n = int(input()) T = [list(map(int, input().split())) for i in range(n)] A = [] class binaryTree: def __init__(self, x, y, z): self.data = x self.par = y self.depth = z def makeTree(self,tree): parID = tree.data[0] t = T[parID] depth = tree.depth if tree.par == -1: tree.kind = "root" elif t[1] == -1 and t[2] == -1: tree.kind = "leaf" else: tree.kind = "international node" if t[1] == -1 and t[2] == -1: tree.deg = 0 tree.l = None tree.r = None if t[1] != -1: tree.l = binaryTree(T[t[1]], parID, depth+1) l_tree = tree.l if t[2] != -1: tree.deg = 2 l_tree.sib = t[2] else: tree.deg = 1 l_tree.sib = -1 self.makeTree(self, l_tree) else: tree.l = None if t[2] != -1: tree.r = binaryTree(T[t[2]], parID, depth+1) r_tree = tree.r if t[1] != -1: tree.deg = 2 r_tree.sib = t[1] else: tree.deg = 1 r_tree.sib = -1 self.makeTree(self, r_tree) else: tree.r = None def setHeight(tree): h1 = h2 = 0 if tree.l != None: h1 = setHeight(tree.l) + 1 if tree.r != None: h2 = setHeight(tree.r) + 1 if tree.r == None and tree.l == None: tree.hei = 0 return 0 tree.hei = max(h1,h2) return max(h1, h2) par = -1 depth = 0 tree = binaryTree(T[0], par,depth) tree.sib = -1 binaryTree.makeTree(binaryTree, tree) setHeight(tree) ID = tree.data[0] parent = tree.par sibling = tree.sib degree = tree.deg depth = tree.depth height = tree.hei kind = tree.kind def printer(tree): ID = tree.data[0] parent = tree.par sibling = tree.sib degree = tree.deg depth = tree.depth height = tree.hei kind = tree.kind print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"\ .format(ID, parent, sibling, degree, depth, height, kind)) if tree.l != None: l_tree = tree.l printer(l_tree) if tree.r != None: r_tree = tree.r printer(r_tree) printer(tree)
s642364611
Accepted
20
5,632
2,876
#coding:utf-8 n = int(input()) T = [list(map(int, input().split())) for i in range(n)] A = [False for i in range(n)] class binaryTree: def __init__(self, node, x=-1): self.node = node self.p = x def partialTree(self,tree,left, right): node = tree.node if left != -1: if A[left]: A[left].p = tree tree.l = A[left] else: tree.l = binaryTree(left, node) A[left] = tree.l tree.l.p = tree else: tree.l = binaryTree(left, node) tree.l.node = -1 if right != -1: if A[right]: A[right].p = tree tree.r = A[right] else: tree.r = binaryTree(right, node) A[right] = tree.r tree.r.p = tree else: tree.r = binaryTree(right, node) tree.r.node = -1 def searchParent(): p_tree = A[0] while p_tree.p != -1: p_tree = p_tree.p return p_tree def setHeight(tree): h1 = h2 = 0 if tree.l.node != -1: h1 = setHeight(tree.l) + 1 if tree.r.node != -1: h2 = setHeight(tree.r) + 1 if tree.l.node == -1 and tree.r.node == -1: tree.hei = 0 return 0 tree.hei = max(h1,h2) return max(h1, h2) def setDepth(tree,depth): tree.dep = depth depth += 1 if tree.l.node != -1: setDepth(tree.l,depth) if tree.r.node != -1: setDepth(tree.r,depth) def getSibling(tree): if tree.p == -1: return -1 if tree.p.l.node != -1 and tree.p.l.node != tree.node: return tree.p.l.node if tree.p.r.node != -1 and tree.p.r.node != tree.node: return tree.p.r.node return -1 def makeTree(): for i in range(n): t = T[i] node = t[0] left = t[1] right = t[2] if A[node]: tree = A[node] else: tree = binaryTree(node) A[node] = tree binaryTree.partialTree(binaryTree, tree,left,right) makeTree() p_tree = searchParent() setHeight(p_tree) depth = 0 setDepth(p_tree,depth) for i in range(n): tree = A[i] tree.sib = getSibling(tree) deg = 0 if tree.r.node != -1: deg += 1 if tree.l.node != -1: deg += 1 if tree.p == -1: kind = "root" else: if deg == 0: kind = "leaf" else: kind = "internal node" ID = i if tree.p == -1: parent = -1 else: parent = tree.p.node sibling = tree.sib degree = deg depth = tree.dep height = tree.hei print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"\ .format(ID, parent, sibling, degree, depth, height, kind))
s331615857
p03997
u869282786
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()) b=int(input()) c=int(input()) print((a+b)*c/2)
s672567229
Accepted
17
2,940
63
a=int(input()) b=int(input()) c=int(input()) print((a+b)*c//2)
s881576167
p03068
u727787724
2,000
1,048,576
Wrong Answer
17
2,940
133
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()) S=list(s) for i in range(n): if S[i]!=S[k-1]: S[i]='*' ans=','.join(S) print(ans)
s930366567
Accepted
17
2,940
133
n=int(input()) s=input() k=int(input()) S=list(s) for i in range(n): if S[i]!=S[k-1]: S[i]='*' ans=''.join(S) print(ans)
s566290339
p03997
u241190800
2,000
262,144
Wrong Answer
17
2,940
78
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.
abh = [int(input()) for i in range(3)] print((abh[0] + abh[1]) * abh[2] * 0.5)
s072632431
Accepted
17
2,940
149
data = [int(input()) for i in range(3)] result = (data[0]+data[1])*data[2]*0.5 if result == int(result) : print(int(result)) else : print(result)
s711710561
p02397
u279483260
1,000
131,072
Wrong Answer
20
7,688
119
Write a program which reads two integers x and y, and prints them in ascending order.
def sort_num(x, y): n = [x, y] n.sort() print(n[0], n[1]) x, y = map(int, input().split()) sort_num(x, y)
s318537189
Accepted
60
7,692
192
def sort_num(x, y): n = [x, y] n.sort() print(n[0], n[1]) while True: x, y = map(int, input().split()) if x == 0 and y == 0: break else: sort_num(x, y)
s794483815
p02399
u780025254
1,000
131,072
Wrong Answer
30
7,692
80
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a, b = map(int, input().split()) d = a // b r = a % b f = a / b print(d, r, f)
s195600901
Accepted
20
5,600
84
a, b = map(int, input().split()) print("{} {} {:.5f}".format(a // b, a % b, a / b))
s600569952
p02612
u984081384
2,000
1,048,576
Wrong Answer
31
9,096
69
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
i = int(input()) if i % 1000: print(0) else: print(1000-(i % 1000))
s183891871
Accepted
29
9,096
74
i = int(input()) if i % 1000 == 0: print(0) else: print(1000-(i % 1000))
s474921674
p03545
u703442202
2,000
262,144
Wrong Answer
17
3,064
626
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.
n = input() s_num = len(n) -1 all_p_m = [] for i in range(2**s_num): p_m_list = [False for i in range(s_num)] for j in range(s_num): if ((i >>j) & 1): p_m_list[j] = True all_p_m.append(p_m_list) for p_m in all_p_m: result = int(n[0]) for i in range(len(p_m)): if p_m[i] == True: result += int(n[i + 1]) else: result -= int(n[i + 1]) if result == 7: ans_p_m = p_m ans = ["0" for i in range(7)] for _ in range(7): if _ %2 ==0: ans[_] = n[_//2] else: if ans_p_m[_//2] == True: ans[_] = "+" else: ans[_] = "-" print("".join(ans))
s019004781
Accepted
18
3,064
642
n = input() s_num = len(n) -1 all_p_m = [] for i in range(2**s_num): p_m_list = [False for i in range(s_num)] for j in range(s_num): if ((i >>j) & 1): p_m_list[j] = True all_p_m.append(p_m_list) for p_m in all_p_m: result = int(n[0]) for i in range(len(p_m)): if p_m[i] == True: result += int(n[i + 1]) else: result -= int(n[i + 1]) if result == 7: ans_p_m = p_m ans = ["0" for i in range(7)] for _ in range(7): if _ %2 ==0: ans[_] = n[_//2] else: if ans_p_m[_//2] == True: ans[_] = "+" else: ans[_] = "-" ans.append("=7") print("".join(ans))
s988377593
p02602
u312158169
2,000
1,048,576
Wrong Answer
2,206
31,704
339
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.
n,k = map(int,input().split()) a = [int(x) for x in input().split()] num = n-k ans = [0] * (num+1) ans[0] = 1 for i in range(num+1): ans[0] *= a[i] for i in range(1,num+1): ans[i] = ans[i-1]/ a[i-1] * a[i+k-1] print(ans) for i in range(1,num+1): if ans[i-1] >= ans[i]: print("No") else: print("Yes")
s518467422
Accepted
168
31,612
184
n,k = map(int,input().split()) a = [int(x) for x in input().split()] num = n-k for i in range(1,num+1): if a[i-1] >= a[i+k-1]: print("No") else: print("Yes")
s693010163
p03370
u536325690
2,000
262,144
Wrong Answer
32
3,060
224
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
n, x = map(int, input().split()) m = [int(input()) for i in range(n)] rest = x - sum(m) min_ = min(m) print(m) count = n while True: rest -= min_ if rest > 0: count += 1 else: break print(count)
s197072277
Accepted
36
3,060
274
n, x = map(int, input().split()) m = [int(input()) for i in range(n)] rest = x - sum(m) min_ = min(m) count = n if rest < 0: count = 0 else: while True: rest -= min_ if rest >= 0: count += 1 else: break print(count)
s851847875
p02612
u430937688
2,000
1,048,576
Wrong Answer
28
9,144
52
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N - ((N - 1) // 1000) * 1000)
s846370383
Accepted
27
9,144
56
N = int(input()) print(((N - 1) // 1000 + 1) * 1000 - N)
s402107641
p03997
u246661425
2,000
262,144
Wrong Answer
18
2,940
69
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(h/2 * (a+b))
s099248428
Accepted
17
2,940
75
a = int(input()) b = int(input()) h = int(input()) print(int((a+b) * h /2))
s810760772
p02600
u645661835
2,000
1,048,576
Wrong Answer
32
9,156
115
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()) initial=400 kyu=8 for add in range(1,9): if X<initial+add*200: print(kyu) break kyu-=1
s795170459
Accepted
34
8,852
130
X=int(input()) initial=400 kyu=8 for add in range(1,9): if X<initial+add*200: print(int(kyu)) break kyu-=1
s752368903
p00020
u184989919
1,000
131,072
Wrong Answer
30
7,428
76
Write a program which replace all the lower-case letters of a given text with the corresponding captital letters.
def Capitalize(): for i in sys.stdin: print(i.upper())
s568271111
Accepted
30
7,276
22
print(input().upper())
s862310947
p03095
u571969099
2,000
1,048,576
Wrong Answer
544
3,188
153
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order.
n=int(input()) s=input() l=n for i in range(n): a=set() for j,k in enumerate(s[i:]): a.add(k) if len(a)!=j+1: break l+=1 print(l)
s412713855
Accepted
35
3,188
143
n=int(input()) s=input() a={} for i in s: if i in a: a[i]+=1 else: a[i]=1 j=1 for k in a: i=a[k] j*=i+1 print((j-1)%(10**9+7))
s461853109
p03860
u588633699
2,000
262,144
Wrong Answer
17
2,940
34
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() print(s[2][0])
s706597876
Accepted
17
2,940
42
s = input().split() print('A'+s[1][0]+'C')
s498833001
p03351
u008357982
2,000
1,048,576
Wrong Answer
17
2,940
91
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());print('YNeos'[abs(a-c)>d or abs(a-b)>d and abs(b-c)>d::2])
s624225632
Accepted
17
2,940
101
a,b,c,d=map(int,input().split()) print("Yes" if abs(c-a)<=d or abs(b-a)<=d and abs(c-b)<=d else "No")
s700159973
p03068
u706884679
2,000
1,048,576
Wrong Answer
17
2,940
192
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
N = int(input()) S = list(input()) K = int(input()) x = S[K-1] s = [i for i, t in enumerate(S) if t == x] for i in range(N): if i in s: S[i-1] = '*' else: pass A = "".join(S) print(A)
s341507859
Accepted
18
3,060
194
N = int(input()) S = list(input()) K = int(input()) x = S[K-1] s = [i for i, t in enumerate(S) if t == x] for i in range(N): if i not in s: S[i] = '*' else: pass A = "".join(S) print(A)
s776632021
p03910
u335540120
2,000
262,144
Wrong Answer
22
3,316
185
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
N = int(input()) ans_max = 0 while ans_max * (ans_max + 1) / 2 < N: ans_max += 1 num_remove = ans_max - N for i in range(1, ans_max + 1): if i != num_remove: print(i)
s115787722
Accepted
23
3,316
206
N = int(input()) ans_max = 0 while ans_max * (ans_max + 1) / 2 < N: ans_max += 1 num_remove = ans_max * (ans_max + 1) // 2 - N for i in range(1, ans_max + 1): if i != num_remove: print(i)
s173977445
p02619
u729133443
2,000
1,048,576
Wrong Answer
25
9,060
1
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
0
s765183144
Accepted
31
10,164
145
d,*s,=map(int,open(i:=0).read().split()) c,*l=[0]*27 for v in s[-d:]: i+=1 l[v-1]=i print(c:=c+s[i*26+v-1]-sum(x*(i-y)for x,y in zip(s,l)))
s523684365
p03069
u528470578
2,000
1,048,576
Wrong Answer
70
3,560
243
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
N = int(input()) S = str(input()) new_S = "" for i in reversed(S): new_S += i for i in range(N): if new_S[i] == ".": S_new = S[i:] break else: S_new = "" print(min(S_new.count('
s662098088
Accepted
93
11,368
251
N = int(input()) S = str(input()) suu = [] s_count = S.count('.') k_count = 0 suu.append(s_count + k_count) for i in range(N): if S[i] == "#": k_count += 1 else: s_count -= 1 suu.append(k_count + s_count) print(min(suu))
s230065851
p02397
u656153606
1,000
131,072
Wrong Answer
50
7,648
138
Write a program which reads two integers x and y, and prints them in ascending order.
while True: a, b = [int(i) for i in input().split()] if a == 0 and b == 0: break print(a, b) if a > b else print(b, a)
s019433573
Accepted
40
8,248
247
list = [] while True: a, b = [int(i) for i in input().split()] if a == 0 and b == 0: break if a < b: list.append([a,b]) else: list.append([b,a]) for i in range(len(list)): print(list[i][0], list[i][1])
s891794663
p03693
u075409829
2,000
262,144
Wrong Answer
17
2,940
94
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) if (g*10+b)%4 == 0: print("Yes") else: print("No")
s620675957
Accepted
17
2,940
94
r, g, b = map(int, input().split()) if (g*10+b)%4 == 0: print("YES") else: print("NO")
s601542867
p02600
u354862173
2,000
1,048,576
Wrong Answer
39
9,972
628
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?
import sys from string import ascii_letters as ascii def Ss(): return sys.stdin.readline().rstrip() def Is(): return map(int, Ss()) def get_kyu(score): if score >= 400 and score <= 599: return 8 if score >= 600 and score <= 799: return 7 if score >= 800 and score <= 999: return 6 if score >= 1000 and score <= 1199: return 5 if score >= 1200 and score <= 1399: return 4 if score >= 1400 and score <= 1599: return 3 if score >= 1600 and score <= 1799: return 2 if score >= 1800 and score <= 1999: return 1 return None score = int(Ss()) print(score) print(get_kyu(score))
s960821252
Accepted
42
9,968
615
import sys from string import ascii_letters as ascii def Ss(): return sys.stdin.readline().rstrip() def Is(): return map(int, Ss()) def get_kyu(score): if score >= 400 and score <= 599: return 8 if score >= 600 and score <= 799: return 7 if score >= 800 and score <= 999: return 6 if score >= 1000 and score <= 1199: return 5 if score >= 1200 and score <= 1399: return 4 if score >= 1400 and score <= 1599: return 3 if score >= 1600 and score <= 1799: return 2 if score >= 1800 and score <= 1999: return 1 return None score = int(Ss()) print(get_kyu(score))
s695313119
p04011
u664481257
2,000
262,144
Wrong Answer
81
7,544
689
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 -*- # !/usr/bin/env python # vim: set fileencoding=utf-8 : def read_input(): N = int(input()) K = int(input()) X = int(input()) Y = int(input()) return N, K, X, Y def check_sum(N, K, X, Y): if N > K: return K * X + (N-K)*Y else: return N * X if __name__ == "__main__": import doctest doctest.testmod() N, K, X, Y = read_input() check_sum(N, K, X, Y)
s050355978
Accepted
22
3,064
705
# -*- coding: utf-8 -*- # !/usr/bin/env python # vim: set fileencoding=utf-8 : def read_input(): N = int(input()) K = int(input()) X = int(input()) Y = int(input()) return N, K, X, Y def check_sum(N, K, X, Y): if N > K: return K * X + (N-K)*Y else: return N * X if __name__ == "__main__": # # doctest.testmod() N, K, X, Y = read_input() print(check_sum(N, K, X, Y))
s674245676
p03005
u373047809
2,000
1,048,576
Wrong Answer
17
2,940
57
Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?
n, k = map(int, input().split()) print([0, 0, n-k][k!=1])
s637409815
Accepted
18
2,940
37
print(eval(input().replace(' ','%')))
s679151941
p03696
u690037900
2,000
262,144
Wrong Answer
17
3,064
320
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
import sys input=sys.stdin.readline N = int(input()) S = list(input()) f = 0 b = 0 count = 0 for i in range(N - 1, -1, -1): if S[i] == '(': if count > 0: count -= 1 else: b += 1 else: count += 1 print('(' * count, end='') print(*S, sep='', end='') print(')' * b)
s729340965
Accepted
17
3,064
286
N = int(input()) S = list(input()) f = 0 b = 0 count = 0 for i in range(N - 1, -1, -1): if S[i] == '(': if count > 0: count -= 1 else: b += 1 else: count += 1 print('(' * count, end='') print(*S, sep='', end='') print(')' * b)
s108153327
p03369
u952022797
2,000
262,144
Wrong Answer
161
13,260
463
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.
# -*- coding: utf-8 -*- import sys import copy import collections from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import numpy as np import statistics from statistics import mean, median,variance,stdev import math def main(): s = input() tmp = 0 for i in range(len(s)): if i == "o": tmp += 1 print(700 + (tmp * 100)) if __name__ == "__main__": main()
s119050066
Accepted
161
13,260
466
# -*- coding: utf-8 -*- import sys import copy import collections from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import numpy as np import statistics from statistics import mean, median,variance,stdev import math def main(): s = input() tmp = 0 for i in range(len(s)): if s[i] == "o": tmp += 1 print(700 + (tmp * 100)) if __name__ == "__main__": main()
s054985198
p03251
u953379577
2,000
1,048,576
Wrong Answer
26
9,136
273
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
n,m,a,b = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) x.sort() y.sort() if x[-1]<y[0]: for i in range(x[-1]+1,y[0]+1): if a<i<b: print("No War") else: print("War") else: print("War")
s482585352
Accepted
29
9,140
291
n,m,a,b = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) x.sort() y.sort() if x[-1]<y[0]: for i in range(x[-1]+1,y[0]+1): if a<i<b: print("No War") break else: print("War") else: print("War")
s157396192
p03943
u244836567
2,000
262,144
Wrong Answer
25
9,116
115
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=input().split() a=int(a) b=int(b) c=int(c) ls=[a,b,c] ls.sort() if a+b==c: print("Yes") else: print("No")
s969322870
Accepted
28
9,116
127
a,b,c=input().split() a=int(a) b=int(b) c=int(c) ls=[a,b,c] ls.sort() if ls[0]+ls[1]==ls[2]: print("Yes") else: print("No")
s813656753
p03796
u479638406
2,000
262,144
Wrong Answer
29
2,940
72
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
n = int(input()) v = 1 for _ in range(n): v = v*v print(v%(1e9+7))
s208019434
Accepted
72
2,940
109
n = int(input()) v = 1 for i in range(n): v = v*(i+1) if v >= 1e9+7: v = v%(int(1e9)+7) print(v)
s073283548
p03759
u235376569
2,000
262,144
Wrong Answer
17
2,940
104
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 = [int(x) for x in input().rstrip().split()] if b-c == c-b: print("YES") else: print("NO")
s325940368
Accepted
19
2,940
104
a,b,c = [int(x) for x in input().rstrip().split()] if b-a == c-b: print("YES") else: print("NO")
s959672181
p02833
u077291787
2,000
1,048,576
Wrong Answer
17
2,940
139
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
# ABC148E - Double Factorial def main(): N = int(input()) if N % 2 == 1: print(0) if __name__ == "__main__": main()
s257299697
Accepted
17
2,940
253
# ABC148E - Double Factorial def main(): N = int(input()) if N % 2: print(0) else: N //= 10 ans = N while N: N //= 5 ans += N print(ans) if __name__ == "__main__": main()
s845161816
p03351
u755944418
2,000
1,048,576
Wrong Answer
17
2,940
130
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,x = map(int, input().split()) if abs(c-a) <= x or (abs(c-b) <= x and abs(b-a) <= x): print('YES') else: print('NO')
s270525453
Accepted
17
2,940
130
a,b,c,x = map(int, input().split()) if abs(c-a) <= x or (abs(c-b) <= x and abs(b-a) <= x): print('Yes') else: print('No')
s258519361
p02388
u451779396
1,000
131,072
Wrong Answer
20
7,312
14
Write a program which calculates the cube of a given integer x.
input("x")*3
s206780586
Accepted
20
7,672
27
x=int(input()) print(x**3)
s584002802
p03067
u452844010
2,000
1,048,576
Wrong Answer
19
3,060
180
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.
import sys str = input() if str[0] < str[2]: if str[1] > str[2]: print('Yes') exit(0) if str[0] > str[2]: if str[1] < str[2]: print('Yes') exit(0) print('No')
s744694762
Accepted
17
3,064
252
import sys str = input().split() str[0] = int(str[0]) str[1] = int(str[1]) str[2] = int(str[2]) if str[0] < str[2]: if str[1] > str[2]: print('Yes') exit(0) if str[0] > str[2]: if str[1] < str[2]: print('Yes') exit(0) print('No')
s102396167
p02601
u330661451
2,000
1,048,576
Time Limit Exceeded
2,205
9,252
252
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
def main(): a,b,c = map(int,input().split()) k = int(input()) i = 0 while a >= b: a *= 2 i += 1 while b >= c: b *= 2 i += 1 print("Yes" if i <= k else "No") if __name__ == '__main__': main()
s110683976
Accepted
32
9,096
252
def main(): a,b,c = map(int,input().split()) k = int(input()) i = 0 while a >= b: b *= 2 i += 1 while b >= c: c *= 2 i += 1 print("Yes" if i <= k else "No") if __name__ == '__main__': main()
s653926194
p03049
u760794812
2,000
1,048,576
Wrong Answer
39
3,700
453
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
N = int(input()) counter = 0 S = [] for s in range(N): s = input() S.append(s) S0 = S[0] a0 = S0.count('A') b0 = S0.count('B') counter += min(a0,b0) a_counter = 0 if a0 > b0: a_counter +=1 for i in range(N-1): ST = S[i+1] a = ST.count('A') b = ST.count('B') if (a_counter == 1) and (b > 1): counter +=1 b = b -1 counter += min(a,b) if a > b: a_couter = 1 else: a_counter = 0 print(counter)
s641023968
Accepted
46
9,192
348
n = int(input()) xa = 0 by = 0 ba = 0 counter = 0 for _ in range(n): s = input() counter += s.count('AB') if s[0]=='B': if s[-1]=='A': ba += 1 else: by += 1 elif s[-1] == 'A': xa += 1 if ba == 0: counter += min(xa,by) else: if xa+by== 0: counter += ba -1 else: counter += ba + min(xa,by) print(counter)
s487606001
p03567
u403753892
2,000
262,144
Wrong Answer
19
3,188
89
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
import re s = input() m = re.match("AC",s) if m: print("Yes") else: print("No")
s213137794
Accepted
19
3,188
91
import re s = input() m = re.search("AC",s) if m: print("Yes") else: print("No")
s165725881
p03048
u373046572
2,000
1,048,576
Wrong Answer
2,104
2,940
189
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
r,g,b,n = map(int,input().split()) cnt = 0 for i in range(n // r + 1): for j in range(n // g + 1): c = n - i * r - j * g if c % b == 0: cnt += 1 print(cnt)
s018631133
Accepted
1,912
2,940
228
r,g,b,n = map(int,input().split(" ")) cnt = 0 for i in range(n // r + 1): for j in range(n // g + 1): c = n - i * r - j * g if c < 0: break if c % b == 0: cnt += 1 print(cnt)
s964557839
p02694
u470189643
2,000
1,048,576
Wrong Answer
23
9,156
134
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()) yen=100 for i in range(3760): yen=math.floor(yen*1.01) if yen>X: break print(i+1)
s673355159
Accepted
22
9,160
145
import math X=int(input()) yen=int(100) for i in range(3800): yen=int(math.floor(yen*1.01)) if yen>=X: break print(i+1)
s184322541
p03679
u487288850
2,000
262,144
Wrong Answer
26
9,144
114
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 b<=a: print('delicious') elif b<=x: print("safe") else: print("dangerous")
s088428273
Accepted
25
8,960
116
x,a,b=map(int,input().split()) if b<=a: print('delicious') elif b-a<=x: print("safe") else: print("dangerous")
s516867516
p03720
u858670323
2,000
262,144
Wrong Answer
17
3,060
204
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n,m = map(int,input().rstrip().split(' ')) G = [[]]*n for i in range(m): a,b = map(int,input().rstrip().split(' ')) a-=1 b-=1 G[a].append(b) G[b].append(a) for i in range(n): print(len(G[i]))
s965643661
Accepted
17
3,060
221
n,m = map(int,input().rstrip().split(' ')) G = [[] for i in range(n)] for i in range(m): a,b = map(int,input().rstrip().split(' ')) a-=1 b-=1 G[a].append(b) G[b].append(a) for i in range(n): print(len(G[i]))
s068113076
p03370
u912652535
2,000
262,144
Wrong Answer
17
2,940
121
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
n , x = map(int,input().split()) m = [int(input()) for i in range(n)] print(m) total = sum(m) print((x-total)//min(m)+n)
s033526261
Accepted
18
2,940
113
n , x = map(int,input().split()) m = [int(input()) for i in range(n)] total = sum(m) print((x-total)//min(m)+n)
s301159521
p03456
u839953865
2,000
262,144
Wrong Answer
25
3,060
180
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a,b=map(str,input().split()) k=int(a+b) c=0 for i in range(1,k): if k%(k-i)==0: c=k-i break print(k) print(c) if k==c*c: print("Yes") else: print("No")
s977067009
Accepted
29
2,940
127
a,b=map(str,input().split()) k=int(a+b) c=0 for i in range(1,k): if k==i*i: print("Yes") exit() print("No")
s954932904
p03456
u198058633
2,000
262,144
Wrong Answer
17
2,940
97
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 sq=math.sqrt(int("".join(input().split()))) print("YES" if sq.is_integer() else "NO")
s217556097
Accepted
17
2,940
78
s=int(input().replace(" ", "")) print("Yes" if int(s**0.5)**2 == s else "No")
s415538180
p02406
u427088273
1,000
131,072
Wrong Answer
20
7,660
82
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; }
num = int(input()) print(' '.join([str(i) for i in range(1,num+1) if i % 3 == 0]))
s639166253
Accepted
40
7,868
96
print(' ' + ' '.join(str(i) for i in range(1, int(input()) + 1) if i % 3 == 0 or '3' in str(i)))
s227772556
p03693
u430483125
2,000
262,144
Wrong Answer
21
3,316
106
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 = input().split() number = int(r+g+b) if number % 4 ==0: print('Yes') else: print('No')
s009881950
Accepted
17
2,940
106
r, g, b = input().split() number = int(r+g+b) if number % 4 ==0: print('YES') else: print('NO')
s472997377
p02796
u340781749
2,000
1,048,576
Wrong Answer
241
18,260
321
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
import sys from operator import itemgetter n = int(input()) robots = [] for line in sys.stdin: X, L = map(int, line.split()) l, r = X - L, X + L robots.append((l, r)) robots.sort(key=itemgetter(1)) curr = -1 ans = 0 for l, r in robots: if curr > l: continue ans += 1 curr = r print(ans)
s824490819
Accepted
250
18,260
330
import sys from operator import itemgetter n = int(input()) robots = [] for line in sys.stdin: X, L = map(int, line.split()) l, r = X - L, X + L robots.append((l, r)) robots.sort(key=itemgetter(1)) curr = -(10 ** 10) ans = 0 for l, r in robots: if curr > l: continue ans += 1 curr = r print(ans)
s579504405
p04043
u083593845
2,000
262,144
Wrong Answer
17
2,940
134
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a,b,c = map(int, input().split()) s = {a,b,c} list1 = [a,b,c] if s == {5,7} and sum(list1) == 17: print("Yes") else : print("No")
s258957569
Accepted
19
3,060
133
a,b,c = map(int, input().split()) s = {a,b,c} list1 = [a,b,c] if s == {5,7} and sum(list1) == 17: print("YES") else : print("NO")
s206784741
p02612
u556594202
2,000
1,048,576
Wrong Answer
27
8,876
31
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N//1000)
s072730618
Accepted
27
9,052
73
N = int(input()) if N%1000==0: print(0) else: print(1000-N%1000)
s507607524
p03478
u843318925
2,000
262,144
Wrong Answer
37
3,060
172
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()) total = 0 for i in range(n): s = str(i + 1) x = sum(list(map(int, s))) if x >= a & x <= b: total += x print(total)
s698322923
Accepted
35
3,060
161
n, a, b = map(int, input().split()) total = 0 for i in range(1, n + 1): s = str(i) if a <= sum(list(map(int, s))) <= b: total += i print(total)
s899955683
p03659
u875361824
2,000
262,144
Wrong Answer
2,104
136,876
309
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
def main(): N = int(input().strip()) a = list(map(int, input().strip().split())) min_v = float("inf") for i in range(1, N): print(a[:i], a[i:]) x = sum(a[:i]) y = sum(a[i:]) min_v = min(min_v, abs(x - y)) print(min_v) if __name__ == '__main__': main()
s286247520
Accepted
160
24,492
643
def main(): N = int(input()) A = list(map(int, input().split())) solve(N,A) def solve(N,A): ans = float("inf") # ans = TLE(N,A,ans) ans = AC(N,A,ans) print(ans) def TLE(N,A, ans): for i in range(1, N): snk = sum(A[:i]) ari = sum(A[i:]) ans = min(ans, abs(snk - ari)) return ans def AC(N,A,ans): cum_A = [None] * N cum_A[0] = A[0] for i in range(1, N): cum_A[i] = cum_A[i-1] + A[i] for i in range(N-1): snk = cum_A[i] ari = cum_A[-1] - snk ans = min(ans, abs(snk - ari)) return ans if __name__ == "__main__": main()
s412692028
p02972
u366886346
2,000
1,048,576
Wrong Answer
593
13,900
241
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
n=int(input()) a=list(map(int,input().split())) ans=[0]*n for i in range(n): num1=n-i num2=0 for j in range((n//num1)-1): num2+=ans[num1*(j+2)-1] num2%=2 ans[-1-i]=(num2+a[-1-i])%2 print(ans.count(1)) print(*ans)
s143299754
Accepted
597
17,804
333
n=int(input()) a=list(map(int,input().split())) ans=[0]*n for i in range(n): num1=n-i num2=0 for j in range((n//num1)-1): num2+=ans[num1*(j+2)-1] num2%=2 ans[-1-i]=(num2+a[-1-i])%2 print(ans.count(1)) ans2=[] for i in range(n): if ans[i]==1: ans2.append(i+1) if len(ans2)!=0: print(*ans2)
s941772451
p03386
u729938879
2,000
262,144
Wrong Answer
2,242
4,212
129
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a, b, k = map(int, input().split()) num = [i for i in range(a, b+1)] ans= set(num[:k]).union(num[-k:]) for i in ans: print(i)
s586355860
Accepted
18
3,060
228
a, b, k = map(int, input().split()) length = b+1 -a num = [] for i in range(a, min(b, a+k-1)+1): print(i) num.append(i) for i in range(max(a, b - (k-1)), b+1): if i not in num: num.append(i) print(i)
s763832908
p04031
u188827677
2,000
262,144
Wrong Answer
29
9,064
175
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
n = int(input()) a = list(map(int, input().split())) m = sum(a)/n if int(m)+1 - m < m - int(m): m = int(m)+1 else: int(m) ans = 0 for i in a: ans += abs(i - m)**2 print(ans)
s706301903
Accepted
29
9,028
183
n = int(input()) a = list(map(int, input().split())) m = sum(a)//n ans = float("inf") for i in range(m, m+2): t = 0 for j in a: t += abs(j-i)**2 ans = min(t,ans) print(ans)
s581367115
p03377
u305965165
2,000
262,144
Wrong Answer
17
2,940
103
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = [int(i) for i in input().split()] if a<=x and x<=a+b: print("Yes") else: print("No")
s996332439
Accepted
18
2,940
103
a, b, x = [int(i) for i in input().split()] if a<=x and x<=a+b: print("YES") else: print("NO")
s928406837
p03434
u992076031
2,000
262,144
Wrong Answer
17
3,060
240
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
N = int(input()) alist = input().split() alist = sorted(alist, reverse=True) print(alist) count = 1 alice = 0 bob = 0 for a in alist: if count % 2: alice += int(a) else: bob += int(a) count+=1 print(alice - bob)
s960353920
Accepted
18
3,060
252
N = int(input()) alist = input().split() aint = list(map(int, alist)) aint = sorted(aint, reverse=True) count = 1 alice = 0 bob = 0 for a in aint: if count % 2: alice += a else: bob += a count = count + 1 print(alice - bob)
s118831430
p03721
u503901534
2,000
262,144
Wrong Answer
293
3,060
185
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
n, k = map(int,input().split()) aa = 0 for i in range(n): a,b = map(int,input().split()) if k -b < 0: None else: aa = a k = k - b print(aa)
s979746519
Accepted
392
13,100
383
n, k = map(int,input().split()) dcic = {} aa = set([]) for i in range(n): a,b = map(int,input().split()) aa.add(a) if a in dcic: dcic[a] = dcic[a] + b else: dcic.update({a:b}) bb = list(sorted(list(aa))) cc = 0 s = 0 for i in range(len(bb)): if s < k: s = s + dcic[bb[i]] cc = bb[i] else: ccc = bb[i] print(cc)
s801875166
p03166
u479719434
2,000
1,048,576
Wrong Answer
500
23,936
920
There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
from collections import deque def main(): N, M = map(int, input().split()) e = [[] for _ in range(N)] input_edges = [0]*N for i in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 e[u].append(v) input_edges[v] += 1 queue = deque() for i, input_edge in enumerate(input_edges): if input_edge == 0: queue.appendleft(i) topological_sorted = [] while queue: v = queue.pop() topological_sorted.append(v) for other_side in e[v]: input_edges[other_side] -= 1 if input_edges[other_side] == 0: queue.appendleft(other_side) dp = [10 ** 9] * N dp[topological_sorted[0]] = 0 for v in topological_sorted: for other_side in e[v]: dp[other_side] = min(dp[v] + 1, dp[other_side]) print(max(dp)) if __name__ == "__main__": main()
s088394933
Accepted
584
59,008
580
import sys sys.setrecursionlimit(10**6) def dfs(v): global dp if dp[v] != -1: return dp[v] res = 0 for next_v in e[v]: res = max(dfs(next_v) + 1, res) dp[v] = res return res def main(): N, M = map(int, input().split()) global e e = [[] for _ in range(N)] for i in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 e[u].append(v) global dp dp = [-1]*N ans = -1 for v in range(N): ans = max(ans, dfs(v)) print(ans) if __name__ == "__main__": main()
s663577792
p03162
u652150585
2,000
1,048,576
Wrong Answer
611
33,908
221
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
n=int(input()) l=[list(map(int,input().split())) for _ in range(n)] dp=[0]*3 for i in range(n): dp[0],dp[1],dp[2]=max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2] print(dp) print(max(dp))
s796168522
Accepted
473
30,580
222
n=int(input()) l=[list(map(int,input().split())) for _ in range(n)] dp=[0]*3 for i in range(n): dp[0],dp[1],dp[2]=max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2] #print(dp) print(max(dp))