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
s035688307
p03719
u926581302
2,000
262,144
Wrong Answer
17
2,940
87
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 B >= C >= A: print('YES') else: print('NO')
s112218991
Accepted
17
2,940
84
A,B,C =map(int,input().split()) if C>=A and C<=B: print('Yes') else: print('No')
s838334819
p03711
u905895868
2,000
262,144
Wrong Answer
25
9,028
342
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
a = map(int, input().split()) input_list = list(a) group_a = [1, 3, 5, 7, 8, 10, 12] group_b = [4, 6, 9, 11] group_c = [2] list_of_list = [group_a, group_b, group_c] count_match = 0 for list_i in list_of_list: if input_list in list_i: count_match += 1 break if count_match == 1: print('Yes') else: print('No')
s169028632
Accepted
29
9,112
348
a = map(int, input().split()) input_set = set(a) group_a = {1, 3, 5, 7, 8, 10, 12} group_b = {4, 6, 9, 11} group_c = {2} list_of_list = [group_a, group_b, group_c] count_match = 0 for set_i in list_of_list: if set_i.issuperset(input_set): count_match += 1 print('Yes') break if not count_match >= 1: print('No')
s024355364
p02237
u792145349
1,000
131,072
Wrong Answer
20
7,700
443
There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V|]$ of $|V|$ lists, one for each vertex in $V$. For each $u \in V$, the adjacency list $Adj[u]$ contains all vertices $v$ such that there is an edge $(u, v) \in E$. That is, $Adj[u]$ consists of all vertices adjacent to $u$ in $G$. An adjacency-matrix representation consists of $|V| \times |V|$ matrix $A = a_{ij}$ such that $a_{ij} = 1$ if $(i, j) \in E$, $a_{ij} = 0$ otherwise. Write a program which reads a directed graph $G$ represented by the adjacency list, and prints its adjacency-matrix representation. $G$ consists of $n\; (=|V|)$ vertices identified by their IDs $1, 2,.., n$ respectively.
# ??\??????????????? n = int(input()) data = [list(map(int,input().split())) for i in range(n)] graph_table = [[0]*n for i in range(n)] for d in data: node_id = d[0] num_of_e = d[1] for e in d[2:]: graph_table[node_id-1][e-1] = 1 print(graph_table) # ?????? for g in graph_table: print(*g)
s484239604
Accepted
60
8,560
423
# ??\??????????????? n = int(input()) data = [list(map(int,input().split())) for i in range(n)] graph_table = [[0]*n for i in range(n)] for d in data: node_id = d[0] num_of_e = d[1] for e in d[2:]: graph_table[node_id-1][e-1] = 1 # ?????? for g in graph_table: print(*g)
s666626300
p02613
u718949306
2,000
1,048,576
Wrong Answer
154
9,216
321
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) a = 0 b = 0 c = 0 d = 0 for n in range(N): s = input() if s == 'AC': a += 1 if s == 'WA': b += 1 if s == 'TLE': c += 1 if s == 'RE': d += 1 print('AC × {}'.format(a)) print('WA × {}'.format(b)) print('TLE × {}'.format(c)) print('RE × {}'.format(d))
s267625405
Accepted
152
9,208
306
N = int(input()) a = 0 b = 0 c = 0 d = 0 for n in range(N): s = input() if s == 'AC': a += 1 if s == 'WA': b += 1 if s == 'TLE': c += 1 if s == 'RE': d += 1 print('AC x ' + str(a)) print('WA x ' + str(b)) print('TLE x ' + str(c)) print('RE x ' + str(d))
s800034754
p02559
u395313349
5,000
1,048,576
Wrong Answer
4,116
76,624
661
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 p x`: a_p \gets a_p + x * `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
def lowbit(x): return x & (-x) def update(n , c ,x , y): while x <= n: c[x] += y x += lowbit(x) def query(c , x): print(len(c) , x) ans = 0 while x != 0: ans += c[x] x -= lowbit(x) return ans def main(): n , q = map(int , input().split()) a_li = list(map(int , input().split())) a_li.insert(0,0) sum_li = [0 for _ in range(n + 1)] for i in range(1 , n + 1): sum_li[i] = sum_li[i - 1] + a_li[i] c = [0 for _ in range(n + 1)] for _ in range(q): t , l , r = map(int , input().split()) if t == 1: print(query(c , r) - query(c , l) + sum_li[r] - sum_li[l]) else: update(n , c , l + 1 , r) if __name__ == '__main__': main()
s317301071
Accepted
3,794
71,476
642
def lowbit(x): return x & (-x) def update(n , c ,x , y): while x <= n: c[x] += y x += lowbit(x) def query(c , x): ans = 0 while x != 0: ans += c[x] x -= lowbit(x) return ans def main(): n , q = map(int , input().split()) a_li = list(map(int , input().split())) a_li.insert(0,0) sum_li = [0 for _ in range(n + 1)] for i in range(1 , n + 1): sum_li[i] = sum_li[i - 1] + a_li[i] c = [0 for _ in range(n + 1)] for _ in range(q): t , l , r = map(int , input().split()) if t == 1: print(query(c , r) - query(c , l) + sum_li[r] - sum_li[l]) else: update(n , c , l + 1 , r) if __name__ == '__main__': main()
s624932463
p03054
u637175065
2,000
1,048,576
Wrong Answer
774
11,428
1,731
We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a string of length N. Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: `L`, `R`, `U` and `D`. The game consists of N steps. The i-th step proceeds as follows: * First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece. * Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece. Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done. Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import random 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 list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] 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 pe(s): return print(str(s), file=sys.stderr) def main(): h,w,n = LI() sr,sc = LI() s = S() t = S() l = r = u = d = 0 for i in range(n): si = s[i] ti = t[i] if si == 'L': l += 1 if l >= sc: return 'NO' elif si == 'R': r += 1 if r+sc > w: return 'NO' elif si == 'U': u += 1 if u >= sr: return 'NO' else: d += 1 if d+sr > h: return 'NO' if ti == 'L': r -= 1 elif ti == 'R': l -= 1 elif ti == 'U': d -= 1 else: u -= 1 if r <= -sr: r = -sr + 1 if l < -(w-sr): l = -(w-sr) if u <= -sc + 1: u = -sc if d < -(h-sc): d = -(h-sc) print(l,r,u,d,sr,sc) return 'YES' print(main())
s784173623
Accepted
122
6,228
1,686
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import random 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 list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] 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 pe(s): return print(str(s), file=sys.stderr) def main(): h,w,n = LI() sc,sr = LI() s = S() t = S() ra = ri = 0 ca = ci = 0 for i in range(n-1,-1,-1): si = s[i] ti = t[i] if ti == 'L': if ra > 0: ra -= 1 elif ti == 'R': if ri > 0: ri -= 1 elif ti == 'U': if ca > 0: ca -= 1 else: if ci > 0: ci -= 1 if si == 'L': ri += 1 elif si == 'R': ra += 1 elif si == 'U': ci += 1 else: ca += 1 if ri + ra >= w: return 'NO' if ci + ca >= h: return 'NO' # print(ri,ra,'c',ci,ca,'s',sr,sc) if sr <= ri or sr + ra > w: return 'NO' if sc <= ci or sc + ca > h: return 'NO' return 'YES' print(main())
s345796147
p03730
u000513658
2,000
262,144
Wrong Answer
148
8,808
139
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A, B, C = map(int, input().split()) for i in range(10**6): if A * i % B == C: print('Yes') break else: print('No')
s221528151
Accepted
151
8,996
139
A, B, C = map(int, input().split()) for i in range(10**6): if A * i % B == C: print('YES') break else: print('NO')
s541834969
p03777
u914330401
2,000
262,144
Wrong Answer
17
2,940
115
Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest.
a, b = map(str, input().split()) if a == 'D': print(b) else: if b == 'H': print('D') else: print('H')
s848383922
Accepted
17
2,940
116
a, b = map(str, input().split()) if a == 'H': print(b) else: if b == 'D': print('H') else: print('D')
s705340654
p02401
u011632847
1,000
131,072
Wrong Answer
20
7,576
381
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while 1: a, operator, b = input().split() if operator == "+": print(int(a) + int(b)) elif operator == "-": print(int(a) - int(b)) elif operator == "*": print(int(a) * int(b)) elif operator == "/": print(int(a) / int(b)) elif operator == "?": break else: print("'" + operator + "'" + " is not a operator.")
s648992183
Accepted
30
7,692
382
while 1: a, operator, b = input().split() if operator == "+": print(int(a) + int(b)) elif operator == "-": print(int(a) - int(b)) elif operator == "*": print(int(a) * int(b)) elif operator == "/": print(int(a) // int(b)) elif operator == "?": break else: print("'" + operator + "'" + " is not a operator.")
s924623823
p03377
u578489732
2,000
262,144
Wrong Answer
17
2,940
336
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.
# -*- coding: utf-8 -*- import sys # ---------------------------------------------------------------- # Use Solve Function def solve(lines): A,B,X = map(int, lines.pop(0).split(' ')) if ( A <= X and A + B >= X ): print('YES') else: print('NO') # # main # lines = [x.strip() for x in sys.stdin.readlines()]
s153955144
Accepted
20
3,060
364
# -*- coding: utf-8 -*- import sys # ---------------------------------------------------------------- # Use Solve Function def solve(lines): A,B,X = map(int, lines.pop(0).split(' ')) if ( A <= X and A + B >= X ): print('YES') else: print('NO') # # main # lines = [x.strip() for x in sys.stdin.readlines()] # # solve !! # solve(lines)
s296728509
p03711
u994521204
2,000
262,144
Wrong Answer
17
3,060
243
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
x,y =map(int,input().split()) number=set([i+1 for i in range(12)]) a=[2] b=[4,6,9,11] c=list(set(number)-set(a)-set(b)) if x in a and y in a:print('YES') elif x in b and y in b:print('YES') elif x in c and y in c:print('YES') else:print('NO')
s773998017
Accepted
17
3,060
159
A =list(map(int,input().split())) a=[2] b=[4,6,9,11] c=[1,3,5,7,8,10,12] if set(A)<=set(a) or set(A)<=set(b) or set(A)<=set(c): print('Yes') else:print('No')
s573027187
p02388
u067299340
1,000
131,072
Wrong Answer
20
5,568
22
Write a program which calculates the cube of a given integer x.
print(int(input())^3)
s305791774
Accepted
20
5,572
23
print(int(input())**3)
s416152397
p03730
u066551652
2,000
262,144
Wrong Answer
32
9,136
334
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = map(int,input().split()) A = [] for i in range(1,b+1): mod = a*i % b if mod in A:break A.append(mod) A.sort() if len(A) >= 2: i = A[1] else: i = 0 if i == 0 and c == 0: print('Yes') exit() elif i == 0 and c != 0: print('No') exit() if c % i == 0: print('Yes') else: print('No')
s285567585
Accepted
32
9,112
181
a, b, c = map(int,input().split()) ans = 'NO' for i in range(1,b+1): mod = a*i % b if mod == 0:continue elif c % mod == 0: ans = 'YES' break print(ans)
s806947045
p02413
u662822413
1,000
131,072
Wrong Answer
20
5,604
528
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
H,W = map(int,input().split()) table = [[0]*(W+1) for i in range(H+1)] for row in range(H): work = list(map(int,input().split())) for col in range(W): table[row][col] = work[col] for row in range(H): for col in range(W): table[row][W] += table[row][col] for col in range(W): for row in range(H): table[H][col] += table[row][col] for row in range(H+1): print("%d"%(table[row][0]),end="") for col in range(1,W+1): print(" %d"%(table[row][col]),end="") print()
s745798785
Accepted
40
6,204
525
H,W = map(int,input().split()) table = [[0]*(W+1) for i in range(H+1)] for row in range(H): work = list(map(int,input().split())) for col in range(W): table[row][col] = work[col] for row in range(H): for col in range(W): table[row][W] += table[row][col] for col in range(W+1): for row in range(H): table[H][col] += table[row][col] for row in range(H+1): print("%d"%(table[row][0]),end="") for col in range(1,W+1): print(" %d"%(table[row][col]),end="") print()
s746817149
p03962
u395816772
2,000
262,144
Wrong Answer
17
2,940
139
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
a,b,c = map(list,input().split()) if a == b and b == c: print('1') elif a == b or a == c or b == c: print('2') else: print('1')
s745217097
Accepted
17
2,940
139
a,b,c = map(list,input().split()) if a == b and b == c: print('1') elif a == b or a == c or b == c: print('2') else: print('3')
s080529094
p04029
u739843002
2,000
262,144
Wrong Answer
27
9,092
48
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()) ans = N*(N-1)/2 print(int(ans))
s095699559
Accepted
26
9,064
49
N = int(input()) ans = N*(N+1)/2 print(int(ans))
s521873803
p03672
u686036872
2,000
262,144
Wrong Answer
18
3,060
201
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
list = list(str(input())) while True: list.pop(-1) print(list) if len(list)%2==0: M=len(list)//2 if list[0:M-1] == list[M:-1]: print(len(list)) break
s490102773
Accepted
17
2,940
123
S = input() for i in range(len(S)): S=S[:-1] if S[:len(S)//2] == S[len(S)//2:]: print(len(S)) break
s123053155
p02388
u138546245
1,000
131,072
Wrong Answer
30
7,496
32
Write a program which calculates the cube of a given integer x.
i = int(input()) print(str(i^3))
s183147592
Accepted
20
7,672
33
i = int(input()) print(str(i**3))
s842318144
p03610
u047197186
2,000
262,144
Wrong Answer
44
9,224
95
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input() res = '' for i, elem in enumerate(s): if i % 2 == 0: res += elem print(elem)
s419636283
Accepted
45
9,148
94
s = input() res = '' for i, elem in enumerate(s): if i % 2 == 0: res += elem print(res)
s805317360
p02612
u185042816
2,000
1,048,576
Wrong Answer
28
9,128
39
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.
price=int(input()) print(price%1000)
s744478883
Accepted
26
9,100
76
price=int(input()) ans=price%1000 if ans!=0: ans=1000-ans print(ans)
s803059106
p03080
u677393869
2,000
1,048,576
Wrong Answer
17
2,940
102
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
N=input(int()) n=input(int()) A=n.count("R") B=n.count("B") if A>B: print("Yes") else: print("No")
s564884671
Accepted
17
2,940
102
N=input(str()) n=input(str()) A=n.count("R") B=n.count("B") if A>B: print("Yes") else: print("No")
s403527823
p02261
u487861672
1,000
131,072
Wrong Answer
20
5,612
1,090
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
#! /usr/local/bin/python3 # coding: utf-8 def swap(c, i, j): t = c[i] c[i] = c[j] c[j] = t def bubble_sort(c, f): for i in range(len(c) - 1): for j in range(i + 1, len(c)): # print(i, j) if f(c[i]) > f(c[j]): swap(c, i, j) return c def selection_sort(c, f): for i in range(len(c)): minj = i for j in range(i, len(c)): if f(c[j]) < f(c[minj]): minj = j swap(c, i, minj) return c def to_group(c): b = {} for i in c: if not(i[1] in b): b[i[1]] = [i] else: b[i[1]] = b[i[1]] + [i] return b def is_stable(c, s): bc = to_group(c) bs = to_group(s(c, lambda x: x[1])) # print(bc) # print(bs) for k in bc: if bc[k] != bs[k]: return "Not stable" return "Stable" n = int(input()) c = input().split() print(" ".join(bubble_sort(c, lambda x: x[1]))) print(is_stable(c, bubble_sort)) print(" ".join(selection_sort(c, lambda x: x[1]))) print(is_stable(c, selection_sort))
s696742931
Accepted
20
5,616
1,156
#! /usr/local/bin/python3 # coding: utf-8 def swap(c, i, j): t = c[i] c[i] = c[j] c[j] = t def bubble_sort(cs, f): c = cs[:] for i in range(len(c) - 1): for j in range(len(c) - 1, i, -1): if f(c[j - 1]) > f(c[j]): swap(c, j - 1, j) # print(i, j, c) return c def selection_sort(cs, f): c = cs[:] for i in range(len(c)): minj = i for j in range(i, len(c)): if f(c[j]) < f(c[minj]): minj = j swap(c, i, minj) # print(c) return c def to_group(c): b = {} for i in c: if not(i[1] in b): b[i[1]] = [i] else: b[i[1]] = b[i[1]] + [i] return b def is_stable(c, s): bc = to_group(c) bs = to_group(s(c, lambda x: x[1])) # print(bc) # print(bs) for k in bc: if bc[k] != bs[k]: return "Not stable" return "Stable" n = int(input()) c = input().split() print(" ".join(bubble_sort(c, lambda x: x[1]))) print(is_stable(c, bubble_sort)) print(" ".join(selection_sort(c, lambda x: x[1]))) print(is_stable(c, selection_sort))
s975606255
p03472
u288948615
2,000
262,144
Wrong Answer
1,891
11,332
488
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
import math N, H = map(int, input().split()) kiri = [] nage = [] for n in range(N): tmps = list(map(int, input().split())) kiri.append(tmps[0]) nage.append(tmps[1]) kiri_max = max(kiri) nage.sort(reverse=True) count = 0 while (H > 0): if (len(nage) != 0): H -= nage[0] nage.pop(0) count += 1 else: if ( H % kiri_max): count += H // kiri_max else: count += H // kiri_max + 1 break print(count)
s542625419
Accepted
1,927
12,024
545
import math N, H = map(int, input().split()) kiri = [] nage = [] for n in range(N): tmps = list(map(int, input().split())) kiri.append(tmps[0]) nage.append(tmps[1]) kiri_max = max(kiri) nage.sort(reverse=True) nage = list(filter(lambda x: x >= kiri_max, nage)) count = 0 while (H > 0): if (len(nage) != 0): H -= nage[0] nage.pop(0) count += 1 else: if ( H % kiri_max == 0): count += H // kiri_max else: count += H // kiri_max + 1 break print(count)
s923626047
p03625
u681444474
2,000
262,144
Wrong Answer
93
14,244
344
We have N sticks with negligible thickness. The length of the i-th stick is A_i. Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
# coding: utf-8 N=int(input()) A=list(map(int,input().split())) A.sort(reverse=True) cnt=1 ans=[] for i in range(N-1): #print(cnt,ans) if A[i]==A[i+1]: cnt+=1 elif cnt>=2: ans.append(A[i-1]) cnt=1 if len(ans)==2: break #print(A) if len(ans)<=1: print(0) else: print(ans[0]*ans[1])
s944509814
Accepted
99
14,244
340
# coding: utf-8 N=int(input()) A=list(map(int,input().split())) A.sort(reverse=True) ans=[] l=0 while l<N-1: #print(cnt,ans) if A[l]==A[l+1]: ans.append(A[l]) if len(ans)==2: break else: l+=2 else: l+=1 #print(A) if len(ans)<=1: print(0) else: print(ans[0]*ans[1])
s569011200
p03478
u075303794
2,000
262,144
Wrong Answer
41
9,124
159
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
N,A,B=map(int,input().split()) ans=0 for x in range(1,N+1): temp=0 for y in str(x): temp+=int(y) if temp>=A and temp<=B: ans+=temp print(ans)
s807271524
Accepted
40
9,092
164
N,A,B=map(int,input().split()) ans=0 for x in range(1,N+1): temp=0 for y in str(x): temp+=int(y) else: if temp>=A and temp<=B: ans+=x print(ans)
s137436763
p03360
u575653048
2,000
262,144
Wrong Answer
17
2,940
90
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
a,b,c = map(int, input().split()) print(a + b + c + max(a, b, c) * (2 ^ (int(input())-1)))
s024763452
Accepted
17
2,940
91
a,b,c = map(int, input().split()) print(a + b + c + max(a, b, c) * (2 ** int(input()) - 1))
s279103706
p02612
u545417074
2,000
1,048,576
Wrong Answer
28
9,048
30
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N%1000)
s267693305
Accepted
30
9,096
103
def solve(): N = int(input()) print((1000-N%1000)%1000) if __name__ == "__main__": solve()
s895538391
p03696
u458486313
2,000
262,144
Wrong Answer
17
3,064
391
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
import sys stdin = sys.stdin ns = lambda: stdin.readline() ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) N = ni() S = ns() X = [0]*(len(S)-1) for i in range(len(S)-1): if(S[i] == '('): X[i] = 1 else: X[i] = -1 x = 0 d = [0]*(len(S)) for i in range(1, len(S)): d[i] = sum(X[0:i]) print ('('*-min(d)+S+')'*(d[len(S)-1]-min(d)))
s038848967
Accepted
17
3,064
328
import sys stdin = sys.stdin ns = lambda: stdin.readline() ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) N = ni() S = ns().strip() d = 0 mind = 0 for i in range(len(S)): if(S[i] == '('): d += 1 else: d -= 1 mind = min(mind,d) print ('('*(-mind) + S + ')'*(d-mind))
s732794995
p03471
u897329068
2,000
262,144
Wrong Answer
1,030
3,064
293
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
def loop(n,y): for s1 in range(n+1): for s2 in range(n+1): if y== s1*10000+s2*5000+(n-s1-s2)*1000: return s1,s2,n-s1-s2 else: return -1,-1,-1 def main(): n,y = map(int,input().split()) s1,s2,s3 = loop(n,y) print("{} {} {}".format(s1,s2,s3)) if __name__ == '__main__': main()
s870583545
Accepted
18
3,064
505
def solve(n, y): tmp1000 = n * 1000 if tmp1000 > y: return -1, -1, -1 diff = y - tmp1000 for y in range(diff // 4000 + 1): tmp5000 = y * 4000 if (diff - tmp5000) % 9000 == 0: x = (diff - tmp5000) // 9000 if x + y <= n: return x, y, n - x - y return -1, -1, -1 print(*solve(*map(int, input().split())))
s827489781
p03962
u396391104
2,000
262,144
Wrong Answer
17
2,940
49
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
c = [map(int,input().split())] print(len(set(c)))
s894374672
Accepted
18
2,940
54
c = list(map(int,input().split())) print(len(set(c)))
s938168274
p03485
u409064224
2,000
262,144
Wrong Answer
17
2,940
118
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b = list(map(float,input().split())) if float(a+b/2) == int(a+b/2): print(int(a+b/2)) else: print(int(a+b/2)+1)
s981552954
Accepted
18
3,060
126
a,b = list(map(float,input().split())) if float((a+b)/2) == int((a+b)/2): print(int((a+b)/2)) else: print(int((a+b)/2)+1)
s158018775
p02612
u724673021
2,000
1,048,576
Wrong Answer
28
9,136
33
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.
i = int(input()) print(i % 1000)
s542256457
Accepted
28
9,152
108
i = int(input()) if i % 1000 == 0: print(0) else: div = i / 1000 print((int(div)+1) * 1000 - i)
s765537813
p03854
u672475305
2,000
262,144
Wrong Answer
19
3,188
239
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] l = ['erase','eraser','dream','dreamer'] lst = [] for i in range(4): w = l[i] w = w[::-1] lst.append(w) for word in lst: s = s.replace(word,'') if len(s) == 0: print('Yes') else: print('No')
s557826479
Accepted
72
3,188
433
s = input()[::-1] lst = [l[::-1] for l in ['dream', 'dreamer', 'erase', 'eraser']] while len(s): flg = False if s[:5] == lst[0]: s = s[5:] flg = True elif s[:7] == lst[1]: s = s[7:] flg = True elif s[:5] == lst[2]: s = s[5:] flg = True elif s[:6] == lst[3]: s = s[6:] flg = True if flg is False: break print('YES' if len(s)==0 else 'NO')
s683214193
p02393
u248424983
1,000
131,072
Wrong Answer
30
7,316
36
Write a program which reads three integers, and prints them in ascending order.
x=input().split( ) x.sort() print(x)
s708186932
Accepted
20
7,428
65
x=input().split( ) x.sort() print(x[0] + " " + x[1] + " " + x[2])
s547548864
p02614
u531631168
1,000
1,048,576
Wrong Answer
54
9,000
440
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
h, w, k = map(int, input().split()) c = [] for _ in range(h): c.append(list(input())) def calc_black_cnt(maskR, maskC): cnt = 0 for i in range(h): for j in range(w): if maskR>>i & 1 == 0 and maskC>>j & 1 == 0 and c[i][j] == '#': cnt += 1 return cnt ans = 0 for maskR in range(1<<h): for maskC in range(1<<w): if calc_black_cnt(maskR, maskC) == k: ans += 1 ans
s922950515
Accepted
55
9,072
447
h, w, k = map(int, input().split()) c = [] for _ in range(h): c.append(list(input())) def calc_black_cnt(maskR, maskC): cnt = 0 for i in range(h): for j in range(w): if maskR>>i & 1 == 0 and maskC>>j & 1 == 0 and c[i][j] == '#': cnt += 1 return cnt ans = 0 for maskR in range(1<<h): for maskC in range(1<<w): if calc_black_cnt(maskR, maskC) == k: ans += 1 print(ans)
s936721947
p04043
u244836567
2,000
262,144
Wrong Answer
27
9,044
108
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=input().split() ls=[a,b,c] ls.sort if ls[0]==ls[1]==5 and ls[2]==7: print("YES") else: print("NO")
s573071737
Accepted
25
8,972
114
a,b,c=input().split() ls=[a,b,c] ls.sort() if ls[0]==ls[1]=="5" and ls[2]=="7": print("YES") else: print("NO")
s154650170
p03448
u281216592
2,000
262,144
Wrong Answer
40
3,060
241
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) B = int(input()) C = int(input()) X = int(input()) X_div = X%50 count = 0 for i in range(A): for j in range(B): for k in range(C): if(10*i + 5*j + k == X_div): count += 1 print(count)
s924827092
Accepted
41
3,060
252
A = int(input()) B = int(input()) C = int(input()) X = int(input()) X_div = int(X/50) count = 0 for i in range(1+A): for j in range(1+B): for k in range(1+C): if(10*i + 2*j + k == X_div): count += 1 print(count)
s034283758
p00352
u548155360
1,000
262,144
Wrong Answer
20
5,592
65
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.
# coding=utf-8 a, b = map(int, input().split()) print((a+b)/2)
s004860977
Accepted
20
5,584
66
# coding=utf-8 a, b = map(int, input().split()) print((a+b)//2)
s788539450
p03407
u993642190
2,000
262,144
Wrong Answer
18
2,940
91
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
A,B,C = [int(i) for i in input().split()] if (A+B <= C) : print("Yes") else : print("No")
s119061824
Accepted
18
2,940
91
A,B,C = [int(i) for i in input().split()] if (A+B >= C) : print("Yes") else : print("No")
s316584049
p03679
u609814378
2,000
262,144
Wrong Answer
17
2,940
161
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.
X,A,B = map(int,input().split()) if X >= (A+B): print("delicious") elif X <= ((A+B)) <= (X+1): print("safe") elif X+1 < (A+B): print("dangerous")
s092067975
Accepted
17
2,940
137
X, A, B = map(int, input().split()) if A - B >= 0: print('delicious') elif B - A <= X: print('safe') else: print('dangerous')
s922949141
p03997
u702018889
2,000
262,144
Wrong Answer
18
2,940
61
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input());b=int(input());h=int(input()) print((a+b)*h/2)
s818806524
Accepted
17
2,940
62
a=int(input());b=int(input());h=int(input()) print((a+b)*h//2)
s401695513
p02929
u218843509
2,000
1,048,576
Wrong Answer
58
3,572
256
There are 2N squares arranged from left to right. You are given a string of length 2N representing the color of each of the squares. The color of the i-th square from the left is black if the i-th character of S is `B`, and white if that character is `W`. You will perform the following operation exactly N times: choose two distinct squares, then invert the colors of these squares and the squares between them. Here, to invert the color of a square is to make it white if it is black, and vice versa. Throughout this process, you cannot choose the same square twice or more. That is, each square has to be chosen exactly once. Find the number of ways to make all the squares white at the end of the process, modulo 10^9+7. Two ways to make the squares white are considered different if and only if there exists i (1 \leq i \leq N) such that the pair of the squares chosen in the i-th operation is different.
import sys n = int(input()) s = input() if s[0] == "W": print(0) sys.exit() MOD = 10**9+7 ans = 1 cnt = 1 for i in range(n): if s[i+1] != s[i]: cnt += 1 else: ans *= cnt ans %= MOD cnt -= 1 if cnt != 0: print(0) else: print(ans)
s153079778
Accepted
128
3,572
352
import sys n = int(input()) s = input() if s[0] == "W": print(0) sys.exit() MOD = 10**9+7 ans = 1 cnt = 1 right = 1 for i in range(2*n-1): if s[i+1] == s[i]: right ^= 1 if right: cnt += 1 else: ans *= cnt ans %= MOD cnt -= 1 if cnt != 0: print(0) else: for i in range(1, n+1): ans *= i ans %= MOD print(ans)
s888800060
p03759
u757274384
2,000
262,144
Wrong Answer
17
2,940
121
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c = map(int, input().split()) A = [a,b,c] A.sort() if A[2] - A[1] == A[1] - A[0]: print("Yes") else: print("No")
s053478981
Accepted
17
2,940
122
a,b,c = map(int, input().split()) A = [a,b,c] A.sort() if A[2] - A[1] == A[1] - A[0]: print("YES") else: print("NO")
s525611423
p03860
u548303713
2,000
262,144
Wrong Answer
17
2,940
45
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() print(a+b[0].upper()+c)
s392787063
Accepted
17
2,940
41
a,b,c=input().split() print("A"+b[0]+"C")
s547221762
p00002
u480716860
1,000
131,072
Wrong Answer
20
5,592
127
Write a program which computes the digit number of sum of two integers a and b.
a,b = map(int, input().split()) sum = a + b digits = 1 while(sum//10 != 0): digits += 1 sum //= 10 print(str(digits))
s601009917
Accepted
30
5,604
291
A = [] B = [] s = True while(s): try: a,b = map(int, input().split()) except: break A.append(a) B.append(b) for i in range(len(A)): sum = A[i] + B[i] digits = 1 while(sum//10 != 0): digits += 1 sum //= 10 print(str(digits))
s740930330
p03166
u644778646
2,000
1,048,576
Wrong Answer
428
69,248
757
There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
from heapq import heappush, heappop import collections import math import heapq from collections import defaultdict import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 10 ** 9 + 7 inf = float("inf") def main(): n, m = map(int, input().split()) e = [[]for i in range(n)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 e[a].append(b) dp = [-1 for i in range(n)] def f(i): if dp[i] != -1: return dp[i] ret = 0 for v in e[i]: ret = max(ret, f(v) + 1) dp[i] = ret return dp[i] ans = 0 for i in range(n): ans = max(f(i), ans) print(ans, dp) if __name__ == '__main__': main()
s212119616
Accepted
432
67,716
753
from heapq import heappush, heappop import collections import math import heapq from collections import defaultdict import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 10 ** 9 + 7 inf = float("inf") def main(): n, m = map(int, input().split()) e = [[]for i in range(n)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 e[a].append(b) dp = [-1 for i in range(n)] def f(i): if dp[i] != -1: return dp[i] ret = 0 for v in e[i]: ret = max(ret, f(v) + 1) dp[i] = ret return dp[i] ans = 0 for i in range(n): ans = max(f(i), ans) print(ans) if __name__ == '__main__': main()
s465410110
p03448
u358791207
2,000
262,144
Wrong Answer
50
3,060
229
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for a in range(A + 1): for b in range(B + 1): for c in range(C + 1): if 500 * a + 100 * b + 50 * c == X: count += 0 print(count)
s212523710
Accepted
51
3,060
229
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for a in range(A + 1): for b in range(B + 1): for c in range(C + 1): if 500 * a + 100 * b + 50 * c == X: count += 1 print(count)
s637869740
p02600
u904217313
2,000
1,048,576
Wrong Answer
32
9,140
47
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
x = int(input()) print(f"{10 - x // 200}-kyu")
s904653012
Accepted
38
9,076
43
x = int(input()) print(f"{10 - x // 200}")
s622668476
p03997
u058592821
2,000
262,144
Wrong Answer
17
2,940
68
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s407422185
Accepted
17
2,940
69
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s634216493
p02393
u956226421
1,000
131,072
Wrong Answer
20
7,564
224
Write a program which reads three integers, and prints them in ascending order.
I = input().split() for i in[0, 1, 2]: I[i] = int(I[i]) for i in[0, 1, 2]: j = i + 1 while j <= 2: if I[i] > I[j]: w = I[i] I[i] = I[j] I[j] = w j += 1 print(I)
s931202722
Accepted
30
7,704
268
I = input().split() for i in[0, 1, 2]: I[i] = int(I[i]) for i in[0, 1, 2]: j = i + 1 while j <= 2: if I[i] > I[j]: w = I[i] I[i] = I[j] I[j] = w j += 1 print(str(I[0]) + ' ' + str(I[1]) + ' ' + str(I[2]))
s953198499
p03197
u690536347
2,000
1,048,576
Wrong Answer
173
7,072
93
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()) l = [int(input()) for _ in range(N)] print("Second" if (N-2)%2 else "First")
s252633416
Accepted
188
7,072
114
N = int(input()) l = [int(input()) for _ in range(N)] print("second" if all(map(lambda x:x%2==0, l)) else "first")
s201537205
p02612
u986068997
2,000
1,048,576
Wrong Answer
26
9,064
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
a=int(input()) print(a%1000)
s499353480
Accepted
26
8,992
82
N = int(input()) tmp = N % 1000 if tmp : print(1000 - tmp) else : print(0)
s995715593
p04035
u459798349
2,000
262,144
Wrong Answer
68
14,060
177
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
n,l=map(int,input().split()) A=[int(i) for i in input().split()] wa=[A[i]+A[i+1] for i in range(n-1)] lim=max(wa) if l<lim: print("Possible") else: print("Impossible")
s478530335
Accepted
142
14,076
353
n,l=map(int,input().split()) A=[int(i) for i in input().split()] wa=[A[i]+A[i+1] for i in range(n-1)] lim=max(wa) knot=wa.index(lim) go=False if l<=lim: print("Possible") go=True else: print("Impossible") if go: for i in range(knot): print(i+1) for i in range(n-knot-2): print(n-i-1) print(knot+1)
s103673024
p03469
u896741788
2,000
262,144
Wrong Answer
17
3,064
35
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
s=input() print("2018".join(s[4:]))
s315583422
Accepted
17
2,940
29
s=input() print("2018"+s[4:])
s829572332
p04011
u434282696
2,000
262,144
Wrong Answer
18
2,940
102
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.
n=int(input()) k=int(input()) x=int(input()) y=int(input()) if k<=n:print(x*k) else:print(x*k+(n-k)*y)
s518179771
Accepted
19
2,940
102
n=int(input()) k=int(input()) x=int(input()) y=int(input()) if n<=k:print(x*n) else:print(x*k+(n-k)*y)
s717366959
p04030
u417874416
2,000
262,144
Wrong Answer
37
3,064
221
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
ret = "" s = input().strip() s = list(str(s)) print(s) for c in s: if c == "0": ret = ret + "0" elif c == "1": ret = ret + "1" else: if ret != "": ret = ret[:-1] print(ret)
s453798836
Accepted
42
3,064
222
ret = "" s = input().strip() s = list(str(s)) #print(s) for c in s: if c == "0": ret = ret + "0" elif c == "1": ret = ret + "1" else: if ret != "": ret = ret[:-1] print(ret)
s207907184
p03711
u468972478
2,000
262,144
Wrong Answer
29
9,080
159
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
n1 = [1, 3, 5, 7, 8, 10, 12] n2 = [4, 6, 9, 11] n3 = [2] nums = [map(int, input().split())] print("Yes" if nums in n1 or nums in n2 or nums in n3 else "No")
s321932348
Accepted
27
9,152
153
n1 = [1, 3, 5, 7, 8, 10, 12] n2 = [4, 6, 9, 11] a, b = map(int, input().split()) print("Yes" if a in n1 and b in n1 or a in n2 and b in n2 else "No")
s930069777
p03862
u057586044
2,000
262,144
Wrong Answer
101
14,068
207
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
N,x=map(int,input().split()) S = [int(i) for i in input().split()] pre,ans = 0,0 for i in range(N): tmp = pre+S[i] if tmp > x: ans += tmp-x S[i] -= tmp-x pre = S[i] print(ans)
s231818298
Accepted
99
14,540
200
N,x=map(int,input().split()) S = list(map(int,input().split())) pre,ans = 0,0 for i in range(N): tmp = pre+S[i] if tmp > x: ans += tmp-x S[i] -= tmp-x pre = S[i] print(ans)
s198774850
p03474
u556589653
2,000
262,144
Wrong Answer
17
3,060
242
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
A,B = map(int,input().split()) S = input() ans = 0 ls = ["1","2","3","4","5","6","7","8","9","0"] if S[A] == "-": for i in range(A+B+1): if S[i] in ls: ans += 1 if ans == (A+B+1): print("Yes") else: print("No")
s960366520
Accepted
18
3,064
257
a,b = map(int,input().split()) S = input() flag = 0 if S[a] != "-": flag += 1 for i in range(0,a): if S[i]== "-": flag += 1 for i in range(a+1,a+b+1): if S[i] == "-": flag += 1 if flag == 0: print("Yes") else: print("No")
s358233112
p03359
u470735879
2,000
262,144
Wrong Answer
17
2,940
78
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a, b = map(int, input().split()) if a < b: print(a) else: print(a - 1)
s525480411
Accepted
17
2,940
79
a, b = map(int, input().split()) if a <= b: print(a) else: print(a - 1)
s593307678
p02645
u605880635
2,000
1,048,576
Wrong Answer
21
9,020
25
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
a = input() print(a[1:4])
s609439600
Accepted
22
8,952
25
a = input() print(a[0:3])
s798779073
p03044
u383713431
2,000
1,048,576
Wrong Answer
376
43,324
953
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
import sys sys.setrecursionlimit(10**8) N = int(input()) graph = [[] for _ in range(N)] for i in range(1, N): u, v, w = map(int, input().split()) graph[u-1].append((v-1, w)) graph[v-1].append((u-1, w)) color = [0 for _ in range(N)] color[0] = 1 def dfs(prev:int, now:int): res = True for adj in graph[now]: v, dist = adj if prev == v: continue if dist % 2 == 0 and color[v] != color[now]: return False if dist % 2 != 0 and color[v] == color[now]: return False if dist % 2 == 0 and color[v] == color[now]: return True if dist % 2 != 0 and color[v] != color[now]: return True if dist % 2 == 0 and color[v] == 0: color[v] = color[now] elif dist % 2 == 1 and color[v] == 0: color[v] = -1 * color[now] res &= dfs(now, v) return res return True print(*color)
s848594458
Accepted
498
84,512
651
import sys sys.setrecursionlimit(10**8) N = int(input()) graph = [[] for _ in range(N)] for i in range(1, N): u, v, w = map(int, input().split()) graph[u-1].append((v-1, w)) graph[v-1].append((u-1, w)) color = [0 for _ in range(N)] visited = [False for _ in range(N)] def dfs(now): for adj in graph[now]: v, dist = adj if visited[v]: continue visited[v] = True color[v] = color[now] + dist dfs(v) return for start in range(N): if not visited[start]: color[start] = 0 visited[start] = True dfs(start) for i in range(N): print(color[i] % 2)
s660615740
p03623
u318073603
2,000
262,144
Wrong Answer
17
2,940
322
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b = map(int,input().split()) a_distant = a - x b_distant = b - x if a_distant > b_distant: print("B") if b_distant > a_distant: print("A") else: print("false")
s472073425
Accepted
17
3,060
388
import math x,a,b = map(int,input().split()) a_distant = a - x b_distant = b - x if a_distant < 0: a_distant = a_distant*(-1) if b_distant < 0: b_distant = b_distant*(-1) if a_distant > b_distant: print("B") else: print("A")
s558766878
p02613
u244434589
2,000
1,048,576
Wrong Answer
147
9,128
293
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N=int(input()) w =0 x =0 y =0 z =0 for i in range(N): s =input() if s =='AC': w +=1 elif s == 'WA': x +=1 elif s == 'TLE': y +=1 elif s == 'RE': z +=1 print ('AC×'+str(w)) print ('WA×'+str(x)) print ('TLe×'+str(y)) print ('RE×'+str(z))
s362101152
Accepted
150
9,128
297
N=int(input()) w =0 x =0 y =0 z =0 for i in range(N): s =input() if s =='AC': w +=1 elif s == 'WA': x +=1 elif s == 'TLE': y +=1 elif s == 'RE': z +=1 print ('AC x '+str(w)) print ('WA x '+str(x)) print ('TLE x '+str(y)) print ('RE x '+str(z))
s365346312
p02842
u368270116
2,000
1,048,576
Wrong Answer
18
3,060
75
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
n=int(input()) x=n/1.08 xx=x*10 if xx%10==0: print(x) else: print(":(")
s550854452
Accepted
28
9,112
116
import math n=int(input()) xc=math.ceil(n/1.08) nn=xc*1.08 if math.floor(nn)==n: print(xc) else: print(":(")
s037905675
p02255
u841945203
1,000
131,072
Wrong Answer
20
5,592
274
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
def insertionSort(A,N): for i in range(0,N): v = A[i] j = i -1 while j>=0 and A[j] > v : A[j+1] = A[j] j-=1 A[j+1] = v print(A) N = int(input()) A = input().split() A = list(map(int,A)) insertionSort(A,N)
s921945271
Accepted
30
5,992
387
def output_A(A): if len(A) == 1: print(A[0]) else: for i in range(len(A)-1): print(f'{A[i]} ',end="") print(f'{A[i+1]}',) N = int(input()) A = list(map(int,input().split())) output_A(A) for i in range(1,len(A)): key = A[i] j = i-1 while j>=0 and A[j] > key : A[j+1] = A[j] j -= 1 A[j+1] = key output_A(A)
s924152321
p03067
u522266410
2,000
1,048,576
Wrong Answer
17
2,940
109
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a = list(map(int, input().split())) if a[1]==max(a) or a[1] == min(a): print('No') else: print('Yes')
s264063088
Accepted
17
2,940
109
a = list(map(int, input().split())) if a[2]==max(a) or a[2] == min(a): print('No') else: print('Yes')
s007321884
p03448
u813569174
2,000
262,144
Wrong Answer
54
3,060
211
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) B = int(input()) C = int(input()) X = int(input()) p = 0 for i in range(A): for j in range(B): for k in range(C): if 500*(i+1) + 100*(j+1) + 50*(k+1) == X: p = p + 1 print(p)
s305356480
Accepted
50
3,060
211
A = int(input()) B = int(input()) C = int(input()) X = int(input()) p = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if 500*(i) + 100*(j) + 50*(k) == X: p = p + 1 print(p)
s789576023
p03477
u830842621
2,000
262,144
Wrong Answer
18
2,940
104
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d = input().split() print("Left" if a + b > c + d else ("Right" if a + b < c + d else "Balanced"))
s525983634
Accepted
18
3,064
114
a,b,c,d = map(int, input().split()) print("Left" if a + b > c + d else ("Right" if a + b < c + d else "Balanced"))
s729622675
p02397
u775586391
1,000
131,072
Wrong Answer
40
7,700
148
Write a program which reads two integers x and y, and prints them in ascending order.
l = [] while True: s = [str(i) for i in input().split()] if s == ['0','0']: break else: l.append(s[0]+' '+s[1]) for i in l: print(i)
s137890211
Accepted
40
7,920
167
l = [] while True: s = [int(i) for i in input().split()] if s == [0,0]: break else: s.sort() l.append(str(s[0])+' '+str(s[1])) for i in l: print(i)
s500874857
p04029
u453642820
2,000
262,144
Wrong Answer
17
2,940
31
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n=int(input()) print(n*(n+1)/2)
s340932203
Accepted
17
2,940
32
n=int(input()) print(n*(n+1)//2)
s800479933
p03611
u987164499
2,000
262,144
Wrong Answer
54
13,960
308
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
from sys import stdin import bisect from math import factorial n = int(stdin.readline().rstrip()) li = list(map(int,stdin.readline().rstrip().split())) point = 0 for i in range(n-1): if li[i]-1 == i: li[i],li[i+1] = li[i+1],li[i] point += 1 if li[-1] == n: point += 1 print(point)
s814190486
Accepted
82
13,964
245
n = int(input()) a = list(map(int,input().split())) point = [0]*(10**5+2) for i in a: if i == 1: point[1] += 1 point[2] += 1 else: point[i] += 1 point[i-1] += 1 point[i+1] += 1 print(max(point))
s356382943
p02608
u930574673
2,000
1,048,576
Wrong Answer
454
9,896
202
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).
N = int(input()) ans = [0] * 100000 for x in range(1, 100): for y in range(1, 100): for z in range(1, 100): ans[x*x+y*y+z*z+x*y+y*z+z*x] += 1 for i in range(N): print(ans[i])
s059802149
Accepted
449
9,856
204
N = int(input()) ans = [0] * 100000 for x in range(1, 100): for y in range(1, 100): for z in range(1, 100): ans[x*x+y*y+z*z+x*y+y*z+z*x-1] += 1 for i in range(N): print(ans[i])
s073591531
p03545
u419686324
2,000
262,144
Wrong Answer
28
3,804
510
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
s = [int(x) for x in input()] import functools @functools.lru_cache(maxsize=None) def f(c, n): print("c ", c, n) if n == 4: if c == 7: return [] else: return None v = s[n] for o in ['+', '-']: print("f ", ''.join([str(x) for x in [c, o, v]]), eval('%d%s%d'% (c,o,v)), n + 1) ret = f(eval('%d%s%d'% (c,o,v)), n + 1) if ret is not None: return [o, v] + ret print(''.join([str(x) for x in ([s[0]] + f(s[0], 1))]) + '=7')
s668294193
Accepted
18
3,060
227
abcd = input() for i in range(1 << 4): exp = '' for j in range(3): op = '+' if i & (1 << j) else '-' exp += abcd[j] + op exp += abcd[3] if eval(exp) == 7: print(exp + '=7') break
s583253486
p02396
u865138391
1,000
131,072
Wrong Answer
130
7,476
107
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
for i in range(10000): x = input() if x == "0": break print("Case {}: {}".format(i, x))
s888816597
Accepted
130
7,304
109
for i in range(1,10001): x = input() if x == "0": break print("Case {}: {}".format(i, x))
s267353526
p02600
u340585574
2,000
1,048,576
Wrong Answer
28
9,144
85
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
x=int(input()) for i in range(8): if(400+i*200)<=x: y=8-i print(y,'級')
s463229252
Accepted
28
9,148
78
x=int(input()) for i in range(8): if(400+i*200)<=x: y=8-i print(y)
s120828076
p02665
u829249049
2,000
1,048,576
Wrong Answer
946
674,392
324
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
import sys N=int(input()) A=list(map(int,input().split())) if A[0]>=1: print(-1) sys.exit() ans=A[N] left=1 P=[1 for i in range(N+1)] for i in range(1,N+1): point=left*2 P[i]=point if point-A[i]<1: print(-1) sys.exit() left=point-A[i] for i in range(N,0,-1): ans+=min(P[i-1],A[i]+A[i-1]) print(ans)
s543227428
Accepted
968
674,268
375
import sys N=int(input()) A=list(map(int,input().split())) if A[0]>=2: print(-1) sys.exit() if A[0]==1: left=0 else: left=1 ans=A[N] P=[1 for i in range(N+1)] for i in range(1,N+1): point=left*2 P[i]=point if point-A[i]<0: print(-1) sys.exit() left=point-A[i] root=A[N] for i in range(N,0,-1): root=min(P[i-1],root+A[i-1]) ans+=root print(ans)
s824496958
p03567
u511379665
2,000
262,144
Wrong Answer
17
3,064
137
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
s=input() for i in range(0,len(s)-1): if s[i]=="A" and s[i+1]=="C": print("Yes") exit() else: print("No")
s559722376
Accepted
17
2,940
120
s=input() for i in range(0,len(s)-1): if s[i]=="A" and s[i+1]=="C": print("Yes") exit() print("No")
s546623662
p03543
u897328029
2,000
262,144
Wrong Answer
17
2,940
201
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
n = input() count = 0 for i, char in enumerate(n): if i == 0: continue if n[i-1] == char: count += 1 else: count = 0 ans = 'Yes' if count >= 3 else 'No' print(ans)
s791997191
Accepted
17
2,940
256
n = input() count = 1 max_c = - float('inf') for i, char in enumerate(n): if i == 0: continue if n[i-1] == char: count += 1 else: count = 1 max_c = max(max_c, count) ans = 'Yes' if max_c >= 3 else 'No' print(ans)
s181641314
p04044
u205042576
2,000
262,144
Wrong Answer
25
9,124
122
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
N, L = map(int, input().split()) s = [] for i in range(N): s.append(input()) s.sort() print(s) print(''.join(s))
s881278906
Accepted
29
9,112
111
N, L = map(int, input().split()) s = [] for i in range(N): s.append(input()) s.sort() print(''.join(s))
s651949515
p03409
u869919400
2,000
262,144
Wrong Answer
19
3,064
500
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
N = int(input()) reds = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1]) blues = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0]) ans = 0 for bx, by in blues: for rx, ry in reds: if rx < bx and ry < by: ans += 1 print((rx, ry), (bx, by)) reds.remove((rx, ry)) break print(ans)
s602200022
Accepted
19
3,064
462
N = int(input()) reds = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1]) blues = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0]) ans = 0 for bx, by in blues: for rx, ry in reds: if rx < bx and ry < by: ans += 1 reds.remove((rx, ry)) break print(ans)
s816238660
p02364
u825008385
1,000
131,072
Wrong Answer
20
5,596
820
Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E).
# Sliding Minimum Elements INF = 2**31 - 1 [n, l] = list(map(int, input().split())) data = list(map(int, input().split())) def initRMQ(tree): global n size = 1 while size < l: size *= 2 i = 1 while i <= 2*size - 1 - 1: tree.append(INF) i += 1 n = size return tree def update(k, a, temp): k += n - 1 temp[k:k+l] = a for i in range(k, k+l, 2): while i > 0: i = int((i - 1)/2) temp[i] = min(temp[i*2 + 1], temp[i*2 + 2]) index = 0 array = initRMQ([INF]) while (len(data) - index - l) >= 0: #temp = list(array) #update(0, data[index:index+l], temp) temp = data[index:index+l] temp.sort() index += 1 if (len(data) - index - l) < 0: print(temp[0]) else: print(temp[0], "", end="")
s762735007
Accepted
1,740
25,276
872
p = [] rank = [] edge = [] cost = 0 def makeSet(x): global p, rank p.append(x) rank.append(0) def findSet(x): global p if x != p[x]: p[x] = findSet(p[x]) return p[x] def link(x, y): global p, rank if rank[x] > rank[y]: p[y] = x else: p[x] = y if rank[x] == rank[y]: rank[y] += 1 def union(x, y): link(findSet(x), findSet(y)) def same(x, y): if findSet(x) == findSet(y): return 1 else: return 0 [v, e] = list(map(int, input().split())) for i in range(v): makeSet(i) for i in range(e): [s, t, w] = list(map(int, input().split())) edge.append([w, s, t]) edge.sort() while v > 1: min = edge.pop(0) if not same(min[1], min[2]): union(min[1], min[2]) cost += min[0] v -= 1 print(cost)
s862598757
p03409
u046187684
2,000
262,144
Wrong Answer
1,208
21,128
774
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import numpy as np n = int(input().strip()) ab = [list(map(int, input().strip().split(" "))) for _ in range(n)] cd = [list(map(int, input().strip().split(" "))) for _ in range(n)] ab = sorted(ab, key=lambda x: x[1]) ab = sorted(ab, key=lambda x: x[0]) cd = sorted(cd, key=lambda x: x[1]) cd = sorted(cd, key=lambda x: x[0]) mat = [[0 for _ in range(n)] for _ in range(n)] for i, _ab in enumerate(ab): for j, _cd in enumerate(cd): if _ab[0] < _cd[0] and _ab[1] < _cd[1]: mat[i][j] = 1 mat = sorted(mat, key=lambda x: sum(x)) mat = np.array(mat) print(mat) ind = set([]) for _mat in mat: iii = np.where(_mat > 0)[0] for _i in iii: if _i not in ind: ind.add(_i) print(len(ind))
s689859889
Accepted
18
3,064
695
def solve(string): n, *abcd = map(int, string.split()) abcd = [(ac, bd) for ac, bd in zip(abcd[::2], abcd[1::2])] ab = abcd[:n] candidate = [] ans = 0 ps = sorted(abcd, key=lambda x: x[0]) for p in ps: if p in ab: candidate.append(p) candidate = sorted(candidate, key=lambda x: x[1], reverse=True) else: for i, _p in enumerate(candidate): if _p[1] < p[1]: ans += 1 candidate.pop(i) break return str(ans) if __name__ == '__main__': n = int(input()) print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))
s077873763
p02927
u223904637
2,000
1,048,576
Wrong Answer
18
2,940
194
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()) ans=0 if d<10: print(0) else: for i in range(10,d+1): for j in range(1,m+1): if (i%10)*(i//10)==j: ans+=1 print(ans)
s546438901
Accepted
19
2,940
221
m,d=map(int,input().split()) ans=0 if d<10: print(0) else: for i in range(10,d+1): for j in range(1,m+1): if (i%10)*(i//10)==j and i%10>=2 and (i//10)>1: ans+=1 print(ans)
s391579770
p00026
u766477342
1,000
131,072
Wrong Answer
30
7,720
885
As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by (x, y) coordinate system. We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and Small. From the point of fall, the ink sinks into surrounding cells as shown in the figure depending on its size. In the figure, a star denotes the point of fall and a circle denotes the surrounding cells. Originally, the paper is white that means for each cell the value of density is 0. The value of density is increased by 1 when the ink sinks into the corresponding cells. For example, if we put a drop of Small ink at (1, 2) and a drop of Medium ink at (3, 2), the ink will sink as shown in the following figure (left side): In the figure, density values of empty cells are 0. The ink sinking into out of the paper should be ignored as shown in the figure (top side). We can put several drops of ink at the same point. Your task is to write a program which reads a sequence of points of fall (x, y) with its size (Small = 1, Medium = 2, Large = 3), and prints the number of cells whose density value is 0. The program must also print the maximum value of density. You may assume that the paper always consists of 10 × 10, and 0 ≤ x < 10, 0 ≤ y < 10\.
d = [[0] * 10 for i in range(10)] def b(x, y): for i in range(x - 2, x + 3): a = 3 - abs(x - i) for a in range(y - a + 1, y + a): if 0 <= i < 10 and 0 <= a < 10: d[a][i] += 1 def m(x, y): for i in range(x - 1, x + 2): for j in range(y - 1, y + 2): if 0 <= i < 10 and 0 <= j < 10: d[j][i] += 1 def s(x, y): r = (1, 0) for i in range(x - 1, x + 2): a = abs(x - i) for j in range(y - r[a], y + r[a] + 1): if 0 <= i < 10 and 0 <= j < 10: d[j][i] += 1 while 1: try: f = (None, s, m, b) x, y, size = list(map(int, input().split(','))) f[size](x, y) except: break r1 = r2 = 0 for i in range(10): for j in range(10): r1 += 1 if d[i][j] == 0 else 0 r2 = max(r2, d[i][j]) print(r1, r2)
s594056350
Accepted
30
7,664
890
d = [[0] * 10 for i in range(10)] def b(x, y): for i in range(x - 2, x + 3): a = 3 - abs(x - i) for a in range(y - a + 1, y + a): if 0 <= i < 10 and 0 <= a < 10: d[a][i] += 1 def m(x, y): for i in range(x - 1, x + 2): for j in range(y - 1, y + 2): if 0 <= i < 10 and 0 <= j < 10: d[j][i] += 1 def s(x, y): r = (1, 0) for i in range(x - 1, x + 2): a = abs(x - i) for j in range(y - r[a], y + r[a] + 1): if 0 <= i < 10 and 0 <= j < 10: d[j][i] += 1 while 1: try: f = (None, s, m, b) x, y, size = list(map(int, input().split(','))) f[size](x, y) except: break r1 = r2 = 0 for i in range(10): for j in range(10): r1 += 1 if d[i][j] == 0 else 0 r2 = max(r2, d[i][j]) print(r1) print(r2)
s032369338
p04013
u844789719
2,000
262,144
Wrong Answer
18
3,064
753
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
N, A = [int(_) for _ in input().split()] X = [int(_) - A for _ in input().split()] X_plus = [_ for _ in X if _ > 0] X_minus = [-_ for _ in X if _ < 0] l_plus = len(X_plus) l_minus = len(X_minus) l_zero = len(X) - l_plus - l_minus s_plus = sum(X_plus) s_minus = sum(X_minus) dp_plus = [0] * (l_plus + 1) dp_minus = [0] * (l_minus + 1) for i in range(l_plus): dp_plus_old = dp_plus.copy() for j in range(l_plus + 1 - X_plus[i]): dp_plus[j + X_plus[i]] += dp_plus_old[j] for i in range(l_minus): dp_minus_old = dp_minus.copy() for j in range(l_minus + 1 - X_minus[i]): dp_minus[j + X_minus[i]] += dp_minus_old[j] ans = 2 ** l_zero - 1 for j in range(min(l_plus, l_minus) + 1): ans += dp_plus[j] * dp_minus[j] print(ans)
s280263124
Accepted
88
11,224
507
import collections N, A = [int(_) for _ in input().split()] X = [int(_) for _ in input().split()] def calc(W): M = len(W) dp = [collections.defaultdict(int) for _ in range(M + 1)] dp[0][0] = 1 for i, w in enumerate(W): for j in range(i, -1, -1): for k, v in dp[j].items(): dp[j + 1][k + w] += v return dp dpx = calc(X) print(sum(dpx[i][i * A] for i in range(1, N + 1)))
s839915173
p03697
u131264627
2,000
262,144
Wrong Answer
17
2,940
87
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
a, b = map(int, input().split()) if a + b < 9: print(a + b) else: print('error')
s150272497
Accepted
18
2,940
93
a, b = map(int, input().split()) if a + b < 10: print(int(a + b)) else: print('error')
s214735913
p03567
u077291787
2,000
262,144
Wrong Answer
17
2,940
153
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
def main(): s = input() print("YES" if "AC" in s else "NO") if __name__ == "__main__": main()
s088190647
Accepted
17
2,940
154
def main(): s = input() print("Yes" if "AC" in s else "No") if __name__ == "__main__": main()
s033270659
p02612
u382639013
2,000
1,048,576
Wrong Answer
33
9,148
69
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) if N%1000 ==0: print(0) else: print(N%1000)
s643017798
Accepted
28
9,148
77
N = int(input()) if N%1000 == 0: print(0) else: print(1000 - N%1000)
s033234506
p02613
u203383537
2,000
1,048,576
Wrong Answer
150
9,180
300
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) l = [0]*4 w = ["AC","WA","TLE","RE"] for i in range(n): s = input() if s == "AC": l[0] += 1 elif s == "WA": l[1] += 1 elif s == "TLE": l[2] += 1 else: l[3] +=1 for i in range(4): print(w[i] + " × " + str(l[i]))
s254403177
Accepted
149
9,144
294
n = int(input()) l = [0]*4 w = ["AC","WA","TLE","RE"] for i in range(n): s = input() if s == "AC": l[0] += 1 elif s == "WA": l[1] += 1 elif s == "TLE": l[2] += 1 else: l[3] +=1 for i in range(4): print(w[i] + " x " + str(l[i]))
s792577469
p03024
u945181840
2,000
1,048,576
Wrong Answer
17
2,940
74
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S = input() if S.count('o') >= 8: print('YES') else: print('NO')
s496251012
Accepted
17
2,940
93
S = input() r = 15 - len(S) if S.count('o') + r >= 8: print('YES') else: print('NO')
s287841328
p03090
u373529207
2,000
1,048,576
Wrong Answer
24
3,612
179
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
N = int(input()) if N % 2 == 0: S = 1 + N else: S = N for i in range(1, N+1): for j in range(i+1, N+1): if i+j == S: continue print(i, j)
s659006241
Accepted
25
4,124
247
N = int(input()) if N % 2 == 0: S = 1 + N else: S = N ans = [] for i in range(1, N+1): for j in range(i+1, N+1): if i+j == S: continue ans.append([i, j]) print(len(ans)) for p in ans: print(p[0], p[1])
s837129023
p03359
u769411997
2,000
262,144
Wrong Answer
17
2,940
77
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a, b = map(int, input().split()) if a < b: print(a) else: print(a-1)
s382238828
Accepted
17
2,940
78
a, b = map(int, input().split()) if a <= b: print(a) else: print(a-1)
s032450805
p03434
u939790872
2,000
262,144
Wrong Answer
28
9,180
213
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
N = int(input()) A = list(map(int, input().split())) alice = 0 bob = 0 A.sort(reverse=True) print(A) for i in range(N): if i%2 == 0: alice += A.pop(0) else: bob += A.pop(0) print(alice-bob)
s197147896
Accepted
27
9,068
204
N = int(input()) A = list(map(int, input().split())) alice = 0 bob = 0 A.sort(reverse=True) for i in range(N): if i%2 == 0: alice += A.pop(0) else: bob += A.pop(0) print(alice-bob)
s148708607
p03387
u602713757
2,000
262,144
Wrong Answer
18
3,064
202
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
A, B, C = map(int, input().split()) D = sorted([A,B,C]) count = int((D[2] - D[0])/2) + int((D[2] - D[0])/2) if (D[2] - D[0])%2 + (D[2] - D[0])%2 == 2: count += 1 else: count += 2 print(count)
s127514254
Accepted
17
3,060
217
A, B, C = map(int, input().split()) D = sorted([A,B,C]) count = int((D[2] - D[0])/2) + int((D[2] - D[1])/2) E = (D[2] - D[0])%2 + (D[2] - D[1])%2 if E == 2: count += 1 elif E == 1: count += 2 print(count)
s027444532
p02534
u976887940
2,000
1,048,576
Wrong Answer
21
9,092
70
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`.
K=int(input()) K+=1 o='' a='ALC' for i in range(1,K): o=o+a print(o)
s023921588
Accepted
22
9,096
109
k=int(input()) k+=1 o='' a='ACL' if k==1: print('') exit() else: for i in range(1,k): o=o+a print(o)
s291464004
p02663
u760107660
2,000
1,048,576
Wrong Answer
22
9,080
76
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
T = input() trade = T.replace('?','D') print(trade)
s646674540
Accepted
25
9,436
249
import datetime H1,M1,H2,M2,K = map(int,input().split()) wakeup = datetime.datetime(2020,5,30,H1,M1,0) sleep = datetime.datetime(2020,5,30,H2,M2,0) active = sleep - wakeup delta = int((active.seconds)/60) ans = delta - K print(ans)
s138520829
p03386
u779170803
2,000
262,144
Wrong Answer
2,231
3,956
510
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.
INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): a,b,c=INTM() abl=b-a+1 ablist=[i for i in range(a,b+1)] #print(ablist) ansa=ablist[0:min(c,abl)] ansb=ablist[max(0,abl-c):abl] #print(ansa,ansb) ans=set(ansa) | set(ansb) for i in ans: print(i) if __name__ == '__main__': do()
s349048747
Accepted
17
3,064
528
INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): a,b,c=INTM() ans=[] for i in range(c): ai=a+i bi=b-i if a<=ai and ai<=b: ans.append(ai) if a<=bi and bi<=b: ans.append(bi) ans=sorted(set(ans)) for i in ans: print(i) if __name__ == '__main__': do()
s641524363
p02742
u128196936
2,000
1,048,576
Wrong Answer
30
9,028
50
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
A, B = map(int, input().split()) print(round(A/B))
s395295447
Accepted
26
9,076
125
A, B = map(int, input().split()) if A == 1 or B == 1: print(1) elif (A*B) % 2 == 0: print(A*B//2) else: print(A*B//2+1)
s397161290
p02401
u732614538
1,000
131,072
Wrong Answer
30
7,268
90
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: try: print(eval(input())) except Exception as e: break
s794577041
Accepted
30
7,332
95
while True: try: print(int(eval(input()))) except Exception as e: break