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
s802863883
p02854
u476435125
2,000
1,048,576
Wrong Answer
147
34,488
371
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
import copy from bisect import bisect_left N=int(input()) la=list(map(int,input().split())) ll=copy.copy(la) #lr=copy.copy(la) for i in range(1,N): ll[i]+=ll[i-1] # lr[i]+=lr[i+1] print(ll) inl=bisect_left(ll,ll[-1]/2) ds=ll[-1]/2-ll[inl-1] db=ll[inl]-ll[-1]/2 if ds<=db: print(ll[-1]-ll[inl-1]*2) else: print(ll[inl]*2-ll[-1])
s598066447
Accepted
125
26,172
361
import copy from bisect import bisect_left N=int(input()) la=list(map(int,input().split())) ll=copy.copy(la) #lr=copy.copy(la) for i in range(1,N): ll[i]+=ll[i-1] # lr[i]+=lr[i+1] inl=bisect_left(ll,ll[-1]/2) ds=ll[-1]/2-ll[inl-1] db=ll[inl]-ll[-1]/2 if ds<=db: print(ll[-1]-ll[inl-1]*2) else: print(ll[inl]*2-ll[-1])
s356038636
p02397
u550922601
1,000
131,072
Wrong Answer
60
5,612
157
Write a program which reads two integers x and y, and prints them in ascending order.
while True : x, y = list(map(int,input().split())) if x == y == 0: break if x > y : print(x, y) else: print(y, x)
s507282077
Accepted
60
5,612
170
while True: x, y = list(map(int, input().split())) if x == 0 and y == 0: break if x > y: print(y, x) else: print(x, y)
s996137221
p02678
u244416763
2,000
1,048,576
Wrong Answer
1,387
47,912
570
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()) a = [0 for _ in range(m)] b = [0 for _ in range(m)] for i in range(m): a[i],b[i] = map(int,input().split()) a[i] -= 1 b[i] -= 1 ans = [0 for _ in range(n-1)] looked = [1 for _ in range(n)] queue = [0] looked[0] = 0 can = [[] for _ in range(n)] for i in range(m): can[a[i]].append(b[i]) can[b[i]].append(a[i]) while(len(queue)): now = queue.pop(0) for i in can[now]: if looked[i]: queue.append(i) looked[i] = 0 ans[i-1] = now+1 print("\n".join(list(map(str,ans))))
s460786121
Accepted
1,543
40,544
639
n,m = map(int,input().split()) a = [0 for _ in range(m)] b = [0 for _ in range(m)] for i in range(m): a[i],b[i] = map(int,input().split()) a[i] -= 1 b[i] -= 1 ans = [-1 for _ in range(n-1)] looked = [1 for _ in range(n)] queue = [0] looked[0] = 0 can = [[] for _ in range(n)] for i in range(m): can[a[i]].append(b[i]) can[b[i]].append(a[i]) while(len(queue)): now = queue.pop(0) for i in can[now]: if looked[i]: queue.append(i) looked[i] = 0 ans[i-1] = now+1 for i in ans: if ans == -1: print("No") exit print("Yes") for i in ans: print(i)
s385217492
p03575
u966000628
2,000
262,144
Wrong Answer
22
3,064
788
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
N,M = list(map(int,input().split())) set =[] s=int(N*(N+1)/2) count = 0 for i in range(M): set.append(list(map(int,input().split()))) def BFS(L): start = L.pop(0) visited.append(start) for item in lis[start-1]: if (item not in visited) and (item not in L): L.append(item) if L: BFS(L) else: global check if sum(visited) == s: check = 1 else: check = 0 for num in range(N): visited = [] lis = [[] for i in range(N)] que = [1] for i,item in enumerate(set): if i == num: continue x,y = item lis[x-1].append(y) lis[y-1].append(x) check = -1 BFS(que) print (check) if check == 0: count += 1 print (count)
s256634282
Accepted
27
3,192
852
N,M = list(map(int,input().split())) lis_s =[] count = 0 for _ in range(M): lis_s.append(tuple(map(int,input().split()))) graph = [[False for i in range(N+1)] for k in range(N+1)] for tp in lis_s: graph[tp[0]][tp[1]] = True graph[tp[1]][tp[0]] = True visited = [False]*(N+1) bridge = False def dfs(v): visited[v] = True for vs in range(1,N+1): if (graph[v][vs] == True) and (visited[vs] == False): dfs(vs) ans = 0 for num in range(M): graph[lis_s[num][0]][lis_s[num][1]] = False graph[lis_s[num][1]][lis_s[num][0]] = False for i in range(N+1): visited[i] = False dfs(1) bridge = False for check in range(1,N+1): if visited[check] == False: bridge = True if bridge: ans += 1 graph[lis_s[num][0]][lis_s[num][1]] = True graph[lis_s[num][1]][lis_s[num][0]] = True print(ans)
s764872076
p03132
u839188633
2,000
1,048,576
Wrong Answer
1,056
61,504
453
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions: * He never visits a point with coordinate less than 0, or a point with coordinate greater than L. * He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate. * He only changes direction at a point with integer coordinate. Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear. After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones: * Put a stone in one of Snuke's ears. * Remove a stone from one of Snuke's ears. Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
a = [int(input()) for _ in range(int(input()))] dp = [[0] * 5 for _ in range(len(a) + 1)] for i, x in enumerate(a): y = x % 2 + (x==0) * 2 z = (x + 1) % 2 dp[i+1][0] = dp[i][0] + x dp[i+1][1] = min(dp[i][0] + y, dp[i][1] + y) dp[i+1][2] = min(dp[i][1] + z, dp[i][0] + z, dp[i][2] + z) dp[i+1][3] = min(dp[i][2] + y, dp[i][1] + y, dp[i][0] + y, dp[i][3] + y) dp[i+1][4] = min(dp[i][3] + x, dp[i+1][3]) print(dp[-1][4])
s982430199
Accepted
993
67,736
364
a = [int(input()) for _ in range(int(input()))] dp = [[0] * 5 for _ in range(len(a) + 1)] for i, x in enumerate(a): m = x % 2 y = m + (not x) * 2 z = 1 - m dp[i+1][0] = dp[i][0] + x dp[i+1][1] = min(dp[i][:2]) + y dp[i+1][2] = min(dp[i][:3]) + z dp[i+1][3] = min(dp[i][:4]) + y dp[i+1][4] = min(dp[i]) + x print(min(dp[-1]))
s117595247
p02694
u663710122
2,000
1,048,576
Wrong Answer
22
9,164
103
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import math X = int(input()) t = 0 m = 100 while m < X: m = math.ceil(m * 1.01) t += 1 print(t)
s421272143
Accepted
21
9,184
104
import math X = int(input()) t = 0 m = 100 while m < X: m = math.floor(m * 1.01) t += 1 print(t)
s529588612
p03418
u057079894
2,000
262,144
Wrong Answer
177
4,464
159
Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
n,m = map(int,input().split()) ans = 0 for i in range(1,n+1): print(ans) ans += n // i * max(i-m,0) + max(n%i-m+1,0) if m == 0: ans -= n print(ans)
s959490039
Accepted
99
2,940
144
n,m = map(int,input().split()) ans = 0 for i in range(1,n+1): ans += n // i * max(i-m,0) + max(n%i-m+1,0) if m == 0: ans -= n print(ans)
s797726964
p03760
u425762225
2,000
262,144
Wrong Answer
17
3,064
279
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
#!/usr/bin/env python3 def main(): O = input() E = input() s = ['x']*(len(O) + len(E)) for i in range(len(O)//2): s[i*2] = O[i] s[i*2+1] = E[i] if len(O) % 2: s[-1] = O[-1] print(''.join(s)) if __name__ == '__main__': main()
s095457633
Accepted
17
3,060
262
#!/usr/bin/env python3 def main(): O = input() E = input() s = [] for i in range(len(E)): s.append(O[i]) s.append(E[i]) if len(O) - len(E): s.append(O[-1]) print(''.join(s)) if __name__ == '__main__': main()
s168418209
p03139
u402966520
2,000
1,048,576
Wrong Answer
17
3,060
487
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.
# 1 <= N < 100 # 0 <= A <= N # 0 <= B <= N inputstr = input() inputary = inputstr.split(" ") print(inputary) N = int(inputary[0]) A = int(inputary[1]) B = int(inputary[2]) suball = N - A - B if suball > 0: suball = 0 else: suball = abs(suball) if A >= B: print(str(B) + " " + str(suball)) elif A < B: print(str(A) + " " + str(suball))
s231001666
Accepted
17
3,060
472
# 1 <= N < 100 # 0 <= A <= N # 0 <= B <= N inputstr = input() inputary = inputstr.split(" ") N = int(inputary[0]) A = int(inputary[1]) B = int(inputary[2]) suball = N - A - B if suball > 0: suball = 0 else: suball = abs(suball) if A >= B: print(str(B) + " " + str(suball)) elif A < B: print(str(A) + " " + str(suball))
s954621337
p02936
u556225812
2,000
1,048,576
Wrong Answer
1,882
109,740
355
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
N, Q = map(int, input().split()) lst = [] cnt = [] ans = [0]*N N = N - 1 for i in range(N): lst.append(list(map(int, input().split()))) for j in range(Q): cnt.append(list(map(int, input().split()))) for k in range(Q): ans[cnt[k][0]-1] += cnt[k][1] for i in range(N): ans[lst[i][1]-1] += ans[lst[i][0]-1] for a in ans: print(a, end=" ")
s179266461
Accepted
1,862
56,080
512
import collections N, Q = map(int, input().split()) lst = [[] for _ in range(N)] ans = [0]*N for i in range(N-1): a, b = map(int, input().split()) lst[b-1].append(a-1) lst[a-1].append(b-1) for j in range(Q): p, x = map(int, input().split()) p -= 1 ans[p] += x q=collections.deque() q.append(0) flag = [0]*N while q: y = q.pop() flag[y] = 1 for k in lst[y]: if flag[k] == 1: continue ans[k] += ans[y] q.append(k) print(*ans)
s290547855
p04029
u102126195
2,000
262,144
Wrong Answer
17
2,940
72
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()) cnt = 0 for i in range(1, N + 1): cnt += 1 print(cnt)
s488850627
Accepted
17
2,940
72
N = int(input()) cnt = 0 for i in range(1, N + 1): cnt += i print(cnt)
s849403466
p03644
u608088992
2,000
262,144
Wrong Answer
17
2,940
179
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N = int(input()) maxdiv = 0 for i in range(1, N + 1): d = i count = 0 while d & 1 == 0: d >>= 1 count += 1 maxdiv = max(maxdiv, count) print(count)
s166685822
Accepted
17
2,940
216
N = int(input()) maxdiv = 0 ans = 1 for i in range(1, N + 1): d = i count = 0 while d % 2 == 0: d //= 2 count += 1 if count > maxdiv: ans = i maxdiv = count print(ans)
s749247005
p02972
u227085629
2,000
1,048,576
Wrong Answer
719
14,904
306
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
n = int(input()) a = list(map(int,input().split())) box = [0]*n for i in range(n,0,-1): k = a[i-1] c = 0 for j in range(1,n//i+1): c += box[i*j-1] if c%2 != k: box[i-1] = 1 ans = [] w = 0 for m in range(n): if box[m] == 1: w += 1 ans.append(str(i+1)) print(w) print(' '.join(ans))
s992757039
Accepted
766
17,212
306
n = int(input()) a = list(map(int,input().split())) box = [0]*n for i in range(n,0,-1): k = a[i-1] c = 0 for j in range(1,n//i+1): c += box[i*j-1] if c%2 != k: box[i-1] = 1 ans = [] w = 0 for m in range(n): if box[m] == 1: w += 1 ans.append(str(m+1)) print(w) print(' '.join(ans))
s505309028
p03469
u408375121
2,000
262,144
Wrong Answer
17
2,940
30
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
S = input() t = '2018' + S[4:]
s711663037
Accepted
17
2,940
39
S = input() t = '2018' + S[4:] print(t)
s916167210
p03625
u142415823
2,000
262,144
Wrong Answer
111
18,600
382
We have N sticks with negligible thickness. The length of the i-th stick is A_i. Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
import collections N = int(input()) A = [int(i) for i in input().split()] stick_num = collections.Counter(A) flag = True ans = 0 for i in sorted(stick_num, reverse=True): if stick_num[i] % 4 == 0: ans = i * i elif stick_num[i] % 2 >= 0: if flag: a = i flag = False else: ans = a * i break print(ans)
s536599783
Accepted
89
14,252
382
N = int(input()) A = [int(i) for i in input().split()] A.sort(reverse=True) flag_h = True flag_v = True h, v = 0, 0 for i in A: if flag_h: if h == i: flag_h = False else: h = i elif flag_v: if v == i: flag_v = False else: v = i if not (flag_v and flag_h): print(h * v) else: print(0)
s194125535
p03377
u456878170
2,000
262,144
Wrong Answer
18
2,940
106
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = list(map(int, input().split())) if a + b >= x and a <= x: print('Yes') else: print('No')
s163756861
Accepted
18
2,940
106
a, b, x = list(map(int, input().split())) if a + b >= x and a <= x: print('YES') else: print('NO')
s165807505
p03547
u209918867
2,000
262,144
Wrong Answer
17
2,940
102
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`. When X and Y are seen as hexadecimal numbers, which is larger?
x=input().split() if sorted(x) == x: s='=' elif sorted(x)[0] == x[0]: s='<' else: s='>' print(s)
s272083248
Accepted
17
2,940
102
s=list(input().split()) ss=sorted(s) if s[0]==s[1]: r='=' elif s==ss: r='<' else: r='>' print(r)
s550507848
p03729
u302292660
2,000
262,144
Wrong Answer
17
2,940
90
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a,b,c = input().split() if a[-1]==b[0] and b[-1]==c[0]: print("Yes") else: print("No")
s048391377
Accepted
17
2,940
90
a,b,c = input().split() if a[-1]==b[0] and b[-1]==c[0]: print("YES") else: print("NO")
s584685316
p03377
u872793589
2,000
262,144
Wrong Answer
17
2,940
173
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.
def main(): A,B,X = map(int, input().split(" ")) if A > X or A + B < X: print("No") else: print("Yes") if __name__ == '__main__': main()
s860465460
Accepted
17
2,940
173
def main(): A,B,X = map(int, input().split(" ")) if A > X or A + B < X: print("NO") else: print("YES") if __name__ == '__main__': main()
s219453045
p02742
u419246138
2,000
1,048,576
Wrong Answer
2,104
3,060
249
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:
num = input().split(" ") ki = 0 gu = 0 sum_kaku = 0 for a in range(int(num[1])): if a % 2 == 0: gu += 1 else: ki += 1 a = 0 while a < int(num[1]): if a % 2 == 0: sum_kaku += ki else: sum_kaku += gu a += 1 print(sum_kaku)
s783712086
Accepted
17
3,060
189
num = input().split(" ") if "1" in num: print(1) else: gu = int(num[1]) // 2 ki = int(num[1]) - int(gu) gu2 = int(num[0]) // 2 ki2 = int(num[0]) - int(gu2) print(gu * gu2 + ki * ki2)
s002526356
p02741
u572373398
2,000
1,048,576
Wrong Answer
18
2,940
23
Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
print(int(input()) - 1)
s342697032
Accepted
17
3,060
130
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(a[int(input()) - 1])
s242500068
p03729
u168416324
2,000
262,144
Wrong Answer
26
9,108
90
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a,b,c=input().split() if a[:-1]==b[0] and b[:-1]==c[0]: print("YES") else: print("NO")
s372072794
Accepted
29
8,916
88
a,b,c=input().split() if a[-1]==b[0] and b[-1]==c[0]: print("YES") else: print("NO")
s970667192
p03385
u538632589
2,000
262,144
Wrong Answer
17
2,940
102
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
s = input() if set([s[0], s[1], s[2]]) == set(['a', 'b', 'c']): print('YES') else: print('NO')
s925327249
Accepted
17
3,064
102
s = input() if set([s[0], s[1], s[2]]) == set(['a', 'b', 'c']): print('Yes') else: print('No')
s738544814
p02613
u749491107
2,000
1,048,576
Wrong Answer
146
16,264
377
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.
row = int(input()) s = [input() for i in range(row)] ac = 0 wa = 0 tle = 0 re = 0 for j in s: if j == "AC": ac += 1 elif j == "WA": wa += 1 elif j == "TLE": tle += 1 elif j == "re": re += 1 ac = str(ac) wa = str(wa) tle = str(tle) re = str(re) print("AC × " + ac) print("WA × " + wa) print("TLE × " + tle) print("RE × " + re)
s802249266
Accepted
159
16,276
373
row = int(input()) s = [input() for i in range(row)] ac = 0 wa = 0 tle = 0 re = 0 for j in s: if j == "AC": ac += 1 elif j == "WA": wa += 1 elif j == "TLE": tle += 1 elif j == "RE": re += 1 ac = str(ac) wa = str(wa) tle = str(tle) re = str(re) print("AC x " + ac) print("WA x " + wa) print("TLE x " + tle) print("RE x " + re)
s258988009
p03477
u464912173
2,000
262,144
Wrong Answer
17
2,940
108
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a, b, c, d = map(int, input().split()) print('Right' if a+b > c+d else 'left' if a+b < c+d else 'Balanced')
s332195871
Accepted
18
2,940
108
a, b, c, d = map(int, input().split()) print('Right' if a+b < c+d else 'Left' if a+b > c+d else 'Balanced')
s737040926
p02534
u934119021
2,000
1,048,576
Wrong Answer
27
9,016
41
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`.
k = int(input()) ans = 'ACL' * k print(k)
s182580777
Accepted
23
9,096
43
k = int(input()) ans = 'ACL' * k print(ans)
s114529774
p00017
u187606290
1,000
131,072
Wrong Answer
40
7,948
555
In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 1, 'a' would be replaced by 'b', 'b' would become 'c', 'y' would become 'z', 'z' would become 'a', and so on. In that case, a text: this is a pen is would become: uijt jt b qfo Write a program which reads a text encrypted by Caesar Chipher and prints the corresponding decoded text. The number of shift is secret and it depends on datasets, but you can assume that the decoded text includes any of the following words: "the", "this", or "that".
import fileinput import string alphabetArray = list(string.ascii_lowercase) for data in fileinput.input(): for n in range(-25, 26): replacedStr = data for i in range(0, 26): if n > 0: replacedStr = replacedStr.replace(alphabetArray[i], alphabetArray[(i + n) % 26]) else: replacedStr = replacedStr.replace(alphabetArray[i], alphabetArray[i + n]) if "this" in replacedStr or "the" in replacedStr or "that" in replacedStr: print(replacedStr) break
s755092374
Accepted
40
7,892
900
import fileinput import string alphabetArray = list(string.ascii_lowercase) for data in fileinput.input(): for n in range(-26, 27): replacedStrAry = list(data.replace('\n', '').replace('\r', '')) for index in range(0, len(replacedStrAry)): if not replacedStrAry[index] in alphabetArray: continue if n >= 0: replacedStrAry[index] = alphabetArray[(alphabetArray.index(replacedStrAry[index]) + n) % 26] else: replacedStrAry[index] = replacedStrAry[index] = alphabetArray[alphabetArray.index(replacedStrAry[index]) + n] replacedStr = "".join(replacedStrAry) replacedStrSplitedBySpace = replacedStr.split(' ') if "the" in replacedStrSplitedBySpace or "this" in replacedStrSplitedBySpace or "that" in replacedStrSplitedBySpace: print(replacedStr) break
s236039123
p03214
u534308356
2,525
1,048,576
Wrong Answer
17
2,940
217
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
N = int(input()) data = list(map(int, input().split())) ave = sum(data) / len(data) thumbnail_num = 1000 for i in range(len(data)): if abs(data[i] - ave) < thumbnail_num: thumbnail_num = i print(thumbnail_num)
s217798955
Accepted
18
3,060
190
N = int(input()) data = list(map(int, input().split())) ave = sum(data) / len(data) ans = 0 for i in range(len(data)): if abs(data[i] - ave) < abs(data[ans] - ave): ans = i print(ans)
s025424943
p02613
u970198631
2,000
1,048,576
Wrong Answer
148
16,108
273
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()) list1=[] for i in range(N): a = input() list1.append(a) a = list1.count('AC') b = list1.count('WA') c = list1.count('TLE') d = list1.count('RE') list2 = [a,b,c,d] print('AC x'+str(a)) print('WA x'+str(b)) print('TLE x'+str(c)) print('RE x'+str(d))
s770562688
Accepted
149
16,248
254
A = int(input()) list1 = [] for i in range(A): a = input() list1.append(a) b =list1.count('AC') c =list1.count('TLE') d =list1.count('RE') e =list1.count('WA') print('AC x '+ str(b)) print('WA x '+ str(e)) print('TLE x '+str(c)) print('RE x '+str(d))
s779949225
p02612
u850512471
2,000
1,048,576
Wrong Answer
30
9,080
55
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
price = int(input()) bochi = price % 1000 print(bochi)
s618083554
Accepted
25
9,116
173
price = int(input()) sen = 1000 senCnt = int(price / 1000) num = 0 if price % sen != 0: senCnt = senCnt + 1 sen = sen * senCnt num = sen - price print(num)
s810680163
p03168
u945181840
2,000
1,048,576
Wrong Answer
233
47,664
368
Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i. Taro has tossed all the N coins. Find the probability of having more heads than tails.
import numpy as np N = int(input()) p = np.array([0.0] + list(map(float, input().split()))) dp = np.zeros((N + 1, N + 1), np.float32) dp[0, 0] = 1 dp[:, 0] = np.cumprod(1 - p).T for i in range(1, N + 1): dp[i][1:] = dp[i - 1][:-1] * p[i] + dp[i - 1][1:] * (1 - p[i]) print(dp[-1][N // 2 + 1:].sum())
s304771764
Accepted
248
82,736
370
import numpy as np N = int(input()) p = np.array([0.0] + list(map(float, input().split()))) dp = np.zeros((N + 1, N + 1), np.float64) dp[0, 0] = 1 dp[:, 0] = np.cumprod(1 - p).T for i in range(1, N + 1): dp[i][1:] = dp[i - 1][:-1] * p[i] + dp[i - 1][1:] * (1 - p[i]) print(dp[-1][(N + 1) // 2:].sum())
s899102627
p02678
u932868243
2,000
1,048,576
Wrong Answer
2,207
49,956
249
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
n,m=map(int,input().split()) ab=[list(map(int,input().split())) for i in range(m)] l=[[]]*n for a,b in ab: l[a-1].append(b) l[b-1].append(a) ans=[[0]]*(n) for j in range(n): for lll in l[j]: ans[lll-1]=j+1 for t in range(1,n): print(ans)
s242081611
Accepted
1,388
38,120
429
n,m=map(int,input().split()) l=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) l[a-1].append(b-1) l[b-1].append(a-1) queue=[0] visit=[0]*n visit[0]=1 ans=[0]*n while len(queue)>0: now=queue.pop(0) for p in l[now]: if visit[p]==0: visit[p]+=1 queue.append(p) ans[p]=now+1 k=ans[1:] if not all(kk!=0 for kk in k): print('No') exit() print('Yes') for kk in k: print(kk)
s948936022
p03338
u076764813
2,000
1,048,576
Wrong Answer
17
2,940
147
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
n=int(input()) s=list(input()) num=0 for i in range(n): x=set(s[:n]) y=set(s[n:]) if len(x&y)>num: num=len(x&y) print(num)
s428817412
Accepted
18
2,940
147
n=int(input()) s=list(input()) num=0 for i in range(n): x=set(s[:i]) y=set(s[i:]) if len(x&y)>num: num=len(x&y) print(num)
s142071421
p03959
u579299997
2,000
262,144
Wrong Answer
23
3,064
74
Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N. Mr. Takahashi traversed the range from the west and Mr. Aoki from the east. The height of Mt. i is h_i, but they have forgotten the value of each h_i. Instead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. i (including Mt. i). Mr. Takahashi's record is T_i and Mr. Aoki's record is A_i. We know that the height of each mountain h_i is a positive integer. Compute the number of the possible sequences of the mountains' heights, modulo 10^9 + 7. Note that the records may be incorrect and thus there may be no possible sequence of the mountains' heights. In such a case, output 0.
from itertools import groupby print(sum(1 for _ in groupby(input())) - 1)
s718065882
Accepted
159
19,012
1,065
N = int(input()) T = list(map(int, input().split())) A = list(map(int, input().split())) R = [] M = 1000000007 def main(): global R global A p = -1 for t in T: if t > p: # new R.append(t) p = t else: R.append(-t) R = list(reversed(R)) A = list(reversed(A)) p = -1 for i, t in enumerate(A): r = R[i] if r < 0: max_h = -r if t > p: # new p = t if t <= max_h: R[i] = t else: return 0 else: R[i] = -min(max_h, t) else: if t > p: # new p = t if t != r: return 0 else: if r > t: return 0 answer = 1 for r in R: if r > 0: answer *= 1 else: max_h = -r answer *= max_h answer %= M return answer print(main())
s851981588
p04029
u364741711
2,000
262,144
Wrong Answer
18
2,940
31
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)
s385461886
Accepted
17
2,940
36
n=int(input()) print(int(n*(n+1)/2))
s671145511
p04011
u430223993
2,000
262,144
Wrong Answer
18
2,940
125
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()) if n <= k: print(n*x) else: print(n*x + (k-n)*y)
s445193069
Accepted
17
3,064
125
n = int(input()) k = int(input()) x = int(input()) y = int(input()) if n <= k: print(n*x) else: print(k*x + (n-k)*y)
s628572240
p02612
u528484796
2,000
1,048,576
Wrong Answer
26
9,140
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n=int(input()) k=n%1000 print(k)
s423274857
Accepted
31
9,152
68
from math import * n=int(input()) k=n/1000 p=ceil(k)*1000 print(p-n)
s935387458
p02409
u879471116
1,000
131,072
Wrong Answer
20
5,600
476
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
A = [] for _ in range(4): floor = [] for _ in range(3): room = [] for _ in range(10): room.append(0) floor.append(room) A.append(floor) n = int(input()) for _ in range(n): b, f, r, v = map(int, input().split()) A[b-1][f-1][r-1] += v for b in A: for f in b: f = list(map(str, f)) print(' '.join(f)) print('#'*20)
s226781565
Accepted
20
5,600
266
A = [] for _ in range(12): A.append([0]*10) n = int(input()) for _ in range(n): b, f, r, v = map(int, input().split()) A[3*b-(3-f)-1][r-1] += v for i in range(12): print(' ', end='') print(' '.join(map(str, A[i]))) if i in [2, 5, 8]: print('#'*20)
s711526601
p03474
u266874640
2,000
262,144
Wrong Answer
17
3,064
464
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.
A,B = map(int,input().split()) S = list(input()) c = 0 if len(S) != A+B+1: print("No") else: for i in range(A): if S[i] == "-": print("No") break else: c += 1 if c == 1 : if S[A+1] != "-": print("No") c += 1 else: for j in range(A+1,A+B+2): if S[j] == "-": print("No") c += 1 break if c == 1: print("Yes")
s536904360
Accepted
20
3,188
462
A,B = map(int,input().split()) S = list(input()) c = 0 if len(S) != A+B+1: print("No") else: for i in range(A): if S[i] == "-": print("No") break else: c += 1 if c == A: if S[A] != "-": print("No") c += 1 else: for j in range(A+1,A+B+1): if S[j] == "-": print("No") c += 1 break if c == A: print("Yes")
s927129706
p00003
u036236649
1,000
131,072
Wrong Answer
30
7,572
186
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
import sys input() for line in sys.stdin: a, b, c = map(int, line.split()) d = (a + b + c) / 2 if(a > d or b > d or c > d): print("NO") else: print("YES")
s117988567
Accepted
40
7,616
225
N = int(input()) for i in range(N): a, b, c = map(int, input().split()) if(a > c): a, c = c, a if(b > c): b, c = c, b if(c**2 == a**2 + b**2): print("YES") else: print("NO")
s738902447
p03495
u142415823
2,000
262,144
Wrong Answer
189
32,540
654
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
import collections def calc(A, K): dist = {} tmp = collections.Counter(A) type_ = len(tmp) if type_ <= K: return 0 for a, count in tmp.items(): if count not in dist.keys(): dist[count] = [a] else: dist[count].append(a) rewrite = 0 print(dist) for i, c in enumerate(sorted(dist.keys()), 1): for _ in dist[c]: rewrite += c if i == type_ - K: return rewrite def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) ans = calc(A, K) print(ans) if __name__ == "__main__": main()
s927464753
Accepted
138
20,184
179
N, K = map(int, input().split()) cnt = [0 for _ in range(N)] for i in map(int, input().split()): cnt[i-1] += 1 ans = 0 for i in sorted(cnt)[:N - K]: ans += i print(ans)
s861945184
p02601
u119015607
2,000
1,048,576
Wrong Answer
28
9,192
234
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
A,B, C= list(map(int,input().split())) K = int(input()) for i in range((K)): if(B>C): C=C*2 print(A,B,C) elif(A>B): B=B*2 print(A,B,C) if (C>B >A): print('Yes') else: print('No')
s859477171
Accepted
25
9,044
227
A,B, C= list(map(int,input().split())) K = int(input()) for i in range((K)): if(A>=B): B=B*2 elif(B>=C): C=C*2 else: break if (C>B >A): print('Yes') else: print('No')
s954208814
p03228
u223904637
2,000
1,048,576
Wrong Answer
18
2,940
117
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()) for i in range(k): a-=a%2 b-=b%2 tmp=a//2 a=b//2 b=tmp print(a,b)
s505499809
Accepted
17
2,940
178
a,b,k=map(int,input().split()) for i in range(k): if i%2==0: a-=a%2 b+=a//2 a=a//2 else: b-=b%2 a+=b//2 b=b//2 print(a,b)
s195873281
p03388
u439542873
2,000
262,144
Wrong Answer
18
3,064
482
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
from math import sqrt q = int(input()) query = [tuple(map(int, input().split())) for _ in range(q)] def sqrtfloor(x): s = int(sqrt(x)) if s ** 2 == x: s -= 1 return s def solve(a, b): a, b = min(a, b), max(a, b) if a == b or a + 1 == b: return 2 * a - 1 else: s = sqrtfloor(a * b) if s * (s + 1) < a * b: return 2 * s - 1 else: return 2 * s - 2 for a, b in query: print(solve(a, b))
s049201298
Accepted
18
3,064
482
from math import sqrt q = int(input()) query = [tuple(map(int, input().split())) for _ in range(q)] def sqrtfloor(x): s = int(sqrt(x)) if s ** 2 == x: s -= 1 return s def solve(a, b): a, b = min(a, b), max(a, b) if a == b or a + 1 == b: return 2 * a - 2 else: s = sqrtfloor(a * b) if s * (s + 1) < a * b: return 2 * s - 1 else: return 2 * s - 2 for a, b in query: print(solve(a, b))
s720207522
p00003
u841567836
1,000
131,072
Wrong Answer
40
5,612
351
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
def judge(lists): lists.sort() if lists[0] ** 2 + lists[1] ** 2 - lists[2] ** 2: return False else: return True def run(): N = int(input()) for _ in range(N): if judge([int(x) for x in input().split()]): print("Yes") else: print("NO") if __name__ == '__main__': run()
s088669244
Accepted
40
5,612
351
def judge(lists): lists.sort() if lists[0] ** 2 + lists[1] ** 2 - lists[2] ** 2: return False else: return True def run(): N = int(input()) for _ in range(N): if judge([int(x) for x in input().split()]): print("YES") else: print("NO") if __name__ == '__main__': run()
s873907373
p02406
u539789745
1,000
131,072
Wrong Answer
20
5,592
147
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
def main(): n = int(input()) for i in range(3, n + 1, 3): print("", i, end="") print("") if __name__ == "__main__": main()
s510899902
Accepted
20
6,176
401
def main(): """ n=30 3 6 9 12 13 15 18 21 23 24 27 30 """ n = int(input()) for i in range(1, n + 1): x = i if x % 3 == 0: print("", i, end="") continue while x > 0: if x % 10 == 3: print("", i, end="") break x //= 10 print("") if __name__ == "__main__": main()
s632719924
p03455
u291628833
2,000
262,144
Wrong Answer
17
2,940
20
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
s = input() print(s)
s076235911
Accepted
17
2,940
82
a,b = map(int,input().split()) if a*b%2 == 0: print("Even") else: print("Odd")
s948319094
p02694
u143051858
2,000
1,048,576
Wrong Answer
25
9,248
111
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x=int(input()) num=100 cnt=0 while num < x: num*=1.01 num=int(num) print(num) cnt+=1 print(cnt)
s318232138
Accepted
21
9,124
96
x=int(input()) num=100 cnt=0 while num < x: num*=1.01 num=int(num) cnt+=1 print(cnt)
s971698498
p02742
u962309487
2,000
1,048,576
Wrong Answer
17
2,940
76
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:
import math h, w = map(int, input().split()) ans = math.ceil(h*w) print(ans)
s270070414
Accepted
18
2,940
122
import math h, w = map(int, input().split()) if h == 1 or w == 1: ans = 1 else: ans = math.ceil(h*w/2) print(ans)
s087135251
p03370
u076543276
2,000
262,144
Wrong Answer
41
3,064
199
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
N, X = [int(i) for i in input().split()] m = [int(input()) for i in range(N)] con = 0 for i in m: X -= i m.sort() print(X) while X > m[0]: X -= m[0] con+=1 print(len(m)+con)
s073801404
Accepted
40
3,060
193
N, X = [int(i) for i in input().split()] m = [int(input()) for i in range(N)] con = 0 for i in m: X -= i m.sort() while X >= m[0]: X -= m[0] con+=1 print(len(m)+con)
s184496523
p04030
u223133214
2,000
262,144
Wrong Answer
17
2,940
211
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
s=list(input()) print(s) ans='' for a in s: if ans=='' and a=='B': continue elif a=='B': ans = ans.rstrip(ans[-1]) elif a=='1': ans+='1' else: ans+='0' print(ans)
s658698767
Accepted
20
2,940
215
s=list(input()) ans=[] for a in s: if len(ans)==0 and a=='B': continue elif a=='B': del ans[-1] elif a=='1': ans.append('1') else: ans.append('0') print(''.join(ans))
s940321603
p03599
u052332717
3,000
262,144
Wrong Answer
61
3,188
450
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
a,b,c,d,e,f = map(int,input().split()) w = set() for x in range(0,f+1,100*a): for y in range(0,f+1-x,100*b): w.add(x+y) s = set() for x in range(0,f+1,c): for y in range(0,f+1-x,d): s.add(x+y) ans = 0 sugerwater = 0 suger = 0 for x in w: for y in s: if 0<x+y<=f and 100*y/(x+y) <= e: if ans < y/(x+y): ans = y/(x+y) sugerwater = x+y suger = y print(x,y)
s946438014
Accepted
63
3,188
461
a,b,c,d,e,f = map(int,input().split()) w = set() for x in range(0,f+1,100*a): for y in range(0,f+1-x,100*b): w.add(x+y) s = set() for x in range(0,f+1,c): for y in range(0,f+1-x,d): s.add(x+y) ans = -1 sugerwater = 0 suger = 0 for x in w: for y in s: if 0<x+y<=f and y <= x*e/100: if ans < y/(x+y): ans = y/(x+y) sugerwater = x+y suger = y print(sugerwater,suger)
s728872674
p03836
u780698286
2,000
262,144
Wrong Answer
26
9,088
167
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) print("U"*(ty-sy) + "R"*(tx-sx+1) + "D"*(ty-sx+1) + "U" + "L" + "U"*(ty-sy+1) + "R"*(tx-sx+1) + "D"*(ty-sy+1) + "L"*(tx-sx))
s503953983
Accepted
25
9,204
228
xy = list(map(int, input().split())) print("U"*(xy[3]-xy[1]) + "R"*(xy[2]-xy[0]) + "D"*(xy[3]-xy[1]) + "L"*(xy[2]-xy[0]+1) + "U"*(xy[3]-xy[1]+1) + "R"*(xy[2]-xy[0]+1) + "D" + "R"+ "D"*(xy[3]-xy[1]+1) + "L"*(xy[2]-xy[0]+1) + "U")
s114058636
p03795
u886902015
2,000
262,144
Wrong Answer
26
9,096
32
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n=int(input()) print(800*n-n%15)
s342632619
Accepted
24
9,128
39
n=int(input()) print(800*n-200*(n//15))
s670983134
p03997
u983918956
2,000
262,144
Wrong Answer
18
3,316
77
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) ans = (a+b) * h print(ans)
s177801054
Accepted
18
2,940
78
a = int(input()) b = int(input()) h = int(input()) s = (a+b) * h // 2 print(s)
s699206819
p03730
u766407523
2,000
262,144
Wrong Answer
17
2,940
119
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A, B, C = map(int, input().split()) for i in range(1, B+1): if A*i%B==C: print("YES") else: print("NO")
s263260932
Accepted
17
2,940
134
A, B, C = map(int, input().split()) for i in range(1, B+1): if A*i%B==C: print("YES") break else: print("NO")
s366452366
p03759
u786020649
2,000
262,144
Wrong Answer
27
9,084
79
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c=map(int,input().split()) if b-c==b-a: print('YES') else: print('NO')
s460121217
Accepted
27
9,008
80
a,b,c=map(int,input().split()) if b-c==a-b: print('YES') else: print('NO')
s089423647
p02612
u171255092
2,000
1,048,576
Wrong Answer
31
9,144
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n % 1000)
s801821270
Accepted
28
9,176
41
n = int(input()) print((1000 - n) % 1000)
s325381229
p03759
u931489673
2,000
262,144
Wrong Answer
17
2,940
82
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c=map(int,input().split()) if (a-b)==(c-b): print("YES") else: print("NO")
s938914536
Accepted
17
2,940
83
a,b,c=map(int,input().split()) if (b-a)==(c-b): print("YES") else: print("NO")
s832474773
p02606
u529737989
2,000
1,048,576
Wrong Answer
29
9,180
67
How many multiples of d are there among the integers between L and R (inclusive)?
L,R,N = map(int,input().split()) Ln = L//N Rn = R//N print(Rn-Ln+1)
s534354038
Accepted
31
9,152
69
L,R,N = map(int,input().split()) Ln = (L-1)//N Rn = R//N print(Rn-Ln)
s038180152
p03836
u100641536
2,000
262,144
Wrong Answer
29
9,164
154
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx,sy,tx,ty = map(int,input().split()) dx=tx-sx dy=ty-sy s="U"*dy+"R"*dx+"D"*dy+"L"*(dx+1)+"U"*(dy+1)+"R"*(dx+1)+"D"+"R"+"D"*(dy+1)+"L"*(dx+1) print(s)
s281698814
Accepted
28
9,156
158
sx,sy,tx,ty = map(int,input().split()) dx=tx-sx dy=ty-sy s="U"*dy+"R"*dx+"D"*dy+"L"*(dx+1)+"U"*(dy+1)+"R"*(dx+1)+"D"+"R"+"D"*(dy+1)+"L"*(dx+1)+"U" print(s)
s483950038
p01304
u798803522
8,000
131,072
Wrong Answer
30
7,812
1,360
平安京は、道が格子状になっている町として知られている。 平安京に住んでいるねこのホクサイは、パトロールのために毎日自宅から町はずれの秘密の場所まで行かなければならない。しかし、毎日同じ道を通るのは飽きるし、後を付けられる危険もあるので、ホクサイはできるだけ毎日異なる経路を使いたい。その一方で、ホクサイは面倒臭がりなので、目的地から遠ざかるような道は通りたくない。 平安京のあちこちの道にはマタタビが落ちていて、ホクサイはマタタビが落ちている道を通ることができない。そのような道を通るとめろめろになってしまうからである。幸いなことに、交差点にはマタタビは落ちていない。 ホクサイは、自宅から秘密の場所までの可能な経路の数を知りたい。ここで、ホクサイの自宅は (0, 0) にあり、秘密の場所は(gx, gy)にある。道は x = i (i は整数), y = j (j は整数) に格子状に敷かれている。
trial = int(input()) for t in range(trial): targ = [int(n) for n in input().split(' ')] root = [[0 for n in range(targ[0] + 1)] for m in range(targ[1] + 1)] matanum = int(input()) for m in range(matanum): matax,matay,secx,secy = (int(n) for n in input().split(' ')) if matax == secx: root[max(matay,secy)][matax] = 'y' else: root[matay][max(secx,matax)] = 'x' root[0][0] = 1 for yaxis in range(targ[1] + 1): for xaxis in range(targ[0] + 1): if xaxis == 0: if root[yaxis][xaxis] == 'y': root[yaxis][xaxis] = 0 else: root[yaxis][xaxis] = 1 elif yaxis == 0: if root[yaxis][xaxis] == 'x': root[yaxis][xaxis] = 0 else: root[yaxis][xaxis] = root[yaxis][xaxis-1] else: if root[yaxis][xaxis] == 'y': root[yaxis][xaxis] = root[yaxis][xaxis - 1] elif root[yaxis][xaxis] == 'x': root[yaxis][xaxis] = root[yaxis - 1][xaxis] else: root[yaxis][xaxis] = root[yaxis - 1][xaxis] + root[yaxis][xaxis - 1] if root[targ[1]][targ[0]] == 0: print("Miserable Hokusai!") else: print(root[targ[1]][targ[0]])
s415333471
Accepted
40
7,752
1,884
trial = int(input()) for t in range(trial): targ = [int(n) for n in input().split(' ')] root = [[0 for n in range(targ[0] + 1)] for m in range(targ[1] + 1)] matanum = int(input()) for m in range(matanum): matax,matay,secx,secy = (int(n) for n in input().split(' ')) if matax == secx: if root[max(matay,secy)][matax] == 'x': root[max(matay,secy)][matax] = 'xy' else: root[max(matay,secy)][matax] = 'y' else: if root[matay][max(matax,secx)] == 'y': root[matay][max(matax,secx)] = 'xy' else: root[matay][max(matax,secx)] = 'x' for yaxis in range(targ[1] + 1): for xaxis in range(targ[0] + 1): if xaxis == 0: if root[yaxis][xaxis] == 'y' or root[yaxis][xaxis] == 'xy': root[yaxis][xaxis] = 0 else: if yaxis == 0: root[0][0] = 1 else: root[yaxis][xaxis] = root[yaxis- 1][xaxis] elif yaxis == 0: if root[yaxis][xaxis] == 'x' or root[yaxis][xaxis] == 'xy': root[yaxis][xaxis] = 0 else: root[yaxis][xaxis] = root[yaxis][xaxis-1] else: if root[yaxis][xaxis] == 'xy': root[yaxis][xaxis] = 0 elif root[yaxis][xaxis] == 'y': root[yaxis][xaxis] = root[yaxis][xaxis - 1] elif root[yaxis][xaxis] == 'x': root[yaxis][xaxis] = root[yaxis - 1][xaxis] else: root[yaxis][xaxis] = root[yaxis - 1][xaxis] + root[yaxis][xaxis - 1] if root[targ[1]][targ[0]] == 0: print("Miserable Hokusai!") else: print(root[targ[1]][targ[0]])
s150230032
p00019
u011621222
1,000
131,072
Wrong Answer
20
7,480
115
Write a program which reads an integer n and prints the factorial of n. You can assume that n ≤ 20\.
factorial= 1 number= int(input("Enter a number:")) for r in range (1,number+1): factorial*=r print(factorial)
s758632174
Accepted
20
5,560
136
def fac(n): ans=1 for i in range(n+1): if i is not 0: ans*=i return ans n = eval(input()) print(fac(n))
s580349496
p03447
u947327691
2,000
262,144
Wrong Answer
17
3,064
58
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
x=int(input()) a=int(input()) b=int(input()) print(x-a-b)
s745207444
Accepted
17
2,940
60
x=int(input()) a=int(input()) b=int(input()) print((x-a)%b)
s068583403
p03005
u671869417
2,000
1,048,576
Wrong Answer
17
2,940
114
Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?
N, K = input().split() N, K = int(N), int(K) if K==1: print(0) if K==2: print(N-1) else: print((N-(K-1))-1)
s580574146
Accepted
17
2,940
91
N, K = input().split() N, K = int(N), int(K) if K==1: print(0) else: print((N-(K-1))-1)
s164548910
p04011
u480568292
2,000
262,144
Wrong Answer
18
3,060
172
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()) n_ = int(input()) m = int(input()) m_ = int(input()) count = 0 N = n-n_ for i in range(N): count += m for x in range(n_): count += m_ print(count)
s544951979
Accepted
17
2,940
68
n,k,x,y = (int(input()) for i in [0]*4) print(n*x-(x-y)*max(n-k,0))
s876284303
p03448
u490623664
2,000
262,144
Wrong Answer
52
3,060
186
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a=int(input()) b=int(input()) c=int(input()) x=int(input()) count=0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if x==500*a+100*b+50*c: count+=1 print(count)
s353147281
Accepted
49
3,060
186
a=int(input()) b=int(input()) c=int(input()) x=int(input()) count=0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if x==500*i+100*j+50*k: count+=1 print(count)
s757160623
p00275
u724548524
1,000
131,072
Wrong Answer
20
5,596
324
百人一首の札を使った遊戯の1つに、「坊主めくり」というものがあります。絵札だけを使う簡単な遊戯なので広く楽しまれています。きまりには様々な派生型がありますが、ここで考える坊主めくりはN人の参加者で、以下のようなルールで行います。 * 64枚の「男」、15枚の「坊主」、21枚の「姫」、計100枚の札を使う。 * 絵が見えないように札を裏がえしにしてよく混ぜ、「札山」をつくる。 * 参加者の一人目から順番に1枚ずつ札山の札を引く。N人目の次は、また一人目から繰り返す。 * 引いた札が男なら、引いた人はその札を手に入れる。 * 引いた札が坊主なら、引いた人はその札を含め、持っている札をすべて「場」に出す。 * 引いた札が姫なら、引いた人はその札を含め、場にある札をすべて手に入れる。 * 札山の札がなくなったら終了で、一番多くの札を持っている人の勝ち。 参加者数と札山に積まれた札の順番が与えられたとき、遊戯が終了した時点で各参加者が持っている札数を昇順で並べたものと、場に残っている札数を出力するプログラムを作成してください。
while 1: n = int(input()) if n == 0:break p = [0] * n s = 0 f = input() for i in range(100): if f[i] == "M":p[i % n] += 1 elif f[i] == "S": s += p[i % n] + 1 p[i % n] = 0 else: p[i % n] += s + 1 s = 0 p += [s] print(*p)
s347330727
Accepted
30
5,608
337
while 1: n = int(input()) if n == 0:break p = [0] * n s = 0 f = input() for i in range(100): if f[i] == "M":p[i % n] += 1 elif f[i] == "S": s += p[i % n] + 1 p[i % n] = 0 else: p[i % n] += s + 1 s = 0 p.sort() p += [s] print(*p)
s385016308
p02399
u485986915
1,000
131,072
Wrong Answer
20
5,596
69
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a,b = map(int,input().split()) d = a/b r = a%b f = a/b print(d,r,f)
s778282683
Accepted
20
5,600
86
a,b = map(int,input().split()) d = a//b r = a%b f = a/b print('%s %s %.5f'%(d,r,f))
s686227064
p03962
u367373844
2,000
262,144
Wrong Answer
17
2,940
252
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
candy_bag = list(map(int, input().split())) max_bag_num = max(candy_bag) bag = 0 small_bag_sum = 0 for bag in candy_bag: if bag == max_bag_num: continue else: small_bag_sum += bag if max_bag_num == small_bag_sum: print("Yes") else: print("No")
s410255828
Accepted
17
3,060
211
a,b,c = map(int,input().split()) same_count = 0 if a == b: same_count += 1 if a == c: same_count += 1 if b == c: same_count += 1 if same_count == 0: print(3) elif same_count == 1: print(2) else: print(1)
s059202245
p02612
u189397279
2,000
1,048,576
Wrong Answer
32
9,136
56
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) while N >= 1000: N -= 1000 print(N)
s117013839
Accepted
29
9,156
115
N = int(input()) for i in range(13): if 1000 * i < N and N <= 1000 * (i + 1): print(1000 * (i + 1) - N)
s809856141
p02850
u691018832
2,000
1,048,576
Wrong Answer
530
44,892
928
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(readline()) ab = [list(map(int, readline().split())) for i in range(n - 1)] gragh = [[] for j in range(n + 1)] for a, b in ab: gragh[a].append(b) gragh[b].append(a) root = 1 parent = [0] * (n + 1) stack = [root] order = [] while stack: x = stack.pop() order.append(x) for y in gragh[x]: if y == parent[x]: continue parent[y] = x stack.append(y) color = [-1] * (n + 1) for x in order: ng = color[x] cnt = 1 for y in gragh[x]: if y == parent[x]: continue if cnt == ng: cnt += 1 color[y] = cnt cnt += 1 ans = [] append = ans.append for a, b in ab: if parent[a] == b: append(color[a]) else: append(color[b]) print(max(ans)) print('/n'.join(map(str, ans)))
s933105721
Accepted
412
45,704
826
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import deque n = int(readline()) graph = [[] for _ in range(n + 1)] for i in range(n - 1): a, b = map(int, readline().split()) graph[a].append((b, i)) graph[b].append((a, i)) color = [-1] * (n + 1) color[1] = -2 ans = [0] * (n - 1) def bfs(s): stack = deque([s]) while stack: num = 1 now = stack.pop() for next, idx in graph[now]: if color[next] != -1: continue if color[now] == num: num += 1 color[next] = num ans[idx] = num num += 1 stack.append(next) bfs(1) print(max(ans)) print('\n'.join(map(str, ans)))
s849387707
p03371
u974935538
2,000
262,144
Wrong Answer
122
8,772
318
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A,B,C,X,Y = map(int,input().split()) cnt_A = X cnt_B = Y cnt_C = 0 ans = [] for _ in range(X+Y): if 2*C<=A+B: cnt_C += 2 cnt_A -= 1 cnt_B -= 1 ans.append(cnt_A*A+cnt_B*B+cnt_C*C) if ((cnt_A<0) or (cnt_B<0)) or ((cnt_C==2*X)or(cnt_C ==Y*22)): break ans.sort() print(ans[0])
s955515432
Accepted
113
3,060
171
a, b, c, x, y = map(int, input().split()) ans = 10000000007 for i in range(10**5 + 1): ans = min(ans, i * (2 * c) + max(0, x - i) * a + max(0, y - i) * b) print(ans)
s751448900
p00046
u546285759
1,000
131,072
Wrong Answer
30
7,400
111
今まで登ったことのある山の標高を記録したデータがあります。このデータを読み込んで、一番高い山と一番低い山の標高差を出力するプログラムを作成してください。
import sys ms = [] try: for v in sys.stdin: ms.append(float(v)) except: print(max(ms)-min(ms))
s697695862
Accepted
20
7,332
207
maxv, minv = 0, 10**6 while True: try: height = float(input()) except: break maxv = height if maxv < height else maxv minv = height if minv > height else minv print(maxv-minv)
s178940969
p03377
u413165887
2,000
262,144
Wrong Answer
17
2,940
93
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = map(int, input().split()) if x<=a or a+b<=x: print("YES") else: print("NO")
s329604838
Accepted
18
2,940
91
a, b, x = map(int, input().split()) if a+b<x or a>x: print("NO") else: print("YES")
s084155396
p03796
u026788530
2,000
262,144
Wrong Answer
45
2,940
70
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
n=int(input()) ans=1 for i in range(n): ans*=(i+1) ans%=1000000007
s584837501
Accepted
43
2,940
84
n=int(input()) ans=1 for i in range(n): ans*=(i+1) ans%=1000000007 print(ans)
s065974721
p03455
u384935968
2,000
262,144
Wrong Answer
24
9,008
84
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=map(int,input().split()) if (a*b) % 2 == 0: print('Odd') else: print('Even')
s891315227
Accepted
21
8,984
83
a,b=map(int,input().split()) if (a*b) % 2 == 0: print('Even') else: print('Odd')
s108892461
p03739
u223663729
2,000
262,144
Wrong Answer
213
14,084
335
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.
n, *A = map(int, open(0).read().split()) def sgn(n): return 0 if n==0 else 1 if n>0 else -1 C = [0, 0] S = [1, -1] for a in A: for i, s in enumerate(S): sgn_sum = sgn(s) if sgn(s+a) != sgn_sum: S[i] += a else: C[i] += abs(s+a+sgn_sum) S[i] = -sgn_sum print(min(C))
s481400204
Accepted
213
14,084
398
n, *A = map(int, open(0).read().split()) def sgn(n): return 0 if n==0 else 1 if n>0 else -1 a = A[0] C = [0 if a>0 else -a+1, 0 if a<0 else a+1] S = [max(1, a), min(-1, a)] for a in A[1:]: for i, s in enumerate(S): sgn_sum = sgn(s) if sgn(s+a) == -sgn_sum: S[i] += a else: C[i] += abs(s+a+sgn_sum) S[i] = -sgn_sum print(min(C))
s715259121
p04029
u479788474
2,000
262,144
Wrong Answer
26
8,944
116
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()) # 1 <= N <= 100 total = N * ( N + 1)/ 2 print(total)
s000983576
Accepted
26
9,072
118
N = int(input()) # 1 <= N <= 100 total = N * ( N + 1) // 2 print(total)
s642011604
p03943
u478888559
2,000
262,144
Wrong Answer
17
2,940
227
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a, b, c = map(int, input().split()) candies = [] candies.append(a) candies.append(b) candies.append(c) max_candy = max(candies) candies.remove(max_candy) if sum(candies) == max_candy: print("YES") else: print("NO")
s817300677
Accepted
17
2,940
227
a, b, c = map(int, input().split()) candies = [] candies.append(a) candies.append(b) candies.append(c) max_candy = max(candies) candies.remove(max_candy) if sum(candies) == max_candy: print("Yes") else: print("No")
s991494708
p03730
u212328220
2,000
262,144
Wrong Answer
2,297
64,220
274
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
import itertools A, B, C = map(int,input().split()) lst = [] for i in range(1,100): lst.append(A * i) for i in range(1,5): for v in itertools.combinations(lst,i): print(v) if sum(v) % B == C: print('YES') exit() print('NO')
s857588609
Accepted
31
9,024
257
import itertools A, B, C = map(int,input().split()) lst = [] for i in range(1,100): lst.append(A * i) for i in range(1,3): for v in itertools.combinations(lst,i): if sum(v) % B == C: print('YES') exit() print('NO')
s594578966
p03418
u466331465
2,000
262,144
Wrong Answer
250
4,456
216
Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
N,K = [int(x) for x in input().split()] ans =0 for i in range(K+1,N+1): print((N//i)*(i-K),N%i+1-K) ans += (N//i)*(i-K) if N%i!=0 and K!=0: ans +=(N%i+1-K) elif N%i!=0 and K==0: ans +=(N%i) print(ans)
s992130624
Accepted
96
3,188
224
N,K = [int(x) for x in input().split()] ans =0 for i in range(K+1,N+1): ans += (N//i)*(i-K) if N%i!=0 and K!=0: ans +=max((N%i+1-K),0) elif N%i!=0 and K==0: ans +=(N%i) print(ans)
s234409705
p03575
u133377913
2,000
262,144
Wrong Answer
170
12,596
1,149
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
# -*- coding: utf-8 -*- import numpy as np N, M = map(int, input().split()) L = [list(map(int, input().split())) for _ in range(M)] adjacent = np.zeros((N, N)) for l in L: adjacent[l[0] - 1, l[1] - 1] = 1 adjacent[l[1] - 1, l[0] - 1] = 1 print(adjacent, end='\n\n') pre = [-1 for _ in range(N)] low = [-1 for _ in range(N)] v = k = 0 ans = 0 def dfs(v, pre, low, k, parent): global ans pre[v] = k k += 1 low[v] = pre[v] for to, n in enumerate(adjacent[v, :]): if n == 1: if pre[to] == -1: # destination has not been visited # visit destination and update low[v] # print('-----', v, '-------') # print(pre, low) low[v] = min(low[v], dfs(to, pre, low, k, v)) if low[to] == pre[to]: ans += 1 # print(v + 1, to + 1) else: # visited if to == parent: pass else: low[v] = min(low[v], low[to]) return low[v] dfs(v, pre, low, k, -1) # print(pre, low) print(ans)
s332385394
Accepted
152
12,476
1,151
# -*- coding: utf-8 -*- import numpy as np N, M = map(int, input().split()) L = [list(map(int, input().split())) for _ in range(M)] adjacent = np.zeros((N, N)) for l in L: adjacent[l[0] - 1, l[1] - 1] = 1 adjacent[l[1] - 1, l[0] - 1] = 1 # print(adjacent, end='\n\n') pre = [-1 for _ in range(N)] low = [-1 for _ in range(N)] v = k = 0 ans = 0 def dfs(v, pre, low, k, parent): global ans pre[v] = k k += 1 low[v] = pre[v] for to, n in enumerate(adjacent[v, :]): if n == 1: if pre[to] == -1: # destination has not been visited # visit destination and update low[v] # print('-----', v, '-------') # print(pre, low) low[v] = min(low[v], dfs(to, pre, low, k, v)) if low[to] == pre[to]: ans += 1 # print(v + 1, to + 1) else: # visited if to == parent: pass else: low[v] = min(low[v], low[to]) return low[v] dfs(v, pre, low, k, -1) # print(pre, low) print(ans)
s094651095
p03370
u476048753
2,000
262,144
Wrong Answer
2,103
3,064
277
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
N, X = map(int, input().split()) powder_list = [int(input()) for i in range(N)] min_powder = min(powder_list) ans = 0 for i in range(N): X -= powder_list[i] if X >= 0: ans += 1 else: break while X < min_powder: X -= min_powder ans += 1 print(ans)
s676882834
Accepted
18
2,940
101
N, X = map(int, input().split()) m = [int(input()) for i in range(N)] print(N + (X-sum(m))//min(m))
s037226643
p04029
u681502232
2,000
262,144
Wrong Answer
26
8,964
150
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?
#043A x=input() i=int(x) sum=0 while i>0: sum=sum+i i=i-1 print(sum)
s132361421
Accepted
24
9,044
160
#043A x=input() i=int(x) sum=0 while i>0: sum=sum+i i=i-1 if i==0 : print(sum)
s890645865
p03999
u403331159
2,000
262,144
Wrong Answer
22
3,444
221
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
s=input() n=len(s)-1 ans=0 for bit in range(1<<n): f=s[0] for i in range(n): if ((bit>>i)&1): f+="+" f+=s[i+1] for i in f.split("+"): ans+=int(i) print(i) print(ans)
s441514804
Accepted
21
3,060
204
s=input() n=len(s)-1 ans=0 for bit in range(1<<n): f=s[0] for i in range(n): if ((bit>>i)&1): f+="+" f+=s[i+1] for i in f.split("+"): ans+=int(i) print(ans)
s942582541
p03486
u382303205
2,000
262,144
Wrong Answer
17
3,064
1,239
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
n = input() m = input() flag = True if len(n) < len(m): for i in range(len(n)): if n[i] == m[i]: continue else: for j in "abcdefghijklmnopqrstuvwxyz": if n[i] == j: flag = True break if m[i] == j: flag = False break break else: flag = False elif len(n) == len(m): for i in range(len(n)): if n[i] == m[i]: continue else: for j in "abcdefghijklmnopqrstuvwxyz": if n[i] == j: flag = True break if m[i] == j: flag = False break break else: flag = False else: for i in range(len(m)): if n[i] == m[i]: continue else: for j in "abcdefghijklmnopqrstuvwxyz": if n[i] == j: flag = True break if m[i] == j: flag = False break break else: flag = False if flag: print("Yes") else: print("No")
s309061909
Accepted
17
3,064
1,283
n = input() m = input() n = sorted(n) m = sorted(m, reverse = True) flag = True if len(n) < len(m): for i in range(len(n)): if n[i] == m[i]: continue else: for j in "abcdefghijklmnopqrstuvwxyz": if n[i] == j: flag = True break if m[i] == j: flag = False break break else: flag = True elif len(n) == len(m): for i in range(len(n)): if n[i] == m[i]: continue else: for j in "abcdefghijklmnopqrstuvwxyz": if n[i] == j: flag = True break if m[i] == j: flag = False break break else: flag = False else: for i in range(len(m)): if n[i] == m[i]: continue else: for j in "abcdefghijklmnopqrstuvwxyz": if n[i] == j: flag = True break if m[i] == j: flag = False break break else: flag = False if flag: print("Yes") else: print("No")
s195190172
p02277
u530663965
1,000
131,072
Wrong Answer
20
5,604
932
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 main(): cards = [] for _ in range(int(input())): cards.append(Card(input())) base_cards = cards.copy() quickSort(cards, 0, len(cards) - 1) for c in cards: print(c.cha, c.num) print(check_stable(base_cards, cards)) def quickSort(A, p, r): if p < r: q = partiton(A, p, r) quickSort(A, p, q - 1) quickSort(A, q + 1, r) def partiton(A, p, r): x = A[-1] i = p - 1 for j in range(p, r): if A[j].num <= x.num: 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 check_stable(base, card): for i in range(0, len(card) - 1): if base.index(card[i]) > base.index(card[i + 1]): return 'Not stable' return 'Stable' class Card: def __init__(self, imp): cha, num = imp.split(' ') self.cha = cha self.num = int(num) main()
s640450554
Accepted
850
24,168
1,619
"""Quick Sort.""" def partition(A, p, r): """Divide list A into A[p:q] whose elements aren't greater than A[q] and A[q+1:r] whose elements are greater than A[q]. Each element of A is a list [x, y]. x is a character of S, H, C or D (trump suits). y is a natural number. Sorting is done based on y numbers. Default value of p is 0. The number as a refernce of the division is A[r]. Return the index q. """ x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: 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): """Sort list A in ascending order with quick sort algorithm. Default value of p is 0 (the start index). r is 1 less than the length of A (the last index of A). """ if p < r: q = partition(A, p, r) quickSort(A, p, q - 1) quickSort(A, q + 1, r) def is_stable(A, B): """Check the stability of sorted list A. A is a sorted list. B is a original list. Return True or False. """ cA = list(A) for x in B: i = cA.index(x) if i == 0: pass elif cA[i - 1][1] == x[1]: return False del cA[i] return True import sys r = int(sys.stdin.readline()) - 1 A = [] for x in sys.stdin.readlines(): suit, num = x.split() num = int(num) A.append([suit, num]) B = list (A) quickSort(A, 0, r) if is_stable(A, B): print('Stable') else: print('Not stable') for x in A: print(*x)
s061529991
p03401
u802963389
2,000
262,144
Wrong Answer
2,104
13,920
280
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
N = int(input()) a = list(map(int, input().split())) a.insert(0, 0) a.append(0) print(a) for i in range(1, N + 1): s = 0 for j in range(N + 1): if j + 1 == i: s += abs(a[j] - a[j+2]) elif j != i: s += abs(a[j] - a[j+1]) print(s)
s816982503
Accepted
184
14,048
257
N = int(input()) a = list(map(int, input().split())) a.insert(0, 0) a.append(0) # print(a) li = [abs(a[i] - a[i+1]) for i in range(N + 1)] sumli = sum(li) for i in range(1, N + 1): print(sumli - (li[i-1] + li[i]) + abs(a[i-1]-a[i+1]))
s599314038
p02741
u671211357
2,000
1,048,576
Wrong Answer
17
2,940
118
Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
ans=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(ans[31])
s199852853
Accepted
17
2,940
135
ans=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K=int(input()) print(ans[K-1])
s458828491
p03712
u818050295
2,000
262,144
Wrong Answer
18
3,064
326
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
a = input().split(" ") tmp_out=[[""] for i in range(int(a[0])+2)] for j in range(int(a[1])+2): tmp_out[0]=["".join(tmp_out[0]+["#"])] for i in range(1, int(a[0])+1): tmp=input().split(" ") tmp_out[i]=["".join(["#"]+tmp+["#"])] tmp_out[int(a[0])+1]=tmp_out[0] for i in range(int(a[0])+2): print(tmp_out[i])
s460244882
Accepted
18
3,064
323
a = input().split(" ") tmp_out=[[""] for i in range(int(a[0])+2)] for j in range(int(a[1])+2): tmp_out[0]=["".join(tmp_out[0]+["#"])] for i in range(1, int(a[0])+1): tmp_out[i]=["".join(["#"]+input().split(" ")+["#"])] tmp_out[int(a[0])+1]=tmp_out[0] for i in range(int(a[0])+2): print("".join(tmp_out[i]))
s906197948
p03610
u427344224
2,000
262,144
Wrong Answer
29
3,572
76
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 = input() s = [h for i, h in enumerate(s) if i % 2 != 0] print("".join(s))
s764378743
Accepted
30
3,572
79
s = input() s = [h for i, h in enumerate(s, 1) if i % 2 != 0] print("".join(s))
s095143989
p03696
u940102677
2,000
262,144
Wrong Answer
18
3,060
203
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
n = int(input()) s = input() i = 0 k = 0 while i < len(s): if s[i] == "(": k += 1 i += 1 else: if k > 0: k -= 1 i += 1 else: s = s[:i] + "(" + s[i:] print(s+")"*k)
s377267633
Accepted
17
3,060
189
n = int(input()) s = input() i = 0 k = 0 while i < len(s): if s[i] == "(": k += 1 else: if k > 0: k -= 1 else: s = "(" + s i += 1 i += 1 print(s+")"*k)
s795610184
p04043
u884323674
2,000
262,144
Wrong Answer
17
2,940
192
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 == 5 and B == 5 and C == 7: print("YES") if A == 5 and B == 7 and C == 5: print("YES") if A == 7 and B == 5 and C == 5: print("YES") else: print("NO")
s312691216
Accepted
17
2,940
117
length = input().split() if length.count("5") == 2 and length.count("7") == 1: print("YES") else: print("NO")
s393140219
p04000
u760794812
3,000
262,144
Wrong Answer
1,977
168,524
326
We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column. Compute the following: * For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
from collections import * h,w,n = map(int,input().split()) dic = defaultdict(int) for _ in range(n): a,b = map(int,input().split()) for i in range(9): dic[a - i //3,b - i % 3] += 1 ans =[0]*(n+1) for i, j in dic: ans[dic[i,j]] += h-1 > i > 0 < j < w -1 ans[0] = (h -2)*(w-2) - sum(ans) for item in ans: print(item)
s993974679
Accepted
2,121
166,872
323
from collections import * h,w,n = map(int,input().split()) dic = defaultdict(int) for _ in range(n): a,b = map(int,input().split()) for i in range(9): dic[a - i //3,b - i % 3] += 1 ans =[0]*10 for i, j in dic: ans[dic[i,j]] += h-1 > i > 0 < j < w -1 ans[0] = (h -2)*(w-2) - sum(ans) for item in ans: print(item)
s292636472
p04043
u467831546
2,000
262,144
Wrong Answer
17
2,940
96
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 == 175: print("yes") else: print("no")
s697561452
Accepted
18
2,940
96
a, b, c = map(int, input().split()) if a * b * c == 175: print("YES") else: print("NO")
s202062308
p02396
u884445603
1,000
131,072
Wrong Answer
40
8,016
101
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
import sys l = sys.stdin.read().split() for k,v in enumerate(l): print("Case {}: {}".format(k,v))
s231034148
Accepted
150
7,380
121
cnt = 1 while True: i = input() if i == '0': break print("Case {}: {}".format(cnt,i)) cnt = cnt+1
s682579907
p03860
u663710122
2,000
262,144
Wrong Answer
19
2,940
46
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
A, S, C = input().split() print(A + S[0] + C)
s779184432
Accepted
21
2,940
29
print('A' + input()[8] + 'C')
s813157513
p02610
u792078574
2,000
1,048,576
Wrong Answer
789
42,516
686
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up in a row. The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise. Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel. Solve this problem for each of the T test cases given.
from heapq import heappush, heappop T = int(input()) def process(arr): arr.sort() baseS = 0 diffS = 0 q = [] length = 0 for K, L, R in arr1: baseS += R diff = L - R heappush(q, diff) diffS += diff length += 1 while length > K: d = heappop(q) diffS -= d length -= 1 return baseS + diffS for _ in range(T): N = int(input()) arr1 = [] arr2 = [] for _ in range(N): K, L, R = list(map(int, input().split())) if L > R: arr1.append((K, L, R)) else: arr2.append((N-K, R, L)) print(process(arr1) + process(arr2))
s251575173
Accepted
727
42,532
685
from heapq import heappush, heappop T = int(input()) def process(arr): arr.sort() baseS = 0 diffS = 0 q = [] length = 0 for K, L, R in arr: baseS += R diff = L - R heappush(q, diff) diffS += diff length += 1 while length > K: d = heappop(q) diffS -= d length -= 1 return baseS + diffS for _ in range(T): N = int(input()) arr1 = [] arr2 = [] for _ in range(N): K, L, R = list(map(int, input().split())) if L > R: arr1.append((K, L, R)) else: arr2.append((N-K, R, L)) print(process(arr1) + process(arr2))
s191106969
p03160
u141574039
2,000
1,048,576
Wrong Answer
156
13,928
393
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N=int(input()) H=list(map(int,input().split())) cost=0 t1,t2=0,0 A=[0]*(N) i=1 while i<N: if i==1: A[i]=abs(H[i]-H[i-1]) #print(i,A[i]) elif i==2: t1=abs(H[i]-H[i-2]) t2=abs(H[i]-H[i-1])+abs(H[i-2]-H[i-1]) A[i]=min(t1,t2) #print(i,A[i],t1,t2) else: t1=abs(H[i]-H[i-1])+A[i-1] t2=abs(H[i]-H[i-2])+A[i-2] A[i]=min(t1,t2) #print(i,A[i],t1,t2) i=i+1
s658571883
Accepted
129
13,980
188
N=int(input()) H=list(map(int,input().split())) DP=[0]*N DP[0]=0 DP[1]=abs(H[1]-H[0]) for i in range(2,N): DP[i]=min((abs(H[i]-H[i-1])+DP[i-1]),(abs(H[i]-H[i-2])+DP[i-2])) print(DP[N-1])