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
s920773708
p03005
u560988566
2,000
1,048,576
Wrong Answer
20
3,316
77
Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?
n,k = map(int, input().split()) ans = n-k+1 if k == 1: ans = 0 print(ans)
s266633828
Accepted
18
2,940
75
n,k = map(int, input().split()) ans = n-k if k == 1: ans = 0 print(ans)
s319779475
p03386
u833492079
2,000
262,144
Wrong Answer
17
3,064
285
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()) # 5 7 2 ans=[] count=0 for i in range(a, b+1): ans.append(i) count += 1 if count > k: break count=0 for i in range(b, a-1, -1): ans.append(i) count += 1 if count > k: break ans = sorted(set(ans), key=ans.index) for i in ans: print(i)
s928313336
Accepted
17
3,060
272
a, b, k = map(int, input().split()) # 5 7 2 ans=[] count=0 for i in range(a, b+1): ans.append(i) count += 1 if count >= k: break count=0 for i in range(b, a-1, -1): ans.append(i) count += 1 if count >= k: break ans = sorted(set(ans)) for i in ans: print(i)
s084057759
p02393
u964416376
1,000
131,072
Wrong Answer
40
7,652
53
Write a program which reads three integers, and prints them in ascending order.
a = [int(i) for i in input().split()] a.sort print(a)
s641380080
Accepted
20
7,732
80
a = [int(i) for i in input().split()] print(' '.join(list(map(str, sorted(a)))))
s676482019
p00275
u766477342
1,000
131,072
Wrong Answer
30
6,720
405
百人一首の札を使った遊戯の1つに、「坊主めくり」というものがあります。絵札だけを使う簡単な遊戯なので広く楽しまれています。きまりには様々な派生型がありますが、ここで考える坊主めくりはN人の参加者で、以下のようなルールで行います。 * 64枚の「男」、15枚の「坊主」、21枚の「姫」、計100枚の札を使う。 * 絵が見えないように札を裏がえしにしてよく混ぜ、「札山」をつくる。 * 参加者の一人目から順番に1枚ずつ札山の札を引く。N人目の次は、また一人目から繰り返す。 * 引いた札が男なら、引いた人はその札を手に入れる。 * 引いた札が坊主なら、引いた人はその札を含め、持っている札をすべて「場」に出す。 * 引いた札が姫なら、引いた人はその札を含め、場にある札をすべて手に入れる。 * 札山の札がなくなったら終了で、一番多くの札を持っている人の勝ち。 参加者数と札山に積まれた札の順番が与えられたとき、遊戯が終了した時点で各参加者が持っている札数を昇順で並べたものと、場に残っている札数を出力するプログラムを作成してください。
while 1: ba = 0 p = [0 for i in range(int(input()))] if len(p) == 0:break for i,v in enumerate(list(input())): p[i%len(p)] += 1 if v == 'L': p[i%len(p)] += ba ba = 0 elif v== 'S': ba += p[i%len(p)] p[i%len(p)] = 0 result = '' for v in p: result += '%d ' % v result += str(ba) print(result)
s242144991
Accepted
50
6,724
413
while 1: ba = 0 p = [0 for i in range(int(input()))] if len(p) == 0:break for i,v in enumerate(list(input())): p[i%len(p)] += 1 if v == 'L': p[i%len(p)] += ba ba = 0 elif v== 'S': ba += p[i%len(p)] p[i%len(p)] = 0 result = '' for v in sorted(p): result += '%d ' % v result += str(ba) print(result)
s492577172
p03855
u389910364
2,000
262,144
Wrong Answer
1,142
73,740
2,716
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
import bisect import heapq import itertools import math import os import re import string import sys from collections import Counter, deque, defaultdict from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 N, K, L = list(map(int, sys.stdin.readline().split())) P, Q = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(K)])) R, S = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(L)])) class UnionFind: def __init__(self, size=None, nodes=None): assert size is not None or nodes is not None if size is not None: self._parents = [i for i in range(size)] self._ranks = [0 for _ in range(size)] self._sizes = [1 for _ in range(size)] else: self._parents = {k: k for k in nodes} self._ranks = {k: 0 for k in nodes} self._sizes = {k: 1 for k in nodes} def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self._ranks[x] > self._ranks[y]: self._parents[y] = x self._sizes[x] += self._sizes[y] else: self._parents[x] = y self._sizes[y] += self._sizes[x] if self._ranks[x] == self._ranks[y]: self._ranks[y] += 1 def find(self, x): if self._parents[x] == x: return x self._parents[x] = self.find(self._parents[x]) return self._parents[x] def size(self, x): return self._sizes[self.find(x)] uf1 = UnionFind(size=N + 1) for p, q in zip(P, Q): uf1.unite(p, q) uf2 = UnionFind(size=N + 1) for r, s in zip(R, S): if uf1.find(r) == uf1.find(s): uf2.unite(r, s) ans = [] for i in range(1, N + 1): ans.append(uf2.size(i)) print(' '.join(map(str, ans)))
s937461274
Accepted
1,343
84,908
2,555
import os import sys from collections import defaultdict if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 N, K, L = list(map(int, sys.stdin.readline().split())) P, Q = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(K)])) R, S = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(L)])) class UnionFind: def __init__(self, size=None, nodes=None): assert size is not None or nodes is not None if size is not None: self._parents = [i for i in range(size)] self._ranks = [0 for _ in range(size)] self._sizes = [1 for _ in range(size)] else: self._parents = {k: k for k in nodes} self._ranks = {k: 0 for k in nodes} self._sizes = {k: 1 for k in nodes} def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self._ranks[x] > self._ranks[y]: self._parents[y] = x self._sizes[x] += self._sizes[y] else: self._parents[x] = y self._sizes[y] += self._sizes[x] if self._ranks[x] == self._ranks[y]: self._ranks[y] += 1 def find(self, x): if self._parents[x] == x: return x self._parents[x] = self.find(self._parents[x]) return self._parents[x] def size(self, x): return self._sizes[self.find(x)] uf1 = UnionFind(size=N + 1) for p, q in zip(P, Q): uf1.unite(p, q) uf2 = UnionFind(size=N + 1) for r, s in zip(R, S): uf2.unite(r, s) counts = defaultdict(int) for i in range(1, N + 1): counts[(uf1.find(i), uf2.find(i))] += 1 ans = [] for i in range(1, N + 1): ans.append(counts[(uf1.find(i), uf2.find(i))]) print(' '.join(map(str, ans)))
s477523380
p03502
u319818856
2,000
262,144
Wrong Answer
18
2,940
255
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
def f(x: int) -> int: s = 0 while x > 0: s += x % 10 x //= 10 return s def harshad_number(N: int) -> bool: return N % f(N) == 0 if __name__ == "__main__": N = int(input()) ans = harshad_number(N) print(ans)
s439767701
Accepted
17
2,940
274
def f(x: int) -> int: s = 0 while x > 0: s += x % 10 x //= 10 return s def harshad_number(N: int) -> bool: return N % f(N) == 0 if __name__ == "__main__": N = int(input()) yes = harshad_number(N) print('Yes' if yes else 'No')
s497590684
p02412
u138628845
1,000
131,072
Wrong Answer
20
5,596
497
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
ele_and_tar = [] rs = [] flag1 = 1 flag2 = 0 while flag1: data = [int(x) for x in input().split()] if data == [0,0]: flag1 = 0 else: ele_and_tar.append(data) for i in range(len(ele_and_tar)): rs.append(0) for math in ele_and_tar: for i in range(1,math[0]+1): for j in range(i+1,math[0]+1): for k in range(j+1,math[0]+1): if (i + j + k) == math[1]: rs[flag2] = rs[flag2] + 1 flag2 = flag2 + 1
s966396303
Accepted
520
5,604
316
while True: res = 0 data = [int(x) for x in input().split()] if data == [0,0]: break for i in range(1,data[0]+1): for j in range(i+1,data[0]+1): for k in range(j+1,data[0]+1): if (i + j + k) == data[1]: res = res + 1 print(res)
s349200353
p03448
u282151316
2,000
262,144
Wrong Answer
48
3,060
227
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for i in range(A): for j in range(B): for k in range(C): if (X== 500*i +100*j +50*k): count += 1 print(count)
s112025710
Accepted
55
3,060
233
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if (X== 500*i +100*j +50*k): count += 1 print(count)
s669472275
p03449
u006425112
2,000
262,144
Wrong Answer
18
3,064
250
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()) A = [] A.append(list(map(int, input().split()))) A.append(list(map(int, input().split()))) print(A) up = A[0][0] bottom = A[1][0] + up for i in range(n-1): up += A[0][i+1] bottom = max(up, bottom) + A[1][i+1] print(bottom)
s656652866
Accepted
17
3,064
240
n = int(input()) A = [] A.append(list(map(int, input().split()))) A.append(list(map(int, input().split()))) up = A[0][0] bottom = A[1][0] + up for i in range(n-1): up += A[0][i+1] bottom = max(up, bottom) + A[1][i+1] print(bottom)
s908054820
p03836
u810625173
2,000
262,144
Wrong Answer
29
9,096
256
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) ans = "" ans += "U" * (ty - sy) + "R" * (tx - sx) ans += "D" * (ty - sy) + "L" * (tx - sx) ans += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) ans += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) print(ans)
s271349577
Accepted
28
9,148
268
sx, sy, tx, ty = map(int, input().split()) ans = "" ans += "U" * (ty - sy) + "R" * (tx - sx) ans += "D" * (ty - sy) + "L" * (tx - sx) ans += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D" ans += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U" print(ans)
s087806453
p03447
u384679440
2,000
262,144
Wrong Answer
17
2,940
88
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
X = int(input()) A = int(input()) B = int(input()) ans = X - A ans -= ans / B print(ans)
s683155861
Accepted
17
2,940
96
X = int(input()) A = int(input()) B = int(input()) ans = X - A ans -= (ans // B ) * B print(ans)
s354698116
p04045
u371467115
2,000
262,144
Wrong Answer
19
3,064
188
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
n,k=map(int,input().split()) d=list(map(str,input().split())) for i in range(n,10000): for j in list(str(i).replace(""," ").split()): if int(j) in d: break print(i) break
s376192340
Accepted
111
2,940
194
n,k=map(int,input().split()) d=list(map(str,input().split())) for i in range(n,88889): for j in list(str(i).replace(""," ").split()): if j in d: break else: print(i) break
s302801549
p03494
u350997995
2,000
262,144
Wrong Answer
17
3,064
374
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N = int(input()) A = list(map(int,input().split())) def gcd(x,y): if x<y: z = x x = y y = z if y==0: return x return gcd(y, x%y) for i in range(N): if i==0: all_gcd = gcd(A[i],A[i+1]) else: all_gcd = gcd(all_gcd,A[i]) print(all_gcd) for i in range(50): if all_gcd<2**i: print(i-1) break
s620357471
Accepted
17
3,064
359
N = int(input()) A = list(map(int,input().split())) def gcd(x,y): if x<y: z = x x = y y = z if y==0: return x return gcd(y, x%y) for i in range(N): if i==0: all_gcd = gcd(A[i],A[i+1]) else: all_gcd = gcd(all_gcd,A[i]) for i in range(50): if all_gcd<2**i: print(i-1) break
s783304930
p03485
u921773161
2,000
262,144
Wrong Answer
17
2,940
93
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b = map(int, input().split()) x = (a+b)/2 if x%1 == 0 : print(x) else : print(x//1 + 1)
s369625217
Accepted
17
2,940
112
a,b = map(int, input().split()) x = (a+b)/2 if x%1 == 0 : print(round(x)) else : print(round(x//1 + 1))
s393371071
p03844
u679817762
2,000
262,144
Wrong Answer
23
9,148
20
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her.
print(exec(input()))
s451947788
Accepted
29
9,004
30
exec('print(' + input() + ')')
s023483132
p03068
u814986259
2,000
1,048,576
Wrong Answer
29
9,128
171
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
N = int(input()) S = input() K = int(input()) e = S[K-1] ans = [] for i in range(N): if S[i] != 'e': ans.append("*") else: ans.append(S[i]) print(''.join(ans))
s998151464
Accepted
25
9,012
170
N = int(input()) S = input() K = int(input()) e = S[K-1] ans = [] for i in range(N): if S[i] != e: ans.append("*") else: ans.append(S[i]) print(''.join(ans))
s594481388
p04031
u113255362
2,000
262,144
Wrong Answer
31
9,136
268
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()) List = list(map(int, input().split())) sumS = 0 for i in range(N): sumS +=List[i] trial = sumS // N mid = 0 res = 10000000 for i in range(N): trial += i mid = 0 for j in range(N): mid += (trial - List[i])**2 res = max(res, mid) print(res)
s424781376
Accepted
33
9,132
268
N=int(input()) List = list(map(int, input().split())) sumS = 0 for i in range(N): sumS +=List[i] trial = sumS // N mid = 0 res = 10000000 for i in range(N): trial += i mid = 0 for j in range(N): mid += (trial - List[j])**2 res = min(res, mid) print(res)
s846514940
p03861
u609061751
2,000
262,144
Wrong Answer
17
2,940
163
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?
import sys input = sys.stdin.readline a, b, x = [int(x) for x in input().split()] B = 1 + b // x if a == 0: print(B) else: A = 1 + a // x print(B - A)
s444272977
Accepted
17
3,060
220
import sys input = sys.stdin.readline a, b, x = [int(x) for x in input().split()] B = 1 + b // x if a == 0: print(B) elif a % x == 0: A = 1 + a // x print(B - A + 1) else: A = 1 + a // x print(B - A)
s957768707
p03659
u303019816
2,000
262,144
Wrong Answer
2,104
24,832
224
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
n = int(input()) A = list(map(int, input().split())) cum_sum = [sum(A[:i+1]) for i in range(len(A))] b = cum_sum[-1] print(cum_sum) ans = float("inf") for a in cum_sum[:-1]: ans = min(ans, abs(2 * a - b)) print(ans)
s971545327
Accepted
169
24,832
184
n = int(input()) A = list(map(int, input().split())) b = sum(A) ans = float("inf") cum_sum = 0 for a in A[:-1]: cum_sum += a ans = min(ans, abs(2 * cum_sum - b)) print(ans)
s092627368
p03485
u693211869
2,000
262,144
Wrong Answer
17
2,940
75
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
import math a, b = map(int, input().split()) x = math.ceil(a / b) print(x)
s987810066
Accepted
17
2,940
87
import math a, b = map(int, input().split()) i = ( a + b) / 2 x = math.ceil(i) print(x)
s932904567
p03493
u266113953
2,000
262,144
Wrong Answer
17
2,940
32
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(s.count("0"))
s064882624
Accepted
18
2,940
32
s = input() print(s.count("1"))
s322914906
p03302
u399280934
2,000
1,048,576
Wrong Answer
17
3,060
105
You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds. Note that a+b=15 and a\times b=15 do not hold at the same time.
a,b=map(int,input().split()) if a+b==15: print('*') elif a*b==15: print('+') else: print('x')
s049859349
Accepted
18
2,940
105
a,b=map(int,input().split()) if a+b==15: print('+') elif a*b==15: print('*') else: print('x')
s210190054
p03911
u052499405
2,000
262,144
Wrong Answer
418
22,036
1,247
On a planet far, far away, M languages are spoken. They are conveniently numbered 1 through M. For _CODE FESTIVAL 20XX_ held on this planet, N participants gathered from all over the planet. The i-th (1≦i≦N) participant can speak K_i languages numbered L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}. Two participants A and B can _communicate_ with each other if and only if one of the following conditions is satisfied: * There exists a language that both A and B can speak. * There exists a participant X that both A and B can communicate with. Determine whether all N participants can communicate with all other participants.
n, m = [int(item) for item in input().split()] query = [] appeared = set() for i in range(n): line = [int(item) for item in input().split()] appeared.update(line[1:]) query.append(line[1:]) class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.size = [1] * n self.rank = [0] * n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def same_check(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): return self.size[self.find(x)] def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 uf = UnionFind(m) for q in query: if len(q) == 1: continue for item in q[1:]: if not uf.same_check(q[0]-1, item-1): uf.union(q[0]-1, item-1) par = uf.find(appeared.pop() - 1) for item in appeared: if uf.find(item - 1) != par: print("No") exit() print("Yes")
s046854250
Accepted
418
22,036
1,247
n, m = [int(item) for item in input().split()] query = [] appeared = set() for i in range(n): line = [int(item) for item in input().split()] appeared.update(line[1:]) query.append(line[1:]) class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.size = [1] * n self.rank = [0] * n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def same_check(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): return self.size[self.find(x)] def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 uf = UnionFind(m) for q in query: if len(q) == 1: continue for item in q[1:]: if not uf.same_check(q[0]-1, item-1): uf.union(q[0]-1, item-1) par = uf.find(appeared.pop() - 1) for item in appeared: if uf.find(item - 1) != par: print("NO") exit() print("YES")
s294547070
p02646
u757715307
2,000
1,048,576
Wrong Answer
22
9,192
271
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a, v = (int(i) for i in input().split(' ')) b, w = (int(i) for i in input().split(' ')) t = int(input()) l1 = a + v * t l2 = b + w * t flag = False if v >= 0: if l1 >= l2: flag = True else: if l1 <= l2: flag = True print("Yes" if flag else "No")
s663375567
Accepted
22
9,128
329
a, v = (int(i) for i in input().split(' ')) b, w = (int(i) for i in input().split(' ')) t = int(input()) flag = False if a < b: l1 = a + v * t l2 = b + w * t if l1 >= l2: flag = True else: l1 = a + (v * -1) * t l2 = b + (w * -1) * t if l1 <= l2: flag = True print("YES" if flag else "NO")
s190254218
p03760
u136090046
2,000
262,144
Wrong Answer
18
3,060
201
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
val = input() val2 = input() res = "" for i in range(0, min(len(val), len(val2))): res += val[i] res += val2[i] if len(val) > len(val2): res += val[-1] else: res += val2[-1] print(res)
s424607302
Accepted
17
3,064
239
val = input() val2 = input() res = "" for i in range(0, min(len(val), len(val2))): res += val[i] res += val2[i] if len(val) == len(val2): pass elif len(val) > len(val2): res += val[-1] else: res += val2[-1] print(res)
s232132404
p03998
u052499405
2,000
262,144
Wrong Answer
19
3,064
581
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.
sa = input() + "#" sb = input() + "#" sc = input() + "#" ia = 0 ib = 0 ic = 0 who = 0 for i in range(300): if who == 0: ia += 1 if sa[ia] == "#": print("a") exit() elif sa[ia] == "b": who = 1 elif sa[ia] == "c": who = 2 elif who == 1: ib += 1 if sb[ib] == "#": print("b") exit() elif sb[ib] == "a": who = 0 elif sb[ib] == "c": who = 2 elif who == 2: ic += 1 if sc[ic] == "#": print("c") exit() elif sc[ic] == "a": who = 0 elif sc[ic] == "b": who = 1
s629260013
Accepted
18
3,064
671
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline sa = input() + "#" sb = input() + "#" sc = input() + "#" ia = 0 ib = 0 ic = 0 who = 0 for i in range(300): if who == 0: if sa[ia] == "#": print("A") exit() elif sa[ia] == "b": who = 1 elif sa[ia] == "c": who = 2 ia += 1 elif who == 1: if sb[ib] == "#": print("B") exit() elif sb[ib] == "a": who = 0 elif sb[ib] == "c": who = 2 ib += 1 elif who == 2: if sc[ic] == "#": print("C") exit() elif sc[ic] == "a": who = 0 elif sc[ic] == "b": who = 1 ic += 1
s848995927
p03729
u629607744
2,000
262,144
Wrong Answer
29
9,000
118
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 = [str(i) for i in input().split()] if a[0][-1] == a[1][0] and a[1][-1] == a[2][0]: print("Yes") else: print("No")
s208751760
Accepted
27
9,032
119
a = [str(i) for i in input().split()] if a[0][-1] == a[1][0] and a[1][-1] == a[2][0]: print("YES") else: print("NO")
s509877314
p03644
u163501259
2,000
262,144
Wrong Answer
18
3,064
238
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()) counter = 0 cnt = [0]*(n+1) for i in range(1,n+1): j = i while(j%2 == 0): j = j/2 counter += 1 cnt[i] = counter counter = 0 max_val = max(cnt) ans = cnt.index(max_val) print(cnt) print(ans)
s800250124
Accepted
17
3,064
237
n = int(input()) counter = 0 cnt = [0]*(n+1) for i in range(1,n+1): j = i while(j%2 == 0): j = j/2 counter += 1 cnt[i] = counter counter = 0 max_val = max(cnt[1:]) ans = cnt[1:].index(max_val) print(ans+1)
s318311220
p03478
u806257533
2,000
262,144
Wrong Answer
33
3,060
216
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).
in_all = list(map(int, input().split())) cnt = 0 for n in range(in_all[0]): tmp = str(n) all = 0 for t in tmp: all += int(t) if all>=in_all[1] and all<=in_all[2]: cnt += 1 print(cnt)
s727797580
Accepted
33
3,060
229
in_all = list(map(int, input().split())) total = 0 for n in range(1, in_all[0]+1): tmp = str(n) all = 0 for t in tmp: all += int(t) if all>=in_all[1] and all<=in_all[2]: total += n print(total)
s410628095
p03891
u297467990
2,000
262,144
Wrong Answer
23
3,064
341
A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum. You are given the integers written in the following three squares in a magic square: * The integer A at the upper row and left column * The integer B at the upper row and middle column * The integer C at the middle row and middle column Determine the integers written in the remaining squares in the magic square. It can be shown that there exists a unique magic square consistent with the given information.
#!/usr/bin/env python3 import itertools a = int(input()) b = int(input()) c = int(input()) for k in itertools.count(): f = [ [ a, b, k-a-b ], [ 2*k-2*a-b-2*c, c, 2*a+b+c-k ], [ a+b+2*c-k, k-b-c, k-a-c ] ] print(*f[0]) print(*f[1]) print(*f[2]) break
s702804732
Accepted
24
3,188
320
#!/usr/bin/env python3 import itertools a = int(input()) b = int(input()) c = int(input()) k = 3*c f = [ [ a, b, k-a-b ], [ 2*k-2*a-b-2*c, c, 2*a+b+c-k ], [ a+b+2*c-k, k-b-c, k-a-c ] ] assert f[0][2] + f[1][1] + f[2][0] == k for y in range(3): print(*f[y])
s561551704
p03493
u027208253
2,000
262,144
Wrong Answer
17
2,940
104
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.
input = input() count = 0 for i in range(len(input)): if input[i] == 1: count += 1 print(count)
s605256914
Accepted
17
2,940
109
input = input() count = 0 for i in range(len(input)): if input[i] == "1": count += 1 print(count)
s244790859
p02833
u475503988
2,000
1,048,576
Wrong Answer
17
2,940
19
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
1000000000000000000
s505388999
Accepted
17
2,940
147
N = int(input()) ans = N // 10 tmp = N // 10 while 5 <= tmp: ans += tmp // 5 tmp = tmp // 5 if N % 2: print(0) else: print(ans)
s383622263
p03478
u271469978
2,000
262,144
Wrong Answer
17
2,940
123
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 while n > 0: if a <= n%10 <= b: ans += n%10 n //= 10 print(ans)
s079789324
Accepted
28
3,064
354
n, a, b = map(int, input().split()) def check_a_b(n, a, b): sum = 0 while n > 0: if sum + n%10 <= b: sum += n%10 n //= 10 else: return False if sum >= a: return True else: return False ans = 0 for i in range(n+1): if check_a_b(i, a, b): ans += i print(ans)
s010946344
p03943
u117193815
2,000
262,144
Wrong Answer
17
2,940
125
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a,b,c = map(int, input().split()) l=[a,b,c] l.sort() if l[0]+l[1]==l[2]: print("YES") else: print("NO")
s656407631
Accepted
17
3,060
124
a,b,c = map(int, input().split()) l=[a,b,c] l.sort() if l[0]+l[1]==l[2]: print("Yes") else: print("No")
s022203697
p03854
u579832365
2,000
262,144
Wrong Answer
20
3,316
234
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() S = S[::-1] print(S) S = S.replace("resare","") S = S.replace("esare","") S = S.replace("remaerd","") S = S.replace("maerd","") if S == "": print("YES") else: print("NO")
s326066559
Accepted
19
3,188
225
S = input() S = S[::-1] S = S.replace("resare","") S = S.replace("esare","") S = S.replace("remaerd","") S = S.replace("maerd","") if S == "": print("YES") else: print("NO")
s611614729
p03370
u295416460
2,000
262,144
Wrong Answer
17
2,940
136
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
N, X = map(int, input().split()) m_list = [int(input()) for _ in range(N)] m_list.sort() x = X - sum(m_list) print(N + x // m_list[-1])
s471889455
Accepted
17
2,940
135
N, X = map(int, input().split()) m_list = [int(input()) for _ in range(N)] m_list.sort() x = X - sum(m_list) print(N + x // m_list[0])
s915942336
p03502
u611090896
2,000
262,144
Wrong Answer
17
2,940
67
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N = input() print('Yes' if int(N) // sum(map(int,N)) ==0 else 'No')
s628448025
Accepted
17
2,940
68
N = input() print('Yes' if int(N) % sum(map(int,N)) == 0 else 'No')
s810379046
p03943
u583276018
2,000
262,144
Wrong Answer
17
2,940
89
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.
s = map(int, input().split()) if(max(s) == sum(s)//2): print("Yes") else: print("No")
s314974121
Accepted
18
2,940
143
s = list(map(int, input().split())) if(sum(s)%2==1): print("No") else: if(max(s) == (sum(s)//2)): print("Yes") else: print("No")
s228134774
p03502
u341855122
2,000
262,144
Wrong Answer
155
12,388
136
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
import numpy as np a = input() c = list(map(int,list(a))) s = sum(np.array(c)) if int(a)%s == 0: print("YES") else: print("NO")
s384663657
Accepted
152
12,416
136
import numpy as np a = input() c = list(map(int,list(a))) s = sum(np.array(c)) if int(a)%s == 0: print("Yes") else: print("No")
s386769088
p03556
u731665172
2,000
262,144
Wrong Answer
17
2,940
33
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
N=int(input()) print(int(N**0.5))
s225298785
Accepted
17
3,060
38
N = int(input()) print(int(N**0.5)**2)
s753377389
p03697
u471684875
2,000
262,144
Wrong Answer
17
2,940
61
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
n,m=map(int,input().split()) print(n+m if n+m<9 else 'error')
s228464692
Accepted
17
2,940
62
n,m=map(int,input().split()) print(n+m if n+m<10 else 'error')
s303492210
p02578
u536034761
2,000
1,048,576
Wrong Answer
106
32,236
149
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
N = int(input()) A = list(map(int, input().split())) pre = A[0] ans = 0 for a in A[1:]: if pre > a: ans += pre - a pre = a print(ans)
s839867550
Accepted
112
32,364
217
N = int(input()) A = list(map(int, input().split())) pre = A[0] ans = 0 if N == 1: print(0) else: for a in A[1:]: if pre > a: ans += pre - a else: pre = a print(ans)
s887122830
p03486
u940743763
2,000
262,144
Wrong Answer
17
2,940
74
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() t = input() if s < t: print('Yes') else: print('No')
s724777654
Accepted
17
2,940
158
s = input() t = input() sol = ''.join((sorted(list(s)))) tol = ''.join(sorted(list(t), reverse=True)) if sol < tol: print('Yes') else: print('No')
s177702158
p03635
u451017206
2,000
262,144
Wrong Answer
17
2,940
58
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
n,m = list(map(int, input().split())) print (n-1 * m - 1)
s149780504
Accepted
17
2,940
59
n,m = list(map(int, input().split())) print ((n-1)*(m-1))
s259843175
p03545
u048034149
2,000
262,144
Wrong Answer
18
3,060
250
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
abcd = input() op = ['+', '-'] for op1 in op: for op2 in op: for op3 in op: tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3] if eval(tmp_ans) == 7: print(tmp_ans)
s957140813
Accepted
17
2,940
278
abcd = input() op = ['+', '-'] for op1 in op: for op2 in op: for op3 in op: tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3] if eval(tmp_ans) == 7: print(tmp_ans+'=7') exit()
s050087409
p03434
u992519990
2,000
262,144
Wrong Answer
18
3,060
154
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
# coding: utf-8 N = int(input()) a = list(map(int,input().split())) a.sort(reverse=True) print(a) alice = sum(a[0::2]) bob = sum(a[1::2]) print(alice-bob)
s449964704
Accepted
17
2,940
145
# coding: utf-8 N = int(input()) a = list(map(int,input().split())) a.sort(reverse=True) alice = sum(a[0::2]) bob = sum(a[1::2]) print(alice-bob)
s483521401
p03854
u296150111
2,000
262,144
Wrong Answer
17
3,188
239
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() i=1 while i<len(s)+1: if s[-i:-i-5:-1]=="erase" \ or s[-i:-i-5:-1]=="dream": print(s[-i:-i-5:-1]) i+=5 elif s[-i:-i-6:-1]=="eraser": i+=6 elif s[-i:-i-7:-1]=="deaamer": i+=7 else: print("NO") exit() print("YES")
s547371473
Accepted
38
3,188
225
s=input() i=1 while i<len(s): if s[-i-4:-i]+s[-i]=="erase" \ or s[-i-4:-i]+s[-i]=="dream": i+=5 elif s[-i-5:-i]+s[-i]=="eraser": i+=6 elif s[-i-6:-i]+s[-i]=="dreamer": i+=7 else: print("NO") exit() print("YES")
s921363513
p03251
u339550873
2,000
1,048,576
Wrong Answer
18
3,060
243
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
#! /usr/bin/env python3 # -*- coding: utf-8 -*- N, M, X, Y = [int(c) for c in input().split()] xls = [int(x) for x in input().split()] yls = [int(c) for c in input().split()] if max (xls) < min(yls): print('War') else: print('No War')
s990384190
Accepted
17
3,060
277
#! /usr/bin/env python3 # -*- coding: utf-8 -*- N, M, X, Y = [int(c) for c in input().split()] xls = [int(x) for x in input().split()] yls = [int(c) for c in input().split()] if max (xls) < min(yls) and Y > max(xls) and X < min(yls): print('No War') else: print('War')
s800989645
p03024
u630096262
2,000
1,048,576
Wrong Answer
17
2,940
82
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
s = input() cnt = s.count('x') if cnt <= 7: print("Yes") else: print("No")
s832937986
Accepted
17
2,940
82
s = input() cnt = s.count('x') if cnt <= 7: print("YES") else: print("NO")
s155779463
p03447
u786020649
2,000
262,144
Wrong Answer
27
9,168
1,202
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
import sys sys.setrecursionlimit(10**9) read=sys.stdin.read class Unionfind(): def __init__(self,n): self.parents=[-1]*n self.dist=[0]*n def find(self,x): if self.parents[x]<0: return self.dist[x],x else: tmp=self.find(self.parents[x]) self.dist[x]+=tmp[0] self.parents[x]=tmp[1] return self.dist[x], self.parents[x] def union(self,x,y,d): rx=self.find(x)[1] ry=self.find(y)[1] diff=self.dist[y]-self.dist[x]-d if rx==ry: if diff!=0: return True return False if diff<0: rx,ry=ry,rx diff=-diff self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff) self.parents[rx]=ry self.dist[rx]=diff return False def main(): n,m,*lrd=map(int,read().split()) v=Unionfind(n) for l,r,d in zip(*[iter(lrd)]*3): if v.union(l-1,r-1,d): print('No') break else: if max(-d-1 for d in v.parents if d<0) >10**9: print('No') else: print('Yes') if __name__=='__main__': main()
s094702218
Accepted
29
9,160
65
import sys x,a,b=map(int,sys.stdin.read().split()) print((x-a)%b)
s297212628
p03997
u958210291
2,000
262,144
Wrong Answer
25
9,160
70
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b =int(input()) h = int(input()) print(((a+b)*2)/2)
s176089477
Accepted
30
9,104
76
a = int(input()) b =int(input()) h = int(input()) print(int(((a+b)*h)/2))
s768239308
p03386
u726439578
2,000
262,144
Wrong Answer
20
3,060
102
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()) for i in range(a,a+k): print(i) for i in range(b-k,b): print(i)
s540519632
Accepted
17
3,060
189
a,b,k=map(int,input().split()) if a+k-1>=b-k+1: for i in range(a,b+1): print(i) else: for i in range(a,a+k): print(i) for i in range(b-k+1,b+1): print(i)
s801036714
p03672
u676010704
2,000
262,144
Wrong Answer
17
3,060
276
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.
def main(): msg = input() while len(msg) >= 2: before = msg[:int(len(msg) / 2)] after = msg[int(len(msg) / 2):] if before == after: print(len(before)) break msg = msg[:-1] if __name__ == '__main__': main()
s127781838
Accepted
17
3,060
341
def main(): msg = input() msg = msg[:-1] if len(msg) % 2 != 0: msg = msg[:-1] while len(msg) >= 2: before = msg[:int(len(msg) / 2)] after = msg[int(len(msg) / 2):] if before == after: print(len(msg)) break msg = msg[:-2] if __name__ == '__main__': main()
s923886336
p02413
u527848444
1,000
131,072
Wrong Answer
30
6,724
248
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
(r,c) = [int(i) for i in input().split()] table = [] for rc in range(r): table.append([int(i) for i in input().split()]) table.append([0 for _ in range(c)]) for row in table: for column in row: print(column,end=' ') print()
s887889421
Accepted
30
7,768
332
(r, c) = [int(i) for i in input().split()] last_row = [0 for _ in range(c+1)] for _ in range(r): row = [int(i) for i in input().split()] for cc in range(c): last_row[cc] += int(row[cc]) print(row[cc], end=' ') print(sum(row)) last_row[-1] = sum(last_row) print(' '.join([str(a) for a in last_row]))
s170749623
p03089
u070163338
2,000
1,048,576
Wrong Answer
62
3,064
427
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
n = int(input()) b = [int(i) for i in input().split()] pool = [] def search_num(num): try: nn = b.index(num) b.remove(num) return num except: if num-1 > 0: return search_num(num-1) else: return -1 for i in range(n): num = search_num(i+1) if num == -1: print('-1') break else: pool.append(str(num)) if i+1 == n: text = '\n'.join(pool) print(text) break
s219490592
Accepted
23
3,188
551
n = int(input()) b = [int(i) for i in input().split()] pool = [] def search_num(num): try: nn = b.index(num) if nn + 1 == num: b.remove(num) return num else: return search_num(num-1) except: if num-1 > 0: return search_num(num-1) else: return -1 if n != len(b): print('-1') else: for i in range(n, 0, -1): num = search_num(i+1) if num == -1: print('-1') break else: pool.append(str(num)) if i == 1: for i in (reversed(pool)): print(i) break
s906160200
p04031
u230717961
2,000
262,144
Wrong Answer
18
3,064
384
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.
def solve(s): sum1 = 0 sum2 = 0 length = 0 for i in s.split(): x = int(i) sum1 += x**2 sum2 += x length += 1 score = 10**8 for y in range(100,-101, -1): tmp = sum1 - sum2*2*y + length*(y**2) score = min(tmp, score) return score if __name__ == "__main__": n = int(input()) s = input() solve(s)
s792832302
Accepted
17
3,064
391
def solve(s): sum1 = 0 sum2 = 0 length = 0 for i in s.split(): x = int(i) sum1 += x**2 sum2 += x length += 1 score = 10**8 for y in range(100,-101, -1): tmp = sum1 - sum2*2*y + length*(y**2) score = min(tmp, score) return score if __name__ == "__main__": n = int(input()) s = input() print(solve(s))
s770632383
p03597
u185037583
2,000
262,144
Wrong Answer
17
2,940
36
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
print(int(input())*2 - int(input()))
s028598898
Accepted
17
2,940
37
print(int(input())**2 - int(input()))
s705132194
p03469
u761087127
2,000
262,144
Wrong Answer
17
2,940
55
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
print(c if i!=3 else '8' for i,c in enumerate(input()))
s370800386
Accepted
18
2,940
66
print("".join([c if i!=3 else '8' for i,c in enumerate(input())]))
s282693995
p02415
u805716376
1,000
131,072
Wrong Answer
20
5,532
34
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
a = input() a.swapcase() print(a)
s014068254
Accepted
20
5,540
28
print(input().swapcase())
s145491241
p03712
u041075929
2,000
262,144
Wrong Answer
19
3,064
468
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.
import sys, os f = lambda:list(map(int,input().split())) if 'local' in os.environ : sys.stdin = open('./input.txt', 'r') def solve(): n, m = f() s = [ input() for i in range(n)] print(s) for i in range(n+2): if i == 0 or i == n+1: for j in range(m+2): print('#', end = '') print() else: print('#',end = '') print(s[i-1], end = '') print('#') solve()
s268885373
Accepted
18
3,060
455
import sys, os f = lambda:list(map(int,input().split())) if 'local' in os.environ : sys.stdin = open('./input.txt', 'r') def solve(): n, m = f() s = [ input() for i in range(n)] for i in range(n+2): if i == 0 or i == n+1: for j in range(m+2): print('#', end = '') print() else: print('#',end = '') print(s[i-1], end = '') print('#') solve()
s596670317
p03456
u636311816
2,000
262,144
Wrong Answer
18
2,940
69
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.
import math;['No','Yes'][math.sqrt(int(input().replace(' ','')))%1>0]
s882625044
Accepted
17
2,940
76
import math;print(['Yes','No'][math.sqrt(int(input().replace(' ','')))%1>0])
s610173268
p04043
u190195462
2,000
262,144
Wrong Answer
30
8,956
246
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
A, B, C = map(str, input().split()) D = 0 E = 0 if A == 5: D += 1 if A == 7: E += 1 if B == 5: D += 1 if B == 7: E += 1 if C == 5: D += 1 if C == 7: E += 1 if D == 2 and E==1: print("YES") else: print("NO")
s125313788
Accepted
24
8,936
272
A, B, C = map(str, input().split()) D = 0 E = 0 if A == "5": D =D + 1 if A == "7": E =E + 1 if B == "5": D =D + 1 if B == "7": E =E + 1 if C == "5": D =D + 1 if C == "7": E =E + 1 if D == 2 and E == 1: print("YES") else: print("NO")
s775450118
p02277
u126478680
1,000
131,072
Wrong Answer
30
6,340
1,037
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
import copy def num_from_card(card): return int(card[2:]) def partition(A, p, r): x = num_from_card(A[r]) i = p-1 for j in range(p, r): if num_from_card(A[j]) <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 def quick_sort(A_i, p, r): A = copy.copy(A_i) if p < r: q = partition(A, p, r) quick_sort(A, p, q-1) quick_sort(A, q+1, r) return A def is_stable(A, sorted_A, N): A_nums = [int(x[1:]) for x in A] same_num = [x for x in set(A_nums) if A_nums.count(x) > 1] A_symbols, sorted_A_symbols = [], [] flag = 'Stable' for num in same_num: if [card[0] for card in A if int(card[1:]) == num] != [card[0] for card in sorted_A if int(card[1:]) == num]: flag = 'Not stable' break return flag n = int(input()) cards = [input() for i in range(n)] sorted_cards = quick_sort(cards, 0, n-1) print(is_stable(cards, sorted_cards, n)) for c in sorted_cards: print(c)
s458138949
Accepted
4,210
14,296
1,229
import copy def num_from_card(card): return int(card[2:]) def partition(A, p, r): x = num_from_card(A[r]) i = p-1 for j in range(p, r): if num_from_card(A[j]) <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 def quick_sort(A, p, r): if p < r: q = partition(A, p, r) quick_sort(A, p, q-1) quick_sort(A, q+1, r) def merge(A, left, mid, right): L = A[left: mid] R = A[mid: right] L.append(' ' + str(int(10e9 + 1))) R.append(' ' + str(int(10e9 + 1))) i, j = 0, 0 for k in range(left, right): if num_from_card(L[i]) <= num_from_card(R[j]): A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def merge_sort(A, left, right): if left + 1 < right: mid = int((left + right)/2) merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) n = int(input()) cards = [input() for i in range(n)] merge_cards = copy.copy(cards) quick_sort(cards, 0, n-1) merge_sort(merge_cards, 0, n) if merge_cards == cards: print('Stable') else: print('Not stable') for c in cards: print(c)
s810266246
p03386
u693007703
2,000
262,144
Wrong Answer
17
3,060
228
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 = [int(i) for i in input().split()] numbers = set() for i in range(A, A+K): if i <= B: numbers.add(i) for j in range(B-K, B): if j >= A: numbers.add(j+1) for n in numbers: print(n)
s433522579
Accepted
17
3,060
259
A, B, K = [int(i) for i in input().split()] numbers = set() for i in range(A, A+K): if i <= B: numbers.add(i) for j in range(B-K, B): if j >= A: numbers.add(j+1) numbers = sorted(numbers) for n in numbers: print(n)
s221793222
p03555
u394731058
2,000
262,144
Wrong Answer
17
2,940
133
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.
i = list(input()) t = list(input()) for _ in range(3): a = i.pop(-1) i.insert(0, a) if i == t: print("YES") else: print("NO")
s460484041
Accepted
17
3,060
134
i = list(input()) t = list(input()) e = i.pop(-1) s = i.pop(0) i.insert(0,e) i.append(s) if i == t: print("YES") else: print("NO")
s088685550
p03997
u872056745
2,000
262,144
Wrong Answer
19
3,060
74
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a + b) * h / 2)
s222753346
Accepted
17
2,940
80
a = int(input()) b = int(input()) h = int(input()) print(int((a + b) * h / 2))
s395324234
p04025
u146575240
2,000
262,144
Wrong Answer
17
3,060
271
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())) A.sort() A_s = set(A) A_s_a = int(sum(A_s)//len(A_s)) if A[N//2+1-1] <= A_s_a: pass else: A_s_a = A_s_a + 1 ans = 0 for i in range(N): ans += (A[i]-A_s_a)**2 print(ans)
s395050797
Accepted
26
3,060
258
N = int(input()) A = list(map(int, input().split())) ans = 10**8 for X in range(-100,101): tmp = 0 for i in range(N): tmp += (A[i]-X)**2 if ans >= tmp: ans = tmp else: pass print(ans)
s699525045
p03478
u812867074
2,000
262,144
Wrong Answer
30
2,940
122
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): if a <= sum(map(int,str(i))) <= b: ans+=1 print(ans)
s307708802
Accepted
30
2,940
123
n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): if a <= sum(map(int,str(i))) <= b: ans+=i print(ans)
s893676923
p02396
u088372268
1,000
131,072
Wrong Answer
30
7,716
165
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
x = list(input().split("\n")) i = 1 for j in x: int_j = int(j) if int_j != 0: print("Case", str(i)+":", int_j) i += 1 else: break
s354972007
Accepted
90
8,120
233
x = [] for k in range(10000): n = input() if n == "0": break x.append(int(n)) i = 1 for j in x: int_j = int(j) if int_j != 0: print("Case", str(i)+":", int_j) i += 1 else: break
s813448030
p03795
u883232818
2,000
262,144
Wrong Answer
17
2,940
62
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N = int(input()) x = 800 * N y = (N / 15) * 200 print(x - y)
s275348563
Accepted
18
2,940
65
N = int(input()) x = 800 * N y = int(N / 15) * 200 print(x - y)
s266125775
p03860
u268792407
2,000
262,144
Wrong Answer
18
2,940
37
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s=input().split()[1] print("A"+s+"C")
s412437186
Accepted
17
2,940
40
s=input().split()[1] print("A"+s[0]+"C")
s517171083
p02267
u569960318
1,000
131,072
Wrong Answer
20
7,404
310
You are given a sequence of _n_ integers S and a sequence of different _q_ integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
def linearSearch(S,t): L = S + [t] i = 0 while L[i] != t: i += 1 if i == len(L)-1: return 0 else : return 1 if __name__=='__main__': n=input() S=input().split() q=input() T=int,input().split() cnt = 0 for t in T: cnt += linearSearch(S,t) print(cnt)
s289446140
Accepted
60
8,092
306
def linearSearch(S,t): L = S + [t] i = 0 while L[i] != t: i += 1 if i == len(L)-1: return 0 else : return 1 if __name__=='__main__': n=input() S=input().split() q=input() T=input().split() cnt = 0 for t in T: cnt += linearSearch(S,t) print(cnt)
s323933744
p02393
u494314211
1,000
131,072
Wrong Answer
30
7,444
50
Write a program which reads three integers, and prints them in ascending order.
a=list(map(int,input().split())) a.sort() print(a)
s311938559
Accepted
20
7,644
63
a=list(map(int,input().split())) a.sort() print(a[0],a[1],a[2])
s055417074
p03679
u657512990
2,000
262,144
Wrong Answer
17
3,060
147
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.
#list(map(int, input().split())) x,a,b=list(map(int, input().split())) if a>=b:print('delicious') elif b-a>=x:print('safe') else:print('dangerous')
s886145469
Accepted
17
3,060
147
#list(map(int, input().split())) x,a,b=list(map(int, input().split())) if a>=b:print('delicious') elif b-a<=x:print('safe') else:print('dangerous')
s186041159
p03795
u393512980
2,000
262,144
Wrong Answer
17
2,940
37
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n=int(input()) print(800*n-200*n//15)
s641825121
Accepted
17
2,940
40
n=int(input()) print(800*n-200*(n//15))
s203458091
p03386
u626337957
2,000
262,144
Wrong Answer
17
2,940
111
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()) for num in (A, B+1): if num <= A+K-1 or num >= A-K+1: print(num)
s721903538
Accepted
18
3,060
212
A, B, K = map(int, input().split()) nums = [] for num in range(A, min(A+K, B+1)): nums.append(num) for num in range(max(B-K+1, A), B+1): nums.append(num) ans = sorted(set(nums)) for num in ans: print(num)
s858679519
p02401
u682357930
1,000
131,072
Wrong Answer
40
7,676
351
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: l = input().split() a = int(l[0]) b = int(l[2]) op = l[1] if op == '?': break if op == '+': ans = a + b print(ans) elif op == '-': ans = a - b print(ans) elif op == '*': ans = a * b print(ans) elif op == '/': ans = a / b print(ans)
s671109004
Accepted
30
7,668
356
while True: l = input().split() a = int(l[0]) b = int(l[2]) op = l[1] if op == '?': break if op == '+': ans = a + b print(ans) elif op == '-': ans = a - b print(ans) elif op == '*': ans = a * b print(ans) elif op == '/': ans = int(a / b) print(ans)
s812299821
p04012
u714533789
2,000
262,144
Wrong Answer
17
2,940
79
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
w=input() odd=[i for i in set(w) if w.count(i)%2] print('NO' if odd else 'YES')
s606447192
Accepted
17
2,940
79
w=input() odd=[i for i in set(w) if w.count(i)%2] print('No' if odd else 'Yes')
s565454161
p03449
u790877102
2,000
262,144
Wrong Answer
17
2,940
167
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()) a1 = list(map(int,input().split())) a2 = list(map(int,input().split())) m = 0 for i in range(n): m = max(m, sum(a1[0:i+1])+sum(a2[i:0])) print(m)
s989360304
Accepted
17
2,940
163
n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) m = 0 for i in range(n): m = max(m, sum(a[0:i+1])+sum(b[i:n])) print(m)
s207342881
p03795
u543954314
2,000
262,144
Wrong Answer
17
2,940
42
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n = int(input()) print(n*800 - (n%15)*200)
s893925391
Accepted
17
2,940
44
n = int(input()) print(n*800 - (n//15)*200)
s101855145
p03548
u667024514
2,000
262,144
Wrong Answer
17
2,940
58
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
a, b, c=map(int,input().split()) a=a-c A=int(a/b) print(A)
s084520857
Accepted
17
2,940
95
a = input().split() b = int(a[0]) c = int(a[1]) d = int(a[2]) b = b-d F = int(b/(c+d)) print(F)
s660147262
p03351
u461833298
2,000
1,048,576
Wrong Answer
17
2,940
131
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 & abs(c-b) <= d) | (abs(a-c) <= d): print('Yes') else: print('No')
s389919057
Accepted
17
2,940
134
a, b, c, d = map(int, input().split()) if (abs(a-b) <= d and abs(c-b) <= d) or (abs(a-c) <= d): print('Yes') else: print('No')
s110009806
p03545
u866833003
2,000
262,144
Wrong Answer
29
8,960
306
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 = input() for bit in range(1 << 3): f = s[0] ans = int(s[0]) for i in range(3): if bit & (1 << i): ans += int(s[i+1]) f += "+" else: ans -= int(s[i+1]) f += "-" f += s[i+1] if ans == 7: print(f) break
s541195311
Accepted
28
8,960
324
s = input() for bit in range(1 << 3): f = s[0] ans = int(s[0]) for i in range(3): if bit & (1 << i): ans += int(s[i+1]) f += "+" else: ans -= int(s[i+1]) f += "-" f += s[i+1] if ans == 7: f += "=7" print(f) break
s584820921
p02392
u464080148
1,000
131,072
Wrong Answer
20
5,588
87
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a,b,c=map(int,input().split()) if a<b and b<c: print("YES") else: print("NO")
s843896394
Accepted
20
5,588
87
a,b,c=map(int,input().split()) if a<b and b<c: print("Yes") else: print("No")
s963752354
p03394
u382423941
2,000
262,144
Wrong Answer
102
7,752
465
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
import fractions def verify(seq): sm = sum(seq) print(all([fractions.gcd(2, sm-2) != 1 for s in seq])) n = int(input()) cnt = 0 ans = [] for i in range(2, 30001): if cnt == n - 1: break if i % 2 == 0 or i % 3 == 0: ans.append(i) cnt += 1 sm = sum(ans) for j in range(i, 30001): if ((sm + j) % (2*3)) == 0: if j % 2 == 0 or j % 3 == 0: ans.append(j) break print(' '.join(map(str, ans)))
s605582339
Accepted
38
5,180
661
n = int(input()) cnt = 0 ans = [] if n == 3: print('2 5 63') else: for i in range(2, 30001): if cnt == n - 2: break if i % 2 == 0 or i % 3 == 0 or i % 5 == 0: ans.append(i) cnt += 1 sm = sum(ans) for j in range(i+1, 30001): for k in range(j+1, 30001): if (sm + j + k) % (2*3*5) == 0 and\ (j % 2 == 0 or j % 3 == 0 or j % 5 == 0) and\ (k % 2 == 0 or k % 3 == 0 or k % 5 == 0): ans.append(j) ans.append(k) break else: continue break print(' '.join(map(str, ans)))
s292016952
p03971
u711238850
2,000
262,144
Wrong Answer
104
4,584
290
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.
n,a,b = tuple(map(int,input().split())) s = list(input()) count = 0 foreign = 0 for s_i in s: if s_i=='a': if count<=a+b: count+=1 print("Yes") elif s_i=='b': if count<=a+b and foreign <= b: count+=1 foreign+=1 print("Yes") else: print("No")
s408310597
Accepted
106
4,712
370
n,a,b = tuple(map(int,input().split())) s = list(input()) rank = 0 brank = 0 for s_i in s: if s_i=='a': if rank==a+b: print("No") continue rank+=1 print("Yes") elif s_i=='b': if rank==a+b: print("No") continue if brank==b: print("No") continue rank+=1 brank+=1 print("Yes") else: print("No")
s234287629
p02936
u321035578
2,000
1,048,576
Wrong Answer
2,033
94,216
615
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
n,q = map(int,input().split()) bond = [] for i in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 if a > b: tmp = a a = b b = tmp bond.append((a,b)) bond.sort() qry = [] for i in range(q): p,x = map(int,input().split()) p -= 1 qry.append((p,x)) parent = [[] for i in range(n)] for i, ab in enumerate(bond): a,b = ab parent[a].append(b) ans = [0] * n for i, qx in enumerate(qry): q,x = qx ans[q] += x a = '' for i, son in enumerate(parent): a += str(ans[i]) + ' ' for j, s in enumerate(son): ans[s] += ans[i] print(a)
s163142080
Accepted
1,753
67,204
625
from collections import deque n,q = map(int,input().split()) edge = [[] for i in range(n)] for i in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 edge[a].append(b) edge[b].append(a) ans = [0] * n for i in range(q): p,x = map(int,input().split()) p -= 1 ans[p] += x isVisited = [False] * n dq = deque([0]) isVisited[0] = True while len(dq) > 0: parent = dq.popleft() for j, son in enumerate(edge[parent]): if isVisited[son]: continue ans[son] += ans[parent] isVisited[son] = True dq.append(son) print(' '.join(map(str, ans)))
s271592913
p03129
u041196979
2,000
1,048,576
Wrong Answer
18
2,940
98
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
N, K = map(int, input().split()) if (N + K - 1) // 2 >= K: print("Yes") else: print("No")
s489758365
Accepted
17
2,940
94
N, K = map(int, input().split()) if (N + 1) // 2 >= K: print("YES") else: print("NO")
s147741668
p03494
u724154852
2,000
262,144
Time Limit Exceeded
2,104
2,940
227
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.
import sys input = sys.stdin.readline n = int(input()) a = (input().split()) b = 1 while True: for i in range(n-1): if int(a[i]) % 2 == 1: break a[i] = int(a[i]) / 2 b +=1 print(b)
s051674949
Accepted
17
3,060
270
import sys input = sys.stdin.readline n = int(input()) a = list(map(int,input().split())) b = 0 c = 2 f = 0 while True: for i in a: if i % c > 0: f = f +1 break if f == 1: break b = b + 1 c = c * 2 print(b)
s273709004
p04045
u252160635
2,000
262,144
Wrong Answer
27
9,224
631
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
N,K = list(map(int, input().split())) D = list(map(int, input().split())) availbale_numbers = [0,1,2,3,4,5,6,7,8,9] for i in D: availbale_numbers.remove(i) print(availbale_numbers) flg = False for item1 in availbale_numbers: for item2 in availbale_numbers: for item3 in availbale_numbers: for item4 in availbale_numbers: if(N <= int(('').join([str(item1),str(item2),str(item3),str(item4)]))): print(('').join([str(item1),str(item2),str(item3),str(item4)])) exit() Nmin = min(availbale_numbers) print(f'{Nmin}{Nmin}{Nmin}{Nmin}{Nmin}')
s879855431
Accepted
100
9,076
292
N,K = list(map(int, input().split())) D = list(map(int, input().split())) availbale_numbers = [0,1,2,3,4,5,6,7,8,9] for i in D: availbale_numbers.remove(i) for i in range(N,99999): if(set(str(i)) <= set([str(a) for a in availbale_numbers])): print(i) break
s429020718
p03994
u436484848
2,000
262,144
Wrong Answer
72
3,700
309
Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string.
str = input() K = int(input()) tempK = K result = "" for i in range(len(str)): changeNum = 122-ord(str[i])+1 if (changeNum <= tempK): result += "a" tempK -= changeNum else: result += str[i] print(result) if (tempK != 0): result = result[:-1] + chr(ord(str[-1]) + tempK) print(result)
s208917887
Accepted
83
3,572
451
str = input() K = int(input()) tempK = K result = "" for i in range(len(str)-1): changeNum = 122-ord(str[i])+1 if (changeNum <= tempK and str[i] != "a"): result += "a" tempK -= changeNum else: result += str[i] tempK %= 26 if (tempK > 0): changeNum = ord(str[-1]) + tempK if (changeNum > 122): changeNum = changeNum -122 + 97 -1 else: changeNum = changeNum result += chr(changeNum) else: result += str[-1] print(result)
s090139485
p03657
u729294108
2,000
262,144
Wrong Answer
17
2,940
138
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().strip().split()) if all([s % 3 == 0 for s in [a, b, a + b]]): print('Possible') else: print('Impossible')
s739335406
Accepted
17
2,940
138
a, b = map(int, input().strip().split()) if any([s % 3 == 0 for s in [a, b, a + b]]): print('Possible') else: print('Impossible')
s124686301
p03455
u794910686
2,000
262,144
Wrong Answer
18
2,940
100
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=(int(x) for x in input().split()) if a*b%2 == 0: print("even") else: print("odd")
s093168850
Accepted
17
2,940
95
a,b=(int(x) for x in input().split()) if a*b%2 == 0: print("Even") else: print("Odd")
s226345284
p03485
u647767910
2,000
262,144
Wrong Answer
19
3,188
66
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
import math a, b = map(int, input().split()) print(math.ceil(a+b))
s506509071
Accepted
17
2,940
74
import math a, b = map(int, input().split()) print(math.ceil((a + b) / 2))
s158740078
p03359
u892091780
2,000
262,144
Wrong Answer
17
2,940
168
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a,b = map(int,input().split()) cnt = 0 if a <= b : while(cnt <= a): print(cnt+1) cnt = cnt+1 else : while(cnt < a): print(cnt+1) cnt = cnt+1
s730341281
Accepted
17
2,940
77
a,b = map(int,input().split()) if a <= b : print(a) else : print(a-1)
s790365518
p03433
u767664985
2,000
262,144
Wrong Answer
17
2,940
109
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())) b = sorted(a)[:: -1] print(sum(b[:: 2]) - sum(b[1:: 2]))
s049905369
Accepted
17
2,940
83
N, A = eval("int(input())," * 2) if N % 500 <= A: print("Yes") else: print("No")
s286850930
p03131
u859897687
2,000
1,048,576
Wrong Answer
17
3,060
207
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
k,a,b=map(int,input().split()) n=1 if b-a<=2: print(k+1) else: if n < a: n = a k = k-a m = k // 2 print(n,m,b-a) n += (b-a)*m if k % 2 ==1: n+=1 print(n)
s523373720
Accepted
17
3,060
258
k,a,b=map(int,input().split()) n=1 if b-a<=2: n += k print(n) elif k<a-1: n += k print(n) else: #b-a>2 k-(a-1)>=0 n = a k -= a-1 #>0 m = k // 2 n += (b-a)*m if k - 2*m ==1: n+=1 print(n)
s770532980
p03417
u902151549
2,000
262,144
Wrong Answer
17
2,940
25
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
print(2) exit() print(3)
s594189332
Accepted
42
5,724
3,571
# coding: utf-8 import re import math from collections import defaultdict from collections import deque from fractions import Fraction import itertools from copy import deepcopy import random import time import os import queue import sys import datetime from functools import lru_cache #@lru_cache(maxsize=None) readline=sys.stdin.readline sys.setrecursionlimit(2000000) #import numpy as np alphabet="abcdefghijklmnopqrstuvwxyz" mod=int(10**9+7) inf=int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find(): def __init__(self,n): self.n=n self.P=[a for a in range(n)] self.rank=[0]*n def find(self,x): if(x!=self.P[x]):self.P[x]=self.find(self.P[x]) return self.P[x] def same(self,x,y): return self.find(x)==self.find(y) def link(self,x,y): if self.rank[x]<self.rank[y]: self.P[x]=y elif self.rank[y]<self.rank[x]: self.P[y]=x else: self.P[x]=y self.rank[y]+=1 def unite(self,x,y): self.link(self.find(x),self.find(y)) def size(self): S=set() for a in range(self.n): S.add(self.find(a)) return len(S) def is_pow(a,b): now=b while now<a: now*=b if now==a:return True else:return False def getbin(num,size): A=[0]*size for a in range(size): if (num>>(size-a-1))&1==1: A[a]=1 else: A[a]=0 return A def get_facs(n,mod_=0): A=[1]*(n+1) for a in range(2,len(A)): A[a]=A[a-1]*a if(mod_>0):A[a]%=mod_ return A def comb(n,r,mod,fac): if(n-r<0):return 0 return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod def next_comb(num,size): x=num&(-num) y=num+x z=num&(~y) z//=x z=z>>1 num=(y|z) if(num>=(1<<size)):return False else:return num def get_primes(n,type="int"): if n==0: if type=="int":return [] else:return [False] A=[True]*(n+1) A[0]=False A[1]=False for a in range(2,n+1): if A[a]: for b in range(a*2,n+1,a): A[b]=False if(type=="bool"):return A B=[] for a in range(n+1): if(A[a]):B.append(a) return B def is_prime(num): if(num<=1):return False i=2 while i*i<=num: if(num%i==0):return False i+=1 return True def ifelse(a,b,c): if a:return b else:return c def join(A,c=""): n=len(A) A=list(map(str,A)) s="" for a in range(n): s+=A[a] if(a<n-1):s+=c return s def factorize(n,type_="dict"): b = 2 list_ = [] while b * b <= n: while n % b == 0: n //= b list_.append(b) b+=1 if n > 1:list_.append(n) if type_=="dict": dic={} for a in list_: if a in dic: dic[a]+=1 else: dic[a]=1 return dic elif type_=="list": return list_ else: return None def pm(x): return x//abs(x) def inputintlist(): return list(map(int,input().split())) ###################################################################################################### H,W=map(int,input().split()) if H==1 and W==1: ans=1 elif H==1 or W==1: ans=max(H,W)-2 else: ans=(H-2)*(W-2) print(ans)
s695871062
p03523
u984529214
2,000
262,144
Wrong Answer
19
3,188
133
You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
import re akb_re = re.compile(r'A?KIHA?BA?RA?$') s = input() mo = akb_re.match(s) if mo == None: print('No') else: print('Yes')
s867687911
Accepted
19
3,188
133
import re akb_re = re.compile(r'A?KIHA?BA?RA?$') s = input() mo = akb_re.match(s) if mo == None: print('NO') else: print('YES')
s262843712
p03141
u689562091
2,000
1,048,576
Wrong Answer
2,109
43,820
411
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".
N = int(input()) l = [] for i in range(N): l.append(list(map(int, input().split()))) l[i] += [i] lA = sorted(l, key=lambda x: (x[0], -x[1])) lB = sorted(l, key=lambda x: (-x[1])) A = B = 0 while lA or lB: #A if i % 2 == 0: tmp = lA.pop(0) A += tmp[0] lB.remove(tmp) #B else: tmp = lB.pop(0) B += tmp[1] lA.remove(tmp) i += 1 print(A-B)
s928555396
Accepted
369
7,388
208
N = int(input()) l = [] sumB = 0 for i in range(N): a, b = map(int, input().split()) l.append(a + b) sumB += b l.sort(reverse=True) A = 0 for i in range(0, N, 2): A += l[i] print(A - sumB)