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
s483711067
p03006
u619458041
2,000
1,048,576
Wrong Answer
157
4,084
716
There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: * Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1. Find the minimum total cost required to collect all the balls when we optimally choose p and q.
import sys from itertools import combinations def main(): input = sys.stdin.readline N = int(input()) cord = [] for _ in range(N): x, y = map(int, input().split()) cord.append((x, y)) ans = 50 for a in combinations(cord, 2): x1, y1 = a[0] x2, y2 = a[1] if x1 == x2: slope = 0 else: slope = (y2 - y1) / (x2 - x1) intercepts = set() for x, y in cord: intercept = y - slope * x intercept = round(intercept, 5) intercepts.add(intercept) print(intercepts) ans = min(ans, len(intercepts)) return ans if __name__ == '__main__': print(main())
s047874862
Accepted
56
3,064
706
import sys from itertools import combinations def main(): input = sys.stdin.readline N = int(input()) cord = set() for _ in range(N): x, y = map(int, input().split()) cord.add((x, y)) if N <= 2: return 1 ans = 50 for a in combinations(cord, 2): x1, y1 = a[0] x2, y2 = a[1] p = x2 - x1 q = y2 - y1 cnt1 = 0 cnt2 = 0 if p == q == 0: continue A = set() B = set() for x, y in cord: A.add((x-p, y-q)) B.add((x+p, y+q)) ans = min(ans, len(A - cord), len(B - cord)) return ans if __name__ == '__main__': print(main())
s083290075
p04029
u023077142
2,000
262,144
Wrong Answer
18
3,064
731
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?
from itertools import combinations, product def gcd(a, b): if a < b: a, b = b, a while b != 0: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) def get(fmt): ps = input().split() r = [] for p, t in zip(ps, fmt): if t == "i": r.append(int(p)) if t == "f": r.append(float(p)) if t == "s": r.append(p) if len(r) == 1: r = r[0] return r def put(*args, **kwargs): print(*args, **kwargs) def rep(n, f, *args, **kwargs): return [f(*args, **kwargs) for _ in range(n)] def rep_im(n, v): return rep(n, lambda: v) YES_NO = ["NO", "YES"] N = get("i") put(N * (N - 1) // 2)
s198664630
Accepted
18
3,064
731
from itertools import combinations, product def gcd(a, b): if a < b: a, b = b, a while b != 0: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) def get(fmt): ps = input().split() r = [] for p, t in zip(ps, fmt): if t == "i": r.append(int(p)) if t == "f": r.append(float(p)) if t == "s": r.append(p) if len(r) == 1: r = r[0] return r def put(*args, **kwargs): print(*args, **kwargs) def rep(n, f, *args, **kwargs): return [f(*args, **kwargs) for _ in range(n)] def rep_im(n, v): return rep(n, lambda: v) YES_NO = ["NO", "YES"] N = get("i") put(N * (N + 1) // 2)
s649676757
p03623
u894694822
2,000
262,144
Wrong Answer
17
2,940
87
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("A") else: print("B")
s392923502
Accepted
17
2,940
87
x, a, b=map(int, input().split()) if abs(x-a)<abs(x-b): print("A") else: print("B")
s030212791
p03434
u824237520
2,000
262,144
Wrong Answer
18
3,060
140
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = int(input()) a = list(map(int, input().split())) a = sorted(a) ans = 0 flag = 1 for x in a: ans += x * flag flag *= -1 print(ans)
s840082611
Accepted
17
2,940
157
n = int(input()) a = list(map(int, input().split())) a = list(reversed(sorted(a))) ans = 0 flag = 1 for x in a: ans += x * flag flag *= -1 print(ans)
s413625983
p02600
u882564128
2,000
1,048,576
Wrong Answer
26
9,216
305
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
x = int(input()) if x >= 400 and x <= 599: s = 8 elif x >= 600 and x <= 799: s = 7 elif x >= 800 and x <= 999: s = 6 elif x >= 1000 and x <= 1199: s = 5 elif x >= 1200 and x <= 1399: s = 4 elif x >= 1400 and x <= 1599: s = 3 elif x >= 1600 and x <= 1799: s = 2 else: s = 1
s266490319
Accepted
28
9,176
315
x = int(input()) if x >= 400 and x <= 599: s = 8 elif x >= 600 and x <= 799: s = 7 elif x >= 800 and x <= 999: s = 6 elif x >= 1000 and x <= 1199: s = 5 elif x >= 1200 and x <= 1399: s = 4 elif x >= 1400 and x <= 1599: s = 3 elif x >= 1600 and x <= 1799: s = 2 else: s = 1 print(s)
s925843199
p03151
u349091349
2,000
1,048,576
Wrong Answer
280
25,956
526
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.
import numpy as np from collections import deque import sys N=int(input()) A=np.array([int(i) for i in input().split()]) B=np.array([int(i) for i in input().split()]) C = A-B minus_idx=np.where(C<0) plus_idx=np.where(C>0) minus = np.sum(C[minus_idx]) plus = deque(np.sort(C[plus_idx])) len_plus = len(plus) if len_plus == 0: print(-1) sys.exit() count = 0 while minus<0: minus += plus.pop() count += 1 len_plus -= 1 if len_plus == 0: print(-1) sys.exit() print(len(minus_idx[0])+count)
s804659463
Accepted
286
23,976
594
import numpy as np from collections import deque import sys N=int(input()) A=np.array([int(i) for i in input().split()]) B=np.array([int(i) for i in input().split()]) C = A-B minus_idx=np.where(C<0) plus_idx=np.where(C>=0) minus = np.sum(C[minus_idx]) plus = deque(np.sort(C[plus_idx])) len_plus = len(plus) if len(minus_idx[0]) == 0: print(0) sys.exit() if len_plus == 0: print(-1) sys.exit() count = 0 while minus<0: try: minus += plus.pop() count += 1 len_plus -= 1 except: print(-1) sys.exit() print(len(minus_idx[0])+count)
s018237166
p03738
u035445296
2,000
262,144
Wrong Answer
26
8,908
104
You are given two positive integers A and B. Compare the magnitudes of these numbers.
a = int(input()) b = int(input()) ans = 'GREATER' if a == b: ans = 'EQUAL' elif a < b: ans = 'LESS'
s843697358
Accepted
30
9,060
114
a = int(input()) b = int(input()) ans = 'GREATER' if a == b: ans = 'EQUAL' elif a < b: ans = 'LESS' print(ans)
s670756918
p03478
u531599639
2,000
262,144
Wrong Answer
57
3,060
210
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()) sums=0 for i in range(1, N+1): m=0 sum=0 for j in range(len(str(i))-1, -1, -1): m=i//(10**j) i-=10**j*m sum+=m if A<=sum<=B: sums+=sum print(sums)
s116657684
Accepted
31
2,940
124
N, A, B = map(int, input().split()) sums=0 for i in range(1, N+1): if A<=sum(map(int, str(i)))<=B: sums+=i print(sums)
s592843349
p00728
u661290476
1,000
131,072
Wrong Answer
30
5,604
350
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance. Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer. You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
while True: try: n = int(input()) MIN = 1000 MAX = 0 points = 0 for i in range(n): p = int(input()) if MIN > p: MIN = p if MAX < p: MAX = p points += p print((points - MIN - MAX) // (n - 2)) except: break
s695727577
Accepted
30
5,592
296
while True: n = int(input()) if n == 0: break MIN = 1000 MAX = 0 points = 0 for i in range(n): p = int(input()) if MIN > p: MIN = p if MAX < p: MAX = p points += p print((points - MIN - MAX) // (n - 2))
s214641800
p03353
u077337864
2,000
1,048,576
Wrong Answer
2,159
928,152
421
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
s = input().strip() k = int(input()) subs = set() ds = {} for i, c in enumerate(s): if c in ds: ds[c].append(i) else: ds[c] = [i] for c, il in sorted(ds.items(), key=lambda x: x[0]): print(c, il) subs |= set([c]) i = 2 while il[0]+i <= len(s): for j in il: if j + i > len(s): break subs.add(s[j:j+i]) i += 1 if len(subs) >= k: break print(list(sorted(subs))[k-1])
s518277484
Accepted
41
4,588
163
s = input().strip() k = int(input()) subs = set() for i in range(1, 6): for j in range(0, len(s)-i+1): subs |= set([s[j:j+i]]) print(list(sorted(subs))[k-1])
s867917065
p03433
u775652851
2,000
262,144
Wrong Answer
30
9,024
76
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
a=int(input()) b=int(input()) if a%500 <b: print("No") else: print("No")
s293866996
Accepted
25
9,016
80
a=int(input()) b=int(input()) if a%500 <= b: print("Yes") else: print("No")
s940056871
p03435
u401487574
2,000
262,144
Wrong Answer
17
3,064
289
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
nums = [list(map(int,input().split())) for i in range(3)] a1 = 0 b1,b2,b3 = map(int,nums[0]) a2 = nums[1][0] -b2 a3 = nums[2][0] -b3 print(a2,a3) print(nums) if nums[1][1] == a2+b2 and nums[1][2] == a2+b3 and nums[2][1] == a3+b2 and nums[2][2] == a3+b3: print("Yes") else:print("No")
s781224742
Accepted
17
3,060
264
nums = [list(map(int,input().split())) for i in range(3)] a1 = 0 b1,b2,b3 = map(int,nums[0]) a2 = nums[1][0] -b1 a3 = nums[2][0] -b1 if nums[1][1] == a2+b2 and nums[1][2] == a2+b3 and nums[2][1] == a3+b2 and nums[2][2] == a3+b3: print("Yes") else:print("No")
s620749289
p04043
u627691992
2,000
262,144
Wrong Answer
27
8,988
80
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.
S = input() print('Yes' if(S.count('5') == 2 and S.count('7') == 1) else 'No')
s508637007
Accepted
24
8,872
80
S = input() print('YES' if(S.count('5') == 2 and S.count('7') == 1) else 'NO')
s140242376
p03971
u638795007
2,000
262,144
Wrong Answer
112
4,796
1,288
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
def examA(): S = SI(); N = len(S) T = "CODEFESTIVAL2016" ans = 0 for i in range(N): if S[i]!=T[i]: ans +=1 print(ans) return def examB(): N, A, B = LI() S = SI() d = defaultdict(int) for s in S: if s=="a": if d["a"]+d["b"]<A+B: print("YES") d[s] += 1 else: print("NO") elif s=="b": if d["a"]+d["b"]<A+B and d["b"]<B: print("YES") d[s] += 1 else: print("NO") else: print("NO") return def examC(): return import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,ALPHABET, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 1e-9 alphabet = [chr(ord('a') + i) for i in range(26)] ALPHABET = [chr(ord('A') + i) for i in range(26)] if __name__ == '__main__': examB()
s460524377
Accepted
114
4,564
1,289
def examA(): S = SI(); N = len(S) T = "CODEFESTIVAL2016" ans = 0 for i in range(N): if S[i]!=T[i]: ans +=1 print(ans) return def examB(): N, A, B = LI() S = SI() d = defaultdict(int) for s in S: if s=="a": if d["a"]+d["b"]<A+B: print("Yes") d[s] += 1 else: print("No") elif s=="b": if d["a"]+d["b"]<A+B and d["b"]<B: print("Yes") d[s] += 1 else: print("No") else: print("No") return def examC(): return import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,ALPHABET, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 1e-9 alphabet = [chr(ord('a') + i) for i in range(26)] ALPHABET = [chr(ord('A') + i) for i in range(26)] if __name__ == '__main__': examB()
s726320556
p03643
u642015143
2,000
262,144
Wrong Answer
17
3,064
21
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
print("abc"+input())
s285951372
Accepted
17
2,940
21
print("ABC"+input())
s057923321
p03485
u847165882
2,000
262,144
Wrong Answer
17
2,940
50
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)))
s826024179
Accepted
17
2,940
49
a,b=map(int,input().split()) print(-(-(a+b)//2))
s990267422
p04030
u411858517
2,000
262,144
Wrong Answer
17
2,940
114
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() res = '' for i in range(len(s)): res += s[i] if s[i] == 'B': res = res[:i-2] print(res)
s852477224
Accepted
18
2,940
258
s = input() res = '' for i in range(len(s)): if res == '': if s[i] == 'B': pass else: res += s[i] else: if s[i] == 'B': res = res[:-1] else: res += s[i] print(res)
s758913098
p02614
u127643144
1,000
1,048,576
Wrong Answer
29
9,176
298
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
nCr = {} def cmb(n, r): if r == 0 or r == n: return 1 if r == 1: return n if (n,r) in nCr: return nCr[(n,r)] nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1) return nCr[(n,r)] h, w, k = map(int, input().split()) c = [list(input()) for _ in range(h)] ans = 0 a = cmb(h*w,k) print(a)
s729160091
Accepted
41
9,360
602
import copy from itertools import combinations h, w, k = map(int, input().split()) c =[input() for i in range(h)] ans = 0 y = [] for i in range(h): y.append(i) x = [] for i in range(w): x.append(i) for i in range(h+1): ty = list(combinations(y, i)) for j in range(w+1): tx = list(combinations(x, j)) for l in ty: for m in tx: cnt = 0 for p in l: for q in m: if c[p][q] == '#': cnt += 1 if cnt == k: ans += 1 print(ans)
s254921087
p02694
u261082314
2,000
1,048,576
Wrong Answer
23
9,048
115
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import math k=int(input()) #r = math.floor(t/100) t = 100 n = 0 while t<= k: t+=math.floor(t/100) n+=1 print(n)
s484247724
Accepted
23
9,156
114
import math k=int(input()) #r = math.floor(t/100) t = 100 n = 0 while t< k: t+=math.floor(t/100) n+=1 print(n)
s601880118
p03160
u479353489
2,000
1,048,576
Wrong Answer
125
14,716
374
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()) a = [int(x) for x in input().split()] def dp(N,a): F = [0]*(len(a)+1) F[0]=0 F[1]=a[0] F[2]=abs(a[1]-a[0]) if N == 1: return F[1] elif N == 2: return F[2] #F[3] = min(F[1]+abs(a[2])) for n in range(3,N+1): F[n] = min(F[n-1] + abs(a[n-1]-a[n-2]),F[n-2]+abs(a[n-1]-a[n-3])) print(F) return F[-1] print(dp(N,a))
s791336311
Accepted
114
13,980
307
N = int(input()) a = [int(x) for x in input().split()] def dp(N,a): F = [0]*(len(a)) F[0]=0 F[1]=abs(a[1]-a[0]) if N == 1: return F[0] elif N == 2: return F[1] for n in range(2,N): F[n] = min(F[n-1] + abs(a[n]-a[n-1]),F[n-2]+abs(a[n]-a[n-2])) return F[-1] print(dp(N,a))
s300608770
p03024
u219503971
2,000
1,048,576
Wrong Answer
17
2,940
103
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=input() ct=0 for i in s: if i=='o': ct+=1 if 15-len(s)+ct>8: print('YES') else: print('NO')
s361765179
Accepted
17
2,940
105
s=input() ct=0 for i in s: if i=='o': ct+=1 if 15-len(s)+ct>=8: print('YES') else: print('NO')
s907527760
p03457
u329006798
2,000
262,144
Wrong Answer
2,104
108,284
608
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
def test(): n = int(input()) t = [0 for _ in range(n+1)] x = [0 for _ in range(n+1)] y = [0 for _ in range(n+1)] for i in range(n): t[i+1], x[i+1], y[i+1] = [int(z) for z in input().split()] print(t,x,y) dt = [t[i+1] - t[i] for i in range(n)] dist = [abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]) for i in range(n)] print(dt, dist) result = "Yes" for i in range(len(t)): if not t[i] % 2 == (abs(x[i])+abs(y[i])) % 2: result = "No" for i in range(len(dt)): if dt < dist: result = "No" print(result) test()
s635151909
Accepted
471
11,824
350
n = int(input()) t = [0 for _ in range(n+1)] x = [0 for _ in range(n+1)] y = [0 for _ in range(n+1)] for i in range(n): t[i+1], x[i+1], y[i+1] = [int(z) for z in input().split()] if t[i+1] - t[i] < abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]) or (t[i+1] % 2 != (abs(x[i+1]) + abs(y[i+1])) % 2): print('No') exit() print('Yes')
s902256785
p03311
u089230684
2,000
1,048,576
Wrong Answer
306
39,024
393
Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
n = input() arr = [int(i) for i in input().split(" ")] sum = {} for i, v in enumerate(arr): if sum.get(abs(v - (i + 1)), False): sum[abs(v - (i + 1))] += 1 else: sum[abs(v - (i + 1))] = 1 max_b = 0 max_times = 0 for key, value in sum.items(): if value > max_times: value = max_times max_b = key sum = 0 for i, v in enumerate(arr): sum += abs(v - (-max_b + (i + 1))) print(sum)
s989043736
Accepted
226
26,128
259
while True: try: n = int(input()) num = list(map(int, input().split())) for ind in range(len(num)): num[ind] -= ind+1 num.sort() print(sum(abs(i-num[len(num)//2])for i in num)) except: break
s617303393
p03485
u863442865
2,000
262,144
Wrong Answer
19
3,316
85
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()) if (a+b)%2: print((a+b+1)/2) else: print((a+b)/2)
s423350721
Accepted
17
2,940
96
a,b = map(int, input().split()) if (a+b)%2: print(int((a+b+1)/2)) else: print(int((a+b)/2))
s658275275
p04029
u677991935
2,000
262,144
Wrong Answer
18
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*(N+1)/2)
s257047999
Accepted
17
2,940
36
N=int(input()) print(int(N*(N+1)/2))
s956326822
p03067
u148551245
2,000
1,048,576
Wrong Answer
17
2,940
93
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a, b, c = map(int, input().split()) if b < a or b > c: print('No') else: print('Yes')
s272836223
Accepted
17
2,940
101
a, b, c = map(int, input().split()) if a < c < b or b < c < a: print('Yes') else: print('No')
s574414848
p02865
u958693198
2,000
1,048,576
Wrong Answer
17
2,940
43
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
int = int(input()) print(int*(int-1)/2+int)
s161295900
Accepted
17
2,940
32
n = int(input()) print((n-1)//2)
s227083976
p00003
u386731818
1,000
131,072
Wrong Answer
40
8,760
502
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
import string import sys import math #??????????????\????????????ip?????\?????? ip = sys.stdin.readlines() ip_list = {} for i in range(len(ip)): ip_list[i] = ip[i].strip("\n").split() for i in range(len(ip)): if len(ip_list[i]) == 1: print("YES") else: if int(ip_list[i][0]) != int(ip_list[i][1]): print("NO") elif int(ip_list[i][0]) != int(ip_list[i][2]): print("NO") else: print("YES")
s212667647
Accepted
100
8,692
732
import string import sys import math #??????????????\????????????ip?????\?????? ip = sys.stdin.readlines() ip_list = {} for i in range(len(ip)): ip_list[i] = ip[i].strip("\n").split() for i in range(1,len(ip)): for j in range(3): #????????????????????? for t in range(3): for k in range(3): if int(ip_list[i][t]) > int(ip_list[i][k]): tmp = ip_list[i][t] ip_list[i][t] = ip_list[i][k] ip_list[i][k] = tmp for i in range(1,len(ip)): if int(ip_list[i][0])**2 == int(ip_list[i][1])**2 + int(ip_list[i][2])**2: print("YES") else: print("NO")
s417868271
p00024
u299798926
1,000
131,072
Wrong Answer
20
5,596
105
Ignoring the air resistance, velocity of a freely falling object $v$ after $t$ seconds and its drop $y$ in $t$ seconds are represented by the following formulas: $ v = 9.8 t $ $ y = 4.9 t^2 $ A person is trying to drop down a glass ball and check whether it will crack. Your task is to write a program to help this experiment. You are given the minimum velocity to crack the ball. Your program should print the lowest possible floor of a building to crack the ball. The height of the $N$ floor of the building is defined by $5 \times N - 5$.
import sys for s in sys.stdin: n=float(s[:-1]) t=n/9.8 y=4.9*t**2 N=(y+5)//5 print(N)
s197170170
Accepted
20
5,640
171
import math while(1): try: n=float(input()) t=n/9.8 y=4.9*t**2 N=(y+5)/5 print(math.ceil(N)) except EOFError: break
s830927808
p02400
u023471147
1,000
131,072
Wrong Answer
20
5,632
88
Write a program which calculates the area and circumference of a circle for given radius r.
from math import pi r = float(input()) print("{0:.10} {1:.10}".format(pi*r**2, 2*pi*r))
s270581277
Accepted
20
5,632
88
from math import pi r = float(input()) print("{0:.6f} {1:.6f}".format(pi*r**2, 2*pi*r))
s014575304
p03162
u163501259
2,000
1,048,576
Wrong Answer
603
31,348
492
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 input = sys.stdin.readline def main(): N = int(input()) HAPPY = [list(map(int, input().split())) for i in range(N)] dp = [[0]*3]*(N+1) for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i+1][k] = max(dp[i+1][k], HAPPY[i][k] + dp[i][j]) print(max(max(dp[N][0], dp[N][1]), dp[N][2])) if __name__ == '__main__': main()
s041548198
Accepted
673
47,332
466
import sys input = sys.stdin.readline def main(): N = int(input()) HAPPY = [list(map(int, input().split())) for i in range(N)] dp = [[0]*3 for i in range(N+1)] for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i+1][k] = max(dp[i+1][k], HAPPY[i][k] + dp[i][j]) print(max(max(dp[N][0], dp[N][1]), dp[N][2])) if __name__ == '__main__': main()
s198835065
p03657
u781025961
2,000
262,144
Wrong Answer
17
2,940
126
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
A,B = map(int,input().split()) if A % 3 ==0 or B % 3 ==0 or (A+B) % 3 ==0: print("Possibe") else: print("Impossible")
s161697041
Accepted
21
3,316
127
A,B = map(int,input().split()) if A % 3 ==0 or B % 3 ==0 or (A+B) % 3 ==0: print("Possible") else: print("Impossible")
s661509607
p03251
u884323674
2,000
1,048,576
Wrong Answer
18
3,060
182
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N, M, X, Y = map(int, input().split()) X = [int(i) for i in input().split()] Y = [int(i) for i in input().split()] if min(Y) - max(X) > 1: print("No War") else: print("War")
s415629719
Accepted
17
3,060
300
N, M, X, Y = map(int, input().split()) X_list = [int(i) for i in input().split()] Y_list = [int(i) for i in input().split()] found = False for Z in range(X+1, Y+1): if max(X_list) < Z and min(Y_list) >= Z: found = True print("No War") break if not found: print("War")
s102493863
p02384
u244742296
1,000
131,072
Wrong Answer
30
6,764
1,282
Construct a dice from a given sequence of integers in the same way as
class Dice(object): def __init__(self, s1, s2, s3, s4, s5, s6): self.s1 = s1 self.s2 = s2 self.s3 = s3 self.s4 = s4 self.s5 = s5 self.s6 = s6 def east(self): prev_s6 = self.s6 self.s6 = self.s3 self.s3 = self.s1 self.s1 = self.s4 self.s4 = prev_s6 def west(self): prev_s6 = self.s6 self.s6 = self.s4 self.s4 = self.s1 self.s1 = self.s3 self.s3 = prev_s6 def north(self): prev_s6 = self.s6 self.s6 = self.s5 self.s5 = self.s1 self.s1 = self.s2 self.s2 = prev_s6 def south(self): prev_s6 = self.s6 self.s6 = self.s2 self.s2 = self.s1 self.s1 = self.s5 self.s5 = prev_s6 def top(self): return self.s1 def front(self): return self.s2 def right(self): return self.s3 s1, s2, s3, s4, s5, s6 = map(int, input().split()) dice = Dice(s1, s2, s3, s4, s5, s6) q = int(input()) for i in range(q): t, f = map(int, input().split()) for j in range(4): for k in range(4): if dice.top() == t and dice.front() == f: break dice.east() dice.north() print(dice.right())
s453750045
Accepted
40
6,788
1,581
class Dice(object): def __init__(self, s1, s2, s3, s4, s5, s6): self.s1 = s1 self.s2 = s2 self.s3 = s3 self.s4 = s4 self.s5 = s5 self.s6 = s6 def east(self): prev_s6 = self.s6 self.s6 = self.s3 self.s3 = self.s1 self.s1 = self.s4 self.s4 = prev_s6 def west(self): prev_s6 = self.s6 self.s6 = self.s4 self.s4 = self.s1 self.s1 = self.s3 self.s3 = prev_s6 def north(self): prev_s6 = self.s6 self.s6 = self.s5 self.s5 = self.s1 self.s1 = self.s2 self.s2 = prev_s6 def south(self): prev_s6 = self.s6 self.s6 = self.s2 self.s2 = self.s1 self.s1 = self.s5 self.s5 = prev_s6 def rotate(self): prev_s2 = self.s2 self.s2 = self.s4 self.s4 = self.s5 self.s5 = self.s3 self.s3 = prev_s2 def top(self): return self.s1 def front(self): return self.s2 def right(self): return self.s3 s1, s2, s3, s4, s5, s6 = map(int, input().split()) dice = Dice(s1, s2, s3, s4, s5, s6) q = int(input()) for i in range(q): t, f = map(int, input().split()) flag = False for j in range(6): if j % 2 == 0: dice.north() else: dice.west() for k in range(4): dice.rotate() if dice.top() == t and dice.front() == f: flag = True break if flag: break print(dice.right())
s062270219
p02257
u792145349
1,000
131,072
Wrong Answer
20
7,764
257
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of _N_ integers and prints the number of prime numbers in the list.
N = int(input()) numbers = [int(input()) for i in range(N)] ans = [] def check_prime(n): for i in range(2, N): if n % i == 0: return 0 else: return 1 for n in numbers: ans.append(check_prime(n)) print(sum(ans))
s738164016
Accepted
570
8,472
269
N = int(input()) numbers = [int(input()) for i in range(N)] ans = [] def check_prime(n): for i in range(2, int(n**0.5)+1): if n % i == 0: return 0 else: return 1 for n in numbers: ans.append(check_prime(n)) print(sum(ans))
s441046867
p03814
u031146664
2,000
262,144
Wrong Answer
24
4,840
108
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 = list(input()) fastA = s.index("A") s.reverse() lastZ = len(s) - s.index("Z")+1 print(lastZ - fastA + 1)
s530520743
Accepted
24
4,840
138
s = list(input()) len = len(s) fastA = s.index("A")+1 s.reverse() Ztsal = s.index("Z")+1 lastZ = len - Ztsal + 1 print(lastZ - fastA + 1)
s242001254
p03719
u473023730
2,000
262,144
Wrong Answer
17
2,940
84
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c=map(int,input().split()) if a<=b and b<=c: print("YES") else: print("NO")
s852854980
Accepted
17
2,940
84
a,b,c=map(int,input().split()) if a<=c and c<=b: print("Yes") else: print("No")
s081753769
p02645
u105146481
2,000
1,048,576
Wrong Answer
23
9,044
34
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
s = input() print(s[0],s[1],s[2])
s730407727
Accepted
21
8,888
34
s = input() print(s[0]+s[1]+s[2])
s446991372
p03760
u702786238
2,000
262,144
Wrong Answer
350
21,264
67
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
import numpy as np print(np.array([list(input()), list(input())]))
s933153472
Accepted
17
3,060
262
S1 = list(input()) S2 = list(input()) ans = [] if len(S1) != len(S2): for s1, s2 in zip(S1[:-1], S2): ans.append(s1) ans.append(s2) ans.append(S1[-1]) else: for s1, s2 in zip(S1, S2): ans.append(s1) ans.append(s2) print("".join(ans))
s537617404
p03695
u244836567
2,000
262,144
Wrong Answer
30
9,300
562
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
a=int(input()) b=list(map(int,input().split())) c=0 d=0 e=0 f=0 g=0 h=0 i=0 j=0 k=0 x=0 for z in range(a): if b[z]<=399: c=c+1 if 400<=b[z]<799: d=d+1 if 800<=b[z]<=1199: e=e+1 if 1200<=b[z]<=1599: f=f+1 if 1600<=b[z]<=1999: g=g+1 if 2000<=b[z]<=2399: h=h+1 if 2400<=b[z]<=2799: i=i+1 if 2800<=b[z]<=3199: j=j+1 if b[z]>=3200: k=k+1 if c!=0: x=x+1 if d!=0: x=x+1 if e!=0: x=x+1 if f!=0: x=x+1 if g!=0: x=x+1 if h!=0: x=x+1 if i!=0: x=x+1 if j!=0: x=x+1 if k+x>a: print(a) else: print(k+x)
s769491786
Accepted
31
9,304
615
a=int(input()) b=list(map(int,input().split())) c=0 d=0 e=0 f=0 g=0 h=0 i=0 j=0 k=0 x=0 for z in range(a): if b[z]<=399: c=c+1 if 400<=b[z]<799: d=d+1 if 800<=b[z]<=1199: e=e+1 if 1200<=b[z]<=1599: f=f+1 if 1600<=b[z]<=1999: g=g+1 if 2000<=b[z]<=2399: h=h+1 if 2400<=b[z]<=2799: i=i+1 if 2800<=b[z]<=3199: j=j+1 if b[z]>=3200: k=k+1 if c!=0: x=x+1 if d!=0: x=x+1 if e!=0: x=x+1 if f!=0: x=x+1 if g!=0: x=x+1 if h!=0: x=x+1 if i!=0: x=x+1 if j!=0: x=x+1 if k+x>a: print(x,a) elif (c+d+e+f+g+h+i+j)==0 and k!=0: print(1,k) else: print(x,k+x)
s195813857
p02690
u112629957
2,000
1,048,576
Wrong Answer
23
9,120
197
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
X=int(input()) for a in range(X): if (a+1)**5-a**5 <= X <= (a+1)**+a**5: A=a break for b in range((a+1)**5-a**5,(a+1)**+a**5+1): if (a+1)**5-b**5 == X: B=b break print(a+1, b)
s996507176
Accepted
208
9,176
142
X=int(input()) I=J=0 for i in range(-300,300): for j in range(-300,300): if i**5-j**5==X: I=i J=j break print(I,J)
s369579265
p03047
u729173935
2,000
1,048,576
Wrong Answer
65
3,064
8
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
print(1)
s152760473
Accepted
17
2,940
48
x,y = map(int,input().split()) print( x - y + 1)
s033650084
p03698
u229518917
2,000
262,144
Wrong Answer
17
2,940
59
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
S=input() L=set(S) print('Yes' if len(S)==len(L) else "No")
s899468962
Accepted
17
2,940
59
S=input() L=set(S) print('yes' if len(S)==len(L) else "no")
s172460626
p04029
u399721252
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)
s516924948
Accepted
17
2,940
36
n = int(input()) print((n*(n+1))//2)
s016940377
p02694
u944325914
2,000
1,048,576
Wrong Answer
26
9,160
116
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import math n=int(input()) c=100 for i in range(10**6): c=math.floor(c*1.01) if c>n: print(i+1) break
s576792057
Accepted
28
9,180
107
import math n=int(input()) c=100 for i in range(4000): c=(c*101)//100 if c>=n: print(i+1) break
s747411737
p02612
u234454594
2,000
1,048,576
Wrong Answer
32
9,136
32
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()) x=n%1000 print(x)
s731451886
Accepted
28
9,156
65
n=int(input()) x=n%1000 if x!=0: print(1000-x) else: print(0)
s429182681
p03227
u678980622
2,000
1,048,576
Wrong Answer
20
2,940
87
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
import sys s = sys.stdin.read().lstrip() if len(s) % 2 == 1: s = s[::-1] print(s)
s928657018
Accepted
17
2,940
87
import sys s = sys.stdin.read().rstrip() if len(s) % 2 == 1: s = s[::-1] print(s)
s275691337
p03437
u000349418
2,000
262,144
Time Limit Exceeded
2,104
27,252
232
You are given positive integers X and Y. If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it. If it does not exist, print -1.
n=int(1.0e+18) x,y=map(int,input().split(' ')) X = n//x if x%y==0: print('-1') else: i=2 while i < X: if x*i % y != 0: print(str(x*i)) else: i+=1 if i >= X: print('-1')
s018024450
Accepted
17
3,060
230
n=int(1.0e+18) x,y=map(int,input().split(' ')) X = n//x if x%y==0: print('-1') else: i=2 while i < X: if (x*i)%y!=0: print(str(x*i)) break i+=1 if i >= X: print('-1')
s602175908
p03455
u399721252
2,000
262,144
Wrong Answer
17
2,940
90
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b = map(int, input().split(" ")) if (a * b) % 2 == 0: print("even") else: print("odd")
s238598378
Accepted
18
2,940
90
a,b = map(int, input().split(" ")) if (a * b) % 2 == 0: print("Even") else: print("Odd")
s882571410
p03139
u373295322
2,000
1,048,576
Wrong Answer
17
2,940
52
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
n, a, b = map(int, input().split()) print(min(a, b))
s732182312
Accepted
24
2,940
87
n, a, b = map(int, input().split()) print("{} {}".format(min(a, b), max(a + b - n, 0)))
s787457055
p03637
u588341295
2,000
262,144
Wrong Answer
76
15,020
562
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.
# -*- coding: utf-8 -*- N = int(input()) aN = list(map(int, input().split())) ok = 0 ng = 0 excp = 0 for i in range(N): if aN[i] % 4 == 0: ok += 1 elif (aN[i] + 2) % 4 == 0: excp += 1 else: ng += 1 ng += excp // 2 ng += excp % 2 if ok + 1 >= ng: print("yes") else: print("No")
s325866449
Accepted
76
15,020
577
# -*- coding: utf-8 -*- N = int(input()) aN = list(map(int, input().split())) ok = 0 ng = 0 excp = 0 for i in range(N): if aN[i] % 4 == 0: ok += 1 elif (aN[i] + 2) % 4 == 0: excp += 1 else: ng += 1 if excp > 0: ng += 1 if ok + 1 >= ng: print("Yes") else: print("No")
s907880369
p03609
u437638594
2,000
262,144
Wrong Answer
17
2,940
61
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()) ans = min(0, X-t) print(ans)
s184801442
Accepted
17
2,940
61
X, t = map(int, input().split()) ans = max(0, X-t) print(ans)
s290933405
p02678
u573272932
2,000
1,048,576
Wrong Answer
652
34,076
379
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
from collections import deque N, M = map(int, input().split()) net = [[] for _ in range(N+1)] vect = [0]*(N+1) for _ in range(M): A, B = map(int, input().split()) net[A].append(B) net[B].append(A) q = deque() q.append(1) while len(q)>0: t = q.popleft() for i in net[t]: if t != i and vect[i] == 0: vect[i] = t q.append(i) for i in range(2, N+1): print(vect[i])
s797381168
Accepted
633
33,940
393
from collections import deque print("Yes") N, M = map(int, input().split()) net = [[] for _ in range(N+1)] vect = [0]*(N+1) for _ in range(M): A, B = map(int, input().split()) net[A].append(B) net[B].append(A) q = deque() q.append(1) while len(q)>0: t = q.popleft() for i in net[t]: if t != i and vect[i] == 0: vect[i] = t q.append(i) for i in range(2, N+1): print(vect[i])
s866510199
p02408
u286589639
1,000
131,072
Wrong Answer
20
7,604
569
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
n = int(input()) S = [1]*13 H = [1]*13 C = [1]*13 D = [1]*13 for i in range(n): mark, number = map(str, input().split()) num = int(number) if mark == "S": S[num-1] = 0 if mark == "H": H[num-1] = 0 if mark == "C": C[num-1] = 0 if mark == "H": H[num-1] = 0 for i in range(13): if S[i]: print("S " + str(i+1)) for i in range(13): if H[i]: print("H " + str(i+1)) for i in range(13): if C[i]: print("C " + str(i+1)) for i in range(13): if D[i]: print("D " + str(i+1))
s399991249
Accepted
30
7,648
632
n = int(input()) S = [1]*13 H = [1]*13 C = [1]*13 D = [1]*13 mark = [""]*n num = [""]*n for i in range(n): mark[i], num[i] = input().split() for i in range(n): if mark[i] == "S": S[int(num[i])-1] = 0 if mark[i] == "H": H[int(num[i])-1] = 0 if mark[i] == "C": C[int(num[i])-1] = 0 if mark[i] == "D": D[int(num[i])-1] = 0 for i in range(13): if S[i]: print("S " + str(i+1)) for i in range(13): if H[i]: print("H " + str(i+1)) for i in range(13): if C[i]: print("C " + str(i+1)) for i in range(13): if D[i]: print("D " + str(i+1))
s262663472
p00071
u811733736
1,000
131,072
Wrong Answer
30
7,788
2,980
縦 8、横 8 のマスからなる図1 のような平面があります。その平面上に、いくつかの爆弾が置かれています。図2 にその例を示します(● = 爆弾)。 | □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ | □| □| □| ●| □| □| ●| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| ●| □| □ ●| □| □| □| ●| □| □| ● □| □| ●| □| □| □| ●| □ □| ●| □| □| □| □| □| □ □| □| □| □| ●| □| □| □ ●| □| ●| □| □| □| ●| □ □| ●| □| ●| □| □| ●| □ 図1| 図2 爆弾が爆発すると、その爆弾の上下左右 3 マスに爆風の影響が及び、それらのマスに置かれている爆弾も連鎖的に爆発します。たとえば、図 3 に示す爆弾が爆発すると図 4 の■のマスに爆風の影響が及びます。 | □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| ●| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ | □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| □| □| ■| □| □| □| □ □| □| □| ■| □| □| □| □ □| □| □| ■| □| □| □| □ ■| ■| ■| ●| ■| ■| ■| □ □| □| □| ■| □| □| □| □ □| □| □| ■| □| □| □| □ 図3| 図4 爆弾が置かれている状態と最初に爆発する爆弾の位置を読み込んで、最終的な平面の状態を出力するプログラムを作成してください。
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0071 """ import sys def check_bombs(map, pos, dir, range=3): if dir == 'up': x, y = pos while range > 0 and y > 0: if map[y-1][x] == '1': return (x, y-1) else: y -= 1 range -= 1 elif dir == 'down': x, y = pos while range > 0 and y < len(map)-1: if map[y+1][x] == '1': return (x, y+1) else: y += 1 range -= 1 elif dir == 'left': x, y = pos while range > 0 and x > 0: if map[y][x-1] == '1': return (x-1, y) else: x -= 1 range -= 1 elif dir == 'right': x, y = pos while range > 0 and x < len(map[0])-1: if map[y][x+1] == '1': return (x+1, y) else: x += 1 range -= 1 else: return None def chain_bombs(map, init_pos): lmap = map[:] detonated = [init_pos] while detonated: x, y = detonated.pop() lmap[y][x] = '0' res = check_bombs(lmap, (x, y), 'up') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'down') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'left') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'right') if res: detonated.append(res) return lmap def main(args): data_set = int(input()) maps = [] init_pos = [] for i in range(data_set): _ = input() maps.append([list(input().strip()) for _ in range(8)]) init_pos.append([int(input())-1, int(input())-1]) count = 1 for map, pos in zip(maps, init_pos): result = chain_bombs(map, pos) print('Data {}:'.format(count)) for row in result: print(''.join(row)) if __name__ == '__main__': main(sys.argv[1:])
s696452791
Accepted
20
7,904
2,999
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0071 """ import sys def check_bombs(map, pos, dir, range=3): if dir == 'up': x, y = pos while range > 0 and y > 0: if map[y-1][x] == '1': return (x, y-1) else: y -= 1 range -= 1 elif dir == 'down': x, y = pos while range > 0 and y < len(map)-1: if map[y+1][x] == '1': return (x, y+1) else: y += 1 range -= 1 elif dir == 'left': x, y = pos while range > 0 and x > 0: if map[y][x-1] == '1': return (x-1, y) else: x -= 1 range -= 1 elif dir == 'right': x, y = pos while range > 0 and x < len(map[0])-1: if map[y][x+1] == '1': return (x+1, y) else: x += 1 range -= 1 else: return None def chain_bombs(map, init_pos): lmap = map[:] detonated = [init_pos] while detonated: x, y = detonated.pop() lmap[y][x] = '0' res = check_bombs(lmap, (x, y), 'up') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'down') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'left') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'right') if res: detonated.append(res) return lmap def main(args): data_set = int(input()) maps = [] init_pos = [] for i in range(data_set): _ = input() maps.append([list(input().strip()) for _ in range(8)]) init_pos.append([int(input())-1, int(input())-1]) count = 1 for map, pos in zip(maps, init_pos): result = chain_bombs(map, pos) print('Data {}:'.format(count)) for row in result: print(''.join(row)) count += 1 if __name__ == '__main__': main(sys.argv[1:])
s743725122
p03712
u393512980
2,000
262,144
Wrong Answer
17
3,060
107
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
h,w=map(int,input().split()) a=['#']*(h+2)+['#'+input()+'#' for _ in range(h)]+['#'] for x in a: print(x)
s577073739
Accepted
17
3,060
114
h,w=map(int,input().split()) a=['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)] for x in a: print(x)
s551391631
p02843
u706330549
2,000
1,048,576
Time Limit Exceeded
2,104
3,060
446
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
import sys x = int(input()) total = 0 for a in range(0,1000): for b in range(0,1000): for c in range(0,1000): for d in range(0,1000): for e in range(0,1000): for f in range(0,1000): total = 100*a + 101*b + 102*c + 103*d + 104*e +105*f if x == total: print(1) sys.exit() print(0)
s895212834
Accepted
17
2,940
330
x = int(input()) # i=1 100-105 # i=2 200-210 # i=3 300-315 # i=4 400-420 # i=5 500-525 # i=6 600-630 # i=7 700-735 # i=8 800-840 # i=9 900-945 # ... # i=19 1900-1995 i = x // 100 if 100*i <= x <= 105*i: print(1) else: print(0)
s576401716
p03160
u975389469
2,000
1,048,576
Wrong Answer
178
43,132
652
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 = [int(i) for i in input().split(" ")] dp = [] for i in range(N-1): diff1 = abs(arr[i+1]-arr[i]) if i == N-2: diff2 = diff1 else: diff2 = abs(arr[i+2]-arr[i]) dp.append({ 1: diff1, 2: diff2 }) def getMinSteps(i): total_cost = 0 while i < len(dp): if dp[i][1] > dp[i][2]: total_cost += dp[i][2] i += 2 else: total_cost += dp[i][1] i += 1 return total_cost print(min(dp[0][1] + getMinSteps(1), dp[0][2] + getMinSteps(2)))
s619919588
Accepted
525
21,076
666
from copy import deepcopy N = int(input()) arr = [int(i) for i in input().split(" ")] def getMinSteps(): dp_2 = [0, ] dp_1 = [abs(arr[1] - arr[0]), ] total_cost = 0 i = 2 while i < N: diff1 = abs(arr[i] - arr[i-1]) diff2 = abs(arr[i] - arr[i-2]) temp = deepcopy(dp_2) dp_2 = deepcopy(dp_1) for j in range(len(dp_1)): dp_1[j] += diff1 for j in range(len(temp)): dp_1.append(temp[j] + diff2) dp_1 = sorted(dp_1)[0:2] i += 1 return min(dp_1) print(getMinSteps())
s259687983
p03478
u265118937
2,000
262,144
Wrong Answer
47
9,040
330
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split()) ans = 0 def digitSum(n): s = str(n) array = list(map(int, s)) return sum(array) for i in range(1, n+1): if a <= digitSum(i) <= b: ans += digitSum(i) print(ans)
s261206257
Accepted
36
8,908
320
n, a, b = map(int, input().split()) ans = 0 def digitSum(n): s = str(n) array = list(map(int, s)) return sum(array) for i in range(1, n+1): if a <= digitSum(i) <= b: ans += i print(ans)
s603048327
p03545
u814986259
2,000
262,144
Wrong Answer
17
3,064
400
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
abcd=list(input()) abcd=list(map(int,abcd)) for i in range(2**3): ret=abcd[0] for j in range(3): if (i>>j)%2==1: ret-=abcd[j+1] else: ret+=abcd[j+1] if ret==7: ans=[str(abcd[0])] for j in range(3): if (i>>j)%2==1: ans.append("-") else: ans.append(str(abcd[j+1])) ans.append("=") ans.append("7") print("".join(ans)) exit(0)
s826760666
Accepted
20
3,064
427
ABCD = list(map(int, list(input()))) ans = ['']*9 for i in range(4): ans[i*2] = str(ABCD[i]) for i in range(2**3): ret = ABCD[0] for j in range(3): if (i >> j) % 2 == 1: ret += ABCD[j+1] ans[j*2 + 1] = '+' else: ret -= ABCD[j+1] ans[j*2 + 1] = '-' if ret == 7: ans[7] = '=' ans[8] = '7' print(''.join(ans)) exit(0)
s711691739
p03472
u022215787
2,000
262,144
Wrong Answer
354
11,684
417
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
N, H = map(int, input().split()) a_list = [] b_list = [] for _ in range(N): a,b = map(int, input().split()) a_list.append(a) b_list.append(b) max_a = max(a_list) b_list = [ i for i in b_list if i > max_a ] b_list.sort(reverse = True) total = 0 count = 0 for b in b_list: total += b count += 1 if total > H: break if total < H: count += int(-(-(H - total)) // max_a) print(count)
s770579441
Accepted
354
11,792
449
import math N, H = map(int, input().split()) a_list = [] b_list = [] for _ in range(N): a,b = map(int, input().split()) a_list.append(a) b_list.append(b) max_a = max(a_list) b_list = [ i for i in b_list if i > max_a ] b_list.sort(reverse = True) total = 0 count = 0 for d in b_list: total += d count += 1 if total >= H: break if total < H: x = math.ceil((H - total) / float(max_a)) count += x print(count)
s437354427
p02612
u362855700
2,000
1,048,576
Wrong Answer
31
9,128
90
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.
price = int(input()) a = price % 1000 result = a if a < 0 else 1000 - price print(result)
s297323671
Accepted
29
9,144
124
price = int(input()) a = price % 1000 if a == 0: print(0) elif a < 0: print(1000 - price) else: print(1000 - a)
s442711898
p02389
u948918088
1,000
131,072
Wrong Answer
20
5,584
116
Write a program which calculates the area and perimeter of a given rectangle.
arg = input().split() a = arg[0] b = arg[1] o = str(int(a)*int(b)) o2 = str(2*(int(a)*int(b))) print(o + " " + o2)
s285532269
Accepted
20
5,588
117
arg = input().split() a = arg[0] b = arg[1] o = str(int(a)*int(b)) o2 = str(2*(int(a)+int(b))) print(o + " " + o2)
s578669008
p03069
u781535828
2,000
1,048,576
Wrong Answer
177
9,636
379
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
N = int(input()) S = list(input()) zeros = ["." for i in range(N)] ones = [" lastone = ["." for i in range(N - 1)] lastone.append("#") z = 0 o = 0 l = 0 for i in range(N): if S[i] != zeros[i]: z += 1 for i in range(N): if S[i] != ones[i]: o += 1 for i in range(N): if S[i] != lastone[i]: l += 1 print(min([z, o, l]))
s224666508
Accepted
119
12,836
298
N = int(input()) S = list(input()) bcount = 0 wcount = 0 mins = [] for i in range(N): if S[i] == ".": wcount += 1 mins.append(wcount) for i in range(N): if S[i] == '#': bcount += 1 else: wcount -= 1 mins.append(bcount + wcount) print(min(mins))
s218018555
p04029
u526818929
2,000
262,144
Wrong Answer
29
9,036
41
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 ** 2 + N) / 2)
s377998756
Accepted
25
9,152
42
N = int(input()) print((N ** 2 + N) // 2)
s245754686
p03623
u846150137
2,000
262,144
Wrong Answer
19
3,316
93
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=[int(i) for i in input().split()] if abs(x-a)>abs(x-b): print("A") else: print("B")
s151256589
Accepted
17
2,940
93
n,a,b=[int(i) for i in input().split()] if abs(n-a)<abs(n-b): print("A") else: print("B")
s177920777
p03658
u187205913
2,000
262,144
Wrong Answer
19
2,940
130
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
n,k = map(int,input().split()) l = list(map(int,input().split())) l.sort() ans = 0 for i in range(k): ans += l[-i] print(ans)
s803682484
Accepted
18
2,940
131
n,k = map(int,input().split()) l = list(map(int,input().split())) l.sort() ans = 0 for i in range(k): ans += l[-i-1] print(ans)
s843182342
p02646
u966542724
2,000
1,048,576
Wrong Answer
26
9,192
244
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 = input().split() b = input().split() t = input() d = abs(int(a[0]) - int(b[0])) if (int(a[1]) <= int(b[1])): print('No') else: sek = int(a[1]) - int(b[1]) if d <= int(t)*sek: print('Yes') else : print('No')
s589316635
Accepted
23
9,196
244
a = input().split() b = input().split() t = input() d = abs(int(a[0]) - int(b[0])) if (int(a[1]) <= int(b[1])): print('NO') else: sek = int(a[1]) - int(b[1]) if d <= int(t)*sek: print('YES') else : print('NO')
s832465742
p03251
u875769753
2,000
1,048,576
Wrong Answer
28
9,116
183
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N,M,X,Y = map(int,input().split()) lsx = list(map(int,input().split()))+[X] lsy = list(map(int,input().split()))+[Y] if max(lsx) < min(lsy): print('No war') else: print('War')
s350456568
Accepted
33
9,116
183
N,M,X,Y = map(int,input().split()) lsx = list(map(int,input().split()))+[X] lsy = list(map(int,input().split()))+[Y] if max(lsx) < min(lsy): print('No War') else: print('War')
s464778326
p03408
u844697453
2,000
262,144
Wrong Answer
17
3,064
312
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
ans={} n=int(input()) for i in range(n): a = input() if a in ans: ans[a]+=1 else: ans[a] = 1 m=int(input()) for i in range(m): a = input() if a in ans: ans[a]-=1 else: ans[a] = -1 ans = sorted(ans.items(), key=lambda x: x[1], reverse=True) print(ans[0][0])
s744203374
Accepted
17
3,064
353
ans={} n=int(input()) for i in range(n): a = input() if a in ans: ans[a]+=1 else: ans[a] = 1 m=int(input()) for i in range(m): a = input() if a in ans: ans[a]-=1 else: ans[a] = -1 ans = sorted(ans.items(), key=lambda x: x[1], reverse=True) if ans[0][1] < 0: print(0) else: print(ans[0][1])
s793340762
p03623
u045408189
2,000
262,144
Wrong Answer
18
2,940
60
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()) print(min(abs(a-x),abs(b-x)))
s601055129
Accepted
17
2,940
87
x,a,b=map(int,input().split()) print('A' if min(abs(a-x),abs(b-x))==abs(a-x) else 'B')
s236457008
p03739
u958506960
2,000
262,144
Wrong Answer
2,104
14,332
296
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.
n = int(input()) a = list(map(int, input().split())) cnt = 0 s = a[0] for i in range(1, n): if a[0] > 0: while s + a[i] >= 0: a[i] -= 1 cnt += 1 if a[0] < 0: while s + a[i] <= 0: a[i] += 1 cnt += 1 s += a[i] print(cnt)
s318325228
Accepted
68
14,332
434
n = int(input()) a = list(map(int, input().split())) def f(isPosi): total = 0 cnt = 0 for i in a: total += i if isPosi: if total >= 0: cnt += 1 + total total = -1 isPosi = False else: if total <= 0: cnt += 1 - total total = 1 isPosi = True return cnt print(min(f(True), f(False)))
s013042661
p02795
u007808656
2,000
1,048,576
Wrong Answer
17
2,940
68
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
h=int(input()) w=int(input()) n=int(input()) print(min(h//n,w//n)+1)
s375046320
Accepted
17
2,940
69
h=int(input()) w=int(input()) n=int(input()) print(-max(-n//h,-n//w))
s132004484
p02413
u343748576
1,000
131,072
Wrong Answer
20
7,636
396
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
r, c = [int(x) for x in input().split()] matrix = [] for i in range(r): matrix.append([int(x) for x in input().split()]) for i in range(r): for j in range(c): print(matrix[i][j], '', end='') print(sum(matrix[i])) for j in range(c): csum = 0 for i in range(r): csum += matrix[i][j] print(csum, '', end='') crsum = 0 crsum += csum print(crsum)
s832547245
Accepted
40
8,788
392
r, c = [int(x) for x in input().split()] matrix = [] for i in range(r): matrix.append([int(x) for x in input().split()]) for i in range(r): for j in range(c): print(matrix[i][j], '', end='') print(sum(matrix[i])) crsum = 0 for j in range(c): csum = 0 for i in range(r): csum += matrix[i][j] print(csum, '', end='') crsum += csum print(crsum)
s840818903
p03371
u578953945
2,000
262,144
Wrong Answer
17
3,064
413
"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,AB,X,Y=map(int,input().split()) ANS=0 if A + B >= AB * 2: if min(X,Y) == X: # X < Y ANS = AB * X * 2 R = Y - X if Y - X > 0 else 0 if B <= AB * 2: ANS += B * R else: ANS += AB * 2 * R else: # X > Y ANS = AB * Y * 2 if Y - X > 0 else 0 R = X - Y if A <= AB * 2: ANS += A * R else: ANS += AB * 2 * R else: ANS = A * X + B * Y print(ANS)
s571143874
Accepted
19
3,064
413
A,B,AB,X,Y=map(int,input().split()) ANS=0 if A + B >= AB * 2: if min(X,Y) == X: # X < Y ANS = AB * X * 2 R = Y - X if Y - X > 0 else 0 if B <= AB * 2: ANS += B * R else: ANS += AB * 2 * R else: # X > Y ANS = AB * Y * 2 R = X - Y if X - Y > 0 else 0 if A <= AB * 2: ANS += A * R else: ANS += AB * 2 * R else: ANS = A * X + B * Y print(ANS)
s150201349
p03556
u896741788
2,000
262,144
Wrong Answer
30
9,220
69
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
n=int(input()) for i in range(1,10**3+2): if i**2>n:print((i-1)**2)
s943855604
Accepted
33
9,084
77
n=int(input()) for i in range(1,10**5+2): if i**2>n:print((i-1)**2);exit()
s043692447
p02602
u233032582
2,000
1,048,576
Wrong Answer
188
24,792
288
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
terms, graded_terms = input().split(" ") grade_list = [i for i in input().split(" ")] x1 = 0 x2 = int(graded_terms) for i in range(int(terms)-int(graded_terms)): if grade_list[int(x1)] < grade_list[int(x2)]: print("yes2") else: print("no") x1 += 1 x2 += 1
s687390362
Accepted
203
24,912
287
terms, graded_terms = input().split(" ") grade_list = [i for i in input().split(" ")] x1 = 0 x2 = int(graded_terms) for i in range(int(terms)-int(graded_terms)): if int(grade_list[x2]) > int(grade_list[x1]): print("Yes") else: print("No") x1 += 1 x2 += 1
s973906547
p02401
u202430481
1,000
131,072
Wrong Answer
20
5,600
303
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.
a_list = [str(x) for x in input().split()] a = int(a_list[0]) b = int(a_list[2]) op = a_list[1] if op == '+': ab = a + b print(ab) elif op == '-': ab = a - b print(ab) elif op == '*': ab = a * b print(ab) elif op == '/': ab = a // b print(ab) elif op == '-': exit()
s558579852
Accepted
20
5,600
543
i = 100 for i in range (i): a_list = [str(x) for x in input().split()] a = int(a_list[0]) b = int(a_list[2]) op = a_list[1] if op == '+': ab = a + b print(ab) i = i + 1 continue elif op == '-': ab = a - b print(ab) i = i + 1 continue elif op == '*': ab = a * b print(ab) i = i + 1 continue elif op == '/': ab = a // b print(ab) i = i + 1 continue elif op == '?': exit()
s350033346
p03854
u240096083
2,000
262,144
Wrong Answer
18
3,188
142
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 = str(input()) l = ['dreamer', 'dream', 'eraser', 'erase'] for i in l: s = s.replace(i,'') if s == "": print('OK') else: print('NG')
s126091767
Accepted
69
3,188
421
s = str(input()) s = s[::-1] l = ['resare', 'esare', 'remaerd', 'maerd'] f = 0 if len(s) == 0: f = 1 while len(s) != 0: if s[:7] == 'remaerd': s = s[7::] elif s[:6] == 'resare': s = s[6::] elif s[:5] == 'esare': s = s[5:] elif s[:5] == 'maerd': s = s[5:] else: f = 1 break if f == 1: print("NO") else: print("YES")
s828440080
p03455
u403355272
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.
a,b = map(int,input().split()) if not (a * b // 2 == 0): print('Odd') else: print('Even')
s527783884
Accepted
20
3,060
73
a,b = map(int,input().split()) print("Even" if a * b % 2 == 0 else "Odd")
s957803814
p03447
u617225232
2,000
262,144
Wrong Answer
31
9,160
66
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
z = int(input()) a = int(input()) b = int(input()) print((z-a)//b)
s152541734
Accepted
27
9,112
66
z = int(input()) a = int(input()) b = int(input()) print((z-a)%b)
s832521060
p03023
u995102075
2,000
1,048,576
Wrong Answer
17
2,940
39
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
N = int(input()) print(180 * (N - 3))
s053434965
Accepted
17
2,940
39
N = int(input()) print(180 * (N - 2))
s710348706
p03380
u638456847
2,000
262,144
Wrong Answer
79
14,052
364
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.
import bisect def main(): N = int(input()) a = [int(i) for i in input().split()] a.sort() n = a[-1] m = n // 2 right = bisect.bisect_right(a, m) if a[right-1] == m: r = m elif m - a[right-1] <= a[right] - m: r = a[right-1] else: r = a[right] print(n, r) if __name__ == "__main__": main()
s241340041
Accepted
101
14,052
284
def main2(): N = int(input()) a = [int(i) for i in input().split()] a.sort() n = a[-1] m = n / 2 tmp = 10**10 for i in a: if abs(m - i) < tmp: tmp = abs(m - i) r = i print(n, r) if __name__ == "__main__": main2()
s756292982
p03149
u892796322
2,000
1,048,576
Wrong Answer
17
2,940
113
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
n = input() print(n) if '1' in n and '7' in n and '9' in n and '4' in n: print("YES") else: print("NO") 1
s452501847
Accepted
18
2,940
102
n = input() if '1' in n and '7' in n and '9' in n and '4' in n: print("YES") else: print("NO")
s916616952
p03643
u114954806
2,000
262,144
Wrong Answer
17
2,940
47
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
print("ABC" if 1<=int(input())<=999 else "ABD")
s489851919
Accepted
17
2,940
20
print("ABC"+input())
s704067761
p03469
u839270538
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.
a = input() print("2017"+a[4:])
s242256712
Accepted
17
2,940
32
a = input() print("2018"+a[4:])
s817937548
p03798
u996252264
2,000
262,144
Wrong Answer
133
4,904
787
Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
N = int(input()) t = list(input()) Ans = ['n' for _ in t] def judge(prevSW, SW, ox): if SW == 'S': if ox == 'o': return prevSW else: if prevSW == 'S': return 'W' else: return 'S' elif SW == 'W': if ox == 'x': return prevSW else: if prevSW == 'S': return 'W' else: return 'S' Ans[0] = 'S' for i in range(1,N): if i == 1: Ans[i] = 'S' else: Ans[i] = judge(Ans[i-2], Ans[i-1], t[i-1]) if judge(Ans[-1], Ans[0], t[-1]) is 'S': print("".join(Ans)) else: for i in range(1,N): if i == 1: Ans[i] = 'W' else: Ans[i] = judge(Ans[i-2], Ans[i-1], t[i-1]) print("".join(Ans))
s793420136
Accepted
174
4,900
1,095
N = int(input()) t = list(input()) Ans = ['n' for _ in t] def judge(prevSW, SW, ox): if SW == 'S': if ox == 'o': return prevSW else: if prevSW == 'S': return 'W' else: return 'S' elif SW == 'W': if ox == 'x': return prevSW else: if prevSW == 'S': return 'W' else: return 'S' def decideorder(startSW): Ans[1] = startSW for i in range(2,N): Ans[i] = judge(Ans[i-2], Ans[i-1], t[i-1]) def check(): if judge(Ans[-2], Ans[-1], t[-1]) is Ans[0] and judge(Ans[-1], Ans[0], t[0]) is Ans[1]: return True else: return False Ans[0] = 'S' decideorder('S') if check(): print("".join(Ans)) else: decideorder('W') if check(): print("".join(Ans)) else: Ans[0] = 'W' decideorder('S') if check(): print("".join(Ans)) else: decideorder('W') if check(): print("".join(Ans)) else: print(-1)
s590460904
p03557
u969190727
2,000
262,144
Wrong Answer
2,105
23,092
286
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.
import bisect n=int(input()) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) C=sorted(list(map(int,input().split()))) ans=0 for a in A: b=bisect.bisect_left(B,a+1) print(b) for i in range(n-b): ans+=n-bisect.bisect_left(C,B[b+i]+1) print(ans)
s127837205
Accepted
331
23,200
260
n=int(input()) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] C=[int(i) for i in input().split()] import bisect A.sort() B.sort() C.sort() ans=0 for b in B: ans+=bisect.bisect_left(A,b)*(n-bisect.bisect_right(C,b)) print(ans)
s305158260
p03730
u152614052
2,000
262,144
Wrong Answer
30
8,948
131
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = map(int, input().split()) ans = "No" for i in range(b): if a*i % b == c: ans = "Yes" break print(ans)
s241962298
Accepted
29
8,980
132
a, b, c = map(int, input().split()) ans = "NO" for i in range(b): if a*i % b == c: ans = "YES" break print(ans)
s798553112
p02390
u971748390
1,000
131,072
Wrong Answer
30
6,796
106
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
import math S=int(input()) ; h = S // 3600 ; m= (S % 3600)/60 ; s= m % 60 ; print ("%d:%d:%d"% (h,m,s))
s517374667
Accepted
30
7,672
74
t=int(input()) h=t//3600 m=(t%3600)//60 s=(t%3600)%60 print(h,m,s,sep=":")
s217708219
p03719
u744898490
2,000
262,144
Wrong Answer
17
2,940
123
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
abc = input().split(' ') if int(abc[2]) > int(abc[1]) and int(abc[2]) < int(abc[1]): print('YES') else: print('NO')
s054192493
Accepted
17
2,940
127
abc = input().split(' ') if int(abc[2]) <= int(abc[1]) and int(abc[2]) >= int(abc[0]): print('Yes') else: print('No')
s480776300
p03352
u859210968
2,000
1,048,576
Wrong Answer
17
2,940
152
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
x = int(input()) a = 1 for i in range(1, 10) : for b in range(1, 32) : if( b**i<=x and a<b**i ) : a = b**i print("{}".format(a))
s877970291
Accepted
17
2,940
152
x = int(input()) a = 1 for i in range(2, 10) : for b in range(1, 32) : if( b**i<=x and a<b**i ) : a = b**i print("{}".format(a))
s486710474
p03377
u826929627
2,000
262,144
Wrong Answer
17
2,940
113
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()) _ = X-A if (_ >= 0) and (_ <= B): ans = 'Yes' else: ans = 'No' print(ans)
s341015674
Accepted
17
2,940
113
A,B,X = map(int, input().split()) _ = X-A if (_ >= 0) and (_ <= B): ans = 'YES' else: ans = 'NO' print(ans)
s982728779
p03671
u397563544
2,000
262,144
Wrong Answer
17
2,940
117
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.
s = input() n = len(s)//2 for i in range(1,n): if s[:n-i] == s[n-i:2*(n-i)]: print(2*(n-i)) break
s077848002
Accepted
18
2,940
60
a = list(map(int,input().split())) a.sort() print(a[0]+a[1])
s598578999
p02240
u726330006
1,000
131,072
Time Limit Exceeded
9,990
6,000
971
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
from collections import deque user_num,rer_num=map(int,input().split()) graph=[[] for loop in range(user_num)] for loop in range(rer_num): user1,user2=map(int,input().split()) graph[user1].append(user2) graph[user2].append(user1) group=[-1]*user_num que=deque([]) que.append(0) tmp_group=0 for user in range(user_num): if(group[user]==-1): que.append(user) group[user]=tmp_group while(1): user1=que.popleft() for user2 in graph[user1]: if(group[user2]!=-1): que.append(user2) group[user2]=tmp_group if(len(que)==0): tmp_group+=1 break for loop in range(int(input())): user1,user2=map(int(input())) if(group[user1]==group[user2]): print("yes") else: print("no")
s637993814
Accepted
610
23,556
977
from collections import deque user_num,rer_num=map(int,input().split()) graph=[[] for loop in range(user_num)] for loop in range(rer_num): user1,user2=map(int,input().split()) graph[user1].append(user2) graph[user2].append(user1) group=[-1]*user_num que=deque([]) que.append(0) tmp_group=0 for user in range(user_num): if(group[user]==-1): que.append(user) group[user]=tmp_group while(1): user1=que.popleft() for user2 in graph[user1]: if(group[user2]==-1): que.append(user2) group[user2]=tmp_group if(len(que)==0): tmp_group+=1 break for loop in range(int(input())): user1,user2=map(int,input().split()) if(group[user1]==group[user2]): print("yes") else: print("no")
s828345930
p03228
u067983636
2,000
1,048,576
Wrong Answer
19
3,060
224
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, B, K = map(int, input().split()) for k in range(K): if k % 2 == 0: if A % 2 == 1: A -= 1 A //= 2 B += A // 2 else: if B % 2 == 1: B -= 1 B //= 2 A += B // 2 print(A, B)
s861370076
Accepted
17
2,940
237
A, B, K = map(int, input().split()) for k in range(K): if k % 2 == 0: if A % 2 == 1: A -= 1 B += A // 2 A -= A // 2 else: if B % 2 == 1: B -= 1 A += B // 2 B -= B // 2 print(A, B)
s780058558
p03659
u411923565
2,000
262,144
Wrong Answer
228
32,660
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|.
N = int(input()) A = list(map(int,input().split())) s = [0]*(N+1) for i in range(N-1): s[i+1] = s[i] + A[i] print(s) ans = 10**10 for i in range(1,N): diff = abs((s[N-1] + A[-1] - s[i]) - s[i]) ans = min(ans,diff) print(ans)
s362966414
Accepted
215
30,536
250
N = int(input()) A = list(map(int,input().split())) s = [0]*(N+1) for i in range(N-1): s[i+1] = s[i] + A[i] ans = 10**10 for i in range(1,N): diff = abs((s[N-1] + A[-1] - s[i]) - s[i]) ans = min(ans,diff) print(ans)
s408107526
p02608
u380815663
2,000
1,048,576
Wrong Answer
823
9,320
295
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
N = int(input()) ans = list() for i in range(N): ans.append(0) for x in range(1,100): for y in range(1,100): for z in range(1,100): tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x if tmp < N: ans[tmp] += 1 for i in range(N): print(ans[i])
s447543286
Accepted
935
9,348
306
N = int(input()) ans = [0]*10050 for i in range(N+1): ans.append(0) for x in range(1,105): for y in range(1,105): for z in range(1,105): tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x if tmp < 10050: ans[tmp] += 1 for i in range(N): print(ans[i+1])
s049300233
p03339
u853952087
2,000
1,048,576
Wrong Answer
314
15,392
386
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
n=int(input()) s=input() r=len([i for i in range(1,n) if s[i]=='E']) l=0 print(l,r) i=1 x=n while i<=n-1: if s[i]=='E' and s[i-1]=='E': r=r-1 l=l elif s[i]=='W' and s[i-1]=='W': r=r l=l+1 elif s[i]=='W' and s[i-1]=='E': r=r l=l elif s[i]=='E' and s[i-1]=='W': r=r-1 l=l+1 x=min(l+r,x) i+=1 print(x)
s609422811
Accepted
317
15,520
377
n=int(input()) s=input() r=len([i for i in range(1,n) if s[i]=='E']) l=0 i=1 x=r+l while i<=n-1: if s[i]=='E' and s[i-1]=='E': r=r-1 l=l elif s[i]=='W' and s[i-1]=='W': r=r l=l+1 elif s[i]=='W' and s[i-1]=='E': r=r l=l elif s[i]=='E' and s[i-1]=='W': r=r-1 l=l+1 x=min(l+r,x) i+=1 print(x)
s565429687
p03486
u277802731
2,000
262,144
Wrong Answer
17
3,060
172
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
#82b s=sorted(list(input())) t=sorted(list(input())) ss=''.join(s) tt=''.join(t) ans=sorted([tt,ss]) if ss==tt: print('NO') else: print(['No','Yes'][ans[0]==ss])
s361302696
Accepted
17
3,060
182
#82b s=sorted(list(input())) t=sorted(list(input())) t=t[::-1] ss=''.join(s) tt=''.join(t) ans=sorted([tt,ss]) if ss==tt: print('No') else: print(['No','Yes'][ans[0]==ss])