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
s016034031
p03761
u548545174
2,000
262,144
Wrong Answer
25
3,572
312
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
import copy n = int(input()) S = [list(input()) for _ in range(n)] common_list = copy.deepcopy(S[0]) for s in S: print(s, common_list) for i in common_list: if i not in s: common_list.remove(i) else: s.remove(i) print("".join(sorted(common_list)))
s232855903
Accepted
33
3,956
340
import string alphabets = string.ascii_lowercase n = int(input()) S = [input() for _ in range(n)] counter = {} for alphabet in alphabets: alphabet_count = [s.count(alphabet) for s in S] counter[alphabet] = min(alphabet_count) ans = "" for alphabet, count in counter.items(): ans += alphabet*count print("".join(sorted(ans)))
s320036512
p03699
u547167033
2,000
262,144
Wrong Answer
19
3,064
260
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
n=int(input()) s=[int(input()) for i in range(n)] dp=[[0]*10 for i in range(n+1)] for i in range(1,n+1): for j in range(10): dp[i][(j+s[i-1])%10]=max(dp[i-1][(j+s[i-1])%10],dp[i-1][j]+s[i-1]) ans=0 for i in range(1,10): ans=max(ans,dp[n][i]) print(ans)
s348224590
Accepted
18
3,064
276
n=int(input()) s=[int(input()) for i in range(n)] dp=[[-10**9]*10 for i in range(n+1)] dp[0][0]=0 for i in range(1,n+1): for j in range(10): dp[i][(j+s[i-1])%10]=max(dp[i-1][(j+s[i-1])%10],dp[i-1][j]+s[i-1]) ans=0 for i in range(1,10): ans=max(ans,dp[n][i]) print(ans)
s347812726
p03997
u940652437
2,000
262,144
Wrong Answer
31
9,032
63
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h/0.5)
s081649812
Accepted
30
9,096
66
a=int(input()) b=int(input()) h=int(input()) print(int((a+b)*h/2))
s820897929
p03360
u350093546
2,000
262,144
Wrong Answer
17
2,940
86
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
a=list(map(int,input().split())) n=int(input()) x=max(a)*2**n print(x+sum(a)-max(a)*2)
s827538137
Accepted
17
2,940
87
a=list(map(int,input().split())) n=int(input()) x=max(a)*(2**n) print(x+sum(a)-max(a))
s602582389
p03457
u606523772
2,000
262,144
Wrong Answer
472
27,380
421
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()) point = [0, 0] t_list = [] ans = "Yes" t = list(map(int, input().split())) dis = abs(point[0]-t[1])+abs(point[1]-t[2]) t_list.append(t) if t[0] < dis: ans = "No" point = [t[1], t[2]] for i in range(N-1): t = list(map(int, input().split())) dis = abs(point[0]-t[1])+abs(point[1]-t[2]) if t_list[-1][0]-t[0] < dis: ans = "No" point = [t[1], t[2]] t_list.append(t) print(ans)
s053286715
Accepted
490
27,380
471
N = int(input()) point = [0, 0] t_list = [] ans = "Yes" t = list(map(int, input().split())) dis = abs(point[0]-t[1])+abs(point[1]-t[2]) t_list.append(t) if t[0] < dis or t[0]%2!=dis%2: ans = "No" point = [t[1], t[2]] for i in range(N-1): t = list(map(int, input().split())) dis = abs(point[0]-t[1])+abs(point[1]-t[2]) if t[0]-t_list[-1][0] < dis or (t[0]-t_list[-1][0])%2!=dis%2: ans = "No" point = [t[1], t[2]] t_list.append(t) print(ans)
s393445450
p03351
u328755070
2,000
1,048,576
Wrong Answer
17
2,940
148
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = list(map(int, input().split())) if abs(a - c) <= d or (abs(a - c) <= d and a <= b and b <= c): print('Yes') else: print('No')
s374917355
Accepted
17
2,940
146
a, b, c, d = list(map(int, input().split())) if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d): print('Yes') else: print('No')
s827386971
p02614
u698868214
1,000
1,048,576
Wrong Answer
52
9,108
456
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
H,W,K = map(int,input().split()) board = [list(input()) for _ in range(H)] ans = 0 for i in range(2**H): part1 = [] part1 += board for j in range(H): if (i>>j)&1: part1[j] = ["*"]*W for k in range(2**W): part2 = [] part2 += part1 for l in range(W): if (k>>l)&1: for n in range(H): part2[n][l] = "*" cnt = 0 for m in part2: cnt += m.count("#") if cnt == K: ans += 1 print(ans)
s559504552
Accepted
63
9,048
316
H,W,K = map(int,input().split()) c = [list(input()) for _ in range(H)] ans = 0 for I in range(2**H): for J in range(2**W): black = 0 for i in range(H): for j in range(W): if (I>>i)&1 == 0 and (J>>j)&1 == 0 and c[i][j] == "#": black += 1 if black == K: ans += 1 print(ans)
s870099392
p03168
u060938295
2,000
1,048,576
Wrong Answer
1,360
14,676
366
Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i. Taro has tossed all the N coins. Find the probability of having more heads than tails.
import sys import numpy as np sys.setrecursionlimit(10 ** 9) #def input(): # return sys.stdin.readline()[:-1] N = int(input()) P = list(map(float,input().split())) dp = np.zeros(N+1, dtype=float) dp[0] = 1 for c in P: dp = np.append(dp[:-1] * (1-c), 0) + np.append(0, dp[:-1] * c) print(dp) ans = np.sum(dp[N//2+1:]) print(ans)
s655799945
Accepted
282
12,504
364
import sys import numpy as np sys.setrecursionlimit(10 ** 9) def input(): return sys.stdin.readline()[:-1] N = int(input()) P = list(map(float,input().split())) dp = np.zeros(N+1, dtype=float) dp[0] = 1 for c in P: dp = np.append(dp[:-1] * (1-c), 0) + np.append(0, dp[:-1] * c) # print(dp) ans = np.sum(dp[N//2+1:]) print(ans)
s440298129
p03635
u649558044
2,000
262,144
Wrong Answer
17
2,940
43
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
s = input() print(s[0]+str(len(s)-2)+s[-1])
s440204968
Accepted
17
2,940
60
n, m = map(int, input().split(' ')) print((n - 1) * (m - 1))
s352064704
p02612
u204437779
2,000
1,048,576
Wrong Answer
30
9,144
36
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()) t = n%1000 print(t)
s404069757
Accepted
29
9,168
108
n = int(input()) s = (n-(n%1000))/1000 if 1000*s == n: print(0) else: t = int(1000*(s+1) - n) print(t)
s390901586
p03433
u409064224
2,000
262,144
Wrong Answer
17
2,940
114
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()) while n < 0: n -= 500 n += 500 if n <= a: print("Yes") else: print("No")
s819595131
Accepted
17
2,940
92
n = int(input()) a = int(input()) n = n % 500 if n <= a: print("Yes") else: print("No")
s205795111
p02389
u839788696
1,000
131,072
Wrong Answer
20
5,572
43
Write a program which calculates the area and perimeter of a given rectangle.
a,b = map(int, input().split()) print(a*b)
s812543019
Accepted
20
5,580
64
a,b = map(int, input().split()) m= a*b l = 2*a + 2*b print(m,l)
s669297380
p03659
u021548497
2,000
262,144
Wrong Answer
149
24,812
188
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
n = int(input()) a = [int(x) for x in input().split()] ans = pow(10, 15) key = sum(a) p = key for i in range(n): p += a[i] if ans > abs(key-2*p): ans = abs(key-2*p) print(ans)
s645930380
Accepted
146
24,832
188
n = int(input()) a = [int(x) for x in input().split()] ans = pow(10, 15) key = sum(a) p = 0 for i in range(n-1): p += a[i] if ans > abs(key-2*p): ans = abs(key-2*p) print(ans)
s119631892
p03371
u552201227
2,000
262,144
Wrong Answer
117
3,060
154
"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()) ans=a*x+b*y for i in range(1,max(x,y)+1): ab=i*2 abc=ab*c+a*max(0,x-1)+b*max(0,y-1) ans = min(ans,abc) print(ans)
s737668131
Accepted
120
3,060
155
a,b,c,x,y=map(int,input().split()) ans=a*x+b*y for i in range(1,max(x,y)+1): ab=i*2 abc=ab*c+a*max(0,x-i)+b*max(0,y-i) ans = min(ans,abc) print(ans)
s970678773
p03846
u595716769
2,000
262,144
Wrong Answer
117
13,880
489
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
n = int(input()) L = [int(i) for i in input().split()] L.sort() print(L) def out_detect(n,L): flag = 0 if n%2 == 0: for i in range(n): if L[i] != -(-(i+1)//2)*2-1: flag = 1 break else: if L[0] != 0: flag = 1 return (flag) for i in range(1,n): if L[i] != (-(-i//2)*2): flag = 1 break return (flag) if out_detect(n,L) == 1: print(0) else: if n%2 == 0: print(pow(2,n//2)) else: print(pow(2,(n-1)//2))
s725564396
Accepted
104
13,880
505
n = int(input()) L = [int(i) for i in input().split()] L.sort() def out_detect(n,L): flag = 0 if n%2 == 0: for i in range(n): if L[i] != -(-(i+1)//2)*2-1: flag = 1 break else: if L[0] != 0: flag = 1 return (flag) for i in range(1,n): if L[i] != (-(-i//2)*2): flag = 1 break return (flag) if out_detect(n,L) == 1: print(0) else: if n%2 == 0: out = pow(2,n//2) else: out = pow(2,(n-1)//2) print(out%(pow(10,9)+7))
s195086327
p03760
u772180901
2,000
262,144
Wrong Answer
17
3,060
173
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.
o = input() e = input() ans = "" m = min(len(o),len(e)) for i in range(m): ans += o[i] ans += e[i] if o < e: ans += e[-1] elif e < o: ans += o[-1] print(ans)
s387722842
Accepted
18
3,064
193
o = input() e = input() ans = "" m = min(len(o),len(e)) for i in range(m): ans += o[i] ans += e[i] if len(o) < len(e): ans += e[-1] elif len(e) < len(o): ans += o[-1] print(ans)
s740052256
p03739
u966740656
2,000
262,144
Wrong Answer
70
14,644
632
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.
def c(ints): for i in range(len(ints)): if ints[i] != 0: sig = 1 if ints[i] > 0 else -1 total = ints[i] mov = i j = i break if i == len(ints) - 1: return i + 1 for i_ in ints[j+1:]: tmp = total + i_ if tmp == 0: mov +=1 tmp = -sig elif sig * tmp > 0: mov += abs(tmp) + 1 tmp = -sig sig *= -1 total = tmp return mov _ = input() inp = input() inp = inp.split(' ') inp = [int(i_) for i_ in inp] c(inp)
s018560458
Accepted
97
14,468
707
def c(ints): sig = -1 sig_ = +1 total = 0 total_ = 0 mov = 0 mov_ = 0 for i_ in ints: tmp = total + i_ tmp_ = total_ + i_ if tmp == 0: mov +=1 tmp = -sig elif sig * tmp > 0: mov += abs(tmp) + 1 tmp = -sig if tmp_ == 0: mov_ +=1 tmp_ = -sig_ elif sig_ * tmp_ > 0: mov_ += abs(tmp_) + 1 tmp_ = -sig_ sig *= -1 total = tmp sig_ *= -1 total_ = tmp_ return min(mov, mov_) _ = input() inp = input() inp = inp.split(' ') inp = [int(i_) for i_ in inp] print(c(inp))
s293282779
p02678
u207241407
2,000
1,048,576
Wrong Answer
2,207
66,220
936
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
import numpy as np N, M = map(int, input().split()) ab = np.array([list(map(int, input().split())) for _ in range(M)]) dp = [[0, float("inf")] for _ in range(N + 1)] tmp = {1} while tmp: for i in list(tmp): abi = ab[np.any(ab == i, axis=1)] ab = np.delete(ab, np.where(ab == i)[0], axis=0) for a, b in abi: if a == 1: dp[b][0] = 1 dp[b][1] = 1 tmp.add(b) elif b == 1: dp[a][0] = 1 dp[a][1] = 1 tmp.add(a) else: if dp[a][1] > dp[b][1] + 1: dp[a][0] = b dp[a][1] = dp[b][1] + 1 if dp[b][1] > dp[a][1] + 1: dp[b][0] = a dp[b][1] = dp[a][1] + 1 tmp.add(a) tmp.add(b) tmp.remove(i) for ans in dp[2 : N + 1]: print(ans[0])
s379229747
Accepted
448
34,940
704
import sys from collections import deque def main(): n, m = map(int, sys.stdin.readline().split()) to = [[] for _ in range(n + 1)] for _ in range(m): a, b = map(int, sys.stdin.readline().split()) to[a].append(b) to[b].append(a) INF = float("inf") dist = [INF] * (n + 1) dist[1] = 0 pre = [0] * (n + 1) que = deque([]) que.append(1) while que: p = que.popleft() for i in to[p]: if dist[i] > dist[p] + 1: dist[i] = dist[p] + 1 pre[i] = p que.append(i) print("Yes") for i in range(2, n + 1): print(pre[i]) if __name__ == "__main__": main()
s396651067
p03251
u589432040
2,000
1,048,576
Wrong Answer
20
3,060
211
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 = list(map(int, input().split())) y = list(map(int, input().split())) for Z in range(X+1, Y+1): if max(x)<Z and min(y)>=Z: print("No War") else: print("War")
s816851057
Accepted
18
3,060
231
N, M, X, Y = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) for Z in range(X+1, Y+1): if max(x)<Z and min(y)>=Z: war = "No War" break else: war = "War" print(war)
s061724829
p02388
u186524656
1,000
131,072
Wrong Answer
30
6,724
23
Write a program which calculates the cube of a given integer x.
print(2**3) print(3**3)
s058622011
Accepted
30
6,724
28
x = int(input()) print(x**3)
s194436113
p03478
u243312682
2,000
262,144
Wrong Answer
48
3,580
362
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).
def main(): inp = list(map(int, input().split())) n = inp[0] a = inp[1] b = inp[2] n_sum = 0 res = 0 for i in range(1, n+1): n_list = list(map(int, list(str(i)))) n_sum = sum(n_list) print(i, n_sum) if a <= n_sum and n_sum <= b: res += i print(res) if __name__ == '__main__': main()
s935063708
Accepted
35
3,064
338
def main(): inp = list(map(int, input().split())) n = inp[0] a = inp[1] b = inp[2] n_sum = 0 res = 0 for i in range(1, n+1): n_list = list(map(int, list(str(i)))) n_sum = sum(n_list) if a <= n_sum and n_sum <= b: res += i print(res) if __name__ == '__main__': main()
s699440706
p03739
u665038048
2,000
262,144
Wrong Answer
17
3,064
472
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.
a = list(map(int, input().split())) t1, s1 = 0, 0 for i, x in enumerate(a): s1 += x if i % 2 == 0: if s1 < 1: t1 += (1-s1) s1 = 1 else: if s1 > -1: t1 += (s1+1) s1 = -1 t2, s2 = 0, 0 for i, x in enumerate(a): s2 += x if i % 2 == 0: if s2 > -1: t2 += (s2+1) s2 = -1 else: if s2 < 1: t2 += (1-s2) s2 = 1 print(min(t1, t2))
s200093085
Accepted
119
14,332
489
n = int(input()) a = list(map(int, input().split())) t1, s1 = 0, 0 for i, x in enumerate(a): s1 += x if i % 2 == 0: if s1 < 1: t1 += (1-s1) s1 = 1 else: if s1 > -1: t1 += (s1+1) s1 = -1 t2, s2 = 0, 0 for i, x in enumerate(a): s2 += x if i % 2 == 0: if s2 > -1: t2 += (s2+1) s2 = -1 else: if s2 < 1: t2 += (1-s2) s2 = 1 print(min(t1, t2))
s117691539
p03478
u923659712
2,000
262,144
Wrong Answer
39
2,940
161
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()) oo=0 for i in range(1,n+1): f=str(i) l=0 for j in range(len(f)): l+=int(f[j]) if a<=l<=b: oo+=l print(oo)
s577591651
Accepted
37
3,060
156
n,a,b=map(int,input().split()) oo=0 for i in range(1,n+1): f=str(i) l=0 for j in range(len(f)): l+=int(f[j]) if a<=l<=b: oo+=i print(oo)
s405160629
p02694
u861886710
2,000
1,048,576
Wrong Answer
25
9,064
105
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?
import math X = int(input()) A = 100 i = 0 while X >= A: A = math.floor(A * 1.01) i += 1 print(i)
s796232325
Accepted
24
9,116
104
import math X = int(input()) A = 100 i = 0 while X > A: A = math.floor(A * 1.01) i += 1 print(i)
s295803036
p03910
u156743806
2,000
262,144
Wrong Answer
17
2,940
62
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
import math N=int(input()) print(int(math.sqrt(N*2-0.25)+0.5))
s554752257
Accepted
21
3,408
202
import math N=int(input()) M=int(math.sqrt(N*2-0.25)+0.5) left = M*(M-1) // 2 sum_=0 for i in range(1,M-(N-left)): print(i) sum_ += i for i in range(M-(N-left),M): print(i+1) sum_ += i+1
s136831187
p03456
u110656379
2,000
262,144
Wrong Answer
18
2,940
111
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 a,b=input().split() c=int(a+b) d=math.sqrt(c) if type(d)=="int": print("Yes") else: print("No")
s654661389
Accepted
17
2,940
109
import math a,b=input().split() c=int(a+b) d=int(math.sqrt(c)) if d**2==c: print("Yes") else: print("No")
s933610440
p02255
u777299405
1,000
131,072
Wrong Answer
30
6,720
240
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.
n = int(input()) a = list(map(int, input().split())) for i in range(1, len(a)): # print(''.join(map(str, a))) v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j + 1] = a[j] j -= 1 a[j + 1] = v print(*a)
s319026649
Accepted
40
6,756
217
n = int(input()) a = list(map(int, input().split())) for i in range(1, len(a)): print(*a) v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j + 1] = a[j] j -= 1 a[j + 1] = v print(*a)
s042238532
p03493
u898042052
2,000
262,144
Wrong Answer
17
2,940
74
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.
input_list = [int(i) for i in input().split()] print(input_list.count(1))
s921401139
Accepted
17
2,940
74
args = input() lst = [int(x) for x in list(str(args))] print(lst.count(1))
s610114571
p02409
u217069758
1,000
131,072
Wrong Answer
20
5,604
301
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
n = int(input()) house = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] for i in range(n): b,f,r,v = map(int, input().split()) house[b - 1][f - 1][r - 1] += v for k in range(4): for j in range(3): print(str(house[k][j])) if k != 3: print('#' * 20)
s229247117
Accepted
20
5,608
375
n = int(input()) oh = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] for tr in range(n): b, f, r, v = map(int, input().split()) oh[b - 1][f - 1][r - 1] += v for k in range(4): for j in range(3): tmp = '' for i in range(10): tmp += (' ' + str(oh[k][j][i])) print(tmp) if k < 3: print('#' * 20)
s137607098
p03860
u020176853
2,000
262,144
Wrong Answer
17
2,940
52
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.
#21:27 s = list(input().upper()) print("A"+s[0]+"C")
s555678381
Accepted
17
2,940
153
#21:27 abc = list(map(str, input().split())) prex = list(abc[0].upper()) x = list(abc[1].upper()) posx = list(abc[2].upper()) print(prex[0]+x[0]+posx[0])
s363648748
p03549
u871303155
2,000
262,144
Wrong Answer
24
3,060
214
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).
import math N, M = map(int, input().split()) t = 100 * (N - M) + 1900 * M ans = 0 first_p = (1/2) ** M p = first_p for i in range(1, 10001): ans += i * t * p p = p * (1 - first_p) print(math.ceil(ans))
s362737209
Accepted
18
3,060
111
import math N, M = map(int, input().split()) t = 100 * (N - M) + 1900 * M ans = t * (2 ** M) print(int(ans))
s042079341
p02614
u887152994
1,000
1,048,576
Wrong Answer
79
9,216
789
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
import itertools H,W,K= map(int,input().split()) List=[list(input()) for i in range(H)] nums=[] total=0 for i in range(1,H+W+1): nums.append(i) for q in range(0,H+W+1): hoge=[] for balls in itertools.combinations(nums, q): hoge.append(balls) for p in range(0,len(hoge)): List_sub=List for i in range(1,H+1): if i in hoge[p]: for j in range(0,W): List_sub[i-1][j]="x" for i in range(H+1,H+W+1): if i in hoge[p]: for j in range(0,H): List_sub[j][i-H-1]="x" s=0 for i in range(0,H): for j in range(0,W): if List_sub[i][j]=="#": s+=1 if s== K: total+=1 print(total)
s093408936
Accepted
165
9,452
804
import itertools import copy H,W,K= map(int,input().split()) List=[list(input()) for i in range(H)] nums=[] total=0 for i in range(1,H+W+1): nums.append(i) for q in range(0,H+W+1): hoge=[] for balls in itertools.combinations(nums, q): hoge.append(balls) for p in range(0,len(hoge)): Listo=copy.deepcopy(List) for i in range(1,H+1): if i in hoge[p]: for j in range(0,W): Listo[i-1][j]="x" for i in range(H+1,H+W+1): if i in hoge[p]: for j in range(0,H): Listo[j][i-H-1]="x" s=0 for i in range(0,H): for j in range(0,W): if Listo[i][j]=="#": s+=1 if s== K: total+=1 print(total)
s243513451
p03696
u279493135
2,000
262,144
Wrong Answer
295
21,516
796
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from bisect import bisect import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() S = input() T = S.replace("()", "") l = 0 r = 0 for x in T: if x == ")": l += 1 else: r += 1 print("("*l + S + ")"*r)
s342581653
Accepted
17
3,060
166
N = int(input()) S = input() l = 0 r = 0 for s in S: if s == "(": r += 1 else: if r >= 1: r -= 1 else: l += 1 print("("*l + S + ")"*r)
s335497286
p02612
u489247698
2,000
1,048,576
Wrong Answer
27
9,148
44
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(int(A))
s386734125
Accepted
31
9,144
80
N = int(input()) if N%1000==0: A = 0 else: A =1000-( N % 1000) print(int(A))
s820192796
p03943
u272522520
2,000
262,144
Wrong Answer
20
2,940
115
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.
s = list(map(int,input().split())) SUM = s[0]+s[1]+s[2] if SUM%2 ==0: print("YES") else: print("NO")
s950201357
Accepted
17
3,060
156
a,b,c = list(map(int, input().split())) if a == b+c: print("Yes") elif b == a+c: print("Yes") elif c == a+b: print("Yes") else: print("No")
s989767066
p03448
u382303205
2,000
262,144
Wrong Answer
18
3,060
191
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a=int(input()) b=int(input()) c=int(input()) x=int(input()) count = 0 for i in range(a+1): for j in range(b+1): if x <= i*500 + j*100 + c*50: count += 1 print(count)
s235122814
Accepted
18
3,064
214
a=int(input()) b=int(input()) c=int(input()) x=int(input()) count = 0 for i in range(a+1): for j in range(b+1): if x >= i*500 + j*100 and x <= i*500 + j*100 + c*50: count += 1 print(count)
s325532931
p03563
u450883456
2,000
262,144
Wrong Answer
17
2,940
46
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
a = int(input()) b = int(input()) print(2*a-b)
s590487605
Accepted
17
2,940
46
a = int(input()) b = int(input()) print(2*b-a)
s203935887
p03469
u500279510
2,000
262,144
Wrong Answer
17
2,940
43
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
S = input() print('2018'+(S.strip('2017')))
s383847437
Accepted
17
2,940
44
S = input() print('2018'+(S.lstrip('2017')))
s151608021
p03447
u064408584
2,000
262,144
Wrong Answer
17
3,064
286
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?
def C_Candies(): N=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) count=0 for i in range(N): if sum(a[i+1:N])<sum(b[i:N-1]): break count = count +1 print(sum(a[0:count])+sum(b[count-1:N+1])) C_Candies()
s768935669
Accepted
17
2,940
61
X =int(input()) A=int(input()) B=int(input()) print((X-A)%B)
s884786231
p03605
u235066013
2,000
262,144
Wrong Answer
17
2,940
72
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=str(input()) if N[0]==9 or N[1]==9: print('Yes') else: print('NO')
s792430692
Accepted
17
2,940
76
N=str(input()) if N[0]=='9' or N[1]=='9': print('Yes') else: print('No')
s273793875
p03485
u275488119
2,000
262,144
Wrong Answer
17
2,940
49
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = map(int, input().split()) print((a+b+1)/2)
s794924822
Accepted
57
3,060
54
a, b = map(int, input().split()) print(int((a+b+1)/2))
s184345604
p02850
u948524308
2,000
1,048,576
Wrong Answer
2,105
34,032
473
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.
N=int(input()) R=[[] for i in range(N)] C=[[] for i in range(N)] a=[] b=[] L=[] for i in range(N-1): ai,bi=map(int,input().split()) a.append(ai-1) b.append(bi-1) R[a[i]].append(b[i]) L.append(len(R[a[i]])) K=max(L) if len(R[0])!=K: K+=1 print(K) for i in range(N-1): for k in range(1,K+1): if not k in C[a[i]]: print(k) C[a[i]].append(k) C[b[i]].append(k) break else:continue
s235671010
Accepted
820
61,508
627
N=int(input()) G=[[] for i in range(N)] a=[] b=[] for i in range(N-1): ai,bi=map(int,input().split()) a.append(ai-1) b.append(bi-1) G[ai-1].append(bi-1) G[bi-1].append(ai-1) k=[0]*N from collections import deque q=deque([0]) visited=[0]*N ans={} p=[-1]*N kmx=0 while q: x=q.popleft() visited[x]=1 cnt=1 for i in G[x]: if visited[i]!=0:continue if p[x]==cnt: cnt+=1 ans[(x,i)]=cnt ans[(i,x)]=cnt p[i] = cnt cnt += 1 kmx=max(kmx,cnt-1) q.append(i) print(kmx) for i in range(N-1): print(ans[(a[i],b[i])])
s393924071
p03155
u477320129
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((N-H+1)+(N-W+1))
s754761053
Accepted
17
2,940
74
N = int(input()) H = int(input()) W = int(input()) print((N-H+1)*(N-W+1))
s619387958
p03555
u171366497
2,000
262,144
Wrong Answer
18
2,940
68
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a=input() b=input() if a==b[::-1]: print('Yes') else:print('No')
s167618505
Accepted
18
2,940
68
a=input() b=input() if a==b[::-1]: print('YES') else:print('NO')
s476644796
p02393
u406434162
1,000
131,072
Wrong Answer
20
5,592
202
Write a program which reads three integers, and prints them in ascending order.
a,b,c = map(int,input().split()) if a > b: x = a a = b b = a elif b > c: x = b b = c c = x elif a > b: x = a a = b b = x print(a,b,c,end = " ")
s176802801
Accepted
20
5,596
214
a,b,c = map(int,input().split()) if a > b: x = a a = b b = x if b > c: x = b b = c c = x if a > b: x = a a = b b = x print(a,b,c,sep = " ")
s026264519
p03814
u506587641
2,000
262,144
Wrong Answer
64
11,256
171
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s = str(input()) Alst = [] Zlst = [] for i in range(len(s)): if s[i]=='A': Alst.append(i) elif s[i]=='Z': Zlst.append(i) print(max(Zlst)-min(Alst))
s201795865
Accepted
66
11,204
173
s = str(input()) Alst = [] Zlst = [] for i in range(len(s)): if s[i]=='A': Alst.append(i) elif s[i]=='Z': Zlst.append(i) print(max(Zlst)-min(Alst)+1)
s312584276
p03759
u854093727
2,000
262,144
Wrong Answer
17
2,940
89
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c = map(int,input().split()) if b-a == c-b : print("Yes") else: print("No")
s988040313
Accepted
17
2,940
89
a,b,c = map(int,input().split()) if b-a == c-b : print("YES") else: print("NO")
s439751374
p02927
u268792407
2,000
1,048,576
Wrong Answer
18
3,060
197
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
m,d=map(int,input().split()) month = [i for i in range(1,m+1)] ct=0 if d<10: print(0) exit() for i in range(11,d+1): a=int(str(i)[0]) b=int(str(i)[1]) if a*b in month: ct+=1 print(ct)
s420156332
Accepted
17
3,060
216
m,d=map(int,input().split()) month = [i for i in range(1,m+1)] ct=0 if d<10: print(0) exit() for i in range(11,d+1): a=int(str(i)[0]) b=int(str(i)[1]) if a*b in month and a>=2 and b>=2: ct+=1 print(ct)
s652343646
p03578
u858136677
2,000
262,144
Wrong Answer
2,105
36,956
309
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.
n = int(input()) d = list(map(int,input().split())) m = int(input()) t = list(map(int,input().split())) for i in range(n): for k in range(len(d)): print(len(d)) if len(t) == 0: print('YES') break elif t[0] == d[k]: del d[k] del t[0] break if len(t) == 0: print('YES') else: print('NO')
s095656850
Accepted
284
57,056
316
import collections n = int(input()) d = list(map(int,input().split())) m = int(input()) t = list(map(int,input().split())) dcounter = collections.Counter(d) tcounter = collections.Counter(t) check = True for i in tcounter.items(): if dcounter[i[0]] < i[1]: check = False if check: print('YES') else: print('NO')
s588831951
p03193
u391731808
2,000
1,048,576
Wrong Answer
21
3,188
125
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?
N,H,W = map(int,input().split()) AB = [list(map(int,input().split())) for _ in [0]*N] print(sum(a<=H and b<=W for a,b in AB))
s281169994
Accepted
20
3,188
126
N,H,W = map(int,input().split()) AB = [list(map(int,input().split())) for _ in [0]*N] print(sum(a>=H and b>=W for a,b in AB))
s085293342
p03457
u711539583
2,000
262,144
Wrong Answer
441
27,324
328
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.
import sys n = int(input()) txy = [] for i in range(n): txy.append(list(map(int, input().split()))) pt = 0 py = 0 px = 0 for t, x, y in txy: dt = t - pt dx = x - px dy = y - py ax = abs(dx) % 2 ay = abs(dy) % 2 a = ax + ay % 2 if abs(dx) + abs(dy) > dt or a != dt % 2: print("No") sys.exit() print("Yes")
s091335309
Accepted
432
27,324
331
import sys n = int(input()) txy = [] for i in range(n): txy.append(list(map(int, input().split()))) pt = 0 py = 0 px = 0 for t, x, y in txy: dt = t - pt dx = x - px dy = y - py ax = abs(dx) % 2 ay = abs(dy) % 2 a = (ax + ay) % 2 if abs(dx) + abs(dy) > dt or a != dt % 2: print("No") sys.exit() print("Yes")
s499671005
p03155
u814986259
2,000
1,048,576
Wrong Answer
17
2,940
69
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()) H+=1-N W+=1-N print(H*W)
s639416809
Accepted
30
9,096
67
N=int(input()) H=int(input()) W=int(input()) print((N-H+1)*(N-W+1))
s255637578
p03597
u539517139
2,000
262,144
Wrong Answer
17
2,940
42
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
n=int(input()) a=int(input()) print(n*2-a)
s029122495
Accepted
17
2,940
44
n=int(input()) a=int(input()) print(n**2-a)
s162260308
p02612
u649840780
2,000
1,048,576
Wrong Answer
27
9,152
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()) print(1000-(n//1000))
s237821796
Accepted
27
9,148
44
n = int(input()) print((1000-(n%1000))%1000)
s295182621
p03795
u754022296
2,000
262,144
Wrong Answer
17
2,940
61
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()) print(800*(min(n, 15)) + 600*(max(0, n-15)))
s342292460
Accepted
17
2,940
43
n = int(input()) print(800*n - 200*(n//15))
s507062874
p02678
u934868410
2,000
1,048,576
Wrong Answer
1,171
68,848
476
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
import queue from collections import defaultdict n,m = map(int,input().split()) g = defaultdict(set) ans = [0]*n for _ in range(m): a,b = map(int,input().split()) a -= 1 b -= 1 g[a].add(b) g[b].add(a) visited = [False]*n visited[0] = True q = queue.Queue() q.put(0) while not q.empty(): v = q.get() for p in g[v]: if not visited[p]: ans[p] = v q.put(p) visited[p] = True for x in ans[1:]: print(x+1)
s213480943
Accepted
1,131
68,864
489
import queue from collections import defaultdict n,m = map(int,input().split()) g = defaultdict(set) ans = [0]*n for _ in range(m): a,b = map(int,input().split()) a -= 1 b -= 1 g[a].add(b) g[b].add(a) visited = [False]*n visited[0] = True q = queue.Queue() q.put(0) while not q.empty(): v = q.get() for p in g[v]: if not visited[p]: ans[p] = v q.put(p) visited[p] = True print('Yes') for x in ans[1:]: print(x+1)
s178652745
p04000
u952022797
3,000
262,144
Wrong Answer
2,130
232,816
686
We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column. Compute the following: * For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
# -*- coding: utf-8 -*- import sys def main(): H, W, N = map(int, input().split(" ")) AB = [] for _ in range(N): a, b = map(int, input().split(" ")) AB.append((a, b)) ans = {} for i, val in enumerate(AB): a, b = val a, b = a-1, b-1 for ba in range(max(0, a-2), min(H-2, a+1)): for bb in range(max(0, b-2), min(W-2, b+1)): if (ba, bb) in ans.keys(): ans[(ba, bb)] += 1 else: ans[(ba, bb)] = 1 if bb == 3: print("{} {}".format(a+1, b+1)) ans2 = [0] * 10 total = (H-2) * (W-2) t = 0 print(ans) for i in ans.values(): ans2[i] += 1 t += 1 ans2[0] = total - t for i in range(10): print(ans2[i]) if __name__ == "__main__": main()
s492284171
Accepted
1,402
165,180
621
# -*- coding: utf-8 -*- import sys def main(): H, W, N = map(int, input().split(" ")) AB = [] for _ in range(N): a, b = map(int, input().split(" ")) AB.append((a, b)) ans = {} for i, val in enumerate(AB): a, b = val a, b = a-1, b-1 for ba in range(max(0, a-2), min(H-2, a+1)): for bb in range(max(0, b-2), min(W-2, b+1)): if (ba, bb) in ans.keys(): ans[(ba, bb)] += 1 else: ans[(ba, bb)] = 1 ans2 = [0] * 10 total = (H-2) * (W-2) t = 0 for i in ans.values(): ans2[i] += 1 t += 1 ans2[0] = total - t for i in range(10): print(ans2[i]) if __name__ == "__main__": main()
s214357355
p03992
u859897687
2,000
262,144
Wrong Answer
18
2,940
32
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
s=input() print(s[:4]+' '+s[5:])
s439040838
Accepted
17
2,940
32
s=input() print(s[:4]+' '+s[4:])
s728693767
p02402
u743390845
1,000
131,072
Wrong Answer
30
7,540
238
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.
n= int(input()) l= list(map(int,input().split())) s= 0 for i in range(n-1): if(l[i+1]<l[0]): l[0],l[i+1]= l[i+1],l[0] for j in range(n-1): if(l[n-1]<l[j]): l[n-1],l[j]= l[j],l[n-1] for k in range(n-1): s+= l[i] print(l[0],l[n-1],s)
s177226934
Accepted
20
8,656
226
n= int(input()) l= list(map(int,input().split())) s= 0 for i in range(n): if(l[i]<l[0]): l[0],l[i]= l[i],l[0] for j in range(n): if(l[n-1]<l[j]): l[n-1],l[j]= l[j],l[n-1] for k in range(n): s+= l[k] print(l[0],l[n-1],s)
s665551000
p03386
u252828980
2,000
262,144
Wrong Answer
17
3,060
198
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a,b,k = map(int,input().split()) lia,lib = [],[] for i in range(a,min(a+k,b)): lia.append(i) for i in range(max(a,b-k+1),b+1): lib.append(i) lia.extend(lib) for i in set(lia): print(i)
s153927757
Accepted
18
3,064
213
a,b,k = map(int,input().split()) lia,lib = [],[] for i in range(a,min(a+k,b)): lia.append(i) for i in range(max(a,b-k+1),b+1): lib.append(i) lia = list(set(lia+lib)) lia.sort() for i in lia: print(i)
s255458891
p03719
u168416324
2,000
262,144
Wrong Answer
27
9,080
83
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c=map(int,input().split()) if b<=a and a<=c: print("Yes") else: print("No")
s244930280
Accepted
28
9,120
116
def yaya(boo): if boo: print("Yes") else: print("No") a,b,c=map(int,input().split()) yaya(a<=c and c<=b)
s866691206
p03971
u283929013
2,000
262,144
Wrong Answer
100
4,016
352
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
n,a,b = map(int,input().split()) S = input() passed = 0 f_passed = 0 for s in S: if s == "a": if passed <= a + b: print("Yes") passed += 1 else: print("No") elif s == "b": if passed <= a + b and f_passed <= b: print("Yes") passed += 1 f_passed += 1 else: print("No") else: print("No")
s019740977
Accepted
104
4,016
355
n,a,b = map(int,input().split()) S = input() passed = 0 f_passed = 0 for s in S: if s == "a": if passed < a + b: print("Yes") passed += 1 else: print("No") elif s == "b": if passed < a + b and f_passed + 1 <= b: print("Yes") passed += 1 f_passed += 1 else: print("No") else: print("No")
s884489225
p03455
u619128059
2,000
262,144
Wrong Answer
17
2,940
118
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
num = list(map(int,input().split())) for m in num: t = m % 2 if t == 0: print("Even") else: print("Odd")
s700588895
Accepted
17
2,940
123
num = list(map(int,input().split())) a = num[0] b = num[1] c = (a * b) % 2 if c == 0: print("Even") else: print("Odd")
s998849713
p03816
u562446079
2,000
262,144
Wrong Answer
62
14,692
133
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
def Main(): n = int(input()) A = list(map(int, input().split())) s = set(A) print(len(s)) if __name__ == '__main__': Main()
s406215743
Accepted
62
14,396
187
def Main(): n = int(input()) A = list(map(int, input().split())) s = set(A) if len(s)%2 == 0: print(len(s) - 1) else: print(len(s)) if __name__ == '__main__': Main()
s729745612
p03193
u457901067
2,000
1,048,576
Wrong Answer
21
3,060
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?
from math import floor N, H, W = map(int, input().split()) ans = 0 for i in range(N): A, B = map(int, input().split()) ans += (A//H) * (B//W) print(ans)
s666493799
Accepted
21
3,060
175
from math import floor N, H, W = map(int, input().split()) ans = 0 for i in range(N): A, B = map(int, input().split()) if (A//H) * (B//W) > 0: ans += 1 print(ans)
s316571912
p02663
u409974118
2,000
1,048,576
Wrong Answer
23
9,080
345
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
T = input() t = T.count("?") num =[] for i in range(0,t+1): st = T.replace("?" , "D", i) for n in range(0,t+1): ste = st.replace("?","P",n) for q in range(0,t+1): stes = ste.replace("?","D",q) num.append(stes) print(num) s = stes.count("DD") f = stes.count("PD") ans = s + f print(ans)
s889354031
Accepted
23
9,160
96
h,m,H,M,k = map(int,input().split()) t1 = 60*h + m t2 = 60*H + M ans = t2 - t1 - k print(ans)
s802723525
p03729
u976162616
2,000
262,144
Wrong Answer
19
2,940
101
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`.
A,B,C = input().split() if A[0] == B[-1] and B[0] == C[0]: print ("YES") else: print ("NO")
s213220105
Accepted
17
2,940
102
A,B,C = input().split() if A[-1] == B[0] and B[-1] == C[0]: print ("YES") else: print ("NO")
s660229648
p02646
u808817704
2,000
1,048,576
Wrong Answer
24
9,072
267
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 = tuple(int(c) for c in input().split(' ')) B, W = tuple(int(c) for c in input().split(' ')) T = int(input()) delta = V - W if A == B: print('YES') exit() elif delta <= 0: print('NO') exit() else: d = abs(A-B) time = d // delta + 1 print(time)
s860649964
Accepted
22
9,192
305
A, V = tuple(int(c) for c in input().split(' ')) B, W = tuple(int(c) for c in input().split(' ')) T = int(input()) delta = V - W if A == B: print('YES') exit() elif delta <= 0: print('NO') exit() else: d = abs(A-B) time = d / delta if time <= T: print('YES') else: print('NO')
s062061789
p02972
u426649993
2,000
1,048,576
Wrong Answer
762
37,300
458
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
N = int(input()) a = list(map(int, str(input()).split())) box = dict(zip(range(N, 0, -1), [0] * N)) output = list() for i in box: mul = N // i total_ball = 0 for m in range(1,mul+1): total_ball += box[m * i] if (a[i-1] == 1 and total_ball % 2 == 0) or (a[i-1] == 0 and total_ball % 2 == 1) : box[i] = 1 output.append(str(i)) else: pass if len(output) != 0: print(' '.join(output)) else: print(0)
s650563050
Accepted
1,500
76,984
547
from collections import OrderedDict N = int(input()) a = list(map(int, str(input()).split())) box = OrderedDict(zip(range(N, 0, -1), [0] * N)) output = list() count = 0 for i in box: mul = N // i total_ball = 0 for m in range(1,mul+1): total_ball += box[m * i] if (a[i-1] == 1 and total_ball % 2 == 0) or (a[i-1] == 0 and total_ball % 2 == 1) : box[i] = 1 count += 1 output.append(str(i)) else: pass if len(output) != 0: print(count) print(' '.join(output)) else: print(0)
s124213923
p03545
u076564993
2,000
262,144
Wrong Answer
18
3,064
383
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.
t=list(map(int,list(input()))) t.append(-1) op=[] def dfs(x,i): if i==4 or len(op)==3: if x==7: ans='' for j in range(4): if j==3: ans+=str(t[j]) else: ans+=str(t[j])+op[j] print(ans) return i+=1 op.append('+') dfs(x+t[i],i) op.pop() op.append('-') dfs(x-t[i],i) op.pop() i-=1 return dfs(t[0],0)
s114736679
Accepted
17
3,064
542
t = list(map(int, list(input()))) t.append(7) op = [] def dfs(x, i): if i == 4 or len(op) == 3: if x == 7: op.append('=') ans = '' for j in range(5): if j == 4: ans += str(t[j]) else: ans += str(t[j]) + op[j] print(ans) exit() return i += 1 op.append('+') dfs(x + t[i], i) op.pop() op.append('-') dfs(x - t[i], i) op.pop() i -= 1 return dfs(t[0], 0)
s576259996
p02408
u605451279
1,000
131,072
Wrong Answer
20
5,592
372
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.
n = int(input()) x = input().split() y = int(x[1]) if x[0] == "S": for i in range(13): if i == x[1]: print("S",i) if x[0] == "H": for j in range(13): if j == x[1]: print("H",j) if x[0] == "C": for k in range(13): if k == x[1]: print("C",k) if x[0] == "D": for l in range(13): if l == x[1]: print("D",l)
s821067281
Accepted
20
5,604
535
n = int(input()) s = list() h = list() c = list() d = list() for i in range(n): a = input().split() p = a[0] q = int(a[1]) if p == 'S': s.append(q) elif p == 'H': h.append(q) elif p == 'C': c.append(q) else:# p == 'D' d.append(q) x = 1 for j in range(13): if x not in s: print('S',x) x += 1 x =1 for k in range(13): if x not in h: print('H',x) x += 1 x = 1 for l in range(13): if x not in c: print('C',x) x += 1 x =1 for m in range(13): if x not in d: print('D',x) x += 1
s469924779
p03544
u218843509
2,000
262,144
Wrong Answer
17
3,060
142
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
n = int(input()) if n == 1: print(2) elif n == 2: print(1) else: l = [2, 1] for _ in range(n - 2): l.append(l[-1] + l[-2]) print(l[-1])
s481747854
Accepted
17
2,940
120
n = int(input()) if n == 1: print(1) else: l = [2, 1] for _ in range(n - 1): l.append(l[-1] + l[-2]) print(l[-1])
s209463403
p03351
u802796197
2,000
1,048,576
Wrong Answer
26
9,132
223
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) print(a, b, c, d) ab = abs(a - b) bc = abs(b - c) ac = abs(a - c) if ab <= d and bc <= d: print('Yes') elif ab <= d or bc <= d or ac <= d: print('Yes') else: print('No')
s507730099
Accepted
28
9,020
327
a, b, c, d = map(int, input().split()) #print(a, b, c, d) distance_ab = abs(a - b) distance_bc = abs(b - c) distance_ac = abs(a - c) if distance_ab <= d and distance_bc <= d: print('Yes') elif distance_ac <= d: print('Yes') else: print('No')
s981036266
p03067
u194894739
2,000
1,048,576
Wrong Answer
23
2,940
134
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 c > b: print('Yes') elif b > c and c > b: print('Yes') else: print('No')
s719401222
Accepted
17
2,940
134
a, b, c = map(int, input().split()) if a > c and c > b: print('Yes') elif b > c and c > a: print('Yes') else: print('No')
s627897738
p03089
u535171899
2,000
1,048,576
Wrong Answer
18
3,064
257
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 = [0]+list(map(int,input().split())) ans_li = [] for i in range(n): for j in range(len(B)-1,0,-1): if j==B[j]: ans_li.append(B.pop(j)) break print(-1);exit() print('\n'.join(map(str,ans_li[::-1])))
s703894594
Accepted
18
3,064
271
n = int(input()) B = [0]+list(map(int,input().split())) ans_li = [] for i in range(n): for j in range(len(B)-1,0,-1): if j==B[j]: ans_li.append(B.pop(j)) break else: print(-1);exit() print('\n'.join(map(str,ans_li[::-1])))
s827461749
p03623
u612721349
2,000
262,144
Wrong Answer
17
2,940
89
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x=sorted(set(chr(97+i) for i in range(26))-set(input())) print("None" if not x else x[0])
s266840285
Accepted
17
2,940
100
print((lambda x:"A" if abs(x[0]-x[2]) > abs(x[0]-x[1]) else "B")([int(i) for i in input().split()]))
s885726210
p00011
u075836834
1,000
131,072
Wrong Answer
20
7,728
150
Let's play Amidakuji. In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines. In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom. Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right.
w=int(input()) n=int(input()) A=[int(i+1) for i in range(w)] for i in range(n): x,y=map(int,input().split(',')) A[x-1],A[y-1]=A[y-1],A[x-1] print(A)
s254797223
Accepted
20
7,664
173
w=int(input()) n=int(input()) A=[int(i+1) for i in range(w)] for i in range(n): x,y=map(int,input().split(',')) A[x-1],A[y-1]=A[y-1],A[x-1] for i in range(w): print(A[i])
s661722157
p02865
u116233709
2,000
1,048,576
Wrong Answer
17
2,940
62
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n=int(input()) if n%2==0: print((n/2)-1) else: print(n//2)
s965167548
Accepted
17
2,940
103
n=int(input()) if n==1 or n==2: print(0) elif n%2==0: print(int((n/2)-1)) else: print(int(n//2))
s850500081
p03503
u533885955
2,000
262,144
Wrong Answer
124
3,192
706
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
N = int(input()) F = [] for i in range(N): F.append(list(map(int,input().split()))) P = [] for i in range(N): P.append(list(map(int,input().split()))) j = 1 MAX = -100000000 for j in range(1023): Fcount = [0 for a in range(N)] b = bin(j) b.lstrip("0b") blist = list(b) L = len(blist) for k in range(10-L): blist.insert(0,"0") m = 0 for m in range(10): if blist[m] == "1": o = 0 for o in range(N): if F[o][m] == 1: Fcount[o]+=1 else: pass kari = 0 for p in range(N): kari+=P[p][Fcount[p]] if MAX <= kari: MAX = kari print(MAX)
s310906545
Accepted
243
3,444
754
#C from collections import deque import bisect import math import heapq import itertools #import sys #input = sys.stdin.readline inf = float("inf") mod = 10**9 + 7 #mod = 998244353 #list(map(int,input().split())) N = int(input()) F = [list(map(int,input().split())) for i in range(N)] P = [list(map(int,input().split())) for i in range(N)] ans = -inf for i in range(1024): if i == 0: continue b = bin(i) b = b.lstrip("0b") while len(b) < 10: b = "0"+b kari = 0 for j in range(N): f = F[j] p = P[j] C = 0 for k in range(10): if b[k] == "1" and f[k] == 1: C+=1 kari += p[C] ans = max(ans,kari) #print(b) print(ans)
s119094425
p03067
u848882989
2,000
1,048,576
Wrong Answer
17
3,060
189
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.
import sys args = list(map(int, input().split())) print(args) if args[0] < args[1] and args[1] < args[2] or args[2] < args[1] and args[1] < args[0]: print("yes") else: print("no")
s801216773
Accepted
17
2,940
203
import sys args = list(map(int, input().split())) if (args[0] < args[2] and args[2] < args[1]) or (args[1] < args[2] and args[2] < args[0]): print("Yes") else: print("No")
s298966032
p03943
u396961814
2,000
262,144
Wrong Answer
17
2,940
120
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.
X = [int(x) for x in input().split()] Y = sorted(X) if Y[0] + Y[1] == Y[2]: print('YES') else: print('NO')
s541012534
Accepted
17
2,940
114
X = [int(x) for x in input().split()] Y = sorted(X) if Y[0] + Y[1] == Y[2]: print('Yes') else: print('No')
s309817511
p03591
u601018334
2,000
262,144
Wrong Answer
17
2,940
75
Ringo is giving a present to Snuke. Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things. You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.
s = input().split() if s[0:4]=='YAKI' : print('Yes') else : print('No')
s306629934
Accepted
17
2,940
67
s = input() if s[0:4]=='YAKI' : print('Yes') else : print('No')
s515306319
p03545
u929569377
2,000
262,144
Wrong Answer
17
3,064
659
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.
array = [int(i) for i in list(input())] flag = False fugou = ['+', '-'] for i in fugou: if i == '+': tmp = array[0] + array[1] else: tmp = array[0] - array[1] for j in fugou: if j == '+': tmp2 = tmp + array[2] else: tmp2 = tmp - array[2] for k in fugou: if k == '+': if tmp2 + array[3] == 7: print(str(array[0]) + i + str(array[1]) + j + str(array[2]) + k + str(array[3])) flag = True break else: if tmp2 - array[3] == 7: print(str(array[0]) + i + str(array[1]) + j + str(array[2]) + k + str(array[3])) flag = True break if flag: break if flag: break
s353035824
Accepted
18
3,064
631
N = list(map(int, list(input()))) flag = False for i in range(2): for j in range(2): for k in range(2): B = (N[1] if i == 0 else -N[1]) C = (N[2] if j == 0 else -N[2]) D = (N[3] if k == 0 else -N[3]) if sum([N[0], B, C, D]) == 7: print(N[0],end='') if i == 0: print('+',end='') else: print('-',end='') print(N[1],end='') if j == 0: print('+',end='') else: print('-',end='') print(N[2],end='') if k == 0: print('+',end='') else: print('-',end='') print(N[3],end='') print('=7') flag = True break if flag: break if flag: break
s256069835
p03434
u354126779
2,000
262,144
Wrong Answer
17
3,060
140
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()) Aseq=input().split() A=[] for i in range(n): A.append(int(Aseq[i])) A.sort() AA=A[0::2] AB=A[1::2] print(sum(AA)-sum(AB))
s350729561
Accepted
17
3,060
152
n=int(input()) Aseq=input().split() A=[] for i in range(n): A.append(int(Aseq[i])) A.sort(reverse=True) AA=A[0::2] AB=A[1::2] print(sum(AA)-sum(AB))
s456458950
p03778
u626468554
2,000
262,144
Wrong Answer
17
2,940
183
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
#n = int(input()) #n,k = map(int,input().split()) #x = list(map(int,input().split())) w,a,b = map(int,input().split()) a = min(b-w-a,a-b-w) if a <0: print(0) else: print(a)
s901931461
Accepted
17
2,940
58
w,a,b = map(int,input().split()) print(max(b-w-a,a-b-w,0))
s274807919
p02255
u510829608
1,000
131,072
Wrong Answer
30
7,648
202
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.
N = int(input()) l = list(map(int, input().split())) print(*l) for i in range(N): t = l[i] j = i-1 while j >= 0 and l[j] > t: l[j+1], l[j] = l[j], l[j+1] j -= 1 print(*l)
s077040344
Accepted
20
8,024
284
N = int(input()) A = list(map(int, input().split())) print(*A) def insertionSort(A, N): for i in range(1, N): v = A[i] j = i-1 while j>= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(*A) insertionSort(A, N)
s519617632
p02402
u623996423
1,000
131,072
Wrong Answer
20
5,588
98
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.
n = int(input()) a = list(map(int, input().split())) for i in range(n): print(a[i], end=' ')
s734622738
Accepted
30
6,580
114
n = int(input()) a = list(map(int, input().split())) print(min(a), end=' ') print(max(a), end=' ') print(sum(a))
s855043226
p03457
u703391033
2,000
262,144
Wrong Answer
459
34,632
304
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()) a=[list(map(int,input().split())) for _ in range(N)] dp=[[0,0] for _ in range(N)] for i in range(N): t=a[i][0]-dp[i-1][1] x=a[i][1] y=a[i][2] if t>=x+y and t%2==(x+y+dp[i-1][1])%2 and dp[i-1][0]==1: dp[i][0]=1 dp[i][1]=a[i][0] if dp[N-1][0]==1:print("Yes") else:print("No")
s934087692
Accepted
497
37,816
324
N=int(input()) a=[list(map(int,input().split())) for _ in range(N)] dp=[[0,0] for _ in range(N+1)] f=True for i in range(N): t=a[i][0]-dp[i][1] x=a[i][1] y=a[i][2] if t>=x+y-dp[i][0] and t%2==(x+y+dp[i][1])%2: dp[i+1][0]=x+y dp[i+1][1]=a[i][0] else: f=False break if f:print("Yes") else:print("No")
s975410157
p02343
u890713354
3,000
131,072
Wrong Answer
20
5,604
1,060
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}. First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively. Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations: * unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set. * same(x, y): determine whether x and y are in the same set.
p=[] rank=[] answer=[] def makeset(x): p[x] = x rank[x] = 0 def union(x,y): link(findset(x),findset(y)) def link(x,y): if rank[x] > rank[y]: p[y] = x else: p[x] = y if rank[x] == rank[y]: rank[y] = rank[y] + 1 def findset(x): if x != p[x]: p[x] = findset(p[x]) return p[x] t,s = map(int,input().split()) for i in range(t): p.append(None) rank.append(None) while True: try: o,x,y = map(int,input().split()) except: break else: if o == 0: if p[x] == None: makeset(x) if p[y] == None: makeset(y) union(x,y) print(p[x]) print(rank[x]) else: if p[x] == None: makeset(x) if p[y] == None: makeset(y) if findset(x) == findset(y): answer.append(1) else: answer.append(0) for i in range(len(answer)): print(answer[i])
s123519931
Accepted
590
6,972
1,009
p=[] rank=[] answer=[] def makeset(x): p[x] = x rank[x] = 0 def union(x,y): link(findset(x),findset(y)) def link(x,y): if rank[x] > rank[y]: p[y] = x else: p[x] = y if rank[x] == rank[y]: rank[y] = rank[y] + 1 def findset(x): if x != p[x]: p[x] = findset(p[x]) return p[x] t,s = map(int,input().split()) for i in range(t): p.append(None) rank.append(None) while True: try: o,x,y = map(int,input().split()) except: break else: if o == 0: if p[x] == None: makeset(x) if p[y] == None: makeset(y) union(x,y) else: if p[x] == None: makeset(x) if p[y] == None: makeset(y) if findset(x) == findset(y): answer.append(1) else: answer.append(0) for i in range(len(answer)): print(answer[i])
s843277819
p02972
u900848911
2,000
1,048,576
Wrong Answer
744
7,504
431
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
N = int(input()) a = list(int(x) for x in input().split()) b = [0] * N index = N // 2 for i in range(index,N): b[i] = a[i] count = 0 for i in range(index): for j in range(index-i-1+(index-i),N,index-i): count += a[j] if count % 2 != a[i]: b[i] = 1 count = 0 for i in range(N): if b[i] == 1: count += 1 print(count) for i in range(N): print(b[i],end=' ') print()
s626078306
Accepted
626
14,092
718
N = int(input()) arr = list(int(x) for x in input().split()) flag = [-1] * N ans = [] for i in range(N-1,-1,-1): sum = 0 for j in range(i,N,i+1): if j == i: continue else: if flag[j] == 1: sum += 1 if sum % 2 == arr[i]: flag[i] = 0 else: flag[i] = 1 ans.append(i+1) num = len(ans) if num == 0: print(num) else: print(num) print(*ans)
s457871168
p02412
u104171359
1,000
131,072
Wrong Answer
20
7,784
758
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
#!usr/bin/env python3 import sys def subset_sum(numbers, target, partial=[]): s = sum(partial) if s == target: if len(partial) != 3: return None print(*partial) if s >= target: return None for i in range(len(numbers)): n = numbers[i] remaining = numbers[i+1:] if len(partial) == 3: break subset_sum(remaining, target, partial + [n]) def program_runner(): while True: lst = [int(num) for num in sys.stdin.readline().split()] if lst[0] == lst[1] == 0: break num_list = [num for num in range(1, lst[0]+1)] subset_sum(num_list, lst[1]) def main(): program_runner() if __name__ == '__main__': main()
s734100842
Accepted
310
7,636
433
#!/usr/local/env python3 import sys def main(): while True: count = 0 n, r = map(int, sys.stdin.readline().split()) if n == r == 0: break for n1 in range(1, n-1): for n2 in range(n1+1, n): for n3 in range(n2+1, n+1): if n1 + n2 + n3 == r: count += 1 print(count) if __name__ == '__main__': main()
s354161948
p03053
u830592648
1,000
1,048,576
Wrong Answer
1,073
248,032
788
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. We will repeatedly perform the following operation until all the squares are black: * Every white square that shares a side with a black square, becomes black. Find the number of operations that will be performed. The initial grid has at least one black square.
from collections import deque H,W=map(int, input().split()) S=[] S.append(list(['X']*(W+2))) for h in range(H): S.append(['X']+list(input())+['X']) S.append(list(['X']*(W+2))) q=deque([]) d=[(1,0),(-1,0),(0,1),(0,-1)] cnt_n=0 def add_q(S): for h in range(1,H+1): for w in range(1,W+1): if S[h][w]=='#': for dy,dx in d: q.append([h+dy,w+dx]) return S,q def chnge_are(S,q): while q: y,x = q.popleft() S[y][x]='#' return S def res_chk(S,cnt_n): res=0 for h in range(H+2): if S[h].count('.')!=0: res=1 if res==1: cnt_n+=1 S,q=add_q(S) S=chnge_are(S,q) return res_chk(S,cnt_n) else: return cnt_n res_chk(S,cnt_n)
s527649760
Accepted
681
52,740
302
from scipy.ndimage import distance_transform_cdt H,W=map(int, input().split()) S=list(list(input()) for h in range(H)) for h in range(H): for w in range(W): if S[h][w]=="#": S[h][w]=0 else: S[h][w]=1 print(distance_transform_cdt(S, metric='taxicab').max())
s973848734
p02612
u080885857
2,000
1,048,576
Wrong Answer
25
9,016
67
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
import math n=int(input()) total = math.ceil(n/1000) print(total-n)
s553572083
Accepted
29
9,008
75
import math n=int(input()) total = math.ceil(n/1000) print((total)*1000-n)
s226999693
p03827
u732743460
2,000
262,144
Wrong Answer
17
2,940
139
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
n = int(input()) x=0 s=input() ans=0 for i in range(n): if s[i]=="I": x=x+1 else: x=x-1 ans=max(ans,x) print(x)
s939512001
Accepted
18
2,940
141
n = int(input()) x=0 s=input() ans=0 for i in range(n): if s[i]=="I": x=x+1 else: x=x-1 ans=max(ans,x) print(ans)
s916604338
p03795
u670961163
2,000
262,144
Wrong Answer
28
9,140
44
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()) print(800*n - 200 * n// 15)
s262097358
Accepted
25
8,932
47
n = int(input()) print(800*n - 200 * (n// 15))
s973610323
p02606
u946648678
2,000
1,048,576
Wrong Answer
27
9,152
120
How many multiples of d are there among the integers between L and R (inclusive)?
l, r, d = [int(x) for x in input().split()] count = 0 for i in range(l, r+1): if not l%d: count += 1 print(count)
s052079447
Accepted
23
9,152
120
l, r, d = [int(x) for x in input().split()] count = 0 for i in range(l, r+1): if not i%d: count += 1 print(count)
s032241953
p03828
u550943777
2,000
262,144
Wrong Answer
18
3,064
401
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
N = int(input()) mod = 10**9+7 arr = [1 for i in range(N+1)] for i in range(2,N+1): if arr[i] > 0: j = 2*i while(j<N+1): arr[j] = 0 j += i prime = [] for i in range(2,N): if arr[i] != 0: prime.append(i) count = 1 for n in prime: tmp = n i = 0 while(tmp < N+1): i += N//tmp tmp *= n count *= (i+1) print(count%mod)
s060249801
Accepted
19
3,064
403
N = int(input()) mod = 10**9+7 arr = [1 for i in range(N+1)] for i in range(2,N+1): if arr[i] > 0: j = 2*i while(j<N+1): arr[j] = 0 j += i prime = [] for i in range(2,N+1): if arr[i] != 0: prime.append(i) count = 1 for n in prime: tmp = n i = 0 while(tmp < N+1): i += N//tmp tmp *= n count *= (i+1) print(count%mod)
s590181043
p02833
u940139461
2,000
1,048,576
Wrong Answer
17
2,940
353
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
N = int(input()) # c = 0 # while True: # a = N // 5 # b = N % 5 # if b != 0: # N = b # else: # N = a # c += N # if N < 5: # break # print(int(c / 2)) n = 1 ans = 0 while 5 ** n < N: a = (N // (5 ** n)) b = (N % (10 ** n)) if b == 0: a = int(a / 2) ans += a n += 1 print(ans)
s955190483
Accepted
17
2,940
229
import math N = int(input()) def main(N): if N % 2 == 1: print(0) return n = 1 ans = 0 N //= 2 while N: N //= 5 ans += N print(ans) if __name__ == "__main__": main(N)
s661728298
p03386
u595375942
2,000
262,144
Wrong Answer
17
3,060
132
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a,b,k=map(int,input().split()) L=set([i for i in range(a,min(a+k,b))]+[i for i in range(max(b-k+1,a),b+1)]) for a in L: print(a)
s631333716
Accepted
19
3,060
99
a,b,k=map(int,input().split()) R=range(a,b+1) for x in sorted(set(R[:k])|set(R[-k:])): print(x)
s847451262
p03658
u878138257
2,000
262,144
Wrong Answer
17
2,940
114
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
n,k = map(int, input().split()) listA = list(map(int, input().split())) listA.sort() listB = listA[:k] sum(listB)
s689095752
Accepted
18
2,940
134
n,k = map(int, input().split()) listA = list(map(int, input().split())) listA.sort(reverse=True) listB = listA[:k] print(sum(listB))