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
s056225528
p02400
u804558166
1,000
131,072
Wrong Answer
20
5,636
99
Write a program which calculates the area and circumference of a circle for given radius r.
from math import pi r= float(input()) area=r*r*pi cir =(r+r)* pi print(f'{(area):.6f}{(cir):.6f}')
s328321993
Accepted
20
5,644
100
from math import pi r= float(input()) area=r*r*pi cir =(r+r)* pi print(f'{(area):.6f} {(cir):.6f}')
s258188638
p03371
u677440371
2,000
262,144
Wrong Answer
17
3,064
380
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A, B, C, X, Y = map(int, input().split()) if A+B <= C*2: min_cost = A*X + B*Y else: if X <= Y: if B >= C*2: min_cost = C*2*X+C*2*(Y-X) else: min_cost = C*2*X+B*(Y-X) else: if A >= C*2: min_cost = C*2*Y+C*2*(X-Y) else: min_cost = C*2*Y+A*(Y-X) print(min_cost)
s847147861
Accepted
17
3,060
167
a,b,c,x,y = map(int, input().split()) ans1 = c * 2 * min(x,y) + a * (x-min(x,y)) + b * (y-min(x,y)) ans2 = a*x + b*y ans3 = c * 2 * max(x,y) print(min(ans1,ans2,ans3))
s827986439
p02659
u221766194
2,000
1,048,576
Wrong Answer
23
9,036
52
Compute A \times B, truncate its fractional part, and print the result as an integer.
A,B = map(float,input().split()) print(round(A * B))
s267806292
Accepted
23
9,096
105
import math A,B = map(float,input().split()) A = int(A) B = int(B * 1000) print(math.floor((A*B)//1000))
s016471710
p03672
u163320134
2,000
262,144
Wrong Answer
18
3,064
225
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
s=input() l=len(s) ans=0 for i in range(2,l,2): tmp=s[:-i] if tmp[:int((l-i)/2)]==tmp[int((l-i)/2):]: ans=l-i break print(tmp) print(tmp[:int((l-i)/2)]) print(tmp[int((l-i)/2):]) print(ans)
s196342807
Accepted
17
3,060
150
s=input() l=len(s) ans=0 for i in range(2,l,2): tmp=s[:-i] if tmp[:int((l-i)/2)]==tmp[int((l-i)/2):]: ans=l-i break print(ans)
s957710930
p03637
u525529288
2,000
262,144
Wrong Answer
69
15,020
496
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
# import numpy as np import math N = int(input()) a = list(map(int, input().split())) two_count = 0 four_count = 0 for i in a: if i >= 4 and i % 4 == 0: four_count += 1 elif i >= 2 and i % 2 == 0: two_count += 1 check = len(a) - two_count if two_count > 0: ans = "YES" if math.ceil(check/2) <= four_count else "NO" else: if check == 2: ans = "YES" if 1 <= four_count else "NO" else: ans = "YES" if check - 2 <= four_count else "NO" print(ans)
s230382111
Accepted
69
15,020
619
# import numpy as np import math N = int(input()) a = list(map(int, input().split())) two_count = 0 four_count = 0 for i in a: if i >= 4 and i % 4 == 0: four_count += 1 elif i >= 2 and i % 2 == 0: two_count += 1 if two_count <= 1: if len(a) == 2: print("Yes" if four_count >= 1 else "No") else: print("Yes" if four_count >= len(a)//2 else "No") else: check = len(a) - two_count if check == 0: print("Yes") elif check <= 2: print("Yes" if four_count >= 1 else "No") else: print("Yes" if four_count >= math.ceil(check/2) else "No")
s748795318
p02388
u936478090
1,000
131,072
Wrong Answer
20
7,616
28
Write a program which calculates the cube of a given integer x.
x = int(input()) print(x^3)
s948610815
Accepted
20
7,620
34
x = input() x = int(x) print(x**3)
s990054384
p03485
u306142032
2,000
262,144
Wrong Answer
17
2,940
54
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = map(int, input().split()) print((a+b)//2 + 1)
s685135732
Accepted
17
2,940
72
import math a, b = map(int, input().split()) print(math.ceil((a+b)/2))
s084108561
p03671
u085883871
2,000
262,144
Wrong Answer
18
3,068
74
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
(a, b, c) = map(int, input().split()) ans = a+b+c - min(a,b,c) print(ans)
s091193691
Accepted
17
2,940
74
(a, b, c) = map(int, input().split()) ans = a+b+c - max(a,b,c) print(ans)
s291222451
p00105
u503263570
1,000
131,072
Wrong Answer
20
7,484
176
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers. You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once. The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
import sys a={} for i in sys.stdin: b,c=i.split() a.setdefault(b, []).append(c) if c=='18':break for a,b in sorted(a.items(), key=lambda x: x[0]): print(a) print(*b)
s168774459
Accepted
30
7,640
175
import sys a={} for i in sys.stdin: b,c=i.split() a.setdefault(b, []).append(c) for a,b in sorted(a.items(), key=lambda x: x[0]): print(a) print(*sorted(map(int,b)))
s897027311
p04044
u552738814
2,000
262,144
Wrong Answer
30
9,068
153
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
n,l = map(int,input().split()) list = [] for i in range(n): word = input() list.append(word) list_connect = "".join(list) print(list_connect)
s505892267
Accepted
24
8,828
147
n,l = map(int,input().split()) word_list = [] for i in range(n): word_list.append(input()) answer = ''.join(sorted(word_list)) print(answer)
s748997480
p03338
u726439578
2,000
1,048,576
Wrong Answer
19
3,064
262
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
n=int(input()) S=input() m=0 for i in range(1,n): x=S[:i] y=S[i:] x1=list(x) x2=set(x1) y1=list(y) y2=set(y1) y1=list(y2) for i in x2: m=max(y1.count(i),m) x="" y="" x1=[] x2=[] y1=[] y2=[] print(m)
s541577434
Accepted
18
3,064
258
n=int(input()) S=input() count1=0 m=0 for i in range(1,n): x=S[:i] y=S[i:] x1=list(x) x2=set(x1) for i in x2: if y.count(i)>=1: count1+=1 m=max(count1,m) count1=0 x="" y="" x1=[] x2=[] print(m)
s259907239
p03659
u987164499
2,000
262,144
Wrong Answer
174
24,176
259
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
from sys import stdin from itertools import accumulate n = int(stdin.readline().rstrip()) li = list(map(int,stdin.readline().rstrip().split())) lin = list(accumulate(li)) su = sum(li) mi = 10**10 for i in range(n): mi = min(mi,abs(su-li[i]*2)) print(mi)
s851575753
Accepted
181
24,796
236
n = int(input()) li = list(map(int,input().split())) from itertools import accumulate lin = list(accumulate(li)) mi = 10**18 S = sum(li) for i in range(n-1): ara = lin[i] sunu = S-ara mi = min(mi,abs(ara-sunu)) print(mi)
s609073927
p03469
u766407523
2,000
262,144
Wrong Answer
17
2,940
31
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
S = input() print("2018"+S[:4])
s008370717
Accepted
18
2,940
31
S = input() print("2018"+S[4:])
s713732321
p03609
u595952233
2,000
262,144
Wrong Answer
29
9,088
51
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
x, t = map(int, input().split()) print(min(x-t, 0))
s732159146
Accepted
29
8,944
51
x, t = map(int, input().split()) print(max(x-t, 0))
s563638564
p02255
u327546577
1,000
131,072
Wrong Answer
20
5,604
226
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
N = int(input()) L = [int(x) for x in input().split()] for i in range(1, N): v = L[i] j = i - 1 while j >= 0 and L[j] > v: L[j + 1] = L[j] j -= 1 L[j + 1] = v print(' '.join(map(str, L)))
s134117565
Accepted
20
5,604
255
N = int(input()) L = [int(x) for x in input().split()] print(' '.join(map(str, L))) for i in range(1, N): v = L[i] j = i - 1 while j >= 0 and L[j] > v: L[j + 1] = L[j] j -= 1 L[j + 1] = v print(' '.join(map(str, L)))
s411339835
p03943
u996284376
2,000
262,144
Wrong Answer
17
2,940
129
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 = list(map(int, input().split())) a.sort(key=int, reverse=True) if a[0] == a[1] + a[2]: print("YES") else: print("NO")
s036416462
Accepted
18
2,940
129
a = list(map(int, input().split())) a.sort(key=int, reverse=True) if a[0] == a[1] + a[2]: print("Yes") else: print("No")
s938082482
p02612
u956318161
2,000
1,048,576
Wrong Answer
26
9,044
42
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()) otsuri=N%1000 print(otsuri)
s021421924
Accepted
30
9,028
64
N=int(input()) k=N%1000 if k==0: t=0 else: t=1000-k print(t)
s952813690
p02697
u327466606
2,000
1,048,576
Wrong Answer
91
9,276
295
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
N,M = map(int,input().split()) # # (0,M),(1,M+2), ... (M//2, 2M) # (M//2+1, M+1), ... half = M+1 cnt = 0 i = 0 j = half while j < N and cnt < M: print(i+1, j+1) i += 1 j += 2 cnt += 1 j = half+1 while j < N and cnt < M: print(i+1, j+1) i += 1 j += 2 cnt += 1
s832808351
Accepted
84
9,280
230
N,M = map(int,input().split()) cnt = 0 i = 0 j = M while i+1 < j and cnt < M: print(i+1, j) i += 1 j -= 1 cnt += 1 i = M j = 2*M+1 while i+1 < j and cnt < M: print(i+1, j) i += 1 j -= 1 cnt += 1
s580827448
p03385
u432805419
2,000
262,144
Wrong Answer
17
2,940
70
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
a = input() if sorted(a) == "abc": print("Yes") else: print("No")
s893385439
Accepted
18
2,940
108
a = input() b = sorted(a) if b[0] == "a" and b[1] == "b" and b[2] == "c": print("Yes") else: print("No")
s739671184
p03720
u187205913
2,000
262,144
Wrong Answer
17
2,940
146
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n,m = map(int,input().split()) l = [] for _ in range(m): a,b = map(int,input().split()) l.append(a) for i in range(1,n+1): print(l.count(i))
s852350793
Accepted
17
3,060
160
n,m = map(int,input().split()) l = [] for _ in range(m): a,b = map(int,input().split()) l.append(a) l.append(b) for i in range(1,n+1): print(l.count(i))
s806842952
p02612
u521649945
2,000
1,048,576
Wrong Answer
29
9,156
118
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.
in_value = int(input()) while(1): in_value %= 1000 if in_value < 1000: print(in_value) break
s226561076
Accepted
29
9,092
182
in_value = int(input()) while(1): in_value %= 1000 if in_value == 0: break elif in_value < 1000: in_value = 1000 - in_value break print(in_value)
s294823410
p03401
u734876600
2,000
262,144
Wrong Answer
185
20,480
263
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
n = int(input()) A = [0] a = list(map(int, input().split())) for a_ in a: A.append(a_) s = 0 A.append(0) print(A) for i in range(n+1): s += abs(A[i+1]-A[i]) for i in range(1, n+1): print(s + abs(A[i+1]-A[i-1]) - (abs(A[i+1]-A[i]) + abs(A[i]-A[i-1])))
s117708751
Accepted
178
20,420
254
n = int(input()) A = [0] a = list(map(int, input().split())) for a_ in a: A.append(a_) s = 0 A.append(0) for i in range(n+1): s += abs(A[i+1]-A[i]) for i in range(1, n+1): print(s + abs(A[i+1]-A[i-1]) - (abs(A[i+1]-A[i]) + abs(A[i]-A[i-1])))
s597792065
p03131
u480138356
2,000
1,048,576
Wrong Answer
17
2,940
169
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
K, A, B = map(int, input().split()) if B - A <= 2: print(K+1) else: m = max(0, (K-A+1)//2) print(m, B-A) ans = m * (B-A) + K - m * 2 + 1 print(ans)
s243872412
Accepted
17
2,940
171
K, A, B = map(int, input().split()) if B - A <= 2: print(K+1) else: m = max(0, (K-A+1)//2) # print(m, B-A) ans = m * (B-A) + K - m * 2 + 1 print(ans)
s230181429
p03861
u275710783
2,000
262,144
Wrong Answer
17
2,940
56
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a, b, x = map(int, input().split()) print(int((b-a)//x))
s794705104
Accepted
17
2,940
66
a, b, x = map(int, input().split()) print((b // x) - ((a-1) // x))
s420794450
p03860
u268516119
2,000
262,144
Wrong Answer
17
2,940
25
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
print("A"+input()[0]+"C")
s981209525
Accepted
17
3,064
42
print("A"+list(input().split())[1][0]+"C")
s664551610
p03160
u283601347
2,000
1,048,576
Wrong Answer
55
20,456
60
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
n=int(input()) arr=list(map(int,input().split())) print(arr)
s649447789
Accepted
126
20,704
283
n=int(input()) arr=list(map(int,input().split())) if n < 2: print(0) vis = [0] * n vis[0] = 0 vis[1] = abs(arr[0]-arr[1]) for i in range(2, n): step_1 = abs(arr[i]-arr[i-1]) + vis[i-1] step_2 = abs(arr[i]-arr[i-2]) + vis[i-2] vis[i] = min(step_1, step_2) print(vis[-1])
s140851621
p03377
u461636820
2,000
262,144
Wrong Answer
19
3,060
159
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.
# -*- coding: utf-8 -*- def main(): A, B, X = map(int, input().split()) print('Yes' if A < X < A + B else 'NO') if __name__ == '__main__': main()
s024541773
Accepted
18
2,940
136
def main(): A, B, X = map(int, input().split()) print('YES' if A <= X <= A + B else 'NO') if __name__ == '__main__': main()
s432688862
p02663
u349765885
2,000
1,048,576
Wrong Answer
25
9,148
95
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
a,b,c,d,e=map(int,input().split()) time=(a-c)*60+b-d ans=time-e print(ans)
s991721139
Accepted
25
9,160
95
a,b,c,d,e=map(int,input().split()) time=(c-a)*60+d-b ans=time-e print(ans)
s413308003
p03565
u807772568
2,000
262,144
Wrong Answer
18
3,064
353
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
s = list(input()) t = list(input()) l = [] for i in range(len(s)-len(t) - 1): f = False for j in range(len(t)): if s[i+j] != '?' and s[i+j] != t[j]: f = False break if f: a = s[:i] + t + s[i+len(t):] l.append(a.replace('?','a')) if len(l)>0: print(min(l)) else: print('UNRESTORABLE')
s431833057
Accepted
18
3,060
341
s = input() t = input() l = [] for i in range(len(s)-len(t) + 1): f = True for j in range(len(t)): if s[i+j] != '?' and s[i+j] != t[j]: f = False break if f: a = s[:i] + t + s[i+len(t):] l.append(a.replace('?','a')) if len(l)>0: print(min(l)) else: print('UNRESTORABLE')
s517441875
p03534
u813098295
2,000
262,144
Wrong Answer
18
3,188
146
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 = input() a = s.count("a") b = s.count("b") c = s.count("c") print ("YES" if (max (a, b, c) - 1) * 2 < sum([a, b ,c]) - max(a, b, c) else "NO")
s540581672
Accepted
18
3,188
124
s = input() a = s.count("a") b = s.count("b") c = s.count("c") print ("YES" if max(a, b, c) - min(a, b, c) <= 1 else "NO")
s437358574
p03436
u094191970
2,000
262,144
Wrong Answer
30
3,316
626
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
from collections import deque h,w=map(int,input().split()) s=[list(input()) for i in range(h)] cnt=0 for i in s: cnt+=i.count('.') print(cnt) sy,sx=0,0 gy,gx=h-1,w-1 dist=[[-1]*w for i in range(h)] dist[sy][sx]=0 que=deque() que.append((sy,sx)) while que: y,x=que.popleft() if y==gy and x==gx: print(dist[y][x]) print(cnt-(dist[y][x]+1)) exit() for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]: ny=y+dy nx=x+dx if 0<=ny<=h-1 and 0<=nx<=w-1 and s[ny][nx]=='.' and dist[ny][nx]==-1: que.append((ny,nx)) dist[ny][nx]=dist[y][x]+1 print(-1)
s678556511
Accepted
28
3,316
588
from collections import deque h,w=map(int,input().split()) s=[list(input()) for i in range(h)] cnt=0 for i in s: cnt+=i.count('.') sy,sx=0,0 gy,gx=h-1,w-1 dist=[[-1]*w for i in range(h)] dist[sy][sx]=0 que=deque() que.append((sy,sx)) while que: y,x=que.popleft() if y==gy and x==gx: print(cnt-(dist[y][x]+1)) exit() for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]: ny=y+dy nx=x+dx if 0<=ny<=h-1 and 0<=nx<=w-1 and s[ny][nx]=='.' and dist[ny][nx]==-1: que.append((ny,nx)) dist[ny][nx]=dist[y][x]+1 print(-1)
s360637590
p03854
u679154596
2,000
262,144
Wrong Answer
275
15,772
692
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`.
import sys sys.setrecursionlimit(1000000) S_list = list(input()) def f(S_list): if S_list == []: print("Yes") exit() elif "".join(S_list[0:11]) == "dreameraser": del S_list[0:11] # print(S_list) f(S_list) elif "".join(S_list[0:10]) == "dreamerase": del S_list[0:10] # print(S_list) f(S_list) elif "".join(S_list[0:7]) == "dreamer": del S_list[0:7] # print(S_list) f(S_list) elif "".join(S_list[0:6]) == "eraser": del S_list[0:6] # print(S_list) f(S_list) elif "".join(S_list[0:5]) == "dream" or "".join(S_list[0:5]) == "erase": del S_list[0:5] # print(S_list) f(S_list) else: print("No") exit() f(S_list)
s687521138
Accepted
274
15,772
692
import sys sys.setrecursionlimit(1000000) S_list = list(input()) def f(S_list): if S_list == []: print("YES") exit() elif "".join(S_list[0:11]) == "dreameraser": del S_list[0:11] # print(S_list) f(S_list) elif "".join(S_list[0:10]) == "dreamerase": del S_list[0:10] # print(S_list) f(S_list) elif "".join(S_list[0:7]) == "dreamer": del S_list[0:7] # print(S_list) f(S_list) elif "".join(S_list[0:6]) == "eraser": del S_list[0:6] # print(S_list) f(S_list) elif "".join(S_list[0:5]) == "dream" or "".join(S_list[0:5]) == "erase": del S_list[0:5] # print(S_list) f(S_list) else: print("NO") exit() f(S_list)
s475031445
p04029
u052499405
2,000
262,144
Wrong Answer
17
2,940
48
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) ans = n + (n+1) // 2 print(ans)
s699151087
Accepted
17
2,940
48
n = int(input()) ans = n * (n+1) // 2 print(ans)
s267837532
p03564
u408620326
2,000
262,144
Wrong Answer
17
3,064
88
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
N,K=int(input()),int(input()) res=1 for _ in range(K): res=min(res*2,res+K) print(res)
s089388300
Accepted
17
2,940
88
N,K=int(input()),int(input()) res=1 for _ in range(N): res=min(res*2,res+K) print(res)
s382000568
p02396
u447009770
1,000
131,072
Wrong Answer
150
7,576
90
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
n = 1 while True: x = int(input()) if x == 0: break print('case ',n, ': ', x, sep='')
s785290793
Accepted
100
8,368
157
### 17.07.2017 n = [] while (True): x = int(input()) if x == 0: break n.append(int(x)) a = 0 for i in n: print('Case ',a+1, ': ', n[a], sep='') a += 1
s676633402
p03162
u738898077
2,000
1,048,576
Wrong Answer
675
33,612
558
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
import sys n = int(input()) abc_list = [] for i in range(n): abc_list.append(list(map(int,input().split()))) pre_suma,pre_sumb,pre_sumc = abc_list[0][0],abc_list[0][1],abc_list[0][2] if n == 1: print(max(pre_suma,pre_sumb,pre_sumc)) sys.exit() for i in range(1,n): a,b,c = abc_list[i][0],abc_list[i][1],abc_list[i][2] suma = a + max(pre_sumb,pre_sumc) sumb = b + max(pre_suma,pre_sumc) sumc = c + max(pre_suma,pre_sumb) pre_suma,pre_sumb,pre_sumc = suma,sumb,sumc print(suma,sumb,sumc) print(max(suma,sumb,sumc))
s451190336
Accepted
557
3,064
281
n = int(input()) ans = [0,0,0] temp = [0,0,0] for i in range(n): a = list(map(int,input().split())) temp[0] = max(ans[1],ans[2])+a[0] temp[1] = max(ans[0],ans[2])+a[1] temp[2] = max(ans[0],ans[1])+a[2] for i in range(3): ans[i] = temp[i] print(max(ans))
s909108620
p03351
u332331919
2,000
1,048,576
Wrong Answer
23
9,136
406
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) d_ab = int(b - a) d_bc = int(c - b) d_ca = int(c - a) if (1 <= a & a <= 100) & (1 <= b & b <= 100) & (1 <= c & c <= 100) : if 1 <= d_ca & d_ca <= d & d <= 100: print('Yes') elif 1 <= d_ab & d_ab <= d & d_ab <= 100 & 1 <= d_bc & d >= d_bc & d_bc <= 100: print('Yes') elif a == b & b == c: print('Yes') else: print('No')
s928614220
Accepted
26
9,156
439
a, b, c, d = map(int, input().split()) d_ab = b - a d_bc = c - b d_ac = c - a if d_ab <0: d_ab = a - b if d_bc <0: d_bc = b - c if d_ac <0: d_ac = a - c if (1 <= a & a <= 100) & (1 <= b & b <= 100) & (1 <= c & c <= 100) & (1 <= d & d <= 100): if 0 <= d_ac & d_ac <= d: print('Yes') elif (0 <= d_ab & d_ab <= d) & (0 <= d_bc & d_bc <= d): print('Yes') else: print('No') else: print('No')
s242966715
p02393
u675844759
1,000
131,072
Wrong Answer
20
7,588
67
Write a program which reads three integers, and prints them in ascending order.
a = [int(i) for i in "3 8 1".split()] a.sort() " ".join(map(str,a))
s862571232
Accepted
20
7,656
68
a = [int(i) for i in input().split()] a.sort() print(a[0],a[1],a[2])
s381435406
p03854
u101680358
2,000
262,144
Wrong Answer
33
3,188
310
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()[::-1] T = ['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]] size = 0 while size < len(S): if S[size:size+5] == T[0] or S[size:size+5] == T[2]: size += 5 elif S[size:size+6] == T[3]: size += 6 elif S[size:size+7] == T[1]: size += 7 else : print('No') exit() print('Yes')
s135129322
Accepted
33
3,188
309
S = input()[::-1] T = ['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]] size = 0 while size < len(S): if S[size:size+5] == T[0] or S[size:size+5] == T[2]: size += 5 elif S[size:size+6] == T[3]: size += 6 elif S[size:size+7] == T[1]: size += 7 else : print('NO') exit() print('YES')
s785420982
p03385
u676059589
2,000
262,144
Wrong Answer
17
3,060
130
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
import sys s=input() l=[0,0,0] for i in s: l[ord(i)-97]+=1 for i in l: if(i!=0): print("No") sys.exit() print("Yes")
s335930707
Accepted
17
2,940
134
import sys s = [0,0,0] t = input() for i in t: s[ord(i)-97]+=1 for i in s: if(i!=1): print('No') sys.exit() print('Yes')
s991048851
p03814
u244836567
2,000
262,144
Wrong Answer
26
9,204
140
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`.
a=input() for i in range(len(a)): if a[i]=="A": b=i break for i in range(len(a)): if a[len(a)-i-1]: c=i break print(c-b)
s941024711
Accepted
42
9,224
146
a=input() for i in range(len(a)): if a[i]=="A": b=i break for k in range(len(a)): if a[-k-1]=="Z": c=k break print(len(a)-c-b)
s111036377
p03140
u754022296
2,000
1,048,576
Wrong Answer
17
3,064
244
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
n = int(input()) a, b, c = input(), input(), input() ax, bx, cx = 0, 0, 0 for i in range(n): if a[i] != b[i]: ax += 1 bx += 1 if b[i] != c[i]: bx += 1 cx += 1 if c[i] != a[i]: cx += 1 ax += 1 print(min(ax, bx, cx))
s777006612
Accepted
17
3,064
255
n = int(input()) a, b, c = input(), input(), input() ans = 0 for i in range(n): if not a[i]==b[i]==c[i]: if (a[i]==b[i] and b[i]!=c[i]) or (b[i]==c[i] and c[i]!=a[i]) or (c[i]==a[i] and a[i]!=b[i]): ans += 1 else: ans += 2 print(ans)
s107888614
p03379
u586639900
2,000
262,144
Wrong Answer
174
30,788
208
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
N = int(input()) X = list(map(int, input().split())) X.sort() center = len(X) // 2 med_l = X[center - 1] med_r = X[center] for n in range(N): if n <= center - 1: print(med_r) else: print(med_l)
s756190239
Accepted
173
28,888
429
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N = int(readline()) X = list(map(int, readline().split())) X_sorted = sorted(X) small, large = X_sorted[(N-1)//2], X_sorted[(N+1)//2] for x in X: if x <= small: print(large) else: print(small)
s361882004
p03487
u140251125
2,000
262,144
Wrong Answer
2,104
15,388
207
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
import math N = input() a = list(map(int, input().split())) a_unique = list(set(a)) d = 0 for ai in a_unique: ni = a.count(ai) if ni < ai: d += ni else: d += ai - ni print(d)
s827401852
Accepted
95
17,908
504
import math N = input() a = list(map(int, input().split())) def f7(seq): seen = set() seen_add = seen.add return [ x for x in seq if x not in seen and not seen_add(x)] d = 0 a_unique = {} for i in range(0,len(a)): if a[i] in a_unique: a_unique[a[i]] += 1 else: a_unique[a[i]] = 1 for ai in a_unique.keys(): if a_unique[ai] >= ai: d += a_unique[ai] - ai else: d += a_unique[ai] print(d)
s111960530
p03386
u667084803
2,000
262,144
Wrong Answer
18
3,060
168
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()) if B - A >2*K: for i in range(K): print(A+i) for i in range(K): print(B-K+i) else: for i in range(A,B+1): print(i)
s613796840
Accepted
17
3,060
174
A, B, K = map(int, input().split()) if B - A +1 >2*K: for i in range(K): print(A+i) for i in range(K): print(B-K+1+i) else: for i in range(A,B+1): print(i)
s410604076
p03573
u769411997
2,000
262,144
Wrong Answer
17
2,940
106
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
a, b, c = map(int, input().split()) if a == b: print(c) elif b == c: print(a) else: print(c)
s673647751
Accepted
17
2,940
106
a, b, c = map(int, input().split()) if a == b: print(c) elif b == c: print(a) else: print(b)
s461901715
p03729
u275212209
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[-1]==B[0])and(B[-1]==C[0])) else "No")
s064902407
Accepted
17
2,940
84
A, B, C=input().split(" ") print("YES" if ((A[-1]==B[0])and(B[-1]==C[0])) else "NO")
s315225039
p02842
u633320358
2,000
1,048,576
Wrong Answer
17
2,940
96
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
n=input() n=int(n) x1=n/1.08 x2=n//1.08 # print(x1,x2) if x1==x2: print(x1) else: print(':(')
s722042523
Accepted
18
3,064
192
n=input() n=int(n) import math x1=n/1.08 a=math.floor(math.floor(x1)*1.08) b=math.floor(math.ceil(x1)*1.08) if n==a: print(math.floor(x1)) elif n==b: print(math.ceil(x1)) else: print(':(')
s691894936
p00990
u269391636
1,000
262,144
Wrong Answer
20
5,660
1,052
A大学ではIDの入力ミスが多発していた。 そこで、A大学は入力ミス防止のため新しいIDを発行することにした。 新しいIDには入力ミス防止のためにIDが正しいかどうかチェックする方法がある。 ・全ての桁の数字の総和を求める。 ・ただし、右端の桁を1番目として、偶数番目の桁の数字を2倍にする。 ・2倍することによって数字が10以上になった時、1の位の数字と10の位の数字を加算した数字をその桁の数字とする。 ・総和が10で割り切れれば正しいID、そうでなければ間違いとする。 例として、53579というIDをチェックする。 全ての桁の数字の総和を求めるので、 5 + 3 + 5 + 7 + 9 ただし、偶数番目の桁の数字を2倍にするので、 5 + _6_ \+ 5 + _14_ \+ 9 2倍することによって数字が10以上になった時、1の位の数字と10の位の数字を加算した数字をその桁の数字とするので、 5 + 6 + 5 + _(1 + 4)_ \+ 9 以上より、総和は30となる。30は10で割り切れるので、53579は正しいIDである。 B君はA大学の大学生であり、新しいIDを発行してもらったが、IDの一部の桁を忘れてしまった。 しかし、忘れてしまった部分にどんな数字が入るか、いくつか候補を絞ることに成功した。 あなたの仕事は、B君のIDの正しい組み合わせが何通りあるかを求めることである。
import itertools n = int(input()) id = input()[::-1] count = 0 a = [] odd, even = 0 , 0 tmp = 0 for i in range(1,n+1): if id[i-1] == "*": if i % 2: odd += 1 else: even += 1 continue if i % 2: x = int(id[i-1]) if x >= 5: tmp += (int(id[i-1]) * 2 - 9) continue tmp += (int(id[i-1]) * 2 - 9) tmp += (int(id[i-1])) m = int(input()) data = list(map(int, input().split())) def sum2(ls): ans = 0 for k in ls: if k >= 5: ans += (k * 2 - 9) else: ans += (k * 2) return ans odd_list = list(map(lambda x: (sum(x) % 10),list(itertools.product(data, repeat=odd)))) even_list = list(map(lambda x: ((sum2(x)) % 10),list(itertools.product(data, repeat=even)))) odd_mod = [odd_list.count(i) for i in range(10)] even_mod = [even_list.count(i) for i in range(10)] for i in range(10): for j in range(10): if ((i + j + tmp) % 10) == 0: count += odd_mod[i] * even_mod[j] print(count)
s300442969
Accepted
430
64,708
1,027
import itertools n = int(input()) id = input()[::-1] count = 0 a = [] odd, even = 0 , 0 tmp = 0 for i in range(1,n+1): if id[i-1] == "*": if i % 2: odd += 1 else: even += 1 elif i % 2 == 0: x = int(id[i-1]) if x >= 5: tmp += (x * 2 - 9) else: tmp += (x * 2) else: tmp += (int(id[i-1])) m = int(input()) data = list(map(int, input().split())) def sum2(ls): ans = 0 for k in ls: if k >= 5: ans += (k * 2 - 9) else: ans += (k * 2) return ans odd_list = list(map(lambda x: (sum(x) % 10),list(itertools.product(data, repeat=odd)))) even_list = list(map(lambda x: ((sum2(x)) % 10),list(itertools.product(data, repeat=even)))) odd_mod = [odd_list.count(i) for i in range(10)] even_mod = [even_list.count(i) for i in range(10)] for i in range(10): for j in range(10): if ((i + j + tmp) % 10) == 0: count += odd_mod[i] * even_mod[j] print(count)
s550026196
p03448
u665224938
2,000
262,144
Wrong Answer
54
3,060
253
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 a in range(A): for b in range(B): for c in range(C): s = a * 500 + b * 100 + c * 50 if s == X: count += 1 print(count)
s266389248
Accepted
53
3,060
291
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for a in range(A+1): for b in range(B+1): for c in range(C+1): s = a * 500 + b * 100 + c * 50 # print(a, b, c, s) if s == X: count += 1 print(count)
s314547171
p02612
u814663076
2,000
1,048,576
Wrong Answer
27
9,168
203
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 def rs(): return sys.stdin.readline().rstrip() def ri(): return int(rs()) def rs_(): return [_ for _ in rs().split()] def ri_(): return [int(_) for _ in rs().split()] N = ri() print(N % 1000)
s243205051
Accepted
26
9,168
233
import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(rs()) def rs_(): return [_ for _ in rs().split()] def ri_(): return [int(_) for _ in rs().split()] N = ri() print(1000 - N % 1000 if N % 1000 > 0 else 0)
s873173300
p03434
u799479335
2,000
262,144
Wrong Answer
154
12,508
215
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.
import numpy as np N = int(input()) a_inputs = input().split() a = np.zeros(N) for i in range(N): a[i] = int(a_inputs[i]) a = np.sort(a)[::-1] alice = a[0::2].sum() bob = a[1::2].sum() print(alice - bob)
s444891754
Accepted
379
18,732
220
import numpy as np N = int(input()) a_inputs = input().split() a = np.zeros(N) for i in range(N): a[i] = int(a_inputs[i]) a = np.sort(a)[::-1] alice = a[0::2].sum() bob = a[1::2].sum() print(int(alice - bob))
s152720206
p03597
u934740772
2,000
262,144
Wrong Answer
18
2,940
85
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
N = int(input()) A = int(input()) S = N * N ANS = N - S ANS = abs(ANS) print (ANS)
s147452401
Accepted
17
2,940
97
N = int(input()) A = int(input()) S = N * N ANS = A - S ANS = abs(ANS) print (ANS)
s258689500
p03759
u310855433
2,000
262,144
Wrong Answer
19
2,940
71
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a, b, c = map(int,input().split()) print("Yes" if b-a == c-b else "No")
s837252752
Accepted
17
2,940
71
a, b, c = map(int,input().split()) print("YES" if b-a == c-b else "NO")
s622491224
p04029
u873715358
2,000
262,144
Wrong Answer
17
2,940
73
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?
child = int(input()) sum = 0 for i in range(child): sum += i print(sum)
s249790762
Accepted
18
2,940
75
child = int(input()) sum = 0 for i in range(child+1): sum += i print(sum)
s172092178
p03140
u561231954
2,000
1,048,576
Wrong Answer
23
3,316
257
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
n=int(input()) a=input() b=input() c=input() ans=0 for j in range(n): d=a[j] e=b[j] f=c[j] if d==e and d!=f: ans+=1 elif d==f and d!=e: ans+=1 elif e==f and e!=d: ans+=1 elif d!=e and e!=f and f!=d: ans+=2
s293626871
Accepted
17
3,064
285
n=int(input()) a=input() b=input() c=input() ans=0 for j in range(n): d=a[j] e=b[j] f=c[j] if d==e and d!=f: ans+=1 elif d==f and d!=e: ans+=1 elif e==f and e!=d: ans+=1 elif d!=e and e!=f and f!=d: ans+=2 print(ans)
s981758252
p03110
u584317622
2,000
1,048,576
Wrong Answer
17
2,940
147
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()) c = 0 for i in range(N): a = list(input().split()) if a[1] == 'BTC': c += float(a[0])*38000 else: c += float(a[0]) print(c)
s083736783
Accepted
17
2,940
150
N = int(input()) c = 0 for i in range(N): a = list(input().split()) if a[1] == 'BTC': c += float(a[0])*380000.0 else: c += float(a[0]) print(c)
s025961132
p03501
u118211443
2,000
262,144
Wrong Answer
21
2,940
62
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=map(int,input().split()) print("B" if N+A>B else "N+A" )
s209988534
Accepted
18
2,940
58
N,A,B=map(int,input().split()) print(B if N*A>B else N*A )
s599270480
p03546
u162660367
2,000
262,144
Wrong Answer
38
4,336
653
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
H,W=map(int,input().split()) C=[] A=[] from queue import Queue def djcstra(frm,to,D): dist=D[frm] Q=sorted(range(len(D)) , key=lambda x:-dist[x]) Q.pop(-1) while len(Q): u=Q.pop(-1) if u==to:break for i,d in enumerate(D[u]): if dist[i] >dist[u]+d: dist[i]=dist[u]+d Q=sorted(sorted(Q , key=lambda x:-dist[x])) return dist[to] for i in range(10): C.append(list(map(int,input().split()))) for i in range(H): A.append(list(map(int,input().split()))) cst=[float('inf')]*10 for i in range(10): cst[i]=djcstra(i,1,C) sum(sum(cst[i] for i in AA if i >= 0) for AA in A)
s095918708
Accepted
29
3,316
353
H,W=map(int,input().split()) C=[] A=[] for i in range(10): C.append(list(map(int,input().split()))) for i in range(H): A.append(list(map(int,input().split()))) # WF for i in range(10): for j in range(10): for k in range(10): C[j][k]=min(C[j][k], C[j][i]+C[i][k]) print(sum(sum(C[i][1] for i in AA if i >= 0) for AA in A))
s749151631
p03338
u116670634
2,000
1,048,576
Wrong Answer
18
3,064
264
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
def types(st1, st2): ret = 0 for i in range(26): j = chr(i + 97) if j in st1 and j in st2: ret += 1 return ret n = int(input()) s = input() ans = 0 for i in range(n-1): ans = max(ans, types(s[:i], s[i+1:])) print(ans)
s746673413
Accepted
18
3,060
262
def types(st1, st2): ret = 0 for i in range(26): j = chr(i + 97) if j in st1 and j in st2: ret += 1 return ret n = int(input()) s = input() ans = 0 for i in range(n-1): ans = max(ans, types(s[:i], s[i:])) print(ans)
s653978895
p03862
u480847874
2,000
262,144
Wrong Answer
64
14,284
467
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
def m(): n, x = map(int, input().split()) a = list(map(int, input().split())) ans = 0 for i in range(1, n-1, 2): if a[i+1] > a[i-1]: if a[i+1] + a[i] < x: continue ans += (a[i+1] + a[i]) -x else: if a[i-1] + a[i] < x: continue ans += (a[i-1] + a[i]) -x if a[-1] + a[-2] < x: return ans ans += (a[-1] + a[-2]) -x return ans print(m())
s233617547
Accepted
86
14,052
384
def m(): n, x = map(int, input().split()) a = list(map(int, input().split())) b = a.copy() ans = 0 for i in range(n): if b[i] > x: b[i] = x for j in range(1, n): if b[j-1] + b[j] > x: b[j] -= (b[j-1] + b[j]) - x else: pass for k in range(n): ans += a[k] - b[k] return ans print(m())
s213563406
p02396
u805716376
1,000
131,072
Wrong Answer
130
5,616
86
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
for i in range(10000): n = int(input()) if n: print(f'Case {i}: {n}')
s413387578
Accepted
140
5,616
88
for i in range(1,10001): n = int(input()) if n: print(f'Case {i}: {n}')
s816195707
p03543
u947327691
2,000
262,144
Wrong Answer
18
2,940
130
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
n=input() cnt=0 for i in range(1,len(n)): if n[i]==n[i-1]: cnt+=1 if cnt >=3: print("Yes") else: print("No")
s081453081
Accepted
17
3,060
112
n=input() if (n[0]==n[1] and n[1]==n[2]) or (n[1]==n[2] and n[2]==n[3]): print("Yes") else: print("No")
s623594280
p02613
u067694718
2,000
1,048,576
Wrong Answer
147
16,620
236
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.
from collections import Counter n = int(input()) a = [input() for i in range(n)] b = Counter(a) b.setdefault("AC", 0) b.setdefault("WA", 0) b.setdefault("TLE", 0) b.setdefault("RE", 0) for i in b.keys(): print(i + " x " + str(b[i]))
s599957728
Accepted
148
16,620
326
from collections import Counter n = int(input()) a = [input() for i in range(n)] b = Counter(a) b.setdefault("AC", 0) b.setdefault("WA", 0) b.setdefault("TLE", 0) b.setdefault("RE", 0) print("AC" + " x " + str(b["AC"])) print("WA" + " x " + str(b["WA"])) print("TLE" + " x " + str(b["TLE"])) print("RE" + " x " + str(b["RE"]))
s322745906
p03377
u058592821
2,000
262,144
Wrong Answer
17
2,940
87
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 = (i for i in input().split()) if x <= b: print('Yes') else: print('No')
s733457228
Accepted
17
2,940
102
a, b, x = (int(i) for i in input().split()) if x >= a and x-a <= b: print('YES') else: print('NO')
s083021785
p03645
u970197315
2,000
262,144
Wrong Answer
977
38,320
606
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
# ABC068 C - Cat Snuke and a Voyage ni = lambda: int(input()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) n,m = nm() G = [[] for _ in range(n)] for i in range(m): a,b = map(int,input().split()) G[a-1].append(b-1) G[b-1].append(a-1) # print(G) for g in G: island_1toi = False island_iton = False for gg in g: if gg == 1: island_1toi = True if gg == n-1: island_iton = True if island_1toi == True and island_iton == True: print('POSSIBLE') exit() print('IMPOSSIBLE')
s595351908
Accepted
968
38,320
425
n,m=map(int,input().split()) G=[[] for i in range(n)] for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 G[a].append(b) G[b].append(a) for g in G: island_1=False island_n=False for gg in g: if gg==0: island_1=True if gg==n-1: island_n=True if island_1==True and island_n==True: print('POSSIBLE') exit() print('IMPOSSIBLE')
s075445951
p02399
u725841747
1,000
131,072
Wrong Answer
20
7,648
95
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
i=list(map(int,input().split(" "))) print("{0} {1} {2}".format(i[0]//i[1],i[0]%i[1],i[0]/i[1]))
s948649636
Accepted
30
7,648
114
i=list(map(int,input().split(" "))) print("{0} {1} {2:0.5f}".format(i[0]//i[1],i[0]%i[1],float(i[0])/float(i[1])))
s375152295
p03592
u163703551
2,000
262,144
Wrong Answer
25
3,572
649
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.
import sys import socket hostname = socket.gethostname() if hostname == 'F451C': sys.stdin = open('b1.in') def read_int_list(): return list(map(int, input().split())) def read_str_list(): return input().split() def read_int(): return int(input()) def read_str(): return input() def main(): n, m, k = read_int_list() if n <= m: for i in range(n + 1): if k == (n * n - i * n) + (i * (m - n)): print('Yes') if n > m: for i in range(m + 1): if k == (m * m - i * m) + (i * (n - m)): print('Yes') else: print('No') main()
s738711137
Accepted
193
3,696
536
import sys import socket hostname = socket.gethostname() if hostname == 'F451C': sys.stdin = open('b1.in') def read_int_list(): return list(map(int, input().split())) def read_str_list(): return input().split() def read_int(): return int(input()) def read_str(): return input() def main(): n, m, k = read_int_list() for i in range(m + 1): for j in range(n + 1): if k == (m - i) * j + (n - j) * i: print('Yes') return print('No') main()
s483829211
p03671
u294385082
2,000
262,144
Wrong Answer
17
2,940
69
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
a = list(sorted(list(map(int,input().split())))) print(a[-1] + a[-2])
s273087888
Accepted
17
2,940
69
a = list(sorted(list(map(int,input().split())))) print(a[0] + a[-2])
s889552233
p03557
u103902792
2,000
262,144
Wrong Answer
352
24,180
420
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()) AS = list(map(int,input().split())) AS.sort() BS = list(map(int,input().split())) BS.sort() CS = list(map(int,input().split())) CS.sort() import bisect AB = [0 for _ in range(n)] BC = [0 for _ in range(n)] a = 0 for b in range(n): AB[b] = bisect.bisect_left(AS,BS[b]) for b in range(n): BC[b] = n-bisect.bisect_left(CS,BS[b]) ans = 0 for i in range(n): ans += AB[b] * BC[b] print(ans)
s826418345
Accepted
381
23,248
279
n = int(input()) AS = list(map(int,input().split())) AS.sort() BS = list(map(int,input().split())) CS = list(map(int,input().split())) CS.sort() import bisect ans = 0 for b in range(n): ans += bisect.bisect_left(AS,BS[b])*(n-bisect.bisect_right(CS,BS[b])) print(ans)
s393624648
p03860
u716660050
2,000
262,144
Wrong Answer
17
2,940
42
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.
l=input().split() print(l[0]+l[1][0]+l[2])
s176286709
Accepted
17
2,940
48
l=input().split() print(l[0][0]+l[1][0]+l[2][0])
s654702980
p03729
u371467115
2,000
262,144
Wrong Answer
18
2,940
106
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() if A[0]==(B[::-1])[0] and B[0]==(C[::-1])[0]: print("YES") else: print("NO")
s514923780
Accepted
18
2,940
107
A,B,C=input().split() if (A[::-1])[0]==B[0] and (B[::-1])[0]==C[0]: print("YES") else: print("NO")
s095315858
p03485
u565093947
2,000
262,144
Wrong Answer
17
2,940
47
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b=map(int,input().split()) print(-(-(a+b)/2))
s609627088
Accepted
17
2,940
48
a,b=map(int,input().split()) print(-(-(a+b)//2))
s015450154
p03998
u891847179
2,000
262,144
Wrong Answer
117
27,136
1,109
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.
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 strings = {} strings['a'] = input() strings['b'] = input() strings['c'] = input() cnts = {s: 0 for s in ['a', 'b', 'c']} next = 'a' while True: if cnts[next] < len(strings[next]) - 1: tmp = strings[next][cnts[next] + 1] cnts[next] += 1 next = tmp else: break print(next.upper())
s020764679
Accepted
30
9,144
451
A =list(str(input())) B =list(str(input())) C =list(str(input())) P=A for i in range(len(A)+len(B)+len(C)+3): if P[0] == 'a': P.pop(0) P=A if len(A) ==0: print('A') break elif P[0] =='b': P.pop(0) P=B if len(B) ==0: print('B') break elif P[0] =='c': P.pop(0) P=C if len(C) ==0: print('C') break
s132152492
p03861
u667024514
2,000
262,144
Wrong Answer
18
2,940
53
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,n = map(int,input().split()) print(a//n-(b-1)//n)
s730167316
Accepted
17
2,940
54
a,b,n = map(int,input().split()) print(b//n-(a-1)//n)
s772178351
p03963
u883048396
2,000
262,144
Wrong Answer
17
2,940
64
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls.
iN,iK = [int(_) for _ in input().split()] print(iN*(iK**(iN-1)))
s441986446
Accepted
17
2,940
69
iN,iK = [int(_) for _ in input().split()] print(iK*((iK-1)**(iN-1)))
s633902892
p02578
u135116520
2,000
1,048,576
Wrong Answer
122
32,008
123
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
N=int(input()) A=list(map(int,input().split())) s=0 for i in range(N-1): if A[i]>A[i+1]: s+=A[i]-A[i+1] print(s)
s807037066
Accepted
155
32,388
167
N=int(input()) A=list(map(int,input().split())) s=0 t=0 for i in range(N): if t>=A[i]: t=max(t,A[i]) s+=t-A[i] else: t=max(t,A[i]) s=s print(s)
s683887547
p02394
u903708019
1,000
131,072
Wrong Answer
30
5,592
206
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
W, H, x, y, r = list(map(int, input().split())) x_right = x + r x_left = x - r y_up = y + r y_down = y - r if x_right <= W & x_left >= 0 & y_up <= H & y_down >= 0: print("Yes") else: print("No")
s251173411
Accepted
20
5,596
212
W, H, x, y, r = list(map(int, input().split())) x_right = x + r x_left = x - r y_up = y + r y_down = y - r if x_right <= W and x_left >= 0 and y_up <= H and y_down >= 0: print("Yes") else: print("No")
s283589879
p04043
u752898745
2,000
262,144
Wrong Answer
17
2,940
147
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.
def irohachan(A,B,C): if (A == 5 or A ==7) and (B == 5 or B ==7) and (C == 5 or C ==7) and (A+B+C ==17): print("YES") else: print("NO")
s346043673
Accepted
17
3,060
218
def irohachan(A,B,C): if (A == 5 or A ==7) and (B == 5 or B ==7) and (C == 5 or C ==7) and (A+B+C ==17): print("YES") else: print("NO") A,B,C = list(map(int, input().split())) irohachan(A,B,C)
s261578170
p03836
u268554510
2,000
262,144
Wrong Answer
17
3,064
257
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx,sy,tx,ty = map(int,input().split()) diff_x = tx-sx diff_y = ty-sy ans = '' ans += 'U'*diff_y ans += 'R'*diff_x ans += 'L' ans += 'U'*(diff_y+1) ans += 'R'*(diff_x+1) ans += 'D' ans += 'R' ans += 'D'*(diff_y+1) ans += 'L'*(diff_x+1) ans += 'U' print(ans)
s994728688
Accepted
17
3,064
293
sx,sy,tx,ty = map(int,input().split()) diff_x = tx-sx diff_y = ty-sy ans = '' ans += 'U'*diff_y ans += 'R'*diff_x ans += 'D'*diff_y ans += 'L'*diff_x ans += 'L' ans += 'U'*(diff_y+1) ans += 'R'*(diff_x+1) ans += 'D' ans += 'R' ans += 'D'*(diff_y+1) ans += 'L'*(diff_x+1) ans += 'U' print(ans)
s438117846
p03544
u595952233
2,000
262,144
Time Limit Exceeded
2,292
3,368,908
86
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()) l = [2, 1] i = 0 while i < n: l.append(l[-1] + l[-2]) print(l[n-2])
s821664103
Accepted
28
9,092
92
n = int(input()) l = [2, 1] i = 0 while i < n: l.append(l[-1] + l[-2]) i+=1 print(l[n])
s215381162
p02694
u692054751
2,000
1,048,576
Wrong Answer
21
9,160
112
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()) cnt = 0 yokin = 100 while (X >= yokin): yokin = int(yokin * 1.01) cnt += 1 print(cnt)
s063249580
Accepted
23
9,160
111
X = int(input()) cnt = 0 yokin = 100 while (X > yokin): yokin = int(yokin * 1.01) cnt += 1 print(cnt)
s777676365
p02255
u576398884
1,000
131,072
Wrong Answer
30
7,692
308
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
def insertionSort(A, N): for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(" ".join(map(str,A))) return A n = int(input()) a = list(map(int, input().split())) insertionSort(a, n)
s287007089
Accepted
20
7,792
340
def pd(A): print(" ".join(map(str,A))) def insertionSort(A, N): pd(A) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v pd(A) return A n = int(input()) a = list(map(int, input().split())) insertionSort(a, n)
s424355806
p04011
u564060397
2,000
262,144
Wrong Answer
17
2,940
117
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
a=list(input()) b=set(a) for i in b: c=a.count(i) if c%2!=0: print("No") exit() print("Yes")
s817123135
Accepted
17
2,940
110
a=int(input()) b=int(input()) c=int(input()) d=int(input()) if a>b: print(b*c+d*(a-b)) else: print(a*c)
s988340993
p03759
u076764813
2,000
262,144
Wrong Answer
17
2,940
85
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c=map(int,input().split()) if b-a == c-b: print("Yes") else: print("No")
s192943891
Accepted
17
2,940
85
a,b,c=map(int,input().split()) if b-a == c-b: print("YES") else: print("NO")
s360197080
p03623
u251123951
2,000
262,144
Wrong Answer
17
2,940
78
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|.
a,b,c=map(int,input().split()) print("A") if abs(a-b)>abs(a-c) else print("B")
s022347443
Accepted
17
2,940
78
a,b,c=map(int,input().split()) print("A") if abs(a-b)<abs(a-c) else print("B")
s537335964
p03711
u414558682
2,000
262,144
Wrong Answer
17
3,060
486
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] c = [2] # print(a) # print(b) # print(c) x, y = map(int, input().split()) # print(a.index(x)) # print(b.index(x)) # print(c.index(x)) # print(a.index(y)) # print(b.index(y)) # print(c.index(y)) # print(x in a) # print(x in b) # print(x in c) # print(b in a) # print(b in b) # print(b in c) if x in a and b in a: print('Yes') elif x in b and b in b: print('Yes') elif x in c and b in c: print('Yes') else: print('No')
s119933127
Accepted
17
3,064
486
a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] c = [2] # print(a) # print(b) # print(c) x, y = map(int, input().split()) # print(a.index(x)) # print(b.index(x)) # print(c.index(x)) # print(a.index(y)) # print(b.index(y)) # print(c.index(y)) # print(x in a) # print(x in b) # print(x in c) # print(b in a) # print(b in b) # print(b in c) if x in a and y in a: print('Yes') elif x in b and y in b: print('Yes') elif x in c and y in c: print('Yes') else: print('No')
s146689644
p03679
u609061751
2,000
262,144
Wrong Answer
17
2,940
188
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.
import sys input = sys.stdin.readline X, A, B = [int(x) for x in input().split()] if (A - B) <= 0: print("delicious") elif (B - A) <= X: print("safe") else: print("dangerous")
s464249298
Accepted
17
3,060
188
import sys input = sys.stdin.readline X, A, B = [int(x) for x in input().split()] if (A - B) >= 0: print("delicious") elif (B - A) <= X: print("safe") else: print("dangerous")
s352974941
p03679
u588633699
2,000
262,144
Wrong Answer
18
2,940
123
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.
X, A, B = map(int, input().split()) if A>=B: print('delicious') elif B-A>=X: print('safe') else: print('dangerous')
s020713902
Accepted
17
2,940
123
X, A, B = map(int, input().split()) if A>=B: print('delicious') elif B-A<=X: print('safe') else: print('dangerous')
s890456207
p03944
u277802731
2,000
262,144
Wrong Answer
17
3,060
239
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
#47b w,h,n = map(int,input().split()) s = w*h for _ in range(n): x,y,a = map(int,input().split()) if a==1: s-=(w-x)*h elif a==2: s-=x*h elif a==3: s-=(h-y)*w else: s-=y*w print(max(0,s))
s753952630
Accepted
17
3,064
292
#47b w,h,n = map(int,input().split()) x,y=0,0 for _ in range(n): xi,yi,a = map(int,input().split()) if a==1: x = max(x,xi) elif a==2: w = min(xi,w) elif a==3: y = max(y,yi) else: h = min(h,yi) print(0 if x>=w or y>=h else (w-x)*(h-y))
s125092708
p02392
u874395007
1,000
131,072
Wrong Answer
20
5,584
104
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a, b, c = map(int, input().split()) if a < b and b < c: ans = 'YES' else: ans = 'NO' print(ans)
s987071768
Accepted
20
5,584
96
a, b, c = map(int, input().split()) if a < b and b < c: print('Yes') else: print('No')
s567283941
p03140
u740284863
2,000
1,048,576
Wrong Answer
17
3,064
275
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
int(input()) a = str(input()) b = str(input()) c = str(input()) def f(a,b,c): ans = 0 for i in range(len(a)): if a[i] != b[i]: ans += 1 if a[i] != c[i]: ans += 1 return ans ans = min(f(a,b,c),f(b,c,a),f(c,a,b)) print(ans)
s521724193
Accepted
17
3,064
297
int(input()) a = str(input()) b = str(input()) c = str(input()) def f(a,b,c): ans = 0 for i in range(len(a)): if a[i] != b[i]: ans += 1 if a[i] != c[i] and c[i] != b[i]: ans += 1 return ans ans = min(f(a,b,c),f(b,c,a),f(c,a,b)) print(ans)
s203981810
p03415
u636684559
2,000
262,144
Wrong Answer
17
2,940
62
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.
res='' for i in range(3): s=input() res+=s[i-1] print(res)
s693714973
Accepted
19
2,940
60
res='' for i in range(3): s=input() res+=s[i] print(res)
s941203972
p03719
u182047166
2,000
262,144
Wrong Answer
17
2,940
254
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
#N = int(input()) #A = [int(x) for x in input().split()] #a, b, c = map(int, input().split()) #name1 = str(input()) #alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5} a, b, c = map(int, input().split()) if a <= b <=c: print("Yes") else: print("No")
s422388025
Accepted
17
2,940
256
#N = int(input()) #A = [int(x) for x in input().split()] #a, b, c = map(int, input().split()) #name1 = str(input()) #alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5} a, b, c = map(int, input().split()) if a <= c <= b: print("Yes") else: print("No")
s385793827
p03493
u371350984
2,000
262,144
Wrong Answer
28
9,108
53
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 = list(map(int, input().split())) print(s.count(1))
s043453687
Accepted
24
8,860
25
print(input().count("1"))
s720532327
p03473
u189487046
2,000
262,144
Wrong Answer
17
2,940
44
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
s = input() print(s.replace("2017", "2018"))
s317398060
Accepted
17
2,940
32
s = int(input()) print(24-s+24)
s401838265
p03494
u545213416
2,000
262,144
Wrong Answer
21
3,060
215
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.
num = int(input()) listName = list(map(int, input().split())) counter = 0 while (len(listName) == num): listName = [i / 2 for i in listName if i%2 == 0] print(listName) counter += 1 print(counter - 1)
s991191187
Accepted
20
3,060
195
num = int(input()) listName = list(map(int, input().split())) counter = 0 while (len(listName) == num): listName = [i / 2 for i in listName if i%2 == 0] counter += 1 print(counter - 1)
s280675339
p00010
u546285759
1,000
131,072
Wrong Answer
30
7,652
417
Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface.
from math import sqrt for _ in range(int(input())): x1, y1, x2, y2, x3, y3= map(float, input().split()) a= sqrt((x3-x2)**2 + (y3-y2)**2) b= sqrt((x3-x1)**2 + (y3-y1)**2) c= sqrt((x2-x1)**2 + (y2-y1)**2) numerator, denominator= 2*b*c, b**2 + c**2 - a**2 cosA= denominator / numerator sinA= sqrt(1 - (cosA)**2) r= a / (2*sinA) px= (x2-x1) / 2 py= (y3-y1) / 2 print(px, py, r)
s516115277
Accepted
20
5,684
598
n = int(input()) for _ in range(n): x1, y1, x2, y2, x3, y3 = map(float, input().split()) a = pow((x3-x2) ** 2 + (y3-y2) ** 2, 0.5) b = pow((x3-x1) ** 2 + (y3-y1) ** 2, 0.5) c = pow((x1-x2) ** 2 + (y1-y2) ** 2, 0.5) cosA = (b**2 + c**2 - a**2) / (2*b*c) sinA = pow(1 - cosA**2, 0.5) R = a / sinA / 2 a, b, c = x1-x2, y1-y2, -(x1**2 + y1**2) + (x2**2 + y2**2) d, e, f = x2-x3, y2-y3, -(x2**2 + y2**2) + (x3**2 + y3**2) l = (c*e - b*f) / (e*a - b*d) m = (c*d - a*f) / (b*d - a*e) l, m = l*-0.5, m*-0.5 print("{:.3f} {:.3f} {:.3f}".format(l, m, R))
s569987276
p03696
u466331465
2,000
262,144
Wrong Answer
18
3,064
318
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
from itertools import groupby N = int(input()) S = input() ans = [] #S1 = groupby(S) a=0 a1=0 b=0 b1=0 cnt = 0 c=0 S1 = groupby(list(S)) for key,group in S1: group = list(group) if list(key)==['(']: a=len(group) a1+=a else: b=len(group) b1+=b a1-=b S = "("*b1+S S = S+")"*a1 print("".join(S))
s105857200
Accepted
18
3,064
344
from itertools import groupby N = int(input()) S = input() ans = [] #S1 = groupby(S) a=0 a1=0 b=0 b1=0 S1 = groupby(list(S)) for key,group in S1: group = list(group) if list(key)==['(']: a1+=len(group) else: if a1<=len(group): b1+=len(group)-a1 a1 = 0 else: a1 -=len(group) S = S+")"*a1 S = "("*b1+S print(S)
s414867676
p03478
u181012033
2,000
262,144
Wrong Answer
2,104
17,140
302
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 find_sum_digits(n): sum = 0 while (n>0): sum += (n % 10) n /= 10 print (n) return sum n,a,b = map(int,input().split(" ")) print(n) total = 0 for i in range(n + 1): print (i) ans = find_sum_digits(i) if a <= ans <= b: total += i print(total)
s711255920
Accepted
36
3,060
144
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 += i print(ans)