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
s804780615
p03623
u442948527
2,000
262,144
Wrong Answer
27
9,160
60
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...
x,a,b=map(int,input().split()) print(max(abs(x-a),abs(x-b)))
s773624397
Accepted
26
9,160
61
x,a,b=map(int,input().split()) print("AB"[abs(x-a)>abs(x-b)])
s766839142
p03416
u882359130
2,000
262,144
Wrong Answer
113
3,060
188
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(ab) for ab in input().split()] ans = 0 for AB in range(A, B+1): AB = str(AB) for i in range(len(AB)//2): if AB[i] != AB[-i]: break else: ans += 1 print(ans)
s354329574
Accepted
99
3,060
206
A, B = [int(ab) for ab in input().split()] ans = 0 for AB in range(A, B+1): AB_str = str(AB) for i in range(len(AB_str)//2): if AB_str[i] != AB_str[-i-1]: break else: ans += 1 print(ans)
s364981484
p03854
u931889893
2,000
262,144
Wrong Answer
17
3,188
334
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() results = True while results: for key_word in ["erase", "eraser", "dream", "dreamer"]: if S.endswith(key_word): S = S.rstrip(key_word) continue if S == '': print("YES") results = False break else: print("NO") results = False...
s672397524
Accepted
19
3,188
163
s = input() s = s.replace('eraser', '') s = s.replace('erase', '') s = s.replace('dreamer', '') s = s.replace('dream', '') if s: print('NO') else: print('YES')
s386406836
p02694
u244416763
2,000
1,048,576
Wrong Answer
24
9,168
87
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 abo...
x = int(input()) r = 100 age = 0 while(r <= x): age += 1 r += r//100 print(age)
s624585804
Accepted
23
9,164
154
import sys x = int(input()) a = 100 age = 0 while (1): if x <= a: print(age) sys.exit() else: age += 1 a += a//100
s469730081
p03546
u099566485
2,000
262,144
Wrong Answer
40
3,444
458
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and...
# 078-D def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(input()) def S(): return list(input()) h,w=IL() c=[IL() for i in range(10)] a=[IL() for i in range(h)] for k in range(10): for i in range(10): for j in range(10): c[i][j]=min(c[i][j],c[i...
s610618335
Accepted
39
3,444
469
# 078-D def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(input()) def S(): return list(input()) h,w=IL() c=[IL() for i in range(10)] a=[IL() for i in range(h)] for k in range(10): for i in range(10): for j in range(10): c[i][j]=min(c[i][j],c[i...
s571444815
p02608
u681444474
2,000
1,048,576
Wrong Answer
829
9,116
266
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).
# coding: utf-8 N = int(input()) ANS = [0] * (N+1) for i in range(1,101): for j in range(1,101): for k in range(1,101): a = i**2 + j**2 + k**2 + i*j + j*k + k*i if a <= N: ANS[a] += 1 for a in ANS: print(a)
s870027568
Accepted
837
9,192
280
# coding: utf-8 N = int(input()) ANS = [0] * (N+1) for i in range(1,101): for j in range(1,101): for k in range(1,101): a = i**2 + j**2 + k**2 + i*j + j*k + k*i if a <= N: ANS[a] += 1 for i in range(1,N+1): print(ANS[i])
s060932146
p04046
u679154596
2,000
262,144
Wrong Answer
2,104
4,880
531
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there ...
H, W, A, B = map(int, input().split()) import math def f(n): a1 = math.factorial(B + n + H - A - 1) % (10**9 + 7) a2 = math.factorial(W - B - 1 - n + A - 1) % (10**9 + 7) b1 = math.factorial(B + n) % (10**9 + 7) b2 = math.factorial(H - A - 1) % (10**9 + 7) b3 = math.factorial(W - B - 1 - n) % (10**9 + 7) ...
s937115372
Accepted
380
27,120
513
H, W, A, B = map(int, input().split()) MOD = 1000000007 fac = [1, 1] inverse = [0, 1] ifac = [1, 1] for i in range(2, H+W): fac.append((fac[-1] * i) % MOD) inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD) ifac.append((ifac[-1] * inverse[i]) % MOD) def f(n): return fac[B+n+H-A-1] * fac[W-B-1-n+A-1] ...
s722211397
p02678
u639380385
2,000
1,048,576
Wrong Answer
470
52,916
878
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 th...
#import re import sys input = sys.stdin.readline #import heapq from collections import deque #import math def main(): n, m = map(int, input().split()) AL = [[] for i in range(n+1)] check = [0 for i in range(n+1)] for i in range(m): s, e = map(int, input().split()) AL[s].append(e) ...
s834377897
Accepted
472
53,300
878
#import re import sys input = sys.stdin.readline #import heapq from collections import deque #import math def main(): n, m = map(int, input().split()) AL = [[] for i in range(n+1)] check = [0 for i in range(n+1)] for i in range(m): s, e = map(int, input().split()) AL[s].append(e) ...
s396691804
p03563
u319818856
2,000
262,144
Wrong Answer
17
2,940
181
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 cont...
def rating_goal(R: float, G: float)->float: return 2*G - R if __name__ == "__main__": R = float(input()) G = float(input()) ans = rating_goal(R, G) print(ans)
s650307034
Accepted
17
2,940
177
def rating_goal(R: float, G: float)->float: return 2*G - R if __name__ == "__main__": R = int(input()) G = int(input()) ans = rating_goal(R, G) print(ans)
s407475432
p03606
u759412327
2,000
262,144
Wrong Answer
20
3,060
100
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
N = int(input()) a = 0 for i in range(N): l,r = list(map(int,input().split())) a+=r-l print(a)
s506016078
Accepted
27
9,108
90
a = 0 for n in range(int(input())): l,r = map(int,input().split()) a+=r-l+1 print(a)
s995554951
p03644
u977349332
2,000
262,144
Wrong Answer
18
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...
a = [64, 32, 16, 8, 4, 2, 1] N = int(input()) for i in a: if i < N: print(i)
s288216929
Accepted
17
2,940
95
a = [64, 32, 16, 8, 4, 2, 1] N = int(input()) for i in a: if i <= N: print(i) break
s535889695
p02411
u602702913
1,000
131,072
Wrong Answer
20
7,612
260
Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, t...
m,f,r=map(int,input().split()) if m or f==-1: print("F") elif m+f>=80: print("A") elif 65<=m+f<80: print("B") elif 50<=m+f<65: pritn("C") elif 30<=m+f<50: print("D") elif 30<m+f<50 and r>50: print("C") elif m+f<30: print("F")
s302015428
Accepted
40
7,720
352
while True: m,f,r=map(int,input().split()) if m==f==r==-1: break elif m==-1 or f==-1: print("F") elif m+f>=80: print("A") elif 65<=m+f<80: print("B") elif 50<=m+f<65: print("C") elif r>=50: print("C") elif 30<=m+f<50: print("D...
s670973910
p03971
u670180528
2,000
262,144
Wrong Answer
105
4,016
230
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from t...
n,a,b=map(int,input().split()) for i in input(): if a+b<1: print("No") elif i=="a" and a: print("Yes") a-=1 elif i=="b": if b: print("Yes") b-=1 else: print("No") else: print("No")
s444541100
Accepted
110
4,144
243
n,a,b=map(int,input().split()) c1=c2=0 for i in input(): if c1+c2>=a+b: print("No") elif i=="a": print("Yes") c1+=1 elif i=="b": if c2>=b: print("No") else: print("Yes") c2+=1 else: print("No")
s457957365
p03377
u037221289
2,000
262,144
Wrong Answer
17
2,940
81
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 B < X: print('YES') else: print('NO')
s875948035
Accepted
18
2,940
89
A,B,X = map(int,input().split(' ')) if B >= X-A >= 0: print('YES') else: print('NO')
s499655694
p02259
u923973323
1,000
131,072
Wrong Answer
20
7,668
539
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, in...
n = int(input()) data = [int(i) for i in input().split(' ')] def bubble_sort(raw_list): n_list = len(raw_list) n_swap = 0 sorted_i = 0 flag = True while flag: flag = False for j in reversed(range(sorted_i, n_list)): if raw_list[j] < raw_list[j-1]: raw_lis...
s252429789
Accepted
40
7,752
543
n = int(input()) data = [int(i) for i in input().split(' ')] def bubble_sort(raw_list): n_list = len(raw_list) n_swap = 0 sorted_i = 0 flag = True while flag: flag = False for j in reversed(range(sorted_i + 1, n_list)): if raw_list[j] < raw_list[j-1]: raw...
s992783196
p02603
u517910772
2,000
1,048,576
Wrong Answer
31
9,080
702
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the n...
def d(): N = int(input()) A = list(map(int, input().split())) money = 1000 stock = 0 for i in range(1, N): print(A[i-1]) if A[i-1] < A[i]: stock += money // A[i-1] money -= A[i-1] * (money // A[i-1]) # print('buy - stock: {}, money: {}'.format(s...
s207396985
Accepted
26
9,160
681
def d(): N = int(input()) A = list(map(int, input().split())) money = 1000 stock = 0 for i in range(1, N): if A[i-1] < A[i]: stock += money // A[i-1] money -= A[i-1] * (money // A[i-1]) # print('buy - stock: {}, money: {}'.format(stock, money)) ...
s862819311
p03574
u276204978
2,000
262,144
Wrong Answer
157
12,468
494
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 con...
import numpy as np H, W = map(int, input().split()) S = [list(input()) for _ in range(H)] dx = [1, 1, 1, 0, 0, -1, -1, -1] dy = [1, 0, -1, 1, -1, 1, 0, -1] for h, row in enumerate(S): for w, i in enumerate(row): if i == '#': for x, y in zip(dx, dy): if 0 <= x+w < W and 0 <= y+h < H: ...
s381223885
Accepted
399
23,584
564
import numpy as np H, W = map(int, input().split()) S = [list(input()) for _ in range(H)] dx = [1, 1, 1, 0, 0, -1, -1, -1] dy = [1, 0, -1, 1, -1, 1, 0, -1] for h, row in enumerate(S): for w, i in enumerate(row): if i == '.': S[h][w] = 0 if i == '#': for x, y in zip(dx, dy): if 0 <...
s243644941
p02619
u802234211
2,000
1,048,576
Wrong Answer
35
9,512
699
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 che...
def complain(comp,c,k,last_hold): # print(k) if(k > 26): # print("___") return comp comp += c[k-1]*((i+1) - last_hold[k-1]) k += 1 # print(comp,"comp") return complain(comp,c,k,last_hold) D = int(input()) c = list(map(int,input().split())) s = ["_"]*(D) print(c) for i in range(...
s039800239
Accepted
40
9,372
829
def complain(comp,c,k,last_hold,i): # print(k) if(k > 26): # print("___") return comp comp += c[k-1]*((i+1) - last_hold[k-1]) k += 1 # print(comp,"comp") return complain(comp,c,k,last_hold,i) D = int(input()) c = list(map(int,input().split())) s = ["_"]*(D) # print(c) for i in ...
s844356561
p03493
u234631479
2,000
262,144
Wrong Answer
17
2,940
65
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
S = input().split() count = 0 for i in S: count+=1 print(count)
s535954131
Accepted
17
2,940
77
count = 0 for i in str(input()): if i == "1": count+=1 print(count)
s246385039
p03963
u991619971
2,000
262,144
Wrong Answer
17
2,940
105
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls.
N, K=map(int,input().split()) print(N,K) count=K for i in range(N-1): count=count*(K-1) print(count)
s041763323
Accepted
17
2,940
94
N, K=map(int,input().split()) count=K for i in range(N-1): count=count*(K-1) print(count)
s521325476
p03592
u222668979
2,000
262,144
Wrong Answer
236
9,164
195
We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attach...
n, m, k = map(int, input().split()) for i in range(n + 1): for j in range(m + 1): if i * (m - j) + j * (n - i) == k: print('Yes') break else: print('No')
s472406130
Accepted
248
9,080
211
from itertools import product n, m, k = map(int, input().split()) for i,j in product(range(n + 1), range(m + 1)): if i * (m - j) + j * (n - i) == k: print('Yes') break else: print('No')
s218955100
p03493
u253011685
2,000
262,144
Wrong Answer
17
2,940
28
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
N=list(input()) N.count('1')
s706893872
Accepted
17
2,940
35
N=list(input()) print(N.count('1'))
s053180694
p03251
u203211107
2,000
1,048,576
Wrong Answer
18
3,060
219
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 incli...
#B - 1 Dimensional World's Tale(ABC110) N,M,X,Y=map(int, input().split()) x=list(map(int, input().split())) y=list(map(int, input().split())) if X<Y and max(x)<Y and Y<=min(y): print("No War") else: print("War")
s354984569
Accepted
17
3,060
216
#B - 1 Dimensional World's Tale(ABC110) N,M,X,Y=map(int, input().split()) x=list(map(int, input().split())) y=list(map(int, input().split())) if max(X,max(x))<min(Y,min(y)): print("No War") else: print("War")
s267580800
p03623
u374146618
2,000
262,144
Wrong Answer
17
2,940
75
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...
x, a, b = [int(_) for _ in input().split()] print(min(abs(a-x), abs(b-x)))
s104419110
Accepted
17
2,940
103
x, a, b = [int(_) for _ in input().split()] if abs(a-x) < abs(b-x): print("A") else: print("B")
s250322724
p03495
u075595666
2,000
262,144
Wrong Answer
241
26,004
462
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
n,k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a.sort() count = 1 chk = [] p = 1 if n == 1: print(0) exit() else: for i in range(n-1): if a[i] != a[i+1]: count += 1 chk.append(p) p = 1 else: p += 1 if a[-1] == a[-2]: chk.append(p) else: ch...
s980870799
Accepted
231
25,340
464
n,k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a.sort() count = 1 chk = [] p = 1 if n == 1: print(0) exit() else: for i in range(n-1): if a[i] != a[i+1]: count += 1 chk.append(p) p = 1 else: p += 1 if a[-1] == a[-2]: chk.append(p) else: ch...
s505241579
p04029
u670180528
2,000
262,144
Wrong Answer
17
2,940
30
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n=int(input());print(n*~-n//2)
s802234526
Accepted
17
3,064
30
n=int(input());print(n*-~n//2)
s775485605
p04044
u551437236
2,000
262,144
Wrong Answer
27
9,132
159
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 sm...
n, l = map(int, input().split()) ll = [] for i in range(n): ll.append(input()) print(ll) ll.sort() print(ll) ans = "" for j in ll: ans += j print(ans)
s425067496
Accepted
27
9,100
139
n, l = map(int, input().split()) ll = [] for i in range(n): ll.append(input()) ll.sort() ans = "" for j in ll: ans += j print(ans)
s850366375
p03472
u327248573
2,000
262,144
Wrong Answer
2,104
11,020
382
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of d...
# -- coding: utf-8 -- N, H = map(int, input().split()) sl = [] th = [] for i in range(N): s, t = map(int, input().split()) sl.append(s) th.append(t) remH = H turn = 0 if sum(th) >= H: while remH > 0: max_i = th.index(max(th)) remH = remH - max(th) th.pop(max_i) turn += 1 ...
s959853114
Accepted
372
8,276
443
# -- coding: utf-8 -- import math N, H = map(int, input().split()) th = [] sl_max = 0 for i in range(N): s, t = map(int, input().split()) sl_max = max(sl_max, s) th.append(t) turn = 0 thdec = sorted(th, reverse=True) for i in range(len(thdec)): if thdec[i] >= sl_max: H -= thdec[i] turn ...
s434513378
p03556
u256464928
2,000
262,144
Wrong Answer
2,104
3,060
89
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
n = (int(input())) ans = 1 for i in range(n+1): if i**i<=n:ans=max(ans,i**i) print(ans)
s844139785
Accepted
18
2,940
42
n = int(input()) print(int(int(n**.5)**2))
s107670098
p03555
u601082779
2,000
262,144
Wrong Answer
17
2,940
46
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a=input();b=input();print("YNEOS"[a[::-1]!=b])
s629186725
Accepted
17
3,064
49
a=input();b=input();print("YNEOS"[a[::-1]!=b::2])
s230132084
p03472
u013513417
2,000
262,144
Wrong Answer
2,105
28,244
445
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of d...
# coding: utf-8 # Your code here! n,H=map(int,input().split()) S=[] for i in range(n): S.append(list(map(int,input().split()))) a=[] b=[] for i in range(n): a.append(S[i][0]) for i in range(n): if(max(a)<S[i][1]): b.append(S[i][1]) b.sort() b.reverse() k=0 count=0 while H>0: if l...
s427866104
Accepted
455
29,332
507
# coding: utf-8 # Your code here! n,H=map(int,input().split()) S=[] for i in range(n): S.append(list(map(int,input().split()))) a=[] b=[] for i in range(n): a.append(S[i][0]) maxa=max(a) for i in range(n): if(maxa<S[i][1]): b.append(S[i][1]) b.sort() b.reverse() k=0 count=0 lenb=len(...
s072693315
p03160
u989157442
2,000
1,048,576
Wrong Answer
116
13,928
241
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of...
n = int(input()) h = list(map(int, input().split())) dp = [0]*n for i in range(n): if i == 0: dp[i] = h[i] elif i == 1: dp[i] = abs(dp[i] - dp[i-1]) else: dp[i] = min(abs(dp[i]-dp[i-1]), abs(dp[i]-dp[i-2])) print(dp[n-1])
s434596858
Accepted
141
13,980
246
n = int(input()) h = list(map(int, input().split())) dp = [0]*n for i in range(n): if i == 0: dp[i] = 0 elif i == 1: dp[i] = abs(h[i]-h[i-1]) else: dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])) print(dp[n-1])
s610009710
p02261
u659034691
1,000
131,072
Wrong Answer
30
7,904
1,324
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubbl...
# your code goes here N=int(input()) Ci=[i for i in input().split()] C=[] for i in range(N): # print(C) C.append([]) C[i].append(Ci[i][0]) # print(C) C[i].append(int(Ci[i][1])) Cb=C fl=1 #print(Cb) while fl==1: fl=0 for j in range(N-1): # print(Cb) if Cb[N-1-j][1]<Cb[N-2-j][1]: ...
s197275755
Accepted
30
7,892
1,355
# your code goes here N=int(input()) Ci=[i for i in input().split()] C=[] for i in range(N): # print(C) C.append([]) C[i].append(Ci[i][0]) # print(C) C[i].append(int(Ci[i][1])) Cb=C fl=1 #print(Cb) while fl==1: fl=0 for j in range(N-1): # print(Cb) if Cb[N-1-j][1]<Cb[N-2-j][1]: ...
s539198399
p03386
u928784113
2,000
262,144
Wrong Answer
19
2,940
166
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()) if B-A+1 <= 2*K: print([i for i in range(A,B+1)]) else: print(i for i in range(A,A+K)) print(i for i in range(B-K+1,B+1))
s663193215
Accepted
18
3,060
196
A,B,K = map(int,input().split()) if B-A+1 > 2*K: for up in range(A,A+K): print(up) for down in range(B-K+1,B+1): print(down) else: for i in range(A,B+1): print(i)
s654436139
p02396
u450020188
1,000
131,072
Wrong Answer
20
7,720
146
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are give...
x =[int(i) for i in input().split()] for i, p in enumerate(x): if p == 0: break else: print("case {0}: {1}".format(i, p))
s350439217
Accepted
130
7,432
104
c=1 while True: i = input() if(i=="0"): break print("Case "+str(c)+": "+i) c+=1
s560338976
p03448
u137722467
2,000
262,144
Wrong Answer
51
3,060
209
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 co...
a = int(input()) b = int(input()) c = int(input()) x = int(input()) count = 0 for i in range(a): for j in range(b): for k in range(c): if 500*i + 100*j + 50*k == x: count += 1 print(count)
s651634588
Accepted
50
3,060
215
a = int(input()) b = int(input()) c = int(input()) x = int(input()) count = 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: count += 1 print(count)
s950778765
p02743
u798316285
2,000
1,048,576
Wrong Answer
20
3,064
155
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c=map(int,input().split()) if c-a-b<=0: print("No") else: l=a*b r=(c-a-b)**2 if r>l: print("Yes") else: print("No")
s927469027
Accepted
17
2,940
158
a,b,c=map(int,input().split()) if c-a-b<=0: print("No") else: l=a*b*4 r=(c-a-b)**2 if r>l: print("Yes") else: print("No")
s828382569
p03598
u785578220
2,000
262,144
Wrong Answer
17
3,060
170
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th t...
n = int(input()) k = int(input()) l = list(map(int, input().split())) for i in range(n): l[i] = min(l[i],abs(l[i]-k)) print(sum(l))
s569025708
Accepted
18
3,060
172
n = int(input()) k = int(input()) l = list(map(int, input().split())) for i in range(n): l[i] = min(l[i],abs(l[i]-k))*2 print(sum(l))
s175573099
p03623
u777078967
2,000
262,144
Wrong Answer
17
2,940
115
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...
n=input().rstrip().split() n=[int(x) for x in n] if abs(n[1]-n[0])>abs(n[2]-n[0]): print("A") else: print("B")
s944251048
Accepted
17
3,064
115
n=input().rstrip().split() n=[int(x) for x in n] if abs(n[1]-n[0])<abs(n[2]-n[0]): print("A") else: print("B")
s990507332
p03549
u107269063
2,000
262,144
Wrong Answer
17
2,940
95
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of th...
n, m = map(int, input().split()) time = 100 * (n - m) + 19000 * m ans = time * 2**m print(ans)
s455623035
Accepted
17
2,940
94
n, m = map(int, input().split()) time = 100 * (n - m) + 1900 * m ans = time * 2**m print(ans)
s605930816
p03485
u988832865
2,000
262,144
Wrong Answer
17
2,940
58
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
A, B = map(int, input().split()) print((A + B + 0.5) // 2)
s691989642
Accepted
17
2,940
62
A, B = map(int, input().split()) print(int((A + B) / 2 + 0.5))
s320548928
p00022
u203261375
1,000
131,072
Wrong Answer
40
5,604
151
Given a sequence of numbers a1, a2, a3, ..., an, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a _contiquous_ subsequence.
while True: n = int(input()) if n == 0: break sum = 0 for _ in range(n): sum += max(int(input()), 0) print(sum)
s403880096
Accepted
40
5,640
265
while True: n = int(input()) if n == 0: break dp = [] for _ in range(n): if len(dp) == 0: dp.append(int(input())) else: x = int(input()) dp.append(max(dp[-1] + x, x)) print(max(dp))
s571703837
p03854
u018591138
2,000
262,144
Wrong Answer
17
3,188
440
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`.
t = ["dream","dreamer","erase","eraser"] t_r = [] for i in range(len(t)): t_r.append(t[i][::-1]) s = input() s_r = s[::-1] flag = True for i in range(len(s_r)): flag2 = False for j in t_r: tmp_s = s_r[i:len(j)] if(tmp_s == j): flag2 = True i += len(j) ...
s217416180
Accepted
44
3,188
534
t = ["dream","dreamer","erase","eraser"] t_r = [] for i in range(len(t)): t_r.append(t[i][::-1]) s = input() s_r = s[::-1] #print(s_r) flag = True i=0 while(i<len(s_r)): flag2 = False for j in range(len(t_r)): t = t_r[j] tmp_s = s_r[i:i+len(t)] #print(t) ...
s258208320
p03568
u227085629
2,000
262,144
Wrong Answer
17
2,940
109
We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How man...
n = int(input()) a = list(map(int,input().split())) k = 1 for k in a: if k%2 == 0: k *= 2 print(3**n-k)
s849597934
Accepted
17
2,940
110
n = int(input()) a = list(map(int,input().split())) k = 1 for d in a: if d%2 == 0: k *= 2 print(3**n-k)
s402382300
p03545
u327310087
2,000
262,144
Wrong Answer
18
3,060
259
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 in...
s = input() n = len(s) - 1 ans = 0 for i in range(1 << n): exp = s[0] for j in range(n): if i & (1 << j): exp += "+" else: exp += "-" exp += s[j + 1] if eval(exp) == 7: ans = exp print(ans)
s875535682
Accepted
17
3,060
272
s = input() n = len(s) - 1 ans = 0 for i in range(1 << n): exp = s[0] for j in range(n): if i & (1 << j): exp += "+" else: exp += "-" exp += s[j + 1] if eval(exp) == 7: ans = exp ans += "=7" print(ans)
s550295658
p03387
u474270503
2,000
262,144
Wrong Answer
17
3,060
312
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be ...
A , B , C = map(int, input().split()) a = [A, B, C] print(a) ct = 0 while True: tmp = min(a) tmp += 2 a.remove(min(a)) a.append(tmp) ct += 1 print(a) if a.count(max(a)) == 3: break if max(a) == min(a) + 1 and a.count(max(a)) == 1: ct += 1 break print(ct)
s404355698
Accepted
19
3,060
290
A , B , C = map(int, input().split()) a = [A, B, C] ct = 0 while True: if a.count(max(a)) == 3: break if max(a) == min(a) + 1 and a.count(max(a)) == 1: ct += 1 break tmp = min(a) tmp += 2 a.remove(min(a)) a.append(tmp) ct += 1 print(ct)
s259319398
p03007
u518064858
2,000
1,048,576
Wrong Answer
278
14,088
961
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the...
n=int(input()) a=sorted(list(map(int,input().split())),reverse=True) if a[-1]>=0: m=sum(a)-a[-1]*2 print(m) for i in range(n-1): if i==0: y=a[-2] x=a[-1] elif i==n-2: y=x-y x=a[0] else: x=x-y y=a[-2-i] pr...
s746904818
Accepted
238
14,492
458
n=int(input()) a=sorted(list(map(int,input().split()))) max=a[-1] min=a[0] if n==2: print(max-min) print(max,min) exit() ans=0 if a[-1]<0: ans+=-sum(a)+max*2 elif a[0]>0: ans+=sum(a)-min*2 else: for x in a: ans+=abs(x) print(ans) X=max Y=min for i in range(1,n-1): if a[i]>=0: ...
s612215960
p02612
u701063973
2,000
1,048,576
Time Limit Exceeded
2,205
9,064
92
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.
cash = int(input()) n=0 paid =0 while paid < cash: paid = 1000 * n print(paid - cash)
s135401413
Accepted
28
9,072
67
cash = int(input()) paid = (1000 - cash % 1000) % 1000 print(paid)
s870289003
p03854
u572142121
2,000
262,144
Wrong Answer
19
3,188
146
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() Word = ['eraser','erase','dreamer','dream'] for i in Word: S=S.replace(i,'') if len(S) == 0 : print('Yes') else : print('No')
s903243708
Accepted
18
3,188
146
S=input() Word = ['eraser','erase','dreamer','dream'] for i in Word: S=S.replace(i,'') if len(S) == 0 : print('YES') else : print('NO')
s392787500
p03563
u783565479
2,000
262,144
Wrong Answer
26
9,040
57
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 cont...
R = int(input()) G = int(input()) print(float(2 * G - R))
s070724449
Accepted
28
9,052
52
R = int(input()) G = int(input()) print((2 * G) - R)
s280845285
p03472
u390958150
2,000
262,144
Wrong Answer
550
21,444
570
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of d...
import math n,h = [int(i) for i in input().split()] A=[] for i in range(n): a,b = input().split() A.append([int(a),int(b)]) A.sort() max_a,max_b = A.pop() A.sort(key=lambda x:x[1],reverse=True) ans = 0 for i in range(n-1): print(A[i][1]) if A[i][1] >= max_a: ans += 1 h -= A[i][1]...
s044258197
Accepted
374
12,116
340
n, h = map(int, input().split()) A = []; B = [] for i in range(n): a, b = map(int, input().split()) A += a,; B += b, a = max(A) T = [] for i in range(n): if a < B[i]: T += B[i], T.sort(reverse=True) ans = 0 for t in T: h -= t; ans += 1 if h <= 0: break if h > 0: ans += (h + a - ...
s473748050
p03591
u586577600
2,000
262,144
Wrong Answer
18
2,940
214
Ringo is giving a present to Snuke. Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things. You are given a string S representing the Japanese ...
def isYaki(input): answer = 'YAKI' for (a, b) in zip(answer, input): if a != b: return 'No' return 'Yes' if __name__ == '__main__': input = input('> ') print(isYaki(input))
s656508801
Accepted
17
2,940
238
def isYaki(S): if len(S) < 4: return 'No' answer = 'YAKI' for (a, b) in zip(answer, S): if a != b: return 'No' return 'Yes' if __name__ == '__main__': S = input() print(isYaki(S))
s835234408
p02413
u628732336
1,000
131,072
Wrong Answer
30
8,288
394
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
r, c = [int(i) for i in input().split()] data = [] sum_row = [0] * (c + 1) for ri in range(r): data.append([int(i) for i in input().split()]) data[ri].append(sum(data[ri])) print(" ".join([str(d) for d in data[ri]])) for ci in range(c + 1): sum_row[ci] += data[ri][ci] print(" ".join([str(s) f...
s000455519
Accepted
20
7,760
338
r, c = [int(i) for i in input().split()] data = [] sum_row = [0] * (c + 1) for ri in range(r): data.append([int(i) for i in input().split()]) data[ri].append(sum(data[ri])) print(" ".join([str(d) for d in data[ri]])) for ci in range(c + 1): sum_row[ci] += data[ri][ci] print(" ".join([str(s) f...
s131141310
p03407
u693211869
2,000
262,144
Wrong Answer
18
2,940
90
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
a, b, c = map(int, input().split()) if a + b >= c: print('YES') else: print('NO')
s017415017
Accepted
17
2,940
90
a, b, c = map(int, input().split()) if a + b >= c: print('Yes') else: print('No')
s926224122
p03501
u252964975
2,000
262,144
Wrong Answer
18
2,940
51
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
a,b,t=map(int, input().split()) print(max([a*b,t]))
s288470860
Accepted
17
2,940
51
a,b,t=map(int, input().split()) print(min([a*b,t]))
s446757642
p02255
u798803522
1,000
131,072
Wrong Answer
30
7,628
267
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key ...
length = int(input()) targ = [int(n) for n in input().split(' ')] for l in range(length): for m in range(l): if targ[l - m] < targ[l - m - 1]: disp = targ[l-m -1] targ[l-m-1] = targ[l-m] targ[l-m] = disp print(targ)
s474316173
Accepted
30
7,740
407
length = int(input()) targ = [int(n) for n in input().split(' ')] for l in range(length): insert = 0 for m in range(l): if targ[l] >= targ[l - m - 1]: insert = l - m break aftdisp = targ[l] for i in range(0,l - insert): disp = targ[l - i] targ[l - i] = tar...
s625799091
p02645
u042558137
2,000
1,048,576
Wrong Answer
20
8,920
25
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.
S = input() print(S[0:4])
s498135300
Accepted
25
9,088
25
S = input() print(S[0:3])
s058642719
p03713
u223904637
2,000
262,144
Wrong Answer
219
3,064
425
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...
n,m=map(int,input().split()) ans=10000000000000 for i in range(1,n): a=i*m nk=n-i if nk%2==0: b=m*(nk//2) ans=min(ans,abs(a-b)) elif nk>1: b=m*((nk+1)//2) c=m*((nk-1)//2) ans=min(ans,max(a,b,c)-min(a,b,c)) if m%2==0: b=nk*m//2 ans=min(ans,abs(a...
s320427275
Accepted
332
3,188
815
n,m=map(int,input().split()) ans=10000000000000 for i in range(1,n): a=i*m nk=n-i if nk%2==0: b=m*(nk//2) ans=min(ans,abs(a-b)) elif nk>1: b=m*((nk+1)//2) c=m*((nk-1)//2) ans=min(ans,max(a,b,c)-min(a,b,c)) if m%2==0: b=nk*m//2 ans=min(ans,abs(a...
s291569562
p02407
u217069758
1,000
131,072
Wrong Answer
20
5,600
99
Write a program which reads a sequence and prints it in the reverse order.
LEN = int(input()) a = list(map(int, input().split())) b = [a[-(i+1)] for i in range(LEN)] print(b)
s974455852
Accepted
20
5,604
112
LEN = int(input()) a = list(map(int, input().split())) print(" ".join(map(str,[a[-(i+1)] for i in range(LEN)])))
s298922262
p03433
u584529823
2,000
262,144
Wrong Answer
17
2,940
87
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) A = int(input()) if N % 500 <= A: print("YES") else: print("NO")
s797684179
Accepted
17
2,940
88
N = int(input()) A = int(input()) if N % 500 <= A: print("Yes") else: print("No")
s667483186
p03251
u390793752
2,000
1,048,576
Wrong Answer
18
3,064
431
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 incli...
def main(): N,M,X,Y = map(int, input().split()) x_wants=[int(s) for s in input().split()] y_wants=[int(s) for s in input().split()] x_wants.append(X) y_wants.append(Y) x_wants = sorted(x_wants) y_wants = sorted(y_wants) x_max = x_wants[len(x_wants)-1] y_min = y_wants[0] if(x_m...
s843258934
Accepted
17
3,064
434
def main(): N,M,X,Y = map(int, input().split()) x_wants=[int(s) for s in input().split()] y_wants=[int(s) for s in input().split()] x_wants.append(X) y_wants.append(Y) x_wants = sorted(x_wants) y_wants = sorted(y_wants) x_max = x_wants[len(x_wants)-1] y_min = y_wants[0] if((y_...
s980311525
p03544
u055941944
2,000
262,144
Wrong Answer
17
3,064
113
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)
# -*- cooding utf-8 -*- n=int(input()) l=[2,1] for i in range(2,n-1): l.append(l[i-2]+l[i-1]) print(l[-1])
s805960287
Accepted
17
2,940
97
n=int(input()) L=[2,1] for i in range(2,n+1): x=L[-1]+L[-2] L.append(x) print(L[-1])
s994982315
p02669
u537142137
2,000
1,048,576
Time Limit Exceeded
2,248
1,447,824
834
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease...
import heapq def pay(N,A,B,C,D): q = [] heapq.heapify(q) num = {} num[0] = 0 num[-1] = -1 heapq.heappush(q,( 0, 0 )) while q: c, n = heapq.heappop(q) # print(n,c) if n == N: break if num.setdefault(n*2,N*D+1) > c+A: heapq.heappush(q,( c+A, n*2 )) num[n*2] = c+A if n...
s542282774
Accepted
101
10,364
968
import heapq def pay2win(): num = set() q = [] heapq.heapify(q) heapq.heappush(q,( 0, N )) cost = N*D while q: c0, n0 = heapq.heappop(q) if n0 in num: continue num.add(n0) if n0 == 0: break if c0 >= cost: break cost = min(cost,c0+n0*D) # n2, m = divmod(n0, ...
s410590458
p02678
u130387509
2,000
1,048,576
Wrong Answer
596
34,916
475
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 th...
from collections import deque n,m = map(int,input().split()) graph = [[] for i in range(n)] mark = [0]*n for i in range(m): a, b = map(int,input().split()) a -=1; b -=1 graph[a].append(b) graph[b].append(a) d = deque([0]) visited = [False]*n visited[0] = True while d: v = d.popleft() for i i...
s126071637
Accepted
651
35,788
479
from collections import deque n,m = map(int,input().split()) graph = [[] for i in range(n)] mark = [0]*n for i in range(m): a, b = map(int,input().split()) a -=1; b -=1 graph[a].append(b) graph[b].append(a) d = deque([0]) visited = [False]*n visited[0] = True while d: v = d.popleft() for i i...
s648366042
p03730
u774539708
2,000
262,144
Wrong Answer
17
2,940
143
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 objecti...
a,b,c=map(int,input().split()) n=0 for i in range(b): if a*(i+1)%b==c: print("Yes") break n+=1 if n==b: print("No")
s628905539
Accepted
18
2,940
143
a,b,c=map(int,input().split()) n=0 for i in range(b): if a*(i+1)%b==c: print("YES") break n+=1 if n==b: print("NO")
s700838425
p03795
u499259667
2,000
262,144
Wrong Answer
17
2,940
37
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant ...
n=int(input()) print(800*n-200*n//15)
s341934785
Accepted
17
2,940
40
n=int(input()) print(800*n-200*(n//15))
s278978607
p02612
u851125702
2,000
1,048,576
Wrong Answer
29
9,144
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N=int(input()) print(N%1000)
s540353910
Accepted
30
9,144
40
N=int(input()) print((1000-N%1000)%1000)
s923973299
p03814
u209619667
2,000
262,144
Wrong Answer
225
4,452
207
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends w...
A = input() count = 0 p = len(A) min_=200000 max_=0 for i in range(p): if (A[i] == 'A'): min_ = min(i,min_) print(min_) if (A[i] == 'Z'): max_ = max(i,max_) print(max_) print(max_-min_+1)
s249196648
Accepted
91
3,516
175
A = input() count = 0 p = len(A) min_=200000 max_=0 for i in range(p): if (A[i] == 'A'): min_ = min(i,min_) if (A[i] == 'Z'): max_ = max(i,max_) print(max_-min_+1)
s304940336
p04029
u289162337
2,000
262,144
Wrong Answer
17
2,940
33
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) print(n*(n+1)/2)
s613029614
Accepted
17
2,940
38
n = int(input()) print(int(n*(n+1)/2))
s806760264
p03386
u706414019
2,000
262,144
Wrong Answer
31
9,176
314
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.
import sys input = sys.stdin.readline A,B,K = list(map(int,input().split())) num_lis = [] for i in range(A,A+K): if i <= B: num_lis.append(i) else: break for i in range(B,B-K,-1): if i>= A: num_lis.append(i) else: break b = sorted(list(set(num_lis))) print(b)
s649480019
Accepted
29
9,188
346
import sys input = sys.stdin.readline A,B,K = list(map(int,input().split())) num_lis = [] for i in range(A,A+K): if i <= B: num_lis.append(i) else: break for i in range(B,B-K,-1): if i>= A: num_lis.append(i) else: break b = sorted(list(set(num_lis))) for i in range...
s008034978
p03813
u852790844
2,000
262,144
Wrong Answer
18
3,060
162
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.
import itertools s = list(input()) s1 = list(itertools.dropwhile(lambda x: x != 'A',s)) s2 = list(itertools.dropwhile(lambda x: x != 'Z',s1[::-1])) print(len(s2))
s606344827
Accepted
17
2,940
62
x = int(input()) ans = "ABC" if x < 1200 else "ARC" print(ans)
s308087183
p03945
u626468554
2,000
262,144
Wrong Answer
44
3,956
193
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones...
#n = int(input()) #n,k = map(int,input().split()) #x = list(map(int,input().split())) s = list(input()) cnt = 0 for i in range(len(s)): if s[i-1] != s[i]: cnt += 1 print(cnt)
s987346339
Accepted
43
3,956
195
#n = int(input()) #n,k = map(int,input().split()) #x = list(map(int,input().split())) s = list(input()) cnt = 0 for i in range(1,len(s)): if s[i-1] != s[i]: cnt += 1 print(cnt)
s332218324
p02264
u822165491
1,000
131,072
Wrong Answer
20
5,604
1,054
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
class MyQueue: def __init__(self): self.queue = [] # list self.top = 0 def isEmpty(self): if self.top==0: return True return False def isFull(self): pass def enqueue(self, x): self.queue.append(x) self.top += 1 def...
s445223525
Accepted
1,010
26,212
1,126
class MyQueue: def __init__(self): self.queue = [] # list self.top = 0 def isEmpty(self): if self.top==0: return True return False def isFull(self): pass def enqueue(self, x): self.queue.append(x) self.top += 1 def...
s056549925
p00001
u950683603
1,000
131,072
Wrong Answer
20
7,400
116
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
ans=[] for i in range (0,10): ans.append(input()) ans.sort(reverse=True) for i in range (0,3): print(ans[i])
s001741914
Accepted
20
7,632
121
ans=[] for i in range (0,10): ans.append(int(input())) ans.sort(reverse=True) for i in range (0,3): print(ans[i])
s687942989
p03997
u623516423
2,000
262,144
Wrong Answer
17
2,940
61
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h/2)
s231089669
Accepted
17
2,940
66
a=int(input()) b=int(input()) h=int(input()) print(int((a+b)*h/2))
s485778765
p04044
u652710582
2,000
262,144
Wrong Answer
17
3,060
126
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 sm...
NL = [ x for x in map(int,input().split()) ] cha = [] i = 0 while i < NL[0]: cha.append(input()) i += 1 print(sorted(cha))
s009026684
Accepted
18
3,060
135
NL = [ x for x in map(int,input().split()) ] cha = [] i = 0 while i < NL[0]: cha.append(input()) i += 1 print(''.join(sorted(cha)))
s706960946
p02607
u081714930
2,000
1,048,576
Wrong Answer
31
9,180
162
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
n = int(input()) lis = list(map(int,input().split())) cnt=0 n=0 for i in lis: if (i)%2 != 0 and n%2 != 0: cnt += 1 n += 1 print(n) print(cnt)
s684064014
Accepted
27
9,164
147
n = int(input()) lis = list(map(int,input().split())) cnt=0 n=1 for i in lis: if i%2 != 0 and n%2 != 0: cnt += 1 n += 1 print(cnt)
s750038711
p03044
u506858457
2,000
1,048,576
Wrong Answer
670
56,608
370
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices...
N=int(input()) links=[set() for _ in [0]*N] print(links) for i in range(1,N): u,v,w=map(int,input().split()) u-=1 v-=1 links[u].add((v,w)) links[v].add((u,w)) ans=[-1]*N q=[(0,0,-1)] while q: v,d,p=q.pop() if d%2==0: ans[v]=0 else: ans[v]=1 for u,w in links[v]: if u==p: continue ...
s916807011
Accepted
696
56,480
357
N=int(input()) links=[set() for _ in [0]*N] for i in range(1,N): u,v,w=map(int,input().split()) u-=1 v-=1 links[u].add((v,w)) links[v].add((u,w)) ans=[-1]*N q=[(0,0,-1)] while q: v,d,p=q.pop() if d%2==0: ans[v]=0 else: ans[v]=1 for u,w in links[v]: if u==p: continue q.append((u,w...
s405777284
p02606
u060012100
2,000
1,048,576
Wrong Answer
28
9,180
85
How many multiples of d are there among the integers between L and R (inclusive)?
L,S,R = map(int,input().split()) for i in range(L,S+1): if (i%R == 0): print(i)
s409844515
Accepted
26
9,156
101
L,S,R = map(int,input().split()) a = 0 for i in range(L,S+1): if (i%R == 0): a = a + 1 print(a)
s272781935
p03597
u079699418
2,000
262,144
Wrong Answer
26
9,020
35
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
x=int(input()) y=int(input()) x*x-y
s102291263
Accepted
28
9,136
43
x=int(input()) y=int(input()) print(x**2-y)
s700546679
p03645
u143492911
2,000
262,144
Wrong Answer
573
13,976
284
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 Snuk...
n,m=map(int,input().split()) s=[] k=[] for i in range(m): a,b=map(int,input().split()) if a==1: s.append(b) if b==n: k.append(1) s_i=set(s) k_i=set(k) for _ in s_i: if _ in k_i: print("POSSIBLE") break else: print("IMPOSSIBLE")
s359421791
Accepted
665
39,272
303
n,m=map(int,input().split()) t=[tuple(map(int,input().split()))for i in range(m)] ans=[] ans_2=[] for i in range(m): if t[i][0]==1: ans.append(t[i][1]) if t[i][1]==n: ans_2.append(t[i][0]) a=set(ans) b=set(ans_2) if a&b: print("POSSIBLE") else: print("IMPOSSIBLE")
s664954943
p02865
u334703235
2,000
1,048,576
Wrong Answer
21
3,316
75
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
a=int(input()) if a % 2 == 0: print(a / 2-1) else: print((a-1)/2)
s293820866
Accepted
17
2,940
95
a=int(input()) if a % 2 == 0: print(str(int(a / 2-1))) else: print(str(int((a-1)/2)))
s289274783
p03197
u693953100
2,000
1,048,576
Wrong Answer
182
7,072
134
There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or more apples from the tree and eat them. Here, the apples chosen a...
n = int(input()) a = [int(input()) for i in range(n)] for i in a: if i%2==1: print('frist') exit() print('second')
s449601005
Accepted
179
7,072
134
n = int(input()) a = [int(input()) for i in range(n)] for i in a: if i%2==1: print('first') exit() print('second')
s954198860
p03478
u798260206
2,000
262,144
Wrong Answer
20
2,940
139
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b = map(int,input().split()) ans = 0 for i in range(n): ione = i%10 iten = i//10 if a<=(ione+iten)<=b: ans += i print(ans)
s939895389
Accepted
32
3,064
137
N, A, B = map(int, input().split()) ans = 0 for i in range(1, N+1): if A <= sum(map(int, list(str(i)))) <= B: ans += i print(ans)
s376092675
p03434
u075401284
2,000
262,144
Wrong Answer
25
9,164
124
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 c...
n = int(input()) a = list(map(int, input().split())) a.sort() alice = sum(a[0:n:2]) bob = sum(a[1:n:2]) print(alice - bob)
s956466270
Accepted
29
9,092
139
n = int(input()) a = list(map(int, input().split())) a.sort(reverse = True) alice = sum(a[0:n:2]) bob = sum(a[1:n:2]) print(alice - bob)
s755381084
p03478
u571537830
2,000
262,144
Time Limit Exceeded
2,205
9,080
208
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split()) ans = 0 for i in range(1,n+1): mod = 0 while n != 0: mod = mod + (i % 10) i = i // 10 if mod >= a and mod <= b: ans += mod print(ans)
s575756878
Accepted
34
9,112
215
n, a, b = map(int, input().split()) ans = 0 for i in range(1,n+1): mod = 0 div = i while div > 0: mod += (div % 10) div //= 10 if mod >= a and mod <= b: ans += i print(ans)
s334467042
p04030
u888512581
2,000
262,144
Wrong Answer
17
2,940
126
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 stri...
s = list(input()) str = "" for i in range(len(s)): if s[i] == 'B': str = str[0:-2] else: str += s[i] print(str)
s835345503
Accepted
17
2,940
126
s = list(input()) str = "" for i in range(len(s)): if s[i] == 'B': str = str[0:-1] else: str += s[i] print(str)
s110319077
p02283
u684241248
2,000
131,072
Wrong Answer
20
5,608
1,528
Search trees are data structures that support dynamic set operations including insert, search, delete and so on. Thus a search tree can be used both as a dictionary and as a priority queue. Binary search tree is one of fundamental search trees. The keys in a binary search tree are always stored in such a way as to sat...
class Tree: def __init__(self, orders): self.root = None for order in orders: if len(order) == 1: self.inorder_print() self.preorder_print() else: self.insert(int(order[1])) def insert(self, key): z = Node(key) ...
s609816874
Accepted
6,850
243,920
1,545
class Tree: def __init__(self, orders): self.root = None for order in orders: if len(order) == 1: self.inorder_print() self.preorder_print() else: self.insert(int(order[1])) def insert(self, key): z = Node(key) ...
s857900439
p03110
u932719058
2,000
1,048,576
Wrong Answer
17
2,940
207
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000`...
n = int(input()) sum = 0 for i in range(n): a = input().split() if a[1] == 'BTC': sum += float(a[0])*380000 else: sum += float(a[0]) print(sum)
s061250770
Accepted
19
3,060
199
n = int(input()) sum = 0 for i in range(n): a = input().split() if a[1] == 'BTC': sum += float(a[0])*380000 else: sum += float(a[0]) print(sum)
s844025227
p03149
u667458133
2,000
1,048,576
Wrong Answer
17
2,940
103
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
N = list(map(int, input().split())) print('Yes' if 1 in N and 4 in N and 7 in N and 9 in N else 'No')
s120205896
Accepted
17
2,940
102
N = list(map(int, input().split())) print('YES' if 1 in N and 4 in N and 7 in N and 9 in N else 'NO')
s157089794
p02281
u510829608
1,000
131,072
Wrong Answer
20
7,656
758
Binary trees are defined recursively. A binary tree _T_ is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: \- a root node. \- a binary tree called its left subtree. \- a binary tree called its right subtree. Your task is to wr...
N = int(input()) tree = [None for _ in range(N)] root = set(range(N)) for i in range(N): i, l, r = map(int,input().split()) tree[i] = (l, r) root -= {l, r} root_node = root.pop() def preorder(i): if i == -1: return (l, r) = tree[i] print(" {}".format(i), end = "") preorder(l) ...
s023112529
Accepted
20
7,776
762
N = int(input()) tree = [None for _ in range(N)] root = set(range(N)) for i in range(N): i, l, r = map(int,input().split()) tree[i] = (l, r) root -= {l, r} root_node = root.pop() def preorder(i): if i == -1: return (l, r) = tree[i] print(" {}".format(i), end = "") preorder(l) ...
s143171122
p02409
u279955105
1,000
131,072
Wrong Answer
20
7,624
318
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth fl...
def print_list(lst) : a = ' '.join(list(map(str, lst))) print(a) n = int(input()) lst = [[[0 for w in range(10)] for q in range(3)] for e in range(4)] for _ in range(n): b,f,r,v = list(map(int, input().split())) lst[b-1][f-1][r-1] = v for i in range(4): print("#"*20) for j in range(3): print_list(lst[i][j])
s344683825
Accepted
20
5,624
365
n = int(input()) capasity = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] for i in range(n): b,f,r,v = map(int, input().split()) capasity[b-1][f-1][r-1] += v for i in range(4): for j in range(3): for k in range(10): print(' {}'.format(capasity[i][j][k]),end='') ...
s886501009
p03731
u103099441
2,000
262,144
Wrong Answer
901
25,196
156
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will pus...
n, t = map(int, input().split()) t_l = [int(i) for i in input().split()] cost = t for i in range(n - 1): t += min(t, t_l[i] - t_l[i - 1]) print(cost)
s773485600
Accepted
157
25,196
158
n, t = map(int, input().split()) t_l = [int(i) for i in input().split()] cost = t for i in range(1, n): cost += min(t, t_l[i] - t_l[i - 1]) print(cost)
s342701012
p04043
u524101931
2,000
262,144
Wrong Answer
17
3,060
214
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 ...
N = input() C5 = 2 C7 = 1 for i in N.split(): if i == '5': C5 -= 1 elif i == '7': C7 -= 1 else: print( 'No' ) break else: if C5 == 0 and C7 == 0: print( 'Yes' ) else: print( 'No' )
s317538704
Accepted
18
3,060
214
N = input() C5 = 2 C7 = 1 for i in N.split(): if i == '5': C5 -= 1 elif i == '7': C7 -= 1 else: print( 'NO' ) break else: if C5 == 0 and C7 == 0: print( 'YES' ) else: print( 'NO' )
s468045014
p03068
u662449766
2,000
1,048,576
Wrong Answer
17
2,940
207
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 `*`.
import sys input = sys.stdin.readline def main(): n = input() s = input() k = int(input()) print("".join([c if c == s[k - 1] else "*" for c in s])) if __name__ == "__main__": main()
s848873375
Accepted
17
2,940
221
import sys input = sys.stdin.readline def main(): n = int(input()) s = input().rstrip() k = int(input()) print("".join([c if c == s[k - 1] else "*" for c in s])) if __name__ == "__main__": main()
s608525334
p03478
u653883313
2,000
262,144
Wrong Answer
27
2,940
203
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()) Ssum = 0 for i in range(1, n+1): tmp = i sum = 0 while i>0 : sum = i%10 i //= 10 if a<=sum and sum<=b: Ssum += tmp print(Ssum)
s906227284
Accepted
30
2,940
204
n, a, b= map(int, input().split()) Ssum = 0 for i in range(1, n+1): tmp = i sum = 0 while i>0 : sum += i%10 i //= 10 if a<=sum and sum<=b: Ssum += tmp print(Ssum)
s173363072
p03778
u594956556
2,000
262,144
Wrong Answer
17
2,940
74
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the min...
W, a, b = map(int, input().split()) print(max(0, max(a, b) - min(a, b)+W))
s137687156
Accepted
17
2,940
79
W, a, b = map(int, input().split()) print(max(0, max(a, b) - (min(a, b) + W)))
s195594063
p02692
u307592354
2,000
1,048,576
Wrong Answer
146
17,516
1,057
There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or ...
def resolve(): N,A,B,C = map(int,input().split()) S=[input() for i in range(N)] ans =[] for s in S: if s =="AB": if A ==B ==0: print("No") return elif A>B: A-=1 B+=1 ans.append("B") ...
s672856286
Accepted
150
17,324
1,933
def resolve(): N,A,B,C = map(int,input().split()) S=[input() for i in range(N)] ans =[] for i in range(N): s=S[i] if s =="AB": if A ==B ==0: print("No") return if A == B ==1 and C == 0 and i < N-1: if S[i+1] =="...
s849786194
p03089
u593567568
2,000
1,048,576
Wrong Answer
31
9,088
308
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N oper...
N = int(input()) B = list(map(int,input().split())) ans = [] while N > 0: ok = False for i in range(N)[::-1]: b = B[i] if b == (i+1): ans.append(b) ok = True break if ok: N -= 1 else: break if N != 0: print(-1) else: print("\n".join(map(str,ans[::-1])))
s795947623
Accepted
29
9,152
419
N = int(input()) B = list(map(int,input().split())) ans = [] while N > 0: ok = False for i in range(N)[::-1]: b = B[i] if b == (i+1): ans.append(b) ok = True k = i break if not ok: break else: newB = [] for i in range(N): if i != k: newB.append(B[i])...
s834072427
p03433
u439392790
2,000
262,144
Wrong Answer
19
2,940
86
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N=int(input()) A=int(input()) if (N-A)%500==0: print('Yes') else: print('No')
s381698808
Accepted
17
2,940
82
N=int(input()) A=int(input()) if N%500<=A: print('Yes') else: print('No')