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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s097923207
|
p02854
|
u858670323
| 2,000
| 1,048,576
|
Wrong Answer
| 163
| 26,396
| 416
|
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
|
N = int(input())
A = list(map(int,input().split()))
def func(A):
A_inf = 0
A_sup = 0
L = sum(A)
for a in A:
if A_inf + a <= L/2:
A_inf += a
A_sup += a
if A_sup <= L/2 and A_sup + a > L/2:
A_sup += a
if A_inf == A_sup:
return 0
x = sum(A) - 2*A_sup
y = 2*A_sup - sum(A)
result = min(x,y)
return result
print(func(A))
|
s072426198
|
Accepted
| 117
| 26,220
| 695
|
N = int(input())
A = list(map(int,input().split()))
def func(A):
A_inf = 0
A_sup = 0
N_inf = 0
N_sup = 0
L = sum(A)
for a in A:
if A_inf <= L/2 - a:
A_inf += a
A_sup += a
N_inf += 1
N_sup += 1
continue
else:
if A_sup <= L/2 and A_sup + a > L/2:
A_sup += a
N_sup += 1
break
if A_inf == A_sup:
return 0
A_mid = A_sup - A_inf
A_left = L/2 - A_inf
A_right = A_sup - L/2
A_lrmin = min(A_left, A_right)
if A_mid-1 >= 2*A_lrmin:
return int(2*A_lrmin)
else:
return int(A_mid)
print(func(A))
|
s842446502
|
p02646
|
u224119985
| 2,000
| 1,048,576
|
Wrong Answer
| 2,205
| 9,204
| 343
|
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())
ans="No"
if v<=w:
ans="No"
else:
for i in range(1,t+1):
if a<b:
a=a+v
b=b+w
if a==b:
ans="Yes"
else:
a=a-v
b=b-v
if a==b:
ans="Yes"
print(ans)
|
s494041708
|
Accepted
| 23
| 9,224
| 464
|
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
ans="NO"
if v<=w:
ans="NO"
else:
if a>b:
if (a-b)%(v-w)==0:
if (a-b)//(v-w)<=t:
ans="YES"
else:
if (a-b)//(v-w)+1<=t:
ans="YES"
elif a<b:
if (a-b)%(v-w)==0:
if (b-a)//(v-w)<=t:
ans="YES"
else:
if (b-a)//(v-w)+1<=t:
ans="YES"
print(ans)
|
s822937225
|
p03433
|
u889989259
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,156
| 185
|
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())
b = 0
while True:
if (500*b + a) > n:
print("NO")
break
if (500*b + a) - n == 0:
print("YES")
break
b+=1
|
s307151187
|
Accepted
| 32
| 9,132
| 256
|
import sys
n = int(input())
a = int(input())
b = 0
while True:
c = 0
if (500*b + c) > n:
print("No")
break
for i in range(a+1):
if (500*b + c) == n:
print("Yes")
sys.exit(0)
c+=1
b+=1
|
s662404207
|
p03469
|
u294394140
| 2,000
| 262,144
|
Wrong Answer
| 28
| 8,984
| 37
|
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 = list(input())
s[3] = "8"
print(s)
|
s553334915
|
Accepted
| 35
| 9,028
| 33
|
s = input()
print("2018" + s[4:])
|
s504187820
|
p03854
|
u575431498
| 2,000
| 262,144
|
Wrong Answer
| 206
| 3,956
| 333
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
S = input()
dp = [False] * (len(S) + 1)
dp[0] = True
T = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(1, len(S) + 1):
tmp = []
for t in T:
if i < len(t):
continue
tmp.append(dp[i-len(t)] and t == S[i-len(t): i])
if any(tmp):
dp[i] = True
print('Yes' if dp[len(S)] else 'No')
|
s283811254
|
Accepted
| 220
| 3,956
| 333
|
S = input()
dp = [False] * (len(S) + 1)
dp[0] = True
T = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(1, len(S) + 1):
tmp = []
for t in T:
if i < len(t):
continue
tmp.append(dp[i-len(t)] and t == S[i-len(t): i])
if any(tmp):
dp[i] = True
print('YES' if dp[len(S)] else 'NO')
|
s278261198
|
p03543
|
u974935538
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 132
|
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
|
from itertools import*
A,B,C,D=input()
for i,j,k in product(["+","-"],repeat=3):
s=A+i+B+j+C+k+D
if eval(s)==7:print(s+"=7");break
|
s618571125
|
Accepted
| 17
| 2,940
| 141
|
s = str(input())
li = list(map(int, s))
if (li[0]==li[1]&li[1]==li[2])or(li[1] == li[2]&li[2]==li[3]):
print("Yes")
else:
print("No")
|
s353482841
|
p02390
|
u405411271
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,568
| 97
|
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
|
s = int(input())
sec = s % 60
min = s // 60 # may be more than 60
hr = min // 60
min = min % 60
|
s026375513
|
Accepted
| 20
| 5,584
| 117
|
s = int(input())
sec = s%60
min = s//60 # may be more than 60
hr = min//60
min = min%60
print(hr, min, sec, sep=':')
|
s636653808
|
p02255
|
u589886885
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,588
| 232
|
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
n = int(input())
ary = [int(x) for x in input().split(' ')]
print(ary)
for i in range(1, n):
v = ary[i]
j = i - 1
while j >= 0 and ary[j] > v:
ary[j + 1] = ary[j]
j -= 1
ary[j + 1] = v
print(ary)
|
s405443583
|
Accepted
| 20
| 7,688
| 250
|
n = int(input())
a = input()
print(a)
a = [int(x) for x in a.split(' ')]
for i in range(1, n):
v = a[i]
j = i - 1
while j >= 0 and a[j] > v:
a[j + 1] = a[j]
j -= 1
a[j + 1] = v
print(' '.join([str(x) for x in a]))
|
s071003459
|
p03377
|
u168416324
| 2,000
| 262,144
|
Wrong Answer
| 28
| 8,980
| 85
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a,b,x=map(int,input().split())
if a<=x and a+b>=x:
print("Yes")
else:
print("No")
|
s496467790
|
Accepted
| 28
| 9,144
| 86
|
a,b,x=map(int,input().split())
if a<=x and a+b>=x:
print("YES")
else:
print("NO")
|
s489003913
|
p03556
|
u102960641
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 37
|
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
|
n = int(input())
print(int(n ** 0.5))
|
s375539093
|
Accepted
| 17
| 2,940
| 57
|
import math
n = int(input())
print(int(math.sqrt(n))**2)
|
s570567733
|
p03730
|
u174273188
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 199
|
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`.
|
def solve():
a, b, c = map(int, input().split())
for i in range(1, b + 1):
if a * i % b == c:
return "Yes"
return "No"
if __name__ == "__main__":
print(solve())
|
s661902922
|
Accepted
| 17
| 2,940
| 201
|
def solve():
a, b, c = map(int, input().split())
for i in range(1, b + 1):
if (a * i) % b == c:
return "YES"
return "NO"
if __name__ == "__main__":
print(solve())
|
s926793288
|
p02866
|
u686230543
| 2,000
| 1,048,576
|
Wrong Answer
| 133
| 14,396
| 493
|
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition: * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.
|
n = int(input())
d_list = list(map(int, input().split()))
divider = 998244353
if d_list[0] != 0:
print(0)
else:
d_sort = sorted(d_list)
d = 1
pre_c = 1
cur_c = 0
count = 1
for i in range(1, n):
if d_sort[i] == d:
cur_c += 1
elif d_sort[i] == d + 1:
count *= pre_c ** cur_c
count %= divider
d += 1
pre_c = cur_c
cur_c = 0
else:
count = 0
cur_c = 0
break
count *= pre_c ** cur_c
count %= divider
print(count)
|
s281611641
|
Accepted
| 147
| 14,020
| 493
|
n = int(input())
d_list = list(map(int, input().split()))
divider = 998244353
if d_list[0] != 0:
print(0)
else:
d_sort = sorted(d_list)
d = 1
pre_c = 1
cur_c = 0
count = 1
for i in range(1, n):
if d_sort[i] == d:
cur_c += 1
elif d_sort[i] == d + 1:
count *= pre_c ** cur_c
count %= divider
d += 1
pre_c = cur_c
cur_c = 1
else:
count = 0
cur_c = 0
break
count *= pre_c ** cur_c
count %= divider
print(count)
|
s554616363
|
p03433
|
u131625544
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 92
|
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
N, A = [int(input()) for _ in range(2)]
if N % 500 == A:
print('Yes')
else:
print('No')
|
s931899058
|
Accepted
| 17
| 2,940
| 92
|
N, A = [int(input()) for _ in range(2)]
if N % 500 <= A:
print('Yes')
else:
print('No')
|
s492400056
|
p03471
|
u965230804
| 2,000
| 262,144
|
Wrong Answer
| 1,483
| 3,064
| 344
|
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.
|
import sys
[n, yen] = list(map(int, input().split()))
ans = [-1, -1, -1]
for x in range(0, yen // 10000 + 1):
for y in range(0, (yen - 10000*x)//5000 + 1):
z = (yen - 10000*x - 5000*y) // 1000
if x + y + z == n:
ans = [x, y, z]
print("{} {} {}".format(ans[0], ans[1], ans[2]))
sys.exit()
|
s525209042
|
Accepted
| 1,465
| 3,060
| 298
|
[n, yen] = list(map(int, input().split()))
ans = [-1, -1, -1]
for x in range(0, yen // 10000 + 1):
for y in range(0, (yen - 10000*x)//5000 + 1):
z = (yen - 10000*x - 5000*y) // 1000
if x + y + z == n:
ans = [x, y, z]
print("{} {} {}".format(ans[0], ans[1], ans[2]))
|
s384276414
|
p03555
|
u005469124
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 123
|
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
N = list(input())
K = list(input())
if N[0]== K[2] and N[1]==K[1] and N[2]== K[0]:
print('Yes')
else:
print('No')
|
s611165153
|
Accepted
| 17
| 2,940
| 123
|
N = list(input())
K = list(input())
if N[0]== K[2] and N[1]==K[1] and N[2]== K[0]:
print('YES')
else:
print('NO')
|
s824205464
|
p03997
|
u898651494
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 68
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h/2)
|
s289146845
|
Accepted
| 17
| 2,940
| 69
|
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h//2)
|
s397169147
|
p03090
|
u869595612
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 3,588
| 185
|
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
|
n= int(input())
s = n + (0 if n%2 == 1 else 1)
ans = []
for i in range(n-1):
for j in range(i+1,n):
if i+j+2 != s:
ans.append(str(i+1)+" "+str(j+1))
for t in ans:
print(t)
|
s224280283
|
Accepted
| 23
| 3,588
| 201
|
n= int(input())
s = n + (0 if n%2 == 1 else 1)
ans = []
for i in range(n-1):
for j in range(i+1,n):
if i+j+2 != s:
ans.append(str(i+1)+" "+str(j+1))
print(len(ans))
for t in ans:
print(t)
|
s832124757
|
p03853
|
u285443936
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 264
|
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
|
H, W = map(int, input().split())
Cij = [input().split() for i in range(H)]
Dij = []
for i in range(H ):
# a = (i + 1) // 2
Dij.append(Cij[i])
Dij.append(Cij[i])
#print(a)
print(Dij)
|
s444728527
|
Accepted
| 18
| 3,060
| 90
|
H, W = map(int, input().split())
for i in range(H):
Ci = input()
print(Ci)
print(Ci)
|
s396367748
|
p03557
|
u492447501
| 2,000
| 262,144
|
Wrong Answer
| 375
| 24,128
| 437
|
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.
|
import bisect
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort()
B.sort()
C.sort()
A_B = [0]*N
B_C = [0]*N
for i in range(N):
count = 0
index = bisect.bisect_right(A,B[i])
A_B[i] = index
for i in range(N):
count = 0
index = bisect.bisect_right(A,B[i])
B_C[i] = index
sum = 0
for i in range(N):
sum = sum + B_C[i]*A_B[i]
print(sum)
|
s396903879
|
Accepted
| 360
| 23,764
| 416
|
import bisect
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort()
B.sort()
C.sort()
A_B = [0]*N
B_C = [0]*N
for i in range(N):
index = bisect.bisect_left(A,B[i])
A_B[i] = index
for i in range(N):
index = bisect.bisect_right(C,B[i])
B_C[i] = len(C)-index
sum = 0
for i in range(N):
sum = sum + B_C[i]*A_B[i]
print(sum)
|
s682436769
|
p03386
|
u327532412
| 2,000
| 262,144
|
Wrong Answer
| 2,281
| 2,231,788
| 178
|
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())
l = B - A
if K > l:
K = l
sub = [i for i in range(A, B+1)]
ans = sub[0:K] + sub[len(sub)-K:len(sub)]
ans.sort()
print(*set(ans), sep='\n')
|
s251289418
|
Accepted
| 28
| 9,184
| 195
|
A, B, K = map(int, input().split())
if K > B-A:
ans = list(range(A, B+1))
else:
ans = list(range(A, A+K)) + list(range(B, B - K, -1))
ans = list(set(ans))
ans.sort()
print(*ans, sep='\n')
|
s716959190
|
p02866
|
u830054172
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 23,004
| 336
|
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition: * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.
|
from collections import Counter
N = int(input())
DD = list(map(int, input().split()))
D = sorted(dict(Counter(DD)).items(), key=lambda x:x[0])
ans = 0
if 1 == DD.count(0):
ans = 1
for i in range(1, len(D)-1):
print(D[i][1], D[i+1][1])
ans *= D[i][1]**D[i+1][1]
print(ans)
else:
print(ans)
|
s346208012
|
Accepted
| 130
| 19,936
| 277
|
from collections import Counter
N = int(input())
DD = list(map(int, input().split()))
D = Counter(DD)
if DD[0] != 0:
print(0)
elif D[0] != 1:
print(0)
else:
ans = 1
for i in range(len(D)-1):
ans *= D[i]**D[i+1]
ans %= 998244353
print(ans)
|
s417023367
|
p03957
|
u676029460
| 1,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 177
|
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtained from the string s by deleting some characters.
|
s = input()
c = False
f = False
for i in s:
if i == 'c':
c = True
if c == True and i == 'f':
f = True
if c & f:
print("Yes")
else :
print("No")
|
s730711444
|
Accepted
| 17
| 2,940
| 197
|
s = input()
c = False
f = False
for i in range(len(s)):
if s[i] == 'C':
c = True
if c == True and s[i] == 'F':
f = True
if c and f:
print("Yes")
else :
print("No")
|
s520571846
|
p03371
|
u170324846
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 90
|
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
|
A, B, C, X, Y = map(int, input().split())
C * 2 * min(X,Y) + max(A * (X - Y), B * (Y - X))
|
s802745718
|
Accepted
| 18
| 3,060
| 135
|
A, B, C, X, Y = map(int, input().split())
print(min(A * X + B * Y, C * 2 * max(X,Y), C * 2 * min(X,Y) + max(A * (X - Y), B * (Y - X))))
|
s215919105
|
p03408
|
u577942884
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 198
|
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
|
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
c = 0
maxl = 0
for i in set(s):
c = s.count(i) - t.count(i)
max1 = max(maxl, c)
print(maxl)
|
s096965868
|
Accepted
| 17
| 3,064
| 198
|
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
c = 0
maxl = 0
for i in set(s):
c = s.count(i) - t.count(i)
maxl = max(maxl, c)
print(maxl)
|
s785091870
|
p03472
|
u590211278
| 2,000
| 262,144
|
Wrong Answer
| 1,828
| 11,392
| 494
|
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
|
import math
n, h = map(int,input().split())
a=[]
b=[]
for i in range(n):
ta, tb = map(int,input().split())
a.append(ta)
b.append(tb)
maxa=max(a)
b.append(maxa)
b.sort()
b.reverse()
damage=0
cnt=0
while(h>damage):
if b[0]>maxa:
damage+=b[0]
del b[0]
cnt+=1
else:
cnt=cnt+int((h-damage)/b[0])
#print(cnt,damage)
damage+=b[0]*((h-damage)/b[0])
if h>damage:
cnt+=1
damage+=b[0]
print(cnt)
|
s281354001
|
Accepted
| 1,838
| 11,264
| 497
|
import math
n, h = map(int,input().split())
a=[]
b=[]
for i in range(n):
ta, tb = map(int,input().split())
a.append(ta)
b.append(tb)
maxa=max(a)
b.append(maxa)
b.sort()
b.reverse()
damage=0
cnt=0
while(h>damage):
if b[0]>maxa:
damage+=b[0]
del b[0]
cnt+=1
else:
cnt=cnt+int((h-damage)/b[0])
#print(cnt,damage)
damage+=b[0]*int((h-damage)/b[0])
if h>damage:
cnt+=1
damage+=b[0]
print(cnt)
|
s138307832
|
p02255
|
u757519851
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,720
| 313
|
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
#!/usr/bin/env python
def InsertSort(N,A):
for i in range(1,N):
v=A[i]
j=i-1
while j>=0 and A[j]>v:
A[j+1]=A[j]
j-=1
A[j+1]=v
print(*A)
if __name__ == "__main__":
N=int(input())
arr=list(map(int,input().split()))
InsertSort(N,arr)
|
s745342437
|
Accepted
| 40
| 6,752
| 329
|
#!/usr/bin/env python
def InsertSort(N,A):
for i in range(1,N):
v=A[i]
j=i-1
while j>=0 and A[j]>v:
A[j+1]=A[j]
j-=1
A[j+1]=v
print(*A)
if __name__ == "__main__":
N=int(input())
arr=list(map(int,input().split()))
print(*arr)
InsertSort(N,arr)
|
s764044860
|
p03047
|
u864650257
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 41
|
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
|
N,K= map(int, input().split())
print(N-K)
|
s582640720
|
Accepted
| 17
| 2,940
| 44
|
N,K= map(int, input().split())
print(N-K +1)
|
s593048995
|
p02742
|
u204260373
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 84
|
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:
|
H,W=map(int,input().split())
if (H*W)%2==0:
print((H*W)/2)
else:
print(H+W+1)
|
s978124294
|
Accepted
| 17
| 2,940
| 102
|
import math
H,W=map(int,input().split())
if H==1 or W==1:
print(1)
else:
print(math.ceil((H*W)/2))
|
s850171723
|
p03693
|
u166560497
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 183
|
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
three = list(map(int, input().split()))
r = three[0]
g = three[1]
b = three[2]
g = str(g)
b = str(b)
gb = g + b
gb = int(gb)
if gb%4 ==0:
print('Yes')
else:
print('No')
|
s861574116
|
Accepted
| 17
| 3,060
| 178
|
three = list(map(int, input().split()))
r = three[0]
g = three[1]
b = three[2]
g = str(g)
b = str(b)
gb = g + b
gb = int(gb)
if gb%4 ==0:
print('YES')
else:
print('NO')
|
s621413497
|
p02249
|
u318430977
| 3,000
| 262,144
|
Wrong Answer
| 20
| 5,556
| 653
|
Find places where a R × C pattern is found within a H × W region. Print top- left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
|
def rabin_karp(T, P, d):
n = len(T)
m = len(P)
if n < m:
return
h = 1
p = 0
t0 = 0
for _ in range(m - 1):
h *= d
for i in range(m):
p = d * p + P[i]
t0 = d * t0 + T[i]
# print("h = ", h)
# print("p = ", p)
for s in range(n - m + 1):
# print("t0 = ", t0)
if p == t0:
print(s)
if s < n - m:
# print(" ", t0 - T[s] * h)
# print(" ", d)
# print(" ", T[s + m])
t0 = d * (t0 - T[s] * h) + T[s + m]
d = 1009
t = list(map(ord, input()))
p = list(map(ord, input()))
rabin_karp(t, p, d)
|
s401390918
|
Accepted
| 1,890
| 94,708
| 1,300
|
base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calculate_hash(f, r, c):
global ph, pw, h
tmp = [[0 for _ in range(c)] for _ in range(r)]
dr, dc = r - ph, c - pw
t1 = 1
for _ in range(pw):
t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in range(pw):
e = e * base1 + f[i][j]
for j in range(dc):
tmp[i][j] = e
e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
tmp[i][dc] = e
t2 = 1
for _ in range(ph):
t2 = (t2 * base2) & mask
for j in range(dc + 1):
e = 0
for i in range(ph):
e = e * base2 + tmp[i][j]
for i in range(dr):
h[i][j] = e
e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
h[dr][j] = e
th, tw = map(int, input().split())
t = [[ord(x) for x in input().strip()] for _ in range(th)]
ph, pw = map(int, input().split())
p = [[ord(x) for x in input().strip()] for _ in range(ph)]
if th >= ph and tw >= pw:
h = [[0 for _ in range(tw)] for _ in range(th)]
calculate_hash(p, ph, pw)
key = h[0][0] & mask
calculate_hash(t, th, tw)
for i in range(th - ph + 1):
for j in range(tw - pw + 1):
if h[i][j] & mask == key:
print(i, j)
|
s397783862
|
p03050
|
u677121387
| 2,000
| 1,048,576
|
Wrong Answer
| 263
| 9,316
| 114
|
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
|
n = int(input())
ans = 0
for i in range(1,int(n**0.5)):
m,r = divmod(n-i,i)
if r == 0: ans += m
print(ans)
|
s588632882
|
Accepted
| 128
| 9,416
| 318
|
def divisor(n):
fac = []
for i in range(1,int(n**0.5)+1):
if n%i == 0:
fac.append(i)
if i*i != n: fac.append(n//i)
return sorted(fac)
n = int(input())
ans = 0
for i in divisor(n):
if i == 1: continue
m = i-1
p,r = divmod(n,m)
if p == r: ans += m
print(ans)
|
s373506153
|
p00292
|
u546285759
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,576
| 94
|
K 個の石から、P 人が順番に1つずつ石を取るゲームがあります。P 人目が石を取った時点で、まだ石が残っていれば、また1人目から順番に1つずつ石を取っていきます。このゲームでは、最後の石を取った人が勝ちとなります。K とP が与えられたとき、何人目が勝つか判定するプログラムを作成してください。
|
for _ in range(int(input())):
k, p= map(int, input().split())
print(p if k%p else k%p)
|
s231772358
|
Accepted
| 30
| 7,712
| 127
|
n = int(input())
for _ in range(n):
K, P = map(int, input().split())
a = K % P
print(P * (a == 0) + (a) * (a != 0))
|
s159070341
|
p03417
|
u347640436
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 234
|
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
|
n, m = map(int, input().split())
if n > m:
n, m = m, n
if n == 1:
if m == 1:
print(1)
elif m == 2:
print(0)
else:
print(m - 2)
elif n == 2:
print(0)
else:
print((n - 2) * (m - 2))
print(abs(n -2) * abs(m - 2))
|
s170838091
|
Accepted
| 17
| 3,060
| 203
|
n, m = map(int, input().split())
if n > m:
n, m = m, n
if n == 1:
if m == 1:
print(1)
elif m == 2:
print(0)
else:
print(m - 2)
elif n == 2:
print(0)
else:
print((n - 2) *(m - 2))
|
s954977128
|
p02613
|
u257472411
| 2,000
| 1,048,576
|
Wrong Answer
| 56
| 14,612
| 554
|
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
import sys
input = sys.stdin.buffer.readline
def main():
n = int(input())
s = [input() for i in range(n)]
ac = 0
wa = 0
tle = 0
re = 0
for i in range(len(s)):
if s[i] == "AC":
ac += 1
elif s[i] == "WA":
wa += 1
elif s[i] == "TLE":
tle += 1
else:
re += 1
print("AC x {}".format(str(ac)))
print("WA x {}".format(str(wa)))
print("TLE x {}".format(str(tle)))
print("RE x {}".format(str(re)))
if __name__ == '__main__':
main()
|
s334897033
|
Accepted
| 141
| 16,296
| 810
|
# import sys
def main():
n = int(input())
s = [input() for i in range(n)]
ac = 0
wa = 0
tle = 0
re = 0
for e in s:
if e == "AC":
ac += 1
elif e == "WA":
wa += 1
elif e == "TLE":
tle += 1
else:
re += 1
# if s[i].strip().decode() == "AC":
# ac += 1
# elif s[i].strip().decode() == "WA":
# elif s[i].strip().decode() == "TLE":
# tle += 1
# else:
# re += 1
print("AC x {}".format(str(ac)))
print("WA x {}".format(str(wa)))
print("TLE x {}".format(str(tle)))
print("RE x {}".format(str(re)))
if __name__ == '__main__':
main()
|
s619512706
|
p03943
|
u340781749
| 2,000
| 262,144
|
Wrong Answer
| 23
| 3,188
| 101
|
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
candies = list(map(int, input().split()))
print('yes' if max(candies) * 2 == sum(candies) else 'no')
|
s213206812
|
Accepted
| 22
| 3,064
| 101
|
candies = list(map(int, input().split()))
print('Yes' if max(candies) * 2 == sum(candies) else 'No')
|
s128623694
|
p03455
|
u271077566
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 89
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
a, b = map(int, input().split())
if a*b%2 == 0:
print('even')
else:
print('odd')
|
s776899716
|
Accepted
| 17
| 2,940
| 90
|
a, b = map(int, input().split())
if (a*b)%2 == 0:
print('Even')
else:
print('Odd')
|
s884056559
|
p03023
|
u777215291
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 33
|
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
|
N = int(input())
print(180*(N-1))
|
s556078759
|
Accepted
| 17
| 2,940
| 33
|
N = int(input())
print(180*(N-2))
|
s501408366
|
p03962
|
u045408189
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 28
|
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
|
n=input()
print(len(set(n)))
|
s039700645
|
Accepted
| 17
| 2,940
| 37
|
n=input().split()
print(len(set(n)))
|
s167490665
|
p02928
|
u758411830
| 2,000
| 1,048,576
|
Wrong Answer
| 546
| 3,188
| 349
|
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
# count inv in A
cnt = 0
for i in range(N):
for j in range(i, N):
if A[i] > A[j]:
cnt += 1
cmb_cnt = 0
for a in A:
cmb_cnt += len([x for x in A if x < a])
kC2 = (K*(K-1))//2
ans = (cnt*K)+(cmb_cnt*kC2)
print(cnt)
print(cmb_cnt)
print(ans%(10**9+7))
|
s622068814
|
Accepted
| 575
| 3,188
| 306
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
for j in range(i, N):
if A[i] > A[j]:
cnt += 1
cmb_cnt = 0
for a in A:
cmb_cnt += len([x for x in A if x < a])
kC2 = (K*(K-1))//2
ans = (cnt*K)+(cmb_cnt*kC2)
print(ans%(10**9+7))
|
s995290152
|
p03502
|
u508405635
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,316
| 168
|
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
|
N = int(input())
def f(X):
return sum(list(map(int, str(X))))
print(f(N))
if N % f(N) == 0:
print('Yse')
else:
print('No')
|
s877310068
|
Accepted
| 19
| 3,316
| 156
|
N = int(input())
def f(X):
return sum(list(map(int, str(X))))
if N % f(N) == 0:
print('Yes')
else:
print('No')
|
s635850567
|
p03067
|
u165233868
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 103
|
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
|
A, B, C = map(int, input().split())
ans = 'Yes' if C in range(min(A, B), abs(B-A)) else 'No'
print(ans)
|
s214095273
|
Accepted
| 17
| 2,940
| 111
|
A, B, C = map(int, input().split())
ans = ''
if A<C<B or B<C<A:
ans = 'Yes'
else:
ans = 'No'
print(ans)
|
s396951349
|
p03962
|
u842388336
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 30
|
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
|
print(len(set(list(input()))))
|
s919913000
|
Accepted
| 17
| 2,940
| 38
|
print(len(set(list(input().split()))))
|
s517366324
|
p03493
|
u490623664
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 79
|
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
a=input()
c=0
if a[0]==1:
c+=1
if a[1]==1:
c+=1
if a[2]==1:
c+=1
print(c)
|
s663326234
|
Accepted
| 17
| 2,940
| 85
|
a=input()
c=0
if a[0]=="1":
c+=1
if a[1]=="1":
c+=1
if a[2]=="1":
c+=1
print(c)
|
s733732193
|
p03505
|
u340781749
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 196
|
_ButCoder Inc._ runs a programming competition site called _ButCoder_. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rating is 0, and a user whose rating reaches K or higher is called _Kaiden_ ("total transmission"). Note that a user's rating may become negative. Hikuhashi is a new user in ButCoder. It is estimated that, his rating increases by A in each of his odd-numbered contests (first, third, fifth, ...), and decreases by B in each of his even-numbered contests (second, fourth, sixth, ...). According to this estimate, after how many contests will he become Kaiden for the first time, or will he never become Kaiden?
|
from math import ceil
def solve(k, a, b):
if k <= a:
return 1
if a <= b:
return -1
return ceil((k - a) // (a - b)) * 2 + 1
print(solve(*map(int, input().split())))
|
s237626735
|
Accepted
| 57
| 5,844
| 265
|
import decimal
from math import ceil
def solve(k, a, b):
if k <= a:
return 1
if a <= b:
return -1
ka = decimal.Decimal(k - a)
ab = decimal.Decimal(a - b)
return ceil(ka / ab) * 2 + 1
print(solve(*map(int, input().split())))
|
s876011543
|
p03471
|
u610950638
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 3,060
| 322
|
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.
|
inn = [int(x) for x in input().split()]
xx = inn[1] // 10000
ans = [-1, -1, -1]
for x in range(xx):
rem = inn[1] - 10000*x
yy = rem // 1000
for y in range(yy):
z = (rem - 5000*y) // 1000
if x+y+z == inn[0]:
ans = [x, y, z]
break
print(' '.join([str(x) for x in ans]))
|
s338008633
|
Accepted
| 1,313
| 3,060
| 375
|
inn = [int(x) for x in input().split()]
xx = inn[1] // 10000
ans = [-1, -1, -1]
if xx <= inn[1]:
for x in range(xx+1):
rem = inn[1] - 10000*x
yy = rem // 5000
for y in range(yy+1):
z = (rem - 5000*y) // 1000
if x+y+z == inn[0]:
ans = [x, y, z]
break
print(' '.join([str(x) for x in ans]))
|
s366987038
|
p00005
|
u806182843
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,576
| 181
|
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
|
def main():
import sys
for line in sys.stdin:
a, b = map(int, line.split())
c = a*b
while a % b != 0:
a, b = b, a%b
print(b, c*b)
if __name__ == '__main__':
main()
|
s946519215
|
Accepted
| 20
| 7,708
| 182
|
def main():
import sys
for line in sys.stdin:
a, b = map(int, line.split())
c = a*b
while a % b != 0:
a, b = b, a%b
print(b, c//b)
if __name__ == '__main__':
main()
|
s661913098
|
p03711
|
u618373524
| 2,000
| 262,144
|
Wrong Answer
| 20
| 2,940
| 163
|
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())
list_a = [1,3,5,7,8,10,12]
list_b = [4,6,9,11]
print("YES" if x in list_a and y in list_b or x in list_b and y in list_b else "NO")
|
s977634946
|
Accepted
| 17
| 3,060
| 166
|
x,y = map(int,input().split())
list_a = [1,3,5,7,8,10,12]
list_b = [4,6,9,11]
print("Yes" if (x in list_a and y in list_a) or (x in list_b and y in list_b) else "No")
|
s892427856
|
p03549
|
u836737505
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 24
|
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).
|
print("わかんねぇ")
|
s922036150
|
Accepted
| 17
| 2,940
| 64
|
n,m = map(int, input().split())
print((2**m)*(1900*m+100*(n-m)))
|
s525499454
|
p03777
|
u456950583
| 2,000
| 262,144
|
Wrong Answer
| 16
| 2,940
| 216
|
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.
|
#!/usr/bin/env python
a, b = input().split()
if a == "H" and b == "D":
print("H")
elif a == "D" and b == "H":
print("D")
elif a == "H" and b == "D":
print("D")
elif a == "D" and b == "D":
print("H")
|
s875116471
|
Accepted
| 17
| 2,940
| 216
|
#!/usr/bin/env python
a, b = input().split()
if a == "H" and b == "H":
print("H")
elif a == "D" and b == "H":
print("D")
elif a == "H" and b == "D":
print("D")
elif a == "D" and b == "D":
print("H")
|
s451720243
|
p02690
|
u190406011
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 9,108
| 311
|
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
|
x = int(input())
k = 1
while True:
if k ** 5 - (k-1) ** 5 > x:
break
k += 1
print(k)
for a in range(k):
amari = x - a ** 5
for b in range(a+1):
if amari == b ** 5:
print(a, -b)
break
if amari == (-b) ** 5:
print(a, b)
break
|
s736305376
|
Accepted
| 24
| 9,112
| 302
|
x = int(input())
k = 1
while True:
if k ** 5 - (k-1) ** 5 > x:
break
k += 1
for a in range(k):
amari = x - a ** 5
for b in range(a+1):
if amari == b ** 5:
print(a, -b)
break
if amari == (-b) ** 5:
print(a, b)
break
|
s594740942
|
p03997
|
u098569005
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 67
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h/2)
|
s134858449
|
Accepted
| 17
| 2,940
| 85
|
a = int(input())
b = int(input())
h = int(input())
S = (a+b)*h/2
S = int(S)
print(S)
|
s790229984
|
p02972
|
u475675023
| 2,000
| 1,048,576
|
Wrong Answer
| 214
| 19,148
| 158
|
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
|
n,*a=map(int,open(0).read().split())
b=[0]*n
for i in range(1,n+1)[::-1]:
if not sum(b[i-1::i])%2==a[i-1]:
b[i-1]=1
print(n)
print(' '.join(map(str,b)))
|
s208123590
|
Accepted
| 243
| 13,056
| 185
|
n,*a=map(int,open(0).read().split())
b=[0]*n
for i in range(1,n+1)[::-1]:
if not sum(b[i-1::i])%2==a[i-1]:
b[i-1]=1
print(sum(b))
print(*[i+1 for i,b_i in enumerate(b) if b_i==1])
|
s970607289
|
p02613
|
u454093752
| 2,000
| 1,048,576
|
Wrong Answer
| 148
| 9,176
| 168
|
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.
|
T = {"AC":0, "WA":0, "TLE":0, "RE":0}
N = int(input())
for i in range(N):
s = input()
T[s] += 1
for i, j in T.items():
print("{0} × {1}".format(i ,j))
|
s098650541
|
Accepted
| 142
| 9,148
| 163
|
T = {"AC":0, "WA":0, "TLE":0, "RE":0}
N = int(input())
for i in range(N):
s = input()
T[s] += 1
for i, j in T.items():
print("{0} x {1}".format(i ,j))
|
s571922872
|
p02613
|
u658627575
| 2,000
| 1,048,576
|
Wrong Answer
| 147
| 9,124
| 444
|
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.
|
judge = {'AC' : 0, 'WA' : 0, 'TLE' : 0, 'RE' : 0}
N = int(input())
for i in range(N):
testcase = input()
if testcase == 'AC':
judge['AC'] += 1
elif testcase == 'WA':
judge['WA'] += 1
elif testcase == 'TLE':
judge['TLE'] += 1
else:
judge['RE'] += 1
print('AC × ' + str(judge['AC']))
print('WA × ' + str(judge['WA']))
print('TLE × ' + str(judge['TLE']))
print('RE × ' + str(judge['RE']))
|
s431145380
|
Accepted
| 145
| 9,128
| 440
|
judge = {'AC' : 0, 'WA' : 0, 'TLE' : 0, 'RE' : 0}
N = int(input())
for i in range(N):
testcase = input()
if testcase == 'AC':
judge['AC'] += 1
elif testcase == 'WA':
judge['WA'] += 1
elif testcase == 'TLE':
judge['TLE'] += 1
else:
judge['RE'] += 1
print('AC x ' + str(judge['AC']))
print('WA x ' + str(judge['WA']))
print('TLE x ' + str(judge['TLE']))
print('RE x ' + str(judge['RE']))
|
s857291323
|
p02263
|
u825178626
| 1,000
| 131,072
|
Wrong Answer
| 30
| 8,300
| 507
|
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
|
# coding: utf-8
# Here your code !
import functools
N = input().split()
stack=[]
for i in N:
if i.isdigit():
stack.append(int(i))
else:
key=0
if i=="+":
p2=stack.pop()
p1=stack.pop()
stack.append(p1+p2)
elif i=="-":
p2=stack.pop()
p1=stack.pop()
stack.append(p1-p2)
elif i=="*":
p2=stack.pop()
p1=stack.pop()
stack.append(p1*p2)
print(stack)
|
s763215585
|
Accepted
| 30
| 8,292
| 510
|
# coding: utf-8
# Here your code !
import functools
N = input().split()
stack=[]
for i in N:
if i.isdigit():
stack.append(int(i))
else:
key=0
if i=="+":
p2=stack.pop()
p1=stack.pop()
stack.append(p1+p2)
elif i=="-":
p2=stack.pop()
p1=stack.pop()
stack.append(p1-p2)
elif i=="*":
p2=stack.pop()
p1=stack.pop()
stack.append(p1*p2)
print(stack[0])
|
s173335213
|
p02255
|
u928491417
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,588
| 305
|
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
num = int(input())
array = list(map(int, input().split()))
# insertion sort
for i in range(num):
insert = array[i]
j = 0
while array[j] < insert:
j+=1
for k in range(i, j, -1):
array[k] = array[k - 1]
array[j] = insert
print(array)
|
s526005471
|
Accepted
| 30
| 5,984
| 454
|
num = int(input())
array = list(map(int, input().split()))
def print_array():
for i in range(num):
if i != num-1:
print(array[i], end=' ')
else:
print(array[i])
# insertion sort
for i in range(num):
insert = array[i]
j = 0
while array[j] < insert:
j+=1
for k in range(i, j, -1):
array[k] = array[k - 1]
array[j] = insert
print_array()
|
s122528333
|
p02431
|
u548252256
| 1,000
| 262,144
|
Wrong Answer
| 20
| 6,000
| 329
|
For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * pushBack($x$): add element $x$ at the end of $A$ * randomAccess($p$):print element $a_p$ * popBack(): delete the last element of $A$ $A$ is a 0-origin array and it is empty in the initial state.
|
from sys import stdin
from collections import deque
num = int(input())
q = deque()
for i in range(num):
cmd = stdin.readline().strip().split()
if cmd[0] == "0":
q.append(cmd[1])
elif cmd[0] == "1":
print(q[int(cmd[1])])
else:
q.pop()
print(*q,sep='\n')
|
s346804512
|
Accepted
| 510
| 20,172
| 318
|
from sys import stdin
from collections import deque
num = int(input())
q = deque()
for i in range(num):
cmd = stdin.readline().strip().split()
if cmd[0] == "0":
q.append(cmd[1])
elif cmd[0] == "1":
print(q[int(cmd[1])],sep='\n')
else:
q.pop()
|
s120015863
|
p03816
|
u317044805
| 2,000
| 262,144
|
Wrong Answer
| 46
| 14,396
| 408
|
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.
|
# -*- coding: utf-8 -*-
nb_int = int(input())
A = list(map(int, input().split(" ")))
uniq_A = list(set(A))
if (nb_int - len(uniq_A)) % 2 == 1:
print(len(uniq_A)+1)
else:
print(len(uniq_A))
|
s246921700
|
Accepted
| 45
| 14,204
| 216
|
# -*- coding: utf-8 -*-
nb_A = int(input())
A = list(map(int, input().split(" ")))
uniq_A = list(set(A))
if (nb_A - len(uniq_A)) % 2 == 1:
print(len(uniq_A)-1)
else:
print(len(uniq_A))
|
s002538735
|
p03050
|
u192154323
| 2,000
| 1,048,576
|
Wrong Answer
| 117
| 9,488
| 512
|
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
|
n = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
divisors = make_divisors(n)
ans = 0
for div in divisors:
print(div)
target = div - 1
if target != 0 and n % target != 0:
ans += target
print(ans)
|
s595999687
|
Accepted
| 123
| 9,628
| 505
|
n = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
divisors = make_divisors(n)
ans = 0
for div in divisors:
if div != 1:
q,r = divmod(n,div-1)
if q == r:
ans += div-1
print(ans)
|
s657487081
|
p04030
|
u780364430
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 129
|
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
|
s = input()
ans = ''
for i in s:
if i == 'B':
ans = ans[:-1]
else:
ans += i
print(ans)
print(ans)
|
s164612044
|
Accepted
| 17
| 2,940
| 110
|
s = input()
ans = ''
for i in s:
if i == 'B':
ans = ans[:-1]
else:
ans += i
print(ans)
|
s327009895
|
p03576
|
u239375815
| 2,000
| 262,144
|
Wrong Answer
| 55
| 3,632
| 633
|
We have N points in a two-dimensional plane. The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i). Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior. Here, points on the sides of the rectangle are considered to be in the interior. Find the minimum possible area of such a rectangle.
|
n, k = map(int, input().split())
ps = [tuple(map(int, input().split())) for i in range(n)]
sx = sorted(ps)
nx = list(enumerate(sx))
ans = 5e18
print(nx[:n - k + 1])
for l, (x1, y1) in nx[:n - k + 1]:
for r, (x2, y2) in nx[l + k - 1:]:
dx = x2 - x1
sy = sorted(y for x, y in sx[l:r + 1])
for y3, y4 in zip(sy, sy[k - 1:]):
print(y3,y4)
if y3 <= y1 and y2 <= y4:
ans = min(ans, dx * (y4 - y3))
print(ans)
|
s759280483
|
Accepted
| 28
| 3,188
| 585
|
n, k = map(int, input().split())
ps = [tuple(map(int, input().split())) for i in range(n)]
sx = sorted(ps)
nx = list(enumerate(sx))
ans = 5e18
for l, (x1, y1) in nx[:n - k + 1]:
for r, (x2, y2) in nx[l + k - 1:]:
dx = x2 - x1
sy = sorted(y for x, y in sx[l:r + 1])
for y3, y4 in zip(sy, sy[k - 1:]):
if y3 <= y1 and y2 <= y4:
ans = min(ans, dx * (y4 - y3))
print(ans)
|
s476999901
|
p04044
|
u625963200
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 104
|
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
|
N=input()
Ss=[]
for _ in range(int(N[0])):
Ss.append(input())
Ss.sort()
for s in Ss:
print(s,end='')
|
s586714007
|
Accepted
| 17
| 3,060
| 85
|
n,l=map(int,input().split())
s = sorted([input() for i in range(n)])
print(*s,sep='')
|
s709672095
|
p02678
|
u596681540
| 2,000
| 1,048,576
|
Wrong Answer
| 2,206
| 44,884
| 459
|
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
|
n, m = map(int, input().split())
path = []
for _ in range(m):
ai, bi = map(int, input().split())
path.append([ai, bi])
# print(path)
linked = set()
for _ in range(m):
for pi in path:
if 1 in pi:
linked.add(pi[0])
linked.add(pi[1])
if pi[0] in linked:
linked.add(pi[1])
elif pi[1] in linked:
linked.add(pi[0])
if len(linked) == n:
print('Yes')
else:
print('No')
|
s447039078
|
Accepted
| 758
| 39,036
| 466
|
from collections import*
import itertools
n, m = map(int, input().split())
posi = [[] for _ in range(n)]
for _ in range(m):
ai, bi = map(int, input().split())
posi[ai - 1] += [bi - 1]
posi[bi-1] += [ai - 1]
# print(posi)
p = [0]*n
q = deque([0])
while q:
v = q.popleft()
for c in posi[v]:
if p[c] < 1:
p[c] = v + 1
q.append(c)
# print(p)
if 0 in p:
print('No')
else:
print('Yes', *p[1:], sep='\n')
|
s337838049
|
p04030
|
u728611988
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 237
|
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
|
s = str(input())
ans = ""
for i in range(len(s)):
if s[i] == "0":
ans += "0"
elif s[i] == "1":
ans += "1"
else:
if len(ans) == 0:
continue
else:
ans = ans[:-1]
print(s)
|
s547507202
|
Accepted
| 17
| 3,060
| 238
|
s = str(input())
ans = ""
for i in range(len(s)):
if s[i] == "0":
ans += "0"
elif s[i] == "1":
ans += "1"
else:
if len(ans) == 0:
continue
else:
ans = ans[:-1]
print(ans)
|
s219838600
|
p03251
|
u641406334
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 174
|
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
|
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
if max(x)<min(y) & X<min(y):
print('No War')
exit()
print('War')
|
s729113692
|
Accepted
| 17
| 3,060
| 219
|
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
num =[i for i in range(X+1,Y+1) if i>max(x) and i<=min(y)]
if len(num)>=1:
print('No War')
else:
print('War')
|
s818166119
|
p03962
|
u089376182
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 24
|
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
|
print(len(set(input())))
|
s205650219
|
Accepted
| 18
| 2,940
| 32
|
print(len(set(input().split())))
|
s385005685
|
p01102
|
u564464686
| 8,000
| 262,144
|
Wrong Answer
| 40
| 5,592
| 852
|
The programming contest named _Concours de Programmation Comtemporaine Interuniversitaire_ (CPCI) has a judging system similar to that of ICPC; contestants have to submit correct outputs for two different inputs to be accepted as a correct solution. Each of the submissions should include the program that generated the output. A pair of submissions is judged to be a correct solution when, in addition to the correctness of the outputs, they include an identical program. Many contestants, however, do not stop including a different version of their programs in their second submissions, after modifying a single string literal in their programs representing the input file name, attempting to process different input. The organizers of CPCI are exploring the possibility of showing a special error message for such _close_ submissions, indicating contestants what's wrong with such submissions. Your task is to detect such close submissions.
|
def p(A,s):
i=0
j=0
s=[]
while(len(A)>i):
if A[i]=='"':
list1=A.partition('"')
s.append(list1[0])
A=list1[2]
i=0
j+=1
elif A[i]==';':
list1=A.partition(';')
s.append(list1[0])
A=list1[2]
i=0
j+=1
else:
i+=1
if len(A)==i:
s.append(A)
return s
A=input()
s1=[]
s2=[]
O=[]
while 1:
i=0
cnt=0
B=input()
s1=p(A,s1)
s2=p(B,s2)
while i<len(s1) and i<len(s2):
if s1[i]!=s2[i]:
cnt+=1
i+=1
if cnt==0:
O.append("IDENTICAL")
elif cnt==1:
O.append("CLOSE")
else:
O.append("DIFFERENT")
A=input()
if A==".":
break
for i in range(len(O)):
print(O[i])
|
s840149698
|
Accepted
| 20
| 5,592
| 553
|
s1=[]
s2=[]
O=[]
while 1:
A=input().split('"')
if A==["."]:
break
i=0
cnt=0
B=input().split('"')
l1=len(A)
l2=len(B)
if l1==l2:
while i<l1 and i<l2:
if A[i]!=B[i]:
cnt+=1
if i%2==0:
cnt+=2
i+=1
if cnt==0:
O.append("IDENTICAL")
elif cnt==1:
O.append("CLOSE")
else:
O.append("DIFFERENT")
else:
O.append("DIFFERENT")
for i in range(len(O)):
print(O[i])
|
s716524045
|
p03408
|
u785066634
| 2,000
| 262,144
|
Wrong Answer
| 24
| 3,444
| 934
|
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
|
import collections
def uzai():
n = int(input())
s = []
for i in range(n):
s_i = input()
s.append(s_i)
count_dict_s = collections.Counter(s)
return n, s, count_dict_s
n,s,count_dict_s = uzai()
m,t,count_dict_t = uzai()
print("count_dict_s",count_dict_s)
print("count_dict_t",count_dict_t)
s_count_l=[]
for s_name, s_count in count_dict_s.items():
for t_name, t_count in count_dict_t.items():
if s_name==t_name:
s_count_l.append(s_count-t_count)
elif s_name not in count_dict_t:
s_count_l.append(s_count)
print(s_name,s_count_l)
if max(s_count_l)<=0:
print('0')
else:
print(max(s_count_l))
|
s626109180
|
Accepted
| 22
| 3,316
| 937
|
import collections
def uzai():
n = int(input())
s = []
for i in range(n):
s_i = input()
s.append(s_i)
count_dict_s = collections.Counter(s)
return n, s, count_dict_s
n,s,count_dict_s = uzai()
m,t,count_dict_t = uzai()
#print("count_dict_s",count_dict_s)
#print("count_dict_t",count_dict_t)
s_count_l=[]
for s_name, s_count in count_dict_s.items():
for t_name, t_count in count_dict_t.items():
if s_name==t_name:
s_count_l.append(s_count-t_count)
elif s_name not in count_dict_t:
s_count_l.append(s_count)
# print(s_name,s_count_l)
if max(s_count_l)<=0:
print('0')
else:
print(max(s_count_l))
|
s054467434
|
p03555
|
u989326345
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 88
|
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
s=str(input())
t=str(input())
t=t[::-1]
if s==t:
print('Yes')
else:
print('No')
|
s166911996
|
Accepted
| 17
| 2,940
| 87
|
s=str(input())
t=str(input())
t=t[::-1]
if s==t:
print('YES')
else:
print('NO')
|
s150628827
|
p03587
|
u026155812
| 2,000
| 262,144
|
Wrong Answer
| 29
| 9,036
| 60
|
Snuke prepared 6 problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not. You are given a string S of length 6. If the i-th character of s is `1`, it means that the i-th problem prepared by Snuke is accepted to be used; `0` means that the problem is not accepted. How many problems prepared by Snuke are accepted to be used in the contest?
|
s=input()
num=0
for x in s:
if x==1:
num+=1
print(num)
|
s484349450
|
Accepted
| 31
| 9,088
| 63
|
s=input()
num=0
for x in s:
if x=="1":
num+=1
print(num)
|
s043871179
|
p03455
|
u393224521
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 90
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
a, b = map(int, input().split())
if a*b % 2 == 1:
print('odd')
else:
print('even')
|
s145262166
|
Accepted
| 18
| 2,940
| 90
|
a, b = map(int, input().split())
if a*b % 2 == 1:
print('Odd')
else:
print('Even')
|
s969305404
|
p03493
|
u016901717
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 31
|
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
print([int(input())].count(1))
|
s021431361
|
Accepted
| 17
| 2,940
| 51
|
a,b,c =map(int,input())
s=[a,b,c]
print(s.count(1))
|
s184219808
|
p03434
|
u561828236
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 235
|
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
|
n = int(input())
card = list(map(int,input().split()))
card = sorted(card,reverse=True)
alice = 0
bob = 0
print(card)
for i,who in enumerate(card):
if i % 2 ==0:
alice += who
else:
bob += who
print(alice-bob)
|
s403229409
|
Accepted
| 18
| 2,940
| 224
|
n = int(input())
card = list(map(int,input().split()))
card = sorted(card,reverse=True)
alice = 0
bob = 0
for i,who in enumerate(card):
if i % 2 ==0:
alice += who
else:
bob += who
print(alice-bob)
|
s667338129
|
p02396
|
u476441153
| 1,000
| 131,072
|
Wrong Answer
| 80
| 8,076
| 153
|
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
|
a = []
while True:
n = int(input())
if n is 0:
break
a.append(n)
for i, v in enumerate(a):
print ("Case " + str(i) + ": "+str(v))
|
s151921535
|
Accepted
| 80
| 7,420
| 130
|
import sys
i=1
while True:
x=sys.stdin.readline().strip()
if x=="0":
break
print("Case %d: %s"%(i,x))
i+=1
|
s383003482
|
p03388
|
u279493135
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 259
|
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
|
import sys
from math import floor
Q = int(input())
AB = [list(map(int, input().split())) for _ in range(Q)]
for A, B in AB:
C = floor((A*B)**(1/2))
if C == (A*B)**(1/2):
C -= 1
if C*(C+1) >= A*B:
print(2*C-2)
elif C*C < A*B:
print(2*C-1)
|
s658848887
|
Accepted
| 18
| 3,188
| 322
|
import sys
from math import floor
Q = int(input())
AB = [sorted(list(map(int, input().split()))) for _ in range(Q)]
for A, B in AB:
if A == B or A+1 == B:
print(2*A-2)
continue
C = floor((A*B)**(1/2))
if C == (A*B)**(1/2):
C -= 1
if C*(C+1) >= A*B:
print(2*C-2)
elif C*C < A*B:
print(2*C-1)
|
s918499528
|
p03160
|
u509690149
| 2,000
| 1,048,576
|
Wrong Answer
| 108
| 16,548
| 481
|
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
|
import sys
def frog():
n = int(sys.stdin.readline())
numbers = sys.stdin.readline().split()
for i in range(n):
numbers[i] = int(numbers[i])
a_list = [0, abs(numbers[1] - numbers[0])]
if n > 2:
a_list.append(abs(numbers[2] - numbers[0]))
else:
return a_list[-1]
for i in range(3, n):
a_list.append(min(a_list[i-1]+abs(numbers[i-1] - numbers[i]), a_list[i-2]+abs(numbers[i-2] - numbers[i])))
return a_list[-1]
frog()
|
s922231476
|
Accepted
| 124
| 16,696
| 438
|
import sys
n = int(sys.stdin.readline())
numbers = sys.stdin.readline().split()
for i in range(n):
numbers[i] = int(numbers[i])
a_list = [0, abs(numbers[1] - numbers[0])]
if n > 2:
a_list.append(abs(numbers[2] - numbers[0]))
else:
print(a_list[-1])
sys.exit()
for i in range(3, n):
a_list.append(min(a_list[i-1]+abs(numbers[i-1] - numbers[i]), a_list[i-2]+abs(numbers[i-2] - numbers[i])))
print(a_list[-1])
sys.exit()
|
s215101607
|
p02646
|
u723065526
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 9,176
| 166
|
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())
ans = "Yes"
if(V>=W):
ans = "No"
elif(abs(A-B)>T*abs(V-W)):
ans = "No"
print(ans)
|
s277183607
|
Accepted
| 22
| 9,184
| 166
|
A, V = map(int,input().split())
B, W = map(int,input().split())
T = int(input())
ans = "YES"
if(V<=W):
ans = "NO"
elif(abs(A-B)>T*abs(V-W)):
ans = "NO"
print(ans)
|
s102280834
|
p00001
|
u810591206
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,224
| 119
|
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
|
list = []
for i in range(10):
list.append(input())
list.sort(reverse = True)
for i in range(3):
print(list[i])
|
s581993887
|
Accepted
| 30
| 7,608
| 126
|
list = []
for i in range(10):
list.append(int(input()))
list.sort(reverse = True)
for j in range(3):
print(list[j])
|
s220891213
|
p02410
|
u745846646
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,716
| 346
|
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 \\]
|
(n,m) = [int() for i in input().split()]
A = []
for nc in range(n):
A.append([int(i) for i in input().split()])
b = []
for mc in range(m):
b.append(int(input()))
product = []
for nc in range(n):
total = 0
for mc in range(m):
total += A[nc][mc] * b[mc]
product.append(total)
[print(p) for p in product]
|
s121579108
|
Accepted
| 20
| 8,176
| 195
|
n,m = map(int,input().split())
rc = [list(map(int,input().split())) for i in range(n)]
vector = [int(input()) for i in range(m)]
[print(sum([j*k for j,k in zip(rc[i],vector)])) for i in range(n)]
|
s234217514
|
p02694
|
u377265351
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 9,160
| 86
|
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())
a = 100
y = 0
while x >= a:
a = int(a*1.01)
y = y+1
print(y)
|
s390110982
|
Accepted
| 23
| 9,160
| 89
|
x = int(input())
a = 100
y = 0
while x > a:
a = int(a*101/100)
y = y+1
print(y)
|
s184191454
|
p02844
|
u729535891
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 3,316
| 340
|
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
|
n = int(input())
S = input()
V = [str(i).zfill(3) for i in range(1000)]
cnt = 0
for v in V:
tmp = 0
i = 0
j = 0
while i < len(S) and j < len(v):
if S[i] == v[j]:
tmp += 1
j += 1
i += 1
else:
i += 1
if tmp == 3:
cnt += 1
print(v)
print(cnt)
|
s149775110
|
Accepted
| 19
| 3,064
| 498
|
n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
if len(str(i)) == 1:
tmp = '00' + str(i)
lst[i] = tmp
elif len(str(i)) == 2:
tmp = '0' + str(i)
lst[i] = tmp
else:
lst[i] = str(i)
cnt = 0
for v in lst:
id_1 = s.find(v[0])
if id_1 == -1:
continue
id_2 = s.find(v[1], id_1 + 1)
if id_2 == -1:
continue
id_3 = s.find(v[2], id_2 + 1)
if id_3 == -1:
continue
cnt += 1
print(cnt)
|
s532057496
|
p03407
|
u340947941
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 190
|
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=list(map(int,input().split(" ")))
if C==(A*0+B*1) or C==(A*1+B*0) or C==(A*1+B*1):
print("Yes")
else:
print("No")
|
s470118418
|
Accepted
| 17
| 2,940
| 154
|
A,B,C=list(map(int,input().split(" ")))
if (A+B)>=C:
print("Yes")
else:
print("No")
|
s620700290
|
p03447
|
u364541509
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 103
|
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())
X1 = X - A
X2 = X1 // B
X3 = X - (X2 * B)
print(X3)
|
s630284553
|
Accepted
| 17
| 2,940
| 104
|
X = int(input())
A = int(input())
B = int(input())
X1 = X - A
X2 = X1 // B
X3 = X1 - (X2 * B)
print(X3)
|
s619973644
|
p03386
|
u680851063
| 2,000
| 262,144
|
Wrong Answer
| 2,138
| 570,776
| 215
|
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())
l = []
for i in range(b-a+1):
l.append(a+i)
#print(l)
c = len(l)
d = min(c,k)
x = []
for j in range(d):
x.append(l[j])
x.append(l[-(j+1)])
print(*list(set(x)),sep='\n')
|
s085625506
|
Accepted
| 18
| 3,060
| 257
|
a,b,k = map(int, input().split())
#print(l)
c = b-a+1
x = []
if k*2 > c:
for i in range(a, b+1):
x.append(i)
else:
for j in range(a, a+k):
x.append(j)
for j in range(b-k+1, b+1):
x.append(j)
print(*sorted(x), sep='\n')
|
s605395462
|
p03478
|
u094213642
| 2,000
| 262,144
|
Wrong Answer
| 36
| 9,008
| 201
|
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
n, a, b = list(map(int, input().split()))
sum = 0
for i in range(n):
s_sum = 0
c = i
while c>0:
s_sum += c%10
c = c//10
if a <= s_sum <= b:
sum += i
print(sum)
|
s469820329
|
Accepted
| 35
| 9,104
| 203
|
n, a, b = list(map(int, input().split()))
sum = 0
for i in range(n+1):
s_sum = 0
c = i
while c>0:
s_sum += c%10
c = c//10
if a <= s_sum <= b:
sum += i
print(sum)
|
s981220090
|
p04043
|
u962985517
| 2,000
| 262,144
|
Wrong Answer
| 22
| 9,064
| 101
|
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
|
a,b,c = map(int,input().split())
ans = 'YES' if (a == 5) and (b == 7) and (c==5) else "NO"
print(ans)
|
s106235384
|
Accepted
| 25
| 8,800
| 111
|
li=list(map(int,input().split()))
ans = 'YES' if (li.count(5) == 2) and (li.count(7) == 1) else "NO"
print(ans)
|
s550439485
|
p03795
|
u779508975
| 2,000
| 262,144
|
Wrong Answer
| 25
| 9,136
| 56
|
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())
answer = int(N*(N+1)/2)
print(answer)
|
s176054709
|
Accepted
| 25
| 9,132
| 59
|
N = int(input())
x = N * 800
y = N // 15 * 200
print(x-y)
|
s298002593
|
p02748
|
u285681431
| 2,000
| 1,048,576
|
Wrong Answer
| 346
| 44,096
| 305
|
You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]
# print(xyc)
cost = []
cost.append(min(a) + min(b))
for x, y, c in xyc:
tmp = a[x - 1] + b[y - 1] - c
cost.append(tmp)
print(cost)
|
s870845106
|
Accepted
| 341
| 42,556
| 310
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]
# print(xyc)
cost = []
cost.append(min(a) + min(b))
for x, y, c in xyc:
tmp = a[x - 1] + b[y - 1] - c
cost.append(tmp)
print(min(cost))
|
s048474129
|
p03720
|
u690536347
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 153
|
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
|
a,b=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(b)]
for i in range(1,a+1):
print(sum(1 for i in l if i[0]==i or i[1]==i))
|
s949552625
|
Accepted
| 17
| 2,940
| 156
|
a,b=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(b)]
for j in range(1,a+1):
print(sum(1 for i in l if i[0]==j or i[1]==j))
|
s373798505
|
p00077
|
u546285759
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,632
| 307
|
文字列が連続した場合、ある規則で文字を置き換え文字列を短くすることができます。たとえば、AAAA という文字列の場合、@4A と表現すれば 1 文字分圧縮されます。この規則で圧縮された文字列を入力してもとの文字列に復元するプログラムを作成してください。ただし、復元した文字列に@文字は出現しないものとします。 また、原文の文字列は英大文字、英小文字、数字、記号であり 100 文字以内、連続する文字は 9 文字以内です。
|
import sys
for line in sys.stdin:
line = line.strip()
i = 0
ans = ""
while i < len(line):
if line[i] == "@":
m = int(line[i+1])
c = line[i+2]
i += 2
ans += m*c
else:
ans += line[i]
i += 1
print(ans)
|
s901126504
|
Accepted
| 30
| 7,508
| 294
|
while True:
try:
string = input()
except:
break
ans = ""
i = 0
while i < len(string):
if string[i] == "@":
ans += int(string[i+1])*string[i+2]
i += 3
else:
ans += string[i]
i += 1
print(ans)
|
s486493808
|
p02972
|
u567534852
| 2,000
| 1,048,576
|
Wrong Answer
| 627
| 6,852
| 268
|
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
|
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in reversed(range(1, n+1)):
for j in range(2*i-1, n, i):
a[i-1] ^= a[j]
if a[i-1] == 1:
count += 1
if count:
print(count)
print(a)
else:
print(0)
|
s354293825
|
Accepted
| 270
| 13,112
| 321
|
n = int(input())
a = list(map(int, input().split()))
ball = [0]*n
for i in reversed(range(1, n+1)):
ball_in_or_not = a[i-1] ^ sum(ball[i-1:n:i]) % 2
if ball_in_or_not == 1:
ball[i-1] =1
if sum(ball) > 0:
print(sum(ball))
print(*[i+1 for i in range(n) if ball[i] > 0])
else:
print(0)
|
s258848499
|
p02850
|
u945181840
| 2,000
| 1,048,576
|
Wrong Answer
| 269
| 32,036
| 629
|
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
|
import sys
from collections import deque
read = sys.stdin.read
N, *ab = map(int, read().split())
graph = [[] for _ in range(N + 1)]
cnt = [0] * (N + 1)
for a, b in zip(*[iter(ab)] * 2):
graph[a].append(b)
graph[b].append(a)
cnt[a] += 1
cnt[b] += 1
color = [0] * (N + 1)
root = cnt.index(1)
queue = deque([root])
color[root] = 1
while queue:
V = queue.popleft()
number = 1
for v in graph[V]:
if color[v] == 0:
while number == color[V]:
number += 1
color[v] = number
queue.append(v)
print(max(color))
print('\n'.join(map(str, color[1:])))
|
s009870215
|
Accepted
| 261
| 25,900
| 506
|
import sys
from collections import deque
read = sys.stdin.read
N, *ab = map(int, read().split())
graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
graph[a].append(b)
color = [0] * (N + 1)
queue = deque([1])
while queue:
V = queue.popleft()
number = 1
for v in graph[V]:
if number == color[V]:
number += 1
color[v] = number
queue.append(v)
number += 1
print(max(color))
for a, b in zip(*[iter(ab)] * 2):
print(color[b])
|
s761263835
|
p03605
|
u427344224
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 53
|
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
N = input()
print("Yes" if N.count("N")>=1 else "No")
|
s850876093
|
Accepted
| 17
| 2,940
| 53
|
N = input()
print("Yes" if N.count("9")>=1 else "No")
|
s100735742
|
p03644
|
u145889196
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 51
|
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.
|
from math import *;print(floor(log2(int(input()))))
|
s250580661
|
Accepted
| 17
| 3,060
| 54
|
from math import *;print(2**floor(log2(int(input()))))
|
s210829001
|
p03544
|
u226912938
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 128
|
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())
Num = [2,1]
for i in range(2,86):
new = Num[i-1] + Num[i-2]
Num.append(new)
ans = Num[n-1]
print(ans)
|
s655319754
|
Accepted
| 17
| 2,940
| 126
|
n = int(input())
Num = [2,1]
for i in range(2,87):
new = Num[i-1] + Num[i-2]
Num.append(new)
ans = Num[n]
print(ans)
|
s136600740
|
p03214
|
u382431597
| 2,525
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 217
|
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
|
n = int(input())
a = list(map(int, input().split()))
ave_a = sum(a) / n
dist = 1000007
flamenum = 0
for i in range(n):
if abs(a[i] - ave_a) < dist:
dist = abs(a[i] - ave_a)
flamenum = i
print(i)
|
s327773473
|
Accepted
| 17
| 3,060
| 245
|
n = int(input())
a = list(map(int, input().split()))
ave_a = sum(a) / n
dist = 1000007
flamenum = 0
for i in range(n):
if abs(a[i] - ave_a) < dist:
dist = abs(a[i] - ave_a)
flamenum = i
#print(dist)
print(flamenum)
|
s683529977
|
p03545
|
u941645670
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 379
|
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.
|
n = input()
for i in range(2 ** 4):
result = 0
formura = ""
for j in range(4):
formura += n[j]
if ((i >> j) & 1):
result -= int(n[j])
formura += "-"
else:
result += int(n[j])
formura += "+"
if result == 7:
print(formura+"=7")
break
|
s281527415
|
Accepted
| 19
| 3,064
| 347
|
n = input()
for i in range(2 ** 3):
result = int(n[0])
formura = n[0]
for j in range(3):
if ((i >> j) & 1):
result -= int(n[j+1])
formura += "-"+n[j+1]
else:
result += int(n[j+1])
formura += "+"+n[j+1]
if result == 7:
print(formura+"=7")
break
|
s680375365
|
p02255
|
u196653484
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,604
| 422
|
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
def Insertion_Sort():
N=int(input())
A=input().split()
for i in range(1,N):
v=A[i]
j=i-1
while j>=0 and A[j]>v:
A[j+1]=A[j]
j=j-1
A[j+1]=v
print(A[0],end="")
for i in range(1,N):
print(" {}".format(A[i]),end="")
print('\n',end="")
if __name__ == "__main__":
Insertion_Sort()
|
s410394178
|
Accepted
| 30
| 5,996
| 802
|
def Insertion_Sort(N,A,flag=0):
for i in range(0,N):
v=A[i]
j=i-1
while j>=0 and A[j]>v:
A[j+1]=A[j]
j=j-1
A[j+1]=v
if flag==1:
print(A[0],end="")
for i in range(1,N):
print(" {}".format(A[i]),end="")
print('\n',end="")
return A
if __name__ == "__main__":
N=int(input())
A=list(map(int,input().split()))
Insertion_Sort(N,A,1)
"""
(py361) [16D8101012J@ise72c ~]$ python ALDS1_1_A.py
10
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
9 10 8 7 6 5 4 3 2 1
8 9 10 7 6 5 4 3 2 1
7 8 9 10 6 5 4 3 2 1
6 7 8 9 10 5 4 3 2 1
5 6 7 8 9 10 4 3 2 1
4 5 6 7 8 9 10 3 2 1
3 4 5 6 7 8 9 10 2 1
2 3 4 5 6 7 8 9 10 1
1 2 3 4 5 6 7 8 9 10
"""
|
s105136217
|
p02795
|
u072719787
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 2,940
| 138
|
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())
if N % max(H, W) == 0:
print(N / max(H, W))
else:
print((N / max(H, W)) + 1)
|
s830648566
|
Accepted
| 17
| 2,940
| 130
|
a = [int(input()) for i in range(2)]
b = int(input())
if b % max(a) == 0:
print(b // max(a))
else:
print(b // max(a) + 1)
|
s277718773
|
p03369
|
u844123804
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 42
|
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
|
num = input()
print(700 + num.count("o"))
|
s583632148
|
Accepted
| 17
| 2,940
| 46
|
num = input()
print(700 + num.count("o")*100)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.