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
s527892710
p03433
u601082779
2,000
262,144
Wrong Answer
17
2,940
56
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
a=int(input());b=int(input());print("Yneos"[a%500<b::2])
s414519637
Accepted
17
2,940
56
a=int(input());b=int(input());print("YNeos"[a%500>b::2])
s980977572
p03494
u884959062
2,000
262,144
Wrong Answer
20
2,940
307
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.
e = [[int(i) for i in input().split()] for i in range(2)] max_count = 0 for i in range(e[0][0]): tmp = e[1][i] count = 0 while True: tmp, m = divmod(tmp, 2) if m == 1: break count += 1 if count < max_count: max_count = count print(max_count)
s216774715
Accepted
19
3,060
312
e = [[int(i) for i in input().split()] for i in range(2)] max_count = 999999 for i in range(e[0][0]): tmp = e[1][i] count = 0 while True: tmp, m = divmod(tmp, 2) if m == 1: break count += 1 if count < max_count: max_count = count print(max_count)
s269136561
p04044
u577504524
2,000
262,144
Wrong Answer
25
9,108
164
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.
#B n,l = map(int,input().split()) word_list=[] for i in range(n): word = str(input()) word_list.append(word) x = sorted(word_list) print(''.join(word_list))
s812948162
Accepted
27
9,172
156
#B n,l = map(int,input().split()) word_list=[] for i in range(n): word = str(input()) word_list.append(word) x = sorted(word_list) print(''.join(x))
s506298878
p02255
u843404779
1,000
131,072
Wrong Answer
20
7,680
457
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 print_list(ele_list): print(" ".join(map(str, ele_list))) def insertion_sort(ele_list): len_ele_list = len(ele_list) for i in range(1, len_ele_list): key = ele_list[i] j = i - 1 while j >= 0 and ele_list[j] > key: ele_list[j+1] = ele_list[j] j -= 1 ele_list[j+1] = key print_list(ele_list) N = int(input()) ele_list = list(map(int, input().split())) insertion_sort(ele_list)
s280184181
Accepted
20
7,672
482
def print_list(ele_list): print(" ".join(map(str, ele_list))) def insertion_sort(ele_list): len_ele_list = len(ele_list) print_list(ele_list) for i in range(1, len_ele_list): key = ele_list[i] j = i - 1 while j >= 0 and ele_list[j] > key: ele_list[j+1] = ele_list[j] j -= 1 ele_list[j+1] = key print_list(ele_list) N = int(input()) ele_list = list(map(int, input().split())) insertion_sort(ele_list)
s054842854
p03680
u936985471
2,000
262,144
Wrong Answer
195
8,948
163
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
n=int(input()) a=[None]*n for i in range(len(a)): a[i]=int(input())-1 cur=0 ok=False for i in range(n+1): cur=a[cur] if cur==1: break print((-1,i)[ok])
s268573231
Accepted
219
7,668
240
n=int(input()) a=[-1]*n for i in range(n): a[i]=int(input())-1 reached=[False]*n tar=0 cnt=0 suc=False while reached[tar]==False: reached[tar]=True cnt+=1 tar=a[tar] if tar==1: suc=True break print((-1,cnt)[suc])
s149297287
p03160
u043236471
2,000
1,048,576
Wrong Answer
156
13,976
309
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N = int(input()) h = [int(x) for x in input().split()] def chmin(a, b): return a if a <= b else b dp = [float('inf')] * N dp[0] = 0 for i in range(1, N): dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1])) if i > 1: dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print(dp[1])
s178854027
Accepted
160
14,052
310
N = int(input()) h = [int(x) for x in input().split()] def chmin(a, b): return a if a <= b else b dp = [float('inf')] * N dp[0] = 0 for i in range(1, N): dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1])) if i > 1: dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print(dp[-1])
s533837426
p03455
u026406748
2,000
262,144
Wrong Answer
18
2,940
121
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a = input().split() b = [int(i) for i in a] c = b[0] * b[1] if c%2 == 0: print("偶数") else: print("奇数")
s984083086
Accepted
17
3,064
116
a = input().split() b = [int(i) for i in a] c = b[0] * b[1] if c%2 == 0: print("Even") else: print("Odd")
s064156669
p02865
u538276565
2,000
1,048,576
Wrong Answer
21
3,316
82
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
def solve(): print(int(input()) // 2) if __name__ == "__main__": solve()
s226582364
Accepted
17
2,940
121
def solve(): i = int(input()) print(i // 2 -1 if i % 2 == 0 else i // 2) if __name__ == "__main__": solve()
s124622292
p03352
u020091453
2,000
1,048,576
Wrong Answer
19
3,188
271
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
import math from bisect import bisect_right X = int(input()) s = list([1]) for i in range(2,math.ceil(1000**0.5)): for j in range(0,9): if i**j > 1000: break else: s.append(i**j) s.sort() print(s[bisect_right(s,X) -1])
s470123917
Accepted
18
3,188
268
import math from bisect import bisect_right X = int(input()) s = list([1]) for i in range(2,math.ceil(1000**0.5)): for j in range(2,9): if i**j > 1000: break else: s.append(i**j) s.sort() print(s[bisect_right(s,X) -1])
s276986789
p03067
u239528020
2,000
1,048,576
Wrong Answer
17
2,940
138
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 = map(int, input().split()) if a >= b: tmp = a b = a a = tmp if a<=c and c<=b: print("yes") else: print("no")
s481828602
Accepted
17
2,940
148
a, b, c = map(int, input().split()) if a >= b: tmp = b b = a a = tmp if a<=c and c<=b: print("Yes") else: print("No")
s080263303
p02383
u299798926
1,000
131,072
Wrong Answer
20
7,812
1,016
Write a program to simulate rolling a dice, which can be constructed by the following net. As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
x=[int(i)for i in input().split()] y=[[int(0)for i in range(4)]for i in range(3)] y[0][1]=x[0] y[1][1]=x[1] y[1][2]=x[2] y[1][0]=x[3] y[1][3]=x[4] y[2][1]=x[5] m=[i for i in input()] z=y.copy() for i in range(len(m)): if m[i]=='N': y[0][1],z[1][1]=z[1][1],y[0][1] y[1][1],z[2][1]=z[2][1],y[1][1] y[1][3],z[0][1]=z[0][1],y[1][3] y[2][1],z[1][3]=z[1][3],y[2][1] z=y.copy() elif m[i]=='S': y[0][1],z[1][3]=z[1][3],y[0][1] y[1][1],z[0][1]=z[0][1],y[1][1] y[1][3],z[2][1]=z[2][1],y[1][3] y[2][1],z[1][1]=z[1][1],y[2][1] z=y.copy() elif m[i]=='W': y[0][1],z[1][2]=z[1][2],y[0][1] y[1][0],z[0][1]=z[0][1],y[1][0] y[1][2],z[2][1]=z[2][1],y[1][2] y[2][1],z[1][0]=z[1][0],y[2][1] z=y.copy() else: y[0][1],z[1][0]=z[1][0],y[0][1] y[1][0],z[2][1]=z[2][1],y[1][0] y[1][2],z[0][1]=z[0][1],y[1][2] y[2][1],z[1][2]=z[1][2],y[2][1] z=y.copy() print(y[0][1])
s212919276
Accepted
10
7,944
788
x=[int(i)for i in input().split()] y=[[int(0)for i in range(4)]for i in range(3)] y[0][1]=x[0] y[1][1]=x[1] y[1][2]=x[2] y[1][0]=x[3] y[1][3]=x[4] y[2][1]=x[5] m=[i for i in input()] for i in range(len(m)): if m[i]=='N': y[0][1],y[1][1]=y[1][1],y[0][1] y[1][1],y[2][1]=y[2][1],y[1][1] y[2][1],y[1][3]=y[1][3],y[2][1] elif m[i]=='S': y[0][1],y[1][3]=y[1][3],y[0][1] y[1][3],y[2][1]=y[2][1],y[1][3] y[2][1],y[1][1]=y[1][1],y[2][1] elif m[i]=='W': y[0][1],y[1][2]=y[1][2],y[0][1] y[1][2],y[2][1]=y[2][1],y[1][2] y[2][1],y[1][0]=y[1][0],y[2][1] elif m[i]=='E': y[0][1],y[1][0]=y[1][0],y[0][1] y[1][0],y[2][1]=y[2][1],y[1][0] y[2][1],y[1][2]=y[1][2],y[2][1] print(y[0][1])
s903259883
p02865
u269778596
2,000
1,048,576
Wrong Answer
2,104
3,932
191
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n = int(input()) count = 0 seen = [] for i in range(1,n+1): if i!=(n-i): if i and n-i not in seen: seen.append(i) seen.append(n-i) count += 1 print(count)
s072836244
Accepted
17
2,940
32
n = int(input()) print((n-1)//2)
s990840260
p02284
u912143677
2,000
131,072
Wrong Answer
20
5,608
1,529
Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I. * insert $k$: Insert a node containing $k$ as key into $T$. * find $k$: Report whether $T$ has a node containing $k$. * print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively.
class Tree(): def __init__(self): self.root = None def insert(self, key): z = Node(key) y = None x = self.root while x: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y == None: self.root = z elif z.key < y.key: y.left = z else: y.right = z def print(self): print('', ' '.join(map(str, self.root.inwalk()))) print('', ' '.join(map(str, self.root.prewalk()))) def find(self, x, k): while x != None and k != x.key: if k < x.key: x = x.left else: x = x.right return x class Node(): def __init__(self, key): self.key = key self.parent = self.left = self.right = None def prewalk(self): ret = [self.key] if self.left: ret += self.left.prewalk() if self.right: ret += self.right.prewalk() return ret def inwalk(self): ret = [] if self.left: ret += self.left.inwalk() ret += [self.key] if self.right: ret += self.right.inwalk() return ret tree = Tree() n = int(input()) for i in range(n): com = input().split() if com[0] == "insert": tree.insert(int(com[1])) elif com[0] == "find": tree.find(tree.root, int(com[1])) else: tree.print()
s063320387
Accepted
6,900
116,656
1,619
class Tree(): def __init__(self): self.root = None def insert(self, key): z = Node(key) y = None x = self.root while x: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y == None: self.root = z elif z.key < y.key: y.left = z else: y.right = z def print(self): print('', ' '.join(map(str, self.root.inwalk()))) print('', ' '.join(map(str, self.root.prewalk()))) def find(self, x, k): while x != None and k != x.key: if k < x.key: x = x.left else: x = x.right return x class Node(): def __init__(self, key): self.key = key self.parent = self.left = self.right = None def prewalk(self): ret = [self.key] if self.left: ret += self.left.prewalk() if self.right: ret += self.right.prewalk() return ret def inwalk(self): ret = [] if self.left: ret += self.left.inwalk() ret += [self.key] if self.right: ret += self.right.inwalk() return ret tree = Tree() n = int(input()) for i in range(n): com = input().split() if com[0] == "insert": tree.insert(int(com[1])) elif com[0] == "find": ans = tree.find(tree.root, int(com[1])) if ans != None: print("yes") else: print("no") else: tree.print()
s953673935
p02257
u196653484
1,000
131,072
Wrong Answer
20
5,672
700
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of _N_ integers and prints the number of prime numbers in the list.
import math def check(B,i): sum=0 for j in range(len(B)): if B[j]%10 in [1,2,4,5,6,8]: del B[j] check(B,i) if B[j]%i==0: sum+=1 del B[j] return sum def Prime_Numbers(A): mx=max(A) sum=0 if 2 in A: sum+=1 if 3 in A: sum+=1 if 5 in A: sum+=1 if 7 in A: sum+=1 i=10 while i <= math.sqrt(mx): mx=max[A] sum+=check(A,i) i+=1 print("A={}".format(A)) return sum if __name__ == "__main__": A=[] n=int(input()) for i in range(n): A.append(int(input())) print(Prime_Numbers(A))
s057474588
Accepted
1,150
6,008
497
import math def Prime_Numbers_Check(x): i=2 flag=True while i <= math.sqrt(x): if x%i==0: flag=False break i+=1 return flag def Prime_Numbers_Count(A): sum=0 for i in A: if Prime_Numbers_Check(i): sum+=1 return sum if __name__ == "__main__": A=[] n=int(input()) for i in range(n): A.append(int(input())) sum=Prime_Numbers_Count(A) print(sum)
s852935007
p03574
u824734140
2,000
262,144
Wrong Answer
34
9,176
521
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 = [list(input()) for _ in range(0, h)] dx = [1, 0, -1, 0, 1, -1, -1, -1] dy = [0, 1, 0, -1, 1, 1, -1, -1] for i in range(0, h): for j in range(0, w): if s[i][j] != '.': continue cnt = 0 for k in range(0, 8): ni = i + dy[k] nj = j + dx[k] if not (ni < 0 or h <= ni) and not (nj < 0 or w <= nj) and s[ni][nj] == '#': cnt += 1 s[i][j] = str(cnt) [print(s[ii]) for ii in range(0, h)]
s449846540
Accepted
38
9,136
529
h, w = map(int, input().split()) s = [list(input()) for _ in range(0, h)] dx = [1, 1, 1, 0, 0, -1, -1, -1] dy = [1, 0, -1, 1, -1, 1, 0, -1] for i in range(0, h): for j in range(0, w): if s[i][j] != '.': continue cnt = 0 for k in range(0, 8): ni = i + dy[k] nj = j + dx[k] if not (ni < 0 or h <= ni) and not (nj < 0 or w <= nj) and s[ni][nj] == '#': cnt += 1 s[i][j] = str(cnt) [print(''.join(s[ii])) for ii in range(0, h)]
s293369405
p03493
u300651214
2,000
262,144
Wrong Answer
25
8,856
32
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
s = list(input()) s.count("1")
s259842484
Accepted
27
9,080
32
a = input() print(a.count('1'))
s484834080
p03759
u160659351
2,000
262,144
Wrong Answer
17
2,940
104
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.
#58 a, b, c = map(int, input().rstrip().split()) if b-a == c-a: print("YES") else: print("NO")
s161513461
Accepted
17
2,940
104
#58 a, b, c = map(int, input().rstrip().split()) if b-a == c-b: print("YES") else: print("NO")
s975871076
p02388
u335511832
1,000
131,072
Wrong Answer
30
6,724
17
Write a program which calculates the cube of a given integer x.
x = 3 print(x**3)
s224024076
Accepted
30
6,724
28
x = int(input()) print(x**3)
s148622904
p03543
u778700306
2,000
262,144
Wrong Answer
18
2,940
130
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**?
a = list(input()) if a[0] == a[1] and a[1] == a[2] or a[1] == a[2] and a[2] == a[3]: print("YES") else: print("NO")
s133782016
Accepted
18
2,940
130
a = list(input()) if a[0] == a[1] and a[1] == a[2] or a[1] == a[2] and a[2] == a[3]: print("Yes") else: print("No")
s913153871
p03303
u674185143
2,000
1,048,576
Wrong Answer
18
2,940
86
You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
s=input() w=int(input()) ans=s[0] for i in range(1,len(s)//w): ans+=s[i*w] print(ans)
s692651247
Accepted
17
2,940
39
s=input() w=int(input()) print(s[0::w])
s582124330
p04031
u901307908
2,000
262,144
Wrong Answer
23
3,064
163
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
n = int(input()) a = input() a = list(map(int, a.split())) #print(a) x_min = round(sum(a) / 3 ) cost = sum([(x_min - i) * (x_min - i) for i in a]) print(cost)
s377213309
Accepted
24
3,188
163
n = int(input()) a = input() a = list(map(int, a.split())) #print(a) x_min = round(sum(a) / n ) cost = sum([(x_min - i) * (x_min - i) for i in a]) print(cost)
s236310590
p03436
u742897895
2,000
262,144
Wrong Answer
32
3,700
819
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
from collections import deque h, w = map(int, input().split()) s = [list(input()) for j in range(h)] dx = [-1, 1, 0, 0] dy = [ 0, 0,-1, 1] q = deque([(0, 0, 0)]) used = {(0, 0)} res = None while q: i, j, cost = q.popleft() if i == w - 1 and j == h - 1: res = cost break for k in range(4): if not (0 <= i + dx[k] < w): continue if not (0 <= j + dy[k] < h): continue if s[j + dy[k]][i + dx[k]] == '#': continue if (i + dx[k], j + dy[k]) in used: continue used.add((i + dx[k], j + dy[k])) q.append((i + dx[k], j + dy[k], cost + 1)) if res: ans = h * w - cost - 1 for j in range(h): print(s[j][:].count('#')) ans -= s[j][:].count('#') print(ans) else: print(-1)
s812892276
Accepted
33
3,700
785
from collections import deque h, w = map(int, input().split()) s = [list(input()) for j in range(h)] dx = [-1, 1, 0, 0] dy = [ 0, 0,-1, 1] q = deque([(0, 0, 0)]) used = {(0, 0)} res = None while q: i, j, cost = q.popleft() if i == w - 1 and j == h - 1: res = cost break for k in range(4): if not (0 <= i + dx[k] < w): continue if not (0 <= j + dy[k] < h): continue if s[j + dy[k]][i + dx[k]] == '#': continue if (i + dx[k], j + dy[k]) in used: continue used.add((i + dx[k], j + dy[k])) q.append((i + dx[k], j + dy[k], cost + 1)) if res: ans = h * w - cost - 1 for j in range(h): ans -= s[j][:].count('#') print(ans) else: print(-1)
s848276033
p03438
u692632484
2,000
262,144
Wrong Answer
29
4,600
345
You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
N=int(input()) a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] total_do=sum(a)-sum(b) must_do_a=0 must_do_b=0 for i in range(N): dist=a[i]-b[i] if dist<0: dist=-dist must_do_a+=int(dist/2) if dist%2!=0: must_do_b+=1 elif dist>0: must_do_b+=dist if must_do_a>=must_do_b: print("YES") else: print("NO")
s861995510
Accepted
28
4,600
370
N=int(input()) a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] can = sum(b)-sum(a) actA,actB = 0,0 for i in range(N): diff = b[i]-a[i] if diff==0:continue if diff>0: actA+=(diff+1)//2 actB+=diff%2 else: actB+=(-diff) leftA = can-actA leftB = can-actB print("Yes" if leftA>=0 and leftA*2==leftB else "No")
s695990924
p03251
u175204984
2,000
1,048,576
Wrong Answer
17
3,064
606
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
l = input().split() N = int(l[0]) M = int(l[1]) X = int(l[2]) Y = int(l[3]) if X < -100: X = -100 elif X > 100: X = 100 if Y < -100: Y = -100 elif Y > 100: Y = 100 lx = input().split() ly = input().split() lx = [int(z) for z in lx] ly = [int(z) for z in ly] lx = sorted(lx) ly = sorted(ly) flag = True if int(ly[0]) - int(lx[N-1]) >= 1: for z in range(int(lx[N-1]) + 1, int(ly[0]) + 1): if z > X and z <= Y: flag = True else: flag = False break else: flag = False if flag: print("No war") else: print("War")
s444526876
Accepted
17
3,064
554
l = input().split() N = int(l[0]) M = int(l[1]) X = int(l[2]) Y = int(l[3]) """ if X < -100: X = -100 elif X > 100: X = 100 if Y < -100: Y = -100 elif Y > 100: Y = 100 """ lx = input().split() ly = input().split() lx = [int(z) for z in lx] ly = [int(z) for z in ly] lx = sorted(lx) ly = sorted(ly) flag = True if int(ly[0]) - int(lx[N-1]) >= 1: for z in range(int(lx[N-1]) + 1, int(ly[0]) + 1): if z > X and z <= Y: flag = False break if flag: print("War") else: print("No War")
s550172635
p03543
u274045692
2,000
262,144
Wrong Answer
17
2,940
125
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() if (N[0] == N[1] and N[1] == N[2]) or (N[1] == N[2] and N[2] == N[3]): print("true") else: print("false")
s927355379
Accepted
18
2,940
121
N = input() if (N[0] == N[1] and N[1] == N[2]) or (N[1] == N[2] and N[2] == N[3]): print("Yes") else: print("No")
s834322207
p03337
u883792993
2,000
1,048,576
Wrong Answer
17
2,940
54
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
A,B=list(map(int, input().split())) max(A+B, A-B, A*B)
s485367244
Accepted
17
2,940
61
A,B=list(map(int, input().split())) print(max(A+B, A-B, A*B))
s542836844
p03379
u057993957
2,000
262,144
Wrong Answer
287
25,620
155
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())) sort_x = sorted(x) l = sort_x[n//2 - 1] r = sort_x[n//2] for xi in x: print(l if xi <= l else r)
s683743771
Accepted
282
25,224
155
n = int(input()) x = list(map(int, input().split())) sort_x = sorted(x) l = sort_x[n//2 - 1] r = sort_x[n//2] for xi in x: print(r if xi <= l else l)
s125406347
p03878
u945181840
2,000
262,144
Wrong Answer
236
34,096
224
There are N computers and N sockets in a one-dimensional world. The coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i. It is guaranteed that these 2N coordinates are pairwise distinct. Snuke wants to connect each computer to a socket using a cable. Each socket can be connected to only one computer. In how many ways can he minimize the total length of the cables? Compute the answer modulo 10^9+7.
import sys import numpy as np read = sys.stdin.read N, *ab = map(int, read().split()) mod = 10 ** 9 + 7 a = np.array(ab[:N], np.int64) b = np.array(ab[N:], np.int64) a.sort() b.sort() idx = np.searchsorted(b, a) print(0)
s304073541
Accepted
278
27,484
566
import sys from operator import itemgetter read = sys.stdin.read N, *ab = map(int, read().split()) mod = 10 ** 9 + 7 ab = list(zip(ab, [0] * N + [1] * N)) ab.sort(key=itemgetter(0)) remain_pc = 0 remain_power = 0 answer = 1 for x, p in ab: if p == 0: if remain_power == 0: remain_pc += 1 continue answer *= remain_power remain_power -= 1 else: if remain_pc == 0: remain_power += 1 continue answer *= remain_pc remain_pc -= 1 answer %= mod print(answer)
s212244612
p02414
u012062731
1,000
131,072
Wrong Answer
20
7,616
539
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
n, m, l = map(int, input().split()) # n = 3, c = 2, l = 3 a_matrix = [list(map(int, input().split())) for row in range(n)] # [[1, 2], [0, 3], [4, 5]] b_matrix = [list(map(int, input().split())) for row in range(m)] # [[1, 2, 1], [0, 3, 2]] result_matrix = [[0 for x in range(l)] for y in range(n)] # [[0, 0, 0], [0, 0, 0], [0, 0, 0]] print(result_matrix) for i in range(n): for j in range(l): for k in range(m): result_matrix[i][j] += a_matrix[i][k] * b_matrix[k][j] for i in range(n): print(' '.join(map(str, result_matrix[i])))
s176105612
Accepted
510
8,896
518
n, m, l = map(int, input().split()) # n = 3, c = 2, l = 3 a_matrix = [list(map(int, input().split())) for row in range(n)] # [[1, 2], [0, 3], [4, 5]] b_matrix = [list(map(int, input().split())) for row in range(m)] # [[1, 2, 1], [0, 3, 2]] result_matrix = [[0 for x in range(l)] for y in range(n)] # [[0, 0, 0], [0, 0, 0], [0, 0, 0]] for i in range(n): for j in range(l): for k in range(m): result_matrix[i][j] += a_matrix[i][k] * b_matrix[k][j] for i in range(n): print(' '.join(map(str, result_matrix[i])))
s152367606
p04043
u629540524
2,000
262,144
Wrong Answer
17
2,940
86
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 = input().split() print('Yes' if a.count('5') == 2 and a.count('7') == 1 else 'No')
s540025696
Accepted
17
2,940
78
a = input() print('YES' if a.count('5') == 2 and a.count('7') == 1 else 'NO')
s641948024
p02866
u571969099
2,000
1,048,576
Wrong Answer
115
14,396
281
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition: * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.
n = int(input()) d = [int(i) for i in input().split()] a = [0] * n for i in d: a[i] += 1 if d[0] != 0: print(0) else: j = 1 for i in range(n - 1): if a[i] == 0: break j *= a[i] ** a[i + 1] j %= 998244353 print(a) print(j)
s153777833
Accepted
126
14,396
275
n = int(input()) d = [int(i) for i in input().split()] a = [0] * n k = 0 for i in d: a[i] += 1 k=max(k,i) if d[0] != 0: print(0) elif a[0] != 1: print(0) else: j = 1 for i in range(k): j *= a[i] ** a[i + 1] j %= 998244353 print(j)
s062215171
p03433
u190079347
2,000
262,144
Wrong Answer
17
2,940
85
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input()) a = int(input()) if n % 500 <= a: print("YES") else: print("NO")
s997369149
Accepted
17
2,940
85
n = int(input()) a = int(input()) if n % 500 <= a: print("Yes") else: print("No")
s395633984
p03377
u294385082
2,000
262,144
Wrong Answer
17
2,940
87
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A,B,X = map(int,input().split()) if A <= X <= A+B : print("Yes") else : print("No")
s985859041
Accepted
17
2,940
87
A,B,X = map(int,input().split()) if A <= X <= A+B : print("YES") else : print("NO")
s194382911
p03338
u265281278
2,000
1,048,576
Wrong Answer
17
3,060
128
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
N = int(input()) S = input() ans = 0 for i in range(1,N): x = set(S[:i]) and set(S[i:]) ans = max(ans,len(x)) print(ans)
s527369613
Accepted
17
2,940
126
N = int(input()) S = input() ans = 0 for i in range(1,N): x = set(S[:i]) & set(S[i:]) ans = max(ans,len(x)) print(ans)
s159462724
p04029
u451017206
2,000
262,144
Wrong Answer
17
2,940
37
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)
s188441235
Accepted
18
2,940
38
N = int(input()) print(N * (N + 1)//2)
s459283168
p02260
u456917014
1,000
131,072
Wrong Answer
20
5,592
207
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
n=int(input()) l=list(map(int,input().split())) count=0 for i in range(n): m=i for j in range(i,n): if l[j]<l[m]: m=j l[i],l[m]=l[m],l[i] count+=1 print(*l) print(count)
s508557251
Accepted
20
5,608
230
n=int(input()) l=list(map(int,input().split())) count=0 for i in range(n): m=i for j in range(i,n): if l[j]<l[m]: m=j l[i],l[m]=l[m],l[i] if l[i]!=l[m]: count+=1 print(*l) print(count)
s015970135
p02259
u865220118
1,000
131,072
Wrong Answer
20
5,592
684
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
A = [] LENGTH =int(input()) A = input().split() N = 0 M = LENGTH - 1 CHANGE = 0 while N <= LENGTH -1 : M = LENGTH - 1 print ('N=',N) # for j = A.length-1 downto i+1 while M >= N + 1: print ('-M=',M) # if A[j] < A[j-1] if A[M] < A[M-1] : tmp = A[M-1] A[M-1] = A[M] A[M] = tmp CHANGE += 1 M -= 1 N += 1 print(" ".join(map(str,A))) print (CHANGE)
s553320550
Accepted
20
5,600
695
A = [] LENGTH =int(input()) A = input().split() N = 0 M = LENGTH - 1 CHANGE = 0 while N <= LENGTH -1 : M = LENGTH - 1 # print ('N=',N) # for j = A.length-1 downto i+1 while M >= N + 1: # print ('-M=',M) # if A[j] < A[j-1] if int(A[M]) < int(A[M-1]) : tmp = A[M-1] A[M-1] = A[M] A[M] = tmp CHANGE += 1 M -= 1 N += 1 print(" ".join(map(str,A))) print (CHANGE)
s317598015
p03796
u703890795
2,000
262,144
Wrong Answer
51
2,940
82
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()) s = 1 for i in range(1, N+1): s *= i s %= (7 + 1E+9) print(s)
s215632958
Accepted
50
2,940
87
N = int(input()) s = 1 for i in range(1, N+1): s *= i s %= (7 + 1E+9) print(int(s))
s544975059
p03673
u385309449
2,000
262,144
Wrong Answer
2,104
25,156
107
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
n = int(input()) a = list(map(int,input().split())) b = [] for i in a: b.append(i) b = b[::-1] print(b)
s203713851
Accepted
68
27,204
180
n = int(input()) a = list(map(str,input().split())) b = a[::-1] b = b[::2] if n%2 == 0: c = a[::2] else: c = a[1::2] d = b+c if n >= 2: print(' '.join(d)) else: print(a[0])
s968350468
p02613
u674190122
2,000
1,048,576
Wrong Answer
152
16,296
252
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.
result = [] for _ in range(int(input())): result.append(input()) print("AC X {}".format(result.count("AC"))) print("WA X {}".format(result.count("WA"))) print("TLE X {}".format(result.count("TLE"))) print("RE X {}".format(result.count("RE")))
s614507616
Accepted
147
16,196
245
result = [] for _ in range(int(input())): result.append(input()) print("AC x {}".format(result.count("AC"))) print("WA x {}".format(result.count("WA"))) print("TLE x {}".format(result.count("TLE"))) print("RE x {}".format(result.count("RE")))
s750473663
p03729
u840570107
2,000
262,144
Wrong Answer
18
3,060
185
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
lis = input().split() lis_a = lis[0][len(lis[0])-1] lis_b = lis[1][len(lis[1])-1] lis_c = lis[2][len(lis[2])-1] if lis_a == lis_b and lis_b == lis_c: print("YES") else: print("NO")
s305700403
Accepted
17
3,060
195
lis = input().split() lis_a = lis[0][len(lis[0])-1] lis_bt = lis[1][0] lis_bf = lis[1][len(lis[1])-1] lis_c = lis[2][0] if lis_a == lis_bt and lis_bf == lis_c: print("YES") else: print("NO")
s326874377
p03813
u863442865
2,000
262,144
Wrong Answer
17
2,940
79
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.
x = int(input()) s = x // 11 a = x % 11 print(s*2+2) if a > 6 else print(s*2+1)
s664918802
Accepted
17
2,940
53
print('ABC') if int(input()) < 1200 else print('ARC')
s609316362
p03054
u052499405
2,000
1,048,576
Wrong Answer
393
3,784
664
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.
h, w, n = [int(item) for item in input().split()] sr, sc = [int(item) for item in input().split()] s = input().rstrip() t = input().rstrip() # l, r, u, d move_limit = [-(w-sr+1), -sr, -(h-sc+1), -sc] max_move = [0] * 4 move = [0] * 4 direction = "LRUD" reverse = "RLDU" for i in range(n): move[direction.index(s[i])] += 1 max_move[direction.index(s[i])] = max(move[direction.index(s[i])], max_move[direction.index(s[i])]) if move[reverse.index(t[i])] < move_limit[reverse.index(t[i])]: move[reverse.index(t[i])] -= 1 if max_move[0] >= sr or max_move[1] > w-sr or max_move[2] >= sc or max_move[3] > h-sc: print("NO") else: print("YES")
s626117054
Accepted
247
3,888
857
h, w, n = [int(item) for item in input().split()] sr, sc = [int(item) for item in input().split()] sr -= 1 sc -= 1 s = input().rstrip() t = input().rstrip() x = sc # Check left for i in range(n): if s[i] == "L": x -= 1 if x < 0: print("NO") exit() if t[i] == "R" and x+1 < w-1: x += 1 x = sc # Check Right for i in range(n): if s[i] == "R": x += 1 if x > w-1: print("NO") exit() if t[i] == "L" and x > 0: x -= 1 y = sr # Check Down for i in range(n): if s[i] == "D": y += 1 if y > h-1: print("NO") exit() if t[i] == "U" and y > 0: y -= 1 y = sr # Check up for i in range(n): if s[i] == "U": y -= 1 if y < 0: print("NO") exit() if t[i] == "D" and y+1 < h-1: y += 1 print("YES")
s064914879
p02399
u731710433
1,000
131,072
Wrong Answer
30
7,480
72
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a, b = map(float, input().split()) print(int(a // b), int(a % b), a / b)
s456933563
Accepted
20
7,728
94
a, b = [int(x) for x in input().split()] print("{0} {1} {2:.5f}".format(a // b, a % b, a / b))
s672416299
p02408
u635647915
1,000
131,072
Wrong Answer
30
7,780
457
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.
#coding:utf-8 def ch2int(a): s=["S","H","C","D"] for i,b in enumerate(s): if a==b: return i def int2ch(i): s=["S","H","C","D"] return s[i] n=int(input()) card=[[0 for i in range(0,4)]for j in range(0,13)] for i in range(n): c,x=list(map(str,input().split())) card[int(x)-1][ch2int(c)]=1 for i,x in enumerate(card): for j,y in enumerate(x): if y==0: print(int2ch(j)+" "+str(i+1))
s912385780
Accepted
20
7,712
457
#coding:utf-8 def ch2int(a): s=["S","H","C","D"] for i,b in enumerate(s): if a==b: return i def int2ch(i): s=["S","H","C","D"] return s[i] n=int(input()) card=[[0 for i in range(0,13)]for j in range(0,4)] for i in range(n): c,x=list(map(str,input().split())) card[ch2int(c)][int(x)-1]=1 for i,x in enumerate(card): for j,y in enumerate(x): if y==0: print(int2ch(i)+" "+str(j+1))
s542307176
p03578
u966601619
2,000
262,144
Wrong Answer
2,105
35,420
312
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
q=input() x=[int(i) for i in input().split()] cnt=input() j=0 y=[int(i) for i in input().split()] for k in range(len(y)) : for i in range(len(x)) : if x[i] == y[k] : del x[i] break if i+1 == len(x) : print('NO') j=1 break if j==0 : print('YES')
s103935280
Accepted
305
41,816
443
q=input() x=[int(i) for i in input().split()] cnt=input() y=[int(i) for i in input().split()] if max(x) >= max(y): MAX=max(x) else: MAX=max(y) dic = {} for k in x : if k in dic.keys() : dic[k] += 1 else : dic[k] = 1 for i in y : if i in dic.keys() : dic[i] -= 1 if dic[i] == -1 : print('NO') exit() else : print('NO') exit() print('YES')
s770316780
p03470
u401077816
2,000
262,144
Wrong Answer
17
2,940
80
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
N = int(input()) A = list(map(int, input().split())) print(len(set(sorted(A))))
s741839572
Accepted
17
2,940
76
N = int(input()) l = sorted([input() for _ in range(N)]) print(len(set(l)))
s018667884
p03089
u731368968
2,000
1,048,576
Wrong Answer
17
3,064
420
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
N=int(input()) b = list(map(int, input().split())) ans=[] for i in range(N): print(b) #j:index of delete + 1(ans base) j = 1 if j < len(b): while b[j] == j + 1: j += 1 if j == len(b):break if b[j - 1] == j: del b[j-1] ans.append(j) else: print(-1) import sys sys.exit() for i in range(len(ans)-1,-1,-1): print(ans[i])
s040202527
Accepted
17
3,064
422
N=int(input()) b = list(map(int, input().split())) ans=[] #delete N times for i in range(N): #j:index of delete + 1(ans base) j = False for k in range(len(b)-1,-1,-1): if b[k] == k + 1: j = True del b[k] ans.append(k+1) break if not j: print(-1) import sys sys.exit() for i in range(len(ans) - 1, -1, -1): print(ans[i])
s822957986
p03549
u463655976
2,000
262,144
Wrong Answer
19
3,188
78
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
N, M = map(int, input().split()) print((1900 * M + 100 * (N-M)) / pow(1/2, M))
s240115259
Accepted
18
2,940
96
N, M = map(int, input().split()) print("{:.0f}".format((1900 * M + 100 * (N-M)) / pow(1/2, M)))
s345213768
p03836
u752513456
2,000
262,144
Wrong Answer
23
3,064
292
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()) s = '' s += 'R' * (tx - sx) + 'U' * (ty - sy) s += 'L' + 'D' * (ty - sy - 1) + 'L' * (tx - sx - 1) + 'D' s += 'D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L' s+= 'U' + 'L' * 2 + 'D' * (ty - sy - 1) + 'L' * (tx - sx - 1) + 'D' + 'R' print(s)
s223291104
Accepted
22
3,064
256
sx, sy, tx, ty = map(int, input().split()) s = '' s += 'U' * (ty - sy) + 'R' * (tx - sx) s += 'D' * (ty - sy) + 'L' * (tx - sx) s += 'L' + 'U' * (ty - sy + 1) + 'R' * (tx - sx + 1) + 'D' s += 'R' + 'D' * (ty - sy + 1) + 'L' * (tx -sx + 1) + 'U' print(s)
s943553690
p03192
u858523893
2,000
1,048,576
Wrong Answer
18
2,940
18
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N?
input().count("2")
s831356119
Accepted
20
2,940
25
print(input().count("2"))
s873401721
p03149
u065793287
2,000
1,048,576
Wrong Answer
18
2,940
87
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
a = list(map(int,input().split())) a.sort() print( 'YES' if a == [1,9,7,4] else 'NO' )
s063261084
Accepted
18
2,940
87
a = list(map(int,input().split())) a.sort() print( 'YES' if a == [1,4,7,9] else 'NO' )
s355021238
p02742
u902380746
2,000
1,048,576
Wrong Answer
18
3,060
217
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:
import sys import math import bisect def main(): n, m = map(int, input().split()) a = (m + 1) // 2 b = m // 2 ans = a * (n + 1) // 2 + b * n // 2 print(ans) if __name__ == "__main__": main()
s677655376
Accepted
17
3,060
278
import sys import math import bisect def main(): n, m = map(int, input().split()) if n == 1 or m == 1: print(1) else: ans = ((m + 1) // 2) * ((n + 1) // 2) ans += (m // 2) * (n // 2) print(ans) if __name__ == "__main__": main()
s419224621
p03471
u281303342
2,000
262,144
Wrong Answer
685
3,060
178
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 = map(int,input().split()) for i in range(N+1): for j in range(N-i+1): if i*10000 + j*5000 + (N-(i+j))*1000 == Y: print(i,j,N-(i+j)) break
s269323620
Accepted
712
3,060
537
# python 3.4.3 import sys input = sys.stdin.readline # ------------------------------------------------------------- # library # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- N,Y = map(int,input().split()) ans = [-1,-1,-1] for i in range(N+1): for j in range(N+1-i): if Y == 10000*i + 5000*j + 1000*(N-i-j): ans = [i,j,N-i-j] print(" ".join(map(str,ans)))
s143581906
p02602
u377834804
2,000
1,048,576
Wrong Answer
1,705
25,184
222
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
N, K = map(int, input().split()) A = [] for i, a in enumerate(input().split()): if i < K: A.append(a) continue else: A.append(a) x = A.pop(0) if x < a: print('Yes') else: print('No')
s835318911
Accepted
1,654
31,544
238
N, K = map(int, input().split()) A = [] for i, a in enumerate(list(map(int, input().split()))): if i < K: A.append(a) continue else: A.append(a) x = A.pop(0) if x < a: print('Yes') else: print('No')
s897746303
p02853
u368796742
2,000
1,048,576
Wrong Answer
17
3,064
412
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
x,y = map(int, input().split()) if x > 3 and y > 3: print("0") elif x == 1: if y == 1: print("100000") elif y == 2: print("50000") elif y == 3: print("40000") elif x == 2: if y == 1: print("500000") elif y == 2: print("40000") elif y == 3: print("30000") elif x == 3: if y == 1: print("400000") elif y == 2: print("30000") elif y == 3: print("20000")
s487102081
Accepted
17
3,064
250
x,y = map(int,input().split()) def point(a): if a == 1: return 300000 elif a == 2: return 200000 elif a == 3: return 100000 else: return 0 c = point(x) b = point(y) if x == 1 and y == 1: print(1000000) else: print(c+b)
s232051202
p03573
u117193815
2,000
262,144
Wrong Answer
17
2,940
68
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
a,b,c=map(int, input().split()) if a==b: print(c) else: print(a)
s550372279
Accepted
17
3,064
91
a,b,c=map(int, input().split()) if a==b: print(c) elif a==c: print(b) else: print(a)
s156151691
p02669
u923270446
2,000
1,048,576
Wrong Answer
23
9,136
458
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
t = int(input()) for i in range(t): n, a, b, c, d = map(int, input().split()) ans = 0 for i in range(60): if n == 1: ans += d n = 0 break if n % 5 == 0: ans += c n //= 5 elif n % 3 == 0: ans += b n //= 3 elif n % 2 == 0: ans += a n //= 2 else: ans += d n += 1 print(ans)
s133993692
Accepted
286
11,004
509
def dfs(n): if n == 1: return d if n == 0: return 0 if n in dic: return dic[n] ans = min(n * d, dfs(n // 2) + a + (n % 2) * d, dfs((n + 1) // 2) + a + ((-1 * n) % 2) * d, dfs(n // 3) + b + (n % 3) * d, dfs((n + 2) // 3) + b + ((-1 * n) % 3) * d, dfs(n // 5) + c + (n % 5) * d, dfs((n + 4) // 5) + c + ((-1 * n) % 5) * d) dic[n] = ans return ans t = int(input()) for i in range(t): n, a, b, c, d = map(int, input().split()) dic = dict() print(dfs(n))
s024264750
p03712
u530383736
2,000
262,144
Wrong Answer
24
3,952
305
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.
# -*- coding: utf-8 -*- H,W = list(map(int, input().rstrip().split())) a_list = [list(input().strip()) for _ in range(H)] #----- b_list=[ ["#" for c in range(W+2)] for r in range(H+2) ] for i in range(H): for j in range(W): b_list[i+1][j+1] = a_list[i][j] for li in b_list: print(*li)
s414538360
Accepted
25
4,596
312
# -*- coding: utf-8 -*- H,W = list(map(int, input().rstrip().split())) a_list = [list(input().strip()) for _ in range(H)] #----- b_list=[ ["#" for c in range(W+2)] for r in range(H+2) ] for i in range(H): for j in range(W): b_list[i+1][j+1] = a_list[i][j] for li in b_list: print(*li,sep="")
s194254079
p04029
u777394984
2,000
262,144
Wrong Answer
21
3,316
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((1+n)*n/2)
s223641914
Accepted
23
3,316
37
n=int(input()) print(int((1+n)*n/2))
s503464086
p03657
u457957084
2,000
262,144
Wrong Answer
17
2,940
122
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
a, b = map(int,input().split()) if (a % 3 != 0) and ( b % 3 != 0): print("Impossible") else: print("Possible")
s537994892
Accepted
17
2,940
141
a, b = map(int,input().split()) if (a % 3 == 0) or( b % 3 == 0) or ((a + b) % 3 ==0): print("Possible") else: print("Impossible")
s176564177
p03501
u344888046
2,000
262,144
Wrong Answer
26
9,100
53
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
N, A, B = map(int, input().split()) print(N * A + B)
s944688488
Accepted
28
9,092
80
N, A, B = map(int, input().split()) ans = N * A if N * A < B else B print(ans)
s380315834
p02615
u608755339
2,000
1,048,576
Wrong Answer
238
31,432
170
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 = sorted([int(i) for i in input().split()], reverse=True) S = A[0] step = 2 print(S) for i in range(1,N-1): S += (A[(i+1)//2]) print(S) print(S)
s707535539
Accepted
150
31,500
150
N = int(input()) A = sorted([int(i) for i in input().split()], reverse=True) S = A[0] step = 2 for i in range(1,N-1): S += (A[(i+1)//2]) print(S)
s586676636
p02850
u602740328
2,000
1,048,576
Wrong Answer
2,105
29,184
581
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
from functools import reduce from operator import mul N = int(input()) ab = [tuple(map(int, input().split())) for _ in range(N-1)] print(N, ab) E_n = {k: 0 for k in ab} for i in range(1,N+1): items = {k:v for k,v in E_n.items() if i in k} c = 0 for k in items.keys(): if items[k] != 0: continue while True: c += 1 if c not in items.values(): items[k] = c break for k,v in items.items(): E_n[k] = v if reduce(mul, E_n.values()) != 0: break print(len(set(E_n.values()))) for k in sorted(E_n.keys()): print(E_n[k])
s227730394
Accepted
605
49,600
417
N = int(input()) edge = {} tree = [[] for i in range(N)] colors = [1]*(N-1) c_p = [[] for i in range(N)] for i in range(N-1): a,b = map(int,input().split()) a,b = a-1,b-1 tree[a].append(b) edge[(a,b)] = i for i in range(N): c = 1 for v_c in tree[i]: while c in c_p[i]: c+=1 colors[edge[(i,v_c)]] = c c_p[v_c].append(c) c+=1 print(max(colors)) print(*colors, sep="\n")
s027836696
p02608
u243748614
2,000
1,048,576
Wrong Answer
2,206
9,204
497
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).
from math import trunc, sqrt def p(x,y,z): return x**2+y**2+z**2+x*y+y*z+z*x def perm(x,y,z): if x==y and y==z and z==x: return 1 if x!=y and y!=z and z!=x: return 6 return 3 def f(n): mn=trunc(sqrt(n // 3))+1 k=0 for x in range(1,mn+1): for y in range(x,mn+1): for z in range(y,mn+1): if p(x,y,z)==n: k += perm(x,y,z) return k N=int(input()) for n in range(1,N): print(n, f(n))
s032108665
Accepted
235
9,252
245
N=int(input()) a=[0]*N x=1 while x*x<=N: y=1 while x*x+y*y+x*y<=N: z=1 while z*z+x*x+y*y+x*y+z*y+z*x<=N: a[z*z+x*x+y*y+x*y+z*y+z*x-1]+=1 z+=1 y+=1 x+=1 for n in a: print(n)
s498309868
p03854
u472534477
2,000
262,144
Wrong Answer
18
3,188
370
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() i=0 while True: flag = False if S[i:i+7] == "dreamer": i += 7 flag = True if S[i:i+6] == "eraser": i += 6 flag = True if S[i:i+5] == "erase" or S[i:i+5] == "dream": i += 5 flag = True if not flag: break if i == len(S): print("Yes") else: print("No")
s642435279
Accepted
18
3,188
128
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") print("YES" if len(s)==0 else "NO")
s261435705
p03944
u589969467
2,000
262,144
Wrong Answer
29
9,076
454
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
w,h,n = map(int,input().split()) #print(x_list) #print(y_list) min_x = 0 max_x = w min_y = 0 max_y = h for i in range(n): x,y,a = map(int,input().split()) if a==1: min_x = x elif a==2: max_x = x elif a==3: min_y = y else: max_y = y if min_x > max_x or min_y > max_y: print(0) else: print((max_x-min_y)*(max_y-min_y))
s836923603
Accepted
29
9,100
498
w,h,n = map(int,input().split()) #print(x_list) #print(y_list) min_x = 0 max_x = w min_y = 0 max_y = h for i in range(n): x,y,a = map(int,input().split()) if a==1: min_x = max(min_x,x) elif a==2: max_x = min(max_x,x) elif a==3: min_y = max(min_y,y) else: max_y = min(max_y,y) if min_x > max_x or min_y > max_y: print(0) else: print((max_x-min_x)*(max_y-min_y))
s862226060
p03360
u936985471
2,000
262,144
Wrong Answer
19
2,940
80
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?
l=list(map(int,input().split())) k=int(input()) print(sum(l)+max(l)**k-max(l))
s048957645
Accepted
17
2,940
73
A=list(map(int,input().split())) print(sum(A)+max(A)*(2**int(input())-1))
s814248298
p03573
u126747509
2,000
262,144
Wrong Answer
22
3,316
229
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
from collections import defaultdict def main(): d = defaultdict(lambda: 0) for i in input().split(): d[int(i)] += 1 d = {v:k for k, v in d.items()} print(d[2]) if __name__ == "__main__": main()
s970267132
Accepted
21
3,316
229
from collections import defaultdict def main(): d = defaultdict(lambda: 0) for i in input().split(): d[int(i)] += 1 d = {v:k for k, v in d.items()} print(d[1]) if __name__ == "__main__": main()
s729025168
p03993
u502175663
2,000
262,144
Wrong Answer
2,103
16,308
255
There are N rabbits, numbered 1 through N. The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i. For a pair of rabbits i and j (i<j), we call the pair (i,j) a _friendly pair_ if the following condition is met. * Rabbit i likes rabbit j and rabbit j likes rabbit i. Calculate the number of the friendly pairs.
n = int(input()) line = input().split(' ') total_list =[] for i in range(0,n): total = i + int(line[i]) total_list.append(total) print(total_list) answer = 0 for i in range(n *2 -1): if total_list.count(i) == 2: answer += 1 print(answer)
s725586290
Accepted
113
10,740
158
n = int(input()) a = input().split(' ') t = 0 for o in range(n): i = o + 1 b = int(a[o]) - i if i == int(a[o + b]): t += 1 print(int(t / 2))
s753410179
p02233
u216229195
1,000
131,072
Wrong Answer
20
7,604
152
Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula: \begin{equation*} fib(n)= \left \\{ \begin{array}{ll} 1 & (n = 0) \\\ 1 & (n = 1) \\\ fib(n - 1) + fib(n - 2) & \\\ \end{array} \right. \end{equation*}
def fib(n): if n < 0: print("error") exit() if n < 2: result = 1 result = fib(n-1) + fib(n-2) return result n = int(input()) fib(n)
s052848630
Accepted
20
5,604
218
def fibr(n): if arr[n] != 0: return arr[n] if n < 2: arr[n] = 1 else: arr[n] = fibr(n-1) + fibr(n-2) return arr[n] n = int(input()) arr = [0 for i in range(n+1)] print(fibr(n))
s800568439
p02748
u490489966
2,000
1,048,576
Wrong Answer
464
18,612
297
You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
#B a,b,m=map(int,input().split()) al=list(map(int,input().split())) bl=list(map(int,input().split())) amin=min(al) bmin=min(bl) minp=amin+bmin print(amin,bmin) for i in range(m): num=list(map(int,input().split())) price=al[num[0]-1]+bl[num[1]-1]-num[2] minp=min(price,minp) print(minp)
s446408584
Accepted
458
18,612
280
#B a,b,m=map(int,input().split()) al=list(map(int,input().split())) bl=list(map(int,input().split())) amin=min(al) bmin=min(bl) minp=amin+bmin for i in range(m): num=list(map(int,input().split())) price=al[num[0]-1]+bl[num[1]-1]-num[2] minp=min(price,minp) print(minp)
s297675886
p03448
u698348858
2,000
262,144
Wrong Answer
30
3,064
268
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.
#coding:utf-8 a = int(input()) b = int(input()) c = int(input()) x = int(input()) cnt = 0 for i in range(a): for j in range(b): for k in range(c): p = a * 500 + b * 100 + c * 50 if p == x: cnt += 1 elif p > x: break print(cnt)
s213251245
Accepted
48
3,064
280
#coding:utf-8 a = int(input()) b = int(input()) c = int(input()) x = int(input()) cnt = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): p = i * 500 + j * 100 + k * 50 if p > x: break if p == x: cnt += 1 print(cnt)
s126579976
p02401
u104931506
1,000
131,072
Time Limit Exceeded
40,000
7,864
179
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.
a, op, b = input().split() while True: if op == '+' : print(a + b) elif op == '-' : print(a - b) elif op == '/' : print(a / b) elif op == '*' : print(a * b) else : break
s214950619
Accepted
40
7,656
203
while True: a, op, b = input().split() a = int(a) b = int(b) if op == '+': print(a + b) elif op == '-': print(a - b) elif op == '/': print(a // b) elif op == '*': print(a * b) else: break
s295979512
p03455
u323532272
2,000
262,144
Wrong Answer
17
2,940
82
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 == 0: print('Even') else: print('Odd')
s764873628
Accepted
17
2,940
85
a, b = map(int, input().split()) if a*b%2 == 0: print('Even') else: print('Odd')
s788949008
p03130
u989623817
2,000
1,048,576
Wrong Answer
17
3,064
392
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
a1, b1 = map(int, input().split()) a2, b2 = map(int, input().split()) a3, b3 = map(int, input().split()) cnt = {1: 0, 2: 0, 3: 0, 4: 0} for i in range(4): if not i+1 in [a1, a2, a3, b1, b2, b3]: print('NO') exit() lis = [a1, a2, a3, b1, b2, b3] c = 0 for l in range(4): cnt = lis.count(l+1) if cnt > 1: c += 1 if c <= 2: print('NO') print('YES')
s987488845
Accepted
17
3,064
401
a1, b1 = map(int, input().split()) a2, b2 = map(int, input().split()) a3, b3 = map(int, input().split()) cnt = {1: 0, 2: 0, 3: 0, 4: 0} for i in range(4): if not i+1 in [a1, a2, a3, b1, b2, b3]: print('NO') exit() lis = [a1, a2, a3, b1, b2, b3] c = 0 for l in range(4): cnt = lis.count(l+1) if cnt > 1: c += 1 if c < 2: print('NO') exit() print('YES')
s164764282
p02742
u571395477
2,000
1,048,576
Wrong Answer
17
2,940
208
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:
import math def main(): H, W = [int(_) for _ in input().split()] if H % 2 == 0 or W % 2 == 0: m = (H * W) /2 else: m = (H * W) /2 m = int(math.ceil(m)) print(m) main()
s983001390
Accepted
18
3,060
294
import sys import math def main(): H, W = [int(_) for _ in input().split()] if H == 1 or W == 1: m = 1 print(int(m)) sys.exit() elif H % 2 == 1 and W % 2 == 1: m = (H * W) // 2 + 1 else: m = (H * W) // 2 print(int(m)) main()
s803407351
p03379
u962127640
2,000
262,144
Wrong Answer
2,109
34,196
233
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.
import numpy as np N= int(input()) a = list(map(int, input().split(' '))) a = np.array(a) ret = [] for i in range(N): ind = np.ones(N, dtype=bool) ind[i] = False tmp = a[ind] ret.append(int(np.median(tmp))) print(ret)
s525779032
Accepted
413
34,156
214
import numpy as np N= int(input()) a = list(map(int, input().split(' '))) sort_a = sorted(a) small = sort_a[N//2-1] big = sort_a[N//2] for aa in a: if aa < big: print(big) else: print(small)
s284051930
p03359
u777846995
2,000
262,144
Wrong Answer
17
2,940
118
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?
x, y = map(int, input().split()) cnt = 0 for i in range(1, 13): if x == i and y == i: cnt += 1 print(cnt)
s639572936
Accepted
17
2,940
74
x, y = map(int, input().split()) if x <= y: print(x) else: print(x-1)
s798753036
p03502
u061545295
2,000
262,144
Wrong Answer
17
2,940
89
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N = input() f = [int(i) for i in N] if N%f == 0: print("Yes") else: print('No')
s915782919
Accepted
17
2,940
110
N = input() num = [int(i) for i in N] f = sum(num) if int(N)%f == 0: print("Yes") else: print('No')
s534572122
p04029
u701318346
2,000
262,144
Wrong Answer
17
2,940
40
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((1 + N) * N / 2)
s162981110
Accepted
17
2,940
45
N = int(input()) print(int((1 + N) * N / 2))
s066801736
p03644
u527190736
2,000
262,144
Wrong Answer
17
2,940
188
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()) x = 1 cnt = 0 list = [] for i in range(n): i = x while i % 2 == 0: i /= 2 cnt += 1 x += 1 list.append(cnt) cnt = 0 print(max(list))
s099147105
Accepted
17
2,940
196
n = int(input()) x = 1 cnt = 0 list = [] for i in range(n): i = x while i % 2 == 0: i = i//2 cnt += 1 x += 1 list.append(cnt) cnt = 0 print(2 ** max(list))
s620950634
p03371
u859897687
2,000
262,144
Wrong Answer
47
3,060
185
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
a,b,c,x,y=map(int,input().split()) if a+b>=c+c: print(a*x+b*y) else: ans=10000000000 for i in range(0,(max(x,y)+1)//2): k=c*2*i+a*(x-i)+b*(y-i) ans=min(ans,k) print(ans)
s511777933
Accepted
121
3,060
150
a,b,c,x,y=map(int,input().split()) ans=10000000000 for i in range(0,(max(x,y)+1)): k=c*2*i+a*max(0,(x-i))+max(0,b*(y-i)) ans=min(ans,k) print(ans)
s987175021
p03193
u518987899
2,000
1,048,576
Wrong Answer
18
3,188
160
There are N rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the i-th material are A_i \times B_i (A_i vertically and B_i horizontally). Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly H \times W. He is trying to obtain such a plate by choosing one of the N materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a 5 \times 3 material cannot be used as a 3 \times 5 plate. Out of the N materials, how many can produce an H \times W plate if properly cut?
import sys lines = [list(map(int, line.strip().split(' '))) for line in sys.stdin] print(sum([1 for h,w in lines[1:] if h <= lines[0][1] and w <= lines[0][2]]))
s210542012
Accepted
18
3,188
160
import sys lines = [list(map(int, line.strip().split(' '))) for line in sys.stdin] print(sum([1 for h,w in lines[1:] if lines[0][1] <= h and lines[0][2] <= w]))
s984572968
p00067
u847467233
1,000
131,072
Wrong Answer
30
5,620
1,085
地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ マスのデータを読み込んで、島の数を出力するプログラムを作成してください。
# AOJ 0067 The Number of Island # Python3 2018.6.16 bal4u # UNION-FIND library MAX = 12*12 id, size = [0]*MAX, [0]*MAX def init(n): for i in range(n): id[i], size[i] = i, 1 def root(i): while i != id[i]: id[i] = id[id[i]] i = id[i] return i def connected(p, q): return root(p) == root(q) def unite(p, q): i, j = root(p), root(q) if i == j: return if size[i] < size[j]: id[i] = j size[j] += size[i] else: id[j] = i size[i] += size[j] # UNION-FIND library arr = [[0 for r in range(12)] for c in range(12)] dr = [-1,0,1, 0 ] dc = [ 0,1,0,-1 ] while True: init(12*12) for r in range(12): arr[r] = list(map(int, input())) for r in range(12): print('r=', arr[r]) for r in range(12): for c in range(12): if arr[r][c] == 0: continue for i in range(4): nr, nc = r + dr[i], c + dc[i] if nr >= 0 and nr < 12 and nc >= 0 and nc < 12: if arr[nr][nc] == 1: unite(r*12+c, nr*12+nc) ans = 0 for r in range(12): for c in range(12): if arr[r][c] == 1 and root(r*12+c) == r*12+c: ans += 1 print(ans) try: input() except: break
s824486759
Accepted
30
5,608
1,045
# AOJ 0067 The Number of Island # Python3 2018.6.16 bal4u # UNION-FIND library MAX = 12*12 id, size = [0]*MAX, [0]*MAX def init(n): for i in range(n): id[i], size[i] = i, 1 def root(i): while i != id[i]: id[i] = id[id[i]] i = id[i] return i def connected(p, q): return root(p) == root(q) def unite(p, q): i, j = root(p), root(q) if i == j: return if size[i] < size[j]: id[i] = j size[j] += size[i] else: id[j] = i size[i] += size[j] # UNION-FIND library arr = [[0 for r in range(12)] for c in range(12)] dr = [-1, 0, 1, 0] dc = [ 0, 1, 0,-1] while True: init(12*12) for r in range(12): arr[r] = list(map(int, input())) for r in range(12): for c in range(12): if arr[r][c] == 0: continue for i in range(4): nr, nc = r + dr[i], c + dc[i] if nr >= 0 and nr < 12 and nc >= 0 and nc < 12: if arr[nr][nc] == 1: unite(r*12+c, nr*12+nc) ans = 0 for r in range(12): for c in range(12): if arr[r][c] == 1 and root(r*12+c) == r*12+c: ans += 1 print(ans) try: input() except: break
s436730464
p03610
u626468554
2,000
262,144
Wrong Answer
76
5,292
76
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 = list(input()) for i in range(1,len(s),2): print(s[i],end="") print()
s277091605
Accepted
68
5,292
76
s = list(input()) for i in range(0,len(s),2): print(s[i],end="") print()
s433879903
p04045
u488884575
2,000
262,144
Wrong Answer
35
3,064
528
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
import itertools N, K = input().split() P = input().split() a= sorted(set([str(i) for i in range(10)])-set(P)) b1 = itertools.product(a, repeat=len(N)) b2 = itertools.product(a, repeat=len(N)+1) ans=str() cnt=0 for i in b1: #print(type(i)) ans = "".join(i) if N <= ans: print(ans) cnt=1 break if cnt==1: for i in b2: ans = "".join(i) if N <= ans: print(ans) break
s421744213
Accepted
19
3,064
548
import itertools N, K = input().split() P = input().split() a= sorted(set([str(i) for i in range(10)])-set(P)) b1 = itertools.product(a, repeat=len(N)) b2 = itertools.product(a, repeat=len(N)+1) ans=str() cnt=0 for i in b1: #print(type(i)) ans = "".join(i) if N <= ans: print(ans) cnt=1 break if cnt==0: for i in b2: ans = "".join(i) #print(ans) if "0"+N <= ans: print(ans) break
s942125315
p03433
u421499233
2,000
262,144
Wrong Answer
17
2,940
125
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) A = int(input()) if N <= A: print("Yes") elif N - 500 <= A: print ("Yes") else: print("No")
s490810038
Accepted
17
2,940
93
N = int(input()) A = int(input()) r = N%500 if A >= r: print("Yes") else: print("No")
s904587578
p03067
u559346857
2,000
1,048,576
Wrong Answer
17
2,940
71
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=map(int,input().split()) print("YES" if a<c<b or b<c<a else "NO")
s981580960
Accepted
18
2,940
71
a,b,c=map(int,input().split()) print("Yes" if a<c<b or b<c<a else "No")
s861338851
p03680
u716660050
2,000
262,144
Wrong Answer
162
12,988
178
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
N=int(input()) a=[int(input())for i in range(N)] p=1 ok=False ans=0 for i in range(N): ans+=1 if p==2: ok=True break p=a[p-1] print(ans if ok else -1)
s946087932
Accepted
160
13,048
178
N=int(input()) a=[int(input())for i in range(N)] p=1 ok=False ans=0 for i in range(N): if p==2: ok=True break p=a[p-1] ans+=1 print(ans if ok else -1)
s590092663
p03573
u798260206
2,000
262,144
Wrong Answer
25
9,020
66
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
a = list(map(int,input().split())) print(sum(a)-sum(list(set(a))))
s459807971
Accepted
33
9,128
144
a = list(map(int,input().split())) if a[0]!=a[1]and a[0]!=a[2]: print(a[0]) elif a[1]!=a[0]and a[1]!=a[2]: print(a[1]) else: print(a[2])
s074099561
p03493
u348868667
2,000
262,144
Wrong Answer
17
2,940
90
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
S = input() count = 0 for i in range(3): if S[i] == 1: count += 1 print(count)
s059615988
Accepted
17
2,940
92
S = input() count = 0 for i in range(3): if S[i] == "1": count += 1 print(count)
s191578545
p04012
u281303342
2,000
262,144
Wrong Answer
21
3,316
173
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.
from collections import Counter W = input() Ans = "YES" C = Counter(W).items() for c in C: _x,cnt = c if cnt%2 != 0: Ans = "NO" break print(Ans)
s858613553
Accepted
20
3,316
526
# python 3.4.3 import sys input = sys.stdin.readline # import numpy as np from collections import Counter # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- W = input().rstrip() C = Counter(W).most_common() ans = "Yes" for _,cnt in C: if cnt%2 == 1: ans = "No" break print(ans)
s562527423
p02406
u682153677
1,000
131,072
Wrong Answer
20
5,592
167
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
# -*- coding: utf-8 -*- n = int(input()) i = 1 while True: if i % 3 == 0 | i % 10 == 3: print(' {0}'.format(i)) i += 1 if i > n: break
s345331143
Accepted
70
6,532
411
# -*- coding: utf-8 -*- from functools import reduce n = int(input()) i = 1 while True: a = [int(x) for x in list(str(i))] if 3 in a: print(" {0}".format(int(reduce(lambda x, y: x + y, [str(x) for x in a]))), end='') elif sum(a) % 3 == 0: print(" {0}".format(int(reduce(lambda x, y: x + y, [str(x) for x in a]))), end='') i += 1 if i > n: print() break
s535452182
p02398
u941509088
1,000
131,072
Wrong Answer
20
7,608
113
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
a, b, c = map(int, input().split()) numbers_list = [i for i in range(a,b+1) if i%c==0] print(len(numbers_list))
s787558495
Accepted
60
7,720
117
a, b, c = map(int, input().split()) numbers_list = [i for i in range(a,b+1) if c % i == 0] print(len(numbers_list))
s242061075
p03719
u646792990
2,000
262,144
Wrong Answer
17
2,940
102
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 = input().split() if a[-1] == b[0] and b[-1] == c[0]: print('YES') else: print('NO')
s971263887
Accepted
17
2,940
98
a, b, c = map(int, input().split()) if a <= c and c <= b: print('Yes') else: print('No')
s949098648
p02390
u120055135
1,000
131,072
Wrong Answer
20
5,580
106
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
S = int(input()) h = int(S/360) m = int((S - h*360)/60) s = int(S - h*360 -m*60) print(h, ':', m, ':', s)
s900517760
Accepted
20
5,588
118
S = int(input()) h = int(S/3600) m = int((S - h*3600)/60) s = int(S - h*3600 - m*60) print(h, ':', m, ':', s, sep='')
s905234598
p03493
u100652283
2,000
262,144
Wrong Answer
17
2,940
128
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
s = input() print(s) count = 0 if s[0] == '1': count+=1 if s[1] == '1': count+=1 if s[2] == '1': count+=1 print(count)
s455106065
Accepted
17
2,940
119
s = input() count = 0 if s[0] == '1': count+=1 if s[1] == '1': count+=1 if s[2] == '1': count+=1 print(count)
s707111910
p03556
u441201379
2,000
262,144
Wrong Answer
17
2,940
72
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
from math import sqrt, floor n = int(input()) print((floor(sqrt(n)))^2)
s387732979
Accepted
17
2,940
79
from math import sqrt, floor n = int(input()) rt = floor(sqrt(n)) print(rt**2)
s095975976
p02865
u163320134
2,000
1,048,576
Wrong Answer
17
2,940
25
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n=int(input()) print(n-1)
s301581079
Accepted
17
2,940
61
n=int(input()) if n%2==0: print(n//2-1) else: print(n//2)