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
s814581844
p03598
u094565093
2,000
262,144
Wrong Answer
1,205
18,752
175
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
import numpy as np X=int(input()) Y=int(np.sqrt(X))+1 max=1 for j in range(2,Y+1): for i in range(1,Y+1): if i**j<=X and i**j>max: max=i**j print(max)
s453054315
Accepted
17
3,060
190
N=int(input()) K=int(input()) S=list(map(int, input().split())) total=0 for i in range(N): if abs(S[i]-K)<S[i]: total+=abs(S[i]-K)*2 else: total+=2*S[i] print(total)
s833981746
p03090
u145035045
2,000
1,048,576
Wrong Answer
25
3,996
195
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
n = int(input()) lst = [] for i in range(1, n + 1): for j in range(i, n + 1): if i != j and i + j != n + 1: lst.append((i, j)) print(len(lst)) for s in lst: print(*s)
s831262190
Accepted
25
3,996
499
n = int(input()) if n % 2 == 0: lst = [] for i in range(1, n + 1): for j in range(i, n + 1): if i != j and i + j != n + 1: lst.append((i, j)) print(len(lst)) for s in lst: print(*s) else: lst = [] for i in range(1, n): for j in range(i, n): if i != j and i + j != n: lst.append((i, j)) for i in range(1, n): lst.append((i, n)) print(len(lst)) for s in lst: print(*s)
s221255108
p03486
u995861601
2,000
262,144
Wrong Answer
17
2,940
66
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.
print("Yes") if sorted(input()) < sorted(input()) else print("No")
s106712651
Accepted
18
2,940
80
print("Yes") if sorted(input()) < sorted(input(), reverse=True) else print("No")
s099238175
p02261
u128811851
1,000
131,072
Wrong Answer
20
6,828
2,006
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, 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).
MARK = 0 NUMBER = 1 def bubble_sort(A): for i in range(len(A)-1): for j in reversed(range(i+1, len(A))): if A[j][NUMBER] < A[j - 1][NUMBER]: swap(A, j-1, j) def selection_sort(A): for i in range(len(A)): mini = i for j in range(i, len(A)): if A[j][NUMBER] < A[mini][NUMBER]: mini = j if mini != i: swap(A, mini, i) def swap(A, i, j): tmp = A[j] A[j] = A[i] A[i] = tmp amount = int(input()) cards = input().split() # list of cards (ex:[H2 S8]) same_numbers = [] isStable_bubble = True isStable_selection = True # make tuple of mark and number for i in range(amount): cards[i] = tuple([cards[i][MARK], int(cards[i][NUMBER])]) # make list of (pairs of) cards which have the same number for i in range(amount-1): number = cards[i][NUMBER] for j in range(i+1, amount): if number == cards[j][NUMBER]: same_numbers.append(cards[i]) same_numbers.append(cards[j]) cards_bubble = list(cards) cards_selection = list(cards) bubble_sort(cards_bubble) selection_sort(cards_selection) # jugle stable or not for i in range(len(same_numbers)): for j in range(amount): if same_numbers[i][NUMBER] == cards_bubble[j][NUMBER]: if same_numbers[i] == cards_bubble[j]: isStable_bubble = True else: isStable_bubble = False if same_numbers[i][NUMBER] == cards_selection[j][NUMBER]: if same_numbers[i] == cards_selection[j]: isStable_selection = True else: isStable_selection = False print(*[cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER]) for i in range(amount)]) if isStable_bubble: print("Stable") else: print("Not Stable") print(*[cards_selection[i][MARK] + str(cards_selection[i][NUMBER]) for i in range(amount)]) if isStable_selection: print("Stable") else: print("Not Stable")
s571217822
Accepted
40
6,780
1,268
MARK = 0 NUMBER = 1 def bubble_sort(A): for i in range(len(A)-1): for j in reversed(range(i+1, len(A))): if A[j][NUMBER] < A[j - 1][NUMBER]: swap(A, j-1, j) def selection_sort(A): for i in range(len(A)): mini = i for j in range(i, len(A)): if A[j][NUMBER] < A[mini][NUMBER]: mini = j if mini != i: swap(A, mini, i) def swap(A, i, j): tmp = A[j] A[j] = A[i] A[i] = tmp amount = int(input()) cards = input().split() # list of cards (ex:[H2 S8]) isStable_selection = True # make tuple of mark and number for i in range(amount): cards[i] = tuple([cards[i][MARK], int(cards[i][NUMBER])]) cards_bubble = list(cards) cards_selection = list(cards) bubble_sort(cards_bubble) selection_sort(cards_selection) # judge stable or not (bubble sort is stable) if cards_bubble == cards_selection: isStable_selection = True else: isStable_selection = False print(*[cards_bubble[i][MARK] + str(cards_bubble[i][NUMBER]) for i in range(amount)]) print("Stable") print(*[cards_selection[i][MARK] + str(cards_selection[i][NUMBER]) for i in range(amount)]) if isStable_selection: print("Stable") else: print("Not stable")
s517614358
p03970
u744592787
2,000
262,144
Wrong Answer
24
3,064
99
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
# -*- coding: utf-8 -*- s = input() if s != 'CODEFESTIVAL2016': s = 'CODEFESTIVAL2016' print(s)
s799080759
Accepted
22
3,064
153
# -*- coding: utf-8 -*- ans = 'CODEFESTIVAL2016' s = input() count = 0 for i in range(len(ans)): if ans[i] != s[i]: count += 1 print(count)
s263590022
p03729
u102126195
2,000
262,144
Wrong Answer
17
2,940
102
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 = list(input().split()) if A[:1] == B[0] and B[-1] == C[0]: print("YES") else: print("NO")
s578360101
Accepted
17
2,940
103
A, B, C = list(input().split()) if A[-1] == B[0] and B[-1] == C[0]: print("YES") else: print("NO")
s182061449
p04029
u973108807
2,000
262,144
Wrong Answer
18
2,940
34
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) print(n*(n-1)//2)
s091432422
Accepted
18
2,940
34
n = int(input()) print(n*(n+1)//2)
s480991227
p03486
u089376182
2,000
262,144
Wrong Answer
17
2,940
57
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.
print('Yes' if sorted(input())<sorted(input()) else 'No')
s657109361
Accepted
17
2,940
64
print('Yes' if sorted(input())<sorted(input())[::-1] else 'No')
s578703114
p03760
u977661421
2,000
262,144
Wrong Answer
17
3,060
241
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.
# -*- coding: utf-8 -*- o = list(input()) e = list(input()) for i in range(min(len(o), len(e))): print(o[i], end = '') print(e[i], end = '') if len(e) > len(o): print(e[len(e) - 1]) if len(o) < len(e): print(o[len(o) - 1])
s008659945
Accepted
17
3,064
468
# -*- coding: utf-8 -*- o = list(input()) e = list(input()) len_o = len(o) len_e = len(e) if len_o == len_e: for i in range(len_o - 1): print(o[i], end = '') print(e[i], end = '') print(o[len_o - 1], end = '') print(e[len_e - 1]) else: for i in range(min(len_o, len_e)): print(o[i], end = '') print(e[i], end = '') if len_e > len_o: print(e[len(e) - 1]) if len_o > len_e: print(o[len(o) - 1])
s281615562
p03657
u121732701
2,000
262,144
Wrong Answer
18
2,940
117
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
A, B= map(int, input().split()) if A+B%3==0 or A%3==0 or B%3==0: print("Possible") else: print("Impossible")
s073088490
Accepted
18
2,940
119
A, B= map(int, input().split()) if (A+B)%3==0 or A%3==0 or B%3==0: print("Possible") else: print("Impossible")
s041551865
p03494
u733774002
2,000
262,144
Time Limit Exceeded
2,104
2,940
234
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N = int(input()) A = list(map(int, input().split())) cnt = 0 while True: i = 0 for i in range(N): if A[i] % 2 == 0: A[i] /=2 i += 1 else: i += 1 break print(cnt)
s286867549
Accepted
19
3,060
145
N = input() A = list(map(int, input().split())) cnt = 0 while all(i % 2 == 0 for i in A): A = [int(j / 2) for j in A] cnt += 1 print(cnt)
s679724047
p03023
u902577051
2,000
1,048,576
Wrong Answer
17
2,940
150
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
# -*- coding: utf-8 -*- s = input() num_win = s.count('o') num_rest = 15 - len(s) if num_win + num_rest > 7: print('YES') else: print('NO')
s385245422
Accepted
17
2,940
63
# -*- coding: utf-8 -*- n = int(input()) print(180 * (n - 2))
s561158056
p03457
u977349332
2,000
262,144
Wrong Answer
857
3,316
226
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
import math n = int(input()) X = 0 Y = 0 T = 0 for i in range(1, n): t,x,y = [int(i) for i in input().split()] sum = abs(X-x)+abs(Y-y) if ( sum )<T-t and sum%2 == T-t: X = x Y = y else: print('No') print('Yes')
s158057058
Accepted
198
3,060
197
import math import sys n = int(input()) for i in range(n): t,x,y = map(int, sys.stdin.readline().split()) d = abs(x)+abs(y) if d > t or (d - t) % 2 != 0: print('No') exit() print('Yes')
s255416332
p03998
u193927973
2,000
262,144
Wrong Answer
31
9,264
369
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
a=input() b=input() c=input() from collections import deque da=deque(list(a)) db=deque(list(b)) dc=deque(list(c)) now=da.popleft() while (1): if now=="a": if da: now=da.popleft() else: break elif now=="b": if db: now=db.popleft() else: break elif now=="c": if dc: now=dc.popleft() else: break print(now)
s748322444
Accepted
32
9,360
377
a=input() b=input() c=input() from collections import deque da=deque(list(a)) db=deque(list(b)) dc=deque(list(c)) now=da.popleft() while (1): if now=="a": if da: now=da.popleft() else: break elif now=="b": if db: now=db.popleft() else: break elif now=="c": if dc: now=dc.popleft() else: break print(now.upper())
s106468749
p03408
u013408661
2,000
262,144
Wrong Answer
18
3,064
275
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
n=int(input()) s=[] for i in range(n): k=input() s.append(k) m=int(input()) t=[] for i in range(m): k=input() t.append(k) check=[] ans=0 for i in s: if i in check: continue if s.count(i)>=t.count(i): ans+=s.count(i)-t.count(i) check.append(i) print(ans)
s799620290
Accepted
18
3,064
258
n=int(input()) s=[] for i in range(n): k=input() s.append(k) m=int(input()) t=[] for i in range(m): k=input() t.append(k) check=[] ans=[0] for i in s: if i in check: continue ans.append(s.count(i)-t.count(i)) check.append(i) print(max(ans))
s798595667
p02401
u215732964
1,000
131,072
Wrong Answer
20
5,600
270
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: a, op, b = input().split() if op == '+': print(int(a) + int(b)) elif op == '-': print(int(a) - int(b)) elif op == '*': print(int(a) * int(b)) elif op == '/': print(int(a) / int(b)) else: break
s753096917
Accepted
20
5,596
271
while True: a, op, b = input().split() if op == '+': print(int(a) + int(b)) elif op == '-': print(int(a) - int(b)) elif op == '*': print(int(a) * int(b)) elif op == '/': print(int(a) // int(b)) else: break
s140036669
p03760
u027641915
2,000
262,144
Wrong Answer
17
3,060
153
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
o = input() e = input() password = '' for i in range(len(o)): password += o[i] if (i != len(o) -1): password += e[i] print(password)
s619632584
Accepted
17
3,064
188
o = input() e = input() password = '' for i in range(len(o)): password += o[i] if (len(o) > len(e)) and ((len(o) - 1) == i): break password += e[i] print(password)
s841791021
p03623
u627530854
2,000
262,144
Wrong Answer
17
2,940
84
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
(x, a, b) = (int(tok) for tok in input().split()) print(min(abs(x - a), abs(x - b)))
s715206629
Accepted
18
2,940
143
(x, a, b) = (int(tok) for tok in input().split()) dist_a = abs(x - a) dist_b = abs(x - b) print("A" if dist_a == min(dist_a, dist_b) else "B")
s719561656
p03160
u426930857
2,000
1,048,576
Wrong Answer
116
13,980
182
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()) l=list(map(int,input().split())) dp=[0 for i in range(n)] dp[1]=l[1]-l[0] for i in range(2,n): dp[i]=min(dp[i-1]+l[i]-l[i-1],dp[i-2]+l[i]-l[i-2]) print(dp[n-1])
s840703163
Accepted
127
13,980
208
n=int(input()) l=list(map(int,input().split())) dp=[0 for i in range(n)] dp[1]=abs(l[1]-l[0]) for i in range(2,n): dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2])) print(dp[n-1]) #print(dp)
s170335059
p03214
u154756110
2,525
1,048,576
Wrong Answer
17
3,064
183
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
N=int(input()) A=list(map(int,input().split())) sum=0.0 for i in range(N): sum+=A[i] sum/=N X=0 ans=0 for i in range(N): A[i]=abs(A[i]-sum) if(A[i]<A[X]): ans=i print(ans+1)
s405935814
Accepted
18
3,064
176
N=int(input()) A=list(map(int,input().split())) sum=0 for i in range(N): sum+=A[i] sum ans=0 for i in range(N): A[i]=abs(A[i]*N-sum) if(A[i]<A[ans]): ans=i print(ans)
s355524288
p04011
u008357982
2,000
262,144
Wrong Answer
17
2,940
50
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
n,k,x,y=map(int,open(0));print([n*k,(n-k)*y][n<k])
s488775257
Accepted
17
2,940
54
n,k,x,y=map(int,open(0));print([n*x,k*x+(n-k)*y][n>k])
s598411799
p03251
u422272120
2,000
1,048,576
Wrong Answer
17
2,940
175
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) if max(x) + 1 < min(y): print ("No War") else: print ("War")
s380483493
Accepted
17
2,940
200
N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) print ("No War") if max(x) < min(y) and (X < max(x) < Y or X < min(y) <= Y) else print ("War")
s981552279
p03477
u074220993
2,000
262,144
Wrong Answer
26
9,016
168
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.
S = list(input()) lenS = len(S) S = S + ['.'] K = lenS i = 0 ps = S[0] for s in S: if s != ps: K = min(K, max(i, lenS-i)) ps = s i += 1 print(K)
s239928415
Accepted
29
9,080
134
A, B, C, D = map(int, input().split()) if A+B == C+D: print('Balanced') elif A+B > C+D: print('Left') else: print('Right')
s870094019
p03407
u662449766
2,000
262,144
Wrong Answer
19
3,060
174
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
import sys input = sys.stdin.readline def main(): a, b, c = map(int, input().split()) print("YES" if c <= a + b else "NO") if __name__ == "__main__": main()
s025690802
Accepted
17
2,940
174
import sys input = sys.stdin.readline def main(): a, b, c = map(int, input().split()) print("Yes" if c <= a + b else "No") if __name__ == "__main__": main()
s373276518
p03998
u654558363
2,000
262,144
Wrong Answer
21
3,316
421
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
from collections import deque if __name__ == "__main__": stacks = [] for i in range(3): stacks.append(deque([x for x in input()])) winner = False turn = 0 while not winner: turn = ord(stacks[turn].popleft()) - ord('a') for i in range(3): if len(stacks[i]) == 0: print(i) winner = chr(97 + i) break print(winner)
s038603971
Accepted
21
3,316
345
from collections import deque if __name__ == "__main__": stacks = [] for i in range(3): stacks.append(deque([x for x in input()])) winner = False turn = 0 while not winner: turn = ord(stacks[turn].popleft()) - ord('a') if len(stacks[turn]) == 0: winner = chr(65 + turn) print(winner)
s690400989
p03079
u920204936
2,000
1,048,576
Wrong Answer
17
2,940
137
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
length = list(map(int, input().split())) if length[0] == length[1] and length[1] == length[2]: print(True) else: print(False)
s018558844
Accepted
18
2,940
137
length = list(map(int, input().split())) if length[0] == length[1] and length[1] == length[2]: print("Yes") else: print("No")
s969816211
p02258
u500396695
1,000
131,072
Wrong Answer
20
7,532
136
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .
n = int(input()) R = [] for i in range(n): R.append(int(input())) r = sorted(R) maximum_profit = r[n-1] - r[0] print(maximum_profit)
s034708120
Accepted
510
7,664
186
n = int(input()) # R[0] minv = int(input()) maxv = - 10 ** 10 # R[1..N-1] for j in range(1, n): r = int(input()) maxv = max(maxv, r - minv) minv = min(minv, r) print(maxv)
s338644676
p04029
u439392790
2,000
262,144
Wrong Answer
18
2,940
33
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?
x=int(input()) print((x/2)*(x+1))
s791976061
Accepted
17
2,940
37
n=int(input()) print(int (n*(n+1)/2))
s707711957
p02601
u517389396
2,000
1,048,576
Wrong Answer
34
9,224
317
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.
import sys def check(r,g,b): return r<g and g<b r,g,b=input().split() r,g,b=int(r),int(g),int(b) K=int(input()) for i in range(K): for j in range(K): for k in range(K): if check(r*2**(i+1),g*2**(j+1),b*2**(k+1)): print("True") sys.exit(0) print("False")
s978479855
Accepted
34
9,160
332
import sys def check(r,g,b): return r<g and g<b r,g,b=input().split() r,g,b=int(r),int(g),int(b) K=int(input())+1 for i in range(K): for j in range(K-i): for k in range(K-i-j): if check(r*2**(i),g*2**(j),b*2**(k)): print("Yes") sys.exit(0) print("No")
s584486600
p03007
u952467214
2,000
1,048,576
Wrong Answer
235
14,228
830
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n = int(input()) a = list( map(int, input().split())) a.sort() from bisect import bisect_left from bisect import bisect_right pos = n - bisect_left(a, 1) neg = bisect_right(a, -1) if pos>=neg: aa = a[neg-1:n-neg+1] for i in range(neg-1): print(a[-1-i], a[i]) aa.append(a[-1-i] - a[i]) aa.sort() tmp = aa[0] for i in range(1,len(aa)-1): print(tmp, a[i]) tmp = tmp-a[i] print(a[-1], tmp) exit() if pos<=neg: aa = a[pos-1:n-pos+1] for i in range(pos-1): print(a[i], a[-1-i]) aa.append(a[i] - a[-1-i]) aa.sort() tmp = aa[-1] print(aa[-1], aa[0]) tmp = aa[-1]-aa[0] for i in range(1,len(aa)-1): print(tmp, a[i]) tmp = tmp-a[i] exit()
s954581493
Accepted
273
19,988
1,001
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n = int(input()) a = list( map(int, input().split())) a.sort() from bisect import bisect_left from bisect import bisect_right pos = n - bisect_left(a, 1) neg = bisect_right(a, -1) ans_exec = [] if pos>=neg: aa = a[max(0,neg-1):n-neg+1] for i in range(neg-1): ans_exec.append((a[-1-i], a[i])) aa.append(a[-1-i] - a[i]) aa.sort() tmp = aa[0] for i in range(1,len(aa)-1): ans_exec.append((tmp, aa[i])) tmp = tmp-aa[i] ans_exec.append((aa[-1], tmp)) ans = aa[-1] - tmp elif pos<=neg: aa = a[max(0,pos-1):n-pos+1] for i in range(pos-1): ans_exec.append((a[i], a[-1-i])) aa.append(a[i] - a[-1-i]) aa.sort() tmp = aa[-1] ans_exec.append((aa[-1], aa[0])) tmp = aa[-1]-aa[0] for i in range(1,len(aa)-1): ans_exec.append((tmp, aa[i])) tmp = tmp-aa[i] ans = tmp print(ans) for a,b in ans_exec: print(a,b)
s645370860
p03385
u544050502
2,000
262,144
Wrong Answer
17
2,940
24
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
print(len(set(input())))
s644560292
Accepted
17
2,940
46
print("Yes" if len(set(input()))==3 else "No")
s709540678
p03351
u341855122
2,000
1,048,576
Wrong Answer
17
3,060
158
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
n = list(map(int,input().split())) if ((n[3] > abs(n[0]-n[1])) and( n[3] > abs(n[1]-n[2]))) or( n[3] > abs(n[0]-n[2])): print('Yes') else: print('No')
s640273188
Accepted
17
3,064
161
n = list(map(int,input().split())) if ((n[3] >= abs(n[0]-n[1])) and( n[3] >= abs(n[1]-n[2]))) or( n[3] >= abs(n[0]-n[2])): print('Yes') else: print('No')
s948834815
p02742
u870518235
2,000
1,048,576
Wrong Answer
17
2,940
112
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
h, w = map(int, input().split()) if h % 2 != 0 and w % 2 != 0: print((h*w-1)/2 + 1) else: print((h*w)/2)
s850020381
Accepted
18
2,940
179
h, w = map(int, input().split()) if h == 1 or w == 1: print(1) else: if h % 2 != 0 and w % 2 != 0: print(int((h*w-1)/2 + 1)) else: print(int((h*w)/2))
s074529987
p03251
u672475305
2,000
1,048,576
Wrong Answer
17
3,064
297
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
n,m,x,y = map(int,input().split()) lstx = list(map(int,input().split())) lsty = list(map(int,input().split())) lstx.append(x) lsty.append(y) maxx = max(lstx) miny = min(lsty) for z in range(x,y+1): if (maxx<z) and (miny>=z): print(z) print('No War') exit() print('War')
s997432322
Accepted
17
3,064
256
n,m,x,y = map(int,input().split()) lstx = list(map(int,input().split())) lsty = list(map(int,input().split())) max_x = max(lstx) min_y = min(lsty) for z in range(x+1,y+1): if (max_x<z) and (min_y>=z): print('No War') exit() print('War')
s722541466
p03910
u463655976
2,000
262,144
Wrong Answer
20
3,060
114
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
import math N = int(input()) * 2 i = math.floor(math.sqrt(N)) while N - 2 * i * (i+1) > 2 * i: i += 1 print(i)
s884798956
Accepted
21
3,408
174
import math N = int(input()) i = math.floor(math.sqrt(2*N)) while i * (i+1) // 2 - N < 0: i += 1 x = i * (i+1) // 2 - N for j in range(1, i+1): if j != x: print(j)
s535239610
p02409
u636711749
1,000
131,072
Wrong Answer
30
6,720
360
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.
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] n = int(input()) for nc in range(n): (b, f, r, v) = [int(i) for i in input().split()] data[b - 1][f - 1][r - 1] += v for b in range(4): for f in range(3): for r in range(10): print(' {0}'.format(data[b][f][r]), end='') print() print('#' * 20)
s898129215
Accepted
30
6,724
391
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] n = int(input()) for nc in range(n): (b, f, r, v) = [int(i) for i in input().split()] data[b - 1][f - 1][r - 1] += v for b in range(4): for f in range(3): for r in range(10): print(' {0}'.format(data[b][f][r]), end='') print() print('#' * 20) if b < 4 -1 else print(end='')
s144691920
p03162
u050698451
2,000
1,048,576
Wrong Answer
2,106
90,080
504
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
N = int(input()) abc = [] for _ in range(N): a, b, c = map(int, input().split()) abc.append([a,b,c]) dp = [[0, 0, 0] for _ in range(N+1)] print(abc) for i in range(1,N+1): dp[i][0] = max(dp[i][0], dp[i-1][1]+abc[i-1][0]) dp[i][0] = max(dp[i][0], dp[i-1][2]+abc[i-1][0]) dp[i][1] = max(dp[i][1], dp[i-1][0]+abc[i-1][1]) dp[i][1] = max(dp[i][1], dp[i-1][2]+abc[i-1][1]) dp[i][2] = max(dp[i][2], dp[i-1][0]+abc[i-1][2]) dp[i][2] = max(dp[i][2], dp[i-1][1]+abc[i-1][2]) print(dp) print(max(dp[N]))
s130301814
Accepted
724
42,532
508
N = int(input()) abc = [] for _ in range(N): a, b, c = map(int, input().split()) abc.append([a,b,c]) dp = [[0, 0, 0] for _ in range(N+1)] # print(abc) for i in range(1,N+1): dp[i][0] = max(dp[i][0], dp[i-1][1]+abc[i-1][0]) dp[i][0] = max(dp[i][0], dp[i-1][2]+abc[i-1][0]) dp[i][1] = max(dp[i][1], dp[i-1][0]+abc[i-1][1]) dp[i][1] = max(dp[i][1], dp[i-1][2]+abc[i-1][1]) dp[i][2] = max(dp[i][2], dp[i-1][0]+abc[i-1][2]) dp[i][2] = max(dp[i][2], dp[i-1][1]+abc[i-1][2]) # print(dp) print(max(dp[N]))
s199706062
p02417
u879471116
1,000
131,072
Wrong Answer
20
5,560
341
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] dic = {} for c in alphabet: dic[c] = 0 string = list(input().rstrip().lower()) for c in string: if c in alphabet: dic[c] = dic[c] + 1 for key in dic: print('{} : {}'.format(key, dic[key]))
s252183724
Accepted
20
5,560
394
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w','x', 'y', 'z'] dic = {} for c in alphabet: dic[c] = 0 while True: try: string = list(input().rstrip().lower()) except EOFError: break for c in string: if c in alphabet: dic[c] = dic[c] + 1 for key in dic: print('{} : {}'.format(key, dic[key]))
s781226185
p03469
u427984570
2,000
262,144
Wrong Answer
17
2,940
34
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
s = input() print("2018" + s[:4])
s267345239
Accepted
18
2,940
35
s = input() print("2018" + s[4:])
s215953341
p03110
u681110193
2,000
1,048,576
Wrong Answer
17
2,940
150
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
n=int(input()) for i in range(n): ans=0 a,b=map(str,input().split()) if b=='JPY': ans+=int(a) else: ans+=float(a)*380000 print(ans)
s402235580
Accepted
17
2,940
148
n=int(input()) ans=0 for i in range(n): a,b=map(str,input().split()) if b=='JPY': ans+=int(a) else: ans+=float(a)*380000 print(ans)
s177166091
p03150
u137724047
2,000
1,048,576
Wrong Answer
18
2,940
166
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
#!/usr/bin/python3 s = input().strip() t = "keyence" for x in range(0,len(t)+1): if s.startswith(t[x:]) and s.endswith(t[:x]): print("YES") exit(0) print("NO")
s229964997
Accepted
17
2,940
166
#!/usr/bin/python3 s = input().strip() t = "keyence" for x in range(0,len(t)+1): if s.startswith(t[:x]) and s.endswith(t[x:]): print("YES") exit(0) print("NO")
s806489107
p03377
u417835834
2,000
262,144
Wrong Answer
17
2,940
95
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 and X <= A+B: print('Yes') else: print('No')
s103990943
Accepted
17
2,940
95
A,B,X = map(int,input().split()) if X >= A and X <= A+B: print('YES') else: print('NO')
s971196520
p03486
u288430479
2,000
262,144
Wrong Answer
17
2,940
114
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = sorted(input()) t = sorted(input()) s = ''.join(s) t = ''.join(t) if s < t: print('Yes') else: print('No')
s189237873
Accepted
23
2,940
120
s = sorted(input()) t = sorted(input())[::-1] s = ''.join(s) t = ''.join(t) if s < t: print('Yes') else: print('No')
s188878459
p03455
u052499405
2,000
262,144
Wrong Answer
18
2,940
117
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = [int(item) for item in input().split()] if a % 2 == 1 and b % 2 == 1: print("Even") else: print("Odd")
s060806784
Accepted
18
2,940
117
a, b = [int(item) for item in input().split()] if a % 2 == 1 and b % 2 == 1: print("Odd") else: print("Even")
s381688614
p03160
u345966487
2,000
1,048,576
Wrong Answer
2,109
22,684
293
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
import numpy as np import sys f = sys.stdin n = int(f.readline()) h = list(map(int, f.readline().split())) h = np.array(h) dp = np.zeros(n, int) for i in range(n - 1): np.minimum( dp[1:-1] + np.abs(h[2:] - h[1:-1]), dp[:-2] + np.abs(h[2:] - h[:-2]), out=dp[2:] ) print(dp[-1])
s855591084
Accepted
115
13,980
201
n = int(input()) h = list(map(int, input().split())) p0, p1 = 0, abs(h[1] - h[0]) for i in range(2, n): p2 = min(p1 + abs(h[i] - h[i - 1]), p0 + abs(h[i] - h[i - 2])) p0, p1 = p1, p2 print(p1)
s082326875
p03448
u881116515
2,000
262,144
Wrong Answer
50
3,060
211
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()) ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if i*500+j*100*k*50 == x: ans += 1 print(ans)
s380544629
Accepted
49
3,060
212
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if i*500+j*100+k*50 == x: ans += 1 print(ans)
s711028269
p03697
u622011073
2,000
262,144
Wrong Answer
17
2,940
48
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
a=input();print('no'*len(a)==len(set(a))or'yes')
s809504684
Accepted
17
2,940
56
a,b=map(int,input().split());print([a+b,'error'][a+b>9])
s550057627
p02612
u617225232
2,000
1,048,576
Wrong Answer
27
9,028
65
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.
a = int(input()) print(0) if a%1000==0 else print(1000-(a//1000))
s613169332
Accepted
29
9,064
65
a = int(input()) print(0) if a%1000==0 else print(1000-(a%1000))
s995128097
p03049
u448354193
2,000
1,048,576
Wrong Answer
43
3,188
468
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
import re n = int(input()) s = [] compiled = re.compile(r"AB") pre = 0 xa=0 bx=0 ba=0 for i in range(n): one = input() pre+=len(compiled.findall(one)) f=one[0] l=one[-1] if f=="B" and l=="A": ba+=1 elif f=="B" and l!="A": bx+=1 elif f!="B" and l=="A": xa+=1 print(xa,bx,ba,pre) cnt=ba-1 if xa>=1: xa-=1 cnt+1 if bx>=1: bx-=1 cnt+1 cnt += xa if xa>bx else bx print(cnt+pre)
s405170297
Accepted
43
3,316
500
import re n = int(input()) s = [] compiled = re.compile(r"AB") pre = 0 xa=0 bx=0 ba=0 for i in range(n): one = input() pre+=len(compiled.findall(one)) f=one[0] l=one[-1] if f=="B" and l=="A": ba+=1 elif f=="B" and l!="A": bx+=1 elif f!="B" and l=="A": xa+=1 #print(ba,bx,xa,pre) cnt=0 if ba>=1: cnt+=ba-1 if xa>=1: xa-=1 cnt+=1 if bx>=1: bx-=1 cnt+=1 cnt += xa if xa<bx else bx print(cnt+pre)
s116664281
p02613
u302701160
2,000
1,048,576
Wrong Answer
153
16,156
221
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()) L =[] for i in range(N): S = input() L.append(S) print("AC * " + str(L.count("AC"))) print("WA * " + str(L.count("WA"))) print("TLE * " + str(L.count("TLE"))) print("RE * " + str(L.count("RE")))
s777973860
Accepted
154
16,072
222
L =[] N = int(input()) for i in range(N): S = input() L.append(S) print("AC x " + str(L.count("AC"))) print("WA x " + str(L.count("WA"))) print("TLE x " + str(L.count("TLE"))) print("RE x " + str(L.count("RE")))
s615575980
p03379
u513434790
2,000
262,144
Wrong Answer
268
25,556
164
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
N = int(input()) X = [0] + list(map(int, input().split())) for i in range(N): if i+1 <= N//2: print(X[(N // 2 + 1)]) else: print(X[N // 2])
s708301344
Accepted
355
26,772
186
N = int(input()) a = [0] + list(map(int, input().split())) X = sorted(a) for i in range(1,N+1): if a[i] <= X[N//2]: print(X[(N // 2 + 1)]) else: print(X[N // 2])
s511663127
p04044
u521323621
2,000
262,144
Wrong Answer
28
9,168
111
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
n,l = map(int,input().split()) a = [] for i in range(n): a.append(input()) a.sort() for i in a: print(i)
s236598680
Accepted
31
9,104
122
n,l = map(int,input().split()) a = [] for i in range(n): a.append(input()) a.sort() print("".join(str(i) for i in a))
s338152689
p03352
u318427318
2,000
1,048,576
Wrong Answer
117
27,276
727
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
#-*-coding:utf-8-*- import sys input=sys.stdin.readline import numpy as np def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def main(): n = int(input()) if n==1: print(1) exit() while True: dp=np.array(factorization(n),dtype=np.int) if np.all(dp[:,1:]!=1) and len(dp)==1: print(n) exit() else: n-=1 if __name__=="__main__": main()
s241090677
Accepted
26
9,060
478
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def main(): n = int(input()) answers=[] if n<=3: print(n) exit() for b in range(2,n): for p in range(2,11): if b**p > n: break elif b**p <=n: answers.append(b**p) else: continue print(max(answers)) if __name__=="__main__": main()
s573136524
p03672
u722535636
2,000
262,144
Wrong Answer
17
2,940
21
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
print(len(input())-2)
s515035725
Accepted
17
2,940
96
s=input() while 1: s=s[:-2] if s[:len(s)//2]==s[len(s)//2:]: break print(len(s))
s248425774
p03543
u136090046
2,000
262,144
Wrong Answer
17
3,060
212
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
num = list(input()) res = 0 tmp = num[0] for i in range(1, 3): if tmp == num[i]: res += 1 else: res = 0 tmp = num[i] if res >= 2: break print("YES" if res >= 2 else "NO")
s846877057
Accepted
17
2,940
192
num = input() array = ["111","222","333","444","555","666","777","888","999","000"] res = 0 for i in array: if i in num: res =1 break print("Yes" if res != 0 else "No")
s269367134
p02612
u812891913
2,000
1,048,576
Wrong Answer
31
9,148
51
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()) a = N // 1000 print(N - (a*1000))
s846076831
Accepted
33
9,148
80
N = int(input()) b = N % 1000 if b == 0: print(0) else: print(1000 - b)
s374633682
p03485
u100800700
2,000
262,144
Wrong Answer
17
2,940
97
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = map(int,input().split()) if (a + b) % 2 == 0: print((a + b)/2) else: print((a + b +1)/2)
s047729012
Accepted
17
2,940
47
a,b=map(int,input().split());print(0--(a+b)//2)
s330888233
p02397
u169794024
1,000
131,072
Wrong Answer
20
7,572
72
Write a program which reads two integers x and y, and prints them in ascending order.
x,y=map(int,input().split()) if x==0 and y==0: brake print(sort(x,y))
s927406822
Accepted
60
7,632
97
while True: x,y=sorted ([int(x) for x in input().split()]) if (x,y)==(0,0): break print(x,y)
s947811319
p02417
u387507798
1,000
131,072
Wrong Answer
20
5,560
247
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
import sys cs = {c: 0 for c in list("abcdefghijklmnopqrstuvwxys")} for c in list(sys.stdin.read()): c = c.lower() if c in cs.keys(): cs[c] = cs[c] + 1 for (k, v) in sorted(list(cs.items())): print('{0} : {1}'.format(k, v))
s898091463
Accepted
20
5,576
249
import sys cs = { c : 0 for c in list("abcdefghijklmnopqrstuvwxyz")} for c in list(sys.stdin.read()): c = c.lower() if c in cs.keys(): cs[c] = cs[c] + 1 for (c,cnt) in sorted(list(cs.items())): print('{0} : {1}'.format(c,cnt))
s632652630
p03795
u601082779
2,000
262,144
Wrong Answer
17
2,940
37
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n=int(input());print(n*800-200*n//15)
s468025116
Accepted
17
2,940
37
n=int(input());print(n*800-n//15*200)
s731543780
p03160
u436173409
2,000
1,048,576
Wrong Answer
137
13,980
192
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 = [int(e) for e in input().split()] dp = [0, abs(h[1]-h[0])] for i in range(2,n): dp.append(min(abs(h[i]-h[i-2]),(abs(h[i]-h[i-1])+abs(h[i-1]-h[i-2])))) print(dp[-1])
s811499197
Accepted
122
13,928
185
n = int(input()) h = [int(e) for e in input().split()] dp = [0, abs(h[1]-h[0])] for i in range(2,n): dp.append(min(dp[-1]+abs(h[i]-h[i-1]),dp[-2]+abs(h[i]-h[i-2]))) print(dp[-1])
s497016087
p03167
u113971909
2,000
1,048,576
Wrong Answer
1,702
21,748
620
There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left. For each i and j (1 \leq i \leq H, 1 \leq j \leq W), Square (i, j) is described by a character a_{i, j}. If a_{i, j} is `.`, Square (i, j) is an empty square; if a_{i, j} is `#`, Square (i, j) is a wall square. It is guaranteed that Squares (1, 1) and (H, W) are empty squares. Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square. Find the number of Taro's paths from Square (1, 1) to (H, W). As the answer can be extremely large, find the count modulo 10^9 + 7.
from collections import deque mod=10**9+7 H,W = map(int,input().split()) Gd = [list(input()) for _ in range(H)] INF = 0 direc = [[1,0],[0,1]] def dfs(start): Rt = [[INF]*W for _ in range(H)] Rt[start[0]][start[1]]=1 q = deque([]) q.append(start) while len(q)!=0: h,w = q.pop()取りだし(後ろ) for d in direc: hs, ws = h + d[0], w + d[1] if not (0<=hs<H and 0<=ws<W): continue if Gd[hs][ws]=='.': if Rt[hs][ws]==INF: q.append([hs,ws]) Rt[hs][ws] = (Rt[hs][ws] + Rt[h][w])%mod return Rt[H-1][W-1] print(dfs([0,0]))
s230031802
Accepted
1,920
51,848
926
#!/usr/bin python3 # -*- coding: utf-8 -*- H, W = map(int,input().split()) sth, stw = 0, 0 glh, glw = H-1, W-1 INF = 0 Gmap = [list(input()) for _ in range(H)] Dist = [[INF]*W for _ in range(H)] direc = {(1,0), (0,1)} mod = 10**9+7 from collections import deque def bfs(init): next_q = deque([]) for hi, hw in init: next_q.append([hi,hw]) Dist[hi][hw] = 1 while len(next_q)!=0: h,w = next_q.popleft() for d in direc: hs, ws = h + d[0], w + d[1] if not (0<=hs<H and 0<=ws<W): continue if Gmap[hs][ws]=='.': if Dist[hs][ws]==INF: next_q.append([hs,ws]) Dist[hs][ws] += Dist[h][w] Dist[hs][ws] %= mod return Dist def main(): ret = bfs([[sth, stw]]) print(ret[glh][glw]) if __name__ == '__main__': main()
s026060769
p02972
u133936772
2,000
1,048,576
Wrong Answer
2,104
10,708
222
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())) l=[0]*n for i in range(n): if a[i]: i+=1 for j in range(int(i**.5)): j+=1 if i%j<1: l[j-1]^=1 if j*j<i: l[i//j-1]^=1 print(*l)
s678648610
Accepted
195
11,700
154
n=int(input()) l=list(map(int,input().split())) for i in range(n//2,0,-1): l[i-1]=sum(l[i-1::i])%2 print(sum(l)) print(*[i+1 for i in range(n) if l[i]])
s510594630
p04043
u308695322
2,000
262,144
Wrong Answer
17
2,940
195
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.
require = ['5','7','5'] data = input().split() result = True for d in data: if d in require: require.pop(require.index(d)) else: result = False break print(result)
s087980733
Accepted
17
2,940
202
require = ['5','7','5'] data = input().split() result = 'YES' for d in data: if d in require: require.pop(require.index(d)) else: result = 'NO' break print(result)
s471283153
p03407
u207707177
2,000
262,144
Wrong Answer
17
2,940
84
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
a,b,c = [int(i) for i in range(3)] if a+b>=c: print("Yes") else: print("No")
s593147257
Accepted
18
2,940
95
a,b,c = [int(i) for i in input().split()] if a + b >= c: print("Yes") else: print("No")
s539440265
p02865
u111559399
2,000
1,048,576
Wrong Answer
17
2,940
89
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
A = input() if (int( A )%2) == 0: print( int(A) / 2 ) else: print( (int(A)-1)/2 )
s249175106
Accepted
17
2,940
102
N = input() if (int( N )%2) == 0: print( int(int(N) / 2 -1) ) else: print( int((int(N)-1)/2) )
s855146905
p03494
u045953894
2,000
262,144
Time Limit Exceeded
2,104
16,080
197
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n =int(input()) nums = list(map(int,input().split())) ans = 0 while True: for i in range(n): if nums[i] % 2 == 0: nums[i] = nums[i] / 2 else: print(ans) break ans += 1
s011838603
Accepted
19
2,940
163
n = int(input()) A = [int(x) for x in input().split()] c = 0 while all(a % 2 == 0 for a in A): A = [a / 2 for a in A] c += 1 print(c)
s264183885
p02406
u482227082
1,000
131,072
Time Limit Exceeded
9,990
5,576
186
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; }
n = int(input()) i = 1 while True: x = i if x % 3 == 0 or x % 10 ==3 or x/10 == 0: print(" %d" %i) i+=1 if i > n: print() break
s058833421
Accepted
20
5,636
395
# # 5d # def main(): n = int(input()) s = "" for i in range(1, n+1): x = i if x % 3 == 0 or x % 10 == 3: s += " " + str(i) else: x //= 10 while x: if x % 10 == 3: s += " " + str(i) break x //= 10 print(s) if __name__ == '__main__': main()
s087713253
p02844
u348868667
2,000
1,048,576
Wrong Answer
2,227
1,981,448
289
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
import itertools N = int(input()) S = input() comb = list(itertools.combinations(list(range(N)),3)) ans = [] for i in comb: pw = [] for j in range(len(comb[0])): pw.append(S[i[j]]) pw = "".join(pw) if pw not in ans: ans.append(pw) print(len(ans)) print(ans)
s060032814
Accepted
741
4,012
436
N = int(input()) S = list(input()) pas = [] for i in range(10): for j in range(10): for k in range(10): pas.append(str(i)+str(j)+str(k)) ans = 0 for pw in pas: if pw[0] in S: ind = S.index(pw[0]) tmp = S[ind+1:] else: continue if pw[1] in tmp: ind = tmp.index(pw[1]) tmp = tmp[ind+1:] else: continue if pw[2] in tmp: ans += 1 print(ans)
s809681459
p02742
u390901183
2,000
1,048,576
Wrong Answer
17
2,940
106
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
H, W = map(int, input().split()) if H * W % 2 == 0: print(H * W / 2) else: print((H * W + 1) / 2)
s904758126
Accepted
17
2,940
153
H, W = map(int, input().split()) if H == 1 or W == 1: print(1) exit() if H * W % 2 == 0: print(H * W // 2) else: print((H * W + 1) // 2)
s266302746
p02936
u502731482
2,000
1,048,576
Wrong Answer
2,106
22,772
472
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.
from collections import deque n, q = map(int, input().split()) cnt = [0] * n a, b = [0] * (n - 1), [0] * (n - 1) for i in range(n - 1): a[i], b[i] = map(int, input().split()) def dfs(a, b, s, x): cnt[s - 1] += x if s not in a: return for i in range(n - 1): if a[i] == s: dfs(a, b, b[i], x) for i in range(q): p, x = map(int, input().split()) dfs(a, b, p, x) for i in range(n): print(cnt[i], end = " ") print()
s780151027
Accepted
1,852
230,932
506
import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline n, q = map(int, input().split()) cnt = [0] * n tree = [[] for i in range(n)] for i in range(n - 1): a, b = map(int, input().split()) tree[a - 1].append(b - 1) tree[b - 1].append(a - 1) for i in range(q): p, x = map(int, input().split()) cnt[p - 1] += x def dfs(cur, par): for chi in tree[cur]: if chi == par: continue cnt[chi] += cnt[cur] dfs(chi, cur) dfs(0, -1) print(*cnt)
s809719042
p03737
u190178779
2,000
262,144
Wrong Answer
28
9,048
248
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
import sys S = list(map(str,input().split())) for I in S: if not I.islower(): sys.exit() if len(I) < 0 or len(I) > 10: sys.exit() result = "" for J in S: print(J[0:1]) result = result + J[0:1] print(result.upper())
s183916550
Accepted
27
9,052
230
import sys S = list(map(str,input().split())) for I in S: if not I.islower(): sys.exit() if len(I) < 0 or len(I) > 10: sys.exit() result = "" for J in S: result = result + J[0:1] print(result.upper())
s485754935
p03860
u346474533
2,000
262,144
Wrong Answer
17
2,940
72
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s = input().split() print(s) for t in s: print(t[0], end='') print()
s670228226
Accepted
17
2,940
65
s = input().split() for t in s: print(t[0], end='') print('')
s194310734
p03485
u294376483
2,000
262,144
Wrong Answer
17
3,060
165
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = input().split() x = (int(a) + int(b)) / 2 print(x) ans = 0 if (int(a) + int(b)) % 2 == 0: ans = x else: ans = (int(a) + int(b)) // 2 + 1 print(ans)
s793430983
Accepted
19
3,060
150
a, b = input().split() ans = 0 if (int(a) + int(b)) % 2 == 0: ans = (int(a) + int(b)) // 2 else: ans = (int(a) + int(b)) // 2 + 1 print(ans)
s471921047
p03557
u426572476
2,000
262,144
Wrong Answer
1,821
24,820
2,809
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
from itertools import permutations import sys import heapq from collections import Counter from collections import deque from fractions import gcd from math import factorial from math import sqrt INF = 1 << 60 sys.setrecursionlimit(10 ** 6) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) # def is_ok(arg): # ''' # ''' # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if is_ok(mid): # ok = mid # else: # ng = mid # return ok n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() c.sort() def is_ok(index, key, x): if x[index] >= key: return True return False def meguru_bisect(ng, ok, key, x): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid, key, x): ok = mid else: ng = mid return ok ans = 0 # print("a =", a) # print("b =", b) # print("c =", c) for i in b: total1 = 0 total2 = 0 if i > a[0]: total1 = meguru_bisect(-1, n, i, a) if i < c[-1]: total2 = n - meguru_bisect(-1, n, i, c) if i == c[meguru_bisect(-1, n, i, c)]: total2 -= 1 ans += total1 * total2 print(ans)
s149170785
Accepted
1,317
31,248
5,119
import sys import heapq import re from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from math import factorial, sqrt, ceil, gcd from functools import lru_cache, reduce from decimal import Decimal from operator import mul INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10 ** 7) # UnionFind class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def dijkstra_heap(s, edge, n): d = [10**20] * n used = [True] * n d[s] = 0 used[s] = False edgelist = [] for a,b in edge[s]: heapq.heappush(edgelist,a*(10**6)+b) while len(edgelist): minedge = heapq.heappop(edgelist) if not used[minedge%(10**6)]: continue v = minedge%(10**6) d[v] = minedge//(10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1]) return d def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def combinations_count(n, r): if n < r: return 0 r = min(r, n - r) numer = reduce(mul, range(n, n - r, -1), 1) denom = reduce(mul, range(1, r + 1), 1) return numer // denom def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(numbers): return reduce(lcm, numbers, 1) def gcd_list(numbers): return reduce(gcd, numbers) def is_prime(n): if n <= 1: return False p = 2 while True: if p ** 2 > n: break if n % p == 0: return False p += 1 return True def eratosthenes(limit): A = [i for i in range(2, limit+1)] P = [] while True: prime = min(A) if prime > sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P def permutation_with_duplicates(L): if L == []: return [[]] else: ret = [] S = sorted(set(L)) for i in S: data = L[:] data.remove(i) for j in permutation_with_duplicates(data): ret.append([i] + j) return ret def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] n = int(input()) a = sorted(list(map(int, input().split())), reverse=True) b = list(map(int, input().split())) c = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): ng = -1 ok = n while abs(ok - ng) > 1: mid = (ok + ng) // 2 if a[mid] < b[i]: ok = mid else: ng = mid ng2 = -1 ok2 = n while abs(ok2 - ng2) > 1: mid2 = (ok2 + ng2) // 2 if c[mid2] > b[i]: ok2 = mid2 else: ng2 = mid2 # print("ok =", ok) # print("ok2 =", ok2) ans += (n - ok) * (n - ok2) print(ans)
s381474274
p03471
u259861571
2,000
262,144
Wrong Answer
21
3,060
363
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
n, y = [int(i) for i in input().split()] ans_l = -1 ans_c = -1 ans_r = -1 for i in range(0, n): for j in range(0, n): k = n - i - j total = i + j + k if total == n: ans_l = str(i) ans_c = str(j) ans_r = str(k) break print(ans_l + " " + ans_c + " " + ans_r)
s754305502
Accepted
896
3,064
293
n, y = [int(i) for i in input().split()] ans = [-1, -1, -1] for i in range(n+1): for j in range(n-i+1): k = n - i - j total = 10000*i+5000*j+1000*k if total == y: ans = [i, j, k] break print(ans[0],ans[1],ans[2])
s286209158
p02833
u982591663
2,000
1,048,576
Wrong Answer
18
3,064
803
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
N = int(input()) ans = 0 def check_ten(N): count = 0 i = 10 exp = 1 while True: divided = N // i if divided == 0: break count += divided exp += 1 i = i ** exp print("check_ten", count) return count def check_five(N): count = 0 i = 5 exp = 1 while True: divided = N // i if divided == 0: break count += divided exp += 1 i = i ** exp print("check_five", count) return count if N % 2 == 0: ans = check_ten(N) else: ans = check_five(N) - check_ten(N) if N < 9: ans = 0 print(ans) # if N % 2 == 1: # else:
s127106101
Accepted
17
3,064
318
N = int(input()) ans = 0 def check_five(N): count = 0 i = 5 exp = 1 while True: divided = N // i if divided == 0: break count += divided exp += 1 i = 5 ** exp return count if N % 2 == 0: ans = check_five(N//2) else: ans = 0 print(ans)
s957268340
p03672
u777028980
2,000
262,144
Wrong Answer
17
3,060
200
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
hoge=input() for i in range(len(hoge)): n=int(len(hoge)/2) print(hoge[n:]) print(hoge[:n]) if(hoge[n:]==hoge[:n]): print(2*n) break else: hoge=hoge[:len(hoge)-1] print(hoge)
s544671523
Accepted
18
2,940
138
hoge=input() for i in range(len(hoge)): hoge=hoge[:len(hoge)-1] n=int(len(hoge)/2) if(hoge[n:]==hoge[:n]): print(2*n) break
s701021266
p02663
u558242240
2,000
1,048,576
Wrong Answer
24
9,048
98
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
h1, m1, h2, m2, k = map(int, input().split()) print(min(0, (h2 * 60 + m2 - k) - (h1 * 60 + m1)))
s104445998
Accepted
21
9,164
90
h1, m1, h2, m2, k = map(int, input().split()) print((h2 * 60 + m2) - (h1 * 60 + m1) - k)
s027980412
p02613
u112007848
2,000
1,048,576
Wrong Answer
152
9,220
340
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
num = (int)(input()) ans = [0, 0, 0, 0] for i in range(num): temp = input() if temp == "AC": ans[0] += 1 elif temp == "WA": ans[1] += 1 elif temp == "TLE": ans[2] += 1 else: ans[3] += 1 print("AC × " + (str)(ans[0])) print("WA × " + (str)(ans[1])) print("TLE × " + (str)(ans[2])) print("RE × " + (str)(ans[3]))
s843465522
Accepted
152
9,216
336
num = (int)(input()) ans = [0, 0, 0, 0] for i in range(num): temp = input() if temp == "AC": ans[0] += 1 elif temp == "WA": ans[1] += 1 elif temp == "TLE": ans[2] += 1 else: ans[3] += 1 print("AC x " + (str)(ans[0])) print("WA x " + (str)(ans[1])) print("TLE x " + (str)(ans[2])) print("RE x " + (str)(ans[3]))
s688011155
p03399
u663710122
2,000
262,144
Wrong Answer
17
2,940
77
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
print(min(min(int(input()), int(input())), min(int(input()), int(input()))))
s954605054
Accepted
17
2,940
72
print(min(int(input()), int(input())) + min(int(input()), int(input())))
s984097629
p03598
u260764792
2,000
262,144
Wrong Answer
17
3,060
201
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
N=int(input()) K=int(input()) c=list(map(int, input().split())) l=[K]*N sub=[] res=[] for i in range(0, N): sub.append(l[i]-c[i]) if (sub[i]<=c[i]): res.append(2*sub[i]) else: res.append(2*c[i])
s005692759
Accepted
17
3,064
217
N=int(input()) K=int(input()) c=list(map(int, input().split())) l=[K]*N sub=[] res=[] for i in range(0, N): sub.append(l[i]-c[i]) if (sub[i]<=c[i]): res.append(2*sub[i]) else: res.append(2*c[i]) print(sum(res))
s634883860
p02665
u541610817
2,000
1,048,576
Wrong Answer
983
682,396
876
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
def Z(): return int(input()) def ZZ(): return [int(_) for _ in input().split()] def main(): N = Z() A = ZZ() if A[0] != 0: print(-1) return v = [[1, 1] for _ in range(N+1)] for i in range(N): x = v[i][1] - A[i] if x < 0: print(-1) return v[i+1][1] = 2 * x if v[N][0] > A[N] or A[N] > v[N][1]: print(-1) return v[N] = [A[N], A[N]] for i in range(N): x = (v[N-i][0]+1)//2 + A[N-i-1] y = v[N-i][1] + A[N-i-1] v[N-i-1][0] = max(v[N-i-1][0], x) v[N-i-1][1] = min(v[N-i-1][1], y) v[N-i-1][0] += A[N-i-1] if v[N-i-1][0] > v[N-i-1][1]: print(-1) break v[0] = [1, 1] output = 0 for i in range(N+1): output += v[i][1] print(output) return if __name__ == '__main__': main()
s099746232
Accepted
870
682,172
904
def Z(): return int(input()) def ZZ(): return [int(_) for _ in input().split()] def main(): N, A = Z(), ZZ() if N == 0 and A[0] == 1: print(1) return if A[0] != 0: print(-1) return v = [[1, 1] for _ in range(N+1)] for i in range(N): x = v[i][1] - A[i] if x < 0: print(-1) return v[i+1][1] = 2 * x if v[N][0] > A[N] or A[N] > v[N][1]: print(-1) return v[N] = [A[N], A[N]] for i in range(N): x = (v[N-i][0]+1)//2 + A[N-i-1] y = v[N-i][1] + A[N-i-1] v[N-i-1][0] = max(v[N-i-1][0], x) v[N-i-1][1] = min(v[N-i-1][1], y) if v[N-i-1][0] > v[N-i-1][1]: print(-1) return v[0] = [1, 1] output = 0 for i in range(N+1): output += v[i][1] print(output) return if __name__ == '__main__': main()
s442678744
p03720
u543954314
2,000
262,144
Wrong Answer
17
2,940
140
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n, m = map(int, input().split()) a = [] for i in range(m): a += list(map(int, input().split())) for i in range(n): print(a.count(i))
s877016856
Accepted
18
2,940
139
n, m = map(int, input().split()) a = [] for i in range(m): a += map(int, input().split()) for i in range(1, n+1): print(a.count(i))
s875570038
p03598
u171366497
2,000
262,144
Wrong Answer
17
2,940
92
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
N=int(input()) K=int(input()) ans=0 for x in map(int,input().split()): ans+=2*min(x,K-x)
s434026357
Accepted
17
2,940
103
N=int(input()) K=int(input()) ans=0 for x in map(int,input().split()): ans+=2*min(x,K-x) print(ans)
s493921689
p03992
u969190727
2,000
262,144
Wrong Answer
18
2,940
32
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
s=input() print(s[:5]+" "+s[4:])
s997895538
Accepted
17
2,940
32
s=input() print(s[:4]+" "+s[4:])
s517355285
p02646
u219494936
2,000
1,048,576
Wrong Answer
23
9,176
188
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
A, V = map(int, input().split(" ")) B, W = map(int, input().split(" ")) T = int(input()) D = B - A S = W - V if S <= 0: print("NO") elif D / S <= T: print("YES") else: print("NO")
s812265777
Accepted
19
9,144
717
A, V = map(int, input().split(" ")) B, W = map(int, input().split(" ")) T = int(input()) if W > V: print("NO") else: if abs(A - B) <= T * (V - W): print("YES") else: print("NO") # if A - B > 0: # if (B + 10**9) / W <= T: # # print("left reach") # Bdist = (B + 10**9) # else: # Bdist = W * T # else: # if (10**9 - B) / W <= T: # # print("right reach") # else: # # print("run right") # Bdist = W * T # Adist = V * T # if Bdist + abs(A - B) <= Adist: # print("YES") # else: # print("NO")
s043353163
p03583
u934442292
2,000
262,144
Wrong Answer
1,012
9,128
357
You are given an integer N. Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w. If there are multiple solutions, any of them will be accepted.
import sys input = sys.stdin.readline def main(): N = int(input()) for h in range(1, 3501): for n in range(1, 3501): a = h * n b = 4 * h * n - (n + h) * N if b > 0 and a % b == 0: w = a // b print(h, n, w) exit() if __name__ == "__main__": main()
s207382573
Accepted
1,158
9,180
361
import sys input = sys.stdin.readline def main(): N = int(input()) for h in range(1, 3501): for n in range(1, 3501): a = h * n * N b = 4 * h * n - (n + h) * N if b > 0 and a % b == 0: w = a // b print(h, n, w) exit() if __name__ == "__main__": main()
s249610575
p03997
u344959959
2,000
262,144
Wrong Answer
26
8,996
75
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) c = int(input()) S = ((a+b)*c)/2 print(S)
s711087832
Accepted
24
9,048
80
a = int(input()) b = int(input()) h = int(input()) S = (a+b)*h/2 print(round(S))
s835958799
p03605
u808593466
2,000
262,144
Wrong Answer
17
2,940
77
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
N = input() if N[0] == 9 or N[1] == 9: print("Yes") else: print("No")
s321273677
Accepted
17
2,940
81
N = input() if N[0] == "9" or N[1] == "9": print("Yes") else: print("No")
s168133422
p03493
u257226830
2,000
262,144
Wrong Answer
17
2,940
51
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
s1,s2,s3 = map(int,input()) s=[s1,s2,s3] s.count(1)
s218998576
Accepted
17
2,940
58
s1,s2,s3 = map(int,input()) s=[s1,s2,s3] print(s.count(1))
s443156452
p03024
u908349502
2,000
1,048,576
Wrong Answer
17
2,940
93
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
s = input() win = s.count('o') if win + (15-len(s)) >= 8: print('Yes') else: print('No')
s286781248
Accepted
18
2,940
94
s = input() win = s.count('o') if win + (15-len(s)) >= 8: print('YES') else: print('NO')
s461884270
p02936
u971091945
2,000
1,048,576
Wrong Answer
1,988
63,560
284
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()) ab = [list(map(int,input().split())) for _ in range(n-1)] ab.sort() li = [0]*n for i in range(q): p, x = map(int, input().split()) li[p-1] += x for i in range(n-1): a, b = ab[i] li[b-1] += li[a-1] for j in li: print(j, end=" ")
s797306249
Accepted
1,589
268,400
456
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 6) n, q = map(int, input().split()) e = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) e[a-1].append(b-1) e[b-1].append(a-1) li = [0]*n for i in range(q): p, x = map(int, input().split()) li[p-1] += x def dfs(i=0, r=-1): for j in e[i]: if j != r: li[j] += li[i] dfs(j, i) dfs() print(*li)
s178112697
p03377
u773246942
2,000
262,144
Wrong Answer
17
2,940
119
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 > X: print("No") elif A + B < X: print("No") else: print("Yes")
s367552707
Accepted
17
2,940
119
A,B,X = list(map(int, input().split())) if A > X: print("NO") elif A + B < X: print("NO") else: print("YES")
s159649877
p03759
u910358825
2,000
262,144
Wrong Answer
24
9,056
71
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c=map(int, input().split()) print("Yes" if b-a==c-b else "No")
s805317907
Accepted
26
8,952
71
a,b,c=map(int, input().split()) print("YES" if b-a==c-b else "NO")
s248331446
p03455
u391475811
2,000
262,144
Wrong Answer
17
2,940
146
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(str,input().split()) C=A+B res=False for i in range(2,1000): if i*i==int(C): res=True if res: print("Yes") else: print("No")
s158606066
Accepted
17
2,940
89
A,B=map(int,input().split()) if A%2==1 and B%2==1: print("Odd") else: print("Even")
s314950972
p02850
u683134447
2,000
1,048,576
Wrong Answer
993
87,672
679
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 sys.setrecursionlimit(10**9) n = int(input()) abl = [] nodes = [[] for i in range(n)] for _ in range(n-1): a,b = map(int,input().split()) abl.append((a,b)) nodes[a-1] += [b-1] nodes[b-1] += [a-1] m_node = 0 for e in nodes: m_node = max(len(e), m_node) use_node = [0 for i in range(n)] dic = {} def dfs(node, start_color): use_node[node] = 1 for e in nodes[node]: if use_node[e] == 0: dic[(node,e)] = (start_color%m_node)+1 dic[(e,node)] = (start_color%m_node)+1 dfs(e, (start_color%m_node)+1) start_color += 1 dfs(0,0) for a,b in abl: print(dic[(a-1,b-1)])
s465290086
Accepted
795
87,676
692
import sys sys.setrecursionlimit(10**9) n = int(input()) abl = [] nodes = [[] for i in range(n)] for _ in range(n-1): a,b = map(int,input().split()) abl.append((a,b)) nodes[a-1] += [b-1] nodes[b-1] += [a-1] m_node = 0 for e in nodes: m_node = max(len(e), m_node) use_node = [0 for i in range(n)] dic = {} def dfs(node, start_color): use_node[node] = 1 for e in nodes[node]: if use_node[e] == 0: dic[(node,e)] = (start_color%m_node)+1 dic[(e,node)] = (start_color%m_node)+1 dfs(e, (start_color%m_node)+1) start_color += 1 dfs(0,0) print(m_node) for a,b in abl: print(dic[(a-1,b-1)])
s523481093
p03494
u552510302
2,000
262,144
Wrong Answer
18
3,060
124
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
a = int(input()) b = list(map(int,input().split())) b.sort() ans = 0 n = b[0] while n % 2 ==0: ans +=1 n = n//2 print(ans)
s806327801
Accepted
20
3,060
203
a = int(input()) b = list(map(int,input().split())) ans = 0 x = True while x: for i in range(a): if b[i] %2 ==1: x=False break b[i] = b[i] /2 ans +=1 ans = ans//a print(ans)
s240374843
p03487
u300579805
2,000
262,144
Wrong Answer
99
21,744
224
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
import collections N = int(input()) A=list(map(int, input().split())) C = dict(collections.Counter(A)) print(C) ans = 0 for k, v in C.items(): if (k>v): ans += v elif(k<v): ans += v-k print(ans)
s779716838
Accepted
82
21,744
215
import collections N = int(input()) A=list(map(int, input().split())) C = dict(collections.Counter(A)) ans = 0 for k, v in C.items(): if (k>v): ans += v elif(k<v): ans += v-k print(ans)
s123094318
p02578
u120789505
2,000
1,048,576
Wrong Answer
33
9,128
511
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
n = 2 * 10**5 # = int(input()) data = list(map(int, input().split(' '))) before_max = 0 dai = 0 for i in range(len(data)): if(i == 0): before_max = data[i] else: if(before_max < data[i]): before_max = data[i] continue elif(before_max > data[i]): dai += before_max - data[i] print(dai)
s474104286
Accepted
135
32,228
497
n = int(input()) data = list(map(int, input().split(' '))) before_max = 0 dai = 0 for i in range(len(data)): if(i == 0): before_max = data[i] else: if(before_max < data[i]): before_max = data[i] continue elif(before_max > data[i]): dai += before_max - data[i] print(dai)