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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s627599645
|
p03471
|
u646130340
| 2,000
| 262,144
|
Wrong Answer
| 749
| 3,060
| 158
|
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
|
N, Y = map(int, input().split())
for a in range(N+1):
for b in range(N - a + 1):
c = N - a - b
if Y == 10000*a + 5000*b + 1000*c:
print(a,b,c)
|
s003249184
|
Accepted
| 838
| 3,060
| 247
|
N, Y = map(int, input().split())
ans_a = -1
ans_b = -1
ans_c = -1
for a in range(N+1):
for b in range(N - a + 1):
c = N - a - b
if Y == 10000*a + 5000*b + 1000*c:
ans_a = a
ans_b = b
ans_c = c
print(ans_a, ans_b, ans_c)
|
s498450927
|
p03435
|
u036104576
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,484
| 735
|
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
|
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
C = [0] * 3
for i in range(3):
C[i] = list(map(int, input().split()))
for i in range(1, 3):
x = C[i][0] - C[i - 1][0]
for j in range(1, 3):
if C[i][j] - C[i - 1][j] != x:
print("NO")
exit()
for j in range(1, 3):
x = C[0][j] - C[0][j - 1]
for i in range(1, 3):
if C[i][j] - C[i][j - 1] != x:
print("NO")
exit()
print("YES")
|
s211135870
|
Accepted
| 29
| 9,164
| 735
|
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
C = [0] * 3
for i in range(3):
C[i] = list(map(int, input().split()))
for i in range(1, 3):
x = C[i][0] - C[i - 1][0]
for j in range(1, 3):
if C[i][j] - C[i - 1][j] != x:
print("No")
exit()
for j in range(1, 3):
x = C[0][j] - C[0][j - 1]
for i in range(1, 3):
if C[i][j] - C[i][j - 1] != x:
print("No")
exit()
print("Yes")
|
s300422261
|
p02601
|
u450288159
| 2,000
| 1,048,576
|
Wrong Answer
| 33
| 9,188
| 472
|
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.
|
def main():
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while(1):
# print(a)
# print(b)
# print(c)
# print('------------------')
if cnt-1 == k:
print('No')
return
cnt += 1
if a < b and b < c:
print('yes')
return
if not a < b:
b = 2*b
elif not b < c:
c = 2*c
if __name__ == '__main__':
main()
|
s016600368
|
Accepted
| 24
| 9,180
| 472
|
def main():
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while(1):
# print(a)
# print(b)
# print(c)
# print('------------------')
if cnt-1 == k:
print('No')
return
cnt += 1
if a < b and b < c:
print('Yes')
return
if not a < b:
b = 2*b
elif not b < c:
c = 2*c
if __name__ == '__main__':
main()
|
s271837643
|
p03729
|
u446711904
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 69
|
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
|
a,b,c=input().split();print('NYoe s'[a[-1]==b[0] and b[-1]==c[0]::2])
|
s643730973
|
Accepted
| 17
| 2,940
| 69
|
a,b,c=input().split();print('NYOE S'[a[-1]==b[0] and b[-1]==c[0]::2])
|
s356394530
|
p03486
|
u692453235
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,276
| 353
|
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
from collections import defaultdict
s = input()
t = input()
AL = "abcdefghijklmnopqrstuvwxyz"
S = defaultdict(int)
T = defaultdict(int)
for al in s:
S[al] += 1
for al in t:
T[al] += 1
ans_s = ""
for al in AL:
ans_s += al*S[al]
ans_t = ""
for al in reversed(list(al)):
ans_t += al*T[al]
if ans_s < ans_t:
print("Yes")
else:
print("No")
|
s344258613
|
Accepted
| 28
| 8,936
| 142
|
s = input()
t = input()
S = "".join(sorted(list(s)))
T = "".join(sorted(list(t), reverse=True))
if S < T:
print("Yes")
else:
print("No")
|
s122598050
|
p03919
|
u943004959
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 355
|
There is a grid with H rows and W columns. The square at the i-th row and j-th column contains a string S_{i,j} of length 5. The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet. Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location. For example, the square at the 6-th row and 8-th column should be reported as `H6`.
|
def solve():
H, W = [int(x) for x in input().split(" ")]
snake = []
for _ in range(H):
snake.append(list(map(str, input().split(" "))))
for i in range(H):
for j in range(W):
if snake[i][j] == "snuke":
print(i + 1, chr(65 + j))
print("".join([chr(65 + j), str(i + 1)]))
solve()
|
s917433391
|
Accepted
| 17
| 3,060
| 313
|
def solve():
H, W = [int(x) for x in input().split(" ")]
snake = []
for _ in range(H):
snake.append(list(map(str, input().split(" "))))
for i in range(H):
for j in range(W):
if snake[i][j] == "snuke":
print("".join([chr(65 + j), str(i + 1)]))
solve()
|
s664068615
|
p03623
|
u234929275
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 385
|
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
|
x,a,b = input().split()
x = int(x)
a = int(a)
b = int(b)
print("x = ", x)
print("a = ", a)
print("b = ", b)
if x < a:
distance_xa = a - x
else:
distance_xa = x - a
print("distance_xa = ", distance_xa)
if x < b:
distance_xb = b - x
else:
distance_xb = x - b
print("distance_xb = ", distance_xb)
if distance_xa < distance_xb:
print("A")
else:
print("B")
|
s644849904
|
Accepted
| 17
| 3,060
| 178
|
x, a, b = input().split()
x = int(x)
a = int(a)
b = int(b)
if x > a:
xa = x-a
else:
xa = a-x
if x > b:
xb = x-b
else:
xb = b-x
if xa > xb:
print("B")
else:
print("A")
|
s062929678
|
p03478
|
u244836567
| 2,000
| 262,144
|
Wrong Answer
| 32
| 9,156
| 125
|
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
d=0
for i in range(a):
if b<=(i//10+(i-(i//10)*10))<=c:
d=d+1
print(d)
|
s453203643
|
Accepted
| 32
| 8,972
| 202
|
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
d=0
for i in range(1,a+1):
if b<=(i//10000+(i//1000-(i//10000)*10))+(i//100-(i//1000)*10)+(i//10-(i//100)*10)+(i//1-(i//10)*10)<=c:
d=d+i
print(d)
|
s180498672
|
p02388
|
u797431839
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,576
| 65
|
Write a program which calculates the cube of a given integer x.
|
x = int(input("数字を入力してください:"))
print(x**3)
|
s480793642
|
Accepted
| 20
| 5,576
| 29
|
x = int(input())
print(x**3)
|
s519869636
|
p02619
|
u942051624
| 2,000
| 1,048,576
|
Wrong Answer
| 60
| 9,376
| 1,059
|
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
|
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]
t=[0 for i in range(D)]
total=[0 for i in range(D)]
lastday=[lastday[i]+1 for i in range(26)]
bestpoint=0
for i in range(26):
temp=[con for con in lastday]
temp[i]=0
minus=sum([x*y for (x,y) in zip(c,temp)])
temppoint=s[0][i]-minus
if bestpoint<temppoint:
today=i
bestpoint=temppoint
minusb=minus
lastday[today]=0
t[0]=today+1
total[0]=s[0][today]-minusb
for days in range(1,D):
lastday=[lastday[i]+1 for i in range(26)]
bestpoint=0
for i in range(26):
temp=[con for con in lastday]
temp[i]=0
minus=sum([x*y for (x,y) in zip(c,temp)])
temppoint=s[days][i]-minus
if bestpoint<temppoint:
today=i
bestpoint=temppoint
minusb=minus
lastday[today]=0
t[days]=today+1
total[days]=total[days-1]+s[days][today]-minusb
for ts in t:
print(ts)
|
s685502865
|
Accepted
| 33
| 9,248
| 566
|
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
test=[int(input()) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]
lastday=[lastday[i]+1 for i in range(26)]
lastday[test[0]-1]=0
minus=sum([x*y for (x,y) in zip(c,lastday)])
points[0]=s[0][test[0]-1]-minus
for i in range(1,D):
lastday=[lastday[i]+1 for i in range(26)]
lastday[test[i]-1]=0
minus=sum([x*y for (x,y) in zip(c,lastday)])
points[i]=points[i-1]+s[i][test[i]-1]-minus
for ps in points:
print(ps)
|
s888220198
|
p03997
|
u939552576
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 61
|
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,b,h = int(input()),int(input()),int(input())
print(a*b*h/2)
|
s176170848
|
Accepted
| 17
| 2,940
| 64
|
a,b,h = int(input()),int(input()),int(input())
print((a+b)*h//2)
|
s522021929
|
p02795
|
u025241948
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 69
|
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
|
H=int(input())
W=int(input())
N=int(input())
a=max(H,W)
print(N//a)
|
s545491619
|
Accepted
| 17
| 2,940
| 92
|
import math
H=int(input())
W=int(input())
N=int(input())
a=max(H,W)
print(math.ceil(N/a))
|
s907058285
|
p03476
|
u994988729
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,104
| 7,064
| 520
|
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
|
def sieve(n):
tmp=[i for i in range(n, 1, -1)]
s=[]
while len(tmp)>0:
p=tmp.pop()
s.append(p)
for i in range(len(tmp), 0, -1):
if tmp[-i]%p==0:
del tmp[-i]
return s
naturals=sieve(100000)
q=int(input())
for _ in range(q):
left, right=map(int,input().split())
count=0
for i in range(left, right+1):
if i==1 or i%2==0:
continue
if i in naturals and int((i+1)/2) in naturals:
count+=1
print(count)
|
s264971715
|
Accepted
| 357
| 15,172
| 720
|
from itertools import chain, accumulate
def prime_set(N):
if N < 4:
return ({}, {}, {2}, {2, 3})[N]
Nsq = int(N ** 0.5 + 0.5) + 1
primes = {2, 3} | set(chain(range(5, N + 1, 6), range(7, N + 1, 6)))
for i in range(5, Nsq, 2):
if i in primes:
primes -= set(range(i * i, N + 1, i * 2))
return primes
U = 10 ** 5 + 10
primes = prime_set(U)
memo = [0] * U
for i in range(1, U, 2):
if i in primes and (i + 1) // 2 in primes:
memo[i] = 1
memo = list(accumulate(memo))
Q = int(input())
ans = []
for _ in range(Q):
l, r = map(int, input().split())
ans.append(memo[r] - memo[l - 1])
print(*ans, sep="\n")
|
s913908151
|
p02936
|
u599114793
| 2,000
| 1,048,576
|
Wrong Answer
| 2,246
| 2,083,572
| 710
|
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
|
from collections import deque
n,q = map(int,input().split())
nei_mat = []
nei_list = [[0]]
score_list = [0] * (n+1)
for i in range(n+1):
nei_mat.append([0]*(n+1))
for i in range(n-1):
a,b = map(int,input().split())
nei_mat[a][b] = 1
for i in range(1,n+1):
work_q = deque([])
work_q.append(i)
visited = []
while work_q:
cal = work_q.popleft()
visited.append(cal)
for j in range(cal, n+1):
if nei_mat[cal][j] == 1:
work_q.append(j)
nei_list.append(visited)
print(nei_list)
for i in range(q):
p,x = map(int,input().split())
for j in range(len(nei_list[p])):
score_list[nei_list[p][j]] += x
print(*score_list[1:])
|
s104736215
|
Accepted
| 1,761
| 63,876
| 509
|
n, q = map(int, input().split())
nei_list = [[] for i in range(n+1)]
for i in range(n - 1):
a, b = map(int, input().split())
nei_list[a].append(b)
nei_list[b].append(a)
score = [0] * (n+1)
for i in range(q):
p, x = map(int, input().split())
score[p] += x
work_stack = [1]
visited = set()
while work_stack:
i = work_stack.pop()
visited.add(i)
for j in nei_list[i]:
if j not in visited:
work_stack.append(j)
score[j] += score[i]
print(*score[1:])
|
s993039699
|
p03549
|
u412563426
| 2,000
| 262,144
|
Wrong Answer
| 21
| 3,188
| 176
|
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
|
n, m = list(map(int, input().split()))
T = 100*(n-m) + 1900 * m
# print(T)
gamma = 0.5**m
sum = 0
for i in range(1000):
sum += T * (i+1) * 1/4 * (3/4) **i
print(round(sum))
|
s978022541
|
Accepted
| 18
| 2,940
| 173
|
n, m = list(map(int, input().split()))
T = 100*(n-m) + 1900 * m
gamma = 0.5**m
sum = 0
for i in range(1000):
sum += T * (i+1) * gamma * (1 - gamma) **i
print(round(sum))
|
s626925890
|
p02606
|
u844895214
| 2,000
| 1,048,576
|
Wrong Answer
| 118
| 26,988
| 434
|
How many multiples of d are there among the integers between L and R (inclusive)?
|
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def Main():
l,r,d = IL()
print(math.ceil((r-l)//d))
return
if __name__=='__main__':
Main()
|
s517164956
|
Accepted
| 130
| 27,144
| 496
|
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def Main():
l,r,d = IL()
c = 0
for rep in range(l,r+1):
if rep%d==0:
c += 1
print(c)
return
if __name__=='__main__':
Main()
|
s138222629
|
p03455
|
u557284649
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 79
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
a, b = map(int, input().split(" "))
r = a * b % 2
print(r if "Odd" else "Even")
|
s406204915
|
Accepted
| 17
| 2,940
| 95
|
a, b = map(int, input().split(" "))
r = a * b % 2
if r == 0:
print("Even")
else:
print("Odd")
|
s080575034
|
p02410
|
u806005289
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,592
| 458
|
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
|
l=input().split()
n=int(l[0])
m=int(l[1])
i=0
A=[]
while i<n:
a=input().split()
for p in a:
A.append(int(p))
i+=1
I=0
B=[]
while I<m:
b=int(input())
B.append(b)
I+=1
#Ci=ai1b1+ai2b2+...+aimbm
#C[i]=a[m*(i)+1]*b[1]+a[m*(i)+2]*b[2]+...a[m*(i)+m]*b[m]
q=0
C=[]
while q<n:
Q=0
cq=0
while Q<m:
cq+=A[m*q+Q]*B[Q]
Q+=1
C.append(cq)
q+=1
print(C)
|
s404116957
|
Accepted
| 30
| 5,948
| 473
|
l=input().split()
n=int(l[0])
m=int(l[1])
i=0
A=[]
while i<n:
a=input().split()
for p in a:
A.append(int(p))
i+=1
I=0
B=[]
while I<m:
b=int(input())
B.append(b)
I+=1
#Ci=ai1b1+ai2b2+...+aimbm
#C[i]=a[m*(i)+1]*b[1]+a[m*(i)+2]*b[2]+...a[m*(i)+m]*b[m]
q=0
C=[]
while q<n:
Q=0
cq=0
while Q<m:
cq+=A[m*q+Q]*B[Q]
Q+=1
C.append(cq)
q+=1
for x in C:
print(x)
|
s834706757
|
p03385
|
u100572972
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 64
|
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
|
N = str(input())
print(('a' in N) and ('b' in N) and ('c' in N))
|
s789693097
|
Accepted
| 17
| 2,940
| 90
|
N = str(input())
print('Yes') if ('a' in N) and ('b' in N) and ('c' in N) else print('No')
|
s604624571
|
p03377
|
u163791883
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 75
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
A, B, X = map(int,input().split())
print('Yes' if A < X < A + B else 'No')
|
s156689049
|
Accepted
| 17
| 2,940
| 77
|
A, B, X = map(int,input().split())
print('YES' if A <= X <= A + B else 'NO')
|
s761222068
|
p03971
|
u701874561
| 2,000
| 262,144
|
Wrong Answer
| 76
| 9,280
| 367
|
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
|
n,a,b=map(int,input().split())
s=input().strip()
njp=0
nop=0
for i in range(len(s)):
if s[i]=='a':
if njp<(a+b):
njp+=1
print('Yes')
else:
print('No')
elif s[i]=='b':
if njp<(a+b):
if nop<=b:
nop+=1
njp+=1
print('yes')
else:
print('No')
else:
print('No')
else:
print('No')
|
s027808437
|
Accepted
| 73
| 9,240
| 366
|
n,a,b=map(int,input().split())
s=input().strip()
njp=0
nop=0
for i in range(len(s)):
if s[i]=='a':
if njp<(a+b):
njp+=1
print('Yes')
else:
print('No')
elif s[i]=='b':
if njp<(a+b):
if nop<b:
nop+=1
njp+=1
print('Yes')
else:
print('No')
else:
print('No')
else:
print('No')
|
s535765151
|
p03644
|
u859897687
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 75
|
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
n=int(input())
for i in range(6,0,-1):
if 2**i<=n:
print(i)
break
|
s159585608
|
Accepted
| 18
| 2,940
| 79
|
n=int(input())
for i in range(6,-1,-1):
if 2**i<=n:
print(2**i)
break
|
s237352347
|
p03644
|
u670180528
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 46
|
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
n=int(input());print(2**(len(bin(n+(n>1)))-3))
|
s442240055
|
Accepted
| 17
| 2,940
| 52
|
n=int(input());print(2**(len(bin(n+(n>1>n&~-n)))-3))
|
s401970296
|
p03565
|
u101851939
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 361
|
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
|
s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if s_dash < t:
pass
else:
for i in range(len(s_dash)-len(t)+1):
for j, k in zip(s_dash[i:i+len(t)], t):
if j != '?' and j != k:
break
else:
answer = s_dash[:i] + t + s_dash[i+len(t):]
answer = answer.replace('?', 'a')
print(answer)
|
s466686608
|
Accepted
| 17
| 3,064
| 371
|
s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if len(s_dash) < len(t):
pass
else:
for i in range(len(s_dash)-len(t)+1):
for j, k in zip(s_dash[i:i+len(t)], t):
if j != '?' and j != k:
break
else:
answer = s_dash[:i] + t + s_dash[i+len(t):]
answer = answer.replace('?', 'a')
print(answer)
|
s200083563
|
p03699
|
u593590006
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 83
|
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
|
n=int(input())
l=[int(input()) for i in range(n)]
s=sum(l)
print(s if s%10 else -0)
|
s532271311
|
Accepted
| 17
| 3,060
| 175
|
n=int(input())
l=[int(input()) for i in range(n)]
s=sum(l)
if s%10:
print(s)
exit()
mini=[i for i in l if i%10]
if not mini:
print(0)
exit()
print(s-min(mini))
|
s739767462
|
p03044
|
u279266699
| 2,000
| 1,048,576
|
Wrong Answer
| 844
| 83,908
| 604
|
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
|
import sys
sys.setrecursionlimit(1000000)
n = int(input())
t = [[] for _ in range(n)]
color = [None for _ in range(n)]
visited = [False for _ in range(n)]
def dfs(n_num):
visited[n_num] = True
for i in t[n_num]:
if visited[i[0]]:
continue
if i[1] % 2 == 0:
color[i[0]] = color[n_num]
else:
color[i[0]] = abs(color[n_num] - 1)
dfs(i[0])
for i in range(n - 1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
t[u] += [(v, w)]
t[v] += [(u, w)]
print(t)
color[0] = 0
dfs(0)
for i in color:
print(i)
|
s868131041
|
Accepted
| 757
| 80,176
| 594
|
import sys
sys.setrecursionlimit(1000000)
n = int(input())
t = [[] for _ in range(n)]
color = [None for _ in range(n)]
visited = [False for _ in range(n)]
def dfs(n_num):
visited[n_num] = True
for i in t[n_num]:
if visited[i[0]]:
continue
if i[1] % 2 == 0:
color[i[0]] = color[n_num]
else:
color[i[0]] = abs(color[n_num] - 1)
dfs(i[0])
for i in range(n - 1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
t[u] += [(v, w)]
t[v] += [(u, w)]
color[0] = 0
dfs(0)
for i in color:
print(i)
|
s047772646
|
p03605
|
u914330401
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 124
|
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
def main():
n = input()
for s in n:
if s == '9':
print("YES")
return
print("NO")
return
main()
|
s983519154
|
Accepted
| 17
| 2,940
| 124
|
def main():
n = input()
for s in n:
if s == '9':
print("Yes")
return
print("No")
return
main()
|
s970206077
|
p03857
|
u205166254
| 2,000
| 262,144
|
Wrong Answer
| 1,391
| 31,168
| 1,119
|
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 f(m, r):
connmap = [[] for _ in range(m + 1)]
for _ in range(r):
a, b = map(int, input().split())
connmap[a].append(b)
connmap[b].append(a)
group = [0] * (m + 1)
num = 0
for i in range(1, m + 1):
if group[i] > 0:
continue
if len(connmap[i]) == 0:
continue
num += 1
group[i] = num
for j in connmap[i]:
group[j] = num
bfs = connmap[i]
while len(bfs) > 0:
tmp = []
for j in bfs:
for k in connmap[j]:
if group[k] > 0:
continue
group[k] = num
tmp.append(k)
bfs = tmp
return group
n, k, l = map(int, input().split())
road = f(n, k)
rail = f(n, l)
count = {}
for i in range(1, n + 1):
key = '{0} {1}'.format(road[i], rail[i])
if key in count:
count[key] += 1
else:
count[key] = 1
for i in range(1, n + 1):
key = '{0} {1}'.format(road[i], rail[i])
print(count[key], end=' ' if i < n else '')
print()
|
s477434553
|
Accepted
| 1,490
| 50,760
| 1,065
|
def f(m, r):
connmap = [[] for _ in range(m + 1)]
for _ in range(r):
a, b = map(int, input().split())
connmap[a].append(b)
connmap[b].append(a)
group = [0] * (m + 1)
num = 0
for i in range(1, m + 1):
if group[i] > 0:
continue
num += 1
group[i] = num
for j in connmap[i]:
group[j] = num
bfs = connmap[i]
while len(bfs) > 0:
tmp = []
for j in bfs:
for k in connmap[j]:
if group[k] > 0:
continue
group[k] = num
tmp.append(k)
bfs = tmp
return group
n, k, l = map(int, input().split())
road = f(n, k)
rail = f(n, l)
count = {}
for i in range(1, n + 1):
key = '{0} {1}'.format(road[i], rail[i])
if key in count:
count[key] += 1
else:
count[key] = 1
for i in range(1, n + 1):
key = '{0} {1}'.format(road[i], rail[i])
print(count[key], end=' ' if i < n else '')
print()
|
s719815445
|
p03449
|
u626468554
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 306
|
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
|
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
ttl = 0
li1 = []
for i in range(n):
ttl += a1[i]
li1.append(ttl)
ttl = 0
li2 = []
for i in range(1,n+1):
ttl += a2[i*(-1)]
li2.append(ttl)
ans = 0
for i in range(n):
ans = max(ans,li1[i]+li2[i])
|
s636271327
|
Accepted
| 17
| 3,064
| 353
|
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
ttl = 0
li1 = []
for i in range(n):
ttl += a1[i]
li1.append(ttl)
ttl = 0
li2 = []
for i in range(1,n+1):
ttl += a2[i*(-1)]
li2.append(ttl)
ans = 0
for i in range(n):
#print(li1[i]+li2[i])
ans = max(ans,li1[i]+li2[(i+1)*(-1)])
print(ans)
|
s144140141
|
p03485
|
u833089798
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,048
| 71
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
# -*- coding:utf-8 -*-
a, b = map(int, input().split())
print((a+b)/2)
|
s509829301
|
Accepted
| 28
| 9,056
| 100
|
# -*- coding:utf-8 -*-
from math import ceil
a, b = map(int, input().split())
print(ceil((a+b)/2))
|
s952037598
|
p03777
|
u686036872
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 109
|
Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest.
|
a, b=input().split()
if a=='H' and b=='H':
print('H')
if a=='D' and b=='D':
print('H')
else:
print('D')
|
s889060369
|
Accepted
| 17
| 2,940
| 137
|
a, b = map(str, input().split())
if a == "H" and b == "H":
print("H")
elif a == "D" and b == "D":
print("H")
else:
print("D")
|
s425829710
|
p02741
|
u695199406
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 154
|
Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
|
list_1 = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
s = list_1[k-1:k+1]
print(s)
|
s448849210
|
Accepted
| 18
| 3,060
| 144
|
list_1 = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(list_1[k-1])
|
s254939078
|
p03377
|
u424044793
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 87
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a,b,x = map(int,input().split())
if a<=x<=(a+b):
print("Yes")
else:
print("No")
|
s053426300
|
Accepted
| 20
| 3,060
| 87
|
a,b,x = map(int,input().split())
if a<=x<=(a+b):
print("YES")
else:
print("NO")
|
s187187372
|
p02262
|
u264972437
| 6,000
| 131,072
|
Wrong Answer
| 30
| 7,776
| 537
|
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
|
def insertionSort(A,n,g,cnt):
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
return A,cnt
def shellSort(A,n):
cnt = 0
m = n//2 + 1
G = [2*i + 1*(i==0) for i in range(m)[::-1]]
for g in G:
A,cnt = insertionSort(A,n,g,cnt)
return A,m,G,cnt
if __name__ == '__main__':
n = int(input())
A = []
[A.append(int(input())) for i in range(n)]
A,m,G,cnt = shellSort(A,n)
print(m)
print(' '.join([str(i) for i in G]))
print(cnt)
[print(a) for a in A]
|
s237960210
|
Accepted
| 20,960
| 55,232
| 647
|
def insertionSort(A,n,g,cnt):
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
return A,cnt
def shellSort(A,n):
cnt = 0
G = [1]
while G[-1]*3+1 <= n:
G.append(G[-1]*3 + 1)
G = G[::-1]
m = len(G)
for g in G:
A,cnt = insertionSort(A,n,g,cnt)
return A,m,G,cnt
if __name__ == '__main__':
n = int(input())
A = []
[A.append(int(input())) for i in range(n)]
A,m,G,cnt = shellSort(A,n)
print(m)
print(' '.join([str(i) for i in G]))
print(cnt)
[print(a) for a in A]
|
s714682643
|
p04011
|
u729119068
| 2,000
| 262,144
|
Wrong Answer
| 29
| 9,184
| 71
|
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.
|
a,b,c,d=[int(input()) for i in range(4)]
print(c*min(a,b)+d*max(b-a,0))
|
s480103769
|
Accepted
| 29
| 9,032
| 71
|
a,b,c,d=[int(input()) for i in range(4)]
print(c*min(a,b)+d*max(a-b,0))
|
s170644289
|
p03565
|
u015593272
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,108
| 1,001
|
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
|
def main():
S_part = list(input())
T_hint = list(input())
N = len(S_part)
ans = []
for i in range(N):
index_init = i
if (index_init + len(T_hint) <= N):
s = S_part[index_init:index_init + len(T_hint)]
if ('?' in s):
FLAG = True
for j in range(len(s)):
if (T_hint[j] != s[j] and s[j] == '?'):
s[j] = T_hint[j]
elif (T_hint[j] != s[j] and s[j] != '?'):
FLAG = False
break
if (FLAG):
tmp_ans = ''.join(s)
tmp_ans = tmp_ans.replace('?', 'a')
ans.append(tmp_ans)
ans.sort()
if (len(ans) > 0):
print(ans[0])
else:
print('UNRESTORABLE')
if __name__ == '__main__':
main()
|
s465185388
|
Accepted
| 26
| 9,108
| 689
|
S_hatena = input()
T_hint = input()
N = len(S_hatena)
ans_list = []
for i in range(N):
index_init = i
index_end = i + len(T_hint) - 1
s = S_hatena[index_init:index_end + 1]
FLAG = True
if (index_end < N):
for j in range(len(T_hint)):
if (s[j] != T_hint[j] and s[j] != '?'):
FLAG = False
break
else:
FLAG = False
if (FLAG):
tmp_ans = S_hatena[:index_init] + T_hint + S_hatena[index_init + len(T_hint):]
tmp_ans = tmp_ans.replace('?', 'a')
ans_list.append(tmp_ans)
ans_list.sort()
if (len(ans_list) > 0):
print(ans_list[0])
else:
print('UNRESTORABLE')
|
s587400597
|
p03658
|
u870297120
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 109
|
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
|
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
a.reverse()
print(sum(a[0:k-1]))
|
s629064684
|
Accepted
| 17
| 2,940
| 107
|
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
a.reverse()
print(sum(a[0:k]))
|
s033350715
|
p03351
|
u245487028
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 3,316
| 152
|
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a, b, c, d = map(int, input().split())
if abs(a-c) < d:
print("Yes")
elif (abs(a-b) < d) and (abs(b-c) < d):
print("Yes")
else:
print("No")
|
s208159527
|
Accepted
| 18
| 2,940
| 155
|
a, b, c, d = map(int, input().split())
if abs(a-c) <= d:
print("Yes")
elif (abs(a-b) <= d) and (abs(b-c) <= d):
print("Yes")
else:
print("No")
|
s297278266
|
p03574
|
u999799597
| 2,000
| 262,144
|
Wrong Answer
| 26
| 3,572
| 1,291
|
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
|
h, w = map(int, input().split())
mass = []
for i in range(h):
x = input()
mass.append([])
for j in range(w):
mass[i].append(x[j])
init = []
for i in range(h):
# x = input()
init.append([])
for j in range(w):
init[i].append(0)
for i in range(h):
for j in range(w):
if mass[i][j] != "#":
# up
if i + 1 < h and mass[i + 1][j] == "#":
init[i][j] += 1
# down
if i - 1 >= 0 and mass[i - 1][j] == "#":
init[i][j] += 1
# right
if j + 1 < w and mass[i][j + 1] == "#":
init[i][j] += 1
# left
if j - 1 >= 0 and mass[i][j - 1] == "#":
init[i][j] += 1
if j + 1 < w and i + 1 < h and mass[i + 1][j + 1] == "#":
init[i][j] += 1
if i - 1 >= 0 and j - 1 >= 0 and mass[i - 1][j - 1] == "#":
init[i][j] += 1
if i + 1 < h and j - 1 >= 0 and mass[i + 1][j - 1] == "#":
init[i][j] += 1
if i - 1 >= 0 and j + 1 < w and mass[i - 1][j + 1] == "#":
init[i][j] += 1
else:
init[i][j] = "#"
for i in range(h):
for j in range(w):
print(init[i][j])
|
s368182954
|
Accepted
| 25
| 3,188
| 1,347
|
h, w = map(int, input().split())
mass = []
for i in range(h):
x = input()
mass.append([])
for j in range(w):
mass[i].append(x[j])
init = []
for i in range(h):
# x = input()
init.append([])
for j in range(w):
init[i].append(0)
for i in range(h):
for j in range(w):
if mass[i][j] != "#":
# up
if i + 1 < h and mass[i + 1][j] == "#":
init[i][j] += 1
# down
if i - 1 >= 0 and mass[i - 1][j] == "#":
init[i][j] += 1
# right
if j + 1 < w and mass[i][j + 1] == "#":
init[i][j] += 1
# left
if j - 1 >= 0 and mass[i][j - 1] == "#":
init[i][j] += 1
if j + 1 < w and i + 1 < h and mass[i + 1][j + 1] == "#":
init[i][j] += 1
if i - 1 >= 0 and j - 1 >= 0 and mass[i - 1][j - 1] == "#":
init[i][j] += 1
if i + 1 < h and j - 1 >= 0 and mass[i + 1][j - 1] == "#":
init[i][j] += 1
if i - 1 >= 0 and j + 1 < w and mass[i - 1][j + 1] == "#":
init[i][j] += 1
else:
init[i][j] = "#"
res = []
for i in range(h):
for j in range(w):
res.append(str(init[i][j]))
print(''.join(res))
res = []
|
s311506158
|
p03385
|
u684084063
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 165
|
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
|
# -*- coding: utf-8 -*-
S = map(int,input().split())
if S=="abc" or S=="acb" or S=="bac" or S=="bca" or S=="cab" or S=="cba":
print("Yes")
else:
print("No")
|
s585352468
|
Accepted
| 17
| 2,940
| 148
|
# -*- coding: utf-8 -*-
S =input()
if S=="abc" or S=="acb" or S=="bac" or S=="bca" or S=="cab" or S=="cba":
print("Yes")
else:
print("No")
|
s346202946
|
p02364
|
u442472098
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,724
| 572
|
Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E).
|
#!/usr/bin/env python3
V, E = map(int, input().split())
D = 0
vertices = []
for i in range(V):
vertices.append(i)
edges = []
for i in range(E):
s, t, d = map(int, input().split())
edges.append((s, t, d))
edges.sort(key=lambda x: x[2])
while edges:
if V == 0:
break
s, t, d = edges.pop(0)
if vertices[s] != vertices[t]:
vertices[s] = vertices[t] = min(vertices[s], vertices[t])
D += d
V -= 1
print(D)
|
s712670690
|
Accepted
| 2,310
| 31,848
| 772
|
#!/usr/bin/env python3
from collections import defaultdict
V, E = map(int, input().split())
D = 0
tree = []
vertices = defaultdict(set)
for i in range(V):
tree.append(i)
vertices[i].add(i)
edges = []
for i in range(E):
s, t, d = map(int, input().split())
edges.append((s, t, d))
edges.sort(key=lambda x: x[2])
while edges:
if V == 1:
break
s, t, d = edges.pop(0)
if tree[s] != tree[t]:
new = min(tree[s], tree[t])
old = max(tree[s], tree[t])
vertices[new] = vertices[new] | vertices[old]
for vertex in vertices[old]:
tree[vertex] = new
D += d
V -= 1
print(D)
|
s778517317
|
p03447
|
u265118937
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 125
|
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
|
x = int(input())
a = int(input())
b = int(input())
cnt = 0
yen = x -a
while yen > 0:
yen -= b
cnt += 1
print(yen -cnt*b)
|
s613863823
|
Accepted
| 17
| 2,940
| 134
|
x = int(input())
a = int(input())
b = int(input())
yen = x -a
while True:
yen -= b
if yen < 0:
yen += b
break
print(yen)
|
s833015161
|
p03836
|
u011062360
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 170
|
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
|
sx, sy, gx, gy = map(int, input().split())
print("U"*(gy-sy)+"R"*(gx-sx)+"D"*(gy-sy)+"L"*(gx-sx)+"L"+"U"*(gy-sy+1)+"R"*(gx-sx+1)+"D"+"R"+"D"*(gy-sy+1)+"L"*(gx-sx+1)+"D")
|
s538170406
|
Accepted
| 18
| 3,060
| 170
|
sx, sy, gx, gy = map(int, input().split())
print("U"*(gy-sy)+"R"*(gx-sx)+"D"*(gy-sy)+"L"*(gx-sx)+"L"+"U"*(gy-sy+1)+"R"*(gx-sx+1)+"D"+"R"+"D"*(gy-sy+1)+"L"*(gx-sx+1)+"U")
|
s246378829
|
p03712
|
u527993431
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 205
|
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
|
H,W=map(int,input().split())
L=[]
for i in range (H):
T=input()
L.append(T)
A="#"*(H+2)
for i in range (H+2):
if i==0 or i==H+1:
print(A)
else:
print("#",end="")
print(L[i-1],end="")
print("#")
|
s026932497
|
Accepted
| 17
| 3,060
| 205
|
H,W=map(int,input().split())
L=[]
for i in range (H):
T=input()
L.append(T)
A="#"*(W+2)
for i in range (H+2):
if i==0 or i==H+1:
print(A)
else:
print("#",end="")
print(L[i-1],end="")
print("#")
|
s588537799
|
p00002
|
u947762778
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,628
| 88
|
Write a program which computes the digit number of sum of two integers a and b.
|
inputNums = list(map(int, input().split()))
print(len(str(inputNums[0] + inputNums[1])))
|
s814189510
|
Accepted
| 60
| 7,652
| 151
|
while True:
try:
inputNums = list(map(int, input().split()))
print(len(str(inputNums[0] + inputNums[1])))
except:
break
|
s147121409
|
p00016
|
u548155360
| 1,000
| 131,072
|
Wrong Answer
| 30
| 5,728
| 304
|
When a boy was cleaning up after his grand father passing, he found an old paper: In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper. For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town. You can assume that d ≤ 100 and -180 ≤ t ≤ 180\.
|
# coding=utf-8
import math
x = 0
y = 0
direction = math.pi/2
while True:
d, a = map(int, input().split(','))
if d == 0 and a == 0:
break
x += d * math.cos(direction)
y += d * math.sin(direction)
direction -= a*math.pi/180
print('{0:.0f}'.format(x))
print('{0:.0f}'.format(y))
|
s841221101
|
Accepted
| 30
| 5,732
| 332
|
# coding=utf-8
import math
x = 0
y = 0
direction = math.pi/2
while True:
d, a = map(int, input().split(','))
if d == 0 and a == 0:
break
x += d * math.cos(direction)
y += d * math.sin(direction)
direction -= a*math.pi/180
print('{0:.0f}'.format(math.modf(x)[1]))
print('{0:.0f}'.format(math.modf(y)[1]))
|
s179956714
|
p03993
|
u542190960
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 13,880
| 271
|
There are N rabbits, numbered 1 through N. The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i. For a pair of rabbits i and j (i<j), we call the pair (i,j) a _friendly pair_ if the following condition is met. * Rabbit i likes rabbit j and rabbit j likes rabbit i. Calculate the number of the friendly pairs.
|
n = int(input())
a_list = list(map(int, input().split()))
cnt = 0
index_list = list(range(0,n,1))
print(index_list)
for i in (index_list):
if a_list[a_list[i]-1] == i+1:
cnt += 1
index_list.remove(a_list[i]-1)
index_list.remove(i)
print(cnt)
|
s243331323
|
Accepted
| 69
| 14,324
| 255
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
if a[a[i]-1] == i + 1:
cnt += 1
print(cnt//2)
|
s936453600
|
p03494
|
u370429695
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 258
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
n = int(input())
li = list(map(int,input().split()))
split_cnt = 0
p = 0
while p == 0:
for i in range(len(li)):
if li[i] % 2 == 1:
p = 1
break
else:
li[i] = li[i] / 2
split_cnt += 1
print(split_cnt)
|
s394244841
|
Accepted
| 20
| 3,060
| 262
|
n = int(input())
li = list(map(int,input().split()))
split_cnt = 0
p = 0
while p == 0:
for i in range(len(li)):
if li[i] % 2 == 1:
p = 1
break
else:
li[i] = li[i] / 2
split_cnt += 1
print(split_cnt - 1)
|
s858587563
|
p03351
|
u516272298
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 112
|
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a,b,c,d = map(int,input().split())
if b-a <= d and c-b <= d and c-a <= d:
print("Yes")
else:
print("No")
|
s053161325
|
Accepted
| 17
| 2,940
| 126
|
a,b,c,d = map(int,input().split())
if abs(b-a) <= d and abs(c-b) <= d or abs(c-a) <= d:
print("Yes")
else:
print("No")
|
s420072289
|
p03469
|
u347397127
| 2,000
| 262,144
|
Wrong Answer
| 25
| 8,908
| 34
|
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
S = input()
print(S[:2]+"8"+S[4:])
|
s298728941
|
Accepted
| 29
| 8,948
| 35
|
S = input()
print(S[:3]+"8"+S[4:])
|
s218741126
|
p03380
|
u426764965
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 14,348
| 487
|
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
|
n = int(input())
a = sorted(map(int, input().split()))
print(a)
from operator import mul
from functools import reduce
def comb(n, r):
r = min(r, n-r)
numer = reduce(mul, range(n, n-r, -1), 1)
denom = reduce(mul, range(1, r+1), 1)
return numer // denom
from bisect import bisect_left
n = a[-1]
p = bisect_left(a, n//2) - 1
ans_r = -1
comb_max = 0
for i in range(p, n):
c = comb(n, a[i])
if c > comb_max:
comb_max = c
ans_r = a[i]
else:
break
print(n, ans_r)
|
s004321577
|
Accepted
| 108
| 14,060
| 157
|
n = int(input())
A = sorted(map(int, input().split()))
ans_n = A[-1]
ans_r = -1
for a in A:
if ans_r < min(a, ans_n - a):
ans_r = a
print(ans_n, ans_r)
|
s606820788
|
p02694
|
u080685822
| 2,000
| 1,048,576
|
Time Limit Exceeded
| 2,206
| 16,908
| 95
|
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
x = int(input())
for n in 10 ** 10 ** 10:
if x <= (101 ** n) / (100 ** (n - 1)):
print(n)
|
s399873321
|
Accepted
| 21
| 9,060
| 99
|
x = int(input())
n = 0
mon = 100
while mon < x:
mon *= 1.01
mon = int(mon)
n += 1
print(n)
|
s098972020
|
p02397
|
u406002631
| 1,000
| 131,072
|
Wrong Answer
| 50
| 5,616
| 126
|
Write a program which reads two integers x and y, and prints them in ascending order.
|
while True:
l = input().split()
b = int(l[0])
c = int(l[1])
if b == 0 and c == 0:
break
print(b,c)
|
s203013074
|
Accepted
| 60
| 5,608
| 175
|
while True:
l = input().split()
b = int(l[0])
c = int(l[1])
if b == 0 and c == 0:
break
if b < c:
print(b, c)
else:
print(c, b)
|
s214007011
|
p03474
|
u859897687
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 65
|
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
|
a,b=map(int,input().split())
s=input()
print(s[:a+1]+"-"+s[a+1:])
|
s467438291
|
Accepted
| 18
| 2,940
| 106
|
a,b=map(int,input().split())
s=input()
if s.count("-")<2 and s[a]=="-":
print("Yes")
else:
print("No")
|
s812748008
|
p02694
|
u688587139
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 9,156
| 108
|
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
import math
a = 100
n = 0
X = int(input())
while a <= X:
n += 1
a = math.floor(a * 1.01)
print(n)
|
s253498758
|
Accepted
| 21
| 9,160
| 108
|
import math
a = 100
n = 0
X = int(input())
while a < X:
n += 1
a = math.floor(a * 1.01)
print(n)
|
s176879858
|
p03645
|
u013408661
| 2,000
| 262,144
|
Wrong Answer
| 354
| 48,640
| 261
|
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
|
import sys
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
possible=[]
possible2=[]
for i in l:
if i[0]==1:
possible.append(i[1])
for i in l:
if i[1]==n:
possible2.append(i[0])
print(len(set(possible)&set(possible2)))
|
s898193123
|
Accepted
| 348
| 48,552
| 308
|
import sys
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
possible=[]
possible2=[]
for i in l:
if i[0]==1:
possible.append(i[1])
for i in l:
if i[1]==n:
possible2.append(i[0])
if len(set(possible)&set(possible2))>0:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
|
s269760557
|
p03305
|
u202826462
| 2,000
| 1,048,576
|
Wrong Answer
| 2,111
| 116,332
| 1,884
|
Kenkoooo is planning a trip in Republic of Snuke. In this country, there are n cities and m trains running. The cities are numbered 1 through n, and the i-th train connects City u_i and v_i bidirectionally. Any city can be reached from any city by changing trains. Two currencies are used in the country: yen and snuuk. Any train fare can be paid by both yen and snuuk. The fare of the i-th train is a_i yen if paid in yen, and b_i snuuk if paid in snuuk. In a city with a money exchange office, you can change 1 yen into 1 snuuk. However, when you do a money exchange, you have to change all your yen into snuuk. That is, if Kenkoooo does a money exchange when he has X yen, he will then have X snuuk. Currently, there is a money exchange office in every city, but the office in City i will shut down in i years and can never be used in and after that year. Kenkoooo is planning to depart City s with 10^{15} yen in his pocket and head for City t, and change his yen into snuuk in some city while traveling. It is acceptable to do the exchange in City s or City t. Kenkoooo would like to have as much snuuk as possible when he reaches City t by making the optimal choices for the route to travel and the city to do the exchange. For each i=0,...,n-1, find the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i years. You can assume that the trip finishes within the year.
|
import heapq
def dijkstra(s):
d = [float("inf")] * (n+1)
used = [True] * (n+1)
d[s] = 0
used[s] = False
edgelist = []
for e in graph_a[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in graph_a[v]:
if used[e[1]]:
heapq.heappush(edgelist,[e[0]+d[v],e[1]])
return d
def dijkstra1(s):
d = [float("inf")] * (n+1)
used = [True] * (n+1)
d[s] = 0
used[s] = False
edgelist = []
for e in graph_b[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in graph_b[v]:
if used[e[1]]:
heapq.heappush(edgelist,[e[0]+d[v],e[1]])
return d
n, m, s, t = map(int, input().split())
graph_a = {i: [] for i in range(1, n + 1)}
graph_b = {i: [] for i in range(1, n + 1)}
for _ in range(m):
u, v, a, b = map(int, input().split())
graph_a[u].append([a, v])
graph_a[v].append([a, u])
graph_b[u].append([b, v])
graph_b[v].append([b, u])
yen = dijkstra(s)
snu = dijkstra1(t)
print(yen,"\n",snu)
cost = [float("INF")] * (n + 1)
for i in range(1, n + 1):
cost[i] = (yen[i] - yen[s]) + snu[i]
for i in range(1, n + 1):
print(1000000000000000 - min(cost))
del cost[1]
|
s905807736
|
Accepted
| 1,606
| 90,184
| 1,211
|
import heapq
INF = 10**18
def dijkstra(s, edge, n):
d = [INF] * n
used = [True] * n #True: not used
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v],e[1]))
return d
n, m, s, t = map(int, input().split())
s -= 1
t -= 1
graph_a = [[] for _ in range(n)]
graph_b = [[] for _ in range(n)]
for i in range(m):
u, v, a, b = map(int, input().split())
u, v = u-1, v-1
graph_a[u].append((a, v))
graph_a[v].append((a, u))
graph_b[u].append((b, v))
graph_b[v].append((b, u))
yen = dijkstra(s, graph_a, n)
snu = dijkstra(t, graph_b, n)
cost = [0] * n
for i in range(n):
cost[i] = (yen[i] + snu[i],i)
heapq.heapify(cost)
c = -1
aaa = 10 ** 15
for i in range(n):
if c < i:
while cost:
nn, t = heapq.heappop(cost)
if t >= i:
c = t
break
print(aaa - nn)
|
s879678034
|
p02645
|
u011277545
| 2,000
| 1,048,576
|
Wrong Answer
| 21
| 9,024
| 22
|
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
|
S=input()
print(S[:2])
|
s578890014
|
Accepted
| 26
| 9,084
| 22
|
S=input()
print(S[:3])
|
s748427237
|
p04030
|
u405256066
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 229
|
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?
|
from sys import stdin
s = (stdin.readline().rstrip())
ans = ""
for i in s:
if i == "0":
ans = ans + "0"
elif i == "1":
ans = "1" + ans
elif i == "B" and len(ans) != 0:
ans = ans[:-1]
print(ans)
|
s680804389
|
Accepted
| 17
| 3,060
| 229
|
from sys import stdin
s = (stdin.readline().rstrip())
ans = ""
for i in s:
if i == "0":
ans = ans + "0"
elif i == "1":
ans = ans + "1"
elif i == "B" and len(ans) != 0:
ans = ans[:-1]
print(ans)
|
s372114743
|
p02399
|
u921038488
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,612
| 139
|
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
|
def getCal(a,b):
return a+b, a%b, float(a/b)
a, b = map(int, input().split())
d, r, f = getCal(a,b)
print("{} {} {}".format(d, r, f))
|
s856695974
|
Accepted
| 20
| 5,596
| 66
|
a, b = map(int, input().split())
print(a//b, a%b, '%.5f' % (a/b))
|
s091061855
|
p03162
|
u280978334
| 2,000
| 1,048,576
|
Wrong Answer
| 1,163
| 35,540
| 374
|
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
|
n = int(input())
import numpy as np
abc = np.array([[int(x) for x in input().split()] for y in range(n)],dtype=int)
dp = np.zeros((n,3),dtype=int)
dp[0] = abc[0]
for p in range(1,n):
dp[p][0] = max(dp[p-1][1],dp[p-1][2]) + abc[p][0]
dp[p][1] = max(dp[p-1][0],dp[p-1][2]) + abc[p][1]
dp[p][2] = max(dp[p-1][0],dp[p-1][1]) + abc[p][2]
print(dp)
print(max(dp[n-1]))
|
s141814636
|
Accepted
| 1,093
| 35,552
| 364
|
n = int(input())
import numpy as np
abc = np.array([[int(x) for x in input().split()] for y in range(n)],dtype=int)
dp = np.zeros((n,3),dtype=int)
dp[0] = abc[0]
for p in range(1,n):
dp[p][0] = max(dp[p-1][1],dp[p-1][2]) + abc[p][0]
dp[p][1] = max(dp[p-1][0],dp[p-1][2]) + abc[p][1]
dp[p][2] = max(dp[p-1][0],dp[p-1][1]) + abc[p][2]
print(max(dp[n-1]))
|
s593464690
|
p02612
|
u383416302
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,080
| 106
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
def main():
n = int(input())
print(n - (n // 1000) * 1000)
if __name__ == "__main__":
main()
|
s397577206
|
Accepted
| 25
| 9,148
| 91
|
def main():
n = int(input())
print(-n%1000)
if __name__ == "__main__":
main()
|
s623625321
|
p02607
|
u260068288
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,060
| 146
|
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())
l=list(map(int,input().split()))
count = 0
for i in range(0,n,2):
print(l[i]&1)
if l[i]&1:
count += 1
print(count)
|
s499094955
|
Accepted
| 26
| 9,100
| 128
|
n= int(input())
l=list(map(int,input().split()))
count = 0
for i in range(0,n,2):
if l[i]&1:
count += 1
print(count)
|
s037772231
|
p03386
|
u863044225
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 173
|
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())
x=[]
for i in range(a,min(b+1,a+k)):
x.append(i)
for i in range(max(a,b-k+1),b+1):
x.append(i)
ans=list(set(x))
for i in ans:
print(i)
|
s639950576
|
Accepted
| 17
| 3,060
| 184
|
a,b,k=map(int,input().split())
x=[]
for i in range(a,min(b+1,a+k)):
x.append(i)
for i in range(max(a,b-k+1),b+1):
x.append(i)
ans=list(set(x))
ans.sort()
for i in ans:
print(i)
|
s982926836
|
p03711
|
u272377260
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 275
|
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
|
x, y = map(int, input().split())
group_1 = (1,2,5,7,8,10,12)
group_2 = (4,7,9,11)
group_3 = (2,)
if x in group_1 and y in group_1:
print('Yes')
elif x in group_2 and y in group_2:
print('Yes')
elif x in group_3 and y in group_3:
print('Yes')
else:
print('No')
|
s226805531
|
Accepted
| 18
| 3,060
| 275
|
x, y = map(int, input().split())
group_1 = (1,3,5,7,8,10,12)
group_2 = (4,6,9,11)
group_3 = (2,)
if x in group_1 and y in group_1:
print('Yes')
elif x in group_2 and y in group_2:
print('Yes')
elif x in group_3 and y in group_3:
print('Yes')
else:
print('No')
|
s021994547
|
p03351
|
u287431190
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 104
|
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a,b,c,d = map(int, input().split())
if (b-a)<=d:
if (c-b)<=d:
print('No')
exit()
print('Yes')
|
s300762906
|
Accepted
| 17
| 2,940
| 152
|
a,b,c,d = map(int, input().split())
if abs(c-a)<=d:
print('Yes')
exit()
if abs(b-a)<=d:
if abs(c-b)<=d:
print('Yes')
exit()
print('No')
|
s139942553
|
p02742
|
u733167185
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 115
|
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
|
import math
H, W = map(int, input().split())
if H*W % 2 == 0:
print(H*W/2)
else:
print(math.floor(H*W/2)+1)
|
s581028115
|
Accepted
| 18
| 2,940
| 94
|
H, W = map(int, input().split())
if H == 1 or W == 1:
print(1)
else:
print((H*W+1)//2)
|
s839568883
|
p04043
|
u903005414
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 107
|
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
|
A = sorted(list(map(int, input().split())))
print('YES' if A[0] == 5 and A[1] == 7 and A[2] == 7 else 'NO')
|
s175514380
|
Accepted
| 17
| 2,940
| 108
|
A = sorted(list(map(int, input().split())))
print('YES' if A[0] == 5 and A[1] == 5 and A[2] == 7 else 'NO')
|
s573413560
|
p02646
|
u911612592
| 2,000
| 1,048,576
|
Wrong Answer
| 26
| 9,144
| 191
|
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,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
AB = abs(A - B)
VW = V - W
if VW == 0:
print("No")
elif AB <= VW * T:
print("Yes")
else:
print("No")
|
s729652814
|
Accepted
| 23
| 9,180
| 192
|
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
AB = abs(A - B)
VW = V - W
if VW == 0:
print("NO")
elif AB <= VW * T:
print("YES")
else:
print("NO")
|
s253123178
|
p03565
|
u480847874
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 570
|
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
|
NOT_FOUND = 'UNRESTORABLE'
def m():
S = list(str(input()))
T = list(str(input()))
first = 0
end = 0
for i in range(len(S) + 1 - len(T)):
for k in range(len(T)):
if S[i+k] != T[k] and S[i+k] != '?':
break
if k == len(T) - 1:
first = i
end = i+k
if (end - first) < len(T):
return NOT_FOUND
j = 0
while first <= end:
S[first] = T[j]
first += 1
j += 1
ans = "".join(S)
r = ans.replace('?', 'a')
return r
print(m())
|
s262189637
|
Accepted
| 17
| 3,064
| 582
|
NOT_FOUND = 'UNRESTORABLE'
def m():
S = list(str(input()))
T = list(str(input()))
first = 0
end = 0
for i in range(len(S) + 1 - len(T)):
for k in range(len(T)):
if S[i + k] != T[k] and S[i + k] != '?':
break
if k == len(T) - 1:
first = i
end = i + k
if (end - first) < len(T) - 1:
return NOT_FOUND
j = 0
while first <= end:
S[first] = T[j]
first += 1
j += 1
ans = "".join(S)
r = ans.replace('?', 'a')
return r
print(m())
|
s551265011
|
p02393
|
u569585396
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,644
| 100
|
Write a program which reads three integers, and prints them in ascending order.
|
x = input().split()
i = list(map(int,x))
a = i[0]
b = i[1]
c = i[2]
print('{} {} {}'.format(c,b,a))
|
s935389820
|
Accepted
| 30
| 7,664
| 92
|
x = input().split()
i = list(map(int,x))
i.sort()
print('{} {} {}'.format(i[0],i[1],i[2]))
|
s664409041
|
p03485
|
u960513073
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 57
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
a, b = map(int, input().split())
print(int((a+b)/2) + 1)
|
s243546957
|
Accepted
| 17
| 2,940
| 161
|
a, b = list(map(int, input().split()))
c = a+b
if c%2 == 0:
print(int(c/2))
else:
print(int(c/2) + 1)
|
s124721813
|
p02388
|
u387507798
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,528
| 16
|
Write a program which calculates the cube of a given integer x.
|
print(input())
|
s401964620
|
Accepted
| 20
| 5,576
| 31
|
n = int(input())
print(n*n*n)
|
s466298205
|
p00375
|
u888548672
| 1,000
| 262,144
|
Wrong Answer
| 20
| 5,580
| 27
|
In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is commonly encountered while you are in America. A value in Fahrenheit can be converted to Celsius by first subtracting $32$ and then multiplying by $\frac{5}{9}$. A simplified method may be used to produce a rough estimate: first subtract $30$ and then divide by $2$. Using the latter method, $68$ Fahrenheit is converted to $19$ Centigrade, i.e., $\frac{(68-30)}{2}$. Make a program to convert Fahrenheit to Celsius using the simplified method: $C = \frac{F - 30}{2}$.
|
print((int(input())-30)/2)
|
s548486311
|
Accepted
| 20
| 5,580
| 32
|
print(int((int(input())-30)/2))
|
s559221849
|
p03456
|
u305732215
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 150
|
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
a, b = input().split()
ab = int(a + b)
rt = round(ab ** 0.5, 1)
rts = str(rt)
print(rts)
if rts[-1] == '0':
print('Yes')
else:
print('No')
|
s407429139
|
Accepted
| 17
| 2,940
| 121
|
a, b = input().split()
ab = int(a + b)
rt = round(ab ** 0.5, 1)
if rt.is_integer():
print('Yes')
else:
print('No')
|
s094077241
|
p03997
|
u367373844
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 101
|
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.
|
up = int(input())
down = int(input())
high = int(input())
area = (up + down ) * high / 2
print(area)
|
s079093741
|
Accepted
| 17
| 2,940
| 105
|
up = int(input())
down = int(input())
high = int(input())
area = (up + down ) * high / 2
print(int(area))
|
s872395483
|
p03385
|
u759412327
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 75
|
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
|
a = input()
b = sorted(a)
if b == "abc":
print("Yes")
else:
print("No")
|
s432561321
|
Accepted
| 29
| 9,080
| 59
|
if len(set(input()))==3:
print("Yes")
else:
print("No")
|
s465573508
|
p02277
|
u805716376
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,608
| 893
|
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
|
a = []
n = int(input())
for _ in range(n):
s, i = input().split()
a += [(s, int(i))]
print(a)
b = a[:]
def partition(a, left, right):
standard = a[right][1]
cnt = left
for i in range(left, right+1):
if i == right:
if a[i][1] <= standard:
a[i],a[cnt] = a[cnt], a[i]
elif a[i][1] <= standard:
a[cnt],a[i] = a[i], a[cnt]
cnt += 1
return cnt
def quickSort(a, left = 0, right = len(a) - 1):
if 1 <= right - left:
cnt_ = partition(a, left, right)
quickSort(a,left, cnt_ - 1)
quickSort(a,cnt_ + 1, right)
quickSort(a, 0 , len(a)-1)
for i in range(n-1):
for j in range(n-1-i):
if b[j][1] > b[j+1][1]:
b[j], b[j+1] = b[j+1], b[j]
if a == b:
print('Stable')
else:
print('Not Stable')
for i in range(n):
print(*a[i])
|
s451227767
|
Accepted
| 1,050
| 24,976
| 792
|
a = []
b = {}
n = int(input())
for _ in range(n):
s, i = input().split()
a += [(s, int(i))]
b.setdefault(int(i), []).append(s)
b = {val: iter(s).__next__ for val, s in b.items()}
def partition(a, left, right):
standard = a[right][1]
cnt = left
for i in range(left, right):
if a[i][1] <= standard:
a[cnt],a[i] = a[i], a[cnt]
cnt += 1
a[cnt],a[right] = a[right], a[cnt]
return cnt
def quickSort(a, left = 0, right = len(a) - 1):
if 1 <= right - left:
cnt_ = partition(a, left, right)
quickSort(a,left, cnt_ - 1)
quickSort(a,cnt_ + 1, right)
quickSort(a, 0 , len(a)-1)
ok = 1
for s, i in a:
if b[i]() != s:
ok = 0
print(['Not stable','Stable'][ok])
for i in range(n):
print(*a[i])
|
s366389460
|
p02606
|
u152614052
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,164
| 103
|
How many multiples of d are there among the integers between L and R (inclusive)?
|
l, r, d = map(int,input().split())
ans = 0
for i in range(l, r+1):
if i % d == 0:
ans += 1
|
s284096444
|
Accepted
| 27
| 9,092
| 115
|
l, r, d = map(int,input().split())
ans = 0
for i in range(l, r+1):
if i % d == 0:
ans += 1
print(ans)
|
s607508653
|
p02645
|
u265118937
| 2,000
| 1,048,576
|
Wrong Answer
| 22
| 9,012
| 63
|
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
|
s = input()
print(s[2], end="")
print(s[1], end="")
print(s[0])
|
s035715470
|
Accepted
| 26
| 8,932
| 24
|
s = input()
print(s[:3])
|
s803714182
|
p00500
|
u352394527
| 8,000
| 131,072
|
Wrong Answer
| 20
| 5,600
| 334
|
JOI decided to play a game with his friends. Her N players participate in this game. The rules for one game are as follows: Each player submits a card with a number between 1 and 100 of her choice. Each player gets the same score as the number he wrote if no one else has written the same number. If someone else wrote the same number as you, you don't get any points. JOI you guys played this game 3 times he did. Write a program that, given the number each player wrote in her 3 games, finds the total score each player got in her 3 games.
|
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
p = [0 for i in range(n)]
for i in range(3):
dic = [[] for _ in range(101)]
for j in range(n):
print(lst)
dic[lst[j][i]].append(j)
for x in range(101):
l = dic[x]
if lst:
if len(l) == 1:
p[l[0]] += x
for i in p:
print(i)
|
s013940872
|
Accepted
| 20
| 5,624
| 319
|
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
p = [0 for i in range(n)]
for i in range(3):
dic = [[] for _ in range(101)]
for j in range(n):
dic[lst[j][i]].append(j)
for x in range(101):
l = dic[x]
if lst:
if len(l) == 1:
p[l[0]] += x
for i in p:
print(i)
|
s739081942
|
p03795
|
u865413330
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 47
|
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
|
n = int(input())
print(800 * n - 200 * n // 15)
|
s852897609
|
Accepted
| 18
| 2,940
| 49
|
n = int(input())
print(800 * n - 200 * (n // 15))
|
s332284314
|
p03557
|
u519923151
| 2,000
| 262,144
|
Wrong Answer
| 2,105
| 45,440
| 516
|
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
|
n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
lal = sorted(al,reverse = True)
lbl = sorted(bl,reverse = True)
lcl = sorted(cl,reverse = True)
res =0
for i in range(n):
x = lcl[i]
for j in range(n):
y = lbl[j]
if x >y:
for k in range(n):
z = lal[k]
if y > z:
res += (n-k)
print(res,x,y,z)
break
print(res)
|
s934535819
|
Accepted
| 346
| 23,328
| 369
|
n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
lal = sorted(al)
lbl = sorted(bl)
lcl = sorted(cl)
from bisect import bisect_left, bisect_right
res = 0
for i in range(n):
bx = lbl[i]
ax = bisect_left(lal,bx)
cx = n - bisect_right(lcl,bx)
res += ax*cx
print(res)
|
s734661554
|
p03943
|
u020176853
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 194
|
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.
|
#20:48
a = list(map(int, input().split()))
lmax = max(a)
lmin = min(a)
left = int(lmax - lmin)
print(left)
if left == a[0] or left == a[1] or left == a[2]:
print("Yes")
else:
print("No")
|
s682385300
|
Accepted
| 17
| 2,940
| 117
|
a = list(map(int, input().split()))
a.sort(reverse=True)
if a[0] == a[1]+a[2]:
print("Yes")
else:
print("No")
|
s820093391
|
p03407
|
u588633699
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 81
|
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
|
A, B, C = map(int, input().split())
if A+B<=C:
print("Yes")
else:
print("No")
|
s756990341
|
Accepted
| 20
| 2,940
| 82
|
A, B, C = map(int, input().split())
if A+B>=C:
print("Yes")
else:
print("No")
|
s914201123
|
p03730
|
u961595602
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 144
|
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
|
A, B, C = map(int, input().split())
a = A % B
for i in range(1, B + 1):
if (a * i) % B == C:
print('Yes')
exit()
print('No')
|
s146245586
|
Accepted
| 17
| 2,940
| 144
|
A, B, C = map(int, input().split())
a = A % B
for i in range(1, B + 1):
if (a * i) % B == C:
print('YES')
exit()
print('NO')
|
s235870820
|
p03044
|
u528005130
| 2,000
| 1,048,576
|
Wrong Answer
| 390
| 4,720
| 257
|
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
|
# coding: utf-8
# Your code here!
N = int(input())
edges = [0] * N
for i in range(N-1):
u, v, w = map(int, input().rstrip().split(' '))
if w % 2 == 0:
edges[u-1] = 1
edges[v-1] = 1
for edge in edges:
print(edge)
|
s440486520
|
Accepted
| 873
| 45,520
| 625
|
# coding: utf-8
# Your code here!
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N-1):
u, v, w = map(int, input().rstrip().split(' '))
u = u - 1
v = v - 1
edges[u].append([v, w])
edges[v].append([u, w])
from collections import deque
temp = deque([[0, 0]])
color = [-1] * N
while len(temp) > 0:
a, b = temp.popleft()
color[a] = b
for edge in edges[a]:
if edge[1] % 2 == 1 and color[edge[0]] == -1:
temp.append([edge[0], 1 - b])
elif color[edge[0]] == -1:
temp.append([edge[0], b])
for c in color:
print(c)
|
s140781998
|
p03090
|
u706414019
| 2,000
| 1,048,576
|
Wrong Answer
| 29
| 9,532
| 432
|
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,math,collections,itertools
input = sys.stdin.readline
N=int(input())
if N%2 == 0:
for i in range(1,N):
for j in range(i+1,N+1):
if i+j == N+1:
continue
else:
print(i,j)
else:
for i in range(1,N):
for j in range(i+1,N+1):
if i + j == N:
continue
else:
print(i,j)
|
s560005519
|
Accepted
| 41
| 9,820
| 575
|
import sys,math,collections,itertools
input = sys.stdin.readline
graph = []
cnt = 0
N=int(input())
if N%2 == 0:
for i in range(1,N):
for j in range(i+1,N+1):
if i+j == N+1:
continue
else:
cnt+=1
graph.append([i,j])
else:
for i in range(1,N):
for j in range(i+1,N+1):
if i + j == N:
continue
else:
cnt+=1
graph.append([i,j])
print(cnt)
for gr in graph:
print(*gr)
|
s309377864
|
p03494
|
u100800700
| 2,000
| 262,144
|
Wrong Answer
| 20
| 2,940
| 228
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
N = input()
A = list(map(int,input().split()))
count = 0
for a in A:
count_local = 0
while a%2 == 0:
a = a/2
count_local += 1
if count_local >= count:
count = count_local
print(count)
|
s703004478
|
Accepted
| 19
| 3,064
| 228
|
c=0;N,*A=map(int,open(0).read().split())
while all(map(lambda i:i&1==0,A)):
A=list(map(lambda i:i>>1,A));c+=1
print(c)
|
s170093888
|
p03354
|
u968846084
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 39,736
| 1,526
|
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations.
|
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())
n,m=map(int,input().split())
A=UnionFind(n)
B=UnionFind(n)
P=list(map(int,input().split()))
for i in range(m):
a,b=map(int,input().split())
a=a-1
b=b-1
A.union(a,b)
B.union(P[a]-1,P[b]-1)
AA=list(A.all_group_members().values())
BB=list(B.all_group_members().values())
ans=0
for i in range(len(AA)):
ans=ans+len(AA[i])+len(BB[i])-len(set(AA[i])|set(BB[i]))
print(ans)
|
s567872629
|
Accepted
| 716
| 39,776
| 1,657
|
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())
n,m=map(int,input().split())
A=UnionFind(n)
P=list(map(int,input().split()))
for i in range(m):
a,b=map(int,input().split())
a=a-1
b=b-1
A.union(a,b)
V=[0]*n
ans=0
AA=[]
c=0
C={}
V=[0]*n
for i in range(n):
if A.parents[i]<0:
AA.append([i])
C[i]=c
c=c+1
V[i]=1
for i in range(n):
if V[i]==0:
AA[C[A.find(i)]].append(i)
for i in range(len(AA)):
B=[]
for j in range(len(AA[i])):
B.append(P[AA[i][j]]-1)
ans=ans+len(AA[i])+len(B)-len(set(AA[i])|set(B))
print(ans)
|
s306854143
|
p03502
|
u919633157
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 114
|
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
|
n=input()
fx=0
for i in n:
fx+=int(i)
print('{}:{}'.format(n,fx))
print('Yes') if int(n)%fx==0 else print('No')
|
s823936129
|
Accepted
| 17
| 2,940
| 75
|
n=int(input())
print('Yes' if n%sum([int(i) for i in str(n)])==0 else 'No')
|
s926836364
|
p03544
|
u620846115
| 2,000
| 262,144
|
Wrong Answer
| 26
| 9,056
| 75
|
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
|
n= int(input())
a,b,c = 2,1,3
for i in range(n-1):
a,b,c=b,c,b+c
print(a)
|
s028345877
|
Accepted
| 31
| 9,160
| 73
|
n= int(input())
a,b,c = 2,1,3
for i in range(n):
a,b,c=b,c,b+c
print(a)
|
s163474444
|
p03486
|
u336564899
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 196
|
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
S = list(input())
T = list(input())
S.sort(reverse=False)
T.sort(reverse=True)
S_str = "".join(S)
T_str = "".join(T)
print(S)
print(T)
if S_str < T_str:
print("Yes")
else:
print("No")
|
s505692850
|
Accepted
| 17
| 3,064
| 177
|
S = list(input())
T = list(input())
S.sort(reverse=False)
T.sort(reverse=True)
S_str = "".join(S)
T_str = "".join(T)
if S_str < T_str:
print("Yes")
else:
print("No")
|
s110936323
|
p03471
|
u086624329
| 2,000
| 262,144
|
Wrong Answer
| 26
| 3,060
| 395
|
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
|
n,y=map(int,input().split())
for s in range(y//10000):
for t in range(y//5000):
for u in range(y//1000):
if 10000*s+5000*t+1000*u==y:
print(s,t,u)
break
else:
continue
break
else:
continue
break
else:
continue
break
|
s299954909
|
Accepted
| 856
| 3,188
| 384
|
n,y=map(int,input().split())
ans=0
for i in range(y//10000,-1,-1):
nokori=(y-i*10000)
for j in range(min(n-i,nokori//5000),-1,-1):
nokori2=nokori-j*5000
if 10000*i+5000*j+1000*(n-i-j)==y:
print(i,j,n-i-j)
ans=1
break
else:
continue
break
if ans==0:
print(-1,-1,-1)
|
s308394105
|
p03380
|
u932868243
| 2,000
| 262,144
|
Wrong Answer
| 76
| 14,060
| 154
|
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
|
n=int(input())
l=list(map(int,input().split()))
m=max(l)
if m%2!=0:
med=(m+1)//2
else:
med=m//2
mi=m
for ll in l:
mi=min(mi,abs(ll-med))
print(m,mi)
|
s057290824
|
Accepted
| 76
| 14,052
| 212
|
n=int(input())
l=list(map(int,input().split()))
m=max(l)
l.remove(m)
if m%2!=0:
med=(m+1)//2
else:
med=m//2
mi=m
for ll in l:
mi=min(mi,abs(ll-med))
if med+mi in l:
print(m,med+mi)
else:
print(m,med-mi)
|
s813238448
|
p04030
|
u052332717
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 222
|
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?
|
li = list(input())
string = ''
for item in li:
if item == '0':
string += '0'
elif item == '1':
string += '1'
else:
string = string[:0]
print(string)
|
s159914204
|
Accepted
| 19
| 2,940
| 185
|
s = input()
ans = ''
for i in s:
if i == '1':
ans += '1'
if i == '0':
ans += '0'
if i == 'B':
if len(ans)>0:
ans = ans[:-1]
print(ans)
|
s042541364
|
p03816
|
u761989513
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 21,964
| 406
|
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
|
import collections
from operator import itemgetter
n = int(input())
a = sorted(list(map(int, input().split())))
ac = collections.Counter(a).most_common()
ac = sorted(ac, key=itemgetter(0))
nokori = 0
for i in ac:
if i[1] > 3:
a = a[:nokori] + a[i[1] - 1 + nokori:]
nokori += 1
else:
use = i[1]
a = a[:nokori] + a[use - 1 + nokori:]
nokori += 1
print(len(a))
|
s684211970
|
Accepted
| 46
| 14,564
| 89
|
n = int(input())
a = list(map(int, input().split()))
b = len(set(a))
print(b - 1 + b % 2)
|
s318470002
|
p03545
|
u608726540
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 545
|
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
|
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
for i in range(-1,2,2):
for j in range(-1,2,2):
for k in range(-1,2,2):
if i ==-1:
a_b='-'
else:
a_b='+'
if j ==-1:
b_c='-'
else:
b_c='+'
if k==-1:
c_d='-'
else:
c_d='+'
t=a+i*b+j*c+k*d
if t==7:
print(str(a)+a_b+str(b)+b_c+str(c)+c_d+str(d)+'==7')
break
|
s624121555
|
Accepted
| 17
| 3,064
| 485
|
s=input()
op_cnt=len(s)-1
for i in range(2**op_cnt):
t=int(s[0])
op=['-']*op_cnt
for j in range(op_cnt):
ans=''
if (i>>j &1):
op[op_cnt-1-j]='+'
for k in range(op_cnt):
if op[k]=='-':
t-=int(s[k+1])
else:
t+=int(s[k+1])
if t==7:
for l in range(op_cnt):
ans+=s[l]+op[l]
ans+=s[op_cnt]
print(ans+'=7')
break
|
s323252975
|
p02613
|
u805852597
| 2,000
| 1,048,576
|
Wrong Answer
| 166
| 9,224
| 305
|
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):
s = str(input())
if s == 'AC':
ac += 1
if s == 'WA':
wa += 1
if s == 'TLE':
tle += 1
if s == 'RE':
re += 1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',ac)
|
s533805912
|
Accepted
| 164
| 9,200
| 305
|
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
s = str(input())
if s == 'AC':
ac += 1
if s == 'WA':
wa += 1
if s == 'TLE':
tle += 1
if s == 'RE':
re += 1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)
|
s726678715
|
p03433
|
u086856505
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 89
|
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')
|
s785116414
|
Accepted
| 18
| 2,940
| 89
|
N = int(input())
A = int(input())
if N % 500 <= A:
print('Yes')
else:
print('No')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.