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 t on a number line is represented by |s-t|.
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 break
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 above for the first time?
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 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
# 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][k]+c[k][j]) ans=0 for i in range(h): for j in range(w): if a[i][j]==-1: continue ans+=c[a[i][j]][1]
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][k]+c[k][j]) ans=0 for i in range(h): for j in range(w): if a[i][j]==-1: continue ans+=c[a[i][j]][1] print(ans)
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 are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7.
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) b4 = math.factorial(A - 1) % (10**9 + 7) return a1 * a2 / b1 / b2 / b3 / b4 def sigma(func, frm, to): result = 0 for i in range(frm, to+1): result += func(i) return result print(sigma(f, 0, W-B-1))
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] * ifac[B+n] * ifac[H-A-1] * ifac[W-B-1-n] * ifac[A-1] def sigma(func, frm, to): result = 0 for i in range(frm, to+1): result += func(i) return result print(sigma(f, 0, W-B-1)%MOD)
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 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.
#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) AL[e].append(s) que = deque() pb = 1, 1 que.append(pb) ANS = [0 for i in range(n+1)] while(que): pb = que.popleft() p = pb[0] b = pb[1] if check[p] == 1: continue elif check[p] == 0: ANS[p] = b check[p] = 1 for num in AL[p]: que.append((num, p)) print("yes") for i in range(n+1): if i in [0, 1]: continue else: print(ANS[i]) if __name__ == '__main__': main()
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) AL[e].append(s) que = deque() pb = 1, 1 que.append(pb) ANS = [0 for i in range(n+1)] while(que): pb = que.popleft() p = pb[0] b = pb[1] if check[p] == 1: continue elif check[p] == 0: ANS[p] = b check[p] = 1 for num in AL[p]: que.append((num, p)) print("Yes") for i in range(n+1): if i in [0, 1]: continue else: print(ANS[i]) if __name__ == '__main__': main()
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 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.
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 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.
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, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
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") else: print("F")
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 the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
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, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
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_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1] n_swap += 1 flag = True sorted_i += 1 print(' '.join([str(i) for i in raw_list])) print(n_swap) bubble_sort(data)
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_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1] n_swap += 1 flag = True sorted_i += 1 print(' '.join([str(i) for i in raw_list])) print(n_swap) bubble_sort(data)
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 next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
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(stock, money)) elif A[i-1] > A[i]: money += stock * A[i-1] stock = 0 # print('sell - stock: {}, money: {}'.format(stock, money)) if A[N-2] < A[N-1]: money += stock * A[N-1] stock = 0 # print('sell - stock: {}, money: {}'.format(stock, money)) print(money) ########## if __name__ == "__main__": d()
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)) elif A[i-1] > A[i]: money += stock * A[i-1] stock = 0 # print('sell - stock: {}, money: {}'.format(stock, money)) if A[N-2] <= A[N-1]: money += stock * A[N-1] stock = 0 # print('sell - stock: {}, money: {}'.format(stock, money)) print(money) ########## if __name__ == "__main__": d()
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 containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
import numpy as np 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: if S[y+h][x+w] == '#': continue elif S[y+h][x+w] == '.': S[y+h][x+w] = 1 else: S[y+h][x+w] += 1 print(S)
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 <= x+w < W and 0 <= y+h < H: if S[y+h][x+w] == '#': continue elif S[y+h][x+w] == '.': S[y+h][x+w] = 1 else: S[y+h][x+w] += 1 for s in S: print(''.join(map(str, s)))
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 check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
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(D): s[i] = list(map(int,input().split())) last_hold = [0]*26 score = [0]*(D+1) for i in range(D): score[i+1] += score[i] t = int(input()) last_hold[t-1] = i+1 comp = 0 k = 1 score[i+1] += s[i][t-1] # print(s[i][t-1],"s") score[i+1] -= complain(comp,c,k,last_hold) for i in range(D): print(score[i+1]) # (1~26)
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 range(D): s[i] = list(map(int,input().split())) last_hold = [0]*26 score = [0]*(D+1) for i in range(D): score[i+1] += score[i] t = int(input()) last_hold[t-1] = i+1 comp = 0 k = 1 score[i+1] += s[i][t-1] # print(s[i][t-1],"s") comp = complain(comp,c,k,last_hold,i) score[i+1] -= comp # print(comp,"comp") # print(score[i+1],"score") for i in range(D): print(score[i+1]) # (1~26) # 18398 # 35037 # 51140 # 65837 # 79325
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 attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
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 inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
#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 t on a number line is represented by |s-t|.
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: chk.append(1) chk.sort() print(chk) print(count) if count <= k: print(0) exit() else: print(sum(chk[:count-k])) exit()
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: chk.append(1) chk.sort() #print(chk) #print(count) if count <= k: print(0) exit() else: print(sum(chk[:count-k])) exit()
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 smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
n, l = map(int, input().split()) 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 damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
# -- 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 else: turn = int((H - sum(th)) / max(sl)) + N print(turn)
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 += 1 if H <= 0: break else: break if H > 0: turn += math.ceil(H / sl_max) print(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 damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
# 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 len(b)>k: H-=b[k] k+=1 count+=1 else: count+=H//max(a) H=0 print(count)
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(b) while H>0: if lenb>k: H-=b[k] k+=1 count+=1 else: count+=H//maxa if(H%maxa!=0): count+=1 H=0 print(count)
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 |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
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 Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
# 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]: # print(Cb) t=Cb[N-1-j] Cb[N-1-j]=Cb[N-2-j] Cb[N-2-j]=t fl=1 # print(C) for i in range(N): Cb[i][1]=str(Cb[i][1]) # print(Cb) Cb[i]="".join(Cb[i]) print(" ".join(Cb)) p="stable" print(p) 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])) Co=[] for i in range(N): Co.append([]) # print(Co) Co[i].append(Ci[i][0]) Co[i].append(int(Ci[i][1])) for i in range(N): minj=i for j in range(i,N): # print(C) if C[j][1]<C[minj][1]: minj=j elif C[j][1]==C[minj][1]: k=0 while k<N and C[j][1]!=Co[k][1]: k+=1 if k<N and C[j][0]!=Co[k][0]: p="not stable" if i!=minj: t=C[i] C[i]=C[minj] C[minj]=t for i in range(N): C[i][1]=str(C[i][1]) C[i]="".join(C[i]) print(" ".join(C)) print(p)
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]: # print(Cb) t=Cb[N-1-j] Cb[N-1-j]=Cb[N-2-j] Cb[N-2-j]=t fl=1 # print(C) for i in range(N): Cb[i][1]=str(Cb[i][1]) # print(Cb) Cb[i]="".join(Cb[i]) print(" ".join(Cb)) p="Stable" print(p) 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])) Co=[] for i in range(N): Co.append([]) # print(Co) Co[i].append(Ci[i][0]) Co[i].append(int(Ci[i][1])) for i in range(N-1): minj=i for j in range(i,N): # print(C) if C[j][1]<C[minj][1]: minj=j elif C[j][1]==C[minj][1]: k=0 while k<N and C[minj][1]!=Co[k][1]: k+=1 # print (j) if k<N and C[minj][0]!=Co[k][0]: p="Not stable" if i!=minj: t=C[i] C[i]=C[minj] C[minj]=t for i in range(N): C[i][1]=str(C[i][1]) C[i]="".join(C[i]) print(" ".join(C)) print(p)
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 given for this problem.
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 coin are different.
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 type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
n = int(input()) k = int(input()) 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 t on a number line is represented by |s-t|.
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 those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
n, m = map(int, input().split()) 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) if flag2 == False: flag = False break if flag==True: print("YES") else: print("NO")
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) if(tmp_s == t): flag2 = True i += len(t) if flag2 == False: flag = False break if flag==True: print("YES") else: print("NO")
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 many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
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 input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
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 proved that we can always make A, B and C all equal by repeatedly performing these operations.
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 final integer on the blackboard and a sequence of operations that maximizes the final integer.
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] print(x,y) elif a[0]<=0: m=-sum(a)+a[0]*2 print(m) for i in range(n-1): if i==0: y=a[1] x=a[0] else: x=x-y y=a[i+1] print(x,y) else: for i in range(n): if a[i]<=0: mem=i break m=0 for j in range(n): m+=abs(a[j]) print(m) for k in range(n-1): if k==0: x=a[mem] y=a[k] elif k==mem-1: y=x-y x=a[k] elif k<mem-1: x=x-y y=a[k] elif k>mem-1: x=x-y y=a[k+1] print(x,y)
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: x=Y y=a[i] print(x,y) Y=x-y else: x=X y=a[i] print(x,y) X=x-y print(X,Y)
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 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(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 damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
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] if h <= 0: print(ans) break if max_b > max_a: h -= max_b ans += 1 if h <= 0: print(ans) else: print(ans+math.ceil(h//max_a)) else: print(ans+math.ceil(h//max_a))
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 - 1) // a print(ans)
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 name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.
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) for s in sum_row])) from pprint import pprint pprint(data) pprint(sum_row)
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) for s in sum_row]))
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 A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
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] = targ[l - i - 1] targ[l - i - 1] = disp print(" ".join([str(n) for n in targ]))
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 to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
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-b)) elif m>1: b=nk*(m+1)//2 c=nk*(m-1)//2 ans=min(ans,max(a,b,c)-min(a,b,c))
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-b)) elif m>1: b=nk*(m+1)//2 c=nk*(m-1)//2 ans=min(ans,max(a,b,c)-min(a,b,c)) for i in range(1,m): a=i*n nk=m-i if nk%2==0: b=n*(nk//2) ans=min(ans,abs(a-b)) elif nk>1: b=n*((nk+1)//2) c=n*((nk-1)//2) ans=min(ans,max(a,b,c)-min(a,b,c)) if n%2==0: b=nk*n//2 ans=min(ans,abs(a-b)) elif n>1: b=nk*(n+1)//2 c=nk*(n-1)//2 ans=min(ans,max(a,b,c)-min(a,b,c)) print(ans)
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 inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
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_max>=y_min): print('War') return print('No war') if __name__ == "__main__": main()
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_min-x_max)<1): print('War') return print('No War') if __name__ == "__main__": main()
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 the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
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 num.setdefault(n*3,N*D+1) > c+B: heapq.heappush(q,( c+B, n*3 )) num[n*3] = c+B if num.setdefault(n*5,N*D+1) > c+C: heapq.heappush(q,( c+C, n*5 )) num[n*5] = c+C if num.setdefault(n+1,N*D+1) > c+D: heapq.heappush(q,( c+D, n+1 )) num[n+1] = c+D if num.setdefault(n-1,N*D+1) > c+D: heapq.heappush(q,( c+D, n-1 )) num[n-1] = c+D # print(num.setdefault(N,-1)) # T = int(input()) for i in range(T): N,A,B,C,D = map(int, input().split()) pay(N,A,B,C,D)
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, 2) if m == 0: heapq.heappush(q,( c0+A, n2 )) else: heapq.heappush(q,( c0+D+A, n2 )) heapq.heappush(q,( c0+D+A, n2+1 )) # n3, m = divmod(n0, 3) if m == 0: heapq.heappush(q,( c0+B, n3 )) elif m == 1: heapq.heappush(q,( c0+D+B, n3 )) else: heapq.heappush(q,( c0+D+B, n3+1 )) # n5, m = divmod(n0, 5) if m == 0: heapq.heappush(q,( c0+C, n5 )) elif m <= 2: heapq.heappush(q,( c0+D*m+C, n5 )) else: heapq.heappush(q,( c0+D*(5-m)+C, n5+1 )) # print(cost) # T = int(input()) for i in range(T): N,A,B,C,D = map(int, input().split()) pay2win()
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 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 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 in graph[v]: if visited[i]:continue visited[i] = True mark[i] = v d.append(i) print('Yes') for i in mark: print(i+1)
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 in graph[v]: if visited[i]:continue visited[i] = True mark[i] = v d.append(i) print('Yes') for i in mark[1:]: print(i+1)
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 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()) 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 be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n=int(input()) print(800*n-200*n//15)
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 with `Z`.
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(len(b)): print(b[i])
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 between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
#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 dequeue(self): if self.top>0: self.top -= 1 return self.queue.pop() else: print("there aren't enough values in Queue") def main(): n, q = map(int, input().split()) A = [ list(map(lambda x: int(x) if x.isdigit() else x, input().split())) for i in range(n) ] A = [{'name': name, 'time': time} for name, time in A] queue = MyQueue() for a in A: queue.enqueue(a) elapsed = 0 while not queue.isEmpty(): elapsed += q job = queue.dequeue() job['time'] = job['time'] - q if job['time']>0: queue.enqueue(job) else: print(job['name']+ ' ' + str(elapsed)) main()
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 dequeue(self): if self.top>0: self.top -= 1 return self.queue.pop(0) else: print("there aren't enough values in Queue") def main(): n, q = map(int, input().split()) A = [ list(map(lambda x: int(x) if x.isdigit() else x, input().split())) for i in range(n) ] A = [{'name': name, 'time': time} for name, time in A] queue = MyQueue() for a in A: queue.enqueue(a) elapsed = 0 while not queue.isEmpty(): job = queue.dequeue() if job['time']>q: elapsed += q job['time'] = job['time'] - q queue.enqueue(job) else: elapsed += job['time'] print(job['name']+ ' ' + str(elapsed)) main()
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 smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
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 painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
N=int(input()) 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 q.append((u,w+d,v)) print('\n'.join(map(str,ans)))
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+d,v)) print('\n'.join(map(str,ans)))
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 Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
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 at the same time must all have different colors. The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?
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 cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = int(input()) 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 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 = 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 satisfy the following binary search tree property: * Let $x$ be a node in a binary search tree. If $y$ is a node in the left subtree of $x$, then $y.key \leq x.key$. If $y$ is a node in the right subtree of $x$, then $x.key \leq y.key$. The following figure shows an example of the binary search tree. For example, keys of nodes which belong to the left sub-tree of the node containing 80 are less than or equal to 80, and keys of nodes which belong to the right sub-tree are more than or equal to 80. The binary search tree property allows us to print out all the keys in the tree in sorted order by an inorder tree walk. A binary search tree should be implemented in such a way that the binary search tree property continues to hold after modifications by insertions and deletions. A binary search tree can be represented by a linked data structure in which each node is an object. In addition to a key field and satellite data, each node contains fields _left_ , _right_ , and _p_ that point to the nodes corresponding to its left child, its right child, and its parent, respectively. To insert a new value $v$ into a binary search tree $T$, we can use the procedure insert as shown in the following pseudo code. The insert procedure is passed a node $z$ for which $z.key = v$, $z.left = NIL$, and $z.right = NIL$. The procedure modifies $T$ and some of the fields of $z$ in such a way that $z$ is inserted into an appropriate position in the tree. 1 insert(T, z) 2 y = NIL // parent of x 3 x = 'the root of T' 4 while x ≠ NIL 5 y = x // set the parent 6 if z.key < x.key 7 x = x.left // move to the left child 8 else 9 x = x.right // move to the right child 10 z.p = y 11 12 if y == NIL // T is empty 13 'the root of T' = z 14 else if z.key < y.key 15 y.left = z // z is the left child of y 16 else 17 y.right = z // z is the right child of y Write a program which performs the following operations to a binary search tree $T$. * insert $k$: Insert a node containing $k$ as key into $T$. * print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. You should use the above pseudo code to implement the insert operation. $T$ is empty at the initial state.
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) y = None x = self.root while x: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if not y: self.root = z elif z.key < y.key: y.left = z else: y.right = z def inorder_print(self): self.root.inorder_print() print() def preorder_print(self): self.root.preorder_print() print() class Node: def __init__(self, key): self.key = key self.parent = None self.left = None self.right = None def inorder_print(self): if self.left: self.left.inorder_print() print(' {}'.format(self.key), end='') if self.right: self.right.inorder_print() def preorder_print(self): print(' {}'.format(self.key), end='') if self.left: self.left.preorder_print() if self.right: self.right.preorder_print() if __name__ == '__main__': import sys m = int(input()) orders = [line.strip().split() for line in sys.stdin]
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) y = None x = self.root while x: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if not y: self.root = z elif z.key < y.key: y.left = z else: y.right = z def inorder_print(self): self.root.inorder_print() print() def preorder_print(self): self.root.preorder_print() print() class Node: def __init__(self, key): self.key = key self.parent = None self.left = None self.right = None def inorder_print(self): if self.left: self.left.inorder_print() print(' {}'.format(self.key), end='') if self.right: self.right.inorder_print() def preorder_print(self): print(' {}'.format(self.key), end='') if self.left: self.left.preorder_print() if self.right: self.right.preorder_print() if __name__ == '__main__': import sys m = int(input()) orders = [line.strip().split() for line in sys.stdin] Tree(orders)
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` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
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 write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: 1. Print the root, the left subtree and right subtree (preorder). 2. Print the left subtree, the root and right subtree (inorder). 3. Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
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) preorder(r) def inorder(i): if i == -1: return (l, r) = tree[i] inorder(l) print(" {}".format(i), end = "") inorder(r) def postorder(i): if i == -1: return (l, r) = tree[i] inorder(l) inorder(r) print(" {}".format(i), end = "") print('Preorder') preorder(root_node) print() print('Inorder') inorder(root_node) print() print('Postorder') postorder(root_node) print()
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) preorder(r) def inorder(i): if i == -1: return (l, r) = tree[i] inorder(l) print(" {}".format(i), end = "") inorder(r) def postorder(i): if i == -1: return (l, r) = tree[i] postorder(l) postorder(r) print(" {}".format(i), end = "") print('Preorder') preorder(root_node) print() print('Inorder') inorder(root_node) print() print('Postorder') postorder(root_node) print()
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 floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
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='') print() if i != 3: print('#'*20)
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 push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
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 of the phrases once, in some order.
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 minimum distance it needs to be moved.
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 C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
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") else: A+=1 B-=1 ans.append("A") elif s =="BC": if C ==B ==0: print("No") return elif C>B: C-=1 B+=1 ans.append("B") else: C+=1 B-=1 ans.append("C") elif s =="AC": if C ==A ==0: print("No") return elif C>A: C-=1 A+=1 ans.append("A") else: C+=1 A-=1 ans.append("C") print("\n".join(ans)) if __name__ == "__main__": resolve()
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] =="AC": A+=1 B-=1 ans.append("A") else: A-=1 B+=1 ans.append("B") elif A>B: A-=1 B+=1 ans.append("B") else: A+=1 B-=1 ans.append("A") elif s =="BC": if C ==B ==0: print("No") return if C == B ==1 and A == 0 and i < N-1: if S[i+1] =="AC": C+=1 B-=1 ans.append("C") else: C-=1 B+=1 ans.append("B") elif C>B: C-=1 B+=1 ans.append("B") else: C+=1 B-=1 ans.append("C") elif s =="AC": if C ==A ==0: print("No") return if C == A ==1 and B == 0 and i < N-1: if S[i+1] =="AB": A+=1 C-=1 ans.append("A") else: C+=1 A-=1 ans.append("C") elif C>A: C-=1 A+=1 ans.append("A") else: C+=1 A-=1 ans.append("C") print("Yes") print("\n".join(ans)) if __name__ == "__main__": resolve()
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 operations. If it is, show one possible sequence of operations that achieves it.
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]) B = newB N -= 1 if N != 0: print(-1) else: print("\n".join(map(str,ans[::-1])))
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')