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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s434623136 | p02678 | u970449052 | 2,000 | 1,048,576 | Wrong Answer | 844 | 38,616 | 478 | 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. | from collections import deque
N,M=map(int,input().split())
tr=[[] for _ in range(N)]
for _ in range(M):
a,b=map(int,input().split())
tr[a-1].append(b-1)
tr[b-1].append(a-1)
print(tr)
ans=[-1]*N
q=deque([0])
v=[True]*N
x=[True]*N
while q:
t=q.popleft()
if v[t]:
v[t]=False
for j in tr[t]:
if x[j]:
x[j]=False
ans[j]=t
q.append(j)
print('Yes')
for i in range(1,N):
print(ans[i]+1) | s443932500 | Accepted | 583 | 35,752 | 468 | from collections import deque
N,M=map(int,input().split())
tr=[[] for _ in range(N)]
for _ in range(M):
a,b=map(int,input().split())
tr[a-1].append(b-1)
tr[b-1].append(a-1)
ans=[-1]*N
q=deque([0])
v=[True]*N
x=[True]*N
while q:
t=q.popleft()
if v[t]:
v[t]=False
for j in tr[t]:
if x[j]:
x[j]=False
ans[j]=t
q.append(j)
print('Yes')
for i in range(1,N):
print(ans[i]+1) |
s781477889 | p03737 | u926581302 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 100 | You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words. | s1, s2, s3= map(str,input().split())
print(s1.upper()[0])
print(s2.upper()[0])
print(s3.upper()[0]) | s464452711 | Accepted | 17 | 2,940 | 90 | s1, s2, s3= map(str,input().split())
print(s1.upper()[0] + s2.upper()[0] + s3.upper()[0]) |
s836140470 | p02612 | u111482164 | 2,000 | 1,048,576 | Wrong Answer | 30 | 9,160 | 86 | 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=input()
n=int(n)
if n/1000==0:
print(n/1000)
else:
print(n%(1000*((1000//n)+1))) | s464521204 | Accepted | 28 | 9,032 | 148 | n=input()
n=int(n)
if n>1000:
count=0
while n>1000:
n=n-1000
count=count+1
print(count*1000-(n+(count-1)*1000))
else:
print(1000-n) |
s913996826 | p02678 | u797059905 | 2,000 | 1,048,576 | Wrong Answer | 2,229 | 618,188 | 1,194 | 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. | def dijkstra(startNode, nodeNum, edgeNum, cost):
d = [float('inf')]*nodeNum
x = [0]*nodeNum
usedNode = [False]*nodeNum
d[startNode] = 0
while True:
v = -1
y = 0
for i in range(n):
if (not usedNode[i]) and (v == -1):
v=i
y=i+1
elif (not usedNode[i]) and d[i] < d[v]:
v=i
y=i+1
if v == -1:
break
usedNode[v] = True
for j in range(n):
if d[j] > d[v]+cost[v][j]:
d[j] = d[v]+cost[v][j]
x[j] = y
return d,x
n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
for i in range(m):
a[i], b[i] = map(int, input().split())
c = [[float('inf') for i in range(n)] for j in range(n)]
for i in range(m):
c[a[i-1]-1][b[i-1]-1] = 1
c[b[i-1]-1][a[i-1]-1] = 1
d,x = dijkstra(0, n, m, c)
print('yes')
for i in range(n-1):
print(x[i+1])
| s126068558 | Accepted | 781 | 37,256 | 809 |
N, M = map(int, input().split())
edges = [[] for i in range(N)]
for i in range(M):
A, B = map(int, input().split())
edges[A - 1] += [B - 1]
edges[B - 1] += [A - 1]
que = [0]
ans = [0] + [-1 for i in range(N - 1)]
while -1 in ans:
quetmp = que
que = []
for node in quetmp:
for neighbor in edges[node]:
if ans[neighbor] == -1:
ans[neighbor] = node + 1
que += [neighbor]
print('Yes')
for a in ans[1:]:
print(a)
|
s450926572 | p03997 | u672898046 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 70 | 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) | s134206953 | Accepted | 18 | 2,940 | 71 | a = int(input())
b = int(input())
h = int(input())
print(((a+b)*h)//2) |
s049927882 | p02420 | u130834228 | 1,000 | 131,072 | Wrong Answer | 30 | 7,592 | 149 | Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string). | while True:
W = list(input())
if W[0] == '-':
break
times = int(input())
for i in range(times):
h = int(input())
X = W[h:]+W[0:h]
print(X) | s657556397 | Accepted | 20 | 7,588 | 158 | while True:
W = list(input())
if W[0] == '-':
break
times = int(input())
for i in range(times):
h = int(input())
W = W[h:]+W[0:h]
print(*W, sep='') |
s213991179 | p04013 | u993161647 | 2,000 | 262,144 | Wrong Answer | 300 | 5,868 | 475 | Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? | N, A = list(map(int,input().split()))
x = list(map(int,input().split()))
X = max(x)
dp=[[0] * (2*N*X + 1) for _ in range(N + 1)]
for j in range(N+1):
for t in range(2*N*X):
if j==0 and t==N*X:
dp[j][t] = 1
elif t-x[j-1] < 0 or t-x[j-1] > 2*N*X:
dp[j][t] = dp[j-1][t]
elif 0 < t-x[j-1] and t-x[j-1] < 2*N*X:
dp[j][t] = dp[j-1][t] + dp[j-1][t-x[j-1]]
else:
dp[j][t] = 0
print(dp[N][N*X]-1) | s963267278 | Accepted | 307 | 5,228 | 499 | N, A = [int(x_i) for x_i in input().split()]
x = [int(x_i) - A for x_i in input().split()]
X = max(x + [A])
dp=[[0] * (2*N*X + 1) for _ in range(N + 1)]
for j in range(N+1):
for t in range(2*N*X):
if j==0 and t==N*X:
dp[j][t] = 1
elif t-x[j-1] < 0 or t-x[j-1] > 2*N*X:
dp[j][t] = dp[j-1][t]
elif 0 < t-x[j-1] and t-x[j-1] < 2*N*X:
dp[j][t] = dp[j-1][t] + dp[j-1][t-x[j-1]]
else:
dp[j][t] = 0
print(dp[N][N*X]-1) |
s293492286 | p03998 | u518455500 | 2,000 | 262,144 | Wrong Answer | 38 | 3,064 | 240 | Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. | mem = []
for i in range(3):
mem.append(list(input()))
mem = [[ord(y)-97 for y in x] for x in mem]
print(mem)
idx = 0
while 1:
if len(mem[idx]) >= 1:
idx = mem[idx].pop(0)
else:
break
print(chr(idx+97).upper()) | s049521960 | Accepted | 44 | 3,064 | 229 | mem = []
for i in range(3):
mem.append(list(input()))
mem = [[ord(y)-97 for y in x] for x in mem]
idx = 0
while 1:
if len(mem[idx]) >= 1:
idx = mem[idx].pop(0)
else:
break
print(chr(idx+97).upper()) |
s045757693 | p03151 | u056358163 | 2,000 | 1,048,576 | Wrong Answer | 154 | 18,708 | 484 | A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. | N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A) < sum(B):
print(-1)
exit()
ans = 0
minus = 0
plus_list = []
for a, b in zip(A, B):
if a < b:
ans += 1
minus += b - a
plus_list.append(a - b)
if minus == 0:
print(0)
exit()
plus_list_ = sorted(plus_list, reverse=True)
for p in plus_list:
minus -= p
ans += 1
if minus < 0:
break
print(ans)
#print(minus)
| s028413410 | Accepted | 140 | 18,708 | 485 | N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A) < sum(B):
print(-1)
exit()
ans = 0
minus = 0
plus_list = []
for a, b in zip(A, B):
if a < b:
ans += 1
minus += b - a
plus_list.append(a - b)
if minus == 0:
print(0)
exit()
plus_list_ = sorted(plus_list, reverse=True)
for p in plus_list_:
minus -= p
ans += 1
if minus < 0:
break
print(ans)
#print(minus)
|
s306161653 | p03635 | u762603420 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 69 | In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city? | n, m = list(map(int, input("test").split()))
print (str((n-1)*(m-1))) | s643780701 | Accepted | 17 | 2,940 | 63 | n, m = list(map(int, input().split()))
print (str((n-1)*(m-1))) |
s643094499 | p03548 | u384679440 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 79 | We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat? | X, Y, Z = map(int, input().split())
ans = int((X - 2 * Z) / (Y + Z))
print(ans) | s543535027 | Accepted | 17 | 2,940 | 75 | X, Y, Z = map(int, input().split())
ans = int((X - Z) / (Y + Z))
print(ans) |
s878245029 | p03587 | u080990738 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 84 | Snuke prepared 6 problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not. You are given a string S of length 6. If the i-th character of s is `1`, it means that the i-th problem prepared by Snuke is accepted to be used; `0` means that the problem is not accepted. How many problems prepared by Snuke are accepted to be used in the contest? | a =input()
c=0
for i in range(0,6):
if a[i] == 1:
c += 1
else:
pass
print(c)
| s247361751 | Accepted | 17 | 2,940 | 104 | a =input()
c=0
for i in range(0,6):
if a[i] == "1":
c += 1
else:
pass
print(c)
|
s696704406 | p03943 | u413411219 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 155 | Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students. | l = list(map(int, input().split()))
print(l)
if l[0] == l[1] + l[2] or l[1] == l[0] + l[2] or l[2] == l[0] + l[1]:
print('Yes')
else:
print('No') | s513904196 | Accepted | 17 | 2,940 | 146 | l = list(map(int, input().split()))
if l[0] == l[1] + l[2] or l[1] == l[0] + l[2] or l[2] == l[0] + l[1]:
print('Yes')
else:
print('No') |
s596670793 | p03457 | u607139498 | 2,000 | 262,144 | Wrong Answer | 352 | 32,144 | 911 | 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. | # -*- coding: utf-8 -*-
import math
n = int(input())
a = [input().split() for i in range(n)]
def travelCheck(alpha, beta):
timeDiff = int(beta[0]) - int(alpha[0])
positionDiff = abs(int(beta[1]) - int(alpha[1])) + abs(int(beta[2]) - int(alpha[2]))
flag = False
if timeDiff >= positionDiff and (timeDiff%2 == positionDiff%2):
flag = True
return flag
start = ['0', '0', '0']
# positionList = []
# positionList.append(start)
# positionList.append(a)
for i in a:
flag = travelCheck(start, i)
start = i
if flag:
print("YES")
if not flag:
print("NO")
| s091744985 | Accepted | 368 | 32,144 | 911 | # -*- coding: utf-8 -*-
import math
n = int(input())
a = [input().split() for i in range(n)]
def travelCheck(alpha, beta):
timeDiff = int(beta[0]) - int(alpha[0])
positionDiff = abs(int(beta[1]) - int(alpha[1])) + abs(int(beta[2]) - int(alpha[2]))
flag = False
if timeDiff >= positionDiff and (timeDiff%2 == positionDiff%2):
flag = True
return flag
start = ['0', '0', '0']
# positionList = []
# positionList.append(start)
# positionList.append(a)
for i in a:
flag = travelCheck(start, i)
start = i
if flag:
print("Yes")
if not flag:
print("No")
|
s304351121 | p03455 | u126107446 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 104 | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. | a, b = map(int, input().split())
sum = a * b
if sum / 2 == 0:
print("even")
else:
print("odd") | s154585051 | Accepted | 17 | 2,940 | 102 | a, b = map(int, input().split())
sum = a * b
if sum % 2 == 0:
print("Even")
else:
print("Odd") |
s850951755 | p03448 | u725044506 | 2,000 | 262,144 | Wrong Answer | 55 | 3,188 | 461 | You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. | A = int(input())
B = int(input())
C = int(input())
X = int(input())
x = 0
count = 0
for a in range(A + 1):
x = a * 500
if x == X:
count += 1
for b in range(B + 1):
x = a * 500 + b * 100
if x == X:
count += 1
for c in range(C + 1):
x = a * 500 + b * 100 + c * 50
# print(x)
if x == X:
count += 1
print(count) | s652834827 | Accepted | 56 | 3,060 | 362 | A = int(input())
B = int(input())
C = int(input())
X = int(input())
x = 0
count = 0
for a in range(A + 1):
x = a * 500
for b in range(B + 1):
x = a * 500 + b * 100
for c in range(C + 1):
x = a * 500 + b * 100 + c * 50
if x == X:
count += 1
print(count)
|
s932611354 | p03449 | u289923433 | 2,000 | 262,144 | Wrong Answer | 19 | 3,064 | 277 | We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel? | N = int(input())
first_line = input().split()
second_line = input().split()
bef_sum = 0
sum = 0
i = 0
j = 0
for i in range(N):
for j in range(i + 1):
sum += int(first_line[j])
sum += int(second_line[i])
if bef_sum < sum:
bef_sum = sum
sum = 0
print(bef_sum) | s935159132 | Accepted | 22 | 3,064 | 375 | N = int(input())
first_line = input().split()
second_line = input().split()
bef_sum = 0
sum = 0
for i in range(N):
for j in range(N):
if j < i:
sum += int(first_line[j])
elif j == i:
sum += int(first_line[j])
sum += int(second_line[i])
else:
sum += int(second_line[j])
if bef_sum < sum:
bef_sum = sum
sum = 0
print(bef_sum)
|
s678400020 | p02613 | u437215432 | 2,000 | 1,048,576 | Wrong Answer | 148 | 9,072 | 294 | Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format. | n = int(input())
ac = wa = tle = re = 0
for i in range(n):
s = input()
if s == 'AC':
ac += 1
elif s == 'WA':
wa += 1
elif s == 'TLE':
tle += 0
elif s == 'RE':
re += 1
print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)
| s112752679 | Accepted | 148 | 9,216 | 293 | n = int(input())
ac = wa = tle = re = 0
for i in range(n):
s = input()
if s == 'AC':
ac += 1
elif s == 'WA':
wa += 1
elif s == 'TLE':
tle += 1
elif s == 'RE':
re += 1
print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re) |
s016990038 | p04030 | u895408600 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 179 | Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now? | s=input()
ans=[]
for i in range(len(s)):
if s[i]=='1':
ans.append('1')
if s[i]=='0':
ans.append('0')
if s[i]=='B':
ans = ans[:-1]
print(*ans) | s035068232 | Accepted | 18 | 3,060 | 187 | s=input()
ans=[]
for i in range(len(s)):
if s[i]=='1':
ans.append('1')
if s[i]=='0':
ans.append('0')
if s[i]=='B':
ans = ans[:-1]
print(''.join(ans)) |
s287781223 | p03456 | u075878544 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 122 | 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. | a,b=map(str, input().split())
c=a+b
d=int(c)
for i in range(1,317):
if d==i**2:
print('Yes')
else:
print('No') | s594252878 | Accepted | 18 | 3,060 | 156 | a,b=map(str, input().split())
c=a+b
d=int(c)
k=0
for i in range(1,1001):
if d==i**2:
k=k+1
else:
k=k
if k>=1:
print('Yes')
else:
print('No') |
s589628279 | p03796 | u467307100 | 2,000 | 262,144 | Wrong Answer | 231 | 3,984 | 64 | Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7. | import math
n = int(input())
print(math.factorial(n) % 10**9+7) | s850640500 | Accepted | 230 | 3,980 | 66 | import math
n = int(input())
print(math.factorial(n) % (10**9+7)) |
s128341841 | p02380 | u539789745 | 1,000 | 131,072 | Wrong Answer | 20 | 5,708 | 350 | For given two sides of a triangle _a_ and _b_ and the angle _C_ between them, calculate the following properties: * S: Area of the triangle * L: The length of the circumference of the triangle * h: The height of the triangle with side a as a bottom edge | import math
def main():
a, b, C = map(int, input().split())
rad = math.pi * C / 180
sin = math.sin(rad)
h = b * sin
S = a * h / 2
a_ = a - math.cos(rad)
len_d = math.sqrt(a_ ** 2 + h ** 2)
print(S)
print(a + b + len_d)
print(h)
if __name__ == "__main__":
main() | s166752536 | Accepted | 20 | 5,728 | 959 | import math
def main():
a, b, C = map(int, input().split())
rad = math.pi * C / 180
sin = math.sin(rad)
h = b * sin
S = a * h / 2
a_ = a - b * math.cos(rad)
len_d = math.sqrt(a_ ** 2 + h ** 2)
print("{:.8f}".format(S))
print("{:.8f}".format(a + b + len_d))
print("{:.8f}".format(h))
if __name__ == "__main__":
main() |
s818832256 | p03544 | u057415180 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 196 | It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2) | n = int(input())
memo = [2, 1]
if n <= 2:
print(memo[n-1])
exit()
else:
for i in range(2,n):
tmp = memo[1]
memo[1] = memo[0] + tmp
memo[0] = tmp
print(memo[1]) | s229642213 | Accepted | 17 | 2,940 | 194 | n = int(input())
memo = [2, 1]
if n == 1:
print(memo[n])
exit()
else:
for i in range(1,n):
tmp = memo[1]
memo[1] = memo[0] + tmp
memo[0] = tmp
print(memo[1]) |
s960267374 | p02865 | u934099192 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 72 | How many ways are there to choose two distinct positive integers totaling N, disregarding the order? | a = int(input())
if a % 2 == 0:
print(a/2 - 1)
else:
print(a/2) | s572794532 | Accepted | 17 | 2,940 | 86 | a = int(input())
if a % 2 == 0:
print(int(int(a/2) - 1))
else:
print(int(a/2)) |
s415845668 | p03160 | u087917227 | 2,000 | 1,048,576 | Wrong Answer | 146 | 14,704 | 235 | There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N. | N=int(input())
hn = list(map(int,input().split()))
inf=float("inf")
dp=[inf]*(N+2)
dp[0], dp[1] = 0, abs(hn[1]-hn[0])
for i in range(2,N):
dp[i] = min(dp[i-2]+abs(hn[i]-hn[i-2]), dp[i-1]+abs(hn[i]-hn[i-1]))
print(dp[N-1])
print(dp) | s357294932 | Accepted | 142 | 13,980 | 225 | N=int(input())
hn = list(map(int,input().split()))
inf=float("inf")
dp=[inf]*(N+2)
dp[0], dp[1] = 0, abs(hn[1]-hn[0])
for i in range(2,N):
dp[i] = min(dp[i-2]+abs(hn[i]-hn[i-2]), dp[i-1]+abs(hn[i]-hn[i-1]))
print(dp[N-1]) |
s288051483 | p02842 | u893270619 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 316 | Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact. | import math
N = int(input())
N_0 = math.ceil(N / 1.08)
N_l = [N_0-2, N_0-1, N_0, N_0+1, N_0+2]
N_l_tax = [math.floor(1.08*x) for x in N_l]
N_l_out = []
for i in range(len(N_l_tax)):
if N_l_tax[i] == N:
N_l_out.append(N_l_tax[i])
if len(N_l_out) != 0:
for j in N_l_out:
print(j)
else:
print(':-(') | s630841136 | Accepted | 17 | 3,064 | 321 | import math
N = int(input())
N_0 = math.ceil(N / 1.08)
M = 10
N_l = [N_0 - M + P for P in range(M*2)]
N_l_tax = [math.floor(1.08*x) for x in N_l]
N_l_out = []
for i in range(len(N_l_tax)):
if N_l_tax[i] == N:
N_l_out.append(N_l[i])
if len(N_l_out) != 0:
for j in N_l_out:
print(j)
else:
print(':(') |
s837199666 | p02261 | u749243807 | 1,000 | 131,072 | Wrong Answer | 20 | 5,608 | 848 | Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance). | count = int(input());
data = input().split(" ");
def bubble_sort(data):
# print(data);
count = len(data);
for i in range(count):
for j in range(count - 1, i, -1):
if data[j][1] < data[j - 1][1]:
data[j], data[j - 1] = data[j - 1], data[j];
# print(data);
def selection_sort(data):
count = len(data);
# print(data);
for i in range(count - 1):
minI = i;
for j in range(i + 1, count):
if data[j][1] < data[minI][1]:
minI = j;
if i != minI:
data[i], data[minI] = data[minI], data[i];
# print(data);
def show(data):
print(" ".join(data));
A = list(data);
bubble_sort(A);
show(A);
print("Stable");
B = list(data);
selection_sort(B);
show(B);
if A == B:
print("Stable");
else:
print("Not Stable");
| s222582874 | Accepted | 20 | 5,608 | 848 | count = int(input());
data = input().split(" ");
def bubble_sort(data):
# print(data);
count = len(data);
for i in range(count):
for j in range(count - 1, i, -1):
if data[j][1] < data[j - 1][1]:
data[j], data[j - 1] = data[j - 1], data[j];
# print(data);
def selection_sort(data):
count = len(data);
# print(data);
for i in range(count - 1):
minI = i;
for j in range(i + 1, count):
if data[j][1] < data[minI][1]:
minI = j;
if i != minI:
data[i], data[minI] = data[minI], data[i];
# print(data);
def show(data):
print(" ".join(data));
A = list(data);
bubble_sort(A);
show(A);
print("Stable");
B = list(data);
selection_sort(B);
show(B);
if A == B:
print("Stable");
else:
print("Not stable");
|
s459416055 | p03501 | u163449343 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 79 | You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours. | n,a,b = map(int, input().split())
if a * n < b:
print(b)
else:
print(a * b) | s897472693 | Accepted | 17 | 2,940 | 79 | n,a,b = map(int, input().split())
if a * n > b:
print(b)
else:
print(a * n) |
s355941015 | p02748 | u308684517 | 2,000 | 1,048,576 | Wrong Answer | 18 | 3,060 | 210 | You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required. | s = input()
if len(s) % 2 != 0:
print("No")
exit()
else:
S = [s[i] + s[i+1] for i in range(0, len(s), 2)]
if len(set(S)) == 1 and S[0] == "hi":
print("Yes")
else:
print("No") | s581934140 | Accepted | 409 | 18,736 | 276 | a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
ans = min(A) + min(B)
for i in range(m):
x, y, c = map(int, input().split())
if A[x-1] + B[y-1] - c < ans:
ans = A[x-1] + B[y-1] - c
print(ans)
|
s494882476 | p03495 | u924374652 | 2,000 | 262,144 | Wrong Answer | 199 | 39,344 | 270 | 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. | import collections
n, k = map(int, input().split())
list_a = list(map(int, input().split()))
count = collections.Counter(list_a)
sort_c = sorted(count.items(), key=lambda x:x[1])
num_kind = len(sort_c)
result = 0
for i in range(num_kind - k):
result += sort_c[i][1]
| s058059526 | Accepted | 214 | 39,320 | 284 | import collections
n, k = map(int, input().split())
list_a = list(map(int, input().split()))
count = collections.Counter(list_a)
sort_c = sorted(count.items(), key=lambda x:x[1])
num_kind = len(sort_c)
result = 0
for i in range(num_kind - k):
result += sort_c[i][1]
print(result)
|
s141223404 | p03945 | u595716769 | 2,000 | 262,144 | Wrong Answer | 37 | 3,188 | 105 | Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place. | s = input()
count = 0
for i in range(len(s)):
now = s[i]
if now != s[i]:
count += 1
print(count) | s299058012 | Accepted | 42 | 3,188 | 119 | s = input()
count = 0
now = s[0]
for i in range(len(s)):
if now != s[i]:
count += 1
now = s[i]
print(count) |
s184806402 | p03478 | u345621867 | 2,000 | 262,144 | Wrong Answer | 34 | 3,552 | 220 | 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())
box = []
for i in range(1,N+1):
s = str(i)
temp = 0
for j in s:
j = int(j)
temp += j
if A <= temp <= B:
box.append(i)
print(box)
print(sum(box)) | s301506180 | Accepted | 40 | 3,296 | 255 | N, A, B = map(int, input().split())
box = []
for i in range(1, N+1 ):
n = len(str(i))
j = i
temp = 0
while n != 0:
temp += (j % 10)
j = int(j / 10)
n -= 1
if A <= temp <= B:
box.append(i)
print(sum(box)) |
s012147783 | p03129 | u709304134 | 2,000 | 1,048,576 | Wrong Answer | 18 | 2,940 | 105 | Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1. | #coding:utf-8
n,k = map(int,input().split())
if 2 * k - 1 <= n:
print ("Yes")
else:
print ("No")
| s296427576 | Accepted | 19 | 2,940 | 105 | #coding:utf-8
n,k = map(int,input().split())
if 2 * k - 1 <= n:
print ("YES")
else:
print ("NO")
|
s523069035 | p03549 | u430771494 | 2,000 | 262,144 | Wrong Answer | 20 | 3,060 | 202 | 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=list(map(int, input().split()))
alper=(1/2)**M
bl=1-alper
ans=1.0
bac=0.1
kaisu=0
while ans!=bac:
kaisu=kaisu+1
bac=ans
ans=ans+(1800*M+100*N)*kaisu*(bl**(kaisu-1))*alper
print(int(ans)) | s054855050 | Accepted | 17 | 2,940 | 91 | N,M=list(map(int, input().split()))
alper=(1/2)**M
time=1800*M+100*N
print(int(time/alper)) |
s553210263 | p02416 | u032662562 | 1,000 | 131,072 | Wrong Answer | 30 | 7,516 | 113 | Write a program which reads an integer and prints sum of its digits. | while True:
v = list(map(int, input().split()))
if len(v)==1 and v[0]==0:
break
print(sum(v)) | s276141325 | Accepted | 20 | 7,612 | 83 | while True:
s = input()
if s=="0":
break
print(sum(map(int,s))) |
s584855458 | p04043 | u477448615 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 116 | Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order. | l = [map(int,input().split())]
if l == [5,5,7] or l == [5,7,5] or l == [7,5,5]:
print("Yes")
else: print("No")
| s590757316 | Accepted | 17 | 2,940 | 120 | l = list(map(int,input().split()))
if l == [5,7,5] or l == [5,5,7] or l == [7,5,5]:
print("YES")
else: print("NO")
|
s760704814 | p02565 | u021548497 | 5,000 | 1,048,576 | Wrong Answer | 323 | 10,876 | 4,189 | Consider placing N flags on a line. Flags are numbered through 1 to N. Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D. Decide whether it is possible to place all N flags. If it is possible, print such a configulation. | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
"""
TwoSat
"""
class SCC:
def __init__(self, n):
self.n = n
self.graph = [[] for _ in range(n)]
self.graph_rev = [[] for _ in range(n)]
self.already = [False]*n
def add_edge(self, fr, to):
if fr == to:
return
self.graph[fr].append(to)
self.graph_rev[to].append(fr)
def dfs(self, node, graph):
self.already[node] = True
for n in graph[node]:
if self.already[n]:
continue
self.dfs(n, graph)
self.order.append(node)
def first_dfs(self):
self.already = [False]*self.n
self.order = []
for i in range(self.n):
if self.already[i] == False:
self.dfs(i, self.graph)
def second_dfs(self):
self.already = [False]*self.n
self.ans = []
for n in reversed(self.order):
if self.already[n]:
continue
self.already[n] = True
self.order = []
self.dfs(n, self.graph_rev)
self.order.reverse()
self.ans.append(self.order)
def scc(self):
self.first_dfs()
self.second_dfs()
return self.ans
class UnionFind:
def __init__(self, n):
self.n = n
self.par = [-1]*(n+1)
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.par[x] > self.par[y]:
x, y = y, x
self.par[x] += self.par[y]
self.par[y] = x
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.par[self.find(x)]
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if root == self.find(i)]
class TwoSat:
def __init__(self, n):
self.n = n
self.scc = SCC(n*2)
self.union = UnionFind(n*2)
def add_sat(self, fr, to):
self.scc.add_edge(fr, to)
def scc_prepare(self):
return self.scc.scc()
def union_prepare(self):
for v in self.res:
if len(v) == 1:
continue
for i in range(len(v)-1):
self.union.union(v[i], v[i+1])
def ts_judge(self):
for i in range(self.n):
if self.union.same(i, i+self.n):
return False
return True
def judge(self):
self.res = self.scc_prepare()
self.union_prepare()
res = self.ts_judge()
return res
def main():
n, d = map(int, input().split())
ts = TwoSat(n*2)
flag = [None]*n
for i in range(n):
x, y = map(int, input().split())
flag[i] = (x, y)
for i in range(n):
ts.add_sat(n*3+i, i)
ts.add_sat(n*2+i, n+i)
for i in range(n):
for j in range(i+1, n):
if abs(flag[i][0] - flag[j][0]) < d:
ts.add_sat(i, n*2+j)
ts.add_sat(j, n*2+i)
ts.add_sat(i, n+j)
ts.add_sat(j, n+i)
if abs(flag[i][0] - flag[j][1]) < d:
ts.add_sat(i, j)
ts.add_sat(i, n*3+j)
ts.add_sat(n+j, n+i)
ts.add_sat(n+j, n*2+i)
if abs(flag[i][1] - flag[j][0]) < d:
ts.add_sat(j, i)
ts.add_sat(j, n*3+i)
ts.add_sat(n+i, n+j)
ts.add_sat(n+i, n*2+j)
if abs(flag[i][1] - flag[j][1]) < d:
ts.add_sat(i+n, j)
ts.add_sat(i+n, j+n*3)
ts.add_sat(j+n, i)
ts.add_sat(j+n, i+n*3)
ans = ts.judge()
print("Yes" if ans else "No")
if __name__ == "__main__":
main() | s534648647 | Accepted | 326 | 11,020 | 4,646 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
"""
TwoSat
"""
class SCC:
def __init__(self, n):
self.n = n
self.graph = [[] for _ in range(n)]
self.graph_rev = [[] for _ in range(n)]
self.already = [False]*n
def add_edge(self, fr, to):
if fr == to:
return
self.graph[fr].append(to)
self.graph_rev[to].append(fr)
def dfs(self, node, graph):
self.already[node] = True
for n in graph[node]:
if self.already[n]:
continue
self.dfs(n, graph)
self.order.append(node)
def first_dfs(self):
self.already = [False]*self.n
self.order = []
for i in range(self.n):
if self.already[i] == False:
self.dfs(i, self.graph)
def second_dfs(self):
self.already = [False]*self.n
self.ans = []
for n in reversed(self.order):
if self.already[n]:
continue
self.already[n] = True
self.order = []
self.dfs(n, self.graph_rev)
self.order.reverse()
self.ans.append(self.order)
def scc(self):
self.first_dfs()
self.second_dfs()
return self.ans
class UnionFind:
def __init__(self, n):
self.n = n
self.par = [-1]*(n+1)
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.par[x] > self.par[y]:
x, y = y, x
self.par[x] += self.par[y]
self.par[y] = x
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.par[self.find(x)]
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if root == self.find(i)]
class TwoSat:
def __init__(self, n):
self.n = n
self.scc = SCC(n*2)
self.union = UnionFind(n*2)
def add_sat(self, fr, to):
self.scc.add_edge(fr, to)
def scc_prepare(self):
return self.scc.scc()
def union_prepare(self):
for v in self.res:
if len(v) == 1:
continue
for i in range(len(v)-1):
self.union.union(v[i], v[i+1])
def ts_judge(self):
for i in range(self.n):
if self.union.same(i, i+self.n):
return False
return True
def judge(self):
self.res = self.scc_prepare()
self.union_prepare()
res = self.ts_judge()
return res
def main():
n, d = map(int, input().split())
ts = TwoSat(n*2)
flag = [None]*n
for i in range(n):
x, y = map(int, input().split())
flag[i] = (x, y)
for i in range(n):
ts.add_sat(n*3+i, i)
ts.add_sat(n*2+i, n+i)
for i in range(n):
for j in range(i+1, n):
if abs(flag[i][0] - flag[j][0]) < d:
ts.add_sat(i, n*2+j)
ts.add_sat(j, n*2+i)
ts.add_sat(i, n+j)
ts.add_sat(j, n+i)
if abs(flag[i][0] - flag[j][1]) < d:
ts.add_sat(i, j)
ts.add_sat(i, n*3+j)
ts.add_sat(n+j, n+i)
ts.add_sat(n+j, n*2+i)
if abs(flag[i][1] - flag[j][0]) < d:
ts.add_sat(j, i)
ts.add_sat(j, n*3+i)
ts.add_sat(n+i, n+j)
ts.add_sat(n+i, n*2+j)
if abs(flag[i][1] - flag[j][1]) < d:
ts.add_sat(i+n, j)
ts.add_sat(i+n, j+n*3)
ts.add_sat(j+n, i)
ts.add_sat(j+n, i+n*3)
ans = ts.judge()
print("Yes" if ans else "No")
if ans:
used = [-1]*n
count = 0
for lis in reversed(ts.res):
for v in lis:
if v >= n*2:
continue
index = v if v < n else v - n
if used[index] == -1:
count += 1
used[index] = v//n
if count == n:
break
for i in range(n):
print(flag[i][used[i]])
if __name__ == "__main__":
main() |
s230204515 | p03457 | u268318377 | 2,000 | 262,144 | Wrong Answer | 409 | 11,816 | 344 | 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,X,Y = [0],[0],[0]
a = 1
for n in range(N):
t,x,y = map(int, input().split())
T.append(t)
X.append(x)
Y.append(y)
for m in range(N):
dt = T[m+1]-T[m]
ds = abs(X[m+1]-X[m]) + abs(Y[m+1]-Y[m])
if dt < ds:
a = 0
if dt%2 != ds%2:
a = 0
if a:
print("YES")
else:
print("NO") | s739152215 | Accepted | 416 | 11,764 | 344 | N = int(input())
T,X,Y = [0],[0],[0]
a = 1
for n in range(N):
t,x,y = map(int, input().split())
T.append(t)
X.append(x)
Y.append(y)
for m in range(N):
dt = T[m+1]-T[m]
ds = abs(X[m+1]-X[m]) + abs(Y[m+1]-Y[m])
if dt < ds:
a = 0
if dt%2 != ds%2:
a = 0
if a:
print("Yes")
else:
print("No") |
s758705134 | p02262 | u741801763 | 6,000 | 131,072 | Wrong Answer | 20 | 5,592 | 587 | Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$ | def insert_sort(L,n,g):
cnt =0
for i in range(g,n):
v = L[i]
j = i-g
while j >= 0 and L[j] > v:
L[j+g] = L[j]
j = j-g
cnt +=1
L[j+g] = v
return cnt
if __name__ == '__main__':
n = int(input())
L = []
G = []
h = 1
cnt = 0
for _ in range(n):
L.append(int(input()))
while 1:
if h > n: break
G.append(h)
h = 3*h + 1
for gap in G[::-1]:
cnt += insert_sort(L,n,gap)
print(*G)
print(cnt)
for i in range(n):
print(L[i])
| s811602854 | Accepted | 18,560 | 45,508 | 615 | def insert_sort(L,n,g):
cnt =0
for i in range(g,n):
v = L[i]
j = i-g
while j >= 0 and L[j] > v:
L[j+g] = L[j]
j = j-g
cnt +=1
L[j+g] = v
return cnt
if __name__ == '__main__':
n = int(input())
L = []
G = []
h = 1
cnt = 0
for _ in range(n):
L.append(int(input()))
while 1:
if h > n: break
G.append(h)
h = 3*h + 1
G = G[::-1]
for gap in G:
cnt += insert_sort(L,n,gap)
print(len(G))
print(*G)
print(cnt)
for i in range(n):
print(L[i])
|
s385402032 | p02850 | u046187684 | 2,000 | 1,048,576 | Wrong Answer | 750 | 75,948 | 975 | 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 deque
def solve(string):
n, *ab = map(int, string.split())
next_ = [dict([]) for _ in range(n + 1)]
color = [set([]) for _ in range(n + 1)]
queue = deque([1])
for a, b in zip(*[iter(ab)] * 2):
next_[a][b] = 0
next_[b][a] = 0
while len(queue) > 0:
c = queue.popleft()
_next = next_[c].items()
use = set(range(1, len(_next) + 1)) - color[c]
_next = (k for k, v in _next if v == 0)
for _n, u in zip(_next, use):
print(_n, u)
queue.append(_n)
next_[c][_n] = u
next_[_n][c] = u
color[c].add(u)
color[_n].add(u)
return str("{}\n{}".format(max(map(lambda x: len(x.keys()), next_)),
"\n".join(str(next_[a][b]) for a, b in zip(*[iter(ab)] * 2))))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| s969417059 | Accepted | 560 | 29,220 | 575 | from collections import deque
def solve(string):
n, *ab = map(int, string.split())
e = [[] for _ in range(n + 1)]
q = [1]
c = [0] * (n + 1)
for a, b in zip(*[iter(ab)] * 2):
e[a].append(b)
while q:
s = q.pop(0)
d = 0
for t in e[s]:
d += 1 + (d + 1 == c[s])
c[t] = d
q.append(t)
return str("{}\n{}".format(max(c), "\n".join(str(c[b]) for _, b in zip(*[iter(ab)] * 2))))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
|
s653366633 | p02283 | u613534067 | 2,000 | 131,072 | Wrong Answer | 20 | 5,600 | 1,120 | Search trees are data structures that support dynamic set operations including insert, search, delete and so on. Thus a search tree can be used both as a dictionary and as a priority queue. Binary search tree is one of fundamental search trees. The keys in a binary search tree are always stored in such a way as to satisfy the following binary search tree property: * Let $x$ be a node in a binary search tree. If $y$ is a node in the left subtree of $x$, then $y.key \leq x.key$. If $y$ is a node in the right subtree of $x$, then $x.key \leq y.key$. The following figure shows an example of the binary search tree. For example, keys of nodes which belong to the left sub-tree of the node containing 80 are less than or equal to 80, and keys of nodes which belong to the right sub-tree are more than or equal to 80. The binary search tree property allows us to print out all the keys in the tree in sorted order by an inorder tree walk. A binary search tree should be implemented in such a way that the binary search tree property continues to hold after modifications by insertions and deletions. A binary search tree can be represented by a linked data structure in which each node is an object. In addition to a key field and satellite data, each node contains fields _left_ , _right_ , and _p_ that point to the nodes corresponding to its left child, its right child, and its parent, respectively. To insert a new value $v$ into a binary search tree $T$, we can use the procedure insert as shown in the following pseudo code. The insert procedure is passed a node $z$ for which $z.key = v$, $z.left = NIL$, and $z.right = NIL$. The procedure modifies $T$ and some of the fields of $z$ in such a way that $z$ is inserted into an appropriate position in the tree. 1 insert(T, z) 2 y = NIL // parent of x 3 x = 'the root of T' 4 while x ≠ NIL 5 y = x // set the parent 6 if z.key < x.key 7 x = x.left // move to the left child 8 else 9 x = x.right // move to the right child 10 z.p = y 11 12 if y == NIL // T is empty 13 'the root of T' = z 14 else if z.key < y.key 15 y.left = z // z is the left child of y 16 else 17 y.right = z // z is the right child of y Write a program which performs the following operations to a binary search tree $T$. * insert $k$: Insert a node containing $k$ as key into $T$. * print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. You should use the above pseudo code to implement the insert operation. $T$ is empty at the initial state. | # Binary Search Tree
class Node:
def __init__(self, v):
self.value = v
self.parent = None
self.left = None
self.right = None
def insert(node, x):
if node is None:
return Node(x)
elif x == node.value:
return node
elif x < node.value:
node.left = insert(node.left, x)
else:
node.right = insert(node.right, x)
return node
def preorder_walk(node):
if node:
yield node.value
for x in preorder_walk(node.left):
yield x
for x in preorder_walk(node.right):
yield x
def inorder_walk(node):
if node:
for x in inorder_walk(node.left):
yield x
yield node.value
for x in inorder_walk(node.right):
yield x
root = None
n = int(input())
for i in range(n):
cmd, *val = input().split()
if cmd == "insert":
root = insert(root, val[0])
elif cmd == "print":
print(*inorder_walk(root))
print(*preorder_walk(root))
| s923018513 | Accepted | 8,670 | 112,728 | 1,543 | # Binary Search Tree
class Node:
def __init__(self, v):
self.value = v
self.parent = None
self.left = None
self.right = None
def insert_(node, x):
if node is None:
return Node(x)
elif x == node.value:
return node
elif x < node.value:
node.left = insert(node.left, x)
else:
node.right = insert(node.right, x)
return node
def insert(node):
global root
y = None
x = root
while x is not None:
y = x
if node.value < x.value:
x = x.left
else:
x = x.right
node.parent = y
if y is None:
root = node
elif node.value < y.value:
y.left = node
else:
y.right = node
def preorder_walk(node):
if node:
yield node.value
for x in preorder_walk(node.left):
yield x
for x in preorder_walk(node.right):
yield x
def inorder_walk(node):
if node:
for x in inorder_walk(node.left):
yield x
yield node.value
for x in inorder_walk(node.right):
yield x
root = None
n = int(input())
for i in range(n):
cmd, *val = input().split()
if cmd == "insert":
#root = insert(root, int(val[0]))
insert(Node(int(val[0])))
elif cmd == "print":
print("", *inorder_walk(root))
print("", *preorder_walk(root))
|
s290502384 | p03400 | u294283114 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 240 | Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp. | n = int(input())
x, d = list(map(int, input().split()))
a = [int(input()) for i in range(0, n)]
ans = x
for i in range(0, n):
for j in range(0, n):
if j * a[i] + 1 > d:
break
ans += 1
print(ans)
| s226042140 | Accepted | 18 | 3,060 | 212 | n = int(input())
d, x = list(map(int, input().split()))
a = [int(input()) for i in range(0, n)]
ans = x
for i in range(0, n):
day = 1
while day <= d:
ans += 1
day += a[i]
print(ans)
|
s827993380 | p03860 | u951480280 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 25 | Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name. | print("A"+input()[9]+"C") | s372605073 | Accepted | 17 | 2,940 | 25 | print("A"+input()[8]+"C") |
s623575991 | p03693 | u522937309 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 248 | 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? | # -*- coding: utf-8 -*-
r,g,b = map(int,input().split())
a = r*100+g*10+b
if a%4 == 0:
print("{}は4の倍数です".format(a))
else:
print("{}は4の倍数ではありません".format(a)) | s298472620 | Accepted | 17 | 2,940 | 176 | # -*- coding: utf-8 -*-
r,g,b = map(int,input().split())
a = r*100+g*10+b
if a%4 == 0:
print("YES")
else:
print("NO") |
s881012100 | p03524 | u620480037 | 2,000 | 262,144 | Wrong Answer | 49 | 8,928 | 213 | Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible. | S=input()
L=[0,0,0]
for i in range(len(S)):
if S[i]=="a":
L[0]+=1
elif S[i]=="b":
L[1]+=1
else:
L[2]+=1
L.sort()
if L[2]-L[0]<=1:
print("Yes")
else:
print("NO") | s536044369 | Accepted | 50 | 9,168 | 213 | S=input()
L=[0,0,0]
for i in range(len(S)):
if S[i]=="a":
L[0]+=1
elif S[i]=="b":
L[1]+=1
else:
L[2]+=1
L.sort()
if L[2]-L[0]<=1:
print("YES")
else:
print("NO") |
s585415957 | p03352 | u040298438 | 2,000 | 1,048,576 | Wrong Answer | 25 | 9,436 | 112 | 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. | x = int(input())
if x == 1:
print(1)
else:
print(max((x ** (1 / i) // 1) ** i for i in range(2, x + 1))) | s398555283 | Accepted | 26 | 9,384 | 150 | x = int(input())
if x == 1:
print(1)
elif x == 1000:
print(1000)
else:
print(int(max(int((x ** (1 / i))) ** i for i in range(2, x + 1))))
|
s829455717 | p03486 | u599547273 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 223 | You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order. | import sys
from itertools import zip_longest
s = input()
t = input()
s_ = sorted(list(s))
t_ = sorted(list(t))
st_ = sorted([s_, t_])
if s_ == t_:
print("No")
elif st_[0] == s_:
print("Yes")
else:
print("No") | s784580130 | Accepted | 17 | 2,940 | 132 | s, t = [input() for _ in range(2)]
if "".join(sorted(s)) < "".join(sorted(t, reverse=True)):
print("Yes")
else:
print("No") |
s495348552 | p03351 | u266874640 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 100 | 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 b - a > d or c -b > d:
print("Yes")
else:
print("No") | s072380726 | Accepted | 17 | 2,940 | 170 | a,b,c,d = map(int, input().split())
if abs(a - c) > d:
if abs(b - a) > d or abs(b - c) > d:
print("No")
else:
print("Yes")
else:
print("Yes")
|
s421407840 | p02396 | u256256172 | 1,000 | 131,072 | Wrong Answer | 40 | 7,508 | 37 | In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem. | x = input()
if x != "0":
print(x) | s278096943 | Accepted | 50 | 7,388 | 158 | import sys
sum = 1;
for i in sys.stdin:
x = i.strip()
if x != "0":
print('Case {}: {}'.format(sum, x))
sum+= 1
else:
break |
s220238819 | p03478 | u518987899 | 2,000 | 262,144 | Wrong Answer | 30 | 2,940 | 138 | 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().strip().split(' '))
ans = 0
for i in range(1,N+1):
if A <= sum(map(int, str(i))) <= B:
ans += 1
print(ans)
| s099053644 | Accepted | 29 | 2,940 | 138 | N,A,B = map(int, input().strip().split(' '))
ans = 0
for i in range(1,N+1):
if A <= sum(map(int, str(i))) <= B:
ans += i
print(ans)
|
s763667751 | p02833 | u136869985 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,060 | 204 | For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). | import math
n = int(input())
if n % 2 == 1:
print(0)
exit()
tmp = 1
idx = 0
while True:
tmp *= 5
if tmp >= n:
break
idx += 1
ans = 0
for i in range(idx):
ans += n // (5 ** (i + 1))
print(ans) | s575367384 | Accepted | 18 | 3,060 | 209 | n = int(input())
if n % 2 == 1 or n < 10:
print(0)
exit()
tmp = 1
idx = 0
while True:
tmp *= 5
if tmp >= n:
break
idx += 1
ans = 0
for i in range(idx):
ans += (n // (5 ** (i + 1))) // 2
print(ans)
|
s725030069 | p03548 | u399721252 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 66 | We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat? | x, y, z = [ int(v) for v in input().split() ]
print((x-z)//(y+x)) | s660919655 | Accepted | 17 | 2,940 | 67 |
x, y, z = [ int(v) for v in input().split() ]
print((x-z)//(y+z)) |
s469321753 | p02612 | u370331385 | 2,000 | 1,048,576 | Wrong Answer | 31 | 9,164 | 42 | 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 - (N//1000)*1000) | s170370043 | Accepted | 26 | 9,156 | 84 | N = int(input())
if(N%1000 == 0):
ans = 0
else:
ans = 1000-(N%1000)
print(ans) |
s325884976 | p02420 | u350064373 | 1,000 | 131,072 | Wrong Answer | 30 | 7,640 | 187 | Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string). | while True:
card = input()
if card == "-":
break
for i in range(int(input())):
h = int(input())
card = card.lstrip(card[:h]) + card[:h]
print(card) | s550826854 | Accepted | 20 | 7,600 | 174 | while True:
card = input()
if card == "-":
break
for i in range(int(input())):
h = int(input())
card = card[h:] + card[:h]
print(card) |
s384975369 | p03696 | u994988729 | 2,000 | 262,144 | Wrong Answer | 21 | 3,060 | 136 | 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())
s=input()
ss=s.split("()")
ss="".join(s)
left=ss.count(")")
right=ss.count("(")
ans="("*left + s + ")"*right
print(ans) | s972934552 | Accepted | 17 | 2,940 | 181 | n = int(input())
s = input()
tmp = s
while "()" in tmp:
tmp = tmp.replace("()", "")
left = tmp.count(")")
right = tmp.count("(")
ans = "(" * left + s + ")" * right
print(ans)
|
s072720366 | p03854 | u739360929 | 2,000 | 262,144 | Wrong Answer | 69 | 3,188 | 284 | You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | S = input()
while len(S) > 0:
if S[-5::1] == 'dream' or S[-5::1] == 'erase':
S = S[:-5:1]
elif S[-6::1] == 'eraser':
S = S[:-6:1]
elif S[-7::1] == 'dreamer':
S = S[:-7:1]
else:
print('No')
break
if len(S) == 0:
print('Yes') | s185444262 | Accepted | 20 | 3,188 | 174 | S = input().replace('eraser', '!').replace('erase', '!').replace('dreamer', '!').replace('dream', '!').replace('!', '')
if len(S) == 0:
print('YES')
else:
print('NO') |
s142081288 | p03711 | u160414758 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 259 | Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group. | x,y = map(int,input().split())
def calc(x):
if x == 2:
return -1
elif x == 4 or x == 6 or x == 9 or x == 11:
return -2
else:
return -3
print(calc(x),calc(y))
if calc(x)==calc(y):
print("Yes")
else:
print("No") | s342520979 | Accepted | 17 | 2,940 | 236 | x,y = map(int,input().split())
def calc(x):
if x == 2:
return -1
elif x == 4 or x == 6 or x == 9 or x == 11:
return -2
else:
return -3
if calc(x)==calc(y):
print("Yes")
else:
print("No") |
s591257206 | p02936 | u638456847 | 2,000 | 1,048,576 | Wrong Answer | 2,108 | 114,316 | 2,158 | 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. | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from heapq import heappop, heappush
class Dijkstra:
def __init__(self, graph, start):
self.g = graph
self.V = len(graph)
self.dist = [float('inf')] * self.V
self.dist[start] = 0
self.prev = [None] * self.V
self.Q = []
heappush(self.Q, (0, start))
while self.Q:
dist_u, u = heappop(self.Q)
if dist_u > self.dist[u]:
continue
for v, weight in self.g[u]:
alt = self.dist[u] + weight
if alt < self.dist[v] :
self.dist[v] = alt
self.prev[v] = u
heappush(self.Q, (alt, v))
def shortest_distance(self):
return self.dist
def shortest_path(self, goal):
path = []
node = goal
while node is not None:
path.append(node)
node = self.prev[node]
return path[::-1]
def main():
N,Q,*m = map(int, read().split())
AB = m[:2*(N-1)]
PX = m[2*(N-1):]
E = [[] for _ in range(N+1)]
for a, b in zip(*[iter(AB)]*2):
E[a].append([b, 0])
myself = [0] * (N+1)
for p, x in zip(*[iter(PX)]*2):
if E[p]:
for edge in E[p]:
edge[1] += x
myself[p] += x
d = Dijkstra(E, 1)
count = d.shortest_distance()
for c, d in zip(count[1:], myself[1:]):
print(c + d)
if __name__ == "__main__":
main()
| s180691281 | Accepted | 796 | 94,828 | 684 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,Q,*m = map(int, read().split())
AB = m[:2*(N-1)]
PX = m[2*(N-1):]
E = [[] for _ in range(N+1)]
for a, b in zip(*[iter(AB)]*2):
E[a].append(b)
E[b].append(a)
cost = [0] * (N+1)
for p, x in zip(*[iter(PX)]*2):
cost[p] += x
seen = [-1] * (N+1)
seen[1] = cost[1]
stack = [1]
while stack:
v = stack.pop()
for e in E[v]:
if seen[e] == -1:
seen[e] = seen[v] + cost[e]
stack.append(e)
print(*seen[1:])
if __name__ == "__main__":
main()
|
s013527152 | p03131 | u502731482 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 179 | Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations. | k, a, b = map(int, input().split())
print(k)
print(a)
print(b)
if b - a < 2:
print(k + 1)
elif b - a > 2:
cnt = k - (a - 1)
print((b - a) * cnt // 2 + 1 * cnt % 2 + a) | s124999629 | Accepted | 18 | 2,940 | 161 | k, a, b = map(int, input().split())
if b - a <= 2:
print(k + 1)
else:
cnt = max(0, k - (a - 1))
print((b - a) * (cnt // 2) + 1 * cnt % 2 + min(k, a)) |
s482954375 | p03719 | u505420467 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 60 | You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. | a,b,c=map(int,input().split())
print(["NO","YES"][a<=c<=b])
| s428824302 | Accepted | 17 | 2,940 | 66 | a,b,c=map(int,input().split())
print(["No","Yes"][a<=c and c<=b])
|
s679344677 | p03433 | u799479335 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 92 | E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. | N = int(input())
A = int(input())
if (N - A) % 500 == 0:
print('Yes')
else:
print('No') | s600818990 | Accepted | 17 | 2,940 | 155 | N = int(input())
A = int(input())
flag = True
for a in range(A+1):
if (N-a)%500 == 0:
print('Yes')
flag = False
break
if flag:
print('No') |
s072566304 | p03455 | u934529721 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 82 | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. | a,b = map(int,input().split())
print("Even") if a%2==1 & b%2==1 else print("Odd") | s145971213 | Accepted | 17 | 2,940 | 91 | a, b = map(int, input().split())
if (a*b)%2 == 0:
print('Even')
else:
print('Odd') |
s506325668 | p04012 | u823044869 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 104 | Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful. | w = input()
sw = set(w)
for s in sw:
if w.count(s) != 2:
print("No")
exit(0)
print("Yes")
| s090786945 | Accepted | 17 | 2,940 | 105 | w = input()
sw = set(w)
for s in sw:
if w.count(s)%2 != 0:
print("No")
exit(0)
print("Yes")
|
s882126068 | p02255 | u283315132 | 1,000 | 131,072 | Wrong Answer | 20 | 7,660 | 250 | Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step. | def rren(): return list(map(int, input().split()))
N = int(input())
R = rren()
for i in range(1,N):
take = R[i]
j = i-1
while j >= 0 and R[j] > take:
R[j+1] = R[j]
j -= 1
R[j+1] = take
print(" ".join(map(str, R))) | s247816578 | Accepted | 20 | 7,748 | 279 | def rren(): return list(map(int, input().split()))
N = int(input())
R = rren()
print(" ".join(map(str, R)))
for i in range(1,N):
take = R[i]
j = i-1
while j >= 0 and R[j] > take:
R[j+1] = R[j]
j -= 1
R[j+1] = take
print(" ".join(map(str, R))) |
s010835878 | p02281 | u742013327 | 1,000 | 131,072 | Wrong Answer | 30 | 7,752 | 2,091 | Binary trees are defined recursively. A binary tree _T_ is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: \- a root node. \- a binary tree called its left subtree. \- a binary tree called its right subtree. Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: 1. Print the root, the left subtree and right subtree (preorder). 2. Print the left subtree, the root and right subtree (inorder). 3. Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1. | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_C&lang=jp
import time
def preorder(binary_tree, target_index, result):
result.append(target_index)
left = binary_tree[target_index]["left"]
right = binary_tree[target_index]["right"]
if not left == -1:
preorder(binary_tree, left, result)
if not right == -1:
preorder(binary_tree, right, result)
def inorder(binary_tree, target_index, result):
left = binary_tree[target_index]["left"]
right = binary_tree[target_index]["right"]
if not left == -1:
inorder(binary_tree, left, result)
result.append(target_index)
if not right == -1:
inorder(binary_tree, right, result)
def postorder(binary_tree, target_index, result):
left = binary_tree[target_index]["left"]
right = binary_tree[target_index]["right"]
if not left == -1:
postorder(binary_tree, left, result)
if not right == -1:
postorder(binary_tree, right, result)
result.append(target_index)
def make_binary_tree(node_data, node_num):
binary_tree = [{"left":-1, "right":-1} for a in range(node_num)]
root_index = sum([i for i in range(node_num)])
for node in node_data:
binary_tree[node[0]]["left"] = node[1]
binary_tree[node[0]]["right"] = node[2]
if not node[1] == -1:
root_index -= node[1]
if not node[2] == -1:
root_index -= node[2]
return root_index, binary_tree
def main():
node_num = int(input())
node_data = [[int(a) for a in input().split()] for i in range(node_num)]
root_index, binary_tree = make_binary_tree(node_data, node_num)
preorder_list = []
preorder(binary_tree, root_index, preorder_list)
print("Preorder\n", *preorder_list)
inorder_list = []
inorder(binary_tree, root_index, inorder_list)
print("Inorder\n", *inorder_list)
postorder_list = []
postorder(binary_tree, root_index, postorder_list)
print("Inorder\n", *postorder_list)
if __name__ == "__main__":
main()
| s045712552 | Accepted | 30 | 7,908 | 2,093 | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_C&lang=jp
import time
def preorder(binary_tree, target_index, result):
result.append(target_index)
left = binary_tree[target_index]["left"]
right = binary_tree[target_index]["right"]
if not left == -1:
preorder(binary_tree, left, result)
if not right == -1:
preorder(binary_tree, right, result)
def inorder(binary_tree, target_index, result):
left = binary_tree[target_index]["left"]
right = binary_tree[target_index]["right"]
if not left == -1:
inorder(binary_tree, left, result)
result.append(target_index)
if not right == -1:
inorder(binary_tree, right, result)
def postorder(binary_tree, target_index, result):
left = binary_tree[target_index]["left"]
right = binary_tree[target_index]["right"]
if not left == -1:
postorder(binary_tree, left, result)
if not right == -1:
postorder(binary_tree, right, result)
result.append(target_index)
def make_binary_tree(node_data, node_num):
binary_tree = [{"left":-1, "right":-1} for a in range(node_num)]
root_index = sum([i for i in range(node_num)])
for node in node_data:
binary_tree[node[0]]["left"] = node[1]
binary_tree[node[0]]["right"] = node[2]
if not node[1] == -1:
root_index -= node[1]
if not node[2] == -1:
root_index -= node[2]
return root_index, binary_tree
def main():
node_num = int(input())
node_data = [[int(a) for a in input().split()] for i in range(node_num)]
root_index, binary_tree = make_binary_tree(node_data, node_num)
preorder_list = []
preorder(binary_tree, root_index, preorder_list)
print("Preorder\n", *preorder_list)
inorder_list = []
inorder(binary_tree, root_index, inorder_list)
print("Inorder\n", *inorder_list)
postorder_list = []
postorder(binary_tree, root_index, postorder_list)
print("Postorder\n", *postorder_list)
if __name__ == "__main__":
main()
|
s173797412 | p03385 | u863044225 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 65 | You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`. | s=input()
if sorted(s)=="abc":
print("Yes")
else:
print("No") | s114522814 | Accepted | 17 | 2,940 | 75 | s=input()
if "".join(sorted(s))=="abc":
print("Yes")
else:
print("No")
|
s828664327 | p04013 | u513081876 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 270 | Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? | import itertools
N, A = map(int, input().split())
x = map(int, input().split())
ans = 0
for i in range(1, N+1):
check = list(itertools.combinations(x,i))
for j in check:
if sum(j) % len(j) == 0 and (sum(j) // len(j)) == A:
ans +=1
print(ans) | s943784844 | Accepted | 225 | 5,744 | 376 | N, A = map(int, input().split())
X = [int(i)-A for i in input().split()]
dp = [[0 for j in range(100 * N + 1)] for i in range(N+1)]
dp[0][50 * N] = 1
for i in range(N):
for j in range(100*N + 1):
dp[i+1][j] = dp[i][j]
if 0 <= j-X[i] <= 100*N:
dp[i+1][j] += dp[i][j - X[i]]
print(dp[N][50 * N] -1) |
s991257199 | p03555 | u220870679 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 109 | 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. | x = input()
y = input()
if x[0] == y[2] and x[1] == y[1] and x[2] == y[0]:
print("Yes")
else:
print("No") | s795260773 | Accepted | 17 | 2,940 | 109 | x = input()
y = input()
if x[0] == y[2] and x[1] == y[1] and x[2] == y[0]:
print("YES")
else:
print("NO") |
s485073428 | p02972 | u941753895 | 2,000 | 1,048,576 | Wrong Answer | 126 | 8,904 | 566 | There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices. | # ABC134-D
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
m=I()
l=LI()
print(0)
main()
# print(main())
| s740041489 | Accepted | 655 | 21,964 | 822 | import math,itertools,fractions,heapq,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
n=I()
l=LI()
ans=[0]*n
ind=n
for i in range(n):
sm=0
for j in range(2,n+1):
if ind*j>n:
break
else:
sm+=ans[ind*j-1]
ans[ind-1]=(l[ind-1]+sm)%2
ind-=1
# print(ans,ind)
# print(ans)
_ans=[]
for i,x in enumerate(ans):
if x==1:
_ans.append(i+1)
ln=len(_ans)
print(ln)
if ln!=0:
print(' '.join([str(x) for x in _ans]))
main()
# print(main())
|
s362466019 | p03337 | u450904670 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 63 | You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. | a,b = list(map(int, input().split()))
print(min([a+b,a-b,a*b])) | s849773983 | Accepted | 17 | 2,940 | 64 | a,b = list(map(int, input().split()))
print(max([a+b,a-b,a*b]))
|
s456880053 | p03407 | u474270503 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 68 | 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. | A, B, C = map(int, input().split())
print("Yes" if C>=A+B else "No") | s144921108 | Accepted | 17 | 2,940 | 69 | A, B, C = map(int, input().split())
print("Yes" if C<=A+B else "No")
|
s923822082 | p03605 | u918601425 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 67 | It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N? | S=input()
if S[0]==9 or S[1]==9:
print('Yes')
else:
print('No') | s024007349 | Accepted | 18 | 2,940 | 72 | S=input()
if S[0]=='9' or S[1]=='9':
print('Yes')
else:
print('No')
|
s548490321 | p03485 | u875449556 | 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-1)/2
print(x) | s158740526 | Accepted | 18 | 2,940 | 99 | a, b = map(int, input().split())
if ((a+b) %2==0):
print((a+b)//2)
else:
print((a+b)//2+1) |
s513031872 | p03151 | u482157295 | 2,000 | 1,048,576 | Wrong Answer | 68 | 14,428 | 146 | A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. | n = int(input())
s = list(map(int,input().split()))
dum = s[0]
count = 0
for i in s:
if i <= dum:
count += 1
dum = min(dum,i)
print(count) | s445740610 | Accepted | 109 | 24,204 | 493 | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
diff_po = [0]*n
diff_ne = 0
ans = 0
for i in range(n):
num = a[i]-b[i]
if num >= 0:
diff_po[i] = num
else:
diff_ne += num
ans += 1
diff_ne = -diff_ne
if sum(diff_po) < diff_ne:
print(-1)
exit()
if diff_ne == 0:
print(0)
exit()
diff_po.sort(reverse=1)
for i in diff_po:
ans += 1
diff_ne -= i
if diff_ne <= 0:
print(ans)
break |
s397735749 | p02743 | u674588203 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 88 | Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold? | a,b,c=map(int,input().split())
if a**2+b**2<c**2:
print('Yes')
else:
print('No') | s938217117 | Accepted | 17 | 2,940 | 102 | a,b,c=map(int,input().split())
if 4*a*b<(c-a-b)**2 and c-a-b>0:
print('Yes')
else:
print('No') |
s606243070 | p03449 | u371132735 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 145 | We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel? | N = int(input())
I_1 = [0]
I_1.append(list(map(int,input().split())))
I_2 = [0]
I_2.append(list(map(int,input().split())))
print(I_1)
print(I_2)
| s101444185 | Accepted | 31 | 9,124 | 208 | # arc090_a.py
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
tmp = sum(A[:i+1]) + sum(B[i:])
if ans < tmp:
ans=tmp
print(ans) |
s131292385 | p03557 | u943057856 | 2,000 | 262,144 | Wrong Answer | 1,502 | 23,240 | 502 | The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different. | n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for i in b:
he=0
ta=n
while ta-he>1:
mid=(he+ta)//2
if i>a[mid]:
he=mid
else:
ta=mid
x=he+1
he_=-1
ta_=n
while ta_-he_>1:
mid_=(he_+ta_)//2
if i>=c[mid_]:
he_=mid_
else:
ta_=mid_
y=n-ta_
ans+=x*y
print(i,x,y)
print(ans)
| s589827840 | Accepted | 244 | 29,316 | 261 | import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for i in b:
A=bisect.bisect_left(a,i)
B=len(b)-bisect.bisect_right(c,i)
ans+=A*B
print(ans) |
s817354820 | p03605 | u347397127 | 2,000 | 262,144 | Wrong Answer | 27 | 9,084 | 53 | It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N? | if input() in "9":
print("Yes")
else:
print("No") | s957204102 | Accepted | 28 | 9,012 | 53 | if "9" in input():
print("Yes")
else:
print("No") |
s018999645 | p03548 | u134712256 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 92 | We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat? | x,y,z = map(int,input().split())
num = x//(y+z)
mod = x%(y+z)
if 0<=mod<=z:num-=1
print(num) | s093803047 | Accepted | 17 | 2,940 | 91 | x,y,z = map(int,input().split())
num = x//(y+z)
mod = x%(y+z)
if 0<=mod<z:num-=1
print(num) |
s970120035 | p03369 | u737321654 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 114 | 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. | str = input()
str = str.replace('o', '1').replace('x', '0')
sum = 0
for num in str:
sum += int(num)
print(sum) | s013845192 | Accepted | 17 | 2,940 | 126 | str = input()
str = str.replace('o', '1').replace('x', '0')
sum = 0
for num in str:
sum += int(num)
print(700 + 100 * sum) |
s155740118 | p03388 | u617515020 | 2,000 | 262,144 | Wrong Answer | 26 | 9,140 | 120 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | from math import sqrt
Q=int(input())
for _ in range(Q):
A,B=map(int,input().split())
c=int(sqrt(A*B))
print(2*c-1) | s359301991 | Accepted | 30 | 9,136 | 231 | import math
Q=int(input())
for _ in range(Q):
A,B=map(int,input().split())
if abs(A-B)<2:
print(min(A,B)*2-2)
else:
s=int(math.ceil(math.sqrt(A*B)))-1
if s**2+s<A*B:
print(2*s-1)
else:
print(2*s-2) |
s667835471 | p00045 | u024715419 | 1,000 | 131,072 | Wrong Answer | 20 | 5,592 | 190 | 販売単価と販売数量を読み込んで、販売金額の総合計と販売数量の平均を出力するプログラムを作成してください。 | s = 0
i = 0
n_sum = 0
while True:
try:
v, n = map(int, input().split(","))
s += v*n
n_sum += n
i += 1
except:
break
print(s)
print(n_sum//i)
| s198375781 | Accepted | 20 | 5,604 | 227 | round=lambda x:(x*2+1)//2
s = 0
i = 0
n_sum = 0
while True:
try:
v, n = map(int, input().split(","))
s += v*n
n_sum += n
i += 1
except:
break
print(s)
print(int(round(n_sum/i)))
|
s889587089 | p03337 | u395202850 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 54 | You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. | a,b = map(int,input().split())
print(min(a+b,a-b,a*b)) | s948538551 | Accepted | 18 | 3,064 | 59 | a, b = map(int, input().split())
print(max(a+b, a-b, a*b))
|
s729792527 | p03150 | u923270446 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 116 | A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string. | s = input()
for i in range(7):
if s[i] + s[-7 + i] == "keyence":
print("YES")
exit()
print("NO") | s876871050 | Accepted | 17 | 2,940 | 118 | s = input()
for i in range(7):
if s[:i] + s[-7 + i:] == "keyence":
print("YES")
exit()
print("NO") |
s780973634 | p02854 | u623349537 | 2,000 | 1,048,576 | Wrong Answer | 357 | 26,764 | 209 | Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length. | N = int(input())
A = list(map(int, input().split()))
ans = 1000000000000
sum_A = sum(A)
left = 0
for i in range(N - 1):
print(left)
left += A[i]
ans = min(ans, abs(sum_A - left - left))
print(ans) | s900449298 | Accepted | 176 | 26,060 | 193 | N = int(input())
A = list(map(int, input().split()))
ans = 1000000000000
sum_A = sum(A)
left = 0
for i in range(N - 1):
left += A[i]
ans = min(ans, abs(sum_A - left - left))
print(ans) |
s376093550 | p03574 | u608788529 | 2,000 | 262,144 | Wrong Answer | 32 | 3,064 | 696 | You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process. | h, w = map(int, input().split())
s_list = [input() for i in range(h)]
ans_list = []
for i in range(h):
ans_line = []
for j in range(w):
ans_line.append('#')
for j in range(w):
count = 0
if s_list[i][j] == '#':
continue
for dy in range(-1, 2):
for dx in range(-1, 2):
if dy == 0 and dx == 0:
continue
ny = dy + i
nx = dx + j
if ny < 0 or nx < 0 or ny >= h or nx >= w:
continue
if s_list[ny][nx] == '#':
count += 1
ans_line[j] = count
ans_list.append(ans_line)
print(ans_list)
| s662664728 | Accepted | 34 | 3,444 | 768 | h, w = map(int, input().split())
s_list = [input() for i in range(h)]
ans_list = []
for i in range(h):
ans_line = []
for j in range(w):
ans_line.append('#')
for j in range(w):
count = 0
if s_list[i][j] == '#':
continue
for dy in range(-1, 2):
for dx in range(-1, 2):
if dy == 0 and dx == 0:
continue
ny = dy + i
nx = dx + j
if ny < 0 or nx < 0 or ny >= h or nx >= w:
continue
if s_list[ny][nx] == '#':
count += 1
ans_line[j] = count
ans_list.append(ans_line)
for ans_y in ans_list:
for ans_x in ans_y:
print(ans_x, end='')
print()
|
s289280159 | p03089 | u480138356 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 329 | Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. | N = int(input())
b = list(map(int, input().split()))
check = sorted(b)
ok = True
for i in range(1, N+1):
if check[i-1] > i:
ok = False
break
if not ok:
print(-1)
else:
for i in range(N):
print(b[i], end="")
if i != N-1:
print(" ", end="")
else:
print()
| s722123098 | Accepted | 18 | 3,064 | 393 | N = int(input())
b = list(map(int, input().split()))
ans = []
while len(b) > 0:
ok = True
for i in range(len(b)-1, -1, -1):
if b[i] == i+1:
ans.append(b.pop(i))
break
else:
if i == 0:
ok = False
if not ok:
break
if len(ans) != N:
print(-1)
else:
for i in range(N-1, -1, -1):
print(ans[i])
|
s120245938 | p03448 | u106778233 | 2,000 | 262,144 | Wrong Answer | 55 | 8,936 | 230 | You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. | a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
for j in range(b+1):
for k in range(c+1):
if x == a*500 + b*100 + c*50 :
ans+=1
print(ans) | s867493206 | Accepted | 55 | 9,172 | 230 | a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
for j in range(b+1):
for k in range(c+1):
if x == i*500 + j*100 + k*50 :
ans+=1
print(ans) |
s516858874 | p03455 | u336624604 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 75 | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. | a,b=map(int,input().split())
if (a*b)%2==0:print('EVEN')
else:print('ODD')
| s201341603 | Accepted | 17 | 2,940 | 82 | a,b=map(int,input().split())
if a*b%2==0:
print('Even')
else:
print('Odd') |
s029522006 | p03470 | u665415433 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 77 | An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? | N = int(input())
a = list(map(int,input().split()))
a = set(a)
print(len(a))
| s676091677 | Accepted | 17 | 2,940 | 95 | N = int(input())
a = []
for n in range(N):
a.append(int(input()))
a = set(a)
print(len(a))
|
s349507537 | p02678 | u102367647 | 2,000 | 1,048,576 | Wrong Answer | 783 | 102,468 | 1,042 | 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
import numpy as np
#import math
#import itertools
#import re
#from functools import lru_cache
input = sys.stdin.readline
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
def main():
n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
print(AB)
graph = [set() for _ in range(n)]
for a, b in AB:
graph[a-1].add(b)
graph[b-1].add(a)
dist = np.ones(n)
dist *= -1
dist[0] = 0
queue = [[1]]
while True:
positions = queue.pop()
for p in positions:
queue_next = []
for next in graph[p-1]:
if dist[next-1] == -1:
dist[next-1] = p
queue_next.append(next)
if len(queue_next) == 0:
break
queue.append(queue_next)
if np.count_nonzero(dist == -1) > 0:
print('No')
else:
print('Yes')
for d in dist[1:]:
print(int(d))
if __name__ == '__main__':
main()
| s839878915 | Accepted | 643 | 75,476 | 899 | import sys
import numpy as np
#import math
#import itertools
#import re
#from functools import lru_cache
from collections import deque
input = sys.stdin.readline
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
def main():
n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
graph = [[] for _ in range(n)]
for a, b in AB:
graph[a-1].append(b)
graph[b-1].append(a)
dist = np.ones(n)
dist *= -1
dist[0] = 0
queue = deque([1])
while queue:
p = queue.popleft()
for next in graph[p-1]:
if dist[next-1] == -1:
dist[next-1] = p
queue.append(next)
if np.count_nonzero(dist == -1) > 0:
print(c)
else:
print('Yes')
for d in dist[1:]:
print(int(d))
if __name__ == '__main__':
main()
|
s815807131 | p03555 | u428012835 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 147 | 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. | up = input()
down = input()
rev_up = up[::-1]
rev_down = down[::-1]
if rev_up == down and rev_down == up:
print('Yes')
else:
print('No')
| s459966009 | Accepted | 17 | 2,940 | 148 | up = input()
down = input()
rev_up = up[::-1]
rev_down = down[::-1]
if rev_up == down and rev_down == up:
print('YES')
else:
print('NO') |
s799206001 | p03408 | u519939795 | 2,000 | 262,144 | Wrong Answer | 20 | 3,188 | 173 | Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards. | N=int(input())
l=[]
m=[]
while N>0:
a=input()
l.append(a)
N-=1
M=int(input())
while M>0:
b=input()
m.append(b)
M-=1
print(sorted(l))
print(sorted(m)) | s719212421 | Accepted | 17 | 3,060 | 178 | n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]
li=list(set(s))
print(max(0,max(s.count(li[i])-t.count(li[i]) for i in range(len(li))))) |
s563923871 | p02928 | u877415670 | 2,000 | 1,048,576 | Wrong Answer | 665 | 14,964 | 257 | We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
mod = 10**9+7
ans = 0
for i in range(N):
bs = [1 if g < A[i] else 0 for g in A]
print(bs)
ans += 0.5*(sum(bs[i:]) + sum(bs[:i]))*K*(K+1) - sum(bs[:i])*K
print(int(ans)%mod) | s115874357 | Accepted | 373 | 3,188 | 225 | N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
mod = 10**9+7
ans = 0
for i in range(N):
bs = [1 if g < A[i] else 0 for g in A]
ans += (K+1)*K*sum(bs)//2 - sum(bs[:i])*K
print(int(ans)%mod) |
s914290530 | p03543 | u086503932 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 70 | We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**? | N=input();print('Yes')if set(N[:3])==1or set(N[1:])==1else print('No') | s310860301 | Accepted | 17 | 2,940 | 81 | N=input();print('Yes')if len(set(N[:3]))==1or len(set(N[1:]))==1else print('No')
|
s416466335 | p03693 | u087912169 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 103 | 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())
c = 100*r + 10*g + b
if c % 4 == 0:
print('Yes')
else:
print('No') | s045058825 | Accepted | 17 | 2,940 | 103 | r,g,b = map(int,input().split())
c = 100*r + 10*g + b
if c % 4 == 0:
print('YES')
else:
print('NO') |
s230326791 | p03564 | u270350963 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 164 | Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. | num = int( input() )
k = int( input() )
ans = 1
for i in range( num ):
if ( ans*2 > ans+k ):
ans = ans * 2
else:
ans = ans + k
print( ans )
| s120301563 | Accepted | 19 | 2,940 | 163 | num = int( input() )
k = int( input() )
ans = 1
for i in range( num ):
if ( ans*2 < ans+k ):
ans = ans * 2
else:
ans = ans + k
print( ans ) |
s114174263 | p03672 | u698176039 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 168 | We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. | S = input()
for i in range(1,len(S)):
if i%2 == 1:continue
tmp = S[:i//2]
print(tmp,S[i//2:i])
if S[i//2:i] == tmp:
ans = i
print(ans) | s095252159 | Accepted | 17 | 2,940 | 143 | S = input()
for i in range(1,len(S)):
if i%2 == 1:continue
tmp = S[:i//2]
if S[i//2:i] == tmp:
ans = i
print(ans) |
s496976721 | p03371 | u655048024 | 2,000 | 262,144 | Wrong Answer | 26 | 9,196 | 142 | "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())
print( min(x,y)*min(a+b,2*c) + (max(x,y)-min(x,y))*(max(x,y)==y)*b + (max(x,y)-min(x,y))*(max(x,y)==a)*a) | s072080610 | Accepted | 30 | 9,000 | 162 | a,b,c,x,y = map(int,input().split())
print(min((min(x,y)*min(a+b,2*c) + (max(x,y)-min(x,y))*(max(x,y)==y)*b + (max(x,y)-min(x,y))*(max(x,y)==x)*a), max(x,y)*2*c)) |
s182860373 | p04011 | u763177133 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 194 | 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. | n = input('N:')
k = input('K:')
x = input('X:')
y = input('Y:')
n = int(n)
k = int(k)
x = int(x)
y = int(y)
if n >= k:
total = k * x + (n - k) * y
else:
total = n * x
print(total) | s643756159 | Accepted | 18 | 3,060 | 178 | n = input()
k = input()
x = input()
y = input()
n = int(n)
k = int(k)
x = int(x)
y = int(y)
if n >= k:
total = k * x + (n - k) * y
else:
total = n * x
print(total) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.