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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s889313206
|
p03505
|
u846552659
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 186 |
_ButCoder Inc._ runs a programming competition site called _ButCoder_. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rating is 0, and a user whose rating reaches K or higher is called _Kaiden_ ("total transmission"). Note that a user's rating may become negative. Hikuhashi is a new user in ButCoder. It is estimated that, his rating increases by A in each of his odd-numbered contests (first, third, fifth, ...), and decreases by B in each of his even-numbered contests (second, fourth, sixth, ...). According to this estimate, after how many contests will he become Kaiden for the first time, or will he never become Kaiden?
|
# -*- coding:utf-8 -*-
import math
k,a,b = map(int, input().split())
if a >= k:
print(1)
else:
if a <= b:
print(-1)
else:
print((2*math.floor((k-a)/(a-b)))+1)
|
s307346955
|
Accepted
| 117 | 5,588 | 219 |
# -*- coding:utf-8 -*-
from decimal import *
import math
k,a,b = map(int, input().split())
if a >= k:
print(1)
else:
if a <= b:
print(-1)
else:
print(2*math.ceil(Decimal(k-a)/Decimal(a-b))+1)
|
s760695107
|
p02613
|
u359752656
| 2,000 | 1,048,576 |
Wrong Answer
| 140 | 16,264 | 258 |
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
N = int(input())
S = [input() for _ in range(N)]
A = S.count("AC")
B = S.count("WA")
C = S.count("TLE")
D = S.count("RE")
print("AC"+"×" + str(A))
print("WA"+"×" + str(B))
print("TLE"+"×" + str(C))
print("RE"+"×" + str(D))
|
s100531762
|
Accepted
| 139 | 16,200 | 253 |
N = int(input())
S = [input() for _ in range(N)]
A = S.count("AC")
B = S.count("WA")
C = S.count("TLE")
D = S.count("RE")
print("AC", "x", str(A))
print("WA", "x", str(B))
print("TLE", "x", str(C))
print("RE", "x", str(D))
|
s126226989
|
p03477
|
u178432859
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 129 |
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
a,b,c,d = map(int, input().split())
if a+b > c+d:
print("Left")
if a+b == c+d:
print("Balanced")
else:
print("Right")
|
s250807120
|
Accepted
| 17 | 3,060 | 131 |
a,b,c,d = map(int, input().split())
if a+b > c+d:
print("Left")
elif a+b == c+d:
print("Balanced")
else:
print("Right")
|
s600156150
|
p03693
|
u630566616
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 89 |
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
r,g,b=map(int,input().split())
if (r*100+g*10+b)%4==0:
print("Yes")
else:
print("No")
|
s012169142
|
Accepted
| 17 | 2,940 | 76 |
r,g,b=input().split()
if int(r+g+b)%4==0:
print("YES")
else:
print("NO")
|
s551865630
|
p02413
|
u131984977
| 1,000 | 131,072 |
Wrong Answer
| 30 | 6,720 | 343 |
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
|
(r, c) = [int(i) for i in input().split()]
ct = [0 for d in range(c)]
tmp = []
for rc in range(r):
tmp = [int(i) for i in input().split()]
total = 0
for cc in range(c):
ct[cc] += tmp[cc]
total += tmp[cc]
print(tmp[cc], end=' ')
print(total)
total = sum(ct)
print(' '.join([str(i) for i in tmp]), total)
|
s497274723
|
Accepted
| 30 | 7,644 | 338 |
r, c = [int(i) for i in input().split()]
data = []
sum_row = [0] * (c + 1)
for ri in range(r):
data.append([int(i) for i in input().split()])
data[ri].append(sum(data[ri]))
print(" ".join([str(d) for d in data[ri]]))
for ci in range(c + 1):
sum_row[ci] += data[ri][ci]
print(" ".join([str(s) for s in sum_row]))
|
s067697793
|
p03567
|
u357630630
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 38 |
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
|
print(["Yes", "No"]["AC" in input()])
|
s096809320
|
Accepted
| 17 | 2,940 | 38 |
print(["No", "Yes"]["AC" in input()])
|
s560755927
|
p02399
|
u446066125
| 1,000 | 131,072 |
Wrong Answer
| 30 | 6,744 | 91 |
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
|
(a, b) = [int(i) for i in input().split()]
d = a // b
r = a % b
f = a / b
print(d, r, f)
|
s303090541
|
Accepted
| 30 | 6,748 | 112 |
(a, b) = [int(i) for i in input().split()]
d = int(a / b)
r = a % b
f = a / b
print('%s %s %.5f' % (d, r, f))
|
s860267706
|
p02612
|
u243312682
| 2,000 | 1,048,576 |
Wrong Answer
| 31 | 9,152 | 109 |
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.
|
def main():
n = int(input())
ans = n % 1000
print(ans)
if __name__ == '__main__':
main()
|
s649547638
|
Accepted
| 32 | 9,144 | 176 |
def main():
n = int(input())
if n % 1000 == 0:
ans = 0
else:
ans = ans = 1000 - (n % 1000)
print(ans)
if __name__ == '__main__':
main()
|
s800757482
|
p03370
|
u644516473
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 99 |
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
|
n, x = map(int, input().split())
m = [int(input()) for _ in range(n)]
print(sum(m) + max(m)*(x-n))
|
s383233321
|
Accepted
| 17 | 2,940 | 103 |
n, x = map(int, input().split())
m = [int(input()) for _ in range(n)]
print(n + (x - sum(m))//min(m))
|
s522223506
|
p00481
|
u028939600
| 8,000 | 131,072 |
Wrong Answer
| 70 | 8,004 | 2,003 |
今年も JOI 町のチーズ工場がチーズの生産を始め,ねずみが巣から顔を出した.JOI 町は東西南北に区画整理されていて,各区画は巣,チーズ工場,障害物,空き地のいずれかである.ねずみは巣から出発して全てのチーズ工場を訪れチーズを 1 個ずつ食べる. この町には,N 個のチーズ工場があり,どの工場も1種類のチーズだけを生産している.チーズの硬さは工場によって異なっており,硬さ 1 から N までのチーズを生産するチーズ工場がちょうど 1 つずつある. ねずみの最初の体力は 1 であり,チーズを 1 個食べるごとに体力が 1 増える.ただし,ねずみは自分の体力よりも硬いチーズを食べることはできない. ねずみは,東西南北に隣り合う区画に 1 分で移動することができるが,障害物の区画には入ることができない.チーズ工場をチーズを食べずに通り過ぎることもできる.すべてのチーズを食べ終えるまでにかかる最短時間を求めるプログラムを書け.ただし,ねずみがチーズを食べるのにかかる時間は無視できる.
|
field = [[4,5,2],[".","X",".",".",1],[".",".",".",".","X"],[".","X","X",".","S"],[".",2,".","X","."]]
for i in range(len(field) - 1):
for j in range(len(field[1])):
if field[i+1][j] == "S":
start_x = j
start_y = i + 1
break
print(start_x,start_y)
def proceed(field,start_x,start_y,start_n,start_N,goal_N):
# print("start[x]",start_x)
# print("start[y]",start_y)
x = [-1,0,1,0]
y = [0,-1,0,1]
next_x = []
next_y = []
next_N = []
# print("s_parameters",start_x,start_y,start_N,start_n,goal_N)
for s_x,s_y,s_N in zip(start_x,start_y,start_N):
for p_x,p_y in zip(x,y):
if 1 <= s_y + p_y < len(field):
#print("y",s_y + p_y)
if 0 <= s_x + p_x < len(field[1]):
#print("x",s_x + p_x)
if field[s_y + p_y][s_x + p_x] != "X":
# print("x",s_x + p_x)
# print("y",s_y + p_y)
next_x.append(s_x + p_x)
next_y.append(s_y + p_y)
# print("[x]",next_x)
# print("[y]",next_y)
if field[s_y + p_y][s_x + p_x] == goal_N:
# print("GOAL_STATE",s_N)
next_N.append(s_N)
if s_N == goal_N:
# print("check",s_N,goal_N,start_N)
print("result",start_n + 1)
return
elif field[s_y + p_y][s_x + p_x] == s_N:
next_N.append(s_N + 1)
# print("EAT CHEESE",next_N)
else:
next_N.append(s_N)
# print("next_N",next_N)
next_n = start_n + 1
proceed(field,next_x,next_y,next_n,next_N,goal_N)
proceed(field,[start_x],[start_y],0,[1],field[0][2])
|
s796180594
|
Accepted
| 8,070 | 36,896 | 1,561 |
def bfs(field,H,W,start_x,start_y,tmp_N):
direction = [[-1,0],[1,0],[0,-1],[0,1]]
que = []
que.append([start_x,start_y])
INF = 1000000
min_path = [[INF] * W for i in range(H)]
min_path[start_y][start_x] = 0
while len(que) != 0:
current = que.pop(0)
for d in direction:
nx = current[0] + d[0]
ny = current[1] + d[1]
if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
min_path[ny][nx] = min_path[current[1]][current[0]] + 1
if field[ny][nx] == tmp_N:
return nx,ny,min_path[ny][nx]
else:
que.append([nx,ny])
def getField():
matrix = []
first = input().strip()
H,W,N = map(int,first.split())
for i in range(H):
row = list(input().strip())
for j in range(W):
if row[j].isdigit():
row[j] = int(row[j])
matrix.append(row)
return matrix,H,W,N
def getStart(field):
for y in range(len(field)):
for x in range(len(field[0])):
if field[y][x] == "S":
return x,y
def main():
matrix,H,W,N = getField()
sx,sy = getStart(matrix)
distance = 0
tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,1)
distance += tmp_dist
tmps = [tmp_x,tmp_y]
for k in range(N-1):
tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+2)
distance += tmp_dist
tmps = [tmp_x,tmp_y]
print(distance)
if __name__=='__main__':
main()
|
s114685390
|
p02975
|
u830054172
| 2,000 | 1,048,576 |
Wrong Answer
| 60 | 14,212 | 296 |
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
|
n = int(input())
a = list(map(int, input().split()))
flag = 0
even = []
odd = []
for i in a:
if i%2 == 0:
even.append(i)
else:
odd.append(i)
if n%2 == 1:
if len(odd) >= 1:
flag = 1
else:
pass
if flag == 1:
print("No")
else:
print("Yes")
|
s764435891
|
Accepted
| 52 | 14,212 | 132 |
N = int(input())
a = list(map(int, input().split()))
t = 0
for a_i in a:
t ^= a_i
# print(t)
print("Yes" if t==0 else "No")
|
s288286546
|
p03644
|
u476468228
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 83 |
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
n = int(input().strip())
while True:
if n & (n-1) == 0:
print(n)
break
n += 1
|
s532321387
|
Accepted
| 18 | 2,940 | 83 |
n = int(input().strip())
while True:
if n & (n-1) == 0:
print(n)
break
n -= 1
|
s114290848
|
p02602
|
u430928274
| 2,000 | 1,048,576 |
Wrong Answer
| 2,206 | 33,888 | 357 |
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
grade_array = []
for i in range(k,n+1) :
grade = 1
for j in range(k) :
grade *= a[i-1-j]
grade_array.append(grade)
print(grade_array)
for i in range(n-k) :
if grade_array[i+1] > grade_array[i] :
print("Yes")
else :
print("No")
|
s938762923
|
Accepted
| 158 | 31,612 | 172 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k,n) :
if a[i-(k-1)-1] < a[i] :
print("Yes")
else :
print("No")
|
s338496990
|
p03457
|
u035445296
| 2,000 | 262,144 |
Wrong Answer
| 227 | 27,196 | 360 |
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
ans = 'Yes'
t_diff = 0
x_diff = 0
y_diff = 0
for i in p:
t_diff = i[0] - t_diff
x_diff = abs(i[1] - x_diff)
y_diff = abs(i[2] - y_diff)
if t_diff > x_diff + y_diff:
if (t_diff - x_diff - y_diff)%2 != 0:
ans = 'No'
break
else:
ans = 'No'
break
print(ans)
|
s970740688
|
Accepted
| 260 | 27,056 | 361 |
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
ans = 'Yes'
t_diff = 0
x_diff = 0
y_diff = 0
for i in p:
t_diff = i[0] - t_diff
x_diff = abs(i[1] - x_diff)
y_diff = abs(i[2] - y_diff)
if t_diff >= x_diff + y_diff:
if (t_diff - x_diff - y_diff)%2 != 0:
ans = 'No'
break
else:
ans = 'No'
break
print(ans)
|
s325786723
|
p02833
|
u595289165
| 2,000 | 1,048,576 |
Wrong Answer
| 148 | 12,504 | 220 |
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 numpy as np
n = int(input())
a = len(str(n))
ans = np.zeros(a+4)
def calc(x, y):
return x // (10 * 5**y)
if n % 2 == 1:
pass
else:
for i in range(a+4):
ans[i] += calc(n, i)
print(sum(ans))
|
s467840771
|
Accepted
| 152 | 12,388 | 201 |
import numpy as np
n = int(input())
a = len(str(n))
ans = 0
def calc(x, y):
return x // (10 * 5**y)
if n % 2 == 1:
pass
else:
for i in range(a+10):
ans += calc(n, i)
print(ans)
|
s237236630
|
p03081
|
u047535298
| 2,000 | 1,048,576 |
Wrong Answer
| 2,105 | 42,656 | 718 |
There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
|
N, Q = map(int, input().split())
s = input()
golems_in = dict([(i, 1) for i in range(N+2)])
golems_in[0] = 0
golems_in[N] = 0
alphabet_to_number = {}
for i in range(N):
c = s[i]
if not c in alphabet_to_number:
alphabet_to_number[c] = [i + 1]
else:
alphabet_to_number[c].append(i + 1)
for i in range(Q):
t, d = input().split()
direction = 1 if d=="R" else -1
n = len(alphabet_to_number[t]) if t in alphabet_to_number else 0
for j in range(n):
if(d == "R"):
c = alphabet_to_number[t][n-j-1]
else:
c = alphabet_to_number[t][j]
golems_in[c+direction] += golems_in[c]
golems_in[c] = 0
print(N-golems_in[0]-golems_in[N+1])
|
s569540654
|
Accepted
| 1,718 | 17,840 | 992 |
N, Q = map(int, input().split())
s = input()
td = [tuple(input().split()) for i in range(Q)]
def left_check(pos):
nowpos = pos
for t, d in td:
if(d=="L" and t==s[nowpos]):
nowpos -= 1
elif(d=="R" and t==s[nowpos]):
nowpos += 1
if(nowpos == N):
return False
elif(nowpos == -1):
return True
return False
def right_check(pos):
nowpos = pos
for t, d in td:
if(d=="L" and t==s[nowpos]):
nowpos -= 1
elif(d=="R" and t==s[nowpos]):
nowpos += 1
if(nowpos == N):
return False
elif(nowpos == -1):
return True
return True
def nibun(l, h, func):
low = l
high = h
mid = (l+h)//2
while low <= high:
x = func(mid)
if(x):
low = mid+1
else:
high = mid-1
mid = (low+high)//2
return mid
print(nibun(0, N-1, right_check)-nibun(0, N-1, left_check))
|
s907724443
|
p02678
|
u336564899
| 2,000 | 1,048,576 |
Wrong Answer
| 872 | 57,928 | 632 |
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 collections
if __name__ == '__main__':
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
ways = [[] for i in range(n+1)]
for i in l:
ways[i[0]].append(i[1])
ways[i[1]].append(i[0])
#print(ways)
q = collections.deque()
ans = [-1] * n
ans[0] = 0
q.append(1)
while(len(q) != 0):
item = q.popleft()
for i in ways[item]:
if ans[i-1] == -1:
ans[i-1] = item
q.append(i)
for i in range(1,n):
print(ans[i])
|
s579349816
|
Accepted
| 849 | 57,788 | 709 |
import collections
if __name__ == '__main__':
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
ways = [[] for i in range(n+1)]
for i in l:
ways[i[0]].append(i[1])
ways[i[1]].append(i[0])
#print(ways)
q = collections.deque()
ans = [-1] * n
ans[0] = 0
q.append(1)
while(len(q) != 0):
item = q.popleft()
for i in ways[item]:
if ans[i-1] == -1:
ans[i-1] = item
q.append(i)
if -1 in ans:
print("No")
else:
print("Yes")
for i in range(1,n):
print(ans[i])
|
s701909772
|
p02694
|
u023185908
| 2,000 | 1,048,576 |
Wrong Answer
| 23 | 9,164 | 158 |
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
import math
x = int(input())
year = 0
y = 100
t = True
while t:
year += 1
y = math.floor(y*1.01)
if y > x:
print(year)
t = False
|
s304434988
|
Accepted
| 22 | 9,096 | 159 |
import math
x = int(input())
year = 0
y = 100
t = True
while t:
year += 1
y = math.floor(y*1.01)
if y >= x:
print(year)
t = False
|
s270884872
|
p03487
|
u163320134
| 2,000 | 262,144 |
Wrong Answer
| 95 | 14,692 | 247 |
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
|
n=int(input())
arr=list(map(int,input().split()))
cnt=[0]*(10**5+1)
ans=0
for i in range(n):
if arr[i]<=10**5:
cnt[arr[i]]+=1
else:
ans+=1
for i in range(1,10**5+1):
if cnt[i]>i:
ans+=cnt[i]-i
else:
ans+=i-cnt[i]
print(ans)
|
s210466589
|
Accepted
| 72 | 14,692 | 307 |
n=int(input())
arr=list(map(int,input().split()))
cnt=[0]*(10**5+1)
ans=0
for i in range(n):
if arr[i]<=10**5:
cnt[arr[i]]+=1
else:
ans+=1
for i in range(1,10**5+1):
if cnt[i]==0:
continue
elif cnt[i]==i:
continue
elif cnt[i]>i:
ans+=cnt[i]-i
else:
ans+=cnt[i]
print(ans)
|
s289282087
|
p02612
|
u731467249
| 2,000 | 1,048,576 |
Wrong Answer
| 32 | 9,144 | 32 |
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N = int(input())
print(N % 1000)
|
s879670505
|
Accepted
| 29 | 9,148 | 81 |
N = int(input())
if N % 1000 > 0:
print(1000 - (N % 1000))
else:
print(0)
|
s948325115
|
p03555
|
u500279510
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 120 |
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
a = input()
b = input()
if (a[0] == b[2]) and (a[1] == b[1]) and (a[2] == b[0]):
print('Yes')
else:
print('No')
|
s386158449
|
Accepted
| 17 | 2,940 | 120 |
a = input()
b = input()
if (a[0] == b[2]) and (a[1] == b[1]) and (a[2] == b[0]):
print('YES')
else:
print('NO')
|
s938395035
|
p03573
|
u434208140
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 60 |
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
|
s=list(map(int,input().split()))
print(sum(s)-min(s)-max(s))
|
s879586350
|
Accepted
| 17 | 2,940 | 64 |
s=list(map(int,input().split()))
print(2*min(s)+2*max(s)-sum(s))
|
s391316467
|
p02409
|
u908651435
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,620 | 293 |
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
|
n=int(input())
a=[[[0]*10 for i in range(3)] for j in range(4)]
for i in range(n):
b,f,r,v=map(int,input().split())
a[b-1][f-1][r-1]=v
for i in range(4):
for j in range(3):
for e in range(10):
print(' '+str(a[i][j][e]),end='')
print()
print('#'*20)
|
s821301349
|
Accepted
| 20 | 5,620 | 311 |
n=int(input())
a=[[[0]*10 for i in range(3)] for j in range(4)]
for i in range(n):
b,f,r,v=map(int,input().split())
a[b-1][f-1][r-1]+=v
for i in range(4):
for j in range(3):
for e in range(10):
print(' '+str(a[i][j][e]),end='')
print()
if i!=3:
print('#'*20)
|
s154753613
|
p03861
|
u492605584
| 2,000 | 262,144 |
Wrong Answer
| 19 | 3,188 | 65 |
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
|
a, b, x = map(int, input().split(" "))
print(int(b + 1 - a) // x)
|
s700891000
|
Accepted
| 18 | 2,940 | 126 |
a, b, x = map(int, input().split(" "))
if a % x == 0:
print(int(b//x) - int(a//x) + 1)
else:
print(int(b//x) - int(a//x))
|
s794955663
|
p02619
|
u485319545
| 2,000 | 1,048,576 |
Wrong Answer
| 37 | 9,268 | 367 |
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
|
d=int(input())
c=list(map(int,input().split()))
s=[]
for _ in range(d):
s_i=list(map(int,input().split()))
s.append(s_i)
for _ in range(d):
t=int(input())
dp=[0]*26
for i in range(d):
s_i = max(s[i])
index=s[i].index(max(s[i]))
dp[index]=i+1
tmp=0
for j in range(26):
tmp+=c[j]*(d-dp[j])
ans = s_i = tmp
print(ans)
|
s272653180
|
Accepted
| 41 | 9,084 | 393 |
d=int(input())
c=list(map(int,input().split()))
s=[]
for _ in range(d):
s_i=list(map(int,input().split()))
s.append(s_i)
t=[]
for _ in range(d):
t_i=int(input())
t.append(t_i)
dp=[0]*26
ans=0
for i in range(d):
s_i = s[i][t[i]-1]
ans+=s_i
dp[t[i]-1]=i+1
tmp=0
for j in range(26):
tmp+=c[j]*((i+1)-dp[j])
ans -= tmp
print(ans)
|
s157685306
|
p04030
|
u290211456
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 165 |
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()
res =[]
for i in range(len(s)):
print(res)
if s[i] == 'B':
if len(res) != 0:
res.pop(len(res)-1)
continue
res.append(s[i])
print("".join(res))
|
s921366106
|
Accepted
| 20 | 3,060 | 153 |
s = input()
res =[]
for i in range(len(s)):
if s[i] == 'B':
if len(res) != 0:
res.pop(len(res)-1)
continue
res.append(s[i])
print("".join(res))
|
s202906481
|
p02678
|
u377989038
| 2,000 | 1,048,576 |
Wrong Answer
| 22 | 9,008 | 11 |
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.
|
print("No")
|
s125979198
|
Accepted
| 681 | 38,464 | 399 |
from collections import deque
print("Yes")
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
a, b = map(int, input().split())
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
q = deque([0])
b = [0] * n
while q:
x = q.popleft()
for i in g[x]:
if b[i] != 0:
continue
b[i] = x + 1
q.append(i)
print(*b[1:], sep="\n")
|
s631713403
|
p03377
|
u698868214
| 2,000 | 262,144 |
Wrong Answer
| 24 | 9,160 | 77 |
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
A,B,X = map(int,input().split())
print("YES" if A+B == X or A == X else "NO")
|
s681772560
|
Accepted
| 23 | 9,100 | 72 |
A,B,X = map(int,input().split())
print("YES" if A <= X <= A+B else "NO")
|
s187027767
|
p03659
|
u859897687
| 2,000 | 262,144 |
Wrong Answer
| 182 | 24,800 | 154 |
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
|
n=int(input())
m=list(map(int,input().split()))
a=sum(m)
for i in range(1,n):
m[i]-=m[i-1]
ans=99999999
for i in m:
ans=min(ans,abs(a-i-i))
print(ans)
|
s336765921
|
Accepted
| 187 | 23,792 | 166 |
n=int(input())
m=list(map(int,input().split()))
a=sum(m)
for i in range(1,n):
m[i]+=m[i-1]
ans=99999999999999
for i in m[:n-1]:
ans=min(ans,abs(a-i-i))
print(ans)
|
s051852586
|
p02972
|
u727025296
| 2,000 | 1,048,576 |
Wrong Answer
| 630 | 20,664 | 699 |
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
|
n = int(input())
a_list = list(map(int, input().split()))
a_count = len(a_list)
boll_list = [0] * n
for rev_index, a in enumerate(reversed(a_list)):
index = a_count - rev_index - 1
if (a + 1) * 2 > a_count:
boll_list[index] = a_list[index]
else:
divide_max = a_count // (index + 1)
total = 0
for i in range(divide_max):
total += boll_list[i]
total = total % 2
if a_list[index] != total:
boll_list[index] = 1
if (1 in boll_list):
output_list = []
for index, i in enumerate(boll_list):
if i == 1:
output_list.append(str(index + 1))
print(' '.join(output_list))
else:
print('0')
|
s612072452
|
Accepted
| 806 | 17,204 | 674 |
n = int(input())
a_list = list(map(int, input().split()))
a_count = len(a_list)
boll_list = [0] * n
for rev_index, a in enumerate(reversed(a_list)):
index = a_count - rev_index - 1
divide_max = a_count // (index + 1)
total = 0
for divide in range(divide_max):
total += boll_list[(index + 1) * (divide + 1) - 1]
if a_list[index] != total % 2:
boll_list[index] = 1
if 1 in boll_list:
output_list = []
for index, i in enumerate(boll_list):
if i == 1:
output_list.append(str(index + 1))
print(len(output_list))
print(' '.join(output_list))
else:
print('0')
|
s173396108
|
p02412
|
u949338836
| 1,000 | 131,072 |
Wrong Answer
| 30 | 6,724 | 294 |
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
|
#coding:utf-8
#1_7_B 2015.4.5
while True:
n,x = map(int,input().split())
if n == x == 0:
break
count = 0
for i in range(1 , n + 1):
for j in range(1 , n + 1):
if (x - i - j) < n and i < j < (x - i -j):
count += 1
print(count)
|
s097703450
|
Accepted
| 80 | 6,728 | 280 |
#coding:utf-8
#1_7_B 2015.4.5
while True:
n,x = map(int,input().split())
if n == x == 0:
break
count = 0
for i in range(1 , n + 1):
for j in range(1 , n + 1):
if i < j < (x - i - j) <= n:
count += 1
print(count)
|
s436857185
|
p02853
|
u629540524
| 2,000 | 1,048,576 |
Wrong Answer
| 30 | 9,108 | 241 |
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
|
x,y = map(int,input().split())
c = 0
if x==1:
c+=300000
elif x == 2:
c+=200000
elif x == 3:
c+=100000
if y==1:
c+=300000
elif y == 2:
c+=200000
elif y == 3:
c+=100000
if x == 1 and y == 1:
x+=400000
print(c)
|
s947810952
|
Accepted
| 27 | 9,184 | 246 |
x,y = map(int,input().split())
c = 0
if x==1:
c+=300000
elif x == 2:
c+=200000
elif x == 3:
c+=100000
if y==1:
c+=300000
elif y == 2:
c+=200000
elif y == 3:
c+=100000
if x == 1 and y == 1:
c+=400000
print(c)
|
s295040557
|
p03006
|
u906428167
| 2,000 | 1,048,576 |
Wrong Answer
| 20 | 3,188 | 523 |
There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: * Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1. Find the minimum total cost required to collect all the balls when we optimally choose p and q.
|
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
lst = []
for i in range(n):
for j in range(i,n):
if a[j][0]-a[i][0] <= 0 and a[j][1]-a[i][1] <= 0:
lst.append([a[i][0]-a[j][0], a[i][1]-a[j][1]])
else:
lst.append([a[j][0]-a[i][0], a[j][1]-a[i][1]])
if n ==1:
print(1)
else:
x = 0
for i in range(len(a)):
c = 0
for j in range(i,len(a)):
if a[i] == a[j]:
c += 1
x = max(x,c)
print(n-x-1)
|
s422657711
|
Accepted
| 296 | 3,316 | 604 |
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
lst = []
for i in range(n):
for j in range(i+1,n):
if a[j][0]-a[i][0] < 0:
lst.append([a[i][0]-a[j][0], a[i][1]-a[j][1]])
if a[j][0]-a[i][0] == 0:
lst.append([a[i][0]-a[j][0], abs(a[i][1]-a[j][1])])
else:
lst.append([a[j][0]-a[i][0], a[j][1]-a[i][1]])
if n ==1:
print(1)
else:
x = 0
for i in range(len(lst)):
c = 1
for j in range(i+1,len(lst)):
if lst[i] == lst[j]:
c += 1
x = max(x,c)
print(n-x)
|
s303298925
|
p04029
|
u090225501
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 39 |
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
n = int(input())
print((1 + n) * n / 2)
|
s416808396
|
Accepted
| 17 | 2,940 | 40 |
n = int(input())
print((1 + n) * n // 2)
|
s963773874
|
p03386
|
u048176319
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 202 |
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
|
A, B, K = map(int, input().split())
if A+K-1 >= B-K+1:
for i in range(A, B+1):
print(i)
else:
for i in range(A, A+K-1):
print(i)
for i in range(B-K+1, B):
print(i)
|
s383300648
|
Accepted
| 17 | 3,060 | 201 |
A, B, K = map(int, input().split())
if A+K-1 >= B-K+1:
for i in range(A, B+1):
print(i)
else:
for i in range(A, A+K):
print(i)
for i in range(B-K+1, B+1):
print(i)
|
s180023903
|
p03796
|
u943657163
| 2,000 | 262,144 |
Wrong Answer
| 2,104 | 3,464 | 78 |
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.
|
n = int(input())
p = 1
for i in range(1, n+1):
p *= i
print(p % 10**9 + 7)
|
s038233927
|
Accepted
| 35 | 2,940 | 81 |
n = int(input())
p, d =1, 10**9+7
for i in range(1,n+1):
p = (p*i) % d
print(p)
|
s837333549
|
p03360
|
u706414019
| 2,000 | 262,144 |
Wrong Answer
| 28 | 9,084 | 90 |
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
|
A = sorted(list(map(int,input().split())))
N = int(input())
A[-1] = A[-1]**N
print(sum(A))
|
s140087887
|
Accepted
| 25 | 9,132 | 92 |
A = sorted(list(map(int,input().split())))
N = int(input())
A[-1] = A[-1]*2**N
print(sum(A))
|
s199543913
|
p02411
|
u748033250
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,528 | 549 |
Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
|
while(1):
chuukan, kimatsu, saishi = map(int, input().split())
state = "None"
if chuukan == kimatsu == saishi == -1:
break
elif (chuukan or kimatsu) == -1:
state = "F"
elif (chuukan*2 + kimatsu*2)/2 >= 80:
state = "A"
elif (chuukan*2 + kimatsu*2)/2 >= 65:
state = "B"
elif (chuukan*2 + kimatsu*2)/2 >= 50:
state = "C"
elif (chuukan*2 + kimatsu*2)/2 >= 30:
if saishi >= 50:
state = "C"
else:
state = "B"
else:
state = "D"
print("DBG ::chuukan{} kimatsu{} saishi{} STATE[{}]".format(chuukan, kimatsu, saishi, state))
|
s640170667
|
Accepted
| 20 | 5,596 | 452 |
mid = 0
end = 0
re = 0
while(1):
mid, end, re = map(int, input().split() )
if (mid == -1) and (end == -1) and (re == -1) :
break
if (mid == -1) or (end == -1):
print("F")
elif mid + end >= 80:
print("A")
elif mid + end >= 65:
print("B")
elif mid + end >= 50:
print("C")
elif mid + end >= 30:
if re >= 50:
print("C")
else: print("D")
else: print("F")
|
s667104354
|
p02238
|
u368083894
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,608 | 637 |
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving the vertex from which $v$ was discovered. This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source. DFS timestamps each vertex as follows: * $d[v]$ records when $v$ is first discovered. * $f[v]$ records when the search finishes examining $v$’s adjacency list. Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules: * $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively. * IDs in the adjacency list are arranged in ascending order. * The program should report the discover time and the finish time for each vertex. * When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID. * The timestamp starts with 1.
|
d = None
f = None
def dfs(g, cur, time):
global d, f
d[cur] = time
for next in g[cur]:
if d[next] == 0:
time = dfs(g, next, time+1)
f[cur] = time + 1
return time + 1
def main():
global d, f
n = int(input())
g = [[] for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
for _ in range(n):
inp = list(map(int, input().split()))
m = inp[0] - 1
k = inp[1]
for i in range(k):
g[m].append(inp[i+2] - 1)
dfs(g, 0, 1)
for i in range(n):
print(i, d[i], f[i])
if __name__ == '__main__':
main()
|
s886144234
|
Accepted
| 20 | 5,660 | 719 |
d = None
f = None
def dfs(g, cur, time):
global d, f
d[cur] = time
for next in g[cur]:
if d[next] == 0:
time = dfs(g, next, time+1)
f[cur] = time + 1
return time + 1
def main():
global d, f
n = int(input())
g = [[] for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
for _ in range(n):
inp = list(map(int, input().split()))
m = inp[0] - 1
k = inp[1]
for i in range(k):
g[m].append(inp[i+2] - 1)
time = 1
for i in range(n):
if d[i] == 0:
time = dfs(g, i, time) + 1
for i in range(n):
print(i+1, d[i], f[i])
if __name__ == '__main__':
main()
|
s096928854
|
p03829
|
u870518235
| 2,000 | 262,144 |
Wrong Answer
| 229 | 12,688 | 387 |
There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one- dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town i is X_i. You are now at town 1, and you want to visit all the other towns. You have two ways to travel: * Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction. * Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered. Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.
|
# -*- coding: utf-8 -*-
# Input
s = [input() for i in range(2)]
N = int(s[0].split()[0])
A = int(s[0].split()[1])
B = int(s[0].split()[2])
X = s[1].split()
F = 0
for i in range(0, N-1):
if A*(int(X[i+1]) - int(X[i])) >= B:
F = F + B
else:
F = F + A*(int(X[i+1]) - int(X[i]))
print(F)
# Output
print(F)
|
s051879414
|
Accepted
| 148 | 11,096 | 377 |
# -*- coding: utf-8 -*-
# Input
s = [input() for i in range(2)]
N = int(s[0].split()[0])
A = int(s[0].split()[1])
B = int(s[0].split()[2])
X = s[1].split()
F = 0
for i in range(0, N-1):
if A*(int(X[i+1]) - int(X[i])) >= B:
F = F + B
else:
F = F + A*(int(X[i+1]) - int(X[i]))
# Output
print(F)
|
s484272474
|
p02390
|
u356022548
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,580 | 242 |
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
|
time = float(input("Input time in seconds: "))
day = time // (24 * 3600)
time = time % (24 * 3600)
hour = time // 3600
time %= 3600
minutes = time // 60
time %= 60
seconds = time
print("d:h:m:s-> %d:%d:%d:%d" % (day, hour, minutes, seconds))
|
s667910871
|
Accepted
| 20 | 5,580 | 150 |
S = float(input())
S = S % (24 * 3600)
hour = S // 3600
S %= 3600
minutes = S // 60
S %= 60
seconds = S
print("%d:%d:%d" % (hour, minutes, seconds))
|
s396825378
|
p02694
|
u919065552
| 2,000 | 1,048,576 |
Wrong Answer
| 21 | 9,024 | 168 |
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
X = int(input())
T = 100
InterestRate = 1.01
n = 0
while True:
T = int(T * InterestRate)
if T >= X:
print(n + 1)
break
n += 1
print("DONE")
|
s666326895
|
Accepted
| 20 | 9,112 | 154 |
X = int(input())
T = 100
InterestRate = 1.01
n = 0
while True:
T = int(T * InterestRate)
if T >= X:
print(n + 1)
break
n += 1
|
s119333780
|
p02279
|
u777299405
| 2,000 | 131,072 |
Wrong Answer
| 30 | 7,744 | 760 |
A graph _G_ = ( _V_ , _E_ ) is a data structure where _V_ is a finite set of vertices and _E_ is a binary relation on _V_ represented by a set of edges. Fig. 1 illustrates an example of a graph (or graphs). **Fig. 1** A free tree is a connnected, acyclic, undirected graph. A rooted tree is a free tree in which one of the vertices is distinguished from the others. A vertex of a rooted tree is called "node." Your task is to write a program which reports the following information for each node _u_ of a given rooted tree _T_ : * node ID of _u_ * parent of _u_ * depth of _u_ * node type (root, internal node or leaf) * a list of chidlren of _u_ If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is ( _p_ , _x_ ), then _p_ is the **parent** of _x_ , and _x_ is a **child** of _p_. The root is the only node in _T_ with no parent. A node with no children is an **external node** or **leaf**. A nonleaf node is an **internal node** The number of children of a node _x_ in a rooted tree _T_ is called the **degree** of _x_. The length of the path from the root _r_ to a node _x_ is the **depth** of _x_ in _T_. Here, the given tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1. Fig. 2 shows an example of rooted trees where ID of each node is indicated by a number in a circle (node). The example corresponds to the first sample input. **Fig. 2**
|
class Tree():
def __init__(self):
self.parent = -1
self.depth = 0
self.child = []
n = int(input())
tree = [Tree() for i in range(n)]
for i in range(n):
cmd = list(map(int, input().split()))
node = tree[cmd[0]]
node.child.extend(cmd[2:])
for j in cmd[2:]:
tree[j].parent = cmd[0]
for t in tree:
d, p = 0, t.parent
while p != -1:
d += 1
p = tree[p].parent
t.depth = d
for i in range(n):
t = tree[i]
if t.parent == -1:
state = "root"
elif t.child:
state = "internal node"
else:
state = "leaf"
print("node {}: parent = {}".format(i, t.parent), "depth = {}".format(
t.depth), state, "[{}]".format(", ".join(map(str, t.child))), sep=", ")
|
s313479925
|
Accepted
| 1,390 | 42,484 | 768 |
class Tree():
def __init__(self):
self.parent = -1
self.depth = 0
self.child = []
n = int(input())
tree = [Tree() for i in range(n)]
for i in range(n):
cmd = list(map(int, input().split()))
node = tree[cmd[0]]
node.child.extend(cmd[2:])
for j in cmd[2:]:
tree[j].parent = cmd[0]
for t in tree:
d, p = 0, t.parent
while p != -1:
d += 1
p = tree[p].parent
t.depth = d
for i in range(n):
t = tree[i]
if t.parent == -1:
state = "root"
elif t.child:
state = "internal node"
else:
state = "leaf"
print("node {}: parent = {}".format(i, t.parent), "depth = {}".format(
t.depth), state, "[{}]".format(", ".join(map(str, t.child))), sep=", ")
|
s501369865
|
p02261
|
u865220118
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,600 | 1,087 |
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).
|
A = []
B = []
C = []
LENGTH =int(input())
A = input().split()
B = A.copy()
C = A.copy()
print(A[1][1:])
def bubble (A, LENGTH):
N = 0
M = LENGTH - 1
CHANGE = 0
while N <= LENGTH -1:
M = LENGTH - 1
while M >= N + 1:
if int(A[M][1:]) < int(A[M-1][1:]):
tmp = A[M-1]
A[M-1] = A[M]
A[M] = tmp
CHANGE += 1
M -= 1
N += 1
print(" ".join(map(str,A)))
print("Stable")
def selection (B, LENGTH):
i = 0
CHANGE_COUNT = 0
while i <= LENGTH -1:
j = i + 1
mini = i
while j <= LENGTH -1:
if int(B[j][1:]) < int(B[mini][1:]):
mini = j
j += 1
if mini != i:
tmp = B[i]
B[i] = B[mini]
B[mini] = tmp
CHANGE_COUNT += 1
i += 1
print(" ".join(map(str,B)))
if B == C:
print("Stable")
else:
print("Not Stable")
bubble (A, LENGTH)
selection (B, LENGTH)
|
s456800092
|
Accepted
| 20 | 5,608 | 1,050 |
A = []
B = []
LENGTH =int(input())
A = input().split()
B = A.copy()
def bubble (A, LENGTH):
N = 0
M = LENGTH - 1
CHANGE = 0
while N <= LENGTH -1:
M = LENGTH - 1
while M >= N + 1:
if int(A[M][1:]) < int(A[M-1][1:]):
tmp = A[M-1]
A[M-1] = A[M]
A[M] = tmp
CHANGE += 1
M -= 1
N += 1
print(" ".join(map(str,A)))
print("Stable")
def selection (B, LENGTH):
i = 0
CHANGE_COUNT = 0
while i <= LENGTH -1:
j = i + 1
mini = i
while j <= LENGTH -1:
if int(B[j][1:]) < int(B[mini][1:]):
mini = j
j += 1
if mini != i:
tmp = B[i]
B[i] = B[mini]
B[mini] = tmp
CHANGE_COUNT += 1
i += 1
print(" ".join(map(str,B)))
if A == B:
print("Stable")
else:
print("Not stable")
bubble (A, LENGTH)
selection (B, LENGTH)
|
s033881504
|
p03943
|
u977193988
| 2,000 | 262,144 |
Wrong Answer
| 19 | 3,316 | 101 |
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
A,B,C=map(int,input().split())
if A+B==C or A+C==B or B+C==A:
print('YES')
else:
print('NO')
|
s501679494
|
Accepted
| 17 | 2,940 | 101 |
A,B,C=map(int,input().split())
if A+B==C or A+C==B or B+C==A:
print('Yes')
else:
print('No')
|
s958037752
|
p03657
|
u282228874
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 118 |
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
|
a,b = map(int,input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
print('Possiblle')
else:
print('Impossible')
|
s845294338
|
Accepted
| 18 | 2,940 | 117 |
a,b = map(int,input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
print('Possible')
else:
print('Impossible')
|
s587675130
|
p02257
|
u696273805
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,664 | 291 |
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of _N_ integers and prints the number of prime numbers in the list.
|
import math
def is_prime(n):
sqrtn = math.ceil(math.sqrt(n))
for i in range(2, sqrtn):
if n % i:
return False
return n != 1
n = int(input())
answer = 0
for _ in range(0, n):
m = int(input())
if is_prime(m):
answer = answer + 1
print(answer)
|
s045723232
|
Accepted
| 70 | 5,620 | 963 |
def witness(a, n, t, u):
x = pow(a, u, n)
for _ in range(0, t):
y = (x * x) % n
if y == 1 and x != 1 and x != (n - 1):
return True
x = y
return y != 1
def is_probably_prime(n, witnesses):
t = 1
u = n >> 1
while u & 1 == 0:
t = t + 1
u >>= 1
assert(2**t * u == n - 1)
for a in witnesses:
if a < n and witness(a, n, t, u):
return False
return True
def is_definitely_prime(n):
if ((not (n & 1)) and n != 2) or (n < 2) or ((n % 3 == 0) and (n != 3)):
return False
elif n <= 3:
return True
else:
return is_probably_prime(n, [2, 7, 61])
n = int(input())
answer = 0
for _ in range(0, n):
m = int(input())
if is_definitely_prime(m):
answer = answer + 1
print(answer)
|
s924735838
|
p04045
|
u950708010
| 2,000 | 262,144 |
Wrong Answer
| 24 | 2,940 | 244 |
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
|
n,k = (int(i) for i in input().split())
d = list(int(i) for i in input().split())
def ketajudge(x):
while x != 0:
if x%10 in d:
return False
break
else:
if x//10 == 0:
return True
break
x = x//10
|
s079848467
|
Accepted
| 48 | 2,940 | 355 |
n,k = (int(i) for i in input().split())
d = list(int(i) for i in input().split())
def ketajudge(x):
while x != 0:
if x%10 in d:
return False
break
else:
if x//10 == 0:
return True
break
x = x//10
for i in range(10*n):
judge = n+i
if ketajudge(judge) == True:
print(judge)
break
|
s107137565
|
p03543
|
u349444371
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 109 |
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()
if N.count(N[0])==4 or N[0]==N[1]==N[2] or N[1]==N[2]==N[3]:
print("YES")
else:
print("NO")
|
s475263705
|
Accepted
| 17 | 2,940 | 109 |
N=input()
if N.count(N[0])==4 or N[0]==N[1]==N[2] or N[1]==N[2]==N[3]:
print("Yes")
else:
print("No")
|
s240986408
|
p02390
|
u886726907
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,576 | 57 |
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
|
t=int(input())
print(t//3600,t//60-60*(t//3600),t%3600)
|
s505523060
|
Accepted
| 20 | 5,576 | 74 |
t=int(input())
print("{}:{}:{}".format(t//3600,t//60-60*(t//3600),t%60))
|
s122463415
|
p03997
|
u636775911
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,060 | 88 |
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.
|
#coding:utf-8
n=[]
for i in range(3):
n.append(int(input()))
print((n[0]+n[1])*n[2]/2)
|
s921240536
|
Accepted
| 17 | 2,940 | 94 |
#coding:utf-8
n=[]
for i in range(3):
n.append(int(input()))
print(int((n[0]+n[1])*n[2]/2))
|
s118053976
|
p02394
|
u798565376
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,592 | 250 |
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
|
l = list(map(int, input().split()))
W = l[0]
H = l[1]
x = l[2]
y = l[3]
r = l[4]
left_x = x - r
right_x = x + r
top_y = y + r
bottom_y = y - r
if left_x >= W and right_x <= W and top_y <= H and bottom_y >= H:
print("Yes")
else:
print("No")
|
s426110934
|
Accepted
| 20 | 5,596 | 250 |
l = list(map(int, input().split()))
W = l[0]
H = l[1]
x = l[2]
y = l[3]
r = l[4]
left_x = x - r
right_x = x + r
top_y = y + r
bottom_y = y - r
if left_x >= 0 and right_x <= W and top_y <= H and bottom_y >= 0:
print("Yes")
else:
print("No")
|
s652742818
|
p03503
|
u140251125
| 2,000 | 262,144 |
Wrong Answer
| 152 | 12,440 | 709 |
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
|
import math
import numpy as np
from operator import mul
# l = [int(x) for x in list(str(N))]
N = int(input())
f = [list(map(int, input().split())) for i in range(N)]
p = [list(map(int, input().split())) for i in range(N)]
c = list(range(N))
for i in range(1,2^10):
i_bin = format(i, 'b')
i_list = [int(x) for x in list(str(i_bin))]
profit = 0
max_p = -10^7-1
for j in range(N):
combine = map(mul, f[j], i_list)
c[j] = sum(combine)
profit += p[j][c[j]]
if profit > max_p:
max_p = profit
print(max_p)
|
s735369566
|
Accepted
| 491 | 19,668 | 736 |
import math
import numpy as np
from operator import mul
# l = [int(x) for x in list(str(N))]
N = int(input())
f = [list(map(int, input().split())) for i in range(N)]
p = [list(map(int, input().split())) for i in range(N)]
c = list(range(N))
max_p = -100**7-1
for i in range(1,2**10):
i_bin = format(i, 'b').zfill(10)
i_list = [int(x) for x in list(str(i_bin))]
profit = 0
for j in range(N):
combine = map(mul, f[j], i_list)
c[j] = sum(combine) # 0 <= c[j] <= 10
profit += p[j][c[j]]
if profit > max_p:
max_p = profit
print(max_p)
|
s590786744
|
p03351
|
u951480280
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 103 |
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a,b,c,d=map(int,input().split());print("YES" if abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d) else "NO")
|
s968356634
|
Accepted
| 18 | 2,940 | 103 |
a,b,c,d=map(int,input().split());print("Yes" if abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d) else "No")
|
s981963572
|
p03377
|
u359856428
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 100 |
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a,b,x = map(int,input().split(' '))
if a <= x and x <= a + b:
print("Yes")
else:
print("No")
|
s035386100
|
Accepted
| 17 | 2,940 | 100 |
a,b,x = map(int,input().split(' '))
if a <= x and x <= a + b:
print("YES")
else:
print("NO")
|
s233545373
|
p02612
|
u585963734
| 2,000 | 1,048,576 |
Wrong Answer
| 29 | 9,148 | 28 |
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N=int(input())
print(N%1000)
|
s818873784
|
Accepted
| 30 | 9,160 | 66 |
N=int(input())
if N%1000==0:
print(0)
else:
print(1000-N%1000)
|
s829664533
|
p02972
|
u343850880
| 2,000 | 1,048,576 |
Wrong Answer
| 129 | 7,276 | 464 |
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
|
N = int(input())
in_list = [int(i) for i in input().split(' ')]
out_list = []
flag = 0
for i in range(1,len(in_list)+1):
count = 0
div_list = in_list[::i]
count += sum(div_list)
if count==in_list[i-1]:
if count!=0:
out_list.append(count)
else :
flag = 1
break
if flag==1:
print(-1)
else:
print(len(out_list))
for i in out_list:
try:
print(*i)
except:
break
|
s480213448
|
Accepted
| 234 | 17,224 | 262 |
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
c = []
for i in range(n,0,-1):
tmp = sum(b[i-1::i])
if tmp%2!=a[i-1]:
b[i-1] = 1
c.append(str(i))
print(len(c))
if len(c)!=0:
print(" ".join(c))
|
s672248166
|
p02831
|
u395620499
| 2,000 | 1,048,576 |
Wrong Answer
| 18 | 2,940 | 154 |
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
|
a,b = map(int, input().split())
def lcm(n, m):
bigger = n if n > m else m
while bigger % n != 0 and bigger % m != 0:
bigger += 1
print(lcm(a,b))
|
s085317354
|
Accepted
| 17 | 2,940 | 159 |
a,b = map(int, input().split())
def gcd(n,m):
while m:
n, m = m, n % m
return n
def lcm(n,m):
return (n*m) // gcd(n,m)
print(lcm(a,b))
|
s845497244
|
p03501
|
u943004959
| 2,000 | 262,144 |
Wrong Answer
| 66 | 3,060 | 179 |
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.
|
def solve():
N, A, B = list(map(int, input().split()))
if N * A > B:
print(N * A)
elif N * A < B:
print(B)
else:
print(B)
solve()
|
s211761793
|
Accepted
| 17 | 2,940 | 102 |
def solve():
N, A, B = list(map(int, input().split()))
print(min(N * A, B))
solve()
|
s903886409
|
p04043
|
u357751375
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 91 |
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
|
A,B,C= input().split()
Sum = A + B + C
if Sum == 17:
print('YES')
else:
print('NO')
|
s695385056
|
Accepted
| 17 | 2,940 | 106 |
A,B,C= input().split()
Sum = int(A) + int(B) + int(C)
if Sum == 17:
print('YES')
else:
print('NO')
|
s158983527
|
p03388
|
u419535209
| 2,000 | 262,144 |
Time Limit Exceeded
| 2,104 | 3,064 | 450 |
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.
|
# PROBLEM D
Q = int(input())
for _ in range(Q):
a, b = sorted([int(s) for s in input().split()])
c = 1
sol = 0
while True:
d = (a * b) // c
while c * d >= a * b:
d -= 1
if c > d:
break
if c < d:
sol_ = (c != a) + (d != b)
else:
sol_ = (c != a) and (c != b)
#print('candidate', c, d, sol_)
sol += sol_
c += 1
print(sol)
|
s536053859
|
Accepted
| 19 | 3,064 | 337 |
# PROBLEM D
Q = int(input())
for _ in range(Q):
a, b = sorted([int(s) for s in input().split()])
c_max = int((a * b) ** 0.5)
if c_max * c_max == a * b:
c_max -= 1
sol = 2 * c_max
if a <= c_max:
sol -= 1
if (c_max * c_max < a * b) and (c_max * (c_max + 1) >= a * b):
sol -= 1
print(sol)
|
s059980875
|
p03816
|
u973712798
| 2,000 | 262,144 |
Wrong Answer
| 2,103 | 70,060 | 696 |
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
|
import collections
n = int(input())
a_list = [int(i) for i in input().split()]
cnt = collections.Counter(a_list)
for key, num in cnt.items():
print(cnt)
if num == 2 or num == 1:
pass
elif num % 2 != 0 and num > 1:
cnt[key] = 1
elif num % 2 == 0 and num > 2:
cnt[key] = 2
else:
pass
# print("?")
c = 0
result = 0
for key, num in cnt.items():
if num == 2:
c += 1
if c % 2 == 0:
result = len(cnt)
else:
result = len(cnt) - 1
print(result)
# print("final:",cnt)
|
s086553427
|
Accepted
| 93 | 18,656 | 759 |
import collections
n = int(input())
a_list = [int(i) for i in input().split()]
cnt = collections.Counter(a_list)
c = 0
for key, num in cnt.items():
# print(cnt)
if num == 2 or num == 1:
if num == 2:
c += 1
pass
elif num % 2 != 0 and num > 1:
cnt[key] = 1
elif num % 2 == 0 and num > 2:
c += 1
cnt[key] = 2
else:
pass
# print("?")
result = 0
# for key, num in cnt.items():
# c += 1
if c % 2 == 0:
result = len(cnt)
else:
result = len(cnt) - 1
print(result)
# print("final:",cnt)
|
s301669510
|
p02612
|
u582759840
| 2,000 | 1,048,576 |
Wrong Answer
| 29 | 9,140 | 24 |
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
print(int(input())%1000)
|
s702845282
|
Accepted
| 26 | 9,144 | 48 |
x=int(input())%1000
print(0 if x==0 else 1000-x)
|
s453191418
|
p03644
|
u357751375
| 2,000 | 262,144 |
Wrong Answer
| 27 | 9,096 | 67 |
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
n = int(input())
if n % 2 == 0:
print(n)
else:
print(n - 1)
|
s567291178
|
Accepted
| 28 | 9,160 | 113 |
n = int(input())
ans = 1
while True:
ans *= 2
if ans > n:
ans = ans // 2
break
print(ans)
|
s786586809
|
p03555
|
u113835532
| 2,000 | 262,144 |
Wrong Answer
| 28 | 8,776 | 51 |
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.
|
print('Yes' if input() == input()[::-1] else 'No')
|
s588563011
|
Accepted
| 28 | 8,828 | 51 |
print('YES' if input() == input()[::-1] else 'NO')
|
s522585391
|
p03090
|
u406492455
| 2,000 | 1,048,576 |
Wrong Answer
| 25 | 3,956 | 153 |
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
|
n = int(input())
E = []
for i in range(n):
for j in range(i+1,n):
if i+j != n-1:
E.append((i,j))
for a,b in E:
print(a+1,b+1)
|
s026059572
|
Accepted
| 26 | 3,996 | 252 |
n = int(input())
E = []
B = [[0]*n for i in range(n)]
for i in range(n):
for j in range(i+1,n):
if i+j != (n-n%2)-1:
E.append((i,j))
B[i][j] = 1
B[j][i] = 1
print(len(E))
for a,b in E:
print(a+1,b+1)
|
s719134968
|
p03998
|
u813371068
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 79 |
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.
|
S={c:list(input()) for c in "abc"}
s = 'a'
while S[s]: s = S[s].pop(0)
print(s)
|
s067526949
|
Accepted
| 17 | 2,940 | 87 |
S={c:list(input()) for c in "abc"}
s = 'a'
while S[s]: s = S[s].pop(0)
print(s.upper())
|
s068923056
|
p03478
|
u399337080
| 2,000 | 262,144 |
Wrong Answer
| 35 | 3,060 | 236 |
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
def digitSum(c):
s = str(c)
array = list(map(int, s))
return sum(array)
n, a, b = map(int,input().split())
print (n,a,b)
ans = 0
for i in range(n+1):
sm = digitSum(i)
if a <= sm <= b:
ans += i
print(ans)
|
s839631087
|
Accepted
| 35 | 3,060 | 137 |
n, a, b = map(int,input().split())
ans = 0
for i in range(n+1):
if a <= sum(list(map(int, str(i)))) <= b:
ans += i
print(ans)
|
s919331752
|
p02821
|
u223663729
| 2,000 | 1,048,576 |
Wrong Answer
| 631 | 41,860 | 441 |
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
|
import numpy as np
from numpy.fft import rfft, irfft
N, M = map(int, input().split())
*A, = map(int, input().split())
B = np.zeros(2*10**5)
for a in A:
B[a] += 1
L = 2*10**5
FB = rfft(B, L)
C = np.rint(irfft(FB*FB)).astype(int)
ans = 0
for i in range(L-1, -1, -1):
c = C[i]
if not c:
continue
print(i, c, M)
if M - c > 0:
ans += i*c
M -= c
else:
ans += i*M
break
print(ans)
|
s651427451
|
Accepted
| 892 | 20,752 | 547 |
from itertools import accumulate
from bisect import bisect_left, bisect_right
N, M = map(int, input().split())
*A, = map(int, input().split())
A.sort()
acc = list(accumulate(A[::-1]))[::-1]+[0]
def isok(x):
cnt = 0
for a in A:
cnt += N - bisect_left(A, x-a)
return cnt >= M
l = 0
r = 202020
while l+1 < r:
m = (l+r)//2
if isok(m):
l = m
else:
r = m
ans = 0
cnt = 0
for a in A:
i = bisect_left(A, l-a)
ans += a*(N-i) + acc[i]
cnt += N-i
if cnt > M:
ans -= l * (cnt-M)
print(ans)
|
s157970142
|
p03644
|
u636822224
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 59 |
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
a=int(input())
cnt=0
if a%2==0:
cnt+=1
else:
print(cnt)
|
s066476133
|
Accepted
| 17 | 2,940 | 101 |
n=int(input())
for i in range(99):
if 2**i <= n:
continue
else:
print(2**(i-1))
break
|
s462991159
|
p03370
|
u278430856
| 2,000 | 262,144 |
Wrong Answer
| 19 | 3,828 | 129 |
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
|
N, X = map(int, input().split())
gram = [int(input()) for i in range(N)]
dp = [0]*10**5
X = X - sum(gram)
print(N+(X/min(gram)))
|
s267169295
|
Accepted
| 18 | 3,828 | 130 |
N, X = map(int, input().split())
gram = [int(input()) for i in range(N)]
dp = [0]*10**5
X = X - sum(gram)
print(N+(X//min(gram)))
|
s276761477
|
p02842
|
u328755070
| 2,000 | 1,048,576 |
Wrong Answer
| 30 | 9,156 | 158 |
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.
|
N = int(input())
senter = N // 1.08
for i in range(1000):
if senter-100+i == N:
print(senter-100+i)
break
else:
print(":(")
|
s009469034
|
Accepted
| 29 | 9,136 | 169 |
N = int(input())
senter = N // 1.08
for i in range(1000):
if int((senter-100+i) * 1.08) == N:
print(int(senter-100+i))
break
else:
print(":(")
|
s642610447
|
p03712
|
u626337957
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,060 | 187 |
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
|
H, W = map(int, input().split())
edge = ['#' for _ in range(W)]
output = edge + [list(input()) for __ in range(H)] + edge
for row in output:
row_str = ''.join(row)
print(row_str)
|
s039545007
|
Accepted
| 18 | 3,060 | 191 |
H, W = map(int, input().split())
edge = [['#'] * (W+2)]
output = edge + [['#'] + list(input()) + ['#'] for __ in range(H)] + edge
for row in output:
row_str = ''.join(row)
print(row_str)
|
s463228541
|
p02608
|
u089230684
| 2,000 | 1,048,576 |
Time Limit Exceeded
| 2,205 | 8,932 | 294 |
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
|
n = int(input())
def calc(c):
g = 0
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
if (x * x) + (y * y) + (z * z) + x * y + y * z + x * z == c:
g += 1
return g
for i in range(n):
print(calc(i))
|
s711255860
|
Accepted
| 154 | 9,296 | 298 |
n = int(input())
a = [0] * (n + 1)
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
c = x * x + y * y + z * z + x * y + y * z + z * x
if c <= n:
a[c] +=1
else:
break
for i in a[1:]:
print(i)
|
s541050926
|
p03693
|
u038290713
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 96 |
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(str, input().split())
n = int(r+g+b)
if n%4 ==0:
print("Yes")
else:
print("No")
|
s986743445
|
Accepted
| 17 | 2,940 | 96 |
r,g,b = map(str, input().split())
n = int(r+g+b)
if n%4 ==0:
print("YES")
else:
print("NO")
|
s657245122
|
p01315
|
u128811851
| 8,000 | 131,072 |
Wrong Answer
| 70 | 6,748 | 652 |
You are passionate about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use the income to grow the ranch. You wanted to grow your field quickly. Therefore, we decided to start by arranging the crops that can be grown in the game based on their income efficiency per hour. You have to buy seeds to grow crops. Here the species name of crop i is given by Li and the price by Pi. When a seed is planted in a field, it sprouts after time Ai. Young leaves emerge after time Bi from the emergence of buds. Leaves grow thick after time Ci from the emergence of young leaves. After the time Di has passed since the leaves grow thick, the flowers bloom. After the time Ei after the flower blooms, the fruit is formed. One seed produces Fi seeds, and each of these seeds can be sold at a price of Si. Some crops are multi-season crops and produce Mi crops in total. Mi = 1 for single cropping. Multi-season crops return to leaves after fruiting until Mi th fruiting. The income for a seed is the amount of money sold for all the fruit of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed until all fruits are produced. Your task is to write a program that takes the input crop information and sorts it in descending order of income efficiency.
|
while True:
amount = int(input())
if amount == 0:
break
efficiency_list = []
for _ in range(amount):
crop = input().split()
time = sum(map(int, crop[2:7]))
M = int(crop[9])
if M > 1:
for _ in range(1, M):
time += int(crop[5]) + int(crop[6])
fruits = M * int(crop[7])
efficiency = (fruits * int(crop[8]) - int(crop[1])) / time
efficiency_list.append(tuple([crop[0], efficiency]))
print(*efficiency_list)
efficiency_list.sort(key=lambda x:(-x[1], x[0]))
for element in efficiency_list:
print(element[0])
print("#")
|
s909968318
|
Accepted
| 60 | 6,732 | 617 |
while True:
amount = int(input())
if amount == 0:
break
efficiency_list = []
for _ in range(amount):
crop = input().split()
time = sum(map(int, crop[2:7]))
M = int(crop[9])
if M > 1:
for _ in range(1, M):
time += int(crop[5]) + int(crop[6])
fruits = M * int(crop[7])
efficiency = (fruits * int(crop[8]) - int(crop[1])) / time
efficiency_list.append((crop[0], efficiency))
efficiency_list.sort(key=lambda x:(-x[1], x[0]))
for element in efficiency_list:
print(element[0])
print("#")
|
s709753328
|
p03408
|
u940102677
| 2,000 | 262,144 |
Wrong Answer
| 29 | 3,060 | 157 |
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.
|
a=[]
b=[]
m=0
for _ in [0]*int(input()):
a += input()
for _ in [0]*int(input()):
b += input()
for s in a:
m = max(m, a.count(s)-b.count(s))
print(m)
|
s802407450
|
Accepted
| 18 | 3,060 | 161 |
a=[]
b=[]
m=0
for _ in [0]*int(input()):
a += [input()]
for _ in [0]*int(input()):
b += [input()]
for s in a:
m = max(m, a.count(s)-b.count(s))
print(m)
|
s509099907
|
p02612
|
u602481141
| 2,000 | 1,048,576 |
Wrong Answer
| 27 | 9,088 | 44 |
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
str = input()
int = int(str[-3:])
print(int)
|
s207727581
|
Accepted
| 27 | 9,144 | 87 |
str = input()
int = int(str[-3:])
if(int == 0):
print(0)
else:
print(1000-int)
|
s716848788
|
p03860
|
u997530672
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 35 |
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.
|
s = input()
print('A' + s[0] + 'C')
|
s239418599
|
Accepted
| 18 | 2,940 | 61 |
a, b, c = map(str, input().split())
print(a[0] + b[0] + c[0])
|
s378194885
|
p03546
|
u064408584
| 2,000 | 262,144 |
Wrong Answer
| 31 | 3,316 | 327 |
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
|
h,w=map(int, input().split())
c=[list(map(int, input().split())) for i in range(10)]
al=[list(map(int, input().split())) for i in range(h)]
ans=0
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j]=min(c[i][j],c[i][k]+c[k][j])
for i in al:
for j in i:
ans+=c[j][1]
print(ans)
|
s206472401
|
Accepted
| 32 | 3,316 | 359 |
h,w=map(int, input().split())
c=[list(map(int, input().split())) for i in range(10)]
al=[list(map(int, input().split())) for i in range(h)]
ans=0
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j]=min(c[i][j],c[i][k]+c[k][j])
ans=0
for i in al:
for j in i:
if j==-1:continue
ans+=c[j][1]
print(ans)
|
s123842396
|
p03455
|
u208713671
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 157 |
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
ab = list(map(int,input("a b =").split())) #1 3 5
a = ab[0]
b = ab[1]
if a*b %2 == 0:
output = "Even"
elif a*b %2 == 1:
output = "Odd"
print(output)
|
s536747961
|
Accepted
| 17 | 2,940 | 150 |
ab = list(map(int,input().split())) #1 3 5
a = ab[0]
b = ab[1]
if a*b %2 == 0:
output = "Even"
elif a*b %2 == 1:
output = "Odd"
print(output)
|
s048119426
|
p03827
|
u361826811
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,064 | 300 |
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
|
import sys
import itertools
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().decode('utf8')
print(max(0, S.count('I') - S.count('D')))
|
s144340651
|
Accepted
| 17 | 3,060 | 382 |
import sys
import itertools
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().decode('utf8')
ans = 0
cnt=0
for i in S:
if i == 'I':
cnt += 1
else:
cnt -= 1
ans=max(ans, cnt)
print(ans)
|
s553085880
|
p03026
|
u200785298
| 2,000 | 1,048,576 |
Wrong Answer
| 53 | 8,304 | 1,332 |
You are given a tree with N vertices 1,2,\ldots,N, and positive integers c_1,c_2,\ldots,c_N. The i-th edge in the tree (1 \leq i \leq N-1) connects Vertex a_i and Vertex b_i. We will write a positive integer on each vertex in T and calculate our _score_ as follows: * On each edge, write the smaller of the integers written on the two endpoints. * Let our score be the sum of the integers written on all the edges. Find the maximum possible score when we write each of c_1,c_2,\ldots,c_N on one vertex in T, and show one way to achieve it. If an integer occurs multiple times in c_1,c_2,\ldots,c_N, we must use it that number of times.
|
#!/usr/bin/env python3
import sys
def solve(N: int, a: "List[int]", b: "List[int]", C: "List[int]"):
conn = [[] for _ in range(N + 1)]
for i in range(N - 1):
conn[a[i]].append(b[i])
conn[b[i]].append(a[i])
counts = [[] for _ in range(N)]
for i in range(1, N + 1):
counts[i - 1] = [len(conn[i]), conn[i], 0, i - 1]
counts.sort(key=lambda x: x[0])
ret = 0
#print(counts)
C.sort()
for i, cnt in enumerate(counts):
cnt[2] = C[i]
#for node in cnt[1]:
# counts[node - 1][0] -= 1
vals = [0] * N
for cnt in counts:
vals[cnt[3]] = cnt[2]
for i in range(N - 1):
ret += min(vals[a[i] - 1], vals[b[i] - 1])
print(ret)
print(' '.join([str(v) for v in vals]))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
a = [int()] * (N-1) # type: "List[int]"
b = [int()] * (N-1) # type: "List[int]"
for i in range(N-1):
a[i] = int(next(tokens))
b[i] = int(next(tokens))
c = [ int(next(tokens)) for _ in range(N) ] # type: "List[int]"
solve(N, a, b, c)
if __name__ == '__main__':
main()
|
s790441404
|
Accepted
| 1,576 | 8,948 | 1,573 |
#!/usr/bin/env python3
import sys
#from queue import Queue
def solve(N: int, a: "List[int]", b: "List[int]", C: "List[int]"):
conn = [[] for _ in range(N)]
for i in range(N - 1):
conn[a[i] - 1].append(b[i] - 1)
conn[b[i] - 1].append(a[i] - 1)
#counts = [Queue() for _ in range(N)]
counts = [[] for _ in range(N)]
for i in range(N):
l = len(conn[i])
#counts[l].put([i, conn[i]])
counts[i] = [len(conn[i]), conn[i], 0, i]
#counts.sort(key=lambda x: x[0])
ret = 0
#print(counts)
C.sort()
idx = 0
while idx < N:
for cnt in counts:
if cnt[2] == 0 and cnt[0] <= 1:
cnt[2] = C[idx]
idx += 1
for node in cnt[1]:
counts[node][0] -= 1
vals = [0] * N
for cnt in counts:
vals[cnt[3]] = cnt[2]
for i in range(N - 1):
ret += min(vals[a[i] - 1], vals[b[i] - 1])
print(ret)
print(' '.join([str(v) for v in vals]))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
a = [int()] * (N-1) # type: "List[int]"
b = [int()] * (N-1) # type: "List[int]"
for i in range(N-1):
a[i] = int(next(tokens))
b[i] = int(next(tokens))
c = [ int(next(tokens)) for _ in range(N) ] # type: "List[int]"
solve(N, a, b, c)
if __name__ == '__main__':
main()
|
s856846287
|
p03416
|
u785578220
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,060 | 159 |
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
|
n,k=map(int, input().split())
if n==2 or k==2:
print(0)
elif n == 1 and k == 1:print(1)
elif n == 1 or k ==1:
print(max(n,k)-2)
else:print((n-2)*(k-2))
|
s981624240
|
Accepted
| 49 | 2,940 | 119 |
k , n = map(int, input().split())
r = 0
for i in range(k,n+1):
s = str(i)
if s == s[::-1]:
r+=1
print(r)
|
s107208646
|
p03623
|
u619458041
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 224 |
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
|
import sys
def main():
input = sys.stdin.readline
x, a, b = map(int, input().split())
if abs(a - x) >= abs(b - x):
return 'A'
else:
return 'B'
if __name__ == '__main__':
print(main())
|
s046632957
|
Accepted
| 18 | 2,940 | 224 |
import sys
def main():
input = sys.stdin.readline
x, a, b = map(int, input().split())
if abs(a - x) <= abs(b - x):
return 'A'
else:
return 'B'
if __name__ == '__main__':
print(main())
|
s726504580
|
p03597
|
u468972478
| 2,000 | 262,144 |
Wrong Answer
| 26 | 9,148 | 47 |
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
|
n = int(input())
w = int(input())
print(n - w)
|
s419122401
|
Accepted
| 26 | 9,152 | 52 |
n = int(input())
w = int(input())
print(n ** 2 - w)
|
s843015333
|
p02678
|
u838644735
| 2,000 | 1,048,576 |
Wrong Answer
| 648 | 68,528 | 712 |
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
def main():
N, M, *AB = map(int, open(0).read().split())
C = {}
for i in range(M):
a = AB[2 * i + 0] - 1
b = AB[2 * i + 1] - 1
if a not in C:
C[a] = []
C[a].append(b)
if b not in C:
C[b] = []
C[b].append(a)
ANS = {i:-1 for i in range(N)}
D = deque()
D.append((0, C[0]))
print(D)
while len(D) != 0:
d = D.popleft()
v = d[0]
L = d[1]
for l in L:
if ANS[l] == -1:
ANS[l] = v
D.append((l, C[l]))
print('Yes')
for i in range(1, N):
print(ANS[i] + 1)
if __name__ == '__main__':
main()
|
s849719787
|
Accepted
| 624 | 68,208 | 714 |
from collections import deque
def main():
N, M, *AB = map(int, open(0).read().split())
C = {}
for i in range(M):
a = AB[2 * i + 0] - 1
b = AB[2 * i + 1] - 1
if a not in C:
C[a] = []
C[a].append(b)
if b not in C:
C[b] = []
C[b].append(a)
ANS = {i:-1 for i in range(N)}
D = deque()
D.append((0, C[0]))
# print(D)
while len(D) != 0:
d = D.popleft()
v = d[0]
L = d[1]
for l in L:
if ANS[l] == -1:
ANS[l] = v
D.append((l, C[l]))
print('Yes')
for i in range(1, N):
print(ANS[i] + 1)
if __name__ == '__main__':
main()
|
s408666748
|
p03565
|
u833963136
| 2,000 | 262,144 |
Wrong Answer
| 29 | 9,108 | 824 |
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
|
s = str(input())
t = str(input())
ns = len(s)
nt = len(t)
start = -1
for j in range(ns):
if t[0] == s[j] or s[j] == '?':
i = 0
j_temp = j
is_ok = True
while i < nt:
i += 1
j_temp += 1
if j_temp >= ns:
is_ok = False
break
if s[j_temp] == '?' or s[j_temp] == t[i]:
if i == nt - 1:
break
continue
if s[j_temp] != t[i]:
is_ok = False
break
if is_ok:
start = j
ans = ""
if start == -1:
print("UNRESTORABLE")
exit()
for i in range(ns):
if start <= i < start + nt:
ans += t[i - start]
elif s[i] == "?":
ans += "a"
else:
ans += s[i]
print(start)
print(ans)
|
s695605910
|
Accepted
| 27 | 8,896 | 857 |
s = str(input())
t = str(input())
ns = len(s)
nt = len(t)
start = -1
for j in range(ns):
if t[0] == s[j] or s[j] == '?':
j_temp = j
i_temp = 0
is_ok = True
while i_temp < nt - 1:
i_temp += 1
j_temp += 1
if j_temp >= ns:
is_ok = False
break
if s[j_temp] == '?' or s[j_temp] == t[i_temp]:
if i_temp == nt - 1:
break
continue
if s[j_temp] != t[i_temp]:
is_ok = False
break
if is_ok:
start = max(j, start)
ans = ""
if start == -1:
print("UNRESTORABLE")
exit()
for i in range(ns):
if start <= i < start + nt:
ans += t[i - start]
elif s[i] == "?":
ans += "a"
else:
ans += s[i]
print(ans)
|
s134773150
|
p02417
|
u853619096
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,400 | 211 |
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
|
z = input()
a = []
b = 0
for i in z:
if i.isupper():
a += i.upper()
a += i
print(a)
al = [chr(i) for i in range(97, 97 + 26)]
for i in al:
b = str(a.count(i))
print('{} : {}'.format(i,b))
|
s880493515
|
Accepted
| 20 | 7,472 | 272 |
z=''
while True:
try:
z += input()
except EOFError:
break
a = []
b = 0
for i in z:
if i.isupper():
a += i.lower()
a += i
al = [chr(i) for i in range(97, 97 + 26)]
for i in al:
b = str(a.count(i))
print('{} : {}'.format(i,b))
|
s620324978
|
p03836
|
u020604402
| 2,000 | 262,144 |
Wrong Answer
| 21 | 3,064 | 416 |
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
|
x1,y1,x2,y2 = map(int ,input().split())
x = x2 - x1
y = y2 - y1
ans = ''
a = 'U'
b = 'D'
c = 'R'
d = 'L'
for _ in range(y):
ans += a
for _ in range(x):
ans += c
for _ in range(y):
ans += b
for _ in range(x) :
ans += d
ans += d
for _ in range(y + 1):
ans += a
for _ in range(x +1):
ans += c
ans += b
ans += c
for _ in range(y + 1):
ans += b
for _ in range(x + 1):
ans += d
print(ans)
|
s753067154
|
Accepted
| 21 | 3,064 | 425 |
x1,y1,x2,y2 = map(int ,input().split())
x = x2 - x1
y = y2 - y1
ans = ''
a = 'U'
b = 'D'
c = 'R'
d = 'L'
for _ in range(y):
ans += a
for _ in range(x):
ans += c
for _ in range(y):
ans += b
for _ in range(x) :
ans += d
ans += d
for _ in range(y + 1):
ans += a
for _ in range(x +1):
ans += c
ans += b
ans += c
for _ in range(y + 1):
ans += b
for _ in range(x + 1):
ans += d
ans += a
print(ans)
|
s559205265
|
p03478
|
u743272507
| 2,000 | 262,144 |
Wrong Answer
| 24 | 3,060 | 191 |
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
n,a,b = map(int,input().split())
def ketawa(i):
ret = 0
while(i):
ret += i % 10
i //= 10
return ret
ret = 0
for i in range(1,n+1):
if a <= ketawa(i) <= b: ret += 1
print(ret)
|
s999678679
|
Accepted
| 24 | 2,940 | 192 |
n,a,b = map(int,input().split())
def ketawa(i):
ret = 0
while(i):
ret += i % 10
i //= 10
return ret
ret = 0
for i in range(1,n+1):
if a <= ketawa(i) <= b: ret += i
print(ret)
|
s041989062
|
p03433
|
u248670337
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 55 |
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
print("YES" if int(input())%500<int(input()) else "NO")
|
s019963356
|
Accepted
| 17 | 2,940 | 56 |
print("Yes" if int(input())%500<=int(input()) else "No")
|
s073647755
|
p03545
|
u235376569
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 184 |
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
|
import sys
a,b,c,d=input()
op=["-","+"]
for i in op:
for j in op:
for k in op:
o=a+i+b+j+c+k+d
ans=eval(o)
if ans==7:
print(o+"+=7")
sys.exit()
|
s898711302
|
Accepted
| 18 | 2,940 | 184 |
import sys
a,b,c,d=input()
op=["-","+"]
for i in op:
for j in op:
for k in op:
o=a+i+b+j+c+k+d
ans=eval(o)
if ans==7:
print(o+"=7")
sys.exit()
|
s889351805
|
p02603
|
u605161376
| 2,000 | 1,048,576 |
Wrong Answer
| 25 | 9,160 | 368 |
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
|
K = int(input())
A = list(map(int, input().split()))
sum = 1000
kabu = 0
for k in range(K):
if k+1 ==K:
sum +=kabu*A[K-1]
break
if A[k]<A[k+1] and A[k]<=sum:
S = int(sum/A[k])
sum = sum-A[k]*S
kabu +=S
elif A[k]>A[k+1] and kabu != 0:
sum = sum + kabu * A[k]
kabu = 0
print(sum)
print(sum)
|
s868376381
|
Accepted
| 31 | 8,896 | 353 |
K = int(input())
A = list(map(int, input().split()))
sum = 1000
kabu = 0
for k in range(K):
if k+1 ==K:
sum +=kabu*A[K-1]
break
if A[k]<A[k+1] and A[k]<=sum:
S = int(sum/A[k])
sum = sum-A[k]*S
kabu +=S
elif A[k]>A[k+1] and kabu != 0:
sum = sum + kabu * A[k]
kabu = 0
print(sum)
|
s894656930
|
p03385
|
u143509139
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 146 |
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 = list(input())
str_list = ['abc','acb','bac','bca','cab','cba']
ans = 'No'
for l in str_list:
if s == l:
ans = 'Yes'
break
print(ans)
|
s617369687
|
Accepted
| 17 | 2,940 | 85 |
s = input()
if 'a' in s and 'b' in s and 'c' in s:
print('Yes')
else:
print('No')
|
s579936986
|
p03352
|
u685983477
| 2,000 | 1,048,576 |
Wrong Answer
| 18 | 2,940 | 120 |
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())
ans = 1
tmp = 0
for i in range(2, x):
tmp = i
while tmp*i <= x:
ans+=1
tmp*=i
print(ans)
|
s187287990
|
Accepted
| 17 | 2,940 | 137 |
x = int(input())
ans = 1
for i in range(2, 1000):
tmp = 2
while i**tmp <= x:
ans=max(ans, i**tmp)
tmp+=1
print(ans)
|
s379929090
|
p04030
|
u363438602
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,060 | 224 |
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()
s=list(s)
l=[]
ls=len(s)
for i in range (ls):
if s[i]=='1':
l.append(1)
elif s[i]=='0':
l.append(0)
else:
if len(l)==0:
l=l
else:
l.pop()
print(l)
|
s303282895
|
Accepted
| 17 | 3,064 | 279 |
s=input()
s=list(s)
l=[]
ls=len(s)
for i in range (ls):
if s[i]=='1':
l.append(1)
elif s[i]=='0':
l.append(0)
else:
if len(l)==0:
l=l
else:
l.pop()
ans=""
for i in range(len(l)):
ans=ans+str(l[i])
print(ans)
|
s093869021
|
p03494
|
u844172143
| 2,000 | 262,144 |
Wrong Answer
| 20 | 3,064 | 428 |
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
N = int(input())
A = list(map(int, input().split()))
def devide(array, count):
print(array);
dividable = True
for i in array:
if ((i % 2) != 0):
dividable = False
if (dividable):
print('a')
for index, value in enumerate(array):
array[index] = value / 2
count += 1
return devide(array, count)
else:
print('b')
print(array)
print(count)
return array, count
devided, count = devide(A, 0)
print(count)
|
s614683230
|
Accepted
| 18 | 3,064 | 357 |
N = int(input())
A = list(map(int, input().split()))
def devide(array, count):
dividable = True
for i in array:
if ((i % 2) != 0):
dividable = False
if (dividable):
for index, value in enumerate(array):
array[index] = value / 2
count += 1
return devide(array, count)
else:
return array, count
devided, count = devide(A, 0)
print(count)
|
s810627036
|
p03386
|
u503901534
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,064 | 500 |
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
|
l = list(map(int, input().split()))
a = l[0]
b = l[1]
c = l[2]
ss = []
ll = []
def checkK(x,y,z):
if y - x + 1 <= z:
counter = int(x)
while counter != y:
ss.append(counter)
counter = counter + 1
for i in range(len(ss)):
print(ss[i])
else:
for i in range(c):
ll.append(a+i)
for i in range(c):
ll.append(b-c+i)
for i in range(len(ll)):
print(ll[i])
checkK(a,b,c)
|
s638481772
|
Accepted
| 17 | 3,064 | 529 |
l = list(map(int, input().split()))
a = l[0]
b = l[1]
c = l[2]
ss = []
mm = []
ll = []
def checkK(x,y,z):
if y - x + 1 <= z *2:
counter = int(x)
while counter != y+1:
ss.append(counter)
counter = counter + 1
for i in range(len(ss)):
print(ss[i])
else:
for i in range(c):
ll.append(a+i)
for i in range(c):
ll.append(b-c+i+1)
for i in range(len(ll)):
print(ll[i])
checkK(a,b,c)
|
s335354853
|
p03377
|
u192541825
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 89 |
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a,b,x=map(int,input().split())
if a<=x and x<=a+b:
print("Yes")
else:
print("No")
|
s463988833
|
Accepted
| 17 | 2,940 | 89 |
a,b,x=map(int,input().split())
if a<=x and x<=a+b:
print("YES")
else:
print("NO")
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.