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
s899586059
p02389
u890164142
1,000
131,072
Wrong Answer
20
7,716
72
Write a program which calculates the area and perimeter of a given rectangle.
a, b = [int(s) for s in input().split()] print(a * b) print(2 * (a + b))
s855649047
Accepted
20
7,632
66
a, b = [int(s) for s in input().split()] print(a * b, 2 * (a + b))
s198795592
p02393
u987701388
1,000
131,072
Wrong Answer
20
5,596
69
Write a program which reads three integers, and prints them in ascending order.
a= list(int(i) for i in input().split()) for s in a: print(s)
s544705484
Accepted
20
5,600
97
a= list(int(i) for i in input().split()) a.sort() risuto = ' '.join(map(str,a)) print(risuto)
s886929591
p03836
u026788530
2,000
262,144
Wrong Answer
31
4,468
535
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
l = input().split(' ') y = int(l[3]) - int(l[1]) x = int(l[2]) - int(l[0]) def my_print(i,str): for j in range(i): print(str,end='') my_print(y,'U') my_print(x,'R') my_print(y,'D') my_print(x+1,'L') my_print(y+1,'U') my_print(x+1,'R') my_print(1,'D') my_print(1,'R') my_print(y,'D') my_print(x+1,'L') my_print(1,'U') print()
s485702342
Accepted
32
4,468
537
l = input().split(' ') y = int(l[3]) - int(l[1]) x = int(l[2]) - int(l[0]) def my_print(i,str): for j in range(i): print(str,end='') my_print(y,'U') my_print(x,'R') my_print(y,'D') my_print(x+1,'L') my_print(y+1,'U') my_print(x+1,'R') my_print(1,'D') my_print(1,'R') my_print(y+1,'D') my_print(x+1,'L') my_print(1,'U') print()
s500873447
p03523
u787456042
2,000
262,144
Wrong Answer
22
3,188
72
You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
import re;print("YNeos"[(re.match("^A?KIHA?BA?RA?$",input())==None)::2])
s430153071
Accepted
22
3,188
72
import re;print("YNEOS"[(re.match("^A?KIHA?BA?RA?$",input())==None)::2])
s246832255
p03471
u391340825
2,000
262,144
Wrong Answer
521
3,064
350
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
def main(): linie = input() vector = [int(x) for x in linie.split()] n = vector[0] y = vector[1] ok = 0 nr1 = -1 nr2 = -1 nr3 = -1 for i in range(n): for j in range(n - i): if i * 1000 + j * 5000 + (n - i - j) * 10000 == y: nr1 = i nr2 = j nr3 = (n - i - j) print(nr1, nr2, nr3) if __name__ == "__main__": main()
s296118612
Accepted
529
3,064
373
def main(): linie = input() vector = [int(x) for x in linie.split()] n = vector[0] y = vector[1] ok = 0 nr1 = -1 nr2 = -1 nr3 = -1 nr = n + 1 for i in range(0, n + 1): for j in range(n + 1 - i): if i * 1000 + j * 5000 + (n - i - j) * 10000 == y: nr1 = i nr2 = j nr3 = (n - i - j) print(nr3, nr2, nr1) if __name__ == "__main__": main()
s553573708
p04030
u100418016
2,000
262,144
Wrong Answer
17
2,940
131
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?
arr =list(input()) ret="" for st in arr: if(st == "B"): ret = ret[:len(st)-1] else: ret = ret + st print(ret)
s901619818
Accepted
19
2,940
129
arr =list(input()) ret="" for st in arr: if(st == "B"): ret = ret[:len(ret)-1] else: ret = ret + st print(ret)
s947201614
p03556
u119982147
2,000
262,144
Wrong Answer
17
2,940
63
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.
import math N = int(input()) rN = math.sqrt(N) print(int(rN))
s918959115
Accepted
23
3,316
71
import math N = int(input()) rN = math.sqrt(N) A = int(rN)**2 print(A)
s439388137
p02694
u240256924
2,000
1,048,576
Wrong Answer
24
9,152
78
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()) a= 100 n = 0 while a<=X: a=int(a*1.01) n+=1 print(n)
s738875250
Accepted
23
9,152
77
X = int(input()) a= 100 n = 0 while a<X: a=int(a*1.01) n+=1 print(n)
s719897881
p03160
u846385882
2,000
1,048,576
Wrong Answer
155
12,488
302
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.
import numpy as np #N=int(input()) #h=list(map(int,input().split())) N=4 h=[10,30,40,20] dp=np.zeros(N) print(dp) dp[1]=abs(h[1]-h[0]) print(dp) for i in range(N-2): dp[i+2]=min(abs(h[i+2]-h[i])+dp[i],abs(h[i+2]-h[i+1])+dp[i+1]) print(dp) #dp[2]=min(h[2]-h[0],h[1]-h[0]) #total print(dp[-1])
s221273902
Accepted
538
22,840
316
import numpy as np N=int(input()) h=list(map(int,input().split())) #N=4 #h=[10,30,40,20] dp=np.zeros(N) #print(dp) dp[1]=abs(h[1]-h[0]) #print(dp) for i in range(N-2): dp[i+2]=min(abs(h[i+2]-h[i])+dp[i],abs(h[i+2]-h[i+1])+dp[i+1]) # print(dp) #dp[2]=min(h[2]-h[0],h[1]-h[0]) #total print(int(dp[-1]))
s058767555
p03162
u807772568
2,000
1,048,576
Wrong Answer
1,042
47,328
291
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
a = int(input()) b = [] m = 0 for i in range(a): b.append(list(map(int,input().split()))) c = [[0,0,0] for i in range(a+1)] for i in range(a): for j in range(3): for k in range(3): if j == k: continue else: c[i+1][k] = max(c[i+1][k],c[i][k] + b[i][j]) print(max(c[-1]))
s749717003
Accepted
1,024
47,328
292
a = int(input()) b = [] m = 0 for i in range(a): b.append(list(map(int,input().split()))) c = [[0,0,0] for i in range(a+1)] for i in range(a): for j in range(3): for k in range(3): if j == k: continue else: c[i+1][k] = max(c[i+1][k],c[i][j] + b[i][k]) print(max(c[-1]))
s227813895
p03385
u485566817
2,000
262,144
Wrong Answer
17
2,940
71
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
s = set(input()) if len(s) == 3: print("YES") else: print("NO")
s924532415
Accepted
17
2,940
71
s = set(input()) if len(s) == 3: print("Yes") else: print("No")
s332607064
p03695
u103902792
2,000
262,144
Wrong Answer
17
3,064
281
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
n = int(input()) ai = list(map(int,input().split())) aj = list(map(lambda x:int(x/400),ai)) print(aj) rainbow = 0 for e in aj: if e >= 8: rainbow += 1 ak= set(aj) ans = 0 for e in ak: if e < 8: ans += 1 print(max(1,ans) ,end='') print(' ' ,end = '') print(ans+ rainbow)
s593350299
Accepted
28
9,056
257
n = int(input()) A = list(map(int,input().split())) col = [0 for _ in range(9)] for a in A: if a >= 3200: col[8] += 1 continue col[a//400] = 1 ans_min = sum(col[:-1]) if ans_min == 0 and col[-1] != 0: ans_min = 1 print(ans_min, sum(col))
s673796196
p02694
u676258045
2,000
1,048,576
Time Limit Exceeded
2,206
9,132
79
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x = int(input()) temp = int(100) while temp < x: temp *= 0.01 print(temp)
s695983930
Accepted
22
9,076
133
import math x = int(input()) temp = int(100) ans = int(0) while temp < x: temp += math.floor(temp * 0.01) ans += 1 print(ans)
s415288157
p02747
u578208203
2,000
1,048,576
Wrong Answer
17
3,064
289
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
if __name__ == '__main__': S=input() i=0 j=len(S) print(j) if j/2==0: for l in range(0,len(S),2): print(l) i=0 if(S[l]=='h' and S[l+1]=='i'): i=1 if i==1: print('Yes') else: print('NO')
s921302166
Accepted
17
2,940
256
if __name__ == '__main__': S=input() i=0 j=len(S) if j%2==0: for l in range(0,len(S),2): i=0 if(S[l]=='h' and S[l+1]=='i'): i=1 if i==1: print('Yes') else: print('No')
s887974517
p03494
u859897687
2,000
262,144
Wrong Answer
18
3,188
161
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n=int(input()) m=list(map(int,input().split())) t=1 ans=0 while t>0: for i in range(n): if m[i]%2>0: t=0 break m[i]//=2 ans+=1 print(ans)
s361970203
Accepted
19
3,060
174
n=int(input()) m=list(map(int,input().split())) t=1 ans=-1 while t>0: for i in range(n): if m[i]%2>0: t=0 break else: m[i]//=2 ans+=1 print(ans)
s510811822
p03545
u669062920
2,000
262,144
Wrong Answer
149
12,504
553
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.
import numpy as np s = [w for w in input()] length = len(s) for i in range(2 ** (length-1)): b = format(i, 'b') b_len = len(b) pad_width = (length - b_len, 0) b_pad = np.pad([n for n in b], pad_width, 'constant', constant_values=0) score = int(s[0]) result = s[0] for flag, num in zip(b_pad, s[1:]): if flag == '1': score += int(num) result += '+' + num else: score -= int(num) result += '-' + num if score == 7: print(result+'=7') break
s893725307
Accepted
165
13,176
541
import numpy as np s = [w for w in input()] length = len(s) for i in range(2 ** (length-1)): b = format(i, 'b') b_len = len(b) pad_width = ((length-1) - b_len, 0) b_pad = np.pad([int(n) for n in b], pad_width, 'constant') score = int(s[0]) result = s[0] for flag, num in zip(b_pad, s[1:]): if flag == 1: score += int(num) result += '+' + num else: score -= int(num) result += '-' + num if score == 7: print(result+'=7') break
s347930301
p04029
u483151310
2,000
262,144
Wrong Answer
17
2,940
204
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?
s = input() # print(s[0]) ans = [] for key in range(len(s)): if s[key] == "0" or s[key] == "1": ans.append(s[key]) if s[key] == "B": ans.pop(-1) print("".join(ans))
s364388176
Accepted
18
2,940
77
N = int(input()) # N = 5 cnt = 0 for i in range(N+1): cnt += i print(cnt)
s920838783
p03836
u888337853
2,000
262,144
Wrong Answer
309
22,160
724
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
import sys # import re import math import collections import bisect import itertools import fractions # import functools import copy import heapq import decimal # import statistics import queue import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): sx, sy, tx, ty = ns() ans = [] ans.extend(["U"] * (ty - sy)) ans.extend((["R"] * (tx - sx))) ans.extend(["D"] * ((ty - sy))) ans.extend((["L"] * (tx - sx))) print(*ans, sep="") if __name__ == '__main__': main()
s418188601
Accepted
164
15,004
954
import sys # import re import math import collections import bisect import itertools import fractions # import functools import copy import heapq import decimal # import statistics import queue import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): sx, sy, tx, ty = ns() ans = [] ans.extend(["U"] * (ty - sy)) ans.extend((["R"] * (tx - sx))) ans.extend(["D"] * ((ty - sy))) ans.extend((["L"] * (tx - sx))) ans.extend(["L"]) ans.extend(["U"] * (ty - sy + 1)) ans.extend((["R"] * (tx - sx + 1))) ans.extend(["DR"]) ans.extend(["D"] * ((ty - sy + 1))) ans.extend((["L"] * (tx - sx + 1))) ans.extend(["U"]) print(*ans, sep="") if __name__ == '__main__': main()
s668158527
p03971
u430223993
2,000
262,144
Wrong Answer
107
4,016
340
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()) s = input() passed = 0 passed_b = 0 for i in s: if i == 'a': print('Yes') if passed <= a+b else print('No') passed += 1 elif i == 'b': print('Yes') if (passed <= a+b) and (passed_b < b) else print('No') passed += 1 passed_b += 1 else: print('No')
s205609142
Accepted
103
4,016
418
n,a,b = map(int, input().split()) s = input() passed = 0 passed_b = 0 for i in s: if i == 'a': if passed < a+b: print('Yes') passed += 1 else: print('No') elif i == 'b': if (passed < a+b) and (passed_b < b): print('Yes') passed += 1 passed_b += 1 else: print('No') else: print('No')
s566405677
p03545
u457601965
2,000
262,144
Wrong Answer
33
9,220
465
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.
import sys import itertools a, b, c, d = list(input()) print(a, b, c,d) lst = ['-', '+'] for i, j, k in itertools.product(range(2), range(2), range(2)): ans = int(a) if i: ans += int(b) else: ans -= int(b) if j: ans += int(c) else: ans -= int(c) if k: ans += int(d) else: ans -= int(d) if ans == 7: print(a,lst[i],b,lst[j],c,lst[k],d,'=7',sep='') sys.exit()
s560699791
Accepted
32
9,148
442
import sys import itertools a, b, c, d = list(input()) lst = ['-', '+'] for i, j, k in itertools.product(range(2), range(2), range(2)): ans = int(a) if i: ans += int(b) else: ans -= int(b) if j: ans += int(c) else: ans -= int(c) if k: ans += int(d) else: ans -= int(d) if ans == 7: print(a,lst[i],b,lst[j],c,lst[k],d,'=7',sep='') break
s764338663
p03722
u899866702
2,000
262,144
Wrong Answer
1,225
8,232
621
There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
INF = float('inf') def Bellmanford(n, e, s): d = [INF]*n d[s] = 0 for i in range(n): print(i) for e_from, e_to, e_cost in e: if d[e_from] != INF and d[e_to] > d[e_from] + e_cost: print("aaa") d[e_to] = d[e_from] + e_cost if i == n-1: return 'inf' return -d[n-1] n,m = (int(x) for x in input().split()) edges = [None] * m for i in range(m): ai, bi, ci = map(int, input().split()) edges[i] = (ai-1, bi-1, -ci) ans = Bellmanford(n, edges, 0) print(ans)
s789558488
Accepted
590
3,316
603
INF = float('inf') def Bellmanford(n, e, s): d = [INF]*n d[s] = 0 for i in range(n): for e_from, e_to, e_cost in e: if d[e_from] != INF and d[e_to] > d[e_from] + e_cost: d[e_to] = d[e_from] + e_cost if i == n-1 and e_to == n-1: return 'inf' return -d[n-1] n,m = (int(x) for x in input().split()) edges = [None] * m for i in range(m): ai, bi, ci = map(int, input().split()) edges[i] = (ai-1, bi-1, -ci) ans = Bellmanford(n, edges, 0) print(ans)
s056857818
p03005
u047816928
2,000
1,048,576
Wrong Answer
17
2,940
53
Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?
N, K = [int(c) for c in input().split()] print(N-K-1)
s806413655
Accepted
17
2,940
83
N, K = [int(c) for c in input().split()] if K==1: print(0) else: print(N-K)
s617336418
p03693
u138486156
2,000
262,144
Wrong Answer
17
2,940
99
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) n = int(r + g + b) if n % 4: print("NO") else: print("YES")
s146003693
Accepted
17
2,940
86
r, g, b = input().split() n = int(r+g+b) if n % 4: print("NO") else: print("YES")
s711944421
p03795
u062864034
2,000
262,144
Wrong Answer
17
2,940
54
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N = int(input()) x = 800 y = 200*int(N/15) print(x-y)
s989303132
Accepted
17
2,940
56
N = int(input()) x = 800*N y = 200*int(N/15) print(x-y)
s279713640
p03624
u366886346
2,000
262,144
Wrong Answer
19
3,188
185
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
s=input() sset=set(s) list1=list(range(97,123)) for i in range(len(sset)): str1=sset.pop() list1.remove(ord(str1)) if len(list1)==0: print("None") else: print(list1[0])
s631279658
Accepted
20
3,188
190
s=input() sset=set(s) list1=list(range(97,123)) for i in range(len(sset)): str1=sset.pop() list1.remove(ord(str1)) if len(list1)==0: print("None") else: print(chr(list1[0]))
s729925195
p03644
u507116804
2,000
262,144
Wrong Answer
17
2,940
68
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n=int(input()) k=0 m=n while m%2==0: k+=1 m=m/2 print(k)
s957861239
Accepted
17
2,940
67
n=int(input()) k=0 while n//2>=1: k+=1 n=n//2 print(2**k)
s439801902
p02936
u464244643
2,000
1,048,576
Wrong Answer
2,003
269,996
623
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
import sys sys.setrecursionlimit(10**6) def main(): def dfs(now, prev=-1): for next in edge[now]: if next == prev: continue score[next] += score[now] dfs(next, now) N, Q = map(int, input().split()) edge = [[] for _ in range(N+1)] for _ in range(N-1): u, v = map(int, input().split()) edge[u].append(v) edge[v].append(u) p = [] x = [] score = [0] * (N+1) for _ in range(Q): p, x = map(int, input().split()) score[p] += x dfs(1) print(score) if __name__ == "__main__": main()
s096976258
Accepted
1,591
268,428
682
import sys sys.setrecursionlimit(10 ** 6) def input(): return sys.stdin.readline()[:-1] def main(): def dfs(now, prev=-1): for next in edge[now]: if next == prev: continue score[next] += score[now] dfs(next, now) N, Q = map(int, input().split()) edge = [[] for _ in range(N+1)] for _ in range(N-1): u, v = map(int, input().split()) edge[u].append(v) edge[v].append(u) p = [] x = [] score = [0] * (N+1) for _ in range(Q): p, x = map(int, input().split()) score[p] += x dfs(1) print(*score[1:]) if __name__ == "__main__": main()
s953577476
p02742
u858742833
2,000
1,048,576
Wrong Answer
19
3,316
93
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
def main(): H, W = list(map(int, input().split())) return min(H, W) print(main())
s602988719
Accepted
18
2,940
140
def main(): H, W = list(map(int, input().split())) if min(H, W) == 1: return 1 return (H * W + 1) // 2 print(main())
s285964112
p02646
u441246928
2,000
1,048,576
Wrong Answer
19
9,164
153
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
A,V = map(int,input().split()) B,W = map(int,input().split()) T = int(input()) if abs(A + V*T) >= abs(B + W*T) : print('Yes') else : print('No')
s427946088
Accepted
24
8,992
262
A,V = map(int,input().split()) B,W = map(int,input().split()) T = int(input()) if B > A : if A + V*T >= B + W*T : print('YES') else : print('NO') elif A > B : if B - W*T >= A - V*T : print('YES') else : print('NO')
s599575409
p02865
u490489966
2,000
1,048,576
Wrong Answer
17
2,940
64
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n=int(input()) if n%2==0: print(n/2-1) else: print(int(n/2))
s420221067
Accepted
17
2,940
73
n=int(input()) if n%2==0: print(int(n/2-1)) else: print(int((n-1)/2))
s809523421
p03493
u288040231
2,000
262,144
Wrong Answer
17
2,940
45
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 = list(input().split()) print(S.count('1'))
s245038768
Accepted
17
2,940
29
s=input() print(s.count('1'))
s054754824
p03855
u651803486
2,000
262,144
Wrong Answer
17
3,064
33
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
print('1 2 2 1') print('1 2 2 1')
s751761182
Accepted
1,676
53,240
1,330
from collections import defaultdict class UnionFind(): def __init__(self, n): self.par = [i for i in range(n)] def root(self, x): if self.par[x] == x: return x else: self.par[x] = self.root(self.par[x]) return self.par[x] def same(self, x, y): return self.root(x) == self.root(y) def unite(self, x, y): x = self.root(x) y = self.root(y) if x == y: return self.par[x] = y return def main(): N, K, L = map(int, input().split()) uf1 = UnionFind(N) uf2 = UnionFind(N) for _ in range(K): p, q = map(int, input().split()) uf1.unite(p-1, q-1) # O(L) for _ in range(L): r, s = map(int, input().split()) uf2.unite(r-1, s-1) # O(N) x O(log_N) cnts = defaultdict(int) for i in range(N): pos = (uf1.root(i), uf2.root(i)) cnts[pos] += 1 ans = [] for i in range(N): pos = (uf1.root(i), uf2.root(i)) ans.append(cnts[pos]) print(*ans) if __name__ == '__main__': main()
s077941667
p02936
u657994700
2,000
1,048,576
Wrong Answer
2,234
2,095,592
601
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
import numpy as np N, Q = map(int, input().split()) tree = [[0] * N for i in range(N)] for i in range(N-1): a, b = map(int, input().split()) print(a, b) tree[a-1][b-1] = 1 tree_np = np.array(tree) for i, _ in enumerate(tree): for node, _ in enumerate(tree[i]): if tree[i][node] == 1: tree[i] = np.array(tree[i]) + np.array(tree[node]) print(tree) ans = np.array([0] * N) for q in range(Q): p, x = map(int, input().split()) ans += np.array(np.array(tree[p-1]) * x) print(ans)
s184731055
Accepted
1,911
86,392
656
from collections import deque N, Q = map(int, input().split()) edge = [[] for i in range(N)] ops = [] ans = [0] * N for _ in range(N-1): a, b = map(int, input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) for _ in range(Q): ops.append(tuple(map(int, input().split()))) for op in ops: node = op[0]-1 pnt = op[1] ans[node] += pnt stack = deque() stack.append((0, -1)) while stack: st = stack.pop() node, parent = st[0], st[1] children = edge[node] for child in children: if child == parent: continue ans[child] += ans[node] stack.append((child, node)) print(*ans)
s027801627
p03371
u127285813
2,000
262,144
Wrong Answer
17
3,064
171
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A, B, C, X, Y = map(int, input().split()) C = min(C, A+B) ans = 0 ans += C*min(X, Y) if X > Y: ans += min(C, A) * abs(X-Y) else: ans + min(C, B) * abs(X-Y) print(ans)
s851258160
Accepted
17
3,060
175
A, B, C, X, Y = map(int, input().split()) C = min(2*C, A+B) ans = 0 ans += C*min(X, Y) if X > Y: ans += min(C, A) * abs(X-Y) else: ans += min(C, B) * abs(X-Y) print(ans)
s464028228
p02601
u143212659
2,000
1,048,576
Wrong Answer
31
9,112
352
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): A, B, C = map(int, input().split()) K = int(input()) print(A, B, C, K) for _ in range(K): if A > B: B *= 2 elif B > C: C *= 2 if A < B < C: print("Yes") else: print("No") if __name__ == "__main__": main()
s552272812
Accepted
31
9,076
338
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): A, B, C = map(int, input().split()) K = int(input()) for _ in range(K): if not A < B: B *= 2 elif not B < C: C *= 2 if A < B < C: print("Yes") else: print("No") if __name__ == "__main__": main()
s805748337
p03478
u943117333
2,000
262,144
Wrong Answer
45
3,388
925
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).
from sys import stdin n,a,b = [int(x) for x in stdin.readline().rstrip().split()] sum = 0 for i in range(n+1): i_sum = 0 i_num = i print("i_num:"+str(i_num)) while(True): if(i_num//10 ==0): i_sum += (i_num%10) break else: i_sum += (i_num%10) i_num = i_num//10 if(a<= i_sum <= b): print(i_sum) sum += i print("-------------------") print(sum)
s261642340
Accepted
26
3,188
929
from sys import stdin n,a,b = [int(x) for x in stdin.readline().rstrip().split()] sum = 0 for i in range(n+1): #print(i) if (a<= i//10000 + (i-i//10000*10000)//1000 + (i-i//1000*1000)//100 + (i-i//100*100)//10 + i%10 <=b): sum += i print(sum)
s974923087
p03854
u323680411
2,000
262,144
Wrong Answer
18
3,188
280
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() cnt = 0 j = len(S) - 1 for i in range(len(S)-1, -1, -1): if j-1 > len("dreamer"): break for dd in ("dream", "dreamer", "erase", "eraser"): if S[i:j+1] == dd: j = i-1 cnt += len(dd) print(("NO", "YES")[len(S) == cnt])
s360253095
Accepted
133
3,188
288
S = input() cnt = 0 j = len(S) - 1 for i in range(len(S) - 1, -1, -1): if j - i > len("dreamer"): break for dd in ("dream", "dreamer", "erase", "eraser"): if S[i:j + 1] == dd: j = i - 1 cnt += len(dd) print(("NO", "YES")[len(S) == cnt])
s213812708
p03227
u811000506
2,000
1,048,576
Wrong Answer
17
2,940
87
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
S = list(str(input())) if len(S) == 2: print(S[0],S[1]) else: print(S[2],S[1],S[0])
s089507911
Accepted
17
2,940
73
S = str(input()) if len(S) == 2: print(S) else: print(S[2]+S[1]+S[0])
s805359498
p03352
u923662841
2,000
1,048,576
Wrong Answer
19
3,060
123
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
import math X = int(input()) b = 1 for i in range(33,1,-1): a = math.floor(math.log(X, i)) b = max(i**a,b) print(b)
s789308141
Accepted
18
2,940
125
x=int(input()) c=1 for b in range(1,x): for p in range(2,x): if b**p<=x:c=max(c,b**p) else:break print(c)
s064206430
p03671
u448655578
2,000
262,144
Wrong Answer
17
2,940
75
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
price = input().split(" ") price = sorted(price) print(price[0] + price[1])
s562210126
Accepted
17
2,940
74
price = list(map(int, input().split(" "))) print(sum(price) - max(price))
s487957643
p03448
u912652535
2,000
262,144
Wrong Answer
41
3,060
285
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(1,a+1): x = 500 * i for j in range(1,b+1): y = 100 * j for k in range(1,c+1): z = 50 * k if x+y+z == X : count += 1 print(count)
s856127569
Accepted
41
3,064
279
a = int(input()) b = int(input()) c = int(input()) X = int(input()) count = 0 for i in range(a+1): x = 500 * i for j in range(b+1): y = 100 * j for k in range(c+1): z = 50 * k if x+y+z == X : count += 1 print(count)
s612270066
p03493
u982743577
2,000
262,144
Wrong Answer
17
2,940
20
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.
print(list(input()))
s327797619
Accepted
17
2,940
31
print(list(input()).count('1'))
s316946058
p03401
u279493135
2,000
262,144
Wrong Answer
266
14,928
877
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N = INT() A = LIST() A.insert(0, 0) A.append(0) print(A) ans = 0 for i in range(N+1): ans += abs(A[i+1]-A[i]) for i in range(N): if A[i]<=A[i+1]<=A[i+2] or A[i+2]<=A[i+1]<=A[i]: print(ans) else: print(ans-2* min( abs(A[i+2]-A[i+1]), abs(A[i+1]-A[i]) ) )
s867265524
Accepted
269
14,672
868
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N = INT() A = LIST() A.insert(0, 0) A.append(0) ans = 0 for i in range(N+1): ans += abs(A[i+1]-A[i]) for i in range(N): if A[i]<=A[i+1]<=A[i+2] or A[i+2]<=A[i+1]<=A[i]: print(ans) else: print(ans-2* min( abs(A[i+2]-A[i+1]), abs(A[i+1]-A[i]) ) )
s022045292
p03155
u546853743
2,000
1,048,576
Wrong Answer
27
8,992
78
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
n=int(input()) h=int(input()) w=int(input()) h -= (n-1) w -= (n-1) print(h*w)
s331181756
Accepted
27
9,144
76
n=int(input()) h=int(input()) w=int(input()) s = n-h+1 t = n-w+1 print(s*t)
s649388060
p03852
u626684023
2,000
262,144
Wrong Answer
17
2,940
160
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
s = input() if s.replace("eraser"," ").replace("erase"," ").replace("dreamer"," ").replace("dream"," ").replace(" ", ""): print("NO") else: print("YES")
s004736672
Accepted
17
2,940
93
l = input() def vowel(l): return "vowel" if l in "aeiou" else "consonant" print(vowel(l))
s110319352
p03455
u054717609
2,000
262,144
Wrong Answer
17
2,940
110
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=map(int,input().split()) c=a*b if(c%2==0): print("even") else: print("odd")
s362391236
Accepted
18
2,940
110
a,b=map(int,input().split()) c=a*b if(c%2==0): print("Even") else: print("Odd")
s309892137
p02396
u908651435
1,000
131,072
Wrong Answer
30
5,552
105
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=1 while True: i=input() print('case {}: {}'.format(x,i)) x+=1 if x==999: break
s488572601
Accepted
70
5,984
115
import sys i=1 for s in sys.stdin: n = int(s) if n == 0: break print("Case ",i,": ",n,sep="") i += 1
s776187794
p00011
u071010747
1,000
131,072
Wrong Answer
20
7,360
242
Let's play Amidakuji. In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines. In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom. Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right.
def main(): LIST=[] for i in range(int(input())): LIST.append(i+1) for j in range(int(input())): a,b=map(int,input().split(",")) LIST[a-1],LIST[b-1]=LIST[b-1],LIST[a-1] for i in LIST: print(i)
s131693188
Accepted
20
7,720
303
def main(): LIST=[] for i in range(int(input())): LIST.append(i+1) for j in range(int(input())): a,b=map(int,input().split(",")) LIST[a-1],LIST[b-1]=LIST[b-1],LIST[a-1] for i in LIST: print(str(i)) if __name__ == '__main__': main()
s062786828
p03738
u319690708
2,000
262,144
Wrong Answer
17
3,060
122
You are given two positive integers A and B. Compare the magnitudes of these numbers.
A = int(input()) B = int(input()) print(A) if A > B: print("GREATER") elif A<B: print("LESS") else: print("EQUAL")
s081498547
Accepted
17
2,940
112
A = int(input()) B = int(input()) if A > B: print("GREATER") elif A<B: print("LESS") else: print("EQUAL")
s486904540
p03698
u449555432
2,000
262,144
Wrong Answer
18
3,060
100
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s = list(input()) t = set(s) print(s) print(t) if len(s) == len(t): print('yes') else: print('no')
s894245965
Accepted
18
2,940
82
s = list(input()) t = set(s) if len(s) == len(t): print('yes') else: print('no')
s297856182
p03089
u174603263
2,000
1,048,576
Wrong Answer
17
3,060
258
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.
import math n = int(input()) b = list(map(int, input().split())) a = [] print(b) for i in range(1, n+1): if(b[i-1] <= i): a.append(b[i-1]) else: break if(a != b): print(-1) else: for i in range(len(a)): print(a[i])
s087821140
Accepted
18
3,064
298
import math n = int(input()) b = list(map(int, input().split())) a = [] lis = [] for i in range(1, n+1): if(b[i-1] <= i): a.append(b[i-1]) lis.insert(b[i-1]-1, b[i-1]) else: break if(a != b): print(-1) else: for i in range(len(a)): print(lis[i])
s240539688
p03110
u375695365
2,000
1,048,576
Wrong Answer
19
3,060
200
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()) xy=[list(map(str,input().split())) for _ in range(n)] ans=0 for i in range(n): if xy[i][1]=="BTC": ans+=38000*float(xy[i][0]) else: ans+=int(xy[i][0]) print(ans)
s836654309
Accepted
18
3,060
203
n=int(input()) xy=[list(map(str,input().split())) for _ in range(n)] ans=0 for i in range(n): if xy[i][1]=="BTC": ans+=380000*float(xy[i][0]) else: ans+=float(xy[i][0]) print(ans)
s532777734
p03502
u069129582
2,000
262,144
Wrong Answer
18
2,940
102
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
n=int(input()) a=0 a+=n%10 b=n//1 while b>0: a+=b%10 b=b//10 print('Yes' if n%a==0 else 'No')
s467451894
Accepted
18
2,940
103
n=int(input()) a=0 a+=n%10 b=n//10 while b>0: a+=b%10 b=b//10 print('Yes' if n%a==0 else 'No')
s404529282
p03160
u424240341
2,000
1,048,576
Wrong Answer
122
14,660
360
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.
def edpcA(n, hs): hm2, hm1 = hs[0], hs[1] dp = [0, abs(hm2-hm1)] hs = list(reversed(hs[2:])) for i in range(2, n): h = hs.pop() d1 = dp[i-1] + abs(h-hm1) d2 = dp[i-2] + abs(h-hm2) dp.append(min(d1, d2)) hm2, hm1 = hm1, h print(dp) n = int(input()) hs = list(map(int, input().split(' '))) edpcA(n, hs)
s382375346
Accepted
112
13,980
364
def edpcA(n, hs): hm2, hm1 = hs[0], hs[1] dp = [0, abs(hm2-hm1)] hs = list(reversed(hs[2:])) for i in range(2, n): h = hs.pop() d1 = dp[i-1] + abs(h-hm1) d2 = dp[i-2] + abs(h-hm2) dp.append(min(d1, d2)) hm2, hm1 = hm1, h print(dp[-1]) n = int(input()) hs = list(map(int, input().split(' '))) edpcA(n, hs)
s645319546
p03377
u755180064
2,000
262,144
Wrong Answer
17
2,940
169
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.
def main(): t = list(map(int, input().split())) if t[0] + t[1] > t[2]: print('Yes') else: print('No') if __name__ == '__main__': main()
s936011807
Accepted
17
2,940
285
url = "https://atcoder.jp//contests/abc094/tasks/abc094_a" def main(): t = list(map(int, input().split())) for i in range(t[1]): tmp = i + t[0] if tmp == t[2]: print('YES') exit() print('NO') if __name__ == '__main__': main()
s370269533
p00586
u858992370
1,000
131,072
Wrong Answer
20
7,500
186
Compute A + B.
import sys val = [] count = 0 for line in sys.stdin: for word in line.split(): val.append(int(word)) count = count + 1 if count == 1: break print (sum(val))
s462720483
Accepted
20
7,420
285
import sys val = [] result = [] count = 0 for line in sys.stdin: if line != '\n': for word in line.split(): val.append(int(word)) result.append(sum(val)) val = [] count = count + 1 else: break for x in result: print(x)
s188107206
p04044
u325264482
2,000
262,144
Wrong Answer
17
3,060
107
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 = list(map(int, input().split())) S = [input() for i in range(N)] Ss = sorted(S) print(','.join(Ss))
s341150768
Accepted
17
3,060
106
N, L = list(map(int, input().split())) S = [input() for i in range(N)] Ss = sorted(S) print(''.join(Ss))
s413724139
p04029
u331464808
2,000
262,144
Wrong Answer
17
2,940
72
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()) res = 1 for i in range(n-1): res = res + i print(res)
s550741920
Accepted
17
2,940
70
n = int(input()) res = 0 for i in range(n+1): res += i print(res)
s431219700
p03737
u201082459
2,000
262,144
Wrong Answer
17
2,940
93
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
a,b,c = map(str,input().split()) print(a[0].capitalize(),b[0].capitalize(),c[0].capitalize())
s875109944
Accepted
17
2,940
93
a,b,c = map(str,input().split()) print(a[0].capitalize()+b[0].capitalize()+c[0].capitalize())
s949651466
p02393
u482227082
1,000
131,072
Wrong Answer
20
5,536
60
Write a program which reads three integers, and prints them in ascending order.
array = input().split() array2= sorted(array) print(array2)
s369246963
Accepted
20
5,588
129
# # 2c # def main(): l = list(map(int, input().split())) l.sort() print(*l) if __name__ == '__main__': main()
s033897436
p02678
u318233626
2,000
1,048,576
Wrong Answer
992
40,376
772
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()) M = [[] for i in range(n)] for i in range(m): a, b = map(int, input().split()) a, b = a - 1, b - 1 M[a].append(b) M[b].append(a) #print(M) R = [-1 for i in range(n)] Q = deque([(0, -2)]) while len(Q) > 0: t = Q[0][0] b = Q[0][1] print(t) print(b) Q.popleft() if R[t] == -1: R[t] = b for i in range(len(M[t])): if R[M[t][i]] == -1: Q.append((M[t][i], t)) else: pass else: pass #print(R) f = 0 for i in range(n): if R[i] == -1: f = 1 break else: pass if f == 1: print('No') else: print('Yes') for i in range(1, n): print(R[i] + 1)
s111543132
Accepted
788
34,868
677
from collections import deque n, m = map(int, input().split()) TO = [[] for i in range(n)] for i in range(m): a, b = map(int, input().split()) a, b = a - 1, b -1 TO[a].append(b) TO[b].append(a) #BFS Q = deque([]) DIST = [-1 for i in range(n)] PRE = [-1 for i in range(n)] DIST[0] = 0 Q.append(0) while len(Q) > 0: x = Q.popleft() for i in range(len(TO[x])): y = TO[x][i] if DIST[y] != -1: continue DIST[y] = DIST[x] + 1 PRE[y] = x Q.append(y) print('Yes') for i in range(n): if i == 0: continue ans = PRE[i] + 1 print(ans)
s997548500
p03473
u345136423
2,000
262,144
Wrong Answer
17
2,940
24
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
print(int(input()) + 24)
s310401475
Accepted
17
2,940
29
print(int(input()) *-1 + 48)
s269239790
p02850
u871980676
2,000
1,048,576
Wrong Answer
706
93,344
896
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline N = int(input()) ab = [ tuple(map(int,input().split())) for i in range(N-1) ] dic = {} color = {} root = [0]*N for i in range(N): dic[i+1] = [] for n in range(N-1): i = ab[n][0] j = ab[n][1] dic[i].append(j) dic[j].append(i) root[i-1] += 1 root[j-1] += 1 color[(i,j)] = 0 root_node = root.index(1)+1 def rec(now_node,prevcolor): nowcolor = 0 tg_list = dic[now_node][:] for elem in tg_list: nowcolor += 1 if nowcolor == prevcolor: nowcolor += 1 dic[elem].remove(now_node) color[(elem,now_node)] = nowcolor color[(now_node,elem)] = nowcolor rec(elem,nowcolor) rec(root_node,0) for n in range(N-1): i = ab[n][0] j = ab[n][1] print(color[(i,j)])
s690606690
Accepted
737
93,380
921
import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline N = int(input()) ab = [ tuple(map(int,input().split())) for i in range(N-1) ] dic = {} color = {} root = [0]*N for i in range(N): dic[i+1] = [] for n in range(N-1): i = ab[n][0] j = ab[n][1] dic[i].append(j) dic[j].append(i) root[i-1] += 1 root[j-1] += 1 color[(i,j)] = 0 root_node = root.index(1)+1 ma = max(root) def rec(now_node,prevcolor): nowcolor = 0 tg_list = dic[now_node][:] for elem in tg_list: nowcolor += 1 if nowcolor == prevcolor: nowcolor += 1 dic[elem].remove(now_node) color[(elem,now_node)] = nowcolor color[(now_node,elem)] = nowcolor rec(elem,nowcolor) rec(root_node,0) print(ma) for n in range(N-1): i = ab[n][0] j = ab[n][1] print(color[(i,j)])
s166541795
p03657
u883465106
2,000
262,144
Wrong Answer
20
3,316
123
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
A,B= list(map(int,input().split())) if (A+B%3)==0 or A%3==0 or B%3==0: print("Possible") else: print("Impossibl")
s675197478
Accepted
17
2,940
124
A,B= list(map(int,input().split())) if (A+B)%3==0 or A%3==0 or B%3==0: print("Possible") else: print("Impossible")
s344539882
p03836
u614314290
2,000
262,144
Wrong Answer
17
3,060
161
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) dx, dy = (ty-sy), (tx-sx) print("U"*dx+"R"*dy+"D"*dy+"L"*dx+"L"+"U"*(dy+1)+"R"*(dx+1)+"DR"+"D"*(dy+1)+"L"*(dx+1)+"U")
s875479143
Accepted
18
3,060
161
sx, sy, tx, ty = map(int, input().split()) dx, dy = (tx-sx), (ty-sy) print("U"*dy+"R"*dx+"D"*dy+"L"*dx+"L"+"U"*(dy+1)+"R"*(dx+1)+"DR"+"D"*(dy+1)+"L"*(dx+1)+"U")
s322275444
p03485
u771167374
2,000
262,144
Wrong Answer
18
2,940
50
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)//2+1)
s862082621
Accepted
17
2,940
95
a, b = map(int, input().split()) if (a+b)%2!=0: print((a+b)//2+1) else: print((a+b)//2)
s897615167
p03578
u348293370
2,000
262,144
Wrong Answer
2,206
39,376
268
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
from os import remove n = int(input()) d_list = list(map(int, input().split())) m = int(input()) t_list = list(map(int, input().split())) for i in range(m): if t_list[i] in d_list: t_list[i] = 0 else: print("No") exit() print("Yes")
s001078064
Accepted
232
57,200
357
import collections n = int(input()) d_list = list(map(int, input().split())) m = int(input()) t_list = list(map(int, input().split())) if m > n: print("NO") exit() d_c = collections.Counter(d_list) t_c = collections.Counter(t_list) for i in t_c: if t_c[i] <= d_c[i]: continue else: print("NO") exit() print("YES")
s225175278
p03387
u131406572
2,000
262,144
Wrong Answer
17
3,064
190
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=list(map(int,input().split())) a.sort() b=a[2]-a[1] c=a[1]-a[0] if b%2==0 and c%2==0: print((b//2)+(c//2)) elif b%2==1 and c%2==1: print((b//2)+(c//2)+2) else: print((b//2)+(c//2)+2)
s636440424
Accepted
17
3,064
345
a=list(map(int,input().split())) a.sort(reverse=True) cnt=0 if (a[0]-a[1])%2==0: cnt+=(a[0]-a[1])//2 if (a[0]-a[2])%2==0: cnt+=(a[0]-a[2])//2 else: cnt+=(a[0]-a[2])//2+2 else: cnt+=(a[0]-a[1])//2+1 a[2]+=1 if (a[0]-a[2])%2==0: cnt+=(a[0]-a[2])//2 else: cnt+=(a[0]-a[2])//2+2 print(cnt)
s105577893
p03945
u698479721
2,000
262,144
Wrong Answer
68
3,188
120
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.
S = input() i = 0 ans = 0 while i < len(S)-1: if S[i] == S[i+1]: ans += 1 i += 1 else: i += 1 print(ans)
s007579700
Accepted
64
3,188
120
S = input() i = 0 ans = 0 while i < len(S)-1: if S[i] != S[i+1]: ans += 1 i += 1 else: i += 1 print(ans)
s607515422
p03151
u377989038
2,000
1,048,576
Wrong Answer
401
31,460
347
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
import numpy as np import sys input = sys.stdin.buffer.readline n = int(input()) a = np.array(list(map(int, input().split()))) b = np.array(list(map(int, input().split()))) c = a - b m = np.sum(c[c < 0]) p = np.sort(c[c >= 0])[::-1] cnt = n - p.size for i in p: if m >= 0: print(cnt) exit() m += i cnt += 1 print(-1)
s098766456
Accepted
270
22,548
385
import numpy as np import sys input = sys.stdin.buffer.readline n = int(input()) a = np.array(list(map(int, input().split()))) b = np.array(list(map(int, input().split()))) c = a - b m = np.sum(c[c < 0]) p = np.sort(c[c >= 0])[::-1] cnt = n - p.size if cnt == 0: print(0) exit() for i in p: m += i cnt += 1 if m >= 0: print(cnt) exit() print(-1)
s355945345
p04043
u268623418
2,000
262,144
Wrong Answer
17
2,940
255
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.
num5 = 0 num7 = 0 for num in map(int, input().split()): print(num) if num == 5: num5 += 1 elif num == 7: num7 += 1 else: print('NO') exit() if num5 == 2 and num7 == 1: print('YES') else: print('NO')
s058097465
Accepted
17
2,940
241
num5 = 0 num7 = 0 for num in map(int, input().split()): if num == 5: num5 += 1 elif num == 7: num7 += 1 else: print('NO') exit() if num5 == 2 and num7 == 1: print('YES') else: print('NO')
s904963472
p03448
u853064660
2,000
262,144
Wrong Answer
25
2,940
441
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,B,C=map(int,input().split()) A,B,C,X=map(int,'30 30 30 12000'.split()) N=0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if i*500+j*100+k*50==X: N+=1 print(N)
s523578345
Accepted
48
3,060
215
A = int(input()) B = int(input()) C = int(input()) X = int(input()) N=0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if i*500+j*100+k*50==X: N+=1 print(N)
s709831778
p02401
u587193722
1,000
131,072
Wrong Answer
30
7,616
189
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
x , y, z = input().split() l = int(x) r = int(z) if y == '+': print(l + r) elif y == '-': print(l - r) elif y == '/': print(l / r) elif y == '*': print(l * r) else: pass
s598748249
Accepted
20
7,652
255
while True: x, y, z = input().split() l = int(x) r = int(z) if y == '+': print(l + r) elif y == '-': print(l - r) elif y == '/': print(l // r) elif y == '*': print(l * r) else: break
s330389907
p02292
u662418022
1,000
131,072
Wrong Answer
30
6,088
1,944
For given three points p0, p1, p2, print COUNTER_CLOCKWISE if p0, p1, p2 make a counterclockwise turn (1), CLOCKWISE if p0, p1, p2 make a clockwise turn (2), ONLINE_BACK if p2 is on a line p2, p0, p1 in this order (3), ONLINE_FRONT if p2 is on a line p0, p1, p2 in this order (4), ON_SEGMENT if p2 is on a segment p0p1 (5).
# -*- coding: utf-8 -*- import collections import math class Vector2(collections.namedtuple("Vector2", ["x", "y"])): def __add__(self, other): return Vector2(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vector2(self.x - other.x, self.y - other.y) def __mul__(self, scalar): return Vector2(self.x * scalar, self.y * scalar) def __neg__(self): return Vector2(-self.x, -self.y) def __pos__(self): return Vector2(+self.x, +self.y) def __abs__(self): # norm return math.sqrt(float(self.x * self.x + self.y * self.y)) def dot(self, other): # dot product return self.x * other.x + self.y * other.y def cross(self, other): # cross product return self.x * other.y - self.y * other.x def getDistanceSP(segment, point): p = point p1, p2 = segment if (p2 - p1).dot(p - p1) < 0: return abs(p - p1) if (p1 - p2).dot(p - p2) < 0: return abs(p - p2) return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1) def getDistance(s1, s2): if 0: # intersect return 0 a, b = s1 c, d = s2 return min(getDistanceSP(s1, c), getDistanceSP(s1, d), getDistanceSP(s2, a), getDistanceSP(s2, b)) def ccw(p0, p1, p2): a = p1 - p0 b = p2 - p0 if a.cross(b) > 0: return 1 elif a.cross(b) < 0: return -1 elif a.dot(b) < 0: return 2 elif abs(a) < abs(b): return -2 else: return 0 if __name__ == '__main__': a, b, c, d = map(int, input().split()) p0 = Vector2(a, b) p1 = Vector2(c, d) q = int(input()) ans = [] for _ in range(q): e, f = map(int, input().split()) p2 = Vector2(e, f) ans.append(ccw(p0, p1, p2)) dic = {1: "COUNTER_CLOCKWISE", -1: "CLOCLWISE", 2: "ONLINE_BACK", -2: "ONLINE_FRONT", 0: "ON_SEGMENT"} for a in ans: print(dic[a])
s273713727
Accepted
50
6,280
1,944
# -*- coding: utf-8 -*- import collections import math class Vector2(collections.namedtuple("Vector2", ["x", "y"])): def __add__(self, other): return Vector2(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vector2(self.x - other.x, self.y - other.y) def __mul__(self, scalar): return Vector2(self.x * scalar, self.y * scalar) def __neg__(self): return Vector2(-self.x, -self.y) def __pos__(self): return Vector2(+self.x, +self.y) def __abs__(self): # norm return math.sqrt(float(self.x * self.x + self.y * self.y)) def dot(self, other): # dot product return self.x * other.x + self.y * other.y def cross(self, other): # cross product return self.x * other.y - self.y * other.x def getDistanceSP(segment, point): p = point p1, p2 = segment if (p2 - p1).dot(p - p1) < 0: return abs(p - p1) if (p1 - p2).dot(p - p2) < 0: return abs(p - p2) return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1) def getDistance(s1, s2): if 0: # intersect return 0 a, b = s1 c, d = s2 return min(getDistanceSP(s1, c), getDistanceSP(s1, d), getDistanceSP(s2, a), getDistanceSP(s2, b)) def ccw(p0, p1, p2): a = p1 - p0 b = p2 - p0 if a.cross(b) > 0: return 1 elif a.cross(b) < 0: return -1 elif a.dot(b) < 0: return 2 elif abs(a) < abs(b): return -2 else: return 0 if __name__ == '__main__': a, b, c, d = map(int, input().split()) p0 = Vector2(a, b) p1 = Vector2(c, d) q = int(input()) ans = [] for _ in range(q): e, f = map(int, input().split()) p2 = Vector2(e, f) ans.append(ccw(p0, p1, p2)) dic = {1: "COUNTER_CLOCKWISE", -1: "CLOCKWISE", 2: "ONLINE_BACK", -2: "ONLINE_FRONT", 0: "ON_SEGMENT"} for a in ans: print(dic[a])
s108363618
p03778
u626337957
2,000
262,144
Wrong Answer
17
2,940
58
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(min(0, B-(A+W)))
s966684685
Accepted
17
2,940
102
W, A, B = map(int, input().split()) if A > B: print(max(0, A-(B+W))) else: print(max(0, B-(A+W)))
s115634494
p01225
u724548524
5,000
131,072
Wrong Answer
30
5,608
498
あなたの友達は最近 UT-Rummy というカードゲームを思いついた. このゲームで使うカードには赤・緑・青のいずれかの色と1から9までのいずれかの番号が つけられている. このゲームのプレイヤーはそれぞれ9枚の手札を持ち, 自分のターンに手札から1枚選んで捨てて, 代わりに山札から1枚引いてくるということを繰り返す. このように順番にターンを進めていき, 最初に手持ちのカードに3枚ずつ3つの「セット」を作ったプレイヤーが勝ちとなる. セットとは,同じ色の3枚のカードからなる組で,すべて同じ数を持っているか 連番をなしているもののことを言う. 連番に関しては,番号の巡回は認められない. 例えば,7, 8, 9は連番であるが 9, 1, 2は連番ではない. あなたの友達はこのゲームをコンピュータゲームとして売り出すという計画を立てて, その一環としてあなたに勝利条件の判定部分を作成して欲しいと頼んできた. あなたの仕事は,手札が勝利条件を満たしているかどうかを判定する プログラムを書くことである.
for _ in range(int(input())): n, c = map(int, input().split()), input().split() c = list(zip(c, n)) c.sort(key = lambda x:x[1]) c.sort(key = lambda x:x[0]) print(c) while c != []: if c[-1] == c[-2] == c[-3]: c = c[:-3] elif (c[-1][0], c[-1][1] -1) in c and (c[-1][0], c[-1][1] -2) in c : c.remove((c[-1][0], c[-1][1] -1)) c.remove((c[-1][0], c[-1][1] -2)) c.pop() else:print(0);break else:print(1)
s160354480
Accepted
20
5,612
485
for _ in range(int(input())): n, c = map(int, input().split()), input().split() c = list(zip(c, n)) c.sort(key = lambda x:x[1]) c.sort(key = lambda x:x[0]) while c != []: if c[-1] == c[-2] == c[-3]: c = c[:-3] elif (c[-1][0], c[-1][1] -1) in c and (c[-1][0], c[-1][1] -2) in c : c.remove((c[-1][0], c[-1][1] -1)) c.remove((c[-1][0], c[-1][1] -2)) c.pop() else:print(0);break else:print(1)
s791089862
p03693
u427690532
2,000
262,144
Wrong Answer
29
8,992
177
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
S_list = list(map(int,input().split())) r, g, b = S_list[0], S_list[1], S_list[2] if (100 * r + 10 * g + b) % 4 == 0 : result = "Yes" else: result = "No" print(result)
s321962910
Accepted
27
9,164
114
a, b, c = map(str, input().split()) num = int(a + b + c) if num % 4 == 0: print("YES") else: print("NO")
s517047990
p03409
u102902647
2,000
262,144
Wrong Answer
20
3,064
904
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
from operator import itemgetter # N = 5 # R = [[0, 0], # [7, 3], # [2, 2], # [4, 8], # [1, 6]] # B = [[8, 5], # [6, 9], # [5, 4], # [9, 1], # [3, 7]] N = int(input()) R = [] for i in range(N): a, b = map(int, input().split()) R.append([a, b]) B = [] for i in range(N): c, d = map(int, input().split()) B.append([c, d]) R.sort(key=itemgetter(0)) B.sort(key=itemgetter(0)) print(R) print(B) res = 0 for r in R: rx, ry = r[0], r[1] flag1 = False flag2 = False for i, b in enumerate(B): if b[0] > rx: flag1 = True break if flag1: B_tmp = B.copy()[i:] B_tmp.sort(key=itemgetter(1)) for ii, b in enumerate(B_tmp): if b[1] > ry: flag2 = True break if flag2: res += 1 B.remove(b) print(res)
s485489772
Accepted
19
3,064
914
from operator import itemgetter # N = 5 # R = [[0, 0], # [7, 3], # [2, 2], # [4, 8], # [1, 6]] # B = [[8, 5], # [6, 9], # [5, 4], # [9, 1], # [3, 7]] N = int(input()) R = [] for i in range(N): a, b = map(int, input().split()) R.append([a, b]) B = [] for i in range(N): c, d = map(int, input().split()) B.append([c, d]) R.sort(key=itemgetter(0)) B.sort(key=itemgetter(0)) # print(R) res = 0 for r in R[::-1]: rx, ry = r[0], r[1] flag1 = False flag2 = False for i, b in enumerate(B): if b[0] > rx: flag1 = True break if flag1: B_tmp = B.copy()[i:] B_tmp.sort(key=itemgetter(1)) for ii, b in enumerate(B_tmp): if b[1] > ry: flag2 = True break if flag2: res += 1 B.remove(b) print(res)
s032462251
p03415
u252964975
2,000
262,144
Wrong Answer
17
2,940
72
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
S1=str(input()) S2=str(input()) S3=str(input()) print(S1[0]+S1[1]+S2[2])
s859777356
Accepted
18
2,940
73
S1=str(input()) S2=str(input()) S3=str(input()) print(S1[0]+S2[1]+S3[2])
s431428133
p04046
u102367647
2,000
262,144
Wrong Answer
187
15,120
1,152
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.
import sys import numpy as np import random from decimal import Decimal import itertools import re import bisect from collections import deque, Counter from functools import lru_cache sys.setrecursionlimit(10**9) INF = 10**13 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ') def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w] def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w] MOD = 1000000007 def main(): n = LI() if __name__ == '__main__': main()
s505323631
Accepted
566
38,192
1,671
import sys import numpy as np import random from decimal import Decimal import itertools import re import bisect from collections import deque, Counter from functools import lru_cache sys.setrecursionlimit(10**9) INF = 10**13 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ') def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w] def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w] MOD = 1000000007 def main(): h, w, a, b = LI() def comb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10 ** 9 + 7 N = 10 ** 5 * 2 fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1]) * inv[-1] % p) ans = 0 for i in range(1,w-b+1): ans += comb(h-a+b+i-2, max(h-a-1, b+i-1), MOD) * comb(a+w-b-i-1, max(a-1, w-b-i), MOD) ans %= MOD print(ans) if __name__ == '__main__': main()
s535506338
p02821
u163320134
2,000
1,048,576
Wrong Answer
1,951
16,580
513
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
n,m=map(int,input().split()) arr=list(map(int,input().split())) arr=sorted(arr,reverse=True) acum=[arr[0]] for i in range(1,n): acum.append(acum[-1]+arr[i]) print(acum) l=0 r=2*10**5+1 while r-l!=1: mid=(l+r)//2 tmp=0 cnt=0 pos=n-1 for i in range(n): while pos!=-1: if arr[i]+arr[pos]>=mid: cnt+=pos+1 tmp+=arr[i]*(pos+1)+acum[pos] break else: pos-=1 if pos==-1: break if cnt<=m: r=mid else: l=mid tmp+=(m-cnt)*l print(tmp)
s920720453
Accepted
1,862
14,152
501
n,m=map(int,input().split()) arr=list(map(int,input().split())) arr=sorted(arr,reverse=True) acum=[arr[0]] for i in range(1,n): acum.append(acum[-1]+arr[i]) l=0 r=2*10**5+1 while r-l!=1: mid=(l+r)//2 tmp=0 cnt=0 pos=n-1 for i in range(n): while pos!=-1: if arr[i]+arr[pos]>=mid: cnt+=pos+1 tmp+=arr[i]*(pos+1)+acum[pos] break else: pos-=1 if pos==-1: break if cnt<=m: r=mid else: l=mid tmp+=(m-cnt)*l print(tmp)
s562203615
p03605
u871596687
2,000
262,144
Wrong Answer
17
2,940
84
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
N = str(input()) if N[0] == 9 or N[1] == 9: print("Yes") else: print("No")
s497995774
Accepted
17
2,940
88
N = str(input()) if N[0] == "9" or N[1] == "9": print("Yes") else: print("No")
s537246343
p02255
u564464686
1,000
131,072
Wrong Answer
20
5,596
230
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.
N=int(input()) A=[0 for i in range(N)] A=input().split() for i in range(N): A[i]=(int)(A[i]) for i in range(N): v=A[i] j = i-1 while j>=0 and A[j]>v: A[j+1]=A[j] j=j-1 A[j+1]=v print(A)
s915622874
Accepted
30
5,984
333
N=int(input()) A=[0 for i in range(N)] A=input().split() for i in range(N): A[i]=(int)(A[i]) for i in range(N): v=A[i] j = i-1 while j>=0 and A[j]>v: A[j+1]=A[j] j=j-1 A[j+1]=v for k in range(N): if k<N-1: print(A[k],end=" ") if k==N-1: print(A[k])
s323021603
p02665
u137226361
2,000
1,048,576
Wrong Answer
827
20,056
262
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
n= int(input()) a = list(map(int, input().split())) #print(a) if a[0] != 0: print(-1) exit(0) b=1 count=1 for i in range(n-1): if a[i+1] > 2*b: print(-1) exit(0) else: b= 2*b-a[i+1] count += 2*b print(count)
s301245662
Accepted
109
20,144
367
n= int(input()) a = list(map(int, input().split())) if n == 0 and a[0]==1: print(1) exit(0) if a[0] != 0: print(-1) exit(0) b=1 count=1 asum =sum(a) alim = asum for i in range(n): if a[i+1] > 2*b: print(-1) exit(0) else: alim = alim - a[i+1] b= min(2*b-a[i+1], alim) count += b print(count+ asum)
s484048533
p03555
u858136677
2,000
262,144
Wrong Answer
17
2,940
101
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() if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]: print('Yes') else: print('No')
s034943850
Accepted
17
2,940
102
a = input() b = input() if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]: print('YES') else: print('NO')
s446928108
p02261
u022407960
1,000
131,072
Wrong Answer
30
7,712
1,657
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).
#!/usr/bin/env python # encoding: utf-8 class Solution: def stable_sort(self): # write your code here array_length = int(input()) array = [str(x) for x in input().split()] bubble_result = self.bubble_sort(array=array, array_length=array_length) selection_result = self.selection_sort(array=array, array_length=array_length) # check whether selection sort is stable if bubble_result == selection_result: print("Stable") else: print("Not Stable") @staticmethod def selection_sort(array, array_length): # selection sort selection_count = 0 for i in range(array_length): min_j = i for j in range(i, array_length): if array[j][1] < array[min_j][1]: min_j = j array[i], array[min_j] = array[min_j], array[i] if i != min_j: selection_count += 1 result = " ".join(map(str, array)) print(result) return result @staticmethod def bubble_sort(array, array_length): flag, bubble_count, cursor = 1, 0, 0 while flag: flag = 0 for j in range(array_length - 1, cursor, -1): if array[j][1] < array[j - 1][1]: array[j], array[j - 1] = array[j - 1], array[j] flag = 1 bubble_count += 1 cursor += 1 result = " ".join(map(str, array)) print(result) print("Stable") return result if __name__ == '__main__': solution = Solution() solution.stable_sort()
s944005336
Accepted
30
8,152
1,711
#!/usr/bin/env python # encoding: utf-8 import copy class Solution: def stable_sort(self): # write your code here array_length = int(input()) array = [str(x) for x in input().split()] array_2 = copy.deepcopy(array) bubble_result = self.bubble_sort(array=array, array_length=array_length) selection_result = self.selection_sort(array=array_2, array_length=array_length) # check whether selection sort is stable if bubble_result == selection_result: print("Stable") else: print("Not stable") @staticmethod def selection_sort(array, array_length): # selection sort selection_count = 0 for i in range(array_length): min_j = i for j in range(i, array_length): if array[j][1] < array[min_j][1]: min_j = j array[i], array[min_j] = array[min_j], array[i] if i != min_j: selection_count += 1 result = " ".join(map(str, array)) print(result) return result @staticmethod def bubble_sort(array, array_length): flag, bubble_count, cursor = 1, 0, 0 while flag: flag = 0 for j in range(array_length - 1, cursor, -1): if array[j][1] < array[j - 1][1]: array[j], array[j - 1] = array[j - 1], array[j] flag = 1 bubble_count += 1 cursor += 1 result = " ".join(map(str, array)) print(result) print("Stable") return result if __name__ == '__main__': solution = Solution() solution.stable_sort()
s734605589
p03738
u172780602
2,000
262,144
Wrong Answer
17
2,940
127
You are given two positive integers A and B. Compare the magnitudes of these numbers.
a=input() b=input() if len(a)>len(b): print("GREATER") elif len(a)<len(b): print("LESS") else: print("EQUAL")
s959484871
Accepted
17
2,940
112
a=int(input()) b=int(input()) if a>b: print("GREATER") elif a<b: print("LESS") else: print("EQUAL")
s208564812
p02742
u909224749
2,000
1,048,576
Wrong Answer
25
9,092
98
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
H, W = map(int, input().split()) if H%2==0 or W%2==0: ans = int(H*W/2) else: ans = (H*W//2)+1
s718663382
Accepted
25
9,056
171
H, W = map(int, input().split()) if H==1 or W==1: ans = 1 elif H%2==0 or W%2==0: ans = int(H*W/2) else: ans = int((H*W+1)/2) print(ans)
s070443376
p03779
u677523557
2,000
262,144
Wrong Answer
30
4,884
126
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
X = int(input()) A = [0] c = 0 while True: c += 1 k = A[-1] + c if k > X: break A.append(k) print(c)
s268261542
Accepted
31
4,884
127
X = int(input()) A = [0] c = 0 while True: c += 1 k = A[-1] + c if k >= X: break A.append(k) print(c)
s169833438
p03386
u232852711
2,000
262,144
Wrong Answer
17
3,060
179
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 = list(map(int, input().split())) ans = set([]) for i in range(a, min(a+k, b+1)): ans.add(i) for i in range(max(a, b-k), b): ans.add(i) for a in ans: print(a)
s197489923
Accepted
17
3,060
197
a, b, k = list(map(int, input().split())) ans = set([]) for i in range(a, min(a+k, b+1)): ans.add(i) for i in range(max(a, b-k+1), b+1): ans.add(i) for a in sorted(list(ans)): print(a)
s350947578
p03795
u324549724
2,000
262,144
Wrong Answer
17
2,940
66
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.
import math n = int(input()) print(math.factorial(n)%1000000007)
s861154889
Accepted
18
2,940
40
n = int(input()) print(n*800-n//15*200)
s035783899
p02612
u895408600
2,000
1,048,576
Wrong Answer
32
9,148
46
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()) ot = N//1000 print(N-ot*1000)
s018035341
Accepted
28
9,152
91
N = int(input()) ot = N//1000 if N%1000 == 0: print(0) else: print((ot+1)*1000 - N)
s567279379
p02678
u993435350
2,000
1,048,576
Wrong Answer
2,212
130,372
701
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 sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) N,M = map(int,input().split()) path = [[] for i in range(N)] inf = 10 ** 6 ans = [[None,inf] for i in range(N - 1)] for _ in range(M): a,b = map(int,input().split()) a = a - 1 b = b - 1 if a > b: a,b = b,a path[a].append(b) path[b].append(a) print(path) def dfs(cur,par,con): if con == N: return for chi in path[cur]: if chi == par: continue if con < ans[chi - 1][1]: ans[chi - 1][0] = cur ans[chi - 1][1] = con + 1 dfs(chi,cur,con + 1) dfs(0,-1,0) if all([i[0] != None for i in ans]): print("Yes") for i in range(N - 1): print(ans[i][0] + 1) else: print("No")
s925981143
Accepted
451
38,276
770
from collections import deque import sys input = sys.stdin.readline N,M = map(int,input().split()) path = [[] for i in range(N)] ans = [None for i in range(N)] visited = [0 for i in range(N)] for _ in range(M): a,b = map(int,input().split()) a = a - 1 b = b - 1 path[a].append(b) path[b].append(a) def bfs(path, root,visited): visited[root] = 1 queue = deque([root]) while queue: cur = queue.popleft() for chi in path[cur]: if visited[chi] == 1: continue else: ans[chi] = cur + 1 visited[chi] = 1 queue.append(chi) if all([i == 1 for i in visited]): return "Yes" else: return "No" flag = bfs(path,0,visited) print(flag) if flag == "Yes": for i in range(1,N): print(ans[i])
s277581600
p03828
u382423941
2,000
262,144
Wrong Answer
43
3,700
417
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
import functools mod = 1e9 + 7 n = int(input()) fact = [1] * (n+1) for i in range(2, n+1): for j in range(2, 32): if i == 0: break while True: if i % j == 0: i /= j fact[j] += 1 else: break if i != 0: fact[int(i)] += 1 print(fact) print(int(functools.reduce(lambda x, y: (x * y) % mod, fact[2:])))
s494189350
Accepted
38
3,700
456
import sys import functools mod = 1e9 + 7 n = int(input()) if n == 1: print(1) sys.exit() fact = [1] * (n+1) for i in range(2, n+1): for j in range(2, 32): if i == 0: break while True: if i % j == 0: i /= j fact[j] += 1 else: break if i != 0: fact[int(i)] += 1 print(int(functools.reduce(lambda x, y: (x * y) % mod, fact[2:])))
s842855549
p03303
u546074985
2,000
1,048,576
Wrong Answer
18
3,060
248
You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
st = input() skpe = int(input()) st_len = len(st) count = st_len // 3 + 1 top_list = [] for i in range(count): top_list.append(st[3 * i:3 * i + 3]) for x in top_list: try: print(x[0], end="") except IndexError: pass
s894692382
Accepted
18
3,060
266
st = input() skpe = int(input()) st_len = len(st) count = (st_len // skpe) + 1 top_list = [] s = "" for i in range(count): top_list.append(st[skpe * i:skpe * i + skpe]) for x in top_list: try: s += x[0] except IndexError: pass print(s)
s338367869
p03110
u225110485
2,000
1,048,576
Wrong Answer
17
3,060
258
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()) xu = [[] for i in range(N)] otoshidama = 0 for i in range(N): xu[i] = list(input().split()) print(xu) for i in xu: if i[1] == 'JPY': otoshidama += int(i[0]) else: otoshidama += float(i[0])*380000 print(otoshidama)
s833499491
Accepted
17
3,060
248
N = int(input()) xu = [[] for i in range(N)] otoshidama = 0 for i in range(N): xu[i] = list(input().split()) for i in xu: if i[1] == 'JPY': otoshidama += int(i[0]) else: otoshidama += float(i[0])*380000 print(otoshidama)
s527385730
p03565
u571867512
2,000
262,144
Wrong Answer
18
3,064
764
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
S_prime = input() T = input() def judge(A,B): for i in range(len(A)): if A[i] != B[i] and A[i] != "?" and B[i] != "?": return False return True def dec(S_prime,T): S_cand = [] for i in range(len(S_prime)-len(T)+1): if judge(S_prime[i:i+len(T)],T): S_cand.append( S_prime[:i] + T + S_prime[i+len(T):] ) print(i,S_prime[:i], T, S_prime[i+len(T):]) return S_cand def S_change(S): S = list(S) for i in range(len(S)): if S[i] == "?": S[i] = "a" S = "".join(S) return S if len(dec(S_prime,T)) == 0: print("UNRESTORABLE") else: Ans = dec(S_prime,T) for i in range(len(Ans)): Ans[i] = S_change(Ans[i]) Ans.sort() print(Ans[0])
s641780462
Accepted
18
3,064
703
S_prime = input() T = input() def judge(A,B): for i in range(len(A)): if A[i] != B[i] and A[i] != "?" and B[i] != "?": return False return True def dec(S_prime,T): S_cand = [] for i in range(len(S_prime)-len(T)+1): if judge(S_prime[i:i+len(T)],T): S_cand.append( S_prime[:i] + T + S_prime[i+len(T):] ) return S_cand def S_change(S): S = list(S) for i in range(len(S)): if S[i] == "?": S[i] = "a" S = "".join(S) return S if len(dec(S_prime,T)) == 0: print("UNRESTORABLE") else: Ans = dec(S_prime,T) for i in range(len(Ans)): Ans[i] = S_change(Ans[i]) Ans.sort() print(Ans[0])
s303613397
p02397
u692415695
1,000
131,072
Wrong Answer
40
7,996
189
Write a program which reads two integers x and y, and prints them in ascending order.
# (c) midandfeed q = [] while(True): a, b = [int(x) for x in input().split()] if ( (a==0) and (b==0) ): break q.append((b,a)) q.sort() for x in q: print("{} {}".format(x[0], x[1]))
s071266149
Accepted
60
7,588
135
# (c) midandfeed while(True): a, b = [int(x) for x in input().split()] if ( (a==0) and (b==0) ): break print( min(a,b), max(a,b) )
s002261938
p02663
u327465093
2,000
1,048,576
Wrong Answer
23
9,080
82
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
h1, m1, h2, m2, k = map(int, input().split()) t1 = h1 * 60 + m1 t2 = h2 * 60 + m1
s691759263
Accepted
23
9,164
99
h1, m1, h2, m2, k = map(int, input().split()) t1 = h1 * 60 + m1 t2 = h2 * 60 + m2 print(t2-t1 - k)
s078951655
p03827
u620846115
2,000
262,144
Wrong Answer
26
9,136
158
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
n = int(input()) a = list(input()) xlist = [] x = 0 for i in range(n): if a[i]=="D": x+=1 elif a[i]=="I": x-=1 xlist.append(x) print(max(xlist))
s895916692
Accepted
25
9,128
159
n = int(input()) a = list(input()) xlist = [0] x = 0 for i in range(n): if a[i]=="D": x-=1 elif a[i]=="I": x+=1 xlist.append(x) print(max(xlist))