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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s859651276
|
p03644
|
u606043821
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,104
| 2,940
| 186
|
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.
|
def divisible(n):
ans = 0
while n%2 == 0:
n /=2
ans +=1
return ans
N = int(input())
a = []
for i in range(N):
a.append(divisible(i))
print(max(a))
|
s151334700
|
Accepted
| 18
| 2,940
| 209
|
def divisible(n):
ans = 0
while n%2 == 0:
n /= 2
ans += 1
return ans
N = int(input())
b = 0
c = 1
for i in range(1,N+1):
if(divisible(i) > b):
b = divisible(i)
c = i
print(c)
|
s360564822
|
p03024
|
u625963200
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 2,940
| 111
|
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
|
S = [str(i) for i in input().split()][0]
count = S.count('o')
if count>=8:
print('YES')
else:
print('NO')
|
s850515358
|
Accepted
| 19
| 2,940
| 111
|
S = [str(i) for i in input().split()][0]
count = S.count('x')
if count>=8:
print('NO')
else:
print('YES')
|
s672787734
|
p03711
|
u557494880
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 348
|
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.
|
W,H = map(int,input().split())
ans = 10**30
for i in range(1,W):
a = H*i
w = W - i
b = max((w//2)*H,w*(H//2))
c = w*H - b
x = max(a,b,c) - min(a,b,c)
ans = min(ans,x)
for i in range(1,H):
a = W*i
h = H - i
b = max((W//2)*h,W*(h//2))
c = h*W - b
x = max(a,b,c) - min(a,b,c)
ans = min(ans,x)
print(ans)
|
s490778449
|
Accepted
| 17
| 3,064
| 203
|
d = {}
d[1] = 1
d[2] = 3
d[3] = 1
d[4] = 2
d[5] = 1
d[6] = 2
d[7] = 1
d[8] = 1
d[9] = 2
d[10] = 1
d[11] = 2
d[12] = 1
x,y = map(int,input().split())
ans = 'No'
if d[x] == d[y]:
ans = 'Yes'
print(ans)
|
s910731657
|
p03409
|
u354638986
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 3,316
| 533
|
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
|
def check_rec(bc, rc, pair):
if len(bc) == 0 or len(rc) == 0:
return pair
bcc = bc.copy()
e = bcc.pop()
pairs = [pair]
for i in rc:
if e[0] > i[0] and e[1] > i[1]:
rcc = rc.copy()
rcc.remove(i)
pairs.append(check_rec(bcc, rcc, pair+1))
return max(pairs)
n = int(input())
rc, bc = set(), set()
for i in range(n):
rc.add(tuple(map(int, input().split())))
for i in range(n):
bc.add(tuple(map(int, input().split())))
print(check_rec(bc, rc, 0))
|
s935618838
|
Accepted
| 18
| 3,064
| 495
|
n = int(input())
rc, bc = [], []
for i in range(n):
rc.append(tuple(map(int, input().split())))
for i in range(n):
bc.append(tuple(map(int, input().split())))
rc.sort(key=lambda tup: tup[0])
bc.sort(key=lambda tup: tup[0])
pairs = 0
for i in bc:
pair = (200, -1)
for j in rc:
if i[0] < j[0]:
break
elif i[1] > j[1] > pair[1]:
pair = j
if i[0] > pair[0] and i[1] > pair[1]:
pairs += 1
rc.remove(pair)
print(pairs)
|
s189344293
|
p03457
|
u586759271
| 2,000
| 262,144
|
Wrong Answer
| 452
| 12,496
| 247
|
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
n=int(input())
t=[0]*n
x=[0]*n
y=[0]*n
for i in range(n):
t[i],x[i],y[i] = map(int,input().split())
for i in range(n-1):
z=abs(x[i]-x[i+1])+abs(y[i]-y[i+1])
if(z<=t[i+1]-t[i] and (z-t[i+1]+t[i])%2==0):
print("yes")
print("No")
|
s535811721
|
Accepted
| 379
| 11,636
| 299
|
n=int(input())
t=[0]*(n+1)
x=[0]*(n+1)
y=[0]*(n+1)
for i in range(n):
t[i+1],x[i+1],y[i+1] = map(int,input().split())
flag=0
for i in range(n):
l=abs(x[i]-x[i+1])+abs(y[i]-y[i+1])
s=t[i+1]-t[i]
if(l>s or (l-s)%2==1):
flag=1
if flag==0:
print("Yes")
else:
print("No")
|
s677813608
|
p03469
|
u238084414
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 40
|
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
S = input()
print("2018/01/" + S[8:9])
|
s126346324
|
Accepted
| 17
| 2,940
| 41
|
S = input()
print("2018/01/" + S[8:10])
|
s015946290
|
p03456
|
u705418271
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,036
| 117
|
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
a,b=map(str,input().split())
c=a+b
c=int(c)
for i in range(1001):
if i**2==c:
print("Yes")
else:
print("No")
|
s537079716
|
Accepted
| 23
| 9,140
| 120
|
a,b=map(str,input().split())
c=a+b
c=int(c)
for i in range(1001):
if i**2==c:
print("Yes")
exit()
print("No")
|
s140078343
|
p03378
|
u480138356
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 205
|
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
|
def main():
N, M, X = map(int, input().split())
a = [0] + list(map(int, input().split())) + [N]
i = 0
while a[i] < N:
i += 1
print(min(i-1, M + 1 - i))
if __name__ == "__main__":
main()
|
s715867306
|
Accepted
| 17
| 2,940
| 214
|
def main():
N, M, X = map(int, input().split())
a = list(map(int, input().split()))
i = 0
while i < M:
if a[i] > X:
break
i += 1
print(min(i, M - i))
if __name__ == "__main__":
main()
|
s515766909
|
p02260
|
u918276501
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,608
| 237
|
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
|
cnt = 0
n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
m = i
for j in range(i, n):
if lst[j] < lst[m]:
m = j
lst[i], lst[m] = lst[j], lst[j-1]
cnt += 1
print(*lst)
print(cnt)
|
s112964243
|
Accepted
| 20
| 7,680
| 258
|
cnt = 0
n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
m = i
for j in range(i, n):
if lst[j] < lst[m]:
m = j
if m != i:
lst[i], lst[m] = lst[m], lst[i]
cnt += 1
print(*lst)
print(cnt)
|
s837876502
|
p04012
|
u668352391
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 253
|
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
|
s = input()
s_list = [s[_] for _ in range(len(s))]
dic = dict()
for c in s_list:
if c in dic:
dic[c] += 1
else:
dic[c] = 1
flg = True
for key in dic:
if dic[key] != 2:
flg = False
if flg:
print('Yes')
else:
print('No')
|
s898610291
|
Accepted
| 17
| 3,060
| 259
|
s = input()
s_list = [s[_] for _ in range(len(s))]
dic = dict()
for c in s_list:
if c in dic:
dic[c] += 1
else:
dic[c] = 1
flg = True
for key in dic:
if dic[key]%2 != 0:
flg = False
break
if flg:
print('Yes')
else:
print('No')
|
s658615635
|
p03796
|
u088488125
| 2,000
| 262,144
|
Wrong Answer
| 43
| 9,148
| 82
|
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
|
n=int(input())
power=1
for i in range(n):
power=(power*i)%(10**9+7)
print(power)
|
s322482580
|
Accepted
| 43
| 9,080
| 87
|
n=int(input())
power=1
for i in range(1,n+1):
power=(power*i)%(10**9+7)
print(power)
|
s482444696
|
p03494
|
u929793345
| 2,000
| 262,144
|
Wrong Answer
| 26
| 9,164
| 161
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
n = int(input())
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
A = [a // 2 for a in A]
count += 1
print(count)
print(A)
|
s057291597
|
Accepted
| 28
| 9,088
| 152
|
n = int(input())
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
A = [a / 2 for a in A]
count += 1
print(count)
|
s066395757
|
p00603
|
u546285759
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,684
| 396
|
There are a number of ways to shuffle a deck of cards. Riffle shuffle is one such example. The following is how to perform riffle shuffle. There is a deck of _n_ cards. First, we divide it into two decks; deck A which consists of the top half of it and deck B of the bottom half. Deck A will have one more card when _n_ is odd. Next, _c_ cards are pulled from bottom of deck A and are stacked on deck C, which is empty initially. Then _c_ cards are pulled from bottom of deck B and stacked on deck C, likewise. This operation is repeated until deck A and B become empty. When the number of cards of deck A(B) is less than _c_ , all cards are pulled. Finally we obtain shuffled deck C. See an example below: - A single riffle operation where n = 9, c = 3 for given deck [0 1 2 3 4 5 6 7 8] (right is top) - Step 0 deck A [4 5 6 7 8] deck B [0 1 2 3] deck C [] - Step 1 deck A [7 8] deck B [0 1 2 3] deck C [4 5 6] - Step 2 deck A [7 8] deck B [3] deck C [4 5 6 0 1 2] - Step 3 deck A [] deck B [3] deck C [4 5 6 0 1 2 7 8] - Step 4 deck A [] deck B [] deck C [4 5 6 0 1 2 7 8 3] shuffled deck [4 5 6 0 1 2 7 8 3] This operation, called riffle operation, is repeated several times. Write a program that simulates Riffle shuffle and answer which card will be finally placed on the top of the deck.
|
while True:
try:
n, r = map(int, input().split())
c = list(map(int, input().split()))
card = [v for v in range(n)]
A, B, C = card[n//2:], card[:n//2], []
for k, v in zip(c, range(r)):
if v % 2 == 0:
C += A[:k]
del A[:k]
else:
C += B[:k]
del B[:k]
except: break
|
s030475449
|
Accepted
| 50
| 7,560
| 417
|
while True:
try:
n, r = map(int, input().split())
cc = list(map(int, input().split()))
card = [v for v in range(n)]
for c in cc:
A, B, C = card[n//2:], card[:n//2], []
while len(A) or len(B):
C += A[:c]
del A[:c]
C += B[:c]
del B[:c]
card = C
print(C[-1])
except: break
|
s279090849
|
p03433
|
u064246852
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 41
|
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
print(int(input()) % 500 <= int(input()))
|
s151002244
|
Accepted
| 18
| 2,940
| 60
|
print("Yes" if int(input()) % 500 <= int(input()) else "No")
|
s166984564
|
p03251
|
u440478998
| 2,000
| 1,048,576
|
Wrong Answer
| 27
| 9,172
| 201
|
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 (X < Y)&(max(x) < min(y))&(max(x) < Y <min(y)):
print("No War")
else:
print("War")
|
s116835026
|
Accepted
| 30
| 9,064
| 206
|
N,M,X,Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
if (X < Y)&(max(x) < min(y))&(max(x) < Y)&(X < min(y)):
print("No War")
else:
print("War")
|
s469478550
|
p03778
|
u732844340
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 281
|
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
|
def main():
x = input().split()
W = int(x[0])
a = int(x[1])
b = int(x[2])
if a+W > b or a < b+W:
print(0)
return
l = [a,a+W,b,b+W]
l.remove(min(l))
l.remove(max(l))
print(max(l) - min(l))
if __name__ == '__main__':
main()
|
s009751889
|
Accepted
| 17
| 3,060
| 258
|
def main():
x = input().split()
W = int(x[0])
a = int(x[1])
b = int(x[2])
if b > a+W:
print(b - (a+W))
return
elif a > b+W:
print(a - (b+W))
return
print(0)
if __name__ == '__main__':
main()
|
s525455058
|
p02393
|
u242221792
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,596
| 216
|
Write a program which reads three integers, and prints them in ascending order.
|
a = list(map(int, input().split()))
for i in range(1,len(a)-1):
v = a[i]
j = i - 1
while j >= 0 and a[j] > v:
a[j+1] = a[j]
j -= 1
a[j+1] = v
print("{} {} {}".format(a[0],a[1],a[2]))
|
s077586590
|
Accepted
| 20
| 5,592
| 214
|
a = list(map(int, input().split()))
for i in range(1,len(a)):
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("{} {} {}".format(a[0],a[1],a[2]))
|
s174160164
|
p00031
|
u868716420
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,484
| 395
|
祖母が天秤を使っています。天秤は、二つの皿の両方に同じ目方のものを載せると釣合い、そうでない場合には、重い方に傾きます。10 個の分銅の重さは、軽い順に 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g です。 祖母は、「1kg くらいまでグラム単位で量れるのよ。」と言います。「じゃあ、試しに、ここにあるジュースの重さを量ってよ」と言ってみると、祖母は左の皿にジュースを、右の皿に 8g と64g と128g の分銅を載せて釣合わせてから、「分銅の目方の合計は 200g だから、ジュースの目方は 200g ね。どう、正しいでしょう?」と答えました。 左の皿に載せる品物の重さを与えるので、天秤で与えられた重みの品物と釣合わせるときに、右の皿に載せる分銅を軽い順に出力するプログラムを作成して下さい。ただし、量るべき品物の重さは、すべての分銅の重さの合計 (=1023g) 以下とします。
|
g = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
while True :
try :
c = -1
left, right = int(input()), []
while True :
if left <= 0 : break
else :
if left - g[c] < 0 : c += -1
else :
left -= g[c]
right.append(g[c])
right.sort()
print(right)
except : break
|
s340499681
|
Accepted
| 30
| 7,612
| 396
|
g = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
while True :
try :
c = -1
left, right = int(input()), []
while True :
if left <= 0 : break
else :
if left - g[c] < 0 : c += -1
else :
left -= g[c]
right.append(g[c])
right.sort()
print(*right)
except : break
|
s666583693
|
p04012
|
u852367841
| 2,000
| 262,144
|
Wrong Answer
| 152
| 12,404
| 483
|
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
|
import numpy as np
w = input()
alp_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
w_list = []
for s in w:
w_list.append(s)
print(w_list)
count_list = []
for i in alp_list:
count = w_list.count(i)
count_list.append(count)
print(count_list)
div_array = np.array(count_list) % 2
div_list = div_array.tolist()
if div_list.count(0) == 26:
print('Yes')
else:
print('No')
|
s754130225
|
Accepted
| 290
| 20,020
| 449
|
import numpy as np
w = input()
alp_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
w_list = []
for s in w:
w_list.append(s)
count_list = []
for i in alp_list:
count = w_list.count(i)
count_list.append(count)
div_array = np.array(count_list) % 2
div_list = div_array.tolist()
if div_list.count(0) == 26:
print('Yes')
else:
print('No')
|
s156391432
|
p03448
|
u142903114
| 2,000
| 262,144
|
Wrong Answer
| 46
| 3,060
| 337
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
|
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i_a in range(a+1):
sum_a = 500 * i_a
print(i_a)
for i_b in range(b+1):
sum_b = 100 * i_b
for i_c in range(c+1):
sum_c = 50 * i_c
if x == (sum_a + sum_b + sum_c):
count += 1
print(count)
|
s011288511
|
Accepted
| 43
| 3,064
| 322
|
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i_a in range(a+1):
sum_a = 500 * i_a
for i_b in range(b+1):
sum_b = 100 * i_b
for i_c in range(c+1):
sum_c = 50 * i_c
if x == (sum_a + sum_b + sum_c):
count += 1
print(count)
|
s450660628
|
p03251
|
u282228874
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,060
| 227
|
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 = list(map(int,input().split()))
y_list = list(map(int,input().split()))
if max(x_list) <= min(y_list) and x <min(y_list) and y > max(x_list):
print('No war')
else:
print('War')
|
s709196072
|
Accepted
| 18
| 3,060
| 227
|
n,m,x,y = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
for z in range(-100,101):
if x < z <= y and max(X) < z <= min(Y):
print("No War")
exit()
print("War")
|
s455998721
|
p03486
|
u750389519
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,104
| 79
|
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
s=input()
t=input()
u=sorted([s])
v=sorted([t])
print("Yes" if u<v else "No")
|
s702526442
|
Accepted
| 29
| 9,020
| 100
|
s=list(input())
t=list(input())
u=sorted(s)
v=sorted(t,reverse=True)
print("Yes" if u<v else "No")
|
s475637638
|
p03992
|
u396495667
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 66
|
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
|
s = list(input())
f= ''.join(s[:4])
b=''.join(s[4:])
print(f,'',b)
|
s960214504
|
Accepted
| 18
| 2,940
| 71
|
s = list(input())
f= ''.join(s[:4])
b=''.join(s[4:])
print(f,b,sep=' ')
|
s968165882
|
p03796
|
u620846115
| 2,000
| 262,144
|
Wrong Answer
| 2,206
| 10,252
| 82
|
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
|
import math
n = int(input())
print(math.factorial(n), math.factorial(n)%(10**9+7))
|
s291696947
|
Accepted
| 275
| 10,200
| 93
|
import math
n = int(input())
a = min(math.factorial(n), math.factorial(n)%(10**9+7))
print(a)
|
s734240258
|
p02262
|
u771410206
| 6,000
| 131,072
|
Wrong Answer
| 20
| 5,612
| 709
|
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
|
n = int(input())
A = [int(input()) for _ in range(n)]
G = [3*i+1 for i in range(max(1,n//3))]
if len(G)>1:
G.sort(reverse=True)
m = len(G)
cnt = 0
def shellSort(A,n):
cccnt = 0
G = [3*i+1 for i in range(min(1,n//3))]
m = len(G)
for k in range(m):
cccnt += insertionSort(A,n,G[k])
return cccnt
def insertionSort(A,n,g):
ccnt = 0
for i in range(g,n):
v = A[i]
j = i-g
while j>=0 and A[j] > v:
A[j+g] = A[j]
j -= g
ccnt += 1
A[j+g] = v
return ccnt
cnt = shellSort(A,n)
print(m)
print(' '.join(map(str,G)))
print(cnt)
for _ in range(n):
print(A[_])
|
s057645056
|
Accepted
| 17,900
| 45,524
| 691
|
n = int(input())
A = [int(input()) for _ in range(n)]
G = [1]
a=1
while True:
a = 3*a+1
if a>=n:
break
G.append(a)
if len(G)>1:
G.sort(reverse=True)
m = len(G)
cnt = 0
def shellSort(A,n):
cccnt = 0
for k in range(m):
cccnt += insertionSort(A,n,G[k])
return cccnt
def insertionSort(A,n,g):
ccnt = 0
for i in range(g,n):
v = A[i]
j = i-g
while j>=0 and A[j] > v:
A[j+g] = A[j]
j -= g
ccnt += 1
A[j+g] = v
return ccnt
cnt = shellSort(A,n)
print(m)
print(' '.join(map(str,G)))
print(cnt)
for _ in range(n):
print(A[_])
|
s440009679
|
p02613
|
u940765148
| 2,000
| 1,048,576
|
Wrong Answer
| 142
| 9,188
| 172
|
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
n = int(input())
result = {}
l = ['AC','WA','TLE','RE']
for i in l:
result[i] = 0
for _ in range(n):
result[input()] += 1
for i in l:
print(f'AC x {result[i]}')
|
s537537566
|
Accepted
| 143
| 9,188
| 173
|
n = int(input())
result = {}
l = ['AC','WA','TLE','RE']
for i in l:
result[i] = 0
for _ in range(n):
result[input()] += 1
for i in l:
print(f'{i} x {result[i]}')
|
s902670045
|
p04029
|
u936985471
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 108
|
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
子供の数=int(input())
答え=0
for 飴の数 in range(1,子供の数):
答え+=飴の数
print(答え)
|
s625724480
|
Accepted
| 18
| 3,064
| 111
|
子供の数=int(input())
答え=0
for 飴の数 in range(1,子供の数+1):
答え+=飴の数
print(答え)
|
s184482106
|
p03472
|
u975561820
| 2,000
| 262,144
|
Wrong Answer
| 390
| 11,344
| 431
|
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?
|
n, h = (int(s) for s in input().split())
a = []
b = []
for i in range(n):
a_i, b_i = (int(s) for s in input().split())
a.append(a_i)
b.append(b_i)
a_max = max(a)
b.sort(reverse=True)
for i, b_i in enumerate(b):
if b_i > a_max:
h -= b_i
if h <= 0:
print(i + 1)
break
else:
print(i + (h - 1) // a_max + 1)
break
else:
print(i + (h - 1) // a_max + 1)
|
s525612753
|
Accepted
| 415
| 11,256
| 437
|
n, h = (int(s) for s in input().split())
a = []
b = []
for i in range(n):
a_i, b_i = (int(s) for s in input().split())
a.append(a_i)
b.append(b_i)
a_max = max(a)
b.sort(reverse=True)
for i, b_i in enumerate(b):
if b_i > a_max:
h -= b_i
if h <= 0:
print(i + 1)
break
else:
print(i + (h - 1) // a_max + 1)
break
else:
print(len(b) + (h - 1) // a_max + 1)
|
s897212563
|
p03474
|
u798086274
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,188
| 124
|
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
|
import re
z=input()[:-1].split(" ")
s=input()
print("Yes") if re.match("[0-9]{"+z[0]+"}-[0-9]{"+z[1]+"}",s) else print("No")
|
s019167259
|
Accepted
| 20
| 3,188
| 117
|
import re
z=re.split('\s',input())
s=input()
print("Yes") if re.match("\d{"+z[0]+"}-\d{"+z[1]+"}",s) else print("No")
|
s417505753
|
p03399
|
u686036872
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 120
|
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
|
A, B, C, D=[int(input()) for i in range(4)]
if A<=B:
train=A
else:
train=B
if C<=D:
bus=C
else:
bus=D
print(A+B)
|
s929820906
|
Accepted
| 17
| 2,940
| 126
|
A, B, C, D=[int(input()) for i in range(4)]
if A<=B:
train=A
else:
train=B
if C<=D:
bus=C
else:
bus=D
print(train+bus)
|
s158844289
|
p02255
|
u862923854
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,456
| 1
|
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.
|
s631182395
|
Accepted
| 30
| 5,980
| 425
|
def show(nums):
for i in range(len(nums)):
if i != len(nums) - 1:
print(nums[i], end = ' ')
else:
print(nums[i])
n = int(input())
nums = list(map(int,input().split()))
show(nums)
for i in range(1,n):
v = nums[i]
j = i - 1
while (j >= 0 and nums[j] > v):
nums[j+1] = nums[j]
j -= 1
nums[j+1]=v
show(nums)
|
|
s834851662
|
p03163
|
u038887660
| 2,000
| 1,048,576
|
Wrong Answer
| 232
| 91,928
| 328
|
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
|
import numpy as np
N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype = "int64")
for i in range(N):
w, v = map(int, input().split())
dp[i,-w:] = dp[i-1, -w:]
dp[i, :W-w+1] = np.fmax(dp[i-1, :W-w+1], dp[i-1, w:]+v)
dp[N-1, 0]
|
s755880129
|
Accepted
| 228
| 91,940
| 335
|
import numpy as np
N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype = "int64")
for i in range(N):
w, v = map(int, input().split())
dp[i,-w:] = dp[i-1, -w:]
dp[i, :W-w+1] = np.fmax(dp[i-1, :W-w+1], dp[i-1, w:]+v)
print(dp[N-1, 0])
|
s152291151
|
p02259
|
u957840591
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,744
| 500
|
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
|
def inputInline():
N=int(input())
numbers=list(map(int,input().split(" ")))
return numbers
def bubbleSort(list):
N=len(list)
count=0
flag=True
while flag:
flag=False
for i in range(N-1):
if list[i]>list[i+1]:
temp=list[i]
list[i]=list[i+1]
list[i+1]=temp
flag=True
count+=1
return (list,count)
result=bubbleSort(inputInline())
print(result[0])
print(result[1])
|
s590744531
|
Accepted
| 30
| 7,808
| 525
|
def inputInline():
N=int(input())
numbers=list(map(int,input().split(" ")))
return numbers
def bubbleSort(list):
N=len(list)
count=0
flag=True
while flag:
flag=False
for i in range(N-1):
if list[i]>list[i+1]:
temp=list[i]
list[i]=list[i+1]
list[i+1]=temp
flag=True
count+=1
return (list,count)
result=bubbleSort(inputInline())
print(" ".join(list(map(str,result[0]))))
print(result[1])
|
s033216214
|
p03338
|
u296013568
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 177
|
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
|
s = "abdcfmekdssldjglle"
l = []
for i in range(len(s)):
x = s[:i]
y = s[i:]
t = 0
for j in x:
if j in y:
t += 1
l.append(t)
print(max(l))
|
s565808336
|
Accepted
| 18
| 3,188
| 351
|
n = int(input())
s = list(input())
l = []
for i in range(len(s)):
x = set(s[:i])
y = set(s[i:])
li = list((x & y))
for i in li:
if li.count(i) >= 2:
while True:
if li.count(i) == 1:
break
else :
li.remove(i)
l.append(len(li))
print(max(l))
|
s594366976
|
p02400
|
u655518263
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,488
| 81
|
Write a program which calculates the area and circumference of a circle for given radius r.
|
import math
r = float(input())
pi = math.pi
a = 2*pi*r
b = pi*r**2
print(a,b)
|
s372264033
|
Accepted
| 30
| 7,608
| 99
|
import math
r = float(input())
pi = math.pi
a = pi*r**2
b = 2*pi*r
print(round(a,6),round(b,6))
|
s346449585
|
p03729
|
u698771758
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 70
|
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
|
a,b,c=input().split()
print(["No","Yes"][a[-1]==b[0] and b[-1]==c[0]])
|
s582184911
|
Accepted
| 17
| 2,940
| 70
|
a,b,c=input().split()
print(["NO","YES"][a[-1]==b[0] and b[-1]==c[0]])
|
s697314678
|
p03471
|
u915355756
| 2,000
| 262,144
|
Wrong Answer
| 1,917
| 3,064
| 367
|
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
|
[N,Y] = list(map(int,input().split()))
x = [0,0,0]
x[0] = Y//10000
x[1] = (Y - (10000*x[0]))//5000
x[2] = (Y - (10000*x[0]) - (5000*x[1]))//1000
ans = [-1,-1,-1]
for i in range(x[0]+1):
for j in range(x[1]+(2*i)+1):
N_temp = (x[0]-i) + (x[1]+2*i-j) + (x[2]+5*j)
if N_temp == N:
ans = [(x[0]-i) , ((x[1]+2*i-j)) , (x[2]+5*j)]
print(ans)
|
s197029313
|
Accepted
| 38
| 3,064
| 514
|
[N,Y] = list(map(int,input().split()))
x = [0,0,0]
x[0] = Y//10000
x[1] = (Y - (10000*x[0]))//5000
x[2] = (Y - (10000*x[0]) - (5000*x[1]))//1000
ans = [-1,-1,-1]
for i in range(x[0]+1):
for j in range(x[1]+(2*i)+1):
N_temp = (x[0]-i) + (x[1]+2*i-j) + (x[2]+5*j)
if N_temp == N:
ans = [(x[0]-i) , ((x[1]+2*i-j)) , (x[2]+5*j)]
print('{0[0]} {0[1]} {0[2]}'.format(ans))
exit()
elif N_temp > N:
break
print('{0[0]} {0[1]} {0[2]}'.format(ans))
|
s530261736
|
p03999
|
u713539685
| 2,000
| 262,144
|
Wrong Answer
| 28
| 3,060
| 184
|
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
|
s=input()
count=0
for i in range(2**(len(s)-1)):
t=""
for j in s:
t+=j
if i%2==1:
t+="+"
i//=2
print(t)
count+=eval(t)
print(count)
|
s007707956
|
Accepted
| 27
| 2,940
| 185
|
s=input()
count=0
for i in range(2**(len(s)-1)):
t=""
for j in s:
t+=j
if i%2==1:
t+="+"
i//=2
#print(t)
count+=eval(t)
print(count)
|
s643653111
|
p03827
|
u521866787
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 114
|
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
|
_=input()
s=input()
x=0
maxn=0
for i in s:
if i == 'I':
x+=0
else:
x-=0
maxn=max(maxn,x)
print(maxn)
|
s550233396
|
Accepted
| 17
| 2,940
| 114
|
_=input()
s=input()
x=0
maxn=0
for i in s:
if i == 'I':
x+=1
else:
x-=1
maxn=max(maxn,x)
print(maxn)
|
s529850460
|
p02613
|
u243061947
| 2,000
| 1,048,576
|
Wrong Answer
| 145
| 9,200
| 241
|
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
N = int(input())
judge = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for i in range(N):
judge[input()] += 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']))
|
s466132052
|
Accepted
| 144
| 9,200
| 241
|
N = int(input())
judge = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for i in range(N):
judge[input()] += 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']))
|
s042758357
|
p03008
|
u671861352
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,064
| 360
|
The squirrel Chokudai has N acorns. One day, he decides to do some trades in multiple precious metal exchanges to make more acorns. His plan is as follows: 1. Get out of the nest with N acorns in his hands. 2. Go to Exchange A and do some trades. 3. Go to Exchange B and do some trades. 4. Go to Exchange A and do some trades. 5. Go back to the nest. In Exchange X (X = A, B), he can perform the following operations any integer number of times (possibly zero) in any order: * Lose g_{X} acorns and gain 1 gram of gold. * Gain g_{X} acorns and lose 1 gram of gold. * Lose s_{X} acorns and gain 1 gram of silver. * Gain s_{X} acorns and lose 1 gram of silver. * Lose b_{X} acorns and gain 1 gram of bronze. * Gain b_{X} acorns and lose 1 gram of bronze. Naturally, he cannot perform an operation that would leave him with a negative amount of acorns, gold, silver, or bronze. What is the maximum number of acorns that he can bring to the nest? Note that gold, silver, or bronze brought to the nest would be worthless because he is just a squirrel.
|
N = int(input())
A = [int(e) for e in input().split()]
B = [int(e) for e in input().split()]
r = {}
for i in range(3):
(a, b) = (A[i], B[i])
if a > b:
r[a / b] = b
elif b > a:
r[b / a] = a
s = 0
for k, v in sorted(r.items(), key=lambda x: -x[0]):
n = int(N / v) * k
s += n
N -= n
if N == 0:
break
print(s)
|
s035876841
|
Accepted
| 26
| 3,192
| 1,532
|
import math
import sys
N = int(input())
GA, SA, BA = list(map(int, input().split()))
GB, SB, BB = list(map(int, input().split()))
def knapsack(n, ga, sa, ba, gb, sb, bb):
values = []
weights = []
if gb / ga > 1:
values.append(gb - ga)
weights.append(ga)
if sb / sa > 1:
values.append(sb - sa)
weights.append(sa)
if bb / ba > 1:
values.append(bb - ba)
weights.append(ba)
if len(values) == 3:
dp = [0] * (n + 1)
dp[0] = n
for i in range(1, n + 1):
x = dp[i - 1]
for w, v in zip(weights, values):
if i - w >= 0:
x = max(x, dp[i - w] + v)
dp[i] = x
return dp[n]
if len(values) == 2:
w1, w2 = weights
v1, v2 = values
if (v1 + w1) / w1 < (v2 + w2) / w2:
v1, v2 = v2, v1
w1, w2 = w2, w1
c1 = n // w1
c2 = (n - w1 * c1) // w2
ret = n + v1 * c1 + v2 * c2
while c1 >= 0:
a = n - w1 * c1 - w2 * c2
c1 -= max(1, math.ceil((w2 - a) / w1))
c2 = (n - w1 * c1) // w2
ret = max(ret, n + v1 * c1 + v2 * c2)
if w1 * c1 + w2 * c2 == n:
break
return ret
if len(values) == 1:
return n + n // weights[0] * values[0]
return n
ans = knapsack(N, GA, SA, BA, GB, SB, BB)
ans = knapsack(ans, GB, SB, BB, GA, SA, BA)
print(int(ans))
|
s325292208
|
p03998
|
u464912173
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 354
|
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
|
A = list(input())
B = list(input())
C = list(input())
X = 'a'
while True:
if X == 'a':
if len(A)==0:
print('a')
exit()
else:
X = A.pop(0)
elif X == 'b':
if len(B)==0:
print('b')
exit()
else:
X = B.pop(0)
elif X == 'c':
if len(C)==0:
print('c')
exit()
else:
X = C.pop(0)
|
s554525745
|
Accepted
| 17
| 3,064
| 354
|
A = list(input())
B = list(input())
C = list(input())
X = 'a'
while True:
if X == 'a':
if len(A)==0:
print('A')
exit()
else:
X = A.pop(0)
elif X == 'b':
if len(B)==0:
print('B')
exit()
else:
X = B.pop(0)
elif X == 'c':
if len(C)==0:
print('C')
exit()
else:
X = C.pop(0)
|
s168192033
|
p03160
|
u910632349
| 2,000
| 1,048,576
|
Wrong Answer
| 130
| 20,704
| 183
|
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.
|
n=int(input())
h=list(map(int,input().split()))
DP=[0]*n
DP[0]=0
DP[1]=abs(h[0]-h[1])
for i in range(n-2):
DP[i+2]=min(DP[i]+abs(h[i]-h[i+2]),DP[i+1]+abs(h[i+2]-h[i+1]))
print(DP)
|
s149389382
|
Accepted
| 122
| 20,276
| 179
|
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(n-2):
dp[i+2]=min(dp[i+1]+abs(h[i+2]-h[i+1]),dp[i]+abs(h[i+2]-h[i]))
print(dp[-1])
|
s347686841
|
p03160
|
u335278042
| 2,000
| 1,048,576
|
Wrong Answer
| 127
| 13,888
| 219
|
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
N = int(input())
lis = [int(i) for i in sys.stdin.readline().split()]
x_1,x_2 = 0,0
for i in range(2,N):
tmp = min(abs(lis[i]-lis[i-1]) + x_1,abs(lis[i] - lis[i-2]) + x_2)
x_1,x_2 = tmp,x_1
print(x_1)
|
s807292263
|
Accepted
| 155
| 13,888
| 259
|
import sys
N = int(input())
lis = [int(i) for i in sys.stdin.readline().split()]
res = [0,abs(lis[1]-lis[0])]
for i in range(2,N):
tmp = min(abs(lis[i]-lis[i-1]) + res[-1],abs(lis[i] - lis[i-2]) + res[-2])
res.append(tmp)
res.pop(0)
print(res[-1])
|
s782816412
|
p03471
|
u648901783
| 2,000
| 262,144
|
Wrong Answer
| 24
| 3,064
| 544
|
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
|
n,y= map(int,input().split())
f = [False]
#binary_search
def binary_search(x,r):
l = 0
while(r-l>=1):
i = int((l+r)/2)
# print(i)
if(4000*i==x):
f[0] = True
return i
elif(i<x):
l=i+1
else:
r = i
return 0
for a in range(0,n+1):
if f[0]==True:
break
b = int(binary_search(y-9000*a-1000*n,n-a+1))
if f[0] == True:
print(a,b,n-a-b)
break
if f[0]==False:
print(-1,-1,-1)
|
s684331847
|
Accepted
| 765
| 3,060
| 315
|
n,y = map(int,input().split())
bool = False
answer=[0,0,0]
for a in range(0,n+1):
for b in range(0,n-a+1):
c = n-a-b
if 10000*a+5000*b+1000*c==y:
answer=[a,b,c]
bool=True
if bool==False:
print(-1, -1, -1)
if bool==True:
print(answer[0], answer[1], answer[2])
|
s012630449
|
p03478
|
u024768467
| 2,000
| 262,144
|
Wrong Answer
| 35
| 3,628
| 339
|
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
n,a,b=map(int,input().split())
def find_sum_of_digits(n):
sum = 0
int(n)
while n > 0:
sum += n % 10
n //= 10
return sum
total = 0
for i in range(1, n+1):
sum_of_digits_tmp = find_sum_of_digits(i)
print(sum_of_digits_tmp)
if a <= sum_of_digits_tmp and sum_of_digits_tmp <= b:
total += i
|
s648460326
|
Accepted
| 27
| 3,060
| 327
|
n,a,b=map(int,input().split())
def find_sum_of_digits(n):
sum = 0
int(n)
while n > 0:
sum += n % 10
n //= 10
return sum
total = 0
for i in range(1, n+1):
sum_of_digits_tmp = find_sum_of_digits(i)
if a <= sum_of_digits_tmp and sum_of_digits_tmp <= b:
total += i
print(total)
|
s690297007
|
p03385
|
u777394984
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 100
|
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
|
a = input()
if a.find("a")>0 and a.find("b")>0 and a.find("c")>0:
print("Yes")
else:
print("No")
|
s275752428
|
Accepted
| 18
| 2,940
| 100
|
a=input()
if a.find("a")>=0and a.find("b")>=0and a.find("c")>=0:
print("Yes")
else:
print("No")
|
s175396349
|
p02399
|
u698693989
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,668
| 181
|
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
|
a,b=map(int,input().split())
d = a // b
r = a % b
f = float(a) / b
l=[d,r,f]
print("{0} {1} {2}".format(l[0],l[1],l[2]))
|
s520613556
|
Accepted
| 20
| 5,608
| 105
|
num=input().split()
a=int(num[0])
b=int(num[1])
d=a//b
r=a%b
f=float(a/b)
print(d,r,"{:.5f}".format(f))
|
s180670026
|
p02833
|
u078816252
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 136
|
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
|
n = input()
test = len(n)
n = int(n)
print(test)
b = 0
if n % 2 == 0:
for i in range(1,test+11):
b = b + (n//(5**(i)))//2
print(b)
|
s051027941
|
Accepted
| 17
| 2,940
| 125
|
n = input()
test = len(n)
n = int(n)
b = 0
if n % 2 == 0:
for i in range(1,test+11):
b = b + (n//(5**(i)))//2
print(b)
|
s833005857
|
p03957
|
u104930676
| 1,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 170
|
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.
|
import sys
s = input()
for i, c in enumerate(s):
if c == 'F':
for j in s[i:]:
if j=='C':
print('Yes')
sys.exit()
print('No')
sys.exit()
|
s995444190
|
Accepted
| 17
| 2,940
| 182
|
import sys
s = input()
for i, c in enumerate(s):
if c == 'C':
for j in s[i:]:
if j=='F':
print('Yes')
sys.exit()
print('No')
sys.exit()
print('No')
|
s300427177
|
p03473
|
u602677143
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,068
| 22
|
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
|
print(int(input())-48)
|
s697469474
|
Accepted
| 17
| 2,940
| 24
|
print(48 - int(input()))
|
s510976080
|
p02566
|
u334712262
| 5,000
| 1,048,576
|
Wrong Answer
| 2,797
| 97,388
| 5,991
|
You are given a string of length N. Calculate the number of distinct substrings of S.
|
class StrAlg:
@staticmethod
def sa_naive(s):
n = len(s)
sa = list(range(n))
sa.sort(key=lambda x: s[x:])
return sa
@staticmethod
def sa_doubling(s):
n = len(s)
sa = list(range(n))
rnk = s
tmp = [0] * n
k = 1
while k < n:
sa.sort(key=lambda x: (rnk[x], rnk[x + k])
if x + k < n else (rnk[x], -1))
tmp[sa[0]] = 0
for i in range(1, n):
tmp[sa[i]] = tmp[sa[i - 1]]
if sa[i - 1] + k < n:
x = (rnk[sa[i - 1]], rnk[sa[i - 1] + k])
else:
x = (rnk[sa[i - 1]], -1)
if sa[i] + k < n:
y = (rnk[sa[i]], rnk[sa[i] + k])
else:
y = (rnk[sa[i]], -1)
if x < y:
tmp[sa[i]] += 1
k *= 2
tmp, rnk = rnk, tmp
return sa
@staticmethod
def sa_is(s, upper):
n = len(s)
if n == 0:
return []
if n == 1:
return [0]
if n == 2:
if s[0] < s[1]:
return [0, 1]
else:
return [1, 0]
if n < 10:
return StrAlg.sa_naive(s)
if n < 50:
return StrAlg.sa_doubling(s)
ls = [0] * n
for i in range(n - 1)[::-1]:
ls[i] = ls[i + 1] if s[i] == s[i + 1] else s[i] < s[i + 1]
sum_l = [0] * (upper + 1)
sum_s = [0] * (upper + 1)
for i in range(n):
if ls[i]:
sum_l[s[i] + 1] += 1
else:
sum_s[s[i]] += 1
for i in range(upper):
sum_s[i] += sum_l[i]
if i < upper:
sum_l[i + 1] += sum_s[i]
lms_map = [-1] * (n + 1)
m = 0
for i in range(1, n):
if not ls[i - 1] and ls[i]:
lms_map[i] = m
m += 1
lms = []
for i in range(1, n):
if not ls[i - 1] and ls[i]:
lms.append(i)
sa = [-1] * n
buf = sum_s.copy()
for d in lms:
if d == n:
continue
sa[buf[s[d]]] = d
buf[s[d]] += 1
buf = sum_l.copy()
sa[buf[s[n - 1]]] = n - 1
buf[s[n - 1]] += 1
for i in range(n):
v = sa[i]
if v >= 1 and not ls[v - 1]:
sa[buf[s[v - 1]]] = v - 1
buf[s[v - 1]] += 1
buf = sum_l.copy()
for i in range(n)[::-1]:
v = sa[i]
if v >= 1 and ls[v - 1]:
buf[s[v - 1] + 1] -= 1
sa[buf[s[v - 1] + 1]] = v - 1
if m:
sorted_lms = []
for v in sa:
if lms_map[v] != -1:
sorted_lms.append(v)
rec_s = [0] * m
rec_upper = 0
rec_s[lms_map[sorted_lms[0]]] = 0
for i in range(1, m):
l = sorted_lms[i - 1]
r = sorted_lms[i]
end_l = lms[lms_map[l] + 1] if lms_map[l] + 1 < m else n
end_r = lms[lms_map[r] + 1] if lms_map[r] + 1 < m else n
same = True
if end_l - l != end_r - r:
same = False
else:
while l < end_l:
if s[l] != s[r]:
break
l += 1
r += 1
if l == n or s[l] != s[r]:
same = False
if not same:
rec_upper += 1
rec_s[lms_map[sorted_lms[i]]] = rec_upper
rec_sa = StrAlg.sa_is(rec_s, rec_upper)
for i in range(m):
sorted_lms[i] = lms[rec_sa[i]]
sa = [-1] * n
buf = sum_s.copy()
for d in sorted_lms:
if d == n:
continue
sa[buf[s[d]]] = d
buf[s[d]] += 1
buf = sum_l.copy()
sa[buf[s[n - 1]]] = n - 1
buf[s[n - 1]] += 1
for i in range(n):
v = sa[i]
if v >= 1 and not ls[v - 1]:
sa[buf[s[v - 1]]] = v - 1
buf[s[v - 1]] += 1
buf = sum_l.copy()
for i in range(n)[::-1]:
v = sa[i]
if v >= 1 and ls[v - 1]:
buf[s[v - 1] + 1] -= 1
sa[buf[s[v - 1] + 1]] = v - 1
return sa
@staticmethod
def suffix_array(s, upper=255):
if type(s) is str:
s = [ord(c) for c in s]
return StrAlg.sa_is(s, upper)
@staticmethod
def lcp_array(s, sa):
n = len(s)
rnk = [0] * n
for i in range(n):
rnk[sa[i]] = i
lcp = [0] * (n - 1)
h = 0
for i in range(n):
if h > 0:
h -= 1
if rnk[i] == 0:
continue
j = sa[rnk[i] - 1]
while j + h < n and i + h < n:
if s[j + h] != s[i + h]:
break
h += 1
lcp[rnk[i] - 1] = h
return lcp
@staticmethod
def z_algorithm(s):
n = len(s)
if n == 0:
return []
z = [0] * n
j = 0
for i in range(1, n):
z[i] = 0 if j + z[j] <= i else min(j + z[j] - i, z[i - j])
while i + z[i] < n and s[z[i]] == s[i + z[i]]:
z[i] += 1
if j + z[j] < i + z[i]:
j = i
z[0] = n
return z
def atcoder_practice2_i():
S = input()
n = len(S)
ans = (n+1)*n // 2
sa = StrAlg.suffix_array(S)
ans -= sum(StrAlg.lcp_array(S, sa))
print(StrAlg.z_algorithm(S))
print(ans)
if __name__ == "__main__":
atcoder_practice2_i()
|
s023832340
|
Accepted
| 2,592
| 97,520
| 5,958
|
class StrAlg:
@staticmethod
def sa_naive(s):
n = len(s)
sa = list(range(n))
sa.sort(key=lambda x: s[x:])
return sa
@staticmethod
def sa_doubling(s):
n = len(s)
sa = list(range(n))
rnk = s
tmp = [0] * n
k = 1
while k < n:
sa.sort(key=lambda x: (rnk[x], rnk[x + k])
if x + k < n else (rnk[x], -1))
tmp[sa[0]] = 0
for i in range(1, n):
tmp[sa[i]] = tmp[sa[i - 1]]
if sa[i - 1] + k < n:
x = (rnk[sa[i - 1]], rnk[sa[i - 1] + k])
else:
x = (rnk[sa[i - 1]], -1)
if sa[i] + k < n:
y = (rnk[sa[i]], rnk[sa[i] + k])
else:
y = (rnk[sa[i]], -1)
if x < y:
tmp[sa[i]] += 1
k *= 2
tmp, rnk = rnk, tmp
return sa
@staticmethod
def sa_is(s, upper):
n = len(s)
if n == 0:
return []
if n == 1:
return [0]
if n == 2:
if s[0] < s[1]:
return [0, 1]
else:
return [1, 0]
if n < 10:
return StrAlg.sa_naive(s)
if n < 50:
return StrAlg.sa_doubling(s)
ls = [0] * n
for i in range(n - 1)[::-1]:
ls[i] = ls[i + 1] if s[i] == s[i + 1] else s[i] < s[i + 1]
sum_l = [0] * (upper + 1)
sum_s = [0] * (upper + 1)
for i in range(n):
if ls[i]:
sum_l[s[i] + 1] += 1
else:
sum_s[s[i]] += 1
for i in range(upper):
sum_s[i] += sum_l[i]
if i < upper:
sum_l[i + 1] += sum_s[i]
lms_map = [-1] * (n + 1)
m = 0
for i in range(1, n):
if not ls[i - 1] and ls[i]:
lms_map[i] = m
m += 1
lms = []
for i in range(1, n):
if not ls[i - 1] and ls[i]:
lms.append(i)
sa = [-1] * n
buf = sum_s.copy()
for d in lms:
if d == n:
continue
sa[buf[s[d]]] = d
buf[s[d]] += 1
buf = sum_l.copy()
sa[buf[s[n - 1]]] = n - 1
buf[s[n - 1]] += 1
for i in range(n):
v = sa[i]
if v >= 1 and not ls[v - 1]:
sa[buf[s[v - 1]]] = v - 1
buf[s[v - 1]] += 1
buf = sum_l.copy()
for i in range(n)[::-1]:
v = sa[i]
if v >= 1 and ls[v - 1]:
buf[s[v - 1] + 1] -= 1
sa[buf[s[v - 1] + 1]] = v - 1
if m:
sorted_lms = []
for v in sa:
if lms_map[v] != -1:
sorted_lms.append(v)
rec_s = [0] * m
rec_upper = 0
rec_s[lms_map[sorted_lms[0]]] = 0
for i in range(1, m):
l = sorted_lms[i - 1]
r = sorted_lms[i]
end_l = lms[lms_map[l] + 1] if lms_map[l] + 1 < m else n
end_r = lms[lms_map[r] + 1] if lms_map[r] + 1 < m else n
same = True
if end_l - l != end_r - r:
same = False
else:
while l < end_l:
if s[l] != s[r]:
break
l += 1
r += 1
if l == n or s[l] != s[r]:
same = False
if not same:
rec_upper += 1
rec_s[lms_map[sorted_lms[i]]] = rec_upper
rec_sa = StrAlg.sa_is(rec_s, rec_upper)
for i in range(m):
sorted_lms[i] = lms[rec_sa[i]]
sa = [-1] * n
buf = sum_s.copy()
for d in sorted_lms:
if d == n:
continue
sa[buf[s[d]]] = d
buf[s[d]] += 1
buf = sum_l.copy()
sa[buf[s[n - 1]]] = n - 1
buf[s[n - 1]] += 1
for i in range(n):
v = sa[i]
if v >= 1 and not ls[v - 1]:
sa[buf[s[v - 1]]] = v - 1
buf[s[v - 1]] += 1
buf = sum_l.copy()
for i in range(n)[::-1]:
v = sa[i]
if v >= 1 and ls[v - 1]:
buf[s[v - 1] + 1] -= 1
sa[buf[s[v - 1] + 1]] = v - 1
return sa
@staticmethod
def suffix_array(s, upper=255):
if type(s) is str:
s = [ord(c) for c in s]
return StrAlg.sa_is(s, upper)
@staticmethod
def lcp_array(s, sa):
n = len(s)
rnk = [0] * n
for i in range(n):
rnk[sa[i]] = i
lcp = [0] * (n - 1)
h = 0
for i in range(n):
if h > 0:
h -= 1
if rnk[i] == 0:
continue
j = sa[rnk[i] - 1]
while j + h < n and i + h < n:
if s[j + h] != s[i + h]:
break
h += 1
lcp[rnk[i] - 1] = h
return lcp
@staticmethod
def z_algorithm(s):
n = len(s)
if n == 0:
return []
z = [0] * n
j = 0
for i in range(1, n):
z[i] = 0 if j + z[j] <= i else min(j + z[j] - i, z[i - j])
while i + z[i] < n and s[z[i]] == s[i + z[i]]:
z[i] += 1
if j + z[j] < i + z[i]:
j = i
z[0] = n
return z
def atcoder_practice2_i():
S = input()
n = len(S)
ans = (n+1)*n // 2
sa = StrAlg.suffix_array(S)
ans -= sum(StrAlg.lcp_array(S, sa))
print(ans)
if __name__ == "__main__":
atcoder_practice2_i()
|
s008842458
|
p03485
|
u653485478
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 97
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
a,b = map(int,input().split())
x = a + b
if x % 2 == 0:
x = x/2
else:
x = (x+1)/2
print(x)
|
s430170663
|
Accepted
| 17
| 2,940
| 99
|
a,b = map(int,input().split())
x = a + b
if x % 2 == 0:
x = x//2
else:
x = (x+1)//2
print(x)
|
s324679613
|
p03485
|
u897302879
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 62
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
a, b = map(int, input().split())
print((a + b)/ 2 + (a+b) % 2)
|
s608415202
|
Accepted
| 17
| 2,940
| 67
|
a, b = map(int, input().split())
print(int((a + b)/ 2) + (a+b) % 2)
|
s624741308
|
p04029
|
u904804404
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 50
|
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
print((lambda x: int(x)*(int(x)+1)/2)( input()))
|
s296284618
|
Accepted
| 18
| 2,940
| 51
|
print((lambda x: int(x)*(int(x)+1)//2)( input()))
|
s472674272
|
p03409
|
u604839890
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,120
| 283
|
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
|
n=int(input())
R=sorted([list(map(int,input().split())) for i in range(n)], key=lambda R: -R[1])
B=sorted([list(map(int,input().split())) for i in range(n)])
print(R)
print(B)
ans=0
for c,d in B:
for a,b in R:
if a<c and b<d:
R.remove([a,b]);ans+=1
break
print(ans)
|
s568574049
|
Accepted
| 27
| 9,132
| 265
|
n=int(input())
R=sorted([list(map(int,input().split())) for i in range(n)], key=lambda R: -R[1])
B=sorted([list(map(int,input().split())) for i in range(n)])
ans=0
for c,d in B:
for a,b in R:
if a<c and b<d:
R.remove([a,b]);ans+=1
break
print(ans)
|
s952433906
|
p02850
|
u104282757
| 2,000
| 1,048,576
|
Wrong Answer
| 822
| 59,328
| 711
|
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.
|
from collections import deque
n = int(input())
g = {i: dict() for i in range(n)}
a_list = [0] * (n - 1)
b_list = [0] * (n - 1)
for i in range(n - 1):
a, b = map(int, input().split())
a_list[i] = a - 1
b_list[i] = b - 1
g[a - 1][b - 1] = -1
g[b - 1][a - 1] = -1
k = max([len(g[a]) for a in range(n)])
used_color = [-1] * n
# BFS
queue = deque([0])
while len(queue) > 0:
p = queue.popleft()
c = used_color[p]
for q in g[p].keys():
if used_color[q] != -1:
continue
c += 1
c %= k
g[p][q] = c
g[q][p] = c
used_color[q] = c
queue.append(q)
print(k)
for i in range(n - 1):
print(g[a_list[i]][b_list[i]] + 1)
|
s846229505
|
Accepted
| 653
| 59,280
| 1,327
|
from collections import deque
def solve(n, a_list, b_list):
# create graph
g = {i: dict() for i in range(n)}
for i in range(n - 1):
a, b = a_list[i] - 1, b_list[i] - 1
g[a][b] = -1
g[b][a] = -1
k = max([len(g[a]) for a in range(n)])
used_color = [-1] * n
used_color[0] = k - 1
# BFS
queue = deque([0])
while len(queue) > 0:
p = queue.popleft()
c = used_color[p]
for q in g[p].keys():
if used_color[q] != -1:
continue
c += 1
c %= k
g[p][q] = c
g[q][p] = c
used_color[q] = c
queue.append(q)
res_list = [0] * (n - 1)
for i in range(n - 1):
res_list[i] = g[a_list[i] - 1][b_list[i] - 1] + 1
return k, res_list
def main():
n = int(input())
a_list = [0] * (n - 1)
b_list = [0] * (n - 1)
for i in range(n - 1):
a, b = map(int, input().split())
a_list[i] = a
b_list[i] = b
k, res_list = solve(n, a_list, b_list)
print(k)
for i in range(n - 1):
print(res_list[i])
def test():
print(solve(3, [1, 2], [2, 3]))
print(solve(8, [1, 2, 2, 2, 4, 5, 6], [2, 3, 4, 5, 7, 6, 8]))
if __name__ == "__main__":
# test()
main()
|
s119093425
|
p02389
|
u679055873
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,652
| 56
|
Write a program which calculates the area and perimeter of a given rectangle.
|
y,z = map(int,input().split())
print(y*z)
print((y+z)*2)
|
s569447673
|
Accepted
| 30
| 7,644
| 61
|
y,z = map(int,input().split())
print((y*z),((y+z)*2),sep=' ')
|
s570827760
|
p02694
|
u468663659
| 2,000
| 1,048,576
|
Wrong Answer
| 49
| 9,248
| 113
|
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())
now = 100
year = 0
while now < X:
X *= 1.01
#X = int(X)
X -= X%1
year += 1
print(year)
|
s506610883
|
Accepted
| 23
| 9,124
| 120
|
X = int(input())
now = 100
year = 0
while now < X:
now *= 1.01
#X = int(X)
now -= now%1
year += 1
print(year)
|
s717384747
|
p03485
|
u352706022
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 60
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
a, b = map(int, input().split())
x = (a + b - 1)/ b
print(x)
|
s189499529
|
Accepted
| 17
| 2,940
| 56
|
a, b = map(int, input().split())
print((a + b + 1) // 2)
|
s248670868
|
p03359
|
u112567325
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 77
|
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
|
A,B = list(map(int,input().split()))
if A < B:
print(A)
else:
print(A-1)
|
s236498992
|
Accepted
| 17
| 2,940
| 78
|
A,B = list(map(int,input().split()))
if A <= B:
print(A)
else:
print(A-1)
|
s408118180
|
p03854
|
u062306892
| 2,000
| 262,144
|
Wrong Answer
| 23
| 3,828
| 155
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
import re
s = input()
re.sub("dream", '', s)
re.sub("dreamer", '', s)
re.sub("erase", '', s)
re.sub("eraser", '', s)
print('YES 'if len(s) == 0 else 'NO')
|
s513016685
|
Accepted
| 22
| 3,572
| 171
|
import re
s = input()
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
print('YES' if len(s) == 0 else 'NO')
|
s857699709
|
p02741
|
u661343770
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 143
|
Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
|
inp = int(input())
lis = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(lis[inp%32])
|
s933985072
|
Accepted
| 17
| 2,940
| 150
|
inp = int(input())
lis = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(lis[(inp-1) % 32])
|
s588746131
|
p02389
|
u279955105
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,496
| 91
|
Write a program which calculates the area and perimeter of a given rectangle.
|
a,b = list(map(int, input().split()))
c = 2 * (a+ b)
d = a * b
print(str(c) + " " + str(d))
|
s736106407
|
Accepted
| 20
| 5,592
| 114
|
Input = input().split()
a = int(Input[0])
b = int(Input[1])
Area = a*b
Rectangle = (a+b)*2
print(Area, Rectangle)
|
s899545790
|
p03475
|
u053250918
| 3,000
| 262,144
|
Wrong Answer
| 80
| 3,064
| 367
|
A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
|
N = int(input())
grid = [list(map(int, input().split())) for _ in range(N-1)]
C = [c[0] for c in grid]
S = [s[1] for s in grid]
F = [f[2] for f in grid]
T = []
for n in range(N):
t = 0
for i in range(n, N-1):
if S[i] >= t:
d = S[i] - t + C[i]
else:
d = ((t - S[i])%F[i]) + C[i]
t += d
T.append(t)
print(T)
|
s596178411
|
Accepted
| 99
| 3,188
| 485
|
N = int(input())
grid = [list(map(int, input().split())) for _ in range(N-1)]
C = [c[0] for c in grid]
S = [s[1] for s in grid]
F = [f[2] for f in grid]
T = []
for n in range(N):
t = 0
for i in range(n, N-1):
if S[i] >= t:
d = S[i] - t + C[i]
else:
temp = (t - S[i])%F[i]
if temp == 0:
d = C[i]
else:
d = F[i] - temp + C[i]
t += d
T.append(t)
for t in T:
print(t)
|
s509000932
|
p03494
|
u951145045
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,206
| 8,900
| 312
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
n=int(input())
flag=0
nums=list(map(int,input().split()))
cnt=0
while flag==0:
for i in range(n):
num=nums[0]/2
key=nums[0]%2
if key==1:
flag==1
break
else:
del nums[0]
nums.append(num)
if flag==0:
cnt+=1
print(cnt)
|
s052824594
|
Accepted
| 25
| 9,260
| 313
|
n=int(input())
nums=list(map(int,input().split()))
cnt=0
flag=0
while flag is 0:
for i in range(n):
num=nums[0]/2
key=nums[0]%2
if key==1:
flag=1
break
else:
del nums[0]
nums.append(num)
if flag==0:
cnt+=1
print(cnt)
|
s649636708
|
p03455
|
u586305367
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 100
|
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%2 == 0 and b%2 == 0:
print('Even')
else:
print('Odd')
|
s860762210
|
Accepted
| 17
| 2,940
| 99
|
a, b = map(int, input().split())
if a%2 == 0 or b%2 == 0:
print('Even')
else:
print('Odd')
|
s589271620
|
p03448
|
u794910686
| 2,000
| 262,144
|
Wrong Answer
| 2,108
| 13,988
| 139
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
|
import numpy as np
input()
A = np.array(list(map(int, input().split())))
ans = 0
while(all(A%2==0)):
A = A/2
ans += 1
print(ans)
|
s539078269
|
Accepted
| 49
| 3,060
| 226
|
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
for b in range(B+1):
for c in range(C+1):
if a*500+b*100+c*50 == X:
ans += 1
print(ans)
|
s271887328
|
p02613
|
u741256380
| 2,000
| 1,048,576
|
Wrong Answer
| 160
| 17,556
| 314
|
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.
|
#! python3
# coding:utf-8
n = int(input())
s = [input() for _ in range(n)]
print(s)
c0=0
c1=0
c2=0
c3=0
for i in s:
if i == "AC":
c0+=1
elif i == "WA":
c1+=1
elif i == "TLE":
c2+=1
else:
c3+=1
print("AC x",c0)
print("WA x",c1)
print("TLE x",c2)
print("RE x",c3)
|
s832776802
|
Accepted
| 146
| 16,336
| 316
|
#! python3
# coding:utf-8
n = int(input())
s = [input() for _ in range(n)]
# print(s)
c0=0
c1=0
c2=0
c3=0
for i in s:
if i == "AC":
c0+=1
elif i == "WA":
c1+=1
elif i == "TLE":
c2+=1
else:
c3+=1
print("AC x",c0)
print("WA x",c1)
print("TLE x",c2)
print("RE x",c3)
|
s831231767
|
p03645
|
u706884679
| 2,000
| 262,144
|
Wrong Answer
| 2,107
| 51,748
| 263
|
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
|
N, M = map(int, input().split())
c = []
for i in range(M):
c.append(list(map(int, input().split())))
for i in range(M):
if c[i][0] == 1:
for j in range(M):
if c[j][0] == c[i][0]:
if c[j][1] == N:
print('POSSIBLE')
exit()
print('IMPOSSIBLE')
|
s014358320
|
Accepted
| 794
| 61,164
| 318
|
N, M = map(int, input().split())
c = []
for i in range(M):
c.append(list(map(int, input().split())))
d = []
e = []
for i in range(M):
if c[i][0] == 1:
d.append(c[i][1])
for i in range(M):
if c[i][1] == N:
e.append(c[i][0])
l = list(set(d) & set(e))
if l == []:
print('IMPOSSIBLE')
else:
print('POSSIBLE')
|
s911768497
|
p03729
|
u114648678
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 88
|
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
|
a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
print('Yes')
else:
print('No')
|
s770713333
|
Accepted
| 17
| 2,940
| 89
|
a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
print('YES')
else:
print('NO')
|
s246161896
|
p03798
|
u018679195
| 2,000
| 262,144
|
Wrong Answer
| 247
| 5,708
| 1,832
|
Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
|
#!/usr/bin/env python3
n = int(input())
s = input()
t = []
l = []
for i in range(n):
t.append("S")
for i in range(n):
if i+1 <= n-1 and i != 0:
if (s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W"):
if t[i-1] == "S":
t[i+1] = "W"
else:
t[i+1] = "S"
else:
t[i+1] = t[i]
elif i == 0:
pass
else:
if ((s[i] == "x" and t[i] == "S") or (s[i] == "o" and t[i] == "W")) and t[0] == t[i-1]: t = "-1"
elif ((s[i] == "x" and t[i] == "W") or (s[i] == "o" and t[i] == "S")) and t[0] != t[i-1]: t = "-1"
elif ((s[0] == "o" and t[0] == "S") or (s[0] == "x" and t[0] == "W")) and t[1] != t[i]: t = "-1"
elif ((s[0] == "o" and t[0] == "W") or (s[0] == "x" and t[0] == "S")) and t[1] == t[i]: t = "-1"
for i in range(n):
l.append("W")
for i in range(n):
if i+1 <= n-1 and i != 0:
if (s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W"):
if l[i-1] == "S":
l[i+1] = "W"
else:
l[i+1] = "S"
else:
l[i+1] = l[i]
elif i == 0:
pass
else:
if(s[i] == "x" and l[i] == "S") or (s[i] == "o" and l[i] == "W") and l[0] == l[i-1]: l = "-1"
elif (s[i] == "x" and l[i] == "W") or (s[i] == "o" and l[i] == "S") and l[0] != l[i-1]: l = "-1"
elif ((s[0] == "o" and l[0] == "S") or (s[0] == "x" and l[0] == "W")) and l[1] != l[i]: l = "-1"
elif ((s[0] == "o" and l[0] == "W") or (s[0] == "x" and l[0] == "S")) and l[1] == l[i]: l = "-1"
if t != "-1" and l == "-1":
for i in t:
print(i,end ="")
elif t == "-1" and l != "-1":
for i in l:
print(i,end ="")
elif t == l:print("-1")
else:
for i in t:
print(i,end ="")
|
s149759810
|
Accepted
| 293
| 3,916
| 1,457
|
n = int(input())
s = input()
def addleave(p):
for i in range(1,n):
if s[i]=="o":
if p[i]=="S":
p += "S" if p[i-1]=="S" else "W"
else:
p += "W" if p[i-1]=="S" else "S"
else:
if p[i]=="S":
p += "W" if p[i-1]=="S" else "S"
else:
p += "S" if p[i-1]=="S" else "W"
return p
def solve():
result = addleave("SS")
if result[-1] == result[0]:
if check(result):
return result[:-1]
result = addleave("SW")
if result[-1] == result[0]:
if check(result):
return result[:-1]
result = addleave("WS")
if result[-1] == result[0]:
if check(result):
return result[:-1]
result = addleave("WW")
if result[-1] == result[0]:
if check(result):
return result[:-1]
return -1
def check(res):
res = res[:-1] + res[:-1] + res[:-1]
flag = True
for i in range(n):
if res[n + i - 1] == res[n + i + 1] and res[n + i]=="S" and s[i]=="o":
pass
elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="S" and s[i]=="x":
pass
elif res[n + i - 1] == res[n + i + 1] and res[n + i]=="W" and s[i]=="x":
pass
elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="W" and s[i]=="o":
pass
else:
flag = False
return flag
print(solve())
|
s605054229
|
p03997
|
u580904613
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 64
|
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(int(a*b*h/2))
|
s205146111
|
Accepted
| 17
| 2,940
| 66
|
a=int(input())
b=int(input())
h=int(input())
print(int((a+b)*h/2))
|
s633651399
|
p03163
|
u436173409
| 2,000
| 1,048,576
|
Wrong Answer
| 2,115
| 195,956
| 373
|
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
|
n,W = [int(e) for e in input().split()]
v = list([0]*n)
w = list([0]*n)
for i in range(n):
w[i],v[i] = [int(e) for e in input().split()]
dp = [[0]*(W+1) for _ in range(n)]
for i in range(n-1):
for j in range(W+1):
if w[i] <= j:
dp[i+1][j] = max(dp[i][j-w[i]] + v[i],dp[i][j])
else:
dp[i+1][j] = dp[i][j]
print(dp[n-1][W])
|
s047596884
|
Accepted
| 217
| 15,520
| 314
|
import numpy as np
n,W = [int(e) for e in input().split()]
v = np.zeros(n,dtype='int64')
w = np.zeros(n,dtype='int64')
for i in range(n):
w[i],v[i] = [int(e) for e in input().split()]
dp = np.zeros(W+1,dtype='int64')
for i in range(n):
dp[w[i]:] = np.maximum(dp[:W-w[i]+1]+v[i],dp[w[i]:])
print(dp[-1])
|
s628691925
|
p03607
|
u629350026
| 2,000
| 262,144
|
Wrong Answer
| 261
| 14,656
| 153
|
You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?
|
n=int(input())
temp=set()
for i in range(0,n):
a=int(input())
if a not in temp:
temp.add(str(a))
else:
temp.remove(str(a))
print(len(temp))
|
s754005195
|
Accepted
| 205
| 11,884
| 144
|
n=int(input())
temp=set()
for i in range(0,n):
a=int(input())
if a not in temp:
temp.add(a)
else:
temp.discard(a)
print(len(temp))
|
s504334421
|
p03455
|
u350909943
| 2,000
| 262,144
|
Wrong Answer
| 29
| 9,088
| 107
|
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())
num = a * b
mod = num % 2
if mod == 0:
print("EVEN")
else:
print("0dd")
|
s463391588
|
Accepted
| 23
| 9,044
| 80
|
a,b = map(int,input().split())
if a*b%2==0:
print("Even")
else:
print("Odd")
|
s077838880
|
p03644
|
u123310422
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 177
|
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
N = int(input())
li = [2**i for i in range(7)]
for i, x in enumerate(li, 1):
if N < li[len(li)-i]:
print(li[len(li)-i-1])
break
else:
continue
|
s964483418
|
Accepted
| 17
| 2,940
| 215
|
#!/usr/bin/env python3
N = int(input())
if N >= 64:
N = 64
elif N >= 32:
N = 32
elif N >= 16:
N = 16
elif N >= 8:
N = 8
elif N >= 4:
N = 4
elif N >= 2:
N = 2
elif N == 1:
N = 1
print(N)
|
s314479943
|
p03860
|
u405256066
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 45
|
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
|
s = list(input().split())[1]
print("A"+s+"C")
|
s583178214
|
Accepted
| 17
| 2,940
| 48
|
s = list(input().split())[1]
print("A"+s[0]+"C")
|
s320656105
|
p03456
|
u910295650
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 143
|
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
A=list(input().split())
for i in range(110):
if int(A[0]+A[1])==i**2:
ans='YES'
break
else:
ans='No'
print(ans)
|
s284741807
|
Accepted
| 17
| 3,060
| 73
|
c=int(input().replace(" ",""))
print("Yes" if c==int(c**.5)**2 else "No")
|
s137775544
|
p02694
|
u250828304
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 9,156
| 135
|
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
import sys
import math
X = int(input())
i = 1
k = int(100*1.01)
while 1:
if X < k:
break
k = int(k * 1.01)
i += 1
print(i)
|
s843577767
|
Accepted
| 21
| 9,128
| 136
|
import sys
import math
X = int(input())
i = 1
k = int(100*1.01)
while 1:
if X <= k:
break
k = int(k * 1.01)
i += 1
print(i)
|
s029273740
|
p03760
|
u477343425
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 67
|
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
|
o=list(input())
e=list(input())+[""]
for x,y in zip(o,e):print(x+y)
|
s743776712
|
Accepted
| 17
| 2,940
| 144
|
o = input()
e = input()
answer = ''
for s,t in zip(o,e):
answer += s
answer += t
if len(o) > len(e):
answer += o[-1]
print(answer)
|
s871167470
|
p02416
|
u661290476
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,644
| 37
|
Write a program which reads an integer and prints sum of its digits.
|
print(sum([int(i) for i in input()]))
|
s496487556
|
Accepted
| 20
| 7,580
| 90
|
while True:
s=input()
if s=="0":
break
print(sum([int(i) for i in s]))
|
s519716020
|
p02678
|
u197968862
| 2,000
| 1,048,576
|
Wrong Answer
| 425
| 45,060
| 100
|
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())
ab = [list(map(int,input().split())) for _ in range(m)]
print('No')
|
s085632845
|
Accepted
| 1,307
| 102,452
| 733
|
from collections import deque
n, m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
q = deque([])
path = [-1] * n
ver = [[] for _ in range(n)]
for i in range(m):
ab[i].sort()
if ab[i][0] == 1:
q.append([ab[i][0]-1,ab[i][1]-1])
#path[ab[i][1]-1] = 1
ver[ab[i][0]-1].append(ab[i][1]-1)
ver[ab[i][1]-1].append(ab[i][0]-1)
def bfs(q, visited_list):
while len(q) > 0:
now = q.popleft()
go = now[1]
if visited_list[go] == -1:
visited_list[go] = now[0]+1
for i in range(len(ver[go])):
q.append([go,ver[go][i]])
return visited_list
ans = bfs(q,path)
print('Yes')
for i in range(1,n):
print(ans[i])
|
s964983413
|
p03447
|
u129978636
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 124
|
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 = A - X
Dcount = X1 // B
Dprice = B * Dcount
print(X1 - Dprice)
|
s126854526
|
Accepted
| 17
| 3,064
| 79
|
X = int( input())
A = int( input())
B = int( input())
X1 = X -A
print(X1 % B)
|
s481514936
|
p03798
|
u457901067
| 2,000
| 262,144
|
Wrong Answer
| 192
| 5,500
| 851
|
Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
|
N = int(input())
ST = input()
pat = [(0,0),(0,1),(1,0),(1,1)]
fl = False
for p in pat:
ans = []
x_now = p[0]
x_prev = p[1]
ans.append(x_now)
for i in range(N):
if ST[i] == 'o':
if x_now == 0:
x_next = x_prev
else:
x_next = 1 - x_prev
else:
if x_now == 0:
x_next = 1 - x_prev
else:
x_next = x_prev
x_prev, x_now = x_now, x_next
ans.append(x_next)
#print(p, ans)
if ans[-1] == ans[0]:
#correct case
fl = True
break
if fl:
for i in range(N):
print("S" if ans[i] == 0 else "W", end="")
else:
print("-1")
|
s106195079
|
Accepted
| 257
| 5,480
| 949
|
N = int(input())
ST = input()
pat = [(0,0),(0,1),(1,0),(1,1)]
fl = False
for p in pat:
ans = []
x_now = p[0]
x_prev = p[1]
ans.append(x_now)
for i in range(N):
if ST[i] == 'o':
if x_now == 0:
x_next = x_prev
else:
x_next = 1 - x_prev
else:
if x_now == 0:
x_next = 1 - x_prev
else:
x_next = x_prev
#print(i, ST[i], x_prev, x_now, x_next)
ans.append(x_next)
x_prev, x_now = x_now, x_next
#if ans[-1] == ans[0]:
if ans[-2] == p[1] and ans[-1] == ans[0]:
#correct case
fl = True
#print(ans)
break
if fl:
for i in range(N):
print("S" if ans[i] == 0 else "W", end="")
print()
else:
print("-1")
|
s888507884
|
p02843
|
u802963389
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,060
| 244
|
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
|
# C - 100 to 105
x = int(input())
d, m = divmod(x, 100)
D = [0] * 5
for i in range(4, -1, -1):
D[i], m = divmod(m, i + 1)
print(D)
if d >= sum(D):
print(1)
else:
print(0)
|
s292157723
|
Accepted
| 17
| 3,060
| 234
|
# C - 100 to 105
x = int(input())
d, m = divmod(x, 100)
D = [0] * 5
for i in range(4, -1, -1):
D[i], m = divmod(m, i + 1)
if d >= sum(D):
print(1)
else:
print(0)
|
s479090115
|
p03997
|
u127856129
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 61
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a=int(input())
b=int(input())
c=int(input())
print((a+b)*c/2)
|
s878228743
|
Accepted
| 17
| 2,940
| 66
|
a=int(input())
b=int(input())
c=int(input())
print(int((a+b)*c/2))
|
s271215362
|
p02399
|
u956645355
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,676
| 118
|
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
|
n = list(map(int, input().split()))
a = n[0]
b = n[1]
d = a // b
r = a % b
f = a / b
print('{} {} {}'.format(d, r, f))
|
s297846624
|
Accepted
| 30
| 7,680
| 122
|
n = list(map(int, input().split()))
a = n[0]
b = n[1]
d = a // b
r = a % b
f = a / b
print('{} {} {:.5f}'.format(d, r, f))
|
s364846410
|
p02421
|
u514745787
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,656
| 231
|
Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in lexicographical order becomes the winner of that turn. The winner obtains 3 points. In the case of a draw, they obtain 1 point each. Write a program which reads a sequence of cards Taro and Hanako have and reports the final scores of the game.
|
n = int(input())
tarou = 0
hanako = 0
for x in range(n):
if hanako > tarou:
hanako += 3
elif tarou > hanako:
tarou += 3
else:
tarou += 1
hanako += 1
print("{0} {1}".format(tarou, hanako))
|
s864231837
|
Accepted
| 30
| 7,652
| 241
|
i = int(input())
tarou = 0
hanako = 0
for x in range(i):
a,b = input().split()
if b > a:
hanako += 3
elif a > b:
tarou += 3
else:
hanako += 1
tarou += 1
print("{0} {1}".format(tarou, hanako))
|
s962517667
|
p03090
|
u721047793
| 2,000
| 1,048,576
|
Wrong Answer
| 230
| 12,992
| 780
|
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.
|
# coding: utf-8
import numpy as np
from functools import lru_cache
import time
def main():
if True:
N = int(input())
else:
pass
T = np.asarray([False]*(N**2))
T = T.reshape(N,N)
Res = np.copy(T)
range_N = np.asarray(range(N))
#range_N += 1
if N % 2 == 0:
for i,j in zip(range_N,range_N[::-1]):
if i >= j: break
T[i,j] = True
else:
for i,j in zip(range_N,range_N[:-1:-1]):
if i >= j: break
T[i,j] = True
Res[T==True] = False
Res[T==False] = True
for i in range_N:
Res[i,i] = False
#print(Res)
for i in range_N:
for j in range_N[i:]:
if Res[i,j] == True: print(i+1,j+1)
if __name__ =='__main__':
main()
|
s314018178
|
Accepted
| 312
| 21,632
| 877
|
# coding: utf-8
import numpy as np
from functools import lru_cache
import time
def main():
if True:
N = int(input())
else:
pass
T = np.asarray([False]*(N**2))
T = T.reshape(N,N)
Res = np.copy(T)
range_N = np.asarray(range(N))
#range_N += 1
if N % 2 == 0:
for i,j in zip(range_N,range_N[::-1]):
if i >= j: break
T[i,j] = True
T[j,i] = True
else:
for i,j in zip(range_N,range_N[::-1]):
j -= 1
if i >= j: break
T[i,j] = True
T[j,i] = True
Res[T==True] = False
Res[T==False] = True
for i in range_N:
Res[i,i] = False
#print(Res)
print(Res[Res].size//2)
for i in range_N:
for j in range_N[i:]:
if Res[i,j] == True: print(i+1,j+1)
if __name__ =='__main__':
main()
|
s817336211
|
p03050
|
u102960641
| 2,000
| 1,048,576
|
Wrong Answer
| 116
| 3,312
| 388
|
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.
|
import math
def all_divisor(n):
small = [1]
large = [n]
for i in range(2, int(math.sqrt(n))):
if n % i == 0:
small.append(i)
large.append(n//i)
large.reverse()
divisor = small + large
return divisor
n = int(input())
n_divisor = all_divisor(n)
ans = 0
for i in n_divisor:
mini_ans = (n - i) // i
if i >= mini_ans:
break
ans += mini_ans
print(ans)
|
s540452296
|
Accepted
| 114
| 3,296
| 373
|
def all_divisor(n):
small = [1]
large = [n]
for i in range(2, int(n ** 0.5)+1):
if n % i == 0:
small.append(i)
large.append(n//i)
large.reverse()
divisor = small + large
return divisor
n = int(input())
n_divisor = all_divisor(n)
ans = 0
for i in n_divisor:
mini_ans = (n - i) // i
if i >= mini_ans:
break
ans += mini_ans
print(ans)
|
s387740476
|
p00590
|
u546285759
| 1,000
| 131,072
|
Wrong Answer
| 720
| 7,728
| 270
|
We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this: 1 2 3 4 5 6 7 8 9 . . . N N . . . 9 8 7 6 5 4 3 2 1 Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime.
|
primes = [0, 0] + [1] * 9999
for i in range(2, 101):
if primes[i]:
for j in range(i*i, 10001, i):
primes[j] = 0
while True:
try:
N = int(input())
except:
break
print(sum(primes[i] & primes[-i] for i in range(1, N+1)))
|
s470697839
|
Accepted
| 490
| 7,752
| 275
|
primes = [0, 0] + [1] * 9999
for i in range(2, 101):
if primes[i]:
for j in range(i*i, 10001, i):
primes[j] = 0
while True:
try:
N = int(input())
except:
break
print(sum(primes[i] and primes[N-i+1] for i in range(1, N+1)))
|
s075498998
|
p03565
|
u802772880
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 262
|
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
|
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
ans='UNRESTRABLE'
for i in range(lsd-lt):
for j in range(lt):
if sd[i+j]!='?' and sd[i+j]!=t[j]:
break
else:
ans=(sd[:i]+t+sd[i+lt:]).replace('?','a')
break
print(ans)
|
s654744826
|
Accepted
| 17
| 3,064
| 274
|
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
for i in range(lsd-lt,-1,-1):
for j in range(lt):
if sd[i+j]!='?' and sd[i+j]!=t[j]:
break
else:
print((sd[:i]+t+sd[i+lt:]).replace('?','a'))
break
else:
print('UNRESTORABLE')
|
s286964650
|
p02272
|
u247976584
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,872
| 911
|
Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right)
|
import math
class MergeSort:
def merge(self, a, n, left, mid, right):
n1 = mid - left
n2 = right - mid
l = a[left:(left+n1)]
r = a[mid:(mid+n2)]
l.append(2000000000)
r.append(2000000000)
i = 0
j = 0
for k in range(left, right):
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
return a
def mergeSort(self, a, n, left, right):
if left + 1 < right:
mid = (left + right) // 2
self.mergeSort(a, n, left, mid)
self.mergeSort(a, n, mid, right)
self.merge(a, n, left, mid, right)
return a
if __name__ == '__main__':
n = int(input().rstrip())
s = [int(i) for i in input().rstrip().split(" ")]
x = MergeSort()
print(x.mergeSort(s, n, 0, n))
|
s293525103
|
Accepted
| 4,790
| 72,700
| 986
|
import math
class MergeSort:
cnt = 0
def merge(self, a, n, left, mid, right):
n1 = mid - left
n2 = right - mid
l = a[left:(left+n1)]
r = a[mid:(mid+n2)]
l.append(2000000000)
r.append(2000000000)
i = 0
j = 0
for k in range(left, right):
self.cnt += 1
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
return a
def mergeSort(self, a, n, left, right):
if left + 1 < right:
mid = (left + right) // 2
self.mergeSort(a, n, left, mid)
self.mergeSort(a, n, mid, right)
self.merge(a, n, left, mid, right)
return a
if __name__ == '__main__':
n = int(input().rstrip())
s = [int(i) for i in input().rstrip().split(" ")]
x = MergeSort()
print(" ".join(map(str, x.mergeSort(s, n, 0, n))))
print(x.cnt)
|
s210825588
|
p03474
|
u835283937
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,060
| 433
|
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
|
def main():
A, B = map(int, input().split())
S = input()
digit = [str(a) for a in range(10)]
collect = True
for i in range(len(S)):
if i == A:
if S[i] != "-":
collect = False
break
else:
if i not in digit:
collect = False
break
if collect == True:
print("Yes")
else:
print("No")
main()
|
s426956191
|
Accepted
| 17
| 3,060
| 436
|
def main():
A, B = map(int, input().split())
S = input()
digit = [str(a) for a in range(10)]
collect = True
for i in range(len(S)):
if i == A:
if S[i] != "-":
collect = False
break
else:
if S[i] not in digit:
collect = False
break
if collect == True:
print("Yes")
else:
print("No")
main()
|
s549002128
|
p02393
|
u204883389
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,528
| 54
|
Write a program which reads three integers, and prints them in ascending order.
|
a, b, c = [int(i) for i in input().split()]
print(min)
|
s371336769
|
Accepted
| 30
| 7,708
| 106
|
data = [int(i) for i in input().split()]
data.sort()
print("{0} {1} {2}".format(data[0],data[1],data[2]))
|
s923780772
|
p02409
|
u808223843
| 1,000
| 131,072
|
Wrong Answer
| 30
| 5,640
| 397
|
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
|
n=int(input())
start=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
b,f,r,v=[int(i) for i in input().split()]
start[b-1][f-1][r-1]+=v
for i in range(4):
for j in range(3):
for k in range(10):
print(" ",end="")
print(start[i][j][k],end="")
print()
for m in range(20):
print("#",end="")
print()
|
s459672645
|
Accepted
| 20
| 5,644
| 423
|
n=int(input())
start=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
b,f,r,v=[int(i) for i in input().split()]
start[b-1][f-1][r-1]+=v
for i in range(4):
for j in range(3):
for k in range(10):
print(" ",end="")
print(start[i][j][k],end="")
print()
if i<=2:
for m in range(20):
print("#",end="")
print()
|
s430596427
|
p02612
|
u004066288
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,144
| 72
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
n = int(input())
if(n % 1000):
print(0)
else:
print(1000 - n % 1000)
|
s326228264
|
Accepted
| 27
| 9,128
| 77
|
n = int(input())
if(n % 1000 == 0):
print(0)
else:
print(1000 - n % 1000)
|
s707385613
|
p03555
|
u379720557
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 147
|
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.
|
S1 = list(input())
S2 = list(input())
flag = 0
for i in range(3):
if S1[i] != S2[2-i]:
flag = 1
if flag:
print('No')
else:
print('Yes')
|
s104969807
|
Accepted
| 17
| 2,940
| 147
|
S1 = list(input())
S2 = list(input())
flag = 0
for i in range(3):
if S1[i] != S2[2-i]:
flag = 1
if flag:
print('NO')
else:
print('YES')
|
s870478586
|
p02608
|
u281152316
| 2,000
| 1,048,576
|
Wrong Answer
| 834
| 9,300
| 262
|
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
|
N = int(input())
num = [0]*N
for i in range(1,10**2):
for j in range(1,10**2):
for k in range(1,10**2):
ans = i**2 + j**2 + k**2 + i*j + j*k + k*i
if ans < N:
num[ans] += 1
for i in range(N):
print(num[i])
|
s106962725
|
Accepted
| 842
| 9,372
| 279
|
N = int(input())
num = [0]*N
for i in range(1,10**2 + 1):
for j in range(1,10**2 + 1):
for k in range(1,10**2 + 1):
ans = i**2 + j**2 + k**2 + i*j + j*k + k*i
if ans <= N:
num[ans - 1] += 1
for i in range(N):
print(num[i])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.