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
s685930405
p04029
u587295817
2,000
262,144
Wrong Answer
37
3,064
32
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
a=int(input()) print(a*(a+1)/2)
s571030175
Accepted
39
3,064
37
a=int(input()) print(int(a*(a+1)/2))
s801562561
p03698
u912650255
2,000
262,144
Wrong Answer
17
2,940
79
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
S = input() if len(set(S)) == len(S) : print('Yes') else: print('No')
s097191981
Accepted
17
2,940
79
S = input() if len(set(S)) == len(S) : print('yes') else: print('no')
s169122617
p03160
u362771726
2,000
1,048,576
Wrong Answer
48
5,824
1,188
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
import sys from io import StringIO import unittest def resolve(): n = int(input()) h = [0] + list(map(int, input().split())) inf = n * 10 ** 4 + 1 ans = [inf for _ in range(n + 1)] ans[0] = 0 ans[1] = h[0] for i in range(2, n + 1): ans[i] = min(ans[i], ans[i - 1] + abs(h[i] - h[i - 1]), ans[i - 2] + abs(h[i - 2] + h[i - 2])) print(ans[-1]) class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """4 10 30 40 20""" output = """30""" self.assertIO(input, output) def test_入力例_2(self): input = """2 10 10""" output = """0""" self.assertIO(input, output) def test_入力例_3(self): input = """6 30 10 60 10 60 50""" output = """40""" self.assertIO(input, output) if __name__ == "__main__": unittest.main() resolve()
s756988338
Accepted
275
122,620
1,866
import sys from io import StringIO import unittest sys.setrecursionlimit(10 ** 7) def memoize(f): cache={} def helper(*args): if args not in cache: cache[args] = f(*args) return cache[args] return helper def resolve(): n = int(input()) h = list(map(int, input().split())) inf = n * 10 ** 7 memo = [inf for _ in range(n)] def dp(n: int) -> int: if n == 0: return 0 elif n == 1: return abs(h[1] - h[0]) elif memo[n] != inf: return memo[n] else: memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2])) return memo[n] print(dp(n - 1)) class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """4 10 30 40 20""" output = """30""" self.assertIO(input, output) def test_入力例_2(self): input = """2 10 10""" output = """0""" self.assertIO(input, output) def test_入力例_3(self): input = """6 30 10 60 10 60 50""" output = """40""" self.assertIO(input, output) if __name__ == "__main__": #unittest.main() resolve()
s041230140
p03861
u599547273
2,000
262,144
Wrong Answer
17
2,940
60
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a, b, x = map(int, input().split(" ")) print((b+1)//x-a//x)
s173125648
Accepted
17
2,940
60
a, b, x = map(int, input().split(" ")) print(b//x-(a-1)//x)
s978589525
p03672
u074220993
2,000
262,144
Wrong Answer
28
9,136
268
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
s = input() D = {} for c in s: if c in D.keys(): D[c] += 1 else: D[c] = 1 for i in range(len(s)+1): for k in D.values(): if k % 1: break else: ans = len(s)-i break D[s[len(s)-1-i]] -= 1 print(ans)
s966356990
Accepted
28
9,068
467
class mystr: def __init__(self,string): self.value = string def isEven(self): l = len(self.value) if (not l & 1) and self.value[:l//2] == self.value[l//2:]: return True else: return False def pop(self): l = len(self.value) self.value = self.value[:l-1] s = mystr(input()) l = len(s.value) for i in reversed(range(l)): s.pop() if s.isEven(): print(i) break
s955563180
p03599
u929793345
3,000
262,144
Wrong Answer
2,839
9,172
700
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
a, b, c, d, e, f = map(int, input().split()) a *= 100 b *= 100 wat = 0 wat_list = [] for i in range(f//a+1): for j in range(f//b+1): wat = a*i+b*j if 0 < wat <= f: wat_list.append(wat) print(wat_list) sug = 0 conc = 0 sug_max = 0 conc_best = 0 sug_best = 0 sug_wat_best = 0 for k in wat_list: sug_max = k//100 * e for l in range(sug_max // c + 1): for m in range(sug_max //d + 1): sug = c*l+d*m conc = sug/(sug+k)*100 if 0<= sug <= sug_max and k+sug <= f and conc_best < conc : conc_best = conc sug_wat_best = sug + k sug_best = sug print(sug_wat_best, sug_best)
s029408052
Accepted
435
9,192
651
a, b, c, d, e, f = list(map(int, input().rstrip().split())) a *= 100 b *= 100 x, y = a, 0 conc_best = 0 for i in range(f // a + 1): for j in range(((f - a * i) // b) + 1): water = i * a + j * b if water == 0: continue rest = f - water sug_max = e * water / 100 for k in range(rest // c + 1): for l in range((rest - c * k) // d + 1): sugar = c * k + d * l conc = sugar / (sugar + water) if sugar <= sug_max and conc> conc_best: conc_best = conc x, y = sugar+water , sugar print(x, y)
s414936929
p03556
u239342230
2,000
262,144
Wrong Answer
17
2,940
31
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.
print(int(int(input())**.5//1))
s416635664
Accepted
18
2,940
31
print(int(int(input())**.5)**2)
s824664798
p03379
u940102677
2,000
262,144
Wrong Answer
217
25,556
149
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
n = int(input()) x = list(map(int, input().split())) a = x[n//2-1] b = x[n//2-1] for i in range(n): if x[i] <= a: print(b) else: print(a)
s606824339
Accepted
304
26,772
161
n = int(input()) x = list(map(int, input().split())) y = sorted(x) a = y[n//2-1] b = y[n//2] for i in range(n): if x[i] <= a: print(b) else: print(a)
s560658985
p03545
u354126779
2,000
262,144
Wrong Answer
17
3,064
617
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.
seq=input() list=[] for i in range(4): list.append(int(seq[i])) ans=[] brk=0 for a in range (2): for b in range (2): for c in range (2): if list[0]+(2*a-1)*list[1]+(2*b-1)*list[2]+(2*c-1)*list[2]==7: ans.append(a) ans.append(b) ans.append(c) brk+=1 break if brk!=0: break if brk!=0: break A="" B="" C="" if a==0: A="-" else: A="+" if b==0: B="-" else: B="+" if c==0: C="-" else: C="+" print(str(list[0])+A+str(list[1])+B+str(list[2])+C+str(list[3]))
s342461589
Accepted
17
3,064
622
seq=input() list=[] for i in range(4): list.append(int(seq[i])) ans=[] brk=0 for a in range (2): for b in range (2): for c in range (2): if list[0]+(2*a-1)*list[1]+(2*b-1)*list[2]+(2*c-1)*list[3]==7: ans.append(a) ans.append(b) ans.append(c) brk+=1 break if brk!=0: break if brk!=0: break A="" B="" C="" if a==0: A="-" else: A="+" if b==0: B="-" else: B="+" if c==0: C="-" else: C="+" print(str(list[0])+A+str(list[1])+B+str(list[2])+C+str(list[3])+"=7")
s233507029
p03141
u092650292
2,000
1,048,576
Wrong Answer
928
41,348
1,385
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end". Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
from fractions import gcd from math import factorial as f from math import ceil,floor,sqrt from sys import exit from copy import deepcopy import numpy as np import bisect def main(): n = int(input()) a = [] b = [] dif = [] for i in range(n): atmp,btmp = map(int,input().split()) a.append(atmp) b.append(btmp) dif.append([atmp-btmp,i]) adif = sorted(dif, key=lambda x: a[x[1]]) adif = list(reversed(adif)) adif = sorted(adif, key=lambda x: x[0]) bdif = sorted(dif, key=lambda x: b[x[1]], reverse=True) bdif = sorted(bdif, key=lambda x: x[0]) #bdif = list(reversed(bdif)) rem = [1 for i in range(n)] takahashi = 0 aoki = 0 tp = 0 ap = 0 for i in range(ceil(n/2)): while tp < n: if rem[adif[tp][1]]: takahashi += a[adif[tp][1]] rem[adif[tp][1]]=0 # print('tp is ' + str(adif[tp][1])) tp +=1 break else: tp +=1 while ap < n: if rem[bdif[ap][1]]: aoki+= b[bdif[ap][1]] rem[bdif[ap][1]]=0 # print('ap is ' + str(bdif[ap][1])) ap+=1 break else: ap += 1 print(takahashi-aoki) main()
s681116900
Accepted
447
29,940
505
def main(): n = int(input()) a = [] b = [] s = [] for i in range(n): atmp,btmp = map(int,input().split()) a.append(atmp) b.append(btmp) s.append([atmp+btmp,i]) s = sorted(s, key=lambda x: x[0], reverse=True) rem = [1 for i in range(n)] takahashi = 0 aoki = 0 for e,i in enumerate(s): if not e % 2: takahashi += a[i[1]] else: aoki += b[i[1]] print(takahashi-aoki) main()
s887386972
p03679
u813174766
2,000
262,144
Wrong Answer
17
2,940
116
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
a,b,c=map(int,input().split()) if b<=c: print("delicious") elif b<=a+c: print("safe") else: print("dangerous")
s412024555
Accepted
17
3,064
116
a,b,c=map(int,input().split()) if c<=b: print("delicious") elif c<=a+b: print("safe") else: print("dangerous")
s257496483
p03998
u408958033
2,000
262,144
Wrong Answer
18
3,064
303
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
a = input() b = input() c = input() a = list(a) b = list(b) c = list(c) x = 'a' while True: if x=='a': x = a.pop(0) elif x=='b': x = b.pop(0) else: x = c.pop(0) if len(a)==0: print("A") break if len(b)==0: print("B") break if len(c)==0: print("C") break
s309467686
Accepted
17
3,064
288
ss = [input() for _ in range(3)] i = 0 while ss[i % 3] != "": card = ss[i % 3][0] ss[i % 3] = ss[i % 3][1:] if card == "a": i = 0 elif card == "b": i = 1 else: i = 2 if i == 0: print("A") elif i == 1: print("B") else: print("C")
s787283137
p03477
u802977614
2,000
262,144
Wrong Answer
17
2,940
118
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d=map(int,input().split()) if a+b<c+d: print("Left") elif a+b==c+d: print("Balanced") else: print("Right")
s555927501
Accepted
17
2,940
118
a,b,c,d=map(int,input().split()) if a+b>c+d: print("Left") elif a+b==c+d: print("Balanced") else: print("Right")
s387855567
p02398
u498511622
1,000
131,072
Wrong Answer
20
7,492
89
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
x,y,z = map(int,input().split()) i=0 for s in range(x,y): if z%s==0: i += 1 print(i)
s923225933
Accepted
20
7,648
93
a,b,c = map(int,input().split()) i=0 for s in range(a,b+1): if c % s == 0: i += 1 print(i)
s876419156
p03657
u960513073
2,000
262,144
Wrong Answer
17
2,940
119
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 = list(map(int, input().split())) if a%3 ==0 or b%3==0 or a+b%3==0: print("Possible") else: print("Impossible")
s503105319
Accepted
17
2,940
121
a,b = list(map(int, input().split())) if a%3 ==0 or b%3==0 or (a+b)%3==0: print("Possible") else: print("Impossible")
s794930503
p02415
u634490486
1,000
131,072
Wrong Answer
20
5,560
206
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
from sys import stdin s = list(stdin.readline()) print(s) for i in range(len(s)): if s[i].islower(): s[i] = s[i].upper() elif s[i].isupper(): s[i] = s[i].lower() print(*s, sep="")
s523573350
Accepted
20
5,544
72
from sys import stdin s = stdin.readline().swapcase() print(s, end="")
s484189335
p03814
u925406312
2,000
262,144
Wrong Answer
17
3,516
76
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s=input() i=s.find('A') j=s.rfind('Z') print(i) print(j) print(abs(i-j+1))
s278550666
Accepted
18
3,512
57
s=input() i=s.find('A') j=s.rfind('Z') print(abs(i-j)+1)
s407511093
p03385
u807772568
2,000
262,144
Wrong Answer
17
3,064
90
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
a = list(input()) if "a" in a and "b" in a and "c" in a: print("YES") else: print("NO")
s109855260
Accepted
17
2,940
199
d = list(input()) a = 0 b = 0 c = 0 for i in range(3): if d[i] == "a": a = 1 if d[i] == "b": b = 1 if d[i] == "c": c = 1 if a*b*c == 1: print("Yes") else: print("No")
s704731052
p02743
u870262604
2,000
1,048,576
Wrong Answer
18
2,940
151
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a, b, c = map(int,input().split()) left = a+b-c if left <= 0: print("Yes") else: if (a*b - left**2) > 0: print("Yes") else: print("No")
s740863697
Accepted
17
2,940
155
a, b, c = map(int,input().split()) right = c-a-b if right <= 0: print("No") else: if (right**2 - 4*a*b) > 0: print("Yes") else: print("No")
s572953741
p03698
u363118893
2,000
262,144
Wrong Answer
17
2,940
88
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
S = str(input()) if len(list(S)) == len(set(S)): print("Yes") else: print("No")
s345271157
Accepted
17
2,940
88
S = str(input()) if len(list(S)) == len(set(S)): print("yes") else: print("no")
s392063078
p04031
u576917603
2,000
262,144
Wrong Answer
17
3,064
779
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
n=int(input()) a=list(map(int,input().split())) def custom_round(number, ndigits=0): if type(number) == int: return number d_point = len(str(number).split('.')[1]) if ndigits >= d_point: return number c = (10 ** d_point) * 2 return round((number * c + 1) / c, ndigits) ave=custom_round(sum(a)/n) ans=0 for i in a: ans+=(ave-i)**2 print(ans)
s691924474
Accepted
19
3,188
784
n=int(input()) a=list(map(int,input().split())) def custom_round(number, ndigits=0): if type(number) == int: return number d_point = len(str(number).split('.')[1]) if ndigits >= d_point: return number c = (10 ** d_point) * 2 return round((number * c + 1) / c, ndigits) ave=custom_round(sum(a)/n) ans=0 for i in a: ans+=(ave-i)**2 print(int(ans))
s079840962
p02401
u885889402
1,000
131,072
Wrong Answer
30
7,736
265
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while(True): (a,op,b) = [s for s in input().split()] a = int(a) b = int(b) if op == "+": print(a+b) elif op == "-": print(a-b) elif op == "//": print(a/b) elif op == "*": print(a*b) else: break
s717740300
Accepted
20
7,676
265
while(True): (a,op,b) = [s for s in input().split()] a = int(a) b = int(b) if op == "+": print(a+b) elif op == "-": print(a-b) elif op == "/": print(a//b) elif op == "*": print(a*b) else: break
s781943764
p02612
u096025032
2,000
1,048,576
Wrong Answer
30
9,152
77
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.
A = int(input()) if A % 1000 == 0: print(A/1000) else: print(A/1000 + 1)
s491498889
Accepted
29
9,152
62
import math A = int(input()) print(math.ceil(A/1000)*1000-A)
s001415526
p02271
u301461168
5,000
131,072
Wrong Answer
30
7,560
395
Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
numA = int(input().rstrip()) listA = list(map(int,input().rstrip().split(" "))) numQ = int(input().rstrip()) listQ = list(map(int,input().rstrip().split(" "))) sumA = [] cnt = 0 for i in range(numA): for j in range(i+1, numA): sumA.append(listA[i]+listA[j]) for i in range(numQ): if sumA.count(listQ[i]) > 0: #exsits print("yes") else: print("no")
s889154247
Accepted
630
58,252
441
import itertools numA = int(input().rstrip()) listA = list(map(int,input().rstrip().split(" "))) numQ = int(input().rstrip()) listQ = list(map(int,input().rstrip().split(" "))) sumA = set([]) cnt = 0 for i in range(1,numA+1): tmpComb = list(itertools.combinations(listA, i)) for nums in tmpComb: sumA.add(sum(nums)) for i in range(numQ): if listQ[i] in sumA: print("yes") else: print("no")
s521213664
p02692
u858742833
2,000
1,048,576
Wrong Answer
24
9,148
11
There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
print('No')
s807207970
Accepted
181
10,716
731
def main(): N, A, B, C = list(map(int, input().split())) S = [{'AB':(0, 1), 'BC': (1, 2), 'AC': (0, 2)}[input()] for _ in range(N)] ABC = [A, B, C] RR = ['A', 'B', 'C'] R = [] for i, (s1, s2) in enumerate(S): if ABC[s1] == 0 and ABC[s2] == 0: return False, None if ABC[s1] < ABC[s2]: s1, s2 = s2, s1 if A + B + C == 2 and ABC[s1] == 1 and ABC[s2] == 1 and i < N - 1 and S[i] != S[i + 1]: s1n, s2n = S[i + 1] if s1 in [s1n, s2n]: s1, s2 = s2, s1 ABC[s1] -= 1 ABC[s2] += 1 R.append(RR[s2]) return True, R a, s = main() if not a: print('No') else: print('Yes') print('\n'.join(s))
s477144474
p03644
u943057856
2,000
262,144
Time Limit Exceeded
2,104
2,940
128
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n=int(input()) ans=0 for i in range(n): a=0 while int(i%2)==0: a+=1 i=i//2 ans=max(ans,a) print(ans)
s123232155
Accepted
17
2,940
103
n=int(input()) l=[2**i for i in range(8)] for i in l[::-1]: if i<=n: print(i) break
s797122524
p03493
u390958150
2,000
262,144
Wrong Answer
17
2,940
99
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
masu = list(input()) count = 0 for i in range(3): if masu[0] == '1': count += 1 print(count)
s443210295
Accepted
17
2,940
100
masu = list(input()) count = 0 for i in range(3): if masu[i] == '1': count += 1 print(count)
s251497128
p02420
u025362139
1,000
131,072
Wrong Answer
20
5,592
202
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
#coding: UTF-8 while True: str = input() if str == '-': break m = int(input()) for num in range(m): h = int(input()) str = str[h:] + str[:h] print(str)
s880353808
Accepted
20
5,604
272
#coding: UTF-8 shuffle = [] while True: str = input() if str == '-': break m = int(input()) for num in range(m): h = int(input()) str = str[h:] + str[:h] shuffle.append(str) for i in range(len(shuffle)): print(shuffle[i])
s677000984
p00102
u811773570
1,000
131,072
Wrong Answer
30
7,564
353
Your task is to develop a tiny little part of spreadsheet software. Write a program which adds up columns and rows of given table as shown in the following figure:
def main(): while True: n = int(input()) if n == 0: break for i in range(n): num = 0 m = map(int, input().split()) for j in m: print("{:5}".format(j), end='') num += j print("{:5}".format(num)) if __name__ == '__main__': main()
s820275768
Accepted
40
7,920
647
from copy import deepcopy def main(): while True: n = int(input()) if n == 0: break tate = [0 for i in range(n)] for i in range(n): num = 0 m = map(int, input().split()) hoge = deepcopy(m) tate = [x + y for (x, y) in zip(tate, hoge)] for j in m: print("{:5}".format(j), end='') num += j print("{:5}".format(num)) num = 0 for j in tate: print("{:5}".format(j), end='') num += j print("{:5}".format(num)) if __name__ == '__main__': main()
s479167029
p03943
u760831084
2,000
262,144
Wrong Answer
17
2,940
97
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a, b, c = sorted(map(int, input().split())) if a == b + c: print('Yes') else: print('No')
s809029206
Accepted
17
2,940
97
a, b, c = sorted(map(int, input().split())) if a + b == c: print('Yes') else: print('No')
s869750453
p02419
u607723579
1,000
131,072
Wrong Answer
20
5,460
1
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
s239421697
Accepted
20
5,572
328
import sys BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 P = str(input()).upper() line = [] while True: tmp_line = str(input()) if tmp_line == 'END_OF_TEXT': break line += tmp_line.upper().split() ans = 0 for tmp_word in line: if tmp_word == P: ans += 1 print("%d"%(ans))
s184692562
p02401
u982632052
1,000
131,072
Wrong Answer
40
7,300
83
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: s = input() if (s == '0 ? 0'): break print(eval(s))
s692607101
Accepted
30
7,544
112
import re while True: s = input() if (re.match(r'.+\s\?\s.+', s)): break print(int(eval(s)))
s309848053
p03712
u934442292
2,000
262,144
Wrong Answer
17
3,060
157
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 for _a in a: _a = input() print("#" * (W + 2)) for _a in a: print("#{}#".format(_a)) print("#" * (W + 2))
s622208223
Accepted
18
3,060
166
H, W = map(int, input().split()) a = [""] * H for i in range(H): a[i] = input() print("#" * (W+2)) for i in range(H): print("#" + a[i] + "#") print("#" * (W+2))
s266600972
p03139
u814986259
2,000
1,048,576
Wrong Answer
17
2,940
76
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
N,A,B=map(int,input().split()) print(max(0,min(A,B) -(N-max(A,B))),min(A,B))
s617706794
Accepted
17
2,940
76
N,A,B=map(int,input().split()) print(min(A,B),max(0,min(A,B) -(N-max(A,B))))
s546169506
p02612
u015647294
2,000
1,048,576
Wrong Answer
25
9,072
48
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()) L = N // 1000 print((L + 1)-N)
s800832529
Accepted
29
9,160
91
N = int(input()) if (N % 1000) != 0: ans = 1000 - N % 1000 else: ans = 0 print(ans)
s688129548
p03196
u340249922
2,000
1,048,576
Wrong Answer
417
3,060
226
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.
N, P = [int(_c) for _c in input().split(" ")] if N == 1: print(P) else: _max = -1 M = int(P ** (1 / N)) for i in range(1, M): var = i ** N if P % var == 0: _max = i print(_max)
s844548102
Accepted
383
3,060
226
N, P = [int(_c) for _c in input().split(" ")] if N == 1: print(P) else: _max = 1 M = int(P ** (1 / N) + 1.0 * 1e-9) for i in range(1, M + 1): if P % (i ** N) == 0: _max = i print(_max)
s127506155
p03853
u856232850
2,000
262,144
Wrong Answer
19
3,188
167
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
n,m =list(map(int,input().split())) a =[] for i in range(n): a.append(list(input())) b = [] for j in a: b.append(j) b.append(j) for k in b: print(k)
s773566975
Accepted
18
3,060
97
n,m =list(map(int,input().split())) for i in range(n): a = input() print(a) print(a)
s864402019
p02613
u875756191
2,000
1,048,576
Wrong Answer
151
9,136
319
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) a = 0 w = 0 t = 0 r = 0 for _ in range(n): s = input() if s == 'AC': a += 1 elif s == 'WA': w += 1 elif s == 'TLE': t += 1 elif s == 'RE': r += 1 print('AC × ' + str(a)) print('WA × ' + str(w)) print('TLE × ' + str(t)) print('RE × ' + str(r))
s605782671
Accepted
146
9,204
315
n = int(input()) a = 0 w = 0 t = 0 r = 0 for _ in range(n): s = input() if s == 'AC': a += 1 elif s == 'WA': w += 1 elif s == 'TLE': t += 1 elif s == 'RE': r += 1 print('AC x ' + str(a)) print('WA x ' + str(w)) print('TLE x ' + str(t)) print('RE x ' + str(r))
s892929017
p03555
u778700306
2,000
262,144
Wrong Answer
18
2,940
85
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a = input() b = reversed(input()) if a == b: print("YES") else: print("NO")
s489049564
Accepted
18
2,940
81
a = input() b = input()[::-1] if a == b: print("YES") else: print("NO")
s276729936
p03606
u492447501
2,000
262,144
Wrong Answer
20
2,940
125
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
N = int(input()) count = 0 for i in range(N): l, r = map(int, input().split()) count = count + (r-l) print(count)
s522825399
Accepted
21
2,940
129
N = int(input()) count = 0 for i in range(N): l, r = map(int, input().split()) count = count + (r-l) + 1 print(count)
s057543311
p02747
u892308039
2,000
1,048,576
Wrong Answer
17
2,940
109
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
S = input() S_size = len(S) S_hi = S.count('hi') if S_size == S_hi: print('Yes') else: print('No')
s412822681
Accepted
18
2,940
110
S = input() S_size = len(S) S_hi = S.count('hi') if S_size == S_hi*2: print('Yes') else: print('No')
s096604072
p03386
u379692329
2,000
262,144
Wrong Answer
17
3,060
193
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A, B, K = map(int, input().split()) select = [] for i in range(A, min(B, A+K)): select.append(i) for i in range(max(A, B-K+1), B+1): select.append(i) for i in set(select): print(i)
s895520808
Accepted
17
3,060
201
A, B, K = map(int, input().split()) select = [] for i in range(A, min(B, A+K)): select.append(i) for i in range(max(A, B-K+1), B+1): select.append(i) for i in sorted(set(select)): print(i)
s944173668
p03695
u013408661
2,000
262,144
Wrong Answer
17
3,064
458
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.
N=int(input()) rate=[0]*8 tourist=0 a=list(map(int,input().split())) for i in range(N): if 1<=i<399: rate[0]+=1 elif 400<=i<=799: rate[1]+=1 elif 800<=i<=1199: rate[2]+=1 elif 1200<=i<=1599: rate[3]+=1 elif 1600<=i<=1999: rate[4]+=1 elif 2000<=i<=2399: rate[5]+=1 elif 2400<=i<=2799: rate[6]+=1 elif 2800<=i<=3199: rate[7]+=1 elif i<=3200: tourist+=1 print(max(8-rate.count(0),1),8-rate.count(0)+tourist)
s992678396
Accepted
17
3,064
400
N=int(input()) rate=[0]*8 tourist=0 a=list(map(int,input().split())) for i in a: if i<400: rate[0]+=1 elif i<800: rate[1]+=1 elif i<1200: rate[2]+=1 elif i<1600: rate[3]+=1 elif i<2000: rate[4]+=1 elif i<2400: rate[5]+=1 elif i<2800: rate[6]+=1 elif i<3200: rate[7]+=1 else: tourist+=1 print(max(8-rate.count(0),1),max(1,8-rate.count(0)+tourist))
s307392789
p03455
u354126779
2,000
262,144
Wrong Answer
17
2,940
81
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=map(int,input().split()) c=a*b if c%2==0: print("Odd") else: print("Even")
s111596529
Accepted
17
2,940
83
a,b=map(int,input().split()) c=a*b if c%2==0: print("Even") else: print("Odd")
s293582592
p03494
u642120132
2,000
262,144
Time Limit Exceeded
2,104
2,940
144
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
_ = input() a = list(map(int, input().split())) cnt = 0 while all(i % 2 == 0 for i in a): for j in a: j /= 2 cnt += 1 print(cnt)
s910500292
Accepted
18
3,060
140
_ = input() a = list(map(int, input().split())) cnt = 0 while all(i % 2 == 0 for i in a): a = [j / 2 for j in a] cnt += 1 print(cnt)
s083683202
p03827
u963903527
2,000
262,144
Wrong Answer
17
2,940
125
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
n = input() s = input() li = list(s) x = 0 for argv in li: if argv == "I": x += 1 elif argv == "D": x -= 1 print(x)
s436171933
Accepted
19
3,060
217
n = input() s = input() li = list(s) x = 0 num_list = list() num_list.append(0) for argv in li: if argv == "I": x += 1 num_list.append(x) elif argv == "D": x -= 1 num_list.append(x) print(max(num_list))
s735408853
p03909
u902151549
2,000
262,144
Wrong Answer
18
3,060
196
There is a grid with H rows and W columns. The square at the i-th row and j-th column contains a string S_{i,j} of length 5. The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet. Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location. For example, the square at the 6-th row and 8-th column should be reported as `H6`.
h,w=map(int,input().split()) A=[input().split() for _ in range(h)] for a in range(h): for b in range(w): if A[a][b]=="snuke": print("{}{}".format(a+1,chr(ord("A")+b))) break
s071064858
Accepted
17
3,060
193
h,w=map(int,input().split()) A=[input().split() for _ in range(h)] for a in range(h): for b in range(w): if A[a][b]=="snuke": print("{1}{0}".format(a+1,chr(ord("A")+b))) break
s662713812
p02612
u331640179
2,000
1,048,576
Wrong Answer
2,205
9,116
56
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()) while n < 1000: n //= 1000 print(n)
s260496376
Accepted
29
9,156
62
n = int(input()) while n > 1000: n -= 1000 print(1000 - n)
s264702627
p03971
u062691227
2,000
262,144
Wrong Answer
69
9,244
318
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.
x, s = *open(0), n, a, b = map(int, x.split()) p = 0 wp = 0 for char in s: if char == 'c' or p >= a+b: print('No') continue if char == 'a': p += 1 print('Yes') continue if wp < b: p += 1 wp += 1 print('Yes') else: print('No')
s556362937
Accepted
72
9,192
323
x = input() s = input() n, a, b = map(int, x.split()) p = 0 wp = 0 for char in s: if char == 'c' or p >= a+b: print('No') continue if char == 'a': p += 1 print('Yes') continue if wp < b: p += 1 wp += 1 print('Yes') else: print('No')
s478794359
p03682
u711238850
2,000
262,144
Wrong Answer
2,113
147,592
3,980
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
import heapq class Graph: def __init__(self,v,edgelist,w_v = None,directed = False): super().__init__() self.v = v self.w_e = [{} for _ in [0]*self.v] self.neighbor = [[] for _ in [0]*self.v] self.w_v = w_v self.directed = directed for i,j,w in edgelist: self.w_e[i][j] = w self.neighbor[i].append(j) def dijkstra(self,v_n): d = [float('inf')]*self.v d[v_n] = 0 prev = [-1]*self.v queue = [] for i,d_i in enumerate(d): heapq.heappush(queue,(d_i,i)) while len(queue)>0: d_u,u = queue.pop() if d[u]<d_u :continue for v in self.neighbor[u]: alt = d[u]+self.w_e[u][v] if d[v]>alt: d[v] = alt prev[v] = u heapq.heappush(queue,(alt,v)) return d,prev def warshallFloyd(self): d = [[10**18]*self.v for _ in [0]*self.v] for i in range(self.v): d[i][i] = 0 for i in range(self.v): for j in self.neighbor[i]: d[i][j] = self.w_e[i][j] for i in range(self.v): for j in self.neighbor[i]: d[i][j] = self.w_e[i][j] for k in range(self.v): for i in range(self.v): for j in range(self.v): check = d[i][k] + d[k][j] if d[i][j] > check: d[i][j] = check return d def prim(self): gb = GraphBuilder(self.v,self.directed) queue = [] for i,w in self.w_e[0].items(): heapq.heappush(queue,(w,0,i)) rest = [True]*self.v rest[0] = False while len(queue)>0: w,i,j = heapq.heappop(queue) if rest[j]: gb.addEdge(i,j,w) rest[j] = False for k,w in self.w_e[j].items(): heapq.heappush(queue,(w,j,k)) return gb class Tree(): def __init__(self,v,e): pass class GraphBuilder(): def __init__(self,v,directed = False): self.v = v self.directed = directed self.edge = [] def addEdge(self,i,j,w=1): if not self.directed: self.edge.append((j,i,w)) self.edge.append((i,j,w)) def addEdges(self,edgelist,weight = True): if weight: if self.directed: for i,j,w in edgelist: self.edge.append((i,j,w)) else: for i,j,w in edgelist: self.edge.append((i,j,w)) self.edge.append((j,i,w)) else: if self.directed: for i,j,w in edgelist: self.edge.append((i,j,1)) else: for i,j,w in edgelist: self.edge.append((i,j,1)) self.edge.append((j,i,1)) def addAdjMat(self, mat): for i,mat_i in enumerate(mat): for j,w in enumerate(mat_i): self.edge.append((i,j,w)) def buildTree(self): pass def buildGraph(self): return Graph(self.v,self.edge,directed=self.directed) def main(): n= int(input()) edge = [] for i in range(n): x,y = list(map(int,input().split())) edge.append((x,y,i)) xs = sorted(edge,key=lambda a:a[0]) ys = sorted(edge,key=lambda a:a[1]) edge = [] for i in range(n-1): x1,y1,p1 = xs[i] x2,y2,p2 = xs[i+1] edge.append((p1,p2,min(x2-x1,y2-y1))) x1,y1,p1 = ys[i] x2,y2,p2 = ys[i+1] edge.append((p1,p2,y2-y1)) gb = GraphBuilder(n) gb.addEdges(edge) mint = gb.buildGraph().prim() print(mint.edge) ans = 0 for a in mint.edge: ans+=a[2] print(ans//2) if __name__ == "__main__": main()
s583514615
Accepted
1,236
49,016
1,630
class UnionFind: def __init__(self,n): super().__init__() self.par = [-1]*n self.rank = [0]*n self.tsize = [1]*n def root(self,x): if self.par[x] == -1: return x else: self.par[x] = self.root(self.par[x]) return self.par[x] def unite(self, x, y): x_r = self.root(x) y_r = self.root(y) if self.rank[x_r]>self.rank[y_r]: self.par[y_r] = x_r elif self.rank[x_r]<self.rank[y_r]: self.par[x_r] = y_r elif x_r != y_r: self.par[y_r] = x_r self.rank[x_r] += 1 if x_r != y_r: size = self.tsize[x_r]+self.tsize[y_r] self.tsize[x_r] = size self.tsize[y_r] = size def isSame(self,x,y): return self.root(x) == self.root(y) def size(self,x): return self.tsize[self.root(x)] def main(): n= int(input()) edge = [] for i in range(n): x,y = list(map(int,input().split())) edge.append((x,y,i)) xs = sorted(edge,key=lambda a:a[0]) ys = sorted(edge,key=lambda a:a[1]) edge = [] for i in range(n-1): x1,y1,p1 = xs[i] x2,y2,p2 = xs[i+1] edge.append((p1,p2,min(x2-x1,abs(y2-y1)))) x1,y1,p1 = ys[i] x2,y2,p2 = ys[i+1] edge.append((p1,p2,min(abs(x2-x1),y2-y1))) edge.sort(key = lambda a:a[2]) uf = UnionFind(n) ans = 0 for x,y,w in edge: if uf.isSame(x,y):continue uf.unite(x,y) ans+=w print(ans) if __name__ == "__main__": main()
s924851114
p03385
u702208001
2,000
262,144
Wrong Answer
17
2,940
49
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
print('YES' if len(set(input())) == 3 else 'No')
s185403068
Accepted
17
2,940
49
print('Yes' if len(set(input())) == 3 else 'No')
s098182958
p04044
u681323954
2,000
262,144
Wrong Answer
17
2,940
43
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
s=input() print(s[0]+str((len(s)-2))+s[-1])
s132647828
Accepted
17
3,060
89
n,l = map(int, input().split()) s = sorted([input() for i in range(n)]) print(*s, sep="")
s692745959
p03433
u936047618
2,000
262,144
Wrong Answer
24
9,156
108
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input("N--->")) a = int(input("A--->")) b = n%500 if a > b: print("Yes") else: print("No")
s456381059
Accepted
23
9,024
95
N = int(input()) A = int(input()) b = N%500 if A >= b: print("Yes") else: print("No")
s860239899
p03998
u136395536
2,000
262,144
Time Limit Exceeded
2,104
7,660
147
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
A = input() B = input() C = input() moji = A[0] while(len(A)!=0 or len(B)!=0 or len(C)!=0): if moji == "a": A = A[2:] print(A)
s125375615
Accepted
17
3,064
466
A = input() B = input() C = input() throw = "a" a = 0 b = 0 c = 0 while True: if throw == "a": if a == len(A): print("A") break throw = A[a] a += 1 elif throw == "b": if b == len(B): print("B") break throw = B[b] b += 1 elif throw == "c": if c == len(C): print("C") break throw = C[c] c += 1
s839210880
p03407
u007550226
2,000
262,144
Wrong Answer
18
2,940
65
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
A,B,C = map(int,input().split()) print('Yes' if A+B<=C else 'No')
s858484192
Accepted
17
2,940
65
A,B,C = map(int,input().split()) print('Yes' if A+B>=C else 'No')
s412390440
p03574
u576917603
2,000
262,144
Wrong Answer
36
3,188
542
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
dx=[-1,0,1,-1,1,-1,0,1] dy=[-1,-1,-1,0,0,1,1,1] h,w=map(int,input().split()) field = [] for i in range(h): field.append(list(input())) print(field) for y in range(h): for x in range(w): if field[y][x]=="#": continue cnt=0 for k in range(8): nx=x+dx[k] ny=y+dy[k] if nx<0 or nx>=w or ny<0 or ny>=h: continue if field[ny][nx]=="#": cnt+=1 field[y][x]=str(cnt) for i in range(h): print("".join(field[i]))
s690134319
Accepted
31
3,188
524
dx=[-1,0,1,-1,1,-1,0,1] dy=[-1,-1,-1,0,0,1,1,1] h,w=map(int,input().split()) field = [] for i in range(h): field.append(list(input())) for y in range(h): for x in range(w): if field[y][x]=="#": continue cnt=0 for k in range(8): nx=x+dx[k] ny=y+dy[k] if nx<0 or nx>=w or ny<0 or ny>=h: continue if field[ny][nx]=="#": cnt+=1 field[y][x]=str(cnt) for i in range(h): print("".join(field[i]))
s518526979
p02612
u257332942
2,000
1,048,576
Wrong Answer
35
9,076
58
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()) while n >= 1000: n -= 1000 print(n)
s310163142
Accepted
27
9,152
79
n = int(input()) a = n % 1000 if a == 0: print(0) else: print(1000-a)
s637826951
p02975
u712397093
2,000
1,048,576
Wrong Answer
114
14,212
137
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
N = int(input()) a = list(map(int, input().split())) sum = 0 for i in range(N): sum ^= a[i] print('Yes' if sum == 0 else 'No')
s259490528
Accepted
58
14,116
133
N = int(input()) a = list(map(int, input().split())) sum = 0 for i in range(N): sum ^= a[i] print('Yes' if sum == 0 else 'No')
s815858999
p03729
u830054172
2,000
262,144
Wrong Answer
17
2,940
107
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a, b, c = list(input().split()) if a[-1] == b[0] and b[-1] == c[0]: print("Yes") else: print("No")
s750049035
Accepted
17
2,940
107
a, b, c = list(input().split()) if a[-1] == b[0] and b[-1] == c[0]: print("YES") else: print("NO")
s690954974
p03657
u701318346
2,000
262,144
Wrong Answer
17
2,940
125
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) == 0: print('Possible') else: print('Impossible')
s347788193
Accepted
24
3,316
132
A, B = map(int, input().split()) if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0: print('Possible') else: print('Impossible')
s519717271
p03854
u110927356
2,000
262,144
Wrong Answer
1,655
21,708
461
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
import math import numpy as np #n, a, b = map(int, input().split()) #print(len(z)) # print(i) #print(sum(a[::2]) - sum(a[1::2])) s = input() s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") if s: print("NO") else: print("YES")
s826395133
Accepted
1,349
21,876
466
import math import numpy as np #n, a, b = map(int, input().split()) #print(len(z)) # print(i) #print(sum(a[::2]) - sum(a[1::2])) s = input() s = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") if s: print("NO") else: print("YES")
s446234187
p03545
u468206018
2,000
262,144
Wrong Answer
17
3,064
435
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.
s = list(input()) def calc(i, a, b,tag): a ,b = int(a), int(b) if i==0: c = a+b tag.append('+') elif i==1: c = a-b tag.append('-') return c, tag for i in range(2): tag = [] c ,tag= calc(i,s[0],s[1],tag) for j in range(2): d ,tag = calc(j,c,s[2],tag) for k in range(2): e ,tag = calc(k,d,s[3],tag) if e == 7: print(s[0]+tag[0]+s[1]+tag[1]+s[2]+tag[2]+s[3]) exit()
s968412314
Accepted
18
3,064
522
s = list(input()) def calc(i, a, b): a ,b = int(a), int(b) if i==0: c = a+b elif i==1: c = a-b return c def tag(t_list): t = [] for p in t_list: if p==0: t.append('+') else: t.append('-') return(t) for i in range(2): c = calc(i,s[0],s[1]) for j in range(2): d = calc(j,c,s[2]) for k in range(2): e = calc(k,d,s[3]) if e == 7: t_list = [i,j,k] t = tag(t_list) print(s[0]+t[0]+s[1]+t[1]+s[2]+t[2]+s[3]+'=7') exit()
s694050670
p03369
u331036636
2,000
262,144
Wrong Answer
18
2,940
103
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
S = input() price = 700 for i in range(len(S)): if S[i] == "○": price += 100 print(price)
s154745777
Accepted
17
2,940
107
S = list(input()) price = 700 for i in range(len(S)): if S[i] == "o": price += 100 print(price)
s562956888
p03486
u429319815
2,000
262,144
Wrong Answer
17
2,940
195
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = input() S = "".join(sorted(s)) t = input() T = "".join(sorted(t)) if S < T: print("Yes") else: print("No")
s352114037
Accepted
17
2,940
176
s = sorted(list(input())) t = sorted(list(input()), reverse=True) s_sorted = "".join(s) t_sorted = "".join(t) if s_sorted < t_sorted: print("Yes") else: print("No")
s649634201
p03610
u525117558
2,000
262,144
Wrong Answer
18
3,444
52
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s=[input().split()] for i in s[::2]: print(s[::2])
s789365121
Accepted
17
3,188
23
s=input() print(s[::2])
s227439201
p00003
u585035894
1,000
131,072
Wrong Answer
40
5,592
146
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.
for _ in range(int(input())): l = list(map(int, input().split())) l.sort() print('YES' if l[0]**2 + l[1] ** 2 == l[2] ** 2 else 'No')
s816231591
Accepted
50
5,604
169
for _ in range(int(input())): a = [int(i) for i in input().split()] print('YES') if a[0]**2 + a[1]**2 + a[2] ** 2 - max(a) **2 == max(a) ** 2 else print('NO')
s841627228
p03351
u333731247
2,000
1,048,576
Wrong Answer
21
2,940
104
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d=map(int,input().split()) if abs(a-b)<d and abs(b-c)<d: print('Yes') else : print('No')
s248730098
Accepted
17
2,940
141
a,b,c,d=map(int,input().split()) if abs(a-b)<=d and abs(b-c)<=d: print('Yes') elif abs(a-c)<=d: print('Yes') else : print('No')
s649068366
p02389
u095590628
1,000
131,072
Wrong Answer
20
5,588
60
Write a program which calculates the area and perimeter of a given rectangle.
ab = [int(n) for n in input().split()] print(ab[0]*ab[1])
s004258845
Accepted
20
5,608
113
ab = [int(n) for n in input().split()] S = ab[0]*ab[1] L = 2*ab[0] + 2*ab[1] print(" ".join(map(str,[S,L])))
s084660637
p03386
u901582103
2,000
262,144
Wrong Answer
2,217
1,839,640
105
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a,b,k=map(int,input().split()) l=[i for i in range(a,b+1)] for s in list(set(l[:k]+l[-k:])): print(s)
s671409885
Accepted
19
3,060
158
a,b,k=map(int,input().split()) s=[i for i in range(a,min(a+k,b+1))] l=[i for i in range(b,max(b-k,a-1),-1)] L=list(set(s+l)) L.sort() for i in L: print(i)
s298577420
p03456
u710921979
2,000
262,144
Wrong Answer
17
2,940
100
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a,b=map(int,input().split()) n=int(a+b) if n==int(n**0.5)**2: print('YES') else: print('NO')
s289605471
Accepted
17
3,060
100
a,b=map(str,input().split()) n=int(a+b) if n==int(n**0.5)**2: print("Yes") else: print("No")
s380498849
p03610
u479638406
2,000
262,144
Wrong Answer
2,104
3,956
94
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = list(input()) for i in range(len(s)): if i%2 == 0: odd = ''.join(s) print(odd)
s049498051
Accepted
38
4,388
122
s = list(input()) t = [] for i in range(len(s)): if i%2 == 0: t.append(s[i]) odd = ''.join(t) print(odd)
s347166281
p03149
u078349616
2,000
1,048,576
Wrong Answer
17
3,060
172
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".
A = list(map(int, input().split())) A1 = A.count("1") A9 = A.count("9") A7 = A.count("7") A4 = A.count("4") if A1 == A9 == A7 == A4 == 1: print("YES") else: print("NO")
s956326800
Accepted
17
3,060
164
A = list(map(int, input().split())) A1 = A.count(1) A9 = A.count(9) A7 = A.count(7) A4 = A.count(4) if A1 == A9 == A7 == A4 == 1: print("YES") else: print("NO")
s964706722
p03759
u090225501
2,000
262,144
Wrong Answer
17
2,940
89
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a, b, c = map(int, input().split()) if b - a == c - a: print('YES') else: print('NO')
s108253002
Accepted
17
2,940
89
a, b, c = map(int, input().split()) if b - a == c - b: print('YES') else: print('NO')
s624743000
p02742
u268792407
2,000
1,048,576
Wrong Answer
17
2,940
57
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
h,w=map(int,input().split()) print(((h+1)//2)*((w+1)//2))
s970710133
Accepted
18
2,940
171
h,w=map(int,input().split()) if h==1 or w==1: print(1) exit() if h%2==1 and w%2==1: a1=((h+1)//2)*(w+1)//2 a2=(h//2)*(w//2) print(a1+a2) else: print((h*w)//2)
s079294836
p03433
u057415180
2,000
262,144
Wrong Answer
17
2,940
84
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input()) a = list(map(int,input().split())) print(sum(a[::2])-sum(a[1::2]))
s923695169
Accepted
17
2,940
88
n = int(input()) a = int(input()) if n%500 <= a: print('Yes') else: print('No')
s762037547
p02607
u124212130
2,000
1,048,576
Wrong Answer
29
9,104
168
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
N = int(input()) Mylist = input().split() Mylist = [int(s) for s in Mylist] ANS = 0 for i in range(N): if i+1 % 2 == 1 and Mylist[i] % 2 == 1: ANS += 1 print(ANS)
s684776705
Accepted
31
9,160
173
N = int(input()) Mylist = input().split() Mylist = [int(s) for s in Mylist] ANS = 0 for i in range(1,N+1): if i % 2 == 1 and Mylist[i-1] % 2 == 1: ANS += 1 print(ANS)
s898989213
p03854
u460878159
2,000
262,144
Wrong Answer
18
3,188
953
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
S=input() l=len(S) r=0 amari = [1,2,3,4] list5 = ['dream', 'erase'] list81 = ['dreamdre', 'dreamera', 'erasedre', 'eraseera'] list82 = ['dreamerd', 'dreamere', 'eraserdre', 'eraserera'] if l<=4: print(False) while l>=5: if S[r:r+5] in list5: if r+5==l: print(True) break elif r+5 == l-1: if S[r:r+6] == 'eraser': print(True) else: print(False) break elif r+5 == l-2: if S[r:r+7] == 'dreamer': print(True) else: print(False) break elif r+5 == l-3 or r+5 == l-4: print(False) break else: if S[r:r+8] in list81: r=r+5 elif S[r:r+8] in list82: r=r+7 else: print(False) break else: print(False) break
s678410282
Accepted
40
3,316
1,000
S=input() l=len(S) r=0 list5 = ['dream', 'erase'] list81 = ['dreamdre', 'dreamera', 'erasedre', 'eraseera'] list82 = ['dreamerd', 'dreamere'] list83 = ['eraserdr', 'eraserer'] if l<=4: print('NO') while l>=5: if S[r:r+5] in list5: if r+5==l: print('YES') break elif r+5 == l-1: if S[r:r+6] == 'eraser': print('YES') else: print('NO') break elif r+5 == l-2: if S[r:r+7] == 'dreamer': print('YES') else: print('NO') break elif r+5 == l-3 or r+5 == l-4: print('NO') break else: if S[r:r+8] in list81: r=r+5 elif S[r:r+8] in list82: r=r+7 elif S[r:r+8] in list83: r=r+6 else: print('NO') break else: print('NO') break
s811603379
p03493
u266874640
2,000
262,144
Wrong Answer
17
2,940
83
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
S = input() result =0 for i in S: if i == 1: result += 1 print(result)
s375047803
Accepted
20
2,940
88
S = input() result =0 for i in S: if i == str(1): result += 1 print(result)
s411642124
p03449
u917558625
2,000
262,144
Wrong Answer
29
9,144
228
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
N=int(input()) p=[0] q=[0] A1=list(map(int,input().split())) A2=list(map(int,input().split())) for i in range(N): p.append(p[i]+A1[N-i-1]) q.append(q[i]+A2[i]) ans=0 for j in range(N): ans=max(ans,p[j+1]+q[j+1]) print(ans)
s353854854
Accepted
32
9,144
228
N=int(input()) p=[0] q=[0] A1=list(map(int,input().split())) A2=list(map(int,input().split())) for i in range(N): p.append(p[i]+A1[i]) q.append(q[i]+A2[N-i-1]) ans=0 for j in range(N): ans=max(ans,p[j+1]+q[N-j]) print(ans)
s563762869
p03493
u903005414
2,000
262,144
Wrong Answer
17
2,940
50
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
s = input() print(sum([1 for i in s if s == '1']))
s116132254
Accepted
18
2,940
45
print(sum([1 for i in input() if i == '1']))
s404051727
p03698
u136869985
2,000
262,144
Wrong Answer
18
2,940
53
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s=input() print(['no', 'ues'][len(set(s)) == len(s)])
s219525263
Accepted
17
2,940
53
s=input() print(['no', 'yes'][len(set(s)) == len(s)])
s420949430
p03796
u450904670
2,000
262,144
Wrong Answer
17
2,940
100
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
n = int(input()) res = 1 for num in (1, n+1): res = res * num res = res % (10**9 + 7) print(res)
s422534863
Accepted
40
2,940
110
n = int(input()) res = 1 for num in range(1, n+1): res = res * num res = res % (10**9 + 7) print(res)
s773738886
p02618
u595833382
2,000
1,048,576
Wrong Answer
151
27,304
613
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
import numpy as np D = int(input()) C = ([int(x) for x in input().split()]) for d in range(D): exec('s{} = ([int(x) for x in input().split()])'.format(d)) S = 0 d = 0 lday = np.array([0] * 26) C = np.array(C) while d != D: exec("curs = np.array(s{})".format(d)) pos_max_i = np.argmax(curs) neg_min_i = np.argmin(C * ( np.array([d]*26 ) * lday )) if np.abs(curs[pos_max_i]) > np.abs(curs[neg_min_i]): S += curs[pos_max_i] lday[pos_max_i] = d print(pos_max_i) else: S += curs[neg_min_i] lday[neg_min_i] = d print(neg_min_i) d += 1
s119649056
Accepted
148
27,400
569
import numpy as np D = int(input()) C = ([int(x) for x in input().split()]) for d in range(D): exec('s{} = ([int(x) for x in input().split()])'.format(d)) d = 0 lday = np.array([0] * 26) C = np.array(C) while d != D: exec("curs = np.array(s{})".format(d)) pos_max_i = np.argmax(curs) decl = C * ( np.array([d]*26 ) - lday ) neg_min_i = np.argmin(decl) if np.abs(curs[pos_max_i]) > np.abs(decl[neg_min_i]): lday[pos_max_i] = d print(pos_max_i+1) else: lday[neg_min_i] = d print(neg_min_i+1) d += 1
s077701312
p03438
u867069435
2,000
262,144
Wrong Answer
1,087
21,492
272
You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
import numpy as np n = int(input()) a = np.array(list(map(int, input().split()))) b = np.array(list(map(int, input().split()))) if np.sum(b[a < b] - a[a < b]) > np.sum(a[b < a] - b[b < a]): print("No") elif np.sum(a) > np.sum(b): print("No") else: print("Yes")
s466596303
Accepted
30
4,596
562
import math n = int(input()) lis1 = list(map(int,input().split())) lis2 = list(map(int,input().split())) k = 0 c = 0 s = 0 cou = sum(lis2)-sum(lis1) if cou < 0: print("No") else: for i in range(n): if lis1[i] < lis2[i]: c += math.ceil((lis2[i] - lis1[i]) / 2) if (lis2[i] - lis1[i])%2 == 0: k += 1 else: s += 1 if c > cou: print("No") elif c == cou: print("Yes") else: if k >= 1: print("Yes") else: print("No")
s373192185
p03435
u641722141
2,000
262,144
Wrong Answer
17
3,060
237
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.
l =[list(map(int, input().split())) for i in range(3)] total1 = total2 = 0 for i in range(3): total1 += sum(l[i]) total2 += l[i][i] print(total1, total2) if total1 == total2 * 3: print('Yes') else: print('No')
s353498167
Accepted
17
2,940
214
l = [[int(i) for i in input().split()] for x in range(3)] total1 = 0 total2 = 0 for i in range(3): total1 += sum(l[i]) total2 += l[i][i] if total1 == total2 * 3: print('Yes') else: print('No')
s722244719
p03165
u102461423
2,000
1,048,576
Wrong Answer
531
82,760
843
You are given strings s and t. Find one longest string that is a subsequence of both s and t.
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np S = np.frombuffer(readline().rstrip(),'S1') T = np.frombuffer(readline().rstrip(),'S1') S,T def LCS(S,T): LS = len(S); LT = len(T) dp = np.zeros((LS+1,LT+1),np.int64) for n,s in enumerate(S,1): equal = (s == T) np.maximum(dp[n,1:],dp[n-1,:-1]+equal*1,out=dp[n,1:]) np.maximum.accumulate(dp[n],out=dp[n]) return dp dp = LCS(S,T) answer = [] max_len = dp[-1,-1] for n in range(len(S),0,-1): if max_len == 0: break equal = (S[n-1]==T) ind = np.where((dp[n,1:]*equal)==max_len)[0] if len(ind): i = ind[0] answer.append(T[i].decode('utf-8')) dp = dp[:,:i+1]; T = T[:i] max_len -= 1 print(''.join(answer[::-1]))
s474530848
Accepted
273
61,968
1,049
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def longest_common_subsequence(S, T): LS, LT = len(S), len(T) dp = np.zeros((LS + 1, LT + 1), np.int32) for n in range(1, LS + 1): dp[n, 1:] = dp[n - 1, :-1] + (S[n - 1] == T) np.maximum(dp[n], dp[n - 1], out=dp[n]) np.maximum.accumulate(dp[n], out=dp[n]) return dp def reconstruct_LCS(S, T, dp): tmp = [] i, j = len(S), len(T) while i > 0 and j > 0: if S[i - 1] == T[j - 1]: i, j = i - 1, j - 1 tmp.append(S[i]) elif dp[i, j] == dp[i - 1, j]: i -= 1 else: j -= 1 return ''.join(reversed(tmp)) S = np.array(list(readline().decode()), 'U1')[:-1] T = np.array(list(readline().decode()), 'U1')[:-1] dp = longest_common_subsequence(S, T) print(reconstruct_LCS(S, T, dp))
s187305385
p03157
u547167033
2,000
1,048,576
Wrong Answer
671
7,028
823
There is a grid with H rows and W columns, where each square is painted black or white. You are given H strings S_1, S_2, ..., S_H, each of length W. If the square at the i-th row from the top and the j-th column from the left is painted black, the j-th character in the string S_i is `#`; if that square is painted white, the j-th character in the string S_i is `.`. Find the number of pairs of a black square c_1 and a white square c_2 that satisfy the following condition: * There is a path from the square c_1 to the square c_2 where we repeatedly move to a vertically or horizontally adjacent square through an alternating sequence of black and white squares: black, white, black, white...
h,w=map(int,input().split()) grid =[list(input()) for i in range(h)] cntW =[[0]*w for i in range(h)] visited=[[False]*w for i in range(h)] for i in range(h): for j in range(w): if grid[i][j]=='#': if j<w-1 and grid[i][j+1]=='.':cntW[i][j]+=1 if j>0 and grid[i][j-1]=='.':cntW[i][j]+=1 if i<h-1 and grid[i+1][j]=='.':cntW[i][j]+=1 if i>0 and grid[i-1][j]=='.':cntW[i][j]+=1 ans=0 for i in range(h): for j in range(w): if visited[i][j]: continue q=[(i,j)] ans+=cntW[i][j] visited[i][j]=True while q: cy,cx=q.pop(0) for nx,ny in ((cy+1,cx+1),(cy-1,cx-1),(cy-1,cx+1),(cy+1,cx-1)): if 0<=nx<w and 0<=ny<h and grid[ny][nx]=='#' and not(visited[ny][nx]): ans+=cntW[ny][nx] visited[ny][nx]=True q.append((ny,nx)) print(ans)
s778382629
Accepted
604
5,748
540
h,w=map(int,input().split()) grid =[list(input()) for i in range(h)] visited=[[False]*w for i in range(h)] ans=0 for i in range(h): for j in range(w): if visited[i][j]: continue q=[(i,j)] d={'#':0,'.':0} while q: cy,cx=q.pop(0) for ny,nx in ((cy+1,cx),(cy-1,cx),(cy,cx+1),(cy,cx-1)): if not(0<=ny<h and 0<=nx<w) or grid[cy][cx]==grid[ny][nx] or visited[ny][nx]: continue d[grid[ny][nx]]+=1 visited[ny][nx]=True q.append((ny,nx)) ans+=d['.']*d['#'] print(ans)
s140564345
p03054
u788137651
2,000
1,048,576
Wrong Answer
162
3,784
705
We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a string of length N. Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: `L`, `R`, `U` and `D`. The game consists of N steps. The i-th step proceeds as follows: * First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece. * Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece. Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done. Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.
H, W, N = map(int, input().split()) sr, sc = map(int, input().split()) S = input() T = input() left = 1 right = W up = 1 down = H for i in reversed(range(N)): if i != N - 1: if T[i] == "U": if down != H: down -= 1 elif T[i] == "D": if up != 1: up += 1 elif T[i] == "L": if right != W: right += 1 else: if left != 1: left -= 1 if S[i] == "U": up -= 1 elif S[i] == "D": down += 1 elif S[i] == "L": left += 1 else: right -= 1 if left <= sr <= right and down <= sc <= up: print("YES") else: print("NO")
s187430729
Accepted
183
3,784
731
H, W, N = map(int, input().split()) sr, sc = map(int, input().split()) S = input() T = input() left = 1 right = W up = 1 down = H for i in reversed(range(N)): if T[i] == "U": down = min(H, down+1) elif T[i] == "D": up = max(1, up-1) elif T[i] == "L": right = min(W, right+1) else: left = max(1, left-1) if S[i] == "U": up += 1 elif S[i] == "D": down -= 1 elif S[i] == "L": left += 1 else: right -= 1 #print(left, right, " ", up, down) if left > right or up > down: print("NO") exit() #print(left, right) #print(up, down) if left <= sc <= right and up <= sr <= down: print("YES") else: print("NO")
s143142159
p03543
u441320782
2,000
262,144
Wrong Answer
18
3,060
123
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
x = [int(i) for i in input()] x.sort() print(x) if x[0]==x[1]==x[2] or x[1]==x[2]==x[3]: print("Yes") else: print("No")
s513861361
Accepted
17
2,940
106
x = [int(i) for i in input()] if x[0]==x[1]==x[2] or x[1]==x[2]==x[3]: print("Yes") else: print("No")
s501194304
p03713
u057586044
2,000
262,144
Wrong Answer
17
3,064
406
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
H,W = map(int,input().split()) hr,ht,vr,vt = 0,0,0,0 hr,vr = H%3*W,W%3*H def t(x,y): if x%3==0: return 0 elif x%3==1: a = ((x//3)*2+1)*(y//2) b = x//3*y c = x*y-a-b return max(a,b,c)-min(a,b,c) else: a = ((x//3)*2+1)*(y//2) b = (x//3+1)*y c = x*y-a-b return max(a,b,c)-min(a,b,c) ht = t(H,W) vt = t(W,H) print(hr,ht,vr,vt)
s976021234
Accepted
17
3,064
430
H,W = map(int,input().split()) res = min(H,W) hr,ht,vr,vt = 0,0,0,0 hr,vr = H%3*W,W%3*H def t(x,y): if x%3==0: return 0 elif x%3==1: a = ((x//3)*2+1)*(y//2) b = x//3*y c = x*y-a-b return max(a,b,c)-min(a,b,c) else: a = ((x//3)*2+1)*(y//2) b = (x//3+1)*y c = x*y-a-b return max(a,b,c)-min(a,b,c) ht = t(H,W) vt = t(W,H) print(min(res,hr,ht,vr,vt))
s384493853
p02694
u344232182
2,000
1,048,576
Wrong Answer
23
9,164
93
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x = int(input()) m = 100 count = 1 while x > m: m = m + m/100 count += 1 print(count)
s519998211
Accepted
21
9,108
109
x = int(input()) m = 100 count = 0 while x > m: r = int(m*0.01) m = m + r count += 1 print(count)
s175641440
p03644
u113255362
2,000
262,144
Wrong Answer
25
9,092
122
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
A = int(input()) chek = 1 res = 0 for i in range(10): chek = 2**i if chek < A: res = 2**(i-1) break print(res)
s237610656
Accepted
30
9,020
122
A = int(input()) chek = 1 res = 0 for i in range(10): chek = 2**i if chek > A: res = 2**(i-1) break print(res)
s970784622
p03643
u893209854
2,000
262,144
Wrong Answer
17
2,940
24
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.
N = input() print(N[3:])
s573018644
Accepted
19
2,940
28
N = input() print('ABC' + N)
s436633604
p03050
u476435125
2,000
1,048,576
Wrong Answer
140
2,940
121
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
N=int(input()) sqrtn=int(N**0.5) ans=0 for r in range(1,sqrtn): if N%r==0: ans+=(int(N/r)-1) print(int(ans))
s749915079
Accepted
145
3,060
135
N=int(input()) sqrtn=int(N**0.5) ans=0 for r in range(1,sqrtn+1): if N%r==0 and N/r-1>r: ans+=(int(N/r)-1) print(int(ans))
s563027181
p03478
u094191970
2,000
262,144
Wrong Answer
37
3,628
229
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): n=i cnt=0 while i//10 != 0: cnt+=i%10 i=i//10 else: cnt+=i if a<=cnt and cnt<=b: print(cnt) ans+=n print(ans)
s177560039
Accepted
29
3,060
210
n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): n=i cnt=0 while i//10 != 0: cnt+=i%10 i=i//10 else: cnt+=i if a<=cnt and cnt<=b: ans+=n print(ans)
s135027647
p00460
u797673668
1,000
131,072
Time Limit Exceeded
40,000
7,588
472
あるプログラミングコンテストでは,競技後の懇親会でビンゴゲームをする習わしがある.しかし,このビンゴゲームで使うビンゴカードは少々特殊で,以下の条件に従って作成される. * ビンゴカードは N 行 N 列のマス目に区切られており,各マス目には正整数が1つずつ書かれている.それらの整数は全て異なる. * マス目に書かれている整数は 1 以上 M 以下である. * ビンゴカードに書かれているN×N個の整数の合計は S である. * どの列を見たときも,上から下に向かって整数は昇順に並んでいる. * どのマス目の整数も,そのマス目より左の列のどの整数よりも大きい. 以下は, N = 5, M = 50, S = 685 のときのビンゴカードの例である. 懇親会のために上の条件を満たすビンゴカードをできるだけたくさん作りたい.ただし,同一のカードを2枚以上作ってはならない.作ることができるビンゴカードの枚数の最大値を 100000 で割った余りを出力するプログラムを作成せよ.
def allocate(remains, limit_h, limit_w): global m if not remains: return 1 if limit_w == 1: return int(remains <= limit_h) return sum(allocate(remains - i, i, limit_w - 1) for i in range(min(limit_h, remains, m - limit_w), (remains - 1) // limit_w, -1)) while True: n, m, s = map(int, input().split()) if not n: break remains = s - sum(range(1, n ** 2 + 1)) print(allocate(remains, remains, n ** 2))
s178889445
Accepted
210
7,756
427
while True: n, m, s = map(int, input().split()) if not n: break n2 = n ** 2 dpp = [0] * (s + 1) dpp[0] = 1 for i in range(1, n2 + 1): dpn = [0] * (s + 1) for j in range(i * (i + 1) // 2, s + 1): dpn[j] += dpp[j - i] + dpn[j - i] if j - m - 1 >= 0: dpn[j] -= dpp[j - m - 1] dpn[j] %= 100000 dpp = dpn print(dpp[s])
s517559739
p03737
u127856129
2,000
262,144
Wrong Answer
17
2,940
49
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
a,b,c=input().split() print(a[0]+b[0]+c[0])
s478464839
Accepted
17
2,940
73
a,b,c=input().split() print(a[0].upper()+b[0].upper()+c[0].upper())
s075756066
p02262
u742013327
6,000
131,072
Wrong Answer
20
7,628
1,347
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_D #??????????????????????????????????????????????????????????????????????????? cnt = 0 def insertion_sort(target_list,g): maxlen = len(target_list) global cnt for focus_index in range(g, maxlen): target = target_list[focus_index] if target < target_list[focus_index - g]: compare_index = focus_index - g while compare_index >= 0 and target_list[compare_index] > target: target_list[compare_index + g] = target_list[compare_index] compare_index = compare_index - g; cnt += 1 target_list[compare_index + g] = target return target_list def shell_sort(target_list): g = [] g_value = 1 while g_value < len(target_list): g.append(g_value) g_value = 3 * g_value + 1 g = g[::-1] print(*g) for i in range(0,len(g)): insertion_sort(target_list, g[i]) def main(): n_list = int(input()) target_list = [int(input()) for n in range(n_list)] cc = shell_sort(target_list) print(cnt) print("\n".join([str(n) for n in target_list])) if __name__ == "__main__": main()
s418374401
Accepted
22,080
127,948
1,371
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_D #??????????????????????????????????????????????????????????????????????????? cnt = 0 def insertion_sort(target_list,g): maxlen = len(target_list) global cnt for focus_index in range(g, maxlen): target = target_list[focus_index] if target < target_list[focus_index - g]: compare_index = focus_index - g while compare_index >= 0 and target_list[compare_index] > target: target_list[compare_index + g] = target_list[compare_index] compare_index = compare_index - g; cnt += 1 target_list[compare_index + g] = target return target_list def shell_sort(target_list): g = [] g_value = 1 while g_value <= len(target_list): g.append(g_value) g_value = 3 * g_value + 1 g = g[::-1] print(len(g)) print(*g) for i in range(0,len(g)): insertion_sort(target_list, g[i]) def main(): n_list = int(input()) target_list = [int(input()) for n in range(n_list)] cc = shell_sort(target_list) print(cnt) print("\n".join([str(n) for n in target_list])) if __name__ == "__main__": main()
s250073480
p02843
u760802228
2,000
1,048,576
Wrong Answer
17
3,064
901
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.)
x = int(input()) total = 0 if x % 10 == 9: total += 104 + 105 elif x % 10 == 8: total += 104 + 104 elif x % 10 == 7: total += 103 + 104 elif x % 10 == 6: total += 105 + 101 elif x % 10 == 5: total += 105 elif x % 10 == 4: total += 104 elif x % 10 == 3: total += 103 elif x % 10 == 2: total += 102 elif x % 10 == 1: total += 101 if x % 100 // 10 == 1: total += 105 + 105 elif x % 100 // 10 == 2: total += 105 * 4 elif x % 100 // 10 == 3: total += 105 * 6 elif x % 100 // 10 == 4: total += 105 * 8 elif x % 100 // 10 == 5: total += 105 * 10 elif x % 100 // 10 == 6: total += 105 * 12 elif x % 100 // 10 == 7: total += 105 * 14 elif x % 100 // 10 == 8: total += 105 * 16 elif x % 100 // 10 == 9: total += 105 * 18 print(total) if total <= x: print(1)
s783690454
Accepted
17
3,064
911
x = int(input()) total = 0 if x % 10 == 9: total += 104 + 105 elif x % 10 == 8: total += 104 + 104 elif x % 10 == 7: total += 103 + 104 elif x % 10 == 6: total += 105 + 101 elif x % 10 == 5: total += 105 elif x % 10 == 4: total += 104 elif x % 10 == 3: total += 103 elif x % 10 == 2: total += 102 elif x % 10 == 1: total += 101 if x % 100 // 10 == 1: total += 105 + 105 elif x % 100 // 10 == 2: total += 105 * 4 elif x % 100 // 10 == 3: total += 105 * 6 elif x % 100 // 10 == 4: total += 105 * 8 elif x % 100 // 10 == 5: total += 105 * 10 elif x % 100 // 10 == 6: total += 105 * 12 elif x % 100 // 10 == 7: total += 105 * 14 elif x % 100 // 10 == 8: total += 105 * 16 elif x % 100 // 10 == 9: total += 105 * 18 if total <= x: print(1) else: print(0)
s120026651
p03592
u057993957
2,000
262,144
Wrong Answer
33
9,112
360
We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
n, m, k = list(map(int, input().split())) flag = False for y in range(m): if n - 2 * y == 0: continue x = (k - m * y) / (n - 2 * y) if (k - m * y) % (n - 2 * y) == 0 and (0 <= x and x <= m): print(y, (k - m * y) / (n - 2 * y), (n - 2 * y), (k - m * y)) flag = True break print("Yes" if flag else "No")
s138800140
Accepted
29
9,132
292
n, m, k = list(map(int, input().split())) flag = False for y in range(n+1): if n - 2 * y == 0: continue x = (k - m * y) / (n - 2 * y) if (k - m * y) % (n - 2 * y) == 0 and (0 <= x and x <= m): flag = True break print("Yes" if flag else "No")