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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s353216552
|
p03828
|
u905582793
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,104
| 3,064
| 403
|
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
def prm(a):
if a==1:
return False
for i in range(2,int(a**0.5+1)):
if a%i==0:
return False
else:
return True
x=int(input())
d=[1]*(x+1)
for i in range(1,x+1):
if prm(i):
d[i]+=1
else:
while not prm(i):
for j in range(2,i):
if i%j==0:
d[j]+=1
i=i//j
break
ans=0
for i in range(x+1):
ans = ans * d[i] % (10**9+7)
print(ans)
|
s314948321
|
Accepted
| 24
| 3,064
| 453
|
def prm(a):
if a==1 or a == 4:
return False
for i in range(2,int(a**0.5+1)):
if a%i==0:
return False
else:
return True
x=int(input())
d=[1]*(x+1)
for i in range(1,x+1):
if prm(i):
d[i]+=1
else:
while not prm(i) and i != 1:
for j in range(2,i):
if i%j==0:
d[j]+=1
i=i//j
break
if i!= 1:
d[i]+=1
ans=1
for i in range(x+1):
ans = ans * d[i] % (10**9+7)
print(ans)
|
s963489634
|
p03861
|
u607075479
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 47
|
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(b//x-a//x)
|
s670930008
|
Accepted
| 18
| 2,940
| 68
|
a,b,x=map(int,input().split())
print(b//x-(a-1)//x if a else b//x+1)
|
s508196201
|
p04043
|
u706159977
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 100
|
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
|
a=list(map(int,input().split()))
if a[0]*a[1]*a[2] ==5*7*5:
print("yes")
else :
print("no")
|
s087433859
|
Accepted
| 18
| 2,940
| 100
|
a=list(map(int,input().split()))
if a[0]*a[1]*a[2] ==5*7*5:
print("YES")
else :
print("NO")
|
s740627257
|
p03044
|
u670180528
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 356
|
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
|
def solve():
n,*l=map(int,open(0).read().split())
con=[[] for _ in range(n)]
dist=[None]*n
dist[0]=0
for a,b,c in zip(*[iter(l)]*3):
con[a-1].append((b-1,c%2))
con[b-1].append((a-1,c%2))
stk=[0]
while stk:
cur=stk.pop()
for nxt,d in con[cur]:
if dist[nxt]==None:
stk.append(nxt)
dist[nxt]=(dist[cur]+d)%2
print(*dist,sep="\n")
|
s787335799
|
Accepted
| 334
| 49,396
| 423
|
def solve():
from collections import deque
n,*l=map(int,open(0).read().split())
con=[[] for _ in range(n)]
dist=[-1]*n
dist[0]=0
for a,b,c in zip(*[iter(l)]*3):
con[a-1].append((b-1,c%2))
con[b-1].append((a-1,c%2))
stk=deque([0])
while stk:
cur=stk.pop()
for nxt,d in con[cur]:
if dist[nxt]<0:
stk.append(nxt)
dist[nxt]=(dist[cur]+d)%2
print(*dist,sep="\n")
if __name__=="__main__":
solve()
|
s115217863
|
p03416
|
u360116509
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,060
| 83
|
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.
|
def main():
A, B = input().split()
print(int(B[:3]) - int(A[:3]))
main()
|
s393983529
|
Accepted
| 80
| 2,940
| 178
|
def main():
A, B = map(int, input().split())
c = 0
for i in range(A, B + 1):
if str(i)[:2] == str(i)[4] + str(i)[3]:
c += 1
print(c)
main()
|
s349356438
|
p04011
|
u050034744
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 170
|
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
data=[]
for i in range(4):
data.append(int(input()))
if data[0]>=data[1]:
a=data[2]*data[0]
b=data[3]*(data[0]-data[1])
print(a+b)
else:
print(data[2]*data[0])
|
s100077509
|
Accepted
| 18
| 3,060
| 170
|
data=[]
for i in range(4):
data.append(int(input()))
if data[0]>=data[1]:
a=data[2]*data[1]
b=data[3]*(data[0]-data[1])
print(a+b)
else:
print(data[2]*data[0])
|
s883713893
|
p03080
|
u646130340
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 165
|
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
|
N = int(input())
s = input()
R = 0
B = 0
for i in s:
if i == 'R':
R += 1
if i == 'B':
B += 1
if R > B:
print('YES')
else:
print('NO')
|
s333187544
|
Accepted
| 17
| 2,940
| 165
|
N = int(input())
s = input()
R = 0
B = 0
for i in s:
if i == 'R':
R += 1
if i == 'B':
B += 1
if R > B:
print('Yes')
else:
print('No')
|
s992831195
|
p03658
|
u093492951
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 161
|
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
|
N, K = [int(i) for i in input().split()]
l = [int(j) for j in input().split()]
l = sorted(l)
ans = 0
for k in range(-1, -K-1 -1):
ans += l[k]
print(ans)
|
s235980215
|
Accepted
| 17
| 2,940
| 159
|
N, K = [int(i) for i in input().split()]
l = [int(j) for j in input().split()]
l = sorted(l)
ans = 0
for k in range(N-K, N, 1):
ans += l[k]
print(ans)
|
s561964928
|
p03556
|
u446828107
| 2,000
| 262,144
|
Wrong Answer
| 37
| 9,056
| 124
|
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
|
N = int(input())
answer = 0
for x in range(1, 100000):
if x ** 2 <= N:
answer = x
else:
break
print(answer)
|
s819491824
|
Accepted
| 45
| 9,152
| 129
|
N = int(input())
answer = 0
for x in range(1, 100000):
if x ** 2 <= N:
answer = x ** 2
else:
break
print(answer)
|
s894255840
|
p03457
|
u390883247
| 2,000
| 262,144
|
Wrong Answer
| 525
| 28,472
| 421
|
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
N = int(input())
Data = []
for _ in range(N):
Data.append(list(map(int,input().split())))
ctime = 0
cx = 0
cy = 0
ans = True
for i in range(N):
nt,nx,ny = Data[i]
dist = abs(nx-cx)+abs(ny-cy)
dtime = nt-ctime
print(dist,dtime)
if dist > dtime or (dtime-dist) % 2 == 1:
ans = False
break
ctime = nt
cx = nx
cy = ny
if ans :
print('Yes')
else:
print('No')
|
s324554999
|
Accepted
| 434
| 27,324
| 399
|
N = int(input())
Data = []
for _ in range(N):
Data.append(list(map(int,input().split())))
ctime = 0
cx = 0
cy = 0
ans = True
for i in range(N):
nt,nx,ny = Data[i]
dist = abs(nx-cx)+abs(ny-cy)
dtime = nt-ctime
if dist > dtime or (dtime-dist) % 2 == 1:
ans = False
break
ctime = nt
cx = nx
cy = ny
if ans :
print('Yes')
else:
print('No')
|
s897417536
|
p03623
|
u791664126
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 61
|
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|.
|
a,b,c=map(int,input().split());print('AB'[abs(a-b)>abs(b-c)])
|
s280673458
|
Accepted
| 17
| 2,940
| 61
|
x,a,b=map(int,input().split());print('AB'[abs(x-a)>abs(x-b)])
|
s707104807
|
p02842
|
u584083761
| 2,000
| 1,048,576
|
Wrong Answer
| 154
| 12,500
| 394
|
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
|
import numpy as np
A = int(input())
if A >= 3000:
print(1)
else:
a = [100,101,102,103,104,105]
N = A//100
dp = np.array([np.array([0 for i in range(A+1)]) for j in range(N+1)])
dp[0][0] = 1
for i in range(N):
for j in np.where(dp[i] == 1)[0]:
#for j in range(A+1):
dp[i+1][j+100:j+106] = 1
print(dp[N][A])
|
s785994366
|
Accepted
| 17
| 3,060
| 183
|
import math
n = int(input())
a = n // 1.08
for i in range(3):
b = math.floor(a*1.08)
if b == n:
ans = round(a)
else:
a += 1
ans = ":("
print(ans)
|
s485951407
|
p04011
|
u894623942
| 2,000
| 262,144
|
Wrong Answer
| 24
| 9,044
| 69
|
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
N= [int(input()) for n in range(4)]
print(N[0]*N[2]+(N[0]-N[1])*N[3])
|
s181142760
|
Accepted
| 24
| 9,176
| 116
|
N= [int(input()) for n in range(4)]
if N[0] < N[1]:
print(N[0]*N[2])
else:
print(N[1]*N[2]+(N[0]-N[1])*N[3])
|
s628246174
|
p03156
|
u576917804
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 462
|
You have written N problems to hold programming contests. The i-th problem will have a score of P_i points if used in a contest. With these problems, you would like to hold as many contests as possible under the following condition: * A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points. The same problem should not be used in multiple contests. At most how many contests can be held?
|
n=int(input())
a,b = map(int,input().split())
p = map(int,input().split())
print(p)
list1 = []
list2 = []
list3 = []
for i in p:
if i<=a:
list1.append(i)
elif i<=b:
list2.append(i)
else:
list3.append(i)
if len(list1)>=len(list2):
if len(list2)>=len(list3):
print(len(list3))
else:
print(len(list2))
else:
if len(list1)>=len(list3):
print(len(list3))
else:
print(len(list1))
|
s255695684
|
Accepted
| 18
| 3,064
| 455
|
n=int(input())
a,b = map(int,input().split())
p = map(int,input().split())
list1 = []
list2 = []
list3 = []
for i in p:
if i<=a:
list1.append(i)
elif i<=b:
list2.append(i)
else:
list3.append(i)
if len(list1)>=len(list2):
if len(list2)>=len(list3):
print(len(list3))
else:
print(len(list2))
else:
if len(list1)>=len(list3):
print(len(list3))
else:
print(len(list1))
|
s207732816
|
p02678
|
u822172788
| 2,000
| 1,048,576
|
Wrong Answer
| 877
| 76,960
| 550
|
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
|
from collections import deque
[N, M] = [ int(x) for x in input().split() ]
G = dict()
for i in range(1,N+1):
G[i] = set()
for i in range(M):
[A,B] = [ int(x) for x in input().split() ]
G[A].add(B)
G[B].add(A)
ans = [0]*(N+1)
Q = deque([1])
visited = set()
while Q:
room = Q.popleft()
if room not in visited:
visited.add(room)
for r in G[room]:
if r not in visited:
ans[r] = room
Q.append(r)
ans[1] = 'Yes'
for i in range(1, N+1):
print(ans[i])
|
s277061444
|
Accepted
| 967
| 82,188
| 620
|
from collections import deque
[N, M] = [ int(x) for x in input().split() ]
G = dict()
for i in range(1,N+1):
G[i] = set()
for i in range(M):
[A,B] = [ int(x) for x in input().split() ]
G[A].add(B)
G[B].add(A)
ans = dict()
Q = deque([1])
visited = set()
while Q:
room = Q.popleft()
if room not in visited:
visited.add(room)
for r in G[room]:
if r not in ans:
ans[r] = room
Q.append(r)
for i in range(2, N+1):
if i not in ans:
print('No')
exit()
ans[1] = 'Yes'
for i in range(1, N+1):
print(ans[i])
|
s871629709
|
p02389
|
u336705996
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,576
| 43
|
Write a program which calculates the area and perimeter of a given rectangle.
|
a,b = map(int,input().split())
print(a*b)
|
s620893750
|
Accepted
| 20
| 5,580
| 51
|
a,b = map(int,input().split())
print(a*b,2*(a+b))
|
s842250533
|
p02842
|
u645618252
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 2,940
| 149
|
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
|
import math
N = int(input())
NN = math.floor(N / 1.08)
NNN = math.floor(NN*1.08)
print(NN, NNN)
if N == NNN:
print(NN)
else:
print(':(')
|
s661200657
|
Accepted
| 17
| 3,060
| 204
|
import math
N = int(input())
NN = math.floor(N / 1.08)
NNN = math.floor(NN*1.08)
if N == NNN:
print(NN)
else:
if math.floor((NN+1)*1.08) == N:
print(NN+1)
else:
print(':(')
|
s872739462
|
p02678
|
u733581231
| 2,000
| 1,048,576
|
Wrong Answer
| 2,209
| 46,936
| 701
|
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 defaultdict
from collections import deque
n , m = map(int , input().split())
g = defaultdict(list)
for i in range(m):
u , v = map(int , input().split())
g[u].append(v)
g[v].append(u)
print(g)
ans = [0]*(n+1)
visited = [False]*(n+1)
q = deque()
q.append(1)
depth = 1
while q:
node = q.popleft()
visited[node] = True
for ele in g[node]:
if not visited[ele]:
if ans[ele] == 0: ans[ele] = depth
q.append(ele)
depth+=1
#print(ans)
a = []
for i in range(2,n+1):
f = 1
for node in g[i]:
print(i,node,ans[i],ans[node])
if ans[node] == ans[i] - 1:
a.append(node)
f = 0
break
if f: print("NO"); exit()
print("YES")
for i in a:
print(i)
#print(ans)
|
s084801442
|
Accepted
| 738
| 39,956
| 515
|
from collections import defaultdict
from collections import deque
n , m = map(int , input().split())
g = defaultdict(list)
for i in range(m):
u , v = map(int , input().split())
g[u].append(v)
g[v].append(u)
#print(g)
visited = [False]*(n+1)
a = [10**10]*(n+1)
q = deque()
q.append(1)
while q:
node = q.popleft()
visited[node] = True
for ele in g[node]:
if not visited[ele]:
if a[ele] != 10**10:
continue
a[ele] = node
q.append(ele)
#print(ans)
#print(a)
print("Yes")
for i in a[2:]:
print(i)
|
s955336445
|
p03485
|
u049355439
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 102
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
a, b = map(int, input().split())
x = (a + b) / 2
if (a + b) % 2 == 0:
print(x)
else:
print(x + 1)
|
s831749755
|
Accepted
| 17
| 2,940
| 113
|
a, b = map(int, input().split())
x = (a + b) / 2
if (a + b) % 2 == 0:
print(int(x))
else:
print(int(x + 1))
|
s137509323
|
p03635
|
u696449926
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 135
|
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
|
chr = input()
chr_list = list(chr)
length = len(chr_list)
a, z = chr_list[0], chr_list[length - 1]
print(a, length - 2, z, sep = '')
|
s264812928
|
Accepted
| 17
| 2,940
| 63
|
n, m = input().split()
n = int(n)
m = int(m)
print((n-1)*(m-1))
|
s259979110
|
p02557
|
u331327289
| 2,000
| 1,048,576
|
Wrong Answer
| 199
| 44,848
| 455
|
Given are two sequences A and B, both of length N. A and B are each sorted in the ascending order. Check if it is possible to reorder the terms of B so that for each i (1 \leq i \leq N) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it.
|
import sys
from collections import Counter
def main():
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = Counter(a)
step = cnt.most_common(1)[0][1]
ans = [0] * n
for i in range(n):
ans[i] = b[(i - step) % n]
if ans[i] == a[i]:
print("No")
exit()
print(*ans)
if __name__ == "__main__":
main()
|
s973210657
|
Accepted
| 411
| 68,400
| 654
|
import sys
from bisect import bisect_right, bisect_left
from collections import Counter
def main():
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = Counter(a + b)
e, num = cnt.most_common(1)[0]
if num > n:
print("No")
else:
step = 0
for e in set(a) & set(b):
s = bisect_right(a, e) - bisect_left(b, e)
step = max(step, s)
ans = [0] * n
for i in range(n):
ans[i] = b[(i - step) % n]
print("Yes")
print(*ans)
if __name__ == "__main__":
main()
|
s747937510
|
p03698
|
u427984570
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 65
|
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
|
s = input()
t = set(s)
print("yes" if len(s) == set(t) else "no")
|
s363157827
|
Accepted
| 17
| 2,940
| 66
|
s = input()
t = set(s)
print("yes" if len(s) == len(t) else "no")
|
s483072054
|
p03478
|
u528720841
| 2,000
| 262,144
|
Wrong Answer
| 750
| 2,940
| 225
|
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 wa(n):
w = 0
while n != 0:
w += n % 10
n /= 10
return w
ans = 0
for i in range(1, N):
w = wa(i)
if A <= w and w <= B:
ans += 1
print(ans)
|
s619421173
|
Accepted
| 29
| 2,940
| 257
|
N, A, B = map(int, input().split())
def wa(n):
w = 0
while n != 0:
w += n % 10
n = int(n / 10)
return w
ans = 0
for i in range(1, N+1):
w = wa(i)
if A <= w and w <= B:
# print(i, w)
ans += i
print(ans)
|
s601641667
|
p03352
|
u243572357
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 2,940
| 111
|
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.
|
c = 1
a = int(input())
for i in range(1, a):
for j in range(2, a):
if i ** j <= a:
c = max(c, i**j)
|
s064445539
|
Accepted
| 25
| 2,940
| 129
|
n = int(input())
ans = 0
for i in range(1,1000):
for j in range(2, 10):
if i**j <= n:
ans = max(ans, i**j)
print(ans)
|
s840994888
|
p04043
|
u027929618
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 131
|
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.
|
n = input().split()
result = 'NO'
print(n)
if n.count('5') == 2 and n.count('7') == 1:
result = 'YES'
print("{} ".format(result))
|
s957137475
|
Accepted
| 17
| 2,940
| 121
|
n = input().split()
result = 'NO'
if n.count('5') == 2 and n.count('7') == 1:
result = 'YES'
print("{}".format(result))
|
s945034879
|
p04043
|
u295961023
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 186
|
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.
|
def main():
li = list(map(int, input().split()))
c5 = li.count(5)
c7 = li.count(7)
print("Yes" if c5 == 2 and c7 == 1 else "No")
if __name__ == '__main__':
main()
|
s482024940
|
Accepted
| 17
| 2,940
| 186
|
def main():
li = list(map(int, input().split()))
c5 = li.count(5)
c7 = li.count(7)
print("YES" if c5 == 2 and c7 == 1 else "NO")
if __name__ == '__main__':
main()
|
s180031378
|
p04043
|
u180528413
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 46
|
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.
|
S = map(int, input().split(' '))
print(sum(S))
|
s095832861
|
Accepted
| 17
| 2,940
| 98
|
A = map(int, input().split(' '))
A_sum = sum(A)
if A_sum == 17:
print('YES')
else:
print('NO')
|
s967751084
|
p03023
|
u606090886
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 161
|
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
|
s = input()
count = 0
for i in range(len(s)):
if s[i] == "〇":
count += 1
n = 15 - len(s) - count
if n >= 0:
print("YES")
else:
print("no")
|
s736662285
|
Accepted
| 17
| 2,940
| 33
|
n = int(input())
print((n-2)*180)
|
s117352040
|
p02420
|
u908651435
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,588
| 225
|
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
|
while True:
s=input()
if s=='-':
break
m=int(input())
s=list(s)
for i in range(m):
h=int(input())
for j in range(h):
pop=s.pop(0)
s.append(pop)
print(s)
|
s217871656
|
Accepted
| 20
| 5,584
| 242
|
while True:
s=input()
if s=='-':
break
m=int(input())
s=list(s)
for i in range(m):
h=int(input())
for j in range(h):
pop=s.pop(0)
s.append(pop)
a=''.join(s)
print(a)
|
s046324645
|
p03998
|
u610143410
| 2,000
| 262,144
|
Wrong Answer
| 25
| 3,316
| 1,323
|
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.
|
class Player:
def __init__(self, name):
self.name = name
self._cards = []
def setcards(self, cards):
for card in cards:
self._cards.insert(0, card)
def getcards(self):
return self._cards
cards = property(getcards, setcards)
def putDown(self):
if len(self.cards) != 0:
return self._cards.pop()
else:
return None
class Game:
def __init__(self, players):
self.players = players
def start(self):
ret = self.play(self.players[0].name)
return ret
def play(self, name):
target = self.searchTarget(name)
card = target.putDown()
if card != None:
return self.play(card)
return name
def searchTarget(self, name):
for player in self.players:
if player.name == name:
return player
if __name__ == '__main__':
a = Player("a")
a.cards = input()
b = Player("b")
b.cards = input()
c = Player("c")
c.cards = input()
g = Game([a, b, c])
winner = g.start()
print(winner)
|
s815982738
|
Accepted
| 24
| 3,188
| 1,331
|
class Player:
def __init__(self, name):
self.name = name
self._cards = []
def setcards(self, cards):
for card in cards:
self._cards.insert(0, card)
def getcards(self):
return self._cards
cards = property(getcards, setcards)
def putDown(self):
if len(self.cards) != 0:
return self._cards.pop()
else:
return None
class Game:
def __init__(self, players):
self.players = players
def start(self):
ret = self.play(self.players[0].name)
return ret
def play(self, name):
target = self.searchTarget(name)
card = target.putDown()
if card != None:
return self.play(card)
return name
def searchTarget(self, name):
for player in self.players:
if player.name == name:
return player
if __name__ == '__main__':
a = Player("a")
a.cards = input()
b = Player("b")
b.cards = input()
c = Player("c")
c.cards = input()
g = Game([a, b, c])
winner = g.start()
print(winner.upper())
|
s950114251
|
p03759
|
u332793228
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 63
|
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
|
a,b,c=map(int,input().split())
print("Yes"if b-a==c-b else"No")
|
s943378670
|
Accepted
| 17
| 2,940
| 63
|
a,b,c=map(int,input().split())
print("YES"if b-a==c-b else"NO")
|
s885331936
|
p03455
|
u410608556
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 120
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
int1,int2 = map(int, input().split())
mp = int1*int2
if mp%2 == 0:
print("even")
elif mp%2 == 1:
print("odd")
|
s693449287
|
Accepted
| 17
| 2,940
| 119
|
int1,int2 = map(int, input().split())
mp = int1*int2
if mp%2 == 0:
print("Even")
elif mp%2 == 1:
print("Odd")
|
s947088010
|
p03610
|
u855057563
| 2,000
| 262,144
|
Wrong Answer
| 81
| 9,880
| 97
|
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
|
s=list(input())
s1=[]
for i in s:
if (s.index(i)+1)%2==1:
s1.append(i)
print(i for i in s1)
|
s833022736
|
Accepted
| 37
| 9,096
| 68
|
s=input()
ans=""
for i in range(0,len(s),2):
ans+=s[i]
print(ans)
|
s518040301
|
p02388
|
u982632052
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,524
| 32
|
Write a program which calculates the cube of a given integer x.
|
x = int(input('> '))
print(x**3)
|
s513028829
|
Accepted
| 20
| 7,656
| 28
|
x = int(input())
print(x**3)
|
s216131522
|
p03854
|
u740767776
| 2,000
| 262,144
|
Wrong Answer
| 23
| 3,956
| 144
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
import re
S = input()
Snew = S[::-1]
print(Snew)
if re.sub('^maerd|remaerd|resare|esare$',"",Snew) == "":
print("Yes")
else:
print("No")
|
s793273331
|
Accepted
| 22
| 3,444
| 148
|
import re
S = input()
Snew = S[::-1]
result = re.sub('maerd|remaerd|resare|esare',"",Snew)
if result == "":
print("YES")
else:
print("NO")
|
s869578084
|
p02612
|
u150788544
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,052
| 81
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
n = int(input())
a = n//1000
b = n%1000
if b == 0:
print(a)
else:
print(a+1)
|
s927747949
|
Accepted
| 27
| 9,164
| 72
|
n = int(input())
b = n%1000
if b == 0:
print(0)
else:
print(1000-b)
|
s478303874
|
p03814
|
u381282312
| 2,000
| 262,144
|
Wrong Answer
| 91
| 14,664
| 174
|
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
|
s = input()
t = []
u = []
for i in range(len(s)):
if s[i] == 'A':
t.append(i)
if s[i] == 'Z':
u.append(i)
print(t)
print(u)
print(max(u) - min(t) + 1)
|
s128170923
|
Accepted
| 50
| 7,520
| 121
|
s = input()
a = s.index('A')
z = []
for i in range(len(s)):
if s[i] == 'Z':
z.append(i)
print(max(z) - a + 1)
|
s562524183
|
p02795
|
u742899538
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 73
|
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
|
H = int(input())
W = int(input())
N = int(input())
print(N // max(H, W))
|
s386226694
|
Accepted
| 18
| 2,940
| 113
|
H = int(input())
W = int(input())
N = int(input())
HW = max(H, W)
a = N // HW
if a * HW < N:
a += 1
print(a)
|
s423030317
|
p03502
|
u398613609
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 227
|
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
|
def solve():
s = input()
t = 0
for i in s:
t += int(i)
print(t)
X = int(s)
print(X % t)
if X % t:
print("No")
else:
print("Yes")
if __name__ == '__main__':
solve()
|
s429348626
|
Accepted
| 17
| 2,940
| 197
|
def solve():
s = input()
t = 0
for i in s:
t += int(i)
X = int(s)
if X % t:
print("No")
else:
print("Yes")
if __name__ == '__main__':
solve()
|
s560187205
|
p03574
|
u638033979
| 2,000
| 262,144
|
Wrong Answer
| 25
| 3,572
| 979
|
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
|
h,w = map(int,input().split())
gaze = ["W"+input()+"W" for _ in range(h)]
print(gaze)
gaze = ["W"*(w+2)]+gaze+["W"*(w+2)]
for i in range(1,h+1):
for j in range(1,w+1):
count = 0
if gaze[i][j] == ".":
if gaze[i-1][j-1] == "#":
count += 1
if gaze[i-1][j] == "#":
count += 1
if gaze[i-1][j+1] == "#":
count += 1
if gaze[i+1][j-1] == "#":
count += 1
if gaze[i+1][j] == "#":
count += 1
if gaze[i+1][j+1] == "#":
count += 1
if gaze[i][j-1] == "#":
count += 1
if gaze[i][j+1] == "#":
count += 1
gaze[i] = gaze[i][:j]+str(count)+gaze[i][j+1:]
s = "abcd"
print(gaze)
for i in range(1,h+1):
for j in range(1,w+1):
if j == w:
print(gaze[i][j])
else:
print(gaze[i][j],end="")
|
s371569608
|
Accepted
| 25
| 3,572
| 937
|
h,w = map(int,input().split())
gaze = ["W"+input()+"W" for _ in range(h)]
gaze = ["W"*(w+2)]+gaze+["W"*(w+2)]
for i in range(1,h+1):
for j in range(1,w+1):
count = 0
if gaze[i][j] == ".":
if gaze[i-1][j-1] == "#":
count += 1
if gaze[i-1][j] == "#":
count += 1
if gaze[i-1][j+1] == "#":
count += 1
if gaze[i+1][j-1] == "#":
count += 1
if gaze[i+1][j] == "#":
count += 1
if gaze[i+1][j+1] == "#":
count += 1
if gaze[i][j-1] == "#":
count += 1
if gaze[i][j+1] == "#":
count += 1
gaze[i] = gaze[i][:j]+str(count)+gaze[i][j+1:]
for i in range(1,h+1):
for j in range(1,w+1):
if j == w:
print(gaze[i][j])
else:
print(gaze[i][j],end="")
|
s933969490
|
p02417
|
u148628801
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,404
| 383
|
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
|
import sys
#fin = open("test.txt", "r")
fin = sys.stdin
sentence = fin.readline()
sentence = sentence.lower()
num_alphabet_list = [0 for i in range(27)]
for c in sentence:
if ord(c) < ord('a') or ord(c) > ord('z'):
continue
num_alphabet_list[ord(c) - ord('a')] += 1
for i in range(0, 27):
print(chr(i + ord('a')), end="")
print(" : ", end="")
print(num_alphabet_list[i])
|
s487788299
|
Accepted
| 20
| 7,456
| 379
|
import sys
#fin = open("test.txt", "r")
fin = sys.stdin
sentence = fin.read()
sentence = sentence.lower()
num_alphabet_list = [0 for i in range(26)]
for c in sentence:
if ord(c) < ord('a') or ord(c) > ord('z'):
continue
num_alphabet_list[ord(c) - ord('a')] += 1
for i in range(0, 26):
print(chr(i + ord('a')), end="")
print(" : ", end="")
print(num_alphabet_list[i])
|
s224614637
|
p02850
|
u503228842
| 2,000
| 1,048,576
|
Wrong Answer
| 2,105
| 34,408
| 637
|
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
|
N = int(input())
edge_num = [0]*(N+1)
edges = []
for _ in range(N-1):
a,b = map(int,input().split())
edge_num[a] += 1
edge_num[b] += 1
edges.append([a,b])
# print(edge_num)
# print(edges)
used_color_table = [[0] for _ in range(N+1)]
#print(used_color_table)
K = max(edge_num)
print(K)
for edge in edges:
for color in range(1,K+1):
if not color in used_color_table[edge[0]] and not color in used_color_table[edge[1]]: # use new color
color_idx = color
continue
print(color_idx)
used_color_table[edge[0]].append((color_idx))
used_color_table[edge[1]].append((color_idx))
|
s789573258
|
Accepted
| 1,404
| 57,972
| 1,029
|
from collections import OrderedDict
from collections import deque
N = int(input())
G = [[] for _ in range(N)]
od = OrderedDict()
for i in range(N-1):
a,b = map(int,input().split())
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
od[(a,b)] = 0
used = [False]*N
parent2colors = [0]*N
que = deque()
que.append(0)
used[0] = True
colors = 0
while len(que) != 0:
v = que.popleft()
colors = max(colors,len(G[v]))
cur_color = 1
for nv in G[v]:
if used[nv]:continue
if cur_color == parent2colors[v]:
cur_color += 1
if (v,nv) in od.keys():
od[(v,nv)] = cur_color
else:
od[(nv,v)] = cur_color
parent2colors[nv] = cur_color
cur_color += 1
used[nv] = True
que.append(nv)
print(colors)
for edge_clr in od.values():
print(edge_clr)
|
s645214393
|
p04011
|
u948524308
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 235
|
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
import sys
W = input()
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for num in alpha:
if W.count(num) %2 != 0:
print("No")
sys.exit()
print("yes")
|
s946265202
|
Accepted
| 17
| 2,940
| 176
|
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N <= K:
cost = N * X
print(cost)
else:
cost = K * X + (N - K) * Y
print(cost)
|
s648683474
|
p04035
|
u941438707
| 2,000
| 262,144
|
Wrong Answer
| 104
| 14,092
| 275
|
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
|
n,l,*a=map(int,open(0).read().split())
ans=[]
for i in range(1,n):
if a[i]+a[i-1]<l:
ans.append(i)
else:
for j in range(n-1,i-1,-1):
ans.append(j)
print("Possile")
print(*ans,sep="\n")
exit()
print("Impossible")
|
s714785688
|
Accepted
| 101
| 14,092
| 282
|
n,l,*a=map(int,open(0).read().split())
ans=[]
for i in range(1,n):
if a[i]+a[i-1]<l:
ans.append(i)
else:
for j in range(n-1,i-1,-1):
ans.append(j)
print("Possible")
print(*ans,sep="\n")
exit()
print("Impossible")
|
s680628591
|
p02388
|
u229478139
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,576
| 29
|
Write a program which calculates the cube of a given integer x.
|
a = int(input())
print(a**2)
|
s998051233
|
Accepted
| 20
| 5,572
| 35
|
n = int(input())
print(pow(n, 3))
|
s793771325
|
p03795
|
u305965165
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 49
|
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
|
n = int(input())
sub = n // 15
print(n*800 - sub)
|
s882544230
|
Accepted
| 17
| 2,940
| 54
|
n = int(input())
sub = n // 15
print(n*800 - sub*200)
|
s150182214
|
p02612
|
u102218630
| 2,000
| 1,048,576
|
Wrong Answer
| 29
| 9,016
| 48
|
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())
maisu=N//1000
print(N-1000*maisu)
|
s228579680
|
Accepted
| 32
| 9,152
| 94
|
N=int(input())
if N%1000==0:
print(0)
else:
maisu=(N//1000)+1
print(-N+1000*maisu)
|
s686764576
|
p03485
|
u595289165
| 2,000
| 262,144
|
Wrong Answer
| 153
| 12,420
| 73
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
import numpy as np
a, b = map(int, input().split())
print(np.ceil(a+b/2))
|
s294106808
|
Accepted
| 19
| 3,060
| 117
|
a, b = map(int, input().split())
sum_ab = a+b
if sum_ab % 2 == 0:
print(sum_ab//2)
else:
print(sum_ab//2 + 1)
|
s945462183
|
p02401
|
u326248180
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,648
| 266
|
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
while(True):
a, b, c = input().split()
a = int(a)
c = int(c)
if b == "+":
print(a + c)
elif b == "-":
print(a - c)
elif b == "*":
print(a * c)
elif b == "/":
print(a / c)
elif b == "?":
break
|
s716755640
|
Accepted
| 30
| 7,336
| 101
|
while 1:
data = input()
if '?' in data:
break
print(eval(data.replace('/','//')))
|
s484720158
|
p02271
|
u089830331
| 5,000
| 131,072
|
Wrong Answer
| 20
| 7,748
| 386
|
Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
|
def solve(p, t):
if p >= len(A): return False
if t == A[p]: return True
if t <= 0: return True
#print("({}, {})".format(p, t))
if solve(p + 1, t):
return True
else:
return solve(p + 1, t - A[p])
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
for t in M:
if solve(0, t): print("yes")
else: print("no")
|
s608419647
|
Accepted
| 150
| 11,076
| 546
|
memo = {}
def solve(p, t):
key = "{}:{}".format(p, t)
if key in memo: return memo[key]
if p >= len(A): return False
if t == A[p]: return True
if t <= 0: return False
#print("({}, {})".format(p, t))
if solve(p + 1, t):
memo["{}:{}".format(p + 1, t)] = True
return True
else:
memo["{}:{}".format(p + 1, t)] = False
return solve(p + 1, t - A[p])
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
for t in M:
if solve(0, t): print("yes")
else: print("no")
|
s175172178
|
p00009
|
u661290476
| 1,000
| 131,072
|
Wrong Answer
| 1,160
| 24,144
| 210
|
Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. 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.
|
prime=[False]*1000000
for i in range(2,1001):
for j in range(i*2,1000000,i):
prime[j]=True
while True:
try:
n=int(input())
except:
break
print(prime[:n+1].count(False))
|
s401736916
|
Accepted
| 730
| 24,148
| 227
|
prime=[True]*1000000
for i in range(2,1000):
if prime[i]:
for j in range(i*2,1000000,i):
prime[j]=False
while True:
try:
n=int(input())
except:
break
print(sum(prime[2:n+1]))
|
s197139486
|
p02257
|
u986478725
| 1,000
| 131,072
|
Wrong Answer
| 50
| 5,692
| 1,353
|
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.
|
# ALDS_1_C.
from math import sqrt, floor
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def get_prime():
P = []
P.append(2); P.append(3); P.append(5); P.append(7)
for n in range(8, 101):
is_prime = True
for i in range(4):
if n % P[i] == 0: is_prime = False; break
if is_prime: P.append(n)
for n in range(101, 10001):
is_prime = True
limit = floor(sqrt(n))
for i in range(len(P)):
if n % P[i] == 0: is_prime = False; break
if P[i] > limit: break
if is_prime: P.append(n)
return P
def main():
primes = get_prime()
n = int(input())
data = []
for i in range(n): data.append(int(input()))
count = 0
for i in range(n):
limit = floor(sqrt(data[i]))
is_prime = True
for p in primes:
if data[i] % p == 0: is_prime = False; break
if p > limit: break
if is_prime: count += 1
print(count)
if __name__ == "__main__":
main()
|
s924949845
|
Accepted
| 180
| 5,976
| 1,526
|
# ALDS_1_C.
from math import sqrt, floor
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def get_prime():
P = []
P.append(2); P.append(3); P.append(5); P.append(7)
for n in range(8, 101):
is_prime = True
for i in range(4):
if n % P[i] == 0: is_prime = False; break
if is_prime: P.append(n)
for n in range(101, 10001):
is_prime = True
limit = floor(sqrt(n))
for i in range(len(P)):
if n % P[i] == 0: is_prime = False; break
if P[i] > limit: break
if is_prime: P.append(n)
return P
def main():
primes = get_prime()
n = int(input())
data = []
for i in range(n): data.append(int(input()))
count = 0
for i in range(n):
if data[i] == 1: continue
if data[i] == 2: count += 1; continue
limit = floor(sqrt(data[i]))
is_prime = True
for p in primes:
if data[i] % p == 0: is_prime = False; break
if p > limit: break
if is_prime: count += 1
print(count)
if __name__ == "__main__":
main()
|
s543514938
|
p03494
|
u621345513
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 3,060
| 251
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
a_list = map(int, input().split())
can_devide = sum([a%2 for a in a_list])==0
count = 0
while can_devide:
count += 1
for i, a in enumerate(a_list):
a_list[i] = a//2
can_devide = sum([a%2 for a in a_list])==0
print(count)
|
s343213459
|
Accepted
| 19
| 2,940
| 270
|
_ = input()
a_list = list(map(int, input().split()))
can_devide = sum([a%2 for a in a_list])==0
count = 0
while can_devide:
count += 1
for i, a in enumerate(a_list):
a_list[i] = a//2
can_devide = sum([a%2 for a in a_list])==0
print(count)
|
s851885112
|
p00323
|
u260980560
| 2,000
| 262,144
|
Wrong Answer
| 20
| 7,548
| 227
|
会津特産の貴金属であるアイヅニウムをリサイクルするPCK社は、全国各地にネットワークを持ち、たくさんの回収車でアイヅニウムを集めてきます。この会社は、処理の効率化のために、塊の重さと個数の単位を規格で定めています。 塊の重さには「ボッコ」という単位を使います。x ボッコのアイヅニウムの重さは 2xグラムです。宝石で例えると、「カラット」のようなものです。また、塊の個数には「マルグ」という単位を使います。y マルグは 2y 個です。1箱に入っている品物の個数である「ダース」のようなものです。ただし、x と y は 0 以上の整数でなければいけません。 回収車 i は、 ai ボッコの重さのアイヅニウムを bi マルグずつ集めます。こうして集まったアイヅニウムを、炉の中に入れて溶かし、いくつかのアイヅニウムの塊を再生しますが、なるべくアイヅニウムの塊の数が少なくなるようにします。このとき、集めてきたアイヅニウムの重さの合計と、再生してできるアイヅニウムの重さの合計は変わりません。 回収車が集めたアイヅニウムの塊のボッコ単位の重さとマルグ単位の個数が与えられたとき、再生後のアイヅニウムの塊の数が最小になるような結果を求めるプログラムを作成せよ。
|
n = int(input())
s = 0
for i in range(n):
a, b = map(int, input().split())
s += 1 << (a+b)
i = 0
ans = []
while s:
if s & 1:
ans.append(i)
s >>= 1
i += 1
print(len(ans))
for e in ans:
print(e, 0)
|
s949093998
|
Accepted
| 1,980
| 10,452
| 211
|
n = int(input())
s = 0
for i in range(n):
a, b = map(int, input().split())
s += 1 << (a+b)
i = 0
ans = []
while s:
if s & 1:
ans.append(i)
s >>= 1
i += 1
for e in ans:
print(e, 0)
|
s618620477
|
p03699
|
u629350026
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 238
|
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
|
n=int(input())
s=[0]*n
for i in range(n):
s[i]=int(input())
s.sort()
ans=sum(s)
temp=0
if ans%10==0:
for i in range(n):
if s[i]%10==0:
temp=temp+1
else:
print(ans-s[i])
if temp==n:
print(0)
else:
print(ans)
|
s265082531
|
Accepted
| 17
| 3,064
| 250
|
n=int(input())
s=[0]*n
for i in range(n):
s[i]=int(input())
s.sort()
ans=sum(s)
temp=0
if ans%10==0:
for i in range(n):
if s[i]%10==0:
temp=temp+1
else:
print(ans-s[i])
break
if temp==n:
print(0)
else:
print(ans)
|
s927063900
|
p03555
|
u580236524
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 100
|
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')
|
s959198781
|
Accepted
| 17
| 2,940
| 100
|
a=input()
b=input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
print('YES')
else:
print('NO')
|
s562938496
|
p03605
|
u750651325
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 86
|
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
N = list(map(int, input().split()))
if 9 in N:
print("Yes")
else:
print("No")
|
s857195673
|
Accepted
| 17
| 2,940
| 69
|
N = list(input())
if "9" in N:
print("Yes")
else:
print("No")
|
s846266584
|
p02612
|
u972036293
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,144
| 101
|
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())
for i in range(11):
if 1000 * i >= N:
ans = i - N
break
print(ans)
|
s106026238
|
Accepted
| 28
| 9,148
| 109
|
N = int(input())
for i in range(11):
if 1000 * i >= N:
ans = 1000 * i - N
break
print(ans)
|
s498322745
|
p02866
|
u626468554
| 2,000
| 1,048,576
|
Wrong Answer
| 132
| 14,036
| 540
|
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition: * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.
|
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))
N = int(input())
D = list(map(int,input().split()))
cnt = [0 for i in range(N)]
flg = 1
if D[0]!=0:
flg = 0
for i in range(N):
if D[i]==0 and i!=0:
flg = 0
else:
cnt[D[i]] += 1
print(cnt)
ans = 1
mod = 998244353
flg2 = 1
for i in range(1,N):
if cnt[i]>0 and flg2:
ans *= cnt[i-1]**cnt[i]
ans %= mod
elif cnt[i]>0 and (not(flg2)):
flg = 0
else:
flg2 = 0
print(ans*flg)
|
s879213268
|
Accepted
| 131
| 14,396
| 530
|
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))
N = int(input())
D = list(map(int,input().split()))
cnt = [0 for i in range(N)]
flg = 1
if D[0]!=0:
flg = 0
for i in range(N):
if D[i]==0 and i!=0:
flg = 0
else:
cnt[D[i]] += 1
ans = 1
mod = 998244353
flg2 = 1
for i in range(1,N):
if cnt[i]>0 and flg2:
ans *= cnt[i-1]**cnt[i]
ans %= mod
elif cnt[i]>0 and (not(flg2)):
flg = 0
else:
flg2 = 0
print(ans*flg)
|
s572205493
|
p04029
|
u469392996
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 75
|
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?
|
a = input()
a = int(a) +1
i = 0
for i in range(a):
i = i + a
print(i)
|
s209379577
|
Accepted
| 17
| 2,940
| 83
|
a = input()
a = int(a) +1
add = 0
for i in range(a):
add = add + i
print(add)
|
s884368591
|
p02612
|
u163313981
| 2,000
| 1,048,576
|
Wrong Answer
| 27
| 9,152
| 88
|
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():
print(str(int(input()) % 1000))
if __name__ == '__main__':
main()
|
s223096824
|
Accepted
| 32
| 9,080
| 122
|
def main():
m = int(input()) % 1000
print(str(0 if m == 0 else 1000 - m))
if __name__ == '__main__':
main()
|
s164413129
|
p02279
|
u564398841
| 2,000
| 131,072
|
Wrong Answer
| 110
| 28,712
| 1,028
|
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**
|
def main():
N = int(input())
A = [0] * N
node_info = [[-1, 0, 'internal node', ['']] for _ in range(int(1E5 + 1))]
for i in range(N):
A[i] = [int(i) for i in input().strip().split()]
for line in A:
if line[1] != 0:
node_info[line[0]][3] = line[2:]
for c in line[2:]:
node_info[c][0] = line[0]
for line in A:
pid = node_info[line[0]][0]
if pid == -1:
node_info[line[0]][2] = 'root'
else:
if node_info[line[0]][3] is None:
node_info[line[0]][2] = 'leaf'
depth = 0
while pid != -1:
depth += 1
pid = node_info[pid][0]
node_info[line[0]][1] = depth
for line in A:
print('node {}: parent = {}, depth = {}, {}, [{}]'.format(
line[0], node_info[line[0]][0],
node_info[line[0]][1], node_info[line[0]][2], ', '.join([str(i) for i in node_info[line[0]][3]]))
)
if __name__ == '__main__':
main()
|
s237706937
|
Accepted
| 1,090
| 56,020
| 753
|
N = int(input())
tree = [{'p': -1, 'c': list(), 'd': 0} for _ in range(N)]
for _ in range(N):
l = list(map(int, input().split()))
tree[l[0]]['c'] = l[2:]
for i in l[2:]:
tree[i]['p'] = l[0]
def calcDepth(tree, root, curDepth=0):
tree[root]['d'] = curDepth
[calcDepth(tree, c, curDepth + 1) for c in tree[root]['c']]
r = 0
for i, t in enumerate(tree):
if t['p'] == -1:
r = i
break
calcDepth(tree, r)
for i in range(N):
state = 'leaf'
if tree[i]['p'] == -1:
state = 'root'
elif len(tree[i]['c']):
state = 'internal node'
print('node {i}: parent = {p}, depth = {d}, {state}, {ch}'.format(
i=i, p=tree[i]['p'], d=tree[i]['d'], state=state, ch=tree[i]['c']
))
|
s389616490
|
p03131
|
u370576244
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 138
|
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
|
K,A,B = map(int,input().split())
a = 1+K
K = K-A-1
if K % 2 == 0:
b = A+(B-A)*(int(K/2))
else:
b = A+(B-A)*(int(K/2))+1
print(max(a,b))
|
s412682601
|
Accepted
| 17
| 3,060
| 139
|
K,A,B = map(int,input().split())
a = 1+K
K = K-A+1
if K % 2 == 0:
b = A+(B-A)*(int(K/2))
else:
b = A+(B-A)*(int(K/2))+1
print(max(a,b))
|
s590171139
|
p03854
|
u540290227
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,188
| 151
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
s = input()
s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if s == '':
print('YES')
else:
print('NO')
|
s080693065
|
Accepted
| 19
| 3,188
| 155
|
s = input()
s = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if s == '':
print('YES')
else:
print('NO')
|
s610633099
|
p02616
|
u941438707
| 2,000
| 1,048,576
|
Wrong Answer
| 2,233
| 34,340
| 467
|
Given are N integers A_1,\ldots,A_N. We will choose exactly K of these elements. Find the maximum possible product of the chosen elements. Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).
|
n,k,*a=map(int,open(0).read().split())
mod=10**9+7
b=[i for i in a if i>0]
c=[i for i in a if i<0]
b.sort()
c.sort()
B,C=len(b),len(c)
D=n-B-C
b=b[::-1]+[0]*k
c+=[0]*k
ans=1
i=j=0
while k:
if b[i]>abs(c[j]):
ans*=b[i]
if ans>=0:
ans%=mod
i+=1
else:
ans*=c[j]
if ans>=0:
ans%=mod
j+=1
k-=1
print(ans)
if ans>=0:
print(ans)
else:
print(ans*pow(c[i-1],mod-2,mod)*c[i]%mod)
|
s638329818
|
Accepted
| 185
| 31,744
| 364
|
n,k,*a=map(int,open(0).read().split())
a.sort()
mod=10**9+7
ans=1
i=0
j=-1
kk=k
while kk>1:
if a[i]*a[i+1]>a[j]*a[j-1]:
ans=ans*a[i]*a[i+1]%mod
i+=2
kk-=2
else:
ans=ans*a[j]%mod
j-=1
kk-=1
if kk==1:
ans=ans*a[j]%mod
if a[-1]<0 and k%2==1:
ans=1
for i in a[n-k:]:
ans=ans*i%mod
print(ans)
|
s470749144
|
p02613
|
u135914156
| 2,000
| 1,048,576
|
Wrong Answer
| 154
| 9,208
| 282
|
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())
C0=0
C1=0
C2=0
C3=0
for i in range(n):
s=input()
if s=='AC':
C0+=1
if s=='WA':
C1+=1
if s=='TLE':
C2+=1
if s=='RE':
C3+=1
print('AC × '+str(C0))
print('WA × '+str(C1))
print('TLE × '+str(C2))
print('RE × '+str(C3))
|
s715518054
|
Accepted
| 148
| 9,152
| 278
|
n=int(input())
C0=0
C1=0
C2=0
C3=0
for i in range(n):
s=input()
if s=='AC':
C0+=1
if s=='WA':
C1+=1
if s=='TLE':
C2+=1
if s=='RE':
C3+=1
print('AC x '+str(C0))
print('WA x '+str(C1))
print('TLE x '+str(C2))
print('RE x '+str(C3))
|
s969769770
|
p04043
|
u474270503
| 2,000
| 262,144
|
Wrong Answer
| 16
| 2,940
| 106
|
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=map(int, input().split())
print("Yes" if max(a, b, c)==7 and min(a,b,c)==5 and a+b+c==17 else "No")
|
s700639099
|
Accepted
| 17
| 2,940
| 106
|
a,b,c=map(int, input().split())
print("YES" if max(a, b, c)==7 and min(a,b,c)==5 and a+b+c==17 else "NO")
|
s984176817
|
p02607
|
u931655383
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,080
| 117
|
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
|
n=int(input())
a=list(map(int,input().split()))
co=0
for i in range(n):
if i%2==0 and a[i]%2==1:
co+=1
print(n)
|
s984155176
|
Accepted
| 32
| 9,048
| 118
|
n=int(input())
a=list(map(int,input().split()))
co=0
for i in range(n):
if i%2==0 and a[i]%2==1:
co+=1
print(co)
|
s189619599
|
p03997
|
u182047166
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 67
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h/2)
|
s904897346
|
Accepted
| 17
| 2,940
| 79
|
a = int(input())
b = int(input())
h = int(input())
print(int((a + b) * h / 2))
|
s207909709
|
p00002
|
u985809245
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,596
| 134
|
Write a program which computes the digit number of sum of two integers a and b.
|
while True:
try:
value = input().split(" ")
result = int(value[0]) * int(value[1])
print(str(result))
except EOFError:
break
|
s180118544
|
Accepted
| 20
| 7,612
| 139
|
while True:
try:
value = input().split(" ")
result = str(int(value[0]) + int(value[1]))
print(len(result))
except EOFError:
break
|
s432329936
|
p02388
|
u352273463
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,328
| 24
|
Write a program which calculates the cube of a given integer x.
|
input("a")
print("a**3")
|
s388011347
|
Accepted
| 20
| 7,612
| 26
|
a=int(input())
print(a**3)
|
s295453138
|
p03643
|
u781027071
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 46
|
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
|
number = input('a')
print('ABC' + str(number))
|
s624672735
|
Accepted
| 18
| 2,940
| 29
|
n = input()
print('ABC' + n)
|
s868438892
|
p03469
|
u439392790
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 31
|
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
s=input()
print('2018/'+s[4:9])
|
s234460934
|
Accepted
| 18
| 2,940
| 37
|
s=str(input())
print('2018'+s[4:10])
|
s064044209
|
p02669
|
u323343031
| 2,000
| 1,048,576
|
Wrong Answer
| 1,902
| 13,908
| 990
|
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
|
DP = {}
def solve(n, a, b, c, d, did_plus=False):
if n <= 0:
return 0
if n == 1:
return d
if n in DP:
return DP[n]
ans = float('inf')
for i in range(-4, 5):
if did_plus:
if i > 0:
continue
num = n + i
trash = abs(i)*d
if num%5 == 0 and num // 5 < n:
ans = min(ans, solve(num//5, a, b, c, d, i>=0) + min(c, d*(num-(num//5))) + trash)
if num%3 == 0 and num // 3 < n:
ans = min(ans, solve(num//3, a, b, c, d, i>=0) + min(b, d*(num-(num//3))) + trash)
if num%2 == 0 and num // 2 < n:
ans = min(ans, solve(num//2, a, b, c, d, i>=0) + min(a, d*(num-(num//2))) + trash)
# print(str(n) + ' ' + str(ans) + ' ' + str(num) + ' ' + str(i))
DP[n] = ans
return ans
def solve2():
DP.clear()
n, a, b, c, d = map(int, input().split())
print(solve(n, a, b, c,d))
t = int(input())
for _ in range(t):
solve2()
|
s067229376
|
Accepted
| 1,971
| 14,080
| 1,231
|
DP = {}
def solve(n, a, b, c, d):
if n <= 0:
return 0
if n == 1:
return d
if n in DP:
return DP[n]
ans = float('inf')
for i in range(-3, 4):
num = n + i
trash = abs(i)*d
if num < 0:
continue
if num%5 == 0 and num // 5 < n:
ans = min(ans, solve(num//5, a, b, c, d) + min(c, d*(num-(num//5))) + trash)
if num%3 == 0 and num // 3 < n:
ans = min(ans, solve(num//3, a, b, c, d) + min(b, d*(num-(num//3))) + trash)
if num%2 == 0 and num // 2 < n:
ans = min(ans, solve(num//2, a, b, c, d) + min(a, d*(num-(num//2))) + trash)
# print(str(n) + ' ' + str(ans) + ' ' + str(num) + ' ' + str(i))
DP[n] = int(ans)
return int(ans)
def solve2():
DP.clear()
ans = float('inf')
n, a, b, c, d = map(int, input().split())
# for j in range(0, 30):
# for k in range(0, 10):
# ans = min(ans, a*i + b*j + c*k + abs(n - val)*(d))
# print(ans)
print(solve(n, a, b, c,d))
t = int(input())
for _ in range(t):
solve2()
|
s810018522
|
p02608
|
u201387466
| 2,000
| 1,048,576
|
Wrong Answer
| 50
| 11,008
| 934
|
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).
|
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
d = defaultdict(int)
for i in range(1,25):
for j in range(1,25):
for k in range(1,25):
a = i*i+j*j+k*k+i*j+j*k+k*i
d[a] += 1
N = int(input())
for i in range(1,N):
print(d[i])
|
s251505821
|
Accepted
| 537
| 13,024
| 939
|
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
d = defaultdict(int)
for i in range(1,100):
for j in range(1,100):
for k in range(1,100):
a = i*i+j*j+k*k+i*j+j*k+k*i
d[a] += 1
N = int(input())
for i in range(1,N+1):
print(d[i])
|
s393413018
|
p02389
|
u648470099
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,516
| 72
|
Write a program which calculates the area and perimeter of a given rectangle.
|
x,y=map(int, input().split())
a = int(x * y)
#print(x,y)
print(int(a))
|
s344779135
|
Accepted
| 20
| 7,656
| 83
|
x,y=map(int, input().split())
a = int(x * y)
b=int(2*x+2*y)
#print(x,y)
print(a,b)
|
s297049016
|
p03436
|
u422990499
| 2,000
| 262,144
|
Wrong Answer
| 24
| 3,192
| 1,558
|
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
|
H,W=map(int,input().split())
L=[]
for i in range(H):
l=list(input())
L.append(l)
T=[[0 for i in range(W)] for l in range(H)]
T[0][0]=1
S=[[0,0]]
SS=[[0,0]]
v=0
count=0
while 1:
count+=1
S=SS
SS=[]
while 1:
x=S[0][1]
y=S[0][0]
if 0<=y and y<H-1:
if L[y+1][x]=="." and T[y+1][x]==0:
s=[y+1,x]
T[y+1][x]=1
SS.append(s)
if y+1==H-1 and x==W-1:
v=1
break
if 0<y and y<=H-1:
if L[y-1][x]=="." and T[y-1][x]==0:
s=[y-1,x]
T[y-1][x]=1
SS.append(s)
if y-1==H-1 and x==W-1:
v=1
break
if 0<=x and x<W-1:
if L[y][x+1]=='.' and T[y][x+1]==0:
s=[y,x+1]
T[y][x+1]=1
SS.append(s)
if y==H-1 and x+1==W-1:
v=1
break
if 0<x and x<=W-1:
if L[y][x-1]=='.' and T[y][x-1]==0:
s=[y,x-1]
T[y][x-1]=1
SS.append(s)
if y==H-1 and x-1==W-1:
v=1
break
S.pop(0)
if len(S)==0:
break
if v==1:
break
if len(SS)==0:
v=0
break
x=0
print(count)
if v==0:
print(-1)
else:
for i in range(H):
for l in range(W):
if L[i][l]=='#':
x+=1
print(W*H-x-count-1)
|
s568447079
|
Accepted
| 24
| 3,192
| 1,545
|
H,W=map(int,input().split())
L=[]
for i in range(H):
l=list(input())
L.append(l)
T=[[0 for i in range(W)] for l in range(H)]
T[0][0]=1
S=[[0,0]]
SS=[[0,0]]
v=0
count=0
while 1:
count+=1
S=SS
SS=[]
while 1:
x=S[0][1]
y=S[0][0]
if 0<=y and y<H-1:
if L[y+1][x]=="." and T[y+1][x]==0:
s=[y+1,x]
T[y+1][x]=1
SS.append(s)
if y+1==H-1 and x==W-1:
v=1
break
if 0<y and y<=H-1:
if L[y-1][x]=="." and T[y-1][x]==0:
s=[y-1,x]
T[y-1][x]=1
SS.append(s)
if y-1==H-1 and x==W-1:
v=1
break
if 0<=x and x<W-1:
if L[y][x+1]=='.' and T[y][x+1]==0:
s=[y,x+1]
T[y][x+1]=1
SS.append(s)
if y==H-1 and x+1==W-1:
v=1
break
if 0<x and x<=W-1:
if L[y][x-1]=='.' and T[y][x-1]==0:
s=[y,x-1]
T[y][x-1]=1
SS.append(s)
if y==H-1 and x-1==W-1:
v=1
break
S.pop(0)
if len(S)==0:
break
if v==1:
break
if len(SS)==0:
v=0
break
x=0
if v==0:
print(-1)
else:
for i in range(H):
for l in range(W):
if L[i][l]=='#':
x+=1
print(W*H-x-count-1)
|
s695042407
|
p03555
|
u408760403
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 131
|
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
C1=input()
C2=input()
l1=list(C1)
l2=list(C2)
if l1[0]==l2[2] and l1[1]==l2[1] and l1[2]==l2[0]:
print('Yes')
else:
print('No')
|
s374534163
|
Accepted
| 17
| 2,940
| 131
|
C1=input()
C2=input()
l1=list(C1)
l2=list(C2)
if l1[0]==l2[2] and l1[1]==l2[1] and l1[2]==l2[0]:
print('YES')
else:
print('NO')
|
s783937824
|
p03623
|
u507116804
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 96
|
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
|
x,a,b=map(int, input().split())
A=abs(x-a)
B=abs(x-b)
if A>B:
print("A")
else:
print("B")
|
s823983113
|
Accepted
| 18
| 2,940
| 96
|
x,a,b= map(int, input().split())
A=abs(x-a)
B=abs(x-b)
if A>B:
print("B")
else:
print("A")
|
s044420324
|
p02613
|
u702399883
| 2,000
| 1,048,576
|
Wrong Answer
| 157
| 16,328
| 376
|
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 i in range(N)]
ac_count=0
wa_count=0
tle_count=0
re_count=0
for i in range(len(S)):
if S[i]=="AC":
ac_count+=1
if S[i]=="WA":
wa_count+=1
if S[i]=="TLE":
tle_count+=1
if S[i]=="RE":
re_count+=1
print("AC × ",ac_count)
print("WA × ",wa_count)
print("TLE × ",tle_count)
print("RE × ",re_count)
|
s193785328
|
Accepted
| 158
| 16,208
| 365
|
N=int(input())
S=[input() for i in range(N)]
ac_count=0
wa_count=0
tle_count=0
re_count=0
for i in range(len(S)):
if S[i]=="AC":
ac_count+=1
if S[i]=="WA":
wa_count+=1
if S[i]=="TLE":
tle_count+=1
if S[i]=="RE":
re_count+=1
print("AC x",ac_count)
print("WA x",wa_count)
print("TLE x",tle_count)
print("RE x",re_count)
|
s718892562
|
p00001
|
u362104929
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,396
| 202
|
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
|
def main():
l = []
for _ in range(10):
l.append(input())
l = sorted(l, reverse=True)
for i in range(3):
print(l[i])
return None
if __name__ == '__main__':
main()
|
s467331419
|
Accepted
| 20
| 7,680
| 207
|
def main():
l = []
for _ in range(10):
l.append(int(input()))
l = sorted(l, reverse=True)
for i in range(3):
print(l[i])
return None
if __name__ == '__main__':
main()
|
s934619139
|
p02972
|
u628335443
| 2,000
| 1,048,576
|
Wrong Answer
| 138
| 24,416
| 565
|
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.
|
import sys
def IN_I(): return int(sys.stdin.readline().rstrip())
def IN_LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IN_S(): return sys.stdin.readline().rstrip()
def IN_LS(): return list(sys.stdin.readline().rstrip().split())
N = IN_I()
a = IN_LI()
b = [0] * N
for i in range(N - 1, -1, -1):
if a[i] == 1:
b[i] = 1 - b[i]
if (i + 1) % 2 == 0:
b[i // 2] = 1
ans = []
for i in range(N):
if b[i] == 1:
ans.append(i + 1)
if len(ans) == 0:
print(0)
else:
print(' '.join(map(str, ans)))
|
s592092326
|
Accepted
| 428
| 26,596
| 563
|
import sys
def IN_I(): return int(sys.stdin.readline().rstrip())
def IN_LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IN_S(): return sys.stdin.readline().rstrip()
def IN_LS(): return list(sys.stdin.readline().rstrip().split())
N = IN_I()
a = [0] + IN_LI()
b = [0] * (N + 1)
ans = []
for i in range(N, 0, -1):
tmp = 0
for j in range(2 * i, N + 1, i):
tmp += b[j]
if tmp % 2 != a[i]:
b[i] = 1
ans.append(i)
if len(ans) == 0:
print(0)
else:
print(len(ans))
print(' '.join(map(str, ans)))
|
s494217481
|
p03067
|
u304486944
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 163
|
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
|
i = input().split(' ')
if i[0] < i[2]:
if i[1] > i[2]:
print('YES')
else:
print('NO')
else:
if i[1] > i[2]:
print('NO')
else:
print('YES')
|
s646421384
|
Accepted
| 17
| 3,060
| 217
|
a, b, c = input().split(' ')
a = int(a)
b = int(b)
c = int(c)
if a > c:
if b < c:
print('Yes')
else:
print('No')
else:
if b > c:
print('Yes')
else:
print('No')
|
s422379422
|
p04045
|
u894440853
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 231
|
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
|
n, k = map(int, input().split())
d = list(map(int, input().split()))
num = n
found = False
while not found:
for i in list(str(num)):
for d_k in d:
if i == d_k:
num += 1
break
found = True
print(num)
|
s416983751
|
Accepted
| 82
| 2,940
| 123
|
N, K = map(int, input().split())
D = set(input().split())
while True:
if not set(str(N)) & D:
break
N += 1
print(N)
|
s064146740
|
p03433
|
u516242950
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 95
|
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
n = int(input())
a = int(input())
if (n - a * 1) % 500 == 0:
print('Yes')
else:
print('No')
|
s424076996
|
Accepted
| 17
| 2,940
| 86
|
n = int(input())
a = (int(input()))
if n % 500 > a:
print('No')
else:
print('Yes')
|
s074248942
|
p03110
|
u972892985
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 165
|
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
|
n = int(input())
ans = 0
for i in range(n):
x, u = input().split()
if u == "BTC":
X = float(x)* 380000
ans += int(X)
else:
ans += int(x)
print(ans)
|
s783579697
|
Accepted
| 17
| 2,940
| 167
|
n = int(input())
ans = 0
for i in range(n):
x, u = input().split()
if u == "BTC":
X = float(x)* 380000
ans += float(X)
else:
ans += int(x)
print(ans)
|
s875833046
|
p03472
|
u103539599
| 2,000
| 262,144
|
Wrong Answer
| 369
| 11,352
| 293
|
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
|
T=0
N,H=map(int, input().split())
A=[]
B=[]
for i in range(N):
a,b=map(int, input().split())
A.append(a)
B.append(b)
A.sort(reverse=True)
for i in range(N):
if A[0]<B[i]:
H-=B[i]
T+=1
if H<=0:
break
if H>0:
T+=int(H/A[0])
print(T)
|
s598152637
|
Accepted
| 358
| 11,312
| 318
|
import math
N,H=map(int, input().split())
A=[]
B=[]
for i in range(N):
a,b=map(int, input().split())
A.append(a)
B.append(b)
ans=0
B.sort(reverse=True)
Am=max(A)
for i in range(N):
if B[i]>=Am:
H-=B[i]
ans+=1
if H<=0:
break
if H>0:
ans+=math.ceil(H/Am)
print(ans)
|
s399890405
|
p02417
|
u839008951
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,568
| 274
|
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
|
instr = input().lower()
alnum = ord('z') - ord('a') + 1
res = [0] * alnum
print(res)
for s in instr:
relc = ord(s) - ord('a')
if 0 <= relc and relc < alnum:
res[relc] += 1
for i in range(alnum):
print("{0} : {1}".format(chr(i + ord('a')), res[i]))
|
s615527043
|
Accepted
| 20
| 5,568
| 302
|
import sys
alnum = ord('z') - ord('a') + 1
res = [0] * alnum
for line in sys.stdin:
instr = line.lower()
for s in instr:
if s.isalpha():
relc = ord(s) - ord('a')
res[relc] += 1
for i in range(alnum):
print("{0} : {1}".format(chr(i + ord('a')), res[i]))
|
s976456692
|
p03738
|
u736729525
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 120
|
You are given two positive integers A and B. Compare the magnitudes of these numbers.
|
A = int(input())
B = int(input())
if A > B:
print("GEATER")
elif A < B:
print("LESS")
else:
print("EQUAL")
|
s468462438
|
Accepted
| 17
| 2,940
| 121
|
A = int(input())
B = int(input())
if A > B:
print("GREATER")
elif A < B:
print("LESS")
else:
print("EQUAL")
|
s900189407
|
p02616
|
u016128476
| 2,000
| 1,048,576
|
Wrong Answer
| 340
| 31,640
| 861
|
Given are N integers A_1,\ldots,A_N. We will choose exactly K of these elements. Find the maximum possible product of the chosen elements. Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9+7
A.sort(key=lambda x: abs(x), reverse=True)
best = [1, -1]
k = [0, 0]
for a in A:
if a == 0:
break
elif a > 0:
if k[0] < K:
best[0] = (best[0]*a)%MOD
k[0] += 1
if k[1] < K:
if k[1] > 0:
best[1] = (best[1]*a)%MOD
k[1] += 1
else:
tbest = best.copy()
if k[1] < K:
if k[1] > 0:
if tbest[0] < tbest[1]*a:
best[0] = (tbest[1]*a)%MOD
k[0] = k[1]+1
if k[0] < K:
if tbest[1] > tbest[0]*a:
best[1] = (tbest[0]*a)%MOD
k[1] = k[0]+1
if k[0] == K:
ans = best[0]
else:
ans = 1
for k in range(K):
ans = (ans*A[-1-k])%MOD
print(ans)
|
s087461308
|
Accepted
| 180
| 33,304
| 1,088
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9+7
def solve():
A.sort(key=lambda x: abs(x), reverse=True)
ans = 1
nneg = 0
a, b, c, d = -1, -1, -1, -1
for k in range(K):
ans = (ans * A[k])%MOD
if A[k] < 0:
nneg += 1
b = k
else:
a = k
if K == N or nneg%2 == 0:
return ans
for k in range(N-1, K-1, -1):
if A[k] < 0:
d = k
else:
c = k
# b must be >= 0
if a == -1 and c == -1: # all minus
ans = 1
for k in range(K):
ans = (ans * A[-1-k])%MOD
return ans
if a == -1 or d == -1:
outn = A[b]
inn = A[c]
elif c == -1:
outn = A[a]
inn = A[d]
else:
if A[a]*A[c] > A[b]*A[d]:
outn = A[b]
inn = A[c]
else:
outn = A[a]
inn = A[d]
ans = (ans * pow(outn, MOD-2, MOD))%MOD
ans = (ans * inn)%MOD
return ans
if __name__ == "__main__":
print(solve())
|
s000240793
|
p03110
|
u637824361
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 163
|
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
|
N = int(input())
ans = 0
for i in range(N):
x, u = input().split()
if u == "BTC":
ans += int(float(x) * 3.8 * (10**5))
else:
ans += int(x)
print(ans)
|
s811042197
|
Accepted
| 17
| 2,940
| 169
|
N = int(input())
ans = 0.00000000
for i in range(N):
x, u = input().split()
if u == "BTC":
ans += float(x) * 3.8 * (10**5)
else:
ans += float(x)
print(ans)
|
s390191117
|
p02612
|
u693025087
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,136
| 48
|
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.
|
# -*- coding: utf-8 -*-
print(int(input())%1000)
|
s577887136
|
Accepted
| 29
| 9,148
| 96
|
# -*- coding: utf-8 -*-
N = int(input())
if N%1000 == 0:
print(0)
else:
print(1000-(N%1000))
|
s295375362
|
p03720
|
u170183831
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,316
| 194
|
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
|
from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(int)
for _ in range(m):
a, b = input().split()
d[a] += 1
d[b] += 1
for i in range(n):
print(d[i + 1])
|
s436056526
|
Accepted
| 20
| 3,316
| 200
|
from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(int)
for _ in range(m):
a, b = input().split()
d[a] += 1
d[b] += 1
for i in range(n):
print(d[str(i + 1)])
|
s259620746
|
p02612
|
u848680818
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,144
| 31
|
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)
|
s677022162
|
Accepted
| 30
| 9,152
| 69
|
n = int(input())
if n%1000==0:
print(0)
else:
print(1000-(n%1000))
|
s154583042
|
p03962
|
u680851063
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 171
|
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
|
a=input().split()
#a=int(input())
#b=int(input())
#c=int(input())
#d=int(input())
if a[0]==a[1]==a[2]:
print(3)
elif a[0]!=a[1]!=a[2]:
print(1)
else:
print(2)
|
s824643464
|
Accepted
| 18
| 2,940
| 132
|
a=input().split()
if a[0]==a[1]==a[2]:
print(1)
elif a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]:
print(3)
else:
print(2)
|
s006680938
|
p03555
|
u772588522
| 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.
|
l_1 = input()
l_2 = input()
if l_2 == ''.join([l_1[-i-1] for i in range(len(l_1))]):
print('Yes')
else:
print('No')
|
s490547594
|
Accepted
| 17
| 2,940
| 120
|
l_1 = input()
l_2 = input()
if l_2 == ''.join([l_1[-i-1] for i in range(len(l_1))]):
print('YES')
else:
print('NO')
|
s603645222
|
p03433
|
u192429849
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 90
|
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
N = int(input())
A = int(input())
if N % 500 <= A:
print('YES')
else:
print('NO')
|
s626022186
|
Accepted
| 18
| 2,940
| 90
|
N = int(input())
A = int(input())
if N % 500 <= A:
print('Yes')
else:
print('No')
|
s886178422
|
p02659
|
u274635633
| 2,000
| 1,048,576
|
Wrong Answer
| 21
| 9,092
| 50
|
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
a,b=map(float,input().split())
print(int(0.5+a*b))
|
s278510878
|
Accepted
| 24
| 9,116
| 85
|
a,b=map(str,input().split())
a=int(a)
n=len(b)
c=int(b[:n-3]+b[n-2:])
print(a*c//100)
|
s983363008
|
p03569
|
u425448230
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,316
| 350
|
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly: * Insert a letter `x` to any position in s of his choice, including the beginning and end of s. Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
|
s = input()
count = 0
left, right = 0, len(s)-1
for i in range(100):
if s[left] == s[right]:
left, right = left+1, right-1
elif s[left] == 'x':
left = left+1
count += 1
elif s[right] == 'x':
right = right-1
count += 1
else :
count = -1
break
if left >= right:
break
|
s485559560
|
Accepted
| 68
| 3,316
| 354
|
s = input()
count = 0
left, right = 0, len(s)-1
while True:
if s[left] == s[right]:
left, right = left+1, right-1
elif s[left] == 'x':
left = left+1
count += 1
elif s[right] == 'x':
right = right-1
count += 1
else :
count = -1
break
if left >= right:
break
print(count)
|
s758847300
|
p03680
|
u864900001
| 2,000
| 262,144
|
Wrong Answer
| 348
| 8,428
| 288
|
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
|
#65
n = int(input())
a = []
for j in range(n):
a.append(int(input()))
count = 0
i = 1
for j in range(n+1):
if a[i-1]==2:
count += 1
print(count)
break
else:
i = a[i-1]
print(a[i-1], i)
count += 1
if j ==n:
print(-1)
|
s637735224
|
Accepted
| 222
| 7,084
| 263
|
#65
n = int(input())
a = []
for j in range(n):
a.append(int(input()))
count = 0
i = 1
for j in range(n+1):
if a[i-1]==2:
count += 1
print(count)
break
else:
i = a[i-1]
count += 1
if j ==n:
print(-1)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.