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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s101352337 | p03962 | u767664985 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 30 | AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him. | print(len(set(list(input())))) | s044069166 | Accepted | 17 | 2,940 | 48 | print(len(set(list(map(int, input().split()))))) |
s823494839 | p03380 | u813387707 | 2,000 | 262,144 | Wrong Answer | 85 | 14,052 | 384 | 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. | from bisect import bisect_left
n = int(input())
a_list = sorted([int(x) for x in input().split()])
base = a_list[-1] // 2
i = bisect_left(a_list, base)
if i > 0:
i -= 1
ans = [a_list[-1], a_list[i], abs(a_list[i] - base)]
for i in range(i + 1, n):
temp = abs(a_list[i] - base)
if temp >= ans[2]:
break
ans[1] = a_list[i]
ans[2] = temp
print(ans[0], ans[1]) | s764801706 | Accepted | 82 | 14,052 | 383 | from bisect import bisect_left
n = int(input())
a_list = sorted([int(x) for x in input().split()])
base = a_list[-1] / 2
i = bisect_left(a_list, base)
if i > 0:
i -= 1
ans = [a_list[-1], a_list[i], abs(a_list[i] - base)]
for i in range(i + 1, n):
temp = abs(a_list[i] - base)
if temp >= ans[2]:
break
ans[1] = a_list[i]
ans[2] = temp
print(ans[0], ans[1]) |
s759999270 | p03474 | u896791216 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 354 | The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom. | nums = "1234567890"
a, b = map(int, input().split())
s = input()
ok_flg = True
for i in range(a):
if s[i] not in nums:
ok_flg = False
break
print(s[a])
if s[a] != "-":
ok_flg = False
for j in range(b):
if s[a + 1 + j] not in nums:
ok_flg = False
break
if ok_flg == True:
print("Yes")
else:
print("No")
| s579524628 | Accepted | 18 | 3,060 | 342 | nums = "1234567890"
a, b = map(int, input().split())
s = input()
ok_flg = True
for i in range(a):
if s[i] not in nums:
ok_flg = False
break
if s[a] != "-":
ok_flg = False
for j in range(b):
if s[a + 1 + j] not in nums:
ok_flg = False
break
if ok_flg == True:
print("Yes")
else:
print("No")
|
s698058803 | p04000 | u866746776 | 3,000 | 262,144 | Wrong Answer | 3,165 | 84,728 | 448 | 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? | from collections import Counter
h, w, n = [int(i) for i in input().split()]
cnt = Counter()
vs = []
for i in range(-1, 2):
for j in range(-1, 2):
vs.append((i,j))
print(list(vs))
for _ in range(n):
a, b = [int(i) for i in input().split()]
for v in vs:
aa = a + v[0]
bb = b + v[1]
if 2<=aa<=h-1 and 2<=bb<=w-1:
cnt.update([(aa, bb)])
print(cnt)
cnt2 = [0] * 10
for k in cnt:
c = cnt[k]
cnt2[c] += 1
for i in cnt2:
print(i)
| s718299667 | Accepted | 2,986 | 119,920 | 469 | from collections import Counter
h, w, n = [int(i) for i in input().split()]
vs = []
for i in range(-1, 2):
for j in range(-1, 2):
vs.append((i,j))
cnt = []
for _ in range(n):
a, b = [int(i) for i in input().split()]
for v in vs:
aa = a + v[0]
bb = b + v[1]
if 2<=aa<=(h-1) and 2<=bb<=(w-1):
cnt.append(aa*w+bb)
cnt = Counter(cnt)
cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
c = cnt[k]
cnt2[c] += 1
cnt2[0] -= 1
for i in cnt2:
print(i)
|
s487876692 | p03379 | u219607170 | 2,000 | 262,144 | Wrong Answer | 2,104 | 25,224 | 119 | When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N. | N = int(input())
X = list(map(int, input().split()))
X.sort()
for i in range(N):
print((X[:i] + X[i+1:])[(N-1)//2]) | s676210749 | Accepted | 308 | 25,472 | 256 | N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
l, r = Y[N//2-1], Y[N//2]
A = []
for i in range(N):
if X[i] <= l:
print(r)
# A.append(r)
else:
print(l)
# A.append(l)
# print('\n'.join(map(str, A))) |
s084401583 | p03485 | u545503667 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 73 | 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 = tuple(map(int, input().split()))
print(((a+b)//2) + (a % b > 0))
| s038848816 | Accepted | 18 | 3,060 | 84 | from math import ceil
a, b = tuple(map(int, input().split()))
print(ceil((a+b)/2))
|
s014598344 | p03672 | u697658632 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 103 | We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. | s = input()
ans = 0
for i in range(1, len(s) // 2 - 1):
if s[:i] == s[i:2*i]:
ans = i
print(ans)
| s250737111 | Accepted | 17 | 2,940 | 103 | s = input()
ans = 0
for i in range(1, len(s) // 2):
if s[:i] == s[i:2*i]:
ans = 2 * i
print(ans)
|
s620950649 | p03471 | u635273885 | 2,000 | 262,144 | Wrong Answer | 1,599 | 3,060 | 229 | 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())
x = -1
y = -1
z = -1
for i in range(n+1):
for j in range(n+1):
k = n-i-j
if 10000*i + 5000*j + 1000*k == y:
x = i
y = j
z = k
print(x, y, z) | s005337463 | Accepted | 834 | 2,940 | 232 | N, Y = map(int, input().split())
x = -1
y = -1
z = -1
for i in range(N+1):
for j in range(N+1-i):
k = N-i-j
if 10000*i + 5000*j + 1000*k == Y:
x = i
y = j
z = k
print(x, y, z)
|
s195762027 | p03943 | u424967964 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 143 | 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. | candy = [int(i) for i in input().split()]
candy = sorted(candy)
print(candy)
if(candy[0]+candy[1]==candy[2]):
print("Yes")
else:
print("No")
| s174988816 | Accepted | 17 | 2,940 | 130 | candy = [int(i) for i in input().split()]
candy = sorted(candy)
if(candy[0]+candy[1]==candy[2]):
print("Yes")
else:
print("No")
|
s764537875 | p03610 | u448655578 | 2,000 | 262,144 | Wrong Answer | 36 | 4,268 | 112 | You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1. | s = list(input())
ans = [s[0]]
for i in range(len(s)):
if i % 2 == 0:
ans.append(s[i])
print(''.join(ans)) | s808076647 | Accepted | 37 | 4,264 | 108 | s = list(input())
ans = []
for i in range(len(s)):
if i % 2 == 0:
ans.append(s[i])
print(''.join(ans)) |
s626565663 | p03695 | u394731058 | 2,000 | 262,144 | Wrong Answer | 23 | 9,096 | 206 | In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users. | n = int(input())
a = list(map(int, input().split()))
c = [False]*8
k = 0
ans = 0
for i in range(n):
cn = a[i]//400
if cn < 8:
if c[cn] == False:
ans += 1
c[cn] = True
else:
k += 1
| s507297352 | Accepted | 27 | 9,072 | 234 | n = int(input())
a = list(map(int, input().split()))
c = [False]*8
k = 0
ans = 0
for i in range(n):
cn = a[i]//400
if cn < 8:
if c[cn] == False:
ans += 1
c[cn] = True
else:
k += 1
print(max(1, ans), ans + k)
|
s057111747 | p03160 | u608053762 | 2,000 | 1,048,576 | Wrong Answer | 533 | 23,088 | 330 | There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N. | import numpy as np
n = map(int, input())
h_list = [int(i) for i in input().split()]
dp = np.zeros((len(h_list)))
dp[1] = h_list[1]-h_list[0]
for i in range(2,len(h_list)):
temp1 = dp[i-1] + abs(h_list[i] - h_list[i-1])
temp2 = dp[i-2] + abs(h_list[i] - h_list[i-2])
dp[i] = min(temp1, temp2)
print(dp[-1]) | s578756256 | Accepted | 806 | 23,092 | 375 | import numpy as np
n = map(int, input())
h_list = [int(i) for i in input().split()]
h_list = np.array(h_list)
dp = np.zeros((len(h_list)))
dp[1] = np.abs(h_list[1]-h_list[0])
for i in range(2,len(h_list)):
temp1 = dp[i-1] + np.abs(h_list[i] - h_list[i-1])
temp2 = dp[i-2] + np.abs(h_list[i] - h_list[i-2])
dp[i] = min(temp1, temp2)
print(int(dp[-1])) |
s315685762 | p03386 | u437215432 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 178 | 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. | # ABC093B
a, b, k = map(int, input().split())
ans = set()
for i in range(a, min(a+k, b+1)):
ans.add(i)
for i in range(max(a, b-k+1), b+1):
ans.add(i)
print(sorted(ans))
| s052533541 | Accepted | 17 | 3,060 | 192 | a, b, k = map(int, input().split())
ans = set()
for i in range(a, min(a+k, b+1)):
ans.add(i)
for i in range(max(a, b-k+1), b+1):
ans.add(i)
ans = sorted(ans)
for i in ans:
print(i) |
s661766930 | p03471 | u728200259 | 2,000 | 262,144 | Wrong Answer | 590 | 8,944 | 274 | 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())
result = [-1 , -1, -1]
for m in range(N + 1):
for f in range(N + 1 - m):
s = N - m - f
if 10000*m + 5000*f + 1000*s == Y:
result = [m, f, s]
break
print(result)
| s913879503 | Accepted | 564 | 9,100 | 328 | N, Y = map(int, input().split())
result = [-1 , -1, -1]
for m in range(N + 1):
for f in range(N + 1 - m):
s = N - m - f
if 10000*m + 5000*f + 1000*s == Y:
result = [m, f, s]
break
print(f'{result[0]} {result[1]} {result[2]}')
|
s723901997 | p03386 | u994521204 | 2,000 | 262,144 | Wrong Answer | 19 | 3,064 | 179 | 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())
A=[i for i in range(a, min((a+k),b+1))]
B=[i for i in range(max((b-k),a)+1,b+1)]
for i in range(len(list(set(A+B)))):
print((list(set(A+B)))[i]) | s032498766 | Accepted | 17 | 3,060 | 224 | a,b,k=map(int,input().split())
A=[i for i in range(a, min((a+k),b))]
B=[i for i in range(max((b-k),a)+1,b+1)]
ans=list(set(A)|set(B))
ans.sort()
if a==b:
print(a)
else:
for i in range(len(ans)):
print(ans[i]) |
s262973473 | p03555 | u010437136 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 162 | 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. | import sys
C1 = sys.stdin.readline()
C2 = sys.stdin.readline()
c1 = C1.rstrip()
c2 = C2.rstrip()
c3 = c2[::-1]
if c1 == c3:
print("Yes")
else:
print("No") | s887356653 | Accepted | 17 | 3,060 | 162 | import sys
C1 = sys.stdin.readline()
C2 = sys.stdin.readline()
c1 = C1.rstrip()
c2 = C2.rstrip()
c3 = c2[::-1]
if c1 == c3:
print("YES")
else:
print("NO") |
s072857398 | p03433 | u035445296 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 83 | E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. | N = int(input())
A = int(input())
if N%500 > A:
print('Yes')
else:
print('No')
| s308537904 | Accepted | 17 | 2,940 | 83 | N = int(input())
A = int(input())
if N%500 > A:
print('No')
else:
print('Yes')
|
s455000360 | p03729 | u111365362 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 116 | 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`. | #16:05
a,b,c = input().split()
x = int(a[-1]==b[0]) * int(b[-1]==c[0])
if x == 1:
print('Yes')
else:
print('No') | s644290709 | Accepted | 18 | 2,940 | 116 | #16:05
a,b,c = input().split()
x = int(a[-1]==b[0]) * int(b[-1]==c[0])
if x == 1:
print('YES')
else:
print('NO') |
s488628806 | p03970 | u859897687 | 2,000 | 262,144 | Wrong Answer | 20 | 2,940 | 87 | CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation. | a=input()
b='CODEFESTIVAL2016'
ans=0
for i in range(16):
ans+=(a[i]==b[i])
print(ans) | s697620052 | Accepted | 17 | 2,940 | 87 | a=input()
b='CODEFESTIVAL2016'
ans=0
for i in range(16):
ans+=(a[i]!=b[i])
print(ans) |
s706873723 | p03090 | u608850287 | 2,000 | 1,048,576 | Wrong Answer | 24 | 3,612 | 167 | You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem. | n = int(input())
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
if n % 2 == 1 and i + j != n \
or n % 2 == 0 and i + j != n + 1:
print(i, j)
| s933073635 | Accepted | 25 | 3,956 | 240 | n = int(input())
edges = []
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
if n % 2 == 1 and i + j != n \
or n % 2 == 0 and i + j != n + 1:
edges.append((i, j))
print(len(edges))
for i, j in edges:
print(i, j) |
s250398949 | p03067 | u951598454 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 143 | 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())
# normalize
norm_A = 0
norm_B = B - A
norm_C = C - A
print('YES' if abs(norm_B) >= abs(norm_C) else 'No') | s648952807 | Accepted | 17 | 2,940 | 170 | A, B, C = map(int, input().split())
# normalize
norm_A = 0
norm_B = B - A
norm_C = C - A
print('Yes' if abs(norm_B) >= abs(norm_C) and (norm_B * norm_C) > 0 else 'No')
|
s550965215 | p03943 | u594956556 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 100 | 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. | abc = list(map(int, input().split()))
if abc[0]+abc[1] == abc[2]:
print('Yes')
else:
print('No') | s704542315 | Accepted | 17 | 2,940 | 112 | abc = list(map(int, input().split()))
abc.sort()
if abc[0]+abc[1] == abc[2]:
print('Yes')
else:
print('No')
|
s929926972 | p02665 | u928784113 | 2,000 | 1,048,576 | Wrong Answer | 143 | 32,532 | 2,364 | Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1. | import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, 10**5 + 1):
fact.append((fact[-1] * i) % Mod)
inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
factinv.append((factinv[-1] * inv[-1]) % Mod)
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n - r] % p
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def pow_k(x, n):
if n == 0:
return 1
K = 1
while n > 1:
if n % 2 != 0:
K *= x
x *= x
n //= 2
return K * x
def main(): #startline-------------------------------------------
n = int(input())
a = list(map(int, input().split()))
accum = sum(a)
ans = 0
b = [0] * (n + 1)
for i in range(1, n + 1):
accum -= a[i]
b[i] = min(2 * b[i - 1] - a[i], accum)
if b[i] < 0:
ans = -1
break
ans += b[i] + a[i]
print(ans)
if __name__ == "__main__":
main() | s210912584 | Accepted | 190 | 32,708 | 2,495 | import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, 10**5 + 1):
fact.append((fact[-1] * i) % Mod)
inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
factinv.append((factinv[-1] * inv[-1]) % Mod)
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n - r] % p
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def pow_k(x, n):
if n == 0:
return 1
K = 1
while n > 1:
if n % 2 != 0:
K *= x
x *= x
n //= 2
return K * x
def main(): #startline-------------------------------------------
n = int(input())
a = list(map(int, input().split()))
accum = sum(a)
ans = 1
b = [0] * (n + 1)
b[0] = 1
for i in range(1, n + 1):
accum -= a[i]
b[i] = min(2 * b[i - 1] - a[i], accum)
if b[i] < 0:
ans = -1
break
ans += b[i] + a[i]
if a[0] == 1:
ans = -1
if n == 0:
if a[0] == 1:
ans = 1
else:
ans = -1
print(ans)
if __name__ == "__main__":
main() |
s439590351 | p02413 | u067975558 | 1,000 | 131,072 | Wrong Answer | 30 | 6,724 | 226 | Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column. | (r, c) = [int(i) for i in input().split()]
a = []
for i in range(r):
a.append([int(i) for i in input().split()])
for i in range(r):
sum = 0
for j in a[i]:
print(j, end=' ')
sum += j
print(sum) | s231738405 | Accepted | 60 | 6,828 | 347 | (r, c) = [int(i) for i in input().split()]
a = []
for i in range(r):
a.append([int(i) for i in input().split()])
a.append([0 for i in range(c)])
for i in range(r + 1):
sum = 0
count = 0
for j in a[i]:
print(j, end=' ')
sum += j
if i != r:
a[r][count] += j
count += 1
print(sum) |
s795874714 | p03680 | u823458368 | 2,000 | 262,144 | Wrong Answer | 209 | 7,084 | 310 | Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. | n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
now = 1
nex = [now-1]
ans = 0
flg = 0
while a[now-1] != 0:
a[now-1], nex = 0, a[now-1]
now = a[nex-1]
ans += 1
if nex == 2:
flg = 1
ans += 1
break
if flg == 1:
print(ans)
else:
print(-1) | s588535343 | Accepted | 223 | 7,084 | 289 | n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
now = 1
nex = a[now-1]
ans = 0
flg = 0
while a[now-1] != 0:
a[now-1], nex = 0, a[now-1]
now = nex
ans += 1
if nex == 2:
flg = 1
break
if flg == 1:
print(ans)
else:
print(-1) |
s627571249 | p03610 | u608088992 | 2,000 | 262,144 | Wrong Answer | 17 | 3,188 | 26 | You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1. | s = input()
print(s[1::2]) | s231316702 | Accepted | 17 | 3,188 | 26 | s = input()
print(s[::2])
|
s450286582 | p03448 | u139112865 | 2,000 | 262,144 | Wrong Answer | 47 | 4,120 | 141 | 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. | #087_B
a,b,c,x=[int(input()) for i in range(4)]
print(sum([500*p+100*q+10*r==x for p in range(a+1) for q in range(b+1) for r in range(c+1)])) | s402844166 | Accepted | 49 | 4,120 | 141 | #087_B
a,b,c,x=[int(input()) for i in range(4)]
print(sum([500*p+100*q+50*r==x for p in range(a+1) for q in range(b+1) for r in range(c+1)])) |
s273420338 | p02389 | u489417537 | 1,000 | 131,072 | Wrong Answer | 20 | 5,572 | 47 | Write a program which calculates the area and perimeter of a given rectangle. | a, b = map(int, input().split())
print(a * b)
| s654616781 | Accepted | 20 | 5,572 | 62 | a, b = map(int, input().split())
print(a * b, a * 2 + b * 2)
|
s576281903 | p03672 | u844005364 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 78 | We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. | n = input()
while n[:len(n)//2] != n[len(n)//2:]:
n = n[:-1]
print(len(n)) | s564434672 | Accepted | 17 | 2,940 | 91 | n = input()
n = n[:-1]
while n[:len(n)//2] != n[len(n)//2:]:
n = n[:-1]
print(len(n))
|
s289283930 | p03815 | u116142267 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 96 | Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: * Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total. | x = int(input())
cnt = int(x / 11) * 2
if x%11<6 and cnt!=0:
print(cnt)
else:
print(cnt+1)
| s614810398 | Accepted | 17 | 2,940 | 114 | x = int(input())
cnt = int(x / 11)*2
if x%11==0:
print(cnt)
elif x%11<=6:
print(cnt+1)
else:
print(cnt+2)
|
s306663057 | p04039 | u903596281 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 532 | Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier. | N,K=map(int,input().split())
D=[int(x) for x in input().split()]
kazu=[9,8,7,6,5,4,3,2,1,0]
for item in D:
kazu.remove(item)
p=[]
m=len(str(N))
for i in range(m):
p.append(kazu[0]*(10**i))
p.sort(reverse=True)
print(p)
j=0
while j<m:
for i in range(1,len(kazu)):
if sum(p)-p[j]+kazu[i]*(10**(m-j-1))>=N:
p[j]=kazu[i]*(10**(m-j-1))
else:
break
j+=1
if sum(p)<N:
if kazu[-1]!=0:
ans=0
for i in range(m+1):
ans+=kazu[-1]*(10**i)
else:
ans=kazu[-2]*(10)**m
else:
ans=sum(p)
print(ans) | s455216406 | Accepted | 17 | 3,064 | 523 | N,K=map(int,input().split())
D=[int(x) for x in input().split()]
kazu=[9,8,7,6,5,4,3,2,1,0]
for item in D:
kazu.remove(item)
p=[]
m=len(str(N))
for i in range(m):
p.append(kazu[0]*(10**i))
p.sort(reverse=True)
j=0
while j<m:
for i in range(1,len(kazu)):
if sum(p)-p[j]+kazu[i]*(10**(m-j-1))>=N:
p[j]=kazu[i]*(10**(m-j-1))
else:
break
j+=1
if sum(p)<N:
if kazu[-1]!=0:
ans=0
for i in range(m+1):
ans+=kazu[-1]*(10**i)
else:
ans=kazu[-2]*(10)**m
else:
ans=sum(p)
print(ans) |
s589777271 | p04043 | u172780602 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 116 | 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()))
if a.count(5)==2:
if a.count(7)==1:
print("Yes")
else:
print("No")
| s973581102 | Accepted | 17 | 2,940 | 146 | a=list(map(int,input().split()))
if a.count(5)==2:
if a.count(7)==1:
print("YES")
else:
print("NO")
else:
print("NO")
|
s280640494 | p02608 | u748311048 | 2,000 | 1,048,576 | Wrong Answer | 60 | 9,604 | 328 | Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N). | from collections import Counter
n = int(input())
l = list()
for i in range(31):
l.append((i, i**2))
# print(l)
c = Counter()
for X in l:
for Y in l:
for Z in l:
x = X[0]
y = Y[0]
z = Z[0]
c[X[1]+Y[1]+Z[1]+x*y+y*z+x*z] += 1
for i in range(1, n+1):
print(c[i])
| s527677664 | Accepted | 753 | 11,848 | 331 | from collections import Counter
n = int(input())
l = list()
for i in range(1,101):
l.append((i, i**2))
# print(l)
c = Counter()
for X in l:
for Y in l:
for Z in l:
x = X[0]
y = Y[0]
z = Z[0]
c[X[1]+Y[1]+Z[1]+x*y+y*z+x*z] += 1
for i in range(1, n+1):
print(c[i])
|
s613245636 | p03545 | u272336707 | 2,000 | 262,144 | Wrong Answer | 20 | 3,064 | 411 | 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 = len(s) - 1
import itertools
li = list(itertools.product({0, 1}, repeat=n))
for i in range(len(li)):
total = int(s[0])
shiki = s[0]
for j in range(n):
if li[i][j] == 0:
total += int(s[j+1])
shiki += "+"+s[j+1]
else:
total -= int(s[j+1])
shiki += "-"+s[j+1]
if total == 7:
print(shiki)
else:
pass | s785889201 | Accepted | 17 | 3,064 | 454 | s= input()
n = len(s) - 1
import itertools
li = list(itertools.product({0, 1}, repeat=n))
for i in range(len(li)):
total = int(s[0])
shiki = s[0]
for j in range(n):
if li[i][j] == 0:
total += int(s[j+1])
shiki += "+"+s[j+1]
else:
total -= int(s[j+1])
shiki += "-"+s[j+1]
if total == 7:
shiki += "="+str(7)
print(shiki)
break
else:
pass
|
s927640455 | p03455 | u313043608 | 2,000 | 262,144 | Wrong Answer | 27 | 9,028 | 78 | 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('Odd')
else:
print('Even') | s963500995 | Accepted | 26 | 9,068 | 79 | a,b=map(int,input().split())
if a*b%2==1:
print('Odd')
else:
print('Even')
|
s229755450 | p01132 | u635391238 | 8,000 | 131,072 | Wrong Answer | 20 | 7,824 | 1,365 | Mr. Bill は店で買い物をしている。 彼の財布にはいくらかの硬貨(10 円玉、50 円玉、100 円玉、500 円玉)が入っているが、彼は今この小銭をできるだけ消費しようとしている。 つまり、適切な枚数の硬貨によって品物の代金を払うことで、釣り銭を受け取った後における硬貨の合計枚数を最小にしようとしている。 幸いなことに、この店の店員はとても律儀かつ親切であるため、釣り銭は常に最適な方法で渡される。 したがって、例えば 1 枚の 500 円玉の代わりに 5 枚の 100 円玉が渡されるようなことはない。 また、例えば 10 円玉を 5 枚出して、50 円玉を釣り銭として受け取ることもできる。 ただし、出した硬貨と同じ種類の硬貨が釣り銭として戻ってくるような払いかたをしてはいけない。 例えば、10 円玉を支払いの際に出したにも関わらず、別の 10 円玉が釣り銭として戻されるようでは、完全に意味のないやりとりが発生してしまうからである。 ところが Mr. Bill は計算が苦手なため、実際に何枚の硬貨を使用すればよいかを彼自身で求めることができなかった。 そこで、彼はあなたに助けを求めてきた。 あなたの仕事は、彼の財布の中にある硬貨の枚数と支払い代金をもとに、使用すべき硬貨の種類と枚数を求めるプログラムを書くことである。なお、店員はお釣りに紙幣を使用することはない。 | def back_oturigation(fee, coin_values, coin_nums):
# 1.
oturi = coin_values[0]*coin_nums[0]\
+coin_values[1]*coin_nums[1]\
+coin_values[2]*coin_nums[2]\
+coin_values[3]*coin_nums[3]\
-fee
use_coins = [0] * len(coin_value)
no_use_coins = [0]*len(coin_value)
# 2.
for i in range(len(coin_value)-1, 0, -1):
no_use_coins[i] = int(oturi / coin_value[i])
oturi = oturi - (coin_value[i] * no_use_coins[i])
#3.
for i in range(0, len(use_coins), 1):
use_coins[i] = coin_nums[i] - no_use_coins[i]
if use_coins[i] > 0:
print(coin_value[i],' ',use_coins[i])
if __name__ == "__main__":
total_fee = int(input('total_fee:'))
coins = input('total_coins:')
coins = coins.split(' ')
coins = [int(coin) for coin in coins]
coin_value=[10, 50, 100, 500]
back_oturigation(total_fee, coin_value, coins) | s564556848 | Accepted | 120 | 7,908 | 1,512 | import math
def back_oturigation(fee, coin_values, coin_nums):
# 1.
oturi = coin_values[0] * coin_nums[0] \
+ coin_values[1] * coin_nums[1] \
+ coin_values[2] * coin_nums[2] \
+ coin_values[3] * coin_nums[3] \
- fee
use_coins = [0] * len(coin_values)
no_use_coins = [0] * len(coin_values)
# 2.
for i in range(len(coin_values) - 1, -1, -1):
no_use_coins[i] = int(oturi / coin_values[i])
oturi = oturi - (coin_values[i] * no_use_coins[i])
# 3.
for i in range(0, len(use_coins), 1):
use_coins[i] = coin_nums[i] - no_use_coins[i]
if use_coins[i] > 0:
print(str(coin_values[i]) + ' ' + str(use_coins[i]))
if __name__ == "__main__":
first = True
while (True):
total_fee = int(input(''))
if total_fee == 0:
break
if first:
first = False
else:
print('')
coins = input('')
coins = coins.split(' ')
coins = [int(coin) for coin in coins]
coin_values = [10, 50, 100, 500]
back_oturigation(total_fee, coin_values, coins) |
s574740943 | p03623 | u404556828 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 178 | Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|. | x, a, b = input().split()
x = int(x)
a = int(a)
b = int(b)
x_a = (x - a) ** 2
x_b = (x - b) ** 2
if x_a > x_b:
print("b")
# elif x_a == x_b:
# print("A = B")
else:
print("A") | s275781292 | Accepted | 17 | 2,940 | 146 | x, a, b = input().split()
x = int(x)
a = int(a)
b = int(b)
x_a = (x - a) ** 2
x_b = (x - b) ** 2
if x_a > x_b:
print("B")
else:
print("A") |
s314062944 | p03449 | u255280439 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 360 | 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())
Board = []
for i in range(2):
Board.append(list(map(int, input().split())))
max_candies = -1
for gotodown_index in range(N):
upper_candies = sum(Board[0][:gotodown_index+1])
lower_candies = sum(Board[1][gotodown_index:])
candies = upper_candies + lower_candies
if candies > max_candies:
max_candies = candies
print(candies)
| s120976492 | Accepted | 17 | 3,060 | 363 | N = int(input())
Board = []
for i in range(2):
Board.append(list(map(int, input().split())))
max_candies = 0
for gotodown_index in range(N):
upper_candies = sum(Board[0][:gotodown_index+1])
lower_candies = sum(Board[1][gotodown_index:])
candies = upper_candies + lower_candies
if candies > max_candies:
max_candies = candies
print(max_candies)
|
s412141678 | p03470 | u992875223 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 137 | 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())
D = [int(input()) for i in range(N)]
D.sort()
ans = 0
for i in range(N - 1):
if D[i] < D[i + 1]: ans += 1
print(ans) | s873220439 | Accepted | 17 | 3,060 | 137 | N = int(input())
D = [int(input()) for i in range(N)]
D.sort()
ans = 1
for i in range(N - 1):
if D[i] < D[i + 1]: ans += 1
print(ans) |
s147598720 | p03636 | u063614215 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 41 | The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way. | s = input()
print(s[0]+str(len(s))+s[-1]) | s130502526 | Accepted | 17 | 2,940 | 58 | s = input()
ans = s[0] + str(len(s)-2) + s[-1]
print(ans) |
s445148754 | p02694 | u648192617 | 2,000 | 1,048,576 | Wrong Answer | 23 | 9,168 | 101 | 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())
Y = 100
year = 0
while Y <= X:
Y = int(Y * 1.01)
year = year + 1
print(year) | s500451213 | Accepted | 20 | 9,108 | 100 | X = int(input())
Y = 100
year = 0
while Y < X:
Y = int(Y * 1.01)
year = year + 1
print(year) |
s711388800 | p04029 | u779728630 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 34 | 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) | s530103717 | Accepted | 17 | 2,940 | 40 | N = int(input())
print( int(N*(N+1)/2))
|
s429376652 | p03433 | u153729035 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 56 | E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. | print('YES' if int(input())%500<=int(input()) else 'NO') | s469628213 | Accepted | 17 | 2,940 | 56 | print('Yes' if int(input())%500<=int(input()) else 'No') |
s522029989 | p03352 | u977096988 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 403 | You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2. | s=input()
X=int(s)
if(X==1):
print(1)
else:
data=[]
for b in range(1,35):
for p in range(2,10):
xt=b**p
if(xt>1000):
break
data.append(xt)
print(data)
dist=2000
ans=-1
for i in range(len(data)):
if(data[i]<X and abs(data[i]-X)<dist):
dist=abs(data[i]-X)
ans=data[i]
print(ans)
| s292659784 | Accepted | 17 | 3,064 | 407 | s=input()
X=int(s)
if(X==1):
print(1)
else:
data=[]
for b in range(1,35):
for p in range(2,10):
xt=b**p
if(xt>1000):
break
data.append(xt)
dist=abs(data[0]-X)
ans=data[0]
for i in range(1,len(data)):
if(data[i]<=X and abs(data[i]-X)<=dist):
dist=abs(data[i]-X)
ans=data[i]
print(ans)
|
s370548713 | p02854 | u667024514 | 2,000 | 1,048,576 | Wrong Answer | 177 | 26,220 | 167 | Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length. | n = int(input())
lis = list(map(int,input().split()))
ans = 10 ** 10
num = sum(lis)
nu = 0
for i in range(n):
nu += lis[i]
ans = min(ans,abs(nu-num//2))
print(ans) | s055235988 | Accepted | 203 | 26,024 | 176 | n = int(input())
lis = list(map(int,input().split()))
ans = 10 ** 10
num = sum(lis)
nu = 0
for i in range(n):
nu += lis[i]
ans = min(ans,abs(nu-num/2))
print(int(ans//0.5)) |
s150828310 | p03610 | u316386814 | 2,000 | 262,144 | Wrong Answer | 19 | 3,188 | 27 | You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1. | s = input()
print(s[1::2]) | s393827304 | Accepted | 17 | 3,188 | 26 | s = input()
print(s[::2]) |
s874383621 | p03674 | u442877951 | 2,000 | 262,144 | Wrong Answer | 2,206 | 20,700 | 549 | You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7. | N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
def cmb(n,r,mod):
a=1
b=1
r = min(r,n-r)
for i in range(r):
a = a*(n-i)%mod
b = b*(i+1)%mod
return a*pow(b,mod-2,mod)%mod
ans = 0
INF = 10**9
x,y = 0,0
l = [INF]*(N+1)
for i in range(N+1):
if l[A[i]-1] != INF:
x = l[A[i]-1]
y = i+1
break
l[A[i]-1] = i+1
print(x,y)
for i in range(1,N+2):
if i == 1:
print(N)
elif i == N+1:
print(1)
elif N+x-y < i:
print(cmb(N+1,i,MOD)%MOD)
else:
print((cmb(N+1,i,MOD) - cmb(N+x-y,i-1,MOD))%MOD) | s014593625 | Accepted | 289 | 27,112 | 985 | def cmb(n, k, mod, fac, ifac):
k = min(k, n-k)
return fac[n] * ifac[k] % mod * ifac[n-k] % mod if n >= k >= 0 else 0
def make_tables(mod, n):
fac = [1, 1]
ifac = [1, 1]
inverse = [0, 1]
for i in range(2, n+1):
fac.append((fac[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod//i)) % mod)
ifac.append((ifac[-1] * inverse[-1]) % mod)
return fac, ifac
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
fac, ifac = make_tables(MOD,N+1)
ans = 0
INF = 10**9
x,y = 0,0
l = [INF]*(N+1)
for i in range(N+1):
if l[A[i]-1] != INF:
x = l[A[i]-1]
y = i+1
break
l[A[i]-1] = i+1
for i in range(1,N+2):
print((cmb(N+1,i,MOD,fac,ifac) - cmb(N+x-y,i-1,MOD,fac,ifac))%MOD) |
s974026329 | p03417 | u527261492 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 436 | There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations. | n,m=map(int,input().split())
if n*m==1:
print(1)
if n*m==2:
print(0)
if n*m==3:
print(1)
if n==2 and m==2:
print(0)
elif n*m==4:
print(2)
if n*m==5:
print(3)
if n==2 and m==3:
print(0)
if n==3 and m==2:
print(0)
elif n*m==6:
print(4)
if n*m==7:
print(5)
if n==2 and m==4:
print(0)
if n==4 and m==2:
print(0)
elif n*m==8:
print(6)
if n==3 and m==3:
print(1)
elif n*m==9:
print(7)
else:
print((n-2)*(m-2))
| s933222408 | Accepted | 18 | 2,940 | 126 | n,m=map(int,input().split())
if n*m==1:
print(1)
elif n==1:
print(m-2)
elif m==1:
print(n-2)
else:
print((n-2)*(m-2))
|
s175051057 | p00002 | u680933765 | 1,000 | 131,072 | Wrong Answer | 20 | 7,548 | 127 | Write a program which computes the digit number of sum of two integers a and b. | # Compatible with Python3
# -*- coding: utf-8 -*-
from math import log10
print(int(log10(eval(input().replace(" ", "+"))) + 1)) | s870972910 | Accepted | 20 | 7,604 | 79 | import sys
[print(len(str(sum(list(map(int, i.split())))))) for i in sys.stdin] |
s127698127 | p03361 | u118019047 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 326 | We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective. | h, w = map(int, input().split())
ls = [[i for i in '.'+input()+'.'] for i in range(h)]
print(ls)
ls.insert(0, ['.' for i in range(w+2)])
print(ls)
ls.append(['.' for i in range(w+2)])
print(ls)
for i in range(len(ls)):
print(ls[i]) | s977586242 | Accepted | 24 | 3,064 | 628 | h,w = list(map(int,input().split()))
table = list()
x = [0,1,0,-1]
y =[1,0,-1,0]
for i in range(h):
table.append(list(input()))
for i in range(h):
j_check = False
for j in range(w):
if table[i][j] == "#":
counter = 0
for a,b in zip(x,y):
if i + b >= h or i + b < 0 or j + a >= w or j + a < 0:
continue
elif table[i+b][j+a] == "#":
counter += 1
if counter == 0:
print("No")
j_check = True
break
if j_check:
break
else:
print("Yes") |
s923041965 | p00014 | u075836834 | 1,000 | 131,072 | Wrong Answer | 20 | 7,668 | 151 | Write a program which computes the area of a shape represented by the following three lines: $y = x^2$ $y = 0$ $x = 600$ It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obtain an approximative area of the shape by adding up areas of many rectangles in the shape as shown in the following figure: $f(x) = x^2$ The approximative area $s$ where the width of the rectangles is $d$ is: area of rectangle where its width is $d$ and height is $f(d)$ $+$ area of rectangle where its width is $d$ and height is $f(2d)$ $+$ area of rectangle where its width is $d$ and height is $f(3d)$ $+$ ... area of rectangle where its width is $d$ and height is $f(600 - d)$ The more we decrease $d$, the higer-precision value which is close to $72000000$ we could obtain. Your program should read the integer $d$ which is a divisor of $600$, and print the area $s$. | def function(a):
s=0
d=a
for i in range(d,600-d+1,d):
s+=a*(d**2)
d+=a
#print("%10d %10d"%(d,s))
return s
n=int(input())
print(function(n)) | s246640490 | Accepted | 30 | 7,564 | 198 | def function(a):
s=0
d=a
for i in range(d,600-d+1,d):
s+=a*(d**2)
d+=a
#print("%10d %10d"%(d,s))
return s
while True:
try:
n=int(input())
print(function(n))
except EOFError:
break |
s309130846 | p03229 | u129019798 | 2,000 | 1,048,576 | Wrong Answer | 660 | 13,444 | 859 | You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like. | N=input()
N=int(N)
L=[]
def diff(L):
total=0
for i in range(len(L)-1):
total+=abs(L[i+1]-L[i])
return total
for i in range(N):
A=input()
L.append(int(A))
L.sort()
if len(L)>3:
length=len(L)
SL=L[:int(length/2)]
LL=L[int(length/2):]
print(SL)
print(LL)
result=[]
result.append(SL[-1])
SL.pop(-1)
last=LL[0]
LL.pop(0)
while True:
try:
result.append(LL[-1])
LL.pop(-1)
result.append(SL[0])
SL.pop(0)
except:
break
result.append(last)
print(result)
print(diff(result))
elif len(L)==3:
all=[diff([L[0],L[1],L[2]]),diff([L[0],L[2],L[1]]),diff([L[1],L[0],L[2]]),diff([L[1],L[2],L[0]]),diff([L[2],L[0],L[1]]),diff([L[2],L[1],L[0]])]
print(max(all))
elif len(L)==2:
print(abs(L[0]-L[1]))
| s241962693 | Accepted | 637 | 9,060 | 902 | N=input()
N=int(N)
L=[]
def diff(L):
total=0
for i in range(len(L)-1):
total+=abs(L[i+1]-L[i])
return total
for i in range(N):
A=input()
L.append(int(A))
L.sort()
if len(L)>3:
length=len(L)
SL=L[:int(length/2)]
LL=L[int(length/2):]
result=[]
result.append(SL[-1])
SL.pop(-1)
last=LL[0]
LL.pop(0)
while True:
try:
result.append(LL[-1])
LL.pop(-1)
result.append(SL[0])
SL.pop(0)
except:
break
if abs(result[-1]-last)>=abs(result[0]-last):
result.append(last)
else:
result.insert(0,last)
print(diff(result))
elif len(L)==3:
all=[diff([L[0],L[1],L[2]]),diff([L[0],L[2],L[1]]),diff([L[1],L[0],L[2]]),diff([L[1],L[2],L[0]]),diff([L[2],L[0],L[1]]),diff([L[2],L[1],L[0]])]
print(max(all))
elif len(L)==2:
print(abs(L[0]-L[1]))
|
s784551686 | p03943 | u143189168 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 136 | 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. | s1 = input().split()
s2 = sorted(s1)
a = int(s2[0])
b = int(s2[1])
c = int(s2[2])
if a + b == c:
print("YES")
else:
print("NO") | s877193592 | Accepted | 17 | 2,940 | 123 | a,b,c = map(int, input().split())
s = [a,b,c]
t = sorted(s)
if t[0] + t[1] == t[2]:
print("Yes")
else:
print("No")
|
s731990344 | p03636 | u696197059 | 2,000 | 262,144 | Wrong Answer | 31 | 9,108 | 142 | The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way. | st_list = list(input())
print(st_list[0])
print(st_list[-1])
print(len(st_list[1:-1]))
print(st_list[0]+str(len(st_list[1:-1]))+st_list[-1]) | s677506272 | Accepted | 28 | 9,088 | 80 | st_list = list(input())
print(st_list[0]+str(len(st_list[1:-1]))+st_list[-1]) |
s360760944 | p03998 | u292978925 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 552 | Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. | sa = input()
sb = input()
sc = input()
now = 'a'
ca = 0
cb = 0
cc = 0
RC = ''
while RC == '':
if now == 'a':
print('a')
if ca == len(sa):
break
now = sa[ca]
ca += 1
elif now == 'b':
print('b')
if cb == len(sb):
break
now = sb[cb]
cb += 1
else:
print('c')
if cc == len(sc):
break
now = sc[cc]
cc += 1
print(now.upper())
| s673199278 | Accepted | 17 | 3,064 | 495 | sa = input()
sb = input()
sc = input()
now = 'a'
ca = 0
cb = 0
cc = 0
RC = ''
while RC == '':
if now == 'a':
if ca == len(sa):
break
now = sa[ca]
ca += 1
elif now == 'b':
if cb == len(sb):
break
now = sb[cb]
cb += 1
else:
if cc == len(sc):
break
now = sc[cc]
cc += 1
print(now.upper())
|
s288922953 | p03436 | u571445182 | 2,000 | 262,144 | Wrong Answer | 31 | 4,596 | 1,971 | We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`. | from collections import deque
nNM = []
nNM = input().rstrip().split(' ')
nH = int(nNM[0])
nW = int(nNM[1])
nTmp = [0 for i in range(nW)]
graph = {}
kyori = {}
checked = {}
nWallCnt = 0
for i in range(nH):
nTmp=input()
# print(nTmp)
for i2 in range(nW):
nPoi=('%d-%d' %(i,i2))
graph[nPoi] = []
kyori[nPoi] = float("inf")
checked[nPoi] = 0
if i==0 and i2==0:
nStart = ('%d-%d' %(0,0))
kyori[nPoi] = int (0)
continue
elif i==nH - 1 and i2==nW - 1:
nGoal = ('%d-%d' %(nH - 1, nW - 1))
continue
elif nTmp[i2]=='#':
nWall = ('%d-%d' %(i,i2))
nWallCnt += 1
checked[nPoi] = 1
else:
if i - 1 >= 0:
graph[nPoi].append('%d-%d' %(i - 1, i2))
if i + 1 < nH :
graph[nPoi].append('%d-%d' %(i + 1 , i2))
if i2 - 1 >= 0:
graph[nPoi].append('%d-%d' %(i , i2 - 1))
if i2 + 1 < nW:
graph[nPoi].append('%d-%d' %(i , i2 + 1))
root_queue = deque()
root_queue += graph[nStart]
nCount = len(graph[nStart])
for i in range(nCount):
kyori[(graph[nStart][i])] = 1
nFlag = 0
while root_queue:
nPoi2 = root_queue.popleft()
if checked[nPoi2] == 0:
if nPoi2 == nGoal:
nFlag = 1
break
else:
root_queue += graph[nPoi2]
for i in range(len(graph[nPoi2])):
nTmpCount = kyori[nPoi2] + 1
if kyori[(graph[nPoi2][i])] > nTmpCount:
kyori[(graph[nPoi2][i])] = nTmpCount
checked[nPoi2] = 1
if nFlag == 0:
print('-1')
else:
nTmp = kyori[nGoal] + 1
nTotal = nH * nW
nAns = nTotal - (nTmp + nWallCnt )
print(nAns)
| s945719376 | Accepted | 38 | 4,596 | 1,837 | from collections import deque
nNM = []
nNM = input().rstrip().split(' ')
nH = int(nNM[0])
nW = int(nNM[1])
nTmp = [0 for i in range(nW)]
graph = {}
kyori = {}
checked = {}
nWallCnt = 0
for i in range(nH):
nTmp=input()
# print(nTmp)
for i2 in range(nW):
# print(nTmp[i2])
nPoi=('%d-%d' %(i,i2))
graph[nPoi] = []
kyori[nPoi] = float("inf")
checked[nPoi] = 0
if i==0 and i2==0:
nStart = ('%d-%d' %(0,0))
kyori[nPoi] = int (0)
if i==nH - 1 and i2==nW - 1:
nGoal = ('%d-%d' %(nH - 1, nW - 1))
elif nTmp[i2]=='#':
nWall = ('%d-%d' %(i,i2))
nWallCnt += 1
checked[nPoi] = 1
else:
if i - 1 >= 0:
graph[nPoi].append('%d-%d' %(i - 1, i2))
if i + 1 < nH :
graph[nPoi].append('%d-%d' %(i + 1 , i2))
if i2 - 1 >= 0:
graph[nPoi].append('%d-%d' %(i , i2 - 1))
if i2 + 1 < nW:
graph[nPoi].append('%d-%d' %(i , i2 + 1))
root_queue = deque()
root_queue += graph[nStart]
nCount = len(graph[nStart])
for i in range(nCount):
kyori[(graph[nStart][i])] = 1
nFlag = 0
while root_queue:
nPoi2 = root_queue.popleft()
if checked[nPoi2] == 0:
if nPoi2 == nGoal:
nFlag = 1
break
else:
root_queue += graph[nPoi2]
for i in range(len(graph[nPoi2])):
nTmpCount = kyori[nPoi2] + 1
if kyori[(graph[nPoi2][i])] > nTmpCount:
kyori[(graph[nPoi2][i])] = nTmpCount
checked[nPoi2] = 1
if nFlag == 0:
print('-1')
else:
nTmp = kyori[nGoal] + 1
nTotal = nH * nW
nAns = nTotal - (nTmp + nWallCnt )
print(nAns)
|
s613408413 | p02665 | u563838154 | 2,000 | 1,048,576 | Wrong Answer | 2,278 | 76,148 | 301 | 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())
a = list(map(int,input().split()))
su = sum(a)
print(su)
l = [su]*n
for i in range(1,n):
l[i]=l[i-1]-a[i-1]
count=0
m=[1]*n
for j in range(1,n):
m[j] = m[j-1]*2
if m[j]>l[j]:
m[j]=l[j]
print(m[j])
count += m[j]
m[j] -= a[j]
count+=a[-1]+1
print(count) | s847992000 | Accepted | 141 | 20,840 | 520 | n = int(input())
a = list(map(int,input().split()))
if a[0] == 1 and n == 0:
print(1)
exit()
su = sum(a)
# print(su)
l = [su]*(n+1)
for i in range(1,n+1):
l[i]=l[i-1]-a[i-1]
# print(l)
count=0
x = 0
m=[1]*(n+1)
for j in range(1,n+1):
m[j] = m[j-1]*2
if m[j]>l[j]:
m[j]=l[j]
if (m[j]<a[j])or(m[j]==a[j] and j!=n):
# print(m[j],a[j])
x = 1
break
# print(m[j])
count += m[j]
m[j] -= a[j]
count+=1
if x==1 or a[0]!=0 :
print(-1)
else:
print(count) |
s637265801 | p03997 | u231122239 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 60 | 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, b, h = [int(input()) for _ in range(3)]
print((a+b)*h/2)
| s633647775 | Accepted | 17 | 2,940 | 61 | a, b, h = [int(input()) for _ in range(3)]
print((a+b)*h//2)
|
s710816540 | p03944 | u289162337 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 431 | There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting. | x_max, y_max, N = map(int, input().split())
x_min, y_min = 0, 0
l = [input().split() for _ in range(N)]
for i in range(N):
if l[i][2] == 1:
x_min = max(x_min, l[i][0])
elif l[i][2] == 2:
x_max = min(x_max, l[i][0])
elif l[i][2] == 3:
y_min = max(y_min, l[i][1])
elif l[i][2] == 4:
y_max = min(y_max, l[i][1])
if x_max-x_min > 0 and y_max-y_min:
print(abs(x_max-x_min)*abs(y_max-y_min))
else:
print(0)
| s757873109 | Accepted | 18 | 3,064 | 443 | x_max, y_max, N = map(int, input().split())
x_min, y_min = 0, 0
l = [[int(i) for i in input().split()] for _ in range(N)]
for i in range(N):
if l[i][2] == 1:
x_min = max(x_min, l[i][0])
elif l[i][2] == 2:
x_max = min(x_max, l[i][0])
elif l[i][2] == 3:
y_min = max(y_min, l[i][1])
elif l[i][2] == 4:
y_max = min(y_max, l[i][1])
if x_max-x_min > 0 and y_max-y_min:
print((x_max-x_min)*(y_max-y_min))
else:
print(0)
|
s706718720 | p03759 | u446711904 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 56 | 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());print('YNEOS'[a+c!=b::2]) | s023668863 | Accepted | 17 | 2,940 | 58 | a,b,c=map(int,input().split());print('YNEOS'[b-a!=c-b::2]) |
s274699755 | p02850 | u561992253 | 2,000 | 1,048,576 | Wrong Answer | 1,076 | 20,516 | 455 | 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. | words = lambda t : list(map(t, input().split()))
n = int(input())
vs = [[] for i in range(n)]
for i in range(n-1):
s,e = words(int)
vs[s-1].append(e-1)
import queue
q = queue.Queue()
q.put(0)
color = [0] * n
color[0] = 1
while not q.empty():
v = q.get()
cur_c = 1
for c in vs[v]:
if color[v] == cur_c:
cur_c +=1
color[c] = cur_c
cur_c += 1
q.put(c)
for i in range(n):
print(color[i])
| s289598686 | Accepted | 1,200 | 30,816 | 547 | words = lambda t : list(map(t, input().split()))
n = int(input())
vs = [[] for i in range(n)]
for i in range(n-1):
s,e = words(int)
vs[s-1].append((e-1,i))
import queue
q = queue.Queue()
q.put(0)
color = [0] * (n-1)
color_par = [0] * (n)
color_par[0] = -1
while not q.empty():
v = q.get()
cur_c = 1
for (c,i) in vs[v]:
if color_par[v] == cur_c:
cur_c +=1
color[i] = cur_c
color_par[c] = cur_c
cur_c += 1
q.put(c)
print(max(color))
for i in range(n-1):
print(color[i])
|
s902605502 | p03610 | u835482198 | 2,000 | 262,144 | Wrong Answer | 18 | 3,188 | 29 | You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1. | s = input()
print(s[0:-1:2])
| s517301840 | Accepted | 17 | 3,188 | 62 | s = input()
if len(s) % 2 == 1:
s += '-'
print(s[0:-1:2])
|
s306981410 | p02357 | u279605379 | 2,000 | 262,144 | Wrong Answer | 20 | 7,772 | 182 | For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $L$, find the minimum of each possible sub-arrays with size $L$ and print them from the beginning. For example, for an array $\\{1, 7, 7, 4, 8, 1, 6\\}$ and $L = 3$, the possible sub-arrays with size $L = 3$ includes $\\{1, 7, 7\\}$, $\\{7, 7, 4\\}$, $\\{7, 4, 8\\}$, $\\{4, 8, 1\\}$, $\\{8, 1, 6\\}$ and the minimum of each sub-array is 1, 4, 4, 1, 1 respectively. | [N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = ""
for i in range(N-L+1):
print(A[i*L:i*L+L])
ans += str(min(A[i:i+L])) + " "
print(ans) | s805308984 | Accepted | 2,110 | 127,964 | 757 | def ascend(a,b):
mini = min(A[a:a+L])
ans[a] = mini
for i in range(a+1,b):
if A[i+L-1] <= mini : mini = A[i+L-1]
elif A[i-1] == mini : mini = min(A[i:i+L])
ans[i] = mini
def descend(a,b):
mini = min(A[b-1:b+L-1])
ans[b-1] = mini
for i in range(b-2,a-1,-1):
if A[i] <= mini : mini = A[i]
elif A[i+L] == mini: mini = min(A[i:i+L])
ans[i] = mini
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
for i in range(100):
if A[i+1] > A[i] : count += 1
if count > 80 : descend(0, N-L+1)
else : ascend(0,N-L+1)
else :
ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1]) |
s961204430 | p03855 | u012694084 | 2,000 | 262,144 | Wrong Answer | 2,110 | 137,460 | 660 | There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways. | N, K, L = list(map(int, input().split(" ")))
N += 1
n_rl = [[[], [], None] for _ in range(N)]
for _ in range(K):
p, q = list(map(int, input().split(" ")))
for i in n_rl[p][0]:
n_rl[i][0].append(q)
n_rl[q][0].append(i)
n_rl[p][0].append(q)
n_rl[q][0].append(p)
for _ in range(L):
r, s = list(map(int, input().split(" ")))
for i in n_rl[r][1]:
n_rl[i][1].append(s)
n_rl[s][1].append(i)
n_rl[r][1].append(s)
n_rl[s][1].append(r)
for rl in n_rl[1:]:
r_set = set(rl[0])
l_set = set(rl[1])
intersection = r_set.intersection(l_set)
print("{} ".format(len(intersection) + 1), end="")
| s303061135 | Accepted | 1,323 | 56,492 | 1,153 | from collections import deque
def create_group(N, n):
city = [[] for _ in range(N + 1)]
for _ in range(n):
p, q = map(int, input().split(" "))
city[p].append(q)
city[q].append(p)
group_list = [0] * (N + 1)
gid = 0
Q = deque()
for i in range(1, N + 1):
if group_list[i] == 0:
gid += 1
Q.clear()
Q.append(i)
group_list[i] = gid
while len(Q) > 0:
x = Q.popleft()
for y in city[x]:
if group_list[y] == 0:
group_list[y] = gid
Q.append(y)
return group_list
if __name__ == "__main__":
N, K, L = list(map(int, input().split(" ")))
rg = create_group(N, K)
lg = create_group(N, L)
rg_lg_dict = {}
for i in range(1, N+1):
key = (rg[i], lg[i])
if key in rg_lg_dict:
rg_lg_dict[key] += 1
else:
rg_lg_dict[key] = 1
print_list = []
for i in range(1, N+1):
key = (rg[i], lg[i])
print_list.append(str(rg_lg_dict[key]))
print(" ".join(print_list))
|
s937706178 | p03635 | u251017754 | 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? | n, m = map(int, input().split())
print(n*m) | s072109859 | Accepted | 17 | 2,940 | 51 | n, m = map(int, input().split())
print((n-1)*(m-1)) |
s962201718 | p03478 | u314350544 | 2,000 | 262,144 | Wrong Answer | 43 | 9,112 | 148 | Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). | n, a, b = map(int, input().split())
ans = 0
for i in range(n + 1):
if a <= sum(list(map(int, list(str(i))))) >= b:
ans += i
print(ans) | s257037067 | Accepted | 39 | 9,164 | 144 | n, a, b = map(int, input().split())
ans = 0
for i in range(n+1):
if a <= sum(list(map(int, list(str(i))))) <= b:
ans += i
print(ans) |
s384888074 | p03592 | u679325651 | 2,000 | 262,144 | Wrong Answer | 2,029 | 17,860 | 219 | We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid. | N,M,K = [int(i) for i in input().split()]
for i in range(0,N+1):
for j in range(0,M+1):
ans = i*M+j*N-i*j*2
print(i,j,ans)
if ans==K:
print("Yes")
exit()
print("No") | s031170731 | Accepted | 392 | 3,064 | 196 | N,M,K = [int(i) for i in input().split()]
for i in range(0,N+1):
for j in range(0,M+1):
ans = i*M+j*N-i*j*2
if ans==K:
print("Yes")
exit()
print("No") |
s050303831 | p03149 | u588633699 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 723 | You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974". | S = str(input())
keyence = 'keyence'
if len(S) == 7:
if S==keyence:
print('YES')
else:
print('NO')
else :
for i in range(0,7):
if keyence[:i] in S and keyence[i:] in S[S.index(keyence[:i])+i:] :
if i==0 and S.index(keyence[i:])==0 :
print('YES')
break
elif i==0 and S.index(keyence[i:])!=0 and len(S)-7 == S.index(keyence[i:]) :
print('YES')
break
elif S.index(keyence[:i])==0 and S[S.index(keyence[i:])+(7-i):] == '' :
print('YES')
break
else:
print('NO') | s213026224 | Accepted | 18 | 2,940 | 121 | N = list(map( int, input().split() ))
if 1 in N and 9 in N and 7 in N and 4 in N:
print('YES')
else:
print('NO') |
s165833142 | p03545 | u566787760 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 339 | 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. | n = input()
cnt = len(n) -1
for i in range(2 ** cnt):
op = ["-"] * cnt
for j in range(cnt):
if ((i >> j) & 1):
op[cnt - 1 - j] = "+"
formula = ""
for p_n,p_o in zip(n,op+[""]):
formula += (p_n + p_o)
print(formula)
if eval(formula) == 7:
print(formula + "=7")
break
| s349067439 | Accepted | 18 | 3,060 | 316 | n = input()
cnt = len(n) -1
for i in range(2 ** cnt):
op = ["-"] * cnt
for j in range(cnt):
if ((i >> j) & 1):
op[cnt - 1 - j] = "+"
formula = ""
for p_n,p_o in zip(n,op+[""]):
formula += (p_n + p_o)
if eval(formula) == 7:
print(formula + "=7")
break
|
s091276177 | p03854 | u156113867 | 2,000 | 262,144 | Wrong Answer | 18 | 3,188 | 157 | You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | S = input()
result = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if result:
print("No")
else:
print("Yes") | s790374119 | Accepted | 19 | 3,188 | 157 | S = input()
result = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if result:
print("NO")
else:
print("YES") |
s016100583 | p03400 | u368796742 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 144 | Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp. | n = int(input())
d,x = map(int,input().split())
for i in range(n):
a = int(input())
b = 1
while b > n:
x += 1
b += a
print(x)
| s114199129 | Accepted | 17 | 2,940 | 146 | n = int(input())
d,x = map(int,input().split())
for i in range(n):
a = int(input())
b = 1
while b <= d:
x += 1
b += a
print(x)
|
s569114264 | p02255 | u935329231 | 1,000 | 131,072 | Wrong Answer | 30 | 7,584 | 489 | 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. | # -*- coding: utf-8 -*-
def insertion_sort(seq, l):
for i, v in enumerate(seq[1:], start=1):
left = i - 1
while left >= 0 and seq[left] > v:
seq[left], seq[left+1] = seq[left+1], seq[left]
left -= 1
print(' '.join([str(n) for n in seq]))
def to_int(v):
return int(v)
def to_seq(v):
return [int(c) for c in v.split()]
if __name__ == '__main__':
l = to_int(input())
seq = to_seq(input())
insertion_sort(seq, l) | s493399684 | Accepted | 20 | 7,748 | 532 | # -*- coding: utf-8 -*-
def insertion_sort(seq, l):
print(' '.join([str(n) for n in seq]))
for i, v in enumerate(seq[1:], start=1):
left = i - 1
while left >= 0 and seq[left] > v:
seq[left], seq[left+1] = seq[left+1], seq[left]
left -= 1
print(' '.join([str(n) for n in seq]))
def to_int(v):
return int(v)
def to_seq(v):
return [int(c) for c in v.split()]
if __name__ == '__main__':
l = to_int(input())
seq = to_seq(input())
insertion_sort(seq, l) |
s174177835 | p02388 | u655518263 | 1,000 | 131,072 | Wrong Answer | 30 | 7,604 | 34 | Write a program which calculates the cube of a given integer x. | x = int(input("x = "))
print(x**3) | s588389409 | Accepted | 20 | 7,676 | 28 | x = int(input())
print(x**3) |
s715962418 | p03814 | u897328029 | 2,000 | 262,144 | Wrong Answer | 18 | 3,816 | 71 | 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 = input()
l = s.find('A')
r = s.rfind('Z')
ans = s[l:r+1]
print(ans)
| s561923559 | Accepted | 17 | 3,628 | 76 | s = input()
l = s.find('A')
r = s.rfind('Z')
ans = len(s[l:r+1])
print(ans)
|
s393344767 | p03386 | u288948615 | 2,000 | 262,144 | Wrong Answer | 2,104 | 3,060 | 106 | 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())
for i in range(A, B+1):
if i-A <= K or B-i <= K:
print(i) | s252828895 | Accepted | 17 | 3,060 | 147 | A, B, K = map(int, input().split())
m = min(A+K, B+1)
for i in range(A, m):
print(i)
n = max(A+K, B-K+1)
for j in range(n, B+1):
print(j) |
s702160989 | p03449 | u310678820 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 208 | 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())
u=[int(j) for j in input().split()]
m=[int(j) for j in input().split()]
ans=0
for i in range(n):
t=0
t=sum(u[:i+1])+sum(m[i:])
print(t)
if ans<t:
ans=t
print(ans)
| s532493057 | Accepted | 19 | 2,940 | 197 | n=int(input())
u=[int(j) for j in input().split()]
m=[int(j) for j in input().split()]
ans=0
for i in range(n):
t=0
t=sum(u[:i+1])+sum(m[i:])
if ans<t:
ans=t
print(ans)
|
s448227607 | p03090 | u426764965 | 2,000 | 1,048,576 | Wrong Answer | 28 | 9,232 | 827 | You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem. | def agc032_b():
n = int(input())
A = [[n], []]
t = 1
for i in range(n-1, 0, -2):
if i == 1: A[t] += [i]
else: A[t] += [i, i-1]
t = abs(t-1)
odd = False
if sum(A[0]) != sum(A[1]):
odd = True
if n % 2 == 1:
if A[0][-1] == 1: A[1].append(1)
else: A[0].append(1)
else:
if A[0][-1] == 1:
A[0] = A[0][:-2] + [3,2,1]
A[1] = A[1][:-2] + [4,1]
else:
A[0] = A[0][:-2] + [4,1]
A[1] = A[1][:-2] + [3,2,1]
#print(A[0], A[1])
cnt = len(A[0]) * len(A[1])
if odd: cnt -= 1
print(cnt)
for a in A[0]:
for b in A[1]:
if a == b: continue
print('{} {}'.format(a, b))
if __name__ == '__main__':
agc032_b() | s535758886 | Accepted | 34 | 9,208 | 380 | def agc032_b():
n = int(input())
g = [[1]*n for _ in range(n)]
for i in range(n//2):
j = 2*(n//2)-1-i
g[i][j] = 0
g[j][i] = 0
cnt = (sum([sum(row) for row in g]) - n) // 2
print(cnt)
for i in range(n):
for j in range(i+1, n):
if g[i][j]: print('{} {}'.format(i+1, j+1))
if __name__ == '__main__':
agc032_b() |
s574986774 | p04043 | u312913211 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 211 | 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. | inpstr = input()
inp = inpstr.split(" ")
inp = list(map(int,inp))
c5 = 0
c7 = 0
for i in inp:
if inp==5:
c5 += 1
elif inp==7:
c7 += 1
if c5 == 2 and c7 == 1:
print('YES')
else:
print('No') | s945346858 | Accepted | 18 | 3,060 | 202 | inpstr = input()
inp = inpstr.split(" ")
inp = list(map(int,inp))
c5 = 0
c7 = 0
for i in inp:
if i==5:
c5 += 1
elif i==7:
c7 += 1
if c5 == 2 and c7 == 1:
print('YES')
else:
print('NO') |
s571431902 | p03862 | u038353231 | 2,000 | 262,144 | Wrong Answer | 187 | 14,252 | 470 | There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective. | import sys
Nx = input().split()
an = input().split()
anx = list()
for item in an:
anx.append(int(item))
x = int(Nx[1])
N = int(Nx[0])
i = 0
count = 0
while i < N - 1:
sum = anx[i] + anx[i + 1]
if sum > x:
count+= sum - x
num = sum - x
anxi = anx[i]
anxi -= num
if anxi < 0:
anxi2 = anx[i + 1] + anxi
anx[i+1] = anxi2
anxi = 0
anx[i] = anxi
i += 1
print(count)
| s011559602 | Accepted | 151 | 14,276 | 469 | import sys
Nx = input().split()
an = input().split()
anx = list()
for item in an:
anx.append(int(item))
x = int(Nx[1])
N = int(Nx[0])
i = 0
count = 0
while i < N - 1:
sum = anx[i] + anx[i + 1]
if sum > x:
count += sum - x
num = sum - x
anxi = anx[i+1]
anxi -= num
if anxi < 0:
anxi2 = anx[i] + anxi
anx[i] = anxi2
anxi = 0
anx[i+1] = anxi
i += 1
print(count)
|
s487573814 | p03351 | u787873596 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,060 | 202 | 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. | line = input().split(' ')
a, b, c, d = int(line[0]), int(line[1]), int(line[2]), int(line[3])
if abs(a-c) < d:
print('Yes')
else:
if abs(a-b) < d and abs(b-c) < d:
print('Yes')
else:
print('No') | s136545194 | Accepted | 17 | 2,940 | 207 | line = input().split(' ')
a, b, c, d = int(line[0]), int(line[1]), int(line[2]), int(line[3])
if abs(a-c) <= d:
print('Yes')
else:
if abs(a-b) <= d and abs(b-c) <= d:
print('Yes')
else:
print('No')
|
s888754158 | p03251 | u357751375 | 2,000 | 1,048,576 | Wrong Answer | 24 | 9,040 | 200 | 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())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort(reverse = True)
b.sort()
if b[0] - a[0] < 2:
print('War')
else:
print('No War') | s118737595 | Accepted | 30 | 9,112 | 215 | n,m,x,y = map(int,input().split())
xl = list(map(int,input().split()))
yl = list(map(int,input().split()))
xl.append(x)
yl.append(y)
xl.sort()
yl.sort()
if xl[-1] < yl[0]:
print('No War')
else:
print('War') |
s922995368 | p03545 | u442581202 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 364 | 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. | import itertools
s = input()
x = ['+','-']
l = list(itertools.product(x,x,x))
res = int(s[0])
for sign in l:
res = int(s[0])
for i in range(3):
if sign[i] == '+':
res += int(s[i+1])
else:
res -= int(s[i+1])
if res == 7:
print(s[0],end="")
for i in range(3):
print(sign[i],end="")
print(s[i+1],end="")
print("") | s152123532 | Accepted | 17 | 3,064 | 379 | import itertools
s = input()
x = ['+','-']
l = list(itertools.product(x,x,x))
res = int(s[0])
for sign in l:
res = int(s[0])
for i in range(3):
if sign[i] == '+':
res += int(s[i+1])
else:
res -= int(s[i+1])
if res == 7:
print(s[0],end="")
for i in range(3):
print(sign[i],end="")
print(s[i+1],end="")
print("=7")
exit(0)
|
s486594913 | p02612 | u070630744 | 2,000 | 1,048,576 | Wrong Answer | 39 | 10,436 | 200 | 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
import collections
import fractions
import itertools
import functools
import operator
def solve():
print(int(input()) - 1000)
return 0
if __name__ == "__main__":
solve()
1900 | s402852391 | Accepted | 41 | 10,440 | 225 | import math
import collections
import fractions
import itertools
import functools
import operator
def solve():
n = int(input())
print(math.ceil(n/1000)*1000 - n)
return 0
if __name__ == "__main__":
solve()
|
s336239176 | p03719 | u393971002 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 91 | 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 a <= c <= b:
print("YES")
else:
print("NO") | s469563898 | Accepted | 17 | 2,940 | 91 | a, b, c = map(int, input().split())
if a <= c <= b:
print("Yes")
else:
print("No") |
s144064895 | p03623 | u852790844 | 2,000 | 262,144 | Wrong Answer | 24 | 3,768 | 133 | 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|. | import string
s = set(input())
a = set(string.ascii_lowercase)
b = sorted(list(a - s))
ans = b[0] if len(b) else "None"
print(ans)
| s878257952 | Accepted | 150 | 12,392 | 114 | import numpy as np
x, a, b = map(int, input().split())
ans = 'A' if np.abs(a-x) < np.abs(b-x) else 'B'
print(ans) |
s018213705 | p02742 | u579508806 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 57 | We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move: | (a,b)=[int(x) for x in input().split()]
print((a+b+1)//2) | s920298113 | Accepted | 17 | 2,940 | 93 | (a,b)=[int(x) for x in input().split()]
if a==1 or b==1:
print(1)
else:
print((a*b+1)//2) |
s148842826 | p02854 | u879478232 | 2,000 | 1,048,576 | Wrong Answer | 2,105 | 26,220 | 210 | Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length. | import sys
n = int(input())
a = list(map(int, input().split()))
postCenter=dif=0
tmp = sys.maxsize
for i in range(n):
if tmp < abs(sum(a[:i])-sum(a[i:])):
tmp = abs(sum(a[:i])-sum(a[i:]))
print(tmp) | s069476453 | Accepted | 179 | 26,220 | 170 | import sys
n = int(input())
a = list(map(int, input().split()))
tmp=sys.maxsize
s = sum(a)
t = 0
for i in range(n):
t += a[i]
tmp = min(tmp,abs(s-t*2))
print(tmp) |
s701638875 | p03448 | u295043075 | 2,000 | 262,144 | Wrong Answer | 188 | 21,804 | 331 | 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. | import numpy
A = int(input())
B = int(input())
C = int(input())
X = int(input())
vA=list(range(A+1))*(B+1)*(C+1)
vB=list(range(B+1))*(A+1)*(C+1)
vC=list(range(C+1))*(A+1)*(B+1)
Com=len(vA)
O = numpy.matrix([500,100,50])
P = numpy.matrix(vA+vB+vC).reshape(3,Com)
Q = O*P
ans=numpy.sum(Q==X)
print(ans) | s839475885 | Accepted | 198 | 19,844 | 401 | import numpy
A = int(input())
B = int(input())
C = int(input())
X = int(input())
lisA=list(range(A+1))
lisB=list(range(B+1))
lisC=list(range(C+1))
vA=numpy.repeat(lisA, len(lisB)*len(lisC))
vB=numpy.repeat(len(lisA)*lisB, len(lisC))
vC=numpy.repeat(len(lisA)*len(lisB)*lisC,1)
O = numpy.matrix([500,100,50])
P = numpy.array([vA,vB,vC]).reshape(3,len(vA))
Q = O*P
ans=numpy.sum(Q==X)
print(ans)
|
s026486983 | p03494 | u360038884 | 2,000 | 262,144 | Time Limit Exceeded | 2,104 | 5,488 | 348 | There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. | n = input()
list = [int(i) for i in input().split()]
count = 0
flg = False
while True:
for num in list:
if num % 2 != 0:
flg = True
break
if flg:
break
else:
count += 1
list = map(lambda x: x / 2, list)
print(count) | s141817241 | Accepted | 19 | 3,060 | 305 | n = input()
list = [int(i) for i in input().split()]
min_count = 1000000000
tmp = 0
for num in list:
tmp = 0
while True:
if num % 2 != 0:
break
else:
tmp += 1
num = num / 2
if min_count > tmp:
min_count = tmp
print(min_count) |
s898370552 | p02396 | u108130680 | 1,000 | 131,072 | Wrong Answer | 50 | 5,596 | 96 | In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem. | i = 1
while True:
x = int(input())
if x == 0:
break
print('Case i : x')
| s604525328 | Accepted | 140 | 5,600 | 119 | c = 1
while True:
x = int(input())
if x == 0:
break
print("Case {}: {}".format(c, x))
c += 1
|
s395174597 | p03455 | u243699903 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 68 | 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==0 else "Even") | s538892606 | Accepted | 17 | 2,940 | 68 | a,b=map(int,input().split())
print("Odd" if (a*b)%2==1 else "Even") |
s284799149 | p02613 | u735542540 | 2,000 | 1,048,576 | Wrong Answer | 147 | 9,196 | 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())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
s = input()
if s == "AC":
ac += 1
elif s == "WA":
wa += 1
elif s == "TLE":
tle += 1
else:
re += 1
print(f"AC × {ac}")
print(f"WA × {wa}")
print(f"TLE × {tle}")
print(f"RE × {re}") | s566424046 | Accepted | 149 | 9,140 | 296 | n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
s = input()
if s == "AC":
ac += 1
elif s == "WA":
wa += 1
elif s == "TLE":
tle += 1
else:
re += 1
print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}") |
s205284244 | p02614 | u571331348 | 1,000 | 1,048,576 | Wrong Answer | 68 | 9,084 | 566 | 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 = [int(x) for x in input().split()]
init_map = []
for i in range(H):
row = list(input())
init_map.append(row)
#print(init_map)
ans = 0
for paint_h in range(2 ** H):
print("h: " + str(paint_h))
for paint_w in range(2 ** W):
print("w: " + str(paint_w))
cnt = 0
for i in range(H):
for j in range(W):
if (paint_h >> i)&1 == 0 and (paint_w >> j)&1 == 0:
if init_map[i][j] == "#":
cnt += 1
if cnt == K:
ans += 1
print(ans)
| s563946404 | Accepted | 64 | 9,196 | 568 | H, W, K = [int(x) for x in input().split()]
init_map = []
for i in range(H):
row = list(input())
init_map.append(row)
#print(init_map)
ans = 0
for paint_h in range(2 ** H):
#print("h: " + str(paint_h))
for paint_w in range(2 ** W):
#print("w: " + str(paint_w))
cnt = 0
for i in range(H):
for j in range(W):
if (paint_h >> i)&1 == 0 and (paint_w >> j)&1 == 0:
if init_map[i][j] == "#":
cnt += 1
if cnt == K:
ans += 1
print(ans) |
s572388574 | p03644 | u597047658 | 2,000 | 262,144 | Wrong Answer | 17 | 3,068 | 227 | Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times. | # N = input()
N = 100
tnum = 0
iter_num = 0
for i in range(N):
res = 0
num = i+1
while num % 2 == 0:
num /= 2
res += 1
if iter_num < res:
iter_num = res
tnum = i+1
print(tnum)
| s477557965 | Accepted | 17 | 2,940 | 223 | N = int(input())
tnum = 0
iter_num = 0
for i in range(N):
res = 0
num = i+1
while num % 2 == 0:
num /= 2
res += 1
if iter_num <= res:
iter_num = res
tnum = i+1
print(tnum)
|
s869212552 | p03377 | u765400831 | 2,000 | 262,144 | Wrong Answer | 19 | 2,940 | 115 | 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 (X < A):
print("No")
elif ((X-A)<=B):
print("Yes")
else:
print("No") | s007049716 | Accepted | 17 | 2,940 | 114 | A,B,X = map(int,input().split())
if (X<A):
print("NO")
elif ((X-A)<=B):
print("YES")
else:
print("NO") |
s814812822 | p02694 | u431225094 | 2,000 | 1,048,576 | Wrong Answer | 21 | 9,176 | 286 | 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 sys
try:
sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
pass
x = int(input())
n = 100
t = 0
while n <= x:
n += (0.01 * n)
n = int(n)
t += 1
# print(n, t)
print(t) | s017541678 | Accepted | 23 | 9,180 | 285 | import sys
try:
sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
pass
x = int(input())
n = 100
t = 0
while n < x:
n += (0.01 * n)
n = int(n)
t += 1
# print(n, t)
print(t) |
s492046625 | p03494 | u902361509 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 247 | There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. | a = list(map(int, input().split()))
ans = 0
while(True):
t = True
for i in a:
if i%2:
t = False
if t == True:
ans += 1
a = list(map(lambda j: j/2, a))
else:
break
print(str(ans)) | s087607562 | Accepted | 18 | 2,940 | 246 | n = input()
a = list(map(int, input().split()))
ans = 0
while(True):
t = True
for i in a:
if i%2:
t = False
if t:
ans += 1
a = [int(x/2) for x in a]
else:
break
print(str(ans))
|
s077391260 | p03433 | u331672674 | 2,000 | 262,144 | Wrong Answer | 20 | 2,940 | 100 | E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. | # -*- coding: utf-8 -*-
n = int(input())
a = int(input())
print("YES" if (n % 500) <= a else "NO") | s764109043 | Accepted | 17 | 2,940 | 100 | # -*- coding: utf-8 -*-
n = int(input())
a = int(input())
print("Yes" if (n % 500) <= a else "No") |
s863613226 | p03679 | u104888971 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 152 | Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache. | X, A, B = map(int, input().split())
print(X, A, B)
if A >= B:
print('delicious')
elif A + X >= B:
print('safe')
else:
print('dangerous') | s953492471 | Accepted | 17 | 2,940 | 136 | X, A, B = map(int, input().split())
if A >= B:
print('delicious')
elif A + X >= B:
print('safe')
else:
print('dangerous') |
s475870742 | p03417 | u736729525 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 225 | There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations. |
def solve(N, M):
# 1 2
# 3 4
#
# (0) (1)
# 1 2 1 2 3
# 3 4 4 5 6
# 5 6 7 8 9
return max(1, (N - 2)) * max(1, (M - 2))
N, M = [int(x) for x in input().split()]
print(solve(N, M))
| s805940227 | Accepted | 18 | 2,940 | 347 |
def solve(N, M):
# 1 2
# 3 4
# 1 2
# 3 4
#
# (0) (1)
# 1 2 1 2 3
# 3 4 4 5 6
# 5 6 7 8 9
def cut(n):
if n == 1:
return 1
elif n == 2:
return 0
return n - 2
return cut(N) * cut(M)
N, M = [int(x) for x in input().split()]
print(solve(N, M))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.