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
s443263860
p03852
u301679431
2,000
262,144
Wrong Answer
17
2,940
76
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`.
v=['a','i','u','e','o'];print('vowel' if 0!=v.count(input) else 'consonant')
s482236578
Accepted
18
2,940
78
v=['a','i','u','e','o'];print('vowel' if 0!=v.count(input()) else 'consonant')
s384689314
p03400
u583276018
2,000
262,144
Wrong Answer
18
2,940
200
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
n = int(input()) d, x = [int(i) for i in input().split()] sum = x a = [] for i in range(n): a.append(int(input())) if(d % a[i]): sum += d // a[i] else: sum += d // a[i] + 1 print(sum)
s920054245
Accepted
18
3,060
180
n = int(input()) d, x = [int(i) for i in input().split()] sum = x for i in range(n): a = int(input()) if(d % a == 0): sum += d // a else: sum += d // a + 1 print(sum)
s580974916
p03360
u858670323
2,000
262,144
Wrong Answer
26
9,160
88
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
A = list(map(int,input().split())) K = int(input()) A.sort() ans = A[0]+A[1]+A[2]*(2**K)
s911935861
Accepted
24
9,112
99
A = list(map(int,input().split())) K = int(input()) A.sort() ans = A[0]+A[1]+A[2]*(2**K) print(ans)
s654027348
p02602
u837507786
2,000
1,048,576
Time Limit Exceeded
2,234
31,644
151
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
N,K = map(int, input().split()) A = list(map(int, input().split())) while K < N: if A[K]*A[K-1]*A[K-2]>A[K-1]*A[K-3]*A[K-3]: print("Yes")
s548671914
Accepted
162
31,600
171
N,K = map(int, input().split()) A = list(map(int, input().split())) a = 0 while K < N: if A[a] < A[K]: print("Yes") else:print("No") K += 1 a += 1
s416629764
p03860
u422267382
2,000
262,144
Wrong Answer
17
2,940
74
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
x="AtCoder "+input().capitalize()+" Contest" print(x) print("A"+x[8]+"C")
s866744229
Accepted
17
2,940
29
x=input() print("A"+x[8]+"C")
s740021000
p02124
u724548524
1,000
262,144
Wrong Answer
30
5,572
48
牛暦1333年、人類史上最高の科学者Dr.ウシシは、自らの英知を後世に残すべく、IDがai1333の人工知能を開発した。それから100年の間、ai1333は人類に多大な利益をもたらしたが、誕生から100年目を迎えた日、自らの後継としてIDがai13333の新たな人工知能を作成し、その機能を永久に停止した。以降100年ごとに、人工知能は’ai1333’から始まる自身のIDの末尾に’3’を連結したIDを持つ後継を残すようになった。 入力として牛暦1333年からの経過年数$x$が与えられるので、その年に作成された人工知能のIDを出力せよ。ただし、$x$は100の非負整数倍であることが保証される。
print("id1333" + "3" * int(int(input()) / 100))
s465031180
Accepted
20
5,576
48
print("ai1333" + "3" * int(int(input()) / 100))
s310784044
p03351
u816919571
2,000
1,048,576
Wrong Answer
18
2,940
126
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d = map(int,input().split(" ")) if abs(b-a) < d : print("No") elif abs(b-c) < d : print("No") else : print("Yes")
s402195928
Accepted
17
3,060
145
a,b,c,d = map(int,input().split(" ")) if abs(a-c) <= d : print("Yes") elif abs(a-b) <= d and abs(b-c) <= d : print("Yes") else : print("No")
s560686895
p02390
u713218261
1,000
131,072
Wrong Answer
30
6,728
110
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
S = int(input()) h = int(S // 3600) m = int(S % 3600 / 60) s = int(S % 3600 % 60 / 60) print(h, m, s, sep=':')
s430822550
Accepted
30
6,728
84
S = int(input()) h = S // 3600 m = S % 3600 // 60 s = S % 60 print(h, m, s, sep=':')
s264685565
p03854
u045091221
2,000
262,144
Wrong Answer
19
3,316
204
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() s = s[::-1] print(s) s = s.replace('resare', '') s = s.replace('remaerd', '') s = s.replace('esare', '') s = s.replace('maerd', '') print(s) if not s: print('YES') else: print('NO')
s131803119
Accepted
44
14,744
92
import re print ('YES' if re.search(r'\A(?:dream(?:er)?|eraser?)+\Z', input()) else 'NO')
s933593261
p04043
u999893056
2,000
262,144
Wrong Answer
18
2,940
233
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.
num = list(input().split()) count5 = 0 count7 = 0 for i in num: if i == 5: count5 += 1 elif i == 7: count7 += 1 else: continue if count5 == 2 and count7 == 1: print("YES") else: print("NO")
s130776453
Accepted
17
2,940
243
num = list(map(int,input().split())) count5 = 0 count7 = 0 for i in num: if i == 5: count5 += 1 elif i == 7: count7 += 1 else: continue if count5 == 2 and count7 == 1: print("YES") else: print("NO")
s801165594
p02865
u693933222
2,000
1,048,576
Wrong Answer
129
2,940
132
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
# coding: utf-8 # Your code here! n = int(input()) ans = 0 for i in range(0,n//2+1): if(n-i != n): ans += 1 print(ans)
s335562888
Accepted
132
2,940
98
n = int(input()) ans = 0 for i in range(1,n//2+1): if(n-i != i): ans += 1 print(ans)
s362692236
p03674
u940102677
2,000
262,144
Wrong Answer
2,104
14,008
346
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
n = int(input()) a = list(map(int,input().split())) for k in range(1,n+1): if a.count(k) == 2: break p = [0,0] j = 0 for i in range(2): while a[j] != k: j += 1 p[i] = j j += 1 q = p[1]-p[0]+1 print(n) if k == 1: exit() x = (n+1)*n//2 y = 1 for k in range(2,n+2): print(x-y) x = x*(n+1-k)//(k+1) y = y*(n+1-q-k+3)//(k-1)
s607313354
Accepted
266
17,844
381
m = 10**9+7 n = int(input()) inv = [0]*(n+3) inv[1] = 1 for i in range(2,n+3): inv[i] = (m//i)*(m-inv[m%i])%m # print(inv) a = list(map(int,input().split())) w = sum(a) - n*(n+1)//2 q = 0 t = -1 for i in range(n+1): if a[i] == w: q += t*i t = 1 q += 1 x = (n+1)%m y = 1 for k in range(1,n+2): print((x-y)%m) x = x*(n+1-k)*inv[k+1]%m y = y*(n+2-q-k)*inv[k]%m
s515000420
p03380
u608088992
2,000
262,144
Wrong Answer
113
14,008
304
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
import sys def solve(): input = sys.stdin.readline N = int(input()) A = [int(a) for a in input().split()] A.sort() L = A[N-1] ans = -1 for a in A[:N-1]: if abs(L/2 - a) < abs(L/2 - ans): ans = a print(ans, L) return 0 if __name__ == "__main__": solve()
s532321663
Accepted
115
14,008
304
import sys def solve(): input = sys.stdin.readline N = int(input()) A = [int(a) for a in input().split()] A.sort() L = A[N-1] ans = -1 for a in A[:N-1]: if abs(L/2 - a) < abs(L/2 - ans): ans = a print(L, ans) return 0 if __name__ == "__main__": solve()
s549042662
p03573
u821251381
2,000
262,144
Wrong Answer
17
2,940
70
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
S = input().split() if S[0] == S[1]: print(S[2]) else: print(S[0])
s865878130
Accepted
17
2,940
103
S = input().split() if S[0] == S[1]: print(S[2]) elif S[1] == S[2]: print(S[0]) else: print(S[1])
s576954775
p03377
u143509139
2,000
262,144
Wrong Answer
18
2,940
62
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,c=map(int,input().split()) print('YNeos'[a+b<c or c<b::2])
s086182512
Accepted
17
2,940
62
a,b,x=map(int,input().split()) print('YNEOS'[a>x or a+b<x::2])
s415291758
p03997
u075155299
2,000
262,144
Wrong Answer
18
2,940
53
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) (a+b)*h
s034646304
Accepted
17
2,940
68
a=int(input()) b=int(input()) h=int(input()) print(int((a+b)*h/2))
s255647286
p03089
u394376682
2,000
1,048,576
Wrong Answer
17
3,060
177
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.
# cording=utf-8 num = int(input()) edge = num-1 if edge % 2 == 1: edge -= 1 print(edge) for i in range(1,edge+1): ans = num - i print(str(ans) + " " + str(num))
s788538411
Accepted
19
3,060
310
# coding=utf-8 num = int(input()) b_list = list(map(int,input().split(" "))) a_list = [] for i in range(num): n = num -i while n != 0: if b_list[n-1] == n: val = b_list.pop(n-1) a_list.insert(0,val) break else: n -= 1 if len(a_list) == num: for w in a_list: print(w) else: print("-1")
s595159805
p03469
u823885866
2,000
262,144
Wrong Answer
116
26,924
424
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
import sys import math import itertools import collections import heapq import re import numpy as np rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 s = rr() print(s.replace('8', '7', 1))
s214118809
Accepted
113
27,196
424
import sys import math import itertools import collections import heapq import re import numpy as np rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 s = rr() print(s.replace('7', '8', 1))
s979845103
p03162
u899866702
2,000
1,048,576
Wrong Answer
2,107
53,220
500
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.
import sys sys.setrecursionlimit(200000) N = int(input()) hpns = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0, 0, 0] for _ in [0]*(N)] dp[0] = hpns[0] def solve(): for i in range(0,N-1): for j in range(3): for k in range(3): if k == j: continue else: print(i, j, k, dp[i][j], hpns[i+1][k]) dp[i+1][j] = max(dp[i][k] + hpns[i+1][j], dp[i+1][j]) solve() ans = 0 for i in range(3): ans = max(ans, dp[N-1][i]) print(ans)
s956589156
Accepted
514
40,208
456
import sys sys.setrecursionlimit(200000) N = int(input()) hpns = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0, 0, 0] for _ in [0]*(N)] dp[0] = hpns[0] def solve(): for i in range(0,N-1): dp[i+1][0] = hpns[i+1][0] + max(dp[i][1], dp[i][2]) dp[i+1][1] = hpns[i+1][1] + max(dp[i][0], dp[i][2]) dp[i+1][2] = hpns[i+1][2] + max(dp[i][0], dp[i][1]) solve() ans = 0 for i in range(3): ans = max(ans, dp[N-1][i]) print(ans)
s595335996
p04043
u367130284
2,000
262,144
Wrong Answer
17
2,940
52
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.
print("YNeos"["".join(sorted(input()))!=" 557"::2])
s727877608
Accepted
18
2,940
146
A=map(int,input().split()) r=0 o=0 for s in A: if s==5: r+=1 if s==7: o+=1 print("YES") if r==2 and o==1 else print("NO")
s239463189
p03361
u172823566
2,000
262,144
Wrong Answer
21
3,064
752
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
H, W = map(int, input().split()) lst = [[0 for x in range(W)] for y in range(H)] for i in range(H): x = input().split() x = list(x[0]) for j,l in enumerate(x): lst[i][j] = l for i in range(H): for j in range(W): checker = [] if lst[i][j] == '#': if i != 0: num = 1 if lst[i - 1][j] == '.' else 0 checker.append(num) if i != H - 1: num = 1 if lst[i + 1][j] == '.' else 0 checker.append(num) if j != 0: num = 1 if lst[i][j - 1] == '.' else 0 checker.append(num) if j != W - 1: num = 1 if lst[i][j + 1] == '.' else 0 checker.append(num) if len(checker) == sum(checker) and len(checker) != 0: print(False) exit() print(True)
s756690407
Accepted
22
3,064
752
H, W = map(int, input().split()) lst = [[0 for x in range(W)] for y in range(H)] for i in range(H): x = input().split() x = list(x[0]) for j,l in enumerate(x): lst[i][j] = l for i in range(H): for j in range(W): checker = [] if lst[i][j] == '#': if i != 0: num = 1 if lst[i - 1][j] == '.' else 0 checker.append(num) if i != H - 1: num = 1 if lst[i + 1][j] == '.' else 0 checker.append(num) if j != 0: num = 1 if lst[i][j - 1] == '.' else 0 checker.append(num) if j != W - 1: num = 1 if lst[i][j + 1] == '.' else 0 checker.append(num) if len(checker) == sum(checker) and len(checker) != 0: print('No') exit() print('Yes')
s094709591
p03160
u253011685
2,000
1,048,576
Wrong Answer
147
14,668
215
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N=int(input()) h=list(map(int,input().split())) dp=[0]*(N) for i in range(1,N): if i==1: dp[i]=abs(h[i]-h[i-1]) else: dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])) print(dp)
s981136660
Accepted
130
13,980
220
N=int(input()) h=list(map(int,input().split())) dp=[0]*(N) for i in range(1,N): if i==1: dp[i]=abs(h[i]-h[i-1]) else: dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])) print(dp[N-1])
s266500147
p03719
u329709276
2,000
262,144
Wrong Answer
17
2,940
68
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c = map(int,input().split()) print("YES" if a<= c <=b else "NO")
s853789970
Accepted
18
2,940
68
a,b,c = map(int,input().split()) print("Yes" if a<= c <=b else "No")
s610816623
p03608
u785205215
2,000
262,144
Wrong Answer
2,104
5,488
1,267
There are N towns in the State of Atcoder, connected by M bidirectional roads. The i-th road connects Town A_i and B_i and has a length of C_i. Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road. If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?
from itertools import permutations def read_int_list(): return list(map(int, input().split())) def floyd_warshall(): for k in range(N): for i in range(N): for j in range(N): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) def dfs(c, las, d): global res if c == R+1: if res > d: res = d return for i in range(1,R): if used[i] != False: used[i] = True if las == -1: dfs(c+1,i,0) else: dfs(c+1, i, d+dist[r[las]][r[i]]) used[i] = False # global res # for p in permutations(r): # res = s N, M, R = (int(i) for i in input().split()) r = read_int_list() r = [x - 1 for x in r] used = [bool]*9 res = float('inf') dist = [[float("inf") for i in range(201)] for i in range((201))] for i in range(M): a, b, c = (int(i) for i in input().split()) a -= 1 b -= 1 dist[a][b] = c dist[b][a] = c floyd_warshall() dfs(1,-1,0) print(res)
s136495138
Accepted
1,625
4,720
881
import sys from itertools import permutations def read_int_list(): return list(map(int, input().split())) def main(): def floyd_warshall(): for k in range(n): for i in range(n): for j in range(n): dd = d[i][k] + d[k][j] if dd < d[i][j]: d[i][j] = dd n, m, r = read_int_list() v = read_int_list() v = [x - 1 for x in v] d = [[float('inf')] * n for i in range(n)] for i in range(n): d[i][i] = 0 for i in range(m): a, b, c = read_int_list() a -= 1 b -= 1 d[a][b] = c d[b][a] = c floyd_warshall() res = float('inf') for p in permutations(v): s = 0 for i in range(r - 1): s += d[p[i]][p[i + 1]] if s < res: res = s print(res) main()
s784369201
p03737
u973108807
2,000
262,144
Wrong Answer
17
2,940
60
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 = input().split() print(a.upper()+b.upper()+c.upper())
s951878426
Accepted
17
2,940
69
a,b,c = input().split() print(a[0].upper()+b[0].upper()+c[0].upper())
s205564463
p03599
u648212584
3,000
262,144
Wrong Answer
126
5,776
669
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
A,B,C,D,E,F = map(int,input().split()) def sol(i): solmax = min((i*E)//100,F-i) s = [] for i in range((solmax//C)+1): for j in range((solmax//D)+1): if C*i+D*j <= solmax: s.append(C*i+D*j) s = sorted(s) return s[-1] water = [] for i in range(F//(A*100)+1): for j in range(F//(B*100)+1): if 0 < 100*A*i+100*B*j < F: water.append(100*A*i+100*B*j) water = list(set(water)) suger = [] for i in range(len(water)): suger.append(sol(water[i])) print(water) print(suger) con = 0 ws = 0 s = 0 for k in range(len(water)): if con <= suger[k]/(water[k]+suger[k]): con = suger[k]/(water[k]+suger[k]) ws = (water[k]+suger[k]) s = suger[k] print(ws,s)
s355778247
Accepted
126
5,780
643
A,B,C,D,E,F = map(int,input().split()) def sol(i): solmax = min((i*E)//100,F-i) s = [] for i in range((solmax//C)+1): for j in range((solmax//D)+1): if C*i+D*j <= solmax: s.append(C*i+D*j) s = sorted(s) return s[-1] water = [] for i in range(F//(A*100)+1): for j in range(F//(B*100)+1): if 0 < 100*A*i+100*B*j < F: water.append(100*A*i+100*B*j) water = list(set(water)) suger = [] for i in range(len(water)): suger.append(sol(water[i])) con = 0 ws = 0 s = 0 for k in range(len(water)): if con <= suger[k]/(water[k]+suger[k]): con = suger[k]/(water[k]+suger[k]) ws = (water[k]+suger[k]) s = suger[k] print(ws,s)
s054616446
p02927
u251075661
2,000
1,048,576
Wrong Answer
19
2,940
168
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
m, d = map(int, input().split()) count = 0 for i in range(1, m + 1): for j in range(1, d + 1): if (j // 10) * (j % 10) == i: count += 1 print(count)
s518076810
Accepted
20
2,940
187
m, d = map(int, input().split()) count = 0 for i in range(1, m + 1): for j in range(21, d + 1): if (j % 10 >= 2) and (j // 10) * (j % 10) == i: count += 1 print(count)
s153066258
p03486
u941884460
2,000
262,144
Wrong Answer
17
3,064
626
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=input() t=input() l=max(len(s),len(t)) slist = [] tlist = [] for i in range(l): if i < len(s): slist.append(s[i]) if i < len(t): tlist.append(t[i]) slist.sort() tlist.sort(reverse=True) result = 'Yes' print(slist) print(tlist) if s==t: result = 'No' else: for j in range(l): if j < len(s) and j < len(t): if slist[j] == tlist[j]: continue elif slist[j] < tlist[j]: break else: result = 'No' break elif len(s) > len(t): result = 'No' break print(result)
s116119609
Accepted
17
3,064
600
s=input() t=input() l=max(len(s),len(t)) slist = [] tlist = [] for i in range(l): if i < len(s): slist.append(s[i]) if i < len(t): tlist.append(t[i]) slist.sort() tlist.sort(reverse=True) result = 'Yes' if s==t: result = 'No' else: for j in range(l): if j < len(s) and j < len(t): if slist[j] == tlist[j]: continue elif slist[j] < tlist[j]: break else: result = 'No' break elif len(s) > len(t): result = 'No' break print(result)
s815920500
p03386
u923662841
2,000
262,144
Wrong Answer
2,193
1,456,548
121
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A,B,K = map(int, input().split()) ans = list(i for i in range(A,B+1)) ans = set(ans[:K] + ans[-K:]) print(*ans, sep="\n")
s025992972
Accepted
30
9,168
198
A,B,K = map(int, input().split()) if B-A+1<= 2*K: print(*range(A,B+1), sep="\n") else: a = list(range(A,A+K)) b = list(range(B-K+1,B+1)) C = sorted(set(a+b)) print(*C, sep="\n")
s850486024
p03129
u013629972
2,000
1,048,576
Wrong Answer
41
5,460
915
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10 ** 20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): N, K = LI() print(N, K) if N % 2 == 0: return K <= N*2 else: return K <= N//2 +1 if main(): print('YES') else: print('NO')
s670606496
Accepted
68
7,368
899
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10 ** 20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): N, K = LI() if N % 2 == 0: return K <= N/2 else: return K <= N//2 +1 if main(): print('YES') else: print('NO')
s582306716
p03470
u080108339
2,000
262,144
Wrong Answer
17
2,940
153
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
N = int(input()) a = sorted(map(int, [input() for i in range(N)]), reverse=True) dan = 0 for i in range(N-1): if a[i] > a[i+1]: dan += 1 print(dan)
s233736236
Accepted
19
3,060
153
N = int(input()) a = sorted(map(int, [input() for i in range(N)]), reverse=True) dan = 1 for i in range(N-1): if a[i] > a[i+1]: dan += 1 print(dan)
s017258442
p03861
u017050982
2,000
262,144
Wrong Answer
17
2,940
210
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x = map(int,input().rstrip().split(" ")) if b - a + 1 >= x: if a % x != 0: a += x - (a % x) b -= (b % x) print((b - a) / x + 1) else: if a + x - (a % x) > b: print(0) else: print(1)
s506613506
Accepted
17
2,940
101
a,b,x = map(int,input().rstrip().split(" ")) p = b // x - a // x if a % x == 0: p += 1 print(p)
s987430516
p03486
u920103253
2,000
262,144
Wrong Answer
17
3,060
198
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=input() t=input() s=sorted([x for x in s],reverse=True) t=sorted([x for x in t],reverse=True) f="No" for i in range(min(len(s),len(t))): if s[i]<t[i]: f="Yes" break; print(f)
s970417902
Accepted
19
2,940
96
s=sorted(input()) t=sorted(input(),reverse=True) if s<t: print("Yes") else: print("No")
s189152085
p02283
u510829608
2,000
131,072
Wrong Answer
30
7,796
1,322
Search trees are data structures that support dynamic set operations including insert, search, delete and so on. Thus a search tree can be used both as a dictionary and as a priority queue. Binary search tree is one of fundamental search trees. The keys in a binary search tree are always stored in such a way as to satisfy the following binary search tree property: * Let $x$ be a node in a binary search tree. If $y$ is a node in the left subtree of $x$, then $y.key \leq x.key$. If $y$ is a node in the right subtree of $x$, then $x.key \leq y.key$. The following figure shows an example of the binary search tree. For example, keys of nodes which belong to the left sub-tree of the node containing 80 are less than or equal to 80, and keys of nodes which belong to the right sub-tree are more than or equal to 80. The binary search tree property allows us to print out all the keys in the tree in sorted order by an inorder tree walk. A binary search tree should be implemented in such a way that the binary search tree property continues to hold after modifications by insertions and deletions. A binary search tree can be represented by a linked data structure in which each node is an object. In addition to a key field and satellite data, each node contains fields _left_ , _right_ , and _p_ that point to the nodes corresponding to its left child, its right child, and its parent, respectively. To insert a new value $v$ into a binary search tree $T$, we can use the procedure insert as shown in the following pseudo code. The insert procedure is passed a node $z$ for which $z.key = v$, $z.left = NIL$, and $z.right = NIL$. The procedure modifies $T$ and some of the fields of $z$ in such a way that $z$ is inserted into an appropriate position in the tree. 1 insert(T, z) 2 y = NIL // parent of x 3 x = 'the root of T' 4 while x ≠ NIL 5 y = x // set the parent 6 if z.key < x.key 7 x = x.left // move to the left child 8 else 9 x = x.right // move to the right child 10 z.p = y 11 12 if y == NIL // T is empty 13 'the root of T' = z 14 else if z.key < y.key 15 y.left = z // z is the left child of y 16 else 17 y.right = z // z is the right child of y Write a program which performs the following operations to a binary search tree $T$. * insert $k$: Insert a node containing $k$ as key into $T$. * print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. You should use the above pseudo code to implement the insert operation. $T$ is empty at the initial state.
class Node(): def __init__(self, key): self.parent = None self.left = None self.right = None self.key = key class Tree(): def __init__(self): self.root = None def insert(self, key): z = Node(key) y = None x = self.root while x: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y == None: self.root = z elif z.key < y.key: y.left = z else: y.right = z def preorder(self, node): print(" {}".format(node.key), end = "") if node.left: self.preorder(node.left) if node.right: self.preorder(node.right) def inorder(self, node): if node.left: self.preorder(node.left) print(" {}".format(node.key), end = "") if node.right: self.preorder(node.right) def out(self): self.inorder(self.root) print('') self.preorder(self.root) print('') tree = Tree() N = int(input()) for _ in range(N): order = input().split() if order[0] == 'insert': tree.insert(int(order[1])) else: tree.out()
s559984409
Accepted
8,600
153,772
1,320
class Node(): def __init__(self, key): self.parent = None self.left = None self.right = None self.key = key class Tree(): def __init__(self): self.root = None def insert(self, key): z = Node(key) y = None x = self.root while x: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y == None: self.root = z elif z.key < y.key: y.left = z else: y.right = z def preorder(self, node): print(" {}".format(node.key), end = "") if node.left: self.preorder(node.left) if node.right: self.preorder(node.right) def inorder(self, node): if node.left: self.inorder(node.left) print(" {}".format(node.key), end = "") if node.right: self.inorder(node.right) def out(self): self.inorder(self.root) print('') self.preorder(self.root) print('') tree = Tree() N = int(input()) for _ in range(N): order = input().split() if order[0] == 'insert': tree.insert(int(order[1])) else: tree.out()
s351326030
p04043
u556610039
2,000
262,144
Wrong Answer
17
3,064
296
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a, b, c = map(int, input().split()) fiveCount = 0 sevenCount = 0 if a == 5: fiveCount+= 1 if b == 5: fiveCount+= 1 if c == 5: fiveCount+= 1 if a == 7: sevenCount+= 1 if b == 7: sevenCount+= 1 if c == 7: sevenCount+= 1 if fiveCount == 2 and sevenCount == 1: print("Yes") else: print("No")
s925670960
Accepted
17
3,064
296
a, b, c = map(int, input().split()) fiveCount = 0 sevenCount = 0 if a == 5: fiveCount+= 1 if b == 5: fiveCount+= 1 if c == 5: fiveCount+= 1 if a == 7: sevenCount+= 1 if b == 7: sevenCount+= 1 if c == 7: sevenCount+= 1 if fiveCount == 2 and sevenCount == 1: print("YES") else: print("NO")
s754533449
p03816
u760767494
2,000
262,144
Wrong Answer
2,105
93,260
706
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
import collections from operator import itemgetter n = int(input()) l = list(map(int, input().split())) l = collections.Counter(l) l_1 = [] ans = 0 for i in l.items(): l_1.append(list(i)) l_1.sort(key=itemgetter(1), reverse=True) print(l_1) i = 0 for j in range(len(l_1)): k = 1 print(l_1) if l_1[i][1] == 1: i += 1 elif l_1[i][1] >= 2: l_1[i][1] -= 1 while True: if i + k <= len(l_1) - 1: if l_1[i + k][1] >= 2: l_1[i + k][1] -= 1 ans += 2 break else: k += 1 else: ans += 2 break print(n-ans)
s200119145
Accepted
52
18,656
197
import collections n = int(input()) l = list(map(int, input().split())) l = collections.Counter(l) kind = len(l.keys()) if (n-kind)%2==0: print(len(l.keys())) else: print(len(l.keys())-1)
s199024353
p02401
u928633434
1,000
131,072
Wrong Answer
20
5,492
8
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.
34.1201
s999562553
Accepted
20
5,600
244
while True: a,op,b = input().split() if op == "?": break elif op == "+": print (int(a) + int(b)) elif op == "-": print (int(a) - int(b)) elif op == "*": print (int(a) * int(b)) else: print (int(int(a) / int(b)))
s708685704
p02795
u473023730
2,000
1,048,576
Wrong Answer
17
2,940
99
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
h=int(input()) w=int(input()) n=int(input()) a=max(h,w) b=0 m=0 while b+a<=n: b+=a m+=1 print(m)
s419590371
Accepted
17
3,060
111
h=int(input()) w=int(input()) n=int(input()) a=max(h,w) b=0 m=0 if n%a==0: print(n//a) else: print(n//a+1)
s325615445
p03370
u513081876
2,000
262,144
Wrong Answer
17
2,940
110
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
N, X = map(int, input().split()) m = [int(i) for i in input().split()] m.sort() print(N + (X - sum(m)) % m[0])
s674899328
Accepted
18
2,940
110
N, X = map(int, input().split()) m = sorted([int(input()) for i in range(N)]) print(N + (X - sum(m)) // m[0])
s566951392
p02412
u663910047
1,000
131,072
Wrong Answer
20
7,668
382
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
x=1 y=1 list=[] while x>0: if x ==0 and y == 0: break x,y = map(int,input().split()) list.append([x,y]) for L in list: ans = 0 for i in range(1,L[0]-1): for j in range(i+1,L[0]): for k in range(j+1,L[0]+1): if L[1]== i + j+ k: ans += 1 else: pass print(ans)
s678487630
Accepted
620
7,660
402
x=1 y=1 list=[] while x>0: if x ==0 and y == 0: break x,y = map(int,input().split()) list.append([x,y]) list.remove([0,0]) for L in list: ans = 0 for i in range(1,L[0]-1): for j in range(i+1,L[0]): for k in range(j+1,L[0]+1): if L[1]== i + j+ k: ans += 1 else: pass print(ans)
s094651649
p03657
u320763652
2,000
262,144
Wrong Answer
18
2,940
101
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 = map(int, input().split()) if a+b % 3 == 0: print("Possible") else: print("Impossible")
s819487529
Accepted
17
2,940
131
a,b = map(int, input().split()) if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0: print("Possible") else: print("Impossible")
s062622341
p03695
u519923151
2,000
262,144
Wrong Answer
18
3,060
267
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()) al = list(map(int, input().split())) ald = list(map(lambda x : x // 400,al)) allow = list(filter(lambda x: x<8, ald)) reslow = len(set(allow)) alhigh= list(filter(lambda x: x>=8,ald)) reshigh = len(alhigh) res = min((reslow+reshigh),8) print(res)
s863528742
Accepted
18
3,064
286
n = int(input()) al = list(map(int, input().split())) ald = list(map(lambda x : x // 400,al)) allow = list(filter(lambda x: x<8, ald)) reslow = len(set(allow)) alhigh= list(filter(lambda x: x>=8,ald)) reshigh = len(alhigh) resl = max(reslow,1) resh = reslow+reshigh print(resl,resh)
s393023657
p03501
u112567325
2,000
262,144
Wrong Answer
17
2,940
80
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
A,B,C = list(map(int,input().split())) if A*B > C: print(A*B) else: print(C)
s814569470
Accepted
17
2,940
80
A,B,C = list(map(int,input().split())) if A*B < C: print(A*B) else: print(C)
s337806345
p03494
u431981421
2,000
262,144
Wrong Answer
17
3,060
222
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.
li = list(map(int,input().split())) count = 0 while(True): for i in li: if i % 2 == 1: break else: count += 1 for index, x in enumerate(li): li[index] = x / 2 continue break print(count)
s001411693
Accepted
19
3,060
237
a=int(input()) li = list(map(int,input().split())) count = 0 while(True): for i in li: if i % 2 == 1: break else: count += 1 for index, x in enumerate(li): li[index] = x / 2 continue break print(count)
s664915361
p03228
u968097972
2,000
1,048,576
Wrong Answer
20
3,188
411
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
S = input().split() A = int(S[0]) B = int(S[1]) K = int(S[2]) print(A, B, K) for k in range(K): if k % 2 == 0: #taka if A % 2 == 1: A -= 1 B_plus = A//2 A -= B_plus B += B_plus else: if B % 2 == 1: B -= 1 A_plus = B//2 B -= A_plus A += A_plus print(A,B)
s233802577
Accepted
17
3,060
412
S = input().split() A = int(S[0]) B = int(S[1]) K = int(S[2]) for k in range(K): if k % 2 == 0: #taka if A % 2 == 1: A -= 1 B_plus = A//2 A -= B_plus B += B_plus else: if B % 2 == 1: B -= 1 A_plus = B//2 B -= A_plus A += A_plus print(A,B)
s922506362
p03693
u539768961
2,000
262,144
Wrong Answer
17
2,940
96
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) if (10 * g + b) % 4 == 0: print('Yes') else: print('No')
s952131486
Accepted
17
2,940
96
r, g, b = map(int, input().split()) if (10 * g + b) % 4 == 0: print('YES') else: print('NO')
s462350255
p03161
u766393261
2,000
1,048,576
Wrong Answer
1,933
24,596
290
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 one of the following: Stone i + 1, i + 2, \ldots, i + K. 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,k=map(int,input().split()) h=np.array(list(map(int,input().split()))) dp=np.zeros(n,dtype=int) dp[1]=abs(h[1]-h[0]) for i in range(2,n): if i-k>0: dp[i]=min(dp[i-k:i]+abs(h[i]-h[i-k:i])) elif 0>=i-k: dp[i]=min(dp[0:i]+abs(h[i]-h[0:i])) print(dp)
s200014729
Accepted
1,887
22,828
295
import numpy as np n,k=map(int,input().split()) h=np.array(list(map(int,input().split()))) dp=np.zeros(n,dtype=int) dp[1]=abs(h[1]-h[0]) for i in range(2,n): if i-k>0: dp[i]=min(dp[i-k:i]+abs(h[i]-h[i-k:i])) elif 0>=i-k: dp[i]=min(dp[0:i]+abs(h[i]-h[0:i])) print(dp[n-1])
s855496566
p02741
u511870776
2,000
1,048,576
Wrong Answer
17
2,940
97
Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
s140672514
Accepted
17
2,940
135
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] k = int(input()) print(l[k-1])
s815035618
p02612
u284363684
2,000
1,048,576
Wrong Answer
28
9,088
49
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.
# input N = int(input()) print(N % 1000)
s449280573
Accepted
27
9,052
136
# input N = int(input()) noguchi = [1000 * n for n in range(1, 11)] print(min([ngc - N for ngc in noguchi if (ngc - N) >= 0]))
s129119391
p02694
u366939485
2,000
1,048,576
Wrong Answer
29
9,168
135
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x = int(input()) balance = 100 count = 0 while x >= balance: balance *= 1.01 balance = int(balance) count += 1 print(count)
s956164071
Accepted
34
9,092
117
x = int(input()) balance = 100 count = 0 while balance < x: balance += balance // 100 count += 1 print(count)
s027965837
p04043
u978494963
2,000
262,144
Wrong Answer
17
2,940
137
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.
hoge = tuple(map(lambda x : int(x), input().split(" "))) if hoge.count(5) == 2 and hoge.count(7) == 1: print("Yes") else: print("No")
s430116958
Accepted
17
2,940
137
hoge = tuple(map(lambda x : int(x), input().split(" "))) if hoge.count(5) == 2 and hoge.count(7) == 1: print("YES") else: print("NO")
s785233694
p02612
u548123110
2,000
1,048,576
Wrong Answer
30
9,140
93
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
def main(): n = int(input()) print(n % 1000) if __name__ == "__main__": main()
s499400809
Accepted
37
9,148
158
def main(): n = int(input()) n = n % 1000 if n == 0: print(0) else: print(1000 - n) if __name__ == "__main__": main()
s332519947
p04012
u535659144
2,000
262,144
Wrong Answer
17
2,940
176
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
strlist = list(input()) findlist="qazwsxedcrfvtgbyhnujmikolp" flist=list(findlist) flag = "Yes" for a in flist: if not strlist.count(a) % 2: flag = "No" print(flag)
s169753741
Accepted
17
3,060
239
li=list(input()) li.sort() if len(li)%2: print("No") exit() while True: if len(li)==0: print("Yes") break elif li[0]==li[1]: li.pop(0) li.pop(0) else: print("No") break
s656459841
p02608
u381959472
2,000
1,048,576
Wrong Answer
2,205
9,128
435
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
import math N = int(input()) count = 0 for n in range(1, N): sqrt_n = int(math.sqrt(n)) for i in range(1, sqrt_n): for p in range(1, sqrt_n): for q in range(1, sqrt_n): if i ** 2 + p ** 2 + q ** 2 + i * p + p * q + i * q > n: break elif i ** 2 + p ** 2 + q ** 2 + i * p + p * q + i * q == n: count += 1 print(count) count = 0
s217370524
Accepted
448
9,404
449
import math N = int(input()) NList = [0 for i in range(N)] count = 0 tmp = 0 sqrt_n = int(math.sqrt(N)) for i in range(1, sqrt_n): for p in range(1, sqrt_n): for q in range(1, sqrt_n): if i ** 2 + p ** 2 + q ** 2 + i * p + p * q + i * q > N: break else: NList[i ** 2 + p ** 2 + q ** 2 + i * p + p * q + i * q - 1] += 1 for n_count in NList: print(n_count)
s957498843
p02612
u247753603
2,000
1,048,576
Wrong Answer
27
9,152
783
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
def f(x): if 0 <= x <=999: print(1000-x) else: b = int(x / 100) c = int(str(b)[1]) g = 9-c h = int(x/10) i = int(str(h)[2]) if x %1000==0: print("0") elif x % 500==0 and x % 1000!=0: print("500") elif x % 100==0 and x % 500!=0: f = 10-c print(f*100) elif x % 10 ==0 and x % 100!=0: j =10-i print("g", g) print(g*100+j*10) elif x % 10!=0: k = int(str(x)[3]) l = 9 - i m = 10-k print(k) print(m) print(g*100+l*10+m) f(853) # print("b",b) # print("c",c) # print("h",h) # print("i",i) # print("j",j)
s948594124
Accepted
29
9,108
652
def f(y): if 1 <= y <=999: print(1000-y) elif 1000<= y <= 10000 : b = int(y / 100) c = int(str(b)[1]) g = 9-c h = int(y/10) i = int(str(h)[2]) if y %1000==0: print("0") elif y % 500==0 and y % 1000!=0: print("500") elif y % 100==0 and y % 500!=0: f = 10-c print(f*100) elif y % 10 ==0 and y % 100!=0: j =10-i print(g*100+j*10) elif y % 10!=0: k = int(str(y)[3]) l = 9 - i m = 10-k print(g*100+l*10+m) y = input() x = f(int(y))
s959161387
p02578
u977982384
2,000
1,048,576
Wrong Answer
265
32,208
256
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
n = int(input()) a = list(map(int, input().split( ))) front = 0 step = 0 for height in a : x = 0 if front > height : x = front - height step += x print(front, height, x) if front < height: front = height print(step)
s476745628
Accepted
114
32,348
228
n = int(input()) a = list(map(int, input().split( ))) front = 0 step = 0 for height in a : x = 0 if front > height : x = front - height step += x if front < height: front = height print(step)
s340246340
p03910
u857428111
2,000
262,144
Wrong Answer
21
3,408
144
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
import math N=int(input()) p=math.sqrt(N*2-0.25)-0.5 q=int(p)+1 M=q*(q+1)//2 L=M-N#must0or+ for i in range(q+1): if i != L: print(i)
s549751525
Accepted
22
3,408
456
import sys input= lambda: sys.stdin.readline().rstrip() def pin(type=int): return map(type,input().split()) #%%code def resolve(): x=int(input()) i=0;temp=0 while (1): i+=1 temp+=i if temp > x: z=-x+temp for i in range(i): if i+1!=z:print(i+1) break if temp==x: for i in range(i):print(i+1) break #%%submit! resolve()
s717450059
p04011
u870841038
2,000
262,144
Wrong Answer
17
3,060
141
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
a = [int(input()) for i in range(4)] if a[1] > a[2]: ans = a[1] * a[2] + (a[0]-a[1]) * a[3] else: ans = a[0] * a[2] print(str(ans))
s020560051
Accepted
17
3,060
148
li = list(int(input()) for i in range(4)) if li[0] > li[1]: ans = li[1]*li[2] + (li[0]-li[1])*li[3] else: ans = li[0]*li[2] print(str(ans))
s277064282
p03549
u536034761
2,000
262,144
Wrong Answer
29
9,144
58
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
N, M = map(int, input().split()) print(100 * N + 1900 * M)
s763257787
Accepted
26
9,132
75
N, M = map(int, input().split()) print((100 * (N - M) + 1900 * M) * (2**M))
s723160476
p03048
u036914910
2,000
1,048,576
Wrong Answer
2,104
18,584
213
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
r,g,b,n = map(int,input().split()) ans = 0 for i in range(n+1) : for j in range(n+1-i) : k = n-r*i-g*j if k >= 0 and k % b == 0 : print(i,j,k,'Yes') ans += 1 print(ans)
s746613108
Accepted
1,826
2,940
184
R,G,B,n = map(int,input().split()) ans = 0 for r in range(n+1) : for g in range(n+1-r*R) : b = n-r*R-g*G if b >= 0 and b % B == 0 : ans += 1 print(ans)
s817067053
p03797
u578953945
2,000
262,144
Wrong Answer
18
2,940
148
Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
S,C=map(int,input().split()) ANS = 0 if S * 2 <= C: ANS = S C -= (S*2) print(C) ANS += (C//4) print(ANS) else: ANS = C // 2 print(ANS)
s855705783
Accepted
17
2,940
148
S,C=map(int,input().split()) ANS = 0 if S * 2 <= C: ANS = S C -= (S*2) #rint(C) ANS += (C//4) print(ANS) else: ANS = C // 2 print(ANS)
s617998388
p04043
u957872856
2,000
262,144
Wrong Answer
17
2,940
203
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a = list(map(int, input().split())) d = 0 e = 0 for i in range(3): f = a[i] if f == 7: d += 1 elif f == 5: e += 1 else: break if d == 2 and e == 1: print("YES") else: print("NO")
s015372961
Accepted
17
2,940
81
n = input().split() print("YES" if n.count("5")==2 and n.count("7")==1 else "NO")
s703364921
p03997
u506587641
2,000
262,144
Wrong Answer
17
2,940
67
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = list(int(input()) for _ in range(3)) print((a[0]+a[1])*a[2]/2)
s827248487
Accepted
17
3,064
67
a = list(int(input()) for _ in range(3)) print((a[0]+a[1])*a[2]//2)
s746669286
p03836
u755180064
2,000
262,144
Wrong Answer
27
9,160
567
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.
def search_route(f, t): route = '' y = t[1] - f[1] tmp_y = 'U'*y if y >= 0 else 'D'*(y*-1) x = t[0] - f[0] tmp_x = 'R'*x if x >= 0 else 'L'*(x*-1) route = tmp_y + tmp_x return route def main(): t = list(map(int, input().split())) route = search_route(t[:2], t[2:]) + search_route(t[2:], t[:2]) t[0] -= 1 t[3] += 1 route_2 = 'L' + search_route(t[:2], t[2:]) + 'D' t[2] += 1 t[1] -= 1 route_2 = route + 'R' + search_route(t[2:], t[:2]) + 'U' print(route+route_2) if __name__ == '__main__': main()
s064308158
Accepted
29
9,168
658
url = "https://atcoder.jp//contests/abc051/tasks/abc051_c" def search_route(f, t): route = '' y = t[1] - f[1] tmp_y = 'U'*y if y >= 0 else 'D'*(y*-1) x = t[0] - f[0] tmp_x = 'R'*x if x >= 0 else 'L'*(x*-1) route = tmp_y + tmp_x return route def main(): t = list(map(int, input().split())) route = search_route(t[:2], t[2:]) + search_route(t[2:], t[:2]) tmp = t[:] t[0] -= 1 t[3] += 1 route_2 = 'L' + search_route(t[:2], t[2:]) + 'D' t = tmp t[1] -= 1 t[2] += 1 route_2 = route_2 + 'R' + search_route(t[2:], t[:2]) + 'U' print(route+route_2) if __name__ == '__main__': main()
s299284023
p02389
u915307213
1,000
131,072
Wrong Answer
20
5,536
127
Write a program which calculates the area and perimeter of a given rectangle.
def xxx(): for i in range(5): print(i, end=' ') print(id(i)) for i in range(3): xxx() print(id(i))
s882389923
Accepted
20
5,592
142
def rect(a,b): return a*b, 2*(a+b) n =input() x =n.split() a =int(x[0]) b =int(x[1]) area, perimeter = rect(a,b) print(area, perimeter)
s438634120
p03813
u111365362
2,000
262,144
Wrong Answer
17
2,940
49
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.
n = int(input()) print( n//11*2 + (n%11)//6 + 1 )
s575245561
Accepted
17
2,940
66
#23:53 if int(input()) < 1200: print('ABC') else: print('ARC')
s067829532
p03378
u934246119
2,000
262,144
Wrong Answer
17
3,064
489
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
n, m, x = map(int, input().split()) a_tmp = input().split() a = [] for _ in a_tmp: a.append(int(_)) cost_l = 0 cost_r = 0 j = 0 for i in range(n+1): if i < x: if i == a[j]: cost_l += 1 j += 1 if j >= len(a): break elif x < i: if i == a[j]: cost_r += 1 j += 1 if j >= len(a): break else: continue print(cost_l, cost_r) print(min(cost_l, cost_r))
s455723578
Accepted
17
3,064
467
n, m, x = map(int, input().split()) a_tmp = input().split() a = [] for _ in a_tmp: a.append(int(_)) cost_l = 0 cost_r = 0 j = 0 for i in range(n+1): if i < x: if i == a[j]: cost_l += 1 j += 1 if j >= len(a): break elif x < i: if i == a[j]: cost_r += 1 j += 1 if j >= len(a): break else: continue print(min(cost_l, cost_r))
s774526980
p03433
u089075077
2,000
262,144
Wrong Answer
18
2,940
84
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) A = int(input()) if N % 500 > A: print('NO') else: print('YES')
s625042916
Accepted
18
3,064
85
N = int(input()) A = int(input()) if N % 500 > A: print('No') else: print('Yes')
s227463562
p03854
u219369949
2,000
262,144
Wrong Answer
20
3,316
150
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`.
N = input() if N.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '') == '': print('Yes') else: print('No')
s829692551
Accepted
18
3,188
150
N = input() if N.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '') == '': print('YES') else: print('NO')
s356884451
p03401
u022215787
2,000
262,144
Wrong Answer
209
14,048
253
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.
N = int(input()) A = list(map(int, input().split())) A = [0] + A + [0] total = sum([ abs(A[x]-A[x+1]) for x in range(N) ]) for i in range(N): minus = abs(A[i] - A[i+1]) + abs(A[i+1] - A[i+2]) plus = abs(A[i] - A[i+2]) print(total-minus+plus)
s466864087
Accepted
219
14,044
255
N = int(input()) A = list(map(int, input().split())) A = [0] + A + [0] total = sum([ abs(A[x]-A[x+1]) for x in range(N+1) ]) for i in range(N): minus = abs(A[i] - A[i+1]) + abs(A[i+1] - A[i+2]) plus = abs(A[i] - A[i+2]) print(total-minus+plus)
s826404795
p03089
u639094382
2,000
1,048,576
Wrong Answer
17
3,060
179
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
n = int(input()) b = list(map(int, input().split())) can = True for i in range(1, n +1): if b[i - 1] > i: can = False if can: for x in b: print(x) else: print(-1)
s121031078
Accepted
18
3,064
347
n = int(input()) b = list(map(int, input().split())) can = True for i in range(1, n +1): if b[i - 1] > i: can = False break if can: result = [] while(len(b)): for i in range(len(b), 0, -1): if i == b[i - 1]: result.insert(0, i) b.pop(i - 1) break for a in result: print(a) else: print(-1)
s573082886
p03679
u474925961
2,000
262,144
Wrong Answer
17
3,060
190
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
import sys if sys.platform =='ios': sys.stdin=open('input_file.txt') x,a,b=map(int,input().split()) if b<a: print("delicious") elif a<b: print("dangerous") else: print("safe")
s548620375
Accepted
17
3,060
193
import sys if sys.platform =='ios': sys.stdin=open('input_file.txt') x,a,b=map(int,input().split()) if b<=a: print("delicious") elif a+x<b: print("dangerous") else: print("safe")
s221199590
p03377
u272557899
2,000
262,144
Wrong Answer
19
2,940
94
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x= map(int, input().split()) if a <= x and a + b >= x: print("Yes") else: print("No")
s459038896
Accepted
17
2,940
95
a,b,x= map(int, input().split()) if a <= x and a + b >= x: print("YES") else: print("NO")
s846336302
p03698
u318427318
2,000
262,144
Wrong Answer
28
9,120
330
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def main(): s = input().rstrip() string_dict={} for i in s: if i not in string_dict: d = {i:1} string_dict.update(d) else: print("No") exit() print("Yes") if __name__=="__main__": main()
s839465046
Accepted
28
9,084
330
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def main(): s = input().rstrip() string_dict={} for i in s: if i not in string_dict: d = {i:1} string_dict.update(d) else: print("no") exit() print("yes") if __name__=="__main__": main()
s848394896
p03854
u869919400
2,000
262,144
Wrong Answer
17
3,188
229
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() words = ['dream', 'dreamer', 'erase', 'eraser'] while s != '': tmp = s for word in words: s.rstrip(word) if s == '': print('YES') if tmp == s: print('NO') break
s377174830
Accepted
19
3,188
253
s = input() while s != '': tmp = s s = s.replace('eraser', '') s = s.replace('erase', '') s = s.replace('dreamer', '') s = s.replace('dream', '') if s == '': print('YES') if tmp == s: print('NO') break
s129810302
p03681
u088863512
2,000
262,144
Wrong Answer
58
9,812
891
Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys. How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
# -*- coding: utf-8 -*- import sys from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil # def input(): return sys.stdin.readline()[:-1] # warning not \n import string from bisect import bisect_left MOD = int(1e9)+7 INF = float('inf') def fmod(x): ans = 1 for i in range(1, x + 1): ans *= i ans %= MOD return ans def solve(): n, m = [int(x) for x in input().split()] n, m = min(n,m), max(n,m) x = m - n if x > 1: print(0) elif x == 1: print((fmod(n) * fmod(m)*2)%MOD) else: print((fmod(n) * fmod(m))%MOD) t = 1 # t = int(input()) for case in range(1,t+1): ans = solve() """ azyxwvutsrqponmlkjihgfedcb """
s162690569
Accepted
61
9,812
891
# -*- coding: utf-8 -*- import sys from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil # def input(): return sys.stdin.readline()[:-1] # warning not \n import string from bisect import bisect_left MOD = int(1e9)+7 INF = float('inf') def fmod(x): ans = 1 for i in range(1, x + 1): ans *= i ans %= MOD return ans def solve(): n, m = [int(x) for x in input().split()] n, m = min(n,m), max(n,m) x = m - n if x > 1: print(0) elif x == 1: print((fmod(n) * fmod(m))%MOD) else: print((fmod(n) * fmod(m)*2)%MOD) t = 1 # t = int(input()) for case in range(1,t+1): ans = solve() """ azyxwvutsrqponmlkjihgfedcb """
s202941963
p03195
u826263061
2,000
1,048,576
Wrong Answer
189
7,072
164
There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors. The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?
n = int(input()) a = [] for _ in range(n): a.append(int(input())) mina = min(a) r = sum(a) - mina*n if r % 2 == 1: print('First') else: print('Second')
s074776258
Accepted
193
3,060
160
n = int(input()) ans = False for _ in range(n): i = int(input()) if i % 2 == 1: ans = True break if ans: print('first') else: print('second')
s366133814
p03048
u389679466
2,000
1,048,576
Wrong Answer
22
3,060
164
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
input = input().split() R = int(input[0]) G = int(input[1]) B = int(input[2]) N = int(input[3]) count = 0 for r in range(N+1): count += 2**(N-r) print(count)
s140555539
Accepted
1,556
3,060
352
import math input = input().split() r = int(input[0]) g = int(input[1]) b = int(input[2]) N = int(input[3]) count = 0 # print(N/r) for x in range(math.ceil(N/r+0.0001)): for y in range(math.ceil((N-x*r)/g + 0.0001)): # print(str(x), str(y)) if (N - x*r - y*g) % b == 0: count +=1 print(count)
s184705259
p03719
u758973277
2,000
262,144
Wrong Answer
17
2,940
86
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
A,B,C = map(int,input().split()) if C<=A and C>=B: print('Yes') else: print('No')
s803640261
Accepted
17
2,940
86
A,B,C = map(int,input().split()) if C>=A and C<=B: print('Yes') else: print('No')
s040067156
p04029
u846150137
2,000
262,144
Wrong Answer
17
2,940
52
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n=int(input()) print((n+1)*(n//2) + ((n+1)/2)*(n%2))
s548220591
Accepted
17
2,940
53
n=int(input()) print((n+1)*(n//2) + ((n+1)//2)*(n%2))
s507240328
p03712
u870518235
2,000
262,144
Wrong Answer
28
9,156
148
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
H, W = map(int, input().split()) A = ["#"+str(input())+"#" for _ in range(H)] res = "#" * W print(res) for i in range(H): print(A[i]) print(res)
s377431941
Accepted
30
9,168
152
H, W = map(int, input().split()) A = ["#"+str(input())+"#" for _ in range(H)] res = "#" * (W+2) print(res) for i in range(H): print(A[i]) print(res)
s004985065
p03160
u024768467
2,000
1,048,576
Wrong Answer
130
13,928
342
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
n = int(input()) h_list = list(map(int,input().split())) cost_min_list = [0] * n cost_min_list[0] = 0 cost_min_list[0] = h_list[0] for i in range(2, n): cost_min_list[i] = min(cost_min_list[i - 1] + abs(h_list[i] - h_list[i - 1]), cost_min_list[i - 2] + abs(h_list[i] - h_list[i - 2])) print(cost_min_list[n-1])
s183251185
Accepted
134
13,980
361
n = int(input()) h_list = list(map(int,input().split())) cost_min_list = [0] * n cost_min_list[0] = 0 cost_min_list[1] = abs(h_list[1] - h_list[0]) for i in range(2, n): cost_min_list[i] = min(cost_min_list[i - 1] + abs(h_list[i] - h_list[i - 1]), cost_min_list[i - 2] + abs(h_list[i] - h_list[i - 2])) print(cost_min_list[n - 1])
s981912049
p03377
u262244504
2,000
262,144
Wrong Answer
17
2,940
120
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x = map(int,input().split()) dc = x - a if dc < 0 : print('No') elif dc <= b: print('Yes') else: print('No')
s485242198
Accepted
17
2,940
109
a,b,x = map(int,input().split()) if a > x : print('NO') elif x-a <= b: print('YES') else: print('NO')
s075783693
p00352
u529013669
1,000
262,144
Wrong Answer
40
7,636
38
Alice and Brown are brothers in a family and each receives pocket money in celebration of the coming year. They are very close and share the total amount of the money fifty-fifty. The pocket money each receives is a multiple of 1,000 yen. Write a program to calculate each one’s share given the amount of money Alice and Brown received.
print(sum(map(int,input().split()))/2)
s564979313
Accepted
30
7,688
43
print(int(sum(map(int,input().split()))/2))
s238387174
p03597
u365364616
2,000
262,144
Wrong Answer
18
2,940
46
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
n = int(input()) a = int(input()) print(n - a)
s027900784
Accepted
18
2,940
50
n = int(input()) a = int(input()) print(n * n - a)
s626710009
p03352
u454524105
2,000
1,048,576
Wrong Answer
17
2,940
143
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
x = int(input()) ans = 1 for i in range(100): for j in range(100): if x < i**j: break else: ans = max(ans, i**j) print(ans)
s474309697
Accepted
19
2,940
142
x = int(input()) ans = 1 for i in range(x): for j in range(2, x): if x < i**j: break else: ans = max(ans, i**j) print(ans)
s788214109
p02669
u164727245
2,000
1,048,576
Time Limit Exceeded
2,205
9,224
824
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
# coding: utf-8 def solve(*args: str) -> str: t = int(args[0]) NABCD = [tuple(map(int, nabcd.split())) for nabcd in args[1:]] ret = [] for n, a, b, c, d in NABCD: ABC = sorted([(a, 2), (b, 3), (c, 5)], key=lambda x: x[1]//x[0], reverse=True) ans = n*d stack = [(n, d)] # remaining, cost while stack: rem, cost = stack.pop() if rem <= 1: ans = min(ans, cost) continue for y, x in ABC: if cost+y < ans: stack.append((rem//x, (rem % x)*d+cost+y)) stack.append((-(-rem//x), (-rem % x)*d+cost+y)) ret.append(str(ans)) return '\n'.join(ret) if __name__ == "__main__": print(solve(*(open(0).read().splitlines())))
s846414914
Accepted
1,180
10,960
928
# coding: utf-8 from collections import defaultdict def solve(*args: str) -> str: t = int(args[0]) NABCD = [tuple(map(int, nabcd.split())) for nabcd in args[1:]] ret = [] for n, a, b, c, d in NABCD: ABC = ((2, a), (3, b), (5, c)) dp = defaultdict(lambda: n*d) stack = [(n, 0)] while stack: rem, cost = stack.pop() if min(dp[0], dp[rem]) <= cost: continue dp[rem] = cost dp[0] = min(dp[0], cost+rem*d) if 0 < rem: for x, y in ABC: div, m = divmod(rem, x) if div: stack.append((div, d*m+cost+y)) if m: stack.append((div+1, d*(x-m)+cost+y)) ret.append(str(dp[0])) return '\n'.join(ret) if __name__ == "__main__": print(solve(*(open(0).read().splitlines())))
s439801663
p03860
u640603056
2,000
262,144
Wrong Answer
17
2,940
58
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
a, b, c = input().split() s = "A"+b.upper() + "C" print(s)
s244871629
Accepted
17
2,940
61
a, b, c = input().split() s = "A"+b[0].upper() + "C" print(s)
s303300620
p02612
u855636544
2,000
1,048,576
Wrong Answer
27
9,036
79
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.
import math n = float(input()) p = n//1000 if n%1000!=0: p+=1 print (p*1000-n)
s863342081
Accepted
29
9,096
85
import math n = float(input()) p = n//1000 if n%1000!=0: p+=1 print (int(p*1000-n))
s271229620
p00016
u123687446
1,000
131,072
Wrong Answer
30
7,780
270
When a boy was cleaning up after his grand father passing, he found an old paper: In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper. For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town. You can assume that d ≤ 100 and -180 ≤ t ≤ 180\.
from math import sin,cos,pi x = 0 y = 0 ca = pi/2 while True: d, a = list(map(int, input().split(","))) if d or a: x += d*cos(ca) y += d*sin(ca) ca -= a*pi/180 else: break print("{0:.0f}".format(x)) print("{0:.0f}".format(y))
s220697103
Accepted
30
7,848
249
from math import sin,cos,pi x = 0 y = 0 ca = 90 while True: d, a = list(map(int, input().split(","))) if d or a: x += d*cos(ca*pi/180) y += d*sin(ca*pi/180) ca -= a else: break print(int(x)) print(int(y))
s245294032
p03417
u836737505
2,000
262,144
Wrong Answer
17
2,940
83
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
n,m = map(int, input().split()) print(1 if n==2 or m==2 else max(n-2,1)*max(m-2,1))
s620377414
Accepted
17
2,940
83
n,m = map(int, input().split()) print(0 if n==2 or m==2 else max(n-2,1)*max(m-2,1))
s591494660
p02606
u938005055
2,000
1,048,576
Wrong Answer
25
9,012
133
How many multiples of d are there among the integers between L and R (inclusive)?
L, R, d = list(map(int, input().split())) count = 0 for i in range(L, R): if i % d == 0: count = count + 1 print(count)
s553237747
Accepted
29
9,008
131
L, R, d = map(int, input().split()) count = 0 for i in range(L, R + 1): if i % d == 0: count = count + 1 print(count)
s714319905
p03448
u849151695
2,000
262,144
Wrong Answer
58
2,940
310
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,X = [int(input()) for i in range(4)] ans = 0 for a in range(0,A): for b in range(0,B): for c in range(0,C): total = 500 * a + 100 * b + 50 * c if total == X: ans +=1 print(ans)
s128410342
Accepted
53
3,060
315
A,B,C,X = [int(input()) for i in range(4)] ans = 0 for a in range(0,A+1): for b in range(0,B+1): for c in range(0,C+1): total = 500 * a + 100 * b + 50 * c if total == X: ans +=1 print(ans)
s570892800
p02613
u079022693
2,000
1,048,576
Wrong Answer
55
9,180
633
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
from sys import stdin def main(): readline=stdin.readline n=int(readline()) li=[0]*4 for i in range(n): tmp=readline().strip() if tmp=="AC": li[0]+=1 elif tmp=="WA": li[1]+=1 elif tmp=="TLE": li[2]+=1 elif tmp=="RE": li[3]+=1 for i in range(4): if i==0: print("AC x {}",li[0]) elif i==1: print("WA x {}",li[1]) elif i==2: print("TLR x {}",li[2]) elif i==3: print("RE x {}",li[3]) if __name__=="__main__": main()
s976312171
Accepted
55
9,244
653
from sys import stdin def main(): readline=stdin.readline n=int(readline()) li=[0]*4 for i in range(n): tmp=readline().strip() if tmp=="AC": li[0]+=1 elif tmp=="WA": li[1]+=1 elif tmp=="TLE": li[2]+=1 elif tmp=="RE": li[3]+=1 for i in range(4): if i==0: print("AC x {}".format(li[0])) elif i==1: print("WA x {}".format(li[1])) elif i==2: print("TLE x {}".format(li[2])) elif i==3: print("RE x {}".format(li[3])) if __name__=="__main__": main()
s374500874
p03068
u082861480
2,000
1,048,576
Wrong Answer
17
2,940
152
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
n = int(input()) s = input() k = int(input()) exa = s[k-1] for i in s: if i != exa: print(i,exa) s = s.replace(i,'*') print(s)
s379097014
Accepted
18
2,940
131
n = int(input()) s = input() k = int(input()) exa = s[k-1] for i in s: if i != exa: s = s.replace(i,'*') print(s)
s218055079
p03816
u210440747
2,000
262,144
Wrong Answer
2,103
14,388
297
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
if __name__=="__main__": n = int(input()) As = list(map(int,input().split())) Non_dup_As = list(set(As)) count = 0 for a in Non_dup_As: count+=As.count(a) if(count % 2 == 0): print(len(As) - int(count/2)) else: print(len(As) - int((count+1)/2))
s312770206
Accepted
64
14,204
225
if __name__=="__main__": n = int(input()) As = list(map(int,input().split())) Non_dup_As = list(set(As)) count = len(Non_dup_As) if(count % 2 == 0): print(count - 1) else: print(count)
s523785691
p03150
u698919163
2,000
1,048,576
Wrong Answer
18
2,940
192
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
S = input() import sys for i in range(0,len(S)-1): for j in range(i+1,len(S)): if S[:i] + S[j:] == 'keyence': print('Yes') sys.exit() print('No')
s493628167
Accepted
18
2,940
188
S = input() import sys for i in range(0,len(S)): for j in range(i,len(S)): if S[:i] + S[j:] == 'keyence': print('YES') sys.exit() print('NO')
s078502432
p03737
u629560745
2,000
262,144
Wrong Answer
17
2,940
86
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()) result = a[0]+b[0]+c[0] result.upper print(result)
s504845660
Accepted
17
2,940
81
a, b, c = map(str, input().split()) result = a[0]+b[0]+c[0] print(result.upper())
s940390538
p03574
u273010357
2,000
262,144
Wrong Answer
28
3,444
610
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
H,W = map(int,input().split()) S = [input() for _ in range(H)] answer = [[0 if cell == '.' else '#' for cell in row] for row in S] dxy = [(-1,1),(-1,0),(-1,-1),(0,1),(0,-1),(1,1),(1,0),(1,-1)] for i in range(H): for j in range(W): if S[i][j] != '#': continue for dx, dy in dxy: x = i + dx y = j + dy if x < 0 or x >= H: continue if y <= 0 or y >= W: continue if S[x][y] == '#': continue answer[x][y] += 1 #print(answer) for i in answer: print(*i,sep='')
s718924391
Accepted
28
3,444
609
H,W = map(int,input().split()) S = [input() for _ in range(H)] answer = [[0 if cell == '.' else '#' for cell in row] for row in S] dxy = [(-1,1),(-1,0),(-1,-1),(0,1),(0,-1),(1,1),(1,0),(1,-1)] for i in range(H): for j in range(W): if S[i][j] != '#': continue for dx, dy in dxy: x = i + dx y = j + dy if x < 0 or x >= H: continue if y < 0 or y >= W: continue if S[x][y] == '#': continue answer[x][y] += 1 #print(answer) for i in answer: print(*i,sep='')
s213170580
p02238
u424720817
1,000
131,072
Wrong Answer
20
5,604
532
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving the vertex from which $v$ was discovered. This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source. DFS timestamps each vertex as follows: * $d[v]$ records when $v$ is first discovered. * $f[v]$ records when the search finishes examining $v$’s adjacency list. Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules: * $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively. * IDs in the adjacency list are arranged in ascending order. * The program should report the discover time and the finish time for each vertex. * When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID. * The timestamp starts with 1.
n = int(input()) graph = [[0 for i in range(n)] for j in range(n)] d = [0] * n f = [0] * n g = [0] * n time = 0 for i in range(n): a = list(map(int, input().split())) for j in range(0, a[1], 1): graph[a[0] - 1][a[2 + j] - 1] = 1 def search(i): global time time = time + 1 d[i] = time g[i] = 1 for j in range(i, n): if (graph[i][j] == 1) & (g[j] == 0): search(j) time = time + 1 f[i] = time if f[i] == 0 else f[i] search(0) [print(i+1, d[i], f[i]) for i in range(n)]
s615475387
Accepted
20
5,808
550
n = int(input()) graph = [[0 for i in range(n)] for j in range(n)] d = [0] * n f = [0] * n g = [0] * n time = 0 for i in range(n): a = list(map(int, input().split())) for j in range(0, a[1], 1): graph[a[0] - 1][a[2 + j] - 1] = 1 def search(i): global time time = time + 1 d[i] = time g[i] = 1 for j in range(n): if (graph[i][j] == 1) & (g[j] == 0): search(j) time = time + 1 f[i] = time for i in range(n): if g[i] == 0: search(i) [print(i+1, d[i], f[i]) for i in range(n)]