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
s213551943
p03730
u984664611
2,000
262,144
Wrong Answer
17
3,064
746
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 a_mod = a % b if a_mod == 0 and c == 0: flag = True elif a_mod == 0: pass elif c % a_mod == 0: flag = True else: # c % ((a%b*n)%b) == 0 for i in range(1, b-1): ia_mod = (i*a_mod) % b if ia_mod == 0: continue elif c % ia_mod == 0: flag = True break if flag: print('Yes') else: print('No')
s357461401
Accepted
17
3,060
746
a, b, c = map(int, input().split()) flag = False a_mod = a % b if a_mod == 0 and c == 0: flag = True elif a_mod == 0: pass elif c % a_mod == 0: flag = True else: # c % ((a%b*n)%b) == 0 for i in range(1, b-1): ia_mod = (i*a_mod) % b if ia_mod == 0: continue elif c % ia_mod == 0: flag = True break if flag: print('YES') else: print('NO')
s425386126
p02645
u730807152
2,000
1,048,576
Wrong Answer
23
9,020
30
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
a = str(input()) print(a[3:])
s457037840
Accepted
23
9,088
26
a = input() print(a[0:3])
s863321400
p02399
u369313788
1,000
131,072
Wrong Answer
20
7,712
97
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(i) for i in input().split()] d = a // b r = a % b f = a / b print((d),(r),float(f))
s928231224
Accepted
30
7,708
114
a, b = [int(i) for i in input().split()] d = a // b r = a % b f = a / b print("{0} {1} {2:.5f}".format(d, r, f))
s677300546
p03997
u059210959
2,000
262,144
Wrong Answer
50
6,092
347
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.
# encoding:utf-8 import copy import random import bisect import fractions import math import sys mod = 10**9+7 sys.setrecursionlimit(mod) a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s516418002
Accepted
54
6,604
348
# encoding:utf-8 import copy import random import bisect import fractions import math import sys mod = 10**9+7 sys.setrecursionlimit(mod) a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s713510595
p03469
u077852398
2,000
262,144
Wrong Answer
29
9,012
36
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.
a = input() a.replace('2017','2018')
s645823252
Accepted
32
8,980
43
a = input() print(a.replace('2017','2018'))
s679801005
p03644
u816070625
2,000
262,144
Wrong Answer
17
2,940
85
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()) i=0 while 2**i<N: i+=1 if 2**i==N: print(i) else: print(i-1)
s831812123
Accepted
17
2,940
93
N=int(input()) i=0 while 2**i<N: i+=1 if 2**i==N: print(2**i) else: print(2**(i-1))
s260967876
p03712
u190525112
2,000
262,144
Wrong Answer
18
3,060
221
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.
x = list(map(int, input().split())) a=[input() for i in range(x[0])] for i in range(x[1]): print('#',end="") print('') for i in a: print('#{0}#'.format(i)) for i in range(x[1]): print('#',end="") print('')
s336169787
Accepted
18
3,060
224
x = list(map(int, input().split())) a=[input() for i in range(x[0])] for i in range(x[1]+2): print('#',end="") print('') for i in a: print('#{0}#'.format(i)) for i in range(x[1]+2): print('#',end="") print('')
s084407776
p03067
u548308904
2,000
1,048,576
Wrong Answer
17
3,060
231
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.
inp = [int(f) for f in input().split()] if inp[0] > inp[2]: if inp[1] < inp[2]: print('Yes') else: print('No') elif inp[0] > inp[2]: if inp[1] < inp[2]: print('Yes') else: print('No')
s972661455
Accepted
17
3,060
231
inp = [int(f) for f in input().split()] if inp[0] > inp[2]: if inp[1] < inp[2]: print('Yes') else: print('No') elif inp[0] < inp[2]: if inp[1] > inp[2]: print('Yes') else: print('No')
s561324352
p02397
u602702913
1,000
131,072
Wrong Answer
60
5,616
125
Write a program which reads two integers x and y, and prints them in ascending order.
while True: x,y=map(int,input().split()) if x<y: print(x,y) elif y<x: print(y,x) elif x==y==0: break
s480636179
Accepted
50
5,608
204
while True: x,y=map(int,input().split()) if x<y: print(x,y) continue elif y<x: print(y,x) continue elif x and y !=0: print(x,y) continue elif x==y==0: break
s930206806
p03943
u689835643
2,000
262,144
Wrong Answer
17
3,064
138
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.
x, y, z = map(int, input().split()) i = x + y + z if i - max(x, y, z) < max(x, y, z) or i % 2 != 0: print('NO') else: print('YES')
s954740923
Accepted
17
2,940
141
x, y, z = map(int, input().split()) i = x + y + z if i - max(x, y, z) == max(x, y, z) and i % 2 == 0: print('Yes') else: print('No')
s615715023
p03548
u178432859
2,000
262,144
Wrong Answer
17
2,940
51
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()) print(x//(y+z+1))
s342697790
Accepted
17
2,940
100
x,y,z = map(int, input().split()) if x%(y+z) >= z: print(x//(y+z)) else: print((x//(y+z))-1)
s453842794
p02842
u606090886
2,000
1,048,576
Wrong Answer
17
2,940
38
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
n = int(input()) print((n/108*100)//1)
s337992287
Accepted
17
2,940
181
n = int(input()) flag = False x = int(n / 108 * 100) for i in range(x-5,x+5): if int(i*1.08) == n: flag = True x = i if flag: print(x) else: print(":(")
s095296932
p03836
u733337827
2,000
262,144
Wrong Answer
17
3,060
176
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) dx = tx-sx dy = ty-sy s = 'R'*dx + 'U'*dy s += 'L'*dx + 'D'*dy s += 'D' + 'R'*(dx+1) + 'U'*dy s += 'U' + 'L'*(dx+1) + 'D'*dy print(s)
s664520381
Accepted
17
3,064
197
sx, sy, tx, ty = map(int, input().split()) dx = tx-sx dy = ty-sy s = 'U'*dy + 'R'*dx s += 'D'*dy + 'L'*dx s += 'L' + 'U'*(dy+1) + 'R'*(dx+1) + 'D' s += 'R' + 'D'*(dy+1) + 'L'*(dx+1) + 'U' print(s)
s018708989
p02972
u821432765
2,000
1,048,576
Wrong Answer
2,104
12,004
259
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())) eo=[] ans=[] for i in range(n): k=eo[:i+1:n-i] if len(k) <= 1: eo.append(a[-(i+1)]) else: eo.append((sum(eo)+a[n-i-1])%2) if eo[-1]==1: ans.append(i+1) eo=eo[::-1] print(eo.count(1)) print(*ans)
s315422834
Accepted
476
17,192
453
from math import ceil N = int(input()) D = ceil(N/2) A = [0] + [int(i) for i in input().split()] boxes = [0] * (N+1) # 1-indexed for i in range(D, N+1): boxes[i] = A[i] for i in range(N-D, 0, -1): c = 0 for j in range(i+i, N+1, i): if boxes[j]: c ^= 1 if c==A[i]: boxes[i]=0 else: boxes[i]=1 res = set() for i in range(1, N+1): if boxes[i]: res.add(i) print(len(res)) print(*res)
s538983044
p03563
u391328897
2,000
262,144
Wrong Answer
17
2,940
49
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
r = int(input()) g = int(input()) print((g-r)/2)
s295426363
Accepted
17
2,940
49
r = int(input()) g = int(input()) print(2*g - r)
s869584752
p02742
u613292673
2,000
1,048,576
Wrong Answer
18
2,940
109
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
H, W = list(map(int, input().split())) n = -(-H // 2) if (W % 2) == 0: print(n*W) else: print(n*W-1)
s794627347
Accepted
17
2,940
101
H, W = list(map(int, input().split())) if H == 1 or W ==1: print(1) else: print(-(-H*W // 2))
s608574513
p03623
u073139376
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|.
x, a, b = map(int, input().split()) print(['B', 'A'][abs(x - a) > abs(x - b)])
s823107838
Accepted
17
2,940
79
x, a, b = map(int, input().split()) print(['A', 'B'][abs(x - a) > abs(x - b)])
s241385168
p03457
u731368968
2,000
262,144
Wrong Answer
410
3,064
365
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
def intime(t, dx, dy): x, y = map(abs, (dx, dy)) if t < 2 and x == 0 and y: return False return True if dx + dy < t else False N = int(input()) bx, by = 0, 0 ans = True for i in range(N): t, x, y = map(int, input().split()) if not intime(t, x - bx, y - by): ans = False bt, bx, by = t, x, y print('Yes' if ans else 'No')
s291103014
Accepted
384
3,064
246
n = int(input()) bt,bx,by=0,0,0 ans=True for i in range(n): t, x, y = map(int, input().split()) dt=t-bt l=abs(x-bx)+abs(y-by) if dt<l: ans = False if (dt-l)%2:ans=False bt,bx,by=t,x,y print('Yes' if ans else 'No')
s871686256
p03997
u316386814
2,000
262,144
Wrong Answer
17
2,940
86
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()) ans = (a + b) * h / 2 print(ans)
s861118114
Accepted
17
2,940
87
a = int(input()) b = int(input()) h = int(input()) ans = (a + b) * h // 2 print(ans)
s235209702
p03371
u155828990
2,000
262,144
Wrong Answer
17
3,060
160
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
a,b,c,x,y=map(int,input().split()) a=0 c*=2 if(x>y): a=min((a*x+b*y),((x-y)*a+y*c),c*max(x,y)) else: a=min((a*x+b*y),((y-x)*a+y*c),c*max(x,y)) print(a)
s055105236
Accepted
19
3,060
159
a,b,c,x,y=map(int,input().split()) s=0 c*=2 if(x>y): s=min((a*x+b*y),((x-y)*a+y*c),c*max(x,y)) else: s=min((a*x+b*y),((y-x)*b+x*c),c*max(x,y)) print(s)
s641559534
p03379
u666198201
2,000
262,144
Wrong Answer
428
25,556
273
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
N=int(input()) A=list(map(int,input().split())) B=[] if N==2: print(A[1]) print(A[0]) exit(0) for i in range(N): B.append(A[i]) B.sort() print(A) print(B) for i in range(N): if A[i]<B[N//2+1]: print(B[N//2]) else: print(B[N//2-1])
s821751434
Accepted
367
25,220
254
N=int(input()) A=list(map(int,input().split())) B=[] if N==2: print(A[1]) print(A[0]) exit(0) for i in range(N): B.append(A[i]) B.sort() for i in range(N): if A[i]<B[N//2]: print(B[N//2]) else: print(B[N//2-1])
s613531412
p03486
u857330600
2,000
262,144
Wrong Answer
17
3,060
173
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=sorted(str(input())) t=sorted(str(input())) t.reverse() print(s,t) l=[s,t] lis=sorted(l) if s==t: print('No') else: if l==lis: print('Yes') else: print('No')
s597542416
Accepted
17
2,940
162
s=sorted(str(input())) t=sorted(str(input())) t.reverse() l=[s,t] lis=sorted(l) if s==t: print('No') else: if l==lis: print('Yes') else: print('No')
s725730232
p02613
u247066121
2,000
1,048,576
Wrong Answer
155
16,328
386
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)] count_AC, count_WA, count_TLE, count_RE = 0, 0, 0, 0 for s in S: if s == 'AC': count_AC+=1 elif s == 'WA': count_WA+=1 elif s == 'TLE': count_TLE+=1 else: count_RE+=1 print('AC × '+str(count_AC)) print('WA × '+str(count_WA)) print('TLE × '+str(count_TLE)) print('RE × '+str(count_RE))
s783669932
Accepted
149
16,192
382
N = int(input()) S = [input() for i in range(N)] count_AC, count_WA, count_TLE, count_RE = 0, 0, 0, 0 for s in S: if s == 'AC': count_AC+=1 elif s == 'WA': count_WA+=1 elif s == 'TLE': count_TLE+=1 else: count_RE+=1 print('AC x '+str(count_AC)) print('WA x '+str(count_WA)) print('TLE x '+str(count_TLE)) print('RE x '+str(count_RE))
s618404238
p03721
u112007848
2,000
262,144
Wrong Answer
219
27,284
190
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(" ")) a = [list(map(int, input().split(" "))) for i in range(n)] count = 0 for x, y in a: count += y if k >= y: print(x) break else: print("None")
s300312185
Accepted
396
28,404
202
n, k = map(int, input().split(" ")) a = sorted([list(map(int, input().split(" "))) for i in range(n)]) count = 0 for x, y in a: count += y if k <= count: print(x) break else: print("None")
s042155610
p03846
u013408661
2,000
262,144
Wrong Answer
55
14,008
311
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
n=int(input()) a=list(map(int,input().split())) stack=[0]*(10**5+1) p=10**9+7 for i in a: stack[i]+=1 if n%2==0: for j in range(1,n+1,2): if stack[j]!=1: print(0) exit() print(pow(2,n//2,p)) exit() for j in range(0,n+1,2): if stack[j]!=1: print(0) exit() print(pow(2,n//2,p))
s018697770
Accepted
57
14,008
365
n=int(input()) a=list(map(int,input().split())) stack=[0]*(10**5+1) p=10**9+7 for i in a: stack[i]+=1 if n%2==0: for j in range(1,n+1,2): if stack[j]!=2: print(0) exit() print(pow(2,n//2,p)) exit() for j in range(0,n+1,2): if j==0 and stack[j]==1: continue if j!=0 and stack[j]!=2: print(0) exit() print(pow(2,n//2,p)) exit()
s078941371
p02865
u434282696
2,000
1,048,576
Wrong Answer
17
2,940
51
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n = int(input());print(n//2 if n%2==0 else n//2 -1)
s135645112
Accepted
17
2,940
51
n = int(input());print(n//2 if n%2==1 else n//2 -1)
s969160730
p03719
u410903849
2,000
262,144
Wrong Answer
26
9,096
155
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
A, B, C = map(int, input().split()) if C >= A and C <= B: print('YES') else: print('NO')
s819852638
Accepted
27
9,164
97
A, B, C = map(int, input().split()) if C >= A and C <= B: print('Yes') else: print('No')
s854377268
p03469
u516242950
2,000
262,144
Wrong Answer
17
2,940
90
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.
date = input().split('/') date[0] == '2018' print(date[0] + '/' + date[1] + '/' + date[2])
s157669366
Accepted
17
2,940
90
date = input().split('/') date[0] = '2018' print(date[0] + '/' + date[1] + '/' + date[2])
s561096528
p03416
u870998297
2,000
262,144
Wrong Answer
56
2,940
155
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
A, B = [int(i) for i in input().split()] count = 0 for i in range(A, B+1): str_A = str(A) if str_A == str_A[::-1]: count += 0 print(count)
s496840417
Accepted
52
2,940
155
A, B = [int(i) for i in input().split()] count = 0 for i in range(A, B+1): str_i = str(i) if str_i == str_i[::-1]: count += 1 print(count)
s548892522
p03997
u881472317
2,000
262,144
Wrong Answer
19
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)
s366193756
Accepted
17
2,940
79
a = int(input()) b = int(input()) h = int(input()) print(int((a + b) * h / 2))
s281348354
p00005
u877201735
1,000
131,072
Wrong Answer
30
7,624
218
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
def gcd(a, b): if (a % b) == 0: return b return gcd(b, a%b) while True: try: nums = list(map(int, input().split())) print(gcd(nums[0], nums[1])) except EOFError: break
s191881532
Accepted
20
7,628
287
def gcd(a, b): if (a % b) == 0: return b return gcd(b, a%b) def lcd(a, b): return a * b // gcd(a, b) while True: try: nums = list(map(int, input().split())) print(gcd(nums[0], nums[1]), lcd(nums[0], nums[1])) except EOFError: break
s140394836
p03478
u905582793
2,000
262,144
Wrong Answer
40
3,060
193
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).
def sm(x): xls=list(str(x)) a=0 for i in range(len(xls)): a+=int(xls[i]) return a n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): if a<=sm(i)<=b: ans+=1 print(ans)
s144972359
Accepted
37
3,060
193
def sm(x): xls=list(str(x)) a=0 for i in range(len(xls)): a+=int(xls[i]) return a n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): if a<=sm(i)<=b: ans+=i print(ans)
s959690123
p03574
u411858517
2,000
262,144
Wrong Answer
32
3,572
613
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.
W,H=map(int,input().split()) arr = [input() for j in range(W)] ans = [['0' for i in range(H)] for j in range(W)] for i in range(0, W): for j in range(0, H): bomb_num = 0 if arr[i][j] == '#': ans[i][j] = '#' break for k in (-1, 0, 1): for l in (-1, 0, 1): if (-1<i+k<W) and (-1<j+l<H): if arr[i+k][j+l] == '#': bomb_num += 1 ans[i][j] = str(bomb_num) for i in range(W): for j in range(H): print(ans[i][j], end = '') print('\n')
s408749925
Accepted
28
3,064
567
W, H=map(int,input().split()) arr = [input() for j in range(W)] ans = ['' for i in range(W)] for i in range(0, W): for j in range(0, H): bomb_num = 0 if arr[i][j] == '#': ans[i] += '#' else: for k in (-1, 0, 1): for l in (-1, 0, 1): if (-1<i+k<W) and (-1<j+l<H): if arr[i+k][j+l] == '#': bomb_num += 1 ans[i] += str(bomb_num) for i in range(W): print(ans[i])
s056769285
p03054
u543954314
2,000
1,048,576
Wrong Answer
44
3,896
472
We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a string of length N. Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: `L`, `R`, `U` and `D`. The game consists of N steps. The i-th step proceeds as follows: * First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece. * Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece. Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done. Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.
from collections import Counter h,w,n = map(int, input().split()) sx,sy = map(int, input().split()) sd = Counter(input()) td = Counter(input()) wb,hb = 0,0 a1 = (sd["L"]+1,w-sd["R"]) a2 = (sx-td["L"],sx+td["R"]) if (a1[0] <= a1[1] and (a1[0]<=a2[1] or a1[1]<=a2[0])) or a2[0]>a2[1]: wb = 1 b1 = (sd["U"]+1,w-sd["D"]) b2 = (sy-td["U"],sy+td["D"]) if (b1[0] <= b1[1] and (b1[0]<=b2[1] or b1[1]<=b2[0])) or b2[0]>b2[1]: hb = 1 if wb&hb: print("YES") else: print("NO")
s239973174
Accepted
216
3,888
630
h,w,n = map(int,input().split()) sr,sc = map(int,input().split()) t = input() s = input() hei = [1,h] wid = [1,w] for i in range(n-1,-1,-1): if s[i] == "L": wid[1] = min(wid[1]+1,w) elif s[i] == "R": wid[0] = max(wid[0]-1,1) elif s[i] == "U": hei[1] = min(hei[1]+1,h) elif s[i] == "D": hei[0] = max(hei[0]-1,1) if t[i] == "L": wid[0] += 1 elif t[i] == "R": wid[1] -= 1 elif t[i] == "U": hei[0] += 1 elif t[i] == "D": hei[1] -= 1 if wid[0]>wid[1] or hei[0]>hei[1]: print("NO") exit(0) if hei[0] <= sr <= hei[1] and wid[0] <= sc <= wid[1]: print("YES") else: print("NO")
s575266742
p03565
u625963200
2,000
262,144
Wrong Answer
17
3,064
404
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`.
S=list(input()) T=list(input()) if len(S)<len(T): print('UNRESTORABLE') else: for i in range(0,len(S)-len(T)+1): flag=False for j in range(i,len(T)): if S[j]=='?' and S[j]==T[j-i]: flag=True else: flag=False if flag: S[i:]=T for j in range(len(S)): if S[j]=='?': S[j]='a' print(*S,sep='') exit() print('UNRESTORABLE')
s669713063
Accepted
17
3,064
314
S=list(input()) T=list(input()) ans='' for i in range(len(S)-len(T)+1): for j in range(i,i+len(T)): if S[j]!=T[j-i] and S[j]!='?': break else: ans=S[:i]+T+S[i+len(T):] if ans=='': print('UNRESTORABLE') else: for i in range(len(ans)): if ans[i]=='?': ans[i]='a' print(*ans,sep='')
s494771220
p03486
u777028980
2,000
262,144
Wrong Answer
17
3,060
250
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
hoge=list(input()) huga=list(input()) hoge.sort() huga.sort() flag=0 for i in range(min(len(hoge),len(huga))): if(hoge[i]>huga[i]): flag=1 if(flag==0): if(len(hoge)>len(huga)): flag=1 if(flag==0): print("Yes") else: print("No")
s980114106
Accepted
17
3,064
326
hoge=list(input()) huga=list(input()) hoge.sort() huga.sort(reverse=True) flag=0 for i in range(min(len(hoge),len(huga))): if(hoge[i]>huga[i]): flag=1 break elif(hoge[i]<huga[i]): flag=-1 break if(flag==0): if(len(hoge)>=len(huga)): flag=1 if(flag==1): print("No") else: print("Yes")
s151224467
p03385
u897302879
2,000
262,144
Wrong Answer
17
2,940
50
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
print('Yes' if sorted(input()) == 'abc' else 'No')
s565286090
Accepted
19
3,060
59
print('Yes' if ''.join(sorted(input())) == 'abc' else 'No')
s301794859
p03050
u140137089
2,000
1,048,576
Wrong Answer
498
3,316
150
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
N = int(input()) tmp = N ** 0.5 sum = 0 k =1 while k < tmp: m = N // k -1 if N % k == 0 and m > tmp-1 and k < m: sum += m k += 1
s966012110
Accepted
489
3,060
164
N = int(input()) tmp = N ** 0.5 sum = 0 k =1 while k < tmp: m = N // k -1 if N % k == 0 and m > tmp-1 and k < m: sum += m k += 1 print(sum)
s076369152
p03997
u321804710
2,000
262,144
Wrong Answer
17
2,940
75
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()) s = (a + b)*h/2 print(s)
s865858198
Accepted
17
2,940
84
a = int(input()) b = int(input()) h = int(input()) s = int((a + b) * h / 2) print(s)
s683807206
p03605
u052332717
2,000
262,144
Wrong Answer
18
2,940
94
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?
s = input() if s[0:1] == '9' or s[1:1] == '9': print('Yes') else: print('No')
s498774635
Accepted
18
2,940
111
n = list(input()) ans = 0 for s in n: if s == '9': print('Yes') break else: print('No')
s799745183
p03836
u339199690
2,000
262,144
Wrong Answer
17
3,060
147
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) res = "" res += "U" * (ty - sy) + "R" * (tx - sx) res += "D" * (ty - sy) + "L" * (tx - sx) print(res)
s051145290
Accepted
17
3,064
269
sx, sy, tx, ty = map(int, input().split()) res = "" res += "U" * (ty - sy) + "R" * (tx - sx) res += "D" * (ty - sy) + "L" * (tx - sx) res += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D" res += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U" print(res)
s669197101
p02612
u629607744
2,000
1,048,576
Wrong Answer
31
9,200
269
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.
def i(): return int(input()) def i2(): return map(int,input().split()) def s(): return str(input()) def l(): return list(input()) def intl(): return list(int(k) for k in input().split()) n = i() print(n%1000) if n%1000 == 0: print(0) else: print( 1000 - n%1000)
s953555269
Accepted
28
9,176
255
def i(): return int(input()) def i2(): return map(int,input().split()) def s(): return str(input()) def l(): return list(input()) def intl(): return list(int(k) for k in input().split()) n = i() if n%1000 == 0: print(0) else: print( 1000 - n%1000)
s887281546
p02614
u092061507
1,000
1,048,576
Wrong Answer
50
9,212
1,860
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
H, W, K = map(int, input().split()) c = [input() for i in range(H)] """ H = 6 W = 6 K = 3 c = ['...#.#', '...###', '#.....', '...#..', '...###', '...##.'] """ ret = 0 for i in range(2**H): for j in range(2**W): num = 0 mask_h = str(bin(i))[2:].zfill(H) mask_w = str(bin(j))[2:].zfill(W) for k in range(H): if mask_h[k] == '0': continue for l in range(W): if mask_w[l] == '0': continue if c[k][l] == '#': num += 1 if num == K: ret += 1 print('num',num) print (ret)
s823035260
Accepted
49
9,220
1,834
H, W, K = map(int, input().split()) c = [input() for i in range(H)] """ H = 6 W = 6 K = 3 c = ['...#.#', '...###', '#.....', '...#..', '...###', '...##.'] """ ret = 0 for i in range(2**H): for j in range(2**W): num = 0 mask_h = str(bin(i))[2:].zfill(H) mask_w = str(bin(j))[2:].zfill(W) for k in range(H): if mask_h[k] == '0': continue for l in range(W): if mask_w[l] == '0': continue if c[k][l] == '#': num += 1 if num == K: ret += 1 print (ret)
s738299468
p03471
u883792993
2,000
262,144
Wrong Answer
848
3,060
247
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 = list(map(int, input().split())) answer = "-1 -1 -1" for a in range(0,N+1): for b in range(0,N-a+1): c = N-a-b sum = a*10000 + b*5000 + c*1000 if answer == sum: answer = "%s %s %s"%(a,b,c) print(answer)
s938162517
Accepted
855
2,940
243
N,Y = list(map(int, input().split())) answer = "-1 -1 -1" for a in range(0,N+1): for b in range(0,N-a+1): c = N-a-b sum = a*10000 + b*5000 + c*1000 if Y == sum: answer = "%s %s %s"%(a,b,c) print(answer)
s649043223
p02613
u323045245
2,000
1,048,576
Wrong Answer
149
9,204
278
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()) ac=0 wa=0 tle=0 re=0 for i in range(n): tmp = input() if tmp == "AC": ac+=1 elif tmp == "WA": wa+=1 elif tmp == "TLE": tle+=1 else: re+=1 print("AC ×",ac) print("WA ×",wa) print("TLE ×",tle) print("RE ×",re)
s329660783
Accepted
146
9,188
274
n=int(input()) ac=0 wa=0 tle=0 re=0 for i in range(n): tmp = input() if tmp == "AC": ac+=1 elif tmp == "WA": wa+=1 elif tmp == "TLE": tle+=1 else: re+=1 print("AC x",ac) print("WA x",wa) print("TLE x",tle) print("RE x",re)
s160022982
p03455
u970308980
2,000
262,144
Wrong Answer
17
2,940
64
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=map(int,input().split()) print('Even' if a%b==0 else 'Odd')
s415059376
Accepted
17
2,940
89
a, b=map(int, input().split()) if (a * b) % 2 == 0: print('Even') else: print('Odd')
s904656809
p02690
u746206084
2,000
1,048,576
Time Limit Exceeded
2,205
9,224
473
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
x=int(input()) s={0} n=1 stop=0 while(1): N=n**5 for i in s: if N-i==x: if i>0: sig=int(i//abs(i)) else: sig=1 print(n,sig*int(pow(abs(i),1/5))) stop=1 elif N-i==-x: if i>0: sig=int(i//abs(i)) else: sig=1 print(n,sig*int(pow(abs(i),1/5))) stop=1 if stop==1: break s|={N,-N}
s008222038
Accepted
22
9,412
545
x=int(input()) s={0} n=1 stop=0 while(1): N=n**5 for i in s: if N-i==x: if i>0: sig=1 elif i<0: sig=-1 else: sig=0 print(n,int(sig*pow(abs(i),1/5))) stop=1 elif i-N==x: if i>0: sig=1 elif i<0: sig=-1 else: sig=0 print(int(sig*pow(abs(i),1/5)),n) stop=1 if stop==1: break s|={N,-N} n+=1
s831247249
p02389
u797636303
1,000
131,072
Wrong Answer
20
5,580
48
Write a program which calculates the area and perimeter of a given rectangle.
a,b = map(int, input().split()) c=a*b d=2*(a+b)
s109665599
Accepted
20
5,584
59
a,b = map(int, input().split()) c=a*b d=2*(a+b) print(c,d)
s829367862
p03672
u499381410
2,000
262,144
Wrong Answer
17
2,940
122
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() cnt = len(s) while True: if s[:len(s) // 2] == s[len(s) // 2:]: break s = s[:-2] cnt -= 2
s822238942
Accepted
17
3,060
205
s = input() if len(s) % 2: s = s[:-1] else: s = s[:-2] cnt = len(s) while True: if s[:len(s) // 2] == s[len(s) // 2:]: break s = s[:-2] cnt -= 2 print(cnt)
s664322494
p02612
u304590784
2,000
1,048,576
Wrong Answer
31
9,156
158
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()) ans = N for i in range(1,10): ans -= 1000 if ans >= 1000: continue elif 1000 > ans >= 0: print(ans) break
s564905878
Accepted
26
9,156
97
N = int(input()) if N % 1000 != 0: ans = 1000 - (N % 1000) print(ans) else: print(0)
s674299165
p02578
u668078904
2,000
1,048,576
Wrong Answer
131
36,448
202
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
N=int(input()) a=input().split() A=list(map(int,a)) print(A) tmp=0 count=0 for i in range(N): if(i==0): tmp=A[0] if(tmp<=A[i]): #print(A[i]) tmp=A[i] else: count+=1 print(count)
s543218416
Accepted
134
32,372
227
N=int(input()) a=input().split() A=list(map(int,a)) #print(A) tmp=0 spring_high=0 for i in range(N): if(i==0): tmp=A[0] if(tmp<=A[i]): #print(A[i]) tmp=A[i] else: spring_high+=tmp-A[i] print(spring_high)
s136341511
p03486
u630657312
2,000
262,144
Wrong Answer
17
3,060
132
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = list(input()) t = list(input()) s.sort() t.sort() s = ''.join(s) t = ''.join(t) if s < t: print('Yes') else: print('No')
s907272627
Accepted
17
3,060
144
s = list(input()) t = list(input()) s.sort() t.sort() t.reverse() s = ''.join(s) t = ''.join(t) if s < t: print('Yes') else: print('No')
s630885204
p02742
u203669169
2,000
1,048,576
Wrong Answer
50
5,496
570
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
from fractions import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations N = [int(_) for _ in input().split()] H, W = N[0], N[1] def solve(H, W): cnt = 0 for i in range(H): if i % 2 == 0: cnt += int(W / 2) + 1 else: cnt += W - (int(W / 2) + 1) return cnt
s527199740
Accepted
17
3,060
431
from math import floor N = [int(_) for _ in input().split()] H, W = N[0], N[1] def solve(H, W): acnt = floor(W / 2) + 1 bcnt = W - acnt if H == 1 or W == 1: return 1 else: return floor((H * W + 1) / 2) # if H % 2 == 0: # cnt = acnt * floor(H/2) + bcnt * floor(H/2) # else: # cnt = acnt * (floor(H/2) + 1) + bcnt * floor(H/2) # return cnt print(solve(H, W))
s096065905
p04029
u655622461
2,000
262,144
Wrong Answer
17
2,940
51
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()) candy = N * (N+1) / 2 print(candy)
s907301575
Accepted
17
2,940
58
N = int(input()) candy = N * (N + 1) / 2 print(int(candy))
s557717408
p02276
u643021750
1,000
131,072
Wrong Answer
20
5,604
471
Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q. In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r). Your task is to read a sequence A and perform the Partition based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].
def partition(p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 A_tmp = A[i] A[i] = A[j] A[j] = A_tmp t = A[i+1] A[i+1] = A[r] A[r] = t n = int(input()) A = [int(_) for _ in input().split()] q = partition(0, n-1) for i in range(n): if i: print(" ") if i == q: print("[") print(A[i]) if i == q: print("]") print("\n")
s884553305
Accepted
300
16,364
519
def partition(p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 A_tmp = A[i] A[i] = A[j] A[j] = A_tmp t = A[i+1] A[i+1] = A[r] A[r] = t return i+1 n = int(input()) A = [int(_) for _ in input().split()] q = partition(0, n-1) for i in range(n): if i: print(" ", end="") if i == q: print("[", end="") print(A[i], end="") if i == q: print("]", end="") print("")
s920250144
p03455
u350179603
2,000
262,144
Wrong Answer
19
3,316
85
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b = map(int, input().split()) if (a*b)%2==0: print("Odd") else: print("Even")
s704326966
Accepted
17
2,940
85
a,b = map(int, input().split()) if (a*b)%2==0: print("Even") else: print("Odd")
s330440216
p03671
u533679935
2,000
262,144
Wrong Answer
18
2,940
133
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
a,b,c=map(int,input().split()) if a+b < c+b or b+c <c+b: print(c+b) elif c+b < a+b or b+c <a+b: print(a+b) else: print(a+c)
s907421639
Accepted
17
3,064
206
x,y,z=map(int,input().split()) if (x+y) <= (x+z) and (x+y)<= (y+z): print(x+y) elif (x+z) <= (x+y) and (x+z) <= (y+z): print(x+z) elif (y+z) <= (x+y) and (y+z) <= (x+z): print(y+z) else: print(x+z)
s525222318
p03377
u693378622
2,000
262,144
Wrong Answer
17
2,940
78
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = map(int, input().split()) print("Yes" if a<=x and x<=a+b else "No" )
s498198474
Accepted
17
2,940
78
a, b, x = map(int, input().split()) print("YES" if a<=x and x<=a+b else "NO" )
s518304887
p03456
u443996531
2,000
262,144
Time Limit Exceeded
2,104
2,940
106
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a,b = input().split() ab = int(a+b) ans = "No" i=3 while i*i<=ab: if i*i == ab: ans="Yes" print(ans)
s075286127
Accepted
18
2,940
113
a,b = input().split() ab = int(a+b) ans = "No" i=3 while i*i<=ab: if i*i == ab: ans="Yes" i+=1 print(ans)
s686847510
p03910
u867378674
2,000
262,144
Wrong Answer
1,518
3,572
285
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()) def calc(n): mx = 1 while True: if n <= mx * (mx + 1) // 2: break mx += 1 return mx ans = [] while n > 0: x = calc(n) ans.append(x) n -= x if x > n: ans.append(n) break print(*ans, sep="\n")
s952499937
Accepted
22
3,572
233
N = int(input()) x = 1 for _ in range(100000): if (x + 2) * (x + 1) // 2 > N: break x += 1 H = [i for i in range(x, 0, -1)] dif = N - sum(H) for i in range(dif): H[(i) % len(H)] += 1 print(*sorted(H), sep="\n")
s057089559
p03456
u496018856
2,000
262,144
Wrong Answer
18
3,192
204
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.
# -*- coding: utf-8 -*- import math a, b = map(str, input().split()) c=a+b c=int(c) if(isinstance(math.sqrt(c),int)): print("Yes") else: print("No")
s027778521
Accepted
17
2,940
201
# -*- coding: utf-8 -*- import math a, b = map(str, input().split()) c=a+b c=int(c) if(math.sqrt(c).is_integer()): print("Yes") else: print("No")
s540978036
p02416
u776758454
1,000
131,072
Wrong Answer
20
7,696
196
Write a program which reads an integer and prints sum of its digits.
def main(): while True: number_string = input() if number_string == '0': break print(list(number_string)) print(sum(map(int, list(number_string)))) main()
s107612400
Accepted
20
7,752
161
def main(): while True: number_string = input() if number_string == '0': break print(sum(map(int, list(number_string)))) main()
s944377106
p03139
u824425238
2,000
1,048,576
Wrong Answer
17
3,064
658
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
# coding: utf-8 import sys import math def main(s): n = s[0] a = s[1] b = s[2] if not(n.isdigit()) or int(n) <= 0 or int(n) > 100: return -1 if not(a.isdigit()) or int(n) < 0 or int(a) > int(n): return -1 if not(b.isdigit()) or int(b) < 0 or int(b) > int(n): return -1 n = int(n) a = int(a) b = int(b) reta = a retb = (n - a) - b if retb > 0 : retb = 0 else: retb = abs(retb) print('{reta} {retb}'.format(reta=reta,retb=retb)) return 0 if __name__ == '__main__': args = sys.argv if len(args) > 1: s = args[1:] main(s)
s663463278
Accepted
17
3,060
263
# coding: utf-8 import sys import math args = input().split() n = int(args[0]) a = int(args[1]) b = int(args[2]) reta = a retb = (n - a) - b if retb > 0: retb = 0 else: retb = abs(retb) print('{reta} {retb}'.format(reta=min(a,b),retb=retb)) sys.exit(0)
s002884639
p02612
u550146131
2,000
1,048,576
Wrong Answer
30
9,136
32
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()) M=N%1000 print(M)
s714356435
Accepted
30
9,148
74
N=int(input()) if N%1000==0: print("0") else: print(1000-(N%1000))
s670311097
p03455
u143903328
2,000
262,144
Wrong Answer
17
2,940
87
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int,input().split()) if a * b % 2: print('odd') else: print('even')
s293486840
Accepted
17
2,940
87
a, b = map(int,input().split()) if a * b % 2: print('Odd') else: print('Even')
s337556900
p03997
u075595666
2,000
262,144
Wrong Answer
17
3,064
445
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 = input() b = input() c = input() a = a.replace("a","") b = b.replace("b","") c = c.replace("c","") turn = 'a' for i in range(500): if turn == 'a': if int(len(a)) == 0: print("A") break else: turn = str(a[0]) a = a[1:] if turn == 'b': if int(len(b)) == 0: print('B') break else: turn = str(b[0]) b = b[1:] if turn == 'c': if int(len(c)) == 0: print('C') break else: turn = str(c[0]) c = c[1:]
s446113671
Accepted
17
2,940
74
a = int(input()) b = int(input()) h = int(input()) print(int((a + b)*h/2))
s637432820
p02401
u369313788
1,000
131,072
Wrong Answer
20
7,660
252
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: a, op, b = input().split() a = int(a) b = int(b) if op == '?': break if op == '+': print(a+b) if op == '-': print(a-b) if op == '*': print(a*b) if op == '/': print(a/b)
s452831712
Accepted
20
7,656
253
while True: a, op, b = input().split() a = int(a) b = int(b) if op == '?': break if op == '+': print(a+b) if op == '-': print(a-b) if op == '*': print(a*b) if op == '/': print(a//b)
s973746159
p03574
u301624971
2,000
262,144
Wrong Answer
73
3,872
873
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 itertools H, W = map(int, input().split()) S = [] ans = [] for _ in range(H): S.append(list(input())) ans.append([' op =[] for i in itertools.product([-1, 0, 1], repeat=2): op.append(i) for i, s1 in enumerate(S): for j, s2 in enumerate(s1): if(s2 == '.'): counter = 0 for o in op: print(i,j,o) if(i == 0 and o[0] == -1): continue elif(i == H-1 and o[0] == 1): continue elif(j == 0 and o[1] == -1): continue elif(j == W-1 and o[1] == 1): continue else: if(S[i + o[0]][j + o[1]] == "#"): counter += 1 ans[i][j] = str(counter) for a in ans: print(''.join(a))
s375685673
Accepted
26
3,316
1,314
def myAnswer(H:int,W:int,S:list) -> None: XY = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]] index = [] ans = [[0]*W for _ in range(H)] for i in range(H): for j in range(W): if(S[i][j] == "#"): ans[i][j] = "#" index.append([i,j]) for i,j in index: for x,y in XY: if(0 > (j + x) or (j + x) >= W or 0 > (i + y) or (i + y) >= H): continue elif(ans[y+i][x+j]== "#"): continue else: ans[y + i][x + j] += 1 for a in ans: string = "" for s in a: string += str(s) print(string) def modelAnswer(H:int,W:int,S:list) -> int: dx = [1,0,-1,0,1,-1,-1,1] dy = [0,1,0,-1,1,1,-1,-1] for i in range(H): for j in range(W): if(S[i][j] == "#"):continue num = 0 for d in range(8): ni = i + dy[d] nj = j + dx[d] if(ni < 0 or H <= ni):continue if(nj < 0 or W <= nj):continue if(S[ni][nj] == "#"): num+=1 S[i][j] = str(num ) for s in S: ans = "" for a in s: ans += a print(ans) def main(): H,W = map(int,input().split()) S = [list(input()) for _ in range(H)] myAnswer(H,W,S[:]) if __name__ == '__main__': main()
s715752388
p03623
u485435834
2,000
262,144
Wrong Answer
17
2,940
218
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|.
location_list = list(map(int, input().split())) ax_length = abs(location_list[0] - location_list[1]) bx_length = abs(location_list[0] - location_list[2]) if ax_length > bx_length: print('A') else: print('B')
s953979639
Accepted
17
2,940
218
location_list = list(map(int, input().split())) ax_length = abs(location_list[0] - location_list[1]) bx_length = abs(location_list[0] - location_list[2]) if ax_length < bx_length: print('A') else: print('B')
s675461350
p03352
u048945791
2,000
1,048,576
Wrong Answer
17
2,940
152
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()) maxInt = 1 i = 2 while i * i <= x: exp = i * i while exp <= x: exp *= i else: maxInt = max(maxInt, exp) i += 1 print(maxInt)
s239758895
Accepted
17
3,064
157
x = int(input()) maxInt = 1 i = 2 while i * i <= x: exp = i * i while exp <= x: exp *= i else: maxInt = max(maxInt, exp // i) i += 1 print(maxInt)
s981035880
p03563
u076764813
2,000
262,144
Wrong Answer
17
2,940
59
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
r = float(input()) g = float(input()) t = 2*g -r print(t)
s328530054
Accepted
17
2,940
55
r = int(input()) g = int(input()) t = 2*g -r print(t)
s283715339
p03024
u960653324
2,000
1,048,576
Wrong Answer
17
2,940
146
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S = list(str(input())) if S.count("o") >= 8: print("Yes") else: if 15 - len(S) + S.count("o") >= 8: print("Yes") else: print("No")
s273348510
Accepted
17
2,940
146
S = list(str(input())) if S.count("o") >= 8: print("YES") else: if 15 - len(S) + S.count("o") >= 8: print("YES") else: print("NO")
s811746654
p03796
u221841077
2,000
262,144
Wrong Answer
2,104
3,464
107
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()) pow = 1 for i in range(1,N+1): pow = pow*i num = 10**9+7 print(pow%num) print(pow)
s626951258
Accepted
35
2,940
100
N = int(input()) pow = 1 num = 10**9+7 for i in range(1,N+1): pow = pow*i%num print(pow%num)
s139117633
p03854
u975966195
2,000
262,144
Wrong Answer
17
3,188
339
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()[::-1] words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']] can = 'Yes' while True: match_any = False for w in words: if s.startswith(w): s = s.replace(w, '', 1) match_any = True break if not match_any: can = 'No' break break print(can)
s211071977
Accepted
82
3,188
326
s = input()[::-1] words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']] can = 'YES' while s: match_any = False for w in words: if s.startswith(w): s = s.replace(w, '', 1) match_any = True break if not match_any: can = 'NO' break print(can)
s109279114
p03379
u063052907
2,000
262,144
Wrong Answer
315
25,472
200
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
n = int(input()) lst_x = list(map(int, input().split())) lst_x.sort() b1 = lst_x[n//2 - 1] b2 = lst_x[n//2] for x in lst_x: if x <= b1: ans = b2 else: ans = b1 print(ans)
s614509774
Accepted
288
26,016
168
n = int(input()) lst_x = list(map(int, input().split())) lst = lst_x[:] lst.sort() b1 = lst[n//2 - 1] b2 = lst[n//2] for x in lst_x: print(b2 if x <= b1 else b1)
s263126798
p02422
u195186080
1,000
131,072
Wrong Answer
20
7,628
353
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
sen = input() n = int(input()) for i in range(n): cmd = input().split() sta = int(cmd[1]) end = int(cmd[2]) if len(cmd) == 4: sen = sen[0:sta] + cmd[3] + sen[end+1:] elif cmd[0] == 'reverse': rev = sen[end+1:sta:-1] sen = sen[0:sta] + rev +sen[end+1:] elif cmd[0] == 'print': print(sen[sta:end+1])
s260170609
Accepted
20
7,700
427
sen = input() n = int(input()) for i in range(n): cmd = input().split() sta = int(cmd[1]) end = int(cmd[2]) if cmd[0] == 'replace': sen = sen[0:sta] + cmd[3] + sen[end+1:] elif cmd[0] == 'reverse': rev = sen[sta:end+1] rev = rev[::-1] # print(rev) sen = sen[0:sta] + rev +sen[end+1:] elif cmd[0] == 'print': print(sen[sta:end+1])
s100734347
p03433
u420200689
2,000
262,144
Wrong Answer
17
2,940
336
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
# -*- coding: utf-8 -*- while True: N = int(input("N = ")) A = int(input("A = ")) if (N >= 1 and N <= 10000) and (A >= 0 and A <= 1000): break if (N / 500) > 0: x = N % 500 if A >= x: print('Yes') else: print('No') else: if A >= N: print('yes') else: print('No')
s378943684
Accepted
17
3,060
323
# -*- coding: utf-8 -*- while True: N = int(input()) A = int(input()) if (N >= 1 and N <= 10000) and (A >= 0 and A <= 1000): break if (N / 500) > 0: x = N % 500 if A >= x: print('Yes') else: print('No') else: if A >= N: print('yes') else: print('No')
s119478616
p03447
u422267382
2,000
262,144
Wrong Answer
17
3,060
114
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,A,B=[int(input()) for i in range(3)] x=0 XX=X-A while XX>0: XX-=B print(XX) x+=1 print(X-A-B*(x-1))
s810102681
Accepted
17
3,064
101
X,A,B=[int(input()) for i in range(3)] x=0 XX=X-A while XX>=0: XX-=B x+=1 print(X-A-B*(x-1))
s198912904
p03469
u750389519
2,000
262,144
Wrong Answer
25
8,944
25
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() S[4],print('8')
s621178352
Accepted
27
8,968
29
S=input() print("2018"+S[4:])
s974076564
p02613
u561294476
2,000
1,048,576
Wrong Answer
29
9,168
194
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 = [i for i in str(input())] print("AC x " + str(S.count('AC'))) print("WA x " + str(S.count('WA'))) print("TLE x " + str(S.count('TLE'))) print("RE x " + str(S.count('RE')))
s551658334
Accepted
158
16,272
221
N = int(input()) S = ["00"] for i in range(N): S.append(str(input())) print("AC x " + str(S.count('AC'))) print("WA x " + str(S.count('WA'))) print("TLE x " + str(S.count('TLE'))) print("RE x " + str(S.count('RE')))
s710227066
p04030
u023229441
2,000
262,144
Wrong Answer
17
2,940
115
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() ans="" for i in s: if i==0 or i==1: ans+=i else: if len(ans)!=0: del ans[-1] print(ans)
s542798634
Accepted
17
2,940
122
s=input() ans="" for i in s: if i=="0" or i=="1": ans+=i else: if len(ans)!=0: ans=ans[:-1] print(ans)
s805899670
p03360
u627417051
2,000
262,144
Wrong Answer
17
3,060
131
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
A, B, C = input().split() K = int(input()) A = int(A) B = int(B) C = int(C) X = (A, B, C) M = max(X) print(M ** K + A + B + C -M)
s461313672
Accepted
17
3,060
137
A, B, C = input().split() K = int(input()) A = int(A) B = int(B) C = int(C) X = (A, B, C) M = max(X) print(M * (2 ** K) + A + B + C -M)
s315262089
p03385
u606033239
2,000
262,144
Wrong Answer
18
2,940
86
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() print(["YES","NO"][S.count("a")>=2 or S.count("b")>=2 or S.count("c")>=2])
s631825100
Accepted
18
2,940
81
S = sorted(input()) if S == ["a","b","c"]: print("Yes") else: print("No")
s508174367
p03644
u676091297
2,000
262,144
Wrong Answer
18
2,940
107
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()) cnt=1 for i in range(0, 100): cnt*=2 if cnt >= n: print(cnt/2) break
s227582708
Accepted
18
2,940
131
import math n=int(input()) cnt=1 for i in range(0, 100): cnt*=2 if cnt > n: print(math.floor(cnt/2)) break
s688759711
p03150
u724732842
2,000
1,048,576
Wrong Answer
17
3,064
496
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 = list(input()) ss = ['k','e','y','e','n','c','e'] p = 6 a = 0 b = 0 c = 0 for i in range(len(ss)): if s[i] == ss[i]: continue else: a = i break else: print('YES') exit() for j in range(len(s)-1,-1,-1): if p >= 0 : if (s[j] == ss[p]): print('ヌッ',c) p -= 1 c += 1 else: b = c break else: print('YES') exit() if a+b == 7: print('YES') else: print('NO')
s789184169
Accepted
18
3,060
359
S = list(input()) s = ['k','e','y','e','n','c','e'] a = 0 for i in range(len(s)): if S[i] == s[i]: continue else: a = i break else: print('YES') exit() ss = s[a:] for i in range(len(ss)): if ss[i] == S[len(S)-len(ss)+i]: continue else: print('NO') exit() else: print('YES')
s854139644
p03854
u936378263
2,000
262,144
Wrong Answer
74
3,956
268
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`.
words = ["dream", "dreamer", "erase", "eraser"] s = input() dp = [0] * (len(s)+1) dp[0] = 1 for i in range(len(s)+1): if dp[i]!=1: continue for word in words: if word in s[i:i+len(word)]: dp[i+len(word)] = 1 print("Yes" if dp[len(s)] else "No")
s711191538
Accepted
76
3,956
268
words = ["dream", "dreamer", "erase", "eraser"] s = input() dp = [0] * (len(s)+1) dp[0] = 1 for i in range(len(s)+1): if dp[i]!=1: continue for word in words: if word in s[i:i+len(word)]: dp[i+len(word)] = 1 print("YES" if dp[len(s)] else "NO")
s021837385
p03719
u052066895
2,000
262,144
Wrong Answer
19
2,940
74
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
A,B,C = map(int, input().split()) print("YES" if A<=C and C<=B else "NO")
s988170624
Accepted
17
2,940
74
A,B,C = map(int, input().split()) print("Yes" if A<=C and C<=B else "No")
s920034227
p02972
u480300350
2,000
1,048,576
Wrong Answer
2,104
18,884
728
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 B = [0] * n ansList = [] def makeList(num): start = num + 1 mul = n // start return [start * j - 1 for j in range(1, mul+1)] def makeRes(indices): flag = 0 for elm in indices: if B[elm] == 1: flag = (flag + 1) % 2 return flag for i in range(n-1, -1, -1): if i + 1 > n / 2: if A[i] == 1: B[i] = 1 ans += 1 ansList.insert(0, i) else: indices = makeList(i) res = makeRes(indices) # print(res) if A[i] != res: B[i] = 1 ans += 1 ansList.insert(0, i) print(ans) print(*ansList)
s238132547
Accepted
662
23,988
999
from collections import deque def main(): n = int(input()) A = list(map(int, input().split())) ans = 0 B = [0] * n # ansList = [] ansList = deque() def makeList(num): start = num + 1 mul = n // start return [start * j - 1 for j in range(1, mul+1)] def makeRes(indices): flag = 0 for elm in indices: if B[elm] == 1: flag = (flag + 1) % 2 return flag for i in range(n-1, -1, -1): if i + 1 > n / 2: if A[i] == 1: B[i] = 1 ans += 1 ansList.appendleft(i+1) else: indices = makeList(i) res = makeRes(indices) # print(res) if A[i] != res: B[i] = 1 ans += 1 ansList.appendleft(i+1) print(ans) if ans != 0: print(*(list(ansList))) if __name__ == "__main__": main()
s476441377
p03448
u409064224
2,000
262,144
Wrong Answer
52
3,060
219
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a = int(input()) b = int(input()) c = int(input()) x = int(input()) res = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if (500*a)+(100*b)+(50*c) == x: res += 1 else: print(res)
s293867756
Accepted
51
3,060
213
a = int(input()) b = int(input()) c = int(input()) x = int(input()) res = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if (500*i)+(100*j)+(50*k) == x: res += 1 print(res)
s075526001
p03386
u039623862
2,000
262,144
Wrong Answer
17
3,060
229
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()) l = set() for x in range(a, a + k): if x > b: break l.add(x) for x in range(b - k, b + 1): if x < a: continue l.add(x) l = list(l) l.sort() print(*l, sep='\n')
s443583857
Accepted
17
3,060
176
a, b, k = map(int, input().split()) u = set() for i in range(k): if a+i <= b: u.add(a + i) if b-i >= a: u.add(b - i) print(*sorted(list(u)), sep='\n')
s298066621
p00031
u358919705
1,000
131,072
Wrong Answer
30
7,604
134
祖母が天秤を使っています。天秤は、二つの皿の両方に同じ目方のものを載せると釣合い、そうでない場合には、重い方に傾きます。10 個の分銅の重さは、軽い順に 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g です。 祖母は、「1kg くらいまでグラム単位で量れるのよ。」と言います。「じゃあ、試しに、ここにあるジュースの重さを量ってよ」と言ってみると、祖母は左の皿にジュースを、右の皿に 8g と64g と128g の分銅を載せて釣合わせてから、「分銅の目方の合計は 200g だから、ジュースの目方は 200g ね。どう、正しいでしょう?」と答えました。 左の皿に載せる品物の重さを与えるので、天秤で与えられた重みの品物と釣合わせるときに、右の皿に載せる分銅を軽い順に出力するプログラムを作成して下さい。ただし、量るべき品物の重さは、すべての分銅の重さの合計 (=1023g) 以下とします。
while True: try: w = int(input()) except: break print(*[2 ** i if w // 2 ** i else '' for i in range(10)])
s359327727
Accepted
30
7,636
205
while True: try: w = int(input()) except: break ans = [2 ** i if w // 2 ** i % 2 else 0 for i in range(10)] while ans.count(0): del ans[ans.index(0)] print(*ans)
s178913781
p03997
u594859393
2,000
262,144
Wrong Answer
17
2,940
56
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a,b,h = [int(input()) for _ in range(3)] print(a*b*h//2)
s385356183
Accepted
17
2,940
58
a,b,h = [int(input()) for _ in range(3)] print((a+b)*h//2)
s145282118
p03162
u591524911
2,000
1,048,576
Wrong Answer
2,109
54,084
418
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()) import numpy as np arr = np.array([input().split() for _ in range(N)], dtype=np.int8) dp = np.zeros_like(arr) for i, arr_ in enumerate(arr): for j in range(len(arr_)): if i == 0: dp[i][j] = arr_[j] continue for k in range(len(arr_)): if j != k: dp[i][j] = max(dp[i-1][k] + arr_[j], dp[i][j]) print(np.max(dp[-1])) #print(dp)
s695994509
Accepted
596
53,492
305
N= int(input()) arr = [list(map(int,input().split())) for _ in range(N)] dp = [ list([0,0,0]) for i in range(N)] for i,l in enumerate(arr): if i == 0: dp[0] = l continue dp[i] = [max(dp[i-1][1:])+l[0], max(dp[i-1][0],dp[i-1][2])+l[1],max(dp[i-1][:2])+l[2]] print(max(dp[-1])) #print(dp)
s209541069
p03698
u168416324
2,000
262,144
Wrong Answer
19
2,940
131
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s=list(input()) li=[] non=False for c in s: if c in li: non=True break if non: print("yes") else: print("no")
s970431942
Accepted
17
2,940
146
s=list(input()) li=[] non=False for c in s: if c in li: non=True break li.append(c) if non: print("no") else: print("yes")
s069265713
p02678
u920977317
2,000
1,048,576
Wrong Answer
2,207
47,036
1,026
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
from collections import deque def main(): RoomNum,PathNum=map(int,input().split()) Link=[] for _ in range(PathNum): array=input().split() Link.append(list(map(int,array))) #Link.append(list(map(int,[array[1],array[0]]))) Link.sort() room_que=deque([1]) sign=[] room_num=[] while len(room_que)>0 and len(Link)>0: current_room=room_que.popleft() for link in Link[:]: if (current_room in link): room_que.append(link[link.index(current_room)^1]) if (link[link.index(current_room)^1] in room_num)==False: sign.append(current_room) room_num.append(link[link.index(current_room)^1]) Link.remove(link) if len(sign)!=RoomNum-1: print("No") else: RS=zip(room_num,sign) RS=sorted(RS) room_num,sign=zip(*RS) print("yes") for i in sign: print(i) if __name__=="__main__": main()
s448039854
Accepted
653
34,972
883
from collections import deque def main(): RoomNum,PathNum=map(int,input().split()) G=[[] for _ in range(RoomNum)] for _ in range(PathNum): a,b=map(int,input().split()) G[a-1].append(b-1) G[b-1].append(a-1) dist=[-1]*RoomNum que=deque([]) dist[0]=0 que.append(0) while len(que)>0: v=que.popleft() for i in G[v]: if dist[i]!=-1: continue dist[i]=v que.append(i) if (-1 in dist): print("No") else: print("Yes") for i in dist[1:]: print(i+1) if __name__=="__main__": main()
s740795718
p03377
u263824932
2,000
262,144
Wrong Answer
17
2,940
110
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A,B,X=map(int,input().split()) if X<A: print('No') elif X>A+B: print('No') else: print('Yes')
s011319135
Accepted
17
2,940
94
A,B,X=map(int,input().split()) if X>=A and A+B>=X: print('YES') else: print('NO')
s759238968
p03544
u131464432
2,000
262,144
Wrong Answer
29
9,100
117
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
N = int(input()) L = [0]*(N+1) L[0] = 2 L[1] = 1 for i in range(2,N+1): L[i] = L[i-1] + L[i-2] print(L) print(L[N])
s594265718
Accepted
31
9,152
108
N = int(input()) L = [0]*(N+1) L[0] = 2 L[1] = 1 for i in range(2,N+1): L[i] = L[i-1] + L[i-2] print(L[N])
s428422082
p03434
u907549201
2,000
262,144
Wrong Answer
17
2,940
138
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.
input() li = list(map(int, input().split())) li.sort(reverse=True) alice = [i for index,i in enumerate(li) if index % 2 == 0] print(alice)
s923545467
Accepted
20
3,060
167
input() li = list(map(int, input().split())) li.sort(reverse=True) alice = sum([i for index,i in enumerate(li) if index % 2 == 0]) ans = alice * 2 - sum(li) print(ans)
s020367818
p02748
u736470924
2,000
1,048,576
Wrong Answer
2,229
2,008,476
715
You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
import itertools A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) m = {} for _ in range(M): x, y, z = map(int, input().split()) key = str(x) + "&" + str(y) if key in m.keys(): if m[key] < z: m[key] = z else: m[key] = z A_B = list(itertools.product(range(A), range(B))) A_B_sum = list(map(lambda x: x[0] + x[1], (itertools.product(a, b)))) for i in range(len(A_B)): # print(str(A_B[i][0]) + "&" + str(A_B[i][1])) if str(A_B[i][0]) + "&" + str(A_B[i][1]) in m.keys(): print(str(A_B[i][0]) + "&" + str(A_B[i][1])) A_B_sum[i] -= m[str(A_B[i][0]) + "&" + str(A_B[i][1])] print(min(A_B_sum))
s675828128
Accepted
418
18,612
271
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) min_a = min(a) min_b = min(b) ans = min_a + min_b for _ in range(M): i, j, c = map(int, input().split()) ans = min(ans, a[i - 1] + b[j - 1] - c) print(ans)
s816192244
p02796
u536600145
2,000
1,048,576
Wrong Answer
348
11,048
227
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.
N = int(input()) left = [] right = [] for i in range(N): x, dis = map(int, input().split(" ")) left.append(x-dis) right.append(x+dis) cnt = 1 for i in range(N-1): if right[i] <= left[i+1]: cnt += 1
s173292683
Accepted
464
22,104
305
N = int(input()) robots = [] for _ in range(N): x, dis = map(int, input().split()) robots.append([x-dis,x+dis]) robots = sorted(robots, key=lambda x: x[1]) cnt = 0 now = -float("inf") for left, right in robots: if left >= now: cnt += 1 now = right print(cnt)