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
s115270428
p02619
u732870425
2,000
1,048,576
Wrong Answer
38
9,320
372
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
D = int(input())#D=365 c = list(map(int, input().split()))#0<=c<=100 s = [list(map(int, input().split())) for _ in range(D)]#0<=s<=20000 t = [int(input()) for _ in range(D)] v = [] last = [0] * 26 value = 0 for d in range(D): for i in range(26): value += s[d][i] value += c[i] * (d - last[i]) v.append(value) for i in range(D): print(v[i])
s550225708
Accepted
30
9,360
422
D = int(input())#D=365 c = list(map(int, input().split()))#0<=c<=100 s = [list(map(int, input().split())) for _ in range(D)]#0<=s<=20000 t = [int(input()) for _ in range(D)] v = [] last = [0] * 26 value = 0 for d in range(D): type = t[d] value += s[d][type - 1] last[type - 1] = d + 1 for i in range(26): value -= c[i] * (d + 1 - last[i]) v.append(value) for i in range(D): print(v[i])
s226177640
p03352
u123896133
2,000
1,048,576
Wrong Answer
17
2,940
156
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
X = int(input()) listx = [] for i in range(40): for j in range(2,11): if i**j<=X: listx.append(i**j) print(max(listx)) print(listx)
s617535111
Accepted
17
2,940
143
X = int(input()) listx = [] for i in range(40): for j in range(2,11): if i**j<=X: listx.append(i**j) print(max(listx))
s967958761
p03434
u859897687
2,000
262,144
Wrong Answer
17
3,060
149
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())) a.sort(reverse=True) ans=0 for i in range(0,n,2): ans+=i for i in range(1,n,2): ans-=i print(ans)
s069493083
Accepted
17
3,060
155
n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) ans=0 for i in range(0,n,2): ans+=a[i] for i in range(1,n,2): ans-=a[i] print(ans)
s299413486
p03486
u346371758
2,000
262,144
Wrong Answer
33
4,208
138
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.
import random s = list(input()) s_ = str(random.shuffle(s)) t = list(input()) t_ = str(random.shuffle(t)) print('Yes' if s_< t_ else 'No')
s719047995
Accepted
17
2,940
111
s = list(input()) s_ = sorted(s) t = list(input()) t_ = sorted(t,reverse=True) print('Yes' if s_< t_ else 'No')
s599642480
p03007
u044220565
2,000
1,048,576
Wrong Answer
184
23,308
1,483
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read printout = sys.stdout.write sprint = sys.stdout.flush #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10 ** 7) #import math # from itertools import product, accumulate, combinations, product import bisect # import numpy as np # from copy import deepcopy #from collections import deque # from decimal import Decimal # from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 998244353 def intread(): return int(sysread()) def mapline(t=int): return map(t, sysread().split()) def mapread(t=int): return map(t, read().split()) def run(): N, *A = mapread() A.sort() i = bisect.bisect_right(A, -EPS) cache = [] if i <= N-1: if i < 1: i = 1 ans = A[i-1] for k in range(i, N-1): cache.append((ans, A[k])) ans -= A[k] cache.append((ans, A[N-1])) ans = A[N-1] - ans for k in range(0, i-1): cache.append((ans, A[k])) ans -= A[k] print(ans) for x, y in cache: print(f'{x} {y}') elif i > N-1: ans = A[-1] for i in range(N-1): cache.append((ans, A[i])) ans -= A[i] print(ans) for x, y in cache: print(f'{x} {y}') if __name__ == "__main__": #print(math.gcd(0, 10)) run()
s149822882
Accepted
233
23,200
1,483
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read printout = sys.stdout.write sprint = sys.stdout.flush #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10 ** 7) #import math # from itertools import product, accumulate, combinations, product import bisect # import numpy as np # from copy import deepcopy #from collections import deque # from decimal import Decimal # from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 998244353 def intread(): return int(sysread()) def mapline(t=int): return map(t, sysread().split()) def mapread(t=int): return map(t, read().split()) def run(): N, *A = mapread() A.sort() i = bisect.bisect_right(A, -EPS) cache = [] if i <= N-1: if i < 1: i = 1 ans = A[i-1] for k in range(i, N-1): cache.append((ans, A[k])) ans -= A[k] cache.append((A[N-1], ans)) ans = A[N-1] - ans for k in range(0, i-1): cache.append((ans, A[k])) ans -= A[k] print(ans) for x, y in cache: print(f'{x} {y}') elif i > N-1: ans = A[-1] for i in range(N-1): cache.append((ans, A[i])) ans -= A[i] print(ans) for x, y in cache: print(f'{x} {y}') if __name__ == "__main__": #print(math.gcd(0, 10)) run()
s794866733
p03672
u098968285
2,000
262,144
Wrong Answer
19
2,940
219
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 = "".join(list(reversed(input()))) n = len(s) ans = 0 for i in range(n): if (n - i) % 2 == 0: now = s[i:] if now[(n-i)//2:] == now[:(n-i)//2]: ans = n - i break print(ans)
s221950419
Accepted
17
2,940
223
s = "".join(list(reversed(input()))) n = len(s) ans = 0 for i in range(1, n): if (n - i) % 2 == 0: now = s[i:] if now[(n-i)//2:] == now[:(n-i)//2]: ans = n - i break print(ans)
s821525518
p02796
u728303437
2,000
1,048,576
Wrong Answer
419
18,956
331
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
n=int(input()) x=[] l=[] w=[] max=-(10**10) num=0 for i in range(n): X,L=map(int,input().split()) x.append(X) l.append(L) w.append(X-L) w.append(X+L) for i in range(len(w)): if (w[i]<max) and i%2==0: num+=1 elif (w[i]<max) and i%2==1: num+=0 else: max=w[i] print(len(w)-num)
s616702649
Accepted
440
21,336
229
n=int(input()) w=[] for i in range(n): x,l=map(int,input().split()) w.append([x-l,x+l]) w.sort(key=lambda x: x[1]) val=-(10**10) ans=0 for i in range(n): if val<=w[i][0]: ans+=1 val=w[i][1] print(ans)
s279863342
p02972
u735891571
2,000
1,048,576
Wrong Answer
1,954
18,100
464
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.
import numpy as np n = int(input()) a = list(map(int,input().split())) ans = np.array(a) k = 2 for i in reversed(range(1, n+1)): if n/k < i: for x in range(2, k): ans[i-1] += ans[x * i - 1] ans[i-1] = ans[i-1] % 2 else: k += 1 for x in range(2, k): ans[i-1] += ans[x * i - 1] ans[i-1] = ans[i-1] % 2 print(np.sum(ans)) for p in np.ndarray.flatten(np.argwhere(ans) + 1): print(p, end=' ')
s045012724
Accepted
891
12,656
443
n = int(input()) a = list(map(int,input().split())) ans = [] k = 2 for i in range(n, 0, -1): if n/k < i: for x in range(2, k): a[i-1] += a[x * i - 1] a[i-1] = a[i-1] % 2 else: while n/k >= i: k += 1 else: for x in range(2, k): a[i-1] += a[x * i - 1] a[i-1] = a[i-1] % 2 if a[i-1] == 1: ans.append(i) print(len(ans)) print(*ans)
s768145974
p02854
u588558668
2,000
1,048,576
Wrong Answer
222
26,220
154
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
n=int(input()) a=list(map(int,input().split())) su=0 mi=2000000 for i in range(n): su+=a[i] left=n-su mi=min(mi,max((su-left),(left-su))) print(mi)
s353244304
Accepted
260
26,220
204
n=int(input()) a=list(map(int,input().split())) su=0 mi=20000000000000000000 for i in range(n): su+=a[i] c=0 for i in range(n): c+=a[i] left=su-c mi=min(mi,max((c-left),(left-c))) print(mi)
s099048073
p03712
u252964975
2,000
262,144
Wrong Answer
18
3,060
157
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()) str_ = "" for i in range(W): str_ = str_ + "#" print(str_) for i in range(H): S=str(input()) print("#"+S+"#") print(str_)
s588448190
Accepted
18
2,940
160
H,W=map(int, input().split()) str_ = "" for i in range(W+2): str_ = str_ + "#" print(str_) for i in range(H): S=str(input()) print("#"+S+"#") print(str_)
s334905373
p02259
u231136358
1,000
131,072
Wrong Answer
20
7,692
331
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.
# selection sort N = int(input()) A = [int(i) for i in input().split()] cnt = 0 for i in range(0, N): min_i = i for j in range(i+1, N)[::-1]: if A[j] < A[min_i]: min_i = j if i != min_i: A[i], A[min_i] = A[min_i], A[i] cnt = cnt + 1 print(' '.join([str(i) for i in A])) print(cnt)
s047902266
Accepted
30
7,724
267
N = int(input()) A = [int(i) for i in input().split()] cnt = 0 for i in range(0, N): for j in range(i+1, N)[::-1]: if A[j] < A[j-1]: A[j], A[j-1] = A[j-1], A[j] cnt = cnt + 1 print(' '.join([str(item) for item in A])) print(cnt)
s507705035
p03448
u755180064
2,000
262,144
Wrong Answer
55
3,064
272
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.
coins = [] for i in range(0, 4): coins.append(int(input())) count = 0 for i in range(1, coins[0] + 1): for j in range(1, coins[1] + 1): for k in range(1, coins[2] + 1): ans = 500*i + 100*j + 50*k if ans == coins[3]: count += 1 print(count)
s196020970
Accepted
43
3,060
426
url = "https://atcoder.jp/contests/abc087/tasks/abc087_b" def main(): coins = [int(input()) for v in range(3)] che = int(input()) count = 0 for i in range(0, coins[0] + 1): for j in range(0, coins[1] + 1): for k in range(0, coins[2] + 1): if che == (500 * i) + (100 * j) + (50 * k): count += 1 print(count) if __name__ == '__main__': main()
s952279887
p02853
u858670323
2,000
1,048,576
Wrong Answer
17
3,060
267
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
X, Y = map(int,input().split()) sum = 0 def get_money(X, sum): if X == 1: sum += 300000 elif X == 2: sum += 200000 elif X == 3: sum += 100000 get_money(X, sum) get_money(Y, sum) if X == 1 and Y ==1: sum += 400000 print(sum)
s614960985
Accepted
18
3,060
359
X, Y = map(int,input().split()) def get_money(X): if X == 1: return 300000 elif X == 2: return 200000 elif X == 3: return 100000 else: return 0 def double_money(X, Y): if X == 1 and Y == 1: return 400000 else: return 0 sum = get_money(X) + get_money(Y) +double_money(X, Y) print(sum)
s568856283
p03545
u128583260
2,000
262,144
Wrong Answer
26
9,028
312
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
s=list(input()) for i in range(2**(len(s)-1)): f =['']*(len(s)-1) siki='' for j in range(len(s)-1): if(i>>j & 1): f[j] = '+' else: f[j] = '-' for k in range(len(s)-1): siki += s[k] + f[k] siki += s[-1] if eval(siki)==7: print(siki)
s845693000
Accepted
30
9,028
352
s=list(input()) for i in range(2**(len(s)-1)): f =['']*(len(s)-1) siki='' for j in range(len(s)-1): if(i>>j & 1): f[j] = '+' else: f[j] = '-' for k in range(len(s)-1): siki += s[k] + f[k] siki += s[-1] if eval(siki)==7: siki += '=7' print(siki) break
s881149929
p03044
u263830634
2,000
1,048,576
Wrong Answer
394
4,720
402
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
N = int(input()) lst = [0] * (N+1) for i in range(N-1): u, v, w = map(int, input().split()) if w%2 == 0: # print ('A') if lst[u] == 0 and lst [v] == 0: lst[u] = 1 lst[v] = 1 elif lst[u] != 0: lst[v] = lst[u] elif lst[v] != 0: lst[u] = lst[v] # print (lst) #print (lst) for j in range(1,N+1): print(lst[j])
s064046404
Accepted
1,075
82,288
870
N = int(input()) import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline lst = [[] for _ in range(N + 1)] for _ in range(N - 1): u, v, w = map(int, input().split()) w = w%2 lst[u].append([v, w]) lst[v].append([u, w]) # print (lst) ans = [-1] * (N + 1) def dfs(x): # return ans[x] for i in lst[x]: # print (i) if ans[i[0]] == -1: if i[1] == 0: ans[i[0]] = ans[x] dfs(i[0]) else: ans[i[0]] = (ans[x] + 1) % 2 dfs(i[0]) return ans[1] = 0 dfs(1) for i in ans[1:]: print (i)
s591523362
p02289
u255317651
2,000
131,072
Wrong Answer
60
21,244
1,494
A priority queue is a data structure which maintains a set $S$ of elements, each of with an associated value (key), and supports the following operations: * $insert(S, k)$: insert an element $k$ into the set $S$ * $extractMax(S)$: remove and return the element of $S$ with the largest key Write a program which performs the $insert(S, k)$ and $extractMax(S)$ operations to a priority queue $S$. The priority queue manages a set of integers, which are also keys for the priority.
# -*- coding: utf-8 -*- """ Created on Sat Jun 9 13:21:18 2018 ALDS1-9c @author: maezawa """ import math def parent(node): return math.floor(node/2) def left(node): return 2*node def right(node): return 2*node+1 def max_heapify(a, i): l = left(i) r = right(i) if l <= h and a[l-1] > a[i-1]: largest = l else: largest = i if r <= h and a[r-1] > a[largest-1]: largest = r if largest != i: a[i-1], a[largest-1] = a[largest-1], a[i-1] max_heapify(a, largest) def build_max_heap(a): for i in list(range(1,h//2+1))[::-1]: max_heapify(a, i) #print(a) def insert(key): global h h += 1 a[h-1] = -3*10**9 heap_increase_key(a, h, key) def heap_increase_key(a, i, key): if key < a[i-1]: print('error') return False a[i-1] = key while i > 1 and a[parent(i)] < a[i-1]: a[i-1], a[parent(i)] = a[parent(i)], a[i-1] i = parent(i) def heap_extract(a): global h if h < 1: print('error') maxh = a[0] a[0] = a[h-1] h -= 1 max_heapify(a, 1) return maxh a = [0]*2000001 h = 0 while True: s = input() if s == 'end': break if s == 'extract': print(heap_extract(a)) continue opcode, operand = s.split() data = int(operand) if opcode == 'insert': insert(data) for i in range(h): print(' {}'.format(a[i]),end = '') print()
s924122828
Accepted
9,070
45,316
376
# -*- coding: utf-8 -*- """ Created on Sat Jun 9 13:21:18 2018 ALDS1-9c @author: maezawa """ import heapq as hq h = [] while True: s = input() if s == 'end': break if s == 'extract': print(-hq.heappop(h)) continue opcode, operand = s.split() data = int(operand) if opcode == 'insert': hq.heappush(h, -data)
s877526931
p03845
u535659144
2,000
262,144
Wrong Answer
24
3,572
235
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds. It does not affect the time to solve the other problems. A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.
import copy t=input() qlist = list(map(int,input().split())) hmd = int(input()) for i in range(hmd): drk=list(map(int,input().split())) alist = copy.copy(qlist) alist[drk[0]-1]=drk[1] print(alist) print(sum(alist))
s112287357
Accepted
24
3,444
218
import copy t=input() qlist = list(map(int,input().split())) hmd = int(input()) for i in range(hmd): drk=list(map(int,input().split())) alist = copy.copy(qlist) alist[drk[0]-1]=drk[1] print(sum(alist))
s146603169
p03044
u185948224
2,000
1,048,576
Wrong Answer
446
33,764
486
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
N = int(input()) uvw = [list(map(int, input().split())) for _ in range(N-1)] clrs = [-1]*(N+1) for u, v, w in uvw: if clrs[u]!=-1 and clrs[v]==-1: if w%2==0:clrs[v]=clrs[u] else:clrs[v]=(clrs[u]+1)%2 elif clrs[u]==-1 and clrs[v]!=-1: if w%2==0:clrs[u]=clrs[v] else:clrs[u]=(clrs[v]+1)%2 else: if w%2==0: clrs[u]=1 clrs[v]=1 else: clrs[u]=0 clrs[v]=1 print(*clrs[1:N+1], sep='\n')
s321302022
Accepted
1,034
77,628
729
from collections import Counter, deque N = int(input()) uvw = [list(map(int, input().split())) for _ in range(N-1)] udict ={} uvdict = {} lst = [] ans = [-1]*(N+1) for u, v, w in uvw: if u in udict:udict[u].append(v) else:udict[u] =[v] if v in udict:udict[v].append(u) else:udict[v] =[u] lst.append(u) lst.append(v) uvdict[(u,v)] = w cnt = Counter(lst) cnt_max = cnt.most_common()[0][0] nxt = deque() nxt.append(cnt_max) passed = [0]*(N+1) d = [0]*(N+1) while nxt!=deque([]): l1 = nxt.popleft() for l2 in udict[l1]: if passed[l2]==1:continue d[l2] = d[l1] + uvdict[min(l1, l2), max(l1, l2)] nxt.append(l2) passed[l1]=1 for i in d[1:]: print(i%2)
s534835803
p02260
u159356473
1,000
131,072
Wrong Answer
20
7,712
901
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.
#coding:UTF-8 def BS(N,A): for i in range(N): for j in reversed(range(i+1,N)): if int(A[j][1:])<int(A[j-1][1:]): swap=A[j] A[j]=A[j-1] A[j-1]=swap return A def SS(N,A): for i in range(N): minj=i for j in range(i,N): if int(A[j][1:]) < int(A[minj][1:]): minj=j swap=A[i] A[i]=A[minj] A[minj]=swap return A def Stable(A1,A2): ans="Stable" for i in range(len(A1)): if A1[i][1:]==A2[i][1:] and A1[i][:1]!=A2[i][:1]: ans="Not stable" return ans def SS2(N,A,B): print(A,B) A1=BS(N,A) print(" ".join(A1)) print("Stable") A2=SS(N,B) print(" ".join(A2)) print(Stable(A1,A2)) if __name__=="__main__": N=int(input()) a=input() A=a.split(" ") B=a.split(" ") SS2(N,A,B)
s671434296
Accepted
20
7,752
504
#coding:UTF-8 def SS(N,A): count=0 for i in range(N): minj = i for j in range(i,N): if A[j]<A[minj]: minj=j if i!=minj: count+=1 swap=A[i] A[i]=A[minj] A[minj]=swap for i in range(len(A)): A[i]=str(A[i]) print(" ".join(A)) print(count) if __name__=="__main__": N=int(input()) a=input() A=a.split(" ") for i in range(len(A)): A[i]=int(A[i]) SS(N,A)
s405774335
p03129
u785220618
2,000
1,048,576
Wrong Answer
19
2,940
92
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
n, k = map(int, input().split()) if k <= -(-n // 2): print('Yes') else: print('No')
s141358315
Accepted
17
3,064
92
n, k = map(int, input().split()) if k <= -(-n // 2): print('YES') else: print('NO')
s609321805
p02388
u922489088
1,000
131,072
Wrong Answer
20
7,424
28
Write a program which calculates the cube of a given integer x.
def test(x): return x**2
s131684417
Accepted
20
7,572
62
import sys d = int(sys.stdin.readline().rstrip()) print(d**3)
s734287178
p02402
u002193969
1,000
131,072
Wrong Answer
20
5,592
183
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
n = int(input()) ai = [int(x) for x in input().split()] min = ai[0] max = ai[0] total = 0 for x in ai: total += x if x < min: min = x if x > max: max = x
s997503372
Accepted
20
6,600
206
n = int(input()) ai = [int(x) for x in input().split()] min = ai[0] max = ai[0] total = 0 for x in ai: total += x if x < min: min = x if x > max: max = x print(min, max, total)
s455158288
p02578
u279439669
2,000
1,048,576
Wrong Answer
168
33,752
359
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
from typing import List def step(n: int, a: List[int])-> int: result = 0 dai = 0 for i in range(1,n): sub = a[i-1] + dai - a[i] print(sub) if sub > 0: dai = sub result += sub continue dai = 0 return result if __name__ == "__main__": n = int(input()) a = list(map(int, input().split())) print(step(n, a))
s635000353
Accepted
115
33,496
344
from typing import List def step(n: int, a: List[int])-> int: result = 0 dai = 0 for i in range(1,n): sub = a[i-1] + dai - a[i] if sub > 0: dai = sub result += sub continue dai = 0 return result if __name__ == "__main__": n = int(input()) a = list(map(int, input().split())) print(step(n, a))
s061037089
p03854
u718949306
2,000
262,144
Wrong Answer
62
3,316
263
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
S = input() T = '' words = ['dream', 'dreamer', 'erase', 'eraser'] for i in range(len(words)): words[i] = words[i][::-1] for i in S[::-1]: T += i for q in words: if T == q: T = '' if T == '': print('Yes') else: print('No')
s319284947
Accepted
66
3,188
248
S = input() L = ['dream', 'dreamer', 'erase', 'eraser'] for i in range(len(L)): L[i] = L[i][::-1] S = S[::-1] T = '' for s in S: T += s for i in L: if T == i: T = '' if T == '': print('YES') else: print('NO')
s501649841
p02975
u285891772
2,000
1,048,576
Wrong Answer
61
21,924
1,042
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * N = INT() a = set(LIST()) if N%3 == 0 and len(a) == 3: print("Yes") elif len(a) == 1 and 0 in a: print("Yes") else: print("No")
s566362063
Accepted
63
21,820
1,216
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N = INT() A = LIST() c = Counter(A) a = list(c.keys()) n = len(a) if n == 1 and c[0] == N: print("Yes") elif N%3 == 0: if n == 3 and len(set(c.values())) == 1 and a[0]^a[1] == a[2]: print("Yes") elif n == 2 and c[0] == N//3: print("Yes") else: print("No") else: print("No")
s915204819
p03543
u396961814
2,000
262,144
Wrong Answer
18
2,940
85
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
n = input() if n[0] == n[1] == n[2] == n[3]: print('Yes') else: print('No')
s135171542
Accepted
17
2,940
100
n = input() if n[0] == n[1] == n[2] or n[1] == n[2] == n[3]: print('Yes') else: print('No')
s564824633
p02612
u297891484
2,000
1,048,576
Wrong Answer
25
9,140
61
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.
value = int(input().strip()) exc = value % 1000 print(exc)
s211315224
Accepted
29
9,144
83
value = int(input().strip()) exc = value % 1000 print(1000-exc if exc > 0 else 0)
s208367782
p03386
u558782626
2,000
262,144
Wrong Answer
17
3,060
140
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 = list(set(range(A, A+K)) | set(range(B-K, B))) ans.sort() for i in ans: if A <= i <= B: print(i)
s251010781
Accepted
17
3,060
144
A, B, K = map(int, input().split()) ans = list(set(range(A, A+K)) | set(range(B-K+1, B+1))) ans.sort() for i in ans: if A <= i <= B: print(i)
s117354336
p03693
u847165882
2,000
262,144
Wrong Answer
17
2,940
77
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()) print("YES" if (100*r+10*g+b%4)==0 else "NO")
s049259834
Accepted
17
2,940
77
r,g,b=map(int,input().split()) print("YES" if (100*r+10*g+b)%4==0 else "NO")
s921436635
p03635
u632114133
2,000
262,144
Wrong Answer
17
2,940
87
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?
words = input() l = len(words) output = words[0] + str(l-2) + words[l-1] print(output)
s999301092
Accepted
20
3,316
81
n, m = input().split() n = int(n) m = int(m) output = (n-1)*(m-1) print(output)
s864943039
p03606
u004025573
2,000
262,144
Wrong Answer
20
3,060
97
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
N=int(input()) ans=0 for i in range(N): l,r=map(int,input().split()) ans+=l-r+1 print(ans)
s693836885
Accepted
20
3,060
111
N=int(input()) ans=0 for i in range(N): l,r=map(int,input().split()) #print(l,r) ans+=r-l+1 print(ans)
s898267115
p04043
u540698208
2,000
262,144
Wrong Answer
17
2,940
112
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
def main(): if input() == '5 7 5': print('YES') else: print('NO') if __name__ == '__main__': main()
s506214173
Accepted
17
2,940
134
def main(): if sorted(input().split()) == ['5','5','7']: print('YES') else: print('NO') if __name__ == '__main__': main()
s583728685
p02399
u326248180
1,000
131,072
Wrong Answer
20
7,476
96
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 = int(a//b) r = a %b f = a // b print("%d %d %d" % (d, r, f))
s125342019
Accepted
20
7,636
96
a, b = map(int, input().split()) d = int(a/b) r = a %b f = a / b print("%d %d %.5f" % (d, r, f))
s481733366
p03574
u914797917
2,000
262,144
Wrong Answer
29
3,444
387
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
H,W=map(int,input().split()) S=[input() for i in range(H)] R=[[] for i in range(H)] for i in range(H): for j in range(W): if S[i][j]=='#': R[i].append('#') else: cnt=0 for k in range(max(0,i-1),min(H,i+2)): for h in range(max(0,j-1),min(W,j+2)): if S[k][h]=='#': cnt+=1 R[i].append(cnt) for i in range(H): print(*R[i])
s700685522
Accepted
25
3,064
415
H,W=map(int,input().split()) S=[input() for i in range(H)] R=['' for i in range(H)] for i in range(H): for j in range(W): sum=0 if i!=0: sum+=S[i-1][max(0,j-1):min(W,j+2)].count('#') sum+=S[i][max(0,j-1):min(W,j+2)].count('#') if i!=H-1: sum+=S[i+1][max(0,j-1):min(W,j+2)].count('#') if S[i][j]=='.': R[i]+=str(sum) else: R[i]+='#' print(*R,sep='\n')
s993021894
p04044
u688925304
2,000
262,144
Wrong Answer
18
3,060
147
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
ln_list = list(map(int, input().split())) print(ln_list) l = [] for list in range(ln_list[0]): l.append(input()) l.sort() a = ''.join(l) print(a)
s243628501
Accepted
17
3,060
134
ln_list = list(map(int, input().split())) l = [] for list in range(ln_list[0]): l.append(input()) l.sort() a = ''.join(l) print(a)
s084469755
p03494
u965581346
2,000
262,144
Wrong Answer
17
2,940
230
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.
# -*- coding: utf-8 -*- numbers = list(map(int, input().split())) count = 0 while(True): if sum(list(map(lambda x: x % 2, numbers))) == 0: numbers = list(map(lambda x: x / 2, numbers)) count += 1 else: break print(count)
s395225090
Accepted
19
3,060
238
# -*- coding: utf-8 -*- input() numbers = list(map(int, input().split())) count = 0 while(True): if sum(list(map(lambda x: x % 2, numbers))) == 0: numbers = list(map(lambda x: x / 2, numbers)) count += 1 else: break print(count)
s822607574
p03502
u354918239
2,000
262,144
Wrong Answer
17
2,940
184
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N = input() L = list(N) counter = 0 for i in range(len(L)) : l = int(L[i]) counter += l if int(N) % counter == 0 : print("Yes") else : print("No") print(counter)
s849156722
Accepted
17
2,940
168
N = input() L = list(N) counter = 0 for i in range(len(L)) : l = int(L[i]) counter += l if int(N) % counter == 0 : print("Yes") else : print("No")
s926095369
p03457
u107267797
2,000
262,144
Wrong Answer
286
28,056
328
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()) L = [list(map(int, input().split())) for i in range(N)] l = [[0, 0, 0]] l.extend(L) flag = True for c in range(1, len(L)): dt = l[c][0] - l[c-1][0] dist = abs(l[c][1] - l[c-1][1]) + abs(l[c][2] - l[c-1][2]) if dist > dt or dist % 2 != dt % 2: flag = False print("YES" if flag else "NO")
s656793153
Accepted
289
28,020
332
N = int(input()) L = [list(map(int, input().split())) for i in range(N)] l = [[0, 0, 0]] l.extend(L) flag = True for c in range(1, len(l)): dt = l[c][0] - l[c-1][0] dist = abs(l[c][1] - l[c-1][1]) + abs(l[c][2] - l[c-1][2]) if dist > dt or (dist % 2) != (dt % 2): flag = False print("Yes" if flag else "No")
s255715887
p03545
u518042385
2,000
262,144
Time Limit Exceeded
2,104
13,552
907
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.
i=input() while True: if int(i[0])+int(i[1])+int(i[2])+int(i[3])==7: print(i[0]+"+"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7") exit elif int(i[0])+int(i[1])+int(i[2])-int(i[3])==7: print(i[0]+"+"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7") exit elif int(i[0])+int(i[1])-int(i[2])-int(i[3])==7: print(i[0]+"+"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7") exit elif int(i[0])-int(i[1])+int(i[2])-int(i[3])==7: print(i[0]+"-"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7") exit elif int(i[0])-int(i[1])-int(i[2])-int(i[3])==7: print(i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7") exit elif int(i[0])+int(i[1])-int(i[2])+int(i[3])==7: print(i[0]+"+"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7") exit elif int(i[0])-int(i[1])+int(i[2])+int(i[3])==7: print(i[0]+"-"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7") exit elif int(i[0])-int(i[1])-int(i[2])+int(i[3])==7: print(i[0]+"-"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7") exit
s241957503
Accepted
18
3,060
201
n=input() l=[1,-1] l1=[0,"+","-"] s="" for i in l: for j in l: for k in l: if int(n[0])+i*int(n[1])+j*int(n[2])+k*int(n[3])==7: s=n[0]+l1[i]+n[1]+l1[j]+n[2]+l1[k]+n[3]+"=7" print(s)
s909841347
p03408
u638282348
2,000
262,144
Wrong Answer
17
3,060
313
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
nblues = int(input()) profits = dict() for _ in range(nblues): word = input().rstrip("\n") profits[word] = profits.get(word, 0) + 1 nreds = int(input()) for _ in range(nreds): word = input().rstrip("\n") profits[word] = profits.get(word, 0) - 1 print(max(profits.items(), key=lambda t: t[1])[0])
s934468747
Accepted
20
3,060
238
dict_ = dict() [exec("dict_['{0}'] = dict_.get('{0}', 0) + 1".format(input())) for _ in range(int(input()))] [exec("dict_['{0}'] = dict_.get('{0}', 0) - 1".format(input())) for _ in range(int(input()))] print(max(max(dict_.values()), 0))
s290800766
p03080
u077019541
2,000
1,048,576
Wrong Answer
18
2,940
89
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
N = [i for i in input()] if N.count("R")>N.count("B"): print("Yes") else: print("No")
s280890221
Accepted
17
2,940
106
s = int(input()) N = [i for i in input()] if N.count("R")>N.count("B"): print("Yes") else: print("No")
s597258188
p02270
u901205536
1,000
131,072
Wrong Answer
20
5,528
673
In the first line, two integers $n$ and $k$ are given separated by a space character. In the following $n$ lines, $w_i$ are given respectively.
def check(P): for i, bag in enumerate(baggage): cur = 0 while su(cur) + bag > P: cur += 1 if cur == k: return False else: lis[cur].append(bag) su[cur] += bag return True def main(): n, k = map(int, input().rstrip().split(" ")) lis = [[] for i in range(k)] su = [0 for i in range(k)] baggage = [int(input()) for i in range(n)] su.append(-1) left = 1 right = 1000000000 while left < right: mid = (left + right)//2 + 1 if check(mid): right = mid else: left = mid print(right)
s847831381
Accepted
1,720
17,308
1,123
def check(P): lis = [[] for i in range(k)] su = [0 for i in range(k)] su.append(-10000) cur = 0 for i, bag in enumerate(baggage): #cur = 0 #print(su,cur,su[cur]) while su[cur] + bag > P: cur += 1 if cur == k: return False else: lis[cur].append(bag) su[cur] += bag #print(lis, su, P) return True def main(): min_P = 1000000000 left = 1 right = 1000000000 mid = (left + right)//2 while left < right: if check(mid): right = mid if min_P > mid: min_P = mid else: left = mid + 1 mid = (left + right)//2 #print(left,right) print(min_P) if __name__ == '__main__': n, k = map(int, input().rstrip().split(" ")) #n,k= 5,3 baggage = [int(input()) for i in range(n)] main()
s004085073
p03587
u525117558
2,000
262,144
Wrong Answer
17
2,940
36
Snuke prepared 6 problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not. You are given a string S of length 6. If the i-th character of s is `1`, it means that the i-th problem prepared by Snuke is accepted to be used; `0` means that the problem is not accepted. How many problems prepared by Snuke are accepted to be used in the contest?
s=input().split() print (s.count(1))
s893707717
Accepted
17
2,940
26
print (input().count("1"))
s368771213
p00002
u500396695
1,000
131,072
Wrong Answer
30
7,512
186
Write a program which computes the digit number of sum of two integers a and b.
import sys L = sys.stdin.readlines() for line in L: ##line????????????????????? N = line.split() sums = int(N[0]) + int(N[1]) print(len(str(sums))+1)
s119493003
Accepted
20
7,528
184
import sys L = sys.stdin.readlines() for line in L: ##line????????????????????? N = line.split() sums = int(N[0]) + int(N[1]) print(len(str(sums)))
s066890249
p02276
u811733736
1,000
131,072
Wrong Answer
20
7,676
702
Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q. In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r). Your task is to read a sequence A and perform the Partition based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].
def partition(A, p, r): x = A[r - 1] i = p - 1 for j in range(p, r-1): if A[j] <= x: i += 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i+1] A[i+1] = A[r-1] A[r-1] = temp return i if __name__ == '__main__': # ??????????????\??? # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11] num_of_data = int(input()) A = [int(x) for x in input().split(' ')] # ??????????????? p = partition(A, 0, len(A)) print(p) left = A[:p+1] partition = A[p+1] right = A[p+2:] print('{0} [{1}] {2}'.format(' '.join(map(str, left)), partition, ' '.join(map(str, right))))
s759109611
Accepted
70
18,268
919
def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i+1] A[i+1] = A[r] A[r] = temp return i+1 if __name__ == '__main__': # ??????????????\??? # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11] num_of_data = int(input()) A = [int(x) for x in input().split(' ')] # ??????????????? p = partition(A, 0, len(A)-1) left = A[:p] partition = A[p] right = A[p+1:] print('{0} [{1}] {2}'.format(' '.join(map(str, left)), partition, ' '.join(map(str, right))))
s464884492
p03563
u518042385
2,000
262,144
Wrong Answer
17
3,064
550
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
w=input() w1=input() num=len(w) num1=len(w1) start=-1 if num<num1: b1=False for i in range(num-num1+1): b=True for j in range(num1): if w[i+j]=="?" or w[i+j]==w1[j]: pass else: b=False if b: start=i if start==-1: print("UNRESTORABLE") else: word="" for i in range(num): if i<start: if w[i]=="?": word+="a" else: word+=w[i] elif start<=i and i<=start+num1-1: word+=w1[i-start] else: if w[i]=="?": word+="a" else: word+=w[i] print(word)
s314115283
Accepted
17
2,940
42
r=int(input()) s=int(input()) print(2*s-r)
s043361272
p03067
u598229387
2,000
1,048,576
Wrong Answer
17
2,940
84
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a,b,c=map(int,input().split()) if a<= b <=c: print('Yes') else: print('No')
s892859828
Accepted
17
3,060
122
a,b,c=map(int,input().split()) if a<= c <=b: print('Yes') elif b<= c <=a: print('Yes') else: print('No')
s298657392
p03853
u811000506
2,000
262,144
Wrong Answer
20
3,188
117
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
H, W = map(int,input().split()) S = [list(input()) for i in range(H)] for i in range(H): print(S[i]) print(S[i])
s987978671
Accepted
20
3,060
111
H, W = map(int,input().split()) S = [input() for i in range(H)] for i in range(H): print(S[i]) print(S[i])
s721523376
p03455
u459386900
2,000
262,144
Wrong Answer
17
2,940
84
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')
s244342870
Accepted
18
2,940
84
a,b = map(int, input().split()) if a*b%2 == 0: print('Even') else: print('Odd')
s552108225
p04030
u555947166
2,000
262,144
Wrong Answer
17
2,940
74
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
s = '0B1BB1' print(s.replace('0B', '').replace('1B', '').replace('B', ''))
s500877349
Accepted
20
2,940
249
s = input() output = '' for i in range(len(s)): if s[i] == '0': output += '0' elif s[i] == '1': output += '1' else: if output == '': pass else: output = output[:-1] print(output)
s612397922
p00025
u862440080
1,000
131,072
Wrong Answer
20
7,420
156
Let's play Hit and Blow game. _A_ imagines four numbers and _B_ guesses the numbers. After _B_ picks out four numbers, _A_ answers: * The number of numbers which have the same place with numbers _A_ imagined (Hit) * The number of numbers included (but different place) in the numbers _A_ imagined (Blow) For example, if _A_ imagined numbers: 9 1 8 2 and _B_ chose: 4 1 5 9 _A_ should say 1 Hit and 1 Blow. Write a program which reads four numbers _A_ imagined and four numbers _B_ chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9.
ansa=input().split() ansb=input().split() hit = sum((1 for a, b in zip(ansa, ansb) if a == b)) blow = sum((1 for a in ansa if a in ansb)) print(hit, blow)
s857823115
Accepted
30
7,568
237
while True: try: ansa=input().split() ansb=input().split() except: break hit = sum((1 for a, b in zip(ansa, ansb) if a == b)) blow = sum((1 for a in ansa if a in ansb)) print(hit, blow - hit)
s039916200
p03963
u409064224
2,000
262,144
Wrong Answer
17
2,940
62
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls.
a = list(map(int,input().split())) print(a[0] * (a[1]-1) +1)
s321249419
Accepted
17
2,940
52
n,k = map(int,input().split()) print(k*(k-1)**(n-1))
s596266562
p02659
u273186459
2,000
1,048,576
Wrong Answer
21
9,084
39
Compute A \times B, truncate its fractional part, and print the result as an integer.
a,b=map(float,input().split()) print(a)
s666299478
Accepted
108
26,960
94
import math import numpy as np a,b=map(np.longdouble,input().split()) c=int(a)*b print(int(c))
s367036456
p03448
u092278825
2,000
262,144
Wrong Answer
17
3,060
322
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 math s = 0 a = int(input()) b = int(input()) c = int(input()) x = int(input()) while x >= 0 and a>=0 : s += max(0, math.floor(min(b, x//100)-(x-50*c)//100+1)) print(a,x,s) a -= 1 x -= 500 print(s)
s405788375
Accepted
17
3,060
337
#ABC 087 B - Coins import math s = 0 a = int(input()) b = int(input()) c = int(input()) x = int(input()) while x >= 0 and a>=0 : s += max(0, min(b, math.floor(x/100))-max(0,math.ceil((x-50*c)/100))+1) a -= 1 x -= 500 print(s)
s221547009
p03351
u214617707
2,000
1,048,576
Wrong Answer
20
3,316
125
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 - b) + abs(b - c) <= d or abs(a - c) <= d: print("Yes") else: print("No")
s616234368
Accepted
17
2,940
134
a, b, c, d = map(int, input().split()) if (abs(a - b) <= d and abs(b - c) <= d) or abs(a - c) <= d: print("Yes") else: print("No")
s752338383
p03401
u934868410
2,000
262,144
Wrong Answer
223
14,176
204
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
n = int(input()) a = [0] + list(map(int,input().split())) + [0] s = 0 for i in range(n): s += abs(a[i+1] - a[i]) for i in range(n): print(s - abs(a[i+2]-a[i+1]) - abs(a[i+1]-a[i]) + abs(a[i+2]-a[i]))
s305386293
Accepted
220
13,920
206
n = int(input()) a = [0] + list(map(int,input().split())) + [0] s = 0 for i in range(n+1): s += abs(a[i+1] - a[i]) for i in range(n): print(s - abs(a[i+2]-a[i+1]) - abs(a[i+1]-a[i]) + abs(a[i+2]-a[i]))
s721192916
p02612
u065578867
2,000
1,048,576
Wrong Answer
31
9,144
30
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)
s982012419
Accepted
30
9,144
81
n = int(input()) if n%1000 == 0: print(0) else: print(1000 - n%1000)
s665524829
p04044
u969848070
2,000
262,144
Wrong Answer
32
9,024
136
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
n, l = map(int, input().split()) a = [] if n == 1: print(input()) exit() for i in range(n): a.append(input()) a.sort() print(a[0])
s586717398
Accepted
30
9,128
148
n, l = map(int, input().split()) a = [] if n == 1: print(input()) exit() for i in range(n): a.append(input()) a.sort() a = ''.join(a) print(a)
s527641095
p03192
u342051078
2,000
1,048,576
Wrong Answer
17
2,940
82
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N?
#%% N = input() cnt = 0 for i in N: if i == '2': cnt +- 1 print(cnt)
s300662607
Accepted
17
2,940
82
#%% N = input() cnt = 0 for i in N: if i == '2': cnt += 1 print(cnt)
s077399806
p02612
u430726059
2,000
1,048,576
Wrong Answer
28
9,068
18
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.
-int(input())%1000
s729172668
Accepted
28
9,080
25
print(-int(input())%1000)
s173731451
p03435
u089142196
2,000
262,144
Wrong Answer
18
3,064
426
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
c=[list(map(int,input().split())) for i in range(3)] info=True for i in range(101): a1=i b1=c[0][0]-a1 b2=c[0][1]-a1 b3=c[0][2]-a1 s=c[1][0]-b1 t=c[1][1]-b2 a2=s if s!=t: info=False break u=c[2][0]-b1 v=c[2][1]-b2 a3=u if u!=v: info=False break if min(a1,a2,a3,b1,b2,b3)<0: info=False break info=True if info: print("Yes") print(a1,a2,a3,b1,b2,b3) else: print("No")
s252809714
Accepted
17
3,064
428
c=[list(map(int,input().split())) for i in range(3)] for i in range(101): info=True a1=i b1=c[0][0]-a1 b2=c[0][1]-a1 b3=c[0][2]-a1 a2=c[1][0]-b1 a3=c[2][0]-b1 if min(a1,a2,a3,b1,b2,b3)<0: info=False if c[1][1]!=a2+b2: info=False if c[2][1]!=a3+b2: info=False if c[1][2]!=a2+b3: info=False if c[2][2]!=a3+b3: info=False if info: print("Yes") break else: print("No")
s934723891
p02833
u606146341
2,000
1,048,576
Wrong Answer
18
3,060
215
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).
import math n = int(input()) def fact(n, x, ans): if x > n: return ans else: ans += math.floor(n/(2*x)) return fact(n, x*5, ans) if n//2: print(0) else: print(fact(n, 5, 0))
s320865080
Accepted
17
3,060
216
import math n = int(input()) def fact(n, x, ans): if x > n: return ans else: ans += math.floor(n//(2*x)) return fact(n, x*5, ans) if n%2: print(0) else: print(fact(n, 5, 0))
s907395665
p02936
u932868389
2,000
1,048,576
Wrong Answer
1,533
112,372
336
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
N, Q = map(int, input().split()) B = [list(map(int, input().split())) for _ in range(N-1)] C = [list(map(int, input().split())) for _ in range(Q)] count = [ 0 for _ in range(N)] for list in C: count[list[0]-1] += list[1] for branch in B: count[branch[1]-1] += count[branch[0]-1] #print(N, Q) #print(C) print(count)
s626304199
Accepted
1,812
301,432
578
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline N, Q = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N-1)] PX = [list(map(int, input().split())) for _ in range(Q)] g = [[] for _ in range(N+1)] for a,b in AB: g[a].append(b) g[b].append(a) cnt = [0] * (N+1) for p,x in PX: cnt[p] += x def dfs(v, p, add): cnt[v] += add for nv in g[v]: if nv == p: continue dfs(nv, v, cnt[v]) dfs(1, 0, 0) print(' '.join(map(str, cnt[1:])))
s463407952
p03067
u113971909
2,000
1,048,576
Wrong Answer
17
2,940
91
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a,b,c=map(int,input().split()) if c in list(range(a,b)): print('YES') else: print('NO')
s728513956
Accepted
17
2,940
105
a,b,c=map(int,input().split()) if c in list(range(min(a,b),max(a,b))): print('Yes') else: print('No')
s015395242
p03130
u400221789
2,000
1,048,576
Wrong Answer
28
9,076
146
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
road = [0]*4 for i in range(3): a,b = map(int,input().split()) road[a-1]+=1 road[b-1]+=1 if max(road)>=3: print('No') else: print('Yes')
s073096403
Accepted
32
9,160
147
road = [0]*4 for i in range(3): a,b = map(int,input().split()) road[a-1]+=1 road[b-1]+=1 if max(road)>=3: print('NO') else: print('YES')
s170949306
p03997
u518556834
2,000
262,144
Wrong Answer
17
2,940
67
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s078117664
Accepted
19
3,060
68
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s741592144
p02607
u096147269
2,000
1,048,576
Wrong Answer
27
9,012
182
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
N = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(N): if i % 2 == 1: if a[i] % 2 == 1: print(a[i]) cnt +=1 print(cnt)
s338167457
Accepted
24
9,020
165
N = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(1,N+1): if i % 2 == 1: if a[i-1] % 2 == 1: cnt +=1 print(cnt)
s540421473
p03795
u296518383
2,000
262,144
Wrong Answer
17
2,940
37
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N=int(input()) print(800*N+N//15*200)
s913534710
Accepted
17
2,940
37
N=int(input()) print(800*N-N//15*200)
s306220264
p04044
u612223903
2,000
262,144
Wrong Answer
18
3,060
155
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
N,L = map(int,input().split()) s = [] for i in range(N): s.append(input()) ans = s[0] for i in range(N): if s[i]<ans: ans = s[i] print(ans)
s971677550
Accepted
17
3,060
105
N,L = map(int,input().split()) s = [] for i in range(N): s.append(input()) s.sort() print(*s,sep= "")
s716880238
p03251
u464032595
2,000
1,048,576
Wrong Answer
17
3,064
436
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 = list(map(int, input().split())) x = [0 for i in range(N)] y = [0 for i in range(M)] x = list(map(int, input().split())) y = list(map(int, input().split())) max_x = max(x) min_y = min(y) r = [i for i in range(max_x, min_y+1)] print(r) count = 1 flag = False while(True): if X + count in r: flag = True break else: count += 1 if X + count == Y: break if flag: print("No War") else: print("War")
s007200999
Accepted
17
3,064
429
N, M, X, Y = list(map(int, input().split())) x = [0 for i in range(N)] y = [0 for i in range(M)] x = list(map(int, input().split())) y = list(map(int, input().split())) max_x = max(x) min_y = min(y) r = [i for i in range(max_x+1, min_y+1)] count = 1 flag = False while(True): if X + count in r: flag = True break else: if X + count == Y: break count += 1 if flag: print("No War") else: print("War")
s798601408
p02401
u227438830
1,000
131,072
Wrong Answer
30
7,520
257
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: a,op,b = input().split() A = int(a) B = int(b) if op == "+": print(A + B) elif op == "=": print(A - B) elif op == "*": print(A * B) elif op == "/": print(A // B) else: break
s010017207
Accepted
20
5,600
253
while True: a,op,b = input().split() A ,B = int(a),int(b) if op == "+": print(A + B) elif op == "-": print(A - B) elif op == "*": print(A * B) elif op == "/": print(A // B) else: break
s646888616
p03730
u408375121
2,000
262,144
Wrong Answer
17
2,940
178
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
def gcd(a, b): if a < b: a, b = b, a while a % b: a, b = b, a % b return b A, B, C = map(int, input().split()) if C % gcd(A, B): print('YES') else: print('NO')
s373552490
Accepted
17
2,940
183
def gcd(a, b): if a < b: a, b = b, a while a % b: a, b = b, a % b return b A, B, C = map(int, input().split()) if C % gcd(A, B) == 0: print('YES') else: print('NO')
s371326765
p02263
u460172144
1,000
131,072
Wrong Answer
20
7,544
439
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
arguments = input().split() print(arguments) array = [] for word in arguments: if word == '-': s1 = array.pop() s2 = array.pop() array.append(s1-s2) elif word == '*': s1 =array.pop() s2 = array.pop() array.append(s1*s2) elif word == '+': s1 = array.pop() s2 = array.pop() array.append(s1+s2) else: array.append(int(word)) print(array.pop())
s010835058
Accepted
20
7,652
423
arguments = input().split() array = [] for word in arguments: if word == '-': s1 = array.pop() s2 = array.pop() array.append(s2-s1) elif word == '*': s1 =array.pop() s2 = array.pop() array.append(s1*s2) elif word == '+': s1 = array.pop() s2 = array.pop() array.append(s1+s2) else: array.append(int(word)) print(array.pop())
s504938024
p02612
u958207414
2,000
1,048,576
Wrong Answer
27
9,088
56
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.
price = 1900 N = int(input()) out = N - price print(out)
s772708323
Accepted
27
9,164
129
N = int(input()) if N % 1000 == 0: print(0) else: div = int(N / 1000) a = (div+1)*1000 out = a - N print(out)
s599290421
p03371
u047816928
2,000
262,144
Wrong Answer
89
3,060
177
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A, B, C, X, Y = list(map(int, input().split())) ans = 10**20 for nc in range(0, max(X,Y)*2+1, 2): na = X-nc//2 nb = Y-nc//2 ans = min(ans, na*A+nb*B+nc*C) print(ans)
s164791587
Accepted
122
3,060
193
A, B, C, X, Y = list(map(int, input().split())) ans = 10**20 for nc in range(0, max(X,Y)*2+1, 2): na = max(X-nc//2, 0) nb = max(Y-nc//2, 0) ans = min(ans, na*A+nb*B+nc*C) print(ans)
s426292150
p03997
u244836567
2,000
262,144
Wrong Answer
28
9,160
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)
s559328829
Accepted
21
9,184
66
a=int(input()) b=int(input()) c=int(input()) print(int((a+b)*c/2))
s324618389
p03416
u902151549
2,000
262,144
Wrong Answer
65
5,044
466
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
# coding: utf-8 import time import re import math import fractions def main(): A,B=map(int,input().split()) count=0 for a in range(A,B+1): s=str(a) r=reversed(s) if s==r: count+=1 print(count) start=time.time() main() #"YNeos"[True::2] #A=list(map(int,input().split())) #A,B,C=map(int,input().split()) #n=int(input())
s024345971
Accepted
123
5,040
482
# coding: utf-8 import time import re import math import fractions def main(): A,B=map(int,input().split()) count=0 for a in range(A,B+1): s=str(a) r="".join(reversed(list(s))) if s==r: count+=1 print(count) start=time.time() main() #"YNeos"[True::2] #A=list(map(int,input().split())) #A,B,C=map(int,input().split()) #n=int(input())
s190552184
p02241
u629780968
1,000
131,072
Wrong Answer
20
5,604
610
For a given weighted graph $G = (V, E)$, find the minimum spanning tree (MST) of $G$ and print total weight of edges belong to the MST.
n = int(input()) m = [[-1 for i in range (n)] for j in range(n)] d = [0]+ [2000]* (n-1) isVisited = [False] * n for i in range(n): nums = list(map(int, input().split())) for j in range(n): m[i][j] = nums[j] def prim_mst(n): while True: mincost = 2000 for i in range(n): if (not isVisited[i]) and (d[i] < mincost): mincost = d[i] u = i isVisited[u] = True if mincost == 2000: break for v in range(n): if (not isVisited[v]) and (m[u][v] != -1): if m[u][v] < d[v]: d[v] = m[u][v] print(d) prim_mst(n)
s969613038
Accepted
20
6,652
564
from heapq import heappush, heappop, heapify N = int(input()) edges = [[] for i in range(N)] for v in range(N): for w, c in enumerate(map(int, input().split())): if c != -1: edges[v].append((w, c)) visited = [0]*N que = [(c, w) for w, c in edges[0]] visited[0] = 1 heapify(que) d=[0]+[10**9]*(N-1) ans = 0 while que: c, u = heappop(que) if visited[u]: continue visited[u] = 1 d[u]=c for v, c in edges[u]: if visited[v]: continue heappush(que, (c, v)) print(sum(d))
s302447700
p03565
u074220993
2,000
262,144
Wrong Answer
24
9,076
557
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 = list(input()) t = list(input()) ls, lt = len(s), len(t) s.reverse() t.reverse() for i in range(ls): for j in range(lt): if i + j >= ls: break if s[i+j] != '?' and s[i+j] != t[j]: break else: for j in range(lt): s[i+j] = t[j] s.reverse() ans = ''.join(s) ans.replace('?','a') break else: ans = 'UNRESTORABLE' print(ans)
s698813494
Accepted
26
9,116
447
def main(): with open(0) as f: S, T = f.read().split() for i in reversed(range(len(S)-len(T)+1)): for j in reversed(range(len(T))): if S[i+j] == T[j] or S[i+j] == '?': continue else: break else: S = S[:i] + T + S[i+len(T):] S = S.replace('?', 'a') print(S) break else: print('UNRESTORABLE') main()
s624405585
p03160
u515108104
2,000
1,048,576
Wrong Answer
135
13,928
220
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] dp.append(abs(h[1]-h[0])) print(dp) if n > 2: for i in range(2,n): dp.append(min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1])) print(dp[-1])
s994927796
Accepted
129
13,928
210
n = int(input()) h = list(map(int, input().split())) dp = [0] dp.append(abs(h[1]-h[0])) if n > 2: for i in range(2,n): dp.append(min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1])) print(dp[-1])
s693407699
p02408
u782850499
1,000
131,072
Wrong Answer
20
7,576
609
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
cards_remain=[] suit=["S","H","C","D"] cards_set=[] output=[] count_card=input() for m in range(int(count_card)): cards_remain.append(input().replace(" ","")) for m in suit: for n in range(13): cards_set.append(m+str(n+1)) cards_lost=list(set(cards_set)-set(cards_remain)) for x in cards_lost: if x[0]=="S": output.append(x) for x in cards_lost: if x[0]=="H": output.append(x) for x in cards_lost: if x[0]=="C": output.append(x) for x in cards_lost: if x[0]=="D": output.append(x) for y in output: print(y[0]+" "+y[1])
s927092339
Accepted
20
7,632
345
cards_remain=[] suit=["S","H","C","D"] cards_set=[] output=[] count_card=input() for l in range(int(count_card)): cards_remain.append(input()) for m in suit: for n in range(13): cards_set.append(m+" "+str(n+1)) for p in cards_set: if p not in cards_remain: output.append(p) for x in output: print(x)
s991542115
p03434
u208844959
2,000
262,144
Wrong Answer
17
3,060
224
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()) list = list(map(int, input().split())) list.sort() for i in range(N): Alice = 0 Bob = 0 if N % 2 == 0: Alice += list[i] else: Bob += list[i] print("{}".format(Alice - Bob))
s147272653
Accepted
17
3,064
217
N = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) Alice = 0 Bob = 0 for i in range(N): if i % 2 == 0: Alice += a[i] else: Bob += a[i] print("{}".format(Alice - Bob))
s569422248
p02613
u583507988
2,000
1,048,576
Wrong Answer
152
16,076
149
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()) s = [] for i in range(n): s_ = input() s.append(s_) res = ['AC', 'WA', 'TLE', 'RE'] for i in res: print(i,'×', s.count(i))
s750361557
Accepted
155
16,220
150
n = int(input()) s = [] for i in range(n): s_ = input() s.append(s_) res = ['AC', 'WA', 'TLE', 'RE'] for i in res: print(i,'x', s.count(i))
s060883118
p03797
u807772568
2,000
262,144
Wrong Answer
17
2,940
86
Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
n,m = map(int,input().split()) if 2*n <= m: print(m//2) else: print(n + m//4)
s880972713
Accepted
18
2,940
92
n,m = map(int,input().split()) if 2*n >= m: print(m//2) else: print(n + (m-2*n)//4)
s078369680
p02613
u265118937
2,000
1,048,576
Wrong Answer
160
16,328
362
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()) s = [] for i in range(n): s.append(input()) #s = list(map(int, input().split())) a =0 b=0 c=0 d=0 for i in range(n): if s[i] == "AC": a += 1 elif s[i] == "WA": b += 1 elif s[i] == "TLE": c += 1 elif s[i] == "RE": d += 1 print("AC ×", a) print("WA ×", b) print("TLE ×", c) print("RE ×", d)
s695540650
Accepted
157
16,340
360
n = int(input()) s = [] for i in range(n): s.append(input()) #s = list(map(int, input().split())) a =0 b=0 c=0 d=0 for i in range(n): if s[i] == "AC": a += 1 elif s[i] == "WA": b += 1 elif s[i] == "TLE": c += 1 elif s[i] == "RE": d += 1 print("AC x", a) print("WA x", b) print("TLE x", c) print("RE x", d)
s943004338
p03447
u816631826
2,000
262,144
Wrong Answer
17
3,064
662
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?
def printUnion(arr1, arr2, m, n): i,j = 0,0 while i < m and j < n: if arr1[i] < arr2[j]: print(arr1[i]) i += 1 elif arr2[j] < arr1[i]: print(arr2[j]) j+= 1 else: print(arr2[j]) j += 1 i += 1 # Print remaining elements of the larger array while i < m: print(arr1[i]) i += 1 while j < n: print(arr2[j]) j += 1 # Driver program to test above function arr1 = [1, 2, 4, 5, 6] arr2 = [2, 3, 5, 7] m = len(arr1) n = len(arr2) printUnion(arr1, arr2, m, n)
s632434811
Accepted
17
2,940
84
a=int(input()) b=int(input()) c=int(input()) s=a-b t=s%c print(t)
s367321807
p02613
u757117214
2,000
1,048,576
Wrong Answer
149
16,424
217
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.
from collections import Counter lst = [] for i in range(int(input())): lst.append(input()) c = Counter(lst) print(f"AC × {c['AC']}") print(f"WA × {c['WA']}") print(f"TLE × {c['TLE']}") print(f"RE × {c['RE']}")
s831309252
Accepted
52
17,236
140
from collections import Counter n,*lst = open(0).read().split() c = Counter(lst) for s in ['AC','WA','TLE','RE']: print(f"{s} x {c[s]}")
s447992834
p03493
u235763683
2,000
262,144
Wrong Answer
19
2,940
18
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
input().count("1")
s844778548
Accepted
17
2,940
25
print(input().count("1"))
s506349826
p03162
u459215900
2,000
1,048,576
Wrong Answer
996
57,480
430
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
N = int(input()) values_list = [] for i in range(N): values = list(map(int, input().split())) values_list.append(values) dp = [[0,0,0] for i in range(N+1)] for i in range(N): for j in range(0, 3): for k in range(0, 3): if j == k: continue dp[i][k] = max(dp[i][k], dp[i-1][j] + values_list[i][k]) print(dp) print(max(dp[N-1]))
s902227134
Accepted
973
47,372
420
N = int(input()) values_list = [] for i in range(N): values = list(map(int, input().split())) values_list.append(values) dp = [[0,0,0] for i in range(N+1)] for i in range(N): for j in range(0, 3): for k in range(0, 3): if j == k: continue dp[i][k] = max(dp[i][k], dp[i-1][j] + values_list[i][k]) print(max(dp[N-1]))
s766343881
p03737
u093033848
2,000
262,144
Wrong Answer
17
2,940
78
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
a, b, c = map(str, input().split()) s = a[0] + b[0] + c[0] s.upper() print(s)
s892560743
Accepted
20
2,940
82
a, b, c = map(str, input().split()) s = a[0] + b[0] + c[0] s = s.upper() print(s)
s866282671
p03957
u627417051
1,000
262,144
Wrong Answer
17
2,940
123
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtained from the string s by deleting some characters.
s = input() C = s.find("C") F = s.rfind("F") print(C, F) if C != -1 and F != -1 and C < F: print("Yes") else: print("No")
s771448641
Accepted
18
2,940
111
s = input() C = s.find("C") F = s.rfind("F") if C != -1 and F != -1 and C < F: print("Yes") else: print("No")
s499918287
p03434
u128859393
2,000
262,144
Wrong Answer
17
2,940
87
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.
input();a = sorted(list(map(int, input().split())));print(sum(a[:: 2]) - sum(a[1:: 2]))
s046405546
Accepted
18
2,940
91
input();a = sorted(list(map(int, input().split())));print(sum(a[-1::-2]) - sum(a[-2::-2]))
s425882410
p02612
u095384238
2,000
1,048,576
Wrong Answer
33
9,144
30
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)
s389599868
Accepted
32
9,156
82
N = int(input()) ans = 1000-N%1000 if ans==1000: print(0) else: print(ans)
s961483409
p03545
u006187236
2,000
262,144
Wrong Answer
18
3,064
494
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.
def dfs(N, ops, nums, Sum): if N == 3: if Sum == 7: print(str(nums[0])+ops[0]+str(nums[1])+ops[1]+str(nums[2])+ops[2]+str(nums[3])) return True else: return False else: ops[N]="+" if dfs(N+1, ops, nums, Sum+nums[N+1]): return True ops[N]="-" if dfs(N+1, ops, nums, Sum-nums[N+1]): return True nums=[int(i) for i in input()] ops=["" for i in range(3)] dfs(0, ops, nums, nums[0])
s080048016
Accepted
18
3,064
499
def dfs(N, ops, nums, Sum): if N == 3: if Sum == 7: print(str(nums[0])+ops[0]+str(nums[1])+ops[1]+str(nums[2])+ops[2]+str(nums[3])+"=7") return True else: return False else: ops[N]="+" if dfs(N+1, ops, nums, Sum+nums[N+1]): return True ops[N]="-" if dfs(N+1, ops, nums, Sum-nums[N+1]): return True nums=[int(i) for i in input()] ops=["" for i in range(3)] dfs(0, ops, nums, nums[0])
s645886213
p02663
u590628174
2,000
1,048,576
Wrong Answer
23
9,160
65
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 = list(map(int, input().split())) print(H1, M1)
s570675313
Accepted
24
9,128
212
H1, M1, H2, M2, K = list(map(int, input().split())) if M1 <= M2: all_time = (H2 - H1) * 60 + (M2 - M1) else: all_time = (H2 - H1 - 1) * 60 + (60 + M2 - M1) available_time = all_time - K print(available_time)
s873609667
p03997
u994307795
2,000
262,144
Wrong Answer
17
2,940
78
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()) ans = (a+b)*h/2 print(ans)
s843962196
Accepted
17
2,940
79
a = int(input()) b = int(input()) h = int(input()) ans = (a+b)*h//2 print(ans)
s208687085
p02664
u417866294
2,000
1,048,576
Wrong Answer
64
10,916
258
For a string S consisting of the uppercase English letters `P` and `D`, let the _doctoral and postdoctoral quotient_ of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3. We have a string T consisting of `P`, `D`, and `?`. Among the strings that can be obtained by replacing each `?` in T with `P` or `D`, find one with the maximum possible doctoral and postdoctoral quotient.
s=input() t=s s_list=list(s) for i in range(len(t)): if t[i]=='?': if t[i-1]=='D': s_list[i]='P' print(s[i]) else: s_list[i]='D' s_cha="".join(s_list) print(s_cha)
s624302924
Accepted
89
10,960
474
s=input() t=s s_list=list(s) for i in range(len(t)): if s_list[i]=='?': if s_list[i-1]=='D': if i==len(t)-1: s_list[i]='D' elif s_list[i+1]=='P': s_list[i]='D' elif s_list[i+1]=='D': s_list[i]='P' else: s_list[i]='P' else: s_list[i]='D' s_cha="".join(s_list) print(s_cha)
s441223032
p02275
u300095814
1,000
131,072
Wrong Answer
30
5,636
339
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in the output array B. This scheme must be modified to handle the situation in which several elements have the same value. Please see the following pseudocode for the detail: Counting-Sort(A, B, k) 1 for i = 0 to k 2 do C[i] = 0 3 for j = 1 to length[A] 4 do C[A[j]] = C[A[j]]+1 5 /* C[i] now contains the number of elements equal to i */ 6 for i = 1 to k 7 do C[i] = C[i] + C[i-1] 8 /* C[i] now contains the number of elements less than or equal to i */ 9 for j = length[A] downto 1 10 do B[C[A[j]]] = A[j] 11 C[A[j]] = C[A[j]]-1 Write a program which sorts elements of given array ascending order based on the counting sort.
n = int(input()) A = list(map(int, input().split())) def countingSort(A, B, k): C = [0] * k for j in range(1, n): C[A[j]]+=1 for i in range(1, k): C[i] = C[i] + C[i - 1] for j in range(1, n)[::-1]: B[C[A[j]]] = A[j] C[A[j]]-=1 return B print(countingSort(A, [0] * n, 10000))
s654001969
Accepted
1,960
231,272
363
n = int(input()) A = list(map(int, input().split())) def countingSort(A, B, k): C = [0] * k for j in range(0, n): C[A[j]]+=1 for i in range(1, k): C[i] = C[i] + C[i - 1] for j in range(0, n)[::-1]: B[C[A[j]] - 1] = A[j] C[A[j]]-=1 return B print(' '.join(map(str, countingSort(A, [0] * n, 10000))))
s489721191
p03377
u441320782
2,000
262,144
Wrong Answer
17
2,940
122
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.
x = list(map(int,input().split())) if x[0] + x[1] >= x[2]: if x[1] >= x[2]: print("Yes") else: print("No")
s507593827
Accepted
17
3,060
196
a = list(map(int,input().split())) if a[0] + a[1]>= a[2]: if a[2] >= a[0]: if a[1] >= a[2] - a[0]: print("YES") else: print("NO") else: print("NO") else: print("NO")
s004534723
p02613
u901850884
2,000
1,048,576
Wrong Answer
138
16,264
204
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()) s = [input() for i in range(n)] print("AC *",s.count('AC')) print("WA *",s.count('WA')) print("TLE *",s.count('TLE')) print("RE *",s.count('RE'))
s063311106
Accepted
142
16,280
163
n=int(input()) s = [input() for i in range(n)] print("AC x",s.count('AC')) print("WA x",s.count('WA')) print("TLE x",s.count('TLE')) print("RE x",s.count('RE'))