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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s126189001
|
p02692
|
u968166680
| 2,000
| 1,048,576
|
Wrong Answer
| 356
| 133,516
| 773
|
There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
|
from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 9)
def input():
return stdin.readline().strip()
N, A, B, C = map(int, input().split())
strings = [input() for _ in range(N)]
def dfs(index, hp):
if index == 0:
return ''
s1, s2 = strings[index-1]
if hp[s1] > 0:
hp2 = hp.copy()
hp2[s1] -= 1
hp2[s2] += 1
ret = dfs(index - 1, hp2)
if ret != False:
return ret + s2
if hp[s2] > 0:
hp2 = hp.copy()
hp2[s2] -= 1
hp2[s1] += 1
ret = dfs(index - 1, hp2)
if ret != False:
return ret + s1
return False
d = {'A': A, 'B': B, 'C': C}
ans = dfs(N, d)
if ans == False:
print('No')
else:
for c in ans:
print(c)
|
s250208510
|
Accepted
| 365
| 133,648
| 789
|
from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 9)
def input():
return stdin.readline().strip()
N, A, B, C = map(int, input().split())
strings = [input() for _ in range(N)]
def dfs(index, hp):
if index == N:
return ''
s1, s2 = strings[index]
if hp[s1] > 0:
hp2 = hp.copy()
hp2[s1] -= 1
hp2[s2] += 1
ret = dfs(index + 1, hp2)
if ret != False:
return s2 + ret
if hp[s2] > 0:
hp2 = hp.copy()
hp2[s2] -= 1
hp2[s1] += 1
ret = dfs(index + 1, hp2)
if ret != False:
return s1 + ret
return False
d = {'A': A, 'B': B, 'C': C}
ans = dfs(0, d)
if ans == False:
print('No')
else:
print('Yes')
for c in ans:
print(c)
|
s137666409
|
p03494
|
u659100741
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 298
|
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()))
cnt = 0
while True:
for i in range(len(a)):
if a[i] % 2 != 0:
break
elif i == len(a)-1:
for j in range(len(a)):
a[j] = a[j]/2
cnt += 1
else:
continue
break
print(cnt)
|
s129326868
|
Accepted
| 20
| 3,060
| 315
|
N = int(input())
a = list(map(int, input().split()))
cnt = 0
while True:
for i in range(len(a)):
if a[i] % 2 != 0:
break
elif i == len(a)-1:
for j in range(len(a)):
a[j] = a[j]/2
cnt += 1
else:
continue
break
print(cnt)
|
s634941866
|
p03400
|
u695079172
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 101
|
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
|
s = int(input())
sm = sum([int(c) for c in str(s)])
if s%sm == 0:
print("Yes")
else:
print("No")
|
s997882932
|
Accepted
| 18
| 3,060
| 366
|
def main():
n = int(input())
d,x = map(int,input().split())
a_s = []
answer = 0
dp = [[0]*d]*n
answer = 0
for i in range(n):
a_s.append(int(input()))
for i in range(n):
for j in range(d):
answer += 1 if (j%a_s[i]==0) else 0
print(answer+x)
main()
|
s154104594
|
p02646
|
u013415932
| 2,000
| 1,048,576
|
Wrong Answer
| 21
| 9,104
| 142
|
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
|
A,Av= map(int, input().split())
B,Bv= map(int,input().split())
T = int(input())
if abs(B-A)>(Av-Bv)*T :
print("No")
else:
print("Yes")
|
s934524000
|
Accepted
| 24
| 9,164
| 142
|
A,Av= map(int, input().split())
B,Bv= map(int,input().split())
T = int(input())
if abs(B-A)>(Av-Bv)*T :
print("NO")
else:
print("YES")
|
s932327091
|
p03470
|
u732870425
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 97
|
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
|
n = int(input())
d = [int(input()) for _ in range(n)]
dd = sorted(d, key=d.index)
print(len(dd))
|
s929340955
|
Accepted
| 18
| 2,940
| 73
|
n = int(input())
d = [int(input()) for _ in range(n)]
print(len(set(d)))
|
s758791893
|
p02409
|
u928633434
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,632
| 523
|
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
|
table = [[[ 0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
i = 0
while i < n:
b,f,r,v = (int(x) for x in input().split())
table[b-1][f-1][r-1] += v
i += 1
for i,elem_i in enumerate(table): # building
for j,elem_j in enumerate(elem_i): # floor
for k, elem_k in enumerate(elem_j): # room
if k != 0:
print (' ', end='')
print (str(elem_k), end='')
print ("")
if i != 3:
print ("###################")
|
s009664565
|
Accepted
| 20
| 5,624
| 483
|
table = [[[ 0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
i = 0
while i < n:
b,f,r,v = (int(x) for x in input().split())
table[b-1][f-1][r-1] += v
i += 1
for i,elem_i in enumerate(table): # building
for j,elem_j in enumerate(elem_i): # floor
for k, elem_k in enumerate(elem_j): # room
print (" " + str(elem_k), end='')
print ("")
if i != 3:
print ("####################")
|
s698709574
|
p03680
|
u998234161
| 2,000
| 262,144
|
Wrong Answer
| 198
| 14,108
| 232
|
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
|
N = int(input())
l = []
for i in range(N):
v = int(input())
l.append(v)
v = l[0]
print(l)
print(v)
ans = 0
while v != 2 and v != -1:
tmp = l[v-1]
l[v-1] = -1
v = tmp
ans += 1
if v == 2:
print(ans)
else:
print(-1)
|
s438531134
|
Accepted
| 177
| 12,948
| 218
|
N = int(input())
l = []
for i in range(N):
v = int(input())
l.append(v)
v = l[0]
ans = 1
while v != 2 and v != -1:
tmp = l[v-1]
l[v-1] = -1
v = tmp
ans += 1
if v == 2:
print(ans)
else:
print(-1)
|
s962571988
|
p02647
|
u278955646
| 2,000
| 1,048,576
|
Wrong Answer
| 2,206
| 32,172
| 434
|
We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i. Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row: * For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i. Find the intensity of each bulb after the K operations.
|
N, K = map(int, input().split())
work = list(map(int, input().split()))
for k in range(0, K):
A = work
work = [0] * N
for i in range(0, N):
for j in range(1, A[i] + 1):
index = i - j
if (index >= 0):
work[index] += 1
work[i] += 1
for j in range(1, A[i] + 1):
index = i + j
if (index < N):
work[i + j] += 1
print(work)
|
s516430432
|
Accepted
| 756
| 149,172
| 576
|
import numpy as np
from numba import njit
@njit('i8,i8,i8[::1]', cache=True)
def fn(N, K, A):
for _ in range(K):
B = np.zeros(N, dtype=np.int64)
for i in range(N):
l = max(0, i - A[i])
r = min(N - 1, i + A[i])
B[l] += 1
if (r + 1 < N):
B[r + 1] -= 1
A = np.cumsum(B)
if (np.all(A == N)):
return A
return A
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A, dtype=np.int64)
B = fn(N, K, A)
print(" ".join(B.astype(str)))
|
s070683329
|
p02255
|
u407235534
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,596
| 333
|
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
def print_tmp(a_li):
t = ''
for i in a_li:
t += str(i) + ' '
print(t)
n = int(input())
a = input()
A = [int(i) for i in a.split(' ')]
print_tmp(A)
for i in range(1, n-1):
v = A[i]
j = i -1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print_tmp(A)
print_tmp(A)
|
s459775575
|
Accepted
| 20
| 5,608
| 313
|
def print_tmp(a_li):
s = [str(a) for a in a_li]
t = ' '.join(s)
print(t)
n = int(input())
a = input()
A = [int(i) for i in a.split(' ')]
print_tmp(A)
for i in range(1, n):
v = A[i]
j = i -1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print_tmp(A)
|
s895794890
|
p02326
|
u022407960
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,672
| 830
|
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
output:
4
"""
import sys
def solve():
dp = [[0] * W for _ in range(H)]
max_width = 0
# for m in range(H):
# for n in range(W):
# print(m, n, carpet_info[m][n])
# dp[m][n] = (int(carpet_info[m][n]) + 1) % 2
# max_width |= dp[m][n]
for i in range(1, H):
for j in range(1, W):
if not int(carpet_info[i][j]):
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
max_width = max(max_width, dp[i][j])
return max_width
if __name__ == '__main__':
_input = sys.stdin.readlines()
H, W = map(int, _input[0].split())
carpet_info = list(map(lambda x: x.split(), _input[1:]))
print(solve())
|
s621074834
|
Accepted
| 1,540
| 60,312
| 611
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
output:
4
"""
import sys
def solve():
dp = [[0] * (W + 1) for _ in range(H + 1)]
for i in range(H):
for j in range(W):
if not int(carpet_info[i][j]):
dp[i + 1][j + 1] = min(dp[i][j], dp[i][j + 1], dp[i + 1][j]) + 1
max_width = max(map(max, dp))
return pow(max_width, 2)
if __name__ == '__main__':
_input = sys.stdin.readlines()
H, W = map(int, _input[0].split())
carpet_info = list(map(lambda x: x.split(), _input[1:]))
print(solve())
|
s252312314
|
p02272
|
u255317651
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,636
| 963
|
Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right)
|
# -*- coding: utf-8 -*-
"""
Created on Thu May 3 19:22:34 2018
ALDS-1-5-C
@author: maezawa
"""
n = int(input())
a = list(map(int, input().split()))
def merge_sort(a, left, right):
if left+1 < right:
mid = (left+right)//2
merge_sort(a, left, mid)
merge_sort(a, mid, right)
merge(a, left, mid, right)
def merge(a, left, mid, right):
n1 = mid - left
n2 = right - mid
l = [None for _ in range(n1+1)]
r = [None for _ in range(n2+1)]
for i in range(n1):
l[i] = a[left + i]
for i in range(n2):
r[i] = a[mid + i]
l[n1] = float('Inf')
r[n2] = float('Inf')
i = 0
j = 0
for k in range(left, right):
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
merge_sort(a, 0, len(a))
print(a[0], end='')
for i in range(1,len(a)):
print(' {}'.format(a[i]), end='')
print()
|
s317073442
|
Accepted
| 4,790
| 61,660
| 917
|
# -*- coding: utf-8 -*-
"""
Created on Thu May 3 19:22:34 2018
ALDS-1-5-C
@author: maezawa
"""
cnt = 0
n = int(input())
a = list(map(int, input().split()))
def merge_sort(a, left, right):
#global cnt
#cnt += 1
if left+1 < right:
mid = (left+right)//2
merge_sort(a, left, mid)
merge_sort(a, mid, right)
merge(a, left, mid, right)
def merge(a, left, mid, right):
global cnt
n1 = mid - left
n2 = right - mid
l = a[left:mid].copy()
r = a[mid:right].copy()
l.append(10**10)
r.append(10**10)
i = 0
j = 0
for k in range(left, right):
cnt += 1
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
merge_sort(a, 0, len(a))
print(a[0], end='')
for i in range(1,len(a)):
print(' {}'.format(a[i]), end='')
print()
print(cnt)
|
s183580819
|
p03855
|
u029315034
| 2,000
| 262,144
|
Wrong Answer
| 1,379
| 73,352
| 909
|
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
|
def dfs(r, c, g, color):
s = [r]
color[r] = c
while len(s) != 0:
u = s.pop()
for i in range(len(g[u])):
v = g[u][i]
if color[v] is None:
color[v] = c
s.append(v)
def assignColor(n, g, color):
color_id = 1
for u in range(n):
if color[u] is None:
dfs(u, color_id, g, color)
color_id += 1
N, K, L = [int(v) for v in input().split()]
road = [[] for i in range(N)]
train = [[] for i in range(N)]
for i in range(K):
p, q = [int(v) - 1 for v in input().split()]
road[p].append(q)
road[q].append(p)
for i in range(L):
r, s = [int(v) - 1 for v in input().split()]
train[r].append(s)
train[s].append(r)
road_color = [None] * N
train_color = [None] * N
assignColor(N, road, road_color)
assignColor(N, train, train_color)
print(' '.join([str(v) for v in road_color]))
|
s393417843
|
Accepted
| 1,470
| 98,916
| 1,067
|
from collections import Counter
def dfs(r, c, g, color):
s = [r]
color[r] = c
while len(s) != 0:
u = s.pop()
for i in range(len(g[u])):
v = g[u][i]
if color[v] is None:
color[v] = c
s.append(v)
def assignColor(n, g, color):
color_id = 1
for u in range(n):
if color[u] is None:
dfs(u, color_id, g, color)
color_id += 1
N, K, L = [int(v) for v in input().split()]
road = [[] for i in range(N)]
train = [[] for i in range(N)]
for i in range(K):
p, q = [int(v) - 1 for v in input().split()]
road[p].append(q)
road[q].append(p)
for i in range(L):
r, s = [int(v) - 1 for v in input().split()]
train[r].append(s)
train[s].append(r)
road_color = [None] * N
train_color = [None] * N
assignColor(N, road, road_color)
assignColor(N, train, train_color)
color_pairs = [(c1, c2) for c1, c2 in zip(road_color, train_color)]
pairs_cnt = Counter(color_pairs)
ans = [str(pairs_cnt[p]) for p in color_pairs]
print(' '.join(ans))
|
s719923014
|
p00002
|
u350064373
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,480
| 147
|
Write a program which computes the digit number of sum of two integers a and b.
|
try:
while True:
result=0
a,b = map(int, input().split())
result = a + b
print(len(result))
except:
pass
|
s949297173
|
Accepted
| 30
| 7,524
| 106
|
try:
while True:
a,b = map(int, input().split())
print(len(str(a+b)))
except:
pass
|
s334235755
|
p03861
|
u129978636
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 48
|
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-a//x)+1)
|
s882979252
|
Accepted
| 17
| 2,940
| 89
|
a,b,x=map(int, input().split())
c=b//x-a//x
if(a%x==0):
print(c+1)
else:
print(c)
|
s749842553
|
p02987
|
u873422538
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 282
|
You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S.
|
import itertools
import sys
def hantei(s):
i = 0
for s1, s2 in itertools.combinations(s, 2):
if s1 == s2:
i += 1
print(s1, s2)
return 'Yes' if i == 2 else 'No'
if __name__ == '__main__':
args = sys.stdin
for arg in args:
print(hantei(str(arg)))
|
s602438612
|
Accepted
| 17
| 3,060
| 359
|
import itertools
import sys
def hantei(s):
hantei = s.isupper()
if hantei:
i = 0
for s1, s2 in itertools.combinations(s, 2):
if s1 == s2:
i += 1
hantei = 'Yes' if i == 2 else 'No'
else:
hantei = 'No'
return hantei
if __name__ == '__main__':
args = sys.stdin
for arg in args:
print(hantei(str(arg)))
|
s976272270
|
p03699
|
u419535209
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 3,064
| 520
|
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?
|
def f(scores, d):
if len(scores) == 1:
if scores[0] % 10 == d:
res = 0
else:
res = scores[0]
else:
f1 = scores[0] + f(scores[1:], get_fld(scores[0], d))
if f1 % 10 == d:
f1 = 0
f2 = f(scores[1:], d)
res = max(f1, f2)
return res
def get_fld(score, d):
res = d - score % 10
if res < 0:
res += 10
return res
N = int(input())
scores = []
for _ in range(N):
scores.append(int(input()))
f(scores, 0)
|
s262851022
|
Accepted
| 17
| 3,060
| 336
|
def f(scores):
res = sum(scores)
if res % 10 == 0:
candidates = list(score for score in scores if score % 10 != 0)
if candidates:
res -= min(candidates)
else:
res = 0
return res
N = int(input())
scores = []
for _ in range(N):
scores.append(int(input()))
print(f(scores))
|
s342989422
|
p03408
|
u728120584
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 371
|
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
|
N = int(input())
S = {}
for i in range(N):
s = input()
if s not in S:
S[s] = 1
continue
S[s] +=1
M = int(input())
T = {}
for i in range(M):
t = input()
if t not in T:
T[t] = 1
continue
T[t] += 1
ans = 0
for key in S.keys():
if key not in T:
continue
ans = max(ans, S[key] - T[key])
print(ans)
|
s189470657
|
Accepted
| 17
| 3,064
| 402
|
N = int(input())
S = {}
for i in range(N):
s = input()
if s not in S:
S[s] = 1
continue
S[s] +=1
M = int(input())
T = {}
for i in range(M):
t = input()
if t not in T:
T[t] = 1
continue
T[t] += 1
ans = 0
for key in S.keys():
if key not in T:
ans = max(ans, S[key])
continue
ans = max(ans, S[key] - T[key])
print(ans)
|
s768170468
|
p03457
|
u902151549
| 2,000
| 262,144
|
Wrong Answer
| 311
| 4,848
| 3,634
|
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find():
def __init__(self,n):
self.n=n
self.P=[a for a in range(N)]
self.rank=[0]*n
def find(self,x):
if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
return self.P[x]
def same(self,x,y):
return self.find(x)==self.find(y)
def link(self,x,y):
if self.rank[x]<self.rank[y]:
self.P[x]=y
elif self.rank[y]<self.rank[x]:
self.P[y]=x
else:
self.P[x]=y
self.rank[y]+=1
def unite(self,x,y):
self.link(self.find(x),self.find(y))
def size(self):
S=set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def is_pow(a,b):
now=b
while now<a:
now*=b
if now==a:return True
else:return False
def bin_(num,size):
A=[0]*size
for a in range(size):
if (num>>(size-a-1))&1==1:
A[a]=1
else:
A[a]=0
return A
def get_facs(n,mod_=0):
A=[1]*(n+1)
for a in range(2,len(A)):
A[a]=A[a-1]*a
if(mod_>0):A[a]%=mod_
return A
def comb(n,r,mod,fac):
if(n-r<0):return 0
return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
x=num&(-num)
y=num+x
z=num&(~y)
z//=x
z=z>>1
num=(y|z)
if(num>=(1<<size)):return False
else:return num
def get_primes(n,type="int"):
if n==0:
if type=="int":return []
else:return [False]
A=[True]*(n+1)
A[0]=False
A[1]=False
for a in range(2,n+1):
if A[a]:
for b in range(a*2,n+1,a):
A[b]=False
if(type=="bool"):return A
B=[]
for a in range(n+1):
if(A[a]):B.append(a)
return B
def is_prime(num):
if(num<=1):return False
i=2
while i*i<=num:
if(num%i==0):return False
i+=1
return True
def ifelse(a,b,c):
if a:return b
else:return c
def join(A,c=""):
n=len(A)
A=list(map(str,A))
s=""
for a in range(n):
s+=A[a]
if(a<n-1):s+=c
return s
def factorize(n,type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b+=1
if n > 1:list_.append(n)
if type_=="dict":
dic={}
for a in list_:
if a in dic:
dic[a]+=1
else:
dic[a]=1
return dic
elif type_=="list":
return list_
else:
return None
def floor_(n,x=1):
return x*(n//x)
def ceil_(n,x=1):
return x*((n+x-1)//x)
return ret
def seifu(x):
return x//abs(x)
######################################################################################################
def main():
N=int(input())
f=True
p=0
for a in range(N):
t,x,y=map(int,input().split())
d=x+y
if not d==t-p:
f=False
p=t
Yn(f)
main()
|
s469341547
|
Accepted
| 395
| 29,128
| 3,846
|
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find():
def __init__(self,n):
self.n=n
self.P=[a for a in range(N)]
self.rank=[0]*n
def find(self,x):
if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
return self.P[x]
def same(self,x,y):
return self.find(x)==self.find(y)
def link(self,x,y):
if self.rank[x]<self.rank[y]:
self.P[x]=y
elif self.rank[y]<self.rank[x]:
self.P[y]=x
else:
self.P[x]=y
self.rank[y]+=1
def unite(self,x,y):
self.link(self.find(x),self.find(y))
def size(self):
S=set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def is_pow(a,b):
now=b
while now<a:
now*=b
if now==a:return True
else:return False
def bin_(num,size):
A=[0]*size
for a in range(size):
if (num>>(size-a-1))&1==1:
A[a]=1
else:
A[a]=0
return A
def get_facs(n,mod_=0):
A=[1]*(n+1)
for a in range(2,len(A)):
A[a]=A[a-1]*a
if(mod_>0):A[a]%=mod_
return A
def comb(n,r,mod,fac):
if(n-r<0):return 0
return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
x=num&(-num)
y=num+x
z=num&(~y)
z//=x
z=z>>1
num=(y|z)
if(num>=(1<<size)):return False
else:return num
def get_primes(n,type="int"):
if n==0:
if type=="int":return []
else:return [False]
A=[True]*(n+1)
A[0]=False
A[1]=False
for a in range(2,n+1):
if A[a]:
for b in range(a*2,n+1,a):
A[b]=False
if(type=="bool"):return A
B=[]
for a in range(n+1):
if(A[a]):B.append(a)
return B
def is_prime(num):
if(num<=1):return False
i=2
while i*i<=num:
if(num%i==0):return False
i+=1
return True
def ifelse(a,b,c):
if a:return b
else:return c
def join(A,c=""):
n=len(A)
A=list(map(str,A))
s=""
for a in range(n):
s+=A[a]
if(a<n-1):s+=c
return s
def factorize(n,type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b+=1
if n > 1:list_.append(n)
if type_=="dict":
dic={}
for a in list_:
if a in dic:
dic[a]+=1
else:
dic[a]=1
return dic
elif type_=="list":
return list_
else:
return None
def floor_(n,x=1):
return x*(n//x)
def ceil_(n,x=1):
return x*((n+x-1)//x)
return ret
def seifu(x):
return x//abs(x)
######################################################################################################
def main():
N=int(input())
f=True
p=0
px=0
py=0
A=[[] for a in range(N)]
for a in range(N):
A[a]=list(map(int,input().split()))
A.sort()
for a in range(N):
t,x,y=A[a][0],A[a][1],A[a][2]
d=abs(x-px)+abs(y-py)
if d>t-p:
f=False
elif ((t-p)-d)%2==1:
f=False
p=t
px=x
py=y
Yn(f)
main()
|
s474197299
|
p03719
|
u972892985
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 83
|
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
|
a, b, c = map(int,input().split())
if a >= c >= b:
print("Yes")
else:
print("No")
|
s118881430
|
Accepted
| 17
| 2,940
| 83
|
a, b, c = map(int,input().split())
if a <= c <= b:
print("Yes")
else:
print("No")
|
s361519231
|
p03477
|
u361826811
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 327
|
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
import sys
import itertools
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
A, B, C, D = map(int, readline().split())
print('Left' if A + B < C + D else 'Balanced' if A + B == C + D else 'Right')
|
s194167441
|
Accepted
| 17
| 3,060
| 327
|
import sys
import itertools
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
A, B, C, D = map(int, readline().split())
print('Left' if A + B > C + D else 'Balanced' if A + B == C + D else 'Right')
|
s050873504
|
p03574
|
u451017206
| 2,000
| 262,144
|
Wrong Answer
| 33
| 3,444
| 505
|
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.
|
from itertools import product
H, W = map(int, input().split())
a = []
for i in range(H): a.append(list(input()))
for i in range(H):
for j in range(W):
b = 0
if a[i][j] == '#':continue
for k,l in product([-1,0,1], repeat=2):
if k == l == 0:continue
h = i + k
w = j + l
if h < 0 or h >= H: continue
if w < 0 or w >= W: continue
if a[h][w] == '#':b+=1
a[i][j] = b
for i in range(H):
print(*a[i])
|
s995899178
|
Accepted
| 33
| 3,064
| 522
|
from itertools import product
H, W = map(int, input().split())
a = []
for i in range(H): a.append(list(input()))
for i in range(H):
for j in range(W):
b = 0
if a[i][j] == '#':continue
for k,l in product([-1,0,1], repeat=2):
if k == l == 0:continue
h = i + k
w = j + l
if h < 0 or h >= H: continue
if w < 0 or w >= W: continue
if a[h][w] == '#':b+=1
a[i][j] = b
for i in range(H):
print(''.join(map(str,a[i])))
|
s157584442
|
p03131
|
u633051991
| 2,000
| 1,048,576
|
Wrong Answer
| 281
| 18,848
| 188
|
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.
|
import numpy as np
K,A,B = map(int,input().split())
if A+1>=B or K<A+1:
print(K+1)
else:
ex = (K-A+1)//2
res= (K-A+1)%2
print(ex)
print(res)
print(A+ex*(B-A)+res)
|
s581841446
|
Accepted
| 149
| 12,488
| 192
|
import numpy as np
K,A,B = map(int,input().split())
if A+1>=B or K<A+1:
print(K+1)
else:
ex = (K-A+1)//2
res= (K-A+1)%2
# print(ex)
# print(res)
print(A+ex*(B-A)+res)
|
s278487188
|
p00018
|
u744114948
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,720
| 94
|
Write a program which reads five numbers and sorts them in descending order.
|
s=list(map(int, input().split()))
s.sort()
for i in s:
print(str(i)+" ", end="")
print()
|
s885944640
|
Accepted
| 20
| 7,644
| 99
|
l = list(map(int, input().split()))
l.sort()
l.reverse()
sl = list(map(str, l))
print(" ".join(sl))
|
s194814183
|
p02853
|
u066455063
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 219
|
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
|
X, Y = map(int, input().split())
ans = 0
if X == 1 and Y == 1:
ans = 700000
elif X == 1 or Y == 1:
ans += 300000
elif X == 2 or Y == 2:
ans += 200000
elif X == 3 or Y == 3:
ans += 100000
print(ans)
|
s454973679
|
Accepted
| 17
| 3,060
| 317
|
X, Y = map(int, input().split())
ans = 0
if X == 1 and Y == 1:
ans = 700000
if X == 2 and Y == 2:
print(400000)
exit()
if X == 3 and Y == 3:
print(200000)
exit()
if X == 1 or Y == 1:
ans += 300000
if X == 2 or Y == 2:
ans += 200000
if X == 3 or Y == 3:
ans += 100000
print(ans)
|
s112782171
|
p03448
|
u610473220
| 2,000
| 262,144
|
Wrong Answer
| 49
| 3,060
| 228
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
|
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cou = 0
for i in range(A):
for j in range(B):
for k in range(C):
if 500 * i + 100 * j + 50 * k == X:
cou += 1
print(cou)
|
s495358520
|
Accepted
| 50
| 3,060
| 234
|
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cou = 0
for i in range(A+1):
for j in range(B+1):
for k in range(C+1):
if 500 * i + 100 * j + 50 * k == X:
cou += 1
print(cou)
|
s944062960
|
p04045
|
u953110527
| 2,000
| 262,144
|
Wrong Answer
| 84
| 6,344
| 333
|
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.
|
from collections import deque
n,k = map(int,input().split())
d = set(list(map(int,input().split())))
a = list({0,1,2,3,4,5,6,7,8,9} - d)
a.sort()
que = deque()
que.append(0)
while que:
ans = que.popleft()
if ans >= n:
print(ans)
exit()
for i in a:
que.append(ans*10 + i)
print(ans*10 + i)
|
s301343254
|
Accepted
| 36
| 5,620
| 307
|
from collections import deque
n,k = map(int,input().split())
d = set(list(map(int,input().split())))
a = list({0,1,2,3,4,5,6,7,8,9} - d)
a.sort()
que = deque()
que.append(0)
while que:
ans = que.popleft()
if ans >= n:
print(ans)
exit()
for i in a:
que.append(ans*10 + i)
|
s134334909
|
p02402
|
u732614538
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,456
| 79
|
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
|
input()
A = list(input().split())
print(min(A),max(A),sum([int(i) for i in A]))
|
s381373948
|
Accepted
| 20
| 8,652
| 79
|
input()
A = list([int(i) for i in input().split()])
print(min(A),max(A),sum(A))
|
s716399570
|
p03386
|
u757274384
| 2,000
| 262,144
|
Wrong Answer
| 2,103
| 3,060
| 164
|
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
|
a,b,k = map(int, input().split())
ans = []
for i in range(a,b+1):
if a<= i <= a+k or b-k <= i <= b:
ans.append(i)
for i in range(len(ans)):
print(ans[i])
|
s358212736
|
Accepted
| 17
| 3,060
| 179
|
a,b,k = map(int, input().split())
A = list(range(a,min(a+k,b+1)))
B = list(range(max(a,b-k+1),b+1))
ans = list(set(A)|set(B))
ans.sort()
for i in range(len(ans)):
print(ans[i])
|
s606025898
|
p03999
|
u236536206
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 280
|
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
|
def dfs(i, f):
if i == n - 1:
return sum(list(map(int, f.split("+"))))
dfs(i + 1, f + s[i + 1])
dfs(i + 1, f + "+" + s[i + 1])
s = input()
n = len(s)
print(dfs(0, s[0]))
|
s566205461
|
Accepted
| 19
| 3,060
| 166
|
s=input()
n=len(s)
def dfs(i,f):
if i==n-1:
return sum(list(map(int,f.split("+"))))
return dfs(i+1,f+s[i+1])+dfs(i+1,f+"+"+s[i+1])
print(dfs(0,s[0]))
|
s131313149
|
p00015
|
u362104929
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,676
| 700
|
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
|
n = int(input())
for _ in range(n):
a = input()
b = input()
m = max(len(a), len(b))
if m > 80:
print("overflow")
a = list(reversed(a))
b = list(reversed(b))
t = 0
ans = []
for i in range(m):
try:
num_a = int(a[i])
except:
num_a = 0
try:
num_b = int(b[i])
except:
num_b = 0
s = num_a + num_b + t
if s >= 10:
t = 1
s -= 10
ans.insert(0, s)
else:
ans.insert(0, s)
t = 0
if t == 1:
ans.insert(0, 1)
if len(ans) > 80:
print("overflow")
else:
print(*ans, sep="")
|
s605777703
|
Accepted
| 30
| 7,672
| 935
|
def main():
n = int(input())
answers = []
for _ in range(n):
a = input()
b = input()
la, lb = len(a), len(b)
if la > 80 or lb > 80:
answers.append("overflow")
continue
if la > lb:
ll = la
for _ in range(la-lb):
b = "0" + b
else:
ll = lb
for _ in range(lb-la):
a = "0" + a
ans = ""
bl = 0
for i in range(ll):
tmp = int(a[ll-i-1]) + int(b[ll-i-1]) + bl
if tmp >= 10:
bl = 1
tmp = tmp % 10
else:
bl = 0
ans = str(tmp) + ans
if bl == 1:
ans = "1" + ans
if len(ans) > 80:
answers.append("overflow")
continue
answers.append(ans)
print(*answers, sep="\n")
if __name__ == "__main__":
main()
|
s936299159
|
p03543
|
u772069660
| 2,000
| 262,144
|
Wrong Answer
| 23
| 7,156
| 176
|
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
|
N = int(input())
if N==0:
print(2)
elif N==1:
print(1)
else:
lucas = [2, 1]
for i in range(N-1):
lucas.append(lucas[i]+lucas[i+1])
print(lucas[-1])
|
s027097257
|
Accepted
| 17
| 2,940
| 142
|
N = input()
if (N[0] == N[1] and N[1] == N[2]):
print("Yes")
elif(N[1] == N[2] and N[2] == N[3]):
print("Yes")
else:
print("No")
|
s372138243
|
p03681
|
u196697332
| 2,000
| 262,144
|
Wrong Answer
| 85
| 3,060
| 271
|
Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys. How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
|
import sys
MOD = 1e9 + 7
N, M = map(int, input().split())
ans = 1
if abs(N - M) > 1:
print(0)
sys.exit()
for n in range(2, N + 1):
ans *= n
ans %= MOD
for m in range(2, M + 1):
ans *= m
ans %= MOD
if N == M:
ans *= 2
ans %= MOD
print(ans)
|
s823147547
|
Accepted
| 93
| 3,060
| 276
|
import sys
MOD = 1e9 + 7
N, M = map(int, input().split())
ans = 1
if abs(N - M) > 1:
print(0)
sys.exit()
for n in range(2, N + 1):
ans *= n
ans %= MOD
for m in range(2, M + 1):
ans *= m
ans %= MOD
if N == M:
ans *= 2
ans %= MOD
print(int(ans))
|
s433087017
|
p03549
|
u094191970
| 2,000
| 262,144
|
Wrong Answer
| 689
| 9,492
| 319
|
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
|
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
ms=1900*m+100*(n-m)
print(ms)
ans=0
for i in range(1,10**6):
p1=0.5**m
p2=(1-0.5**m)**(i-1)
p=p1*p2
t_ms=ms*i
ans+=p*t_ms
ans=int(ans)
q=ans%10
if q!=0:
ans+=10-q
print(ans)
|
s814953650
|
Accepted
| 30
| 9,100
| 176
|
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
ms=1900*m+100*(n-m)
ans=ms*(2**m)
print(ans)
|
s432681488
|
p03457
|
u425236751
| 2,000
| 262,144
|
Wrong Answer
| 359
| 3,064
| 210
|
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
n = int(input())
t=0
x=0
y=0
ans ="Yes"
for i in range(n):
tt,xx,yy = map(int,input().split())
dif = abs(x-xx)
dif +=abs(y-yy)
if (tt-t != dif):
ans = "No"
break;
t=tt
x=xx
y=yy
print(ans)
|
s341154756
|
Accepted
| 371
| 3,064
| 227
|
n = int(input())
t=0
x=0
y=0
ans ="Yes"
for i in range(n):
tt,xx,yy = map(int,input().split())
dif = abs(x-xx)
dif +=abs(y-yy)
if dif>(tt-t) or dif%2 !=(tt-t)%2:
ans = "No"
break;
t=tt
x=xx
y=yy
print(ans)
|
s171701304
|
p03415
|
u905510147
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 70
|
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
|
a = 0
for i in range(3):
li = input()
print(li[i])
i += 1
|
s789732932
|
Accepted
| 17
| 2,940
| 91
|
a = 0
ans = ""
for i in range(3):
li = input()
ans += li[i]
i += 1
print(ans)
|
s783163132
|
p03814
|
u405328424
| 2,000
| 262,144
|
Wrong Answer
| 96
| 9,196
| 222
|
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()
len = len(S)
start = len
end = 0
for i in range(len):
if(S[i] == "A"):
temp_start = i+1
start = min(start,temp_start)
if(S[i] == "Z"):
temp_end = i+1
end = max(end,temp_end)
print(end-start)
|
s946665410
|
Accepted
| 98
| 9,240
| 224
|
S = input()
len = len(S)
start = len
end = 0
for i in range(len):
if(S[i] == "A"):
temp_start = i+1
start = min(start,temp_start)
if(S[i] == "Z"):
temp_end = i+1
end = max(end,temp_end)
print(end-start+1)
|
s127951987
|
p03415
|
u090325904
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 58
|
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
|
a = input()
b = input()
c = input()
print(a[0],b[1],c[2])
|
s238364843
|
Accepted
| 17
| 2,940
| 66
|
a = input()
b = input()
c = input()
st = a[0]+b[1]+c[2]
print(st)
|
s460008151
|
p03495
|
u672475305
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 27,172
| 293
|
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
|
n,k = map(int,input().split())
lst = list(map(int,input().split()))
typ = list(set(lst))
NumList = []
for i in range(len(typ)):
c = lst.count(lst[i])
NumList.append([lst[i],c])
NumList.sort(key = lambda x:x[1])
cnt = 0
for i in range(len(typ) - k):
cnt += NumList[i][1]
print(cnt)
|
s956824731
|
Accepted
| 267
| 50,088
| 262
|
from collections import Counter
n,k = map(int,input().split())
lst = list(map(int,input().split()))
typ = list(set(lst))
ans = 0
NumList = Counter(lst)
num = sorted(NumList.items(),key=lambda x:x[1])
for l in range(len(typ)-k):
ans += num[l][1]
print(ans)
|
s602281494
|
p03360
|
u375616706
| 2,000
| 262,144
|
Wrong Answer
| 19
| 2,940
| 180
|
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
|
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
l = list(map(int, input().split()))
K = int(input())
print(sum(l)+(max(l))*(K-1))
|
s500920296
|
Accepted
| 17
| 2,940
| 234
|
# python template for atcoder1
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
l = list(map(int, input().split()))
K = int(input())
ans = sum(l)-max(l)
ans += max(l)*(2**K)
print(ans)
|
s239093792
|
p03251
|
u790812284
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 161
|
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
|
n,m,x,y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
if max(x)<min(y):
print("No war")
else:
print("War")
|
s293167368
|
Accepted
| 17
| 3,060
| 184
|
n,m,X,Y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.append(X)
y.append(Y)
if max(x)<min(y):
print("No War")
else:
print("War")
|
s929677609
|
p03795
|
u809670194
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 67
|
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.
|
a = input()
a = int(a[0])
x = 800*a
y = int(a/15)*200
print(x-y)
|
s065682150
|
Accepted
| 17
| 2,940
| 59
|
a = int(input())
x = 800*a
y = int(a/15)*200
print(x-y)
|
s577069578
|
p03433
|
u432853936
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 100
|
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
n = int(input())
a = int(input())
if n % 500 <= a:
print("YES")
else:
print("NO")
|
s718134125
|
Accepted
| 17
| 2,940
| 100
|
n = int(input())
a = int(input())
if n % 500 <= a:
print("Yes")
else:
print("No")
|
s962995218
|
p03695
|
u754022296
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 181
|
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
|
n = int(input())
A = list(map(int, input().split()))
c = 0
for i in range(8):
for j in A:
if 400*i <= j < 400*(i+1):
c += 1
if i<7:
break
print(c)
|
s759488641
|
Accepted
| 17
| 2,940
| 153
|
n = int(input())
s = set()
c = 0
for i in map(int, input().split()):
if i >= 3200:
c += 1
else:
s.add(i//400)
print(max(1, len(s)), len(s)+c)
|
s421037304
|
p02398
|
u019678978
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,652
| 118
|
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
|
a,b,c = list(map(int,input().split()))
count = 0
for i in range(a,b) :
if (c % i) == 0 :
count = count + 1
|
s656049088
|
Accepted
| 20
| 7,672
| 133
|
a,b,c = list(map(int,input().split()))
count = 0
for i in range(a,b+1) :
if (c % i) == 0 :
count = count + 1
print(count)
|
s008641712
|
p00005
|
u040533857
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,732
| 409
|
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
|
while True:
try:
spam=map(int, input().split(' '))
spam = [i for i in spam]
spam.sort()
cola = spam[0] * spam[1]
while True:
if spam[0] == 0:
print(spam[1])
print(int(cola/spam[1]))
break
pre = spam[0]
spam[0] = spam[1] % spam[0]
spam[1] = pre
except:
break
|
s419397400
|
Accepted
| 30
| 6,728
| 402
|
while True:
try:
spam=map(int, input().split(' '))
spam = [i for i in spam]
spam.sort()
cola = spam[0] * spam[1]
while True:
if spam[0] == 0:
print('{} {}'.format(spam[1],int(cola/spam[1])))
break
pre = spam[0]
spam[0] = spam[1] % spam[0]
spam[1] = pre
except:
break
|
s181171512
|
p03997
|
u223133214
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 418
|
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.
|
ABC = []
for i in range(3):
ABC.append(input())
pl_list = {0: 'A', 1: 'B', 2: 'C'}
pl = 0
while True:
if ABC[pl] == '':
print(pl_list[pl])
exit()
plcard = ABC[pl][0]
string = ABC[pl]
string = list(string)
string = string[1:]
string = ''.join(string)
ABC[pl] = string
if plcard == 'a':
pl = 0
elif plcard == 'b':
pl = 1
else:
pl = 2
|
s428428944
|
Accepted
| 18
| 2,940
| 65
|
a,b,h = int(input()),int(input()),int(input())
print((a+b)*h//2)
|
s650837807
|
p04029
|
u498397607
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 53
|
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?
|
num = int(input())
ans = num * (num+1) / 2
print(ans)
|
s662798794
|
Accepted
| 17
| 2,940
| 60
|
num = int(input())
ans = int(num * (num + 1) / 2)
print(ans)
|
s116934696
|
p03494
|
u840649762
| 2,000
| 262,144
|
Wrong Answer
| 25
| 9,004
| 122
|
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()))
for i in range(len(A)):
if A[i] % 2 == 1:
print(i)
break
|
s466499955
|
Accepted
| 27
| 9,024
| 275
|
N = int(input())
A = list(map(int,input().split()))
count = 0
roop = True
while roop == True:
for i in range(N):
if A[i] % 2 == 0:
A[i] /= 2
else:
roop = False
break
if roop == True:
count += 1
print(count)
|
s992384628
|
p02612
|
u394950523
| 2,000
| 1,048,576
|
Wrong Answer
| 26
| 9,092
| 115
|
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())
C = N // 1000
T = N - C * 1000
if N // 1000 == 0:
ans = 1000 - T
else:
ans = 0
print(ans)
|
s987222019
|
Accepted
| 31
| 9,164
| 111
|
N = int(input())
C = N // 1000
T = N - C * 1000
ans = 1000 - T
if ans >= 1000:
ans = 1000 - ans
print(ans)
|
s184884370
|
p03943
|
u059210959
| 2,000
| 262,144
|
Wrong Answer
| 39
| 5,456
| 387
|
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
# encoding:utf-8
import copy
import random
import bisect
import fractions
import math
import sys
mod = 10**9+7
sys.setrecursionlimit(mod)
a,b,c = map(int,input().split())
if a+b == c or a == b+c or b == a+c:
print("YES")
else:
print("NO")
|
s050806280
|
Accepted
| 40
| 5,576
| 387
|
# encoding:utf-8
import copy
import random
import bisect
import fractions
import math
import sys
mod = 10**9+7
sys.setrecursionlimit(mod)
a,b,c = map(int,input().split())
if a+b == c or a == b+c or b == a+c:
print("Yes")
else:
print("No")
|
s229567776
|
p02613
|
u978313283
| 2,000
| 1,048,576
|
Wrong Answer
| 151
| 16,516
| 285
|
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.
|
import collections
AC=0
WA=0
TLE=0
RE=0
N=int(input())
S=[]
for i in range(N):
S.append(input())
count=collections.Counter(S)
print("AC x {}".format(count["AC"]))
print("WA x {}".format(count["WA"]))
print("TLE x {}".format(count["TLE"]))
print("RE x {}".format(count["RE"]))
|
s680606287
|
Accepted
| 149
| 16,576
| 277
|
import collections
AC=0
WA=0
TLE=0
RE=0
N=int(input())
S=[]
for i in range(N):
S.append(input())
count=collections.Counter(S)
print("AC x {}".format(count["AC"]))
print("WA x {}".format(count["WA"]))
print("TLE x {}".format(count["TLE"]))
print("RE x {}".format(count["RE"]))
|
s222605672
|
p03693
|
u627530854
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 72
|
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
print("YES" if int("".join(sorted(input().split()))) % 4 == 0 else "NO")
|
s635785587
|
Accepted
| 17
| 2,940
| 64
|
print("YES" if int("".join(input().split())) % 4 == 0 else "NO")
|
s417433939
|
p03487
|
u064408584
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 17,012
| 411
|
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
|
def C_Good_Sequence():
N=int(input())
a=list(map(int, input().split()))
print(a)
b=set(a)
print(b)
count=0
ans=0
for i in b:
for j in range(N):
if a[j]==i:
count += 1
print(i,count)
if count<i:
ans += count
elif count >i:
ans += count-i
count=0
print(ans)
C_Good_Sequence()
|
s982792064
|
Accepted
| 79
| 17,780
| 353
|
def C_Good_Sequence():
N=int(input())
a=list(map(int, input().split()))
count={}
ans=0
for num in a:
count[num]= count.get(num,0)+1
for num in count:
if num > count[num]:
ans += count[num]
elif num < count[num]:
ans += count[num]-num
print(ans)
C_Good_Sequence()
|
s975125514
|
p03369
|
u611090896
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 43
|
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
|
S = input()
print(700 + 100 * S.count('x'))
|
s830019784
|
Accepted
| 17
| 2,940
| 49
|
S = input()
print(700 + 100 * int(S.count("o")))
|
s824525038
|
p03339
|
u880911340
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 3,916
| 307
|
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
|
N=int(input())
l = input()
mi = 300000
print(l)
for i in range(N):
count=0
for j in range(N):
if i>j:
if l[j]=="W":
count+=1
elif i<j:
if l[j]=="E":
count+=1
else:
continue
mi=min(mi,count)
print(mi)
|
s651082067
|
Accepted
| 183
| 3,676
| 200
|
N=int(input())
l = input()
count0 = l[1:].count("E")
count=count0
mi=count0
for i in range(1, N):
if l[i-1]=="W":
count+=1
if l[i]=="E":
count-=1
mi=min(mi,count)
print(mi)
|
s928960026
|
p04043
|
u637175065
| 2,000
| 262,144
|
Wrong Answer
| 52
| 5,644
| 276
|
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.
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def main():
a = list(map(int,input().split()))
if sum(a) == 12:
return 'YES'
return 'NO'
print(main())
|
s484427285
|
Accepted
| 53
| 5,640
| 276
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def main():
a = list(map(int,input().split()))
if sum(a) == 17:
return 'YES'
return 'NO'
print(main())
|
s046833071
|
p00008
|
u342537066
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,724
| 176
|
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
|
cnt=0
n=int(input())
s=range(10)
for i in s:
for j in s:
for k in s:
for l in s:
if i+j+k+l==n:
cnt+=1
print(cnt)
|
s275587924
|
Accepted
| 160
| 6,720
| 302
|
while True:
try:
n=int(input())
s=range(10)
cnt=0
for i in s:
for j in s:
for k in s:
for l in s:
if i+j+k+l==n:
cnt+=1
print(cnt)
except:
break
|
s774654581
|
p02602
|
u075304271
| 2,000
| 1,048,576
|
Wrong Answer
| 2,206
| 36,316
| 552
|
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
|
import math
import collections
import fractions
import itertools
import functools
import operator
def solve():
n, k = map(int, input().split())
a = [1] + list(map(int, input().split()))
hoge = 1
ruiseki = []
for i in range(k):
hoge *= a[i+1]
for i in range(k, n+1):
ruiseki.append(hoge//a[i-k]*a[i])
print(a)
print(ruiseki)
for i in range(n-k):
if ruiseki[i] < ruiseki[i+1]:
print("Yes")
else:
print("No")
return 0
if __name__ == "__main__":
solve()
|
s276747568
|
Accepted
| 136
| 32,912
| 322
|
import math
import collections
import fractions
import itertools
import functools
import operator
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k, n):
print("Yes") if a[i] > a[i-k] else print("No")
return 0
if __name__ == "__main__":
solve()
|
s921176113
|
p03796
|
u961674365
| 2,000
| 262,144
|
Wrong Answer
| 36
| 2,940
| 66
|
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
|
n=int(input())
for i in range(n):
n=(n*(i+1))%(10**9+7)
print(n)
|
s772981637
|
Accepted
| 34
| 2,940
| 70
|
n=int(input())
p=1
for i in range(1,n+1):
p=(p*i)%(10**9+7)
print(p)
|
s677399569
|
p02618
|
u879921371
| 2,000
| 1,048,576
|
Wrong Answer
| 218
| 27,688
| 4,733
|
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
|
#import random
import numpy as np
def main():
d=int(input())
c=np.array(list(map(int,input().split())))
s=[None]*d
r0=[None]*d
r1=[None]*d
cm=np.array([0]*26)
cd=np.array([0]*26)
#t=[None]*d
for i in range(d):
s[i]=list(map(int,input().split()))
s=np.array(s)
# t[i]=int(input())-1
for j in range(d):
#rand = np.random.randint(26, size = 10)
#print(np.argmax(s[j])+1)
r_i=np.argmax(s[j])
cd=c*cm
if np.max(cd>s[i][r_i]):
r_i=np.argmax(cd)
r0[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
#r_i+=1
#print(r_i)
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if rand[j]>80:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
#r0=t
score0=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r0[j]
score0+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score0+=-np.sum(cd)
score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r1[j]
score1+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score1+=-np.sum(cd)
if score1>score0:
r0=r1
score0=score1
#score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if rand[j]>75:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r1[j]
score1+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score1+=-np.sum(cd)
if score1>score0:
r0=r1
score0=score1
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if rand[j]>60:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r1[j]
score1+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score1+=-np.sum(cd)
if score1>score0:
r0=r1
score0=score1
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if rand[j]>50:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r1[j]
score1+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score1+=-np.sum(cd)
if score1>score0:
r0=r1
score0=score1
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if rand[j]>45:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r1[j]
score1+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score1+=-np.sum(cd)
if score1>score0:
r0=r1
score0=score1
for j in range(d):
print(r0[j]+1)
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if 70< rand[j] < 90:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r1[j]
score1+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score1+=-np.sum(cd)
if score1>score0:
r0=r1
score0=score1
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if 10< rand[j] < 30:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r1[j]
score1+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score1+=-np.sum(cd)
if score1>score0:
r0=r1
score0=score1
for j in range(d):
print(r0[j]+1)
main()
|
s437890915
|
Accepted
| 388
| 27,568
| 1,954
|
#import random
import numpy as np
def main():
d=int(input())
c=np.array(list(map(int,input().split())))
s=[None]*d
r0=[None]*d
r1=[None]*d
cm=np.array([0]*26)
cd=np.array([0]*26)
#t=[None]*d
for i in range(d):
s[i]=list(map(int,input().split()))
s=np.array(s)
# t[i]=int(input())-1
for j in range(d):
#rand = np.random.randint(26, size = 10)
#print(np.argmax(s[j])+1)
r_i=np.argmax(s[j])
cd=c*cm
if np.max(cd>s[i][r_i]):
r_i=np.argmax(cd)
r0[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
score0=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r0[j]
score0+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
score0+=-np.sum(cd)
#r_i+=1
#print(r_i)
"""
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if rand[j]>80:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
#r0=t
"""
testc=(90,80,85,75,70,65,60,55,50,45,40,35,30,25,20,15,99,98,97,96,95,94,93,92,91)
for l in testc:
cm=np.array([0]*26)
cd=np.array([0]*26)
rand = np.random.randint(100, size = d)
for j in range(d):
#print(np.argmax(s[j])+1)
r_i=r0[j]
cd=c*cm
if rand[j]>l:
r_i=np.argmax(cd)
r1[j]=r_i
for k in range(26):
cm[k]+=1
cm[r_i]=0
score1=0
cm=np.array([0]*26)
cd=np.array([0]*26)
for j in range(d):
r0_j=r1[j]
#print(score1)
score1+=s[j][r0_j]
for k in range(26):
cm[k]+=1
cm[r0_j]=0
cd=c*cm
#print(cm)
score1+=-np.sum(cd)
#print(score0)
#print(score1)
if score1>score0:
r0=r1
score0=score1
for j in range(d):
print(r0[j]+1)
main()
|
s124386044
|
p03573
|
u363610900
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 78
|
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
|
A, B, C = map(int, input().split())
print(A if A == B else B if B == C else C)
|
s071629886
|
Accepted
| 18
| 2,940
| 78
|
A, B, C = map(int, input().split())
print(C if A == B else A if B == C else B)
|
s983565799
|
p03457
|
u713396196
| 2,000
| 262,144
|
Wrong Answer
| 319
| 3,060
| 160
|
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())
for i in range(n):
t, x, y = map(int, input().split())
if x + y < t or (x + y + t) % 2:
print("No")
exit()
print("Yes")
|
s490236035
|
Accepted
| 334
| 3,060
| 160
|
n = int(input())
for i in range(n):
t,x,y=map(int,input().split())
if(not((x+y)<=t and (x+y)%2 == t%2)):
print("No")
exit()
print("Yes")
|
s530420943
|
p03129
|
u923270446
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 190
|
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
|
n, k = map(int, input().split())
ans = ""
if n % 2 == 0:
if n / 2 >= k:
ans = "Yes"
else:
ans = "No"
else:
if n // 2 + 1 >= k:
ans = "Yes"
else:
ans = "No"
print(ans)
|
s696908811
|
Accepted
| 18
| 3,060
| 190
|
n, k = map(int, input().split())
ans = ""
if n % 2 == 0:
if n / 2 >= k:
ans = "YES"
else:
ans = "NO"
else:
if n // 2 + 1 >= k:
ans = "YES"
else:
ans = "NO"
print(ans)
|
s679930252
|
p02422
|
u823030818
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,720
| 353
|
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
|
text = input()
count = int(input())
for c in range(count):
args = input().split()
(a,b) = [int(x) for x in args[1:3]]
if args[0] == 'print':
print(text[a:b + 1])
elif args[0] == 'reverse':
text = text[0:a] + text[a:b][::-1] + text[b + 1:]
elif args[0] == 'replace':
text = text[0:a] + args[3] + text[b + 1:]
|
s117373942
|
Accepted
| 40
| 6,724
| 358
|
text = input()
count = int(input())
for c in range(count):
args = input().split()
(a, b) = [int(x) for x in args[1:3]]
if args[0] == 'print':
print(text[a:b + 1])
elif args[0] == 'reverse':
text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
elif args[0] == 'replace':
text = text[0:a] + args[3] + text[b + 1:]
|
s443811376
|
p03479
|
u823885866
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 83
|
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
|
n, m = map(int, input().split())
cnt = 0
while n <= m:
n *= 2
cnt += 1
print(n)
|
s073807146
|
Accepted
| 17
| 2,940
| 86
|
n, m = map(int, input().split())
cnt = 0
while n <= m:
n *= 2
cnt += 1
print(cnt)
|
s651937086
|
p03997
|
u905743924
| 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(h*(a+b)/2)
|
s547547200
|
Accepted
| 17
| 2,940
| 72
|
a = int(input())
b = int(input())
h = int(input())
print(int(h*(a+b)/2))
|
s821026855
|
p02385
|
u747709646
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,820
| 2,261
|
Write a program which reads the two dices constructed in the same way as [Dice I](description.jsp?id=ITP1_11_A), and determines whether these two dices are identical. You can roll a dice in the same way as [Dice I](description.jsp?id=ITP1_11_A), and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
|
class Dice:
dice = {'N':2, 'E':4, 'S':5, 'W':3}
faces = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6}
currTop = 1
def __init__(self, faces = None):
if faces is not None:
self.faces = faces
def top(self):
return self.currTop
def topFace(self):
return self.faces[self.currTop]
def rot(self, direction):
newTop = self.dice[direction]
currTop = self.currTop
self.currTop = newTop
if direction == 'N':
self.dice['N'] = 7 - currTop
self.dice['S'] = currTop
elif direction == 'S':
self.dice['N'] = currTop
self.dice['S'] = 7 - currTop
elif direction == 'E':
self.dice['E'] = 7 - currTop
self.dice['W'] = currTop
elif direction == 'W':
self.dice['E'] = currTop
self.dice['W'] = 7 - currTop
def yaw(self, direction):
newDice = {}
if direction == 'E':
newDice['N'] = self.dice['E']
newDice['E'] = self.dice['S']
newDice['S'] = self.dice['W']
newDice['W'] = self.dice['N']
if direction == 'W':
newDice['N'] = self.dice['W']
newDice['E'] = self.dice['N']
newDice['S'] = self.dice['E']
newDice['W'] = self.dice['S']
self.dice = newDice
faces1 = {k:v for k,v in zip(range(1,7), map(int, input().split()))}
faces2 = {k:v for k,v in zip(range(1,7), map(int, input().split()))}
d1 = Dice(faces1)
d2 = Dice(faces2)
if d1.topFace() != d2.topFace():
# search d1.topFace() in d2 and rotate to make d2.topFace() equal to d1.topFace().
key = [k for k,v in d2.dice.items() if d1.topFace() == d2.faces[v]]
if len(key) == 0:
d2.rot('N')
key = [k for k,v in d2.dice.items() if d1.topFace() == d2.faces[v]]
d2.rot(key[0])
if d1.topFace() != d2.topFace():
print('No')
exit()
while True:
cnt = 0
if cnt > 4 or d1.faces[d1.dice['N']] == d2.faces[d2.dice['N']]:
break
d2.yaw('E')
cnt += 1
d2State = {k:d2.faces[v] for k,v in d2.dice.items()}
for d1k,d1f in {k:d1.faces[v] for k,v in d1.dice.items()}.items():
if d1f != d2State[d1k]:
print('No')
exit()
print('Yes')
|
s726226847
|
Accepted
| 60
| 7,968
| 2,660
|
class Dice:
def __init__(self, faces = None):
self.dice = {'N':2, 'E':4, 'S':5, 'W':3}
self.faces = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6}
self.currTop = 1
if faces is not None:
self.faces = faces
def top(self):
return self.currTop
def topFace(self):
return self.faces[self.currTop]
def bottom(self):
return 7 - self.currTop
def bottomFace(self):
return self.faces[self.bottom()]
def rot(self, direction):
newTop = self.dice[direction]
currTop = self.currTop
self.currTop = newTop
if direction == 'N':
self.dice['N'] = 7 - currTop
self.dice['S'] = currTop
elif direction == 'S':
self.dice['N'] = currTop
self.dice['S'] = 7 - currTop
elif direction == 'E':
self.dice['E'] = 7 - currTop
self.dice['W'] = currTop
elif direction == 'W':
self.dice['E'] = currTop
self.dice['W'] = 7 - currTop
def yaw(self, direction):
newDice = {}
if direction == 'E':
newDice['N'] = self.dice['E']
newDice['E'] = self.dice['S']
newDice['S'] = self.dice['W']
newDice['W'] = self.dice['N']
if direction == 'W':
newDice['N'] = self.dice['W']
newDice['E'] = self.dice['N']
newDice['S'] = self.dice['E']
newDice['W'] = self.dice['S']
self.dice = newDice
dbg = False
faces1 = {k:v for k,v in zip(range(1,7), map(int, input().split()))}
faces2 = {k:v for k,v in zip(range(1,7), map(int, input().split()))}
d1 = Dice(faces1)
d2 = Dice(faces2)
d2indexes = [d2index for d2index,d2face in d2.faces.items() if d1.topFace() == d2face]
for d2topIndex in d2indexes:
if dbg: print('d2topIndex:%d' % (d2topIndex) )
# search d1.topFace() in d2 and rotate to make d2.topFace() equal to d1.topFace().
key = [k for k,v in d2.dice.items() if d2topIndex == v]
if len(key) == 0:
d2.rot('N')
key = [k for k,v in d2.dice.items() if d2topIndex == v]
d2.rot(key[0])
if d1.topFace() != d2.topFace() or d1.bottomFace() != d2.bottomFace():
continue
# rotate(yaw) to make frontIdx front.
cnt = 0
while True:
if dbg: print('cnt:%d' % (cnt) )
if cnt > 4:
break
d2.yaw('E')
cnt += 1
d1State = {k:d1.faces[v] for k,v in d1.dice.items()}
d2State = {k:d2.faces[v] for k,v in d2.dice.items()}
if d1State == d2State:
print('Yes')
exit()
print('No')
|
s655051024
|
p03409
|
u239528020
| 2,000
| 262,144
|
Wrong Answer
| 316
| 53,008
| 331
|
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
|
#!/usr/bin/env python3
import networkx as nx
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
for j in range(n):
a, b = ab[i]
c, d = cd[i]
if a < c and b < d:
ans += 1
print(ans)
|
s262221466
|
Accepted
| 355
| 54,272
| 915
|
#!/usr/bin/env python3
import networkx as nx
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
match_list = [[] for i in range(n)]
for i in range(n):
for j in range(n):
a, b = ab[i]
c, d = cd[j]
if a < c and b < d:
match_list[i].append(j)
# print(match_list)
group1 = range(n)
group2 = range(n, 2*n)
g = nx.Graph()
g.add_nodes_from(group1, bipartite=1)
g.add_nodes_from(group2, bipartite=0)
for i, list_ in enumerate(match_list):
for j in list_:
g.add_edge(i, j+n, weight=1)
# A, B = bipartite.sets(g)
# pos.update((n, (1, i)) for i, n in enumerate(A))
# pos.update((n, (2, i)) for i, n in enumerate(B))
# plt.axis("off")
# plt.show()
d = nx.max_weight_matching(g)
print(len(d))
|
s681625023
|
p02607
|
u969226579
| 2,000
| 1,048,576
|
Wrong Answer
| 25
| 9,040
| 173
|
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()))
cnt = 0
for i in range(n):
if i % 2 == 0 and a[i] % 2 != 0:
print(i, a[i], cnt)
cnt += 1
print(cnt)
|
s303427540
|
Accepted
| 37
| 9,156
| 145
|
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
if i % 2 == 0 and a[i] % 2 != 0:
cnt += 1
print(cnt)
|
s378699934
|
p02850
|
u189479417
| 2,000
| 1,048,576
|
Wrong Answer
| 2,106
| 123,240
| 667
|
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.
|
import sys
sys.setrecursionlimit(4100000)
N = int(input())
edges = [[] for i in range(N+1)]
color = [0 for i in range(N-1)]
for i in range(N-1):
a, b = map(int,input().split())
edges[a].append([b,i])
edges[b].append([a,i])
root = -1
MAX = 0
for i in range(N+1):
if MAX < len(edges[i]):
root = i
MAX = len(edges[i])
K = MAX
def dfs(parent,v,c):
for i in range(len(edges[v])):
if edges[v][i][0] != parent:
color[edges[v][i][1]] = (c+i)%K
print(color)
dfs(v,edges[v][i][0],(c+i)%K)
dfs(-1,root,0)
print(K)
for i in color:
if i == 0:
print(K)
else:
print(i)
|
s129275945
|
Accepted
| 855
| 77,936
| 704
|
import sys
sys.setrecursionlimit(4100000)
N = int(input())
edges = [[] for i in range(N+1)]
color = [0 for i in range(N-1)]
for i in range(N-1):
a, b = map(int,input().split())
edges[a].append([b,i])
edges[b].append([a,i])
root = -1
MAX = 0
for i in range(N+1):
if MAX < len(edges[i]):
root = i
MAX = len(edges[i])
K = MAX
def dfs(parent,v,c):
flag = 0
for i in range(len(edges[v])):
if edges[v][i][0] == parent:
flag = 1
else:
color[edges[v][i][1]] = (c+i+1-flag)%K
dfs(v,edges[v][i][0],(c+i+1-flag)%K)
dfs(-1,root,0)
print(K)
for i in color:
if i == 0:
print(K)
else:
print(i)
|
s427736813
|
p03796
|
u845620905
| 2,000
| 262,144
|
Wrong Answer
| 32
| 2,940
| 104
|
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
|
n = int(input())
mod = 1000000007
ans = 1
for i in range(1, n+1):
ans *= 1
ans %= mod
print(ans)
|
s012506163
|
Accepted
| 40
| 2,940
| 104
|
n = int(input())
mod = 1000000007
ans = 1
for i in range(1, n+1):
ans *= i
ans %= mod
print(ans)
|
s104270408
|
p02853
|
u642012866
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,108
| 118
|
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
|
X, Y = map(int, input().split())
res = min(4-X, 0)*10**5 + min(4-Y, 0)*10**5
if X==Y==1:
res += 400000
print(res)
|
s491382441
|
Accepted
| 27
| 9,188
| 372
|
X, Y = map(int, input().split())
def solver(X, Y):
if X == 1 and Y == 1:
print(1000000)
return
a = 0
if X == 1:
a += 300000
if X == 2:
a += 200000
if X == 3:
a += 100000
if Y == 1:
a += 300000
if Y == 2:
a += 200000
if Y == 3:
a += 100000
print(a)
solver(X, Y)
|
s971920728
|
p04045
|
u788681441
| 2,000
| 262,144
|
Wrong Answer
| 24
| 3,064
| 325
|
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())
n = str(n)
dislikes = map(int, input().split())
result = []
for p in n:
for x in range(10):
if x not in dislikes and x>=int(p):
result.append(str(x))
break
print(''.join(result))
|
s235004213
|
Accepted
| 158
| 3,064
| 384
|
n, k = map(int, input().split())
dislikes = list(map(int, input().split()))
m = n
while True:
m = list(str(m))
l = []
for p in m:
if int(p) not in dislikes:
l.append(p)
continue
else:
m = int(''.join(m))+1
break
if len(l) >= len(str(n)):
if int(''.join(l))>=n:
break
print(''.join(m))
|
s901204877
|
p02393
|
u042885182
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,532
| 303
|
Write a program which reads three integers, and prints them in ascending order.
|
# coding: utf-8
# Here your code !
def func():
try:
line=input().rstrip()
numbers=line.split(" ")
for i,item in enumerate(numbers):
numbers[i]=int(item)
except:
print("input error")
return -1
numbers.sort()
print(numbers)
func()
|
s387032701
|
Accepted
| 30
| 7,656
| 391
|
# coding: utf-8
# Here your code !
def func():
try:
line=input().rstrip()
numbers=line.split(" ")
for i,item in enumerate(numbers):
numbers[i]=int(item)
except:
print("input error")
return -1
numbers.sort()
result=""
for num in numbers:
result+=str(num)+" "
print(result.rstrip(" "))
func()
|
s964793225
|
p03997
|
u552122040
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 75
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
print((a + b) * h / 2)
|
s529138502
|
Accepted
| 17
| 2,940
| 76
|
a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)
|
s666506171
|
p03997
|
u707690642
| 2,000
| 262,144
|
Wrong Answer
| 21
| 3,316
| 100
|
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.
|
input_ = [input() for i in range(3)]
a, b, h = input_
s = (int(a) + int(b)) * int(h) / 2
print(s)
|
s835378396
|
Accepted
| 17
| 2,940
| 105
|
input_ = [input() for i in range(3)]
a, b, h = input_
s = int((int(a) + int(b)) * int(h) / 2)
print(s)
|
s504458306
|
p03861
|
u955248595
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,172
| 62
|
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 = (int(T) for T in input().split())
print((b//x)-(a//x))
|
s437369148
|
Accepted
| 29
| 9,048
| 71
|
a,b,x = (int(T) for T in input().split())
print((b//x)-(a//x)+(a%x==0))
|
s419887268
|
p02601
|
u501364195
| 2,000
| 1,048,576
|
Wrong Answer
| 33
| 9,224
| 432
|
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
|
A, B, C = map(int, input().split())
K = int(input())
a=0
for i in range(K+1):
for j in range(K-i+1):
for k in range(K-i-j+1):
if i+j+k==K:
A_, B_, C_ = A, B, C
A_ = A*(2**i)
B_ = B*(2**j)
C_ = C*(2**k)
print(A,B,C,i,j,k)
if C_>B_>A_:
print('Yes:',A_,B_,C_,i,j,k)
a=1
break
if a==1:
break
if a==1:
break
if a==0:
print('No')
|
s077241502
|
Accepted
| 24
| 8,968
| 389
|
A, B, C = map(int, input().split())
K = int(input())
a=0
for i in range(K+1):
for j in range(K-i+1):
for k in range(K-i-j+1):
if i+j+k==K:
A_, B_, C_ = A, B, C
A_ = A*(2**i)
B_ = B*(2**j)
C_ = C*(2**k)
if C_>B_>A_:
print('Yes')
a=1
break
if a==1:
break
if a==1:
break
if a==0:
print('No')
|
s410746065
|
p03090
|
u888337853
| 2,000
| 1,048,576
|
Wrong Answer
| 47
| 11,732
| 1,958
|
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
|
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))
# ===CODE===
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
n = ni()
ans = []
for i in range(n):
for j in range(i + 1, n):
if i + j + 2 != n + 1:
ans.append([i + 1, j + 1])
print(len(ans))
for a, b in ans:
print(a, b)
if __name__ == '__main__':
main()
|
s548317837
|
Accepted
| 43
| 11,752
| 1,985
|
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))
# ===CODE===
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
n = ni()
ans = []
odd = int(n % 2)
for i in range(n):
for j in range(i + 1, n):
if i + j + 2 != n + 1 - odd:
ans.append([i + 1, j + 1])
print(len(ans))
for a, b in ans:
print(a, b)
if __name__ == '__main__':
main()
|
s393088557
|
p00774
|
u209989098
| 8,000
| 131,072
|
Wrong Answer
| 140
| 5,628
| 845
|
We are playing a puzzle. An upright board with _H_ rows by 5 columns of cells, as shown in the figure below, is used in this puzzle. A stone engraved with a digit, one of 1 through 9, is placed in each of the cells. When three or more stones in horizontally adjacent cells are engraved with the same digit, the stones will disappear. If there are stones in the cells above the cell with a disappeared stone, the stones in the above cells will drop down, filling the vacancy. The puzzle proceeds taking the following steps. 1. When three or more stones in horizontally adjacent cells are engraved with the same digit, the stones will disappear. Disappearances of all such groups of stones take place simultaneously. 2. When stones are in the cells above the emptied cells, these stones drop down so that the emptied cells are filled. 3. After the completion of all stone drops, if one or more groups of stones satisfy the disappearance condition, repeat by returning to the step 1. The score of this puzzle is the sum of the digits on the disappeared stones. Write a program that calculates the score of given configurations of stones.
|
a = int(input())
global s
s = 0
def de(ppp,h):
re = False
co = 0
global s
for lo in ppp:
for j ,cell in enumerate(lo):
k = j
p = j
if k <= 2:
while cell == lo[k+1] and cell != None:
co += 1
if k == 3:
j = k
break
k += 1
j = k - 1
if co >= 2:
re = True
s += (co+1)*cell
for l in range(5):
if l >= p and l < k+2:
lo[l] = None
co = 0
return re
def mo(ppp,h):
for i ,roe in enumerate(ppp):
for j , cell in enumerate(roe):
kkk = i
while i != 0 and ppp[kkk-1][j] == None:
ppp[kkk-1][j] = ppp[kkk][j]
ppp[kkk][j] = None
if kkk == 1:
break
kkk -= 1
while a != 0:
ppp = [list(map(int,input().split())) for i in range(a)]
ppp.reverse()
while(de(ppp,a) == True):
mo(ppp,a)
print(ppp)
print(s)
s = 0
a = int(input())
|
s363236952
|
Accepted
| 140
| 5,632
| 828
|
a = int(input())
global s
s = 0
def de(ppp,h):
re = False
co = 0
global s
for lo in ppp:
for j ,cell in enumerate(lo):
k = j
p = j
if k <= 2:
while cell == lo[k+1] and cell != None:
co += 1
if k == 3:
j = k+1
break
k += 1
j = k
if co >= 2:
re = True
s += (co+1)*cell
for l in range(5):
if l >= p and l <= j:
lo[l] = None
co = 0
return re
def mo(ppp,h):
for i ,roe in enumerate(ppp):
for j , cell in enumerate(roe):
kkk = i
while i != 0 and ppp[kkk-1][j] == None:
ppp[kkk-1][j] = ppp[kkk][j]
ppp[kkk][j] = None
if kkk == 1:
break
kkk -= 1
while a != 0:
ppp = [list(map(int,input().split())) for i in range(a)]
ppp.reverse()
while(de(ppp,a) == True):
mo(ppp,a)
print(s)
s = 0
a = int(input())
|
s105832738
|
p03578
|
u545368057
| 2,000
| 262,144
|
Wrong Answer
| 500
| 35,420
| 424
|
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
|
N = int(input())
Ds = list(map(int,input().split()))
M = int(input())
Ts = list(map(int,input().split()))
sDs = [-1]+sorted(Ds)
sTs = sorted(Ts)
print(sDs)
print(sTs)
# flg = True
ind = 0
for t in sTs:
flg = False
for j in range(ind+1,len(sDs)):
if sDs[j] == t:
ind = j
flg = True
break
if not flg:
print("NO")
break
if flg:
print("YES")
|
s360574304
|
Accepted
| 406
| 35,420
| 389
|
N = int(input())
Ds = list(map(int,input().split()))
M = int(input())
Ts = list(map(int,input().split()))
sDs = [-1]+sorted(Ds)
sTs = sorted(Ts)
ind = 0
for t in sTs:
flg = False
for j in range(ind+1,len(sDs)):
if sDs[j] == t:
ind = j
flg = True
break
if not flg:
print("NO")
break
if flg:
print("YES")
|
s961607916
|
p03611
|
u294385082
| 2,000
| 262,144
|
Wrong Answer
| 113
| 19,700
| 315
|
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
|
n = int(input())
a = list(map(int,input().split()))
dict = {}
dict[0] = 0
dict[1] = 0
for i in range(2,n+2):
if i not in dict:
dict[i] = 1
else:
dict[i] += 1
dict[len(dict)] = 0
dict[len(dict)] = 0
ans = 0
for j in range(len(dict)-2):
ans = max(ans,dict[j]+dict[j+1]+dict[j+2])
print(ans)
|
s485702713
|
Accepted
| 98
| 13,964
| 180
|
n = int(input())
a = list(map(int,input().split()))
ans = 0
l = [0]*100001
for i in a:
l[i] += 1
for i in range(len(l)-2):
ans = max(ans,l[i]+l[i+1]+l[i+2])
print(ans)
|
s393919334
|
p04029
|
u089636269
| 2,000
| 262,144
|
Wrong Answer
| 23
| 3,064
| 122
|
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?
|
# coding: UTF8
# python3
# input = "10"
input = input()
sum = 0
for num in range(1,int(input)):
sum += num;
print(sum)
|
s622704762
|
Accepted
| 23
| 3,064
| 128
|
# coding: UTF8
# python3
# input = "10"
input = input()
sum = 0
for num in range(1,int(input) + 1):
sum += num;
print(sum)
|
s339014497
|
p03730
|
u811176339
| 2,000
| 262,144
|
Wrong Answer
| 29
| 9,000
| 172
|
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
|
a, b, c = [int(w) for w in input().split()]
cond = False
for n in range(a, a*b+1, a):
if n % b == c:
cond = True
break
print("Yes" if cond else "No")
|
s621528148
|
Accepted
| 29
| 9,076
| 172
|
a, b, c = [int(w) for w in input().split()]
cond = False
for n in range(a, a*b+1, a):
if n % b == c:
cond = True
break
print("YES" if cond else "NO")
|
s116658983
|
p02842
|
u732870425
| 2,000
| 1,048,576
|
Wrong Answer
| 36
| 2,940
| 125
|
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())
for i in range(50001):
if N == math.floor(i * 1.08):
print(i)
else:
print(":(")
|
s209111845
|
Accepted
| 33
| 3,060
| 139
|
import math
N = int(input())
for i in range(50001):
if N == math.floor(i * 1.08):
print(i)
break
else:
print(":(")
|
s603442342
|
p02269
|
u547838013
| 2,000
| 131,072
|
Wrong Answer
| 20
| 5,596
| 283
|
Your task is to write a program of a simple _dictionary_ which implements the following instructions: * **insert _str_** : insert a string _str_ in to the dictionary * **find _str_** : if the distionary contains _str_ , then print 'yes', otherwise print 'no'
|
n = int(input())
strs = []
for i in range(n):
s = input().split()
print(s)
if(s[0] == 'insert'):
if(s[1] not in strs):
strs.append(s[1])
else:
if(s[1] in strs):
print('yes')
else:
print('no')
print (strs)
|
s937299784
|
Accepted
| 4,710
| 33,112
| 255
|
n = int(input())
strs = {}
for i in range(n):
s = input().split()
if(s[0] == 'insert'):
if(s[1] not in strs):
strs[s[1]] = ''
else:
if(s[1] in strs):
print('yes')
else:
print('no')
|
s489446435
|
p03845
|
u481333386
| 2,000
| 262,144
|
Wrong Answer
| 21
| 3,316
| 360
|
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds. It does not affect the time to solve the other problems. A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.
|
# -*- coding: utf-8 -*-
def main():
problems = int(input())
solve_times = [int(e) for e in input().split()]
drinks = int(input())
for i in range(drinks):
problem_idx, solve_time = [int(e) for e in input().split()]
problem_idx -= 1
solve_times[problem_idx] = solve_time
print(sum(solve_times))
print(main())
|
s286157863
|
Accepted
| 49
| 3,700
| 438
|
# -*- coding: utf-8 -*-
from copy import deepcopy
def main():
problems = int(input())
solve_times = [int(e) for e in input().split()]
drinks = int(input())
for i in range(drinks):
solve_times_copy = deepcopy(solve_times)
problem_idx, solve_time = [int(e) for e in input().split()]
problem_idx -= 1
solve_times_copy[problem_idx] = solve_time
print(sum(solve_times_copy))
main()
|
s974026900
|
p03672
|
u787449825
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 292
|
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
|
S = [i for i in input()]
while True:
S.pop(-1)
if len(S)%2==0:
s = ''.join(S)
s1 = s[:(len(S)//2)]
s2 = s[len(S)//2:]
print(s1, s2)
if s1 == s2:
print(len(S))
exit(0)
elif len(S)==0:
print(0)
exit(0)
|
s504514384
|
Accepted
| 18
| 3,060
| 270
|
S = [i for i in input()]
while True:
S.pop(-1)
if len(S)%2==0:
s = ''.join(S)
s1 = s[:(len(S)//2)]
s2 = s[len(S)//2:]
if s1 == s2:
print(len(S))
exit(0)
elif len(S)==0:
print(0)
exit(0)
|
s389831192
|
p02613
|
u039860745
| 2,000
| 1,048,576
|
Wrong Answer
| 145
| 9,208
| 326
|
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
a = input()
if a == "AC":
AC += 1
elif a == "WA":
WA += 1
elif a == "TLE":
TLE += 1
elif a == "RE":
RE += 1
print(f"AC ✖︎ {AC}")
print(f"WA ✖︎ {WA}")
print(f"TLE ✖︎ {TLE}")
print(f"RE ✖︎ {RE}")
|
s828815824
|
Accepted
| 143
| 9,168
| 306
|
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
a = input()
if a == "AC":
AC += 1
elif a == "WA":
WA += 1
elif a == "TLE":
TLE += 1
elif a == "RE":
RE += 1
print(f"AC x {AC}")
print(f"WA x {WA}")
print(f"TLE x {TLE}")
print(f"RE x {RE}")
|
s792938753
|
p04030
|
u287920108
| 2,000
| 262,144
|
Wrong Answer
| 16
| 2,940
| 203
|
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
|
s = input()
lst = []
for i in s:
if i == 'B' and len(lst) !=0:
lst.pop()
elif i == 'B':
continue
else:
lst.append(i)
print(lst)
|
s606284391
|
Accepted
| 19
| 2,940
| 212
|
s = input()
lst = []
for i in s:
if i == 'B' and len(lst) !=0:
lst.pop()
elif i == 'B':
continue
else:
lst.append(i)
print(''.join(lst))
|
s959643236
|
p03943
|
u578049848
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 102
|
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
a,b,c = map(int,input().split())
if max(a,b,c)*2 == a + b + c:
print('YES')
else:
print('NO')
|
s100510577
|
Accepted
| 17
| 2,940
| 103
|
a,b,c = map(int,input().split())
if max(a,b,c)*2 == a + b + c:
print('Yes')
else:
print('No')
|
s611498396
|
p04011
|
u981898278
| 2,000
| 262,144
|
Wrong Answer
| 26
| 9,044
| 126
|
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, K, X, Y = [int(input()) for i in range(4)]
print("{} {} {} {}".format(N, K, X, Y))
res = X * K + Y * (N - K)
print(res)
|
s154603664
|
Accepted
| 29
| 9,088
| 192
|
N, K, X, Y = [int(input()) for i in range(4)]
#print("{} {} {} {}".format(N, K, X, Y))
res = 0
for i in range(N):
if i + 1 <= K:
res += X
else:
res += Y
print(res)
|
s222649563
|
p02607
|
u123745130
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,184
| 159
|
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.
|
a=int(input())
lst=list(map(int,input().split()))
print(a,lst)
cnt=0
for i in range(0,a,2):
if (lst[i] % 2==1) :
cnt+=1
print(i)
print(cnt)
|
s797200597
|
Accepted
| 22
| 9,164
| 129
|
a=int(input())
lst=list(map(int,input().split()))
cnt=0
for i in range(0,a,2):
if (lst[i] % 2==1) :
cnt+=1
print(cnt)
|
s103603511
|
p03080
|
u527261492
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 111
|
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=list(input().split())
r=s.count('R')
b=s.count('B')
if r>b:
print('Yes')
else:
print('No')
|
s806384380
|
Accepted
| 18
| 2,940
| 98
|
N=int(input())
s=input()
r=s.count('R')
b=s.count('B')
if r>b:
print('Yes')
else:
print('No')
|
s163622502
|
p03450
|
u467736898
| 2,000
| 262,144
|
Wrong Answer
| 1,099
| 77,076
| 849
|
There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
|
N, M = map(int, input().split())
Info = [list(map(int, input().split())) for i in range(M)]
Group = [[i] for i in range(N+1)]
Distance = [[i, 0] for i in range(N+1)]
for info in Info:
l, r, d = info
lp, rp = Distance[l][0], Distance[r][0]
print(info, lp, rp)
if lp != rp:
if len(Group[lp]) > len(Group[rp]):
Group[lp] += Group[rp]
for h in Group[rp]:
Distance[h][0] = lp
Distance[h][1] += d
else:
Group[rp] += Group[lp]
for h in Group[lp]:
Distance[h][0] = rp
Distance[h][1] -= d
else:
if not Distance[r][1] - Distance[l][1] == d:
print("No")
exit()
print("Yes")
|
s097410521
|
Accepted
| 1,207
| 75,264
| 870
|
N, M = map(int, input().split())
Info = [list(map(int, input().split())) for i in range(M)]
Group = [[i] for i in range(N+1)]
Distance = [[i, 0] for i in range(N+1)]
for info in Info:
l, r, d = info
lp, rp = Distance[l][0], Distance[r][0]
lpd, rpd = Distance[l][1], Distance[r][1]
if lp != rp:
if len(Group[lp]) > len(Group[rp]):
Group[lp] += Group[rp]
for h in Group[rp]:
Distance[h][0] = lp
Distance[h][1] += d + lpd - rpd
else:
Group[rp] += Group[lp]
for h in Group[lp]:
Distance[h][0] = rp
Distance[h][1] -= d + lpd - rpd
else:
if rpd - lpd != d:
print("No")
exit()
print("Yes")
|
s831375565
|
p02451
|
u209989098
| 2,000
| 262,144
|
Wrong Answer
| 20
| 5,600
| 290
|
For a given sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, find a specific value $k$ given as a query.
|
a = int(input())
b = list(map(int,input().split()))
def nibu(low,high,i):
middle = (low+high)//2
if b[middle] <= i:
low = middle
else:
high = middle
if low == high:
if i == b[low]:
return 1
else:
return 0
for i in range(a):
k = int(input())
print(nibu(0,len(b),k))
|
s995131992
|
Accepted
| 3,760
| 17,420
| 374
|
input()
b = list(map(int,input().split()))
def nibu(low,high,i):
middle = int((low+high)/2)
if low == high:
if i == b[low]:
return 1
else:
return 0
if b[middle] < i:
low = middle + 1
return nibu(low,high,i)
elif b[middle] >= i:
high = middle
return nibu(low,high,i)
a = int(input())
for i in range(a):
k = int(input())
print(nibu(0,len(b)-1,k))
|
s723710811
|
p03502
|
u084949493
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 189
|
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
|
N = int(input())
def calcSumOfDigits(i):
sum = 0
for s in str(i):
sum += int(s)
return sum
sum = calcSumOfDigits(N)
if N == sum:
print("Yes")
else:
print("No")
|
s314042234
|
Accepted
| 18
| 3,060
| 191
|
N = int(input())
def calcSumOfDigits(N):
sum = 0
for s in str(N):
sum += int(s)
return sum
sum = calcSumOfDigits(N)
if N%sum == 0:
print("Yes")
else:
print("No")
|
s799501012
|
p03992
|
u397953026
| 2,000
| 262,144
|
Wrong Answer
| 28
| 8,968
| 48
|
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
|
s = str(input())
print(s[:4]+" "+s[5:],sep = "")
|
s123898243
|
Accepted
| 23
| 8,856
| 48
|
s = str(input())
print(s[:4]+" "+s[4:],sep = "")
|
s176362459
|
p02936
|
u262597910
| 2,000
| 1,048,576
|
Wrong Answer
| 2,112
| 130,976
| 664
|
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
|
n,q = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n-1)]
way = [[] for i in range(n+1)]
for i in range(n-1):
way[x[i][0]].append(x[i][1])
print(way)
y = [list(map(int, input().split())) for _ in range(q)]
def ta(v):
for j in range(q):
count = 0
if (y[j]!=[]):
if (y[j][0]==v):
count += y[j][1]
return count
ans = [0]*(n+1)
stack = [(1,-1)]
while stack:
v,par = stack.pop()
if (way[v]!=[]):
for i in range(len(way[v])):
stack.append((way[v][i],v))
if v==1:
ans[v] = ta(v)
else:
ans[v] += (ta(v) + ans[par])
print(ans)
|
s895813337
|
Accepted
| 1,033
| 73,604
| 693
|
import sys
input = sys.stdin.readline
def main():
n,q = map(int, input().split())
way = [[] for _ in range(n)]
for i in range(n-1):
a,b = map(int, input().split())
way[a-1].append(b-1)
way[b-1].append(a-1)
add = [0]*n
for i in range(q):
a,b = map(int, input().split())
add[a-1] += b
ans = [-1]*n
ans[0] = add[0]
stack = [(0,add[0])]
while stack:
a,b = stack.pop()
for i in range(len(way[a])):
if (ans[way[a][i]]==-1):
stack.append((way[a][i],b+add[way[a][i]]))
ans[way[a][i]] = b+add[way[a][i]]
print(*ans)
if __name__=="__main__":
main()
|
s707839282
|
p03175
|
u736604846
| 2,000
| 1,048,576
|
Wrong Answer
| 650
| 48,132
| 884
|
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black. Here, it is not allowed to paint two adjacent vertices both in black. Find the number of ways in which the vertices can be painted, modulo 10^9 + 7.
|
import sys
sys.setrecursionlimit(10**9)
BLK = 1
WHT = 0
MOD = 10 ** 9 + 7
def calcdp(r, p, bw):
if dp[r][bw] != -1:
return dp[r][bw]
if p == 0:
cs = H[r]
else:
cs = H[r] - {p}
if len(cs) == 1:
dp[r][bw] = 1
return 1
else:
if bw == BLK:
res = 1
for c in cs:
res = (res * calcdp(c, r, WHT)) % MOD
dp[r][BLK] = res
return res
else:
res = 1
for c in cs:
res = (res * (calcdp(c, r, WHT) + calcdp(c, r, BLK))) % MOD
dp[r][WHT] = res
return res
N = int(input())
H = [set() for _ in range(N + 1)]
for _ in range(1, N):
x, y = map(int, input().split())
H[x].add(y)
H[y].add(x)
dp = [[-1] * 2 for _ in range(N + 1)]
print((calcdp(1, 0, BLK) + calcdp(1, 0, WHT)) % MOD)
|
s731730909
|
Accepted
| 1,134
| 148,884
| 894
|
import sys
sys.setrecursionlimit(10**9)
BLK = 1
WHT = 0
MOD = 10 ** 9 + 7
def calcdp(r, p, bw):
if dp[r][bw] != -1:
return dp[r][bw]
if p == 0:
cs = H[r]
else:
cs = H[r] - {p}
if len(cs) == 0:
dp[r][bw] = 1
return 1
else:
if bw == BLK:
res = 1
for c in cs:
res = (res * calcdp(c, r, WHT)) % MOD
dp[r][BLK] = res
return res
else:
res = 1
for c in cs:
res = (res * (calcdp(c, r, WHT) + calcdp(c, r, BLK))) % MOD
dp[r][WHT] = res
return res
N = int(input())
H = [set() for _ in range(N + 1)]
for _ in range(1, N):
x, y = map(int, input().split())
H[x].add(y)
H[y].add(x)
dp = [[-1] * 2 for _ in range(N + 1)]
print((calcdp(1, 0, BLK) + calcdp(1, 0, WHT)) % MOD)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.