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
s823920468
p03853
u691018832
2,000
262,144
Wrong Answer
17
3,060
260
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) h, w = map(int, readline().split()) for i in range(h): c = read().rstrip().decode() print(c + '\n' + c)
s169632016
Accepted
17
3,064
264
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) h, w = map(int, readline().split()) for i in range(h): c = readline().rstrip().decode() print(c + '\n' + c)
s934028473
p03636
u669770658
2,000
262,144
Wrong Answer
17
2,940
57
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
s = str(input()) print(s[0] + str(len(s[1:-2])) + s[-1])
s824614407
Accepted
17
2,940
57
s = str(input()) print(s[0] + str(len(s[1:-1])) + s[-1])
s059514290
p04012
u614550445
2,000
262,144
Wrong Answer
21
3,316
160
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.
from collections import Counter w = input() c = Counter(w) for k, v in c.items(): if v % 2 != 0: print("NO") exit() print("YES")
s198843093
Accepted
20
3,316
152
from collections import Counter w = input() c = Counter(w) for k, v in c.items(): if v % 2 != 0: print("No") exit() print("Yes")
s559584711
p03565
u231079882
2,000
262,144
Wrong Answer
18
3,060
339
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
s = input() t = input() ans = "UNRESTORABLE" for i in range(len(s)-len(t)+1): for j in range(len(t)): if s[i+j] != t[j] and s[i+j] != "?": break if j == len(t) - 1: mazai = (s[:i] + t + s[i+len(t):]).replace("?","a") if mazai < "UNRESTORABLE": ans = mazai print(ans)
s017736567
Accepted
22
3,064
347
s = input() t = input() ans = "UNRESTORABLE" for i in range(len(s)-len(t)+1): for j in range(len(t)): if s[i+j] != t[j] and s[i+j] != "?": break if j == len(t) - 1: mazai = (s[:i] + t + s[i+len(t):]).replace("?","a") if True or mazai < "UNRESTORABLE": ans = mazai print(ans)
s689472726
p03591
u215743476
2,000
262,144
Wrong Answer
17
2,940
71
Ringo is giving a present to Snuke. Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things. You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.
s = input() if s[0:3] == 'YAKI': print('Yes') else: print('No')
s408952492
Accepted
17
2,940
71
s = input() if s[0:4] == 'YAKI': print('Yes') else: print('No')
s676091988
p03486
u675073679
2,000
262,144
Wrong Answer
17
3,060
205
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.
def main(): s = sorted(input()) t = sorted(input()) S = ','.join(s) T = ','.join(t) if S < T: print('Yes') else: print('No') if __name__ == '__main__': main()
s226484279
Accepted
17
2,940
211
def main(): s = sorted(input()) t = sorted(input())[::-1] S = ','.join(s) T = ','.join(t) if S < T: print('Yes') else: print('No') if __name__ == '__main__': main()
s336743473
p03150
u411923565
2,000
1,048,576
Wrong Answer
46
9,068
325
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
#15 B - KEYENCE String S = list(input()) result = 'NO' for i in range(len(S)): Scpy = S.copy() for j in range(i,len(S)): Scond = Scpy[:i]+Scpy[j:] print(Scond) if (''.join(Scond)) == ('keyence'): result = 'YES' break else: continue break print(result)
s986260429
Accepted
31
9,096
303
#15 B - KEYENCE String S = list(input()) result = 'NO' for i in range(len(S)): Scpy = S.copy() for j in range(i,len(S)): Scond = Scpy[:i]+Scpy[j:] if (''.join(Scond)) == ('keyence'): result = 'YES' break else: continue break print(result)
s164631380
p03545
u316386814
2,000
262,144
Wrong Answer
18
3,064
345
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
from itertools import product li = list(map(int, input())) for ops in product('+-', repeat=3): tmp = li[0] for o, n in zip(ops, li[1:]): if o == '+': tmp += n else: tmp -= n if tmp == 7: ans = str(li[0]) for o, n in zip(ops, li[1:]): ans += o + str(n) print(ans)
s211610879
Accepted
18
3,060
379
from itertools import product li = list(map(int, input())) for ops in product('+-', repeat=3): tmp = li[0] for o, n in zip(ops, li[1:]): if o == '+': tmp += n else: tmp -= n if tmp == 7: ans = str(li[0]) for o, n in zip(ops, li[1:]): ans += o + str(n) ans += '=7' break print(ans)
s370123355
p02678
u350491208
2,000
1,048,576
Wrong Answer
618
36,400
534
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
from collections import deque n, m = map(int, input().split()) graph = [[] for _ in range(n + 1)] for i in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) # print(graph) mark = [-1]*(n+1) mark[0] = 0 mark[1] = 0 d = deque() d.append(1) while d: v = d.popleft() for i in graph[v]: if mark[i] != -1: continue mark[i] = v d.append(i) if mark.count(-1) > 0: print("No") else: print("Yes") ans = mark[1:] print(*ans, sep="\n")
s657229744
Accepted
620
36,404
534
from collections import deque n, m = map(int, input().split()) graph = [[] for _ in range(n + 1)] for i in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) # print(graph) mark = [-1]*(n+1) mark[0] = 0 mark[1] = 0 d = deque() d.append(1) while d: v = d.popleft() for i in graph[v]: if mark[i] != -1: continue mark[i] = v d.append(i) if mark.count(-1) > 0: print("No") else: print("Yes") ans = mark[2:] print(*ans, sep="\n")
s576560720
p03827
u252828980
2,000
262,144
Wrong Answer
18
3,060
163
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).
n = int(input()) s = input() cnt = 0 n = 0 for i in range(n): if s[i] == "I": n += 1 elif s[i] =="D": n -= 1 cnt = max(cnt,n) print(cnt)
s148711859
Accepted
18
3,060
196
n = int(input()) s = input() max1 = -100 n = 0 for i in range(len(s)): if s[i] == "I": n += 1 elif s[i] =="D": n -= 1 max1 = max(max1,n) print(max(max1,0))
s932623124
p02694
u460229551
2,000
1,048,576
Wrong Answer
25
9,164
85
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()) m=100 cnt=0 while x>=m: cnt+=1 m=(m*1.01)//1 print(str(cnt))
s327379467
Accepted
24
9,228
83
x=int(input()) m=100 cnt=0 while x>m: cnt+=1 m=(m*1.01)//1 print(str(cnt))
s908353824
p03644
u882370611
2,000
262,144
Wrong Answer
17
2,940
60
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()) ans=0 while 2**ans <n: ans+=1 print(2**ans)
s231274110
Accepted
17
2,940
66
n=int(input()) ans=0 while 2**ans <=n: ans+=1 print(2**(ans-1))
s859563967
p03693
u506287026
2,000
262,144
Wrong Answer
17
2,940
103
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) if int(r + g + b) % 4 == 0: print('YES') else: print('NO')
s372692577
Accepted
17
2,940
93
r, g, b = input().split() if int(r + g + b) % 4 == 0: print('YES') else: print('NO')
s876005342
p03377
u816587940
2,000
262,144
Wrong Answer
17
2,940
86
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = (map(int, input().split())) k = a+b>=x and a<=x print('Yes' if k else 'No')
s639594637
Accepted
17
2,940
90
a, b, x = (map(int, input().split())) k = (a+b>=x) and (a<=x) print('YES' if k else 'NO')
s684277945
p03920
u668785999
2,000
262,144
Wrong Answer
18
2,940
109
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
N = int(input()) for k in range(N): if(N >= 2 * k + 1): N -= k else: break print(N)
s240965685
Accepted
24
3,572
178
N = int(input()) vec = [] k = 0 sum = 0 while(k**2 + k < 2*N): k += 1 sum += k vec.append(k) if(sum - N): vec.remove(sum - N) for i in range(len(vec)): print(vec[i])
s105097977
p03485
u108377418
2,000
262,144
Wrong Answer
20
3,060
153
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
import math if __name__ == "__main__": print("--2つの整数を入力する--") a, b = map(int, input().split()) print( math.ceil( (a + b ) / 2) )
s302019445
Accepted
18
3,188
110
import math if __name__ == "__main__": a, b = map(int, input().split()) print( math.ceil( (a + b ) / 2) )
s491789617
p02659
u743420240
2,000
1,048,576
Wrong Answer
22
9,148
101
Compute A \times B, truncate its fractional part, and print the result as an integer.
def main(): a, b = input().split() a = int(a) b = float(b) print(a*b) main()
s940178600
Accepted
29
10,068
150
from decimal import Decimal def main(): a, b = input().split() a = Decimal(a) b = Decimal(b) res = int(a*b) print(res) main()
s327485765
p03644
u448720391
2,000
262,144
Wrong Answer
17
2,940
151
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.
import sys n = int(input()) a = [2**i for i in range(0,7)] for i in range(len(a)): if n <= a[i]: print(a[i]) sys.exit() print(64)
s677709130
Accepted
18
3,060
210
import sys n = int(input()) a = [2**i for i in range(0,7)] for i in range(len(a)): if n == a[i]: print(a[i]) sys.exit() elif n < a[i]: print(a[i-1]) sys.exit() print(64)
s099632381
p03377
u691018832
2,000
262,144
Wrong Answer
17
2,940
99
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = map(int, input().split()) if x-a > 0 and a+b >= x: print('Yes') else: print('No')
s577089985
Accepted
17
2,940
100
a, b, x = map(int, input().split()) if x-a >= 0 and a+b >= x: print('YES') else: print('NO')
s293663184
p03697
u481026841
2,000
262,144
Wrong Answer
17
2,940
92
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
a,b = map(int,input().split()) n = a + b if n >= 10: print('error') else: print('n')
s948305643
Accepted
17
2,940
90
a,b = map(int,input().split()) n = a + b if n >= 10: print('error') else: print(n)
s169502867
p03944
u408958033
2,000
262,144
Wrong Answer
18
3,188
849
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
def cin(): return map(int,input().split()) def cino(test=False): if not test: return int(input()) else: return input() def cina(): return list(map(int,input().split())) a,b,c = cin() p = -1 q = 1e9 r = -1 s = 1e9 for i in range(c): x,y,z = cin() if z==1: p = max(x,p) elif z==2: q = min(x,q) elif z==3: r = max(r,y) else: s = min(s,y) if p==-1: p = 0 if q==1e9: q = a if r==-1: r=0 if s==1e9: s=b # w = b-(b-r+b-s) # print(v,w) l1 = list(range(0,p+1)) l2 = list(range(q,a)) l1 = set(l1) l2 = set(l2) l3 = l1.union(l2) l4 = list(range(0,r)) l5 = list(range(s,b+1)) l4 = set(l4) l5 = set(l5) l6 = l4.union(l5) print(l3,l6) # print(l1,l2) print(p,q,r,s) if(len(l3)==a or len(l6)==b): print(0) else: print((a-len(l3)+1)*(b-len(l6)+1))
s015178478
Accepted
18
3,064
540
def cin(): return map(int,input().split()) def cino(test=False): if not test: return int(input()) else: return input() def cina(): return list(map(int,input().split())) a,b,c = cin() p = -1 q = 1e9 r = -1 s = 1e9 for i in range(c): x,y,z = cin() if z==1: p = max(x,p) elif z==2: q = min(x,q) elif z==3: r = max(r,y) else: s = min(s,y) if p==-1: p = 0 if q==1e9: q = a if r==-1: r=0 if s==1e9: s=b ans = (q-p)*(s-r) if p>q or r>s: print(0) else: print(ans)
s471039742
p03738
u088974156
2,000
262,144
Wrong Answer
17
2,940
108
You are given two positive integers A and B. Compare the magnitudes of these numbers.
a=int(input()) b=int(input()) if(a>b): print("LESS") elif(a==b): print("EQUAL") else: print("GREATER")
s669028615
Accepted
17
2,940
108
a=int(input()) b=int(input()) if(a<b): print("LESS") elif(a==b): print("EQUAL") else: print("GREATER")
s579917055
p03997
u717626627
2,000
262,144
Wrong Answer
17
2,940
66
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print(a*b*h/2)
s406633431
Accepted
17
2,940
69
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s952888570
p02608
u143441425
2,000
1,048,576
Wrong Answer
605
106,508
593
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).
from numba import njit @njit('i8(i8)', cache=True) def fun(n): mx = int((n**.5) // 3) + 1 pairs = 0 for x in range(1, mx + 1): for y in range(x, mx + 1): for z in range(y, mx + 1): v = x*x + y*y + z*z + x*y + y*z + z*x if v == n: if x == y == z: pairs += 1 elif x == y or y == z: pairs += 3 else: pairs += 6 return pairs n = int(input()) for i in range(n): ps = fun(i + 1) print(ps)
s820555569
Accepted
1,126
106,588
622
from numba import njit @njit('i8(i8)', cache=True) def fun(n): #mx = n#int((n**.5) // 3) + 1 mx = int(n**.5 + 0.5) pairs = 0 for x in range(1, mx + 1): for y in range(x, mx + 1): for z in range(y, mx + 1): v = x*x + y*y + z*z + x*y + y*z + z*x if v == n: if x == y == z: pairs += 1 elif x == y or y == z: pairs += 3 else: pairs += 6 return pairs n = int(input()) for i in range(n): ps = fun(i + 1) print(ps)
s962592133
p02601
u409974118
2,000
1,048,576
Wrong Answer
29
9,164
179
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
a,b,c = map(int,input().split()) k = int(input()) an = 0 while a >= b: b *= 2 an +=1 while b>=c: c *=2 an +=1 if an > k: print("NO") else : print("YES")
s136577532
Accepted
29
9,160
179
a,b,c = map(int,input().split()) k = int(input()) an = 0 while a >= b: b *= 2 an +=1 while b>=c: c *=2 an +=1 if an > k: print("No") else : print("Yes")
s343812192
p02612
u234007117
2,000
1,048,576
Wrong Answer
32
9,080
33
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n % 1000)
s598639376
Accepted
29
9,088
78
n = int(input()) if n % 1000 == 0: print(0) else: print(1000 - (n % 1000))
s693440130
p00008
u661290476
1,000
131,072
Wrong Answer
30
7,604
322
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
INF=-1 memo=[[INF]*51 for i in range(5)] def rec(i,n): if memo[i][n]!=INF: return memo[i][n] if i==4: return 1 if n==0 else 0 for m in range(10): memo[i][n]+=rec(i+1,n-m) return memo[i][n] while True: try: n=int(input()) print(rec(0,n)) except: break
s492362451
Accepted
200
7,496
280
while True: try: n=int(input()) except: break cnt=0 for i in range(10): for j in range(10): for k in range(10): for l in range(10): if i+k+j+l==n: cnt+=1 print(cnt)
s576928587
p03729
u127856129
2,000
262,144
Wrong Answer
17
2,940
98
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() s=[a,b,c] if a[-0]==b[0] and b[-0]==c[0]: print("YES") else: print("NO")
s552266774
Accepted
17
2,940
99
a,b,c=input().split() s=[a,b,c] if a[-1]==b[0] and b[-1]==c[0]: print("YES") else: print("NO")
s304333631
p03386
u580404776
2,000
262,144
Wrong Answer
17
3,060
177
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A,B,K=map(int,input().split()) ans=[] for i in range(K): if A+i<=B: ans.append(A+i) if B-i>=A: ans.append(B-i) ans=list(set(ans)) print(*ans, sep='\n')
s322677312
Accepted
17
3,060
186
A,B,K=map(int,input().split()) ans=[] for i in range(K): if A+i<=B: ans.append(A+i) if B-i>=A: ans.append(B-i) ans=sorted(list(set(ans))) print(*ans, sep='\n')
s742056105
p03565
u927534107
2,000
262,144
Wrong Answer
17
3,064
294
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
s=str(input()) t=str(input()) for i in range(len(s)-len(t)+1): l=list(s[len(s)-len(t)-i:len(s)-i]) if all([l[i]==t[i] or l[i]=="?" for i in range(len(t))]): s_new=s[:len(s)-len(t)-i]+t+s[len(s)-i:] break s=s.replace("?","a") if t in s:print(s) else:print("UNRESTORABLE")
s688727034
Accepted
17
3,064
284
s=str(input()) t=str(input()) for i in range(len(s)-len(t)+1): l=s[len(s)-len(t)-i:len(s)-i] if all([l[i]==t[i] or l[i]=="?" for i in range(len(t))]): s=s[:len(s)-len(t)-i]+t+s[len(s)-i:] break s=s.replace("?","a") if t in s:print(s) else:print("UNRESTORABLE")
s157684572
p03478
u694244301
2,000
262,144
Wrong Answer
549
9,156
201
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split()) ans = 0 for i in range(1, n + 1): t = 0 k = i while(True): t += k % 10 k = k / 10 if k == 0: break if a <= t <= b: ans += 1 print(ans)
s074725989
Accepted
39
9,128
207
n, a, b = map(int, input().split()) ans = 0 for i in range(1, n + 1): t = 0 k = i while(True): t += k % 10 k = int(k / 10) if k == 0: break if a <= t <= b: ans += i print(ans)
s650460064
p00461
u546285759
1,000
131,072
Wrong Answer
20
7,688
147
整数 _n_ (1 ≤ _n_ ) に対し, _n_ \+ 1 個の I と _n_ 個の O を I から始めて交互に並べてできる文字列を _P n_ とする.ここで I と O はそれぞれ英大文字のアイとオーである. _P_ 1| IOI ---|--- _P_ 2| IOIOI _P_ 3| IOIOIOI | .| | .| | .| _P_ _n_| IOIOIO ... OI (O が _n_ 個) 図 1-1 本問で考える文字列 _P n_ 整数 _n_ と, I と O のみからなる文字列 _s_ が与えられた時, _s_ の中に _P n_ が何ヶ所含まれているかを出力するプログラムを作成せよ.
n, m, s= int(input()), int(input()), input() ioi= "IOI" if n==3 else "IOI"+"OI"*(n-1) n= 2*n+1 print(sum(1 for i in range(m-n+1) if s[i:i+n]==ioi))
s916258132
Accepted
540
9,452
198
while True: n= int(input()) if n== 0: break m, s= int(input()), input() ioi= "IOI" if n==3 else "IOI"+"OI"*(n-1) n= 2*n+1 print(sum(1 for i in range(m-n+1) if s[i:i+n]==ioi))
s709261450
p03455
u321121629
2,000
262,144
Wrong Answer
17
2,940
96
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=[int(i) for i in input().split()] c = a*b if c % 2 ==0: print('even') else: print('odd')
s363801108
Accepted
17
2,940
89
a,b = map(int, input().split()) if (a * b) % 2 == 0: print('Even') else: print('Odd')
s979751236
p00003
u710016128
1,000
131,072
Wrong Answer
30
7,600
255
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
n = int(input()) ans = list() for i in range(n): line = input().split(" ") if (line[0] == line[1]) or (line[1] == line[2]) or (line[0] == line[2]): ans.append("YES") else: ans.append("NO") for j in range(n): print(ans[j])
s288722789
Accepted
30
7,676
369
n = int(input()) ans = list() for i in range(n): line = input().split(" ") a = float(line[0]) b = float(line[1]) c = float(line[2]) if ((a**2 + b**2) == c**2) or ((b**2 + c**2) == a**2) or ((c**2 + a**2) == b**2): ans.append("YES") else: ans.append("NO") for j in range(n): print(ans[j])
s634881736
p03228
u612721349
2,000
1,048,576
Wrong Answer
17
3,060
210
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
a, b, c = map(int, input().split()) for i in range(c): if c % 2 == 0: if a % 2 == 1: a -= 1 b += a // 2 a //= 2 else: if b % 2 == 1: b-= 1 a += b // 2 b //= 2 print(a, b)
s084335043
Accepted
17
2,940
211
a, b, c = map(int, input().split()) for i in range(c): if i % 2 == 0: if a % 2 == 1: a -= 1 b += a // 2 a //= 2 else: if b % 2 == 1: b-= 1 a += b // 2 b //= 2 print(a, b)
s238811424
p03680
u565476466
2,000
262,144
Wrong Answer
2,104
7,084
164
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
N = int(input()) a = [int(input()) for _ in range(N)] ans, nex = 1, a[0] while ans < N or nex == 2: nex = a[nex - 1] ans += 1 print(ans if ans != N else -1)
s602392974
Accepted
201
7,084
165
N = int(input()) a = [int(input()) for _ in range(N)] ans, nex = 1, a[0] while ans < N and nex != 2: nex = a[nex - 1] ans += 1 print(ans if ans != N else -1)
s783671863
p02865
u148551245
2,000
1,048,576
Wrong Answer
17
2,940
87
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n = int(input()) if n % 2 == 1: print((n - 1) / 2) else: print((n - 1) / 2 - 1)
s406527640
Accepted
17
2,940
91
n = int(input()) if n % 2 == 1: print(int((n - 1) / 2)) else: print(int(n / 2 - 1))
s388625909
p00009
u197615397
1,000
131,072
Time Limit Exceeded
5,940
10,892
347
Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
from collections import deque import bisect from math import sqrt import sys primes = deque([2, 3, 5, 7, 11, 13, 17, 19]) append = primes.append for i in range(21, 1000000, 2): for j in range(3, int(sqrt(i))+1, 2): if i%j == 0: break else: append(i) for l in sys.stdin: print(bisect.bisect(primes, int(l)))
s455040375
Accepted
140
40,592
573
def get_prime_set(ub): from itertools import chain from math import sqrt if ub < 4: return ({}, {}, {2}, {2, 3})[ub] ub, ub_sqrt = ub+1, int(sqrt(ub))+1 primes = {2, 3} | set(chain(range(5, ub, 6), range(7, ub, 6))) du = primes.difference_update for n in chain(range(5, ub_sqrt, 6), range(7, ub_sqrt, 6)): if n in primes: du(range(n*3, ub, n*2)) return primes import sys from bisect import bisect_right primes = list(get_prime_set(999999)) print(*(bisect_right(primes, int(n)) for n in sys.stdin), sep="\n")
s213011546
p02614
u903005414
1,000
1,048,576
Wrong Answer
67
9,116
471
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
H, W, K = map(int, input().split()) C = [] for _ in range(H): C.append(list(input())) # print(f'{C=}') ans = 0 for H_bit in range(1 << H): for W_bit in range(1 << W): cnt = 0 for i in range(H): for j in range(W): if ((H_bit >> i) & 1) == 0 and ((W_bit >> i) & 1) == 0 and C[i][j] == '#': cnt += 1 if cnt == K: ans += 1 print(ans)
s422972599
Accepted
63
9,216
764
H, W, K = map(int, input().split()) C = [] for _ in range(H): C.append(list(input())) # print(f'{C=}') ans = 0 for H_bit in range(1 << H): H_idx = [] for i in range(H): if H_bit & (1 << i): H_idx.append(i) # print(f'{H_bit=}, {H_idx=}') for W_bit in range(1 << W): W_idx = [] for i in range(W): if W_bit & (1 << i): W_idx.append(i) # print(f'{H_idx=}, {W_idx=}') cnt = 0 for i in range(H): for j in range(W): if i not in H_idx and j not in W_idx and C[i][j] == '#': cnt += 1 if cnt == K: ans += 1 print(ans)
s749592444
p02613
u321415743
2,000
1,048,576
Wrong Answer
189
9,180
233
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.
num = int(input()) test = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0} for i in range(num): result = input() for j in test.keys(): if result == j: test[result] += 1 for i in test: print(i, '×', str(test[i]))
s930198010
Accepted
185
9,184
232
num = int(input()) test = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0} for i in range(num): result = input() for j in test.keys(): if result == j: test[result] += 1 for i in test: print(i, 'x', str(test[i]))
s037318805
p03635
u031146664
2,000
262,144
Wrong Answer
17
2,940
66
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
s = input() lis = [s[:1],str(len(s)-2),s[-1]] print("".join(lis))
s452231018
Accepted
17
2,940
51
a, b = map(int, input().split()) print((a-1)*(b-1))
s151414922
p03478
u548545174
2,000
262,144
Wrong Answer
35
3,060
179
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()) ans = 0 for i in range(1, N + 1): s = 0 i = str(i) for n in i: s += int(n) if A <= s <= B: ans += s print(ans)
s635623539
Accepted
34
2,940
161
N, A, B = map(int, input().split()) ans = 0 for i in range(1, N+1): i = str(i) if A <= sum([int(j) for j in i]) <= B: ans += int(i) print(ans)
s172869221
p02853
u785578220
2,000
1,048,576
Wrong Answer
18
3,060
152
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
l = [300000,200000,100000] a,b = map(int,input().split()) res = 0 if a in range(1,4): res +=l[a-1] if b in range(1,4): res +=l[b-1] print(res)
s724329644
Accepted
17
3,060
187
l = [300000,200000,100000] a,b = map(int,input().split()) res = 0 if a in range(1,4): res +=l[a-1] if b in range(1,4): res +=l[b-1] if a == b and a==1: res+=400000 print(res)
s023404749
p03387
u166306121
2,000
262,144
Wrong Answer
18
3,064
439
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
A,B,C = map(int,input().split()) oddcnt = 0 sub = [A,B,C] sub2 = [i - min(sub) for i in sub] sub2 = sorted(sub2)[1:3] print(sub2) for i in sub2: if i%2 != 0: oddcnt += 1 if oddcnt == 0: print((sub2[1]+(sub2[1]-sub2[0]))//2) elif oddcnt == 1: if sub2[0]%2 ==0: print((sub2[1]+(sub2[1]-sub2[0]))//2) else: print((sub2[1]+(sub2[1]-sub2[0]+1))//2+1) else: print((sub2[1]+(sub2[1]-sub2[0]+1))//2+1)
s090276564
Accepted
18
3,064
441
A,B,C = map(int,input().split()) oddcnt = 0 sub = [A,B,C] sub2 = [i - min(sub) for i in sub] sub2 = sorted(sub2)[1:3] # print(sub2) for i in sub2: if i%2 != 0: oddcnt += 1 if oddcnt == 0: print((sub2[1]+(sub2[1]-sub2[0]))//2) elif oddcnt == 1: if sub2[0]%2 ==0: print((sub2[1]+(sub2[1]-sub2[0]))//2) else: print((sub2[1]+(sub2[1]-sub2[0]+1))//2+1) else: print((sub2[1]+(sub2[1]-sub2[0]+1))//2+1)
s460606660
p03777
u019584841
2,000
262,144
Wrong Answer
18
2,940
79
Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest.
a,b=input().split() if a==b=="H" and a==b=="D": print("H") else: print("D")
s104666289
Accepted
17
2,940
79
a,b=input().split() if a==b=="H" or a==b=="D": print("H") else: print("D")
s757403352
p03644
u957084285
2,000
262,144
Time Limit Exceeded
2,104
2,940
193
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()) ans = 1 max_count = 0 n = 2 while (n <= N): k = n count = 0 while k%2 == 0: k /= 2 count += 1 if count > max_count: ans = n max_count = count print(ans)
s568377447
Accepted
17
2,940
203
N = int(input()) ans = 1 max_count = 0 n = 2 while (n <= N): k = n count = 0 while k%2 == 0: k /= 2 count += 1 if count > max_count: ans = n max_count = count n += 1 print(ans)
s924980346
p03302
u945181840
2,000
1,048,576
Wrong Answer
17
2,940
101
You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds. Note that a+b=15 and a\times b=15 do not hold at the same time.
a, b = map(int, input().split()) if a + b == 15 or a * b == 15: print('*') else: print('x')
s772876510
Accepted
17
2,940
119
a, b = map(int, input().split()) if a + b == 15: print('+') elif a * b == 15: print('*') else: print('x')
s605197286
p03795
u026788530
2,000
262,144
Wrong Answer
17
2,940
38
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n=int(input()) print(n*800-200*n//15)
s782180311
Accepted
17
2,940
39
n=int(input()) print(n*800-200*(n//15))
s956772922
p02972
u620868411
2,000
1,048,576
Wrong Answer
955
10,708
382
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
# -*- coding: utf-8 -*- n = int(input()) al = list(map(int, input().split())) bl = [0]*n for i in range(n,0,-1): if i*2>n: if al[i-1]>0: bl[i-1] = 1 continue c = 2 s = 0 while i*c<=n: s += bl[i*c-1] c += 1 if al[i-1]==1: bl[i-1] = 1 if s%2==0 else 0 else: bl[i-1] = 0 if s%2==0 else 1 print(*bl)
s512879416
Accepted
1,016
14,196
491
# -*- coding: utf-8 -*- n = int(input()) al = list(map(int, input().split())) bl = [0]*n for i in range(n,0,-1): if i*2>n: if al[i-1]>0: bl[i-1] = 1 continue c = 2 s = 0 while i*c<=n: s += bl[i*c-1] c += 1 if al[i-1]==1: bl[i-1] = 1 if s%2==0 else 0 else: bl[i-1] = 0 if s%2==0 else 1 res = [] for i in range(1,n+1): if bl[i-1]>0: res.append(i) print(len(res)) if len(res)>0: print(*res)
s714911264
p03437
u808003008
2,000
262,144
Wrong Answer
17
2,940
182
You are given positive integers X and Y. If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it. If it does not exist, print -1.
x, y = list(map(int, input().split())) if x == y: print(-1) else: for i in range(1, 100): if x * i > y and x * i % y != 0: print(x * i) break
s455831455
Accepted
18
2,940
212
x, y = list(map(int, input().split())) if x == y: print(-1) else: for i in range(2, 11): if x * i % y != 0: print(x * i) break elif i == 10: print(-1)
s798861780
p03436
u619144316
2,000
262,144
Wrong Answer
2,114
185,828
662
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
H,W = [int(i) for i in input().split(' ')] MAP = [] SUM = 0 for i in range(H): tmp = list(input()) SUM += tmp.count('#') MAP.append(tmp) print(MAP,SUM) S = [[0,0]] while True: tmp = [] for s in S: if not s[1] == W -1: if MAP[s[0]][s[1]+1] == '.': a = [s[0], s[1]+1] tmp.append(a) if not s[0] == H -1: if MAP[s[0]+1][s[1]] == '.': a = [s[0]+1, s[1]] tmp.append(a) S = tmp if len(s) == 0: print(-1) exit() if [H-1,W-1] in S: move = H + W - 1 print(H*W - move - SUM) exit()
s922615558
Accepted
40
9,404
894
from collections import deque def main(): R,C= map(int,input().split()) S = [0,0] mv = [[1,0],[-1,0],[0,-1],[0,1]] MAP = [] flg = 0 block = 0 for _ in range(R): t = list(input()) block += t.count('#') MAP.append(t) stack = deque([S]) MAP_c = [[None]*C for _ in range(R)] MAP_c[0][0] = 1 while stack: v = stack.popleft() for m in mv: u = [v[0]+m[0],v[1]+m[1]] if u[0] >=0 and u[0] < R and u[1] >= 0 and u[1] < C and MAP[u[0]][u[1]] == '.': MAP[u[0]][u[1]] = '#' MAP_c[u[0]][u[1]] = MAP_c[v[0]][v[1]] + 1 stack.append(u) if u == [R-1,C-1]: flg = 1 if flg == 1: break if flg == 1: a = MAP_c[R-1][C-1] print(R*C - a - block) else: print(-1) main()
s127224732
p03712
u037430802
2,000
262,144
Wrong Answer
18
3,060
201
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
h,w = map(int,input().split()) ans = [] ans.append("*"*(w+2)) for i in range(h): s = input() tmp = "*" tmp += s tmp += "*" ans.append(tmp) ans.append("*"*(w+2)) for i in ans: print(i)
s712061298
Accepted
18
3,060
201
h,w = map(int,input().split()) ans = [] ans.append("#"*(w+2)) for i in range(h): s = input() tmp = "#" tmp += s tmp += "#" ans.append(tmp) ans.append("#"*(w+2)) for i in ans: print(i)
s459895776
p03612
u405256066
2,000
262,144
Wrong Answer
65
13,880
193
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
from sys import stdin N = int(stdin.readline().rstrip()) P = [int(x) for x in stdin.readline().rstrip().split()] cnt = 0 for i,j in enumerate(P): if i+1 != j: cnt += 1 print(cnt//2)
s747103548
Accepted
72
13,880
272
from sys import stdin N = int(stdin.readline().rstrip()) P = [int(x) for x in stdin.readline().rstrip().split()] cnt = 0 ans = 0 for i,j in enumerate(P): if i+1 == j: cnt += 1 else: ans += ((cnt+1)//2) cnt = 0 ans += ((cnt+1)//2) print(ans)
s063486413
p00005
u896025703
1,000
131,072
Wrong Answer
30
7,716
215
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) while True: try: a, b = map(int, input().split()) print(gcd(a, b), lcm(a, b)) except EOFError: break
s277840971
Accepted
30
7,612
225
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) while True: try: a, b = map(int, input().split()) print(int(gcd(a, b)), int(lcm(a, b))) except EOFError: break
s777900045
p03730
u509214520
2,000
262,144
Wrong Answer
27
9,156
136
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A, B, C = map(int, input().split()) amari = [] for i in range(1, B+100): amari.append(A*i%B) print('Yes' if C in amari else 'No')
s681649619
Accepted
26
9,008
134
A, B, C = map(int, input().split()) amari = [] for i in range(1, B+1): amari.append(A*i%B) print('YES' if C in amari else 'NO')
s418579128
p03644
u208120643
2,000
262,144
Wrong Answer
117
27,068
409
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.
import numpy as np N = 100 # N=int(input()) Division_2 = [] number=[] for i in range(1, N+1): j = i count = 0 while True: count += 1 j = j/2 if j/2 != int(j/2): break Division_2.append(count) number.append(i) Division_2=np.array(Division_2) print(number[np.argmax(Division_2)])
s070392965
Accepted
116
27,228
427
import numpy as np #N = 100 N=int(input()) Division_2 = [] number=[] for i in range(1, N+1): j = i count = 0 while True: if j/2 != int(j/2): break j = j/2 count += 1 Division_2.append(count) number.append(i) Division_2=np.array(Division_2) print(number[np.argmax(Division_2)]) #print(Division_2)
s855010924
p03456
u955547613
2,000
262,144
Wrong Answer
17
2,940
160
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.
# -*- coding: utf-8 -*- import math a, b = map(str, input().split()) c = int(a + b) root = math.sqrt(c) if root**2 == c: print("YES") else: print("NO")
s727624261
Accepted
17
3,060
265
# -*- coding: utf-8 -*- import math a, b = map(str, input().split()) c = int(a + b) flag = False for i in range(1, 1000): if (i**2 == c): flag = True print("Yes") break elif (i**2 > c): break if not flag: print("No")
s316162565
p03555
u863044225
2,000
262,144
Wrong Answer
17
2,940
49
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
s=input() t=input() print('YNeos'[s!=t[::-1]::2])
s948893185
Accepted
17
2,940
50
s=input() t=input() print('YNEOS'[s!=t[::-1]::2])
s152868514
p03455
u002459665
2,000
262,144
Wrong Answer
18
2,940
94
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if a * b % 2 == 0: print('Odd') else: print('Even')
s856969688
Accepted
17
2,940
94
a, b = map(int, input().split()) if a * b % 2 == 0: print('Even') else: print('Odd')
s531059617
p02613
u753971348
2,000
1,048,576
Wrong Answer
151
9,164
316
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) ac, re, wa, tle = 0,0,0,0 for i in range(N): line = input() if line == "AC": ac += 1 elif line == "TLE": tle += 1 elif line == "WA": wa += 1 elif line == "RE": re += 1 print("AC × " + str(ac)) print("WA × " + str(wa)) print("TLE × " + str(tle)) print("RE × " + str(re))
s633855983
Accepted
149
9,140
312
N = int(input()) ac, re, wa, tle = 0,0,0,0 for i in range(N): line = input() if line == "AC": ac += 1 elif line == "TLE": tle += 1 elif line == "WA": wa += 1 elif line == "RE": re += 1 print("AC x " + str(ac)) print("WA x " + str(wa)) print("TLE x " + str(tle)) print("RE x " + str(re))
s860408228
p03556
u558836062
2,000
262,144
Wrong Answer
25
3,060
132
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
A,B,N = 0,1,int(input()) while (True): A += 1 if A*A>N: break b = A*A print('{0} = {1}**2' .format(b,int(b**(1/2))))
s004562579
Accepted
24
2,940
94
A,B,N = 0,1,int(input()) while (True): A += 1 if A*A>N: break b = A*A print(b)
s204758160
p02613
u544865362
2,000
1,048,576
Wrong Answer
158
9,180
234
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()) hashmap = { 'AC' : 0, 'WA' : 0, 'TLE': 0, 'RE' : 0 } while n > 0: t = input() hashmap[t] = hashmap.get(t, 0) + 1 n -= 1 for key, val in hashmap.items(): print(key + "x" + str(val))
s421992840
Accepted
163
9,476
292
n = int(input()) import collections # hashmap = collections.OrderedDict() hashmap = { 'AC' : 0, 'WA' : 0, 'TLE': 0, 'RE' : 0 } while n > 0: t = input() hashmap[t] = hashmap.get(t, 0) + 1 n -= 1 for key, val in hashmap.items(): print(key + " x " + str(val))
s174597591
p02612
u531219227
2,000
1,048,576
Wrong Answer
34
9,080
31
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N%1000)
s712961196
Accepted
28
9,156
70
N = int(input()) if N%1000 != 0: print(1000-N%1000) else: print(0)
s841923495
p03351
u740284863
2,000
1,048,576
Wrong Answer
17
2,940
138
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d = map(int,input().split()) if abs(a-c) <= d: print("Yes") elif abs(a-b)+abs(b-c) <= d: print("Yes") else: print("No")
s680215695
Accepted
17
2,940
147
a,b,c,d = map(int,input().split()) if abs(a-c) <= d: print("Yes") elif abs(a-b) <= d and abs(b-c) <= d: print("Yes") else: print("No")
s845541187
p02663
u686230543
2,000
1,048,576
Wrong Answer
22
9,104
100
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
h1, m1, h2, m2, k = map(int, input().split()) t1 = 60 * h1 + m1 t2 = 60 * h2 * m2 print(t2 - t1 - k)
s885391321
Accepted
20
9,164
100
h1, m1, h2, m2, k = map(int, input().split()) t1 = 60 * h1 + m1 t2 = 60 * h2 + m2 print(t2 - t1 - k)
s617248135
p03695
u210827208
2,000
262,144
Wrong Answer
19
3,188
556
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
n=int(input()) A=list(map(int,input().split())) ov=0 res=0 C=[0]*8 for i in A: if 1<=i and i<400: C[0]+=1 elif 400<=i and i<800: C[1]+=1 elif 800<=i and i<1200: C[2]+=1 elif 1200<=i and i<1600: C[3]+=1 elif 1600<=i and i<2000: C[4]+=1 elif 2000<=i and i<2400: C[5]+=1 elif 2400<=i and i<2800: C[6]+=1 elif 2800<=i and i<3200: C[7]+=1 else: ov+=1 for j in C: if j!=0: res+=1 if res+ov>8: print(8) else: print(res+ov)
s948783072
Accepted
17
3,060
186
n=int(input()) A=list(map(int,input().split())) C=[0]*9 for i in A: x=i//400 if x<8: C[x]=1 else: C[8]+=1 b=sum(C[:8]) print(str(max(b,1))+' '+str(b+C[8]))
s793130491
p02821
u295294832
2,000
1,048,576
Wrong Answer
2,104
14,140
1,244
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
N,M= [int(i) for i in input().split()] n = sorted([int(x) for x in input().split()],reverse = True) print(n) MM=n[0]*2 mm=n[-1]*2 l=[0]*2 r=MM//2 while True: c=0 for i in range(N): for j in range(i,N): if n[i]+n[j] > r: if i==j: c+=1 else: c+=2 l[0] = i l[1] = j print(c,r) if c==M: break if abs(MM-mm) < 2: r=mm break elif c>M: mm=r r=(MM+mm)//2 elif c<M: MM=r r=(mm+MM)//2 #print("fin",c,r,l[0],l[1]) v=0 q=0 for i in range(l[0]+1): for j in range(i,N): t=n[i]+n[j] if t > r: if i==j: v+=t q+=1 else: v+=t*2 q+=2 if q>M: v-=t break if q==M: break print(v)
s742946905
Accepted
1,435
14,388
596
from bisect import bisect_left N,M= [int(i) for i in input().split()] n = sorted([int(x) for x in input().split()]) s =[0]*(N+1) s[0]=n[0] for i in range(1,N+1): s[i] = s[i-1]+n[i-1] MM=n[-1]*2 mm=n[0]*2 while True: c=0 r=(mm+MM)//2 for i in range(N): c += N-bisect_left(n,r-n[i]) if (MM-mm) < 2: break elif c>=M: mm=r elif c<M: MM=r v=0 for i in range(N): j=bisect_left(n,r-n[i]) v+= (s[N] - s[j]) + (N-j)*n[i] v = v - (c-M)*(r) print(v)
s740754503
p03455
u709806735
2,000
262,144
Wrong Answer
17
2,940
89
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a ,b =map(int,input().split()) if (a*b)%2 ==0: print("even") else: print("odd")
s628669236
Accepted
17
2,940
89
a ,b =map(int,input().split()) if (a*b)%2 ==0: print("Even") else: print("Odd")
s601537488
p02412
u352203480
1,000
131,072
Wrong Answer
30
5,596
408
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
while True: n, x = map(int, input().split()) if n == 0 and x == 0: break else: sums = 0 count = 0 for i in range(1, n-1): for j in range(i+1, n): for k in range(j+1, n+1): sums = i + j + k print(sums) if sums == x: count += 1
s269816139
Accepted
610
5,596
396
while True: n, x = map(int, input().split()) if n == 0 and x == 0: break else: sums = 0 count = 0 for i in range(1, n-1): for j in range(i+1, n): for k in range(j+1, n+1): sums = i + j + k if sums == x: count += 1 print(count)
s672354329
p04035
u414809621
2,000
262,144
Wrong Answer
307
14,724
685
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
# -*- coding: utf-8 -*- """ Created on Fri Aug 5 22:01:07 2016 @author: dotha """ def say(l,r): for i in range(l,r): print(i+1) if l>r: for i in range(l,r,-1): print(i-1) def solver(N,L,a): for i in range(N-2): if a[i+1]+a[i] >= L: break else: print('Impossible') return print('Possible') left = 0 for i in range(N-1): if a[i+1]+a[i] > L: say(left,i) left = i if left == N-2: print(left+1) break else: say(N-1,left) N,L=map(int,input().split(' ')) a=list(map(int,input().split(' '))) solver(N,L,a)
s448829027
Accepted
221
14,148
430
def main(): n, l = (int(s) for s in input().strip().split(' ')) an = [int (s) for s in input().strip().split(' ')] for i in range(1, n): if an[i-1] + an[i] >= l: print('Possible') index = i break else: print('Impossible') return for i in range(1, index): print(i) for i in range(n-1, index, -1): print(i) print(index) main()
s543349955
p03738
u080364835
2,000
262,144
Wrong Answer
17
2,940
107
You are given two positive integers A and B. Compare the magnitudes of these numbers.
a = int(input()) b = int(input()) if a > b: print('GRATER') elif a < b: print('LESS') else: print('EQUAL')
s343194715
Accepted
17
3,060
108
a = int(input()) b = int(input()) if a > b: print('GREATER') elif a < b: print('LESS') else: print('EQUAL')
s180430427
p02844
u951401193
2,000
1,048,576
Wrong Answer
33
3,060
112
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
n = int(input()) s = input() h = [0]*1000 for i in range(n-2): tmp = int(s[i:i+3]) h[tmp]=1 print(sum(h))
s973263624
Accepted
584
3,188
139
input() a, b, c = set(), set(), set() for x in input(): c.update(y + x for y in b) b.update(y + x for y in a) a.add(x) print(len(c))
s148921126
p03369
u538956308
2,000
262,144
Wrong Answer
17
2,940
53
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
S = input() topping = S.count("o") print(700+topping)
s378227888
Accepted
17
2,940
69
S = input() topping = S.count("o") ans = 700 + topping*100 print(ans)
s774197795
p03457
u626331732
2,000
262,144
Wrong Answer
432
21,108
382
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()) txy = [[0,0,0]] for i in range(N): txy.append([int(x) for x in input().split()]) flg = 0 for j in range(1, N + 1): dt = txy[j][0] - txy[j - 1][0] dx = txy[j][1] - txy[j - 1][1] dy = txy[j][2] - txy[j - 1][2] d = dt - abs(dx) - abs(dy) if d < 0 or d % 2 != 0: print("NO") flg = 1 break if flg == 0: print("YES")
s596371081
Accepted
415
21,108
382
N = int(input()) txy = [[0,0,0]] for i in range(N): txy.append([int(x) for x in input().split()]) flg = 0 for j in range(1, N + 1): dt = txy[j][0] - txy[j - 1][0] dx = txy[j][1] - txy[j - 1][1] dy = txy[j][2] - txy[j - 1][2] d = dt - abs(dx) - abs(dy) if d < 0 or d % 2 != 0: print("No") flg = 1 break if flg == 0: print("Yes")
s467040003
p02614
u945405878
1,000
1,048,576
Wrong Answer
132
27,084
1,053
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
import numpy as np import itertools n_tate, n_yoko, n_kuro = map(int, input().split()) matrix = [] for _ in range(n_tate): yoko = [_ for _ in str(input())] yoko2 = [] for char in yoko: if char == "#": yoko2.append(1) else: yoko2.append(0) matrix.append(yoko2) matrix2 = np.array(matrix) tmp = [0, 1] tate_use_list = list(itertools.combinations_with_replacement(tmp, n_tate)) yoko_use_list = list(itertools.combinations_with_replacement(tmp, n_yoko)) # print("original") # print(np.array(matrix)) # print() i = 0 counter = 0 for tate_use in tate_use_list: for yoko_use in yoko_use_list: # print("tate use:", tate_use) # print("yoko_use:", yoko_use) matrix3 = matrix2.copy() A = np.array(tate_use).reshape(-1, 1) B = np.array(yoko_use) matrix4 = matrix3 * A * B # print(matrix4) total = np.sum(matrix4) i += 1 if total == n_kuro: counter += 1 print(counter)
s841929843
Accepted
162
27,156
1,098
import numpy as np import itertools n_tate, n_yoko, n_kuro = map(int, input().split()) matrix = [] for _ in range(n_tate): yoko = [_ for _ in str(input())] yoko2 = [] for char in yoko: if char == "#": yoko2.append(1) else: yoko2.append(0) matrix.append(yoko2) matrix2 = np.array(matrix) tmp = [0, 1] tate_use_list = list(itertools.product(tmp, repeat=n_tate)) yoko_use_list = list(itertools.product(tmp, repeat=n_yoko)) # print("original") # print(np.array(matrix)) # print() i = 0 counter = 0 for tate_use in tate_use_list: for yoko_use in yoko_use_list: # print(i) # print("tate use:", tate_use) # print("yoko_use:", yoko_use) matrix3 = matrix2.copy() A = np.array(tate_use).reshape(-1, 1) B = np.array(yoko_use) matrix4 = matrix3 * A * B total = np.sum(matrix4) i += 1 # print(matrix4) if total == n_kuro: # print(" -> OK!") counter += 1 # print() print(counter)
s013528962
p03827
u483645888
2,000
262,144
Wrong Answer
17
2,940
157
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).
n = int(input()) cnt = 0 ch = 0 *w, = map(str,input().split()) for i in w: if i == 'I': cnt+=1 else: cnt-=1 if cnt > ch: ch = cnt print(ch)
s582578329
Accepted
17
2,940
98
input() x,mx=0,0 for w in input(): #print(w) x+=1 if w=='I' else -1 mx = max(x,mx) print(mx)
s560928623
p03475
u428132025
3,000
262,144
Wrong Answer
299
5,188
453
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.
import sys input = sys.stdin.readline n = int(input()) c, s, f = [0]*(n-1), [0]*(n-1), [0]*(n-1) for i in range(n-1): c[i], s[i], f[i] = map(int, input().split()) ans = [0]*n for i in range(n-1): time = s[i] for j in range(i, n-1): if time < s[j]: time = s[j] if time % f[j] != 0: time += f[j] - time % f[j] time += c[j] print(i, j, time) ans[i] = time for i in ans: print(i)
s412184969
Accepted
106
3,188
427
import sys input = sys.stdin.readline n = int(input()) c, s, f = [0]*(n-1), [0]*(n-1), [0]*(n-1) for i in range(n-1): c[i], s[i], f[i] = map(int, input().split()) ans = [0]*n for i in range(n-1): time = s[i] for j in range(i, n-1): if time < s[j]: time = s[j] if time % f[j] != 0: time += f[j] - time % f[j] time += c[j] ans[i] = time for i in ans: print(i)
s814805313
p02415
u720674978
1,000
131,072
Wrong Answer
20
5,532
24
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
print(input().swapcase)
s543043180
Accepted
20
5,540
26
print(input().swapcase())
s034421826
p03971
u714931250
2,000
262,144
Wrong Answer
82
9,308
396
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
n,a,b = map(int, input().split()) s = str(input()) a_count,b_count = 0,0 for i in range(n): if s[i] == 'c': print('No') elif s[i] == 'a': if a_count+b_count < a+b: print('Yes') a_count += 1 else: print('No') elif s[i] == 'b': if a_count+b_count < a+b and b_count < b: print('Yes') b_count += 1 else: print('No') print(a_count,b_count)
s613183597
Accepted
80
9,312
373
n,a,b = map(int, input().split()) s = str(input()) a_count,b_count = 0,0 for i in range(n): if s[i] == 'c': print('No') elif s[i] == 'a': if a_count+b_count < a+b: print('Yes') a_count += 1 else: print('No') elif s[i] == 'b': if a_count+b_count < a+b and b_count < b: print('Yes') b_count += 1 else: print('No')
s361471785
p03471
u591808161
2,000
262,144
Wrong Answer
808
3,064
516
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) n, y = MI() result = "-1 -1 -1" for i in range(n, -1, -1): a = i * 10000 if a > y: break for j in range(n-i, -1, -1): b = a + j * 5000 if b > y: break if b + 1000 * (n-i-j) == y: result = str(a)+" "+str(b)+" "+str(n-i-j) print(result) sys.exit() print(result)
s836735413
Accepted
514
3,064
600
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): n, y = MI() result = "-1 -1 -1" for i in range(n, -1, -1): a = i * 10000 if a <= y: for j in range(n-i, -1, -1): b = a + j * 5000 if b <= y: if b + 1000 * (n-i-j) == y: result = str(i)+" "+str(j)+" "+str(n-i-j) print(result) sys.exit() print(result) main()
s675603505
p03407
u887207211
2,000
262,144
Wrong Answer
19
3,064
83
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
A, B, C = map(int,input().split()) if(A+B <= C): print("Yes") else: print("No")
s907672658
Accepted
18
2,940
104
A, B, C = map(int,input().split()) ans = "No" if(A+B >= C or A >= C or B >= C): ans = "Yes" print(ans)
s486485806
p03155
u474925961
2,000
1,048,576
Wrong Answer
17
2,940
68
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
n=int(input()) h=int(input()) w=int(input()) print((h-n+1)*(w-n+1))
s867027737
Accepted
17
2,940
68
n=int(input()) h=int(input()) w=int(input()) print((n-h+1)*(n-w+1))
s443875309
p03149
u871303155
2,000
1,048,576
Wrong Answer
18
2,940
115
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
l = map(int, input().split()) list = [1, 4, 7, 9] for num in list: if(num not in l): print("NO") print("YES")
s463020087
Accepted
19
2,940
181
l = list(map(int, input().split())) list = [1, 4, 7, 9] flg = True for num in list: if(num in l): pass else: flg = False if(flg): print("YES") else: print("NO")
s248017569
p03672
u697696097
2,000
262,144
Wrong Answer
18
3,188
122
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
s=input().strip() for i in range(1000): r=-2*i s2 = s[:r] half=len(s2)//2 if s2[half:]==s2[:half*-1]: print(r)
s936474064
Accepted
17
3,060
157
import sys s=input().strip() for i in range(1,1000): r=-2*i s2 = s[:r] half=len(s2)//2 if s2[half:]==s2[:half*-1]: print(len(s)+r) sys.exit()
s004738291
p03434
u487594898
2,000
262,144
Wrong Answer
17
3,064
199
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
N = int(input()) A = list(map(int,input().split())) SA = sorted(A,reverse=True) ALI =0 BOB=0 for i in range(1,N,2): ALI += SA[i] for n in range(2,N,2): BOB += SA[n] ans = ALI - BOB print(ans)
s265639680
Accepted
18
3,060
210
N = int(input()) A = list(map(int,input().split())) SA = sorted(A,reverse=True) ALI =0 BOB=0 for i in range(0,N,2): ALI += int(SA[i]) for n in range(1,N,2): BOB += int(SA[n]) ans = ALI - BOB print(ans)
s598336140
p03624
u193927973
2,000
262,144
Wrong Answer
27
3,956
173
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
s=list(input()) s=list(set(s)) s.sort() print(s) import string l=string.ascii_lowercase ans="None" for i in range(len(s)): if s[i]!=l[i]: ans=l[i] break print(ans)
s290577518
Accepted
26
3,956
134
s=list(input()) s=set(s) import string l=string.ascii_lowercase ans="None" for a in l: if a not in s: ans=a break print(ans)
s173401026
p03564
u825528847
2,000
262,144
Wrong Answer
20
3,316
336
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
import re S = input() T = input() lenT = len(T) can = [] for it in re.finditer(T[0], S): a = it.span()[0] tmp = S[a+1: a+lenT] if len(tmp) == len(T) - 1 and all("?" == h for h in list(tmp)): tmp = S[:a] + T + S[a+lenT:] can.append(tmp.replace("?", "a")) print("UNRESTORABLE" if len(can) == 0 else can[-1])
s863516817
Accepted
18
2,940
90
N = int(input()) K = int(input()) x = 1 for _ in range(N): x = min(2*x, x+K) print(x)
s777888927
p02743
u514118270
2,000
1,048,576
Wrong Answer
17
2,940
130
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c = list(map(int,input().split())) d = 1 / 2 A = a ** d B = b ** d C = c ** d if A + B < c: print('Yes') else: print('No')
s127345298
Accepted
43
5,332
172
from decimal import Decimal a,b,c = list(map(Decimal,input().split())) d = Decimal('0.5') A = a ** d B = b ** d C = c ** d if A + B < C: print('Yes') else: print('No')
s915903449
p02388
u249954942
1,000
131,072
Wrong Answer
20
7,364
90
Write a program which calculates the cube of a given integer x.
## coding: UTF-8 def main(): print(pow(int(input()), 3)) if __name__ == "main": main()
s513910199
Accepted
30
7,640
45
x = int(input()) y = 3 p = pow(x, y) print(p)
s409850251
p03251
u397953026
2,000
1,048,576
Wrong Answer
26
9,136
242
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())) x.sort() y.sort() for i in range(X+1,Y+1,1): if i <= y[0] and i > x[-1]: print("No war") break else: print("War")
s333229721
Accepted
31
9,148
245
n,m,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) x.sort() y.sort() for i in range(X+1,Y+1,1): if i <= min(y) and i > max(x): print("No War") break else: print("War")
s827389008
p03377
u944209426
2,000
262,144
Wrong Answer
17
2,940
136
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = list(map(int, input().split())) ans=0 if a+b>=x: if a<=x: ans+=1 if ans==0: print('No') else: print('Yes')
s671541043
Accepted
20
3,316
136
a, b, x = list(map(int, input().split())) ans=0 if a+b>=x: if a<=x: ans+=1 if ans==0: print('NO') else: print('YES')
s902270604
p03759
u133936772
2,000
262,144
Wrong Answer
17
2,940
60
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c = map(int,input().split()) print('YNEOS'[a-b!=c-b::2])
s664662636
Accepted
19
2,940
61
a,b,c = map(int,input().split()) print('YNEOS'[a-b!=b-c::2])
s536657510
p03958
u422104747
1,000
262,144
Wrong Answer
25
3,064
90
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
l=list(map(int, input().split())) r=list(map(int, input().split())) print(2*max(r)-l[0]-1)
s900825091
Accepted
22
3,064
97
l=list(map(int, input().split())) r=list(map(int, input().split())) print(max(0,2*max(r)-l[0]-1))
s875388731
p03731
u140251125
2,000
262,144
Wrong Answer
146
25,196
235
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
# input N, T = map(int, input().split()) T_lst = list(map(int, input().split())) ans = 0 for i in range(N): if T_lst[i] <= T_lst[i - 1] + T: ans += T_lst[i] - T_lst[i - 1] else: ans += T ans += T print(ans)
s169471961
Accepted
151
26,832
238
# input N, T = map(int, input().split()) T_lst = list(map(int, input().split())) ans = 0 for i in range(1, N): if T_lst[i] <= T_lst[i - 1] + T: ans += T_lst[i] - T_lst[i - 1] else: ans += T ans += T print(ans)
s124892977
p04029
u540912766
2,000
262,144
Wrong Answer
26
9,096
40
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?
N = int(input()) print(N * (N + 1) / 2)
s598264672
Accepted
23
9,164
45
N = int(input()) print(int(N * (N + 1) / 2))
s326323257
p03673
u589969467
2,000
262,144
Wrong Answer
2,206
30,860
196
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
n = int(input()) a = list(map(int,input().split())) ans = [] for i in range(n): if i%2==1: ans.insert(0,a[i]) else: ans.append(a[i]) if n%2==1: ans.reverse() print(ans)
s250831252
Accepted
823
31,504
445
import collections def f(myList): ans = '' if len(myList)%2==0: for i in range(len(myList)): ans += str(myList[i]) + ' ' else: for i in range(len(myList)): ans += str(myList[-(i+1)]) + ' ' return ans[:-1] n = int(input()) a = list(map(int,input().split())) b = collections.deque() for i in range(n): if i%2==0: b.append(a[i]) else: b.appendleft(a[i]) print(f(b))
s206697307
p02678
u578464015
2,000
1,048,576
Wrong Answer
1,465
46,364
458
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()) d={} for i in range(m): x,y=map(int,input().split()) if x in d: d[x].append(y) else: d[x]=[y] if y in d: d[y].append(x) else: d[y]=[x] parent=[0]*(n+1) bfs=[1] visited=set([1]) while len(bfs)!=0: x=bfs.pop(0) visited.add(x) for i in d[x]: if i not in visited: bfs.append(i) parent[i]=x visited.add(i) if len(visited)==n: print('YES') for i in range(2,n+1): print(parent[i]) else: print('NO')
s468470816
Accepted
1,586
46,304
458
n,m=map(int,input().split()) d={} for i in range(m): x,y=map(int,input().split()) if x in d: d[x].append(y) else: d[x]=[y] if y in d: d[y].append(x) else: d[y]=[x] parent=[0]*(n+1) bfs=[1] visited=set([1]) while len(bfs)!=0: x=bfs.pop(0) visited.add(x) for i in d[x]: if i not in visited: bfs.append(i) parent[i]=x visited.add(i) if len(visited)==n: print('Yes') for i in range(2,n+1): print(parent[i]) else: print('No')
s041489461
p03760
u551109821
2,000
262,144
Wrong Answer
17
3,060
166
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()) ans = [] for i in range(len(E)): ans.append(O[i]) ans.append(E[i]) if len(O) > len(E): ans.append(O[-1]) print(ans)
s567426362
Accepted
17
3,060
175
O = list(input()) E = list(input()) ans = [] for i in range(len(E)): ans.append(O[i]) ans.append(E[i]) if len(O) > len(E): ans.append(O[-1]) print(''.join(ans))
s859929380
p02388
u676498528
1,000
131,072
Wrong Answer
30
6,716
4
Write a program which calculates the cube of a given integer x.
2**3
s272630543
Accepted
30
6,724
42
num = input() num = int(num) print(num**3)
s801153595
p02616
u597553490
2,000
1,048,576
Wrong Answer
235
33,252
2,230
Given are N integers A_1,\ldots,A_N. We will choose exactly K of these elements. Find the maximum possible product of the chosen elements. Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).
import sys, bisect if(__name__ == "__main__"): N, K = map( int, input().strip().split() ) divisor = 10**9+7 list_a = list( map(int, input().strip().split()) ) multiplies = 1 if(N==K or N==1): for i in range(N): multiplies = multiplies * list_a[i] % divisor print(multiplies) else: list_a.sort() N_negative_numbers = bisect.bisect_left(list_a, 0) N_select_negatives = K + N_negative_numbers -N flag_overzero = True if(N_select_negatives > 0 and N_select_negatives % 2 != 0): flag_overzero = False if(flag_overzero == True): left = 0 right = N-1 multiply_right = list_a[right] * list_a[right-1] flag_left = True while(K>0): if(K>1): K -= 2 if(flag_left==True): multiply_left = list_a[left] * list_a[left+1] else: multiply_right = list_a[right] * list_a[right-1] if(multiply_left > multiply_right): multiply_left %= divisor multiplies = multiplies * multiply_left % divisor left += 2 flag_left=True print(multiply_left, multiplies) else: multiply_right %= divisor multiplies = multiplies * multiply_right % divisor right -= 2 flag_left=False print(multiply_right, multiplies) else: multiplies = multiplies * list_a[right] % divisor K =0 print(multiplies) else: list_a = [ abs(list_a[i]) for i in range(N)] list_a.sort() for i in range(K-1): multiplies = multiplies * list_a[i] % divisor multiplies = (-1) * multiplies * list_a[K-1] % divisor print(multiplies)
s430855502
Accepted
147
30,852
3,294
import sys if(__name__ == "__main__"): N, K = map( int, input().strip().split() ) divisor = 10**9+7 list_a = list( map( int, input().strip().split() ) ) multiplies = 1 if(N==K): for i in range(N): multiplies = multiplies * list_a[i] % divisor else: list_a.sort() if(list_a[-1] < 0 and K % 2 != 0): for i in range(K): multiplies = multiplies * list_a[N-1-i] % divisor elif(K==1): multiplies = list_a[N-1] else: left = 0 right = N-1 if(K%2!=0): multiplies = multiplies * list_a[right] % divisor right -= 1 multiply_left = list_a[left] * list_a[left+1] multiply_right = list_a[right] * list_a[right-1] flag_left = True for s in range(K//2): if(flag_left==True): multiply_left = list_a[left] * list_a[left+1] else: multiply_right = list_a[right] * list_a[right-1] if(multiply_left < multiply_right): multiply_right %= divisor multiplies = multiplies * multiply_right % divisor right -= 2 flag_left=False else: multiply_left%=divisor multiplies = multiplies * multiply_left % divisor left += 2 flag_left=True print(multiplies)