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
s630740745
p02273
u358919705
2,000
131,072
Wrong Answer
20
7,636
679
Write a program which reads an integer _n_ and draws a Koch curve based on recursive calles of depth _n_. The Koch curve is well known as a kind of You should start (0, 0), (100, 0) as the first segment.
from math import sin, cos, pi def koch(px, py, qx, qy, n): if n == 0: return True sx = (2 * px + qx) / 3 sy = (2 * py + qy) / 3 tx = (px + 2 * qx) / 3 ty = (py + 2 * qy) / 3 ux = sx + (tx - sx) * cos(pi / 3) - (ty - sy) * sin(pi / 3) uy = sy + (tx - sx) * sin(pi / 3) - (ty - sy) * cos(pi / 3) koch(px, py, sx, sy, n - 1) print("{:.8f} {:.8f}".format(sx, sy)) koch(sx, sy, ux, uy, n - 1) print("{:.8f} {:.8f}".format(ux, uy)) koch(ux, uy, tx, ty, n - 1) print("{:.8f} {:.8f}".format(tx, ty)) koch(tx, ty, qx, qy, n - 1) print("{:.8f} {:.8f}".format(0, 0)) koch(0, 0, 100, 0, 2) print("{:.8f} {:.8f}".format(100, 0))
s096063314
Accepted
40
7,976
696
from math import sin, cos, pi def koch(px, py, qx, qy, n): if n == 0: return True sx = (2 * px + qx) / 3 sy = (2 * py + qy) / 3 tx = (px + 2 * qx) / 3 ty = (py + 2 * qy) / 3 ux = sx + (tx - sx) * cos(pi / 3) - (ty - sy) * sin(pi / 3) uy = sy + (tx - sx) * sin(pi / 3) + (ty - sy) * cos(pi / 3) koch(px, py, sx, sy, n - 1) print("{:.8f} {:.8f}".format(sx, sy)) koch(sx, sy, ux, uy, n - 1) print("{:.8f} {:.8f}".format(ux, uy)) koch(ux, uy, tx, ty, n - 1) print("{:.8f} {:.8f}".format(tx, ty)) koch(tx, ty, qx, qy, n - 1) n = int(input()) print("{:.8f} {:.8f}".format(0, 0)) koch(0, 0, 100, 0, n) print("{:.8f} {:.8f}".format(100, 0))
s017219674
p04043
u552502395
2,000
262,144
Wrong Answer
17
2,940
123
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.
L = list(map(int, input().split())) L.sort() if L[0] == 5 and L[1]==5 and L[2]==7: print("Yes"); else: print("No");
s504223148
Accepted
18
2,940
124
L = list(map(int, input().split())) L.sort() if L[0] == 5 and L[1]==5 and L[2]==7: print("YES"); else: print("NO");
s543550692
p02408
u874395007
1,000
131,072
Wrong Answer
20
5,596
409
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.
N = int(input()) cards = [] for i in range(N): line = input().split() a = line[0] num = int(line[1]) cards.append((a, num)) tarinai_list = [] for a in ['S', 'H', 'C', 'D']: for num in range(1, 14): for card in cards: if a == card[0] and num == card[1]: break tarinai_list.append((a, num)) for l in tarinai_list: print(' '.join(map(str, l)))
s346468231
Accepted
20
5,616
468
suits = ['S', 'H', 'C', 'D'] table = [[False] * 14 for i in range(4)] N = int(input()) for _i in range(N): mark, num = input().split() num = int(num) if mark == 'S': table[0][num] = True if mark == 'H': table[1][num] = True if mark == 'C': table[2][num] = True if mark == 'D': table[3][num] = True for i in range(4): for j in range(1, 14): if not table[i][j]: print(f'{suits[i]} {j}')
s002544504
p02613
u223215060
2,000
1,048,576
Wrong Answer
164
9,212
323
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()) a = 0 b = 0 c = 0 d = 0 for i in range(n): s = str(input()) if s == 'AC' : a += 1 elif s == 'WA': b += 1 elif s == 'TLE': c += 1 else: d += 1 print('AC ร— {}'.format(a)) print('WA ร— {}'.format(b)) print('TLE ร— {}'.format(c)) print('RE ร— {}'.format(d))
s150371612
Accepted
159
9,220
319
n = int(input()) a = 0 b = 0 c = 0 d = 0 for i in range(n): s = str(input()) if s == 'AC' : a += 1 elif s == 'WA': b += 1 elif s == 'TLE': c += 1 else: d += 1 print('AC x {}'.format(a)) print('WA x {}'.format(b)) print('TLE x {}'.format(c)) print('RE x {}'.format(d))
s624914821
p02612
u688375653
2,000
1,048,576
Wrong Answer
35
9,164
216
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
def input_int(): return map(int, input().split()) def one_int(): return int(input()) def one_str(): return input() def many_int(): return list(map(int, input().split())) a=one_int() print(a%1000)
s918721163
Accepted
30
9,168
257
def input_int(): return map(int, input().split()) def one_int(): return int(input()) def one_str(): return input() def many_int(): return list(map(int, input().split())) a=one_int() if a%1000>0: print(1000-a%1000) else: print(0)
s029074857
p04043
u054412614
2,000
262,144
Wrong Answer
17
2,940
100
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a,b,c=map(int,input().split()) if a+b+c==17: if a==7 or b==7 or c==7: print("YES") print("NO")
s716340605
Accepted
17
3,060
206
a,b,c=map(int,input().split()) if a+b+c==17: if a==5 and b==5: print("YES") elif a==5 and c==5: print("YES") elif b==5 and c==5: print("YES") else: print("NO") else: print("NO")
s295197457
p03214
u374171306
2,525
1,048,576
Wrong Answer
17
3,064
289
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
N = int(input()) a = list(map(int,input().split())) sum = 0 for i in a: sum += i avg = sum/N result = 0 tmp = 0 for i in range(len(a)): ans = avg - a[i] ans = ans if ans < 0 else ans * -1 if i == 0: result = i tmp = ans elif tmp > ans: result = i print(result)
s036552831
Accepted
17
3,064
282
N = int(input()) a = list(map(int,input().split())) sum = sum(a) avg = sum/N result = 0 tmp = 0 for i in range(len(a)): ans = avg - a[i] ans = ans if ans > 0 else ans * -1 if i == 0: result = i tmp = ans elif tmp > ans: result = i tmp = ans print(result)
s941393182
p03386
u433380437
2,000
262,144
Wrong Answer
27
9,196
213
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()) A=[] for i in range(a,min(a+k+1,b+1)): A.append(i) for j in range(b,max(b-k,a),-1): A.append(j) A.sort(reverse=False) B=list(set(A)) for p in range(len(B)): print(B[p])
s813008554
Accepted
26
9,196
218
a,b,k = map(int,input().split()) A=[] B=[] for i in range(a,min(a+k,b+1)): A.append(i) for j in range(b,max(b-k,a-1),-1): A.append(j) B=list(set(A)) B.sort(reverse=False) for p in range(len(B)): print(B[p])
s028786285
p03673
u368796742
2,000
262,144
Wrong Answer
2,104
26,016
117
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
n = int(input()) l = list(map(int,input().split())) ans = [] for i in l: ans.append(i) ans = ans[::-1] print(ans)
s893002989
Accepted
176
26,180
256
n = int(input()) l = list(map(int,input().split())) if n % 2 == 0: ans = [l[i] for i in range(n-1,-1,-2)] + [l[i] for i in range(0,n-1,2)] print(*ans) else: ans = [l[i] for i in range(n-1,-1,-2)] + [l[i] for i in range(1,n-1,2)] print(*ans)
s452476073
p03449
u224050758
2,000
262,144
Wrong Answer
17
3,064
720
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
N = int(input()) HIGH = [int(x) for x in input().split()] LOW = [int(x) for x in input().split()] def get_sum(diff_list): max_abs_value = max(diff_list, key=abs) max_abs_index = diff_list.index(max_abs_value) corrects = [HIGH[i] if i <= max_abs_index else LOW[i] for i, _ in enumerate(diff_list)] print(corrects) return sum(corrects) def main(): first = HIGH.pop(0) last = LOW.pop() diff_list = [] high = low = 0 for i in range(N - 1): high = high + HIGH[i] low = low + LOW[i] diff_list.append(high - low) sum = get_sum(diff_list) if len(diff_list) != 0 else 0 result = first + sum + last print(result) if __name__ == "__main__": main()
s021480213
Accepted
17
3,064
439
N = int(input()) HIGH = [int(x) for x in input().split()] LOW = [int(x) for x in input().split()] def main(): first = HIGH.pop(0) last = LOW.pop() mid_len = len(HIGH) mid_sum = 0 for i in range(mid_len)[::-1]: # reversed mid_sum = max(mid_sum, sum(HIGH)) HIGH[i] = LOW[i] mid_sum = max(mid_sum, sum(LOW)) result = first + mid_sum + last print(result) if __name__ == "__main__": main()
s084613857
p03679
u396391104
2,000
262,144
Wrong Answer
17
2,940
117
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b=map(int,input().split()) if a<b: print("delicious") elif (b-a)<=x: print("safe") else: print("dangerous")
s528166273
Accepted
17
3,060
118
x,a,b=map(int,input().split()) if a>=b: print("delicious") elif (b-a)<=x: print("safe") else: print("dangerous")
s214125881
p02389
u681232780
1,000
131,072
Wrong Answer
20
5,580
74
Write a program which calculates the area and perimeter of a given rectangle.
a,b=map(int,input().split()) print('้ข็ฉ',a*b,'ๅ‘จใฎ้•ทใ•',2*a+2*b)
s984654957
Accepted
20
5,580
49
a,b=map(int,input().split()) print(a*b,2*a+2*b)
s229107576
p02614
u396472025
1,000
1,048,576
Wrong Answer
29
8,988
8
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
print(0)
s753061871
Accepted
65
9,064
426
H, W, K = map(int, input().split()) C = [list(input()) for _ in range(H)] ans = 0 for h_ptn in range(2 ** H): for w_ptn in range(2 ** W): cnt = 0 for h in range(H): for w in range(W): if (h_ptn >> h) & 1 == 0 and (w_ptn >> w) & 1 == 0: if C[h][w] == '#': cnt += 1 if cnt == K: ans += 1 print(ans)
s886539732
p02697
u069125420
2,000
1,048,576
Wrong Answer
74
9,216
79
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
N, M = map(int, input().split()) for i in range(0, M): print(i + 1, N - i)
s428959221
Accepted
74
9,188
330
N, M = map(int, input().split()) M_f = M * 2 + 1 if M % 2 != 0: for i in range(0, M // 2): print(i + 1, (M) - i) for i in range(0, M // 2 + 1): print(M + 1 + i, M_f - i) else: for i in range(0, M // 2): print(i + 1, (M + 1) - i) for i in range(0, M // 2): print(M + 2 + i, M_f - i)
s170492670
p03579
u830592648
2,000
262,144
Wrong Answer
2,105
107,600
495
Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v. Find the maximum possible number of edges that can be added.
import sys sys.setrecursionlimit(10**6) n,m=map(int,input().split()) s=[[]for i in range(n+1)] c=[0]*(n+1) for i in range(m): a,b=map(int,input().split()) s[a].append(b) s[b].append(a) def dfs(v,t): c[v]=t print('start :'+str(c)) for i in s[v]: if c[i]==t: return False if c[i]==0: dfs(i,-t) # return False else: return True if dfs(1,1): q=c.count(1) print((n-q)*q-m) else: print((n*(n-1)//2)-m)
s216070048
Accepted
541
31,156
491
import sys sys.setrecursionlimit(10**6) n,m=map(int,input().split()) s=[[]for i in range(n+1)] c=[0]*(n+1) for i in range(m): a,b=map(int,input().split()) s[a].append(b) s[b].append(a) def dfs(v,t): c[v]=t # print('start :'+str(c)) for i in s[v]: if c[i]==t: return False if c[i]==0 and not dfs(i,-t): return False else: return True if dfs(1,1): q=c.count(1) print((n-q)*q-m) else: print((n*(n-1)//2)-m)
s193988837
p02663
u921352252
2,000
1,048,576
Wrong Answer
22
9,404
300
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?
import time import datetime from datetime import timedelta H1,M1,H2,M2,K=map(int,input().split()) delta1=timedelta(minutes=M1,hours=H1) delta2=timedelta(minutes=M2,hours=H2) delta=delta2-delta1 delta_minutes=delta.total_seconds()/60 if delta_minutes>30: print(delta_minutes-30) else: print(0)
s340040007
Accepted
22
9,400
293
import datetime from datetime import timedelta H1,M1,H2,M2,K=map(int,input().split()) delta1=timedelta(minutes=M1,hours=H1) delta2=timedelta(minutes=M2,hours=H2) delta=delta2-delta1 delta_minutes=delta.total_seconds()/60 if delta_minutes>=K: print(round(delta_minutes-K)) else: print(0)
s365171171
p03472
u648212584
2,000
262,144
Wrong Answer
542
32,880
341
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, โ€ฆ, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 โ‰ค i โ‰ค N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 โ‰ค i โ‰ค N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
N,M = map(int,input().split()) X = [list(map(int,input().split())) for _ in range(N)] X = sorted(X,key=lambda X:-X[0]) a = X[0][0] X = sorted(X,key=lambda X:-X[1]) count = 0 for i in range(N): if a <= X[i][1]: M -= X[i][1] count += 1 if M <= 0: break print(M,count) if M > 0: count += -((-M)//a) else: count += 1 print(count)
s759119760
Accepted
550
32,880
306
N,M = map(int,input().split()) X = [list(map(int,input().split())) for _ in range(N)] X = sorted(X,key=lambda X:-X[0]) a = X[0][0] X = sorted(X,key=lambda X:-X[1]) i = 0 count = 0 while M > 0: if i < N and X[i][1] > a: M -= X[i][1] i += 1 else: count += -(-M//a) break count += 1 print(count)
s997279731
p02742
u368579103
2,000
1,048,576
Wrong Answer
17
2,940
134
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
h,w = list(map(int,input().split())) if h % 2 == 0: ans = h / 2 * w else: ans = ((h + 1) / 2 * w) - (int(w / 2) * 1) print(ans)
s047152859
Accepted
17
3,060
171
h,w = list(map(int,input().split())) if h % 2 == 0: ans = h / 2 * w elif h == 1 or w == 1: ans = 1 else: ans = ((h + 1) / 2 * w) - (int(w / 2) * 1) print(int(ans))
s027749541
p03637
u625963200
2,000
262,144
Wrong Answer
63
14,252
218
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 โ‰ค i โ‰ค N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
n=int(input()) A=list(map(int,input().split())) cnt1,cnt2,cnt3=0,0,0 for a in A: if a%4==0: cnt1+=1 elif a%2==0: cnt2+=1 cnt3+=cnt2//2 print('Yes') if cnt3>=n//2 else print('No')
s900401669
Accepted
62
15,020
192
n=int(input()) A=list(map(int,input().split())) cnt1,cnt2,cnt3=0,0,0 for a in A: if a%4==0: cnt1+=1 elif a%2==0: cnt2+=1 cnt1+=cnt2//2 print('Yes') if cnt1>=n//2 else print('No')
s498758327
p03155
u568789901
2,000
1,048,576
Wrong Answer
18
2,940
66
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
N=int(input()) H=int(input()) W=int(input()) print((N//H)*(N//W))
s499067353
Accepted
17
2,940
68
N=int(input()) H=int(input()) W=int(input()) print((N-H+1)*(N-W+1))
s965304572
p03711
u023127434
2,000
262,144
Wrong Answer
26
9,028
195
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 โ‰ค x < y โ‰ค 12), determine whether they belong to the same group.
x, y = map(int, input().split()) a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] c = [2] if (x in a and y in a) or (x in b and y in b) or (x in c and y in c): print("YES") else: print("NO")
s266835306
Accepted
28
9,192
195
a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] c = [2] x, y = map(int, input().split()) if (x in a and y in a) or (x in b and y in b) or (x in c and y in c): print("Yes") else: print("No")
s708871206
p03351
u559313689
2,000
1,048,576
Wrong Answer
23
9,128
164
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()) x=abs(b-a) y=abs(c-b) z=abs(c-a) if z <= d: print('Yes') elif y <= d and z <= d: print('Yes') else: print('No')
s570656686
Accepted
28
9,148
164
a, b, c, d = map(int, input().split()) x=abs(b-a) y=abs(c-b) z=abs(c-a) if z <= d: print('Yes') elif y <= d and x <= d: print('Yes') else: print('No')
s960631414
p02670
u490195279
2,000
1,048,576
Time Limit Exceeded
2,206
38,116
1,325
Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
N=int(input()) S=list(map(int,input().split())) count=0 P=[0]*(N*N+1) for j in range(N*N): P[j+1]=S.index(j+1) for i in range(N*N): player=S[i] hayasa=P[player] que=[[] for _ in range(N)] d=[-1]*(N*N+1) que[0].append(player) d[player]=0 j=0 finish=0 while True: for kouho in que[j]: if kouho%N==0: finish=1 break if kouho%N==1: finish=1 break if kouho+N>N*N: finish=1 break if kouho<N: finish=1 break if d[kouho+N]==-1: if P[kouho+N]>hayasa: que[j+1].append(kouho+N) d[kouho+N]=0 else: que[j].append(kouho+N) d[kouho+N]=0 if d[kouho-N]==-1: if P[kouho-N]>hayasa: que[j+1].append(kouho-N) d[kouho-N]=0 else: que[j].append(kouho-N) d[kouho-N]=0 if d[kouho+1]==-1: if P[kouho+1]>hayasa: que[j+1].append(kouho+1) d[kouho+1]=0 else: que[j].append(kouho+1) d[kouho+1]=0 if d[kouho-1]==-1: if P[kouho-1]>hayasa: que[j+1].append(kouho-1) d[kouho-1]=0 else: que[j].append(kouho-1) d[kouho-1]=0 if finish==1: count+=j
s936294108
Accepted
1,498
118,800
841
from numba import njit import numpy as np @njit def main(N, P): lista = [1, -1, N, -N] d = np.zeros((N, N), dtype=np.int32) d = d.ravel() sit = np.ones_like(d) stack = np.empty_like(d) count = 0 for i in range(N*N): d[i] = min(i % N, (N-1-i) % N, i//N, N-1-i//N) for player in P: sit[player-1] = 0 count += d[player-1] stack[0] = player num = 0 while num >= 0: p = stack[num] num -= 1 a = d[p-1]+sit[p-1] for i in lista: if p+i < 1 or p + i > N*N: continue if d[p+i-1] > a: d[p+i-1] = a num += 1 stack[num] = p+i print(count) N = int(input()) P = np.array(input().split(), np.int32) main(N, P)
s566157781
p03095
u426108351
2,000
1,048,576
Wrong Answer
20
3,316
144
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order.
s = list(input().split()) import collections s = collections.Counter(s) s = s.most_common() ans = 1 for i in s: ans *= i[1] print(ans-1)
s226582274
Accepted
27
4,140
161
n = input() s = list(input()) import collections s = collections.Counter(s) s = s.most_common() ans = 1 for i in s: ans *= i[1]+1 print((ans-1)%1000000007)
s891847550
p03997
u037430802
2,000
262,144
Wrong Answer
18
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)
s854985139
Accepted
18
2,940
72
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h/2))
s798271302
p02389
u998185318
1,000
131,072
Wrong Answer
40
6,516
113
Write a program which calculates the area and perimeter of a given rectangle.
import re numbers = input() lines = re.split(" ", numbers) a = int(lines[0]) b = int(lines[1]) print(a * b / 2)
s207792382
Accepted
20
5,592
149
numbers = input() lines = numbers.split(" ") a = int(lines[0]) b = int(lines[1]) area = str(a * b) line = str(2 * (a + b)) print(area + " " + line)
s009140122
p03151
u286955577
2,000
1,048,576
Wrong Answer
1,233
34,656
469
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
import numpy as np def solve(A, B): diff = np.array(A) - np.array(B) shortage = list(filter(lambda d: d < 0, diff)) remainder = sorted(list(filter(lambda d: d > 0, diff)), reverse=True) short_sum = sum(shortage) counter = 0 for r in remainder: if short_sum >= 0: return len(shortage) + counter short_sum += r counter += 1 return -1 N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) print(solve(A, B))
s500345376
Accepted
115
18,484
505
import operator def solve(A, B): diff = list(map(operator.sub, A, B)) shortage = list(filter(lambda d: d < 0, diff)) remainder = list(filter(lambda d: d > 0, diff)) remainder.sort(reverse=True) short_sum = sum(shortage) if short_sum == 0: return 0 counter = len(shortage) for r in remainder: short_sum += r counter += 1 if short_sum >= 0: return counter return -1 N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) print(solve(A, B))
s032772711
p03478
u955907183
2,000
262,144
Wrong Answer
51
3,636
290
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split()) allsum = 0 for i in range(1,n+1): l = list(str(i)) li = [int(s) for s in l] tmpsum = sum(li) print (tmpsum) #for s in range(0,len(l)): # print(s) if ((tmpsum >= a) and (tmpsum <= b)): print("ok") allsum = allsum + i print(allsum)
s811471706
Accepted
37
3,064
257
n, a, b = map(int, input().split()) allsum = 0 for i in range(1,n+1): l = list(str(i)) li = [int(s) for s in l] tmpsum = sum(li) #for s in range(0,len(l)): # print(s) if ((tmpsum >= a) and (tmpsum <= b)): allsum = allsum + i print(allsum)
s480192564
p03623
u934868410
2,000
262,144
Wrong Answer
17
2,940
88
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b = map(int,input().split()) if abs(x-a) > abs(x-b): print('A') else: print('B')
s676978470
Accepted
17
2,940
88
x,a,b = map(int,input().split()) if abs(x-a) < abs(x-b): print('A') else: print('B')
s447849524
p02389
u369093003
1,000
131,072
Wrong Answer
20
5,576
44
Write a program which calculates the area and perimeter of a given rectangle.
a,b=map(int,input().split(" ")) print(a*b)
s085403033
Accepted
20
5,580
52
a,b=map(int,input().split(" ")) print(a*b,2*a+2*b)
s576702310
p03377
u074445770
2,000
262,144
Wrong Answer
17
2,940
85
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x=map(int,input().split()) if 0<=x-a<=b: print("Yes") else: print("No")
s959055775
Accepted
17
2,940
85
a,b,x=map(int,input().split()) if 0<=x-a<=b: print("YES") else: print("NO")
s845679213
p02394
u229478139
1,000
131,072
Wrong Answer
20
5,592
284
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
l = list(map(int, input('Please input int: ').split())) W = l[0] H = l[1] x = l[2] y = l[3] r = l[4] if (0 <= x <= W) and (0 <= y <= H): if (0 <= x - r) and (x + r <= W) and (0 <= y - r) and (y + r <= H): print('Yes') else: print('No') else: print('No')
s672238061
Accepted
20
5,596
132
w, h, x, y, r = list(map(int, input().split())) if (r <= x <= w - r) and (r <= y <= h - r): print('Yes') else: print('No')
s917451019
p04044
u927870520
2,000
262,144
Wrong Answer
19
3,060
145
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=list(map(int,input().split())) S=[list(input()) for i in range(n)] [S[i].sort() for i in range(len(S))] S.sort() ans=''.join(S[0]) print(ans)
s972996116
Accepted
17
3,060
99
n,l=list(map(int,input().split())) S=[input() for i in range(n)] S.sort() ans=''.join(S) print(ans)
s915783814
p02743
u614875193
2,000
1,048,576
Wrong Answer
17
3,060
68
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c=map(int,input().split()) print('NYoe s'[a**.5+b**.5<c**.5::2])
s717304015
Accepted
17
2,940
115
a,b,c=map(int,input().split()) if a*a+b*b+c*c-2*(a*b+b*c+c*a)>0 and c-a-b>0: print('Yes') else: print('No')
s334579465
p03160
u208497224
2,000
1,048,576
Wrong Answer
639
22,724
389
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
import numpy as np n = int(input()) h_list = list(map(int, input().split())) dp = [0] * n dp[1] = np.abs(h_list[1] - h_list[0]) print(dp) for ashiba_index in range(2, n): dp[ashiba_index] = min(dp[ashiba_index-1]+np.abs(h_list[ashiba_index] - h_list[ashiba_index-1]), dp[ashiba_index-2] + np.abs(h_list[ashiba_index]-h_list[ashiba_index-2])) print(dp[n-1])
s192934990
Accepted
631
22,760
379
import numpy as np n = int(input()) h_list = list(map(int, input().split())) dp = [0] * n dp[1] = np.abs(h_list[1] - h_list[0]) for ashiba_index in range(2, n): dp[ashiba_index] = min(dp[ashiba_index-1]+np.abs(h_list[ashiba_index] - h_list[ashiba_index-1]), dp[ashiba_index-2] + np.abs(h_list[ashiba_index]-h_list[ashiba_index-2])) print(dp[n-1])
s431705160
p03377
u333731247
2,000
262,144
Wrong Answer
17
2,940
57
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A,B,X=map(int,input().split()) if A<=X: print('Yes')
s663786024
Accepted
17
3,060
122
A,B,X=map(int,input().split()) if A<=X and A+B>=X: print('YES') elif A>X: print('NO') elif A+B<X: print('NO')
s962201608
p03228
u008173855
2,000
1,048,576
Wrong Answer
17
3,060
237
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
a, b, k = map(int,input().split()) cnt = 0 while True: if cnt==k: break if a%2!=0: a-=1 b+=a/2 a = a/2 cnt+=1 if cnt==k: break if b%2!=0: b-=1 a+=b/2 b = b/2 cnt+=1
s389506845
Accepted
17
3,060
259
a, b, k = map(int,input().split()) cnt = 0 while True: if cnt==k: break if a%2!=0: a-=1 b+=a/2 a = a/2 cnt+=1 if cnt==k: break if b%2!=0: b-=1 a+=b/2 b = b/2 cnt+=1 print(int(a),int(b))
s472919869
p02928
u727801592
2,000
1,048,576
Wrong Answer
376
3,188
241
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
n,k=map(int, input().split()) a=list(map(int, input().split())) ans=0 for i in range(n-1): for j in range(i+1,n): if a[i]>a[j]: ans+=1 print(10**9+7) x=(ans*k*(k+1))//2 y=(n*(n-1))//2 z=(k*(k-1))//2 print((x+(y-ans)*z)%(10**9+7))
s948844482
Accepted
794
3,188
251
n,k=map(int, input().split()) a=list(map(int, input().split())) ans=0 rev=0 for i in range(n-1): for j in range(i+1,n): if a[i]>a[j]: ans+=1 if a[i]<a[j]: rev+=1 x=(ans*k*(k+1))//2 y=(rev*k*(k-1))//2 print((x+y)%(10**9+7))
s073581385
p02243
u426534722
1,000
131,072
Wrong Answer
20
5,672
605
For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$.
import sys readline = sys.stdin.readline from heapq import heapify, heappush, heappop INF = float("inf") def MAIN(): n = int(input()) G = [[i, INF] for i in range(n)] G[0][1] = 0 m = {} for _ in range(n): A = list(map(int, readline().split())) m[A[0]] = {} for i in range(2, len(A), 2): m[A[0]][A[i]] = A[i + 1] dp = [(0, 0)] while dp: cost, u = heappop(dp) for v, c in m[u].items(): if G[v][1] > G[u][1] + c: G[v][1] = G[u][1] + c heappush(dp, (G[v][1], v)) print(*G) MAIN()
s277957998
Accepted
340
40,036
652
import sys readline = sys.stdin.readline from heapq import heapify, heappush, heappop INF = float("inf") def MAIN(): n = int(input()) adj = [[]] * n for _ in range(0, n): U = list(map(int, input().split())) adj[U[0]] = zip(U[2::2], U[3::2]) def dijkstra(): d = [INF] * n d[0] = 0 hq = [(0, 0)] while hq: u = heappop(hq)[1] for v, c in adj[u]: alt = d[u] + c if d[v] > alt: d[v] = alt heappush(hq, (alt, v)) print("\n".join(f"{i} {c}" for i, c in enumerate(d))) dijkstra() MAIN()
s394145298
p04011
u886274153
2,000
262,144
Wrong Answer
19
3,060
222
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
N, K, X, Y = [int(input()) for j in range(4)] def price(N, K, X, Y): if N < K: return N * X else: print("exceed", K, X, K * X + (N-K) * Y) return N * X + (N-K) * Y print(price(N, K, X, Y))
s786411994
Accepted
17
2,940
173
N, K, X, Y = [int(input()) for i in range(4)] def price(N, K, X, Y): if N < K: return N * X else: return K * X + (N-K) * Y print(price(N, K, X, Y))
s918114014
p03854
u911276694
2,000
262,144
Wrong Answer
18
3,444
686
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`.
def extract_6(x): strtemp=' ' if(len(x)>=6): temp=[0]*6 for i in range(6): temp[i]=x[len(x)-6+i] else: temp='false' strtemp=''.join(temp) print(strtemp) return(strtemp) def extract_5(x): strtemp=' ' if(len(x)>=5): temp=[0]*5 for i in range(5): temp[i]=x[len(x)-5+i] else: temp='false' strtemp=''.join(temp) print(strtemp) return(strtemp) S=input() flag=1 while(flag==1): if(extract_6(S)=='dreamer'): S=S.rstrip('dreamer') elif(extract_6(S)=='eraser'): S=S.rstrip('eraser') elif(extract_5(S)=='dream'): S=S.rstrip('dream') elif(extract_5(S)=='erase'): S=S.rstrip('erase') else: flag=0 if len(S)!=0: print('NO') else: print('YES') print(S)
s771456075
Accepted
159
3,316
768
def extract_6(x): strtemp=' ' if(len(x)>=6): temp=[0]*6 for i in range(6): temp[i]=x[len(x)-6+i] else: temp='false' strtemp=''.join(temp) return(strtemp) def extract_5(x): strtemp=' ' if(len(x)>=5): temp=[0]*5 for i in range(5): temp[i]=x[len(x)-5+i] else: temp='false' strtemp=''.join(temp) return(strtemp) def extract_7(x): strtemp=' ' if(len(x)>=7): temp=[0]*7 for i in range(7): temp[i]=x[len(x)-7+i] else: temp='false' strtemp=''.join(temp) return(strtemp) S=input() flag=1 while(flag==1): if(extract_7(S)=='dreamer'): S=S[:-7] elif(extract_6(S)=='eraser'): S=S[:-6] elif(extract_5(S)=='dream'): S=S[:-5] elif(extract_5(S)=='erase'): S=S[:-5] else: flag=0 if len(S)!=0: print('NO') else: print('YES')
s529588901
p03049
u269318751
2,000
1,048,576
Wrong Answer
33
3,700
360
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
#python 3.5.2 N = int(input()) s_list = [input() for i in range(N)] cnt = sum([1 for s in s_list if "AB" in s]) a_end, b_start, a_b = 0, 0, 0 for s in s_list: if s[0] == "B" and s[-1] == "A": a_b += 1 elif s[0] == "B": b_start += 1 elif s[-1] == "A": a_end += 1 print(a_end, b_start, a_b) print(min(a_end, b_start)+a_b+cnt)
s374461523
Accepted
34
3,700
523
#python 3.5.2 N = int(input()) s_list = [input() for i in range(N)] cnt = sum([s.count("AB") for s in s_list]) a_end, b_start, a_b = 0, 0, 0 for s in s_list: if s[0] == "B" and s[-1] == "A": a_b += 1 elif s[0] == "B": b_start += 1 elif s[-1] == "A": a_end += 1 if a_b == 0: cnt += min(a_end, b_start) else: cnt += a_b - 1 if a_end >= 1: cnt += 1 a_end -= 1 if b_start >= 1: cnt += 1 b_start -= 1 cnt += min(a_end, b_start) print(cnt)
s089978473
p03693
u735069283
2,000
262,144
Wrong Answer
17
2,940
105
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()) result = (r*100+g*10+b)%4 if result==0: print('yes') else: print('no')
s838649651
Accepted
17
2,940
79
r,g,b=map(int,input().split()) print('YES' if (r*100+g*10+b)%4 == 0 else 'NO')
s700323501
p02831
u517099533
2,000
1,048,576
Wrong Answer
17
3,064
841
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
a, b = list(map(int, input().split())) def prime(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a a = sorted(prime(a)) b = sorted(prime(b)) print(a, b) c = set() def cal(a, b): c = set() for i in range(len(a)): c.add(a[i]) for i in range(len(b)): c.add(b[i]) ans = [] e = 1 for i in range(len(c)): d =c.pop() if a.count(d) >= b.count(d): for j in range(a.count(d)): ans.append(d) else: for j in range(b.count(d)): ans.append(d) for i in range(len(ans)): e *= ans[i] return e print(cal(a, b))
s849085132
Accepted
17
3,064
829
a, b = list(map(int, input().split())) def prime(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a a = sorted(prime(a)) b = sorted(prime(b)) c = set() def cal(a, b): c = set() for i in range(len(a)): c.add(a[i]) for i in range(len(b)): c.add(b[i]) ans = [] e = 1 for i in range(len(c)): d =c.pop() if a.count(d) >= b.count(d): for j in range(a.count(d)): ans.append(d) else: for j in range(b.count(d)): ans.append(d) for i in range(len(ans)): e *= ans[i] return e print(cal(a, b))
s358770222
p04029
u633450100
2,000
262,144
Wrong Answer
17
2,940
34
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
N = int(input()) print(N*(N+1)/2)
s283460653
Accepted
17
2,940
34
N = int(input()) print(N*(N+1)//2)
s741726103
p03973
u619819312
2,000
262,144
Wrong Answer
268
7,084
271
N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i. Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets a positive integer P indicating its price, and shows this product to customers in order, starting from the front of the line. This step is repeated as described below. At each step, when a product is shown to a customer, if price P is equal to or less than the cash held by that customer at the time, the customer buys the product and Mr. Takahashi ends the current step. That is, the cash held by the first customer in line with cash equal to or greater than P decreases by P, and the next step begins. Mr. Takahashi can set the value of positive integer P independently at each step. He would like to sell as many products as possible. However, if a customer were to end up with 0 cash on hand after a purchase, that person would not have the fare to go home. Customers not being able to go home would be a problem for Mr. Takahashi, so he does not want anyone to end up with 0 cash. Help out Mr. Takahashi by writing a program that determines the maximum number of products he can sell, when the initial cash in possession of each customer is given.
n=int(input()) a=[int(input())for i in range(n)] c=0 b=1 d=0 while c<n: if a[c]==b: b+=1 c+=1 else: if a[c]%b==0: d+=max((a[c]-2-b)//b+1,a[c]//b-1) c+=1 else: d+=a[c]//b c+=1 print(d)
s105469461
Accepted
237
7,084
311
n=int(input()) a=[int(input())for i in range(n)] c=0 b=1 d=0 while c<n: if a[c]==b: b+=1 c+=1 else: if a[c]%b==0: d+=((a[c]-2-b)//b+1if b!=1 else a[c]-1) c+=1 b+=(1 if b==1 else 0) else: d+=a[c]//b c+=1 print(d)
s630636725
p03548
u169501420
2,000
262,144
Wrong Answer
19
3,060
233
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
# -*- coding: utf-8 -*- [X, Y, Z] = [int(i) for i in input().split()] personal_width = Y + Z chair_width = X - 2 * Z number = chair_width // personal_width amari = X % personal_width if amari >= X: number += 1 print(number)
s928115938
Accepted
17
3,060
229
# -*- coding: utf-8 -*- [X, Y, Z] = [int(i) for i in input().split()] personal_width = Y + Z chair_width = X - Z number = chair_width // personal_width amari = X % personal_width if amari >= X: number += 1 print(number)
s908386243
p02842
u677121387
2,000
1,048,576
Wrong Answer
17
2,940
91
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
N = int(input()) X = int(N//1.08) if (X*1.08)//1 == N: print(X) else: print(":(")
s911858907
Accepted
17
2,940
132
N = int(input()) X = int(N//1.08) if (X*1.08)//1 == N: print(X) elif ((X+1)*1.08)//1 == N: print(X+1) else: print(":(")
s808741121
p03353
u672475305
2,000
1,048,576
Wrong Answer
1,766
4,340
207
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
s = input() k = int(input()) dct = [] for i in range(len(s)): for j in range(k+1): word = s[i:i+j] if word not in dct: dct.append(word) dct.sort() for d in dct: print(d)
s625049104
Accepted
33
3,188
331
s = input() k = int(input()) lst = sorted(list(set(s))) tank = [] for tg in lst: for i in range(len(s)): if s[i]==tg: for j in range(k): if i+j<=len(s) and (s[i:i+j+1] not in tank): tank.append(s[i:i+j+1]) if len(tank) >= k: break tank.sort() print(tank[k-1])
s940631038
p02612
u337949146
2,000
1,048,576
Wrong Answer
28
9,152
24
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.
print(int(input())%1000)
s970017768
Accepted
27
8,940
36
print((1000-int(input())%1000)%1000)
s327325882
p02277
u917432951
1,000
131,072
Wrong Answer
30
7,704
1,057
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
def partition(A,p,r): x = A[r] i = p-1 for j in range(p,r): if A[j][1] <= x[1]: i = i+1 (A[i],A[j]) = (A[j],A[i]) (A[i+1],A[r]) = (A[r],A[i+1]) return i+1 def quicksort(A,p,r): if p < r: q = partition(A,p,r) quicksort(A,p,q-1) quicksort(A,q+1,r) def isStable(A,n): for i in range(1,n-1): if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]: return False return True if __name__ == '__main__': n = (int)(input()) A = [] for i in range(0,n): tmp = list(input().split()) A.append((tmp[0],(int)(tmp[1]),i)) quicksort(A,0,n-1) print("Stable" if isStable(A,n) else "Not Stable" ) for x in A: print(x[0],x[1])
s406779650
Accepted
1,080
22,516
1,057
def partition(A,p,r): x = A[r] i = p-1 for j in range(p,r): if A[j][1] <= x[1]: i = i+1 (A[i],A[j]) = (A[j],A[i]) (A[i+1],A[r]) = (A[r],A[i+1]) return i+1 def quicksort(A,p,r): if p < r: q = partition(A,p,r) quicksort(A,p,q-1) quicksort(A,q+1,r) def isStable(A,n): for i in range(1,n-1): if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]: return False return True if __name__ == '__main__': n = (int)(input()) A = [] for i in range(0,n): tmp = list(input().split()) A.append((tmp[0],(int)(tmp[1]),i)) quicksort(A,0,n-1) print("Stable" if isStable(A,n) else "Not stable" ) for x in A: print(x[0],x[1])
s498922794
p03478
u702018889
2,000
262,144
Wrong Answer
25
9,116
148
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b=map(int,input().split()) ans=0 for i in range(1,a+1): k=list(str(i)) m=list(map(int,k)) if a<=sum(m)<=b: ans+=i print(ans)
s467497399
Accepted
41
9,120
148
a,b,c=map(int,input().split()) ans=0 for i in range(1,a+1): n=list(str(i)) m=list(map(int,n)) if b<=sum(m)<=c: ans+=i print(ans)
s865870138
p03971
u261886891
2,000
262,144
Wrong Answer
109
4,016
400
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
N, A, B = list(map(int, input().split())) S = input() cnt1 = 0 cnt2 = 0 for x in S: if x == 'a': if cnt1 < A+B: print("YES") cnt1 += 1 else: print("NO") elif x == 'b': if cnt1 < A+B and cnt2 < B: print("YES") cnt1 += 1 cnt2 += 1 else: print("NO") else: print("NO")
s025445341
Accepted
101
4,244
400
N, A, B = list(map(int, input().split())) S = input() cnt1 = 0 cnt2 = 0 for x in S: if x == 'a': if cnt1 < A+B: print("Yes") cnt1 += 1 else: print("No") elif x == 'b': if cnt1 < A+B and cnt2 < B: print("Yes") cnt1 += 1 cnt2 += 1 else: print("No") else: print("No")
s659498389
p03574
u989345508
2,000
262,144
Wrong Answer
21
3,444
447
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()+"." if i!=h else "."*(w+1) for i in range(h+1)] def count_8(i,j): global h,w,s cnt=s[i-1][j-1]=="#"+s[i-1][j+1]=="#"+s[i+1][j-1]=="#"+s[i+1][j+1]=="#" \ +s[i-1][j]=="#"+s[i][j-1]=="#"+s[i+1][j]=="#"+s[i][j+1]=="#" return cnt for i in range(h): for j in range(w): if s[i][j]=="#": print("#",end="") else: print(count_8(i,j),end="") print()
s716463461
Accepted
21
3,064
472
h,w=map(int,input().split()) s=[input()+"." if i!=h else "."*(w+1) for i in range(h+1)] def count_8(i,j): global h,w,s cnt=str((s[i-1][j-1]=="#")+(s[i-1][j+1]=="#")+(s[i+1][j-1]=="#")+(s[i+1][j+1]=="#") \ +(s[i-1][j]=="#")+(s[i][j-1]=="#")+(s[i+1][j]=="#")+(s[i][j+1]=="#")) return cnt for i in range(h): s_sub="" for j in range(w): if s[i][j]=="#": s_sub+="#" else: s_sub+=count_8(i,j) print(s_sub)
s284709733
p04011
u693694535
2,000
262,144
Wrong Answer
17
2,940
83
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
N=int(input()) K=int(input()) X=int(input()) Y=int(input()) Q=N*X+Y*(N-K) print(Q)
s104380784
Accepted
17
2,940
117
N=int(input()) K=int(input()) X=int(input()) Y=int(input()) if N<=K: Q=N*X else: Q=K*X+(N-K)*Y print(int(Q))
s550726446
p02421
u144068724
1,000
131,072
Wrong Answer
30
7,576
343
Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in lexicographical order becomes the winner of that turn. The winner obtains 3 points. In the case of a draw, they obtain 1 point each. Write a program which reads a sequence of cards Taro and Hanako have and reports the final scores of the game.
n = int(input()) t_point = 0 h_point = 0 for i in range(n): card = input().split() print(card) taro = card[0] card.sort() card.reverse() print(card) if card[0] == card[1]: t_point += 1 h_point += 1 elif card[0] == taro: t_point += 3 else: h_point += 3 print(t_point,h_point)
s575313410
Accepted
30
7,568
311
n = int(input()) t_point = 0 h_point = 0 for i in range(n): card = input().split() taro = card[0] card.sort() card.reverse() if card[0] == card[1]: t_point += 1 h_point += 1 elif card[0] == taro: t_point += 3 else: h_point += 3 print(t_point,h_point)
s752189975
p02796
u509150616
2,000
1,048,576
Wrong Answer
2,207
43,516
589
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.
import numpy as np def solve(XL, N): XL.sort(key = lambda x:x[0]) for i in range(N): if XL[i][0] == None: pass else: right = XL[i][0] + XL[i][1] for j in range(i+1, N): if XL[j][0] == None: pass elif XL[j][0] - XL[j][1] < right: XL[j][0] = None count = 0 for i in range(N): if XL[i][0] != 0: count += 1 return count N = int(input()) XL = [] for i in range(N): x, l = map(int, input().split(' ')) XL.append([x, l]) print(solve(XL, N))
s480693947
Accepted
320
25,428
329
def solve(XL, N): XL.sort(key=lambda x:x[1]) count = N for i in range(1, N): if XL[i][0] < XL[i-1][1]: XL[i][1] = XL[i-1][1] count -= 1 return count N = int(input()) XL = [] for i in range(N): x, l = map(int, input().split(' ')) XL.append([x-l, x+l]) print(solve(XL, N))
s800632920
p03610
u865413330
2,000
262,144
Wrong Answer
19
3,316
112
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = list(input().split()) result = "" for i in range(len(s)): if i % 2 != 0: result += s[i] print(s)
s015344358
Accepted
45
3,956
114
s = list(input()) result = "" for i in range(len(s)): if (i+1) % 2 != 0: result += s[i] print(result)
s302678392
p02841
u263339477
2,000
1,048,576
Wrong Answer
17
2,940
79
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
a, b=map(int, input().split()) c, d=map(int, input().split()) 0 if a==c else 1
s865005484
Accepted
18
2,940
86
a, b=map(int, input().split()) c, d=map(int, input().split()) print(0 if a==c else 1)
s992752886
p03719
u604655161
2,000
262,144
Wrong Answer
17
2,940
197
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
def ABC_61_A(): A,B,C = map(int, input().split()) if C>=A and C<=B: print('YES') else: print('NO') if __name__ == '__main__': ABC_61_A()
s875643493
Accepted
17
2,940
197
def ABC_61_A(): A,B,C = map(int, input().split()) if C>=A and C<=B: print('Yes') else: print('No') if __name__ == '__main__': ABC_61_A()
s421703070
p04043
u102242691
2,000
262,144
Wrong Answer
19
2,940
159
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a = list(map(int,input().split())) if a.sort() == [5,5,7]: print("YES") else: print("NO")
s910000240
Accepted
17
2,940
171
a = list(map(int,input().split())) a.sort() #print(a) if a == [5,5,7]: print("YES") else: print("NO")
s620055745
p03473
u636775911
2,000
262,144
Wrong Answer
17
2,940
45
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
#coding:utf-8 n=int(input()) n-=48 print(n)
s764091390
Accepted
17
2,940
46
#coding:utf-8 n=int(input()) n=48-n print(n)
s683469339
p03555
u875769753
2,000
262,144
Wrong Answer
27
9,040
144
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
C1 = input() C2 = input() ans = 'YES' if C1[0] != C2[2]: ans = 'NO' if C1[1] != C2[1]: ans = 'NO' if C1[2] != C2[1]: ans = 'NO' print(ans)
s107729958
Accepted
33
8,932
144
C1 = input() C2 = input() ans = 'YES' if C1[0] != C2[2]: ans = 'NO' if C1[1] != C2[1]: ans = 'NO' if C1[2] != C2[0]: ans = 'NO' print(ans)
s192978028
p02842
u556225812
2,000
1,048,576
Wrong Answer
17
2,940
90
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
N = int(input()) x = N // 1.08 M = x * 1.08 // 1 if N == M: print(x) else: print(':(')
s387296831
Accepted
17
2,940
117
import math N = int(input())*100 x = math.ceil(N / 108) M = x*108 if M//100 == N//100: print(x) else: print(':(')
s388574511
p00205
u847467233
1,000
131,072
Wrong Answer
30
5,596
434
ไปฒ่‰ฏใ— 5 ไบบ็ต„ใงใ˜ใ‚ƒใ‚“ใ‘ใ‚“ใ‚’ใ™ใ‚‹ใ“ใจใซใชใ‚Šใพใ—ใŸใ€‚ใ˜ใ‚ƒใ‚“ใ‘ใ‚“ใจใฏใ€ใ‚ฐใƒผใ€ใƒใƒงใ‚ญใ€ใƒ‘ใƒผใจใ„ใ† 3ใคใฎๆ‰‹ใŒใ‚ใ‚Šใ€ใ‚ฐใƒผใจใƒใƒงใ‚ญใฎๅ‹่ฒ ใชใ‚‰ใ‚ฐใƒผใŒใ€Œๅ‹ใกใ€ใƒปใƒใƒงใ‚ญใŒใ€Œ่ฒ ใ‘ใ€ใ€ใƒใƒงใ‚ญใจใƒ‘ใƒผใชใ‚‰ใ€ใƒใƒงใ‚ญใŒใ€Œๅ‹ใกใ€ใƒปใƒ‘ใƒผใŒใ€Œ่ฒ ใ‘ใ€ใ€ใƒ‘ใƒผใจใ‚ฐใƒผใชใ‚‰ใƒ‘ใƒผใŒใ€Œๅ‹ใกใ€ใƒปใ‚ฐใƒผใŒใ€Œ่ฒ ใ‘ใ€ใจใ„ใ†ใƒซใƒผใƒซใงใ™ใ€‚ๅ…จๅ“กใŒๅŒใ˜ๆ‰‹ใ€ใพใŸใฏใ‚ฐใƒผใ€ใƒใƒงใ‚ญใ€ใƒ‘ใƒผๅ…จใฆใŒๅ‡บใŸๅ ดๅˆใฏใ€Œใ‚ใ„ใ“ใ€ใจใชใ‚Šใพใ™ใ€‚ 5 ไบบใฎใ˜ใ‚ƒใ‚“ใ‘ใ‚“ใฎๆ‰‹ใ‚’ๅ…ฅๅŠ›ใจใ—ใ€ใใ‚Œใžใ‚Œใฎไบบใฎๅ‹ๆ•—ใ‚’ๅ‡บๅŠ›ใ™ใ‚‹ใƒ—ใƒญใ‚ฐใƒฉใƒ ใ‚’ไฝœๆˆใ—ใฆใใ ใ•ใ„ใ€‚ใ˜ใ‚ƒใ‚“ใ‘ใ‚“ใฎๆ‰‹ใฏใ€ใ‚ฐใƒผใฏ 1ใ€ใƒใƒงใ‚ญใฏ 2ใ€ใƒ‘ใƒผใฏ 3 ใฎๆ•ฐๅญ—ใง่กจใ—ใพใ™ใ€‚ๅ‹ๆ•—ใฏใ€Œๅ‹ใกใ€ใ‚’ 1ใ€ใ€Œ่ฒ ใ‘ใ€ใ‚’ 2ใ€ใ€Œใ‚ใ„ใ“ใ€ใ‚’ 3 ใฎๆ•ฐๅญ—ใง่กจใ—ใ€ๅ…ฅๅŠ›้ †ใซๅพ“ใฃใฆๅ‡บๅŠ›ใ—ใพใ™ใ€‚
# AOJ 0205: Rock, Paper, Scissors # Python3 2018.6.25 bal4u h = [0]*5 while True: try: for i in range(5): h[i] = int(input()) except: break print(type(h), h) if len(set(h)) == 1 or len(set(h)) == 3: print(*[3]*5, sep='\n') continue ans = [1]*5 for i in range(5): if h[i] == 1: ans[i] += (h.count(3) > 0) elif h[i] == 2: ans[i] += (h.count(1) > 0) else: ans[i] += (h.count(2) > 0) print(*ans, sep='\n')
s404357430
Accepted
30
5,596
415
# AOJ 0205: Rock, Paper, Scissors # Python3 2018.6.25 bal4u h = [0]*5 while True: try: for i in range(5): h[i] = int(input()) except: break if len(set(h)) == 1 or len(set(h)) == 3: print(*[3]*5, sep='\n') continue ans = [1]*5 for i in range(5): if h[i] == 1: ans[i] += (h.count(3) > 0) elif h[i] == 2: ans[i] += (h.count(1) > 0) else: ans[i] += (h.count(2) > 0) print(*ans, sep='\n')
s033927637
p03555
u306142032
2,000
262,144
Wrong Answer
17
2,940
88
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
c = input() c_r = input() if reversed(c) == c_r: print("Yes") else: print("No")
s931305783
Accepted
17
2,940
90
c = input() c_r = input() c = c[::-1] if c == c_r: print("YES") else: print("NO")
s365093698
p02399
u828399801
1,000
131,072
Wrong Answer
20
7,648
151
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)
splited = input().split(" ") f = int(splited[0])/int(splited[1]) r = int(splited[0])%int(splited[1]) d = int(splited[0])//int(splited[1]) print(d,r,f)
s070731138
Accepted
30
7,644
171
splited = input().split(" ") f = int(splited[0])/int(splited[1]) r = int(splited[0])%int(splited[1]) d = int(splited[0])//int(splited[1]) print(d, r, "{0:.5f}".format(f))
s888470459
p02401
u535719732
1,000
131,072
Wrong Answer
20
5,608
260
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.
ans = 0 while True: num = list(map(str,input().split())) if(num[1] == "?"): break a = int(num[0]) b = int(num[2]) if(num[1] == "+"): ans=a+b elif(num[1] == "-"): ans=a-b elif(num[1] == "*"): ans=a*b else: ans=a/b print(ans)
s340797392
Accepted
20
5,596
286
ans = 0 while True: num = list(map(str,input().split())) if(num[1] == "?"): break a = int(num[0]) b = int(num[2]) op = num[1] if(op == "+"): ans=a+b elif(op == "-"): ans=a-b elif(op == "*"): ans=a*b elif(op == "/"): ans=a/b print("%d" %ans)
s590129856
p03862
u994521204
2,000
262,144
Wrong Answer
191
20,788
516
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
n, x = map(int, input().split()) A = list(map(int, input().split())) cnt = [0] * (n - 1) ans1 = 0 for i in range(n - 1): cnt[i] = A[i] + A[i + 1] cnt[i] -= x cnt[i] = max(cnt[i], 0) temp_cnt = cnt[::] print(cnt) for i in range(n - 1): if temp_cnt[i] == 0: continue if i < n - 2: ans1 += temp_cnt[i] temp_cnt[i + 1] -= min(A[i + 1], temp_cnt[i]) temp_cnt[i] = 0 temp_cnt[i + 1] = max(temp_cnt[i + 1], 0) # print(ans1) ans1 += temp_cnt[-1] print(ans1)
s752001377
Accepted
192
19,908
518
n, x = map(int, input().split()) A = list(map(int, input().split())) cnt = [0] * (n - 1) ans1 = 0 for i in range(n - 1): cnt[i] = A[i] + A[i + 1] cnt[i] -= x cnt[i] = max(cnt[i], 0) temp_cnt = cnt[::] # print(cnt) for i in range(n - 1): if temp_cnt[i] == 0: continue if i < n - 2: ans1 += temp_cnt[i] temp_cnt[i + 1] -= min(A[i + 1], temp_cnt[i]) temp_cnt[i] = 0 temp_cnt[i + 1] = max(temp_cnt[i + 1], 0) # print(ans1) ans1 += temp_cnt[-1] print(ans1)
s914848154
p03455
u652150585
2,000
262,144
Wrong Answer
17
2,940
98
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
num=list(map(int,input().split())) if num[0]*num[1]%2==0: print("even") else: print("odd")
s130597870
Accepted
17
2,940
98
num=list(map(int,input().split())) if num[0]*num[1]%2==0: print("Even") else: print("Odd")
s782947332
p03469
u902917675
2,000
262,144
Wrong Answer
26
8,996
34
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
x = input() print("2018" + x[6:])
s209941608
Accepted
27
8,980
34
x = input() print("2018" + x[4:])
s388984764
p03139
u102960641
2,000
1,048,576
Wrong Answer
17
2,940
63
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
n,a,b = map(int, input().split()) print(min(a,b), min(a+b-n,n))
s147547952
Accepted
17
2,940
71
n,a,b = map(int, input().split()) print(min(a,b), max(min(a+b-n,n),0))
s039968824
p03699
u747602774
2,000
262,144
Wrong Answer
17
2,940
145
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
N=int(input()) li=[] for n in range(N): li.append(int(input())) print(li) li.sort() S=sum(li) while S%10==0 and li!=[]: S-=li.pop(0) print(S)
s029359531
Accepted
17
3,060
211
N=int(input()) li=[] for n in range(N): li.append(int(input())) li.sort() S=sum(li) while S%10==0 and li!=[]: if li[0]%10==0: li.pop(0) else: S-=li.pop(0) if li==[]: print(0) else: print(S)
s975958420
p02389
u279483260
1,000
131,072
Wrong Answer
30
7,632
164
Write a program which calculates the area and perimeter of a given rectangle.
def calc(a, b): area = a * b circumference = (a * 2) + (b * 2) return area, circumference a, b = map(int, input('a, b???').split()) print(calc(a, b))
s448454035
Accepted
20
5,588
129
# -*- coding: utf-8 -*- a, b = map(int, input().split()) area = a * b circle = (a + b) * 2 print('{} {}'.format(area, circle))
s476606548
p02274
u196653484
1,000
131,072
Wrong Answer
20
5,596
655
For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following program: bubbleSort(A) cnt = 0 // the number of inversions for i = 0 to A.length-1 for j = A.length-1 downto i+1 if A[j] < A[j-1] swap(A[j], A[j-1]) cnt++ return cnt For the given sequence $A$, print the number of inversions of $A$. Note that you should not use the above program, which brings Time Limit Exceeded.
count=0 def merge(A, left, mid, right): global count L=A[left:mid]+[2**32] R=A[mid:right]+[2**32] i=0 j=0 for k in range(left,right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 count+=1 def merge_sort(A, left, right): if left+1 < right: mid=(left+right)//2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) if __name__ == "__main__": n=int(input()) A=list(map(int,input().split())) merge_sort(A,0,n) print(*A) print(count)
s086971547
Accepted
2,070
27,480
732
count=0 def merge(A, left, mid, right): global count h=[] L=A[left:mid]+[2**32] R=A[mid:right]+[2**32] i=0 j=0 for k in range(left,right): if L[i] <= R[j]: A[k] = L[i] h.append(L[i]) i += 1 else: A[k] = R[j] h.append(R[j]) j += 1 if i < len(L)-1: count += len(L) - 1 - i def merge_sort(A, left, right): if left+1 < right: mid=(left+right)//2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) if __name__ == "__main__": n=int(input()) A=list(map(int,input().split())) merge_sort(A,0,n) print(count)
s467526187
p03047
u163449343
2,000
1,048,576
Wrong Answer
17
2,940
49
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
n,k = map(int, input().split()) print((n-2)*k//k)
s584844110
Accepted
17
3,060
146
n,k = map(int, input().split()) ans = 0 num = [i for i in range(1, k+1)] while num[-1] <= n: num = [i+1 for i in num] ans += 1 print(ans)
s687550744
p03815
u576432509
2,000
262,144
Wrong Answer
18
2,940
79
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: * Operation: Rotate the die 90ยฐ toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.
x=int(input()) xi=x//11 if xi==0: print(2*xi) else: print(2*xi+1)
s820286143
Accepted
17
2,940
102
x=int(input()) n=x//11 if x%11==0: print(2*n) elif x%11<=6: print(2*n+1) else: print(2*n+2)
s265693889
p02280
u805716376
1,000
131,072
Wrong Answer
20
5,624
928
A rooted binary tree is a tree with a root node in which every node has at most two children. Your task is to write a program which reads a rooted binary tree _T_ and prints the following information for each node _u_ of _T_ : * node ID of _u_ * parent of _u_ * sibling of _u_ * the number of children of _u_ * depth of _u_ * height of _u_ * node type (root, internal node or leaf) If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_ have the same parent, we say _u_ is a sibling of _v_ (vice versa). The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf. Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
n = int(input()) deg = [0]*n child, parent = {}, {} sib = [None]*n for i in range(n): a = list(map(int, input().split())) if a[1] != -1: child[i] = a[1:] sib[a[1]] = a[2] sib[a[2]] = a[1] deg[i] = 2 for j in child[i]: parent[j] = i else: child[i] = [] root = (set(child)-set(parent)).pop() depth = [None]*n depth[root] = 0 hei = [None]*n parent[root] = -1 sib[root] = -1 print(child) def dfs(s): if len(child[s]) == 0: hei[s] = 0 return for i in child[s]: depth[i] = depth[s] + 1 dfs(i) hei[s] = max(hei[i] for i in child[s]) + 1 dfs(root) for i in range(n): node_type = 'root' if parent[i] == -1 else 'leaf' if len(child[i]) == 0 else 'internal node' print(f'node {i}: parent = {parent[i]}, sibling = {sib[i]}, degree = {deg[i]}, depth = {depth[i]}, height = {hei[i]}, {node_type}')
s605531279
Accepted
20
5,644
1,228
n = int(input()) deg = [0]*n child, parent = {}, {} sib = [None]*n for i in range(n): a = list(map(int, input().split())) if a[1] != -1: if a[2] == -1: child[a[0]] = [a[1]] sib[a[1]] = a[2] deg[a[0]] = 1 else: child[a[0]] = a[1:] sib[a[1]] = a[2] sib[a[2]] = a[1] deg[a[0]] = 2 for j in child[a[0]]: parent[j] = a[0] elif a[2] != -1: child[a[0]] = [a[2]] sib[a[2]] = a[1] deg[a[0]] = 1 for j in child[a[0]]: parent[j] = a[0] else: child[a[0]] = [] root = (set(child)-set(parent)).pop() depth = [None]*n depth[root] = 0 hei = [None]*n parent[root] = -1 sib[root] = -1 def dfs(s): if len(child[s]) == 0: hei[s] = 0 return for i in child[s]: depth[i] = depth[s] + 1 dfs(i) hei[s] = max(hei[i] for i in child[s]) + 1 dfs(root) for i in range(n): node_type = 'root' if parent[i] == -1 else 'leaf' if len(child[i]) == 0 else 'internal node' print(f'node {i}: parent = {parent[i]}, sibling = {sib[i]}, degree = {deg[i]}, depth = {depth[i]}, height = {hei[i]}, {node_type}')
s426800742
p01086
u037441960
8,000
262,144
Wrong Answer
20
5,604
453
A _Short Phrase_ (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition: > (The Condition for a Short Phrase) > The sequence of words can be divided into five sections such that the total > number of the letters in the word(s) of the first section is five, that of > the second is seven, and those of the rest are five, seven, and seven, > respectively. The following is an example of a Short Phrase. > > do the best and enjoy today at acm icpc In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase. Now, _Short Phrase Parnassus_ published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
while True : n = int(input()) if(n == 0) : break else : A = [5, 7, 5, 7, 7] ans = 0 w = [len(input()) for i in range(n)] for i in range(n) : k = 0 s = 0 for j in range(i, n) : s += w[j] if(s == A[k]) : s = 0 k += 1 if(k == 5) : ans = i + 1 break elif(s > A[k]) : break if(ans != 0) : break print(ans)
s281421007
Accepted
30
5,616
773
while True : n = int(input()) if(n == 0) : break else : S = [len(input()) for i in range(n)] T = [5, 7, 5, 7, 7] ans = 0 for i in range(n) : s = 0 w = 0 for j in range(i, n) : s += S[j] if(s == T[w]) : s = 0 w += 1 if(w == 5) : ans = i + 1 break else : pass elif(s > T[w]) : break else : pass if(ans != 0) : break else : pass print(ans)
s353404115
p03474
u697696097
2,000
262,144
Wrong Answer
17
3,064
305
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
import sys a,b=map(int,input().split()) ss=input().strip() if len(ss) != (a+b+1): print("No") sys.exit() #a 3 123-345 nums=[0,1,2,3,4,5,6,7,8,9] for i in range(len(ss)): if i==a: if i!="-": print("No") sys.exit() elif i not in nums: print("No") sys.exit() print("Yes")
s831457473
Accepted
17
3,064
333
import sys a,b=map(int,input().split()) ss=input().strip() if len(ss) != (a+b+1): print("No") sys.exit() #a 3 123-345 nums=["0","1","2","3","4","5","6","7","8","9"] for i in range(len(ss)): if i==a: if ss[i]!="-": print("No") sys.exit() elif ss[i] not in nums: print("No") sys.exit() print("Yes")
s139539292
p03470
u496975476
2,000
262,144
Wrong Answer
17
2,940
186
An _X -layered kagami mochi_ (X โ‰ฅ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
#! /usr/bin/env python3 n = int(input()) d = list(map(int, input().split(" "))) result = 1 d.sort() for i in range(1, len(d)): if d[i-1] < d[i]: result += 1 print(result)
s605919328
Accepted
17
3,060
204
#! /usr/bin/env python3 n = int(input()) d = [] result = 1 for _ in range(0, n): d.append(int(input())) d.sort() for i in range(1, len(d)): if d[i-1] < d[i]: result += 1 print(result)
s149768989
p04029
u231647664
2,000
262,144
Wrong Answer
18
2,940
241
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
a = str(input()) b = list(a) c = len(b) strs = [] for i in range(c): if b[i] == 'B': if i == 0 or len(strs) == 0 or b[i-1] == 'B': continue else: strs = strs[:-1] else: strs.append(b[i]) print(''.join(strs))
s028637446
Accepted
18
2,940
55
a = int(input()) l = range(1, a+1) b = sum(l) print(b)
s337580613
p02678
u623283955
2,000
1,048,576
Wrong Answer
832
67,424
375
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
N,M=map(int,input().split()) l=[set() for i in range(N)] for i in range(M): a,b=map(int,input().split()) l[a-1].add(b-1) l[b-1].add(a-1) ope=[1]*N ope[0]=0 s={0} ans=[-1]*N while len(s): news=set() for j in s: for k in l[j]: if ope[k]: news.add(k) ans[k]=j ope[k]=0 s=news print('yes') for i in range(1,N): print(ans[i]+1)
s931176400
Accepted
780
67,612
375
N,M=map(int,input().split()) l=[set() for i in range(N)] for i in range(M): a,b=map(int,input().split()) l[a-1].add(b-1) l[b-1].add(a-1) ope=[1]*N ope[0]=0 s={0} ans=[-1]*N while len(s): news=set() for j in s: for k in l[j]: if ope[k]: news.add(k) ans[k]=j ope[k]=0 s=news print('Yes') for i in range(1,N): print(ans[i]+1)
s952905734
p03493
u320325426
2,000
262,144
Wrong Answer
17
2,940
25
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
print(input().count("0"))
s689431015
Accepted
17
2,940
25
print(input().count("1"))
s302469794
p03992
u258009780
2,000
262,144
Wrong Answer
17
2,940
39
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
d = input() print(d[0:3] + " " + d[4:])
s354331477
Accepted
17
2,940
33
d=input() print(d[:4]+" "+d[4:])
s332858447
p03944
u141574039
2,000
262,144
Wrong Answer
20
3,064
507
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 โ‰ฆ i โ‰ฆ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 โ‰ฆ i โ‰ฆ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
W,H,N=map(int,input().split()) S=[0]*N; p=0 for i in range(N): x,y,a=map(int,input().split()) S[i]=[x,y,a] print("x,y,a",S) e=101;w=-1;n=101;s=-1 for i in range(N): if S[i][2]==1: w=max(w,S[i][0]) elif S[i][2]==2: e=min(e,S[i][0]) elif S[i][2]==3: s=max(s,S[i][1]) elif S[i][2]==4: n=min(n,S[i][1]) print("w,e,s,n",w,e,s,n) for i in range(1,H+1): for j in range(1,W+1): if (j<=w and w>0) or (j>=e and e<101) or (i>=n and n<101) or (i<=s and s>0): p=p+1 print(W*H-p)
s270459990
Accepted
20
3,064
507
W,H,N=map(int,input().split()) S=[0]*N; p=0 for i in range(N): x,y,a=map(int,input().split()) S[i]=[x,y,a] #print("x,y,a",S) e=101;w=-1;n=101;s=-1 for i in range(N): if S[i][2]==1: w=max(w,S[i][0]) elif S[i][2]==2: e=min(e,S[i][0]) elif S[i][2]==3: s=max(s,S[i][1]) elif S[i][2]==4: n=min(n,S[i][1]) #print("w,e,s,n",w,e,s,n) for i in range(1,H+1): for j in range(1,W+1): if (j<=w and w>0) or (j>e and e<101) or (i>n and n<101) or (i<=s and s>0): p=p+1 print(W*H-p)
s372822356
p02283
u564398841
2,000
131,072
Wrong Answer
20
7,740
1,055
Search trees are data structures that support dynamic set operations including insert, search, delete and so on. Thus a search tree can be used both as a dictionary and as a priority queue. Binary search tree is one of fundamental search trees. The keys in a binary search tree are always stored in such a way as to satisfy the following binary search tree property: * Let $x$ be a node in a binary search tree. If $y$ is a node in the left subtree of $x$, then $y.key \leq x.key$. If $y$ is a node in the right subtree of $x$, then $x.key \leq y.key$. The following figure shows an example of the binary search tree. For example, keys of nodes which belong to the left sub-tree of the node containing 80 are less than or equal to 80, and keys of nodes which belong to the right sub-tree are more than or equal to 80. The binary search tree property allows us to print out all the keys in the tree in sorted order by an inorder tree walk. A binary search tree should be implemented in such a way that the binary search tree property continues to hold after modifications by insertions and deletions. A binary search tree can be represented by a linked data structure in which each node is an object. In addition to a key field and satellite data, each node contains fields _left_ , _right_ , and _p_ that point to the nodes corresponding to its left child, its right child, and its parent, respectively. To insert a new value $v$ into a binary search tree $T$, we can use the procedure insert as shown in the following pseudo code. The insert procedure is passed a node $z$ for which $z.key = v$, $z.left = NIL$, and $z.right = NIL$. The procedure modifies $T$ and some of the fields of $z$ in such a way that $z$ is inserted into an appropriate position in the tree. 1 insert(T, z) 2 y = NIL // parent of x 3 x = 'the root of T' 4 while x โ‰  NIL 5 y = x // set the parent 6 if z.key < x.key 7 x = x.left // move to the left child 8 else 9 x = x.right // move to the right child 10 z.p = y 11 12 if y == NIL // T is empty 13 'the root of T' = z 14 else if z.key < y.key 15 y.left = z // z is the left child of y 16 else 17 y.right = z // z is the right child of y Write a program which performs the following operations to a binary search tree $T$. * insert $k$: Insert a node containing $k$ as key into $T$. * print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. You should use the above pseudo code to implement the insert operation. $T$ is empty at the initial state.
treeRoot = {'left': None, 'right': None, 'p': None, 'val': None} root = None def insert(val): global root z = {'left': None, 'right': None, 'p': None, 'val': val} x = root y = None while x: y = x if z['val'] < x['val']: x = x['left'] else: x = x['right'] z['p'] = y if y is None: root = z else: if z['val'] < y['val']: y['left'] = z else: y['right'] = z def inorder(root): if root is None: return inorder(root['left']) print(root['val']) inorder(root['right']) def preorder(root): if root is None: return print(root['val']) preorder(root['left']) preorder(root['right']) M = int(input()) for _ in range(M): line = input() if line == 'print': inorder(root) preorder(root) break inst, k = line.split() k = int(k) if inst == 'insert': insert(k) elif inst == 'find': pass elif inst == 'delete': pass
s833969901
Accepted
9,150
153,872
1,500
class Node: def __init__(self, val=None): self.l = None self.r = None self.p = None self.v = val def insert(self, val): if self.v is None: self.v = val return n = Node(val) cur_node = self prev_node = None while cur_node: prev_node = cur_node if val < prev_node.v: cur_node = prev_node.l else: cur_node = prev_node.r if prev_node is None: self.v = n.v else: if val < prev_node.v: prev_node.l = n else: prev_node.r = n def __str__(self): return str(self.v) def preorder(self): if self.v: print(' {0}'.format(self.v), end='') if self.l: self.l.preorder() if self.r: self.r.preorder() def inorder(self): if self.l: self.l.inorder() if self.v: print(' {0}'.format(self.v), end='') if self.r: self.r.inorder() M = int(input()) tree = Node() for _ in range(M): line = input().strip() if line == 'print': tree.inorder() print('') tree.preorder() print('') else: inst, k = line.split() k = int(k) if inst == 'insert': tree.insert(k) elif inst == 'find': pass elif inst == 'delete': pass
s200032350
p02557
u299869545
2,000
1,048,576
Wrong Answer
883
52,196
1,454
Given are two sequences A and B, both of length N. A and B are each sorted in the ascending order. Check if it is possible to reorder the terms of B so that for each i (1 \leq i \leq N) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it.
from heapq import heappush, heappop n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) all_freq = {} cnt_b = [0] * 220000 for num in b:cnt_b[num] += 1 for num in a: if num not in all_freq: all_freq[num] = 0 all_freq[num] += 1 for num in b: if num not in all_freq: all_freq[num] = 0 all_freq[num] += 1 heap = [] for num, freq in all_freq.items(): if freq > n: print("No") exit() if cnt_b[num] > 0: heappush(heap, (-freq, num)) ans = [] def get_max(): (freq, num) = heappop(heap) freq = -freq while all_freq[num] != freq: (freq, num) = heappop(heap) freq = -freq return num for num in a: most_freq_num = get_max() if most_freq_num != num: ans.append(most_freq_num) all_freq[most_freq_num] -= 1 cnt_b[most_freq_num] -= 1 if cnt_b[most_freq_num] > 0: heappush(heap, (-all_freq[most_freq_num], most_freq_num)) else: second_freq_num = get_max() heappush(heap, (-all_freq[most_freq_num], most_freq_num)) ans.append(second_freq_num) all_freq[second_freq_num] -= 1 cnt_b[second_freq_num] -= 1 if cnt_b[second_freq_num] > 0: heappush(heap, (-all_freq[second_freq_num], second_freq_num)) if cnt_b[num] == 0:continue all_freq[num] -= 1 heappush(heap, (-all_freq[num], num)) print(*ans)
s791635895
Accepted
873
52,224
1,467
from heapq import heappush, heappop n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) all_freq = {} cnt_b = [0] * 220000 for num in b:cnt_b[num] += 1 for num in a: if num not in all_freq: all_freq[num] = 0 all_freq[num] += 1 for num in b: if num not in all_freq: all_freq[num] = 0 all_freq[num] += 1 heap = [] for num, freq in all_freq.items(): if freq > n: print("No") exit() if cnt_b[num] > 0: heappush(heap, (-freq, num)) ans = [] def get_max(): (freq, num) = heappop(heap) freq = -freq while all_freq[num] != freq: (freq, num) = heappop(heap) freq = -freq return num for num in a: most_freq_num = get_max() if most_freq_num != num: ans.append(most_freq_num) all_freq[most_freq_num] -= 1 cnt_b[most_freq_num] -= 1 if cnt_b[most_freq_num] > 0: heappush(heap, (-all_freq[most_freq_num], most_freq_num)) else: second_freq_num = get_max() heappush(heap, (-all_freq[most_freq_num], most_freq_num)) ans.append(second_freq_num) all_freq[second_freq_num] -= 1 cnt_b[second_freq_num] -= 1 if cnt_b[second_freq_num] > 0: heappush(heap, (-all_freq[second_freq_num], second_freq_num)) all_freq[num] -= 1 if cnt_b[num] == 0:continue heappush(heap, (-all_freq[num], num)) print("Yes") print(*ans)
s632503206
p03493
u212328220
2,000
262,144
Wrong Answer
56
5,224
141
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.
import random s1 = random.randint(0,1) s2 = random.randint(0,1) s3 = random.randint(0,1) masu_list = (s1, s2, s3) print(masu_list.count(1))
s218179277
Accepted
20
3,316
63
import random masu_list = input() print(masu_list.count('1'))
s822606087
p03097
u353797797
2,000
1,048,576
Wrong Answer
714
11,440
1,209
You are given integers N,\ A and B. Determine if there exists a permutation (P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the following conditions, and create one such permutation if it exists. * P_0=A * P_{2^N-1}=B * For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit.
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def main(): def parity_onebit(x): return bin(x).count("1") & 1 def make_route(s, g, state): if state.count(-1) == 1: return [s, g] sep_dig = bin(s ^ g)[::-1].find("1") s_bit = (s >> sep_dig) & 1 Lstate = state[:] Rstate = state[:] Lstate[sep_dig] = s_bit Rstate[sep_dig] = 1 - s_bit for i in range(16): ng = 0 i_copy = i for sk in Lstate[::-1]: ng <<= 1 if sk == -1: ng += i_copy & 1 i_copy >>= 1 else: ng += sk ns = ng ^ (1 << sep_dig) if ng != s and parity_onebit(ng) != parity_onebit(s) and ns != g: break res = make_route(s, ng, Lstate) state[sep_dig] = 1 - s_bit res += make_route(ns, g, Rstate) return res n, s, g = map(int, input().split()) if parity_onebit(s) == parity_onebit(g): print("NO") exit() ans=make_route(s, g, [-1] * n) print(*ans) main()
s093485760
Accepted
744
14,888
1,033
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def bit(xx):return [format(x,"b") for x in xx] popcnt=lambda x:bin(x).count("1") def solve(xx,a,b): if len(xx)==2:return [a,b] k=(a^b).bit_length()-1 aa=[] bb=[] for x in xx: if (x>>k&1)==(a>>k&1):aa.append(x) else:bb.append(x) i=0 mid=aa[i] while mid==a or (mid^1<<k)==b or popcnt(a)&1==popcnt(mid)&1: i+=1 mid=aa[i] #print(bit(xx),a,b,k,bit(aa),bit(bb),format(mid,"b")) return solve(aa,a,mid)+solve(bb,mid^1<<k,b) def main(): n,a,b=MI() if (popcnt(a)&1)^(popcnt(b)&1)==0: print("NO") exit() print("YES") print(*solve(list(range(1<<n)),a,b)) main()
s675998429
p03493
u923010184
2,000
262,144
Wrong Answer
18
2,940
184
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
[a] = map(str,input().split()) b = 0 if a[0] == 1: c = b + 1 else: c = b if a[1] == 1: d = c + 1 else: d = c if a[2] == 1: e = d + 1 else: e = d print(e)
s189391288
Accepted
17
2,940
25
print(input().count("1"))
s203719246
p03457
u256106029
2,000
262,144
Wrong Answer
381
27,380
775
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()) trip = [] for i in range(n): array = list(map(int, input().strip().split())) trip.append(array) def func(num: int, query): for j in range(len(query)): if (query[j][0] % 2 == 0 and not (query[j][1] + query[j][2]) % 2 == 0) or \ (not query[j][0] % 2 == 0 and (query[j][1] + query[j][2]) % 2 == 0) or \ query[j][1] + query[j][2] > query[j][0]: return print('No') elif (query[j][0] % 2 == 0 and (query[j][1] + query[j][2]) % 2 == 0) or \ (not query[j][0] % 2 == 0 and not (query[j][1] + query[j][2]) % 2 == 0) and \ query[j][1] + query[j][2] <= query[j][0] and \ j + 1 == num: return print('YES') func(num=n, query=trip)
s520052290
Accepted
448
27,324
561
n = int(input()) travel = [[0, 0, 0]] for i in range(n): array = list(map(int, input().strip().split())) travel.append(array) def func(num, query): for j in range(num): time_temp = query[j+1][0] - query[j][0] x_temp = abs(query[j+1][1] - query[j][1]) y_temp = abs(query[j+1][2] - query[j][2]) if not (x_temp + y_temp) % 2 == time_temp % 2: print('No') return if x_temp + y_temp > time_temp: print('No') return print('Yes') func(num=n, query=travel)
s532995884
p03416
u507116804
2,000
262,144
Wrong Answer
62
2,940
154
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.
a,b=map(int, input().split()) n=b-a k=0 for i in range(n+1): A=str(a) if A[0]==A[4] and A[1]==A[3]: k+=1 else: k+=0 a+=1
s554563052
Accepted
71
2,940
164
a,b=map(int, input().split()) n=b-a k=0 for i in range(n+1): A=str(a) if A[0]==A[-1] and A[1]==A[-2]: k+=1 else: k+=0 a+=1 print(k)
s493235128
p01852
u546285759
5,000
262,144
Wrong Answer
20
7,520
61
่‚‰่ฅฟใใ‚“ใฏๆŒ‡ใฎๆ•ฐใ‚’ๅข—ใ‚„ใ—ใŸใ‚Šๆธ›ใ‚‰ใ—ใŸใ‚Šใงใใ‚‹๏ผŽ ่‚‰่ฅฟใใ‚“ใฎๅ‰ใซใฏ n ๅ€‹ใฎใพใ‚“ใ˜ใ‚…ใ†ใŒใ‚ใ‚‹๏ผŽ ่‚‰่ฅฟใใ‚“ใฏๆŒ‡ใ‚’ๆŠ˜ใฃใฆใพใ‚“ใ˜ใ‚…ใ†ใฎๅ€‹ๆ•ฐใ‚’ๆ•ฐใˆใ‚ˆใ†ใจใ—ใฆใ„ใ‚‹๏ผŽ ่‚‰่ฅฟใใ‚“ใฎๆŒ‡ใŒๅ–ใ‚Œใ‚‹ๅฝขใฏๆŠ˜ใ‚Œใฆใ„ใ‚‹ใ‹ๆŠ˜ใ‚Œใฆใ„ใชใ„ใ‹ใฎ 2 ใคใ—ใ‹็„กใ„๏ผŽ ่‚‰่ฅฟใใ‚“ใฏ [2 ้€ฒๆ•ฐ](http://www.asahi-net.or.jp/~ax2s-kmtn/ref/bdh.html)ใ‚’็†่งฃใ—ใฆใ„ใ‚‹๏ผŽ ่‚‰่ฅฟใใ‚“ใฏๅ„ๆŒ‡ใซ 2 ้€ฒๆ•ฐใฎๆกใ‚’ๅฏพๅฟœใ•ใ›ใฆๆ•ฐใ‚’ๆ•ฐใˆใ‚‹ใ“ใจใŒๅ‡บๆฅใ‚‹๏ผŽ ่‚‰่ฅฟใใ‚“ใฏๅฏพๆ•ฐใ‚’็†่งฃใ—ใฆใ„ใชใ„๏ผŽ ่‚‰่ฅฟใใ‚“ใฎใ‹ใ‚ใ‚Šใซใพใ‚“ใ˜ใ‚…ใ†ใ‚’ๆ•ฐใˆไธŠใ’ใ‚‹ใฎใซๅฟ…่ฆใชๆŒ‡ใฎๆœฌๆ•ฐใฎๆœ€ๅฐๅ€คใ‚’ๆฑ‚ใ‚ใ‚ˆ๏ผŽ
n = int(input()) print(1 if n == 0 else len(str(bin(n))[2:]))
s071612278
Accepted
40
7,708
70
n = int(input()) print(0 * (n == 0) + len(str(bin(n))[2:]) * (n != 0))
s394479923
p03379
u909643606
2,000
262,144
Wrong Answer
126
25,472
202
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
n=int(input()) a=[int(i) for i in input().split()] enu=max(a) k=(enu)/2 sa=float("inf") for i in range(n): if abs(k-a[i])<sa and a[i]!=enu: sa=abs(k-a[i]) aru=a[i] print(enu,aru)
s423180173
Accepted
304
25,348
303
n=int(input()) x=[int(i) for i in input().split()] nn=n//2 y=x[:] x.sort() low_median=x[nn-1] high_median=x[nn] [print(high_median) if y[i]<high_median else print(low_median) for i in range(n) ]
s968619933
p03456
u163421511
2,000
262,144
Wrong Answer
31
9,324
115
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
A, B = map(int, input().split()) num = int(A+B) result = "Yes" if num**0.5 == int(num**0.5) else "No" print(result)
s886142996
Accepted
31
9,436
103
A, B = input().split() num = (int(A+B))**0.5 result = "Yes" if num.is_integer() else "No" print(result)
s625339515
p02419
u177808190
1,000
131,072
Wrong Answer
20
5,556
254
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
import sys c = 0 for num, line in enumerate(sys.stdin): if line == 'END_OF_TEXT': break if num == 0: hoge = line continue for word in line.strip().split(): if word.lower() == hoge: c += 1 print (c)
s739470020
Accepted
20
5,556
254
c = 0 hoge = '' while True: sent = input() if sent.strip() == 'END_OF_TEXT': break if hoge: for word in sent.split(): if word.lower() == hoge: c += 1 else: hoge = sent.strip() print (c)
s145420541
p02613
u135197221
2,000
1,048,576
Wrong Answer
140
16,504
169
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 n = int(input()) words = Counter([input() for i in range(n)]) for i in ("AC", "WA", "TLE", "RE"): print(f"{i} X {words.get(i, 0)}")
s257021435
Accepted
142
16,396
169
from collections import Counter n = int(input()) words = Counter([input() for i in range(n)]) for i in ("AC", "WA", "TLE", "RE"): print(f"{i} x {words.get(i, 0)}")
s884730484
p03455
u497326082
2,000
262,144
Wrong Answer
18
2,940
93
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b = map(int,input().split()) if (a + b) % 2 == 1: print("Odd") else: print("Even")
s891766894
Accepted
17
2,940
86
a,b = map(int,input().split()) if a*b % 2 == 1: print("Odd") else: print("Even")
s387027129
p03456
u951601135
2,000
262,144
Wrong Answer
54
3,060
154
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a,b = map(str,input().split( )) #print(a+b) count=0 for i in range(1,int(a+b)): if(i*i == int(a+b)): print('Yes') break if(count==0):print('No')
s585786840
Accepted
18
3,060
59
print("No"if int("".join(input().split()))**.5%1 else"Yes")