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
s918348827
p03353
u280016524
2,000
1,048,576
Wrong Answer
35
4,932
291
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
s=input() K=int(input()) listA=[] for j in range(1,K+1): for i in range(len(s)): listA.append(s[i:i+j]) listA.sort() x="" count=0 for i in range(len(listA)): if(x!=listA[i]): count+=1 x=listA[i] if(count==K): print(x) break; print(listA)
s159611484
Accepted
34
4,340
278
s=input() K=int(input()) listA=[] for j in range(1,K+1): for i in range(len(s)): listA.append(s[i:i+j]) listA.sort() x="" count=0 for i in range(len(listA)): if(x!=listA[i]): count+=1 x=listA[i] if(count==K): print(x) break;
s386640168
p02432
u629874472
2,000
262,144
Wrong Answer
20
5,596
343
For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print element $a_p$. * pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state.
cnt = int(input()) a = [] for i in range(cnt): li = list(map(int,input().split())) if li[0] == 0: if li[1] == 0: a.insert(0,li[2]) else: a.insert(-1,li[2]) if li[0] == 1: print(a[li[1]]) if li[0] ==2: if li[1]==0: a.pop(0) else: a.pop(-1)
s854391807
Accepted
1,700
21,984
379
from collections import deque cnt = int(input()) a = deque() for i in range(cnt): li = list(map(int,input().split())) if li[0] == 0: if li[1] == 0: a.appendleft(li[2]) else: a.append(li[2]) if li[0] == 1: print(a[li[1]]) if li[0] ==2: if li[1]==0: a.popleft() else: a.pop()
s912106749
p04012
u006425112
2,000
262,144
Wrong Answer
17
3,060
168
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.
w = input() flag = True for i in range(len(w)): if w[i] != "a" and w[i] != "z": flag = False break if flag: print("Yes") else: print("No")
s127590940
Accepted
20
3,316
197
from collections import Counter w = input() c = Counter(w) flag = True for i in c.values(): if i % 2 == 1: flag = False break if flag: print("Yes") else: print("No")
s496684059
p03846
u652150585
2,000
262,144
Wrong Answer
106
16,096
704
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
import collections n=int(input()) l=list(map(int,input().split())) s=collections.Counter(l) s=s.most_common() print(s) a=1 if n%2==0: for i in s: if i[1]!=2: print(0) exit() elif i[0]%2!=1 or i[1]//2>n//2: print(0) exit() else: for j in range(n//2): a=(2*a)%1000000007 print(a) elif n%2==1: if (0,1) not in s: print(0) exit() else: del s[-1] print(s) for i in s: if i[1]!=2 or i[0]%2!=0 or i[0]//2>n//2: print(0) exit() else: for j in range(n//2): a=(2*a)%1000000007 print(a)
s553212885
Accepted
89
16,096
706
import collections n=int(input()) l=list(map(int,input().split())) s=collections.Counter(l) s=s.most_common() #print(s) a=1 if n%2==0: for i in s: if i[1]!=2: print(0) exit() elif i[0]%2!=1 or i[1]//2>n//2: print(0) exit() else: for j in range(n//2): a=(2*a)%1000000007 print(a) elif n%2==1: if (0,1) not in s: print(0) exit() else: del s[-1] #print(s) for i in s: if i[1]!=2 or i[0]%2!=0 or i[0]//2>n//2: print(0) exit() else: for j in range(n//2): a=(2*a)%1000000007 print(a)
s612293257
p02413
u138628845
1,000
131,072
Wrong Answer
20
5,592
364
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.
all_ele = [] sum_ele = [] h,w = [int(x) for x in input().split()] for ele in range(h): all_ele.append([int(x) for x in input().split()]) all_ele[ele].append(sum(all_ele[ele])) all_ele.append([int(x) for x in range(w+1)]) for a in range(w + 1): for b in range(h): sum_ele.append(all_ele[b][a]) all_ele[h][a] = sum(sum_ele) sum_ele = []
s444720097
Accepted
20
5,684
440
all_ele = [] sum_ele = [] h,w = [int(x) for x in input().split()] for ele in range(h): all_ele.append([int(x) for x in input().split()]) all_ele[ele].append(sum(all_ele[ele])) all_ele.append([int(x) for x in range(w+1)]) for a in range(len(all_ele[0])): for b in range(h): sum_ele.append(all_ele[b][a]) all_ele[h][a] = sum(sum_ele) sum_ele = [] for out1 in all_ele: print(' '.join(map(str,out1)))
s686731977
p03943
u997530672
2,000
262,144
Wrong Answer
17
2,940
117
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a, b, c = map(int, input().split()) if a + b == c or b + c == a or a + c == b: print('YES') else: print('NO')
s739800817
Accepted
17
2,940
117
a, b, c = map(int, input().split()) if a + b == c or b + c == a or a + c == b: print('Yes') else: print('No')
s221639777
p02408
u546968095
1,000
131,072
Wrong Answer
20
5,592
574
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
Cards = [ "S 1", "H 1", "C 1", "D 1", "S 2", "H 2", "C 2", "D 2", "S 3", "H 3", "C 3", "D 3", "S 4", "H 4", "C 4", "D 4", "S 5", "H 5", "C 5", "D 5", "S 6", "H 6", "C 6", "D 6", "S 7", "H 7", "C 7", "D 7", "S 8", "H 8", "C 8", "D 8", "S 9", "H 9", "C 9", "D 9", "S 10", "H 10", "C 10", "D 10", "S 11", "H 11", "C 11", "D 11", "S 12", "H 12", "C 12", "D 12", "S 13", "H 13", "C 13", "D 13", ] n = input() for i in range(int(n)): rm = input() Cards.remove(rm) for i in range(52 - int(n)): print(Cards.pop(0))
s283062162
Accepted
20
5,596
538
Cards = [ "S 1", "S 2", "S 3", "S 4", "S 5", "S 6", "S 7", "S 8", "S 9", "S 10", "S 11", "S 12", "S 13", "H 1", "H 2", "H 3", "H 4", "H 5", "H 6", "H 7", "H 8", "H 9", "H 10", "H 11", "H 12", "H 13", "C 1", "C 2", "C 3", "C 4", "C 5", "C 6", "C 7", "C 8", "C 9", "C 10", "C 11", "C 12", "C 13", "D 1", "D 2", "D 3", "D 4", "D 5", "D 6", "D 7", "D 8", "D 9", "D 10", "D 11", "D 12", "D 13", ] n = input() for i in range(int(n)): rm = input() Cards.remove(rm) for i in range(52 - int(n)): print(Cards.pop(0))
s264467905
p02613
u566297428
2,000
1,048,576
Wrong Answer
142
16,616
205
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.
import collections N = int(input()) S = [input() for _ in range(N)] c = collections.Counter(S) print('AC', '×', c['AC']) print('WA', '×', c['WA']) print('TLE', '×', c['TLE']) print('RE', '×', c['RE'])
s958644426
Accepted
141
16,552
188
import collections N = int(input()) S = [input() for _ in range(N)] print('AC x', S.count('AC')) print('WA x', S.count('WA')) print('TLE x', S.count('TLE')) print('RE x', S.count('RE'))
s044371366
p03693
u830592648
2,000
262,144
Wrong Answer
17
2,940
84
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?
n = int(input().replace(" ","")) if n%4 == 0: print("Yes") else: print("No")
s878251698
Accepted
18
2,940
84
n = int(input().replace(" ","")) if n%4 == 0: print("YES") else: print("NO")
s174991501
p03385
u120810144
2,000
262,144
Wrong Answer
17
2,940
63
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
s = input() s = sorted(s) print("Yes" if s == "abc" else "No")
s222889858
Accepted
17
2,940
71
s = input() s = "".join(sorted(s)) print("Yes" if s == "abc" else "No")
s308611607
p03861
u396391104
2,000
262,144
Wrong Answer
17
2,940
49
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().split()) print(b//x-a//x)
s728123175
Accepted
17
2,940
54
a,b,x = map(int,input().split()) print(b//x-(a-1)//x)
s507022784
p02615
u395620499
2,000
1,048,576
Wrong Answer
144
31,432
138
Quickly after finishing the tutorial of the online game _ATChat_ , you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the **friendliness** of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets **comfort** equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?
n = int(input()) a = list(map(int, input().split())) a.sort() ans = 0 for i in range(1,n+1): ans += a[n-i//2-1] print(ans)
s948875738
Accepted
153
31,408
132
n = int(input()) a = list(map(int, input().split())) a.sort() ans = 0 for i in range(1, n): ans += a[n - i//2 - 1] print(ans)
s266208848
p03449
u458725980
2,000
262,144
Wrong Answer
18
3,064
452
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
N = int(input()) A = [list(map(int,input().split())) for i in range(2)] Am = [[0 for j in range(N)] for i in range(2)] Am[0][0] = A[0][0] Am[1][0] = A[0][0] + A[1][0] for i in range(N): if i > 0: Am[0][i] = A[0][i] + Am[0][i-1] for i in range(N): if i > 0: Am[1][i] = A[1][i] + max( Am[0][i] , Am[1][i - 1]) print(Am)
s850465528
Accepted
18
3,064
472
N = int(input()) A = [list(map(int,input().split())) for i in range(2)] Am = [[0 for j in range(N)] for i in range(2)] Am[0][0] = A[0][0] Am[1][0] = A[0][0] + A[1][0] for i in range(N): if i > 0: Am[0][i] = A[0][i] + Am[0][i-1] for i in range(N): if i > 0: Am[1][i] = A[1][i] + max( Am[0][i] , Am[1][i - 1]) #print(Am) print(Am[1][N-1])
s513926490
p03844
u282813849
2,000
262,144
Wrong Answer
27
9,016
20
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her.
s = input() print(s)
s219885875
Accepted
26
9,092
110
s = input() a, op, b = s.split() a = int(a) b = int(b) if op == "+": c = a + b else: c = a - b print(c)
s782853043
p03379
u652656291
2,000
262,144
Wrong Answer
330
25,472
150
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
N = int(input()) X = list(map(int,input().split())) X.sort() L = X[N//2 - 1] R = X[N//2] for x in X: if x >= R: print(L) else: print(R)
s126376622
Accepted
303
25,224
178
N = int(input()) X = [int(x) for x in input().split()] X_sorted = sorted(X) L = X_sorted[N//2 - 1] R = X_sorted[N//2] for x in X: if x >= R: print(L) else: print(R)
s244492075
p03644
u281216592
2,000
262,144
Time Limit Exceeded
2,104
2,940
217
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N = int(input()) counter =-1 number = 0 for i in range(N): k = i now_counter = 0 while(k % 2 == 0): now_counter += 1 k /= 2 if(now_counter > counter): number = i print(number)
s833543607
Accepted
17
2,940
251
N = int(input()) counter =-1 number = 0 for i in range(N): k = i+1 now_counter = 0 while(k % 2 == 0): now_counter += 1 k /= 2 if(now_counter > counter): number = i+1 counter = now_counter print(number)
s859169763
p00003
u372789658
1,000
131,072
Wrong Answer
40
7,624
100
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
num = int(input()) for i in range (num): a=input().split() print( a[0]==a[1] and a[1]==a[2])
s472306008
Accepted
40
7,524
173
num = int(input()) for i in range (num): a=sorted(list(map(int,input().split()))) if a[0]**2+a[1]**2 == (a[2])**2: print("YES") else: print("NO")
s052728800
p02416
u227984374
1,000
131,072
Wrong Answer
20
5,584
92
Write a program which reads an integer and prints sum of its digits.
N = input() ans = 0 for i in range(len(N)) : k = int(N[i]) ans = ans + k print(ans)
s628376640
Accepted
20
5,584
91
while True : N = sum(map(int, input())) if N == 0 : break print(N)
s838650212
p04030
u082861480
2,000
262,144
Wrong Answer
17
2,940
212
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?
w = input() res = [] for i in w: print(i,res) if i =='1': res.append(i) elif i == '0': res.append(i) elif len(res) > 0: res.pop() else: pass print(''.join(res))
s390923795
Accepted
17
3,060
195
w = input() res = [] for i in w: if i =='1': res.append(i) elif i == '0': res.append(i) elif len(res) > 0: res.pop() else: pass print(''.join(res))
s933199739
p02842
u988832865
2,000
1,048,576
Wrong Answer
31
2,940
150
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()) def solve(N): for i in range(60000): if int(i * 1.08) == N: print(i) else: print(":(") solve(N)
s723320113
Accepted
31
2,940
168
N = int(input()) def solve(N): for i in range(60000): if int(i * 1.08) == N: print(i) break else: print(":(") solve(N)
s337830965
p00022
u519227872
1,000
131,072
Wrong Answer
40
7,932
409
Given a sequence of numbers a1, a2, a3, ..., an, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a _contiquous_ subsequence.
from sys import stdin def getMax(array): mx = mx2 = array[0] for i in array[1:]: mx2 = max(i, mx2 + i) print(mx2,mx) mx = max(mx, mx2) return mx for line in stdin: n = int(line) if n == 0: break array = [] for line in stdin: line = int(line) array.append(line) if len(array) == n: break print(getMax(array))
s990987879
Accepted
30
7,724
387
from sys import stdin def getMax(array): mx = mx2 = array[0] for i in array[1:]: mx2 = max(i, mx2 + i) mx = max(mx, mx2) return mx for line in stdin: n = int(line) if n == 0: break array = [] for line in stdin: line = int(line) array.append(line) if len(array) == n: break print(getMax(array))
s652394260
p03488
u811202694
2,000
524,288
Wrong Answer
2,117
189,416
795
A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction. This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back. * `F` : Move in the current direction by distance 1. * `T` : Turn 90 degrees, either clockwise or counterclockwise. The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.
import numpy as np s = list(input()) target = np.array([int(i) for i in input().split()]) direction = np.array([[1, 0], [0, -1], [-1, 0], [0, 1]]) queue = [[np.array([0, 0]), 0, s]] flag = False while queue: state, now_d, s = queue.pop(0) print(target, state, s) if len(s) == 0: if np.allclose(target, state): flag = True break else: continue operation = s[0] diff = target - state if operation == "F": next_state = state + direction[now_d] queue.append([next_state, now_d, s[1:]]) elif operation == "T": queue.append([state, (now_d+1) % 4, s[1:]]) queue.append([state, (now_d-1) % 4, s[1:]]) if flag: print("Yes") else: print("No")
s951544387
Accepted
20
3,188
666
s = input().split("T") x, y = ([int(i) for i in input().split()]) movex = [] movey = [] for i, t in enumerate(s): if i % 2 == 0: movex.append(len(t)) else: movey.append(len(t)) def t_dfs(move, target, is_x): if is_x: target -= move.pop(0) move.sort(reverse=True) for dx in move: if target > 0: target -= dx else: target += dx return target == 0 if t_dfs(movex, x, True) and t_dfs(movey, y, False): print("Yes") else: print("No")
s980345161
p03380
u497952650
2,000
262,144
Wrong Answer
113
14,428
196
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.
n = int(input()) a = list(map(int,input().split())) a.sort() M = max(a) m = M//2 tmp = 1e9 for i in range(n-1): if tmp > abs(a[i]-m): tmp = abs(a[i]-m) ans = i print(M,a[ans])
s825680020
Accepted
69
14,428
203
n = int(input()) a = list(map(int,input().split())) m = max(a) res = 1e10 ans = 0 for i in a: if i != m: if abs(m//2-i) < res: res = abs(m//2-i) ans = i print(m,ans)
s951919024
p03386
u844789719
2,000
262,144
Wrong Answer
17
3,060
206
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 = [int(_) for _ in input().split()] if A+K < B-K: print("\n".join([str(_) for _ in list(range(A,A+K+1)) + list(range(B-K,B+1))])) else: print("\n".join([str(_) for _ in list(range(A,B+1))]))
s622831927
Accepted
17
2,940
208
A, B, K = [int(_) for _ in input().split()] if 2*K <= B-A: print("\n".join([str(_) for _ in list(range(A,A+K)) + list(range(B-K+1,B+1))])) else: print("\n".join([str(_) for _ in list(range(A,B+1))]))
s555865999
p03693
u154297942
2,000
262,144
Wrong Answer
18
2,940
109
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?
a,b,c = map(int, input().split()) if (100 * a + 10 * b + c) % 4 == 0: print("Yes") else: print("No")
s407439563
Accepted
18
2,940
109
a,b,c = map(int, input().split()) if (100 * a + 10 * b + c) % 4 == 0: print("YES") else: print("NO")
s873114489
p03679
u729133443
2,000
262,144
Wrong Answer
17
2,940
88
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());print([[['safe','dangerous'][b-a>x]],'delicious'][a-b<0])
s774245911
Accepted
27
9,148
84
x,a,b=map(int,input().split()) print(('delicious',('safe','dangerous')[b-a>x])[a<b])
s847559461
p02612
u286754585
2,000
1,048,576
Wrong Answer
32
8,996
82
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(int(n-(n//1000)*1000))
s177422077
Accepted
27
9,028
83
n=int(input()) a=n//1000 if (n%1000==0): print(0) else: print((a+1)*1000-n)
s467102968
p02865
u364061715
2,000
1,048,576
Wrong Answer
17
2,940
77
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
N = int(input()) if N%2==1: print(int((N-1)/2)) else: print(int(N/2))
s418219845
Accepted
17
2,940
81
N = int(input()) if N%2==1: print(int((N-1)/2)) else: print(int((N-2)/2))
s042861721
p03485
u636822224
2,000
262,144
Wrong Answer
17
2,940
97
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = map(int, input().split()) if type(a/b) == int: print(int(a/b)) else: print(int(a/b+1))
s310761979
Accepted
25
3,064
54
a,b = map(int,input().split()) print(int((a+b+2-1)/2))
s631329918
p03645
u712187387
2,000
262,144
Wrong Answer
2,107
61,600
304
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
N, M = map(int,input().split()) ships = [] for m in range(M): ships.append(list(map(int,input().split()))) print(ships) flag = 0 for n in range(2,N+1): print(n) if [1,n] in ships and [n,N] in ships: print("POSSIBLE") flag=1 break if flag==0: print("IMPOSSIBLE")
s760085849
Accepted
669
21,812
339
N, M = map(int,input().split()) ships_1 = [] ships_2 = [] for m in range(M): tmp = list(map(int,input().split())) if tmp[0]==1: ships_1.append(tmp[1]) elif tmp[1] == N: ships_2.append(tmp[0]) matched_list = list(set(ships_1) & set(ships_2)) if matched_list: print("POSSIBLE") else: print("IMPOSSIBLE")
s172730918
p03720
u396391104
2,000
262,144
Wrong Answer
17
2,940
123
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n,m = map(int,input().split()) list = [list(input().split()) for i in range(m)] for i in range(n): print(list.count(i+1))
s539349229
Accepted
17
2,940
154
n,m = map(int,input().split()) list = [0]*n for i in range(m): a,b = map(int,input().split()) list[a-1] += 1 list[b-1] += 1 [print(c) for c in list]
s651001019
p03623
u768896740
2,000
262,144
Wrong Answer
17
2,940
66
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
n, a, b = map(int, input().split()) print(min(abs(n-a), abs(n-b)))
s053365492
Accepted
17
2,940
111
n, a, b = map(int, input().split()) if min(abs(n-a), abs(n-b)) == abs(n-a): print('A') else: print('B')
s073516529
p03836
u006657459
2,000
262,144
Wrong Answer
17
3,060
199
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) tx -= sx ty -= sy r = 'U' * ty + 'R' * tx + 'D' * ty + 'L' * (tx+1) + \ 'U' * (ty+1) + 'U' * (tx+1) + 'DR' + 'D' * (ty+1) + 'L' * (tx+1) + 'U' print(r)
s356264327
Accepted
17
3,060
199
sx, sy, tx, ty = map(int, input().split()) tx -= sx ty -= sy r = 'U' * ty + 'R' * tx + 'D' * ty + 'L' * (tx+1) + \ 'U' * (ty+1) + 'R' * (tx+1) + 'DR' + 'D' * (ty+1) + 'L' * (tx+1) + 'U' print(r)
s374904319
p03024
u681150536
2,000
1,048,576
Wrong Answer
17
2,940
189
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.
from sys import exit S = input() min_win = len(S) - 7 win_count = 0 for s in S: if s == 'o': win_count += 1 if win_count >= min_win: print('Yes') else: print('No')
s028128623
Accepted
17
2,940
189
from sys import exit S = input() min_win = len(S) - 7 win_count = 0 for s in S: if s == 'o': win_count += 1 if win_count >= min_win: print('YES') else: print('NO')
s207767322
p03719
u663710122
2,000
262,144
Wrong Answer
17
2,940
75
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")
s625874743
Accepted
21
3,316
84
print((lambda A, B, C: "Yes" if A <= C <= B else "No")(*map(int, input().split())))
s015658014
p02747
u072606168
2,000
1,048,576
Wrong Answer
17
2,940
117
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
s = list(input()) if len(s)%2 == 1: print("No") elif s.count("hi") == len(s)//2: print("Yes") else: print("No")
s039344564
Accepted
17
2,940
111
s = input() if len(s)%2 == 1: print("No") elif s.count("hi") == len(s)//2: print("Yes") else: print("No")
s416982790
p03448
u165318982
2,000
262,144
Wrong Answer
60
9,148
244
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()) answer = 0 for i in range(A): for j in range(B): for k in range(C): total = 500 * i + 100 * j + 50 * k if total == X: answer += 1 print(str(answer))
s893226044
Accepted
58
9,172
249
A = int(input()) B = int(input()) C = int(input()) X = int(input()) answer = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): total = 500 * i + 100 * j + 50 * k if total == X: answer += 1 print(str(answer))
s809434231
p03448
u627283301
2,000
262,144
Wrong Answer
51
3,060
239
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.
#ABC087 B A=int(input()) B=int(input()) C=int(input()) X=int(input()) able_number=0 for a in range(A): for b in range(B): for c in range(C): if X==500*a+100*b+50*c: able_number+=1 print(able_number)
s301087210
Accepted
51
3,064
245
#ABC087 B A=int(input()) B=int(input()) C=int(input()) X=int(input()) able_number=0 for a in range(A+1): for b in range(B+1): for c in range(C+1): if X==500*a+100*b+50*c: able_number+=1 print(able_number)
s891512431
p03699
u702582248
2,000
262,144
Wrong Answer
18
3,060
176
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
n = int(input()) a = [int(input()) for i in range(n)] b = min([i for i in a if i % 10] + [0]) if sum(a) % 10: print(sum(a)) elif b: print(sum(a) - b) else: print(0)
s666560538
Accepted
17
3,060
160
n = int(input()) a = [int(input()) for i in range(n)] b = min([i for i in a if i % 10] + [sum(a)]) if sum(a) % 10: print(sum(a)) else: print(sum(a) - b)
s332903739
p04029
u912115033
2,000
262,144
Wrong Answer
17
2,940
33
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) print(n*(n+1)/2)
s417808695
Accepted
17
2,940
34
n = int(input()) print(n*(n+1)//2)
s953988534
p03494
u309018392
2,000
262,144
Time Limit Exceeded
2,104
3,060
108
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.
input() A = list(map(int,input().split())) count=0 while all(a%2==0 for a in A): count+=1 print(count)
s114777705
Accepted
18
3,060
129
input() A = list(map(int,input().split())) count=0 while all(a%2==0 for a in A): A=[a/2 for a in A] count+=1 print(count)
s921280711
p03386
u127856129
2,000
262,144
Wrong Answer
17
3,060
219
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,c=map(int,input().split()) d=c+1 e=b-a f=0 g=0 if d==e: while e>f: print(a) a+=1 f+=1 else: while c>f: print(a) a+=1 f+=1 while c>g: print(b-1) b+=1 g+=1
s880815984
Accepted
18
3,060
169
a,b,k=map(int,input().split()) if b-a+1<=k*2: for i in range(a,1+b): print(i) else: for i in range(a,a+k): print(i) for y in range(b-k+1,b+1): print(y)
s305382088
p03448
u922769680
2,000
262,144
Wrong Answer
18
3,064
236
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=500*a+100*b+50*c 0<= a, b, c <=50 1<= a+b+c <=50 50<= x <=20000 list_a=[0] for i in range(0,a): for j in range(0,b): list_a.append(str("i""j")) print(len(list_a))
s805193485
Accepted
49
3,064
244
a=int(input()) b=int(input()) c=int(input()) X=int(input()) 0<=a,b,c<=50 a+b+c>=1 count=0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if(500*i)+(100*j)+(50*k)==X: count+=1 print(count)
s431214808
p02369
u067972379
1,000
131,072
Wrong Answer
30
6,008
1,091
Find a cycle in a directed graph G(V, E).
from collections import deque, defaultdict def topological_sort(V, E): ''' Kahn's Algorithm (O(|V| + |E|) time) Input: V = [0, 1, ..., N-1]: a list of vertices of the digraph E: the adjacency list of the digraph (dict) Output: If the input digraph is acyclic, then return a topological sorting of the digraph. Else, return None. ''' indeg = {v: 0 for v in V} for ends in E.values(): for v in ends: indeg[v] += 1 q = deque([v for v in V if indeg[v] == 0]) top_sorted = [] while q: v = q.popleft() top_sorted.append(v) for u in E[v]: indeg[u] -= 1 if indeg[u] == 0: q.append(u) if len(top_sorted) == len(V): # The input digraph is acyclic. return top_sorted else: # There is a directed cycle in the digraph. return None N, M = map(int, input().split()) V = range(N) E = defaultdict(list) for _ in range(M): s, t = map(int, input().split()) E[s].append(t) print(0 if topological_sort(V, E) is None else 1)
s648181220
Accepted
30
6,012
1,091
from collections import deque, defaultdict def topological_sort(V, E): ''' Kahn's Algorithm (O(|V| + |E|) time) Input: V = [0, 1, ..., N-1]: a list of vertices of the digraph E: the adjacency list of the digraph (dict) Output: If the input digraph is acyclic, then return a topological sorting of the digraph. Else, return None. ''' indeg = {v: 0 for v in V} for ends in E.values(): for v in ends: indeg[v] += 1 q = deque([v for v in V if indeg[v] == 0]) top_sorted = [] while q: v = q.popleft() top_sorted.append(v) for u in E[v]: indeg[u] -= 1 if indeg[u] == 0: q.append(u) if len(top_sorted) == len(V): # The input digraph is acyclic. return top_sorted else: # There is a directed cycle in the digraph. return None N, M = map(int, input().split()) V = range(N) E = defaultdict(list) for _ in range(M): s, t = map(int, input().split()) E[s].append(t) print(1 if topological_sort(V, E) is None else 0)
s711639942
p03813
u619728370
2,000
262,144
Wrong Answer
17
2,940
78
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.
s = input() a = s.find("A") z = s.rfind("Z") print(a) print(z) print(z-a)
s168079115
Accepted
17
2,940
183
# -*- coding: utf-8 -*- x = int(input()) if x<1200: print("ABC") else: print("ARC")
s583211350
p02646
u181644161
2,000
1,048,576
Wrong Answer
20
9,176
187
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) flag=0 if w-v<0: if abs(a-b) <= t*abs(v-w): flag=1 if flag==1: print("Yes") else: print("No")
s458068525
Accepted
25
9,176
187
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) flag=0 if w-v<0: if abs(a-b) <= t*abs(v-w): flag=1 if flag==1: print("YES") else: print("NO")
s714734030
p02613
u954954040
2,000
1,048,576
Wrong Answer
28
9,164
33
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()) print(N+N*N+N*N*N)
s418358806
Accepted
145
16,248
260
list=[] count=int(input()) for i in range(count): list.append(input()) print("AC"+" "+"x"+" "+str(list.count("AC"))) print("WA"+" "+"x"+" "+str(list.count("WA"))) print("TLE"+" "+"x"+" "+str(list.count("TLE"))) print("RE"+" "+"x"+" "+str(list.count("RE")))
s625290020
p02645
u081365646
2,000
1,048,576
Wrong Answer
20
9,020
24
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
s = input() print(s[:2])
s602585775
Accepted
22
9,024
24
s = input() print(s[:3])
s928769825
p02613
u966542724
2,000
1,048,576
Wrong Answer
150
9,200
294
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()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): s = input() if s == 'AC': ac += 1 elif s == 'WA': wa += 1 elif s == 'TLE': tle += 1 else: re += 1 print('AC ×', ac) print('WA ×', wa) print('TLE ×', tle) print('RE ×', re)
s081404524
Accepted
151
9,004
290
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): s = input() if s == 'AC': ac += 1 elif s == 'WA': wa += 1 elif s == 'TLE': tle += 1 else: re += 1 print('AC x', ac) print('WA x', wa) print('TLE x', tle) print('RE x', re)
s631983588
p02612
u733866054
2,000
1,048,576
Wrong Answer
30
9,156
137
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()) otsuri=10000 for i in range(10) : if N-1000*i>=0 : coin=N-1000*i otsuri=min(otsuri,coin) print(otsuri)
s057293660
Accepted
26
9,080
137
N=int(input()) otsuri=10000 for i in range(11) : if 1000*i-N>=0 : coin=1000*i-N otsuri=min(otsuri,coin) print(otsuri)
s933750682
p03814
u546440137
2,000
262,144
Wrong Answer
60
10,580
189
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s=list(input()) a=0 z=0 for i in range(len(s)): if i=="A": a=i break ss=s.reverse() for i in range(len(s)): if i=="Z": z=i break print(len(s)-(a+z))
s946612618
Accepted
48
11,948
194
s=list(input()) a=0 z=0 for i in range(len(s)): if s[i]=="A": a=i break S=list(reversed(s)) for j in range(len(S)): if S[j]=="Z": z=j break print(len(s)-a-z)
s016854446
p03471
u123648284
2,000
262,144
Wrong Answer
759
3,060
289
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.
N, Y = list(map(int, input().split())) l = [0, 0, 0] flg = False for i in range(N+1): if flg: break for j in range(N+1-i): k = N-(i+j) if Y == 1000*i + 5000*j + 10000*k: print('{} {} {}'.format(i, j, k)) flg = True break if not flg: print('-1 -1 -1')
s066927841
Accepted
1,097
3,060
312
N, Y = map(int, input().split()) res = ["-1", "-1", "-1"] for i in range(N+1): if i * 10000 > Y: break for j in range(N-i+1): if i * 10000 + j * 5000 > Y: break k = N-(i+j) if i * 10000 + j * 5000 + k * 1000 == Y: res = [str(i), str(j), str(k)] break print(" ".join(res))
s461282452
p03606
u088552457
2,000
262,144
Wrong Answer
23
3,060
156
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
n = int(input()) answer = 0 for i in range(n): a, b = map(int, input().split()) if a == b: answer += 1 else: answer += b - a print(answer)
s896253253
Accepted
20
3,060
123
n = int(input()) answer = 0 for i in range(n): a, b = map(int, input().split()) answer += (b + 1) - a print(answer)
s397992513
p03457
u558782626
2,000
262,144
Wrong Answer
378
3,060
213
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
N = int(input()) t0, x0, y0 = (0, 0, 0) for _ in range(N): t1, x1, y1 = map(int, input().split()) if abs(x1-x0)+abs(y1-y0) > t1-t0 or (abs(x1-x0)+abs(y1-y0)) % (t1-t0): print('No') break else: print('Yes')
s147245896
Accepted
392
3,064
243
N = int(input()) t0, x0, y0 = (0, 0, 0) for _ in range(N): t1, x1, y1 = map(int, input().split()) if abs(x1-x0)+abs(y1-y0) > t1-t0 or (abs(x1-x0)+abs(y1-y0))%2 != (t1-t0)%2: print('No') break t0, x0, y0 = t1, x1, y1 else: print('Yes')
s092792313
p04043
u490553751
2,000
262,144
Wrong Answer
17
2,940
164
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.
import sys input = sys.stdin.readline li = [int(i) for i in input().split()] li.sort() a = "No" if li[0] == 5 and li[1] == 5 and li[2] == 7 : a = "Yes" print(a)
s167319169
Accepted
16
2,940
164
import sys input = sys.stdin.readline li = [int(i) for i in input().split()] li.sort() a = "NO" if li[0] == 5 and li[1] == 5 and li[2] == 7 : a = "YES" print(a)
s850391597
p03067
u929813319
2,000
1,048,576
Wrong Answer
17
2,940
190
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,b,c = list(map(int,input().split())) if b-a> 0: if c-b > 0: print("no") else: print("yes") else: if b-c > 0: print("no") else: print("yes")
s074912732
Accepted
17
3,060
145
a,b,c = list(map(int,input().split())) if b-c > 0 and c-a > 0: print("Yes") elif a-c > 0 and c-b > 0: print("Yes") else: print("No")
s416575159
p03624
u315868385
2,000
262,144
Wrong Answer
17
3,188
141
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
S = input() for i in range(ord('a'), ord('z')+1): c = chr(i) if c not in S: print(c) if c == 'z': print("None")
s026005819
Accepted
17
3,188
137
S = input() l = [chr(i) for i in range(ord('a'), ord('z')+1) if chr(i) not in S] if len(l) == 0: print("None") else: print(l[0])
s001989615
p03160
u683956577
2,000
1,048,576
Wrong Answer
141
14,660
343
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n = ni() h = na() dp = [0]*n dp[0] = 0 dp[1] = abs(h[1]-h[0]) count = 1 for i in range(2,n): dp[i] = min(abs(h[i-1]-h[i])+dp[i-1], abs(h[i-2]-h[i])+dp[i-2]) print(dp)
s179442893
Accepted
153
14,012
393
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n = ni() h = na() A = [0 for _ in range(n)] for i in range(n): if i == 1: A[i] = abs(h[i]-h[i-1]) elif i>1: A[i] = min(A[i-1]+abs(h[i]-h[i-1]),A[i-2]+abs(h[i]-h[i-2])) else: A[i] = A[i] print(A[-1])
s822375857
p02397
u002193969
1,000
131,072
Wrong Answer
50
5,612
114
Write a program which reads two integers x and y, and prints them in ascending order.
while True: a, b = [int(x) for x in input().split()] if a == 0 and b == 0: break print(a, b)
s432988419
Accepted
60
5,616
162
while True: a, b = [int(x) for x in input().split()] if a == 0 and b == 0: break if a < b: print(a, b) else: print(b, a)
s930562745
p03672
u859897687
2,000
262,144
Wrong Answer
17
2,940
121
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.
s=input() for i in range(len(s)-1,0,-1): if i%2>0: continue if s[:i//2]==s[i//2:i]: print(s[:i//2]) break
s753317549
Accepted
18
2,940
114
s=input() for i in range(len(s)-1,0,-1): if i%2>0: continue if s[:i//2]==s[i//2:i]: print(i) break
s027310739
p02393
u152353734
1,000
131,072
Wrong Answer
30
6,724
104
Write a program which reads three integers, and prints them in ascending order.
(a, b, c) = [int(i) for i in input().split()] if a < b < c: print('1 3 8') else: print('3 1 8')
s550593200
Accepted
30
6,728
282
nums = input().split() a = int(nums[0]) b = int(nums[1]) c = int(nums[2]) if a <= b <= c: print(a, b, c) elif a <= c <= b: print(a, c, b) elif b <= a <= c: print(b, a, c) elif b <= c <= a: print(b, c, a) elif c <= a <= b: print(c, a, b) else: print(c, b, a)
s065479205
p02394
u727538672
1,000
131,072
Wrong Answer
20
7,528
147
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
W, H, x, y, r = map(int, input().split()) if (x + r) > W and (x - r) > 0 and (y + r) > H and (y - r) > 0 : print("Yes") else : print("No")
s609701180
Accepted
20
7,656
151
W, H, x, y, r = map(int, input().split()) if (x + r) <= W and (x - r) >= 0 and (y + r) <= H and (y - r) >= 0 : print("Yes") else : print("No")
s449735868
p03455
u684084063
2,000
262,144
Wrong Answer
17
3,060
164
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
# -*- coding: utf-8 -*- import math a,b =map(int,input().split()) N =str(a)+str(b) ans= math.sqrt(int(N)) if int(N)==ans*ans: print("Yes") else: print("No")
s497306239
Accepted
17
2,940
112
# -*- coding: utf-8 -*- a,b =map(int,input().split()) N=a*b if 0==N%2: print("Even") else: print("Odd")
s740173202
p03574
u798316285
2,000
262,144
Wrong Answer
22
3,444
446
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=[["."]*(w+2)]+[["."]+list(input())+["."] for _ in range(h)]+[["."]*(w+2)] ans=[[0]*w]*h for i in range(1,h+1): for j in range(1,w+1): if S[i][j]=="#": ans[i-1][j-1]="#" else: count=(S[i-1][j-1]=="#")+(S[i-1][j]=="#")+(S[i-1][j+1]=="#")+(S[i][j-1]=="#")+(S[i][j+1]=="#")+(S[i+1][j-1]=="#")+(S[i+1][j]=="#")+(S[i+1][j+1]=="#") ans[i-1][j-1]=count for i in range(h): print(*ans[i],sep="")
s197306352
Accepted
21
3,444
478
h,w=map(int,input().split()) S=[["."]*(w+2)]+[["."]+list(input())+["."] for _ in range(h)]+[["."]*(w+2)] ans=[[0 for i in range(w)] for j in range(h)] for i in range(1,h+1): for j in range(1,w+1): if S[i][j]=="#": ans[i-1][j-1]="#" else: count=(S[i-1][j-1]=="#")+(S[i-1][j]=="#")+(S[i-1][j+1]=="#")+(S[i][j-1]=="#")+(S[i][j+1]=="#")+(S[i+1][j-1]=="#")+(S[i+1][j]=="#")+(S[i+1][j+1]=="#") ans[i-1][j-1]=count for i in range(h): print(*ans[i],sep="")
s000992162
p03005
u267222408
2,000
1,048,576
Wrong Answer
22
2,940
79
Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?
N, K = map(int, input().split()) if K == 1: print(0) else: print(N-K-1)
s180229798
Accepted
17
2,940
78
N, K = map(int, input().split()) if K == 1: print(0) else: print(N-K)
s391190439
p03387
u588558668
2,000
262,144
Wrong Answer
17
3,064
217
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.
l=list(map(int,input().split())) l.sort() a=l[0] b=l[1] c=l[2] ans=0 while a<c-1: a+=2 ans+=1 while b<c-1: b+=2 ans+=1 if a==c and b==c: print(ans) elif a!=c and b!=c: print(ans+2) else: print(ans+1)
s283516449
Accepted
17
3,060
218
l=list(map(int,input().split())) l.sort() a=l[0] b=l[1] c=l[2] ans=0 while a<c-1: a+=2 ans+=1 while b<c-1: b+=2 ans+=1 if a==c and b==c: print(ans) elif a!=c and b!=c: print(ans+1) else: print(ans+2)
s734067568
p02743
u933341648
2,000
1,048,576
Wrong Answer
17
2,940
93
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
import math a, b, c = map(int, input().split()) ans = a + b < c print('Yes' if ans else 'No')
s445802785
Accepted
17
2,940
114
a, b, c = map(int, input().split()) x = c - a - b ans = x > 0 and 4 * a * b < x ** 2 print('Yes' if ans else 'No')
s281697288
p03388
u263830634
2,000
262,144
Wrong Answer
18
3,060
347
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
import math Q = int(input()) for _ in range(Q): A, B = map(int, input().split()) score = A*B if A > B: A, B = B, A if A == B: print (2 * A -2) elif A+1 == B: print (2 * A - 2) else: c = int(math.sqrt(A*B)) print (2 * c -1)
s844915096
Accepted
18
3,064
464
import math Q = int(input()) for _ in range(Q): A, B = map(int, input().split()) score = A*B if A > B: A, B = B, A if A == B: print (2 * A -2) elif A+1 == B: print (2 * A - 2) else: c = int(math.sqrt(A*B)) if c ** 2 == A * B: c -= 1 if c * (c+1) >= A * B: print (2 * c -2) else: print (2 * c -1)
s192502481
p00027
u560214129
1,000
131,072
Wrong Answer
30
8,064
550
Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29.
from datetime import date import sys for line in sys.stdin.readlines(): m , d = map(int,line.split()) if m != 0 and d != 0 : val = date(2004,m,d) day = val.isoweekday() if day == 0: print("Sunday") elif day == 1: print("Monday") elif day == 2: print("Tuesday") elif day == 3: print("Wednesday") elif day == 4: print("Thursday") elif day == 5: print("Friday") else: print("Saturday") else: break
s929465513
Accepted
30
8,048
550
from datetime import date import sys for line in sys.stdin.readlines(): m , d = map(int,line.split()) if m != 0 and d != 0 : val = date(2004,m,d) day = val.isoweekday() if day == 7: print("Sunday") elif day == 1: print("Monday") elif day == 2: print("Tuesday") elif day == 3: print("Wednesday") elif day == 4: print("Thursday") elif day == 5: print("Friday") else: print("Saturday") else: break
s474894075
p02390
u830563109
1,000
131,072
Wrong Answer
20
5,536
44
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 = 2000 m = s / 60 h = m / 60 print(s,m,h)
s598239501
Accepted
20
5,588
92
a = int(input()) h = int(a/3600) m=int((a%3600)/60) s=int((a%3600)%60) print(h,m,s,sep=":")
s270022212
p02393
u050103511
1,000
131,072
Wrong Answer
20
7,444
57
Write a program which reads three integers, and prints them in ascending order.
list = [i for i in input().split()] print(" ".join(list))
s403381218
Accepted
20
7,672
82
L = [int(i) for i in input().split()] print(' '.join([str(i) for i in sorted(L)]))
s418538757
p03854
u697559326
2,000
262,144
Wrong Answer
87
3,572
694
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
S = input() word = ["dream","dreamer","erase","eraser"] S = S[::-1] for i in range(len(word)): word[i] = word[i][::-1] print(S, S[5:], S[11:] == "") while True: for i in range(len(word)): flag2 = False if word[i] == S[:len(word[i])]: flag2 = True S = S[len(word[i]):] break if S == "": print("YES") break elif flag2 == False: print("NO") break
s710761112
Accepted
92
3,188
629
S = input() word = ["dream","dreamer","erase","eraser"] S = S[::-1] for i in range(len(word)): word[i] = word[i][::-1] while True: for i in range(len(word)): flag2 = False if word[i] == S[:len(word[i])]: flag2 = True S = S[len(word[i]):] break if S == "": print("YES") break elif flag2 == False: print("NO") break
s839981874
p00042
u078042885
1,000
131,072
Wrong Answer
30
7,680
327
宝物がたくさん収蔵されている博物館に、泥棒が大きな風呂敷を一つだけ持って忍び込みました。盗み出したいものはたくさんありますが、風呂敷が耐えられる重さが限られており、これを超えると風呂敷が破れてしまいます。そこで泥棒は、用意した風呂敷を破らず且つ最も価値が高くなるようなお宝の組み合わせを考えなくてはなりません。 風呂敷が耐えられる重さ W、および博物館にある個々のお宝の価値と重さを読み込んで、重さの総和が W を超えない範囲で価値の総和が最大になるときの、お宝の価値総和と重さの総和を出力するプログラムを作成してください。ただし、価値の総和が最大になる組み合わせが複数あるときは、重さの総和が小さいものを出力することとします。
c=1 while 1: W=int(input()) if W==0:break n=int(input()) dp=[0]*(W+1) for i in range(n): v,w = map(int, input().split(',')) for j in range(W,w-1,-1): dp[j]=max(dp[j-w]+v,dp[j]) for i in range(W): if dp[W]==dp[i]:break print('Case %d\n%d\n%d'%(c,dp[W],i)) c+=1
s763289547
Accepted
370
7,652
328
c=1 while 1: W=int(input()) if W==0:break dp=[0]*(W+1) for i in range(int(input())): v,w=map(int, input().split(',')) for j in range(W,w-1,-1): if dp[j]<dp[j-w]+v:dp[j]=dp[j-w]+v for i in range(W+1): if dp[W]==dp[i]:break print('Case %d:\n%d\n%d'%(c,dp[W],i)) c+=1
s811424017
p03644
u982139831
2,000
262,144
Wrong Answer
17
2,940
80
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N = int(input()) if N%2==0: print(N) elif N==1: print(N) else: print(N-1)
s367998253
Accepted
17
2,940
223
N = int(input()) num_list=[] for num in range(1,N+1): counter=0 while True: if int(num/2)==num/2: num/=2 counter+=1 else: break num_list.append(counter) print(num_list.index(max(num_list))+1)
s709506157
p03024
u296518383
2,000
1,048,576
Wrong Answer
17
2,940
47
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.
print("No" if input().count("x")>=8 else "Yes")
s337032455
Accepted
17
2,940
47
print("NO" if input().count("x")>=8 else "YES")
s724345343
p03050
u063896676
2,000
1,048,576
Wrong Answer
160
2,940
173
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
# coding: utf-8 n = int(input()) output = 0 # n = (m+1)*x = y*x (y>=2) for x in range(1, int(pow(n, 0.5))): if n % x == 0: output += n // x - 1 print(output)
s772846437
Accepted
311
3,060
199
# coding: utf-8 n = int(input()) output = 0 # n = (m+1)*x = y*x (y>=2) limit = pow(n+0.25, 0.5)-0.5 x = 1 while x < limit: if n % x == 0: output += n // x - 1 x += 1 print(output)
s574569700
p02314
u724548524
1,000
131,072
Wrong Answer
20
5,600
409
Find the minimum number of coins to make change for n cents using coins of denominations d1, d2,.., dm. The coins can be used any number of times.
def cs(n, p, c): global count, m if p >= count: return m if n % c[0] == 0: count = min(count, p + n // c[0]) return count elif c[0] < n: return min(cs(n - c[0], p + 1, c), cs(n, p, c[1:])) else: return cs(n, p, c[1:]) n, m = map(int, input().split()) c = list(map(int, input().split())) c.sort(reverse = True) print(c) count = n print(cs(n, 0, c))
s194791978
Accepted
60
5,604
414
def cs(n, p, c): global count, m if n % c[0] == 0: count = min(count, p + n // c[0]) return count elif p + n // c[0] >= count: return n elif c[0] < n: return min(cs(n - c[0], p + 1, c), cs(n, p, c[1:])) else: return cs(n, p, c[1:]) n, m = map(int, input().split()) c = list(map(int, input().split())) c.sort(reverse = True) count = n print(cs(n, 0, c))
s427879074
p03852
u246572032
2,000
262,144
Wrong Answer
17
2,940
96
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`.
x = input() print('vowel' if x=='a' and x=='e' and x=='i' and x=='o' and x=='u' else'consonant')
s619727228
Accepted
17
2,940
59
c = input() print('vowel' if c in 'aeiou' else 'consonant')
s341539371
p03353
u227082700
2,000
1,048,576
Wrong Answer
35
4,340
119
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
s=input() k=int(input()) a=[] for i in range(k): for j in range(len(s)-i):a.append(s[j:j+i+1]) a.sort() print(a[k-1])
s418422407
Accepted
34
4,592
122
s=input() k=int(input()) a={s} for i in range(k): for j in range(len(s)-i):a.add(s[j:j+i+1]) print(sorted(list(a))[k-1])
s477957747
p03455
u023229441
2,000
262,144
Wrong Answer
17
2,940
79
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=map(int,input().split()) if a*b//2==0: print("Even") else: print("Odd")
s021793515
Accepted
17
2,940
59
a,b=map(int,input().split()) print("EOvdedn"[a*b%2==1::2])
s731322656
p03796
u589730912
2,000
262,144
Wrong Answer
2,104
10,136
99
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
N = int(input()) power = 1 for i in range(1, N+1): power *= i print(power **N % (10 ** 9 + 7))
s698699050
Accepted
34
2,940
111
N = int(input()) power = 1 div = 10 ** 9 + 7 for i in range(1, N+1): power = power * i % div print(power)
s053721163
p03486
u379424722
2,000
262,144
Wrong Answer
17
2,940
161
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.
n = input() #print(n) n = ''.join(sorted(n)) m = input() #print(m) m = ''.join(sorted(m)) #print(n) #print(m) if n < m: print("Yes") else: print("No")
s107949640
Accepted
20
3,060
177
n = input() #print(n) n = ''.join(sorted(n)) m = input() #print(m) m = ''.join(sorted(m, reverse = True)) #print(n) #print(m) if n < m: print("Yes") else: print("No")
s830438502
p02747
u661977789
2,000
1,048,576
Wrong Answer
17
2,940
68
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
h = input().replace("hi", "") o = "Yes" if len(h) else "No" print(o)
s324612004
Accepted
17
2,940
51
print("No" if input().replace("hi", "") else "Yes")
s969583103
p03474
u220345792
2,000
262,144
Wrong Answer
19
2,940
127
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.
l = input().split() a=input() b=a.split("-") if len(b[0]) == l[0] and len(b[1])==l[1]: print('YES') else: print('NO')
s634358400
Accepted
17
2,940
119
A, B = map(int, input().split()) S = input() if S[A] == "-" and S.count("-") == 1: print("Yes") else: print("No")
s402871765
p04029
u475675023
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))
s241167526
Accepted
17
2,940
32
N=int(input());print(N*(N+1)//2)
s901940380
p02972
u186967328
2,000
1,048,576
Wrong Answer
556
20,540
327
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
N = int(input()) a = list(map(int,input().split())) b = [0 for i in range(N)] def check(i): cnt = 0 n = i while n <= N: cnt += b[n-1] n += i return cnt for i in range(N-1,-1,-1): if a[i] + check(i+1) == 1: b[i] = 1 print(b.count(1)) L = [str(int(i)) for i in b] print(' '.join(L))
s550455592
Accepted
569
22,324
423
N = int(input()) a = list(map(int,input().split())) b = [0 for i in range(N)] def check(i): cnt = 0 n = i while n <= N: cnt += b[n-1] n += i return cnt for i in range(N-1,-1,-1): if (a[i] + check(i+1))%2 == 1: b[i] = 1 ans = [] cnt = 0 for i in range(N): if b[i] == 1: cnt += 1 ans.append(i+1) print(cnt) L = [str(int(i)) for i in ans] print(' '.join(L))
s733622852
p03681
u216392490
2,000
262,144
Wrong Answer
36
3,060
350
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.
import sys sys.setrecursionlimit(int(1e6)) N, M = list(map(int, input().split())) base = int(1e9 + 7) ans = 0 if abs(N -M) > 1: pass else: fact = 1 for i in range(1, min(N+1, M+1)): fact = (fact * i) % (base) if N == M: ans = 2 * fact * fact else: ans = fact * fact * max(N, M) print(ans) ans = ans % base print(ans)
s330959585
Accepted
36
3,060
338
import sys sys.setrecursionlimit(int(1e6)) N, M = list(map(int, input().split())) base = int(1e9 + 7) ans = 0 if abs(N -M) > 1: pass else: fact = 1 for i in range(1, min(N+1, M+1)): fact = (fact * i) % (base) if N == M: ans = 2 * fact * fact else: ans = fact * fact * max(N, M) ans = ans % base print(ans)
s023780876
p03693
u835924161
2,000
262,144
Wrong Answer
17
2,940
95
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?
a,b,c=map(str,input().split()) a+=b a+=c if int(a)%4==0: print("Yes") else: print("No")
s175203201
Accepted
17
2,940
95
a,b,c=map(str,input().split()) a+=b a+=c if int(a)%4==0: print("YES") else: print("NO")
s725896869
p02401
u940150266
1,000
131,072
Wrong Answer
20
5,604
271
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): a,op,b = input().split() if op == '+': print(int(a)+int(b)) elif op == '-': print(int(a)-int(b)) elif op == '*': print(int(a)*int(b)) elif op == '/': print(int(a)/int(b)) elif op == '?': break
s731156631
Accepted
20
5,600
276
while(True): a,op,b = input().split() if op == '+': print(int(a)+int(b)) elif op == '-': print(int(a)-int(b)) elif op == '*': print(int(a)*int(b)) elif op == '/': print(int(int(a)/int(b))) elif op == '?': break
s875081265
p03163
u763115743
2,000
1,048,576
Wrong Answer
2,110
109,428
585
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
def solve(n, w, items): dp = [[0] * (w + 1) for i in range(n + 1)] for i in range(1, n + 1): for j in range(1, w + 1): prev = i - 1 dp[i][j] = max(dp[i][j], dp[prev][j]) weight, value = items[i - 1][0], items[i - 1][1] if j - weight >= 0: dp[i][j] = max(dp[i][j], dp[i][j - weight] + value) return dp[n][w] def main(): n, w = map(int, input().split()) items = [] for i in range(n): items.append(list(map(int, input().split()))) ans = solve(n, w, items) print(ans) main()
s195418154
Accepted
303
20,116
370
import numpy as np def solve(w, items): dp = np.zeros(w + 1, dtype=int) for weight, value in items: dp[weight:] = np.maximum(dp[weight:], dp[:w-weight+1] + value) return dp[w] def main(): n, w = map(int, input().split()) items = list(list(map(int, input().split())) for _ in range(n)) ans = solve(w, items) print(ans) main()
s356490979
p02401
u922112509
1,000
131,072
Wrong Answer
20
5,612
332
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.
# Simple Calculator end = 0 while end == 0: n = [i for i in input().rstrip().split()] a = int(n[0]) op = n[1] b = int(n[2]) if op == '+': print(a + b) elif op == '-': print(a - b) elif op == '*': print(a * b) elif op == '/': print(a / b) else: end += 1
s538306254
Accepted
20
5,604
333
# Simple Calculator end = 0 while end == 0: n = [i for i in input().rstrip().split()] a = int(n[0]) op = n[1] b = int(n[2]) if op == '+': print(a + b) elif op == '-': print(a - b) elif op == '*': print(a * b) elif op == '/': print(a // b) else: end += 1
s754922559
p02612
u848097937
2,000
1,048,576
Wrong Answer
32
9,024
78
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: print(1000) else: print(1000 - N % 1000)
s949182830
Accepted
28
9,028
77
n = int(input()) if n % 1000 == 0: print(0) else: print(1000 - n % 1000)
s120435557
p03860
u508141157
2,000
262,144
Wrong Answer
17
2,940
24
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.
print("A%sC",input()[0])
s573230800
Accepted
20
2,940
25
print("A"+input()[8]+"C")
s134726885
p03548
u497046426
2,000
262,144
Wrong Answer
17
2,940
67
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
X, Y, Z = map(int, input().split()) ans = X // (Y + 2*Z) print(ans)
s868307765
Accepted
17
3,064
71
X, Y, Z = map(int, input().split()) ans = (X - Z) // (Y + Z) print(ans)
s834090465
p03672
u397563544
2,000
262,144
Wrong Answer
18
2,940
115
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.
s = input() n = len(s)//2 for i in range(n): if s[:n-i] == s[n-i:2*(n-i)]: print(2*(n-i)) break
s520033011
Accepted
18
2,940
117
s = input() n = len(s)//2 for i in range(1,n): if s[:n-i] == s[n-i:2*(n-i)]: print(2*(n-i)) break
s321164929
p02678
u029785897
2,000
1,048,576
Wrong Answer
881
48,888
661
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
from collections import deque N, M = map(int, input().split()) Gs = [[] for _ in range(N+1)] for _ in range(M): a, b = map(int, input().split()) Gs[a].append(b) Gs[b].append(a) ms = [0] * (N+1) def bfs(c): queue = deque() ns = Gs[c] for n in ns: queue.append((n, c)) while queue: c, p = queue.popleft() if ms[c] != 0: continue ms[c] = p ns = Gs[c] for n in ns: if n != p: queue.append((n, c)) bfs(1) print(ms) for m in ms[2:]: if m == 0: print('No') break else: print('Yes') for m in ms[2:]: print(m)
s562498203
Accepted
800
48,808
651
from collections import deque N, M = map(int, input().split()) Gs = [[] for _ in range(N+1)] for _ in range(M): a, b = map(int, input().split()) Gs[a].append(b) Gs[b].append(a) ms = [0] * (N+1) def bfs(c): queue = deque() ns = Gs[c] for n in ns: queue.append((n, c)) while queue: c, p = queue.popleft() if ms[c] != 0: continue ms[c] = p ns = Gs[c] for n in ns: if n != p: queue.append((n, c)) bfs(1) for m in ms[2:]: if m == 0: print('No') break else: print('Yes') for m in ms[2:]: print(m)
s692706354
p03386
u565204025
2,000
262,144
Wrong Answer
18
3,060
211
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.
# -*- coding: utf-8 -*- a,b,k = map(int,input().split()) list = [] for i in range(a,a+k): list.append(i) for i in range(b,b-k,-1): list.append(i) list.sort() l = set(list) for i in l: print(i)
s821426364
Accepted
19
3,060
240
# -*- coding: utf-8 -*- a,b,k = map(int,input().split()) lists = [] for i in range(a,min(a+k,b+1)): lists.append(i) for i in range(b,max(b-k,a),-1): lists.append(i) l = set(lists) m = list(l) m.sort() for i in m: print(i)
s492228338
p03493
u566143855
2,000
262,144
Wrong Answer
17
2,940
95
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
n = input() i = [] for x in range(int(n)): if x % 2 == 0: i.append(x) print(len(i))
s723056994
Accepted
17
2,940
25
print(input().count("1"))
s690187545
p03712
u217627525
2,000
262,144
Wrong Answer
20
3,060
116
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()) print("*"*(w+2)) for i in range(h): a=input() print("*"+a+"*") print("*"*(w+2))
s485619044
Accepted
17
3,060
116
h,w=map(int,input().split()) print("#"*(w+2)) for i in range(h): a=input() print("#"+a+"#") print("#"*(w+2))
s211272444
p02601
u256769262
2,000
1,048,576
Wrong Answer
24
9,180
228
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
a = list(map(int, input().split())) n = int(input()) while 1: if n == 0: print("No") break elif a[0] >= a[1]: a[1] *= 2 n -= 1 elif a[1] >= a[2]: a[2] *= 2 n -= 1 else: print("Yse") break
s089124301
Accepted
26
9,156
224
a = list(map(int, input().split())) n = int(input()) for i in range(n): if a[0] >= a[1]: a[1] *= 2 elif a[1] >= a[2]: a[2] *= 2 if a[0] < a[1] < a[2]: print("Yes") else: print("No")