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
s660120482
p04043
u786020649
2,000
262,144
Wrong Answer
27
9,040
173
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.
import sys a,b,c=map(int,input().split()) l=[a,b,c,a,b] for x in range(3): if l[x]==l[x+1] and l[x]==5 and l[x]==7: print('YES') sys.exit() print('NO')
s357153384
Accepted
27
9,136
175
import sys a,b,c=map(int,input().split()) l=[a,b,c,a,b] for x in range(3): if l[x]==l[x+1] and l[x]==5 and l[x+2]==7: print('YES') sys.exit() print('NO')
s513243936
p03351
u497046426
2,000
1,048,576
Wrong Answer
18
3,060
132
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) if (abs(a-c) <= d) or (max(abs(a - b), abs(b-c)) < d): print('Yes') else: print('No')
s019673176
Accepted
18
2,940
133
a, b, c, d = map(int, input().split()) if (abs(a-c) <= d) or (max(abs(a - b), abs(b-c)) <= d): print('Yes') else: print('No')
s867448297
p03377
u931636178
2,000
262,144
Wrong Answer
17
2,940
86
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A,B,X = map(int,input().split()) if (A+B) >= X: print("Yes") else: print("No")
s716233363
Accepted
17
2,940
114
A,B,X = map(int,input().split()) if A > X: print("NO") elif (A+B) >= X: print("YES") else: print("NO")
s996419560
p03555
u813174766
2,000
262,144
Wrong Answer
17
2,940
60
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a=input() x='YES' if input()==reversed(a) else 'NO' print(x)
s229987705
Accepted
18
2,940
53
a=input()[::-1] print('YES' if input()==a else 'NO')
s139992532
p00036
u868716420
1,000
131,072
Wrong Answer
20
7,344
976
縦 8、横 8 のマスからなる図 1 のような平面があります。 □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ 図1 --- この平面上に、以下の A から G の図形のどれかが一つだけ置かれています。 | A --- ■| ■| | ---|---|---|--- ■| ■| | | | | | | | | B --- | ■| | ---|---|---|--- | ■| | | ■| | | ■| | | C --- ■| ■| ■| ■ ---|---|---|--- | | | | | | | | | | D --- | ■| | ---|---|---|--- ■| ■| | ■| | | | | | | E --- ■| ■| | ---|---|---|--- | ■| ■| | | | | | | | F --- ■| | | ---|---|---|--- ■| ■| | | ■| | | | | | G --- | ■| ■| ---|---|---|--- ■| ■| | | | | | | | たとえば、次の図 2 の例では E の図形が置かれています。 | □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| ■| ■| □| □| □| □| □ □| □| ■| ■| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ 図2 --- 平面の中で図形が占めているマスを 1、占めていないマスを 0 で表現した数字の列を読み込んで、置かれている図形の種類(A〜G)を出力するプログラムを作成してください。 ただし、ひとつの平面に置かれている図形は必ず1つで、複数の図形が置かれていることはありません。また、A〜G で表される図形以外のものが置かれていることはありません。
while True : try : switch = 0 for _ in range(9) : if switch == 0 : temp = input() if temp == '00000000' or temp == '' : pass else : onetwo, place = 0, 0 if '1111' in temp : print('C') switch = 1 else : onetwo, place = temp.count('1'), temp.index('1') temp = input() if onetwo == 1 : if temp.count('1') == 1 : print('B') elif temp.index('1') == place : print('F') else : print('D') elif onetwo == 2 : if temp.index('1') == place : print('A') elif temp.index('1') == place + 1 : print('E') else : print('G') switch = 1 else : input() except : break
s820400088
Accepted
30
7,336
766
while True : try : temp = input() if temp == '00000000' or temp == '' : pass else : if '1111' in temp : print('C') else : onetwo, place = temp.count('1'), temp.index('1') temp = input() if onetwo == 1 : if temp.count('1') == 1 : print('B') input() elif temp.index('1') == place : print('F') else : print('D') input() elif onetwo == 2 : if temp.index('1') == place : print('A') elif temp.index('1') == place + 1 : print('E') else : print('G') except : break
s375250397
p03852
u003501233
2,000
262,144
Wrong Answer
17
2,940
124
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()) b=["a","i","u","e","o"] for i in range(5): if c == b[i]: print("vowel") else: print("consonant")
s192301598
Accepted
17
2,940
80
c=str(input()) b="aiueo" if c in b: print("vowel") else: print("consonant")
s372076826
p03693
u713465512
2,000
262,144
Wrong Answer
17
2,940
85
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r,g,b = map(int, input().split()) if g*b%4==0: print("YES") else: print("NO")
s728957404
Accepted
17
2,940
90
r,g,b = map(int, input().split()) if (g*10+b)%4==0: print("YES") else: print("NO")
s288686199
p03455
u504256702
2,000
262,144
Wrong Answer
17
2,940
99
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
if any(list(map(lambda x: int(x) % 2 == 0, input().split()))): print("Odd") else: print("Even")
s539721854
Accepted
17
2,940
99
if any(list(map(lambda x: int(x) % 2 == 0, input().split()))): print("Even") else: print("Odd")
s207046967
p03228
u464555934
2,000
1,048,576
Wrong Answer
17
3,060
353
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
a = list(map(int,input().split())) A = a[0]; B = a[1]; K = a[2] for i in range(K): if i % 2 == 0: if A % 2 == 1: A -= 1 cokkie = A / 2 A -= cokkie B += cokkie else: if B % 2 == 1: B -= 1 cokkie = B / 2 B -= cokkie A += cokkie print(str(A) + " " + str(B))
s890001434
Accepted
17
3,064
363
a = list(map(int,input().split())) A = a[0]; B = a[1]; K = a[2] for i in range(K): if i % 2 == 0: if A % 2 == 1: A -= 1 cokkie = A / 2 A -= cokkie B += cokkie else: if B % 2 == 1: B -= 1 cokkie = B / 2 B -= cokkie A += cokkie print(str(int(A)) + " " + str(int(B)))
s649273756
p03351
u230717961
2,000
1,048,576
Wrong Answer
17
2,940
161
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()) ab = abs(a - b) bc = abs(b - c) ca = abs(c - a) if(ab < d and bc < d and ca < d): print("Yes") else: print("No")
s468888382
Accepted
17
2,940
155
a,b,c,d = map(int, input().split()) ab = abs(a - b) bc = abs(b - c) ca = abs(c - a) if(ab <= d and bc <= d or ca <=d): print("Yes") else: print("No")
s965212521
p03738
u499317876
2,000
262,144
Wrong Answer
17
3,064
319
You are given two positive integers A and B. Compare the magnitudes of these numbers.
a=input() b=input() A=len(a) B=len(b) if A<B: print("LESS") elif B<A: print("GREATER") else: for i in range(A): if int(a[i])<int(b[i]): print("LESS") elif int(b[i])<int(a[i]): print("GREATER") elif int(a[i])==int(b[i]) and i==A-1: print("EQUAL")
s541137265
Accepted
18
3,064
356
a=input() b=input() A=len(a) B=len(b) if A<B: print("LESS") elif B<A: print("GREATER") else: for i in range(A): if int(a[i])<int(b[i]): print("LESS") break elif int(b[i])<int(a[i]): print("GREATER") break elif int(a[i])==int(b[i]) and i==A-1: print("EQUAL")
s275950637
p03854
u116348130
2,000
262,144
Wrong Answer
19
3,188
180
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() sc = ["dreameraser", "dreamerase", "dreamer", "dream", "eracer", "erace"] for i in sc: s = s.replace(i, '') if len(s) == 0: print("YES") else: print("NO")
s538450921
Accepted
18
3,188
139
S = input() sc = ["eraser", "erase", "dreamer", "dream"] for i in sc: S = S.replace(i, "") if S: print("NO") else: print("YES")
s980192057
p03658
u188244611
2,000
262,144
Wrong Answer
17
2,940
136
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.
# ABC 67, B - snake toy n, k = [int(el) for el in input().split(' ')] L = sorted([int(l) for l in input().split(' ')]) print(L[-k:])
s429800485
Accepted
17
2,940
141
# ABC 67, B - snake toy n, k = [int(el) for el in input().split(' ')] L = sorted([int(l) for l in input().split(' ')]) print(sum(L[-k:]))
s554371269
p03385
u627530854
2,000
262,144
Wrong Answer
17
2,940
50
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
print("Yes" if sorted(input()) == "abc" else "No")
s326493643
Accepted
17
2,940
59
print("Yes" if "".join(sorted(input())) == "abc" else "No")
s371028885
p03469
u672316981
2,000
262,144
Wrong Answer
26
8,892
48
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 = str(input()) ans = '2018' + s[5:] print(ans)
s477692117
Accepted
24
8,940
48
s = str(input()) ans = '2018' + s[4:] print(ans)
s394743116
p02606
u759076129
2,000
1,048,576
Wrong Answer
32
9,152
103
How many multiples of d are there among the integers between L and R (inclusive)?
L, R, d = map(int, input().split()) c = 0 for i in range(L, R+1): if i % 3 == 0: c += 1 print(c)
s327331536
Accepted
34
9,148
104
L, R, d = map(int, input().split()) c = 0 for i in range(L, R+1): if i % d == 0: c += 1 print(c)
s542637422
p03493
u642682703
2,000
262,144
Wrong Answer
17
2,940
218
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.
evens = [6,4,10,4] itr = 0 flg = True while flg: evens = list(map(lambda x: (x/2), evens)) is_evens = list(map(lambda x: x.is_integer(), evens)) if not all(is_evens): flg = False break itr+=1 print(itr)
s816673493
Accepted
17
2,940
35
num = input() print(num.count('1'))
s748503660
p03359
u503111914
2,000
262,144
Wrong Answer
17
2,940
139
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()) c = 0 for i in range(1,a): for j in range(1,b): if i == j : c += 1 else: None print(c)
s602772880
Accepted
17
2,940
55
a,b = map(int,input().split()) print(a-1 if a>b else a)
s012587739
p03151
u767664985
2,000
1,048,576
Wrong Answer
104
18,292
279
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) ans, mana = 0, 0 for i in range(N): if A[i] >= B[i]: mana += A[i] - B[i] else: mana -= B[i] - A[i] ans += 1 if mana >= 0: print(ans) else: print(-1)
s112145629
Accepted
270
42,240
483
import numpy as np from bisect import bisect_right N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) diff = [0 for i in range(N)] need = 0 ans = 0 for i in range(N): diff[i] = A[i] - B[i] if diff[i] < 0: need += -diff[i] ans += 1 diff[i] = 0 diff = sorted(diff, reverse=True) cumsum = np.cumsum(diff) if need != 0: ans += bisect_right(cumsum, need)+1 if ans > N: ans = -1 print(ans)
s898699391
p04000
u419686324
3,000
262,144
Wrong Answer
1,670
151,176
540
We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column. Compute the following: * For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
h, w, n = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] sa = {} for a,b in ab: for i in range(3): aa = a + i if aa < 3 or h < aa: continue for j in range(3): bb = b + j if bb < 3 or w < bb: continue id = "%d,%d" % (aa, bb) sa[id] = sa.get(id, 0) + 1 s = {} for x in sa.values(): s[x] = s.setdefault(x, 0) + 1 print((w - 2) * (h - 2) - len(sa.keys())) for i in range(10): print(s.get(i, 0))
s439030455
Accepted
1,698
151,176
543
h, w, n = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] sa = {} for a,b in ab: for i in range(3): aa = a + i if aa < 3 or h < aa: continue for j in range(3): bb = b + j if bb < 3 or w < bb: continue id = "%d,%d" % (aa, bb) sa[id] = sa.get(id, 0) + 1 s = {} for x in sa.values(): s[x] = s.setdefault(x, 0) + 1 print((w - 2) * (h - 2) - len(sa.keys())) for i in range(1, 10): print(s.get(i, 0))
s932966662
p02972
u265506056
2,000
1,048,576
Wrong Answer
1,002
10,740
340
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
N=int(input()) A=[] B=[] for i in range(N): B.append(0) A=list(map(int,input().split())) for i in reversed(range(N)): a=i+1 b=N//a c=0 for j in range(b): d=a*(j+1) c=c+B[d-1] e=c%2 if e==A[i]: B[i]=0 else: B[i]=1 C=sum(B) if C==0: print(0) else: print(C) print(*B)
s485275607
Accepted
510
14,072
348
N=int(input()) a=list(map(int,input().split())) A=[0]*N B=[] for i in range(N//2,N): if a[i]==1: A[i]=1 B.append(i+1) for i in range(N//2)[::-1]: asum=0 x=i+1 for j in range(i,N,x): asum=asum+A[j] if asum%2!=a[i]: A[i]=1 B.append(i+1) count=sum(A) print(count) if count!=0: print(*B)
s721445451
p03854
u727551259
2,000
262,144
Wrong Answer
20
4,424
273
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 re s = input() ptn = re.compile(r'maerd|remaerd|sare|resare') tmp = s[::-1] while(True): res = re.match(ptn , tmp) if res is None: print(tmp) break tmp = tmp.replace(res.group(),'',1) print(tmp) if len(tmp) == 0: print('YES') else: print('NO')
s258399532
Accepted
108
3,444
246
import re s = input() ptn = re.compile(r'maerd|remaerd|resare|esare') tmp = s[::-1] while(True): res = re.match(ptn , tmp) if res is None: break tmp = tmp.replace(res.group(),'',1) if len(tmp) == 0: print('YES') else: print('NO')
s940968837
p03759
u368104473
2,000
262,144
Wrong Answer
17
2,940
88
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 == b-c: print('Yes') else: print('No')
s945269752
Accepted
17
2,940
94
a, b, c = map(int, input().split()) if b - a == c - b : print("YES") else: print("NO")
s683612697
p03549
u023229441
2,000
262,144
Time Limit Exceeded
2,206
11,136
994
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 sys import math import heapq mod=10**9+7 inf=float("inf") from math import sqrt from collections import deque from collections import Counter from collections import defaultdict from collections import OrderedDict from math import ceil input=lambda: sys.stdin.readline().strip() sys.setrecursionlimit(11451419) from decimal import Decimal from functools import lru_cache n,m=map(int,input().split()) A=100*(n-m)+1900*m p=pow(2,m) @lru_cache(maxsize=10**10) def per(n): if n==1: return 1/p return (1-sum([per(i) for i in range(1,n)]))*(1/p) ans=0 for i in range(1,10000): ans+= i*A*per(i) print(round(ans))
s970463165
Accepted
212
10,272
993
import sys import math import heapq mod=10**9+7 inf=float("inf") from math import sqrt from collections import deque from collections import Counter from collections import defaultdict from collections import OrderedDict from math import ceil input=lambda: sys.stdin.readline().strip() sys.setrecursionlimit(11451419) from decimal import Decimal from functools import lru_cache n,m=map(int,input().split()) A=100*(n-m)+1900*m p=pow(2,m) @lru_cache(maxsize=10**10) def per(n): if n==1: return 1/p return (1-sum([per(i) for i in range(1,n)]))*(1/p) ans=0 for i in range(1,2000): ans+= i*A*per(i) print(round(ans))
s170072080
p02384
u391228754
1,000
131,072
Time Limit Exceeded
40,000
7,752
1,601
Construct a dice from a given sequence of integers in the same way as
class Dice(object): def __init__(self, top, south, east, west, north, bottom): self.top = top self.south = south self.east = east self.west = west self.north = north self.bottom = bottom def get_top(self): return self.top def rotate(self, directions): for direction in directions: if direction == 'S': self.prev_top = self.top self.top = self.north self.north = self.bottom self.bottom = self.south self.south = self.prev_top elif direction == 'E': self.prev_top = self.top self.top = self.west self.west = self.bottom self.bottom = self.east self.east = self.prev_top elif direction == 'W': self.prev_top = self.top self.top = self.east self.east = self.bottom self.bottom = self.west self.west = self.prev_top elif direction == 'N': self.prev_top = self.top self.top = self.south self.south = self.bottom self.bottom = self.north self.north = self.prev_top dice = Dice(*map(int,input().split())) n = int(input()) for i in range(n): a, b = input().split() if dice.east == b or dice.west == b: dice.rotate("W") while a != dice.top: dice.rotate("N") while b != dice.south: dice.rotate("W") print(dice.east)
s740943421
Accepted
20
7,780
1,157
class Dice: def __init__(self, faces): self.faces = tuple(faces) def roll_north(self): self.faces = (self.faces[1], self.faces[5], self.faces[2], self.faces[3], self.faces[0], self.faces[4]) def roll_south(self): self.faces = (self.faces[4], self.faces[0], self.faces[2], self.faces[3], self.faces[5], self.faces[1]) def roll_west(self): self.faces = (self.faces[2], self.faces[1], self.faces[5], self.faces[0], self.faces[4], self.faces[3]) def roll_east(self): self.faces = (self.faces[3], self.faces[1], self.faces[0], self.faces[5], self.faces[4], self.faces[2]) def number(self, face_id): return self.faces[face_id - 1] dice = Dice(list(map(int, input().split()))) n = int(input()) for i in range(n): (face1, face2) = map(int, input().split()) if face2 == dice.number(3) or face2 == dice.number(4): dice.roll_west() while dice.number(2) != face2: dice.roll_north() while dice.number(1) != face1: dice.roll_west() print(dice.number(3))
s512560749
p03796
u223904637
2,000
262,144
Wrong Answer
54
2,940
97
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()) mod=1e9+7 ans=1 for i in range(1,n+1): ans*=i%mod ans=ans%mod print(ans)
s428992045
Accepted
55
2,940
99
n=int(input()) mod=1e9+7 ans=1 for i in range(1,n+1): ans*=i ans=ans%mod print(round(ans))
s418316011
p03610
u779508975
2,000
262,144
Wrong Answer
42
9,408
138
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s=input() odd_num=list() for i in range(len(s)): if i % 2 == 0: odd_num.append(s[i]) answer=" ".join(odd_num) print(answer)
s472993330
Accepted
41
9,272
140
s=input() odd_num=list() for i in range(len(s)): if i % 2 == 0: odd_num.append(s[i]) answer="".join(odd_num) print(answer)
s189533629
p03997
u564060397
2,000
262,144
Wrong Answer
18
2,940
62
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()) c=int(input()) print((a+b)*c/2)
s014561064
Accepted
17
2,940
63
a=int(input()) b=int(input()) c=int(input()) print((a+b)*c//2)
s253342494
p02646
u652104963
2,000
1,048,576
Wrong Answer
24
9,180
173
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a,v = map(int, input().split()) b,w = map(int, input().split()) t = int(input()) x = abs((b-a)/v) y = abs((w*x)/v) l = x + y if l > t: print('YES') else: print('NO')
s936701147
Accepted
23
9,168
146
a,v = map(int, input().split()) b,w = map(int, input().split()) t = int(input()) if v*t >= abs(b-a) + w*t: print('YES') else: print('NO')
s345920680
p02263
u766183517
1,000
131,072
Wrong Answer
20
5,532
36
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
line = input().split() print(line)
s780869374
Accepted
20
5,600
399
line = input().split() stack = [] ans = 0 for elem in line: if elem in ['+', '-', '*']: ele2 = int(stack.pop()) ele1 = int(stack.pop()) if elem == '+': tmp = ele1 + ele2 if elem == '-': tmp = ele1 - ele2 if elem == '*': tmp = ele1 * ele2 stack.append(tmp) else: stack.append(elem) print(stack[0])
s328686931
p03814
u084320347
2,000
262,144
Wrong Answer
18
3,816
150
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s = input() print(s[1:-1]) r_s = s[::-1] if r_s.index("Z")==0: print(len(s[s.index("A"):])) else: print(len(s[s.index("A"):-r_s.index("Z")]))
s575362552
Accepted
18
3,560
135
s = input() r_s = s[::-1] if r_s.index("Z")==0: print(len(s[s.index("A"):])) else: print(len(s[s.index("A"):-r_s.index("Z")]))
s871207239
p03338
u027622859
2,000
1,048,576
Wrong Answer
17
3,064
237
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 main(): N = int(input()) S = input() count = 0 max_ = 0 for i in range(N): x = set(S[:i]) y = set(S[:i]) max_ = max(len(x&y), max_) print(max_) if __name__=='__main__': main()
s588905998
Accepted
17
3,064
237
def main(): N = int(input()) S = input() count = 0 max_ = 0 for i in range(N): x = set(S[:i]) y = set(S[i:]) max_ = max(len(x&y), max_) print(max_) if __name__=='__main__': main()
s688282147
p03160
u387774811
2,000
1,048,576
Wrong Answer
2,111
127,180
552
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.
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline def cost(l,r): if (l,r) in memo: return memo[(l,r)] else: ans=float('inf') for j in range(l,r): if (l,j) in memo: a=memo[(l,j)] else: a=cost(l,j) if (j+1) in memo: b=memo[(j+1,r)] else: b=cost(j+1,r) ans=min(ans,a+b) memo[(l,r)]=ans+size[r+1]-size[l] return(ans+size[r+1]-size[l]) memo={} N=int(input()) size=[0]*(N+1) a = list(map(int,input().split())) for i in range(N): memo[(i,i)] = 0 size[i+1]=size[i]+a[i] print(cost(0,N-1))
s822812075
Accepted
138
13,928
204
N=int(input()) h=list(map(int,input().split())) ans=[0]*(N) ans[0]=0 ans[1]=abs(h[1]-h[0]) if N>2 : for i in range(2,N): ans[i]=min(ans[i-2]+abs(h[i]-h[i-2]),ans[i-1]+abs(h[i]-h[i-1])) print(ans[N-1])
s418018684
p02612
u920977317
2,000
1,048,576
Wrong Answer
33
9,152
150
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 main(): N=int(input()) mod=N%1000 if N==0: print("0") else: print(1000-N) if __name__=="__main__": main()
s017771919
Accepted
27
9,156
152
def main(): N=int(input()) mod=N%1000 if mod==0: print(0) else: print(1000-mod) if __name__=="__main__": main()
s065233473
p03377
u007550226
2,000
262,144
Wrong Answer
21
3,060
78
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A,B,X = map(int,input().split()) if A<= X <= A+B:print('Yes') else:print('No')
s020135695
Accepted
17
2,940
78
A,B,X = map(int,input().split()) if A<= X <= A+B:print('YES') else:print('NO')
s834793417
p03998
u363407238
2,000
262,144
Wrong Answer
17
3,060
196
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
a = 'abcb' b = 'aacb' c = 'bccc' d = { 'a': a, 'b': b, 'c': c } n = 'a' while (True): if d[n] == '': break nx = d[n][0] d[n] = d[n][1:] n = nx print(n.upper())
s700814027
Accepted
18
2,940
95
d = {x : list(input()) for x in "abc"} x = "a" while d[x]: x = d[x].pop(0) print(x.upper())
s495959372
p03567
u314902127
2,000
262,144
Wrong Answer
18
2,940
65
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
s = input() if s in "AC": print("Yes") else: print("No")
s466040393
Accepted
17
2,940
66
s = input() if "AC" in s : print("Yes") else: print("No")
s676728760
p03711
u811000506
2,000
262,144
Wrong Answer
17
3,060
216
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()) li1 = [1,3,5,7,8,10,12] li2 = [4,6,9,11] li3 = [2] if li1.count(x)==1 and li1.count(y)==1 or li2.count(x)==1 and li2.count(y)==1 or x==y and y==2: print("YES") else: print("NO")
s809772988
Accepted
18
3,064
217
x,y = map(int,input().split()) li1 = [1,3,5,7,8,10,12] li2 = [4,6,9,11] li3 = [2] if li1.count(x)==1 and li1.count(y)==1 or li2.count(x)==1 and li2.count(y)==1 or x==y and y==2: print("Yes") else: print("No")
s695118513
p02420
u957840591
1,000
131,072
Wrong Answer
30
7,520
377
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Str=[] H=[] h=[] while True: x=input() if x.isalpha(): if h!=[]: H.append(h) h=[] Str.append(x) elif x=='-': H.append(h) break else: h.append(int(x)) for i in range(len(Str)): a=Str[i] for j in range(len(H[i])): a=a[H[i][j]:]+a[:H[i][j]] Str[i]=a for str in Str: print(str)
s446196401
Accepted
20
7,624
358
Str=[] H=[] h=[] while True: x=input() if x=='-': break Str.append(x) m=int(input()) for i in range(m): x=int(input()) h.append(x) H.append(h) h=[] for i in range(len(Str)): a=Str[i] for j in range(len(H[i])): a=''.join([a[H[i][j]:],a[:H[i][j]]]) Str[i]=a for str in Str: print(str)
s200108620
p03379
u545368057
2,000
262,144
Wrong Answer
291
25,556
332
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()) Xs = list(map(int, input().split())) sXs = sorted(Xs) m1 = sXs[N//2] m2 = sXs[N//2 - 1] print(m1,m2) if m1 == m2: for i in range(N): print(m1) else: for x in Xs: if x <= m2: print(m1) else: print(m2)
s045833076
Accepted
311
25,228
334
N = int(input()) Xs = list(map(int, input().split())) sXs = sorted(Xs) m1 = sXs[N//2] m2 = sXs[N//2 - 1] # print(m1,m2) if m1 == m2: for i in range(N): print(m1) else: for x in Xs: if x <= m2: print(m1) else: print(m2)
s173747761
p02749
u291278680
2,000
1,048,576
Wrong Answer
1,472
198,844
1,635
We have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i. Takahashi loves the number 3. He is seeking a permutation p_1, p_2, \ldots , p_N of integers from 1 to N satisfying the following condition: * For every pair of vertices (i, j), if the distance between Vertex i and Vertex j is 3, the sum or product of p_i and p_j is a multiple of 3. Here the distance between Vertex i and Vertex j is the number of edges contained in the shortest path from Vertex i to Vertex j. Help Takahashi by finding a permutation that satisfies the condition.
import sys sys.setrecursionlimit(700000) def s_in(): return input() def n_in(): return int(input()) def l_in(): return list(map(int, input().split())) def print_l(l): print(' '.join(map(str, l))) class Interval(): def __init__(self, li): self.li = li self.n = len(li) self.sum_li = [li[0]] for i in range(1, self.n): self.sum_li.append(self.sum_li[i-1] + li[i]) def sum(self, a, b=None): if b is None: return self.sum(0, a) res = self.sum_li[min(self.n-1, b-1)] if a > 0: res -= self.sum_li[a-1] return res N = n_in() edges = [[] for _ in range(N)] for _ in range(N-1): a,b = l_in() edges[a-1].append(b-1) edges[b-1].append(a-1) S = [] F = [0]*N depth = [0]*N visited = set() def dfs(v, d): visited.add(v) F[v] = len(S) depth[v] = d S.append(v) for w in edges[v]: if w in visited: continue dfs(w, d+1) S.append(v) dfs(0, 0) res = [0 for _ in range(N)] from collections import deque q = deque([i for i in range(1,N+1) if i%3 == 0 ] + [i for i in range(1,N+1) if i%3 != 0 ]) if len(list(filter(lambda d: d%2 == 0, depth))) < N//2: for i, d in enumerate(depth): if d%2 == 0: res[i] = q.popleft() for i, d in enumerate(depth): if d%2 != 0: res[i] = q.popleft() else: for i, d in enumerate(depth): if d%2 != 0: res[i] = q.popleft() for i, d in enumerate(depth): if d%2 == 0: res[i] = q.popleft() print_l(res)
s866092871
Accepted
1,457
193,596
2,346
import sys sys.setrecursionlimit(700000) def s_in(): return input() def n_in(): return int(input()) def l_in(): return list(map(int, input().split())) def print_l(l): print(' '.join(map(str, l))) class Interval(): def __init__(self, li): self.li = li self.n = len(li) self.sum_li = [li[0]] for i in range(1, self.n): self.sum_li.append(self.sum_li[i-1] + li[i]) def sum(self, a, b=None): if b is None: return self.sum(0, a) res = self.sum_li[min(self.n-1, b-1)] if a > 0: res -= self.sum_li[a-1] return res N = n_in() edges = [[] for _ in range(N)] for _ in range(N-1): a,b = l_in() edges[a-1].append(b-1) edges[b-1].append(a-1) S = [] depth = [0]*N visited = set() def dfs(v, d): visited.add(v) depth[v] = d S.append(v) for w in edges[v]: if w in visited: continue dfs(w, d+1) S.append(v) root = 0 dfs(root, 0) res = [0 for _ in range(N)] from collections import deque q0 = deque(i for i in range(1,N+1) if i%3 == 0) q1 = deque(i for i in range(1,N+1) if i%3 == 1) q2 = deque(i for i in range(1,N+1) if i%3 == 2) even_depth = len(list(filter(lambda d: d%2 == 0, depth))) odd_depth = len(list(filter(lambda d: d%2 != 0, depth))) if even_depth > N//3 and odd_depth > N//3: for i, d in enumerate(depth): if d%2 == 0: if len(q1) > 0: res[i] = q1.popleft() else: res[i] = q0.popleft() else: if len(q2) > 0: res[i] = q2.popleft() else: res[i] = q0.popleft() elif even_depth <= N//3: for i, d in enumerate(depth): if d%2 == 0: res[i] = q0.popleft() else: if len(q1) > 0: res[i] = q1.popleft() elif len(q2) > 0: res[i] = q2.popleft() else: res[i] = q0.popleft() else: for i, d in enumerate(depth): if d%2 != 0: res[i] = q0.popleft() else: if len(q1) > 0: res[i] = q1.popleft() elif len(q2) > 0: res[i] = q2.popleft() else: res[i] = q0.popleft() print_l(res)
s811346928
p02601
u034194513
2,000
1,048,576
Wrong Answer
32
9,464
384
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
import random nums = input().split() print(nums) #A = nums[0] #B = nums[1] #C = nums[2] a = int(nums[0]) b = int(nums[1]) c = int(nums[2]) print(a) K = input() k = int(K) #print(type(a)) print(k) cnt = 0 #print(type(cnt)) while a >= b: cnt +=1 b *= 2 print(b) while b >= c: cnt += 1 c *= 2 print(c) #if cnt if cnt <= k: print("Yes") else: print("No")
s501388727
Accepted
33
9,484
471
import random nums = input().split() #print(nums) #A = nums[0] #B = nums[1] #C = nums[2] a = int(nums[0]) b = int(nums[1]) c = int(nums[2]) #print(a) K = input() k = int(K) #print(type(a)) #print(k) cnt = 0 #print(type(cnt)) while a >= b: cnt +=1 b *= 2 #print(b) while b >= c: cnt += 1 c *= 2 #print(c) #if cnt if cnt <= k: print("Yes") else: print("No") #for hoge in range(1,k +1): # print(hoge) #print(random.choice(nums)) #print(A)
s157287517
p03623
u094565093
2,000
262,144
Wrong Answer
17
2,940
98
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b=map(int,input().split()) if abs(x-a)>abs(x-b): print(abs(x-a)) else: print(abs(x-b))
s416906512
Accepted
17
2,940
88
x,a,b=map(int,input().split()) if abs(x-a)>abs(x-b): print('B') else: print('A')
s209920980
p03399
u777846995
2,000
262,144
Wrong Answer
17
2,940
140
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
number = 4 fare = [int(input()) for a in range(number)] fare_train = min(fare[0:1]) fare_bus = min(fare[2:3]) print(fare_train + fare_bus)
s924362239
Accepted
17
3,064
394
number = 4 fare = [int(input()) for a in range(number)] fare_added = [] fare_added.append(fare[0] + fare[2]) #A + C fare_added.append(fare[0] + fare[3]) #A + D fare_added.append(fare[1] + fare[2]) #B + C fare_added.append(fare[1] + fare[3]) #B + D for i, elem in enumerate(fare_added): if i == 0: fare_min = elem if fare_min > elem: fare_min = elem print(fare_min)
s230860439
p02865
u735912743
2,000
1,048,576
Wrong Answer
17
2,940
15
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
int(input())//2
s208960436
Accepted
17
2,940
26
print((int(input())-1)//2)
s941786315
p03067
u071211072
2,000
1,048,576
Wrong Answer
28
9,096
122
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
A,B,C = list(map(int,input().split(' '))) [A,B] = [max(A,B),min(A,B)] if C>=A and C<=B: print('Yes') else: print('No')
s165060162
Accepted
25
9,080
110
A,B,C = list(map(int,input().split(' '))) if C>min(A,B) and C<max(A,B): print('Yes') else: print('No')
s500470554
p03386
u619458041
2,000
262,144
Wrong Answer
18
3,060
296
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.
import sys def main(): input = sys.stdin.readline A, B, K = map(int, input().split()) i = 0 while i < K: a, b = A + i, B - i i += 1 if a == b: print(a) break elif a > b: break else: print(a) print(b) if __name__ == '__main__': main()
s351025132
Accepted
18
3,060
260
import sys def main(): input = sys.stdin.readline A, B, K = map(int, input().split()) ans = list(range(A, min(A+K, B))) + list(range(max(B-(K-1), A), B+1)) ans = sorted(list(set(ans))) for i in ans: print(i) if __name__ == '__main__': main()
s207780767
p03433
u864711178
2,000
262,144
Wrong Answer
17
2,940
75
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
#coding: utf-8 n = int(input()) a = int(input()) rest = n % 500 print(rest)
s558287263
Accepted
17
2,940
96
n = int(input()) a = int(input()) if a - (n % 500) >= 0: print("Yes") else: print("No")
s204094099
p03377
u941022948
2,000
262,144
Wrong Answer
18
3,060
109
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, c= map(int, input().split()) if a+b>c: print('No') elif a>c: print('No') else: print('Yes')
s275851867
Accepted
17
2,940
109
a, b, c= map(int, input().split()) if a+b<c: print('NO') elif a>c: print('NO') else: print('YES')
s962411834
p03469
u727787724
2,000
262,144
Wrong Answer
17
2,940
54
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().split('/') s[0]='2018' print(s[0]+s[1]+s[2])
s239758509
Accepted
18
2,940
63
s=input().split('/') s[0]='2018' print(s[0]+'/'+s[1]+'/'+s[2])
s383212962
p03998
u778720350
2,000
262,144
Wrong Answer
17
3,060
234
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
a = input() b = input() c = input() cards = {'a': a, 'b': b, 'c': c} turn = 'a' while True: if len(cards[turn]) == 0: print(turn) break draw = cards[turn][0] cards[turn] = cards[turn][1:] turn = draw
s711157376
Accepted
17
3,060
242
a = input() b = input() c = input() cards = {'a': a, 'b': b, 'c': c} turn = 'a' while True: if len(cards[turn]) == 0: print(turn.upper()) break draw = cards[turn][0] cards[turn] = cards[turn][1:] turn = draw
s835943992
p03377
u601082779
2,000
262,144
Wrong Answer
17
2,940
59
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,c=map(int,input().split());print("YNEOS"[a<=c<=a+b::2])
s408669111
Accepted
17
2,940
62
a,b,c=map(int,input().split());print("YNEOS"[a>c or c>a+b::2])
s389766777
p02646
u266113953
2,000
1,048,576
Wrong Answer
19
9,204
166
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
A,V = map(int, input().split()) B,W = map(int, input().split()) T = int(input()) if (V-W) != 0 and T >= (abs(A-B)/(V-W)) >= 0: print("Yes") else: print("No")
s070532315
Accepted
21
9,180
166
A,V = map(int, input().split()) B,W = map(int, input().split()) T = int(input()) if (V-W) != 0 and T >= (abs(A-B)/(V-W)) >= 0: print("YES") else: print("NO")
s786281263
p02389
u556014061
1,000
131,072
Wrong Answer
20
7,488
49
Write a program which calculates the area and perimeter of a given rectangle.
a, b = map(int, input().split()) print(a*2 + b*2)
s525742136
Accepted
20
7,528
54
a, b = map(int, input().split()) print(a*b, a*2 + b*2)
s113763537
p04030
u853900545
2,000
262,144
Wrong Answer
17
2,940
102
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
s = input() a = [] for _ in s: if _ == 'B': a = a[:-1] else: a += _ print(a)
s025737609
Accepted
17
2,940
102
s = input() a = '' for _ in s: if _ == 'B': a = a[:-1] else: a += _ print(a)
s978936135
p03680
u433380437
2,000
262,144
Wrong Answer
2,265
49,644
142
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=[0] for i in range(n): a.append(int(input())) s=1 cnt=0 while s !=2: s=a[s] cnt +=1 print(s) print(cnt)
s970199219
Accepted
171
12,760
174
n = int(input()) a=[0] for i in range(n): a.append(int(input())) s=1 cnt=0 while s !=2: s=a[s] cnt +=1 if cnt ==n: print(-1) exit() print(cnt)
s716572617
p03162
u494058663
2,000
1,048,576
Wrong Answer
570
36,132
425
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.
N = int(input()) A = [] B = [] C = [] for i in range(N): tmp_a,tmp_b,tmp_c = map(int,input().split()) A.append(tmp_a) B.append(tmp_b) C.append(tmp_c) dp = [[0 for j in range(3)] for i in range(N)] dp[0][0] = A[0] dp[0][1] = B[0] dp[0][2] = C[0] for i in range(1,N): dp[i][0] = max(dp[i-1][1],dp[i-1][2])+A[i] dp[i][1] = max(dp[i-1][0],dp[i-1][2])+B[i] dp[i][2] = max(dp[i-1][0],dp[i-1][1])+C[i]
s995269982
Accepted
569
36,208
473
N = int(input()) A = [] B = [] C = [] for i in range(N): tmp_a,tmp_b,tmp_c = map(int,input().split()) A.append(tmp_a) B.append(tmp_b) C.append(tmp_c) dp = [[0 for j in range(3)] for i in range(N)] dp[0][0] = A[0] dp[0][1] = B[0] dp[0][2] = C[0] for i in range(1,N): dp[i][0] = max(dp[i-1][1],dp[i-1][2])+A[i] dp[i][1] = max(dp[i-1][0],dp[i-1][2])+B[i] dp[i][2] = max(dp[i-1][0],dp[i-1][1])+C[i] print(max(dp[-1][0],dp[-1][1],dp[-1][2]))
s617682818
p02613
u127126063
2,000
1,048,576
Wrong Answer
151
9,204
277
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n=int(input()) ac=0 wa=0 tle=0 re=0 for i in range(n): c=input() if c=='AC': ac+=1 elif c=='WA': wa+=1 elif c=='TLE': tle+=1 else: re+=1 print("AC X {}".format(ac)) print("WA X {}".format(wa)) print("TLE X {}".format(tle)) print("RE X {}".format(re))
s714326638
Accepted
151
9,232
277
n=int(input()) ac=0 wa=0 tle=0 re=0 for i in range(n): c=input() if c=='AC': ac+=1 elif c=='WA': wa+=1 elif c=='TLE': tle+=1 else: re+=1 print("AC x {}".format(ac)) print("WA x {}".format(wa)) print("TLE x {}".format(tle)) print("RE x {}".format(re))
s342631378
p03778
u117193815
2,000
262,144
Wrong Answer
17
2,940
83
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
w,a,b= map(int ,input().split()) if b>=w+a: print((w+a)-b) else: print(w-b)
s355518291
Accepted
17
3,060
133
w,a,b= map(int ,input().split()) if w>=a and b<=w+a: print(0) elif a+w<=b: print(b-(a+w)) elif b+w<=a: print(a-(b+w))
s918909630
p03564
u403331159
2,000
262,144
Wrong Answer
17
2,940
101
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=int(input()) k=int(input()) d=1 for i in range(n): if k>2*d: d=d*2 else: d=d+k print(d)
s495343376
Accepted
17
2,940
101
n=int(input()) k=int(input()) d=1 for i in range(n): if k>=d: d=d*2 else: d=d+k print(d)
s365418262
p00004
u811841526
1,000
131,072
Wrong Answer
30
7,628
206
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
while True: try: a,b,c,d,e,f = map(int, input().split()) except EOFError: break x = c/a + (f*a-c*d)*b / (e*a-d*b) / a y = (f*a - c*d) / (e*a - b*d) print('{:.3f} {:.3f}')
s651615219
Accepted
20
7,568
221
while True: try: a,b,c,d,e,f = map(int, input().split()) except EOFError: break x = c/a - (b/a) * (a*f-c*d) / (a*e-b*d) y = (f*a - c*d) / (e*a - b*d) print('{:.3f} {:.3f}'.format(x, y))
s278723034
p03338
u953379577
2,000
1,048,576
Wrong Answer
26
9,044
132
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 = list(input()) ans = 0 for i in range(n): x = s[:i+1] y = s[i:] ans = max(ans,len(set(x)&set(y)))
s048108019
Accepted
26
9,020
146
n = int(input()) s = list(input()) ans = 0 for i in range(n): x = s[:i+1] y = s[i+1:] ans = max(ans,len(set(x)&set(y))) print(ans)
s487996193
p04029
u202877219
2,000
262,144
Wrong Answer
17
2,940
169
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() z = "" for i in range(len(s)): if s[i] == "0": z += "0" elif s[i] == "1": z+= "1" elif s[i] == "B": z = z[:-1] print (z)
s081663292
Accepted
17
2,940
66
n = int(input()) x = 0 for i in range(n+1): x = x+i print (x)
s851556987
p02388
u464802001
1,000
131,072
Wrong Answer
20
7,476
32
Write a program which calculates the cube of a given integer x.
a=int(input()) s=a**3 print("s")
s549653880
Accepted
30
7,608
30
a=int(input()) s=a**3 print(s)
s008358329
p03502
u698919163
2,000
262,144
Wrong Answer
17
2,940
132
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N = input() tmp = 0 for i in range(len(N)): tmp += int(N[i]) if tmp % int(N) == 0: print('Yes') else: print('No')
s590607008
Accepted
18
2,940
132
N = input() tmp = 0 for i in range(len(N)): tmp += int(N[i]) if int(N) % tmp == 0: print('Yes') else: print('No')
s845132368
p03673
u858136677
2,000
262,144
Wrong Answer
95
26,180
72
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
n = int(input()) a = list(map(int,input().split())) a.reverse() print(a)
s799895809
Accepted
360
26,180
325
n = int(input()) a = list(map(int,input().split())) a.insert(0,0) b = [] if n%2==0: i=n while i>=2: b.append(a[i]) i += -2 k=1 while k<=n-1: b.append(a[k]) k += 2 else: i=n while i>=1: b.append(a[i]) i += -2 k=2 while k<=n-1: b.append(a[k]) k+=2 for i in range(n-1): print(b[i],end=' ') print(b[n-1])
s105665734
p03836
u088552457
2,000
262,144
Wrong Answer
19
3,064
384
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()) dx = tx - sx dy = ty - sy r = '' for i in range(dy): r += 'U' for i in range(dx): r += 'R' for i in range(dy): r += 'D' for i in range(dx): r += 'L' r += 'L' for i in range(dy + 1): r += 'U' for i in range(dx + 1): r += 'R' r += 'R' for i in range(dy + 1): r += 'D' for i in range(dx + 1): r += 'L' r += 'U' print(r)
s863609377
Accepted
19
3,064
393
sx, sy, tx, ty = map(int, input().split()) dx = tx - sx dy = ty - sy r = '' for i in range(dy): r += 'U' for i in range(dx): r += 'R' for i in range(dy): r += 'D' for i in range(dx): r += 'L' r += 'L' for i in range(dy + 1): r += 'U' for i in range(dx + 1): r += 'R' r += 'D' r += 'R' for i in range(dy + 1): r += 'D' for i in range(dx + 1): r += 'L' r += 'U' print(r)
s588028637
p03485
u598229387
2,000
262,144
Wrong Answer
17
2,940
55
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(int((a+b)//2 +1))
s041199729
Accepted
17
2,940
51
a,b = map(int, input().split()) print(-(-(a+b)//2))
s235130312
p02578
u007637377
2,000
1,048,576
Wrong Answer
102
32,108
129
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())) ans = 0 h = A[0] for a in A: if h > a: ans += h - a h = a print(ans)
s440665121
Accepted
100
32,164
139
N = int(input()) A = list(map(int, input().split())) ans = 0 h = A[0] for a in A: if h > a: ans += h - a else: h = a print(ans)
s975799717
p02255
u917432951
1,000
131,072
Wrong Answer
20
7,548
379
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.
if __name__ == '__main__': N = (int)(input()) A = list(map(int,input().split())) 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 = j -1 A[j+1] = v if i == N - 1: print(' '.join(map(str,A)),end = '') else: print(' '.join(map(str,A)))
s591519542
Accepted
20
7,724
318
if __name__ == '__main__': N = (int)(input()) A = list(map(int,input().split())) print(' '.join(map(str,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 = j -1 A[j+1] = v print(' '.join(map(str,A)))
s206137100
p03607
u826263061
2,000
262,144
Wrong Answer
216
14,312
139
You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?
n = int(input()) a = set([]) for i in range(n): k = int(input()) if k in a: a.remove(k) else: a.add(k) ans = len(a) print(a)
s000931349
Accepted
201
11,884
141
n = int(input()) a = set([]) for i in range(n): k = int(input()) if k in a: a.remove(k) else: a.add(k) ans = len(a) print(ans)
s072576884
p03229
u405256066
2,000
1,048,576
Wrong Answer
251
8,912
395
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
from sys import stdin N = int(stdin.readline().rstrip()) A = [] for i in range(N): A.append(int(input())) A.sort() ans = 0 if N % 2 == 0: tmp = [-1,1] + [2]*((N-2)//2) + [-2]*((N-2)//2) for i,j in zip(sorted(tmp),A): ans += (i*j) print(ans) else: tmp = [-1,1] + [2]*((N-1)//2) + [-2]*((N-2)//2) for i,j in zip(sorted(tmp),A): ans += (i*j) print(ans)
s359791204
Accepted
279
9,656
552
from sys import stdin N = int(stdin.readline().rstrip()) A = [] for i in range(N): A.append(int(input())) A.sort() if N % 2 != 0: ans1 = 0 tmp = [-1,-1] + [2]*((N-1)//2) + [-2]*((N-2)//2) for i,j in zip(sorted(tmp),A): ans1 += (i*j) ans2 = 0 tmp = [1,1] + [2]*((N-2)//2) + [-2]*((N-1)//2) for i,j in zip(sorted(tmp),A): ans2 += (i*j) print(max(ans1,ans2)) else: ans = 0 tmp = [-1,1] + [2]*((N-2)//2) + [-2]*((N-2)//2) for i,j in zip(sorted(tmp),A): ans += (i*j) print(ans)
s019173241
p03473
u629540524
2,000
262,144
Wrong Answer
17
2,940
28
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
m = int(input()) print(m+24)
s771943609
Accepted
17
2,940
28
m = int(input()) print(48-m)
s011285646
p03473
u759412327
2,000
262,144
Wrong Answer
17
2,940
22
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
print(int(input())+24)
s033459545
Accepted
27
9,144
22
print(48-int(input()))
s942982292
p03024
u249447366
2,000
1,048,576
Wrong Answer
17
2,940
108
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
s = list(input()) cnt = s.count('o') rest = 15 - len(s) ans = 'Yes' if cnt + rest >= 8 else 'No' print(ans)
s882463146
Accepted
17
2,940
108
s = list(input()) cnt = s.count('o') rest = 15 - len(s) ans = 'YES' if cnt + rest >= 8 else 'NO' print(ans)
s408282187
p03079
u174603263
2,000
1,048,576
Wrong Answer
17
2,940
103
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
a, b, c = input().split() if(a+b > c and a+c > b and b+c > a): print('yes') else: print('no')
s658290406
Accepted
17
2,940
89
a, b, c = input().split() if(a == b and b == c): print('Yes') else: print('No')
s237572740
p03503
u609738635
2,000
262,144
Wrong Answer
80
3,064
718
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
# -*- coding: utf-8 -*- def main(N,F,P): inf = float("INF") ans = -inf print(F,P) for i in range(1,1<<10): count = [0]*N tmp = 0 for j in range(10): if((i>>j)&1): for k in range(N): if F[k][j]==1: count[k] += 1 else: continue for l in range(N): tmp += P[l][count[l]] ans = max(ans,tmp) print(ans) if __name__ == '__main__': N = int(input()) F,P = [],[] for i in range(N): F.append([int(j) for j in input().split()]) for i in range(N): P.append([int(j) for j in input().split()]) main(N,F,P)
s058637217
Accepted
80
3,064
703
# -*- coding: utf-8 -*- def main(N,F,P): inf = float("INF") ans = -inf for i in range(1,1<<10): count = [0]*N tmp = 0 for j in range(10): if((i>>j)&1): for k in range(N): if F[k][j]==1: count[k] += 1 else: continue for l in range(N): tmp += P[l][count[l]] ans = max(ans,tmp) print(ans) if __name__ == '__main__': N = int(input()) F,P = [],[] for i in range(N): F.append([int(j) for j in input().split()]) for i in range(N): P.append([int(j) for j in input().split()]) main(N,F,P)
s823087745
p03229
u518042385
2,000
1,048,576
Wrong Answer
242
8,284
350
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
n=int(input()) l=[] for i in range(n): l.append(int(input())) l1=sorted(l) if n%2==0: k=n//2 sum=0 for i in range(0,k): sum-=2*l1[i] for i in range(k,n): sum+=2*l1[i] sum-=l1[k] sum+=l1[k-1] else: k=n//2 sum=0 for i in range(k,n): sum+=2*l1[i] for i in range(k): sum-=2*l1[i] sum-=l1[0] sum-=l1[1] print(sum)
s036303971
Accepted
263
8,296
500
n=int(input()) l=[] for i in range(n): l.append(int(input())) l1=sorted(l) if n%2==0: k=n//2 sum=0 for i in range(0,k): sum-=2*l1[i] for i in range(k,n): sum+=2*l1[i] sum-=l1[k] sum+=l1[k-1] print(sum) else: k=n//2 sum=0 for i in range(k,n): sum+=2*l1[i] for i in range(k): sum-=2*l1[i] sum-=l1[k] sum-=l1[k+1] sum1=0 for i in range(k+1,n): sum1+=2*l1[i] for i in range(k+1): sum1-=2*l1[i] sum1+=l1[k] sum1+=l1[k-1] print(max(sum,sum1))
s653846116
p02260
u995963067
1,000
131,072
Wrong Answer
20
5,592
471
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.
def sel_sort(A, N): count = 0 for n in range(N): minm = n for m in range(n, N): if A[m] < A[minm]: minm = m if minm != n: A[n], A[minm] = A[minm], A[n] count += 1 return (A, count) if __name__ == '__main__': N = int(input()) A = list(map(int, input().split(' '))) ans = sel_sort(A, N) print(ans[0]) print(ans[1])
s137056551
Accepted
20
5,608
499
def sel_sort(A, N): count = 0 for n in range(N): minm = n for m in range(n, N): if A[m] < A[minm]: minm = m if minm != n: A[n], A[minm] = A[minm], A[n] count += 1 return (A, count) if __name__ == '__main__': N = int(input()) A = list(map(int, input().split(' '))) ans = sel_sort(A, N) print(' '.join([str(x) for x in ans[0]])) print(ans[1])
s560786132
p03719
u341087021
2,000
262,144
Wrong Answer
18
2,940
124
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
import sys a, b, c = [int(x) for x in sys.stdin.readline().split()] if a <= c and b >= c: print('YES') else: print('NO')
s136754106
Accepted
17
2,940
124
import sys a, b, c = [int(x) for x in sys.stdin.readline().split()] if a <= c and b >= c: print('Yes') else: print('No')
s710619111
p02831
u557750361
2,000
1,048,576
Wrong Answer
17
2,940
126
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
A, B = map(int, input().split()) if A > B and 0 == A % B: print(A) elif B > A and 0 == B % B: print(B) else: print(A*B)
s025341537
Accepted
45
2,940
186
num = [int(i) for i in input().split()] A = max(num) B = min(num) X = A*B num = 0 while X >= num: num += B if 0 == num % A: print(num) break elif X == num: print(num)
s478773564
p03494
u854093727
2,000
262,144
Wrong Answer
19
2,940
226
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N = input() A = list(map(int,input().split())) print(A) res = 0 while True: result = 0 for i in A: if i%2: result = 1 if result: break A = [i/2 for i in A] res += 1 print(res)
s108354961
Accepted
22
2,940
217
N = input() A = list(map(int,input().split())) res = 0 while True: result = 0 for i in A: if i%2: result = 1 if result: break A = [i/2 for i in A] res += 1 print(res)
s002015691
p04029
u138486156
2,000
262,144
Wrong Answer
17
2,940
34
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()) print(n*(n-1)//2)
s743978685
Accepted
17
2,940
35
n = int(input()) print(n*(n+1)//2)
s586914147
p03854
u359358631
2,000
262,144
Wrong Answer
37
9,148
393
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`.
def main(): S = input() border = len(S) while True: if S[border - 5: border] == "dream": border -= 5 elif S[border - 7: border] == "dreamer": border -= 7 elif S[border - 5: border] == "erase": border -= 5 elif S[border - 6: border] == "eraser": border -= 6 else: break if border == 0: print("Yes") else: print("No") if __name__ == "__main__": main()
s351832832
Accepted
37
9,244
393
def main(): S = input() border = len(S) while True: if S[border - 5: border] == "dream": border -= 5 elif S[border - 7: border] == "dreamer": border -= 7 elif S[border - 5: border] == "erase": border -= 5 elif S[border - 6: border] == "eraser": border -= 6 else: break if border == 0: print("YES") else: print("NO") if __name__ == "__main__": main()
s134823749
p03160
u670133596
2,000
1,048,576
Wrong Answer
145
14,724
357
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()) H = list(map(int, input().split())) dp = [] for i, h in enumerate(H) : if (i==0) : dp.append(0) continue if (i==1) : dp.append(abs(H[0]-H[1])) continue one = abs(dp[i-2] + (H[i]-H[i-1])) two = abs(H[i]-H[i-2]) if (one < two): dp.append(dp[i-1] + one) else : dp.append(dp[i-2] + two) print(dp)
s396896998
Accepted
186
13,928
403
N = int(input()) H = list(map(int, input().split())) f_inf = float('inf') dp = [f_inf] * (10**5+10) dp[0] = 0 for i in range(N-1): dp[i+1] = min(dp[i+1], dp[i] + abs(H[i+1] - H[i])) if (i != N-2): dp[i+2] = min(dp[i+2], dp[i] + abs(H[i+2] - H[i])) print(dp[N-1])
s179877093
p03555
u844196583
2,000
262,144
Wrong Answer
23
9,096
312
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
data1 = list(map(str, input().split())) data2 = list(map(str, input().split())) count = len(data1) - 1 sw = 0 i = 0 j = len(data2)-1 while i <= count: if data1[i] == data2[j]: sw += 1 print(data1[i],data2[j]) i += 1 j -= 1 if sw == len(data1): print("Yes") else: print("No")
s839584674
Accepted
23
8,824
211
data1 = input() data2 = input() count = 3 -1 sw = 0 i = 0 j = len(data2)-1 while i <= count: if data1[i] == data2[j]: sw += 1 i += 1 j -= 1 if sw == 3: print("YES") else: print("NO")
s049066853
p03828
u599547273
2,000
262,144
Wrong Answer
18
3,060
248
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
def is_prime(q): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False return pow(2, q-1, q) == 1 n = int(input()) count = 1 for i in range(1, n+1): if is_prime(i): count += 1 print(count)
s120507967
Accepted
125
3,188
447
def is_prime(q): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False return pow(2, q-1, q) == 1 N = int(input()) p = [0]*(N+1) for i in range(2, N+1): for j in range(2, i+1): if is_prime(j) == False: continue while i%j==0: i //= j p[j] += 1 if i == 1: break r = 1 for q in p: r = r * (q+1) print(r%(10**9+7))
s041926637
p03635
u339922532
2,000
262,144
Wrong Answer
17
2,940
58
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
n, m = map(int, input().split()) print((n - 2) * (m - 2))
s898949509
Accepted
17
2,940
58
n, m = map(int, input().split()) print((n - 1) * (m - 1))
s272519188
p03814
u584529823
2,000
262,144
Wrong Answer
18
3,812
87
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s = input() A_index = s.find("A") Z_index = s.rfind("Z") print(s[A_index:Z_index + 1])
s737621314
Accepted
17
3,500
86
s = input() A_index = s.find("A") Z_index = s.rfind("Z") print(Z_index - A_index + 1)
s378320128
p02612
u725359833
2,000
1,048,576
Wrong Answer
29
9,032
34
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n % 1000)
s256914048
Accepted
29
9,036
84
n = int(input()) if n % 1000 == 0: print(0) else: print(1000 - (n % 1000))
s050646773
p02401
u508732591
1,000
131,072
Wrong Answer
20
7,484
124
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.
import sys for i in sys.stdin: a,op,b = i.split() if op == "?": break else: print(eval(a+op+b))
s551991364
Accepted
40
7,408
113
import sys for i in sys.stdin: if "?" in i: break else: print(eval(i.replace("/","//")))
s879887077
p03470
u084949493
2,000
262,144
Wrong Answer
18
2,940
80
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
N = int(input()) d = list(map(int, input().split())) ds = set(d) print(len(ds))
s274850333
Accepted
18
2,940
98
N = int(input()) d = [] for ni in range(N): d.append(int(input())) ds = set(d) print(len(ds))
s284367705
p03478
u808537778
2,000
262,144
Wrong Answer
30
3,060
278
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b = map(int, input().split()) c = 0 for i in range(1,n+1): n4 = n//10**4 n3 = n//10**3 - n4*10 n2 = n//10**2 - n4*100 - n3*10 n1 = n//10**1 - n4*1000 - n3*100 -n2*10 n0 = n - n4*10000 -n3*1000-n2*100-n1*10 sum = n4+n3+n2+n1+n0 if sum>=a and sum<=b: c+=sum
s369072047
Accepted
30
3,060
291
n,a,b = map(int, input().split()) c = 0 for i in range(1,n+1): n4 = i//10**4 n3 = i//10**3 - n4*10 n2 = i//10**2 - n4*100 - n3*10 n1 = i//10**1 - n4*1000 - n3*100 -n2*10 n0 = i - n4*10000 -n3*1000-n2*100-n1*10 total = n4+n3+n2+n1+n0 if total>=a and total<=b: c+= i print(c)
s263119754
p03730
u018591138
2,000
262,144
Wrong Answer
18
3,060
203
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()) flag = False print(C) for i in range(B): t = i*A%B if t == C: flag = True if flag == True: print("YES") else: print("NO")
s969736391
Accepted
17
2,940
193
A,B,C = map(int, input().split()) flag = False for i in range(B): t = i*A%B if t == C: flag = True if flag == True: print("YES") else: print("NO")
s407376829
p04029
u019584841
2,000
262,144
Wrong Answer
17
2,940
31
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()) print((n+1)*n/2)
s826460435
Accepted
17
2,940
37
n=int(input()) print(int((n+1)*n/2))
s200918096
p03380
u625963200
2,000
262,144
Wrong Answer
276
25,324
203
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 scipy.misc import comb n=int(input()) A=list(map(int,input().split())) A.sort() max_,num=0,0 for a in A: if max_<comb(A[-1],a): max_=comb(A[-1],a) num=a else: break print(A[-1],num)
s771292168
Accepted
129
14,060
166
n=int(input()) A=list(map(int,input().split())) A.sort() num=float('inf') for i in range(n-1): if abs(num-A[-1]/2)>abs(A[i]-A[-1]/2): num=A[i] print(A[-1],num)
s017846001
p00002
u995990363
1,000
131,072
Wrong Answer
30
5,688
223
Write a program which computes the digit number of sum of two integers a and b.
import sys, math def run(): N = [] for n in sys.stdin: a,b = map(int, n.split()) N.append((a,b)) for a,b in N: print(math.ceil(math.log10(a+b))) if __name__ == '__main__': run()
s225111746
Accepted
30
5,688
228
import sys, math def run(): N = [] for n in sys.stdin: a,b = map(int, n.split()) N.append((a,b)) for a,b in N: print(math.floor(math.log10(a+b)) + 1) if __name__ == '__main__': run()
s995056235
p03997
u045953894
2,000
262,144
Wrong Answer
17
2,940
66
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()) S=h*(a+b)/2 print(S)
s275624702
Accepted
17
2,940
74
a=int(input());b=int(input());h=int(input()) S=h*(a+b)/2 s=int(S) print(s)
s198351207
p03681
u027002244
2,000
262,144
Wrong Answer
2,104
3,480
346
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.
a=list(map(int,input().split())) ans=0 i=0 if max(a)-min(a)>=2: pass else: ans=1 i=max(a) if a[0]==a[1]: while i!=0: ans=ans*i i=i-1 ans=ans*ans else: while i!=0: ans=ans*i i=i-1 ans=ans*ans/max(a) #print(ans) print(int(ans%1000000007 ))
s457481200
Accepted
444
4,376
356
import math a=list(map(int,input().split())) ans=0 if max(a)-min(a)>=2: print(0) else: if a[0]==a[1]: ans=math.factorial(max(a)) ans=(ans%1000000007)*(ans%1000000007)*2 else: ans=math.factorial(max(a)) ans1 = math.factorial(min(a)) ans=(ans%1000000007)*((ans1)%1000000007) print(int(ans%1000000007 ))
s677016338
p03796
u257974487
2,000
262,144
Wrong Answer
18
3,188
33
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.
print(int(input()) % 1000000007)
s032021754
Accepted
40
2,940
86
N = int(input()) p = 1 for i in range(1,N+1): p *= i p %= 1000000007 print(p)