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
s416797330
p02578
u684849102
2,000
1,048,576
Wrong Answer
130
32,364
165
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 = int(input()) A = list(map(int, input().split())) a=0 result=0 for i in range(n-1): if A[i] > A[i+1]: a = A[i] - A[i+1] result += a print(result)
s119727384
Accepted
154
32,188
181
n = int(input()) A = list(map(int, input().split())) a=0 result=0 for i in range(n-1): if A[i] > A[i+1]: a = A[i] - A[i+1] A[i+1] += a result += a print(result)
s168291316
p03470
u150985282
2,000
262,144
Wrong Answer
19
2,940
161
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
N = int(input()) d = list(map(int, [input() for i in range(N)])) d.sort() count = 0 for i in range(0, N-1): if d[i] < d[i+1]: count += 1 print(count)
s415994459
Accepted
17
3,064
219
N = int(input()) d = list(map(int, [input() for i in range(N)])) bucket = [0 for i in range(110)] for i in range(N): bucket[d[i]] += 1 count = 0 for i in range(110): if bucket[i] != 0: count += 1 print(count)
s871243969
p03408
u129978636
2,000
262,144
Wrong Answer
19
3,188
291
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 = list() for i in range(N): S = input() s.append(S) M = int( input()) t = list() for j in range(M): T = input() t.append(T) judge = 0 for l in range(N): money = s.count(s[i]) - t.count(s[i]) if( judge < money): judge = money print('judge')
s456691019
Accepted
17
3,060
256
N = int( input()) s = [ input() for i in range(N)] M = int(input()) t = [ input() for j in range(M)] judge = 0 for l in range(N): money = s.count(s[l]) - t.count(s[l]) if( judge < money): judge = money else: continue print(judge)
s848817675
p03854
u693048766
2,000
262,144
Wrong Answer
59
3,188
653
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
s = input() curs = [0] while True: next_curs = [] break_ = False for c in curs: #print(c) if s[c:c+5] == 'dream': next_curs.append( c+5 ) if len(s) == c+5: break_ = True if s[c:c+7] == 'dreamer': next_curs.append( c+7 ) if len(s) == c+7: break_ = True if s[c:c+5] == 'erase': next_curs.append( c+5 ) if len(s) == c+5: break_ = True if s[c:c+6] == 'eraser': next_curs.append( c+6 ) if len(s) == c+6: break_ = True if next_curs == []: print('No') break if break_: print('Yes') break curs = next_curs
s281689260
Accepted
60
3,188
653
s = input() curs = [0] while True: next_curs = [] break_ = False for c in curs: #print(c) if s[c:c+5] == 'dream': next_curs.append( c+5 ) if len(s) == c+5: break_ = True if s[c:c+7] == 'dreamer': next_curs.append( c+7 ) if len(s) == c+7: break_ = True if s[c:c+5] == 'erase': next_curs.append( c+5 ) if len(s) == c+5: break_ = True if s[c:c+6] == 'eraser': next_curs.append( c+6 ) if len(s) == c+6: break_ = True if next_curs == []: print('NO') break if break_: print('YES') break curs = next_curs
s618122535
p04012
u677393869
2,000
262,144
Wrong Answer
17
2,940
100
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
N=input() for i in N: if N.count(i)%2==0: pass else: print("NO") exit() print("YES")
s846259884
Accepted
25
9,004
239
N = input() ans_num = 0 set_N = list(set(N)) for i in set_N: if N.count(i) % 2 == 1: ans_num = 1 break else: continue if ans_num == 0: print('Yes') else : print('No')
s485439972
p03455
u728774856
2,000
262,144
Wrong Answer
17
2,940
88
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if (a * b ) % 2: print('odd') else: print('even')
s298065925
Accepted
17
2,940
100
a, b = map(int, input().split()) if a % 2 == 0 or b % 2 == 0: print('Even') else: print('Odd')
s969945549
p03998
u703890795
2,000
262,144
Wrong Answer
17
3,064
571
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.
Sa = input() Sb = input() Sc = input() pl = 0 while(True): if pl == 0: s = Sa[0] if s == "a": pl = 0 elif s == "b": pl = 1 else: pl = 2 Sa = Sa[1:] elif pl == 1: s = Sb[0] if s == "a": pl = 0 elif s == "b": pl = 1 else: pl = 2 Sb = Sb[1:] else: s = Sc[0] if s == "a": pl = 0 elif s == "b": pl = 1 else: pl = 2 Sc = Sc[1:] if len(Sa)==0: print("A") break elif len(Sb)==0: print("B") break elif len(Sc)==0: print("C") break
s484993650
Accepted
17
3,064
601
Sa = input() Sb = input() Sc = input() pl = 0 while(True): if len(Sa)==0 and pl==0: print("A") break elif len(Sb)==0 and pl==1: print("B") break elif len(Sc)==0 and pl==2: print("C") break if pl == 0: s = Sa[0] if s == "a": pl = 0 elif s == "b": pl = 1 else: pl = 2 Sa = Sa[1:] elif pl == 1: s = Sb[0] if s == "a": pl = 0 elif s == "b": pl = 1 else: pl = 2 Sb = Sb[1:] else: s = Sc[0] if s == "a": pl = 0 elif s == "b": pl = 1 else: pl = 2 Sc = Sc[1:]
s047332820
p00168
u844945939
1,000
131,072
Wrong Answer
30
6,748
165
一郎君の家の裏山には観音堂があります。この観音堂まではふもとから 30 段の階段があり、一郎君は、毎日のように観音堂まで遊びに行きます。一郎君は階段を1足で3段まで上がることができます。遊んでいるうちに階段の上り方の種類(段の飛ばし方の個数)が非常にたくさんあることに気がつきました。 そこで、一日に 10 種類の上り方をし、すべての上り方を試そうと考えました。しかし数学を熟知しているあなたはそんなことでは一郎君の寿命が尽きてしまうことを知っているはずです。 一郎君の計画が実現不可能であることを一郎君に納得させるために、階段の段数 n を入力とし、一日に 10 種類の上り方をするとして、一郎君がすべての上り方を実行するのに要する年数を出力するプログラムを作成してください。一年は 365 日として計算してください。一日でも必要なら一年とします。365 日なら 1 年であり、366 日なら 2 年となります。
a = [1, 1, 2] for i in range(3, 31): a.append(sum(a[-3:])) while True: n = int(input()) if not n: break print(((a[n] + 9) / 10 + 364) / 365)
s391713949
Accepted
30
6,720
161
a = [1] for i in range(1, 31): a.append(sum(a[-3:])) while True: n = int(input()) if not n: break print(((a[n] + 9) // 10 + 364) // 365)
s974875879
p03593
u405660020
2,000
262,144
Wrong Answer
24
3,680
810
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter. Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition: * Every row and column in A' can be read as a palindrome. Determine whether he can create a matrix satisfying the condition.
from collections import Counter import math h, w = map(int,input().split()) a = [list(input()) for _ in range(h)] c=Counter(sum(a,[])) if h%2==0 and w%2==0: g1=0 g2=0 g4=(h//2)*(w//2) elif h%2==1 and w%2==0: g1=0 g2=w//2 g4=(h//2)*(w//2) elif h%2==0 and w%2==1: g1=0 g2=h//2 g4=(h//2)*(w//2) else: g1=1 g2=(h//2)+(w//2) g4=(h//2)*(w//2) print(c) g1_cnt=0 g2_cnt=0 g4_cnt=0 for key in c: if c[key]%4==1: g1_cnt+=1 g4_cnt+=c[key]//4 elif c[key]%4==2: g2_cnt+=1 g4_cnt+=c[key]//4 elif c[key]%4==2: g1_cnt+=1 g2_cnt+=1 g4_cnt+=c[key]//4 else: g4_cnt+=c[key]//4 # print(g1,g2,g4) # print(g1_cnt,g2_cnt,g4_cnt) print('Yes' if g1==g1_cnt and g2==g2_cnt and g4==g4_cnt else 'No')
s206634291
Accepted
23
3,680
927
from collections import Counter import math h, w = map(int,input().split()) a = [list(input()) for _ in range(h)] c=Counter(sum(a,[])) if h%2==0 and w%2==0: g1=0 g2=0 g4=(h//2)*(w//2) elif h%2==1 and w%2==0: g1=0 g2=w//2 g4=(h//2)*(w//2) elif h%2==0 and w%2==1: g1=0 g2=h//2 g4=(h//2)*(w//2) else: g1=1 g2=(h//2)+(w//2) g4=(h//2)*(w//2) g1_cnt=0 g2_cnt=0 g4_cnt=0 for key in c: if c[key]%4==1: g1_cnt+=1 g4_cnt+=c[key]//4 elif c[key]%4==2: g2_cnt+=1 g4_cnt+=c[key]//4 elif c[key]%4==2: g1_cnt+=1 g2_cnt+=1 g4_cnt+=c[key]//4 else: g4_cnt+=c[key]//4 # print(g1,g2,g4) # print(g1_cnt,g2_cnt,g4_cnt) flag=False if g1==g1_cnt: if g2==g2_cnt and g4==g4_cnt: flag=True elif g2_cnt<g4_cnt and g2>g4 and g2*2+g4*4==g2_cnt*2+g4_cnt*4: flag=True print('Yes' if flag else 'No')
s047455216
p03338
u581603131
2,000
1,048,576
Wrong Answer
17
2,940
79
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
N = int(input()) S = input() print(max(len(set[:i]&set[i:])) for i in range(N))
s411296864
Accepted
18
3,060
85
N = int(input()) S = input() print(max(len(set(S[:i])&set(S[i:])) for i in range(N)))
s055604428
p03095
u595893956
2,000
1,048,576
Wrong Answer
17
3,060
86
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order.
s=input() ret=1 for i in range(97, 97+26): x=s.count(chr(i)) ret*=x+1 print(ret-1)
s090911769
Accepted
20
3,188
128
n=input() s=input() ret=1 for i in range(97, 97+26): x=s.count(chr(i)) ret*=x+1 ret%=1000000007 print((ret-1)%1000000007)
s925192587
p02393
u619570677
1,000
131,072
Wrong Answer
20
7,452
264
Write a program which reads three integers, and prints them in ascending order.
a,b,c = list(map(int,input().split())) if a < b: if a < c: if b < c: print(a < b < c) else: print("a < c < b") else: print("c < a < b") elif a > b: if b < c: if a < c: print("b < a < c") else: print("b < c < a") else: print("c < b < a")
s462821406
Accepted
20
7,656
80
num = list(map(int, input().split())) num.sort() print(num[0], num[1], num[2])
s349681551
p02406
u870718588
1,000
131,072
Wrong Answer
20
7,460
249
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()) for i in range(1, n + 1): x = i if x % 3 == 0: print(" ", i, sep="") else: while x > 0: if x % 10 == 3: print(" ", i, sep="") break x //= 10 print()
s600654312
Accepted
30
8,216
124
n = int(input()) for i in range(1, n + 1): if i % 3 == 0 or "3" in str(i): print(" ", i, sep="", end="") print()
s971259168
p03448
u814663076
2,000
262,144
Wrong Answer
48
3,060
254
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
import sys sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline() A, B, C, X = [int(input()) for i in range(4)] cnt = 0 for a in range(A): for b in range(B): for c in range(C): if 500*a + 100*b + 50*c == X: cnt += 1 print(cnt)
s093346295
Accepted
54
3,060
260
import sys sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline() A, B, C, X = [int(input()) for i in range(4)] cnt = 0 for a in range(A+1): for b in range(B+1): for c in range(C+1): if 500*a + 100*b + 50*c == X: cnt += 1 print(cnt)
s763739457
p03090
u674885198
2,000
1,048,576
Wrong Answer
27
4,244
396
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()) if n%2==0: lis=[[i,n+1-i] for i in range(1,int(n/2)+1)] else: lis=[[i,n-i] for i in range(1,int((n-1)/2)+1)] + [[n]] connect_lis=[] for i in lis: for j in i: for k in lis: if k!=i: for p in k: if j < p: connect_lis.append([j,p]) for i in connect_lis: print(i[0],'',i[1])
s292905651
Accepted
26
4,124
416
n = int(input()) if n%2==0: lis=[[i,n+1-i] for i in range(1,int(n/2)+1)] else: lis=[[i,n-i] for i in range(1,int((n-1)/2)+1)] + [[n]] connect_lis=[] for i in lis: for j in i: for k in lis: if k!=i: for p in k: if j < p: connect_lis.append([j,p]) print(len(connect_lis)) for i in connect_lis: print(i[0],i[1])
s012256307
p02390
u498511622
1,000
131,072
Wrong Answer
20
7,504
82
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
s=int(input()) h=s/3600 s=s%3600 m=s/60 s=s%60 print(str(h),":",str(m),":",str(s))
s550008947
Accepted
20
7,740
143
import math s=int(input()) h=math.floor(s/3600) s=math.floor(s%3600) m=math.floor(s/60) s=math.floor(s%60) print(str(h)+":"+str(m)+":"+str(s))
s711063757
p03149
u794173881
2,000
1,048,576
Wrong Answer
17
3,064
324
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
n1,n2,n3,n4 = map(int,input().split()) if n1==1 or n2==1 or n3==1 or n4==1: if n1==7 or n2==7 or n3==7 or n4==7: if n1==9 or n2==9 or n3==9 or n4==9: if n1==4 or n2==4 or n3==4 or n4==4: print("Yes") else: print("No") else: print("No") else: print("No") else: print("No")
s090814383
Accepted
17
3,064
325
n1,n2,n3,n4 = map(int,input().split()) if n1==1 or n2==1 or n3==1 or n4==1: if n1==7 or n2==7 or n3==7 or n4==7: if n1==9 or n2==9 or n3==9 or n4==9: if n1==4 or n2==4 or n3==4 or n4==4: print("YES") else: print("NO") else: print("NO") else: print("NO") else: print("NO")
s440868245
p02408
u845643816
1,000
131,072
Wrong Answer
30
7,760
224
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
import itertools n = int(input()) c = list(itertools.product(['S', 'H', 'C', 'D'], range(1,14))) for _ in range(n): s, num = input().split() c.remove((s, int(num))) for i in range(4*13 - n): print(*c, sep = '\n')
s764087573
Accepted
30
7,744
226
import itertools n = int(input()) c = list(itertools.product(['S', 'H', 'C', 'D'], range(1,14))) for _ in range(n): s, num = input().split() c.remove((s, int(num))) for i in range(4*13 - n): print(c[i][0], c[i][1])
s993814438
p04030
u016622494
2,000
262,144
Wrong Answer
17
3,060
283
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
S = input() str = [] print(len(S)) result = "" flg = 0 for i in range(len(S)): if flg == 1: flg = 0 continue if S[len(S)-1 - i] == 'b': flg = 1 else: str.append(S[len(S) - 1 - i]) str.reverse() for i in str: result += i print(result)
s642670821
Accepted
17
2,940
161
S = input() str = [] result = "" flg = 0 for i in range(len(S)): if S[i] == 'B': result = result[:-1] else: result += S[i] print(result)
s043054890
p03720
u694946470
2,000
262,144
Wrong Answer
17
3,060
229
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 = [] b = [] for i in range(M): a.append(list(map(int, input().split()))) print (a) a=[flatten for inner in a for flatten in inner] for i in range(N): b.append((a.count(i+1))) print (b)
s353559777
Accepted
17
3,060
273
N, M = map(int,input().split()) a = [] b = [] for i in range(M): a.append(list(map(int, input().split()))) a=[flatten for inner in a for flatten in inner] for i in range(N): b.append((a.count(i+1))) c = list(map(str, b)) answer = '\n'.join(c) print(answer)
s074075341
p03471
u590048048
2,000
262,144
Wrong Answer
2,104
3,572
678
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 = map(int, input().split()) y = y // 1000 print(n, y) def find_by_for(v, n): """ the tuple by example ((0, 0, 0), (10, 5, 1), 100, 10) """ queue = [] queue.append(((0, 0, 0), (1, 5, 10), v, n)) while queue: xs, fv, v, n = queue.pop() if v == 0 and n == 0: return "%d %d %d"%(xs[2], xs[1], xs[0]) elif not fv or v <= 0 or n <= 0: pass else: queue.append((xs, fv[:-1], v, n)) z = list(xs) idx = len(fv) -1 z[idx] +=1 queue.append((tuple(z), fv, v - fv[idx], n -1)) return "-1 -1 -1" print(find_by_for(y, n))
s050010105
Accepted
19
3,064
920
def find_min(v): x = v % 10 return (x % 5, x//5, v // 10) def find_max(v): return (v, 0, 0) def conv10to5(xs): return (xs[0], xs[1] +2, xs[2] - 1) def undoconv10to5(xs): return (xs[0], xs[1] -2, xs[2] + 1) def conv5to1(xs): return (xs[0]+5, xs[1] -1, xs[2]) def next(xs): if xs[2] == 0: if xs[1] == 0: return None else: return conv5to1(xs) else: if xs[1] < 7: return conv10to5(xs) else: return conv5to1(undoconv10to5(undoconv10to5(undoconv10to5(xs)))) def find(v, n): xs = find_min(v) m = sum(xs) if m > n or n > v: return (-1, -1, -1) while xs: if sum(xs) == n: return xs xs = next(xs) return (-1, -1, -1) if __name__ == "__main__": n, y = map(int, input().split()) y = y // 1000 print("{2} {1} {0}".format(*find(y, n)))
s848056225
p03503
u590048048
2,000
262,144
Wrong Answer
240
3,064
520
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
def profit(xs, n, F, P): return sum([P[i][sum(map(lambda x: x[0]*x[1], zip(xs, F[i])))] for i in range(n)]) def vector(k): return [1 if k & 1 << i else 0 for i in range(10)] def foo(n, F, P): return max([profit(vector(i), n, F, P) for pat in range(1, 1024)]) if __name__ == "__main__": n = int(input()) F = {} P = {} for i in range(n): F[i] = list(map(int, input().split())) for i in range(n): P[i] = list(map(int, input().split())) print(foo(n, F, P))
s999096484
Accepted
239
3,188
522
def profit(xs, n, F, P): return sum([P[i][sum(map(lambda x: x[0]*x[1], zip(xs, F[i])))] for i in range(n)]) def vector(k): return [1 if k & 1 << i else 0 for i in range(10)] def foo(n, F, P): return max([profit(vector(pat), n, F, P) for pat in range(1, 1024)]) if __name__ == "__main__": n = int(input()) F = {} P = {} for i in range(n): F[i] = list(map(int, input().split())) for i in range(n): P[i] = list(map(int, input().split())) print(foo(n, F, P))
s019402865
p02264
u548155360
1,000
131,072
Wrong Answer
30
7,616
331
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
n, q = map(int, input().split()) p = [] time = 0 for i in range(n): p.append(input().split()) p[i][1] = int(p[i][1]) print("{0} {1}".format(p[0][0], time)) while(len(p) > 0): if (p[0][1]<= q): time += p[0][1] print("{0} {1}".format(p[0][0], time)) p.pop(0) else: time += q p[0][1] -= q p.append(p[0]) p.pop(0)
s834183402
Accepted
820
19,428
291
n, q = map(int, input().split()) p = [] time = 0 for i in range(n): p.append(input().split()) p[i][1] = int(p[i][1]) while(len(p) > 0): if (p[0][1]<= q): time += p[0][1] print("{0} {1}".format(p[0][0], time)) p.pop(0) else: time += q p[0][1] -= q p.append(p[0]) p.pop(0)
s720864444
p02607
u505026996
2,000
1,048,576
Wrong Answer
27
9,160
121
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
lst=list(map(int,input().split())) cnt=0 for i,j in enumerate(lst,1): if i%2!=0 and j%2!=0: cnt+=1 print(cnt)
s382812097
Accepted
26
9,116
202
n=int(input()) lst=list(map(int,input().split())) cnt=0 for i,j in enumerate(lst,1): if i%2==0: pass else: if j%2==0: pass else: cnt+=1 print(cnt)
s764439826
p02393
u933096856
1,000
131,072
Wrong Answer
20
7,680
45
Write a program which reads three integers, and prints them in ascending order.
print(list(sorted(map(int,input().split()))))
s595915061
Accepted
50
7,672
46
print(*list(sorted(map(int,input().split()))))
s702991252
p00004
u957021485
1,000
131,072
Time Limit Exceeded
17,630
7,676
390
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
import itertools import operator dataset = [] while True: try: dataset.append(input()) except EOFError: break for item in dataset: a, b, c, d, e, f = [int(i) for i in item.split()] for i in range(-1000, 1001): for j in range(-1000, 1001): if a * i + b * j == c and d * i + e * j == f: print("{:.3f} {:.3f}".format(i, j))
s494389333
Accepted
20
7,588
268
import sys dataset = sys.stdin.readlines() for item in dataset: a, b, c, d, e, f = list(map(int, item.split())) y = (c * d - f * a)/(b * d - e * a) x = (c * e - b * f) / (a * e - b * d) if x == 0: x = 0 print("{:.3f} {:.3f}".format(x, y))
s095948087
p03456
u413377603
2,000
262,144
Wrong Answer
18
3,068
63
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
import math a,b=map(str,input().split()) d=math.sqrt(int(a+b))
s310708390
Accepted
18
2,940
103
import math a,b=input().split() d=int(a+b) if math.sqrt(d)%1==0: print("Yes") else: print("No")
s114630536
p03386
u951601135
2,000
262,144
Wrong Answer
19
3,060
99
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a,b,k=map(int,input().split()) for i in range(a,a+k): print(i) for i in range(b-k,b): print(i)
s841698849
Accepted
22
3,060
144
a,b,k=map(int,input().split()) r=range(a,b+1) for i in sorted(set(r[:k])|set(r[-k:])):print(i)
s085581626
p02613
u727787724
2,000
1,048,576
Wrong Answer
148
9,136
214
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()) ans=[0]*4 for i in range(n): s=input() if s=='AC': ans[0]+=1 elif s=='WA': ans[1]+=1 elif s=='TLE': ans[2]+=1 else: ans[3]+=1 for i in range(4): print("AC x "+str(ans[i]))
s661605824
Accepted
148
9,024
276
n=int(input()) ans=[0]*4 for i in range(n): s=input() if s=='AC': ans[0]+=1 elif s=='WA': ans[1]+=1 elif s=='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]))
s547810987
p03644
u102242691
2,000
262,144
Wrong Answer
17
2,940
82
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n = int(input()) count = 0 while 2 ** count <= 100: count += 1 print(count)
s699693925
Accepted
17
2,940
89
n = int(input()) count = 0 while 2 ** count <= n: count += 1 print(2 ** (count-1))
s456278933
p03129
u518064858
2,000
1,048,576
Wrong Answer
17
2,940
83
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
n,k=map(int,input().split()) x=n//2 if x<k: print("NO") else: print("YES")
s892349247
Accepted
17
2,940
87
n,k=map(int,input().split()) x=-(-n//2) if x<k: print("NO") else: print("YES")
s144121063
p00043
u724963150
1,000
131,072
Time Limit Exceeded
40,000
7,580
835
1 〜 9 の数字を 14 個組み合わせて完成させるパズルがあります。与えられた 13 個の数字にもうひとつ数字を付け加えて完成させます。 パズルの完成条件は * 同じ数字を2つ組み合わせたものが必ずひとつ必要です。 * 残りの12 個の数字は、3個の数字の組み合わせ4つです。 3個の数字の組み合わせ方は、同じ数字を3つ組み合わせたものか、または3つの連続する数字を組み合わせたものです。ただし、9 1 2 のような並びは連続する数字とは認められません。 * 同じ数字は4 回まで使えます。 13 個の数字からなる文字列を読み込んで、パズルを完成することができる数字を昇順に全て出力するプログラムを作成してください。なお、1〜9 のどの数字を付け加えてもパズルを完成させることができないときは 0 を出力してください。 例えば与えられた文字列が 3456666777999 の場合 「2」があれば、 234 567 666 77 999 「3」があれば、 33 456 666 777 999 「5」があれば、 345 567 666 77 999 「8」があれば、 345 666 678 77 999 というふうに、2 3 5 8 のいずれかの数字が付け加えられるとパズルは完成します。「6」でも整いますが、5 回目の使用になるので、この例では使えないことに注意してください。
def Solve(c,s): if s: for i in range(9): if c[i]>4:return False elif c[i]>=2: cc=c[:] cc[i]-=2 if Solve(cc,False):return True else: if c.count(0)+c.count(3)==9:return True else: for i in range(9): if c[i]<0:return False elif c[i]>=1 and i<7: cc=c[:] for j in range(3): cc[i+j]-=1 if Solve(cc,False):return True _in="" while True: ans=[] try:_in="9118992346175" except EOFError:break for i in range(9): l=sorted((_in+str(i+1))[::1]) count=[l.count(str(j+1))for j in range(9)] if Solve(count,True):ans.append(str(i+1)) print(0 if len(ans)==0 else " ".join(ans))
s613447063
Accepted
80
7,472
972
def Solve(c,s): if s: if max(c)>4:return False for i in range(9): if c[i]>=2: cc=c[:] cc[i]-=2 if Solve(cc,False):return True else: check=0 for i in range(4):check+=c.count(3*i) if check==9:return True else: for i in range(7): if c[i]>=1: cc=c[:] isneg=False for j in range(3): cc[i+j]-=1 if cc[i+j]<0: isneg=True break if isneg==False and Solve(cc,False):return True _in="" while True: ans=[] try:_in=input() except EOFError:break for i in range(9): l=(_in+str(i+1))[::1] count=[l.count(str(j+1))for j in range(9)] if Solve(count,True):ans.append(str(i+1)) print(0 if len(ans)==0 else " ".join(ans))
s616405815
p00015
u650459696
1,000
131,072
Wrong Answer
20
7,540
143
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
l = int(input()) for i in range(l): a = int(input()) + int(input()) if(a >= 1E79): print('overflow') else: print(a)
s171687918
Accepted
50
7,572
150
l = int(input()) for i in range(l): a = int(input()) + int(input()) if(len(str(a)) > 80): print('overflow') else: print(a)
s440951212
p03713
u761989513
2,000
262,144
Wrong Answer
255
3,064
316
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
h, w = map(int, input().split()) ans = float("inf") for i in range(h): choco = [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)] ans = min(ans, max(choco) - min(choco)) for i in range(w): choco = [i * h, (w - i) * (h // 2), (w - i) * (h - h // 2)] ans = min(ans, max(choco) - min(choco)) print(ans)
s738421579
Accepted
517
3,064
582
h, w = map(int, input().split()) ans = float("inf") for i in range(h): choco = [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)] ans = min(ans, max(choco) - min(choco)) for i in range(w): choco = [i * h, (w - i) * (h // 2), (w - i) * (h - h // 2)] ans = min(ans, max(choco) - min(choco)) for i in range(h): choco = [i * w, w * ((h - i) // 2), w * ((h - i) - (h - i) // 2)] ans = min(ans, max(choco) - min(choco)) for i in range(w): choco = [i * h, h * ((w - i) // 2), h * ((w - i) - (w - i) // 2)] ans = min(ans, max(choco) - min(choco)) print(ans)
s715535817
p02612
u942697937
2,000
1,048,576
Wrong Answer
29
9,136
34
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N % 1000)
s717702269
Accepted
28
9,160
82
N = int(input()) if N % 1000 == 0: print(0) else: print(1000 - N % 1000)
s975502520
p00065
u811733736
1,000
131,072
Wrong Answer
30
7,800
920
取引先の顧客番号と取引日を月ごとに記録したデータがあります。今月のデータと先月のデータを読み込んで、先月から2ヶ月連続で取引のある会社の顧客番号と取引のあった回数を出力するプログラムを作成してください。ただし、月々の取引先数は 1,000 社以内です。
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0065 """ import sys from collections import Counter def analyze_data(this_month, last_month): result = [] tm = Counter(this_month) lm = Counter(last_month) for ele in lm: if ele in tm: c = lm[ele] + tm[ele] result.append([ele, c]) return result def main(args): this_month = [] last_month = [] month = this_month for line in sys.stdin: if len(line) == 1: # ??\?????????????????? month = last_month else: id, date = line.strip().split(',') month.append(id) #this_month = [123, 56, 34] #last_month = [123, 56, 123] result = analyze_data(this_month, last_month) result.sort() for d in result: print('{} {}'.format(d[0], d[1])) if __name__ == '__main__': main(sys.argv[1:])
s730385182
Accepted
30
7,896
964
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0065 """ import sys from collections import Counter def analyze_data(this_month, last_month): result = [] tm = Counter(this_month) lm = Counter(last_month) for ele in lm: if ele in tm: c = lm[ele] + tm[ele] result.append([ele, c]) result.sort() return result def main(args): this_month = [] last_month = [] month = this_month for line in sys.stdin: if len(line) == 1: # ??\?????????????????? month = last_month else: id, date = line.strip().split(',') month.append(int(id)) # this_month = [1, 123, 56, 34, 23, 1, 23] result = analyze_data(this_month, last_month) for d in result: print('{} {}'.format(d[0], d[1])) if __name__ == '__main__': main(sys.argv[1:])
s385742857
p03006
u891847179
2,000
1,048,576
Wrong Answer
123
27,324
1,586
There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: * Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1. Find the minimum total cost required to collect all the balls when we optimally choose p and q.
# # Make IO faster # import sys # input = sys.stdin.readline # X = input() # N = int(input()) # X, Y = map(int, input().split()) for N lines # XY = [list(map(int, input().split())) for _ in range(N)] # from IPython import embed; embed(); exit(); import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() coords = [] for i in range(N): x, y = MAP() coords.append((x, y)) dic = defaultdict(int) pq_pairs = [] for i in range(N): for j in range(N): if i >= j: continue p = coords[i][0] - coords[j][0] q = coords[i][1] - coords[j][1] if p < 0: p = -p q = -q dic[(p, q)] += 1 ans = 0 for k, v in dic.items(): if v > ans: ans = v print(N - ans)
s841929504
Accepted
35
9,648
617
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq n = ni() if n==1: print(1) exit() xy = [] for i in range(n): xy.append(tma()) co = collections.Counter() for i in range(n): for j in range(n): if i==j: continue x1,y1 = xy[i] x2,y2 = xy[j] co[(x2-x1,y2-y1)] +=1 ans = 10**9 for num in co.values(): ans = min(ans,n-num) print(ans)
s460946295
p03455
u649558044
2,000
262,144
Wrong Answer
17
2,940
110
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
from math import sqrt n = int(input().replace(' ','')) m = int(sqrt(n)) ** 2 print('Yes' if n == m else 'No')
s200923607
Accepted
17
2,940
68
print('Odd' if eval(input().replace(' ', '*')) % 2 == 1 else 'Even')
s292113724
p03525
u905582793
2,000
262,144
Wrong Answer
19
3,064
479
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi. Takahashi checked and found that the _time gap_ (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is defined to be min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local time in the i-th person's city is either d o'clock or 24-d o'clock at the moment when the local time in Takahashi's city is 0 o'clock, for example. Then, for each pair of two people chosen from the N+1 people, he wrote out the time gap between their cities. Let the smallest time gap among them be s hours. Find the maximum possible value of s.
n=int(input()) d=list(map(int,input().split())) d.sort() time=[0]*24 time[0]=1 for i in range(n): if d[i]==0: print(0) exit() if i%2: if time[d[i]]==1: print(0) exit() time[d[i]]=1 else: if time[24-d[i]]==1: print(0) exit() time[24-d[i]]=1 flg=0 ans=0 cnt=0 for i in range(25): i=i%24 if time[i]==0 and not flg: flg=1 cnt=1 elif time[i]==0: cnt+=1 else: ans=max(ans,cnt) cnt=0 print(ans)
s717561995
Accepted
17
3,064
314
n=int(input()) d=list(map(int,input().split())) d.sort() time=[0]*24 time[0]=1 for i in range(n): if i%2: time[d[i]]+=1 else: time[-d[i]]+=1 if max(time)>1: print(0) exit() ans=[] cnt=1 for i in range(1,25): i=i%24 if time[i]==0: cnt+=1 else: ans.append(cnt) cnt=1 print(min(ans))
s204344691
p02277
u831244171
1,000
131,072
Wrong Answer
20
7,736
827
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
def partition(a,b,c,p,r): x = a[r] i = p - 1 for j in range(p,r): if x >= a[j]: i += 1 a[i],a[j] = a[j],a[i] b[i],b[j] = b[j],b[i] c[i],c[j] = c[j],c[i] a[i+1],a[r] = a[r],a[i+1] b[i+1],b[r] = b[r],b[i+1] c[i+1],c[r] = c[r],c[i+1] return i+1 def quickSort(a,b,c,p,r): if p < r: q = partition(a,b,c,p,r-1) quickSort(a,b,c,p,q-1) quickSort(a,b,c,q+1,r) def checkStable(a,b): for i in range(1,len(a)): if a[i-1] == a[i]: if b[i-1] > b[i]: return "Not Stable" return "Stable" n = int(input()) mark = [""]*n num = [0]*n count = [i for i in range(n)] for i in range(n): mark[i],num[i] = input().split() num = list(map(int,num)) quickSort(num,mark,count,0,n) print(checkStable(num,count)) for i in range(n): print(mark[i],num[i])
s912311296
Accepted
1,130
22,668
827
def partition(a,b,c,p,r): x = a[r] i = p - 1 for j in range(p,r): if x >= a[j]: i += 1 a[i],a[j] = a[j],a[i] b[i],b[j] = b[j],b[i] c[i],c[j] = c[j],c[i] a[i+1],a[r] = a[r],a[i+1] b[i+1],b[r] = b[r],b[i+1] c[i+1],c[r] = c[r],c[i+1] return i+1 def quickSort(a,b,c,p,r): if p < r: q = partition(a,b,c,p,r) quickSort(a,b,c,p,q-1) quickSort(a,b,c,q+1,r) def checkStable(a,b): for i in range(1,len(a)): if a[i-1] == a[i]: if b[i-1] > b[i]: return "Not stable" return "Stable" n = int(input()) mark = [""]*n num = [0]*n count = [i for i in range(n)] for i in range(n): mark[i],num[i] = input().split() num = list(map(int,num)) quickSort(num,mark,count,0,n-1) print(checkStable(num,count)) for i in range(n): print(mark[i],num[i])
s938619320
p03998
u330310077
2,000
262,144
Wrong Answer
17
3,060
239
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.
dk = {} dk["a"] = input() dk["b"] = input() dk["c"] = input() n = "a" for i in range(0,100): if len(dk[n]) == 0: print("Break! finalist is {}".format(n)) break nn = dk[n][0] dk[n] = dk[n].lstrip(nn) n = nn
s569632758
Accepted
17
2,940
281
def game(dk, first): n = first while True: if len(dk[n]) == 0: return n.upper() break nn = dk[n][0] dk[n] = dk[n][1:] n = nn pass dk = {} dk["a"] = input() dk["b"] = input() dk["c"] = input() print(game(dk,"a"))
s959422081
p02409
u639421643
1,000
131,072
Wrong Answer
20
7,656
547
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.
place = [] bn,fn,rn=[4,3,10] for i in range(bn): place.append([]) for j in range(fn): place[i].append([]) for k in range(rn): place[i][j].append(0) count = int(input()) for i in range(count): b,f,r,v = map(int, input().split()) place[b-1][f-1][r-1] += v for i in range(bn): for j in range(fn): line = "" for k in range(rn): line += " " line += str(place[i][j][k]) print(line) mark = "" for i in range(20): mark += "#" print(mark)
s654372249
Accepted
20
7,716
581
place = [] bn,fn,rn=[4,3,10] for i in range(bn): place.append([]) for j in range(fn): place[i].append([]) for k in range(rn): place[i][j].append(0) count = int(input()) for i in range(count): b,f,r,v = map(int, input().split()) place[b-1][f-1][r-1] += v for i in range(bn): for j in range(fn): line = "" for k in range(rn): line += " " line += str(place[i][j][k]) print(line) if(i == bn -1): break mark = "" for i in range(20): mark += "#" print(mark)
s050515405
p03302
u787562674
2,000
1,048,576
Wrong Answer
21
3,316
114
You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds. Note that a+b=15 and a\times b=15 do not hold at the same time.
a, b = map(int, input().split()) if a*b == 15: print("*") elif a*b == 15: print("+") else: print("x")
s769102046
Accepted
18
2,940
114
a, b = map(int, input().split()) if a*b == 15: print("*") elif a+b == 15: print("+") else: print("x")
s117886838
p03643
u724742135
2,000
262,144
Wrong Answer
18
2,940
64
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
from sys import stdin n = stdin.readline().rstrip() print('A'+n)
s062019291
Accepted
18
2,940
66
from sys import stdin n = stdin.readline().rstrip() print('ABC'+n)
s343290034
p03494
u038408819
2,000
262,144
Time Limit Exceeded
2,104
3,060
145
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())) ans = 0 while all(A % 2 == 0 for A in a): A = [i / 2 for i in a] ans += 1 print(ans)
s666590318
Accepted
19
3,060
146
n = int(input()) a = list(map(int, input().split())) ans = 0 while all(A % 2 == 0 for A in a): a = [i / 2 for i in a] ans += 1 print(ans)
s383524169
p03964
u312078744
2,000
262,144
Wrong Answer
2,104
3,060
315
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time. Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
n = int(input()) x, y = map(int, input().split()) t, a = x, y for _ in range(n - 1): tt, aa = map(int, input().split()) c = 1 if (t >= a): while (tt * c < t): c += 1 else: while (aa * c < a): c += 1 t = tt * c a = aa * c ans = t + a print(ans)
s037163575
Accepted
42
10,480
605
import math from fractions import Fraction from decimal import * # ex) Fraction(2,6) > 1/3 > 0.33333 n = int(input()) x, y = map(int, input().split()) t, a = x, y for _ in range(n - 1): tt, aa = map(int, input().split()) # c = 1 c = max(math.ceil(Fraction(t, tt)), math.ceil(Fraction(a, aa))) c = max(1, c) t = tt * c a = aa * c ans = t + a print(ans)
s186098341
p03251
u157850041
2,000
1,048,576
Wrong Answer
17
3,064
332
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.
a = input().split() n = int(a[0]) m = int(a[1]) x = int(a[2]) y = int(a[3]) a = input().split() a = [int(s) for s in a] x_max = max(a) a = input().split() a = [int(s) for s in a] y_min = min(a) print(y <= x_max , y_min <= x , x_max >= y_min) if y <= x_max or y_min <= x or x_max >= y_min: print("War") else: print("No War")
s329666803
Accepted
17
3,064
284
a = input().split() n = int(a[0]) m = int(a[1]) x = int(a[2]) y = int(a[3]) a = input().split() a = [int(s) for s in a] x_max = max(a) a = input().split() a = [int(s) for s in a] y_min = min(a) if x_max >= y or y_min <= x or x_max >= y_min: print("War") else: print("No War")
s770940876
p02393
u978086225
1,000
131,072
Wrong Answer
30
6,716
106
Write a program which reads three integers, and prints them in ascending order.
nums = input().split() a = int(nums[0]) b = int(nums[1]) c = int(nums[2]) if a < b < c: print(a, b, c)
s155623782
Accepted
30
6,724
281
nums = input().split() a = int(nums[0]) b = int(nums[1]) c = int(nums[2]) if a <= b <= c: print(a, b, c) elif a <= c <= b: print(a, c, b) elif b <= a <= c: print(b, a, c) elif b <= c <= a: print(b, c, a) elif c <= a <= b: print(c, a, b) else: print(c, b, a)
s985344002
p02418
u650790815
1,000
131,072
Wrong Answer
20
7,292
75
Write a program which finds a pattern $p$ in a ring shaped text $s$.
s = input() p = input() if s in p*2: print('yes') else: print('no')
s720646633
Accepted
20
7,392
56
s,p = input()*2,input() print('Yes' if p in s else 'No')
s379600124
p03150
u480138356
2,000
1,048,576
Wrong Answer
21
3,316
345
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.
import sys input = sys.stdin.readline def ok(s): for i in range(len(s)): for j in range(i, len(s)): print(s[:i] + s[j:]) if s[:i] + s[j:] == "keyence": return True return False def main(): s = input().strip() print("YES" if ok(s) else "NO") if __name__ == "__main__": main()
s273694253
Accepted
18
3,060
540
import sys input = sys.stdin.readline def ok(s): for i in range(len(s)+1): for j in range(i, len(s)+1): # for k in range(len(s)): # if i <= k and k < j: # print("_", end="") # else: # print(s[k], end="") if s[:i] + s[j:] == "keyence": return True return False def main(): s = input().strip() print("YES" if ok(s) else "NO") if __name__ == "__main__": main()
s901687962
p02831
u723444827
2,000
1,048,576
Wrong Answer
17
3,060
325
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
def gcd(a,b): if (a % b) == 0: return b else: return gcd(b, a%b) def lcm(a, b): y = gcd(a,b) print(y) if (y == 0): return a*b else: return a*b/y A, B = map(int,input().split()) if A < B: t = A A = B B = t x = int(lcm(A,B)) print(x)
s112866236
Accepted
17
3,060
312
def gcd(a,b): if (a % b) == 0: return b else: return gcd(b, a%b) def lcm(a, b): y = gcd(a,b) if (y == 0): return a*b else: return a*b/y A, B = map(int,input().split()) if A < B: t = A A = B B = t x = int(lcm(A,B)) print(x)
s587563227
p04043
u759412327
2,000
262,144
Wrong Answer
17
2,940
43
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.
print(["YES'","NO"][input().count("7")==2])
s753543609
Accepted
27
9,056
80
if sorted(map(int,input().split()))==[5,5,7]: print("YES") else: print("NO")
s917535928
p03861
u976162616
2,000
262,144
Wrong Answer
18
2,940
166
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
if __name__ == "__main__": A,B,C = map(int, input().split()) result = B // C result -= A // C if (A % C == 0): result -= 1 print (result)
s385969280
Accepted
17
2,940
166
if __name__ == "__main__": A,B,C = map(int, input().split()) result = B // C result -= A // C if (A % C == 0): result += 1 print (result)
s005315860
p03993
u215315599
2,000
262,144
Wrong Answer
83
14,008
145
There are N rabbits, numbered 1 through N. The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i. For a pair of rabbits i and j (i<j), we call the pair (i,j) a _friendly pair_ if the following condition is met. * Rabbit i likes rabbit j and rabbit j likes rabbit i. Calculate the number of the friendly pairs.
N = int(input()) A = list(map(lambda x:int(x)-1,input().split())) print(A) ans = 0 for i in range(N): if A[A[i]] == i: ans += 1 print(ans//2)
s955326835
Accepted
76
14,008
137
N = int(input()) A = list(map(lambda x:int(x)-1,input().split())) ans = 0 for i in range(N): if A[A[i]] == i: ans += 1 print(ans//2)
s775235681
p03504
u988402778
2,000
262,144
Wrong Answer
775
125,180
5,374
Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
# using main() makes code faster from the point of view of "access to variables in global name-space" # for i, a in enumerate(iterable) # divmod(x, y) returns the tuple (x//y, x%y) # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f import sys sys.setrecursionlimit(10**7) from itertools import accumulate, combinations, permutations # https://docs.python.org/ja/3/library/itertools.html from math import factorial def combinations_count(n, r): # faster than the following code # return factorial(n) // (factorial(n - r) * factorial(r)) if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def combination_with_repetition_count(n, r): return combinations_count(n + r - 1, r) from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html from operator import itemgetter # ex1: List.sort(key=itemgetter(1)) # ex2: sorted(tuples, key=itemgetter(1,2)) from functools import reduce from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead. def gcds(numbers): return reduce(gcd, numbers) def lcm(x, y): return (x * y) // gcd(x, y) def lcms(numbers): return reduce(lcm, numbers, 1) # first create factorial_list # fac_list = mod_factorial_list(n) INF = 10 ** 18 MOD = 10 ** 6 + 3 modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow! def modinv(a, p = MOD): # evaluate reciprocal using Fermat's little theorem: # a**(p-1) is identical to 1 (mod p) when a and p is coprime return modpow(a, p-2, p) def modinv_list(n, p = MOD): if n <= 1: return [0,1][:n+1] else: inv_t = [0,1] for i in range(2, n+1): inv_t += [inv_t[p % i] * (p - int(p / i)) % p] return inv_t def modfactorial_list(n, p = MOD): if n == 0: return [1] else: l = [0] * (n+1) tmp = 1 for i in range(1, n+1): tmp = tmp * i % p l[i] = tmp return l def modcomb(n, k, fac_list = [], p = MOD): # fac_list = modfactorial_list(100) # print(modcomb(100, 5, modfactorial_list(100))) from math import factorial if n < 0 or k < 0 or n < k: return 0 if n == 0 or k == 0: return 1 if len(fac_list) <= n: a = factorial(n) % p b = factorial(k) % p c = factorial(n-k) % p else: a = fac_list[n] b = fac_list[k] c = fac_list[n-k] return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p def modadd(a, b, p = MOD): return (a + b) % MOD def modsub(a, b, p = MOD): return (a - b) % p def modmul(a, b, p = MOD): return ((a % p) * (b % p)) % p def moddiv(a, b, p = MOD): return modmul(a, modpow(b, p-2, p)) # initialize variables and set inputs #initialize variables # to initialize list, use [0] * n # to initialize two dimentional array, use [[0] * N for _ in range(N)] # open(0).read() is a convenient method: # ex) n, m, *x = map(int, open(0).read().split()) # min(x[::2]) - max(x[1::2]) # ex2) *x, = map(int, open(0).read().split()) # don't forget to add comma after *x if only one variable is used # calculate and output # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6 # sys.stdin = open('sample.txt') # for test # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: map(int, r().split()) N, C = R() STC = [R() for _ in range(N)] tbl = [[0]*(2*(10**5)+5) for _ in range(C)] # watch out: join tv programmes which are continuously broadcast in one channel for s, t, c in STC: c -= 1 if tbl[c][2*s] != 0: tbl[c][2*s] += 1 tbl[c][2*t] -= 1 elif tbl[c][2*t-1] != 0: tbl[c][2*t-1] -= 1 tbl[c][2*s-1] += 1 else: tbl[c][2*s-1] = 1 tbl[c][2*t] = -1 # for s, t, c in STC: # c -= 1 # if tbl[c][s] == -1: # tbl[c][s] = 0 # tbl[c][t] = -1 # elif tbl[c][t-1] == 1: # tbl[c][s-1] = 1 # tbl[c][t-1] = 0 # else: # tbl[c][s-1] = 1 # tbl[c][t] = -1 tbl2 = [list(accumulate(a)) for a in tbl] ans = max([sum(x) for x in zip(*tbl2)]) print(ans) # res = 0 # cc = 0 # for j in range(C): # if tbl2[j][i]: # cc += 1 # res = max(res, cc) # print(res) # if __name__ == '__main__': # main()
s054934209
Accepted
1,638
123,388
1,016
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: map(int, r().split()) N, C = R() STC = [R() for _ in range(N)] # 0.5sec as one unit tbl = [[0]*(2*(10**5)+5) for _ in range(C)] for s, t, c in STC: c -= 1 # if we can record the programms continuously (ver1) if tbl[c][2*s] != 0: tbl[c][2*s] += 1 tbl[c][2*t] -= 1 # if we can record the programms continuously (ver2) elif tbl[c][2*t-1] != 0: tbl[c][2*t-1] -= 1 tbl[c][2*s-1] += 1 # else: else: tbl[c][2*s-1] = 1 tbl[c][2*t] = -1 tbl2 = [list(accumulate(a)) for a in tbl] # ans = max([sum(x) for x in zip(*tbl2)]) # print(ans) res = 0 for i in range(200002): cc = 0 for j in range(C): if tbl2[j][i] == 1: cc += 1 res = max(res, cc) print(res)
s798665800
p02390
u090921599
1,000
131,072
Wrong Answer
20
5,456
1
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
s470924865
Accepted
20
5,584
94
S = int(input()) h = S // 3600 m = S % 3600 // 60 s = S % 60 print(h, ':',m, ':', s, sep='')
s979766410
p03997
u391059484
2,000
262,144
Wrong Answer
18
2,940
61
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a, b, h = [int(input()) for i in range(3)] print((a + b)*h/2)
s476192490
Accepted
17
2,940
66
a, b, h = [int(input()) for i in range(3)] print(int((a + b)*h/2))
s369624092
p03141
u404676457
2,000
1,048,576
Wrong Answer
609
48,736
361
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end". Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
n = int(input()) ab = [list(map(int, input().split())) for _ in range(n)] div = [[abs(ab[i][1] - ab[i][0]), ab[i][0], ab[i][1]] for i in range(n)] div = sorted(div, key=lambda x: x[0], reverse=True) print(div) counta = 0 countb = 0 for i in range(n): if i % 2 == 0: counta += div[i][1] else: countb += div[i][2] print(counta - countb)
s198239765
Accepted
556
40,136
344
n = int(input()) ab = [list(map(int, input().split())) for i in range(n)] div = [[ab[i][1] + ab[i][0], ab[i][0], ab[i][1]] for i in range(n)] div = sorted(div, key=lambda x: x[0], reverse=True) counta = 0 countb = 0 for i in range(n): if i % 2 == 0: counta += div[i][1] else: countb += div[i][2] print(counta - countb)
s860133947
p04030
u976225138
2,000
262,144
Wrong Answer
17
2,940
134
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
ans = "" for s in input(): if s == "B": if ans: ans = ans[:-2] else: ans += s else: print(ans)
s593658998
Accepted
17
3,060
131
ans = "" for s in input(): if s == "B" and ans: ans = ans[:-1] elif s != "B": ans += s else: print(ans)
s970588785
p03836
u057109575
2,000
262,144
Wrong Answer
17
3,064
486
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) def func(a, b, x, y): ans = '' if x > a: ans += 'R' * (x - a) if x < a: ans += 'L' * (a - x) if y > b: ans += 'U' * (y - b) if y < b: ans += 'D' * (b - y) return ans print('U' + func(sx + 1, sy, tx + 1, ty) + 'D' \ + 'R' + func(tx, ty + 1, sx, sy + 1) + 'L' \ + 'L' + func(sx - 1, sy, tx - 1, ty) + 'R' \ + 'D' + func(tx, ty - 1, sx, sy - 1) + 'U')
s334642211
Accepted
17
3,060
269
sx, sy, tx, ty = map(int, input().split()) print('U' * (ty - sy) + 'R' * (tx - sx) \ + 'D' * (ty - sy) + 'L' * (tx - sx) \ + 'L' + 'U' * (ty - sy + 1) + 'R' * (tx - sx + 1) + 'D' \ + 'R' + 'D' * (ty - sy + 1) + 'L' * (tx - sx + 1) + 'U' )
s121397555
p03379
u988402778
2,000
262,144
Wrong Answer
316
25,220
234
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 = [int(i) for i in input().split()] sortx = sorted(x) mid_left = sortx[(n//2)-1] mid_right = sortx[(n//2)] for i in range(n): if sortx[i] <= mid_left: print(mid_right) else: print(mid_left)
s951041911
Accepted
305
25,220
230
n = int(input()) x = [int(i) for i in input().split()] sortx = sorted(x) mid_left = sortx[(n//2)-1] mid_right = sortx[(n//2)] for i in range(n): if x[i] <= mid_left: print(mid_right) else: print(mid_left)
s377078893
p03377
u565464228
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 a <= x <= a + b: print("Yes") else: print("No")
s806566434
Accepted
17
2,940
119
a, b, x = map(int, input().split(" ")) # x>=a and x<=a+b if x>=a and x<=a+b: print("YES") else: print("NO")
s016733910
p03545
u714533789
2,000
262,144
Wrong Answer
17
3,060
164
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
from itertools import product s = input() for i in product('+-', repeat=3): t = ''.join([a+b for a, b in zip(list(i), s)]) if eval(t) == 7: print(t+'=7');exit()
s790452716
Accepted
17
3,060
174
from itertools import product s = input() for ops in product('+-', repeat=3): t = ''.join([a+b for a, b in zip(s, ops)]) t += s[-1] if eval(t) == 7: print(t+'=7');exit()
s938749175
p03992
u016843859
2,000
262,144
Wrong Answer
29
9,124
113
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() for i in range(4): print(s[i],end="") print(" ",end="") for i in range(8): print(s[i+4],end="")
s635264833
Accepted
20
9,052
123
s=input() for i in range(4): print(s[i],end="") print(" ",end="") for i in range(8): print(s[i+4],end="") print("")
s203535397
p03524
u871841829
2,000
262,144
Wrong Answer
26
3,564
292
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
from collections import Counter S = input() d = Counter(S) na = 0 if "a" not in d.keys() else d["a"] nb = 0 if "b" not in d.keys() else d["b"] nc = 0 if "c" not in d.keys() else d["c"] if abs(na - nb) <= 1 and abs(nc - na) <= 1 and abs(nb - nc) <= 1: print("Yes") else: print("No")
s193012830
Accepted
26
3,564
291
from collections import Counter S = input() d = Counter(S) na = 0 if "a" not in d.keys() else d["a"] nb = 0 if "b" not in d.keys() else d["b"] nc = 0 if "c" not in d.keys() else d["c"] if abs(na - nb) <= 1 and abs(nc - na) <= 1 and abs(nb - nc) <= 1: print("YES") else: print("NO")
s872617581
p02418
u656153606
1,000
131,072
Wrong Answer
20
7,352
101
Write a program which finds a pattern $p$ in a ring shaped text $s$.
s = list(input()) p = input() s.extend(s) if p in s: print("Yes") else: print("No") print(s)
s363028577
Accepted
70
7,452
80
s = input() p = input() s += s if p in s: print("Yes") else: print("No")
s710039246
p03555
u746419473
2,000
262,144
Wrong Answer
17
2,940
97
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
h = input() l = input() print("Yes" if h[0] == l[2] and l[0] == h[2] and h[1] == l[1] else "No")
s162738624
Accepted
17
2,940
78
s = input() s += input() print("YES" if s == "".join(reversed(s)) else "NO")
s023901645
p00006
u777299405
1,000
131,072
Wrong Answer
30
7,308
24
Write a program which reverses a given string str.
print(reversed(input()))
s914070854
Accepted
20
7,412
20
print(input()[::-1])
s849413610
p00506
u150984829
8,000
131,072
Wrong Answer
20
5,644
197
入力ファイルの1行目に正整数 n が書いてあり, 2行目には半角空白文字1つを区切りとして, n 個の正整数が書いてある. n は 2 または 3 であり, 2行目に書かれているどの整数も値は 108 以下である. これら2個または3個の数の公約数をすべて求め, 小さい方から順に1行に1個ずつ出力せよ. 自明な公約数(「1」)も出力すること. 出力ファイルにおいては, 出力の最後行にも改行コードを入れること.
input() n=sorted(list(map(int,input().split()))) m=n[0] a=[] for x in range(1,int(m**.5)+1): if m%x==0:a+=[x,m/x] for c in sorted(a): for k in n[1:]: if k%c:break else:print(c)
s905135484
Accepted
20
5,636
207
input() n=sorted(list(map(int,input().split()))) m=n[0] a=set() for x in range(1,int(m**.5)+1): if m%x==0:a|={x,m//x} for c in sorted(list(a)): for k in n[1:]: if k%c:break else:print(c)
s104901018
p02694
u219494936
2,000
1,048,576
Wrong Answer
33
9,148
117
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
X = int(input()) K = 100 i = 1 while 1: K *= 1.01 K = int(K) if K > X: break i += 1 print(i)
s264604303
Accepted
31
8,952
116
X = int(input()) K = 100 i = 1 while 1: K *= 101 K //= 100 if K >= X: break i += 1 print(i)
s962142491
p02255
u534156032
1,000
131,072
Wrong Answer
20
7,716
292
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
def insersionSort(A, N): print(" ".join(map(str,A))) for i in range(1,N-1): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] =v print(" ".join(map(str,A))) n = int(input()) a = [int(i) for i in input().split()] insersionSort(a, n)
s286230665
Accepted
50
7,720
217
n = int(input()) a = [int(i) for i in input().split()] for i in range(n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v print(" ".join(map(str, a)))
s813591722
p03494
u363836311
2,000
262,144
Wrong Answer
19
3,060
171
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())) t=0 g=0 for i in range(n): while a[i]%2==0: t+=1 a[i]=a[i]//2 if g==0: g=t else: g=min(g,t) print(g)
s221236445
Accepted
19
3,060
197
n=int(input()) a=list(map(int, input().split())) t=0 g=0 while g==0: for i in range(n): if a[i]%2==0: a[i]=a[i]//2 t+=1 else: g=1 print(t//n)
s047771218
p03673
u887207211
2,000
262,144
Wrong Answer
2,105
21,748
133
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
N = int(input()) A = input().split() B = '' for i in range(N): if(i%2 == 0): B = A[i] + B else: B += A[i] print(B[::-1])
s154065349
Accepted
108
23,972
112
N = int(input()) A = input().split() if(N%2 == 0): print(*(A[::-2]+A[::2])) else: print(*(A[::-2]+A[1::2]))
s240827223
p03251
u254086528
2,000
1,048,576
Wrong Answer
17
3,064
271
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,cx,cy = map(int,input().split()) x = list(int(i) for i in input().split()) y = list(int(i) for i in input().split()) x.sort() y.sort() z = range(cx+1,cy+1) ans = "War" for v in z: if (v > x[n-1]) and (v <= y[0]): ans = "No war" break print(ans)
s863040259
Accepted
17
3,064
271
n,m,cx,cy = map(int,input().split()) x = list(int(i) for i in input().split()) y = list(int(i) for i in input().split()) x.sort() y.sort() z = range(cx+1,cy+1) ans = "War" for v in z: if (v > x[n-1]) and (v <= y[0]): ans = "No War" break print(ans)
s714331166
p03645
u576917603
2,000
262,144
Wrong Answer
756
49,172
251
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
n,m=map(int,input().split()) a=[[int(i) for i in input().split()]for i in range(m)] print(a) s=set() for i in a: if i[1]==n: s.add(i[0]) for i in a: if i[0]==1 and i[1] in s: print('POSSIBLE') exit() print('IMPOSSIBLE')
s499004041
Accepted
668
40,856
394
n,m=map(int,input().split()) a=[[int(i) for i in input().split()]for i in range(m)] b=[None]*n for i in a: if i[1]==n: if b[i[0]-1]!=None: print('POSSIBLE') exit() else: b[i[0]-1]=True if i[0]==1: if b[i[1]-1]!=None: print('POSSIBLE') exit() else: b[i[1]-1]=True print('IMPOSSIBLE')
s690393386
p03643
u865413330
2,000
262,144
Wrong Answer
18
3,060
302
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
n = int(input()) count = 0 currCount = 0 ans = 0 for i in range(n+1): currCount = 0 currNum = i while (i % 2) == 0: if i == 0: break i = int(i / 2) currCount += 1 if count < currCount: count = currCount ans = currNum print(ans, count)
s943885956
Accepted
20
2,940
28
n = input() print("ABC" + n)
s493458084
p03711
u432805419
2,000
262,144
Wrong Answer
17
3,064
202
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
a = list(map(int,input().split())) b = [1,3,5,7,8,10,12] c = [4,6,9,11] if a[0] == 2 or a[1] == 2: print("No") elif a[0] in b == a[1] in b or a[0] in c == a[1] in c: print("Yes") else: print("No")
s724705489
Accepted
17
2,940
124
a = list(map(int,input().split())) b = [0,1,3,1,2,1,2,1,1,2,1,2,1] if b[a[0]] == b[a[1]]: print("Yes") else: print("No")
s140472577
p03759
u762540523
2,000
262,144
Wrong Answer
18
2,940
58
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c=map(int,input().split());print("YNeos"[b-a!=c-b::2])
s069559888
Accepted
17
2,940
58
a,b,c=map(int,input().split());print("YNEOS"[b-a!=c-b::2])
s267040045
p00004
u150984829
1,000
131,072
Wrong Answer
20
5,604
111
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
import sys for e in sys.stdin: a,b,c,d,e,f=map(int,e.split()) print((c*d-a*f)/(b*d-a*e),(c*e-b*f)/(a*e-b*d))
s750030173
Accepted
20
5,632
121
import sys for e in sys.stdin: a,b,c,d,e,f=map(int,e.split()) y=(c*d-a*f)/(b*d-a*e) print(f'{(c-b*y)/a:.3f} {y:.3f}')
s675568262
p02697
u517152997
2,000
1,048,576
Wrong Answer
158
27,284
420
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
# import sys import math import numpy as np import itertools n,m = (int(i) for i in input().split()) if n % 2 == 0: if m / 4 <= 1: for i in range(0,m): print(i+1, n//2-i) else: for i in range(0,n//4+1): print(i+1,n//2-i) for i in range(n//2+1,m): print(i+n//2+1, n-i+n//2) else: for i in range(0,m): print(i+1,n-1-i)
s651016806
Accepted
154
27,260
383
# import sys import math import numpy as np import itertools n,m = (int(i) for i in input().split()) if m % 2 == 0: for i in range(0,m//2): print(i+1,m+1-i) for i in range(m//2,m): print(m//2+2+i,m*2+m//2+1-i) else: for i in range(0,m//2): print(i+1,m-i) for i in range(m//2+1,m+1): print(m//2+1+i,m*2+m//2+2-i)
s449689500
p02408
u450020188
1,000
131,072
Wrong Answer
30
7,708
358
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
n = int(input()) cards = [[ s+' '+str(n) for n in range(1,14)] for s in ['S','H','C','D']] for _ in range(n): suit,num = input().split() if suit=='S': cards[0][int(num)-1] = 0 elif suit=='H': cards[1][int(num)-1] = 0 elif suit=='C': cards[2][int(num)-1] = 0 elif suit=='D': cards[3][int(num)-1] = 0 for s in cards: if n!=0: print(n)
s623662261
Accepted
30
7,740
378
n = int(input()) cards = [[ s+' '+str(n) for n in range(1,14)] for s in ['S','H','C','D']] for _ in range(n): suit,num = input().split() if suit=='S': cards[0][int(num)-1] = 0 elif suit=='H': cards[1][int(num)-1] = 0 elif suit=='C': cards[2][int(num)-1] = 0 elif suit=='D': cards[3][int(num)-1] = 0 for s in cards: for n in s: if n!=0: print(n)
s790421968
p02578
u004823354
2,000
1,048,576
Wrong Answer
113
32,200
164
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 = int(input()) a = list(map(int,input().split())) max = 0 sum = 0 for i in range(n): if a[i] > max: max = a[i] else: sum += a[i] - max print(sum)
s563696995
Accepted
114
32,032
167
n = int(input()) a = list(map(int,input().split())) max = 0 sum = 0 for i in range(n): if a[i] > max: max = a[i] else: sum += (max - a[i]) print(sum)
s507259100
p03214
u163320134
2,525
1,048,576
Wrong Answer
17
2,940
162
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()) arr=list(map(int,input().split())) avg=sum(arr)/n pos=0 diff=10**9 for i in range(n): if abs(arr[i]-avg)<diff: diff=abs(arr[i]-avg) pos=i
s613327036
Accepted
17
3,060
173
n=int(input()) arr=list(map(int,input().split())) avg=sum(arr)/n pos=0 diff=10**9 for i in range(n): if abs(arr[i]-avg)<diff: diff=abs(arr[i]-avg) pos=i print(pos)
s471008299
p03455
u760527120
2,000
262,144
Wrong Answer
21
3,316
88
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if a * b % 2 == 0: print('Odd') else: print('Even')
s714561013
Accepted
17
2,940
88
a, b = map(int, input().split()) if a * b % 2 == 0: print('Even') else: print('Odd')
s812693896
p03549
u052332717
2,000
262,144
Wrong Answer
18
2,940
154
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
n,m = map(int,input().split()) success = 0.5**m failure = 1 - success operation_time = 1900*m + 100*(n-m) print(success*operation_time//((1-failure)**2))
s535519891
Accepted
18
2,940
161
n,m = map(int,input().split()) success = 0.5**m failure = 1 - success operation_time = 1900*m + 100*(n-m) print(int((success*operation_time//((1-failure)**2))))
s348052314
p03853
u481333386
2,000
262,144
Wrong Answer
17
3,060
163
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
height, width = [int(e) for e in input().split()] lst = [] for i in range(height): pict = input() lst.append(pict) lst.append(pict) '\n'.join(lst)
s043746513
Accepted
18
3,060
170
height, width = [int(e) for e in input().split()] lst = [] for i in range(height): pict = input() lst.append(pict) lst.append(pict) print('\n'.join(lst))
s445265123
p03378
u798586213
2,000
262,144
Wrong Answer
17
3,060
307
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
N,M,X = (int(i) for i in input().split()) A = list(map(int,input().split())) print(A) small = 0 big = 0 for j in A: if j < X: continue else: small=small+1 for j in A: if j > X: continue else: big=big+1 if big>=small: print(small) else: print(big)
s693118024
Accepted
17
3,060
299
N,M,X = (int(i) for i in input().split()) A = list(map(int,input().split())) small = 0 big = 0 for j in A: if j < X: continue else: small=small+1 for j in A: if j > X: continue else: big=big+1 if big>=small: print(small) else: print(big)
s124614993
p03578
u544280305
2,000
262,144
Wrong Answer
533
71,956
716
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
import sys from collections import Counter candnum=int(input()) candiff=list(map(int,input().split())) pronum=int(input()) candiff=Counter(candiff) prodiff=list(map(int,input().split())) prodiff=Counter(candiff) if pronum>candnum: print("NO") sys.exit() #print(candnum) print(candiff) #print(pronum) print(prodiff) ''' while candnum>=1 and pronum>=1: if candiff[candnum-1]<prodiff[pronum-1]: print("NO") sys.exit() candnum-=1 pronum-=1 print("YES") sys.exit() ''' #print(candiff) #print(prodiff) for k,v in prodiff.items(): if k in candiff: if candiff[k]<v: print("NO") sys.exit() else: print("NO") sys.exit() print("YES")
s741438228
Accepted
285
55,648
445
import sys from collections import Counter candnum=int(input()) candiff=list(map(int,input().split())) pronum=int(input()) prodiff=list(map(int,input().split())) candiff=Counter(candiff) prodiff=Counter(prodiff) if pronum>candnum: print("NO") sys.exit() for k,v in prodiff.items(): if k in candiff: if candiff[k]<v: print("NO") sys.exit() else: print("NO") sys.exit() print("YES")
s977208080
p02612
u882853528
2,000
1,048,576
Wrong Answer
25
9,140
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N % 1000)
s871974639
Accepted
28
9,176
81
N = int(input()) if N%1000 == 0: print(0) else: print(1000 - (N % 1000))
s978108145
p03997
u702786238
2,000
262,144
Wrong Answer
17
2,940
68
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s429020044
Accepted
17
2,940
70
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s053428820
p03597
u284854859
2,000
262,144
Wrong Answer
17
2,940
43
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
n=int(input()) a=int(input()) print(n*2-a)
s115420882
Accepted
17
2,940
45
n=int(input()) a=int(input()) print(n**2-a)
s316767313
p03469
u419963262
2,000
262,144
Wrong Answer
17
2,940
28
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() S[3]=="8" print(S)
s501233216
Accepted
17
2,940
25
print("2018"+input()[4:])
s833080534
p03578
u379692329
2,000
262,144
Wrong Answer
2,105
35,420
343
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
N = int(input()) D = [int(_) for _ in input().split()] M = int(input()) T = [int(_) for _ in input().split()] D = sorted(D) T = sorted(T) Dstart = 0 flag = True for i in T: for j in D[Dstart:]: Dstart += 1 if i == j: break if Dstart == N: flag = False break print("YES" if flag else "NO")
s748229370
Accepted
357
35,324
316
N = int(input()) D = [int(_) for _ in input().split()] M = int(input()) T = [int(_) for _ in input().split()] D = sorted(D) T = sorted(T) Tindex = 0 flag = False for i in D: if i == T[Tindex]: Tindex += 1 if Tindex == M: flag = True break print("YES" if flag else "NO")
s174510202
p03494
u531674264
2,000
262,144
Wrong Answer
18
3,060
382
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 = input() a = list(map(int, input().split())) b = 0 def hantei(a): b = list(map(lambda x: x % 2, a)) c = 0 for i in range(len(b)): if a[i] == "0": c += 0 else: c += 1 if b == 0: d = 0 else: d = 1 return d while True: c = hantei(a) if c == 0: b += 1 else: break print(b)
s817130229
Accepted
21
3,064
406
n = input() a = list(map(int, input().split())) c = 0 def han(a): b = list(map(lambda x: x % 2, a)) c = 0 for i in b: if i == 0: c += 1 else: c -= 1 if c == len(b):return 1 else: return 0 while True: if han(a) == 1: a = list(map(lambda x: x / 2, a)) c += 1 if han(a) == 0: break c = 0 print(c)
s713294081
p03695
u697690147
2,000
262,144
Wrong Answer
28
9,136
226
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
N = int(input()) a = list(map(int, input().split())) c = [0] * 8 r = 0 for i in a: col = i // 400 if col <= 7: c[col] = 1 else: r += 1 c = sum(c) print(min(8, r) if r>c else c) print(min(8,r+c))
s445314413
Accepted
25
9,128
199
N = int(input()) a = list(map(int, input().split())) c = [0] * 8 r = 0 for i in a: col = i // 400 if col <= 7: c[col] = 1 else: r += 1 c = sum(c) print(max(1, c), r+c)
s693145670
p03338
u345710188
2,000
1,048,576
Wrong Answer
17
3,060
189
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
N = int(input()) S = input() a = set(S[:1]) b = set(S[1:]) M = a & b for i in range(2,N): a = set(S[:i]) b = set(S[i:]) if (a & b) > M: M = (a & b) else: print(M) break
s146676510
Accepted
17
3,060
179
N = int(input()) S = input() a = set(S[:1]) b = set(S[1:]) M = len(a & b) for i in range(2,N): a = set(S[:i]) b = set(S[i:]) if len(a & b) > M: M = len(a & b) print(M)
s250226615
p00001
u350804311
1,000
131,072
Wrong Answer
20
7,684
125
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
import sys a = [] for line in sys.stdin: a.append(int(line)) a.sort() print(str(a[0])) print(str(a[1])) print(str(a[2]))
s717374360
Accepted
20
7,680
122
import sys a = [] for line in sys.stdin: a.append(int(line)) a.sort() a.reverse() print(a[0]) print(a[1]) print(a[2])
s351287663
p03474
u242518667
2,000
262,144
Wrong Answer
22
3,316
105
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
a,b=map(int,input().split()) s=input().split('-') print('YES' if len(s[0])==a and len(s[1])==b else 'NO')
s591455705
Accepted
17
2,940
105
a,b=map(int,input().split()) s=input().split('-') print('Yes' if len(s[0])==a and len(s[1])==b else 'No')
s462523541
p00101
u748033250
1,000
131,072
Wrong Answer
20
7,576
111
An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina". Your task is to write a program which replace all the words "Hoshino" with "Hoshina". You can assume that the number of characters in a text is less than or equal to 1000.
num = int(input()) for i in range(num): box = input() box.replace("Hoshino", "Hoshina") print(box)
s117062116
Accepted
20
7,524
108
num = int(input()) for i in range(num): box = input() print(box.replace("Hoshino", "Hoshina"))
s653020566
p03434
u406767170
2,000
262,144
Wrong Answer
17
3,064
181
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = int(input()) card = list(map(int,input().split())) card.sort() for i in range(n//2): ans = card[2*i]-card[2*i+1] if n%2==1: ans += card[-1] print(ans)
s449106143
Accepted
18
3,060
196
n = int(input()) card = list(map(int,input().split())) card.sort(reverse=True) asum = 0 bsum = 0 for i in range(n): if i%2==0: asum += card[i] else: bsum += card[i] print(asum-bsum)