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
s715257289
p03720
u722189950
2,000
262,144
Wrong Answer
18
3,064
306
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?
#ABC061B N,M = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(M)] ans =[] for i in range(1,M+1): count=0 for j in range(M): if ab[j][0] ==i: count +=1 if ab[j][1] ==i: count +=1 ans.append(count) for a in ans: print(a)
s348504684
Accepted
18
3,064
306
#ABC061B N,M = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(M)] ans =[] for i in range(1,N+1): count=0 for j in range(M): if ab[j][0] ==i: count +=1 if ab[j][1] ==i: count +=1 ans.append(count) for a in ans: print(a)
s981539652
p02401
u299798926
1,000
131,072
Wrong Answer
20
7,644
255
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while 1: x,y,z=(i for i in input().split()) if y=='?': break elif y=='+': print(int(x)+int(z)) elif y =='-': print(int(x)-int(z)) elif y=='*': print(int(x)*int(z)) else : print(int(x)/int(z))
s613605444
Accepted
20
7,728
256
while 1: x,y,z=(i for i in input().split()) if y=='?': break elif y=='+': print(int(x)+int(z)) elif y =='-': print(int(x)-int(z)) elif y=='*': print(int(x)*int(z)) else : print(int(x)//int(z))
s761455329
p02612
u188305619
2,000
1,048,576
Wrong Answer
27
9,148
62
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.
def solver(N): return N % 1000 print(solver(int(input())))
s543326485
Accepted
30
9,108
167
def solver(N): for i in range(1,11): charge = 1000 * i - N if charge >= 0 and charge < 1000: return charge print(solver(int(input())))
s972167454
p02260
u733159526
1,000
131,072
Wrong Answer
30
7,528
513
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
dummy = input() s_list = list(map(int,input().split())) print(s_list) count = 0 for i in range(len(s_list)-1): min_i = i for j in range(i,len(s_list)): if s_list[j] < s_list[min_i]: min_i = j if s_list[i] != s_list[min_i]: count += 1 min_num = s_list[min_i] s_list[min_i] = s_list[i] s_list[i] = min_num for i,row in enumerate(s_list): if i == 0: print(row,end='') else: print('',row,end='') print() print(count)
s088543365
Accepted
20
7,696
787
dummy = input() s_list = list(map(int,input().split())) #print(s_list) count = 0 if len(s_list) == 1: for i,row in enumerate(s_list): if i == 0: print(row,end='') else: print('',row,end='') print() print(count) else: for i in range(len(s_list)-1): min_i = i for j in range(i,len(s_list)): if s_list[j] < s_list[min_i]: min_i = j if s_list[i] != s_list[min_i]: count += 1 min_num = s_list[min_i] s_list[min_i] = s_list[i] s_list[i] = min_num for i,row in enumerate(s_list): if i == 0: print(row,end='') else: print('',row,end='') print() print(count)
s992672627
p03681
u135116520
2,000
262,144
Wrong Answer
2,111
3,564
319
Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys. How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
N,M=map(int,input().split()) MOD=10**9+7 if N>=M: s=1 for i in range(2,N+1): s=s*i s=s%MOD t=N-M+2 for j in range(N-M+3,N+1): t=t*j t=t%MOD print((s*t)%MOD) else: s=1 for i in range(2,M+1): s=s*i s=s%MOD t=M-N+2 for j in range(N-M+3,N+1): t=t*j t=t%MOD print((s*t)%MOD)
s453481225
Accepted
56
3,064
219
N,M=map(int,input().split()) MOD=10**9+7 s=1 for i in range(2,N+1): s=(s*i)%MOD t=1 for i in range(2,M+1): t=(t*i)%MOD if abs(N-M)>1: print(0) exit() if abs(N-M)==1: print((s*t)%MOD) else: print((2*s*t)%MOD)
s003587895
p03679
u432805419
2,000
262,144
Wrong Answer
17
3,060
143
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
a = list(map(int,input().split())) if a[1] <= a[2]: print("delicious") elif (a[2] - a[1]) <= a[0]: print("safe") else: print("dangerous")
s872505864
Accepted
17
2,940
143
a = list(map(int,input().split())) if a[1] >= a[2]: print("delicious") elif (a[2] - a[1]) <= a[0]: print("safe") else: print("dangerous")
s743298146
p03997
u952130512
2,000
262,144
Wrong Answer
17
2,940
61
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h/2)
s178966861
Accepted
17
2,940
66
a=int(input()) b=int(input()) h=int(input()) print(int((a+b)*h/2))
s737522188
p02410
u572790226
1,000
131,072
Wrong Answer
20
7,740
289
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
n, m = map(int, input().split()) A = [] B = [] for line in range(n): A.append(list(map(int, input().split()))) for line in range(m): B.append(int(input())) print(A,B) ret = [] for i in range(n): ret.append(sum(A[i][j] * B[j] for j in range(m))) print('\n'.join(map(str, ret)))
s020490375
Accepted
40
8,024
290
n, m = map(int, input().split()) A = [] B = [] for line in range(n): A.append(list(map(int, input().split()))) for line in range(m): B.append(int(input())) ret = [] for i in range(n): ret.append(sum(A[i][j] * B[j] for j in range(m))) print('\n'.join(map(str, ret)))
s341311826
p03455
u947123009
2,000
262,144
Wrong Answer
23
9,004
92
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if a * b % 2 == 1: print("odd") else: print("even")
s330727924
Accepted
22
9,016
92
a, b = map(int, input().split()) if a * b % 2 == 1: print("Odd") else: print("Even")
s511328791
p03477
u089142196
2,000
262,144
Wrong Answer
17
2,940
117
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()) if A+B>C+D: print("Left") if A+B==C+D: print("Balanced") else: print("Right")
s397197032
Accepted
17
3,060
119
A,B,C,D=map(int,input().split()) if A+B>C+D: print("Left") elif A+B==C+D: print("Balanced") else: print("Right")
s711200638
p02613
u175217658
2,000
1,048,576
Wrong Answer
173
16,140
316
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 = [0]*N AC = int(0) WA = int(0) TLE = int(0) RE = int(0) for i in range(0,N): S[i] = input() if(S[i]=='AC'): AC += 1 if(S[i]=='WA'): WA += 1 if(S[i]=='TLE'): TLE += 1 if(S[i]=='RE'): RE += 1 print('AC *', AC) print('WA *', WA) print('TLE *', TLE) print('RE *', RE)
s585720793
Accepted
172
16,180
316
N = int(input()) S = [0]*N AC = int(0) WA = int(0) TLE = int(0) RE = int(0) for i in range(0,N): S[i] = input() if(S[i]=='AC'): AC += 1 if(S[i]=='WA'): WA += 1 if(S[i]=='TLE'): TLE += 1 if(S[i]=='RE'): RE += 1 print('AC x', AC) print('WA x', WA) print('TLE x', TLE) print('RE x', RE)
s451523257
p03658
u477320129
2,000
262,144
Wrong Answer
28
8,936
91
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
N, K = map(int, input().split()) print(sorted(map(int, input().split()), reverse=True)[:K])
s514053991
Accepted
27
9,156
97
N, K = map(int, input().split()) print(sum(sorted(map(int, input().split()), reverse=True)[:K]))
s704481811
p03471
u734876600
2,000
262,144
Wrong Answer
1,454
3,060
299
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 = 0 c = 1 for i in range(y // 10000 + 1): for j in range(y // 5000 + 1): if n - i - j >= 0 and (y - 10000 * i - 5000 * j) % 1000 == 0: if c != 0: print(i, j, (y- 10000 * i - 5000 * j)//1000) c = 0
s387581795
Accepted
1,586
3,064
341
n,y = map(int,input().split()) ans = 0 c = 1 for i in range(y // 10000 + 1,-1,-1): for j in range(y // 5000 + 1,-1,-1): if n - i - j >= 0 and y - 10000 * i - 5000 * j == 1000 * (n-i-j): if c != 0: print(i, j, (y-10000*i-5000*j)//1000) c = 0 if c == 1: print('-1 -1 -1')
s794220545
p03455
u770490999
2,000
262,144
Wrong Answer
28
9,080
85
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if (a*b) %2==0: print("Odd") else: print("Even")
s307060010
Accepted
28
9,096
82
a, b = map(int, input().split()) if (a*b) %2: print("Odd") else: print("Even")
s207090405
p03997
u633450100
2,000
262,144
Wrong Answer
17
2,940
67
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)
s843983146
Accepted
17
2,940
68
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s438535593
p03852
u259738923
2,000
262,144
Wrong Answer
17
2,940
59
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
['vowel','consonant'][not input() in ['a','e','i','o','u']]
s747245664
Accepted
16
2,940
157
let = input() if let == 'a' or let == "i" or let == "u" or let == "e" or let == "o" : result = "vowel" else: result = "consonant" print(result)
s491140513
p03129
u743272507
2,000
1,048,576
Wrong Answer
17
2,940
89
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()) l = n//2 if k <= l: print("YES") else: print("NO")
s097373459
Accepted
19
3,060
110
n,k = map(int,input().split()) l = (n+1)//2 if n == 1: l = 1 if k <= l: print("YES") else: print("NO")
s414474377
p03488
u545368057
2,000
524,288
Wrong Answer
2,216
435,504
804
A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction. This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back. * `F` : Move in the current direction by distance 1. * `T` : Turn 90 degrees, either clockwise or counterclockwise. The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.
Ss = input() x,y = map(int, input().split()) direc = 0 Ss = Ss + "T" prev = Ss[0] if prev == "F": cnt = 1 direc = 0 else: cnt = 0 direc = 1 mvs = [] for S in Ss[1:]: if prev == "F" and S == "F": cnt += 1 elif prev == "F" and S == "T": mvs.append((direc, cnt)) direc ^= 1 cnt = 0 elif prev == "T" and S == "F": cnt += 1 else: direc ^= 1 prev = S print(mvs) import copy cs = set() cs.add(0) for direc, dist in mvs: cs_tmp = copy.copy(cs) for c in cs_tmp: if direc == 0: cs.add(c+dist) cs.add(c-dist) else: cs.add(c+8000*dist) cs.add(c-8000*dist) print(cs) print(y*8000+x) if y*8000+x in cs: print("Yes") else: print("No")
s855722534
Accepted
1,037
10,396
594
from copy import copy Ss = input() + "T" X, Y = map(int, input().split()) d = [len(s) for s in Ss.split("T")] x = d[0] d_x = d[2::2] d_y = d[1::2] xs = set([x]) ys = set([0]) blx = [X in xs] for d in d_x: xs_ = set() for x in xs: xs_.add(x+d) xs_.add(x-d) blx.append(X in xs_) xs = copy(xs_) bly = [] for d in d_y: ys_ = set() for y in ys: ys_.add(y+d) ys_.add(y-d) bly.append(Y in ys_) ys = copy(ys_) if blx[-1] and bly[-1]: print("Yes") else: print("No")
s855467815
p03130
u058861899
2,000
1,048,576
Wrong Answer
18
3,060
211
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.
a=[0 for i in range(3)] b=[0 for i in range(3)] for i in range(3): a[i],b[i] = map(int,input().split()) a=(set(a)) b=(set(b)) if len(a)==3 and len(b)==3: print("YES") else: print("NO")
s154393106
Accepted
17
2,940
186
a="" for i in range(3): a+=(str(input())) error=0 for i in range(4): if a.count(str(i+1))>2: error=1 if error==0: print("YES") else: print("NO")
s561310205
p02389
u281808376
1,000
131,072
Wrong Answer
20
5,572
51
Write a program which calculates the area and perimeter of a given rectangle.
a_b=input().split() print(int(a_b[0])*int(a_b[1]))
s458951755
Accepted
20
5,592
81
a_b=input().split() a=int(a_b[0]) b=int(a_b[1]) print(str(a*b)+" "+str((a+b)*2))
s552203100
p03644
u445404615
2,000
262,144
Wrong Answer
20
3,060
51
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
s = input() print(s[0] + str(len(s[1:-1])) + s[-1])
s603145486
Accepted
17
2,940
148
n = int(input()) for i in range(1,10): if 2**i == n: print(2**i) exit() if 2**i > n: print(2**(i-1)) exit()
s823410118
p03828
u619819312
2,000
262,144
Wrong Answer
32
3,064
397
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
n=int(input()) k=[2] mod=10**9+7 for i in range(2,n+1): for j in range(len(k)): if i%k[j]==0: break else: k.append(i) h=[1 for i in range(len(k))] print(k) for i in range(2,n+1): c=0 while i!=1: if i%k[c]==0: i=i/k[c] h[c]+=1 else: c+=1 p=1 print(h) for i in range(len(k)): p=(p*h[i])%mod print(p)
s507279229
Accepted
30
3,064
379
n=int(input()) k=[2] mod=10**9+7 for i in range(2,n+1): for j in range(len(k)): if i%k[j]==0: break else: k.append(i) h=[1 for i in range(len(k))] for i in range(2,n+1): c=0 while i!=1: if i%k[c]==0: i=i/k[c] h[c]+=1 else: c+=1 p=1 for i in range(len(k)): p=(p*h[i])%mod print(p)
s457101245
p03591
u223904637
2,000
262,144
Wrong Answer
17
2,940
93
Ringo is giving a present to Snuke. Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things. You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.
s=list(input()) if len(s)>=4 and s[0:5]==list('YAKI'): print('Yes') else: print('No')
s310155536
Accepted
17
2,940
93
s=list(input()) if len(s)>=4 and s[0:4]==list('YAKI'): print('Yes') else: print('No')
s883138851
p03958
u697690147
1,000
262,144
Wrong Answer
29
9,096
175
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
a = list(map(int, input().split())) largest = a[0] total = 0 for ai in a: total += ai if ai > largest: largest = ai print(max(largest-(total-largest+1), 0))
s792227119
Accepted
26
9,168
129
k, t = list(map(int, input().split())) a = list(map(int, input().split())) largest = max(a) print(max(largest-(k-largest+1), 0))
s586419080
p03471
u681110193
2,000
262,144
Wrong Answer
17
3,060
208
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
N,Y = map(int,input().split()) Y /= 1000 if Y // 10 + (Y % 10) // 5 + (Y % 10) % 5 > N: print(-1,-1,-1) elif Y // 10 + (Y % 10) // 5 + (Y % 10) % 5 == N: print(Y // 10 , (Y % 10) // 5 , (Y % 10) % 5)
s640926151
Accepted
859
3,064
396
N,Y = map(int,input().split()) Y /= 1000 x=int(Y//10) y= int((Y % 10) // 5) z=int((Y % 10) % 5) flag = False if x+y+z > N: print(-1,-1,-1) elif x + y + z == N: print(x , y , z) else: for i in range (N): for j in range(N-i): if 10*i+5*j+(N-i-j)==Y: print(i,j,N-i-j) flag=True break if flag: break if flag==False: print(-1,-1,-1)
s968620438
p03796
u532514769
2,000
262,144
Wrong Answer
30
2,940
72
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
n=int(input()) x=0 for i in range(n): x=x*(n+1)%1000000007 print(x)
s693016857
Accepted
38
2,940
72
n=int(input()) x=1 for i in range(n): x=x*(i+1)%1000000007 print(x)
s314127090
p03474
u627417051
2,000
262,144
Wrong Answer
17
3,064
201
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
A, B = list(map(int, input().split())) S = input() a = S[0:A] x = S[A] b = S[A + 1:] print(a, x, b) if list(a).count("-") == 0 and x == "-" and list(b).count("-") == 0: print("Yes") else: print("No")
s445066762
Accepted
17
3,060
186
A, B = list(map(int, input().split())) S = input() a = S[0:A] x = S[A] b = S[A + 1:] if list(a).count("-") == 0 and x == "-" and list(b).count("-") == 0: print("Yes") else: print("No")
s581175283
p02393
u226541377
1,000
131,072
Wrong Answer
20
7,516
81
Write a program which reads three integers, and prints them in ascending order.
a,b,c = map(int,input().split()) numbers = [a,b,c] numbers.sort() print(numbers)
s000777655
Accepted
30
7,640
137
a,b,c = map(int,input().split()) numbers = [a,b,c] numbers.sort() print(str(numbers[0]) + " " + str(numbers[1]) + " " + str(numbers[2]))
s376816782
p03227
u223904637
2,000
1,048,576
Wrong Answer
18
2,940
128
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.
s=list(input()) ans='' if len(s)==2: print(','.join(s)) else: tmp=s[0] s[0]=s[2] s[2]=tmp print(','.join(s))
s382167111
Accepted
17
2,940
126
s=list(input()) ans='' if len(s)==2: print(''.join(s)) else: tmp=s[0] s[0]=s[2] s[2]=tmp print(''.join(s))
s419261119
p03606
u898967808
2,000
262,144
Wrong Answer
20
2,940
107
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
n = int(input()) ans = 0 for i in range(n): a,b = map(int,input().split()) ans += b-a-1 print(ans)
s733084589
Accepted
20
3,060
107
n = int(input()) ans = 0 for i in range(n): a,b = map(int,input().split()) ans += b-a+1 print(ans)
s474325615
p02865
u844697453
2,000
1,048,576
Wrong Answer
17
2,940
37
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
a = int(input()) print(a//2+0**(a%2))
s923102034
Accepted
17
2,940
37
a = int(input()) print(a//2-0**(a%2))
s325906853
p03657
u642905089
2,000
262,144
Wrong Answer
17
2,940
226
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.
def sunuke(A, B): re = 0 if A % 3 == 0: re = 1 if B % 3 == 0: re = 1 if (A+B) % 3 == 0: re = 1 if re ==1: return "Possible" else: return "Impossible"
s807234108
Accepted
17
3,060
228
Imp = list(map(int, input().split())) A = Imp[0] B = Imp[1] re = 0 if A % 3 == 0: re = 1 if B % 3 == 0: re = 1 if (A+B) % 3 == 0: re = 1 if re ==1: print("Possible") else: print("Impossible")
s593287197
p03680
u183896397
2,000
262,144
Wrong Answer
208
7,084
298
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
N = int(input()) A = [] for i in range(N): a = int(input()) A.append(a) check = 0 count = 0 botton = 1 print(A[1 -1]) for i in range(N): count += 1 if A[botton - 1] == 2: check = 1 break botton = A[botton - 1] if check == 0: print(-1) else: print(count)
s839357284
Accepted
217
7,084
283
N = int(input()) A = [] for i in range(N): a = int(input()) A.append(a) check = 0 count = 0 botton = 1 for i in range(N): count += 1 if A[botton - 1] == 2: check = 1 break botton = A[botton - 1] if check == 0: print(-1) else: print(count)
s579680241
p03860
u881378225
2,000
262,144
Wrong Answer
17
2,940
31
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s = input() print("A"+s[0]+"C")
s423695006
Accepted
17
2,940
51
s=input().split(" ") print(s[0][0]+s[1][0]+s[2][0])
s841478739
p00292
u724548524
1,000
131,072
Wrong Answer
20
5,580
82
K 個の石から、P 人が順番に1つずつ石を取るゲームがあります。P 人目が石を取った時点で、まだ石が残っていれば、また1人目から順番に1つずつ石を取っていきます。このゲームでは、最後の石を取った人が勝ちとなります。K とP が与えられたとき、何人目が勝つか判定するプログラムを作成してください。
for _ in range(int(input())): a,b = map(int,input().split()) print(a%b+1)
s329687840
Accepted
20
5,588
86
for _ in range(int(input())): a,b = map(int,input().split()) print((a-1)%b+1)
s274783757
p03524
u366886346
2,000
262,144
Wrong Answer
36
9,704
147
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.
s=list(input()) a=s.count("a") b=s.count("b") c=s.count("c") if min(a,b,c)!=0 and max(a,b,c)-min(a,b,c)<=1: print("Yes") else: print("No")
s550405374
Accepted
36
9,740
285
s=list(input()) a=s.count("a") b=s.count("b") c=s.count("c") l1=[a,b,c] l1.sort() if l1[0]==0 and l1[1]==1 and l1[2]==1: print("YES") elif min(a,b,c)!=0 and max(a,b,c)-min(a,b,c)<=1: print("YES") elif a+b+c==max(a,b,c) and max(a,b,c)==1: print("YES") else: print("NO")
s863567680
p02409
u150984829
1,000
131,072
Wrong Answer
20
5,608
197
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
a=[[[0]*10]*3]*4 for _ in range(int(input())): b,f,r,v=map(int,input().split()) a[b-1][f-1][r-1]=v for i in range(4): for j in range(3): for k in range(10): print(a[i][j][k]) print('#'*20)
s242734199
Accepted
20
5,620
199
a=[[10*[0]for _ in[0]*3]for _ in[0]*4] for _ in[0]*int(input()): b,f,r,v=map(int,input().split()) a[b-1][f-1][r-1]+=v for i in range(4): for j in range(3):print('',*a[i][j]) if i<3:print('#'*20)
s614771402
p03408
u177756077
2,000
262,144
Wrong Answer
18
3,064
260
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
N=int(input()) s=[input() for i in range(N)] M=int(input()) t=[input() for i in range(M)] dict={} wordlist=list(set(s+t)) for i in wordlist: cnt=0 if i in s: cnt=cnt+1 if i in t: cnt=cnt-1 dict[i]=cnt print(max(dict.values()))
s132193809
Accepted
20
3,316
269
from collections import Counter N=int(input()) s=[input() for i in range(N)] M=int(input()) t=[input() for i in range(M)] wordlist=list(set(s+t)) cnt=0 ss=Counter(s) tt=Counter(t) for i in wordlist: buf=ss[i]-tt[i] if cnt<buf: cnt=buf print(cnt)
s701382948
p03359
u923279197
2,000
262,144
Wrong Answer
17
2,940
70
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a,b=map(int,input().split()) if a<b: print(a) else: print(a-1)
s278153330
Accepted
17
2,940
71
a,b=map(int,input().split()) if a<=b: print(a) else: print(a-1)
s834984589
p03860
u265118937
2,000
262,144
Wrong Answer
27
9,096
61
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s = input() print("A", end="") print(s[0], end="") print("C")
s660731489
Accepted
26
8,956
34
s = input() print(s[0]+s[8]+s[-7])
s129347205
p03415
u608432532
2,000
262,144
Wrong Answer
17
2,940
92
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
c = list() for i in range(3): c.append(input(i)) #print(c) print(c[0][0]+c[1][1]+c[2][2])
s013326325
Accepted
18
2,940
91
c = list() for i in range(3): c.append(input()) #print(c) print(c[0][0]+c[1][1]+c[2][2])
s907126060
p02393
u521963900
1,000
131,072
Wrong Answer
20
7,668
55
Write a program which reads three integers, and prints them in ascending order.
N = [int(i) for i in input().split()] N.sort() print(N)
s411461723
Accepted
20
7,752
74
N = [int(i) for i in input().split()] N.sort() print(" ".join(map(str,N)))
s733142140
p02388
u090921599
1,000
131,072
Wrong Answer
20
5,568
40
Write a program which calculates the cube of a given integer x.
x = input() n = int(x)^3 print('n=', n)
s733728456
Accepted
20
5,576
35
x = int(input()) print(x * x * x)
s901948557
p03711
u882620594
2,000
262,144
Wrong Answer
18
3,064
386
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.
import sys a=list(map(int,input().split())) flg=0 A=[1,3,5,7,8,10,12] B=[4,6,9,11] C=[2] for i in range(len(A)): if A[i]==a[0]: for j in range(len(A)): if A[j]==a[1]: flg=1 for i in range(len(B)): if B[i]==a[0]: for j in range(len(B)): if B[j]==a[1]: flg=1 if flg==1: print("YES") else: print("NO")
s975587235
Accepted
17
3,064
386
import sys a=list(map(int,input().split())) flg=0 A=[1,3,5,7,8,10,12] B=[4,6,9,11] C=[2] for i in range(len(A)): if A[i]==a[0]: for j in range(len(A)): if A[j]==a[1]: flg=1 for i in range(len(B)): if B[i]==a[0]: for j in range(len(B)): if B[j]==a[1]: flg=1 if flg==1: print("Yes") else: print("No")
s707996624
p03387
u594244257
2,000
262,144
Wrong Answer
17
3,060
342
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
A,B,C = map(int, input().split()) ret = 0 if not (A%2 == B%2 and B%2 == C%2): ret += 1 if A%2 == B%2: A += 1 B += 1 else: B += 1 C += 1 # print(A,B,C) max_elem = max(A,B,C) ret += (max_elem-A)//2 + (max_elem-B)//2 + (max_elem-C)//2 print(ret)
s858129438
Accepted
17
3,064
455
A,B,C = map(int, input().split()) ret = 0 if not (A%2 == B%2 and B%2 == C%2): ret += 1 if A%2 == B%2: A += 1 B += 1 elif B%2 == C%2: B += 1 C += 1 else: A += 1 C += 1 max_elem = max(A,B,C) ret += (max_elem-A)//2 + (max_elem-B)//2 + (max_elem-C)//2 print(ret)
s850203166
p03730
u576335153
2,000
262,144
Wrong Answer
32
9,076
283
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 = '' if a % b == 0: if c == 0: ans = 'YES' else: ans = 'NO' else: k = a % b for x in range(c+1): if (k * x) % b == c: ans = 'YES' break else: ans = 'NO' print(ans)
s987369256
Accepted
26
9,064
283
a, b, c = map(int, input().split()) ans = '' if a % b == 0: if c == 0: ans = 'YES' else: ans = 'NO' else: k = a % b for x in range(101): if (k * x) % b == c: ans = 'YES' break else: ans = 'NO' print(ans)
s712517092
p02281
u851695354
1,000
131,072
Wrong Answer
20
7,664
1,133
Binary trees are defined recursively. A binary tree _T_ is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: \- a root node. \- a binary tree called its left subtree. \- a binary tree called its right subtree. Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: 1. Print the root, the left subtree and right subtree (preorder). 2. Print the left subtree, the root and right subtree (inorder). 3. Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
class Tree: def __init__(self,parent,left,right): self.parent = parent self.left = left self.right = right def preparse(u): if u == -1: return print(" ", end="") print(u, end="") preparse(trees[u].left) preparse(trees[u].right) def inparse(u): if u == -1: return inparse(trees[u].left) print(" ", end="") print(u, end="") inparse(trees[u].right) def postparse(u): if u == -1: return postparse(trees[u].left) postparse(trees[u].right) print(" ", end="") print(u, end="") N = int(input()) # ????????? trees = [Tree(-1,-1,-1) for i in range(N)] for i in range(N): l = list(map(int, input().split())) no = l[0] left = l[1] right = l[2] trees[no].left = left trees[no].right = right if left != -1: trees[left].parent = no if right != -1: trees[right].parent = no print("Preorder") preparse(0) print("") print("Inorder") inparse(0) print("") print("Postorder") postparse(0)
s998818119
Accepted
20
7,852
1,213
class Tree: def __init__(self,parent,left,right): self.parent = parent self.left = left self.right = right def preparse(u): if u == -1: return print(" ", end="") print(u, end="") preparse(trees[u].left) preparse(trees[u].right) def inparse(u): if u == -1: return inparse(trees[u].left) print(" ", end="") print(u, end="") inparse(trees[u].right) def postparse(u): if u == -1: return postparse(trees[u].left) postparse(trees[u].right) print(" ", end="") print(u, end="") N = int(input()) # ????????? trees = [Tree(-1,-1,-1) for i in range(N)] for i in range(N): l = list(map(int, input().split())) no = l[0] left = l[1] right = l[2] trees[no].left = left trees[no].right = right if left != -1: trees[left].parent = no if right != -1: trees[right].parent = no r = 0 for i in range(N): if trees[i].parent == -1: r = i print("Preorder") preparse(r) print("") print("Inorder") inparse(r) print("") print("Postorder") postparse(r) print("")
s768340439
p04043
u632369368
2,000
262,144
Wrong Answer
17
2,940
128
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.
V = tuple([int(n) for n in input().split()]) if V in [(5, 5, 7), (5, 7, 5), (7, 5, 5)]: print('Yes') else: print('No')
s431258015
Accepted
17
2,940
128
V = tuple([int(n) for n in input().split()]) if V in [(5, 5, 7), (5, 7, 5), (7, 5, 5)]: print('YES') else: print('NO')
s099176677
p03711
u661980786
2,000
262,144
Wrong Answer
17
3,060
227
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.
x,y = map(int,input().split()) g1 = [1,3,4,5,6,10,12] g2 = [4,6,9,11] g3 = [2] if x in g1 and y in g1: print("YES") elif x in g2 and y in g2: print("YES") elif x in g3 and y in g3: print("YES") else: print("NO")
s380951416
Accepted
17
3,060
227
x,y = map(int,input().split()) g1 = [1,3,5,7,8,10,12] g2 = [4,6,9,11] g3 = [2] if x in g1 and y in g1: print("Yes") elif x in g2 and y in g2: print("Yes") elif x in g3 and y in g3: print("Yes") else: print("No")
s223783587
p03447
u825528847
2,000
262,144
Wrong Answer
19
3,316
69
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
X = int(input()) A = int(input()) B = int(input()) print((X-A) // B)
s183197161
Accepted
19
3,316
93
X = int(input()) A = int(input()) B = int(input()) tmp = (X-A) // B print((X-A) - (tmp * B))
s018289636
p00424
u355726239
1,000
131,072
Wrong Answer
340
7,172
345
与えられた変換表にもとづき,データを変換するプログラムを作成しなさい. データに使われている文字は英字か数字で,英字は大文字と小文字を区別する.変換表に現れる文字の順序に規則性はない. 変換表は空白をはさんで前と後ろの 2 つの文字がある(文字列ではない).変換方法は,変換表のある行の前の文字がデータに現れたら,そのたびにその文字を後ろの文字に変換し出力する.変換は 1 度だけで,変換した文字がまた変換対象の文字になっても変換しない.変換表に現れない文字は変換せず,そのまま出力する. 入力ファイルには,変換表(最初の n + 1 行)に続き変換するデータ(n + 2 行目以降)が書いてある. 1 行目に変換表の行数 n,続く n 行の各行は,空白をはさんで 2 つの文字,さらに続けて, n + 2 行目に変換するデータの行数 m,続く m 行の各行は 1 文字である. m ≤ 105 とする.出力は,出力例のように途中に空白や改行は入れず 1 行とせよ. 入力例 --- 3 A a 0 5 5 4 10 A B C 0 1 4 5 a b A 出力例 aBC5144aba
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: dic = {} n = int(input()) if n == 0: break for i in range(n): key, value = input().split() dic[key] = value print(dic) ret = '' m = int(input()) for i in range(m): s = input() ret += dic.get(s, s) print(ret)
s552085775
Accepted
340
7,168
339
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: dic = {} n = int(input()) if n == 0: break for i in range(n): key, value = input().split() dic[key] = value ret = '' m = int(input()) for i in range(m): s = input().strip() ret += dic.get(s, s) print(ret)
s188561894
p03377
u222841610
2,000
262,144
Wrong Answer
17
2,940
68
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()) print('Yes' if a<=x<=a+b else 'No')
s916965451
Accepted
17
2,940
68
a,b,x = map(int,input().split()) print('YES' if a<=x<=a+b else 'NO')
s629721583
p04043
u919025034
2,000
262,144
Wrong Answer
17
2,940
150
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.
# coding: utf-8 # Your code here! a = list(map(int,input().split())) if a.count(5) == 2 and a.count(7) == 1: print("Yes") else: print("No")
s643639194
Accepted
17
2,940
150
# coding: utf-8 # Your code here! a = list(map(int,input().split())) if a.count(5) == 2 and a.count(7) == 1: print("YES") else: print("NO")
s802004910
p02694
u456376495
2,000
1,048,576
Wrong Answer
28
9,104
76
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x=int(input()) i=100 j=0 while i<x: i=int(i*1.01) j+=1 print(j-1)
s956299874
Accepted
30
9,036
68
x=int(input()) i=100 j=0 while i<x: i+=i//100 j+=1 print(j)
s750692279
p03129
u023229441
2,000
1,048,576
Wrong Answer
17
2,940
78
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
a,b=map(int,input().split()) if a>=(2*b+1): print("YES") else: print("NO")
s272803557
Accepted
17
2,940
79
a,b=map(int,input().split()) if a>=(2*b-1): print("YES") else: print("NO")
s812211870
p02612
u677253688
2,000
1,048,576
Wrong Answer
28
9,140
52
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) a = n%1000 a = 1000-a a%=a print(a)
s484775504
Accepted
29
9,140
56
n = int(input()) x = (n+1000-1)//1000 x*=1000 print(x-n)
s829697684
p03493
u294714703
2,000
262,144
Wrong Answer
26
8,896
30
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() s[0] + s[1] + s[2]
s335256466
Accepted
26
9,100
57
s = str(input()) print(int(s[0]) + int(s[1]) + int(s[2]))
s958501498
p02613
u254221913
2,000
1,048,576
Wrong Answer
145
16,168
216
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 = [0] * n for i in range(n): s[i] = input() print('AC × ' + str(s.count('AC'))) print('WA × ' + str(s.count('WA'))) print('TLE × ' + str(s.count('TLE'))) print('RE × ' + str(s.count('RE')))
s637689440
Accepted
147
16,176
212
n = int(input()) s = [0] * n for i in range(n): s[i] = input() print('AC x ' + str(s.count('AC'))) print('WA x ' + str(s.count('WA'))) print('TLE x ' + str(s.count('TLE'))) print('RE x ' + str(s.count('RE')))
s474661887
p02678
u219494936
2,000
1,048,576
Wrong Answer
2,207
63,356
616
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 heapq import numpy as np N, M = [int(x) for x in input().split(" ")] e = {i: [] for i in range(N)} for _ in range(M): a, b = [int(x)-1 for x in input().split(" ")] e[a] = e[a] + [b] e[b] = e[b] + [a] # roots = [[int(x) for x in input().split(" ")] for _ in range(M)] d = np.ones(N, dtype=int) * np.inf d[0] = 0 prev = np.ones(N, dtype=int) * -1 q = [(d[0], 0)] heapq.heapify(q) while len(q) != 0: c, u = heapq.heappop(q) for nv in e[u]: alt = d[u] + 1 if d[nv] > alt: d[nv] = alt prev[nv] = u heapq.heappush(q, (alt, nv)) print("YES") for p in prev[1:]: print(p+1)
s881030318
Accepted
1,628
59,708
481
import heapq import numpy as np N, M = [int(x) for x in input().split(" ")] e = {i: [] for i in range(N)} for _ in range(M): a, b = [int(x)-1 for x in input().split(" ")] e[a].append(b) e[b].append(a) d = np.ones(N, dtype=int) * -1 q = [0] while len(q) != 0: v = q.pop(0) for ne in e[v]: if d[ne] == -1: d[ne] = v q.append(ne) print("Yes") # for p in prev[1:]: # print(p+1) # print("\n".join([str(p+1) for p in d[1:]])) for p in d[1:]: print(p+1)
s117524590
p03592
u569272329
2,000
262,144
Wrong Answer
314
2,940
228
We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
N, M, K = map(int, input().split()) flag = True for i in range(0, N+1): for j in range(0, M+1): if (i*(M-j)+j*(N-i)) == K: print("Yes") flag = False break if flag: print("No")
s558346397
Accepted
305
2,940
208
N, M, K = map(int, input().split()) flag = False for i in range(0, N+1): for j in range(0, M+1): if (i*(M-j)+j*(N-i)) == K: flag = True if flag: print("Yes") else: print("No")
s132378156
p02659
u464626513
2,000
1,048,576
Wrong Answer
23
9,104
95
Compute A \times B, truncate its fractional part, and print the result as an integer.
input = input() split = input.split() out = float(split[0]) * float(split[1]) print(round(out))
s050452298
Accepted
20
9,168
106
split = input().split() num1 = int(split[0]) num2 = int(float(split[1])*1000) print(int(num1*num2)//1000)
s507726056
p03007
u866769581
2,000
1,048,576
Wrong Answer
324
21,836
316
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.
#c.py from collections import deque n = int(input()) lis = list(map(int,input().split())) lis.sort() lis = deque(lis) x = 0 ans_lis = [] while len(lis) != 1: mi = lis.popleft() ma = lis.pop() lis.append(mi - ma) ans_lis.append([mi,ma]) x += 1 print(lis[0]) for x in ans_lis: print(x[0],x[1])
s248699856
Accepted
296
23,108
326
#c.py n = int(input()) lis = list(map(int,input().split())) lis.sort() m = lis[0] M = lis[-1] ans_lis = [] for now in lis[1:-1]: if now > 0: ans_lis.append([m,now]) m -= now else: ans_lis.append([M,now]) M -= now ans_lis.append([M,m]) print(M-m) for x in ans_lis: print(x[0],x[1])
s292780380
p04029
u180528413
2,000
262,144
Wrong Answer
18
2,940
170
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?
s = input() s_list = list(s) count = s.count('B') for _ in range(count): ind = s_list.index('B') s_list[ind-1] = '' s = ''.join(s_list) s = s.replace('B','') print(s)
s353625084
Accepted
355
21,556
122
import numpy as np N = int(input()) all_list = [i for i in range(1, N+1)] result = np.cumsum(all_list) print(max(result))
s536901166
p03712
u535171899
2,000
262,144
Wrong Answer
18
3,060
113
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()) print('#'*w) for i in range(h): s = input() print('#'+s+'#') print('#'*w)
s214532990
Accepted
18
3,060
189
h,w = map(int,input().split()) ans_map = [['#'*(w+2)]] for i in range(h): s = input() ans_map.append(['#'+s+'#']) ans_map.append(['#'*(w+2)]) for ans in ans_map: print(ans[0])
s060875300
p03943
u246661425
2,000
262,144
Wrong Answer
17
2,940
112
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 a + c ==b or b + c == a: print("YES") else: print("NO")
s973385030
Accepted
17
2,940
112
a, b, c = map(int, input().split()) if a + b == c or a + c ==b or b + c == a: print("Yes") else: print("No")
s278782898
p03478
u359856428
2,000
262,144
Time Limit Exceeded
2,104
2,940
234
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).
def Fanc(x): ans = 0 while x > 0: ans += x % 10 x // 10 return ans N,A,B = map(int,input().split()) sum = 0 for i in range(1,N + 1): if A < Fanc(i) and Fanc(i) < B: sum += i print(sum)
s797296258
Accepted
31
3,060
240
def Fanc(x): ans = 0 while x > 0: ans += x % 10 x = x // 10 return ans N,A,B = map(int,input().split()) sum = 0 for i in range(1,N + 1): if A <= Fanc(i) and Fanc(i) <= B: sum += i print(sum)
s575871180
p02612
u626228246
2,000
1,048,576
Wrong Answer
34
9,144
93
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.
import sys n = int(input()) for i in range(100): if 1000*i >= n: print(1000*i - n)
s882164939
Accepted
28
9,152
103
import sys n = int(input()) for i in range(100): if 1000*i >= n: print(1000*i - n) sys.exit()
s397254078
p03544
u835482198
2,000
262,144
Wrong Answer
17
2,940
97
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()) ls = [2, 1] for i in range(n - 1): ls.append(ls[-1] + ls[-1]) print(ls[-1])
s420662619
Accepted
17
2,940
97
n = int(input()) ls = [2, 1] for i in range(n - 1): ls.append(ls[-1] + ls[-2]) print(ls[-1])
s874124288
p03166
u823885866
2,000
1,048,576
Wrong Answer
2,112
80,948
495
There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
import sys import math import itertools import collections import numpy as np rl = sys.stdin.readline N, M = map(int, rl().split()) li = [[] for _ in range(N)] deg = [0] * N for _ in range(M): a, b = map(int, rl().split()) a -= 1 b -= 1 li[a].append(b) deg[b] = 1 deg = [i for i in range(N) if deg[i] == 0] print(deg) dp = [0] * N for i in deg: for j in li[i]: if dp[j] < dp[i] + 1: dp[j] = dp[i] + 1 deg.append(j) print(dp)
s856551136
Accepted
423
31,632
638
import sys import math import itertools import collections import numpy as np rl = sys.stdin.readline def a(): N, M = map(int, rl().split()) li = [[] for _ in range(N)] deg = [0] * N for _ in range(M): a, b = map(int, rl().split()) a -= 1 b -= 1 li[a].append(b) deg[b] += 1 d = collections.deque([i for i in range(N) if deg[i] == 0]) dp = [0] * N while d: i = d.popleft() for j in li[i]: deg[j] -= 1 if deg[j] == 0: dp[j] = max(dp[j] ,dp[i] + 1) d.append(j) print(max(dp)) a()
s019946762
p03494
u409757418
2,000
262,144
Wrong Answer
19
3,060
162
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()) ais = input().split() t = [] for a in ais: m = 0 a = int(a) while a % 2 == 0: m += 1 a = a / 2 t.append(m) print(t) print(min(t))
s007600814
Accepted
19
2,940
153
n = int(input()) ais = input().split() t = [] for a in ais: m = 0 a = int(a) while a % 2 == 0: m += 1 a = a / 2 t.append(m) print(min(t))
s949303707
p03433
u940780117
2,000
262,144
Wrong Answer
17
3,064
85
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()) mod = N%500 if mod<=A: print('YES') else: print('NO')
s625084059
Accepted
17
2,940
85
N=int(input()) A=int(input()) mod = N%500 if mod<=A: print('Yes') else: print('No')
s749915822
p02281
u096660561
1,000
131,072
Wrong Answer
20
5,456
1
Binary trees are defined recursively. A binary tree _T_ is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: \- a root node. \- a binary tree called its left subtree. \- a binary tree called its right subtree. Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: 1. Print the root, the left subtree and right subtree (preorder). 2. Print the left subtree, the root and right subtree (inorder). 3. Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
s240697603
Accepted
20
5,624
1,563
def Pre(i): if dali[i].node != -1: ret = dali[i].node dali[i].node = -1 order.append(ret) if dali[i].left != -1: Pre(dali[i].left) if dali[i].right != -1: Pre(dali[i].right) def Pre2(u): if u == -1: return order.append(u) Pre2(dali[u].left) Pre2(dali[u].right) def In2(u): if u == -1: return In2(dali2[u].left) order.append(u) In2(dali2[u].right) def Postorder(u): if u == -1: return None Postorder(dali3[u].left) Postorder(dali3[u].right) order.append(dali3[u].node) dali3[u].node = -1 class BiTree(): def __init__(self, node, left, right): self.node = node self.left = left self.right = right def inputdata(i): node, left, right = list(map(int, input().split())) dali[node] = BiTree(node, left, right) dali2[node] = BiTree(node, left, right) dali3[node] = BiTree(node, left, right) # Getting Root n = int(input()) dali = [0] * n dali2 = [0] * n dali3 = [0] * n order = [] for i in range(n): inputdata(i) for i in range(n): for j in range(n): if i == dali[j].left or i == dali[j].right: break if j == n-1: root = i break order = [] Pre2(root) print("Preorder") print(" ",end = "") print(*order) order = [] In2(root) print("Inorder") print(" ",end = "") print(*order) order = [] print("Postorder") print(" ",end = "") Postorder(root) print(*order)
s742318057
p03549
u626881915
2,000
262,144
Wrong Answer
24
3,188
262
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
import math n, m = map(int, input().split()) s = 0 p = [0.0] k = 1 s_old = -1.0 while s - s_old >= 0.0000001: pr = (1 - sum(p)) / (2**m) p.append(pr) s_old = s s += (1900 * m + 100 * (n - m)) * k * pr k += 1 print(s) print(math.ceil(s))
s902659726
Accepted
23
3,064
247
import math n, m = map(int, input().split()) s = 0 p = [0.0] k = 1 s_old = -1.0 while s - s_old >= 0.0000001: pr = (1 - sum(p)) / (2**m) p.append(pr) s_old = s s += (1900 * m + 100 * (n - m)) * k * pr k += 1 print(math.ceil(s))
s326568746
p02612
u729008627
2,000
1,048,576
Wrong Answer
31
9,144
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)
s096177960
Accepted
32
9,144
31
N = int(input()) print(-N%1000)
s948709210
p03592
u751663243
2,000
262,144
Wrong Answer
216
3,188
316
We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
N,M,K = map(int,input().strip().split()) def judge(N,M,K): if K > N * M or K < 0: return False for n in range(1, N + 1): for m in range(1, M + 1): if n * M + m * N - m * n == K: return True return False if judge(N, M, K): print("Yes") else: print("No")
s654858272
Accepted
247
3,060
318
N,M,K = map(int,input().strip().split()) def judge(N,M,K): if K > N * M or K < 0: return False for n in range(0, N + 1): for m in range(0, M + 1): if n * M + m * N - 2*m * n == K: return True return False if judge(N, M, K): print("Yes") else: print("No")
s084859286
p03251
u370331385
2,000
1,048,576
Wrong Answer
19
3,064
227
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N,M,X,Y = map(int,input().split()) X = input().split() Y = input().split() for i in range(N): X[i] = int(X[i]) for i in range(M): Y[i] = int(Y[i]) X.sort() Y.sort() if((X[-1]+1)<Y[0]): print('No war') else: print('war')
s256159016
Accepted
20
3,064
250
N,M,x,y = map(int,input().split()) X = input().split() Y = input().split() for i in range(N): X[i] = int(X[i]) for i in range(M): Y[i] = int(Y[i]) X.sort() Y.sort() Z = Y[0] if( (X[-1]<Z)and(x<Z)and(Z<=y)): print('No War') else: print('War')
s354463949
p02607
u084411645
2,000
1,048,576
Wrong Answer
31
8,972
53
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
print(sum([int(i)%2 for i in input().split()[1::2]]))
s939173048
Accepted
26
8,960
61
input() print(sum([int(i)%2 for i in input().split()[::2]]))
s678336141
p00015
u811773570
1,000
131,072
Wrong Answer
20
7,516
226
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
ans = [] i = int(input()) for n in range(i): j = int(input()) k = int(input()) x = str(j + k) if len(x) >= 80: ans.append("overflow") else: ans.append(x) for n in range(i): print(ans[n])
s142305443
Accepted
20
7,632
160
a = int(input()) for i in range(a): x = int(input()) y = int(input()) if x + y >= 10 ** 80: print("overflow") else: print(x + y)
s187062473
p03563
u257974487
2,000
262,144
Wrong Answer
17
3,064
299
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.
import sys s = input() T=input() p = 0 for i in range(len(s)-len(T)+1,0,-1): for j in range(len(T)): if T[j]!=s[i-1+j] and "?"!= s[i-1+j] : break p = 1 else: s=s[:i-1]+T+s[i+len(T)-1:] s = s.replace('?', 'a') print(s) sys.exit() if p == 1: print("UNRESTORABLE")
s757934792
Accepted
17
2,940
50
a = int(input()) b = int(input()) print(b*2 - a)
s900025888
p03433
u861141787
2,000
262,144
Wrong Answer
17
2,940
90
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 N % 500 <= A: print("YES") else: print("NO")
s479842987
Accepted
17
2,940
90
N = int(input()) A = int(input()) if N % 500 <= A: print("Yes") else: print("No")
s137779869
p03352
u023229441
2,000
1,048,576
Wrong Answer
17
2,940
128
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.
z=int(input()) x=[] for i in range(31): for j in range(10): if (i+1)**(j+1)<=z: x.append((i+1)**(j+1)) print(max(x))
s470245675
Accepted
17
2,940
129
z=int(input()) x=[] for i in range(31): for j in range(10): if (i+1)**(j+2)<=z: x.append((i+1)**(j+2)) print(max(x))
s639873794
p03455
u911472374
2,000
262,144
Wrong Answer
18
2,940
101
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()) c = a * b if c % 2 == 1: print("Odd") else: print("even")
s497804826
Accepted
17
2,940
104
a, b = map(int, input().split()) c = int(a * b) if c % 2 == 0: print("Even") else: print("Odd")
s110528904
p03501
u426572476
2,000
262,144
Wrong Answer
17
2,940
69
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.
import math n, a, b = map(int, input().split()) print(min(b, a + n))
s028730308
Accepted
17
2,940
69
import math n, a, b = map(int, input().split()) print(min(b, a * n))
s504914822
p02821
u057668615
2,000
1,048,576
Wrong Answer
1,385
17,840
1,170
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
import sys, math, itertools, collections, bisect mans = float('inf') mod = 10 **9 +7 ans = 0 count = 0 pro = 0 N, M = map(int, input().split()) A = sorted(map(int, input().split())) B = [0] + A[:] for i in range(N): B [i+1] += B[i] print('A', A) print('B', B) def solve_binary(mid): tmp = 0 for i, ai in enumerate(A): tmp += N - bisect.bisect_left(A, mid-ai) return tmp >= M def binary_search(N): ok = 0 ng = N while abs(ok - ng ) > 1: mid = (ok + ng) // 2 if solve_binary(mid): ok = mid else: ng = mid return ok binresult = binary_search(2*10**5+1) #binresult=ok #print(binresult) for i, ai in enumerate(A): ans += ai*(N - bisect.bisect_left(A, binresult-ai)) + B[N] - B[bisect.bisect_left(A, binresult-ai)] count += N - bisect.bisect_left(A, binresult-ai) ans -= binresult * (count-M) print(ans)
s176480472
Accepted
1,445
14,780
1,179
#Eans import sys, math, itertools, collections, bisect mans = float('inf') mod = 10 **9 +7 ans = 0 count = 0 pro = 0 N, M = map(int, input().split()) A = sorted(map(int, input().split())) B = [0] + A[:] for i in range(N): B [i+1] += B[i] #print('A', A) def solve_binary(mid): tmp = 0 for i, ai in enumerate(A): tmp += N - bisect.bisect_left(A, mid-ai) return tmp >= M def binary_search(N): ok = 0 ng = N while abs(ok - ng ) > 1: mid = (ok + ng) // 2 if solve_binary(mid): ok = mid else: ng = mid return ok binresult = binary_search(2*10**5+1) #binresult=ok #print(binresult) for i, ai in enumerate(A): ans += ai*(N - bisect.bisect_left(A, binresult-ai)) + B[N] - B[bisect.bisect_left(A, binresult-ai)] count += N - bisect.bisect_left(A, binresult-ai) ans -= binresult * (count-M) print(ans)
s049011055
p03598
u790301364
2,000
262,144
Wrong Answer
18
3,060
356
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
def main48(): n = int(input()) k = int(input()) data = input().split() x = [] for i in range(n): x.append(int(data[i])) result = 0 for i in range(n): if x[i] < k-x[i]: result = result + x[i] else: result = result + k-x[i] print(result) if __name__ == "__main__": main48()
s556918959
Accepted
17
3,064
366
def main48(): n = int(input()) k = int(input()) data = input().split() x = [] for i in range(n): x.append(int(data[i])) result = 0 for i in range(n): if x[i] < k-x[i]: result = result + x[i] * 2 else: result = result + (k-x[i]) * 2 print(result) if __name__ == "__main__": main48()
s941727965
p03455
u176796545
2,000
262,144
Wrong Answer
20
3,316
74
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("Even" if a%2==0 and b%2==0 else "Odd")
s893562688
Accepted
19
2,940
64
a, b=map(int, input().split()) print("Odd" if a*b%2 else "Even")
s116533889
p03644
u103902792
2,000
262,144
Wrong Answer
17
2,940
74
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n = int(input()) for i in range(n): m = 2**i if m > n: print(m//2)
s879005688
Accepted
17
2,940
121
n = int(input()) if n == 1: print(1) exit(0) for i in range(n): m = 2**i if m > n: print(m//2) exit(0)
s184192450
p02796
u997641430
2,000
1,048,576
Wrong Answer
457
16,984
227
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
n = int(input()) X = [] for i in range(n): x, y = map(int, input().split()) X.append((x - y + 1, x + y)) X.sort() ter = 0 cnt = 0 for left, right in X: if ter < left: ter = right cnt += 1 print(cnt)
s562868787
Accepted
407
18,252
248
n = int(input()) X = [] for i in range(n): x, y = map(int, input().split()) X.append((x - y, x + y)) X.sort(key=lambda x: x[1]) ter = -10**10 cnt = 0 for left, right in X: if ter <= left: ter = right cnt += 1 print(cnt)
s664396099
p03471
u289288647
2,000
262,144
Wrong Answer
2,206
9,104
422
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.
import sys N, Y = map(int, input().split()) num = [min(N, Y//10000), min(N, Y//5000), min(N, Y//1000)] for i in reversed(range(0, num[0]+1)): for j in reversed(range(0, N-i+1)): if 10000*i + 5000*j > Y: continue for k in reversed(range(0, N-i-j+1)): if 10000*i + 5000*j + 1000*k == Y: print('%d %d %d' % (i, j, k)) sys.exit() print('-1 -1 -1')
s571822796
Accepted
724
8,948
388
import sys N, Y = map(int, input().split()) num = min(N, Y//10000) if 10000*N < Y: print('-1 -1 -1') sys.exit() for i in reversed(range(0, num+1)): for j in reversed(range(0, N-i+1)): if 10000*i + 5000*j > Y: continue if 10000*i + 5000*j + 1000*(N-i-j) == Y: print('%d %d %d' % (i, j, N-i-j)) sys.exit() print('-1 -1 -1')
s501855452
p03852
u629350026
2,000
262,144
Wrong Answer
18
2,940
66
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
c=str(input()) if c in "aiueo": print("YES") else: print("NO")
s072505949
Accepted
17
2,940
75
c=str(input()) if c in "aiueo": print("vowel") else: print("consonant")
s787220098
p02612
u163971674
2,000
1,048,576
Wrong Answer
25
9,140
28
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)
s635734765
Accepted
27
9,152
70
n=int(input()) a=n%1000 if a==0: print(0) else: print(1000-n%1000)
s736863778
p03380
u672475305
2,000
262,144
Wrong Answer
2,104
14,180
291
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
from math import factorial n = int(input()) lst = list(map(int,input().split())) lst.sort() num = lst[-1] ans = 0 for i in range(n): x = factorial(num) / factorial(lst[i]) / factorial(num-lst[i]) if (x > ans): ans = x else: print(lst[i-1],num) exit()
s572075496
Accepted
120
14,428
152
n = int(input()) A = list(map(int,input().split())) A.sort() y = max(A) x = A[0] for a in A: if abs(y/2-a) < abs(y/2 - x): x = a print(y, x)
s133836884
p04029
u879693268
2,000
262,144
Wrong Answer
17
2,940
36
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=int(input()) print(int(a*(a-1)/2))
s895126292
Accepted
17
2,940
36
a=int(input()) print(int(a*(a+1)/2))
s551040688
p03557
u368780724
2,000
262,144
Wrong Answer
1,725
23,328
758
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
N = int(input()) A = list(map(int, input().split())) #A = [int(x) for x in input().split()] B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() A = [-float('inf')] + A + [float('inf')] B.sort() C.sort() C = [-float('inf')] + C + [float('inf')] total = 0 for i in range(N): low = 0 high = N + 1 while high - low > 1: mid1 = (low + high) // 2 if A[mid1] < B[i]: low = mid1 else: high = mid1 mid1 = low low = 0 high = N + 1 while high - low > 1: mid2 = (low + high) // 2 if C[mid2] <= B[i]: low = mid2 else: high = mid2 mid2 = high print(mid1, mid2) total += mid1 * (N + 1 - mid2) print(total)
s574556658
Accepted
1,545
23,328
736
N = int(input()) A = list(map(int, input().split())) #A = [int(x) for x in input().split()] B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() A = [-float('inf')] + A + [float('inf')] B.sort() C.sort() C = [-float('inf')] + C + [float('inf')] total = 0 for i in range(N): low = 0 high = N + 1 while high - low > 1: mid1 = (low + high) // 2 if A[mid1] < B[i]: low = mid1 else: high = mid1 mid1 = low low = 0 high = N + 1 while high - low > 1: mid2 = (low + high) // 2 if C[mid2] <= B[i]: low = mid2 else: high = mid2 mid2 = high total += mid1 * (N + 1 - mid2) print(total)
s534600417
p03380
u507611905
2,000
262,144
Wrong Answer
88
14,052
423
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
n = int(input()) a = [int(i) for i in input().split()] a.sort() if n == 2: print(str(a[1])+" "+str(a[0])) else: maximum = a[-1] a.pop() half = maximum/2 a.append(half) a.sort() position = a.index(half) large = a[position+1] small = a[position-1] print(position) print(large) print(small) if large - (half) < (half) - small: print(str(maximum)+" "+str(large)) else: print(str(maximum)+" "+str(small))
s763521742
Accepted
91
14,052
568
n = int(input()) a = [int(i) for i in input().split()] a.sort() if n == 2: print(str(a[1])+" "+str(a[0])) else: maximum = a[-1] a.pop() half = maximum/2 a.append(half) a.sort() position = a.index(half) if position+1 >= len(a): print(str(maximum)+" "+str(int(a[position-1]))) exit() else: large = int(a[position+1]) if position-1 <= 0: print(str(maximum)+" "+str(int(a[position+1]))) exit() else: small = int(a[position-1]) if large - (half) < (half) - small: print(str(maximum)+" "+str(large)) else: print(str(maximum)+" "+str(small))
s359442820
p03760
u366886346
2,000
262,144
Wrong Answer
17
2,940
136
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
o=input() e=input() ans="" for i in range(len(e)): ans+=o[i//2] ans+=e[i//2] if len(o)!=len(e): ans+=o[len(o)-1] print(ans)
s255342086
Accepted
17
2,940
130
o=input() e=input() ans="" for i in range(len(e)): ans+=o[i] ans+=e[i] if len(o)!=len(e): ans+=o[len(o)-1] print(ans)
s502229592
p03860
u440129511
2,000
262,144
Wrong Answer
17
2,940
65
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s= list(map(str,input().split())) print('A' + ''+ s[0] + '' +'C')
s607506939
Accepted
17
2,940
43
a,s,c=input().split() print(a[0]+s[0]+c[0])
s521386973
p03170
u060938295
2,000
1,048,576
Wrong Answer
1,702
14,652
508
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.
# -*- coding: utf-8 -*- """ Created on Sat Apr 25 18:20:35 2020 """ import sys import numpy as np sys.setrecursionlimit(10 ** 9) #def input(): # return sys.stdin.readline()[:-1] mod = 10**9+7 #N = int(input()) N, K = map(int,input().split()) A = np.array(list(map(int,input().split()))) dp = np.arange(K + A[-1]+1) >= 0 for i in range(K, -1, -1): if np.all(dp[A+i]): dp[i] = False # print(i, dp[i],A+i,dp[A+i]) #print(dp) if dp[0]: ans = 'Frist' else: ans = 'Second' print(ans)
s100019338
Accepted
572
4,632
543
# -*- coding: utf-8 -*- """ Created on Sat Apr 25 18:20:35 2020 """ import sys #import numpy as np sys.setrecursionlimit(10 ** 9) #def input(): # return sys.stdin.readline()[:-1] mod = 10**9+7 #N = int(input()) N, K = map(int,input().split()) A = list(map(int,input().split())) dp = [i <= K for i in range(K + A[-1]+1)] for i in range(K, -1, -1): for a in A: if dp[a+i]: dp[i] = False break # print(i, dp[i],A+i,dp[A+i]) #print(dp) if dp[0]: ans = 'Second' else: ans = 'First' print(ans)
s729228075
p03150
u672781822
2,000
1,048,576
Wrong Answer
17
3,064
426
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
s = input() if s.startswith('k') and s.startswith('eyence'): print('YES') elif s.startswith('ke') and s.startswith('yence'): print('YES') elif s.startswith('key') and s.startswith('ence'): print('YES') elif s.startswith('keye') and s.startswith('nce'): print('YES') elif s.startswith('keyen') and s.startswith('ce'): print('YES') elif s.startswith('keyenc') and s.startswith('e'): print('YES') else: print('NO')
s673282911
Accepted
18
3,060
415
s = input() if s.startswith('k') and s.endswith('eyence'): print('YES') elif s.startswith('ke') and s.endswith('yence'): print('YES') elif s.startswith('key') and s.endswith('ence'): print('YES') elif s.startswith('keye') and s.endswith('nce'): print('YES') elif s.startswith('keyen') and s.endswith('ce'): print('YES') elif s.startswith('keyenc') and s.endswith('e'): print('YES') else: print('NO')
s631175138
p00002
u545973195
1,000
131,072
Wrong Answer
20
7,496
50
Write a program which computes the digit number of sum of two integers a and b.
a=map(int,input().split()) print(len(str(sum(a))))
s438878505
Accepted
20
7,464
97
while True: try: a=input().split() except: break b=int(a[0])+int(a[1]) print(len(str(b)))