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
s699421589
p03110
u853185302
2,000
1,048,576
Wrong Answer
17
3,060
220
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
N = int(input()) list_m = [input().split() for _ in range(N)] money = 0 for i in range(N): if list_m[i][1] == 'JPY': money += float(list_m[i][0]) else: money += float(list_m[i][0])*380000.0 print(int(money))
s119178503
Accepted
17
2,940
155
N = int(input()) o = [list(input().split()) for _ in range(N)] ans = 0 for x,u in o: if u == "JPY": ans+=int(x) else: ans += 380000*float(x) print(ans)
s024756528
p03555
u955251526
2,000
262,144
Wrong Answer
17
2,940
113
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.
a = input() b = input() for i in range(3): if a[i] != b[2-i]: print('No') exit() print('Yes')
s262261112
Accepted
17
2,940
113
a = input() b = input() for i in range(3): if a[i] != b[2-i]: print('NO') exit() print('YES')
s936909166
p02420
u427088273
1,000
131,072
Wrong Answer
30
7,584
203
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
while True: string = input() if string == '-': break num = -1 ind = len(string) for _ in range(int(input())): num += int(input()) print(string[num//ind:]+string[0:num//ind])
s710338595
Accepted
20
7,608
182
while True: string = input() if string == '-': break for i in range(int(input())): num = int(input()) string = string[num:] + string[:num] print(string)
s535211888
p03351
u641406334
2,000
1,048,576
Wrong Answer
17
3,060
152
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int,input().split()) if abs(a-b)<=d or abs(b-c)<=d: print("YES") elif abs(a-b)<=d and abs(b-c)<=d: print("Yes") else: print("No")
s997508399
Accepted
17
2,940
121
a, b, c, d = map(int,input().split()) if (abs(a-b)<=d and abs(b-c)<=d) or abs(a-c)<=d: print("Yes") else: print("No")
s868205104
p03170
u348481445
2,000
1,048,576
Wrong Answer
1,803
5,872
241
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other. Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro: * Choose an element x in A, and remove exactly x stones from the pile. A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
n,k=map(int,input().split()) a=list(map(int,input().split())) dp=[False]*(k+1) for i in range(0,k+1): for j in a: if i>=j and dp[i-j]==False: dp[i]=True print(dp) print ("First" if dp[k] else "Second")
s110598681
Accepted
1,708
3,828
232
n,k=map(int,input().split()) a=list(map(int,input().split())) dp=[False]*(k+1) for i in range(0,k+1): for j in a: if i>=j and dp[i-j]==False: dp[i]=True print ("First" if dp[k] else "Second")
s849145545
p03129
u709970295
2,000
1,048,576
Wrong Answer
17
2,940
88
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
n,k = map(int,input().split()) if n//2+ n%2 >= k: print('Yes') else: print('No')
s485637338
Accepted
17
2,940
89
n,k = map(int,input().split()) if n//2+ n%2 >= k: print('YES') else: print('NO')
s664851793
p03695
u812803774
2,000
262,144
Wrong Answer
18
3,064
1,024
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.
number = int(input()) rate = [int(i) for i in input().split()] counter = {} for r in rate: if 1 <= r < 400: counter["grey"] = counter.get("grey", 0) + 1 if 400 <= r < 800: counter["brown"] = counter.get("brown", 0) + 1 if 800 <= r < 1200: counter["green"] = counter.get("green", 0) + 1 if 1200 <= r < 1600: counter["sky"] = counter.get("sky", 0) + 1 if 1600 <= r < 2000: counter["blue"] = counter.get("blue", 0) + 1 if 2000 <= r < 2400: counter["yellow"] = counter.get("yellow", 0) + 1 if 2400 <= r < 2800: counter["orange"] = counter.get("orange", 0) + 1 if 2800 <= r < 3200: counter["red"] = counter.get("red", 0) + 1 if 3200 <= r: counter["color"] = counter.get("color", 0) + 1 answer = 0 for k, v in counter.items(): if not v == 0: answer += 1 if counter.get("color", 0) == 0: print(str(answer) + " ", str(answer)) else: print(str(answer-1) + " " + str(answer-1+counter["color"]))
s178328084
Accepted
17
3,064
1,114
number = int(input()) rate = [int(i) for i in input().split()] # In[7]: counter = {} for r in rate: if 1 <= r < 400: counter["grey"] = counter.get("grey", 0) + 1 if 400 <= r < 800: counter["brown"] = counter.get("brown", 0) + 1 if 800 <= r < 1200: counter["green"] = counter.get("green", 0) + 1 if 1200 <= r < 1600: counter["sky"] = counter.get("sky", 0) + 1 if 1600 <= r < 2000: counter["blue"] = counter.get("blue", 0) + 1 if 2000 <= r < 2400: counter["yellow"] = counter.get("yellow", 0) + 1 if 2400 <= r < 2800: counter["orange"] = counter.get("orange", 0) + 1 if 2800 <= r < 3200: counter["red"] = counter.get("red", 0) + 1 if 3200 <= r: counter["color"] = counter.get("color", 0) + 1 answer = 0 for k, v in counter.items(): if not v == 0: answer += 1 if counter.get("color", 0) == 0: print(str(answer) + " " + str(answer)) else: if answer == 1: print("1 " + str(counter["color"])) else: print(str(answer-1) + " " + str(answer-1+counter["color"]))
s052296487
p03623
u218838821
2,000
262,144
Wrong Answer
30
9,008
131
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
S = input() S_set = set(S) for i in range(97,123): if chr(i) not in S_set: print(chr(i)) exit() print("None")
s200659472
Accepted
25
9,092
91
x, a, b = map(int,input().split()) if abs(a-x) > abs(b-x): print("B") else: print("A")
s067701382
p02578
u784450941
2,000
1,048,576
Wrong Answer
175
33,948
602
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.
# cording:utf-8 N = int(input()) N_i = [0] * N N_i = list(map(int, input().split())) print(N_i) Sum = 0 for i in range(1, N): Sum_i = 0 if (N_i[i-1] + Sum_i) > N_i[i]: Sum_i = N_i[i-1] - N_i[i] N_i[i] = N_i[i] + Sum_i Sum = Sum + Sum_i print(Sum)
s650477836
Accepted
153
33,632
581
# cording:utf-8 N = int(input()) N_i = [0] * N N_i = list(map(int, input().split())) Sum = 0 for i in range(1, N): Sum_i = 0 if N_i[i-1] > N_i[i]: Sum_i = N_i[i-1] - N_i[i] N_i[i] = N_i[i] + Sum_i Sum = Sum + Sum_i print(Sum)
s016156067
p03826
u283846680
2,000
262,144
Wrong Answer
18
2,940
64
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
a, b, c, d = list(map(int, input().split())) print(min(a*b,c*d))
s273641117
Accepted
17
2,940
65
a, b, c, d = list(map(int, input().split())) print(max(a*b,c*d))
s053699657
p03860
u172035535
2,000
262,144
Wrong Answer
17
2,940
34
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
print("AtCoder",input(),"Contest")
s611254569
Accepted
17
2,940
45
a,b,c = input().split() print(a[0]+b[0]+c[0])
s742338472
p02419
u744506422
1,000
131,072
Wrong Answer
20
5,556
167
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
st=input() count=0 while(True): s=input() if s=="END_OF_TEXT": break t=s.split() for k in t: if k==s: count+=1 print(count)
s584208437
Accepted
20
5,556
176
st=input() count=0 while(True): s=input() if s=="END_OF_TEXT": break t=s.split() for k in t: if k.lower()==st: count+=1 print(count)
s231065969
p00011
u379956761
1,000
131,072
Wrong Answer
30
6,788
352
Let's play Amidakuji. In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines. In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom. Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right.
#!/usr/bin/env python #-*- coding:utf-8 -*- import sys import math w = int(input()) n = int(input()) s = [] for _ in range(n): x = input().split(',') s.append((int(x[0]), int(x[1]))) result = [i for i in range(1, w+1)] print(len(result)) for x, y in s: result[x-1], result[y-1] = result[y-1], result[x-1] for x in result: print(x)
s563667379
Accepted
30
6,784
333
#!/usr/bin/env python #-*- coding:utf-8 -*- import sys import math w = int(input()) n = int(input()) s = [] for _ in range(n): x = input().split(',') s.append((int(x[0]), int(x[1]))) result = [i for i in range(1, w+1)] for x, y in s: result[x-1], result[y-1] = result[y-1], result[x-1] for x in result: print(x)
s139430215
p03457
u854685063
2,000
262,144
Wrong Answer
344
17,580
967
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
import sys import math import itertools as it def I():return int(sys.stdin.readline().replace("\n","")) def I2():return map(int,sys.stdin.readline().replace("\n","").split()) def S():return str(sys.stdin.readline().replace("\n","")) def L():return list(sys.stdin.readline().replace("\n","")) def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()] def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split())) def f(x1,y1,x2,y2,t): l = abs(x1-x2)+abs(y1-y2) if l <= t: if l%2 == t%2: return True return False if __name__ == "__main__": n = I() t = [0] x = [0] y = [0] for i in range(n): a,b,c = I2() t.append(a) x.append(b) y.append(c) for i in range(n): print(x[i],y[i],x[i+1],y[i+1],t[i+1]-t[i]) if not f(x[i],y[i],x[i+1],y[i+1],t[i+1]-t[i]): print("No") exit() print("Yes")
s576485796
Accepted
188
17,564
968
import sys import math import itertools as it def I():return int(sys.stdin.readline().replace("\n","")) def I2():return map(int,sys.stdin.readline().replace("\n","").split()) def S():return str(sys.stdin.readline().replace("\n","")) def L():return list(sys.stdin.readline().replace("\n","")) def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()] def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split())) def f(x1,y1,x2,y2,t): l = abs(x1-x2)+abs(y1-y2) if l <= t: if l%2 == t%2: return True return False if __name__ == "__main__": n = I() t = [0] x = [0] y = [0] for i in range(n): a,b,c = I2() t.append(a) x.append(b) y.append(c) for i in range(n): #print(x[i],y[i],x[i+1],y[i+1],t[i+1]-t[i]) if not f(x[i],y[i],x[i+1],y[i+1],t[i+1]-t[i]): print("No") exit() print("Yes")
s759066779
p02928
u445624660
2,000
1,048,576
Wrong Answer
1,832
21,620
573
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
n, k = map(int, input().split()) a = list(map(int, input().split())) x, y = 0, 0 for i in range(n - 1): for j in range(i + 1, n): if a[i] > a[j]: x += 1 for i in range(n - 1, 0, -1): for j in range(i - 1, -1, -1): if a[j] < a[i]: print("yes i, j={}, {}".format(i, j)) y += 1 print() print(x, y) MOD = 10 ** 9 + 7 print((x * k) % MOD + (y * (k - 1)) % MOD)
s592943800
Accepted
539
9,272
1,082
# # 3 4 2 1 2 -> 3+3+1+0+0 = 7 # 3 4 2 1 2 | 3 4 2 1 2 -> (3*2)+(1*1+3*2)+(1*2)+0+(1*1) + 7 = 16 + 7 # 3 4 2 1 2 | 3 4 2 1 2 | 3 4 2 1 2 -> (3*3)+(2*1+3*3)+(1*3)+0+(2*1) + 16+7 = 25+16+7 n, k = map(int, input().split()) a = list(map(int, input().split())) mod = 10**9 + 7 base = 0 for i in range(n): for j in range(i, n): if a[i] > a[j]: base += 1 additional = 0 for i in range(n): for j in range(i): if a[i] > a[j]: additional += 1 ans = (k * (k + 1) // 2 % mod * base + (k - 1) * k // 2 % mod * additional) % mod print(ans)
s316933590
p03860
u115877451
2,000
262,144
Wrong Answer
17
2,940
84
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
a=input().split(' ') b=a[1] c=list(str(b)) print(c) d=c[0] print('A',d,'C',sep='')
s079120769
Accepted
17
2,940
75
a=input().split(' ') b=a[1] c=list(str(b)) d=c[0] print('A',d,'C',sep='')
s857813744
p03485
u546440137
2,000
262,144
Wrong Answer
26
8,968
61
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b=map(int,input().split()) c=(a+b-1)/b d=int(c) print(d)
s994440806
Accepted
25
9,124
197
a,b=map(int,input().split()) if a%2==0 and b%2==0: print(int((a+b)/2)) elif a%2==1 and b%2==1: print(int((a+b)/2)) elif a%2==0 and b%2==1: print(int((a+b+1)/2)) else: print(int((a+b+1)/2))
s787024181
p03657
u003501233
2,000
262,144
Wrong Answer
18
2,940
94
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
A,B=map(int,input().split()) if A+B % 3 == 0: print("Possible") else: print("Impossible")
s436438025
Accepted
17
2,940
112
A,B=map(int,input().split()) if A%3==0 or B%3==0 or (A+B)%3==0: print("Possible") else: print("Impossible")
s645179376
p03448
u136395536
2,000
262,144
Wrong Answer
53
3,060
268
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) #500 B = int(input()) #100 C = int(input()) #50 X = int(input()) count = 0 for i in range(1,A+1): for j in range(1,B+1): for k in range(1,C+1): if (X%(500*i+100*j+50*k)==0): count = count + 1 print(count)
s233241453
Accepted
57
3,060
269
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): summy = 500*i + 100*j + 50*k if summy == X: count = count + 1 print(count)
s741599857
p02259
u496045719
1,000
131,072
Wrong Answer
20
7,500
361
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
def main(): element_num = int(input()) elements = [int(s) for s in input().split()] swap_count = 0 for i in range(1, element_num): for j in reversed(range(i, element_num)): if elements[j-1] > elements[j]: elements[j-1], elements[j] = elements[j], elements[j-1] swap_count += 1 print(elements) print(swap_count) return 0
s234658876
Accepted
40
7,676
424
def main(): element_num = int(input()) elements = [int(s) for s in input().split()] swap_count = 0 for i in range(1, element_num): for j in reversed(range(i, element_num)): if elements[j-1] > elements[j]: elements[j-1], elements[j] = elements[j], elements[j-1] swap_count += 1 print(' '.join(list(map(str, elements)))) print(swap_count) return 0 if __name__ == '__main__': main()
s503966778
p03993
u403355272
2,000
262,144
Wrong Answer
160
14,008
171
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()) jk =0 le = list(map(int,input().split())) le = [0] + le for i in range(N): print(le[le[i]]) if le[le[i]] == i: jk += 1 print(le[le[i]])
s751803049
Accepted
63
13,880
148
N = int(input()) jk =0 le = list(map(int,input().split())) le = [0] + le for i in range(N): if le[le[i]] == i: jk += 1 print(jk // 2)
s984210656
p03228
u334535590
2,000
1,048,576
Wrong Answer
17
3,060
267
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
# -*- coding-UTF-8 -*- A, B, K = map(int, input().split()) i = 0 while True: i += 1 if A%2: A -= 1 A /= 2 B += A if i == K: break i += 1 if B%2: B -= 1 B /= 2 A += B if i == K: break print(A,B)
s093059107
Accepted
18
3,060
277
# -*- coding-UTF-8 -*- A, B, K = map(int, input().split()) i = 0 while True: i += 1 if A%2: A -= 1 A /= 2 B += A if i == K: break i += 1 if B%2: B -= 1 B /= 2 A += B if i == K: break print(int(A),int(B))
s505689310
p03394
u843135954
2,000
262,144
Wrong Answer
38
9,476
631
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n = ni() import math a = [2,3] now = 30000 for i in range(n-2): if i == n-3: total = sum(a) while True: if (total+now)%6 == 0 and math.gcd(total,now) > 1: a.append(now) break now-=1 else: while True: if now%2 == 0 or now%3 == 0: a.append(now) break now-=1 print(*a)
s916613417
Accepted
43
10,112
991
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n = ni() import math if n==3: print(2,5,63) exit() a = [2,3,5] now = 30000 for i in range(n-3): if i == n-4: total = sum(a) m = now while True: if (total+now)%30 == 0 and math.gcd(total,now) > 1: a.append(now) break if now < 6: if a[-1]%2==0: a[-1]-=2 elif a[-1]%3==0: a[-1]-=3 elif a[-1]%5==0: a[-1]-=5 total = sum(a) now = m+1 now-=1 else: while True: if now%2 == 0 or now%3 == 0 or now%5 == 0: a.append(now) now-=1 break now-=1 print(*a)
s276137710
p03457
u975966195
2,000
262,144
Wrong Answer
416
27,300
416
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
n = int(input()) info = [list(map(int, input().split())) for i in range(n)] info.insert(0, [0, 0, 0]) x_diff, y_diff = 0, 0 for i in range(n): dt = info[i+1][0] - info[i][0] x_diff = abs(info[i+1][1] - info[i][1]) y_diff = abs(info[i+1][2] - info[i][2]) if dt < x_diff + y_diff: print('NO') exit() if dt%2 != (x_diff + y_diff)%2: print('NO') exit() print('YES')
s673571527
Accepted
319
2,940
163
n = int(input()) for i in range(n): t, x, y = map(int, input().split()) if (x + y) > t or (x + y + t) % 2: print('No') exit() print('Yes')
s094210718
p03433
u381572327
2,000
262,144
Wrong Answer
18
2,940
130
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N, A = int(input()), int(input()) print(N, A) while N >= 500: N = N - 500 if A >= N: print("Yes") else: print("No")
s452197295
Accepted
18
2,940
118
N, A = int(input()), int(input()) while N >= 500: N = N - 500 if A >= N: print("Yes") else: print("No")
s412995760
p03730
u762420987
2,000
262,144
Wrong Answer
20
2,940
239
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A,B,C = map(int,input().split()) A_ = A counter = 0 while True: if A_%B == C: print("Yes") break A_ += A counter += 1 if counter > B: print("No") break #go
s847983441
Accepted
17
2,940
239
A,B,C = map(int,input().split()) A_ = A counter = 0 while True: if A_%B == C: print("YES") break A_ += A counter += 1 if counter > B: print("NO") break #go
s002407435
p02613
u785728112
2,000
1,048,576
Wrong Answer
163
16,320
329
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) S = [] a = 0 t = 0 w = 0 r = 0 for _ in range(n): S.append(input()) for i in range(n): if S[i]=="AC": a += 1 elif S[i]=="TLE": t += 1 elif S[i]=="WA": w += 1 else: r += 1 a = str(a) w = str(w) t = str(t) r = str(r) print("ACx"+a) print("WAx"+w) print("TLE"+t) print("REx"+r)
s755986579
Accepted
170
16,132
328
n = int(input()) S = [] a = 0 t = 0 w = 0 r = 0 for _ in range(n): S.append(input()) for i in range(n): if S[i]=="AC": a += 1 elif S[i]=="TLE": t += 1 elif S[i]=="WA": w += 1 else: r += 1 a = str(a) w = str(w) t = str(t) r = str(r) print("AC x "+a) print("WA x "+w) print("TLE x "+t) print("RE x "+r)
s702584901
p02613
u695329583
2,000
1,048,576
Wrong Answer
149
9,096
204
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) for _ in range(n) : l = list(input()) print('AC x ' + str(l.count('AC'))) print('WA x ' + str(l.count('WA'))) print('TLE x ' + str(l.count('TLE'))) print('RE x ' + str(l.count('RE')))
s615206278
Accepted
148
16,204
211
n = int(input()) l = [] for i in range(n) : l.append(input()) print('AC x ' + str(l.count('AC'))) print('WA x ' + str(l.count('WA'))) print('TLE x ' + str(l.count('TLE'))) print('RE x ' + str(l.count('RE')))
s747024276
p03472
u797550216
2,000
262,144
Wrong Answer
411
29,812
565
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
import bisect import sys n,h = map(int,input().split()) ab = [list(map(int,input().split())) for i in range(n)] b = [ab[i][1] for i in range(n)] if n == 1: if h <= ab[0][1]: print(1) sys.exit() else: print(1+(h-ab[0][1])//ab[0][0]) sys.exit() max_a = 0 for i in range(n): max_a = max(max_a, ab[i][0]) b.sort() idx = bisect.bisect_right(b,max_a) ans = 0 for i in b[idx:][::-1]: h -= i ans += 1 if h <= 0: break if h <= 0: print(ans) else: print(ans + h//max_a)
s438404593
Accepted
417
29,716
727
import bisect import sys import math n,h = map(int,input().split()) ab = [list(map(int,input().split())) for i in range(n)] b = [ab[i][1] for i in range(n)] if n == 1: if h <= ab[0][1]: print(1) sys.exit() else: if ab[0][1] >= ab[0][0]: print(1+(math.ceil((h-ab[0][1])/ab[0][0]))) sys.exit() else: print(math.ceil(h/ab[0][1])) sys.exit() max_a = 0 for i in range(n): max_a = max(max_a, ab[i][0]) b.sort() idx = bisect.bisect_right(b,max_a) ans = 0 for i in b[idx:][::-1]: h -= i ans += 1 if h <= 0: break if h <= 0: print(ans) else: print(ans + math.ceil(h/max_a))
s794096434
p03251
u622570247
2,000
1,048,576
Wrong Answer
28
9,024
224
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
n, m, x, y = map(int, input().split()) xx = tuple(map(int, input().split())) yy = tuple(map(int, input().split())) if x > y: print('War') exit(0) if min(yy) - max(xx) > 1: print("No War") else: print("War")
s635146210
Accepted
27
9,108
221
n, m, x, y = map(int, input().split()) xx = tuple(map(int, input().split())) + (x,) yy = tuple(map(int, input().split())) + (y,) maxx = max(xx) miny = min(yy) if maxx >= miny: print('War') else: print('No War')
s242413297
p02694
u332317213
2,000
1,048,576
Wrong Answer
24
9,176
245
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import math def main(): X = input() X = int(X) output = 100 year = 0 while output <= X: output = int(output * 1.01) math.floor(output) year += 1 print(year) if __name__ == "__main__": main()
s361846155
Accepted
22
9,156
244
import math def main(): X = input() X = int(X) output = 100 year = 0 while output < X: output = int(output * 1.01) math.floor(output) year += 1 print(year) if __name__ == "__main__": main()
s899714241
p02972
u830054172
2,000
1,048,576
Wrong Answer
108
6,880
379
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
n = int(input()) a = input() al = list(map(int, a.split())) ans = [al.index(i)+1 for i in al if i == 1] if set(al) == 0: print(0) else: if sum(al)%2 != al[0]: print(-1) else: for i in range(2,n): if sum(al[i::i])%2 != al[i]: print(-1) break else: print(sum(al)) print(ans)
s972113901
Accepted
552
22,324
665
N = int(input()) a = list(map(int, input().split())) b = [0 for i in range(N)] def check(i): n = i cnt = 0 while n <= N: cnt += b[n-1] n += i return cnt for i in range(N-1, -1, -1): if (a[i]+check(i+1))%2 == 1: b[i] = 1 ans = sum(b) ll = [] for i in range(N): if b[i] == 1: ll.append(i+1) lll = [str(i) for i in ll] if ans == 0: print(ans) else: print(ans) print(" ".join(lll))
s831940631
p03637
u549383771
2,000
262,144
Wrong Answer
17
3,064
338
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
a_list = list(map(int,input().split())) cntn = 0 cnt2 = 0 cnt4 = 0 for i in a_list: if i%4 == 0: cnt4 += 1 elif i%2 == 0: cnt2 += 1 else: cntn += 1 cnt4seat = cnt4*2 flag = True cnt4seat -= cntn if cnt2 == 1: cnt4seat -= 1 if cnt4seat >= 0: print('Yes') else: print('No')
s459720246
Accepted
64
15,020
421
n = int(input()) a_list = list(map(int,input().split())) cntn = 0 cnt2 = 0 cnt4 = 0 for i in a_list: if i%4 == 0: cnt4 += 1 elif i%2 == 0: cnt2 += 1 else: cntn += 1 flag = True if cnt4+ 1 >= cntn : flag = True else: flag = False if cnt2 >= 1: if cnt4 >= cntn : flag = True else: flag = False if flag: print('Yes') else: print('No')
s541697852
p02751
u340781749
2,000
1,048,576
Wrong Answer
19
6,004
155
We have a grid with (2^N - 1) rows and (2^M-1) columns. You are asked to write 0 or 1 in each of these squares. Let a_{i,j} be the number written in the square at the i-th row from the top and the j-th column from the left. For a quadruple of integers (i_1, i_2, j_1, j_2) such that 1\leq i_1 \leq i_2\leq 2^N-1, 1\leq j_1 \leq j_2\leq 2^M-1, let S(i_1, i_2, j_1, j_2) = \displaystyle \sum_{r=i_1}^{i_2}\sum_{c=j_1}^{j_2}a_{r,c}. Then, let the _oddness_ of the grid be the number of quadruples (i_1, i_2, j_1, j_2) such that S(i_1, i_2, j_1, j_2) is odd. Find a way to fill in the grid that maximizes its oddness.
n, m = map(int, input().split()) ans = [] ans.append('0' + '1' * (2 ** m - 2)) ans.extend(['1' + '0' * (2 ** m - 2)] * (2 ** n - 2)) print('\n'.join(ans))
s240355641
Accepted
22
6,840
559
n, m = map(int, input().split()) ans = [0, 1] for i in range(1, min(n, m)): k = 1 << i x = (1 << k) - 1 slide = [a << k for a in ans] new_ans = [s | a for s, a in zip(slide, ans)] new_ans.extend(s | (a ^ x) for s, a in zip(slide, ans)) ans = new_ans if n > m: ans *= 1 << (n - m) elif n < m: for i in range(n, m): k = 1 << i ans = [(a << k) | a for a in ans] ans = [a0 ^ a1 for a0, a1 in zip(ans, ans[1:])] ans = [a ^ (a >> 1) for a in ans] print('\n'.join(map(('{:0' + str(2 ** m - 1) + 'b}').format, ans)))
s878859719
p02388
u318393460
1,000
131,072
Wrong Answer
20
5,572
27
Write a program which calculates the cube of a given integer x.
x =int(input()) print(x^3)
s618690861
Accepted
20
5,576
29
x = int(input()) print(x**3)
s377432341
p02795
u306950978
2,000
1,048,576
Wrong Answer
17
2,940
72
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
h = int(input()) w = int(input()) n = int(input()) print(min(n//h,n//w))
s015776233
Accepted
18
3,064
80
h = int(input()) w = int(input()) n = int(input()) print(min(-(-n//h),-(-n//w)))
s835343138
p03599
u540307496
3,000
262,144
Wrong Answer
29
3,064
622
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
a,b,c,d,e,f=map(int,input().split()) ans_wat = 0 ans_sug = 0 ans_rate = 0 maxrate = 100 * e / (e + 100) for i in range(31): for j in range(31): water = (i * a + j * b) * 100 if (water <= f and water): nsug = min(f - water, water) for k in range(nsug): l = (nsug - k*c) suger = k * c + l * d rate = 100 * suger / (suger + water) if(ans_rate <= rate) and (rate <= maxrate): ans_rate = rate ans_sug = suger ans_wat = water print(ans_wat+ans_sug,ans_sug)
s809998280
Accepted
21
3,064
588
a,b,c,d,e,f=map(int,input().split()) ans_wat = 0 ans_sug = 0 ans_rate = 0 for i in range(31): for j in range(31): water = (i * a + j * b) * 100 if (water <= f and water): nsug = min(water * e // 100, f - water) for k in range(nsug//c+1): l = (nsug - k*c)//d suger = k * c + l * d rate = 100 * suger / (suger + water) if(ans_rate <= rate): ans_rate = rate ans_sug = suger ans_wat = water print(ans_wat+ans_sug,ans_sug)
s101540717
p03360
u818655004
2,000
262,144
Wrong Answer
17
2,940
117
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
a, b, c = map(int, input().split()) k = int(input()) m = max(max(a, b), c) sum_ = a + b + c res = sum_ - m + m*(2**k)
s933931218
Accepted
17
2,940
128
a, b, c = map(int, input().split()) k = int(input()) m = max(max(a, b), c) sum_ = a + b + c res = sum_ - m + m*(2**k) print(res)
s537457263
p03502
u074220993
2,000
262,144
Wrong Answer
29
9,112
95
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N = input() f = lambda X:sum(int(x) for x in X) print('Yes' if f(N)%int(N) == 0 else 'No')
s283695804
Accepted
27
9,072
167
def harshad(n): if n % sum(map(int, list(str(n)))) == 0: return True else: return False N = int(input()) print('Yes' if harshad(N) else 'No')
s838288594
p01839
u046108504
8,000
524,288
Wrong Answer
20
5,596
364
時は進んで 2060 年,共に 70 歳を迎える前田さんと後藤さんは長い付き合いの友人であり,大学時代にACM-ICPCで共に戦った仲間でもある. 二人は今でもよく一緒にお茶を飲みつつ,競技プログラミングの話で盛り上がっている. 二人で一緒にお茶を飲む時,前田さんが 1 回`A`と言うと,その発言の後に後藤さんがちょうど 1 回`Un`と返事をする習慣がいつのまにか出来た. しかし最近後藤さんは物忘れや勘違いをすることが多く,前田さんが`A`と言っても,後藤さんはたまに`Un`の返事を忘れたり,余計に返事をしたりする. ついこの間も前田さんと後藤さんはお茶を飲みながら,二人のお気に入りのデータ構造について話し込んでいたようだ. この時の会話の中から,`A`で表される前田さんの発言と,`Un`で表される後藤さんの返事のみからなる記録が時系列で与えられたとき,後藤さんが習慣通りに反応したとみなすことが出来るかチェックしてほしい. 注意点として,前田さんの発言に対し,後藤さんの返事が多少遅れても,後藤さんは習慣通りに反応したとみなせる場合がある,ということが挙げられる. 例えば,前田さんが2回連続して`A`と言った後,後藤さんが 2 回連続して`Un`と返事をして会話が終了した場合は,後藤さんが習慣通りの返事をしたとみなされる (Sample Input 2 参照). また,会話が終了した時点で,前田さんが`A`と言った回数と,後藤さんが`Un`と返事した回数が一致しても,後藤さんが習慣通りに返事をしたとはみなされない場合もあるので注意すること. 例えば,前田さんが1回`A`と言った後,後藤さんが 2 回連続して`Un`と返事し,その後で前田さんが 1 回`A`と言って会話が終了した場合は,後藤さんが習慣通りの返事をしたとはみなされない (Sample Input 3 参照).
def solve(): N = int(input()) S = [input() for _ in range(N)] a_count = 1 if S[0] == "A" else -1 if N == 1 and a_count == -1: return "NO" for i in range(1, N): if a_count > 0: a_count += 1 if S[i] == "A" else -1 else: return "NO" return "YES" if __name__ == "__main__": print(solve())
s894127621
Accepted
20
5,604
424
def solve(): N = int(input()) S = [input() for _ in range(N)] a_count = 1 if S[0] == "A" else -1 # if N == 1 and a_count == -1: # return "NO" for i in range(1, N): if a_count >= 0: a_count += 1 if S[i] == "A" else -1 else: return "NO" if a_count == 0: return "YES" else: return "NO" if __name__ == "__main__": print(solve())
s263021908
p03544
u819710930
2,000
262,144
Wrong Answer
17
3,064
66
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
a,b=2,1 n=int(input()) for i in range(n-1): a,b=b,a+b print(a)
s464422012
Accepted
17
2,940
62
a,b=2,1 for i in range(int(input())): a,b=b,(a+b) print(a)
s124435374
p03370
u681323954
2,000
262,144
Wrong Answer
18
2,940
91
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
n,x=map(int,input().split()) M=[int(input()) for _ in range(n)] print(x-sum(M) + x//min(M))
s743628030
Accepted
18
2,940
93
n,x=map(int,input().split()) l=[int(input()) for _ in range(n)] print(n+((x-sum(l))//min(l)))
s928391895
p03478
u172569352
2,000
262,144
Wrong Answer
37
3,552
189
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
N, A, B = [int(i) for i in input().split()] b = [] for i in range(N+1): a = [int(j) for j in list(str(i))] if A <= sum(a) <=B: b.append(i) print(b) print(sum(b))
s540688209
Accepted
37
3,296
170
N, A, B = [int(i) for i in input().split()] b = [] for i in range(N+1): a = [int(j) for j in list(str(i))] if A <= sum(a) <=B: b.append(i) print(sum(b))
s145164899
p03407
u721970149
2,000
262,144
Wrong Answer
19
2,940
135
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
A, B, C = map(int, input().split()) if A == C or B == C or (A+B) == C : print("Yes") else : print("No")
s503280810
Accepted
17
2,940
115
A, B, C = map(int, input().split()) if (A+B) >= C : print("Yes") else : print("No")
s292424319
p03149
u981767024
2,000
1,048,576
Wrong Answer
17
3,060
397
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".
# 2019/01/13 # Input n = [0, 0, 0, 0] val = [1, 9, 7, 4] valflg = [0, 0, 0, 0] n[0], n[1], n[2], n[3] = map(int,input().split()) for idx in range(4): for idx2 in range(4): if n[idx] == val[idx2]: valflg[idx2] = 1 if valflg[0] + valflg[1] + valflg[2] + valflg[3] == 4: ans = "Yes" else: ans = "No" # Output print(ans)
s531825360
Accepted
19
3,064
400
# 2019/01/13 # Input n = [0, 0, 0, 0] val = [1, 9, 7, 4] valflg = [0, 0, 0, 0] n[0], n[1], n[2], n[3] = map(int,input().split()) for idx in range(4): for idx2 in range(4): if n[idx] == val[idx2]: valflg[idx2] = 1 if valflg[0] + valflg[1] + valflg[2] + valflg[3] == 4: ans = "YES" else: ans = "NO" # Output print(ans)
s880179805
p03417
u690536347
2,000
262,144
Wrong Answer
17
3,064
97
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
a,b=map(int,input().split()) if b==1: print(b-2) elif b==2: print(b+2) else: print((b-2)*a)
s921567975
Accepted
17
3,060
130
l=list(map(int,input().split())) N=min(l) M=max(l) if N==1 and M==1: print(1) elif N==1: print(M-2) else: print((M-2)*(N-2))
s915161750
p03693
u019053283
2,000
262,144
Wrong Answer
17
2,940
194
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
from sys import stdin A, B, C = [int(x) for x in stdin.readline().rstrip().split()] total = str(A) + str(B) + str(C) print(total) if int(total) % 4 == 0: print('Yes') else: print('No')
s305801551
Accepted
18
2,940
181
from sys import stdin A, B, C = [int(x) for x in stdin.readline().rstrip().split()] total = str(A) + str(B) + str(C) if int(total) % 4 == 0: print('YES') else: print('NO')
s662752867
p03471
u391819434
2,000
262,144
Wrong Answer
28
9,180
206
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()) x=y=z=0 while N and 5000*N<Y: Y-=10000 N-=1 x+=1 while N and 1000*N<Y: Y-=5000 N-=1 y+=1 z=N if z*1000==Y: print(x,y,z) else: print(-1,-1,-1)
s404728089
Accepted
660
9,116
196
N,Y=map(int,input().split()) x=y=z=0 ans=[-1,-1,-1] while x<=N: y=0 while x+y<=N: if 10000*x+5000*y+1000*(N-x-y)==Y: ans=[x,y,N-x-y] y+=1 x+=1 print(*ans)
s908130694
p02606
u050017042
2,000
1,048,576
Wrong Answer
27
9,072
99
How many multiples of d are there among the integers between L and R (inclusive)?
l,r,d=map(int,input().split()) ans=0 for i in range(l,r+1): if d%i==0: ans+=1 print(ans)
s688549062
Accepted
23
9,012
94
l,r,d=map(int,input().split()) ans=0 for i in range(l,r+1): if i%d==0: ans+=1 print(ans)
s787145290
p03730
u886297662
2,000
262,144
Wrong Answer
2,103
2,940
127
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = map(int, input().split()) k = 1 while a * k < b: if a * k % b == c: print('YES') break else: print('NO')
s563392405
Accepted
17
2,940
200
a, b, c = map(int, input().split()) k = 1 cnt = 0 while True: amari = a * k % b if amari == c: cnt += 1 if amari == 0: break k += 1 if cnt == 0: print('NO') else: print('YES')
s402263389
p02396
u186282999
1,000
131,072
Wrong Answer
140
8,000
260
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
input_list = [] flag = True while flag: input_value = input() if input_value == "0": flag = False input_list.append(input_value) print("Hello") for i in range(0, len(input_list)-1): print("Case {0}:{1}".format(i, input_list[i]))
s560517939
Accepted
70
8,044
245
input_list = [] flag = True while flag: input_value = input() if input_value == "0": flag = False input_list.append(input_value) for i in range(0, len(input_list)-1): print("Case {0}: {1}".format(i+1, input_list[i]))
s421680520
p03836
u821588465
2,000
262,144
Wrong Answer
30
9,416
462
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()) ans = [] for i in range(ty-sy): ans.append('U') for i in range(tx-sx): ans.append('R') for i in range(abs(sy-ty)): ans.append('D') for i in range(abs(sx-tx)): ans.append('L') ans.append('L') for i in range(ty+1-sy): ans.append('U') for i in range(tx-sx+1): ans.append('R') ans.append('D') ans.append('R') for i in range(abs(sx-tx)+1): ans.append('L') ans.append('U') print(*ans, sep='')
s284762759
Accepted
28
9,280
512
sx, sy, tx, ty = map(int, input().split()) ans = [] for i in range(ty-sy): ans.append("U") for i in range(tx-sx): ans.append("R") for i in range(abs(sy-ty)): ans.append("D") for i in range(abs(sx-tx)): ans.append("L") ans.append("L") for i in range(ty-sy+1): ans.append("U") for i in range(tx-sx+1): ans.append("R") ans.append("D") ans.append("R") for i in range(abs(sy-ty)+1): ans.append("D") for i in range(abs(sx-tx)+1): ans.append("L") ans.append("U") print(*ans, sep='')
s365692267
p00003
u600263347
1,000
131,072
Wrong Answer
40
5,600
278
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
def main(): n = int(input()) for i in range(n): Array = list(map(int,input().split())) Array.sort() if Array[2]**2 == Array[0]**2 + Array[1]**2: print("yes") else: print("No") if __name__ == '__main__': main()
s031911519
Accepted
40
5,604
278
def main(): n = int(input()) for i in range(n): Array = list(map(int,input().split())) Array.sort() if Array[2]**2 == Array[0]**2 + Array[1]**2: print("YES") else: print("NO") if __name__ == '__main__': main()
s188211607
p03698
u946424121
2,000
262,144
Wrong Answer
17
2,940
91
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s = input() if [x for x in s] == set([x for x in s]): print("yes") else: print("no")
s542688589
Accepted
17
2,940
62
s = input() print("yes" if len(s) == len(set(s)) else "no")
s773005407
p03637
u282228874
2,000
262,144
Wrong Answer
67
14,252
337
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
n = int(input()) A =list(map(int,input().split())) num4 = [] num2 = [] num1 = [] for a in A: if a%4 == 0: num4.append(a) elif a%2 == 0: num2.append(a) else: num1.append(a) if len(num1)-1 > len(num4): print("No") elif len(num2)==1 and len(num4)<len(num1)+1: print("No") else: print("Yes")
s618888138
Accepted
66
14,252
357
n = int(input()) A =list(map(int,input().split())) num4 = 0 num2 = 0 num1 = 0 for a in A: if a%4 == 0: num4 += 1 elif a%2 == 0: num2 += 1 else: num1 += 1 if num2 == 0: if num4 >= num1-1: print("Yes") else: print("No") else: if num4 >= num1: print("Yes") else: print("No")
s155026830
p02415
u498511622
1,000
131,072
Wrong Answer
20
7,328
26
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
x=input().lower() print(x)
s824783306
Accepted
20
7,396
25
print(input().swapcase())
s304189342
p02613
u810787773
2,000
1,048,576
Wrong Answer
145
16,204
444
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.
def main(): N = int(input()) S = [input() for _ in range(N)] AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(N): if S[i] == 'AC': AC += 1 elif S[i] == 'WA': WA += 1 elif S[i] == 'TLE': TLE += 1 else: RE += 1 print('AC × ' + str(AC)) print('WA × ' + str(WA)) print('TLE × ' + str(TLE)) print('RE × ' + str(RE)) main()
s955632708
Accepted
142
16,244
440
def main(): N = int(input()) S = [input() for _ in range(N)] AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(N): if S[i] == 'AC': AC += 1 elif S[i] == 'WA': WA += 1 elif S[i] == 'TLE': TLE += 1 else: RE += 1 print('AC x ' + str(AC)) print('WA x ' + str(WA)) print('TLE x ' + str(TLE)) print('RE x ' + str(RE)) main()
s272302984
p02255
u428229577
1,000
131,072
Wrong Answer
20
7,332
254
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.
leng = input() ind = input() indsprit = ind.split(" ") print(indsprit) for i in range(len(indsprit)): v = indsprit[i] j = i -1 while j >= 0 and indsprit[j] > v: indsprit[j+1] = indsprit[j] j -= 1 indsprit[j+1] = v print(indsprit) print(indsprit)
s048507332
Accepted
20
8,016
180
N = int(input()) A = list(map(int, input().split())) print(*A) for i in range(1, 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(*A)
s367119247
p02600
u320304481
2,000
1,048,576
Wrong Answer
30
9,068
89
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
X = int(input()) if 400 <= X <= 599: print(8) else: t = X//200 -1 print(8-t)
s621599139
Accepted
28
9,024
34
X = int(input()) print(10-X//200)
s433370622
p02245
u960937651
1,000
131,072
Wrong Answer
30
6,012
910
The goal of the 8 puzzle problem is to complete pieces on $3 \times 3$ cells where one of the cells is empty space. In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 8 as shown below. 1 3 0 4 2 5 7 8 6 You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps). 1 2 3 4 5 6 7 8 0 Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle.
from collections import deque MOVE = {'U': (0, -1), 'D': (0, 1), 'L': (-1, 0), 'R': (1, 0)} def next(numbers): for d in 'UDLR': z = numbers.index(0) tx, ty = z % 3 + MOVE[d][0], z if 0 <= tx < 3 and 0 <= ty < 3: t = ty * 3 + tx result = list(numbers) result[z], result[t] = numbers[t], 0 yield d, tuple(result) def bfs(puzzle): queue = deque([(puzzle, '')]) seen = set() while queue: numbers, route = queue.popleft() seen.add(numbers) if numbers == (1, 2, 3, 4, 5, 6, 7, 8, 0): return route for direction, new_numbers in next(numbers): if new_numbers not in seen: queue.append((new_numbers, route + direction)) return route puzzle = () for i in range(3): a,b,c = map(int, input().split()) puzzle += (a,b,c) print(len(bfs(puzzle)))
s226518475
Accepted
3,830
55,808
927
from collections import deque MOVE = {'U': (0, -1), 'D': (0, 1), 'L': (-1, 0), 'R': (1, 0)} def next(numbers): for d in 'UDLR': z = numbers.index(0) tx, ty = z % 3 + MOVE[d][0], z // 3 + MOVE[d][1] if 0 <= tx < 3 and 0 <= ty < 3: t = ty * 3 + tx result = list(numbers) result[z], result[t] = numbers[t], 0 yield d, tuple(result) def bfs(puzzle): queue = deque([(puzzle, '')]) seen = set() while queue: numbers, route = queue.popleft() seen.add(numbers) if numbers == (1, 2, 3, 4, 5, 6, 7, 8, 0): return route for direction, new_numbers in next(numbers): if new_numbers not in seen: queue.append((new_numbers, route + direction)) return route puzzle = () for i in range(3): a,b,c = map(int, input().split()) puzzle += (a,b,c) print(len(bfs(puzzle)))
s672454775
p04029
u503111914
2,000
262,144
Wrong Answer
17
2,940
55
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
a = 0 for i in range(1,int(input())): a += i print(a)
s964817210
Accepted
18
2,940
59
a = 0 for i in range(1,int(input())+1): a += i print(a)
s030798386
p03378
u603234915
2,000
262,144
Wrong Answer
17
3,060
255
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.
l = list(map(int,input().split())) a = list(map(int,input().split())) b = [] c = [] for n in a: if n > l[2]: b.append(n) else: c.append(n) if l[2] - l[1] <= l[1]: print('{}'.format(len(c))) else: print('{}'.format(len(b)))
s952086211
Accepted
17
2,940
203
l = list(map(int,input().split())) a = list(map(int,input().split())) b = [] c = [] for n in a: if n > l[2]: b.append(n) else: c.append(n) print('{}'.format(min(len(b),len(c))))
s119332459
p03814
u167681750
2,000
262,144
Wrong Answer
18
3,500
62
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s = input() l = s.find("A") r = s.rfind("Z") print(l - r + 1)
s192765253
Accepted
18
3,500
61
s = input() l = s.find("A") r = s.rfind("Z") print(r - l + 1)
s201582413
p03068
u580004585
2,000
1,048,576
Wrong Answer
17
2,940
77
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
n = int(input()) s = input() k = int(input()) print(s.replace(s[k -1], '*'))
s831610092
Accepted
17
2,940
147
n = int(input()) s = input() k = int(input()) res = "" for i in s: if i == s[k - 1]: res += i else: res += "*" print(res)
s640236480
p04043
u920621778
2,000
262,144
Wrong Answer
17
2,940
68
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a, b , c = map(int, input().split()) print(a*b*c==175 and a+b+c==17)
s940843427
Accepted
17
2,940
100
a, b , c = map(int, input().split()) flag = a*b*c==175 and a+b+c==17 print('YES' if flag else 'NO')
s731682193
p03860
u099212858
2,000
262,144
Wrong Answer
27
9,112
41
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
a, b, c = input().split() print(a+b[0]+c)
s940544520
Accepted
29
8,900
67
a = list(map(str,input().split())) x = a[1] print("A"+ x[0] + "C")
s534369476
p03556
u103902792
2,000
262,144
Wrong Answer
27
2,940
79
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
n = int(input()) for i in range(n+1): if i**2 > n: print(i-1) exit(0)
s152849194
Accepted
27
2,940
134
n = int(input()) for i in range(n+1): if i**2 >= n: if i **2 == n: print(i**2) else: print((i-1)**2) exit(0)
s928158265
p02690
u368249389
2,000
1,048,576
Wrong Answer
1,011
9,512
869
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr # input X = int(input()) f_list = factorization(X) f_list = sorted(f_list, key=lambda x: x[1]) tmp_num = 0 for f in f_list: if f[1]==1: tmp_num = f[0] break tmp_num_2 = X // tmp_num # count ans = [0, 0] for a in range(tmp_num+1): b = -1 * (tmp_num - a) if (a**4 + a**3 * b + a**2 * b**2 + a*b**3 + b**4)==tmp_num_2: ans[0] = a ans[1] = b break # output print(" ".join(list(map(str, ans))))
s602090711
Accepted
544
9,092
309
# input X = int(input()) ans_list = [0, 0] # count for a in range(-500, 501): for b in range(-500, 501): if a**5-b**5==X: ans_list[0] = a ans_list[1] = b break # output print(" ".join(map(str, ans_list)))
s079799708
p03814
u503111914
2,000
262,144
Wrong Answer
18
3,500
45
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
S = input() print(S.rindex("Z")-S.index("A"))
s139599342
Accepted
18
3,500
51
S = input() print(S.rindex("Z") - S.index("A") + 1)
s351047728
p03352
u024340351
2,000
1,048,576
Wrong Answer
18
3,192
1,273
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
s = int(input()) snooker =[0]*1000 for p in range (1, 100): for q in range (1, 10): if p**q<=10000: snooker[10*(p-1)+q-1]=p**q snooker = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000, 1024, 1089, 1156, 1225, 1296, 1331, 1369, 1444, 1521, 1600, 1681, 1728, 1764, 1849, 1936, 2025, 2116, 2187, 2197, 2209, 2304, 2401, 2500, 2601, 2704, 2744, 2809, 2916, 3025, 3125, 3136, 3249, 3364, 3375, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 4913, 5041, 5184, 5329, 5476, 5625, 5776, 5832, 5929, 6084, 6241, 6400, 6561, 6724, 6859, 6889, 7056, 7225, 7396, 7569, 7744, 7776, 7921, 8000, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9261, 9409, 9604, 9801] slist = [0]*209 for i in range (0, 209): if snooker[i]<=s: slist[i]=snooker[i] print(max(slist))
s655022834
Accepted
18
3,064
938
s = int(input()) snooker =[0]*1000 for p in range (1, 100): for q in range (2, 10): if p**q<=10000: snooker[10*(p-1)+q-1]=p**q snooker = [1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000, 1024, 1089, 1156, 1225, 1296, 1331, 1369, 1444, 1521, 1600, 1681, 1728, 1764, 1849, 1936, 2025, 2116, 2187, 2197, 2209, 2304, 2401, 2500, 2601, 2704, 2744, 2809, 2916, 3025, 3125, 3136, 3249, 3364, 3375, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 4913, 5041, 5184, 5329, 5476, 5625, 5776, 5832, 5929, 6084, 6241, 6400, 6561, 6724, 6859, 6889, 7056, 7225, 7396, 7569, 7744, 7776, 7921, 8000, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9261, 9409, 9604, 9801, 10000] slist = [0]*123 for i in range (0, 123): if snooker[i]<=s: slist[i]=snooker[i] print(max(slist))
s063365744
p02694
u090729464
2,000
1,048,576
Wrong Answer
25
9,116
201
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import math X = int(input()) deposit = 100 cnt = 0 for i in range(1,100**18): deposit = math.floor(deposit * 1.01) cnt += 1 if deposit >= X: print(deposit) break print(cnt)
s559357583
Accepted
21
9,088
178
import math X = int(input()) deposit = 100 cnt = 0 for i in range(1,100**18): deposit = math.floor(deposit * 1.01) cnt += 1 if deposit >= X: break print(cnt)
s687414058
p03544
u159703196
2,000
262,144
Wrong Answer
17
3,060
121
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
i=int(input()) L=[0,1,1] for j in range(2,i): a=L[j-1]+L[j] L.append(a) print(a) A = 2*L[i-1]+L[i] print(A)
s447991233
Accepted
17
2,940
147
i=int(input()) L=[0,1,1] if i==1: A=1 else: for j in range(2,i): a=L[j-1]+L[j] L.append(a) A = 2*L[i-1]+L[i] print(A)
s749258474
p02678
u638902622
2,000
1,048,576
Wrong Answer
535
63,344
2,170
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
import sys def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x-1, MII())) ## dp ## def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)] def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x,'b') def to_oct(x: int) -> str: return format(x,'o') def to_hex(x: int) -> str: return format(x,'x') def divc(x,y) -> int: return -(-x//y) def divf(x,y) -> int: return x//y def gcd(x,y): while y: x,y = y,x%y return x def lcm(x,y): return x*y//gcd(x,y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0] def get_primes(n=10**3): """Return a list of prime numbers n or less""" is_prime = [True]*(n+1) is_prime[0] = is_prime[1] = False for i in range(2, int(n**0.5)+1): if not is_prime[i]: continue for j in range(i*2, n+1, i): is_prime[j] = False return [i for i in range(n+1) if is_prime[i]] def prime_factor(n): """Return a list of prime factorization numbers of n""" res = [] for i in range(2,int(n**0.5)+1): while n%i==0: res.append(i); n //= i if n != 1: res.append(n) return res ## const ## MOD=10**9+7 ## libs ## import itertools as it import functools as ft from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left #======================================================# def main(): n, m = MII() ab = [MIIZ() for _ in range(m)] g = [[] for _ in range(n)] for a,b in ab: g[a].append(b) g[b].append(a) dist = [-1]*n dq = deque() dist[0] = 0 dq.append(0) res = [0]*n while dq: v = dq.popleft() for nv in g[v]: if dist[nv] != -1: continue res[nv] = v dist[nv] = dist[v] + 1 dq.append(nv) res = [i+1 for i in res[1:]] print(*res,sep='\n') if __name__ == '__main__': main()
s710896969
Accepted
551
63,320
2,187
import sys def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x-1, MII())) ## dp ## def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)] def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x,'b') def to_oct(x: int) -> str: return format(x,'o') def to_hex(x: int) -> str: return format(x,'x') def divc(x,y) -> int: return -(-x//y) def divf(x,y) -> int: return x//y def gcd(x,y): while y: x,y = y,x%y return x def lcm(x,y): return x*y//gcd(x,y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0] def get_primes(n=10**3): """Return a list of prime numbers n or less""" is_prime = [True]*(n+1) is_prime[0] = is_prime[1] = False for i in range(2, int(n**0.5)+1): if not is_prime[i]: continue for j in range(i*2, n+1, i): is_prime[j] = False return [i for i in range(n+1) if is_prime[i]] def prime_factor(n): """Return a list of prime factorization numbers of n""" res = [] for i in range(2,int(n**0.5)+1): while n%i==0: res.append(i); n //= i if n != 1: res.append(n) return res ## const ## MOD=10**9+7 ## libs ## import itertools as it import functools as ft from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left #======================================================# def main(): n, m = MII() ab = [MIIZ() for _ in range(m)] g = [[] for _ in range(n)] for a,b in ab: g[a].append(b) g[b].append(a) dist = [-1]*n dq = deque() dist[0] = 0 dq.append(0) res = [0]*n while dq: v = dq.popleft() for nv in g[v]: if dist[nv] != -1: continue res[nv] = v dist[nv] = dist[v] + 1 dq.append(nv) res = [i+1 for i in res[1:]] print('Yes') print(*res,sep='\n') if __name__ == '__main__': main()
s942710116
p03455
u195177386
2,000
262,144
Wrong Answer
17
2,940
75
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()) print('Odd' if (a*b) % 2 == 0 else 'Even')
s953264348
Accepted
17
2,940
75
a, b = map(int, input().split()) print('Even' if (a*b) % 2 == 0 else 'Odd')
s469472789
p03360
u732159958
2,000
262,144
Wrong Answer
17
2,940
84
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
a, b, c = map(int, input().split()) k = int(input()) print(pow(2, k) * max(a, b, c))
s511089260
Accepted
17
2,940
99
a = list(map(int, input().split())) k = int(input()) a.sort() print(pow(2, k) * a[2] + a[1] + a[0])
s837113148
p03720
u612721349
2,000
262,144
Wrong Answer
21
3,316
197
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?
from collections import defaultdict n, k = map(int, input().split()) d = defaultdict(int) for _ in [0]*k: a, b = map(int, input().split()) d[a] += 1 d[b] += 1 for i in range(n): print(d[i])
s367894565
Accepted
20
3,316
199
from collections import defaultdict n, k = map(int, input().split()) d = defaultdict(int) for _ in [0]*k: a, b = map(int, input().split()) d[a] += 1 d[b] += 1 for i in range(n): print(d[i+1])
s425332008
p03472
u310678820
2,000
262,144
Wrong Answer
527
30,840
475
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
def solve(): N, H = map(int, input().split()) katana = [] for i in range(N): a, b = map(int, input().split()) katana.append((a, 0, i)) katana.append((b, 1, i)) katana = sorted(katana, reverse = True) ans = 0 for i in range(N*2): k = katana[i] #print(H, ans, k) if H<=0: return ans if k[1]==0: break H-=k[0] ans+=1 return ans+(H-1)//k[0] print(solve())
s350985734
Accepted
533
30,824
493
import math def solve(): N, H = map(int, input().split()) katana = [] for i in range(N): a, b = map(int, input().split()) katana.append((a, 0, i)) katana.append((b, 1, i)) katana = sorted(katana, reverse = True) ans = 0 for i in range(N*2): k = katana[i] #print(H, ans, k) if H<=0: return ans if k[1]==0: break H-=k[0] ans+=1 return ans+math.ceil(H/k[0]) print(solve())
s493022309
p02742
u289288647
2,000
1,048,576
Wrong Answer
27
9,088
117
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
H, W = map(int, input().split()) if W == 1: print(1) elif W%2 == 1: print(H*W//2+1) else: print(H*W//2)
s130142835
Accepted
29
9,000
134
H, W = map(int, input().split()) if W == 1 or H == 1: print(1) elif H%2 == W%2 == 1: print(H*W//2+1) else: print(H*W//2)
s444380858
p02608
u585963734
2,000
1,048,576
Wrong Answer
84
9,660
425
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
import sys readline = sys.stdin.buffer.readline N=int(readline()) n=int(pow(N//3,0.5)) cnt=[0]*(N+1) for i in range(1,n): for j in range(i,n): for k in range(j,n): if pow(i,2)+pow(j,2)+pow(k,2)+i*j+j*k+k*i<=N: if i==j and j==k and k==i: cnt[pow(i,2)+pow(j,2)+pow(k,2)+i*j+j*k+k*i]+=1 else: cnt[pow(i,2)+pow(j,2)+pow(k,2)+i*j+j*k+k*i]+=3 for i in range(1,N): print(cnt[i])
s943587324
Accepted
753
78,744
313
import sys import itertools as itr readline = sys.stdin.buffer.readline N=int(readline()) n=int(pow(N,0.5)) chk=list(itr.product(range(1,n),repeat=3)) cnt=[0]*(N+1) for c in chk: i=c[0] j=c[1] k=c[2] if i*i+j*j+k*k+i*j+j*k+k*i<=N: cnt[i*i+j*j+k*k+i*j+j*k+k*i]+=1 for i in range(1,N+1): print(cnt[i])
s424241947
p02390
u216229195
1,000
131,072
Wrong Answer
20
7,564
75
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.
x = int(input()) h = x//(60*60) m = x%(60*60) s = x%60 print(h,m,s,sep=":")
s983231581
Accepted
60
7,620
76
x = int(input()) h = x//(60*60) m = (x//60)%60 s = x%60 print(h,m,s,sep=":")
s771339541
p02975
u239528020
2,000
1,048,576
Wrong Answer
50
14,120
181
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
### A N = int(input()) a_all = list(map(int, input().split())) print(a_all) if N!=3: print("No") elif (a_all[0]^a_all[1]==a_all[2]): print("Yes") else: print("No")
s491627057
Accepted
61
14,212
766
### A N = int(input()) a_all = list(map(int, input().split())) t = list(set(a_all)) if len(t)==3: if (t[0]^t[1]==t[2]): a=0 b=0 c=0 for i in a_all: if i==t[0]: a+=1 elif i==t[1]: b+=1 else: c+=1 if a==b and b==c: print("Yes") else: print("No") else: print("No") elif len(t)==2: a=0 b=0 for i in a_all: if i==t[0]: a+=1 else: b+=1 if(a == b*2 or b == a*2): print("Yes") else: print("No") elif len(t)==1: if t[0]^t[0]==t[0]: print("Yes") else: print("No") else: print("No")
s386093851
p03860
u884795391
2,000
262,144
Wrong Answer
17
2,940
32
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
a = input() print('A'+a[8]+'B')
s839527470
Accepted
17
2,940
32
a = input() print('A'+a[8]+'C')
s264469258
p03854
u768896740
2,000
262,144
Wrong Answer
18
3,188
428
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() s_2 = s[::-1] t = [] count = 0 # word_list = ['dream', 'dreamer', 'erase', 'eraser'] word_list = ['maerd', 'remaerd', 'esare', 'resare'] for i in range(10000): if count == len(s): break if s_2[count:count+5] in word_list: count += 5 continue elif s_2[count:count+6] in word_list: count += 6 continue else: print('No') exit() print('Yes')
s940159072
Accepted
51
4,652
398
s = input() s = list(s) s = s[::-1] word_list = ['maerd', 'remaerd', 'esare', 'resare'] i = 0 while i != len(s): a = s[i:i+5] a = ''.join(a) b = s[i:i+6] b = ''.join(b) c = s[i:i+7] c = ''.join(c) if a in word_list: i += 5 elif b in word_list: i += 6 elif c in word_list: i += 7 else: print('NO') exit() print('YES')
s807930717
p03054
u892251744
2,000
1,048,576
Wrong Answer
424
37,024
986
We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a string of length N. Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: `L`, `R`, `U` and `D`. The game consists of N steps. The i-th step proceeds as follows: * First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece. * Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece. Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done. Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.
H,W,N = map(int, input().split()) Sr, Sc = map(int, input().split()) S = input() T = input() atk_U = [0]*N atk_D = [0]*N atk_L = [0]*N atk_R = [0]*N u = 0 d = 0 l = 0 r = 0 for i in range(N): if S[i] == 'U': u += 1 if S[i] == 'D': d += 1 if S[i] == 'L': l += 1 if S[i] == 'R': r += 1 atk_U[i] = u atk_D[i] = d atk_L[i] = l atk_R[i] = r def_U = [0]*N def_D = [0]*N def_L = [0]*N def_R = [0]*N u = 0 d = 0 l = 0 r = 0 for i in range(N-1): if T[i] == 'U': u += 1 if T[i] == 'D': d += 1 if T[i] == 'L': l += 1 if T[i] == 'R': r += 1 def_U[i+1] = d def_D[i+1] = u def_L[i+1] = r def_R[i+1] = l dam_U = max([atk_U[i] - def_U[i] for i in range(N)]) dam_D = max([atk_D[i] - def_D[i] for i in range(N)]) dam_L = max([atk_L[i] - def_L[i] for i in range(N)]) dam_R = max([atk_R[i] - def_R[i] for i in range(N)]) if dam_U < Sr + 1 and dam_D < H - Sr + 1 and dam_L < Sc + 1 and dam_R < W - Sc + 1: print('NO') else: print('YES')
s348896981
Accepted
523
36,188
1,122
H,W,N = map(int, input().split()) Sr, Sc = map(int, input().split()) S = input() T = input() atk_U = [0]*N atk_D = [0]*N atk_L = [0]*N atk_R = [0]*N u = 0 d = 0 l = 0 r = 0 for i in range(N): if S[i] == 'U': u += 1 if S[i] == 'D': d += 1 if S[i] == 'L': l += 1 if S[i] == 'R': r += 1 atk_U[i] = u atk_D[i] = d atk_L[i] = l atk_R[i] = r def_U = [0]*N def_D = [0]*N def_L = [0]*N def_R = [0]*N u = 0 d = 0 l = 0 r = 0 for i in range(N-1): if T[i] == 'U': if u + 1 - atk_D[i] < Sr: u += 1 if T[i] == 'D': if d + 1 - atk_U[i] < H - Sr + 1: d += 1 if T[i] == 'L': if l + 1 - atk_R[i] < Sc: l += 1 if T[i] == 'R': if r + 1 - atk_L[i] < W - Sc + 1: r += 1 def_U[i+1] = d def_D[i+1] = u def_L[i+1] = r def_R[i+1] = l dam_U = max([atk_U[i] - def_U[i] for i in range(N)]) dam_D = max([atk_D[i] - def_D[i] for i in range(N)]) dam_L = max([atk_L[i] - def_L[i] for i in range(N)]) dam_R = max([atk_R[i] - def_R[i] for i in range(N)]) if dam_U < Sr and dam_D < H - Sr + 1 and dam_L < Sc and dam_R < W - Sc + 1: print('YES') else: print('NO')
s734290316
p03730
u430478288
2,000
262,144
Wrong Answer
17
2,940
133
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A, B, C = map(int, input().split()) for i in range(1000): if (A * i) % B == C: print('YES') break print('NO')
s454909085
Accepted
154
2,940
169
A, B, C = map(int, input().split()) def check(): for i in range(1000000): if (A * i) % B == C: return 'YES' return 'NO' print(check())
s946968637
p03636
u865413330
2,000
262,144
Wrong Answer
18
2,940
51
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
s = input() print(s[0] + str(len(s[0:-1])) + s[-1])
s562569054
Accepted
17
2,940
51
s = input() print(s[0] + str(len(s[1:-1])) + s[-1])
s982673235
p03470
u743154453
2,000
262,144
Wrong Answer
18
2,940
108
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 = [] for i in range(N): d.append(int(input())) print(d[i]) print(len(set(d)))
s802379708
Accepted
17
3,064
92
N = int(input()) d = [] for i in range(N): d.append(int(input())) print(len(set(d)))
s613981376
p02397
u108130680
1,000
131,072
Wrong Answer
30
5,616
128
Write a program which reads two integers x and y, and prints them in ascending order.
while True: a,b = map(int, input().split()) if a == 0 and b == 0: break if a > b: print(b, a) else: print(a, b)
s878771677
Accepted
60
5,612
141
while True: x,y = map(int, input().split()) if x == 0 and y == 0:break if x > y: print(y, x) else: print(x, y)
s638020275
p02610
u858742833
2,000
1,048,576
Wrong Answer
786
59,516
437
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up in a row. The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise. Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel. Solve this problem for each of the T test cases given.
import heapq def main(): T = int(input()) for _ in range(T): N = int(input()) KLR = [tuple(map(int, input().split())) for _ in range(N)] KLR.sort() H = [] s = 0 for k, l, r in KLR: s += r heapq.heappush(H, (l - r, k)) while len(H) > k or (H and H[0][1]<= len(H)): heapq.heappop(H) print(s + sum(l for l, k in H)) main()
s518721244
Accepted
931
65,744
734
import heapq def main(): T = int(input()) for _ in range(T): N = int(input()) KLR = [tuple(map(int, input().split())) for _ in range(N)] KLR.sort() H = [] T = [] s = 0 for k, l, r in KLR: s += r if l - r >= 0: heapq.heappush(H, (l - r, k)) while len(H) > k: T.append(heapq.heappop(H)) else: T.append((l - r, k)) s += sum(l for l, k in H) H = [] T.sort(key = lambda x: -x[1]) for l, k in T: heapq.heappush(H, (-l, N - k)) while len(H) > N - k: s -= heapq.heappop(H)[0] print(s) main()
s820079935
p03813
u599547273
2,000
262,144
Wrong Answer
17
2,940
36
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.
print("A{'BR'[int(input())<1200]}C")
s740651905
Accepted
17
2,940
35
print("AARBCC "[input()<"1200"::2])
s538501469
p03609
u863442865
2,000
262,144
Wrong Answer
17
2,940
19
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
print(input()[::2])
s911587231
Accepted
17
2,940
74
x,t = map(int, input().split()) if x>=t: print(x-t) else: print(0)
s652185605
p03998
u040298438
2,000
262,144
Wrong Answer
28
8,932
171
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
a, b, c = (input() for _ in range(3)) d = {"a": a, "b": b, "c": c} nex = "a" while len(d[nex]) != 0: tmp = d[nex][0] d[nex] = d[nex][1:] nex = tmp print(nex)
s165818443
Accepted
30
9,020
180
a, b, c = (input() for _ in range(3)) d = {"a": a, "b": b, "c": c} nex = "a" while len(d[nex]) != 0: tmp = d[nex][0] d[nex] = d[nex][1:] nex = tmp print(nex.upper())
s244390215
p03543
u094191970
2,000
262,144
Wrong Answer
17
2,940
48
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
n=input() print('Yes' if n[:3]==n[1:] else 'No')
s647940888
Accepted
17
2,940
72
n=input() print('Yes' if n[0]==n[1]==n[2] or n[1]==n[2]==n[3] else 'No')
s566796148
p03449
u363407238
2,000
262,144
Wrong Answer
18
3,060
205
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
n = int(input()) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) a1.append(0) suml = [] for i in range(n): suml.append([sum(a1[:-i - 1]) + sum(a2[-i - 1:])]) print(max(suml))
s927634601
Accepted
19
3,060
208
n = int(input()) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) a1.append(0) suml = [] for i in range(n): suml.append([sum(a1[:-i - 1]) + sum(a2[-i - 1:])]) print(max(suml)[0])
s436958800
p03575
u623687794
2,000
262,144
Wrong Answer
22
3,064
1,045
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
n,m=map(int,input().split()) graph=[[False]*n for i in range(n)] node=[None for i in range(m)] visited=[False]*n for i in range(m): a,b=map(int,input().split()) graph[a-1][b-1],graph[b-1][a-1]=True,True node[i]=[a-1,b-1] def dfs(v): visited[v]=True for i in range(n): if graph[v][i]==False:continue if visited[i]==True:continue dfs(i) ans=0 for i in range(m): graph[node[i][0]][node[i][1]],graph[node[i][1]][node[i][0]]=False,False for j in range(n):visited[j]=False dfs(0) for h in range(n): if visited[h]==False: ans+=1 break print(ans)
s272765290
Accepted
27
3,064
1,160
n,m=map(int,input().split()) graph=[[False]*n for i in range(n)] node=[None for i in range(m)] visited=[False]*n for i in range(m): a,b=map(int,input().split()) graph[a-1][b-1],graph[b-1][a-1]=True,True node[i]=[a-1,b-1] def dfs(v): visited[v]=True for i in range(n): if graph[v][i]==False:continue if visited[i]==True:continue dfs(i) ans=0 for i in range(m): graph[node[i][0]][node[i][1]],graph[node[i][1]][node[i][0]]=False,False for j in range(n):visited[j]=False dfs(0) for h in range(n): if visited[h]==False: ans+=1 break graph[node[i][0]][node[i][1]],graph[node[i][1]][node[i][0]]=True,True print(ans)
s503063524
p02399
u435300817
1,000
131,072
Wrong Answer
40
7,692
97
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
values = input() a, b = [int(x) for x in values.split()] print(a // b) print(a % b) print(a / b)
s121193827
Accepted
20
7,684
111
values = input() a, b = [int(x) for x in values.split()] print('{0} {1} {2:.5f}'.format(a // b, a % b, a / b))
s429258416
p03550
u214617707
2,000
262,144
Wrong Answer
17
3,316
215
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
N, Z, W = map(int, input().split()) a = list(map(int, input().split())) a = a[::-1] print(a) if N == 1: print(a[0]-W) elif abs(a[0]-a[1]) > abs(a[0] - W): print(abs(a[0]-a[1])) else: print(abs(a[0] - W))
s491704452
Accepted
17
3,188
211
N, Z, W = map(int, input().split()) a = list(map(int, input().split())) a = a[::-1] if N == 1: print(abs(a[0]-W)) elif abs(a[0]-a[1]) > abs(a[0] - W): print(abs(a[0]-a[1])) else: print(abs(a[0] - W))
s312969354
p02422
u682153677
1,000
131,072
Wrong Answer
20
5,612
617
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
# -*- coding: utf-8 -*- s = list(input()) q = int(input()) for i in range(q): n = list(input().split()) if 'print' in n: for i in range(int(n[1]), int(n[2])): print(str(s[i]), end='') print() elif 'reverse' in n: for i in range(int(int(n[2]) / 2)): s[int(n[1]) + i], s[int(n[2]) - i] = s[int(n[2]) - i], s[int(n[1]) + i] elif 'replace' in n: for i in range(int(n[1]), int(n[2]) + 1): s.pop(int(n[1])) count = int(n[1]) for j in list(n[3]): s.insert(count, j) count += 1
s081076036
Accepted
40
5,816
644
# -*- coding: utf-8 -*- import math s = list(input()) q = int(input()) for i in range(q): n = list(input().split()) if 'print' in n: for j in range(int(n[1]), int(n[2]) + 1): print(str(s[j]), end='') print() elif 'reverse' in n: for k in range(math.floor((int(n[2]) - int(n[1]) + 1) / 2)): s[int(n[1]) + k], s[int(n[2]) - k] = s[int(n[2]) - k], s[int(n[1]) + k] elif 'replace' in n: for l in range(int(n[1]), int(n[2]) + 1): s.pop(int(n[1])) count = int(n[1]) for m in list(n[3]): s.insert(count, m) count += 1
s315412007
p03044
u665038048
2,000
1,048,576
Wrong Answer
782
49,556
456
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
from collections import deque n = int(input()) es = [[] for _ in range(n)] for _ in range(n-1): u, v, w = map(int, input().split()) u -= 1 v -= 1 es[u].append((v, w)) es[v].append((u, w)) print(es) clr = [None]*n clr[0] = 0 dq = deque() dq.append(0) while dq: v = dq.popleft() for nv, w in es[v]: if clr[nv] is not None: continue clr[nv] = (clr[v] + w)%2 dq.append(nv) print(*clr, sep='\n')
s038879764
Accepted
681
94,624
414
import sys sys.setrecursionlimit(10**5) n = int(input()) t = {i:{} for i in range(n)} ans = [-1]*n for _ in range(n-1): u ,v, w = map(int, input().split()) t[u-1][v-1] = w t[v-1][u-1] = w def dfs(x): for y in t[x]: del t[y][x] ans[y] = ans[x] if t[x][y] % 2 == 0 else 1 - ans[x] if len(t[y]) > 0: dfs(y) ans[0] = 0 dfs(0) for i in range(n): print(ans[i])
s134857948
p04045
u686036872
2,000
262,144
Time Limit Exceeded
2,104
2,940
244
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
N, K = map(int, input().split()) D = list(map(int, input().split())) L=[] for i in range(0, 10): if i not in D: L.append("i") i = N while True: if set(list(str((i)))) <= set(L): print(i) break i += 1
s757687568
Accepted
107
3,060
256
N, K = map(int, input().split()) D = list(map(int, input().split())) L=[] for i in range(0, 10): if i not in D: L.append(str(i)) L.sort() i = N while True: if set(list(str((i)))) <= set(L): print(i) break i += 1