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
s395593260
p03377
u347397127
2,000
262,144
Wrong Answer
23
9,020
83
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x = map(int,input().split()) if a<x and b>x: print("Yes") else: print("No")
s069276569
Accepted
28
9,132
88
a,b,x = map(int,input().split()) if a<=x and a+b>=x: print("YES") else: print("NO")
s758711844
p03415
u406114804
2,000
262,144
Wrong Answer
17
2,940
57
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
a = input() b = input() c = input() print(a[0],b[1],c[2])
s663084571
Accepted
17
2,940
57
a = input() b = input() c = input() print(a[0]+b[1]+c[2])
s751629860
p04043
u296783581
2,000
262,144
Wrong Answer
17
3,064
151
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a = list(map(int, input().split())) n = sum(x == 7 for x in a) k = sum(x == 5 for x in a) if n == 2 and k == 1: print("Yes") else: print("No")
s826883126
Accepted
18
2,940
150
a = list(map(int, input().split())) n = sum(x == 7 for x in a) k = sum(x == 5 for x in a) if n == 1 and k == 2: print("YES") else: print("NO")
s735573963
p02280
u317901693
1,000
131,072
Wrong Answer
20
7,712
1,664
A rooted binary tree is a tree with a root node in which every node has at most two children. Your task is to write a program which reads a rooted binary tree _T_ and prints the following information for each node _u_ of _T_ : * node ID of _u_ * parent of _u_ * sibling of _u_ * the number of children of _u_ * depth of _u_ * height of _u_ * node type (root, internal node or leaf) If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_ have the same parent, we say _u_ is a sibling of _v_ (vice versa). The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf. Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
# -*- coding: utf-8 -*- class Node(object): def __init__(self, N): self.parent = [-1 for i in range(N)] self.left = [-1 for i in range(N)] self.right = [-1 for i in range(N)] self.depth = [-1 for i in range(N)] self.sibling = [-1 for i in range(N)] self.hight = [0 for i in range(N)] self.degree = [0 for i in range(N)] self.max_depth = None def set_depth(self, u): d, U = 0, u while T.parent[u] is not -1: u = T.parent[u] d += 1 self.depth[U] = d def set_hight(self, u): self.hight[u] = self.max_depth - self.depth[u] N = int(input()) # create node T = Node(N) for j in range(N): A = [int(i) for i in input().split()] T.left[A[0]] = A[1] for u in A[1:]: if u is not -1: T.parent[u] = A[0] T.degree[A[0]] += 1 if (A[1] is not -1) and (A[2] is not -1): T.right[A[1]] = A[2] T.sibling[A[1]], T.sibling[A[2]] = A[2], A[1] for i in range(N): T.set_depth(i) # set max_depth T.max_depth = max(T.depth) for i in range(N): T.set_hight(i) # ?????? for i in range(N): if T.parent[i] is -1: node = "root" elif T.left[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, hight = {5}, {6}".format(i, T.parent[i], T.sibling[i], T.degree[i], T.depth[i], T.hight[i], node))
s085988206
Accepted
20
7,876
1,827
# -*- coding: utf-8 -*- class Node(object): def __init__(self, N): self.parent = [-1 for i in range(N)] self.left = [-1 for i in range(N)] self.right = [-1 for i in range(N)] self.depth = [-1 for i in range(N)] self.sibling = [-1 for i in range(N)] self.height = [0 for i in range(N)] self.degree = [0 for i in range(N)] def set_depth(self, u): d, U = 0, u while T.parent[u] is not -1: u = T.parent[u] d += 1 self.depth[U] = d def set_height(self, u): h1 = h2 = 0 if self.left[u] is not -1: h1 = self.set_height(self.left[u]) + 1 if self.right[u] is not -1: h2 = self.set_height(self.right[u]) + 1 self.height[u] = max(h1, h2) return max(h1, h2) N = int(input()) # create node T = Node(N) for j in range(N): A = [int(i) for i in input().split()] T.left[A[0]] = A[1] T.right[A[0]] = A[2] for u in A[1:]: if u is not -1: T.parent[u] = A[0] T.degree[A[0]] += 1 if (A[1] is not -1) and (A[2] is not -1): T.sibling[A[1]], T.sibling[A[2]] = A[2], A[1] for i in range(N): T.set_depth(i) T.set_height(T.parent.index(-1)) # ?????? for i in range(N): if T.parent[i] is -1: node = "root" elif T.left[i] is -1 and T.right[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}".format(i, T.parent[i], T.sibling[i], T.degree[i], T.depth[i], T.height[i], node))
s122368078
p03693
u509094491
2,000
262,144
Wrong Answer
17
2,940
106
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?
i = list(map(int, input().split())) s=i[0]*100+i[1]*10+i[2] if s%4==0: print("Yes") else : print("No")
s300105855
Accepted
17
2,940
95
r,g,b=input().split() sum=100*r+10*g+b if int(sum)%4==0: print("YES") else: print("NO")
s467345620
p03447
u352499693
2,000
262,144
Wrong Answer
18
2,940
67
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
x, a, b = map(int, (input() for i in range(3))) print((x-a+b-1)//b)
s803369691
Accepted
17
2,940
62
x, a, b = map(int, (input() for i in range(3))) print((x-a)%b)
s708557910
p03577
u798086274
2,000
262,144
Wrong Answer
17
2,940
25
Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
s = input() print(s[:-7])
s311787738
Accepted
17
2,940
25
s = input() print(s[:-8])
s432297093
p03470
u541091793
2,000
262,144
Wrong Answer
18
2,940
189
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()) mochi = [int(input()) for i in range(n)] mochi.reverse() size = 0 max = 9999999999 for m in mochi: if m < max: size += 1 max = m print(size)
s520610333
Accepted
19
2,940
213
n = int(input()) mochi = [int(input()) for i in range(n)] mochi.sort(reverse=True) size = 0 max = 9999999999 for m in mochi: # print(m) if m < max: size += 1 max = m print(size)
s515460077
p04011
u634248565
2,000
262,144
Wrong Answer
17
2,940
116
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
a = int(input()) b = int(input()) h = int(input()) one = int(a + b) two = int(one/2) ans = int(two*h) print (ans)
s338194370
Accepted
18
2,940
118
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) if N > K: print(K*X+(N-K)*Y) else: print(N*X)
s335835309
p03160
u353080785
2,000
1,048,576
Wrong Answer
42
13,924
718
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.
#!/usr/bin/env python # coding: utf-8 dp = {} NOT_FOUND = 99999 def sget(i): if i in dp: return dp[i] return NOT_FOUND def chmin(a, b): if (a < b): return a return b def main(N, hs): for i in range(1, N): dp[i] = chmin(sget(i), sget(i - 1) + abs(hs[i] - hs[i - 1])) if i > 1: dp[i] = chmin(sget(i), sget(i - 2) + abs(hs[i] - hs[i - 2])) return dp[N-1] if __name__ == '__main__': #N = 4 #hs = [10, 30, 40, 20] #N = 2 #hs = [10, 10] #N = 6 #hs = [30, 10, 60, 10, 60, 50] #N = 2 #hs = [1, 3, 2, 1] N = int(input()) hs = list(map(int, input().split(" "))) dp[0] = 0 #print(main(N, hs)) print(dp)
s528262434
Accepted
199
23,216
1,210
#!/usr/bin/env python # coding: utf-8 N = int(input()) h = list(map(int, input().split())) #dp = {} NOT_FOUND = pow(10, 4) + 1 def sget(i): if i in dp: return dp[i] return NOT_FOUND #dp = {0: 0, 1: abs(h[0] - h[1])} #print(dp[N-1]) dp = {0: 0} for i in range(1, N): dp[i] = sget(i-1) + abs(h[i] - h[i-1]) if i > 1: dp[i] = min(sget(i), sget(i-2) + abs(h[i] - h[i-2])) print(dp[N-1]) #def main(N, hs): # dp[0] = 0 # #def rec(i): # # return 0 # # res = NOT_FOUND # # res = chmin(res, rec(i-1) + abs(hs[i] - hs[i-1])) # # if (i > 1): # # res = chmin(res, rec(i-2) + abs(hs[i] - hs[i-2])) # # dp[i] = res # #return rec(N-1)
s703023425
p04029
u502304480
2,000
262,144
Wrong Answer
19
2,940
103
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()) q, mod = divmod(n, 2) if mod == 0: print((1 + n) * q) else: print((1 + n) * q + q)
s285559093
Accepted
17
2,940
54
n = int(input()) l = list(range(1, n+1)) print(sum(l))
s894746894
p00004
u412890344
1,000
131,072
Wrong Answer
20
7,740
629
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
def get_input(): while True: try: yield "".join(input()) except EOFError: break if __name__ == "__main__": array = list(get_input()) #print(array) for i in range(len(array)): a,b,c,d,e,f = array[i].split() if int(b)!=0: x = (int(b)*int(f) - int(c)*int(e))/(int(b)*int(d) - int(a)*int(e)) y = -(int(a)/int(b))*x + int(c)/int(b) elif int(b)==0 and int(a)!=0: x = int(c)/int(a) y = -(int(d)/int(e))*x + int(f) print("{0} {1}".format(x,y))
s969931884
Accepted
30
7,720
876
def get_input(): while True: try: yield "".join(input()) except EOFError: break if __name__ == "__main__": array = list(get_input()) for i in range(len(array)): temp_a,temp_b,temp_c,temp_d,temp_e,temp_f = array[i].split() a,b,c,d,e,f = int(temp_a),int(temp_b),int(temp_c),int(temp_d),int(temp_e),int(temp_f) if a!=0: if e-b*d/a !=0: y = (f-c*d/a)/(e-b*d/a) x = (c - b*y)/a else: print("cannot solve equation") else: if b!=0: y = c/b if d!=0: x = (f -e*y)/d else: print("cannot solve equation") print("{:.3f} {:.3f}".format(x,y))
s908246708
p03377
u948524308
2,000
262,144
Wrong Answer
17
2,940
96
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A,B,X = map(int,input().split()) if A <= X and X-A <= B: print("Yes") else: print("No")
s962177377
Accepted
26
3,064
96
A,B,X = map(int,input().split()) if A <= X and X-A <= B: print("YES") else: print("NO")
s556886764
p03457
u095426154
2,000
262,144
Wrong Answer
457
11,824
366
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()) t=[0 for i in range(n)] x=[0 for i in range(n)] y=[0 for i in range(n)] for i in range(n): t[i],x[i],y[i]=list(map(int,input().split(" "))) x.insert(0,0) y.insert(0,0) for i in range(n-1): abx=abs(x[i]-x[i+1]) aby=abs(y[i]-y[i+1]) if abx+aby>t[i] or (abs(x[i+1])+abs(y[i+1]))%2!=t[i]%2: print("NO") exit(0) print("YES")
s621709910
Accepted
467
11,824
387
n=int(input()) t=[0 for i in range(n)] x=[0 for i in range(n)] y=[0 for i in range(n)] for i in range(n): t[i],x[i],y[i]=list(map(int,input().split(" "))) t.insert(0,0) x.insert(0,0) y.insert(0,0) for i in range(n): abx=abs(x[i]-x[i+1]) aby=abs(y[i]-y[i+1]) if abx+aby>t[i+1]-t[i] or (abs(x[i+1])+abs(y[i+1]))%2!=t[i+1]%2: print("No") exit(0) print("Yes")
s551135046
p03478
u733132703
2,000
262,144
Wrong Answer
38
9,248
246
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
N,A,B = map(int,input().split()) def check_num(n): s = str(n) array = list(map(int,s)) return sum(array) list_1 = [i for i in range(1,N+1)] list_2 = [] for _ in list_1: if A<=check_num(_)<=B: list_2.append(_) else: pass
s516554186
Accepted
40
9,432
268
N,A,B = map(int,input().split()) def check_num(n): s = str(n) array = list(map(int,s)) return sum(array) list_1 = [i for i in range(1,N+1)] list_2 = [] for _ in list_1: if A<=check_num(_)<=B: list_2.append(_) else: pass print(sum(list_2))
s872254805
p03478
u000842852
2,000
262,144
Wrong Answer
286
12,504
251
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
import numpy as np N, A, B = map(int, input().split()) total = 0 for i in range(N+1): a = i lis =[] while i >0: lis.append(i%10) i //=10 lis.reverse() lis = np.array(lis) SUM = np.sum(lis) if SUM >=A and SUM <=B: total += a
s630836618
Accepted
294
12,472
272
import numpy as np N, A, B = map(int, input().split()) total = 0 for i in range(1, N+1): a = i lis =[] while i >0: lis.append(i%10) i //=10 lis.reverse() lis = np.array(lis) SUM = np.sum(lis) if SUM >=A and SUM <=B: total += a print(total)
s449791854
p03433
u075409829
2,000
262,144
Wrong Answer
17
2,940
93
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)%500 == 0: print("Yes") else: print("No")
s169250491
Accepted
17
2,940
88
N = int(input()) A = int(input()) if N%500 <= A: print("Yes") else: print("No")
s180023767
p03548
u620846115
2,000
262,144
Wrong Answer
33
9,144
46
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()) print((x-z)//y)
s434450617
Accepted
26
9,160
50
x,y,z=map(int,input().split()) print((x-z)//(y+z))
s962387074
p03943
u143492911
2,000
262,144
Wrong Answer
18
2,940
138
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: print("Yes") exit() if b+c==a: print("Yes") if a+c==b: print("Yes") print("No")
s282687654
Accepted
18
2,940
160
a,b,c=map(int,input().split()) if a+b==c: print("Yes") exit() if b+c==a: print("Yes") exit() if a+c==b: print("Yes") exit() print("No")
s640568838
p04030
u370852395
2,000
262,144
Wrong Answer
17
2,940
254
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?
str_list=[] tmp=[] s='' str_list=list(input()) for i in str_list: if i =='0': tmp.append('0') elif i == '1': tmp.append('1') elif i == 'B' and tmp: tmp.pop() for i in range(len(tmp)): s+=tmp[i] print(tmp) print(s)
s571315879
Accepted
17
3,060
243
str_list=[] tmp=[] s='' str_list=list(input()) for i in str_list: if i =='0': tmp.append('0') elif i == '1': tmp.append('1') elif i == 'B' and tmp: tmp.pop() for i in range(len(tmp)): s+=tmp[i] print(s)
s981462393
p03720
u633450100
2,000
262,144
Wrong Answer
27
9,176
193
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 = [int(i) for i in input().split()] list = [] for i in range(M): a,b = [int(i) for i in input().split()] list.append(a) list.append(b) for i in range(N): print(list.count(i))
s169857579
Accepted
27
9,120
193
N,M = [int(i) for i in input().split()] list = [] for i in range(M): a,b = [int(i) for i in input().split()] list.append(a) list.append(b) for i in range(1,N+1): print(list.count(i))
s806453136
p02612
u387870994
2,000
1,048,576
Wrong Answer
29
9,136
19
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.
print(input()[-3:])
s416442519
Accepted
28
9,160
79
n = int(input()) if n % 1000 == 0: print(0) else: print(1000 - n%1000)
s820986982
p02613
u122743999
2,000
1,048,576
Wrong Answer
158
9,196
364
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.
score = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0} N = int(input()) for _ in range(N): result = input() if result == 'AC': score[result] += 1 elif result == 'WA': score[result] += 1 elif result == 'TLE': score[result] += 1 elif result == 'RE': score[result] += 1 for i in score.keys(): print(i, '×', score[i])
s829225196
Accepted
158
9,196
362
score = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0} N = int(input()) for _ in range(N): result = input() if result == 'AC': score[result] += 1 elif result == 'WA': score[result] += 1 elif result == 'TLE': score[result] += 1 elif result == 'RE': score[result] += 1 for i in score.keys(): print(i, 'x', score[i])
s485784400
p03760
u626881915
2,000
262,144
Wrong Answer
25
8,972
113
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
s=input() t=input() l="" i=0 j=0 while i < len(s): l+=s[i] i+=1 while j < len(t): l+=t[j] j+=1 print(l)
s396045687
Accepted
25
9,052
171
s=input() t=input() l="" i=0 j=0 while True: if i < len(s): l+=s[i] i+=1 if j < len(t): l+=t[j] j+=1 if len(l) == len(s)+len(t): break print(l)
s896151112
p02392
u933096856
1,000
131,072
Wrong Answer
20
7,684
89
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a,b,c=map(int,input().split()) if a < b and b < c: print('YES') else: print('NO')
s291658141
Accepted
50
7,696
89
a,b,c=map(int,input().split()) if a < b and b < c: print('Yes') else: print('No')
s351695897
p03156
u814986259
2,000
1,048,576
Wrong Answer
18
3,064
264
You have written N problems to hold programming contests. The i-th problem will have a score of P_i points if used in a contest. With these problems, you would like to hold as many contests as possible under the following condition: * A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points. The same problem should not be used in multiple contests. At most how many contests can be held?
import bisect N = int(input()) A,B = map(int, input().split()) P = list(map(int, input().split())) P.sort() ans = N id = bisect.bisect_right(P,A) ans = min(ans,id) prev = id id = bisect.bisect_right(P,B) ans = min(ans,id - prev) ans = min(ans,N-1 - id) print(ans)
s356419642
Accepted
18
3,060
262
import bisect N = int(input()) A,B = map(int, input().split()) P = list(map(int, input().split())) P.sort() ans = N id = bisect.bisect_right(P,A) ans = min(ans,id) prev = id id = bisect.bisect_right(P,B) ans = min(ans,id - prev) ans = min(ans,N - id) print(ans)
s889633468
p03181
u729133443
2,000
1,048,576
Wrong Answer
994
31,796
474
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other black vertex by passing through only black vertices. You are given a positive integer M. For each v (1 \leq v \leq N), answer the following question: * Assuming that Vertex v has to be black, find the number of ways in which the vertices can be painted, modulo M.
n,m,*t=map(int,open(0).read().split()) e=[[]for _ in range(n)] for a,b in zip(*[iter(t)]*2): e[a-1]+=b-1, e[b-1]+=a-1, o=[] s=[0] f=[1]*n for v in s: o+=v, f[v]=0 t=[] for w in e[v]: if f[w]: s+=w, t+=w, e[v]=t dp1=[0]*n for v in o[::-1]: t=1 for w in e[v]: t=t*(dp1[w]+1)%m dp1[v]=t dp2=[0]*n dp2[0]=1 for v in o: t=dp2[v]*dp1[v]%m for w in e[v]: dp2[w]=t*pow(dp1[w]+1,m-2,m)+1 for dp1,dp2 in zip(dp1,dp2): print(dp1*dp2%m)
s225957576
Accepted
1,272
57,740
592
n,m,*t=map(int,open(0).read().split()) e=[[]for _ in range(n)] for a,b in zip(*[iter(t)]*2): e[a-1]+=b-1, e[b-1]+=a-1, o=[] s=[0] f=[1]*n for v in s: o+=v, f[v]=0 t=[] for w in e[v]: if f[w]: s+=w, t+=w, e[v]=t dp1=[0]*n c=[[]for _ in range(n)] for v in o[::-1]: c1,c2=[1],[1] for w in e[v]: c1+=c1[-1]*(dp1[w]+1)%m, for w in e[v][::-1]: c2+=c2[-1]*(dp1[w]+1)%m, dp1[v]=c1[-1] c[v]=c1,c2[-2::-1] dp2=[0]*n dp2[0]=1 for v in o: t=dp2[v] for w,c1,c2 in zip(e[v],*c[v]): dp2[w]=(t*c1*c2+1)%m for dp1,dp2 in zip(dp1,dp2): print(dp1*dp2%m)
s671297858
p03469
u620846115
2,000
262,144
Wrong Answer
31
8,900
45
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
n = input() n.replace("2017","2018") print(n)
s388281216
Accepted
26
8,980
49
s = input() s = s.replace("2017","2018") print(s)
s354972974
p03605
u388297793
2,000
262,144
Wrong Answer
25
9,088
61
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
n=input() if n in "9": print("Yes") else: print("No")
s648270599
Accepted
29
9,044
61
n=input() if "9" in n: print("Yes") else: print("No")
s398233114
p03455
u773686010
2,000
262,144
Wrong Answer
25
9,156
106
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 % 2 == 0) and (b % 2 ==0): print ('Even') else: print('Odd')
s507758877
Accepted
29
8,852
145
##AtCoder Beginners Selection Product a,b = map(int, input().split()) if (a % 2 == 0) or (b % 2 ==0): print ('Even') else: print('Odd')
s578695914
p03155
u802963389
2,000
1,048,576
Wrong Answer
17
2,940
74
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
N = int(input()) H = int(input()) W = int(input()) print((W-N+1)*(H-N+1))
s045283311
Accepted
18
2,940
75
N = int(input()) H = int(input()) W = int(input()) print((N-W+1)*(N-H+1))
s713827601
p03050
u688126754
2,000
1,048,576
Wrong Answer
277
12,652
317
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.
import numpy as np N = int(input()) divisor_lst = [] for i in range(1, int(np.sqrt(N))+1): if N % i == 0: divisor_lst.append(i) divisor_lst.append(N//i) print(i) arr = np.array(divisor_lst) print(arr) arr -= 1 print(int(np.sum(arr)) - 1)
s329250976
Accepted
501
12,424
209
import numpy as np N = int(input()) divisor_lst = [] i = 1 while i+2 <= N//i: if N % i == 0: divisor_lst.append(N//i) i += 1 arr = np.array(divisor_lst) arr -= 1 print(int(np.sum(arr)))
s317613064
p04029
u095089755
2,000
262,144
Wrong Answer
17
2,940
39
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)
s861075422
Accepted
17
2,940
40
N = int(input()) print(N * (N + 1) // 2)
s653563815
p03860
u719840207
2,000
262,144
Wrong Answer
17
2,940
25
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"+input()[0]+"C")
s696341782
Accepted
17
2,940
25
print("A"+input()[8]+"C")
s633523526
p03599
u687053495
3,000
262,144
Time Limit Exceeded
3,156
3,064
530
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
A, B, C, D, E, F = map(int, input().split()) density = 0 ans = (0, 0) for a in range(31): for b in range(31): for c in range(100): for d in range(100): water = 100*a*A + 100*b*B suger = c*C + d*D if water + suger > F or water == 0: continue if suger > 0 and (suger / water * 100) > E: continue tmp = (100 * suger) / (water + suger) if tmp >= density: density = tmp ans = (water+suger, suger) print(*ans)
s095009304
Accepted
316
3,064
502
A, B, C, D, E, F = map(int, input().split()) density = -1 ans = (0, 0) for a in range(31): for b in range(31): for c in range(101): for d in range(101): water = 100*a*A + 100*b*B suger = c*C + d*D if water + suger > F or water == 0: break if (water / 100) * E >= suger: tmp = (100 * suger) / (water + suger) if tmp > density: density = tmp ans = (water+suger, suger) print(*ans)
s560451247
p00728
u780025254
1,000
131,072
Wrong Answer
20
7,684
266
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance. Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer. You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
import sys while True: n = int(sys.stdin.readline().rstrip()) if n == 0: break scores = [int(sys.stdin.readline().rstrip()) for i in range(n)] result = (sum(scores) - (min(scores) + max(scores)) // n - 2) print(result)
s022082523
Accepted
30
7,720
252
import sys while True: n = int(sys.stdin.readline().rstrip()) if n == 0: break scores = [int(sys.stdin.readline().rstrip()) for i in range(n)] result = (sum(scores) - (max(scores) + min(scores))) // (n - 2) print(result)
s395615633
p03478
u382431597
2,000
262,144
Wrong Answer
38
3,060
176
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b = list(map(int, input().split())) isum = 0 for i in range(1,n+1): tmp = [int(j) for j in list(str(i))] if a <= sum(tmp) <= b: isum += sum(tmp) print(isum)
s943466963
Accepted
36
3,060
194
n,a,b = list(map(int, input().split())) isum = 0 for i in range(1,n+1): tmp = [int(j) for j in list(str(i))] #print(tmp,sum(tmp)) if a <= sum(tmp) <= b: isum += i print(isum)
s728401768
p02412
u744506422
1,000
131,072
Wrong Answer
20
5,596
360
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
a=[] w="" while(w!="0 0"): w=input() a.append(w) a.pop() for st in a: s=st.split() n=int(s[0]) x=int(s[1]) count=0 for a in range(1,x//3+1): for b in range(a+1,(x-a)//2+1): if (x-a-b)<=n and b<(x-a-b): count+=1 print("{0} {1} {2}".format(a,b,x-a-b)) print("{0}".format(count))
s771592452
Accepted
30
5,596
305
a=[] w="" while(w!="0 0"): w=input() a.append(w) a.pop() for st in a: s=st.split() n=int(s[0]) x=int(s[1]) count=0 for a in range(1,x//3+1): for b in range(a+1,(x-a)//2+1): if (x-a-b)<=n and b<(x-a-b): count+=1 print("{0}".format(count))
s241409241
p03455
u263830634
2,000
262,144
Wrong Answer
17
2,940
94
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 ('Evev') else: print ('Odd')
s399601991
Accepted
17
2,940
94
a, b = map(int, input().split()) if (a*b) %2 == 0: print ('Even') else: print ('Odd')
s227270360
p03477
u597455618
2,000
262,144
Wrong Answer
17
2,940
128
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a, b, c, d = map(int, input().split()) if a+b < c+d: print("Left") elif a+b == c+d: print("Balanced") else: print("Right")
s842857642
Accepted
17
3,060
128
a, b, c, d = map(int, input().split()) if a+b > c+d: print("Left") elif a+b == c+d: print("Balanced") else: print("Right")
s213684572
p03339
u880466014
2,000
1,048,576
Wrong Answer
17
3,060
89
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
S = list(input()) e = S.count('E') w = S.count('W') if e > w: print(w) else: print(e)
s427259990
Accepted
110
3,700
466
N = int(input()) S = input() E_count = S.count('E') W_count = 0 mini_count = E_count for i in S: if i == 'E': E_count -= 1 else: W_count += 1 if mini_count > E_count + W_count: mini_count = E_count + W_count print(mini_count)
s188666720
p02612
u925242392
2,000
1,048,576
Wrong Answer
33
9,056
63
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n=int(input()) if n%1000==0: print(0) else: print(n-n%1000)
s420455270
Accepted
28
9,040
75
n=int(input()) if n%1000==0: print(0) else: print(((n//1000)+1)*1000-n)
s715780801
p02258
u716198574
1,000
131,072
Wrong Answer
30
7,744
276
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .
N = int(input('R ?????????: ')) R = [int(input('R[%s]: ' % (str(i)))) for i in range(N)] maxv = -20000000000 minv = R[0] for i in range(1, N): if R[i] - minv > maxv: maxv = R[i] - minv if minv > R[i]: minv = R[i] print('?????§??????: ' + str(maxv))
s035365251
Accepted
520
15,688
183
N = int(input()) R = [int(input()) for i in range(N)] maxv = -20000000000 minv = R[0] for i in range(1, N): maxv = max(R[i] - minv, maxv) minv = min(R[i], minv) print(maxv)
s700692696
p02397
u104171359
1,000
131,072
Wrong Answer
60
7,624
430
Write a program which reads two integers x and y, and prints them in ascending order.
#!usr/bin/env python3 def string_two_numbers_spliter(): x, y = [int(i) for i in input().split()] return x, y def swap_two_numbers_asc(x, y): if x > y: x, y = y, x return x, y def main(): while True: x, y = string_two_numbers_spliter() swap_two_numbers_asc(x, y) if x == 0 and y == 0: break print('%d %d' % (x, y)) if __name__ == '__main__': main()
s355365052
Accepted
70
7,760
441
#!usr/bin/env python3 def string_two_numbers_spliter(): x, y = [int(i) for i in input().split()] return x, y def swap_two_numbers_asc(x, y): x, y = y, x return x, y def main(): while True: x, y = string_two_numbers_spliter() if x == 0 and y == 0: break if x > y: x, y = swap_two_numbers_asc(x, y) print('%d %d' % (x, y)) if __name__ == '__main__': main()
s085167343
p03380
u556225812
2,000
262,144
Wrong Answer
2,145
925,008
408
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
import math import itertools def comb(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(input()) lst = list(map(int, input().split())) ans = set(itertools.combinations(lst, 2)) max = 0 for i in ans: if i[0] > i[1]: n = i[0] r = i[1] else: n = i[1] r = i[0] x = comb(n, r) if x >= max: pair = [n, r] print(*pair)
s706236565
Accepted
81
14,180
252
import bisect import math N = int(input()) lst = list(map(int, input().split())) lst.sort() n = max(lst) a = bisect.bisect_right(lst, n//2) if abs(math.ceil(n/2)-lst[a]) >= abs(math.ceil(n/2)-lst[a-1]): print(n, lst[a-1]) else: print(n, lst[a])
s014624010
p03251
u788137651
2,000
1,048,576
Wrong Answer
17
3,060
377
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.
N, M, X, Y = map(int, input().split()) x = [int(i) for i in input().split()] y = [int(i) for i in input().split()] print(x, y) if X < Y: max_x = max(x) min_y = min(y) if max_x+1 < min_y: print("No War") else: print("War") else: min_x = min(x) max_y = max(y) if min_x > max_y+1: print("No War") else: print("War")
s614907253
Accepted
19
2,940
235
N, M, X, Y = map(int, input().split()) x = [int(i) for i in input().split()] y = [int(i) for i in input().split()] max_x = max(x) min_y = min(y) if max_x < min_y and max_x < Y and min_y > X: print("No War") else: print("War")
s607514632
p02277
u599130514
1,000
131,072
Wrong Answer
20
5,608
1,365
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L, R = A[left: left + n1], A[mid: mid + n2] L.append([0,2000000000]) R.append([0,2000000000]) i, j = 0, 0 for k in range(left, right): if L[i][1] <= R[j][1]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) def partition(A, p, r): x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quick_sort(A, p, r): if p < r: q = partition(A, p, r) quick_sort(A, p, q - 1) quick_sort(A, q + 1, r) n = int(input()) cards = [] merge_cards = [] for _ in range(n): tmp = input().split(' ') cards.append([tmp[0], int(tmp[1])]) merge_cards.append([tmp[0], int(tmp[1])]) mergeSort(merge_cards, 0, n) quick_sort(cards, 0, n - 1) if merge_cards == cards: print("Stable") else: print("Not Stable") for card in cards: print(*card)
s869088596
Accepted
1,770
30,216
1,365
def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L, R = A[left: left + n1], A[mid: mid + n2] L.append([0,2000000000]) R.append([0,2000000000]) i, j = 0, 0 for k in range(left, right): if L[i][1] <= R[j][1]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) def partition(A, p, r): x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quick_sort(A, p, r): if p < r: q = partition(A, p, r) quick_sort(A, p, q - 1) quick_sort(A, q + 1, r) n = int(input()) cards = [] merge_cards = [] for _ in range(n): tmp = input().split(' ') cards.append([tmp[0], int(tmp[1])]) merge_cards.append([tmp[0], int(tmp[1])]) mergeSort(merge_cards, 0, n) quick_sort(cards, 0, n - 1) if merge_cards == cards: print("Stable") else: print("Not stable") for card in cards: print(*card)
s422499200
p00003
u477023447
1,000
131,072
Wrong Answer
30
5,920
305
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.
tri_list = [] N = int(input()) for i in range(N): tri = input() tri_list.append(tri.split()) for i in range(N): tri_list[i].sort() print(tri_list[i]) if int(tri_list[i][2])^2 == int(tri_list[i][0])^2 + int(tri_list[i][1])^2 : print("YES") else : print("NO")
s126417528
Accepted
40
5,600
256
n = int(input()) for i in range(n): tri_list = list(map(int,input().split(" "))) tri_list.sort() a = int(tri_list[2]) ** 2 b = int(tri_list[0]) ** 2 + int(tri_list[1]) ** 2 if a == b: print("YES") else: print("NO")
s281048358
p03943
u904945034
2,000
262,144
Wrong Answer
31
9,160
112
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 = list(map(int,input().split())) b = a.pop(a.index(max(a))) if b == sum(a): print("YES") else: print("NO")
s485277227
Accepted
28
9,064
112
a = list(map(int,input().split())) b = a.pop(a.index(max(a))) if b == sum(a): print("Yes") else: print("No")
s517752580
p03545
u212328220
2,000
262,144
Wrong Answer
31
9,200
322
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
s = input() n = 3 for i in range(2**n): ans = s[0] sum = int(s[0]) for j in range(3): if 1 & (i >> j): ans += f'+{s[j+1]}' sum += int(s[j+1]) else: ans += f'-{s[j+1]}' sum -= int(s[j+1]) if sum == 7: print(f'{ans}+7') exit()
s164350221
Accepted
29
8,996
322
s = input() n = 3 for i in range(2**n): ans = s[0] sum = int(s[0]) for j in range(3): if 1 & (i >> j): ans += f'+{s[j+1]}' sum += int(s[j+1]) else: ans += f'-{s[j+1]}' sum -= int(s[j+1]) if sum == 7: print(f'{ans}=7') exit()
s764921437
p03543
u395894569
2,000
262,144
Wrong Answer
17
2,940
56
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=list(input()) print('YES' if len(set(n))<=2 else 'NO')
s181070020
Accepted
17
2,940
119
n=list(input()) for i in range(2): if n[i] == n[i + 1] == n[i + 2]: print('Yes') exit() print('No')
s964176122
p03697
u077019541
2,000
262,144
Wrong Answer
17
2,940
82
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
A,B = map(int,input().split()) if A+B<=10: print("error") else: print(A+B)
s496451427
Accepted
17
2,940
82
A,B = map(int,input().split()) if A+B>=10: print("error") else: print(A+B)
s704455252
p03720
u204523044
2,000
262,144
Wrong Answer
17
3,060
221
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()) a = [] b = [] for i in range(M): ai, bi = map(int, input().split()) a.append(ai) b.append(bi) for i in range(N): r = 0 r += a.count(i+1) r += b.count(i+1) print(r)
s775103691
Accepted
18
3,060
225
N, M = map(int, input().split()) a = [] b = [] for i in range(M): ai, bi = map(int, input().split()) a.append(ai) b.append(bi) for i in range(N): r = 0 r += a.count(i+1) r += b.count(i+1) print(r)
s481408102
p03369
u608726540
2,000
262,144
Wrong Answer
17
2,940
33
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
x=input() print(700+x.count('o'))
s397669508
Accepted
17
2,940
48
s=list(input()) n=s.count('o') print(700+100*n)
s424496641
p02665
u935241425
2,000
1,048,576
Wrong Answer
58
20,064
555
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
n = int( input() ) p = [ int( pi ) for pi in input().split() ] sump = int( 0 ) for pi in p: sump += pi ch = int( -1 ) ans = int( 0 ) for i in range( n+1 ): if i == 0: ans += 1 px = 1 elif i == 1: ans = -1 break else: if px*2 <= sump: ans += px*2 px = px*2 - p[ i ] sump = sump - p[ i ] else: ans += sump px = sump - p[ i ] sump = sump - p[ i ] if px < 0: ans = -1 break print( ans )
s070400953
Accepted
103
20,008
828
n = int( input() ) p = [ int( pi ) for pi in input().split() ] sump = int( 0 ) for pi in p: sump += pi ans = int( 0 ) for i in range( n+1 ): if i == 0: ans += 1 px = 1 if p[ i ] == 1 and n == 0: ans = 1 break if p[ i ] != 0 and p[ i ] != 1: ans = -1 break else: if px*2 <= sump: ans += px*2 px = px*2 - p[ i ] sump = sump - p[ i ] else: ans += sump px = sump - p[ i ] sump = sump - p[ i ] # print( px, sump ) if i != n and px <= 0: ans = -1 break elif i == n and sump != 0: ans = -1 break elif i == n and px != 0: ans = -1 break print( ans )
s712416594
p03471
u728498511
2,000
262,144
Wrong Answer
18
3,064
485
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()) y /= 1000 a = [0]*3 a[1], a[2] = divmod(y, 5) ans = [-1]*3 while sum(a)!=n: if n-sum(a) >= 4: tmp = (n-sum(a))//4 a[1] -= tmp a[2] += tmp*5 elif n-sum(a) <= -1: tmp = sum(a)-n a[1] -= tmp*2 a[0] += tmp else: tmp = n-sum(a) a[1] -= tmp*3 a[2] += tmp*5 a[0] += tmp if a[1]<0:break else: ans = a ans = list(map(int, ans)) print(*ans)
s526870228
Accepted
432
2,940
148
n,y=map(int,input().split()) ans=[-1]*3 y//=1000 for i in range(n+1): for j in range(n-i+1): if i*9+j*4+n==y:ans=[i,j,n-i-j] print(*ans)
s976189493
p03455
u226176079
2,000
262,144
Wrong Answer
17
2,940
101
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()) x = a * b if x % 2 == 0: print('EVEN') else: print('Odd')
s651220666
Accepted
17
2,940
102
a, b = map(int, input().split()) x = a * b if x % 2 == 0: print('Even') else: print('Odd')
s465286314
p03067
u476124554
2,000
1,048,576
Wrong Answer
17
2,940
110
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 < c and b < c or c < a and b < c: print('Yes') else: print('No')
s775563421
Accepted
17
2,940
110
a,b,c = map(int,input().split()) if a < c and c < b or c < a and b < c: print('Yes') else: print('No')
s050143963
p02742
u664907598
2,000
1,048,576
Wrong Answer
17
2,940
94
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
h,w = map(int,input().split()) if h*w % 2 == 0: print(h*w/2) else: print((h*w+1)/2)
s242569024
Accepted
17
2,940
138
h,w = map(int,input().split()) if h ==1 or w ==1: print(1) elif h*w % 2 == 0: print(int(h*w/2)) else: print(int((h*w+1)/2))
s667578334
p00050
u546285759
1,000
131,072
Wrong Answer
20
7,340
155
福島県は果物の産地としても有名で、その中でも特に桃とりんごは全国でも指折りの生産量を誇っています。ところで、ある販売用の英文パンフレットの印刷原稿を作ったところ、手違いでりんごに関する記述と桃に関する記述を逆に書いてしまいました。 あなたは、apple と peach を修正する仕事を任されましたが、なにぶん面倒です。1行の英文を入力して、そのなかの apple という文字列を全て peach に、peach という文字列を全てapple に交換した英文を出力するプログラムを作成してください。
d = {"apple": "peach", "peach": "apple"} ans = [] for c in input().split(): try: ans.append(d[c]) except: ans.append(c) print(*ans)
s370787563
Accepted
50
7,368
236
ans = [] for word in input().split(): if "apple" in word: ans.append(word.replace("apple", "peach")) elif "peach" in word: ans.append(word.replace("peach", "apple")) else: ans.append(word) print(*ans)
s142515986
p03486
u193927973
2,000
262,144
Wrong Answer
18
3,064
189
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=list(input()) t=list(input()) s.sort() t.sort(reverse=True) l=min(len(s), len(t)) for i in range(l): if s[i]>t[i]: print("No") exit() if s==t: print("No") else: print("Yes")
s662418305
Accepted
17
3,064
271
s=list(input()) t=list(input()) s.sort() t.sort(reverse=True) l=min(len(s), len(t)) for i in range(l): if s[i]==t[i]: continue if s[i]<t[i]: print("Yes") exit() else: print("No") exit() if len(s)>=len(t): print("No") else: print("Yes")
s679611284
p03448
u352623442
2,000
262,144
Wrong Answer
18
3,180
315
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()) ans = 0 for i in range(a+1): if i*500 <= x: for k in range(b+1): if k*100 <= (x-i*500): if (x-i*500-k*100)/50 <= c: print(i,k,(x-i*500-k*100)/50) ans += 1 print(ans)
s289497159
Accepted
18
3,060
265
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for i in range(a+1): if i*500 <= x: for k in range(b+1): if k*100 <= (x-i*500): if (x-i*500-k*100)/50 <= c: ans += 1 print(ans)
s333922783
p03502
u079022116
2,000
262,144
Wrong Answer
17
2,940
76
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() a = [] for i in range(len(n)): a.append(int(n[i])) print(sum(a))
s500131934
Accepted
18
2,940
119
n=input() a = [] for i in range(len(n)): a.append(int(n[i])) if int(n) % sum(a) == 0: print('Yes') else:print('No')
s758576386
p03860
u785205215
2,000
262,144
Wrong Answer
18
2,940
204
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.
from sys import stdin, stdout def readLine_str_list():return list(map(str, stdin.readline().split())) def main(): s = readLine_str_list() print("A"+s[0]+"C") if __name__ == "__main__": main()
s936515210
Accepted
17
2,940
207
from sys import stdin, stdout def readLine_str_list():return list(map(str, stdin.readline().split())) def main(): s = readLine_str_list() print("A"+s[1][0]+"C") if __name__ == "__main__": main()
s554633431
p02612
u005569385
2,000
1,048,576
Wrong Answer
27
9,136
38
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()) a = N % 1000 print(a)
s176589415
Accepted
30
9,092
84
N = int(input()) a = 1000-(N % 1000) if N%1000 == 0: print(0) else: print(a)
s829411113
p02865
u177388368
2,000
1,048,576
Wrong Answer
20
3,316
30
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n=int(input()) n=n//2 print(n)
s776669817
Accepted
17
2,940
58
n=int(input()) if n%2==0:n=n/2-1 else:n=n//2 print(int(n))
s816474498
p02285
u370086573
2,000
131,072
Wrong Answer
30
7,784
2,703
Write a program which performs the following operations to a binary search tree $T$ by adding delete operation to B: Binary Search Tree II. * insert $k$: Insert a node containing $k$ as key into $T$. * find $k$: Report whether $T$ has a node containing $k$. * delete $k$: Delete a node containing $k$. * print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. The operation delete $k$ for deleting a given node $z$ containing key $k$ from $T$ can be implemented by an algorithm which considers the following cases: 1. If $z$ has no children, we modify its parent $z.p$ to replace $z$ with NIL as its child (delete $z$). 2. If $z$ has only a single child, we "splice out" $z$ by making a new link between its child and its parent. 3. If $z$ has two children, we splice out $z$'s successor $y$ and replace $z$'s key with $y$'s key.
class Tree: def __init__(self): self.root = None def insert(self, key): z = Node(key) y = None x = self.root while x: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y is None: self.root = z elif z.key < y.key: y.left = z else: y.right = z def find(self, key): x = self.root while x and key != x.key: if key < x.key: x = x.left else: x = x.right return x def getSuccessor(self, x): if x.right is not None: return self.getMinimum(x.right) y = x.parent while y and x == y.right: x = y y = y.parent return y def getMinimum(self, x): while x.left is not None: x = x.left return x def delete(self, z): if z.left is None or z.right is None: y = z else: y = getSuccessor(z) # y??????x???????????? if y.left is not None: x = y.left else: x = y.right if x is not None: x.parent = y.parent if y.parent is None: self.root = x elif y == y.parent.left: y.parent.left = x else: y.parent.right = x if y != z: z.key = y.key def show(self): print(" ", end="") print(*list(map(str, self.root.inwalk()))) print(" ", end="") print(*list(map(str, self.root.prewalk()))) class Node: def __init__(self, key): self.key = key self.parent = self.left = self.right = None def prewalk(self): nodeList = [self.key] if self.left: nodeList += self.left.prewalk() if self.right: nodeList += self.right.prewalk() return nodeList def inwalk(self): nodeList = [] if self.left: nodeList += self.left.inwalk() nodeList += [self.key] if self.right: nodeList += self.right.inwalk() return nodeList tree = Tree() n = int(input()) for i in range(n): cmd = list(input().split()) if cmd[0] == 'insert': tree.insert(int(cmd[1])) elif cmd[0] == 'find': if tree.find(int(cmd[1])): print("yes") else: print("no") elif cmd[0] == 'print': tree.show()
s242016225
Accepted
8,040
156,584
2,799
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 is None: self.root = z elif z.key < y.key: y.left = z else: y.right = z def find(self, key): x = self.root while x and key != x.key: if key < x.key: x = x.left else: x = x.right return x def getSuccessor(self, x): if x.right is not None: return self.getMinimum(x.right) y = x.parent while y and x == y.right: x = y y = y.parent return y def getMinimum(self, x): while x.left is not None: x = x.left return x def delete(self, key): z = self.find(key) if z.left is None or z.right is None: y = z else: y = self.getSuccessor(z) # y??????x???????????? if y.left is not None: x = y.left else: x = y.right if x is not None: x.parent = y.parent if y.parent is None: self.root = x elif y == y.parent.left: y.parent.left = x else: y.parent.right = x if y != z: z.key = y.key def show(self): print(" ", end="") print(*list(map(str, self.root.inwalk()))) print(" ", end="") print(*list(map(str, self.root.prewalk()))) class Node: def __init__(self, key): self.key = key self.parent = self.left = self.right = None def prewalk(self): nodeList = [self.key] if self.left: nodeList += self.left.prewalk() if self.right: nodeList += self.right.prewalk() return nodeList def inwalk(self): nodeList = [] if self.left: nodeList += self.left.inwalk() nodeList += [self.key] if self.right: nodeList += self.right.inwalk() return nodeList tree = Tree() n = int(input()) for i in range(n): cmd = list(input().split()) if cmd[0] == 'insert': tree.insert(int(cmd[1])) elif cmd[0] == 'find': if tree.find(int(cmd[1])): print("yes") else: print("no") elif cmd[0] == 'print': tree.show() elif cmd[0] == 'delete': tree.delete(int(cmd[1]))
s271894920
p03455
u021548497
2,000
262,144
Wrong Answer
17
2,940
67
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()) print("Odd" if a*b//2 else "Even")
s328530289
Accepted
17
2,940
81
a, b = map(int, input().split()) if (a*b)%2: print("Odd") else: print("Even")
s734789980
p03493
u257856080
2,000
262,144
Wrong Answer
17
3,060
324
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=int(input()) count = 0 if n == 0: print(0) elif n == 1: print(1) elif n > 10 and n <100: count = count + 1 n = n%10 if n == 1: count = count + 1 print(count) elif n > 100: count = count + 1 n = n%100 if n > 10: count = count + 1 n = n%10 if n == 1: count = count + 1 print(count)
s785208890
Accepted
17
3,064
489
def ten_decision(n,count): tmp = count if n >= 10 and n<100: count = count + 1 n = n%10 if n == 1: count = count + 1 if tmp == count: return 0 return count n=int(input()) count = 0 if n == 0: print(0) elif n == 1: print(1) elif ten_decision(n,count): print(ten_decision(n,count)) elif n >= 100: count = count + 1 n = n%100 if ten_decision(n,count): print(ten_decision(n,count)) else : if n ==1: count = count + 1 print(count)
s886369104
p03671
u306142032
2,000
262,144
Wrong Answer
17
2,940
113
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
a, b, c = map(int, input().split()) p = [] p.append(a+b) p.append(b+c) p.append(c+a) p.sort() print(p[0] + p[1])
s523113116
Accepted
17
2,940
106
a, b, c = map(int, input().split()) p = [] p.append(a+b) p.append(b+c) p.append(c+a) p.sort() print(p[0])
s150274588
p03385
u740047492
2,000
262,144
Wrong Answer
17
2,940
61
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
a = input() if "abc" in a: print("Yes") else: print("No")
s799619880
Accepted
17
2,940
85
a = input() if "a" in a and "b" in a and "c" in a: print("Yes") else: print("No")
s196408276
p03047
u496762077
2,000
1,048,576
Wrong Answer
17
2,940
44
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
k,n = map(int, input().split()) print(n-k+1)
s009431322
Accepted
48
2,940
44
n,k = map(int, input().split()) print(n-k+1)
s609730305
p03795
u560988566
2,000
262,144
Wrong Answer
17
2,940
49
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n = int(input()) x = n * 800 y = n//15 print(x-y)
s163347074
Accepted
19
2,940
71
n = int(input()) x = n * 800 y = (n // 15) * 200 ans = x - y print(ans)
s800841068
p02407
u811841526
1,000
131,072
Wrong Answer
20
7,396
48
Write a program which reads a sequence and prints it in the reverse order.
input() xs = input().split() print(reversed(xs))
s236072505
Accepted
20
5,540
62
n = input() l = input().split() print(' '.join(reversed(l)))
s132066915
p03477
u131881594
2,000
262,144
Wrong Answer
29
9,136
111
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d=map(int,input().split()) if a+b>c+d: print("left") elif a+b<c+d: print("right") else: print("balanced")
s524530497
Accepted
29
9,184
112
a,b,c,d=map(int,input().split()) if a+b>c+d: print("Left") elif a+b<c+d: print("Right") else: print("Balanced")
s477777209
p03377
u133936772
2,000
262,144
Wrong Answer
28
9,088
62
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x=map(int,input().split()) print('YNeos'[x<a or x>a+b::2])
s719802701
Accepted
29
9,060
61
a,b,x=map(int,input().split()) print(['NO','YES'][a<=x<=a+b])
s297824103
p03456
u202877219
2,000
262,144
Wrong Answer
17
2,940
139
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
import math x,y = map(str, input().split()) a = x+y y = math.sqrt(int(a)) print (a,y) if a == y: print ("Yes") else: print ("No")
s970633650
Accepted
17
2,940
122
import math x,y = map(str, input().split()) a = x+y if math.sqrt(int(a)) % 1 == 0: print("Yes") else: print("No")
s924297868
p03959
u648212584
2,000
262,144
Wrong Answer
272
17,120
1,256
Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N. Mr. Takahashi traversed the range from the west and Mr. Aoki from the east. The height of Mt. i is h_i, but they have forgotten the value of each h_i. Instead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. i (including Mt. i). Mr. Takahashi's record is T_i and Mr. Aoki's record is A_i. We know that the height of each mountain h_i is a positive integer. Compute the number of the possible sequences of the mountains' heights, modulo 10^9 + 7. Note that the records may be incorrect and thus there may be no possible sequence of the mountains' heights. In such a case, output 0.
import sys input = sys.stdin.buffer.readline from operator import itemgetter def main(): N = int(input()) t = list(map(int,input().split())) a = list(map(int,input().split())) MOD = 10**9+7 tt,tl = 0,[False for _ in range(N)] for x,num in enumerate(t): if num > tt: tl[x] = True tt = num at,al = 0,[False for _ in range(N)] for x,num in enumerate(a[::-1]): if num > at: al[-x-1] = True at = num print(tl,al) ans,now = 1,0 for i in range(N): print(i,now) if tl[i] == True and al[i] == True: if now < t[i] == a[i]: now = min(t[i],a[i]) else: print(-1) exit() elif tl[i] == True and al[i] == False: if now > t[i]: print(-1) exit() else: now = t[i] elif tl[i] == False and al[i] == True: if now < a[i]: print(-1) exit() else: now = a[i] else: ans *= min(t[i],a[i]) ans %= MOD print(ans) if __name__ == "__main__": main()
s628527614
Accepted
140
17,120
1,195
import sys input = sys.stdin.buffer.readline from operator import itemgetter def main(): N = int(input()) t = list(map(int,input().split())) a = list(map(int,input().split())) MOD = 10**9+7 tt,tl = 0,[False for _ in range(N)] for x,num in enumerate(t): if num > tt: tl[x] = True tt = num at,al = 0,[False for _ in range(N)] for x,num in enumerate(a[::-1]): if num > at: al[-x-1] = True at = num ans,now = 1,0 for i in range(N): if tl[i] == True and al[i] == True: if now < t[i] == a[i]: now = a[i] else: print(0) exit() elif tl[i] == True and al[i] == False: if t[i] > a[i]: print(0) exit() else: now = t[i] elif tl[i] == False and al[i] == True: if t[i] < a[i]: print(0) exit() else: now = a[i] else: ans *= min(t[i],a[i]) ans %= MOD print(ans) if __name__ == "__main__": main()
s016754098
p03502
u143492911
2,000
262,144
Wrong Answer
17
2,940
121
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() x=int(n) y=0 for i in n: y+=int(i) print(y) print(x) if x%y==0: print("Yes") else: print("No")
s611522005
Accepted
18
3,060
152
n=list(map(int,input())) moji="" ans=0 for i in n: moji+=str(i) ans+=i moji_i=int(moji) if moji_i%ans==0: print("Yes") else: print("No")
s225555262
p03140
u325264482
2,000
1,048,576
Wrong Answer
17
3,064
281
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
N = int(input()) A = input() B = input() C = input() cntAB = N cntBC = N cntCA = N for i in range(N): if A[i] == B[i]: cntAB -= 1 if B[i] == C[i]: cntBC -= 1 if C[i] == A[i]: cntCA -= 1 cnt = [cntAB, cntBC, cntCA] print(sum(cnt) - max(cnt))
s265250111
Accepted
17
3,060
363
N = int(input()) A = input() B = input() C = input() ans = 0 for i in range(N): if A[i] == B[i]: if B[i] == C[i]: ans += 0 else: ans += 1 else: if B[i] == C[i]: ans += 1 else: if C[i] != A[i]: ans += 2 else: ans += 1 print(ans)
s915328227
p00003
u842823276
1,000
131,072
Wrong Answer
40
5,600
249
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.
def ifTriangle(a, b, c): if a**2 + b**2 == c: print("YES") else: print("NO") n=int(input()) for i in range(n): lines=list(map(int, input().split())) lines.sort() ifTriangle(lines[0], lines[1], lines[2]) #ifTriangle(a, b, c)
s360977183
Accepted
40
5,600
230
def ifTriangle(a, b, c): if (a**2) + (b**2) == c**2: print("YES") else: print("NO") n=int(input()) for i in range(n): lines=list(map(int, input().split())) lines.sort() ifTriangle(lines[0], lines[1], lines[2])
s663862085
p03449
u268279636
2,000
262,144
Wrong Answer
20
3,060
195
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()) l1=input().split(' ') l2=input().split(' ') max=0 for i in range(N): sum=0 for j in range(i+1): sum+=int(l1[j]) for k in range(N-i): sum+=int(l2[k]) if max<sum: max=sum
s964000583
Accepted
20
3,064
207
N=int(input()) l1=input().split(' ') l2=input().split(' ') max=0 for i in range(N): sum=0 for j in range(i+1): sum+=int(l1[j]) for k in range(i,N): sum+=int(l2[k]) if max<sum: max=sum print(max)
s360183056
p03434
u627417051
2,000
262,144
Wrong Answer
17
3,060
172
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
N = int(input()) A = list(map(int, input().split())) alice = 0 bob = 0 A.sort() for i in range(N): if i % 2 ==0: alice += A[-i] else: bob += A[-i] print(alice - bob)
s643107955
Accepted
17
3,060
180
N = int(input()) A = list(map(int, input().split())) alice = 0 bob = 0 A.sort() for i in range(N): if i % 2 ==0: alice += A[-i - 1] else: bob += A[-i - 1] print(alice - bob)
s180946466
p02402
u731896389
1,000
131,072
Wrong Answer
20
7,532
77
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
input() a = list(map(int,input().split())) print(min(a),max(a),sum(a)/len(a))
s455522516
Accepted
20
8,568
70
input() a = list(map(int,input().split())) print(min(a),max(a),sum(a))
s138115840
p02646
u932370518
2,000
1,048,576
Wrong Answer
25
9,192
184
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 = [int(a) for a in input().split()] b, w = [int(a) for a in input().split()] t = int(input()) ret = w-v ans = "" if (ret*t) <= (b-a): ans = "NO" else: ans = "YES" print(ans)
s095928534
Accepted
21
9,180
214
a, v = [int(a) for a in input().split()] b, w = [int(a) for a in input().split()] t = int(input()) distance = abs(b-a) ds = v - w ans = "" if (ds * t) < (distance): ans = "NO" else: ans = "YES" print(ans)
s556653360
p02407
u150984829
1,000
131,072
Wrong Answer
20
5,536
39
Write a program which reads a sequence and prints it in the reverse order.
input() print(*sorted(input().split()))
s176023963
Accepted
20
5,556
37
input() print(*input().split()[::-1])
s663680843
p02401
u019678978
1,000
131,072
Wrong Answer
20
7,660
292
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.
alist = [ x for x in input().split() ] if alist[1] == "*" : print(int(alist[0]) * int(alist[2])) elif alist[1] == "/" : print(int(alist[0]) / int(alist[2])) elif alist[1] == "+" : print(int(alist[0]) + int(alist[2])) elif alist[1] == "-" : print(int(alist[0]) - int(alist[2]))
s704876789
Accepted
30
7,804
406
import math while True : alist = [ x for x in input().split() ] if alist[1] == "?" : break elif alist[1] == "*" : print(int(alist[0]) * int(alist[2])) elif alist[1] == "/" : print(math.floor(int(alist[0]) / int(alist[2]))) elif alist[1] == "+" : print(int(alist[0]) + int(alist[2])) elif alist[1] == "-" : print(int(alist[0]) - int(alist[2]))
s157421360
p02645
u695474809
2,000
1,048,576
Wrong Answer
28
9,560
175
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.
import random name = list(input()) print(name[random.randint(0,len(name)-1)],end="") print(name[random.randint(0,len(name)-1)],end="") print(name[random.randint(0,len(name))])
s207956792
Accepted
29
8,848
33
S = input() print(S[0]+S[1]+S[2])
s546836700
p03024
u902576227
2,000
1,048,576
Wrong Answer
17
2,940
103
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
s=input() cnt=0 for i in range(len(s)): if s[i] == 'o': cnt+=1 print("YES" if cnt >= 8 else "NO")
s366027745
Accepted
17
2,940
116
s=input() cnt=0 for i in range(len(s)): if s[i] == 'o': cnt+=1 print("YES" if cnt >= 8-(15-len(s)) else "NO")
s506450434
p02261
u612243550
1,000
131,072
Wrong Answer
20
7,668
928
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
def select(S): for i in range(0, n): minj = i for j in range(i, n): if int(S[j][1]) < int(S[minj][1]): minj = j (S[i], S[minj]) = (S[minj], S[i]) return S def bubble(B): flag = True while flag: flag = False for j in reversed(range(1, n)): if int(B[j][1]) < int(B[j-1][1]): (B[j-1], B[j]) = (B[j], B[j-1]) flag = True return B def isStable(inA, out): for i in range(0, n): for j in range(i+1, n): for a in range(0, n): for b in range(a+1, n): if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]: return "Not Stable" return "Stable" n = int(input()) A = input().split(' ') B = bubble(A[:]) print(" ".join(B)) print(isStable(A, B)) S = select(A[:]) print(" ".join(S)) print(isStable(A, S))
s453678351
Accepted
130
7,764
928
def select(S): for i in range(0, n): minj = i for j in range(i, n): if int(S[j][1]) < int(S[minj][1]): minj = j (S[i], S[minj]) = (S[minj], S[i]) return S def bubble(B): flag = True while flag: flag = False for j in reversed(range(1, n)): if int(B[j][1]) < int(B[j-1][1]): (B[j-1], B[j]) = (B[j], B[j-1]) flag = True return B def isStable(inA, out): for i in range(0, n): for j in range(i+1, n): for a in range(0, n): for b in range(a+1, n): if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]: return "Not stable" return "Stable" n = int(input()) A = input().split(' ') B = bubble(A[:]) print(" ".join(B)) print(isStable(A, B)) S = select(A[:]) print(" ".join(S)) print(isStable(A, S))
s966935341
p03359
u119578112
2,000
262,144
Wrong Answer
17
2,940
93
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?
N = list(map(int, input().split())) if N[0] < N[1]: print(N[0]) else : print(N[0]-1)
s794315793
Accepted
17
2,940
94
N = list(map(int, input().split())) if N[0] <= N[1]: print(N[0]) else : print(N[0]-1)
s476070840
p03643
u723721005
2,000
262,144
Wrong Answer
17
2,940
43
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
str=input(); print ("ABC", str) print('\n')
s735832300
Accepted
17
2,940
23
print("ABC" + input())
s890802845
p03589
u646352133
2,000
262,144
Wrong Answer
17
3,064
124
You are given an integer N. Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w. If there are multiple solutions, any of them will be accepted.
n = int(input()) if n % 4 == 0: out = n/4*3 print(out,out,out) elif n % 2 == 0: print(n/2,n,n) else: pass
s284178143
Accepted
1,968
3,064
280
N = int(input()) for a in range(1,3501): for b in range(1,3501): if (4*a*b - a*N - b*N) > 0: c = (a*b*N) // (4*a*b - a*N - b*N) else: continue if c != 0 and 4/N == (1/a + 1/b + 1/c): print(a,b,c) exit()
s496915076
p02694
u012955130
2,000
1,048,576
Wrong Answer
22
9,164
115
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
X = int(input()) _sum = 100 year = 0 while _sum <= X: _sum = int(_sum * 1.01) year += 1 print(int(year))
s617432525
Accepted
21
9,168
162
import math X = int(input()) _sum = 100 year = 0 while True: if _sum >= X : break _sum = math.floor(_sum * 1.01) year += 1 print(int(year))
s319258104
p03504
u375616706
2,000
262,144
Wrong Answer
386
27,400
256
Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
N, C = list(map(int, input().split())) prog = [] for _ in range(N): prog.append((list)(map(int, input().split()))) T = 10**5 for i in range(T): a = 0 for i in range(T): a = 1 for i in range(T): a = 2 for i in range(T): a = 6 print(a)
s537718256
Accepted
1,600
77,904
670
from itertools import accumulate # -*- coding: utf-8 -*- # python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, C = map(int, input().split()) TV = dict() programs = [list(map(int, input().split())) for _ in range(N)] last_time = max([p[1] for p in programs]) for i in range(1, C+1): TV[i] = [0]*(last_time*2+2) for s, t, c in programs: s *= 2 t *= 2 TV[c][s] += 1 TV[c][t+1] -= 1 for c in range(1, C+1): TV[c] = list(accumulate(TV[c])) ans = 0 for i in range(last_time*2+1): tmp = 0 for c in range(1, C+1): if TV[c][i] > 0: tmp += 1 ans = max(ans, tmp) print(ans)
s764745563
p02271
u022407960
5,000
131,072
Wrong Answer
60
7,776
713
Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
# encoding: utf-8 import sys __input = sys.stdin.readlines() length_1 = int(__input[0]) array_1 = list(map(int, __input[1].split())) length_2 = int(__input[2]) array_2 = list(map(int, __input[3].split())) def solution(): print(length_1, array_1, length_2, array_2) assert length_1 == len(array_1) and length_2 == len(array_2) for i in range(length_2): ans = solve(0, array_2[i]) if ans: print("yes") else: print("no") return None def solve(i, m): if m == 0: return True if i >= length_1: return False res = solve(i + 1, m) or solve(i + 1, m - array_1[i]) return res if __name__ == '__main__': solution()
s480602819
Accepted
20
7,768
738
# encoding: utf-8 import sys __input = sys.stdin.readlines() length_1 = int(__input[0]) array_1 = list(map(int, __input[1].split())) length_2 = int(__input[2]) array_2 = list(map(int, __input[3].split())) record = [False] * 2000 def solution(): assert length_1 == len(array_1) and length_2 == len(array_2) for i in array_1: # record[i] = True for j in range(2000 - i, 0, -1): if record[j]: record[i + j] = True record[i] = True for index in array_2: if record[index]: print("yes") else: print("no") if __name__ == '__main__': solution()
s555369105
p02747
u159994501
2,000
1,048,576
Wrong Answer
18
2,940
72
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 = input() s.replace('hi', '') if s: print('No') else: print('Yes')
s875787102
Accepted
19
2,940
77
s = input() s = s.replace('hi', '') if s: print('No') else: print('Yes')
s013197757
p02613
u765776018
2,000
1,048,576
Wrong Answer
152
9,212
300
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) k = {} k['AC\r'] =0 k["TLE\r"]=0 k["WA\r"]=0 k["RE\r"]=0 for i in range(n): a = str(input()) #print(a) if a in k: k[a]+=1 print("AC x {}".format(k['AC\r'])) print("WA x {}".format(k['WA\r'])) print("TLE x {}".format(k['TLE\r'])) print("RE x {}".format(k['RE\r']))
s526222708
Accepted
159
9,188
284
n = int(input()) k = {} k['AC'] =0 k["TLE"]=0 k["WA"]=0 k["RE"]=0 for i in range(n): a = str(input()) #print(a) if a in k: k[a]+=1 print("AC x {}".format(k['AC'])) print("WA x {}".format(k['WA'])) print("TLE x {}".format(k['TLE'])) print("RE x {}".format(k['RE']))
s259236166
p03557
u411858517
2,000
262,144
Wrong Answer
2,105
23,360
1,052
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() res = 0 for i in range(N): low = 0 high = N - 1 t1 = (low + high) // 2 while (low <= high): if ( A[t1-1] <= B[i] < A[t1]): break elif (B[i] > A[t1]): low = t1 + 1 elif (B[i] < A[t1]): high = t1- 1 elif (t1 == N-1): break t1 = (low + high) // 2 low = 0 high = N - 1 t2 = (low + high) // 2 while (low <= high): if ( C[t2-1] <= B[i] < C[t2] ): break elif (B[i] > C[t2]): low = t2 + 1 elif (B[i] < C[t2]): high = t2 - 1 elif (t2 == 0): break t2 = (low + high) // 2 res += (t1+1) * (N - t2 - 1) print(res, t1, t2)
s015877798
Accepted
327
23,328
272
import bisect N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() res = 0 for b in B: res += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) print(res)
s666787404
p03965
u415905784
2,000
262,144
Wrong Answer
18
3,188
53
AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
s = input() print((s.count('p') - s.count('g')) // 2)
s919008049
Accepted
18
3,188
53
s = input() print((s.count('g') - s.count('p')) // 2)