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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s666236524 | p02612 | u089142196 | 2,000 | 1,048,576 | Wrong Answer | 33 | 9,108 | 28 | We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required. | N=int(input())
print(N%1000) | s449806400 | Accepted | 27 | 9,088 | 70 | N=int(input())
if N%1000==0:
print(0)
else:
print(1000-N%1000) |
s670811317 | p03228 | u811202694 | 2,000 | 1,048,576 | Wrong Answer | 21 | 3,316 | 256 | In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total. | a,b,k = map(int,input().split())
for i in range(k):
if i % 2 == 0:
if a % 2 == 1:
a -= 1
b += a / 2
a /= 2
else:
if b % 2 == 1:
b -= 1
a += b / 2
b /= 2
print(a,b) | s718521636 | Accepted | 17 | 2,940 | 267 | a,b,k = map(int,input().split())
for i in range(k):
if i % 2 == 0:
if a % 2 == 1:
a -= 1
b += a // 2
a = a // 2
else:
if b % 2 == 1:
b -= 1
a += b // 2
b = b // 2
print(a,b)
|
s528923194 | p02659 | u044514121 | 2,000 | 1,048,576 | Wrong Answer | 24 | 9,096 | 117 | Compute A \times B, truncate its fractional part, and print the result as an integer. | import sys
input = sys.stdin.readline
x = sorted(list(map(float, input().split())))
print(x)
print(int(x[0]*x[1])) | s260064098 | Accepted | 22 | 9,096 | 68 |
a,b=map(float,input().split())
B=round(100*b)
print(int(a)*B//100)
|
s773547789 | p02406 | u342125850 | 1,000 | 131,072 | Wrong Answer | 50 | 7,532 | 99 | In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } | num = int(input())
x=""
for i in range(1, num+1):
if i % 3 == 0:
x += (" " + str(i))
print(x) | s055510228 | Accepted | 30 | 8,220 | 112 | x = int(input())
for i in range(3, x + 1):
if i % 3 == 0 or '3' in str(i):
print('', i , end = '')
print() |
s028177805 | p03054 | u983918956 | 2,000 | 1,048,576 | Wrong Answer | 384 | 3,784 | 941 | We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a string of length N. Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: `L`, `R`, `U` and `D`. The game consists of N steps. The i-th step proceeds as follows: * First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece. * Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece. Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done. Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally. | H,W,N = map(int,input().split())
sr,sc = [int(e)-1 for e in input().split()]
S = input()
T = input()
r = 0
l = 0
u = 0
d = 0
ans = "Yes"
for j in range(N):
for i in range(2):
if i == 0:
mark = S[j]
if mark == "R":
r += 1
elif mark == "L":
l += 1
elif mark == "U":
u += 1
elif mark == "D":
d += 1
if i == 1:
mark = T[j]
if mark == "R":
if sc + l > 0:
l -= 1
elif mark == "L":
if sc - r < W-1:
r -= 1
elif mark == "U":
if sr - d < H-1:
d -= 1
elif mark == "D":
if sr + u > 0:
u -= 1
if r > W-1-sc or l > sc or u > sr or d > H-1-sr:
ans = "No"
print(ans) | s466931869 | Accepted | 395 | 3,788 | 849 | H,W,N = map(int,input().split())
sr,sc = [int(e)-1 for e in input().split()]
S = input()
T = input()
r = 0
l = 0
u = 0
d = 0
ans = "YES"
for j in range(N):
for i in range(2):
if i == 0:
mark = S[j]
if mark == "R":
r += 1
elif mark == "L":
l += 1
elif mark == "U":
u += 1
elif mark == "D":
d += 1
if i == 1:
mark = T[j]
if mark == "R":
l = max(l-1,-(W-1-sc))
elif mark == "L":
r = max(r-1,-sc)
elif mark == "U":
d = max(d-1,-sr)
elif mark == "D":
u = max(u-1,-(H-1-sr))
if r > W-1-sc or l > sc or u > sr or d > H-1-sr:
ans = "NO"
print(ans) |
s565291421 | p03474 | u811202694 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 197 | 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. | a ,b = (map(int,input().split()))
post = input().split("-")
if len(post) == 2:
if(len(post[0])==a and len(post[1])==b):
print("YES")
else:
print("NO")
else:
print("NO") | s496755108 | Accepted | 17 | 3,060 | 197 | a ,b = (map(int,input().split()))
post = input().split("-")
if len(post) == 2:
if(len(post[0])==a and len(post[1])==b):
print("Yes")
else:
print("No")
else:
print("No") |
s472086576 | p03352 | u368796742 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 196 | 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. | n = int(input())
l = []
l.append(1)
for i in range(2,40):
b = i**2
while b <= 1000:
l.append(b)
b*= i
l.sort()
for i in range(len(l)):
if n > l[i]:
print(l[i-1])
exit()
| s742339086 | Accepted | 17 | 2,940 | 209 | n = int(input())
l = []
l.append(1)
for i in range(2,40):
b = i**2
while b <= 1000:
l.append(b)
b*= i
l.sort()
for i in range(len(l)):
if n < l[i]:
print(l[i-1])
exit()
print(1000)
|
s237226192 | p02612 | u182166469 | 2,000 | 1,048,576 | Wrong Answer | 28 | 9,084 | 60 | We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required. | n=int(input())
num=int(n/1000)+1
ans=num*1000-n
print(n)
| s417843914 | Accepted | 29 | 9,088 | 102 | n=int(input())
if n%1000 == 0:
ans=n%1000
else:
num=n//1000+1
ans=num*1000-n
print(int(ans))
|
s627920085 | p03456 | u358003829 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 119 | AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number. | import math
a, b = input().split()
a = a+b
if math.sqrt(int(a)).is_integer():
print(a, "YES")
else:
print(a, "NO")
| s344223610 | Accepted | 319 | 21,644 | 118 | import numpy as np
a, b = input().split()
a = a+b
if np.sqrt(int(a)).is_integer():
print("Yes")
else:
print("No")
|
s428219993 | p03485 | u896741788 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 46 | You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer. | a,b=map(int,input().split())
print((a+b)//1+1) | s315289694 | Accepted | 17 | 2,940 | 81 | a,b=map(int,input().split())
print((a+b)//2 + 1) if (a+b)%2 else print((a+b)//2)
|
s550406390 | p03730 | u910756197 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 165 | We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`. | a, b, c = map(int, input().split(" "))
flag = False
for i in range(1, b):
if a * i % b == c:
flag = True
if flag:
print("Yes")
else:
print("No")
| s626840196 | Accepted | 17 | 2,940 | 167 | a, b, c = map(int, input().split(" "))
flag = False
for i in range(1, b):
if (a * i) % b == c:
flag = True
if flag:
print("YES")
else:
print("NO")
|
s483845773 | p00003 | u957680575 | 1,000 | 131,072 | Wrong Answer | 40 | 7,444 | 220 | Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so. | N = int(input())
for i in range(N):
a = list(map(int, input().split()))
a = sorted(a)
x = a[0]
y = a[1]
z = a[2]
if x**2 + y**2 == z**2:
print("yes")
else:
print("no")
| s820954740 | Accepted | 40 | 7,524 | 220 | N = int(input())
for i in range(N):
a = list(map(int, input().split()))
a = sorted(a)
x = a[0]
y = a[1]
z = a[2]
if x**2 + y**2 == z**2:
print("YES")
else:
print("NO")
|
s931084602 | p03371 | u799691369 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 379 | "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas. | A, B, C, X, Y = map(int,input().split())
def best_pizza_cost(ln, hn):
if ln == X: lp = A
else: lp = B
if hn == Y: hp = B
else: hp = A
fnp = lp * ln + hp * ln
fhp = C * ln * 2
left = hn-ln
snp = hp * left
shp = C * left * 2
print(fnp, fhp, snp, shp)
return min(fnp, fhp) + min(snp, shp)
print(best_pizza_cost(min(X, Y), max(X, Y))) | s511943746 | Accepted | 19 | 3,064 | 380 | A, B, C, X, Y = map(int,input().split())
def best_pizza_cost(ln, hn):
if ln == X: lp = A
else: lp = B
if hn == Y: hp = B
else: hp = A
fnp = lp * ln + hp * ln
fhp = C * ln * 2
left = hn-ln
snp = hp * left
shp = C * left * 2
#print(fnp, fhp, snp, shp)
return min(fnp, fhp) + min(snp, shp)
print(best_pizza_cost(min(X, Y), max(X, Y))) |
s187623890 | p00006 | u340991036 | 1,000 | 131,072 | Wrong Answer | 20 | 5,536 | 25 | Write a program which reverses a given string str. | print(reversed(input()))
| s040764027 | Accepted | 20 | 5,544 | 22 | print(input()[::-1])
|
s842166924 | p03478 | u514383727 | 2,000 | 262,144 | Wrong Answer | 53 | 3,308 | 226 | Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). | n, a, b = list(map(int, input().split()))
res = 0
for num in range(1, n+1):
n_list = list(map(int, list(str(num))))
total = sum(n_list)
print(n_list)
if a <= total and total <= b:
res += num
print(res)
| s842136212 | Accepted | 37 | 3,060 | 208 | n, a, b = list(map(int, input().split()))
res = 0
for num in range(1, n+1):
n_list = list(map(int, list(str(num))))
total = sum(n_list)
if a <= total and total <= b:
res += num
print(res)
|
s472007909 | p03696 | u518042385 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 324 | You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one. | n=int(input())
w=input()
l=0
r=0
m=0
for i in range(n):
if w[i]=="(":
l+=1
else:
r+=1
m=max(m,r-l)
if m==0:
if l>r:
print(w+")"*(l-r))
else:
print("("*(r-l)+w)
else:
if l>r:
print("("*m+w+")"*(m+l-r))
else:
if l+m>r:
print("("*m+w+")"*(r-l-m))
else:
print("("*(r-l-m)+w) | s841035610 | Accepted | 17 | 3,064 | 363 | n=int(input())
w=input()
l=0
r=0
m=0
for i in range(n):
if w[i]=="(":
l+=1
else:
r+=1
m=max(m,r-l)
if m==0:
if l>r:
print(w+")"*(l-r))
else:
print("("*(r-l)+w)
else:
if l>r:
print("("*m+w+")"*(m+l-r))
else:
if l+m>r:
print("("*m+w+")"*(-r+l+m))
elif l+m==r:
print("("*m+w)
else:
print("("*(r-l-m)+w) |
s374062022 | p03814 | u281303342 | 2,000 | 262,144 | Wrong Answer | 18 | 3,516 | 60 | 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()
print(len(S) -S[::-1].find("Z") -S.find("A") +2) | s682689481 | Accepted | 18 | 3,516 | 407 | # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
ai = S.find("A")
zi = S.rfind("Z")
print(zi-ai+1) |
s525345597 | p03149 | u923270446 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 118 | 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 = input()
for i in range(7):
if s[:i] + s[-7 + i:] == "keyence":
print("YES")
exit()
print("NO") | s247083044 | Accepted | 17 | 2,940 | 101 | n = list(map(int, input().split()))
if set(n) == {1, 9, 7, 4}:
print("YES")
else:
print("NO") |
s441877069 | p03377 | u189806337 | 2,000 | 262,144 | Wrong Answer | 26 | 9,100 | 80 | 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 b >= x - a:
print('Yes')
else:
print('No') | s562887094 | Accepted | 28 | 9,032 | 85 | a,b,x = map(int,input().split())
if b >= x - a >= 0:
print('YES')
else:
print('NO') |
s078057557 | p02795 | u917872021 | 2,000 | 1,048,576 | Wrong Answer | 19 | 3,060 | 90 | We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations. | h = int(input())
w = int(input())
n = int(input())
k = max(h, w)
print((n - k + 1) // k) | s982791671 | Accepted | 17 | 2,940 | 90 | h = int(input())
w = int(input())
n = int(input())
k = max(h, w)
print((n + k - 1) // k)
|
s470338086 | p02850 | u619144316 | 2,000 | 1,048,576 | Wrong Answer | 2,107 | 60,968 | 680 | Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors. | from collections import defaultdict,deque
N = int(input())
graph = defaultdict(list)
colored = dict()
for _ in range(N-1):
a, b = map(int,input().split())
graph[a].append(b)
graph[b].append(a)
colored[(a,b)] = None
MAX = 0
for v in graph.values():
MAX = max(MAX, len(v))
color_list = list(range(1,MAX+1))
color_node = dict()
for i in range(1,N+1):
color_node[i] = []
for (a,b) in colored.keys():
for c in color_list:
if not c in color_node[a] and not c in color_node[b]:
colored[(a,b)] = c
color_node[a].append(c)
color_node[b].append(c)
break
for v in colored.values():
print(v) | s146586349 | Accepted | 261 | 34,212 | 419 | from collections import defaultdict,deque
graph = defaultdict(list)
N, *AB = map(int, open(0).read().split())
for a, b in zip(*[iter(AB)] * 2):
graph[a].append(b)
stack = deque([1])
C = [0] * (N + 1)
while stack:
v = stack.popleft()
c = 0
for w in graph[v]:
c += 1 + (c + 1 == C[v])
C[w] = c
stack.append(w)
print(max(C))
print("\n".join(str(C[b]) for b in AB[1::2])) |
s061967874 | p03228 | u377989038 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 170 | In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total. | a, b, k = map(int, input().split())
for i in range(k):
if i % 2:
a += b // 2
b -= b // 2
else:
b += a // 2
a -= a // 2
print(a, b) | s061780403 | Accepted | 17 | 2,940 | 162 | a, b, k = map(int, input().split())
for i in range(k):
if i % 2:
a += b // 2
b //= 2
else:
b += a // 2
a //= 2
print(a, b) |
s263414921 | p03815 | u871239364 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 56 | 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. | import math
x = int(input())
print(math.ceil(x-x%11/11)) | s721667785 | Accepted | 17 | 2,940 | 85 | import math
x = int(input())
print(2*math.ceil(x/11.0)+(-1 if 1 <= x%11 <= 6 else 0)) |
s308648708 | p02233 | u072053884 | 1,000 | 131,072 | Wrong Answer | 20 | 7,376 | 105 | Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula: \begin{equation*} fib(n)= \left \\{ \begin{array}{ll} 1 & (n = 0) \\\ 1 & (n = 1) \\\ fib(n - 1) + fib(n - 2) & \\\ \end{array} \right. \end{equation*} | def fib2(n):
a1, a2 = 1, 0
while n > 0:
a1, a2 = a1 + a2, a1
n -= 1
return a1 | s923491183 | Accepted | 30 | 7,764 | 343 | def deco_fibo(func):
answer_list = [1, 1] + [None] * 43
def main_fibo(i):
ans = answer_list[i]
if ans:
return ans
ans = func(i)
answer_list[i] = ans
return ans
return main_fibo
@deco_fibo
def fibo(num):
return fibo(num - 1) + fibo(num - 2)
n = int(input())
print(fibo(n)) |
s335745238 | p02678 | u024782094 | 2,000 | 1,048,576 | Wrong Answer | 668 | 41,088 | 662 | There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. | import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n,m=mp()
step=[-1]*(n+1)
ans=[-1]*(n+1)
edge=[[i] for i in range(n+1)]
for i in range(m):
a,b=mp()
edge[a].append(b)
edge[b].append(a)
que=deque()
que.append(edge[1])
step[1]=0
while len(que):
q=que.popleft()
for i in range(1,len(q)):
if step[q[i]]==-1:
step[q[i]]=0
ans[q[i]]=q[0]
que.append(edge[q[i]])
print("Yes")
print(ans)
for i in range(2,n+1):
print(ans[i]) | s087905708 | Accepted | 639 | 40,032 | 651 | import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n,m=mp()
step=[-1]*(n+1)
ans=[-1]*(n+1)
edge=[[i] for i in range(n+1)]
for i in range(m):
a,b=mp()
edge[a].append(b)
edge[b].append(a)
que=deque()
que.append(edge[1])
step[1]=0
while len(que):
q=que.popleft()
for i in range(1,len(q)):
if step[q[i]]==-1:
step[q[i]]=0
ans[q[i]]=q[0]
que.append(edge[q[i]])
print("Yes")
for i in range(2,n+1):
print(ans[i]) |
s324282382 | p03549 | u297109012 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 181 | Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer). | def solve(N, M):
p = 1 / pow(0.5, M)
return ((N - M) * 100 + M * 1900) * p
if __name__ == "__main__":
N, M = tuple(map(int, input().split(" ")))
print(solve(N, M))
| s595623007 | Accepted | 18 | 2,940 | 186 | def solve(N, M):
p = 1 / pow(0.5, M)
return int(((N - M) * 100 + M * 1900) * p)
if __name__ == "__main__":
N, M = tuple(map(int, input().split(" ")))
print(solve(N, M))
|
s700473930 | p03351 | u776871252 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 140 | Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate. | a, b, c, d = map(int, input().split())
if a + c < d:
print("Yes")
elif a + b < d and b + c < d:
print("Yes")
else:
print("No")
| s334860462 | Accepted | 17 | 2,940 | 158 | a, b, c, d = map(int, input().split())
if abs(a - c) <= d:
print("Yes")
elif abs(a - b) <= d and abs(b - c) <= d:
print("Yes")
else:
print("No")
|
s012321062 | p03251 | u155828990 | 2,000 | 1,048,576 | Wrong Answer | 18 | 3,064 | 276 | Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out. | N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort()
y.sort()
ans=False
for i in range(X+1,Y+1):
print(i)
if(x[-1]<i and y[0]>=i):
ans=True
break
if(ans):
print('No War')
else:
print('War') | s895399600 | Accepted | 18 | 3,064 | 263 | N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort()
y.sort()
ans=False
for i in range(X+1,Y+1):
if(x[-1]<i and y[0]>=i):
ans=True
break
if(ans):
print('No War')
else:
print('War') |
s886643671 | p03110 | u951480280 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 144 | Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total? | n = int(input())
ans = 0
for i in range(n):
ans += eval(input().replace(" ","*").replace("JPY","1").replace("BTC","380000"))
print(int(ans)) | s909021016 | Accepted | 17 | 2,940 | 139 | n = int(input())
ans = 0
for i in range(n):
ans += eval(input().replace(" ","*").replace("JPY","1").replace("BTC","380000"))
print(ans) |
s550845468 | p03370 | u582817680 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 248 | Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition. | import math
N, X = map(int, input().split())
kinds = []
num = 0
for i in range(N):
kinds.append(int(input()))
num = num + kinds[i]
tmp_kinds = sorted(kinds)
little = tmp_kinds[0]
print(little)
ans = math.floor((X-num)/little+N)
print(ans) | s244805985 | Accepted | 20 | 3,060 | 211 | N, X = map(int, input().split())
kinds = []
num = 0
for i in range(N):
kinds.append(int(input()))
num = num + kinds[i]
tmp_kinds = sorted(kinds)
little = tmp_kinds[0]
ans = (X-num)//little+N
print(ans) |
s572199397 | p03436 | u815763296 | 2,000 | 262,144 | Time Limit Exceeded | 2,208 | 89,324 | 1,009 | 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 `#`. | import sys
from collections import deque
def LI():
return list(map(int, input().split()))
def LSH(h):
return [list(input()) for _ in range(h)]
H, W = LI()
A = LSH(H)
MAP = [[0 for i in range(W)]for j in range(H)]
white = 0
for i in range(H):
S = A[i]
for j in range(W):
if S[j] == "#":
MAP[i][j] = "#"
else:
MAP[i][j] = "."
white += 1
d = deque()
d.append([0, 0])
looked = [[0 for i in range(W)]for j in range(H)]
looked[0][0] = 1
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
count = -1
while d:
h, w = d.popleft()
for i in move:
a = h+i[0]
b = w+i[0]
if not(0 <= a < H) or not(0 <= b < W) or looked[a][b] == 0 or MAP[a][b] == "#":
continue
if a == H-1 and b == W-1:
count = looked[h][w]+1
break
d.append([a, b])
looked[a][b] = looked[h][w]+1
if count != -1:
break
if count == -1:
print(count)
sys.exit()
print(white-count)
| s641237298 | Accepted | 35 | 9,508 | 795 | import sys
from collections import deque
def LI():
return list(map(int, input().split()))
def LSH(h):
return [list(input()) for _ in range(h)]
H, W = LI()
MAP = LSH(H)
d = deque()
d.append([0, 0])
looked = [[0 for i in range(W)]for j in range(H)]
looked[0][0] = 1
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
while d:
x = d.popleft()
h = x[0]
w = x[1]
for i in move:
a = h+i[0]
b = w+i[1]
if not(0 <= a < H) or not(0 <= b < W) or looked[a][b] != 0 or MAP[a][b] == "#":
continue
d.append([a, b])
looked[a][b] = looked[h][w]+1
if looked[H-1][W-1] == 0:
print(-1)
sys.exit()
white = 0
for i in range(H):
for j in range(W):
if MAP[i][j] == ".":
white += 1
print(white-looked[H-1][W-1])
|
s131041497 | p03555 | u871596687 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 141 | 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. | c1 = list(input())
c2 = list(input())
if c1[0] == c2[2] and c1[1] == c2[1] and c1[2] == c2[0]:
print("Yes")
else:
print("No")
| s963542541 | Accepted | 17 | 2,940 | 149 | c1 = list(input())
c2 = list(input())
if (c1[0] == c2[2]) and (c1[1] == c2[1]) and (c1[2] == c2[0]):
print("YES")
else:
print("NO")
|
s868623575 | p02417 | u566311709 | 1,000 | 131,072 | Wrong Answer | 30 | 5,560 | 105 | Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters. | s = input()
l = [chr(i) for i in range(97, 97+26)]
for a in l:
print("{0}: {1}".format(a, s.count(a)))
| s991728982 | Accepted | 20 | 5,556 | 96 | import sys
s=sys.stdin.read().lower()
for i in range(97,123):print(chr(i),':',s.count(chr(i)))
|
s489718017 | p03049 | u266014018 | 2,000 | 1,048,576 | Wrong Answer | 36 | 9,260 | 625 | Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string. | def main():
import sys
def input(): return sys.stdin.readline().rstrip()
n = int(input())
s_table = [0]*3
ans = 0
for i in range(n):
s = input()
ans += s.count('AB')
if s[0]=='B' and s[-1] == 'A':
s_table[0] += 1
elif s[0] == 'B' and s[-1] != 'A':
s_table[1] += 1
elif s[0] != 'B' and s[-1] == 'A':
s_table[2] += 1
m = min(s_table[1:])
s_table[0] += m
s_table[1] -= m
s_table[2] -= m
ans += s_table[0]-1 + min(1, sum(s_table[1:]))
print(ans)
if __name__ == '__main__':
main() | s357821308 | Accepted | 37 | 9,220 | 658 | def main():
import sys
def input(): return sys.stdin.readline().rstrip()
n = int(input())
s_table = [0]*3
ans = 0
for i in range(n):
s = input()
ans += s.count('AB')
if s[0] == 'B' and s[-1] == 'A':
s_table[0] += 1
elif s[0] == 'B' and s[-1] != 'A':
s_table[1] += 1
elif s[0] != 'B' and s[-1] == 'A':
s_table[2] += 1
if s_table[0] == 0:
ans += min(s_table[1:])
elif sum(s_table[1:]) > 0:
ans += s_table[0]+min(s_table[1:])
else:
ans += s_table[0]-1
print(ans)
if __name__ == '__main__':
main() |
s070203473 | p03997 | u728611988 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 77 | You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid. | a = int(input())
b = int(input())
h = int(input())
ans = (a+b)*h/2
print(ans) | s434694192 | Accepted | 17 | 2,940 | 82 | a = int(input())
b = int(input())
h = int(input())
ans = (a+b)*h/2
print(int(ans)) |
s321571697 | p03574 | u284854859 | 2,000 | 262,144 | Wrong Answer | 29 | 3,192 | 1,518 | You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process. | h,w = map(int,input().split())
s = []
for i in range(h):
a =list(input())
s.append(a)
print(s)
for i in range(h):
for j in range(w):
if s[i][j] == '.':
c = 0
if i-1 >= 0 and i-1 <= h-1 and j-1 >= 0 and j-1 <= w-1:
if s[i-1][j-1] == '#':
c += 1
if i >= 0 and i <= h-1 and j-1 >= 0 and j-1 <= w-1:
if s[i][j-1] == '#':
c += 1
if i+11 >= 0 and i+1 <= h-1 and j-1 >= 0 and j-1 <= w-1:
if s[i+1][j-1] == '#':
c += 1
if i-1 >= 0 and i-1 <= h-1 and j >= 0 and j <= w-1:
if s[i-1][j] == '#' :
c += 1
if i >= 0 and i <= h-1 and j >= 0 and j <= w-1:
if s[i][j] == '#':
c += 1
if i+1 >= 0 and i+1 <= h-1 and j >= 0 and j <= w-1:
if s[i+1][j] == '#':
c += 1
if i-1 >= 0 and i-1 <= h-1 and j+1 >= 0 and j+1 <= w-1:
if s[i-1][j+1] == '#' :
c += 1
if i >= 0 and i <= h-1 and j+1 >= 0 and j+1 <= w-1:
if s[i][j+1] == '#':
c += 1
if i+1 >= 0 and i+1 <= h-1 and j+1 >= 0 and j+1 <= w-1:
if s[i+1][j+1] == '#':
c += 1
s[i][j] = str(c)
for i in range(h):
k = ''
for j in range(w):
k += s[i][j]
print(k) | s721029838 | Accepted | 28 | 3,192 | 1,519 | h,w = map(int,input().split())
s = []
for i in range(h):
a =list(input())
s.append(a)
#print(s)
for i in range(h):
for j in range(w):
if s[i][j] == '.':
c = 0
if i-1 >= 0 and i-1 <= h-1 and j-1 >= 0 and j-1 <= w-1:
if s[i-1][j-1] == '#':
c += 1
if i >= 0 and i <= h-1 and j-1 >= 0 and j-1 <= w-1:
if s[i][j-1] == '#':
c += 1
if i+11 >= 0 and i+1 <= h-1 and j-1 >= 0 and j-1 <= w-1:
if s[i+1][j-1] == '#':
c += 1
if i-1 >= 0 and i-1 <= h-1 and j >= 0 and j <= w-1:
if s[i-1][j] == '#' :
c += 1
if i >= 0 and i <= h-1 and j >= 0 and j <= w-1:
if s[i][j] == '#':
c += 1
if i+1 >= 0 and i+1 <= h-1 and j >= 0 and j <= w-1:
if s[i+1][j] == '#':
c += 1
if i-1 >= 0 and i-1 <= h-1 and j+1 >= 0 and j+1 <= w-1:
if s[i-1][j+1] == '#' :
c += 1
if i >= 0 and i <= h-1 and j+1 >= 0 and j+1 <= w-1:
if s[i][j+1] == '#':
c += 1
if i+1 >= 0 and i+1 <= h-1 and j+1 >= 0 and j+1 <= w-1:
if s[i+1][j+1] == '#':
c += 1
s[i][j] = str(c)
for i in range(h):
k = ''
for j in range(w):
k += s[i][j]
print(k) |
s280811834 | p03635 | u417014669 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 58 | 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? | word=str(input())
print(word[0]+str(len(word)-2)+word[-1]) | s450495910 | Accepted | 17 | 2,940 | 47 | a,b=map(int,input().split())
print((a-1)*(b-1)) |
s195318271 | p02927 | u607754357 | 2,000 | 1,048,576 | Wrong Answer | 20 | 3,060 | 290 | Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have? | S = input().split()
M = int(S[0])
D = int(S[1])
count = 0
for m in range(1, M + 1):
for d in range(1, D + 1):
d1 = d % 10
d10 = d // 10
if d1 >= 2 and d10 >= 2:
if d1 * d10 == m:
count += 1
print(m, d)
print(count) | s385170201 | Accepted | 20 | 3,060 | 262 | S = input().split()
M = int(S[0])
D = int(S[1])
count = 0
for m in range(1, M + 1):
for d in range(1, D + 1):
d1 = d % 10
d10 = d // 10
if d1 >= 2 and d10 >= 2:
if d1 * d10 == m:
count += 1
print(count) |
s119328906 | p03699 | u240789102 | 2,000 | 262,144 | Wrong Answer | 2,202 | 1,416,564 | 312 | You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade? | import itertools
DIM = int(input())
args = [int(input()) for a in range(DIM)]
while(DIM>0):
comb = list(itertools.combinations(args, DIM))
combMax = list(map(sum, comb))
for c in combMax:
if c%10==0:
continue
else:
print(c)
exit()
DIM = DIM -1 | s287674698 | Accepted | 18 | 3,064 | 431 | import itertools
DIM = int(input())
args = [int(input()) for a in range(DIM)]
temp = list(map(lambda x:x%10, args))
if sum(temp) == 0:
print(0)
exit()
i = DIM
while(i>0):
comb = list(itertools.combinations(args, i))
combMax = list(map(sum, comb))
for c in sorted(combMax, reverse=True):
if c%10==0:
continue
else:
print(c)
exit()
i = i -1
print(0)
exit() |
s158862943 | p03387 | u867826040 | 2,000 | 262,144 | Wrong Answer | 30 | 9,108 | 459 | You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations. | def f(abc,c):
print(abc)
m = max(abc)
a = 0
for i in abc:
a += (i < m)
if a == 0:
return c
c += 1
if a <= 1:
for i,x in enumerate(abc):
if x < m:
abc[i] += 2
break
return f(abc,c)
else:
for i,x in enumerate(abc):
if x < m:
abc[i] += 1
return f(abc,c)
abc = list(map(int, input().split()))
print(f(abc,0))
| s832034793 | Accepted | 27 | 9,116 | 444 | def f(abc,c):
m = max(abc)
a = 0
for i in abc:
a += (i < m)
if a == 0:
return c
c += 1
if a <= 1:
for i,x in enumerate(abc):
if x < m:
abc[i] += 2
break
return f(abc,c)
else:
for i,x in enumerate(abc):
if x < m:
abc[i] += 1
return f(abc,c)
abc = list(map(int, input().split()))
print(f(abc,0))
|
s036037918 | p03565 | u075012704 | 2,000 | 262,144 | Wrong Answer | 20 | 3,188 | 537 | E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`. | S = input()
T = input()
def check(S, T):
for i in range(len(S)):
if (T[i] == S[i]) or (S[i] == "?"):
pass
else:
return False
else:
return True
hint_len = len(T)
for i in range(len(S)-(hint_len+1) , -1 , -1):
if check(S[i+1:i+hint_len+1], T):
S = list(S)
S[i:i+hint_len+1] = list(T)
for i in range(len(S)):
if S[i] == "?":
S[i] = "a"
print("".join(S))
break
else:
print("UNRESTORABLE")
| s015531459 | Accepted | 17 | 3,064 | 454 | from itertools import zip_longest
S = input()
T = input()
NT = len(T)
candidate = []
for i in range(len(S)):
for target, t in zip_longest(S[i:i+NT], T):
if target != "?" and target != t:
break
else:
candidate.append(S[:i] + T + S[i+NT:])
ans_candidate = []
for c in candidate:
c = c.replace("?", "a")
ans_candidate.append(c)
ans_candidate.sort()
print(ans_candidate[0] if ans_candidate else "UNRESTORABLE")
|
s597771788 | p03361 | u636311816 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 701 | 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())
d=[]
d.append("."*(w+2))
for i in range(h):
r = input()
d.append("."+r+".")
d.append("."*(w+2))
#print(d)
no=True
def isok(d,i,j):
c = 0
c = c+1 if d[i-1][j]=="#" else c
c = c+1 if d[i][j-1]=="#" else c
c = c+1 if d[i][j+1]=="#" else c
c = c+1 if d[i+1][j]=="#" else c
result= True if c > 0 else False
return result
for i in range(h):
if no == True:
break
for j in range(w):
if no == True:
break
if d[i][j] == "#":
a = isok(d,i,j)
if a == False:
no = True
break
result = "no" if no==True else "yes"
print(result) | s642665413 | Accepted | 19 | 3,064 | 717 | h,w = map(int,input().split())
d=[]
d.append("."*(w+2))
for i in range(h):
r = input()
d.append("."+r+".")
d.append("."*(w+2))
#print(d)
no = False
def isok(d,i,j):
c = 0
c = c+1 if d[i-1][j]=="#" else c
c = c+1 if d[i][j-1]=="#" else c
c = c+1 if d[i][j+1]=="#" else c
c = c+1 if d[i+1][j]=="#" else c
result= True if c > 0 else False
return result
for i in range(1,h+2):
if no == True:
break
for j in range(1,w+2):
if no == True:
break
if d[i][j] == "#":
a = isok(d,i,j)
if a == False:
no = True
break
result = "No" if no==True else "Yes"
print(result) |
s832041129 | p03545 | u244434589 | 2,000 | 262,144 | Wrong Answer | 28 | 9,204 | 668 | 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. | a,b,c,d=map(int,input())
print('%d+%d+%d+%d=7' %(a,b,c,d))
p = (a+b)%7
q = (c+d)%7
r = (a-b)%7
s = (c-d)%7
if p == q:
print('%d+%d-%d+%d=7' %(a,b,c,d))
exit()
elif p == s:
print('%d+%d-%d-%d=7' %(a,b,c,d))
exit()
elif r == q:
print('%d-%d-%d+%d=7' %(a,b,c,d))
exit()
elif r == s:
print('%d-%d-%d-%d=7' %(a,b,c,d))
exit()
elif p+q ==7:
print('%d+%d+%d+%d=7' %(a,b,c,d))
exit()
elif p+s ==7:
print('%d+%d+%d-%d=7' %(a,b,c,d))
exit()
elif r+q ==7:
print('%d-%d+%d+%d=7' %(a,b,c,d))
exit()
elif r+s ==7:
print('%d-%d+%d-%d=7' %(a,b,c,d))
exit() | s067037162 | Accepted | 25 | 9,272 | 626 | a,b,c,d=map(int,input())
if a+b-c+d == 7:
print('%d+%d-%d+%d=7' %(a,b,c,d))
exit()
elif a+b-c-d == 7:
print('%d+%d-%d-%d=7' %(a,b,c,d))
exit()
elif a-b-c+d == 7:
print('%d-%d-%d+%d=7' %(a,b,c,d))
exit()
elif a-b-c-d == 7:
print('%d-%d-%d-%d=7' %(a,b,c,d))
exit()
elif a+b+c+d ==7:
print('%d+%d+%d+%d=7' %(a,b,c,d))
exit()
elif a+b+c-d ==7:
print('%d+%d+%d-%d=7' %(a,b,c,d))
exit()
elif a-b+c+d ==7:
print('%d-%d+%d+%d=7' %(a,b,c,d))
exit()
elif a-b+c-d ==7:
print('%d-%d+%d-%d=7' %(a,b,c,d))
exit() |
s708022596 | p04029 | u200245833 | 2,000 | 262,144 | Wrong Answer | 26 | 8,912 | 128 | 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? | s = list(input())
out = []
for s1 in s:
if s1 == 'B':
if out != []:
out.pop()
else:
out.append(s1)
print(''.join(out)) | s188155574 | Accepted | 26 | 9,040 | 56 | n=int(input())
i=0
while n > 0:
i+=n
n-=1
print(i) |
s094765371 | p04044 | u996564551 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 128 | Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m. | N, L = input().split(' ')
N = int(N)
L = int(L)
a = []
for i in range(N):
a.append(input().rstrip())
a.sort()
b = ''.join(a) | s322868698 | Accepted | 18 | 3,060 | 137 | N, L = input().split(' ')
N = int(N)
L = int(L)
a = []
for i in range(N):
a.append(input().rstrip())
a.sort()
b = ''.join(a)
print(b) |
s298044148 | p03502 | u330314953 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 127 | An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. | n = input()
m = 0
for i in range(len(n)):
m = int(n[i]) + m
if int(n) % int(m) == 0:
print("YES")
else:
print("NO") | s588178331 | Accepted | 17 | 2,940 | 127 | n = input()
m = 0
for i in range(len(n)):
m = int(n[i]) + m
if int(n) % int(m) == 0:
print("Yes")
else:
print("No") |
s441459388 | p00445 | u811773570 | 1,000 | 131,072 | Wrong Answer | 40 | 7,440 | 192 | 与えられた文字列内の連続する3文字が,JOIまたはIOIという並びになっている個所がそれぞれ何個所あるのかを数え上げるプログラムを作成せよ.文字列はアルファベットの大文字だけからなる.例えば下図の「JOIOIOI」という文字列にはJOIが1個所,IOIが2個所に含まれている. | s = input()
joi = 0
ioi = 0
for i in range(len(s) - 2):
x = s[i] + s[i + 1] + s[i + 2]
if (x == "JOI"):
joi += 1
elif (x == "IOI"):
ioi += 1
print(joi)
print(ioi) | s345359191 | Accepted | 50 | 7,496 | 279 | while True:
try:
s = input()
except:
break
joi = 0
ioi = 0
for i in range(len(s) - 2):
x = s[i] + s[i + 1] + s[i + 2]
if x == "JOI":
joi += 1
if x == "IOI":
ioi += 1
print(joi)
print(ioi) |
s584022874 | p03599 | u600608564 | 3,000 | 262,144 | Wrong Answer | 381 | 21,108 | 706 | Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water. |
A, B, C, D, E, F = map(int, input().split())
w_list = []
s_list = []
d_list = []
for a in range(31):
for b in range(31):
for c in range(101):
for d in range(101):
w = (100 * A) * a + (100 * B) * b
s = C * c + D * d
if w == 0:
break
if w + s > F:
break
else:
if s <= w/100 * E:
d = 100 * s / (w + s)
w_list.append(w)
s_list.append(s)
d_list.append(d)
print(w_list[d_list.index(max(d_list))], s_list[d_list.index(max(d_list))]) | s469805938 | Accepted | 353 | 21,172 | 679 | A, B, C, D, E, F = map(int, input().split())
w_list = []
s_list = []
d_list = []
for a in range(31):
for b in range(31):
for c in range(101):
for d in range(101):
w = (100 * A) * a + (100 * B) * b
s = C * c + D * d
if w == 0 or w + s > F:
break
else:
if w // 100 * E >= s:
d = s / (w + s)
w_list.append(w)
s_list.append(s)
d_list.append(d)
print(w_list[d_list.index(max(d_list))] + s_list[d_list.index(max(d_list))], s_list[d_list.index(max(d_list))])
|
s706684352 | p03644 | u396391104 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 64 | Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times. | n = int(input())
ans = 1
while ans < n:
ans *= 2
print(ans)
| s180010997 | Accepted | 18 | 2,940 | 65 | n = int(input())
ans = 1
while ans <= n:
ans *= 2
print(ans//2) |
s103010039 | p03469 | u853586331 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 40 | On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. | S=input()
T=S.replace(S[3],'8')
print(T) | s607474425 | Accepted | 17 | 2,940 | 45 | S=input()
S=S.replace('2017','2018')
print(S) |
s220332937 | p04011 | u428397309 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 151 | There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee. | # -*- coding: utf-8 -*-
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
ans = min(K, N) * X + min(abs(N - K), 0) * Y
print(ans)
| s377599241 | Accepted | 17 | 2,940 | 168 | # -*- coding: utf-8 -*-
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N < K:
ans = N * X
else:
ans = K * X + (N - K) * Y
print(ans)
|
s579348858 | p03997 | u506287026 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 75 | You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid. | a = int(input())
b = int(input())
h = int(input())
print((a + b) * h / 2)
| s779583152 | Accepted | 16 | 2,940 | 80 | a = int(input())
b = int(input())
h = int(input())
print(int((a + b) * h / 2))
|
s062788601 | p03457 | u287132915 | 2,000 | 262,144 | Wrong Answer | 414 | 11,636 | 377 | AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan. | N = int(input())
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
for i in range(1, N+1):
t[i], x[i], y[i] = map(int,input().split())
for i in range(1, N+1):
if t[i]-t[i-1] < abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]):
print('NO')
exit()
elif (t[i]-t[i-1]) % 2 != (abs(x[i]-x[i-1]) + abs(y[i]-y[i-1])) % 2:
print('NO')
exit()
print('YES') | s324150520 | Accepted | 379 | 11,636 | 344 | N = int(input())
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
for i in range(1, N+1):
t[i], x[i], y[i] = map(int,input().split())
for i in range(1, N+1):
if t[i]-t[i-1] < abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]):
print('No')
exit()
elif t[i] % 2 != (x[i] + y[i]) % 2:
print('No')
exit()
print('Yes') |
s267896128 | p03712 | u985125584 | 2,000 | 262,144 | Wrong Answer | 36 | 4,596 | 397 | You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1. | H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
b = [[]*(W+2) for _ in range(H+2)]
b[0] = list('#'*(W+2))
b[H+1] = list('#'*(W+2))
for i in range(1,H+1):
print(i)
b[i] = list('#')
for j in range(len(a[i-1])):
b[i].append(a[i-1][j])
b[i].append('#')
for i in range(H+2):
for j in range(W+2):
print(''.join(b[i][j]), end='')
print() | s907863779 | Accepted | 18 | 3,060 | 169 |
H, W = map(int, input().split())
a = ['']*H
for i in range(H):
a[i] = input()
print('#'*(W+2))
for i in range(H):
print('#{}#'.format(a[i]))
print('#'*(W+2)) |
s286860292 | p03139 | u902151549 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 43 | We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question. | N,A,B=map(int,input().split())
print(A+B-N) | s709346225 | Accepted | 108 | 9,932 | 2,645 | # coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find():
def __init__(self,n):
self.n=n
self.P=[a for a in range(N)]
self.rank=[0]*n
def find(self,x):
if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
return self.P[x]
def same(self,x,y):
return self.find(x)==self.find(y)
def link(self,x,y):
if self.rank[x]<self.rank[y]:
self.P[x]=y
elif self.rank[y]<self.rank[x]:
self.P[y]=x
else:
self.P[x]=y
self.rank[y]+=1
def unite(self,x,y):
self.link(self.find(x),self.find(y))
def size(self):
S=set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def bin_(num,size):
A=[0]*size
for a in range(size):
if (num>>(size-a-1))&1==1:
A[a]=1
else:
A[a]=0
return A
def fac_list(n,mod_=0):
A=[1]*(n+1)
for a in range(2,len(A)):
A[a]=A[a-1]*a
if(mod>0):A[a]%=mod_
return A
def comb(n,r,mod,fac):
if(n-r<0):return 0
return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
x=num&(-num)
y=num+x
z=num&(~y)
z//=x
z=z>>1
num=(y|z)
if(num>=(1<<size)):return False
else:
return num
def get_primes(n,type="int"):
A=[True]*(n+1)
A[0]=False
A[1]=False
for a in range(2,n+1):
if A[a]:
for b in range(a*2,n+1,a):
A[b]=False
if(type=="bool"):return A
B=[]
for a in range(n+1):
if(A[a]):B.append(a)
return B
def is_prime(num):
if(num<=2):return False
i=2
while i*i<=num:
if(num%i==0):return False
i+=1
return True
def join(A,c=" "):
n=len(A)
A=list(map(str,A))
s=""
for a in range(n):
s+=A[a]
if(a<n-1):s+=c
return s
#######################################################################################################
N,A,B=map(int,input().split())
r=0
if A+B<N:
r=0
else:
r=A+B-N
print(min(A,B),r)
|
s141143504 | p03160 | u655761160 | 2,000 | 1,048,576 | Wrong Answer | 143 | 13,980 | 404 | 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. | def ch_min(a, b):
if (a > b):
a = b
return a
if __name__ == "__main__":
N = int(input())
h = list(map(int, input().split()))
INF = 10 ** 10
dp = [INF] * 100010
dp[0] = 0
for i in range(N):
dp[i + 1] = ch_min(dp[i], dp[i] + abs(h[i] - h[i - 1]))
if (i > 1):
dp[i + 2] = ch_min(dp[i], dp[i] + abs(h[i] - h[i - 2]))
print(dp[N - 1])
| s583081697 | Accepted | 124 | 13,980 | 228 | N = int(input())
h = list(map(int, input().split()))
x = [0] * N
x[1] = x[0] + abs(h[1] - h[0])
for i in range(2, N):
x[i] = min(x[i - 1] + abs(h[i] - h[i - 1]),
x[i - 2] + abs(h[i] - h[i - 2]))
print(x[N-1])
|
s078414072 | p03351 | u596536048 | 2,000 | 1,048,576 | Wrong Answer | 26 | 9,132 | 417 | 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. | print('数直線上にいるA、B、Cの位置と会話が可能な距離を入力してください')
a, b, c, d = map(int, input().split())
ac_displacement = abs(c - a)
ab_displacement = abs(b - a)
bc_displacement = abs(c - b)
print('会話の可能性は')
if ac_displacement <= d and bc_displacement <= d:
print('Yes')
elif ab_displacement <= d and bc_displacement <= d:
print('Yes')
else:
print('No') | s267303777 | Accepted | 27 | 9,176 | 258 | a, b, c, d = map(int, input().split())
ac_displacement = abs(c - a)
ab_displacement = abs(b - a)
bc_displacement = abs(c - b)
if ac_displacement <= d:
print('Yes')
elif ab_displacement <= d and bc_displacement <= d:
print('Yes')
else:
print('No') |
s028257084 | p03478 | u546440137 | 2,000 | 262,144 | Wrong Answer | 40 | 9,064 | 127 | 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())
count=0
for i in range(n+1):
if a<=sum(map(int,str(i)))<=b:
count+=1
print(count) | s273823095 | Accepted | 37 | 9,156 | 128 | n,a,b=map(int,input().split())
count=0
for i in range(n+1):
if a<=sum(map(int,str(i)))<=b:
count+=i
print(count)
|
s957163349 | p03574 | u127499732 | 2,000 | 262,144 | Wrong Answer | 24 | 3,188 | 310 | You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process. | a,b=map(int,input().split())
l=[["."]*(b+2)]+[["."]+list(input())+["."] for _ in range(a)]+[["."]*(b+2)]
for i in range(1,a+1,1):
for j in range(1,b+1,1):
if l[i][j]!="#":
l[i][j]=str(sum(l[x][y]=="#" for x in [i-1,i,i+1] for y in [j-1,j,j+1]))
for i in range(1,a+1,1):
print("".join(l[i][1:-2])) | s873871507 | Accepted | 24 | 3,188 | 310 | a,b=map(int,input().split())
l=[["."]*(b+2)]+[["."]+list(input())+["."] for _ in range(a)]+[["."]*(b+2)]
for i in range(1,a+1,1):
for j in range(1,b+1,1):
if l[i][j]!="#":
l[i][j]=str(sum(l[x][y]=="#" for x in [i-1,i,i+1] for y in [j-1,j,j+1]))
for i in range(1,a+1,1):
print("".join(l[i][1:-1])) |
s553257173 | p03693 | u076996519 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 86 | AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4? | r,g,b = map(int, input().split())
if r+g+b % 4:
print("NO")
else:
print("YES") | s266397388 | Accepted | 17 | 2,940 | 95 | r,g,b = map(int, input().split())
if (r*100+g*10+b) % 4:
print("NO")
else:
print("YES") |
s722498690 | p03503 | u371385198 | 2,000 | 262,144 | Wrong Answer | 220 | 3,064 | 632 | Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period. | import sys
input = sys.stdin.readline
def readstr():
return input().strip()
def readint():
return int(input())
def readnums():
return map(int, input().split())
def readstrs():
return input().split()
def main():
N = readint()
F = [''.join(readstrs()) for _ in range(N)]
P = [list(readnums()) for _ in range(N)]
ans = -(10 ** 9)
for j, f in enumerate(F):
val = 0
for i in range(1, 1024):
c = bin(i & int(f, 2))[2:]
v = sum(map(int, c))
val += P[j][v]
ans = max(ans, val)
print(ans)
if __name__ == "__main__":
main()
| s699303128 | Accepted | 223 | 3,064 | 632 | import sys
input = sys.stdin.readline
def readstr():
return input().strip()
def readint():
return int(input())
def readnums():
return map(int, input().split())
def readstrs():
return input().split()
def main():
N = readint()
F = [''.join(readstrs()) for _ in range(N)]
P = [list(readnums()) for _ in range(N)]
ans = -(10 ** 9)
for i in range(1, 1024):
val = 0
for j, f in enumerate(F):
c = bin(i & int(f, 2))[2:]
v = sum(map(int, c))
val += P[j][v]
ans = max(ans, val)
print(ans)
if __name__ == "__main__":
main()
|
s002792504 | p02389 | u668507147 | 1,000 | 131,072 | Wrong Answer | 20 | 5,592 | 96 | Write a program which calculates the area and perimeter of a given rectangle. | dim = list(map(int, input().split(' ')))
w, h = dim[0], dim[1]
print(w * h)
print(2 * (w + h))
| s274203865 | Accepted | 20 | 5,588 | 108 | dim = list(map(int, input().split(' ')))
w, h = dim[0], dim[1]
print('{0} {1}'.format(w * h, 2 * (w + h)))
|
s787303395 | p03142 | u477320129 | 2,000 | 1,048,576 | Wrong Answer | 695 | 64,932 | 615 | There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of the vertices, except the root, has a directed edge coming from its parent. Note that the root may not be Vertex 1. Takahashi has added M new directed edges to this graph. Each of these M edges, u \rightarrow v, extends from some vertex u to its descendant v. You are given the directed graph with N vertices and N-1+M edges after Takahashi added edges. More specifically, you are given N-1+M pairs of integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the i-th edge extends from Vertex A_i to Vertex B_i. Restore the original rooted tree. | # from collections import namedtuple
# Node = namedtuple("Node", "in, out")
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N+M-1)]
ine = [[] * N for _ in range(N)]
oute = [[] * N for _ in range(N)]
for a, b in AB:
ine[b-1].append(a-1)
oute[a-1].append(b-1)
root = ine.index([])
v = [len(e) for e in ine]
print(v)
ans = [0] * N
q = [(root, n) for n in oute[root]]
while q:
nq = []
for p, n in q:
v[n] -= 1
if v[n] == 0:
ans[n] = p + 1
nq += [(n, nn) for nn in oute[n]]
q = nq
print("\n".join(map(str, ans)))
| s339392829 | Accepted | 706 | 64,484 | 616 | # from collections import namedtuple
# Node = namedtuple("Node", "in, out")
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N+M-1)]
ine = [[] * N for _ in range(N)]
oute = [[] * N for _ in range(N)]
for a, b in AB:
ine[b-1].append(a-1)
oute[a-1].append(b-1)
root = ine.index([])
v = [len(e) for e in ine]
#print(v)
ans = [0] * N
q = [(root, n) for n in oute[root]]
while q:
nq = []
for p, n in q:
v[n] -= 1
if v[n] == 0:
ans[n] = p + 1
nq += [(n, nn) for nn in oute[n]]
q = nq
print("\n".join(map(str, ans)))
|
s935481864 | p03369 | u900538037 | 2,000 | 262,144 | Wrong Answer | 19 | 3,188 | 96 | In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen. | s = input()
count = 0
for i in range(3):
'o' in s[i]
count += 1
print(700 + count * 100) | s871208904 | Accepted | 17 | 2,940 | 104 | s = input()
count = 0
for i in range(3):
if 'o' in s[i]:
count += 1
print(700 + count * 100) |
s480524269 | p02796 | u572193732 | 2,000 | 1,048,576 | Wrong Answer | 609 | 35,248 | 367 | In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep. | N = int(input())
XL = []
for i in range(N):
tmp = list(map(int, input().split()))
XL.append(tmp)
XL = sorted(XL, key=lambda x:x[0])
i = 0
now = 0
count = 0
while i <= len(XL)-2:
now_arm = XL[now][0] + XL[now][1]
if now_arm > XL[i+1][0] - XL[i+1][1]:
count += 1
else:
now = i
i += 1
print(XL)
print(len(XL) - count) | s954147727 | Accepted | 546 | 29,864 | 470 | N = int(input())
XL = []
for i in range(N):
tmp = list(map(int, input().split()))
XL.append(tmp)
XL = sorted(XL, key=lambda x:x[0])
i = 0
now = 0
count = 0
while i <= len(XL)-2:
now_arm = XL[now][0] + XL[now][1]
if now_arm > XL[i+1][0] - XL[i+1][1]:
count += 1
if XL[i+1][0] + XL[i+1][1] < now_arm:
now = i+1
else:
pass
else:
now = i+1
i += 1
#print(XL)
print(len(XL) - count)
|
s353824951 | p03555 | u685244071 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 99 | You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise. | a = input()
b = input()
b_reverse = a[::-1]
if a == b_reverse:
print('YES')
else:
print('NO') | s343436550 | Accepted | 17 | 2,940 | 100 | a = input()
b = input()
b_reverse = b[::-1]
if a == b_reverse:
print('YES')
else:
print('NO')
|
s623052992 | p03438 | u201928947 | 2,000 | 262,144 | Wrong Answer | 27 | 4,596 | 379 | You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j. | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
numa = 0
numb = 0
num = sum(b)-sum(a)
for i in range(n):
x = b[i] - a[i]
if x > 0:
numa += -(-x//2)
if x % 2 == 1:
numb += 1
else:
numb -= x
print(num,numa,numb)
if (num-numa)*2 == num-numb and num > numa:
print("Yes")
else:
print("No") | s586029499 | Accepted | 29 | 4,600 | 359 | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
numa = 0
numb = 0
num = sum(b)-sum(a)
for i in range(n):
x = b[i] - a[i]
if x > 0:
numa += -(-x//2)
if x % 2 == 1:
numb += 1
else:
numb -= x
if (num-numa)*2 == num-numb and num >= numa:
print("Yes")
else:
print("No") |
s798927970 | p02606 | u051496905 | 2,000 | 1,048,576 | Wrong Answer | 23 | 9,020 | 105 | How many multiples of d are there among the integers between L and R (inclusive)? | L, R ,d = map(int,input().split())
L = 0
for i in range(L,R):
if i % d == 0:
L += 1
print(L)
| s891928435 | Accepted | 24 | 9,128 | 122 | L, R ,d = map(int,input().split())
P = 0
for i in range(L,R+1):
# print(i)
if i % d == 0:
P += 1
print(P)
|
s207731676 | p03352 | u286754585 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,060 | 187 | 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. | List=[1]
for i in range(2,32):
j=1
while(i**j<=1000):
List.append(i**j)
j+=1
#print(List)
x=int(input())
for i in range(x,0,-1):
if (List.count(i)>0):
print(i)
break | s643409188 | Accepted | 17 | 2,940 | 187 | List=[1]
for i in range(2,32):
j=2
while(i**j<=1000):
List.append(i**j)
j+=1
#print(List)
x=int(input())
for i in range(x,0,-1):
if (List.count(i)>0):
print(i)
break |
s412593170 | p03152 | u566529875 | 2,000 | 1,048,576 | Wrong Answer | 2,104 | 4,112 | 613 | Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7. | n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
ans = 1
cnta = 0
cntb = 0
mod = 1000000007
for num in range(n*m,0,-1):
if num in a and num in b:
cnta += 1
cntb += 1
cnta%=mod
cntb%=mod
elif num in a and num not in b:
ans *= cntb
ans %= mod
cnta += 1
elif num not in a and num in b:
ans *= cnta
ans %= mod
cntb += 1
else:
ans *= (cnta*cntb - (n*m - num))%mod
ans %= mod
print(cnta,cntb,ans)
print(ans) | s901990069 | Accepted | 719 | 3,316 | 447 | n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
A=set(a);B=set(b)
ans = 1
cnta = 0
cntb = 0
mod = 10**9+7
for num in range(n*m,0,-1):
if num in A and num in B:
cnta += 1
cntb += 1
elif num in A:
ans *= cntb
cnta += 1
elif num in B:
ans *= cnta
cntb += 1
else:
ans *= (cnta*cntb - (n*m - num))%mod
ans %= mod
print(ans) |
s084691775 | p03610 | u693953100 | 2,000 | 262,144 | Wrong Answer | 17 | 3,188 | 24 | 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]) | s995984721 | Accepted | 17 | 3,188 | 24 | s=input()
print(s[::2])
|
s784035006 | p03478 | u063248081 | 2,000 | 262,144 | Wrong Answer | 37 | 3,060 | 146 | 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 += 1
print(ans) | s517289032 | Accepted | 37 | 3,060 | 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) |
s049018526 | p03478 | u371467115 | 2,000 | 262,144 | Wrong Answer | 139 | 2,940 | 135 | 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())
total=0
for i in range(n+1):
i=eval("+".join(str(i)))
if a<=int(i)<=b:
total=int(i)
print(total) | s896827589 | Accepted | 142 | 2,940 | 137 | n,a,b=map(int,input().split())
total=0
for i in range(n+1):
j=eval("+".join(str(i)))
if a<=int(j)<=b:
total+=int(i)
print(total)
|
s939820647 | p03814 | u883232818 | 2,000 | 262,144 | Wrong Answer | 40 | 3,816 | 246 | 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()
count = 0
top = 0
end = 0
while True:
if S[count] == 'A':
top = count
break
count += 1
count = -1
while True:
if S[count] == 'Z':
end = count
break
count -= 1
print(S[top:end + 1])
| s187500593 | Accepted | 46 | 3,516 | 296 | S = input()
count = 0
top = 0
end = 0
while True:
if S[count] == 'A':
top = count
break
count += 1
count = -1
while True:
if S[count] == 'Z':
end = count + 1
break
count -= 1
if end == 0:
print(len(S[top:]))
else:
print(len(S[top:end])) |
s935840347 | p03545 | u840570107 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 177 | 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. | a, b, c, d = list(input())
en = ["+", "-"]
for x in en:
for y in en:
for z in en:
s = a + x + b + y + c + z + d
if eval(s) == 7:
print(s)
break | s342282082 | Accepted | 32 | 9,108 | 187 | n = input()
lis = ["+", "-"]
for x in lis:
for y in lis:
for z in lis:
p = n[0] + x + n[1] + y + n[2] + z + n[3]
if eval(p) == 7:
print(p + "=7")
exit() |
s805220612 | p03457 | u801701525 | 2,000 | 262,144 | Wrong Answer | 457 | 21,108 | 552 | AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan. | N = int(input())
p = [[ 0 for i in range(3)] for j in range(N+1)]
for i in range(1,N+1):
p[i][0], p[i][1], p[i][2] = map(int,input().split())
cant = True
if p[1][0] % 2 == (p[1][1] + p[1][2]) % 2 and p[1][0] >= p[1][1] + p[1][2]:
cant = False
if cant:
print('NO')
exit()
if N > 1:
for i in range(1, N+1):
ts = p[i][0] - p[i-1][0]
ps = p[i][1] - p[i-1][1] + p[i][2] - p[i-1][2]
if ts%2 == ps%2 and ts >= ps:
cant = False
else:
print('NO')
exit()
print('YES') | s256585450 | Accepted | 478 | 21,108 | 558 | N = int(input())
p = [[ 0 for i in range(3)] for j in range(N+1)]
for i in range(1,N+1):
p[i][0], p[i][1], p[i][2] = map(int,input().split())
cant = True
if p[1][0] % 2 == (p[1][1] + p[1][2]) % 2 and p[1][0] >= p[1][1] + p[1][2]:
cant = False
if cant:
print('No')
exit()
if N > 1:
for i in range(1, N+1):
ts = p[i][0] - p[i-1][0]
ps = p[i][1] - p[i-1][1] + p[i][2] - p[i-1][2]
if ts%2 == ps%2 and ts*ts >= ps*ps:
cant = False
else:
print('No')
exit()
print('Yes') |
s904410133 | p03457 | u260040951 | 2,000 | 262,144 | Wrong Answer | 330 | 3,060 | 191 | AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan. | N = int(input())
b = 0
for i in range(N):
t, x, y = map(int, input().split())
if t < (x+y) or (t+x+y) % 2:
print("NO")
b = 1
break
if b == 0:
print("YES")
| s505022658 | Accepted | 328 | 2,940 | 191 | N = int(input())
b = 0
for i in range(N):
t, x, y = map(int, input().split())
if t < (x+y) or (t+x+y) % 2:
print("No")
b = 1
break
if b == 0:
print("Yes")
|
s910837617 | p03495 | u711539583 | 2,000 | 262,144 | Wrong Answer | 128 | 32,184 | 231 | Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them. | n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for ai in a:
if ai in d:
d[ai] += 1
else:
d[ai] = 1
l = [d[key] for key in d]
l.sort()
if len(l) < k:
print(0)
else:
print(n - sum(l[:k]))
| s606947301 | Accepted | 131 | 32,184 | 245 | n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for ai in a:
if ai in d:
d[ai] += 1
else:
d[ai] = 1
l = [d[key] for key in d]
l.sort(reverse = True)
if len(l) < k:
print(0)
else:
print(n - sum(l[:k]))
|
s227001146 | p03377 | u586149955 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 92 | 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 = [int(_) for _ in input().split()]
print('Yes' if x >= a and x <= (a+b) else 'No')
| s808663847 | Accepted | 17 | 2,940 | 92 | a, b, x = [int(_) for _ in input().split()]
print('YES' if x >= a and x <= (a+b) else 'NO')
|
s003173155 | p03698 | u532966492 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 46 | You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different. | s=list(input());"yneos"[len(s)>len(set(s))::2] | s020924388 | Accepted | 17 | 2,940 | 53 | s=list(input());print("yneos"[len(s)>len(set(s))::2]) |
s388726007 | p03696 | u934442292 | 2,000 | 262,144 | Wrong Answer | 34 | 9,160 | 494 | You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one. | import sys
input = sys.stdin.readline
def main():
N = int(input())
S = input().rstrip()
ans = ""
n_left = 0
for s in S:
if s == "(":
ans = "".join((ans, "("))
n_left += 1
else:
if n_left > 0:
n_left -= 1
ans = "".join((ans, ")"))
else:
ans = "".join((ans, "()"))
ans = "".join((ans, ")" * n_left))
print(ans)
if __name__ == "__main__":
main()
| s541147317 | Accepted | 30 | 9,052 | 373 | import sys
input = sys.stdin.readline
def main():
N = int(input())
S = input().rstrip()
L = 0
R = 0
for s in S:
if s == "(":
R += 1
else:
if R > 0:
R -= 1
else:
L += 1
ans = "".join(["(" * L, S, ")" * R])
print(ans)
if __name__ == "__main__":
main()
|
s667157405 | p03407 | u676496404 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 78 | An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. | m,n,y=map(int,input().split())
if (m+n)<=y:
print("Yes")
else:
print("No") | s493963849 | Accepted | 17 | 2,940 | 78 | m,n,y=map(int,input().split())
if y<=(m+n):
print("Yes")
else:
print("No") |
s170994375 | p02612 | u727717182 | 2,000 | 1,048,576 | Wrong Answer | 26 | 9,144 | 144 | 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. | from sys import stdin
def main():
input = stdin.readline
N = int(input())
print(N % 1000)
if __name__ == "__main__":
main() | s882835151 | Accepted | 32 | 9,156 | 175 | from sys import stdin
def main():
input = stdin.readline
N = int(input())
ans = (1000 - N % 1000) % 1000
print(ans)
if __name__ == "__main__":
main() |
s095250543 | p02936 | u010090035 | 2,000 | 1,048,576 | Wrong Answer | 2,106 | 41,136 | 513 | Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations. | from collections import deque
n,q=map(int,input().split())
edge=[[] for _ in range(n+1)]
c=[0 for _ in range(n+1)]
for i in range(n-1):
a,b=map(int,input().split())
edge[a].append(b)
for i in range(q):
p,x=map(int,input().split())
vq=deque()
vq.append(p)
while(len(vq)>0):
# print(vq)
pi=vq.popleft()
c[pi]+=x
child=edge[pi]
for j in range(len(child)):
vq.append(child[j])
for i in range(1,n+1):
print(str(c[i])+" ",end="")
print()
| s839149283 | Accepted | 1,894 | 70,232 | 702 | from collections import deque
import sys
sys.setrecursionlimit(10**9)
n,q=map(int,input().split())
link=[[] for _ in range(n)]
for _ in range(n-1):
a,b=map(int,input().split())
link[a-1].append(b-1)
link[b-1].append(a-1)
v_counter=[0 for _ in range(n)]
for _ in range(q):
p,x=map(int,input().split())
v_counter[p-1]+=x
point=[0 for _ in range(n)]
que=deque()
que.append(0)
used=set()
used.add(0)
point[0] += v_counter[0]
while(len(que)>0):
ind=que.popleft()
relate=link[ind]
for i in relate:
if(i in used):
continue
else:
point[i] += point[ind] + v_counter[i]
que.append(i)
used.add(i)
print(*point)
|
s177317043 | p03854 | u703391033 | 2,000 | 262,144 | Wrong Answer | 74 | 3,956 | 233 | 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`. | SET=["dreamer", "dream", "eraser", "erase"]
S=input()
dp=[0]*100010
dp[0]=1
for i in range(len(S)):
if not dp[i]:continue
for j in SET:
if S[i:i+len(j)]==j:
dp[i+len(j)]=1
if dp[len(S)]==1:print("Yes")
else:print("No") | s137082640 | Accepted | 70 | 3,956 | 233 | SET=["dreamer", "dream", "eraser", "erase"]
S=input()
dp=[0]*100010
dp[0]=1
for i in range(len(S)):
if not dp[i]:continue
for j in SET:
if S[i:i+len(j)]==j:
dp[i+len(j)]=1
if dp[len(S)]==1:print("YES")
else:print("NO") |
s394436812 | p04043 | u409064224 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 113 | 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("7") == 1 and a.count("5") == 2:
print("YES")
else:
print("NO") | s756869365 | Accepted | 17 | 2,940 | 86 | a = list(map(int,input().split()))
if sum(a) == 17:
print("YES")
else:
print("NO") |
s188769395 | p02865 | u549278479 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 91 | How many ways are there to choose two distinct positive integers totaling N, disregarding the order? | N = int(input())
if (N % 2 == 1):
ans = (N-1) / 2
else:
ans = N/2 - 1
print(ans)
| s128433902 | Accepted | 18 | 2,940 | 96 | N = int(input())
if (N % 2 == 1):
ans = (N-1) / 2
else:
ans = N/2 - 1
print(int(ans))
|
s905889161 | p03597 | u759651152 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 136 | We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black? | #-*-coding:utf-8-*-
def main():
n = int(input())
a = int(input())
print(n ** n - a)
if __name__ == '__main__':
main() | s898308340 | Accepted | 18 | 2,940 | 135 | #-*-coding:utf-8-*-
def main():
n = int(input())
a = int(input())
print(n * n - a)
if __name__ == '__main__':
main() |
s604185319 | p03130 | u297109012 | 2,000 | 1,048,576 | Wrong Answer | 20 | 3,316 | 395 | There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. | from collections import Counter
def solve(ABs):
ABs = sorted([ (min(a, b), max(a, b)) for (a, b) in ABs])
ac = Counter([a for (a, b) in ABs])
bc = Counter([a for (a, b) in ABs])
if len(ac) == 3 or len(bc) == 3:
return "YES"
else:
return "NO"
if __name__ == "__main__":
ABs = [tuple(map(int, input().split(" "))) for _ in range(3)]
print(solve(ABs))
| s624319536 | Accepted | 25 | 3,436 | 347 | from collections import Counter
def solve(ABs):
ac = Counter([a for (a, b) in ABs] + [b for (a, b) in ABs])
if "".join(sorted([str(v) for v in ac.values()])) == "1122":
return "YES"
else:
return "NO"
if __name__ == "__main__":
ABs = [tuple(map(int, input().split(" "))) for _ in range(3)]
print(solve(ABs))
|
s547860821 | p02602 | u330661451 | 2,000 | 1,048,576 | Wrong Answer | 98 | 31,388 | 243 | M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term. | def main():
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = []
for i in range(k,n):
ans.append("Yes" if a[i] > a[i-k] else "No")
print("/n".join(ans))
if __name__ == '__main__':
main() | s467707702 | Accepted | 97 | 31,420 | 243 | def main():
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = []
for i in range(k,n):
ans.append("Yes" if a[i] > a[i-k] else "No")
print("\n".join(ans))
if __name__ == '__main__':
main() |
s776861712 | p02613 | u385309449 | 2,000 | 1,048,576 | Wrong Answer | 149 | 16,328 | 315 | 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())
s=[input() for _ in range(n)]
c0=0
c1=0
c2=0
c3=0
for i in s:
if i=="AC":
c0+=1
elif i=="WA":
c1+=1
elif i=="TLE":
c2+=1
elif i=="RE":
c3+=1
print("AC"+" "+"×"+" "+str(c0))
print("WA"+" "+"×"+" "+str(c1))
print("TLE"+" "+"×"+" "+str(c2))
print("RE"+" "+"×"+" "+str(c3))
| s913604867 | Accepted | 152 | 16,332 | 311 | n=int(input())
s=[input() for _ in range(n)]
c0=0
c1=0
c2=0
c3=0
for i in s:
if i=="AC":
c0+=1
elif i=="WA":
c1+=1
elif i=="TLE":
c2+=1
elif i=="RE":
c3+=1
print("AC"+" "+"x"+" "+str(c0))
print("WA"+" "+"x"+" "+str(c1))
print("TLE"+" "+"x"+" "+str(c2))
print("RE"+" "+"x"+" "+str(c3))
|
s995018046 | p00003 | u234052535 | 1,000 | 131,072 | Wrong Answer | 60 | 7,588 | 219 | Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so. | for i in range(0, int(input())):
sidelen = [int(j) for j in input().split(" ")]
sidelen.sort(reverse=True)
if(sidelen[0]**2 == sidelen[1]**2+sidelen[2]**2):
print("Yes")
else:
print("NO") | s681694688 | Accepted | 40 | 7,648 | 275 | import sys
for i in sys.stdin:
try:
sidelen = [int(j) for j in i.split(" ")]
sidelen.sort(reverse=True)
if(sidelen[0]**2 == sidelen[1]**2 + sidelen[2]**2):
print("YES")
else:
print("NO")
except:
continue |
s876345879 | p02257 | u901205536 | 1,000 | 131,072 | Wrong Answer | 20 | 5,660 | 291 | A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of _N_ integers and prints the number of prime numbers in the list. | import math
def prime(num):
judge = True
for i in range(1, int(math.sqrt(num)+1)):
if num % i == 0:
judge = False
return judge
n = int(input())
cnt = 0
for i in range(n):
num = int(input())
if prime(num) == True:
cnt += 1
print(cnt)
| s734735429 | Accepted | 4,440 | 5,680 | 284 | import math
def prime(num):
judge = True
for i in range(2, int(math.sqrt(num)+1)):
if num % i == 0:
judge = False
return judge
n = int(input())
cnt = 0
a =[]
for i in range(n):
num = int(input())
if prime(num):
cnt += 1
print(cnt)
|
s665606033 | p03485 | u202570162 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 58 | You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer. | a,b = map(int,input().split())
x = (a+b)/2
print(int(x)+1) | s336675841 | Accepted | 17 | 2,940 | 102 | a,b = map(int,input().split())
x = (a+b)/2
if int(x) == x:
print(int(x))
else:
print(int(x)+1) |
s354148185 | p03359 | u600261652 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 60 | In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi? | a, b = map(int, input().split())
print("a" if b>=a else "b") | s029132930 | Accepted | 17 | 2,940 | 58 | a, b = map(int, input().split())
print(a if b>=a else a-1) |
s041508190 | p02612 | u006738234 | 2,000 | 1,048,576 | Wrong Answer | 31 | 9,140 | 62 | We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required. | N = int(input())
while(N >= 1000):
N = N - 1000
print(N) | s018486475 | Accepted | 25 | 9,148 | 138 | N = int(input())
if (N >= 1000):
while(N > 1000):
N = N - 1000
N = 1000 - N
else:
N = 1000 - N
print(N)
|
s805330323 | p03435 | u657541767 | 2,000 | 262,144 | Time Limit Exceeded | 2,104 | 3,064 | 556 | We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct. | c = [list(map(int, input().split())) for _ in range(3)]
ok = False
for a1 in range(101):
for a2 in range(101):
for a3 in range(101):
b1 = c[0][0] - a1
b2 = c[0][1] - a1
b3 = c[0][2] - a1
a = [a1, a2, a3]
b = [b1, b2, b3]
ok_sub = True
for i in range(3):
for j in range(3):
if a[i] + b[j] != c[i][j]:
ok_sub = False
if ok_sub:
ok = True
print('Yes') if ok else print('No') | s141477367 | Accepted | 17 | 3,060 | 277 | c = [list(map(int, input().split())) for _ in range(3)]
ok = True
b = [c[0][0], c[0][1], c[0][2]]
a = [0, c[1][0] - b[0], c[2][0] - b[0]]
for i in range(3):
for j in range(3):
if a[i] + b[j] != c[i][j]:
ok = False
print('Yes') if ok else print('No')
|
s256717403 | p03549 | u030090262 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 105 | Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer). | N, M = map(int, input().split())
X = 100 * (N-M) + 1900 * M
Y = (1 / 2)**M
print(X * Y / ((1 - Y) ** 2))
| s998270380 | Accepted | 18 | 3,188 | 91 | N, M = map(int, input().split())
X = 100 * (N-M) + 1900 * M
Y = (1 / 2)**M
print(int(X/Y))
|
s710717358 | p03228 | u405660020 | 2,000 | 1,048,576 | Wrong Answer | 26 | 9,112 | 167 | In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total. | a,b,k=map(int,input().split())
for i in range(k):
if a%2==1:
a-=1
b+=a//2
a=a//2
if b%2==1:
b-=1
a+=b//2
b=b//2
print(a,b)
| s366276017 | Accepted | 30 | 9,060 | 204 | a,b,k=map(int,input().split())
for i in range(k):
if i%2==0:
if a%2==1:
a-=1
b+=a//2
a=a//2
else:
if b%2==1:
b-=1
a+=b//2
b=b//2
print(a,b)
|
s224274368 | p03563 | u374802266 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 34 | Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it. | print(2*int(input())-int(input())) | s138970464 | Accepted | 17 | 2,940 | 42 | a,b=int(input()),int(input())
print(2*b-a) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.