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
s523657649
p03352
u943015560
2,000
1,048,576
Wrong Answer
18
3,060
327
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.
def Exponential(): X = int(input()) if X<1 or X>1000: return ("Oops! X is out of the range!") if X ==1: return(X) res=[] for b in range(X, 0, -1): for p in range(2, X+1, 1): if b**p <=X: res.append(b**p) else: break return(max(res)) Exponential()
s138910416
Accepted
18
3,060
306
def Exponential(): X = int(input()) if X<1 or X>1000: return ("Oops! X is out of the range!") res=[1] for b in range(1, X+1): for p in range(2, X+1, 1): if b**p <=X: res.append(b**p) else: break print(max(res)) Exponential()
s716269564
p03543
u209918867
2,000
262,144
Wrong Answer
17
2,940
66
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**?
s=int(input()) print(any([str(i)*3 in str(s) for i in range(10)]))
s683875823
Accepted
17
2,940
88
s=int(input()) print("Yes" if any([str(i)*3 in str(s) for i in range(10)]) else "No" )
s535847188
p03501
u232852711
2,000
262,144
Wrong Answer
17
2,940
55
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
n, a, b = list(map(int, input().split())) min(n*a, b)
s409528904
Accepted
17
2,940
62
n, a, b = list(map(int, input().split())) print(min(n*a, b))
s835847206
p03699
u773686010
2,000
262,144
Wrong Answer
29
9,204
255
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
N = int(input()) dp = [[0]*2 for i in range(N + 1)] for i in range(1,N + 1): P = int(input()) dp[i][False] = max(dp[i-1]) dp[i][True] = max(dp[i-1][False] + P,dp[i-1][True] + P) print(max(list(map(lambda x:x if x % 10 != 0 else 0,dp[-1]))))
s144385532
Accepted
66
10,208
201
N = int(input()) dp = [0] for i in range(N): P = int(input()) dp_p = list(map(lambda x:x + P,dp)) dp = list(set(dp + dp_p)) P_List = [0] + [i for i in dp if i % 10 != 0] print(max(P_List))
s889886246
p03110
u151005508
2,000
1,048,576
Wrong Answer
17
3,060
230
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()) xv=[] for _ in range(N): xv.append(tuple(input().split())) profit=0 for val in xv: if val[1]=='JPY': profit+=int(val[0]) else: profit+=float(val[0])*380000.0 print(N, xv) print(profit)
s904750251
Accepted
18
3,060
231
N = int(input()) xv=[] for _ in range(N): xv.append(tuple(input().split())) profit=0 for val in xv: if val[1]=='JPY': profit+=int(val[0]) else: profit+=float(val[0])*380000.0 #print(N, xv) print(profit)
s241901848
p03379
u883048396
2,000
262,144
Wrong Answer
247
29,616
274
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
iN = int(input()) aX = [int(_) for _ in input().split()] aXs = sorted(aX) iMu = iN//2 iMd = iN//2 -1 iMuV = aX[iMu] iMdV = aX[iMd] if iMuV == iMdV: print("\n".join([str(iMuV)]*iN)) else: print("\n".join(map(str,map(lambda x: iMuV if x < iMuV else iMdV ,aX))))
s244971577
Accepted
241
29,808
275
iN = int(input()) aX = [int(_) for _ in input().split()] aXs = sorted(aX) iMu = iN//2 iMd = iN//2 -1 iMuV = aXs[iMu] iMdV = aXs[iMd] if iMuV == iMdV: print("\n".join([str(iMuV)]*iN)) else: print("\n".join(map(str,map(lambda x: iMuV if x < iMuV else iMdV ,aX))))
s748738608
p03139
u008582165
2,000
1,048,576
Wrong Answer
17
2,940
86
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
N,A,B = map(int,input().split()) a = min(A,B) b = A + B - N print("{} {}".format(a,b))
s962861354
Accepted
17
3,060
207
N,A,B = map(int,input().split()) if A == 0 or B == 0: print("0 0") elif N >= A + B: a = min(A,B) print("{} {}".format(a,0)) else: a = min(A,B) b = A + B - N print("{} {}".format(a,b))
s451548827
p03740
u600402037
2,000
262,144
Wrong Answer
17
2,940
201
Alice and Brown loves games. Today, they will play the following game. In this game, there are two piles initially consisting of X and Y stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice: * Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile. The player who becomes unable to perform the operation, loses the game. Given X and Y, determine the winner of the game, assuming that both players play optimally.
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) X, Y = lr() if abs(Y - X) >= 2: print('Alice') else: print('Bob') # 24
s403235842
Accepted
18
2,940
203
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) X, Y = lr() if abs(Y - X) >= 2: print('Alice') else: print('Brown') # 24
s568295428
p03130
u572012241
2,000
1,048,576
Wrong Answer
18
3,064
592
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
import heapq from sys import stdin input = stdin.readline # n = int(input()) # a = list(map(int,input().split())) # ab=[] # a,b = map(int, input().split()) # ab.append([a,b]) def main(): count =[0]*4 for i in range(3): a,b = map(int, input().split()) count[a-1]+=1 count[b-1]+=1 flag = True for i in count: if i ==3: flag=False if flag: print("Yes") else: print("No") if __name__ == '__main__': main()
s672767802
Accepted
18
3,060
592
import heapq from sys import stdin input = stdin.readline # n = int(input()) # a = list(map(int,input().split())) # ab=[] # a,b = map(int, input().split()) # ab.append([a,b]) def main(): count =[0]*4 for i in range(3): a,b = map(int, input().split()) count[a-1]+=1 count[b-1]+=1 flag = True for i in count: if i ==3: flag=False if flag: print("YES") else: print("NO") if __name__ == '__main__': main()
s558913931
p03693
u708211626
2,000
262,144
Wrong Answer
25
9,020
84
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?
a=input().split() b=''.join(a) if int(b)%4==0: print('Yes') else: print('No')
s748311911
Accepted
24
9,080
84
a=input().split() b=''.join(a) if int(b)%4==0: print('YES') else: print('NO')
s817124800
p03416
u790301364
2,000
262,144
Wrong Answer
77
3,064
464
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
def main6(): str = input(''); buf = str.split(); num = []; result = 0; for i in range(2): num.insert(i,int(buf[i])); for i in range(num[1] - num[0] + 1): k = num[0] + i; k1 = int(k/10000); k2 = int(k/1000)%10; k4 = int(k/10)%10; k5 = k%10; if k1 == k5 & k2 == k4: result = result + 1; print(result); if __name__ == '__main__': #main4() #main5() main6()
s739181324
Accepted
71
3,064
469
def main6(): str = input(''); buf = str.split(); num = []; result = 0; for i in range(2): num.insert(i,int(buf[i])); for i in range(num[1] - num[0] + 1): k = num[0] + i; k1 = int(k/10000)%10; k2 = int(k/1000)%10; k4 = int(k/10)%10; k5 = k%10; if k1 == k5 and k2 == k4: result = result + 1; print(result); if __name__ == '__main__': #main4() #main5() main6()
s009628349
p02972
u668785999
2,000
1,048,576
Wrong Answer
985
15,332
488
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
N = int(input()) a = list(map(int,input().split())) ans = [0 for i in range(N+1)] flag = True for i in range(N,0,-1): for j in range(1,N+1): if i*j>N: break else: if ans[i*j] %2 == a[i*j -1 ]%2: pass else: if j == 1: ans[i*j] +=1 else: flag = False break if flag: print(sum(ans)) print(*a[1:]) else: print(-1)
s411833640
Accepted
678
17,652
403
N = int(input()) a = list(map(int,input().split())) ans = [0 for i in range(N+1)] for i in range(N,0,-1): res = 0 for j in range(1,N+1): if i*j>N: break else: res += ans[i*j] if res%2 != a[i-1]: ans[i] += 1 print(sum(ans)) A = [] for i,v in enumerate(ans): if v>0: A.append(i) print(*A)
s474929009
p02831
u201928947
2,000
1,048,576
Wrong Answer
17
3,060
175
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
a,b = map(int,input().split()) def gcd(x,y): if x % y == 0: return y elif y % x == 0: return x else: return gcd(y,abs(y-x)) print(gcd(a,b))
s992875543
Accepted
17
3,060
182
a,b = map(int,input().split()) def gcd(x,y): if x % y == 0: return y elif y % x == 0: return x else: return gcd(y,abs(y-x)) print(a*b//(gcd(a,b)))
s150367933
p03067
u386249594
2,000
1,048,576
Wrong Answer
17
2,940
131
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
A,B,C = map(int,input().split()) if A < B and B < C: print('Yes') elif C < B and B < A: print('Yes') else: print('No')
s168028421
Accepted
17
2,940
131
A,B,C = map(int,input().split()) if A < C and C < B: print('Yes') elif B < C and C < A: print('Yes') else: print('No')
s346172495
p03477
u130900604
2,000
262,144
Wrong Answer
17
2,940
126
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d=map(int,input().split()) l=a+b r=c+d if l==r: print("Balanced") elif r<l: print("Right") else: print("Left")
s344282259
Accepted
17
2,940
127
a,b,c,d=map(int,input().split()) l=a+b r=c+d if l==r: print("Balanced") elif r>l: print("Right") else: print("Left")
s864271468
p02612
u601393594
2,000
1,048,576
Wrong Answer
29
9,040
53
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) p = n - (n // 1000) * 1000 print(p)
s873601937
Accepted
27
9,092
81
n = int(input()) if n % 1000 == 0: p=0 else: p=((n//1000)+1)*1000-n print(p)
s160605272
p03997
u337820403
2,000
262,144
Wrong Answer
17
2,940
76
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print(((a + b) * h) / 2)
s866406193
Accepted
17
2,940
81
a = int(input()) b = int(input()) h = int(input()) print(int(((a + b) * h) / 2))
s991551176
p02831
u037190233
2,000
1,048,576
Wrong Answer
17
2,940
134
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
x,y = input().split() x = int(x) y = int(y) if x < y: a = y b = x else: a = x b = y while b: a, b = b, a % b print(x*y/a)
s487198152
Accepted
17
2,940
140
x,y = input().split() x = int(x) y = int(y) if x < y: a = y b = x else: a = x b = y while b: a, b = b, a % b print(x * y // a)
s716266007
p03730
u341926204
2,000
262,144
Wrong Answer
17
2,940
168
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`.
def b(): a, b, c = map(int, input().split()) for i in range(c+1): if a*i % b == c: print('YES') break else: print('NO') b()
s656944476
Accepted
17
2,940
169
def b(): a, b, c = map(int, input().split()) for i in range(2, b): if a*i % b == c: print('YES') break else: print('NO') b()
s163429361
p03434
u845937249
2,000
262,144
Wrong Answer
17
3,060
403
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = input() n = int(n) nums = input().split() nums = list(map(int,nums)) print(nums) nums.sort(reverse=True) print(nums) i = 0 Alis = 0 Bob = 0 for i in range(0,n): if i % 2 == 0: Alis = Alis + nums[i] else: Bob = Bob + nums[i] print(Alis-Bob) #print(Alis) #print(Bob)
s334697332
Accepted
18
3,060
405
n = input() n = int(n) nums = input().split() nums = list(map(int,nums)) #print(nums) nums.sort(reverse=True) #print(nums) i = 0 Alis = 0 Bob = 0 for i in range(0,n): if i % 2 == 0: Alis = Alis + nums[i] else: Bob = Bob + nums[i] print(Alis-Bob) #print(Alis) #print(Bob)
s498780202
p03494
u396495667
2,000
262,144
Time Limit Exceeded
2,104
2,940
140
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input()) a = [int() for _ in input().split()] cnt =0 while all(i%2==0 for i in a): a = [int(i//2) for i in a] cnt +=1 print(cnt)
s550597140
Accepted
19
2,940
152
n = int(input()) A = list(map(int,input().split())) c = 0 while all(a%2 == 0 for a in A) : for i in range(len(A)): A[i] = A[i]/2 c += 1 print(c)
s066094299
p02390
u335508235
1,000
131,072
Wrong Answer
30
7,708
79
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
s=int(input()) hour=s/3600 min=s/600%60 sec=s%60 print(hour, min,sec,sep=":")
s839441212
Accepted
70
7,704
91
a = int(input()) h=int(a/3600) m=int((a%3600)/60) s=int((a%3600)%60) print (h,m,s,sep=":")
s452043721
p02603
u997641430
2,000
1,048,576
Wrong Answer
27
9,064
375
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
n = int(input()) *A, = map(int, input().split()) n = 10 A = [200] * n A = [200] + A + [0] money = 1000 stock = 0 for i in range(1, n + 1): if (A[i - 1] > A[i]) and (A[i] <= A[i + 1]): cnt = money // A[i] money -= cnt * A[i] stock += cnt if (A[i - 1] <= A[i]) and (A[i] > A[i + 1]): money += stock * A[i] stock = 0 print(money)
s909477544
Accepted
27
9,136
145
n = int(input()) *A, = map(int, input().split()) ans = 1000 for i in range(n - 1): ans += (ans // A[i]) * max(A[i + 1] - A[i], 0) print(ans)
s661663505
p03456
u127535085
2,000
262,144
Wrong Answer
17
2,940
140
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
from math import sqrt a,b = input().split() ans = sqrt(int(a+b)) print(ans) if ans / int(ans) == 1: print("Yes") else: print("No")
s513324165
Accepted
17
2,940
129
from math import sqrt a,b = input().split() ans = sqrt(int(a+b)) if ans / int(ans) == 1: print("Yes") else: print("No")
s657983422
p03473
u037485167
2,000
262,144
Time Limit Exceeded
2,104
5,612
620
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
candidates = [2] + list(range(3,100001,2)) i = 1 got_one = True while got_one: p = candidates[i] new_candidates = candidates[:i+1] for j in candidates[i+1:]: if j%p != 0: new_candidates.append(j) if len(new_candidates) == len(candidates): got_one = False candidates = new_candidates i = i + 1 similar = [] for p in candidates: if (p+1)/2 in candidates: similar.append(p) answers = [] n = int(input()) for q in range(n): [l, r] = [int(i) for i in input().split()] answers.append(sum([l <= p <= r for p in similar])) for a in answers: print(a)
s804803225
Accepted
17
2,940
33
s = int(input()) print(24-s + 24)
s976714094
p03433
u088974156
2,000
262,144
Wrong Answer
17
2,940
106
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=int(input()) a=int(input()) if(a==0): print("YES") elif((a%500)>n): print("NO") else: print("YES")
s816988670
Accepted
17
2,940
80
n=int(input()) a=int(input()) if((n%500)<=a): print("Yes") else: print("No")
s534282350
p02406
u217069758
1,000
131,072
Wrong Answer
20
5,592
145
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
n = int(input()) result = [] for i in range(1, n+1): if (i % 3 == 0) or (i // 10 == 3): result.append(str(i)) print(' '.join(result))
s030035490
Accepted
20
5,636
156
n = int(input()) result = '' for i in range(3, n+1): if (i % 3 == 0) or (i % 10 == 3) or ('3' in str(i)): result += (' ' + str(i)) print(result)
s060247417
p03386
u098982053
2,000
262,144
Wrong Answer
2,226
2,076,568
138
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A,B,K = map(int,input().split(" ")) List = [i for i in range(A,B+1)] la = List[:K] lb = List[-K:] L = la+lb for l in set(L): print(l)
s631621710
Accepted
18
3,060
195
A,B,K = map(int,input().split(" ")) if 2*K >= B-A+1: for i in range(A,B+1): print(i) else: for i in range(A,A+K): print(i) for i in range(B-K+1,B+1): print(i)
s531065190
p03161
u365375535
2,000
1,048,576
Wrong Answer
2,104
14,888
412
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
def run(): N, K = map(int, input().split()) h_li = [int(h) for h in input().split()] cost_li = [0] * (N) cost_li[1] = abs(h_li[0] - h_li[1]) for n in range(2, N): if n < K: k = n else: k = K cost = float('inf') h = h_li[n] for _k in range(1, k+1): cost = min(cost, cost_li[n-_k] + abs(h_li[n-_k]-h)) cost_li[n] = cost print(cost_li) if __name__ == '__main__': run()
s579416342
Accepted
1,866
13,980
359
def run(): N, K = map(int, input().split()) h_li = [int(h) for h in input().split()] cost_li = [0] * N cost_li[1] = abs(h_li[0] - h_li[1]) for n in range(2, N): k = max(0, n - K) h = h_li[n] cost = min([cost_li[i] + abs(h_li[i] - h) for i in range(k, n)]) cost_li[n] = cost print(cost_li[N-1]) if __name__ == '__main__': run()
s128618651
p03069
u248670337
2,000
1,048,576
Wrong Answer
27
9,036
26
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
print(input().count('#.'))
s905591866
Accepted
110
9,252
87
_,s=open(b:=0);w=a=s.count('.') for c in s:b+=(x:=c<'.');w-=(x<1);a=min(a,b+w) print(a)
s427591508
p03139
u703890795
2,000
1,048,576
Wrong Answer
17
2,940
65
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
N, A, B = map(int, input().split()) print(max(A,B), max(A+B-N,0))
s797409990
Accepted
17
2,940
65
N, A, B = map(int, input().split()) print(min(A,B), max(A+B-N,0))
s905662789
p02601
u540698208
2,000
1,048,576
Wrong Answer
31
9,052
296
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
def main(): A, B, C = (int(x) for x in input().split()) K = int(input()) while not A < B < C and K > 0: if A >= B: B *= 2 else: C *= 2 K -= 1 print(A, B, C, K) if A < B < C: print('Yes') else: print('No') if __name__ == '__main__': main()
s168757330
Accepted
31
9,052
298
def main(): A, B, C = (int(x) for x in input().split()) K = int(input()) while not A < B < C and K > 0: if A >= B: B *= 2 else: C *= 2 K -= 1 if A < B < C: print('Yes') else: print('No') if __name__ == '__main__': main()
s817617243
p03486
u440161695
2,000
262,144
Wrong Answer
17
3,064
78
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=sorted(input()) t=sorted(input()) if s<t: print("Yes") else: print("No")
s735995730
Accepted
17
2,940
63
print("Yes" if sorted(input())<sorted(input())[::-1] else "No")
s505766460
p03964
u239981649
2,000
262,144
Wrong Answer
22
3,188
248
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time. Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
import math n = int(input()) a = [list(map(int, input().split())) for _ in range(n)] for k in range(n): if k: m = min(math.ceil(a[k-1][0]/a[k][0]), math.ceil(a[k-1][1]/a[k][1])) a[k] = [m*a[k][0], m*a[k][1]] print(sum(a[n-1]))
s842300532
Accepted
84
5,332
340
from math import ceil from decimal import Decimal as Deci n = int(input()) a = [list(map(int, input().split())) for _ in range(n)] for k in range(n): if k: m0 = ceil(Deci(a[k-1][0])/Deci(a[k][0])) m1 = ceil(Deci(a[k-1][1])/Deci(a[k][1])) m = max(m0, m1) a[k] = [m*a[k][0], m*a[k][1]] print(sum(a[n-1]))
s114374542
p03407
u140480594
2,000
262,144
Wrong Answer
17
2,940
89
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 = list(map(int, input().split())) if A + B <= C : print("Yes") else : print("No")
s394132121
Accepted
17
2,940
89
A, B, C = list(map(int, input().split())) if A + B >= C : print("Yes") else : print("No")
s924622018
p03711
u136090046
2,000
262,144
Wrong Answer
17
3,064
260
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
val = [int(x) for x in input().split()] if val[0] == 2 or val[1] == 2: print("NO") elif val[0] in [4,6,9,11] and val[1] in [4,6,9,11]: print("YES") elif val[0] in [1,3,5,7,8,10,12] and val[1] in [1,3,5,7,8,10,12]: print("YES") else: print("NO")
s002300578
Accepted
19
3,064
251
x,y = map(int,input().split()) list1 = [1,3,5,7,8,10,12] list2 = [4,6,9,11] list3 = [2] if x in list1 and y in list1: print('Yes') elif x in list2 and y in list2: print('Yes') elif x in list3 and y in list3: print('Yes') else: print('No')
s954780482
p02603
u242196904
2,000
1,048,576
Wrong Answer
31
9,160
172
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
n = int(input()) a = list(map(int, input().split())) money = 1000 for i in range(n - 1): if a[i+1] > a[i]: money = money % a[i] + money // a[i] * a[i+1] money
s357632667
Accepted
31
9,108
179
n = int(input()) a = list(map(int, input().split())) money = 1000 for i in range(n - 1): if a[i+1] > a[i]: money = money % a[i] + money // a[i] * a[i+1] print(money)
s986733894
p03563
u663438907
2,000
262,144
Wrong Answer
17
2,940
49
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
R = int(input()) G = int(input()) print(G - 2*R)
s629748508
Accepted
17
2,940
49
R = int(input()) G = int(input()) print(2*G - R)
s711923642
p03339
u233437481
2,000
1,048,576
Wrong Answer
463
21,064
258
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
N = int(input()) S = list(input()) E = [0]*(N+1) W = [0]*(N+1) ans = 10000*10000 for i in range(N-1): if S[i] == 'E': E[i+1] += E[i] + 1 else: W[i+1] += W[i] + 1 for i in range(N): ans = min(ans,E[i]+W[i]) print(ans)
s230103803
Accepted
329
19,916
336
N = int(input()) S = list(input()) E = [0]*N W = [0]*N ans = 10000*10000 for i in range(N-1): if S[i] == 'W': W[i+1] += W[i] + 1 else: W[i+1] = W[i] for i in range(N)[:0:-1]: if S[i] == 'E': E[i-1] += E[i] + 1 else: E[i-1] = E[i] for i in range(N): ans = min(ans,E[i]+W[i]) print(ans)
s397076318
p02647
u469550773
2,000
1,048,576
Wrong Answer
2,206
51,460
525
We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i. Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row: * For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i. Find the intensity of each bulb after the K operations.
import numpy as np Debug = False # Calculate intensity N, K = [int(v) for v in input().split(" ")] A_arr = [int(v) for v in input().split(" ")] def Luminate(A_arr, i): step = np.arange(len(A_arr)) distance = abs(step - i) isLuminated = distance < np.array(A_arr)+1 if Debug: print(step, distance,isLuminated) return isLuminated def get_Intensity(A_arr): return [np.sum(Luminate(A_arr, i)) for i in range(len(A_arr))] Intensity = A_arr for i in range(K): Intensity = get_Intensity(Intensity) print(Intensity)
s350664820
Accepted
1,434
51,568
396
import numpy as np N, K = map(int, input().split(' ')) A = tuple(map(int, input().split(' '))) indexes = np.arange(0, N) dp = np.zeros(shape=N + 1, dtype=np.int64) for k in range(K): np.add.at(dp, np.maximum(0, indexes - A), 1) np.add.at(dp, np.minimum(N, indexes + A + 1), -1) A = dp.cumsum()[:-1] if np.all(A == N): break dp *= 0 print(' '.join(map(str, A)))
s253859640
p03813
u312078744
2,000
262,144
Wrong Answer
17
2,940
79
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.
s = input() num = len(s) A = s.find("A") Z = s.rfind("Z") ans = Z - A print(Z)
s278494947
Accepted
18
3,064
77
score = int(input()) if (score < 1200): print("ABC") else: print("ARC")
s834930045
p02646
u433836112
2,000
1,048,576
Wrong Answer
23
9,180
182
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a, v = list(map(int, input().strip().split())) b, w = list(map(int, input().strip().split())) t = int(input().strip()) if abs(a-b) <= (v-w)*t: print('Yes') else: print('No')
s711581398
Accepted
22
9,176
182
a, v = list(map(int, input().strip().split())) b, w = list(map(int, input().strip().split())) t = int(input().strip()) if abs(a-b) <= (v-w)*t: print('YES') else: print('NO')
s513525674
p03494
u600402037
2,000
262,144
Wrong Answer
17
3,060
324
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input()) a_list = list(map(int, input().split())) min_a = min(a_list) count = 0 while min_a % 2 == 0: min_a /= 2 count += 1 #print(count) while True: for i in range(n): if a_list[i] / 2 ** count % 2 !=0: break else: count += 1 continue break print(count)
s464117639
Accepted
151
12,504
149
import numpy as np input() A = np.array(list(map(int, input().split()))) count = 0 while all(A%2==0): count += 1 A //= 2 print(count)
s347843082
p03623
u952130512
2,000
262,144
Wrong Answer
17
2,940
71
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b=input().split() print(min(abs(int(x)-int(a)),abs(int(x)-int(b))))
s530070726
Accepted
18
2,940
95
x,a,b=input().split() if abs(int(x)-int(a))<abs(int(x)-int(b)): print("A") else: print("B")
s100434315
p03433
u824326335
2,000
262,144
Wrong Answer
17
2,940
57
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
print("YES" if int(input())%500 < int(input()) else "NO")
s980654369
Accepted
18
2,940
58
print("Yes" if int(input())%500 <= int(input()) else "No")
s668456974
p03624
u753682919
2,000
262,144
Wrong Answer
24
3,956
123
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
S=list(input()) A=list("abcdefghijklmnopqrstuvwxyz") if set(S)!=set(A): print(A[A.index(min(S))-1]) else: print("None")
s058064999
Accepted
21
3,188
183
S=set(input()) Al="qwertyuiopasdfghjklzxcvbnm" AL=list(Al) l=[] for i in range(len(Al)): if not AL[i] in S: l.append(AL[i]) if l!=[]: print(sorted(l)[0]) else: print("None")
s433156110
p03457
u925567828
2,000
262,144
Wrong Answer
445
12,496
787
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 N = int(input()) t=[0]*(N+1) x=[0]*(N+1) y=[0]*(N+1) dist = 0 dt = 0 now_x =0 now_y =0 t[0] = 0 x[0] = now_x y[0] = now_y for i in range(1,N+1): t[i],x[i],y[i] = map(int, input().split()) for i in range(1,N+1): dist = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]) dt = abs(t[i] - t[i-1]) if(dist > dt): print('No') sys.exit() else: if(dt %2 != dist %2): print('No') sys.exit() else: print('Yes')
s653263563
Accepted
374
11,636
755
import sys N = int(input()) t=[0]*(N+1) x=[0]*(N+1) y=[0]*(N+1) dist = 0 dt = 0 now_x =0 now_y =0 t[0] = 0 x[0] = now_x y[0] = now_y for i in range(1,N+1): t[i],x[i],y[i] = map(int, input().split()) for i in range(1,N+1): dist = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]) dt = abs(t[i] - t[i-1]) if(dist > dt): print('No') sys.exit() else: if(dt %2 != dist %2): print('No') sys.exit() print('Yes')
s943613917
p02613
u228303592
2,000
1,048,576
Wrong Answer
160
16,164
304
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()) k = [input() for i in range(n)] ac = 0 wa = 0 tle = 0 re = 0 for j in range(n): if k[j] == 'AC': ac += 1 elif k[j] == 'WA': wa += 1 elif k[j] == 'TLE': tle += 1 elif k[j] == 'RE': re += 1 print("AC *",ac) print("WA *",wa) print("TLE *",tle) print("RE *",re)
s238764478
Accepted
160
16,192
304
n = int(input()) k = [input() for i in range(n)] ac = 0 wa = 0 tle = 0 re = 0 for j in range(n): if k[j] == 'AC': ac += 1 elif k[j] == 'WA': wa += 1 elif k[j] == 'TLE': tle += 1 elif k[j] == 'RE': re += 1 print("AC x",ac) print("WA x",wa) print("TLE x",tle) print("RE x",re)
s030004100
p03854
u193182854
2,000
262,144
Wrong Answer
18
3,316
158
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() words = "eraser", "erase", "dreamer", "dream" for word in words: s = s.replace(word, "") print(s) print("YES" if len(s) == 0 else "NO")
s286106229
Accepted
19
3,188
145
s = input() words = "eraser", "erase", "dreamer", "dream" for word in words: s = s.replace(word, "") print("YES" if len(s) == 0 else "NO")
s418097994
p03438
u462329577
2,000
262,144
Wrong Answer
22
4,600
187
You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
#!/usr/bin/env python N = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) if N > sum(b)-sum(a): print("No") else: print("Yes") print(sum(b)-sum(a))
s237632658
Accepted
38
10,588
407
#!/usr/bin/env python3 # input import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) res = 0 for i in range(n): if a[i] > b[i]: res -= a[i] - b[i] else: res += (b[i] - a[i]) // 2 if res >= 0: print("Yes") else: print("No")
s151468390
p02389
u678690126
1,000
131,072
Wrong Answer
20
5,584
88
Write a program which calculates the area and perimeter of a given rectangle.
a, b = map(int, input().split()) if 1 <= a <= 100 and 1 <= b <= 100: print(a * b)
s486228302
Accepted
20
5,596
142
a, b = map(int, input().split()) if 1 <= a <= 100 and 1 <= b <= 100: area = a * b perimeter = (a + b) * 2 print(area, perimeter)
s669011812
p03796
u032189172
2,000
262,144
Wrong Answer
229
3,984
79
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
from math import factorial N = int(input()) P = factorial(N) print(N%(10**9+7))
s403283897
Accepted
231
4,020
79
from math import factorial N = int(input()) P = factorial(N) print(P%(10**9+7))
s625262924
p03846
u332385682
2,000
262,144
Wrong Answer
86
14,820
348
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
from collections import Counter N = int(input()) A = [int(a) for a in input().split()] c = Counter(A) c_v = sorted(c.values()) if N % 2 == 0: if c_v == [2] * (N // 2): print(2 ** (N // 2)) else: print(0) else: if c_v == [1].extend([2] * ((N - 1) // 2)): print(2 ** ((N - 1) // 2)) else: print(0)
s494368645
Accepted
93
18,272
330
from collections import Counter N = int(input()) A = [int(a) for a in input().split()] check = {} if N % 2 == 0: for i in range(1, N, 2): check[i] = 2 else: check[0] = 1 for i in range(2, N, 2): check[i] = 2 if check == Counter(A): print((2 ** (N // 2)) % (10 ** 9 + 7)) else: print(0)
s646020812
p03730
u281303342
2,000
262,144
Wrong Answer
17
2,940
128
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()) Ans = "No" for i in range(1,101): if (A*i)%B==C: Ans="Yes" break print(Ans)
s454595964
Accepted
17
3,060
251
# atcoder : python3 (3.4.3) import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) mod = 10**9+7 # main A,B,C = map(int,input().split()) ans = "NO" for i in range(1,B+1): if (A*i)%B == C: ans = "YES" break print(ans)
s592729210
p03556
u385167811
2,000
262,144
Wrong Answer
22
2,940
131
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()) i = 1 while True: if i ** 2 > n: print(i-1) break i += 1 if i >= 10000: break
s761635342
Accepted
31
2,940
139
n = int(input()) i = 1 while True: if i ** 2 > n: print((i-1)**2) break i += 1 if i >= 10000000: break
s216093813
p02678
u536034761
2,000
1,048,576
Wrong Answer
830
38,572
500
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.
from collections import deque N, M = map(int, input().split()) ways = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 ways[a].append(b) ways[b].append(a) print(ways) searched = [0 for i in range(N)] searched[0] = 1 ans = [0 for i in range(N)] d = deque([]) d.append(0) while d: tmp = d.popleft() for w in ways[tmp]: if searched[w] == 0: searched[w] = 1 ans[w] = tmp d.append(w) print("Yes") for a in ans[1:]: print(a + 1)
s209396647
Accepted
723
35,804
488
from collections import deque N, M = map(int, input().split()) ways = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 ways[a].append(b) ways[b].append(a) searched = [0 for i in range(N)] searched[0] = 1 ans = [0 for i in range(N)] d = deque([]) d.append(0) while d: tmp = d.popleft() for w in ways[tmp]: if searched[w] == 0: searched[w] = 1 ans[w] = tmp d.append(w) print("Yes") for a in ans[1:]: print(a + 1)
s013763781
p03760
u785220618
2,000
262,144
Wrong Answer
17
2,940
240
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
# -*- coding: utf-8 -*- o = list(input()[::2]) e = list(input()[1::2]) ans = [] while len(o) and len(e): if len(o): ans.append(o[0]) del o[0] if len(e): ans.append(e[0]) del e[0] print(''.join(ans))
s602306656
Accepted
17
2,940
228
# -*- coding: utf-8 -*- o = list(input()) e = list(input()) ans = [] while len(o) or len(e): if len(o): ans.append(o[0]) del o[0] if len(e): ans.append(e[0]) del e[0] print(''.join(ans))
s139289172
p03646
u923712635
2,000
262,144
Wrong Answer
2,104
39,412
84
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given an integer K. Find an integer sequence a_i such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.
K = int(input()) print(K+1) for x in range(K+1,1,-1): print(x,end=' ') print(0)
s956672387
Accepted
18
3,064
568
K = int(input()) if(K==0): print(4) print(3,3,3,3) elif(K==1): print(3) print(1,0,3) elif(K<50): n = K li = [i for i in range(n)] for i in range(n): for j in range(n): if(i==j): li[j] += n else: li[j] -= 1 print(n) print(*li) else: x = K%50 y = K//50 li = [y+i for i in range(50)] for i in range(x): for j in range(50): if(i==j): li[j] += 50 else: li[j] -= 1 print(50) print(*li)
s517025478
p03377
u870518235
2,000
262,144
Wrong Answer
28
9,108
93
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A, B, X = map(int, input().split()) if 0 < X - A <= B: print("Yes") else: print("No")
s458643622
Accepted
27
9,112
94
A, B, X = map(int, input().split()) if 0 <= X - A <= B: print("YES") else: print("NO")
s707870654
p03493
u330314953
2,000
262,144
Wrong Answer
17
2,940
89
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
s = input() cnt = 0 for i in range(len(s)): if s[i] == 1: cnt += 1 print(cnt)
s033416070
Accepted
17
2,940
91
s = input() cnt = 0 for i in range(len(s)): if s[i] == "1": cnt += 1 print(cnt)
s599780800
p03494
u018591138
2,000
262,144
Wrong Answer
20
3,060
281
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input(">>")) a = map(int, input(">>").split()) count = 0 flag = True while(flag): tmp_a = [] for i in a: if i % 2 !=0: flag = False break tmp_a.append(i/2) a = tmp_a if flag == True: count += 1 print(count)
s061149329
Accepted
19
3,060
273
n = int(input()) a = map(int, input().split()) count = 0 flag = True while(flag): tmp_a = [] for i in a: if i % 2 !=0: flag = False break tmp_a.append(i/2) a = tmp_a if flag == True: count += 1 print(count)
s047422443
p02613
u798093965
2,000
1,048,576
Wrong Answer
142
9,136
320
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()) C = 0 D = 0 E = 0 F = 0 S = '' for i in range(N): S = input() if S == 'AC': C += 1 elif S == 'WA': D += 1 elif S == 'TLE': E += 1 elif S == 'RE': F += 1 print('AC × '+ str(C)) print('WA × '+ str(D)) print('TLE × '+ str(E)) print('RE × '+ str(F))
s403306009
Accepted
148
8,988
313
N = int(input()) C = 0 D = 0 E = 0 F = 0 S = '' for i in range(N): S = input() if S == 'AC': C += 1 elif S == 'WA': D += 1 elif S == 'TLE': E += 1 elif S == 'RE': F += 1 print('AC x '+ str(C), 'WA x ' + str(D), 'TLE x ' + str(E), 'RE x ' + str(F), sep='\n')
s624821151
p03795
u365254117
2,000
262,144
Wrong Answer
17
2,940
79
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n =int(input()) if n >= 15: print(800*n-(n-15)*200) else: print(800*n)
s467230611
Accepted
17
2,940
39
n =int(input()) print(800*n-n//15*200)
s550513030
p03448
u729911693
2,000
262,144
Wrong Answer
49
3,060
235
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a = int(input()) b = int(input()) c = int(input()) x = int(input()) count = 0 for l in range(0, a): for m in range(0, b): for n in range(0, c): if(500*l+100*m+50*n == x): count+=1 print(count)
s191061795
Accepted
49
3,060
241
a = int(input()) b = int(input()) c = int(input()) x = int(input()) count = 0 for l in range(0, a+1): for m in range(0, b+1): for n in range(0, c+1): if(500*l+100*m+50*n == x): count+=1 print(count)
s079494934
p03814
u319818856
2,000
262,144
Wrong Answer
18
3,516
175
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`.
def a2z_string(s: str)->int: a = s.find('a') z = s.rfind('z') return z - a + 1 if __name__ == "__main__": s = input() ans = a2z_string(s) print(ans)
s169218320
Accepted
17
3,512
175
def a2z_string(s: str)->int: a = s.find('A') z = s.rfind('Z') return z - a + 1 if __name__ == "__main__": s = input() ans = a2z_string(s) print(ans)
s397954512
p03712
u591779169
2,000
262,144
Wrong Answer
18
3,060
161
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
h, w = map(int, input().split()) a = [] for i in range(h): a.append(input()) print("#"*(w+2)) for j in range(h): print("#" + a[0] + "#") print("#"*(w+2))
s297579456
Accepted
18
3,060
161
h, w = map(int, input().split()) a = [] for i in range(h): a.append(input()) print("#"*(w+2)) for j in range(h): print("#" + a[j] + "#") print("#"*(w+2))
s194106733
p03456
u640753006
2,000
262,144
Wrong Answer
18
2,940
137
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
import math a,b = map(int, input().split()) if a%2 == 0 or b%2 == 0: print(math.floor(a*b/2)) else: print(math.floor(a*b/2+1))
s737945277
Accepted
17
2,940
140
import math a, b = input().split() ab = a+b ab = int(ab) ans = math.sqrt(ab) if ans.is_integer(): print('Yes') else: print('No')
s579818008
p03729
u735008991
2,000
262,144
Wrong Answer
17
2,940
84
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a, b, c = input().split() print("YES" if a[0] == b[-1] and b[-1] == c[0] else "NO")
s109721702
Accepted
17
2,940
84
a, b, c = input().split() print("YES" if a[-1] == b[0] and b[-1] == c[0] else "NO")
s134117599
p03455
u155774139
2,000
262,144
Wrong Answer
17
2,940
88
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if a % b == 0: print("Even") else: print("Odd")
s354235930
Accepted
18
2,940
90
a, b = map(int, input().split()) if a*b % 2 == 0: print("Even") else: print("Odd")
s289023543
p02612
u277312083
2,000
1,048,576
Wrong Answer
33
9,136
27
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
print(int(input()) % 1000)
s243142900
Accepted
31
9,140
78
n = int(input()) if n % 1000: print(1000 - (n % 1000)) else: print(0)
s583049850
p03472
u091051505
2,000
262,144
Wrong Answer
406
12,084
550
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?
from collections import deque n, h = map(int, input().split()) a_list = [] b_list = [] time = 0 for _ in range(n): a, b = map(int, input().split()) a_list.append(a) b_list.append(b) a_list.sort() b_list.sort(reverse=True) b_stack = deque(b_list) while h > 0: if len(b_stack) > 0: if a_list[-1] < b_stack[0]: h -= b_stack.popleft() time += 1 else: time += h // a_list[-1] h = 0 else: time += h // a_list[-1] h = 0 print(time)
s573330252
Accepted
409
12,056
582
from collections import deque import math n, h = map(int, input().split()) a_list = [] b_list = [] time = 0 for _ in range(n): a, b = map(int, input().split()) a_list.append(a) b_list.append(b) a_list.sort() b_list.sort(reverse=True) b_stack = deque(b_list) while h > 0: if len(b_stack) > 0: if a_list[-1] < b_stack[0]: h -= b_stack.popleft() time += 1 else: time += math.ceil(h / a_list[-1]) h = 0 else: time += math.ceil(h / a_list[-1]) h = 0 print(time)
s569534872
p03007
u350997995
2,000
1,048,576
Wrong Answer
1,833
21,524
346
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
from heapq import heapify, heappop, heappush N = int(input()) A = list(map(int,input().split())) heapify(A) ans = [] for i in range(N-1,0,-1): n = i+1 a,b = A.pop(0),A.pop() if n%2==1: ans.append([a,b]) heappush(A,a-b) else: ans.append([b,a]) heappush(A,b-a) print(A[0]) for a in ans: print(*a)
s893821718
Accepted
270
21,676
312
N = int(input()) A = list(map(int,input().split())) ans = [] A.sort() a = A.pop(0) b = A.pop() N -= 2 k = 1 for i in range(N): y = A.pop() if y<0:k=0 if k: ans.append([a,y]) a -= y else: ans.append([b,y]) b -= y ans.append([b,a]) print(b-a) for a in ans: print(*a)
s247800609
p02612
u707808519
2,000
1,048,576
Wrong Answer
30
9,140
30
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N%1000)
s655029638
Accepted
29
9,148
74
N = int(input()) if N%1000 == 0: print(0) else: print(1000-N%1000)
s861917379
p03457
u473633103
2,000
262,144
Wrong Answer
17
3,064
365
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.
# coding: utf-8 # Your code here! n = int(input()) now = [0,0] time = 0 flag = True for i in range(n): t,x,y = map(int,input().split()) if t-time >= abs((now[0]-x)*(now[1]-y)) and (t-time)%2==((now[0]-x)*(now[1]-y))%2: now = [x,y] time = t else: flag = False break if flag: print("Yes") else: print("No")
s000926790
Accepted
379
3,064
365
# coding: utf-8 # Your code here! n = int(input()) now = [0,0] time = 0 flag = True for i in range(n): t,x,y = map(int,input().split()) if t-time >= abs((now[0]-x)+(now[1]-y)) and (t-time)%2==((now[0]-x)+(now[1]-y))%2: now = [x,y] time = t else: flag = False break if flag: print("Yes") else: print("No")
s203160662
p03524
u024782094
2,000
262,144
Wrong Answer
18
3,188
296
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
import sys def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) s=input() l=[] l.append(s.count("a")) l.append(s.count("b")) l.append(s.count("c")) if max(l)-min(l)<=1: print("Yes") else: print("No")
s988325147
Accepted
18
3,188
296
import sys def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) s=input() l=[] l.append(s.count("a")) l.append(s.count("b")) l.append(s.count("c")) if max(l)-min(l)<=1: print("YES") else: print("NO")
s267270178
p02288
u027872723
2,000
131,072
Wrong Answer
30
7,656
561
A binary heap which satisfies max-heap property is called max-heap. In a max- heap, for every node $i$ other than the root, $A Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code. $maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap. 1 maxHeapify(A, i) 2 l = left(i) 3 r = right(i) 4 // select the node which has the maximum value 5 if l ≤ H and A[l] > A[i] 6 largest = l 7 else 8 largest = i 9 if r ≤ H and A[r] > A[largest] 10 largest = r 11 12 if largest ≠ i // value of children is larger than that of i 13 swap A[i] and A[largest] 14 maxHeapify(A, largest) // call recursively The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner. 1 buildMaxHeap(A) 2 for i = H/2 downto 1 3 maxHeapify(A, i)
# -*- coding: utf_8 -*- def maxHeapify(A, i): l = 2 * i r = 2 * i + 1 largest = i if l < len(A): largest = largest if A[largest] > A[l] else l if r < len(A): largest = largest if A[largest] > A[r] else r if largest != i: A[largest], A[i] = A[i], A[largest] maxHeapify(A, largest) if __name__ == "__main__": H = int(input()) a = [int(x) for x in input().split()] print(str(int(H/2))) for i in range(int(H / 2), 1, -1): maxHeapify(a, i) print(" ".join(str(x) for x in a)),
s347530122
Accepted
1,000
65,720
562
# -*- coding: utf_8 -*- def maxHeapify(A, i): l = 2 * i - 1 r = 2 * i largest = i - 1 if l < len(A): largest = largest if A[largest] > A[l] else l if r < len(A): largest = largest if A[largest] > A[r] else r if largest != i - 1: A[largest], A[i - 1] = A[i - 1], A[largest] maxHeapify(A, largest + 1) if __name__ == "__main__": H = int(input()) a = [int(x) for x in input().split()] for i in range(int(H / 2), 0, -1): maxHeapify(a, i) print(" " + " ".join(str(x) for x in a)),
s961655495
p03563
u119982147
2,000
262,144
Wrong Answer
17
3,064
199
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
N = int(input()) K = int(input()) A = 1 + ( N * K ) B = 1 * 2 +(N-1)*K C = 1 * 2^2 +(N-2)*K D = 1 * 2^3 +(N-3)*K if A<B: print(A) elif B<C: print(B) elif C<D: print(C) else: print(D)
s226378370
Accepted
17
2,940
47
R = int(input()) G = int(input()) print(2*G-R)
s483933245
p03369
u581603131
2,000
262,144
Wrong Answer
18
2,940
47
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
list = list(input()) print(list.count('o')*100)
s015467968
Accepted
18
2,940
51
list = list(input()) print(list.count('o')*100+700)
s129490002
p03480
u497952650
2,000
262,144
Wrong Answer
61
3,188
236
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times. * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
S = input() ans = 0 tmp = 0 l = len(S) for i in range(l-1): if i == l-2: ans = max(ans,tmp+1) tmp = 0 elif S[i] == S[i+1]: tmp += 1 else: ans = max(ans,tmp+1) tmp = 0 print(min(2,ans))
s978526344
Accepted
64
3,316
198
S = input() l = len(S) ans = l """ if len(set(list(S))) == 1 and S[0] == "0": print(0) exit() """ for i in range(l-1): if S[i] != S[i+1]: ans = min(ans,max(l-i-1,i+1)) print(ans)
s074371895
p02612
u089230684
2,000
1,048,576
Wrong Answer
26
9,160
276
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N=int(input()) if 1<=N<=10000: yen=N%1000 if yen==0: print(yen) print("We can pay the exact price.") else: yen1=1000-yen print(yen1) print("We will use two 1000-yen bills to pay the price and receive %d yen in change."%yen1)
s696910486
Accepted
28
9,144
102
n = int(input()) x = n % 1000 if x == 0: print(x) else: a = ((n // 1000) + 1) * 1000 print(a - n)
s231553901
p02388
u500935997
1,000
131,072
Wrong Answer
20
5,516
37
Write a program which calculates the cube of a given integer x.
x = 2 y = 3 print(x**3) print(y**3)
s053472942
Accepted
20
5,576
30
x = int(input()) print(x**3)
s889072232
p03227
u038409959
2,000
1,048,576
Wrong Answer
17
2,940
124
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
# coding: utf-8 s = input().strip() if len(s) == 2: print(s) else: for c in s: print(c, end="") print()
s217264639
Accepted
17
2,940
105
# coding: utf-8 s = input().strip() if len(s) == 2: print(s) else: ans = s[::-1] print(ans)
s817883969
p02612
u385873134
2,000
1,048,576
Wrong Answer
34
9,144
33
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N % 1000)
s186399658
Accepted
28
9,140
77
import math N = int(input()) tmp = math.ceil(N / 1000) print(1000*tmp - N)
s105764160
p03377
u663843442
2,000
262,144
Wrong Answer
20
3,316
149
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
if __name__ == '__main__': A, B, X = map(int, input().split()) if A <= X and X <= A + B: print("Yes") else: print("No")
s358697990
Accepted
17
2,940
149
if __name__ == '__main__': A, B, X = map(int, input().split()) if A <= X and X <= A + B: print("YES") else: print("NO")
s127697841
p03610
u727238330
2,000
262,144
Wrong Answer
28
9,124
29
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input(str) print(s[::2])
s507288065
Accepted
24
9,016
26
s = input() print(s[::2])
s877757471
p03998
u748311048
2,000
262,144
Wrong Answer
17
3,064
457
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
sa = str(input()) sb = str(input()) sc = str(input()) turn = 'a' while True: if turn == 'a': if sa == '': print('A') exit() turn = sa[0] sa = sa[1:] elif turn == 'b': if sb == '': print('B') exit() turn = sb[0] sb = sb[1:] else: if sc == '': print('C') exit() turn = sc[0] sc = sc[1:] print(turn)
s360822171
Accepted
18
3,064
441
sa = str(input()) sb = str(input()) sc = str(input()) turn = 'a' while True: if turn == 'a': if sa == '': print('A') exit() turn = sa[0] sa = sa[1:] elif turn == 'b': if sb == '': print('B') exit() turn = sb[0] sb = sb[1:] else: if sc == '': print('C') exit() turn = sc[0] sc = sc[1:]
s185612287
p03713
u806855121
2,000
262,144
Wrong Answer
258
3,064
347
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
H, W = map(int, input().split()) Smin = 10**5 * 10**5 for i in range(1, H): S1 = i * W S2 = (H-i) * (W//2) S3 = (H-i) * (W-W//2) Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3)) for i in range(1, W): S1 = i * H S2 = (W-i) * (H//2) S3 = (W-i) * (H-H//2) Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3)) print(Smin)
s169084354
Accepted
500
3,064
559
H, W = map(int, input().split()) Smin = 10**5 * 10**5 for i in range(1, H): S1 = i * W S2 = (H-i) * (W//2) S3 = (H-i) * (W-W//2) Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3)) S2 = (H-i)//2 * W S3 = ((H-i)-(H-i)//2) * W Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3)) for i in range(1, W): S1 = i * H S2 = (W-i) * (H//2) S3 = (W-i) * (H-H//2) Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3)) S2 = (W-i)//2 * H S3 = ((W-i)-(W-i)//2) * H Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3)) print(Smin)
s439261611
p03544
u870297120
2,000
262,144
Wrong Answer
17
2,940
231
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)
n = int(input()) memo = [-1]*(n+1) def func(i): if i == 0: return 2 if i == 1: return 1 if memo[i] != -1: return memo[i] memo[i] = func(i-2) + func(i-1) return memo[i] func(n)
s162873342
Accepted
18
3,060
238
n = int(input()) memo = [-1]*(n+1) def func(i): if i == 0: return 2 if i == 1: return 1 if memo[i] != -1: return memo[i] memo[i] = func(i-2) + func(i-1) return memo[i] print(func(n))
s884608364
p03828
u652656291
2,000
262,144
Wrong Answer
31
9,004
92
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
n = int(input()) mod = 10**9 +7 ans = 1 for i in range(1,n+1): ans *= (i % mod) print(ans)
s251155293
Accepted
31
9,116
284
mod=10**9+7 import math n=int(input()) ans=1 l=[0]*n for ii in range(2,n+1): i=ii for j in range(2,int(math.sqrt(i))+1): if i%j==0: cnt=0 while i%j==0: cnt+=1;i//=j l[j-1]+=cnt if i!=1: l[i-1]+=1 for i in l: ans*=(i+1) ans%=mod print(ans)
s207795745
p02850
u365364616
2,000
1,048,576
Wrong Answer
758
46,796
868
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
from collections import defaultdict def bfs(i, V, E, Ec): V[i] = 1 Q = [(i, 1)] while(True): Qi = [] for q, cq in Q: c = 1 if cq == c: c += 1 for j, idx in E[q]: if V[j] == 0: V[j] = 1 Qi.append((j, c)) Ec[idx] = c if c + 1 == cq: c += 2 else: c += 1 if len(Qi) == 0: break else: Q = Qi return V, Ec n = int(input()) E = defaultdict(list) for i in range(n - 1): a, b = map(int, input().split()) E[a].append((b, i)) E[b].append((a, i)) Ec = [None for _ in range(n - 1)] V = [0 for _ in range(n + 1)] _, Ec = bfs(1, V, E, Ec) print(max(Ec)) for c in Ec: print(c)
s955797427
Accepted
729
46,444
788
from collections import defaultdict def bfs(i, V, E, Ec): V[i] = 1 Q = [(i, 0)] while(True): Qi = [] for q, cq in Q: c = 1 for j, idx in E[q]: if V[j] == 0: if cq == c: c += 1 V[j] = 1 Qi.append((j, c)) Ec[idx] = c c += 1 if len(Qi) == 0: break else: Q = Qi return V, Ec n = int(input()) E = defaultdict(list) for i in range(n - 1): a, b = map(int, input().split()) E[a].append((b, i)) E[b].append((a, i)) Ec = [None for _ in range(n - 1)] V = [0 for _ in range(n + 1)] _, Ec = bfs(1, V, E, Ec) print(max(Ec)) for c in Ec: print(c)
s528570750
p03502
u062189367
2,000
262,144
Wrong Answer
17
2,940
178
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 = int(input()) n = N print(len(str(N))) sum = 0 while N>0: N1 = N%10 print(N1) sum += N1 N = (N-N1)/10 if n%sum == 0: print('Yes') else: print('No')
s425548392
Accepted
20
3,060
147
N = int(input()) n = N sum = 0 while N>0: N1 = N%10 sum += N1 N = (N-N1)/10 if n%sum == 0: print('Yes') else: print('No')
s688883086
p03485
u164229553
2,000
262,144
Wrong Answer
148
12,468
80
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.
import numpy as np a, b = [int(j) for j in input().split()] print((a+b)//2 + 1)
s050048015
Accepted
150
12,424
78
import numpy as np a, b = [int(j) for j in input().split()] print((a+b+1)//2)
s059446836
p02613
u341543478
2,000
1,048,576
Wrong Answer
149
9,144
338
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()) ac = 0 wa = 0 tle = 0 re = 0 for _ in range(n): s = input() if s == 'AC': ac += 1 elif s == 'WA': wa += 1 elif s == 'TLE': tle += 1 elif s == 'RE': re += 1 print('AC x {}'.format(ac)) print('WA x {}'.format(wa)) print('TLE x {}'.format(tle)) print('re x {}'.format(re))
s558229951
Accepted
147
9,100
338
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for _ in range(n): s = input() if s == 'AC': ac += 1 elif s == 'WA': wa += 1 elif s == 'TLE': tle += 1 elif s == 'RE': re += 1 print('AC x {}'.format(ac)) print('WA x {}'.format(wa)) print('TLE x {}'.format(tle)) print('RE x {}'.format(re))
s023614965
p03543
u216631280
2,000
262,144
Wrong Answer
17
2,940
123
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**?
x = input() count = 0 for i in range(3): if x[i] == x[i + 1]: count += 1 if count >= 3: print('Yes') else: print('No')
s720323763
Accepted
17
2,940
93
n = input() if n[0] == n[1] == n[2] or n[1] == n[2] == n[3]: print('Yes') else: print('No')
s570126499
p03943
u410903849
2,000
262,144
Wrong Answer
25
9,028
115
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a,b,c = map(int,input().split()) if a + b == c or b + c == a or a + c == b: print("YES") else: print("NO")
s173738768
Accepted
28
9,144
115
a,b,c = map(int,input().split()) if a + b == c or b + c == a or a + c == b: print("Yes") else: print("No")
s359944917
p03471
u829895669
2,000
262,144
Wrong Answer
844
3,060
205
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()) ans = (-1,-1,-1) for i in range(N + 1): for j in range(N + 1 - i): k = N - i - j if 10000*i + 5000*j + 1000*k == Y: ans = (i,j,k) print(ans)
s691263109
Accepted
812
3,060
207
N,Y = map(int, input().split()) a,b,c = -1,-1,-1 for i in range(N + 1): for j in range(N + 1 - i): k = N - i - j if 10000*i + 5000*j + 1000*k == Y: a,b,c = i,j,k print(a,b,c)
s819916106
p03416
u123745130
2,000
262,144
Wrong Answer
68
2,940
141
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
x,y=map(int,input().split()) print(x,y) count_num=0 for i in range(x,y+1): if str(i)==str(i)[::-1]: count_num+=1 print(count_num)
s065087683
Accepted
62
2,940
130
x,y=map(int,input().split()) count_num=0 for i in range(x,y+1): if str(i)==str(i)[::-1]: count_num+=1 print(count_num)
s341567095
p02618
u608755339
2,000
1,048,576
Wrong Answer
37
9,200
171
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
N = 26 D = int(input()) C = [int(i) for i in input().split()] S = [] for i in range(D): s = max([int(i) for i in input().split()]) S.append(s) for i in S: print(i)
s983373808
Accepted
36
9,208
198
N = 26 D = int(input()) C = [int(i) for i in input().split()] S = [] for i in range(D): s = [int(i) for i in input().split()] m = max(s) i = s.index(m) S.append(i+1) for i in S: print(i)
s544779132
p04029
u111525113
2,000
262,144
Wrong Answer
18
2,940
45
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?
num = int(input()) print( num * (num+1) / 2 )
s222752577
Accepted
18
2,940
50
num = int(input()) print(int( num * (num+1) / 2 ))
s720440362
p03478
u874723578
2,000
262,144
Wrong Answer
36
3,060
141
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b = map(int, input().split()) ans = 0 for i in range(n+1): if a <= sum(list(map(int,list(str(i))))) <= b: ans += 1 print(ans)
s521830107
Accepted
36
3,060
144
n,a,b = map(int, input().split()) ans = 0 for i in range(1, n+1): if a <= sum(list(map(int,list(str(i))))) <= b: ans += i print(ans)