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
s881332816
p03149
u371467115
2,000
1,048,576
Wrong Answer
17
2,940
88
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
n=list(map(int,input().split())) s=[1,9,4,7] if n==s: print("YES") else: print("NO")
s648632399
Accepted
17
2,940
98
n=list(map(int,input().split())) s=[1,9,4,7] if set(n)==set(s): print("YES") else: print("NO")
s935552964
p03493
u571710867
2,000
262,144
Wrong Answer
18
2,940
30
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 = str(input()) s.count('1')
s774529980
Accepted
17
2,940
36
s = str(input()) print(s.count('1'))
s458171720
p03719
u079699418
2,000
262,144
Wrong Answer
29
9,088
95
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c=map(int, input().split()) if a <= c <= b: print('YES') else: print('NO')
s314659956
Accepted
26
9,076
85
a,b,c=map(int,input().split()) if a <= c <= b: print('Yes') else: print('No')
s461752545
p02614
u595353654
1,000
1,048,576
Wrong Answer
123
27,192
3,292
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
##a = int(stdin.readline().rstrip()) ##b, c = [int(x) for x in stdin.readline().rstrip().split()] ##s = stdin.readline().rstrip() ##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...] ##a = [[0] * 2 for _ in range(n)] a[0,0] # -*- coding: utf-8 -*- from sys import stdin from operator import itemgetter from collections import deque, Counter import math import pprint from functools import reduce import numpy as np import random import bisect import copy MOD = 1000000007 INF = float('inf') alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] def keta(kazu): kazu_str = str(kazu) kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))] return kazu_list def gcd(*numbers): return reduce(math.gcd, numbers) def combination(m,n): # mCn if n > m: return 'すまん' return math.factorial(m) // (math.factorial(m-n) * math.factorial(n)) def pow_k(x,n): if n == 0: return 1 K = 1 while n > 1: if n % 2 != 0: K *= x x *= x n //= 2 return K * x def fact(n): arr = {} temp = n for i in range(2,int(n**0.5)+1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr[i] = cnt if temp != 1: arr[temp] = 1 if arr == {}: arr[n] = 1 return arr def main(): h, w, k = [int(x) for x in stdin.readline().rstrip().split()] board = [] kuro = 0 pattern_h = [[0]*h for _ in range(2 ** h)] pattern_w = [[0]*w for _ in range(2 ** w)] ans = 0 nokori = 0 for _ in range(h): s = stdin.readline().rstrip() v = [s[i] for i in range(0, len(s))] kuro += v.count("#") board.append(v) memo = copy.deepcopy(board) for i in range(2 ** h): for j in range(h): if (i >> j) & 1: pattern_h[i][j] = j + 1 for i in range(2 ** w): for j in range(w): if (i >> j) & 1: pattern_w[i][j] = j + 1 for i in range(2 ** w): for j in range(w): if pattern_w[i][j] != 0: for l in range(h): memo[l][j] = "x" print(memo) for i2 in range(2 ** h): for j2 in range(h): if pattern_h[i2][j2] == 0: nokori += memo[j2].count("#") if k == nokori: ans += 1 nokori = 0 memo = copy.deepcopy(board) print(ans) main()
s536159774
Accepted
122
27,288
3,272
##a = int(stdin.readline().rstrip()) ##b, c = [int(x) for x in stdin.readline().rstrip().split()] ##s = stdin.readline().rstrip() ##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...] ##a = [[0] * 2 for _ in range(n)] a[0,0] # -*- coding: utf-8 -*- from sys import stdin from operator import itemgetter from collections import deque, Counter import math import pprint from functools import reduce import numpy as np import random import bisect import copy MOD = 1000000007 INF = float('inf') alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] def keta(kazu): kazu_str = str(kazu) kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))] return kazu_list def gcd(*numbers): return reduce(math.gcd, numbers) def combination(m,n): # mCn if n > m: return 'すまん' return math.factorial(m) // (math.factorial(m-n) * math.factorial(n)) def pow_k(x,n): if n == 0: return 1 K = 1 while n > 1: if n % 2 != 0: K *= x x *= x n //= 2 return K * x def fact(n): arr = {} temp = n for i in range(2,int(n**0.5)+1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr[i] = cnt if temp != 1: arr[temp] = 1 if arr == {}: arr[n] = 1 return arr def main(): h, w, k = [int(x) for x in stdin.readline().rstrip().split()] board = [] kuro = 0 pattern_h = [[0]*h for _ in range(2 ** h)] pattern_w = [[0]*w for _ in range(2 ** w)] ans = 0 nokori = 0 for _ in range(h): s = stdin.readline().rstrip() v = [s[i] for i in range(0, len(s))] kuro += v.count("#") board.append(v) memo = copy.deepcopy(board) for i in range(2 ** h): for j in range(h): if (i >> j) & 1: pattern_h[i][j] = j + 1 for i in range(2 ** w): for j in range(w): if (i >> j) & 1: pattern_w[i][j] = j + 1 for i in range(2 ** w): for j in range(w): if pattern_w[i][j] != 0: for l in range(h): memo[l][j] = "x" for i2 in range(2 ** h): for j2 in range(h): if pattern_h[i2][j2] == 0: nokori += memo[j2].count("#") if k == nokori: ans += 1 nokori = 0 memo = copy.deepcopy(board) print(ans) main()
s043944742
p03448
u186893542
2,000
262,144
Wrong Answer
56
3,064
204
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()) res = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if a*i + b*j + c*k == x: res += 1 print(res)
s817983712
Accepted
49
3,064
210
a = int(input()) b = int(input()) c = int(input()) x = int(input()) res = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if 500*i + 100*j + 50*k == x: res += 1 print(res)
s871643059
p02418
u914146430
1,000
131,072
Wrong Answer
20
7,404
70
Write a program which finds a pattern $p$ in a ring shaped text $s$.
s=input() p=input() if p in s: print("Yes") else: print("No")
s055686084
Accepted
20
7,476
76
s=input() p=input() s+=s if p in s: print("Yes") else: print("No")
s909330694
p02690
u768496010
2,000
1,048,576
Wrong Answer
44
9,164
250
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
x = int(input()) def fun(x): res = [] for a in range(-100, 100): for b in range(-100, 100): mult = a**5 - b**5 if mult == x: res = a, b break print(str(res)[1:-1]) fun(x)
s817400918
Accepted
1,988
9,116
254
x = int(input()) def fun(x): res = [] for a in range(-1000, 1000): for b in range(-1000, 1000): mult = a**5 - b**5 if mult == x: res = a, b break print(res[0], res[1]) fun(x)
s391738219
p03680
u021337285
2,000
262,144
Wrong Answer
175
13,392
218
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
N = int(input()) a = list(map(int, [input() for i in range(N)])) current_index = 1 for i in range(N - 1): current_index = a[current_index - 1] if current_index == 2: print(i) exit() print(-1)
s906436112
Accepted
173
13,356
221
N = int(input()) a = list(map(int, [input() for i in range(N)])) current_index = 1 for i in range(N - 1): current_index = a[current_index - 1] if current_index == 2: print(i + 1) exit() print(-1)
s379112734
p03407
u488127128
2,000
262,144
Wrong Answer
18
2,940
66
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')
s543550640
Accepted
17
2,940
66
a,b,c = map(int, input().split()) print('Yes' if a+b>=c else 'No')
s756743664
p03493
u254091062
2,000
262,144
Wrong Answer
26
9,048
24
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.
a = input() a.count('1')
s263759916
Accepted
26
9,076
31
a = input() print(a.count('1'))
s605004580
p03416
u419686324
2,000
262,144
Wrong Answer
63
2,940
102
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
a, b = map(int, input().split()) sum(map(lambda i: 1 if str(i) == str(i)[::-1] else 0, range(a, b+1)))
s087235690
Accepted
62
3,064
109
a, b = map(int, input().split()) print(sum(map(lambda i: 1 if str(i) == str(i)[::-1] else 0, range(a, b+1))))
s260091503
p02646
u457460736
2,000
1,048,576
Wrong Answer
31
9,612
343
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.
import math import collections import itertools import copy def YesNo(Bool): if(Bool): print("YES") else: print("NO") return def resolve(): A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) if(A+V*T >= B+W*T): print("Yes") else: print("No") resolve()
s975048352
Accepted
33
9,456
589
import math import collections import itertools import copy def YesNo(Bool): if(Bool): print("YES") else: print("NO") return def resolve(): A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) if(A<B and V<=W): print("NO") return if(A>B and V<=W): print("NO") return if(A<B): if(A+V*T >= B+W*T): print("YES") else: print("NO") else: if(A-V*T <= B-W*T): print("YES") else: print("NO") resolve()
s459116939
p03962
u393229280
2,000
262,144
Wrong Answer
25
3,444
79
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
import collections a = input() c = collections.Counter(list(a)) print(len(c))
s499888370
Accepted
20
3,316
82
import collections a = input() c = collections.Counter(a.split()) print(len(c))
s324874509
p02612
u724742135
2,000
1,048,576
Wrong Answer
27
9,152
70
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.
from sys import stdin N = int(stdin.readline().rstrip()) print(N%1000)
s172613928
Accepted
25
9,056
82
from sys import stdin N = int(stdin.readline().rstrip()) print((1000-N%1000)%1000)
s392146572
p03379
u735008991
2,000
262,144
Wrong Answer
491
25,228
165
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.
import bisect N = int(input()) X = list(map(int, input().split())) Y = sorted(X.copy()) for x in X: print(Y[N//2-1] if bisect.bisect(Y, x) >= N//2 else Y[N//2])
s727332240
Accepted
496
25,224
164
import bisect N = int(input()) X = list(map(int, input().split())) Y = sorted(X.copy()) for x in X: print(Y[N//2-1] if bisect.bisect(Y, x) > N//2 else Y[N//2])
s708259337
p03623
u665038048
2,000
262,144
Wrong Answer
17
2,940
66
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x, a, b = map(int, input().split()) print(min(abs(x-a), abs(x-b)))
s667967166
Accepted
17
2,940
95
x, a, b = map(int, input().split()) if abs(x-a) > abs(x-b): print('B') else: print('A')
s177474630
p03777
u789364190
2,000
262,144
Wrong Answer
17
2,940
98
Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest.
str = input().split(' ') a = str[0] b = str[1] res = 'H' if a != b: res = 'D' else: res = 'H'
s190605197
Accepted
17
2,940
111
str = input().split(' ') a = str[0] b = str[1] res = 'H' if a != b: res = 'D' else: res = 'H' print(res)
s638941644
p01125
u124909914
8,000
131,072
Wrong Answer
90
6,780
859
宇宙暦 1603〜1867 年,人々はその時代のことを EDO 時代と呼ぶ.EDO とは当時最先端の宇宙航行技術,Enhanced Driving Operation のことであり、1603 年に Dr.Izy によって開発された. あなたは宇宙冒険家であり,宇宙を飛び回って様々な惑星を冒険していた.その冒険の途中で,あなたはとても不思議な惑星を発見した.その惑星には,至るところに七色に輝く不思議な宝石が落ちていた.あなたはその惑星への降下を試みようと考えたが,重大な問題のためにそれは不可能であることがわかった.その惑星の空気には,人間が触れただけで即死してしまうような猛毒の成分が含まれていたのだ. そこで,あなたはロボットを使って宝石を回収することを考えついた.あなたはその惑星の周回軌道にて待機する.そして,降下させたロボットを遠隔操作することによって宝石を回収するのだ.あなたは,ロボットに「移動する方向」と「移動する距離」の組からなる命令の列によってロボットを遠隔操作する.ロボットは移動経路上(到達点を含む)に宝石を見つけると,それらを全て回収する. あなたの仕事は,ロボットが与えられた全ての命令の実行を終えたときに,全ての宝石を回収することができたかどうかを判定するプログラムを書くことである. なお,ロボットが不思議な宝石を回収する範囲はそれほど広くない.そのため,ロボットが移動する範囲は全て 2 次元の平面で表すことができる.そして,ロボットが移動する範囲は (0,0) および (20,20) をそれぞれ左下隅および右上隅とする正方形の内部(境界線を含む)である.ロボットは常に範囲の中央,すなわち (10,10) の座標に降下する.また,全ての宝石は中央以外の格子点上にあることが保証されている.
#!/usr/bin/python3 while True: n = int(input()) if n == 0 : break gems = [] for i in range(n): gem = tuple(map(int, input().split())) gems.append(gem) m = int(input()) bot = [10, 10] history = [(10, 10)] for j in range(m): move = list(input().split()) move[1] = int(move[1]) if move[0] == 'N': index = 1 #y direc = 1 # pos elif move[0] == 'S': index = 1 derec = -1 elif move[0] == 'E': index = 0 #x direc = 1 else: #W index = 0 direc = -1 for j in range(abs(move[1])): bot[index] += direc history.append(tuple(bot)) for g in gems: if g not in history: print("No") break print("Yes")
s985437313
Accepted
90
6,784
885
#!/usr/bin/python3 while True: n = int(input()) if n == 0 : break gems = [] for i in range(n): gem = tuple(map(int, input().split())) gems.append(gem) m = int(input()) bot = [10, 10] history = [(10, 10)] for j in range(m): move = list(input().split()) move[1] = int(move[1]) if move[0] == 'N': index = 1 #y direc = 1 # pos elif move[0] == 'S': index = 1 direc = -1 elif move[0] == 'E': index = 0 #x direc = 1 else: #W index = 0 direc = -1 for j in range(abs(move[1])): bot[index] += direc history.append(tuple(bot)) f = True for g in gems: if g not in history: f = False break print("Yes" if f else "No")
s588012097
p03712
u370413678
2,000
262,144
Wrong Answer
17
3,060
195
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.
size=[int(i) for i in input().split()] image=[[str(input())] for i in range(size[0])] print(image) print("#"*(size[1]+2)) for i in image: print(''.join(["#"]+i+["#"])) print("#"*(size[1]+2))
s330578164
Accepted
17
3,060
182
size=[int(i) for i in input().split()] image=[[str(input())] for i in range(size[0])] print("#"*(size[1]+2)) for i in image: print(''.join(["#"]+i+["#"])) print("#"*(size[1]+2))
s665558346
p02694
u746154235
2,000
1,048,576
Wrong Answer
25
9,248
150
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()) import math price=100 year=0 while True: price += round(price*0.01) year+=1 print(price) if price >= X: break print(year)
s813456506
Accepted
23
9,144
120
import math X = int(input()) price=100 year=0 while price < X: price += math.floor(price*0.01) year+=1 print(year)
s929133122
p03796
u807021746
2,000
262,144
Wrong Answer
2,206
9,924
87
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.
import math N = int(input()) a = math.factorial(N) print(a) x = a % (10**9+7) print(x)
s557619520
Accepted
157
9,892
77
import math N = int(input()) a = math.factorial(N) x = a % (10**9+7) print(x)
s827181656
p03556
u223904637
2,000
262,144
Wrong Answer
23
2,940
64
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()) ans=0 while ans*ans<=n: ans+=1 print(ans-1)
s954504624
Accepted
23
2,940
69
n=int(input()) ans=0 while ans*ans<=n: ans+=1 print((ans-1)**2)
s864221065
p04046
u957084285
2,000
262,144
Wrong Answer
328
18,804
479
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7.
MOD = 10**9+7 N = 200000 p = [1] * (N+1) q = [1] * (N+1) for i in range(1, N+1): p[i] = (p[i-1]*(i)%MOD) q[0] = pow(p[-1], MOD-2, MOD) for i in range(1, N+1): q[i] = (N-i+1)*q[i-1]%MOD q.reverse() def nCk(n,k): if k > n or n == 0: return 0 elif k == 0: return 1 else: return p[n]*q[k]%MOD*q[n-k]%MOD h,w,a,b = map(int, input().split()) ans = 0 for i in range(b, w): ans += nCk(h-a+i-1, i)*nCk(w-i-2+a, w-i-1)%MOD print(ans%MOD)
s292088103
Accepted
335
18,804
492
MOD = 10**9+7 N = 200000 p = [1] * (N+1) q = [1] * (N+1) for i in range(1, N+1): p[i] = (p[i-1]*(i)%MOD) q[0] = pow(p[-1], MOD-2, MOD) for i in range(1, N+1): q[i] = (N-i+1)*q[i-1]%MOD q.reverse() def nCk(n,k): if k > n or (k != 0 and n == 0): return 0 elif k == 0: return 1 else: return p[n]*q[k]%MOD*q[n-k]%MOD h,w,a,b = map(int, input().split()) ans = 0 for i in range(b, w): ans += nCk(h-a+i-1, i)*nCk(w-i-2+a, w-i-1)%MOD print(ans%MOD)
s112776093
p03759
u143051858
2,000
262,144
Wrong Answer
17
2,940
78
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')
s881389677
Accepted
17
2,940
79
A,B,C=map(int,input().split()) if B-A==C-B: print('YES') else: print('NO')
s758973735
p03836
u044459372
2,000
262,144
Wrong Answer
17
3,064
385
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.
def main(): sx, sy, tx, ty = map(int, input().split()) ans = solve(sx, sy, tx, ty) print(ans) def solve(sx, sy, tx, ty): dx = tx - sx dy = ty - sy st = 'U' * dy + 'R' * dx ts = 'D' * dy + 'L' * dy rt1 = st + ts rt2 = 'L' + 'U' + st + 'R' + 'D' + 'R' + 'D' + ts + 'L' + 'U' ans = rt1 + rt2 return ans if __name__ == '__main__': main()
s394976088
Accepted
17
3,064
385
def main(): sx, sy, tx, ty = map(int, input().split()) ans = solve(sx, sy, tx, ty) print(ans) def solve(sx, sy, tx, ty): dx = tx - sx dy = ty - sy st = 'U' * dy + 'R' * dx ts = 'D' * dy + 'L' * dx rt1 = st + ts rt2 = 'L' + 'U' + st + 'R' + 'D' + 'R' + 'D' + ts + 'L' + 'U' ans = rt1 + rt2 return ans if __name__ == '__main__': main()
s247548969
p03836
u830054172
2,000
262,144
Wrong Answer
17
3,060
235
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()) x = tx-sx y = ty-sy ans = "" out1 = "R"*x+"U"*y return1 = "L"*x+"D"*y out2a = "LU" out2b = "RD" return2a = "RD" return2b = "LU" print(out1+return1+out2a+out1+out2b+return2a+return1+return2b)
s489536761
Accepted
17
3,060
172
sx, sy, tx, ty = map(int, input().split()) x = tx-sx y = ty-sy ans = "" go = "U"*y+"R"*x back = "D"*y+"L"*x a1 = "LU" a2 = "RDRD" a3 = "LU" print(go+back+a1+go+a2+back+a3)
s794576017
p03523
u601575292
2,000
262,144
Wrong Answer
2,103
3,064
424
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`?
S = list(input()) n = len(S) def solve(S): if n < 5 or n > 9: return "No" while len(S) < 9: if S[0] != "A": S.insert(0, "A") elif S[4] != "A": S.insert(4, "A") elif S[6] != "A": S.insert(6, "A") elif S[-1] != "A": S.append("A") if "".join(S) == "AKIHABARA": return "Yes" else: return "No" print(solve(S))
s836532797
Accepted
19
3,188
112
import re S = input() if re.fullmatch(r"A?KIHA?BA?RA?",S): print("YES") else: print("NO") exit()
s638610427
p02831
u242196904
2,000
1,048,576
Wrong Answer
18
2,940
186
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
def gcd(a, b): if a < b : a, b = b, a while True: a, b = b, a % b if b == 0: return a a, b = map(int, input().split()) int(a * b / gcd(a, b))
s824102909
Accepted
17
3,060
193
def gcd(a, b): if a < b : a, b = b, a while True: a, b = b, a % b if b == 0: return a a, b = map(int, input().split()) print(int(a * b / gcd(a, b)))
s119188371
p03567
u503111914
2,000
262,144
Wrong Answer
20
2,940
100
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
S = input() for i in range(len(S)-1): if S[i]+S[i] == "AC": print("Yes") break print("No")
s979112607
Accepted
18
2,940
119
import sys S = input() for i in range(len(S)-1): if S[i]+S[i+1] == "AC": print("Yes") sys.exit() print("No")
s677176075
p03693
u993268357
2,000
262,144
Wrong Answer
17
2,940
28
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
a = input().strip() print(a)
s853787901
Accepted
18
2,940
97
a = input().strip().split() num = int(''.join(a)) if num%4==0: print('YES') else: print('NO')
s808096725
p03486
u584520370
2,000
262,144
Wrong Answer
17
2,940
143
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 = list(input()) t = list(input()) s_a = ''.join(sorted(s)) t_a = ''.join(sorted(t)) if s_a < t_a : print('Yes') else : print('No')
s217336597
Accepted
17
2,940
156
s = list(input()) t = list(input()) s_a = ''.join(sorted(s)) t_a = ''.join(sorted(t, reverse=True)) if s_a < t_a : print('Yes') else : print('No')
s144138504
p02842
u759076129
2,000
1,048,576
Wrong Answer
28
9,100
194
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
n = int(input()) x = round(n / 1.08) n_dash = int(x*1.08) if n_dash == n: print(n_dash) elif n_dash-1 == n: print(n_dash-1) elif n_dash+1 == n: print(n_dash+1) else: print(':(')
s368601915
Accepted
27
9,124
262
def n_cand(x): return int(x*1.08) n = int(input()) x = round(n / 1.08) n_dash = n_cand(x) n_dash_m = n_cand(x-1) n_dash_p = n_cand(x+1) if n_dash == n: print(x) elif n_dash_m == n: print(x-1) elif n_dash_p == n: print(x+1) else: print(':(')
s894041042
p02396
u494048940
1,000
131,072
Wrong Answer
90
6,348
148
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.
i=0 a=list() while True : a.append(int(input())) i+=1 if a[i-1]==0: break for j in range(i) : print("Case" , j+1 ,":",a[j])
s836998032
Accepted
140
5,616
117
i=0 a=list() while True : a=int(input()) if a == 0: break i+=1 print('Case %d: %d'%(i,a))
s481812899
p03455
u609814378
2,000
262,144
Wrong Answer
132
3,064
227
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(str, input().split()) abint = int(a+b) ans = 0 for i in range(1,1001): for j in range(1,1001): if i*j == abint and i == j: ans = ans + 1 if ans == 0: print("No") else: print("Yes")
s644333971
Accepted
17
2,940
103
a,b = map(int, input().split()) a_b = ((a*b)%2) if a_b == 0: print("Even") else: print("Odd")
s429059584
p03377
u379142263
2,000
262,144
Wrong Answer
21
3,316
289
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import collections a,b,x = map(int,input().split()) ab = a+b least = x - a if least<0: print("No") sys.exit() if b>=least: print("Yes") else: print("No")
s232673525
Accepted
21
3,316
237
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import collections a,b,x = map(int,input().split()) ab = a+b if x>=a and x<=ab: print("YES") else: print("NO")
s662993721
p02972
u224346910
2,000
1,048,576
Wrong Answer
413
22,716
276
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
def main(): N = int(input()) a = [None] + list(map(int, input().split())) b = [0]*(N+1) for i in range(N, 0, -1): ball = [b[j] for j in range(i, N+1, i)] if sum(ball) % 2 != a[i]: b[i] = 1 print(' '.join(map(str, b[1:]))) main()
s084302712
Accepted
427
19,248
351
def main(): N = int(input()) a = [None] + list(map(int, input().split())) b = [None] + [0]*N for i in range(N, 0, -1): ball = [b[j] for j in range(i, N+1, i)] if sum(ball) % 2 != a[i]: b[i] = 1 ans = [str(i) for i, n in enumerate(b) if n==1] print(len(ans)) print(' '.join(map(str, ans))) main()
s479107176
p03229
u455696302
2,000
1,048,576
Wrong Answer
1,025
11,072
874
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
N = int(input()) A = [int(input()) for _ in range(N)] A = sorted(A) print(A) res = 0 if len(A) % 2 == 1: if len(A) > 3: mid = int(len(A)/2) now_num = A.pop(mid) for i in range(len(A)): if len(A) == 0: break if i % 2 == 0: res += A[-1] - now_num now_num = A.pop(-1) else: res += now_num - A[0] now_num = A.pop(0) print(res) else: res += A[-1] - A[0] res += A[-2] - A[0] print(res) else: mid = int(len(A)/2) - 1 now_num = A.pop(mid) for i in range(len(A)): if len(A) == 0: break if i % 2 == 0: res += A[-1] - now_num now_num = A.pop(-1) else: res += now_num - A[0] now_num = A.pop(0) print(res)
s277470786
Accepted
1,884
8,928
818
N = int(input()) A_in = [int(input()) for _ in range(N)] A = sorted(A_in) res1 = 0 A2 = [] for i in range(len(A)): if len(A) == 1: if abs(A[0] - A2[0]) < abs(A[0] - A2[-1]): A2.append(A[0]) else: A2.insert(0,A[0]) break if i % 2 == 0: A2.append(A.pop(-1)) else: A2.append(A.pop(0)) for i in range(len(A2)-1): res1 += abs(A2[i] - A2[i+1]) A = sorted(A_in,reverse=True) res2 = 0 A2 = [] for i in range(len(A)): if len(A) == 1: if abs(A[0] - A2[0]) < abs(A[0] - A2[-1]): A2.append(A[0]) else: A2.insert(0,A[0]) break if i % 2 == 0: A2.append(A.pop(-1)) else: A2.append(A.pop(0)) for i in range(len(A2)-1): res2 += abs(A2[i] - A2[i+1]) print(max(res1,res2))
s197378441
p03997
u980503157
2,000
262,144
Wrong Answer
26
9,100
68
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*h)
s772938432
Accepted
21
9,148
74
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)/2*h))
s041765243
p03400
u667024514
2,000
262,144
Wrong Answer
17
2,940
132
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
import math n = int(input()) d,x = map(int,input().split()) cou = x for i in range(n): cou += math.ceil(int(input())/d) print(cou)
s520006661
Accepted
18
3,060
162
import math n = int(input()) d,x = map(int,input().split()) lis = [int(input()) for i in range(n)] cou = x for i in range(n):cou += math.ceil(d/lis[i]) print(cou)
s134099473
p03671
u243159381
2,000
262,144
Wrong Answer
28
9,056
115
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
a,b,c=map(int,input().split()) if a>b and a>c: print(a+b) elif b>a and b>c: print(a+c) else: print(b+c)
s087745270
Accepted
27
8,916
62
a=list(map(int,input().split())) b=sorted(a) print(b[0]+b[1])
s222426929
p02972
u536325690
2,000
1,048,576
Wrong Answer
2,104
7,716
402
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
N = int(input()) a = [-1] a.extend([int(i) for i in input().split()]) ans = [-1] ans.extend([0 for i in range(N)]) for i in reversed(range(1, N+1)): tmp = 0 for j in reversed(range(i,N+1)): if j == i: if tmp % 2 == 0: ans[j] = 1 else: ans[j] = 0 if j % i == 0: tmp += ans[j] print(len(ans)-1) print(ans[1:])
s261058482
Accepted
615
14,136
350
N = int(input()) a = [int(i) for i in input().split()] ans = [0 for i in range(N)] for i in reversed(range(1, N+1)): tmp = 0 for j in range(i, N+1, i): tmp += ans[j-1] if tmp % 2 != a[i-1]: ans[i-1] = 1 anslist = [] for i in range(N): if ans[i] == 1: anslist.append(i+1) print(len(anslist)) print(*anslist)
s931737730
p03472
u552176911
2,000
262,144
Wrong Answer
288
29,856
396
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
import math n, h = map(int, input().split(" ")) abL = [list(map(int, input().split(" "))) for _ in range(n)] aL = [] bL = [] for a, b in abL: aL.append(a) bL.append(b) aL = sorted(aL) bL = sorted(bL) aMax = max(aL) ans = 0 while h != 0: if h <= 0: break if len(bL) == 0 or bL[-1] < aMax: ans += h // aMax break ans += 1 h -= bL.pop() print(ans)
s835162110
Accepted
286
29,732
406
import math n, h = map(int, input().split(" ")) abL = [list(map(int, input().split(" "))) for _ in range(n)] aL = [] bL = [] for a, b in abL: aL.append(a) bL.append(b) aL = sorted(aL) bL = sorted(bL) aMax = max(aL) ans = 0 while h != 0: if h <= 0: break if len(bL) == 0 or bL[-1] < aMax: ans += math.ceil(h / aMax) break ans += 1 h -= bL.pop() print(ans)
s468760567
p03447
u626228246
2,000
262,144
Wrong Answer
19
2,940
82
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()) buf = ((X-A)//B)*B print(X-A-B)
s638756614
Accepted
17
2,940
85
X = int(input()) A = int(input()) B = int(input()) buf = ((X-A)//B)*B print(X-A-buf)
s377632261
p02396
u482227082
1,000
131,072
Wrong Answer
130
5,568
122
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
for i in range(10000): line = input() if line == "0": break else: print("Case ", "i: ", line)
s454904321
Accepted
130
5,628
197
# # 3b # def main(): i = 1 while True: x = int(input()) if x == 0: break print(f"Case {i}: {x}") i += 1 if __name__ == '__main__': main()
s142918294
p03816
u665038048
2,000
262,144
Wrong Answer
46
14,564
78
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
n = int(input()) a = list(map(int, input().split())) print(len(list(set(a))))
s363604985
Accepted
51
14,388
152
n = int(input()) a = list(map(int, input().split())) if len(list(set(a))) % 2 == 1: print(len(list(set(a)))) else: print(len(list(set(a))) - 1)
s793571711
p03599
u145889196
3,000
262,144
Wrong Answer
79
3,188
832
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()) density=0 Ans1=0 Ans2=0 water=set() sugar=set() bm=F//(100*B) for i in range(bm+1): rw=F-100*i*B am=rw//(100*A) for j in range(am+1): water.add(100*i*B+100*j*A) dm=F//D for i in range(dm+1): rs=F-i*D cm=rs//C for j in range(cm+1): sugar.add(i*D+j*C) sugar=sorted(sugar) sugar.pop(0) water=sorted(water) water.pop(0) for s in sugar: for w in water: if w/100*E<s: break elif s+w>F: break else: den=s/w if den>density: density=den Ans1=s+w Ans2=s else: break print(Ans1) print(Ans2)
s688037081
Accepted
76
3,188
639
#C A,B,C,D,E,F=map(int,input().split()) density=0 Ans1=0 Ans2=0 water=set() sugar=set() bm=F//(100*B) for i in range(bm+1): rw=F-100*i*B am=rw//(100*A) for j in range(am+1): water.add(100*i*B+100*j*A) dm=F//D for i in range(dm+1): rs=F-i*D cm=rs//C for j in range(cm+1): sugar.add(i*D+j*C) sugar=sorted(sugar) water=sorted(water) for s in sugar: for w in water: if w/100*E>=s and s+w<=F and s+w!=0: den=s/(s+w) if den>=density: density=den Ans1=s+w Ans2=s else: break print(Ans1,Ans2)
s659408777
p03623
u922487073
2,000
262,144
Wrong Answer
16
2,940
64
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b = map(int, input().split()) print(min(abs(x-a), abs(x-b)))
s988057523
Accepted
17
2,940
76
x,a,b = map(int, input().split()) print("B" if abs(x-a) > abs(x-b) else "A")
s204991007
p03477
u320098990
2,000
262,144
Wrong Answer
26
9,016
230
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.
in_list = input().split(' ') A = in_list[0] B = in_list[1] C = in_list[2] D = in_list[3] L = int(A) + int(B) R = int(C) + int(D) print(L, R) if L < R: print('Right') elif L > R: print('Left') else: print('Balanced')
s850650347
Accepted
25
9,056
217
in_list = input().split(' ') A = in_list[0] B = in_list[1] C = in_list[2] D = in_list[3] L = int(A) + int(B) R = int(C) + int(D) if L < R: print('Right') elif L > R: print('Left') else: print('Balanced')
s838874266
p03372
u794173881
2,000
262,144
Wrong Answer
794
47,040
1,016
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
n,c = map(int,input().split()) info = [[0,0]]+[list(map(int,input().split())) for i in range(n)]+[[c,0]] left_info = info[::-1] right_ruiseki = [0]*(n+1) left_ruiseki = [0]*(n+1) ou_right_ruiseki = [0]*(n+1) ou_left_ruiseki = [0]*(n+1) for i in range(n): right_ruiseki[i+1] = right_ruiseki[i] + info[i+1][1] - info[i+1][0] + info[i][0] left_ruiseki[i+1] = left_ruiseki[i] + left_info[i+1][1] + left_info[i+1][0] - left_info[i][0] ou_right_ruiseki[i+1] = ou_right_ruiseki[i] + info[i+1][1] - 2*info[i+1][0] + 2*info[i][0] ou_left_ruiseki[i+1] = ou_left_ruiseki[i] + left_info[i+1][1] + 2*left_info[i+1][0] - 2*left_info[i][0] for i in range(n): right_ruiseki[i+1]=max(right_ruiseki[i],right_ruiseki[i+1]) left_ruiseki[i+1]=max(left_ruiseki[i],left_ruiseki[i+1]) ans = 0 for i in range(n): tmp1 = ou_right_ruiseki[i+1]+left_ruiseki[n-(i+1)] tmp2 = ou_left_ruiseki[i+1]+right_ruiseki[n-(i+1)] ans = max(tmp1,tmp2,ans) print(ans)
s741712898
Accepted
802
47,040
1,075
n,c = map(int,input().split()) info = [[0,0]]+[list(map(int,input().split())) for i in range(n)]+[[c,0]] left_info = info[::-1] right_ruiseki = [0]*(n+1) left_ruiseki = [0]*(n+1) ou_right_ruiseki = [0]*(n+1) ou_left_ruiseki = [0]*(n+1) for i in range(n): right_ruiseki[i+1] = right_ruiseki[i] + info[i+1][1] - info[i+1][0] + info[i][0] left_ruiseki[i+1] = left_ruiseki[i] + left_info[i+1][1] + left_info[i+1][0] - left_info[i][0] ou_right_ruiseki[i+1] = ou_right_ruiseki[i] + info[i+1][1] - 2*info[i+1][0] + 2*info[i][0] ou_left_ruiseki[i+1] = ou_left_ruiseki[i] + left_info[i+1][1] + 2*left_info[i+1][0] - 2*left_info[i][0] for i in range(n): right_ruiseki[i+1]=max(right_ruiseki[i],right_ruiseki[i+1]) left_ruiseki[i+1]=max(left_ruiseki[i],left_ruiseki[i+1]) ans = 0 for i in range(n+1): tmp1 = ou_right_ruiseki[i]+left_ruiseki[n-i] tmp2 = ou_left_ruiseki[i]+right_ruiseki[n-i] ans = max(tmp1,tmp2,ans) print(ans)
s188772834
p03605
u153419200
2,000
262,144
Wrong Answer
17
2,940
67
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
a=input() if a[0]==9 or a[1]==9: print('Yes') else: print('No')
s826759821
Accepted
17
2,940
70
a=int(input()) if a>=90 or a%10==9: print('Yes') else: print('No')
s295826595
p02238
u923668099
1,000
131,072
Wrong Answer
30
7,720
807
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving the vertex from which $v$ was discovered. This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source. DFS timestamps each vertex as follows: * $d[v]$ records when $v$ is first discovered. * $f[v]$ records when the search finishes examining $v$’s adjacency list. Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules: * $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively. * IDs in the adjacency list are arranged in ascending order. * The program should report the discover time and the finish time for each vertex. * When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID. * The timestamp starts with 1.
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None time = 0 def dfs(u, adj, d, f, sumi): global time time += 1 d[u] = time for v in adj[u]: if v not in sumi: dfs(v, adj, d, f, sumi) sumi.add(v) time += 1 f[u] = time def solve(): n = int(input()) adj = [None] * n for i in range(n): u, k, *vs = [int(j) - 1 for j in input().split()] adj[u] = vs d = [0] * n f = [0] * n sumi = {0} dfs(0, adj, d, f, sumi) for i in range(n): print(i, d[i], f[i]) pass if __name__ == '__main__': solve()
s574399946
Accepted
20
7,824
1,037
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None time = 0 def dfs(u, adj, d, f, sumi): global time sumi.add(u) time += 1 d[u] = time for v in adj[u]: if v not in sumi: dfs(v, adj, d, f, sumi) time += 1 f[u] = time def solve(): n = int(input()) adj = [None] * n for i in range(n): u, k, *vs = [int(j) - 1 for j in input().split()] adj[u] = vs d = [0] * n f = [0] * n sumi = {0} mitan = set(range(1, n)) dfs(0, adj, d, f, sumi) mitan -= sumi while mitan: u = min(mitan) dfs(u, adj, d, f, sumi) mitan -= sumi for i in range(n): print(i + 1, d[i], f[i]) pass if __name__ == '__main__': solve()
s917661406
p03151
u369402805
2,000
1,048,576
Wrong Answer
125
18,356
582
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
N = int(input()) a_list = [int(a) for a in input().split()] b_list = [int(a) for a in input().split()] # N = 3 # a_list = [17, 7, 1] # b_list = [25, 6, 14] if sum(a_list) < sum(b_list): print("-1") else: d_list = [a - b for a, b in zip(a_list, b_list)] d_list.sort() minus = [d for d in d_list if d < 0] deficit = sum(minus) ans = len(minus) if deficit == 0: print("0") else: for i in range(N): deficit += d_list[-i] if deficit >= 0: ans += i + 1 break print(str(ans))
s308027651
Accepted
133
19,068
533
N = int(input()) a_list = [int(a) for a in input().split()] b_list = [int(a) for a in input().split()] if sum(a_list) < sum(b_list): print("-1") else: d_list = [a - b for a, b in zip(a_list, b_list)] d_list.sort() minus = [d for d in d_list if d < 0] deficit = sum(minus) ans = len(minus) if deficit == 0: print("0") else: for i in range(N): deficit += d_list[-i - 1] if deficit >= 0: ans += i + 1 break print(str(ans))
s069504883
p02612
u118665579
2,000
1,048,576
Wrong Answer
28
9,132
30
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n%1000)
s130002546
Accepted
28
9,148
87
S = int(input()) if S % 1000 == 0: W = 0 else: W = 1000-(S % 1000) print(W) 190
s318210278
p03795
u779073299
2,000
262,144
Wrong Answer
18
2,940
52
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.
a = int(input()) ans = a*800 - (a%15)*200 print(ans)
s130428997
Accepted
17
2,940
53
a = int(input()) ans = a*800 - (a//15)*200 print(ans)
s291561457
p02264
u684241248
1,000
131,072
Wrong Answer
30
6,000
378
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
from collections import deque n, q = [int(_) for _ in input().split()] processes = deque([tuple(input().split()) for i in range(n)]) time = 0 while processes: process = processes.popleft() if int(process[1]) < q: time += int(process[1]) print(process[0], time) else: time += q processes.append((process[0], int(process[1]) - q))
s038718871
Accepted
340
12,644
379
from collections import deque n, q = [int(_) for _ in input().split()] processes = deque([tuple(input().split()) for i in range(n)]) time = 0 while processes: process = processes.popleft() if int(process[1]) <= q: time += int(process[1]) print(process[0], time) else: time += q processes.append((process[0], int(process[1]) - q))
s034053733
p02401
u757827098
1,000
131,072
Wrong Answer
20
7,648
263
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 = input().split() a =int(a) b =int(b) if op == '?': break if op == '+': print(a+b) if op == '-': print(a-b) if op == '*': print(a*b) if op == '/': print(a/b)
s016587724
Accepted
30
7,656
264
while True: a,op,b = input().split() a =int(a) b =int(b) if op == '?': break if op == '+': print(a+b) if op == '-': print(a-b) if op == '*': print(a*b) if op == '/': print(a//b)
s601799101
p03139
u371467115
2,000
1,048,576
Wrong Answer
17
2,940
79
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()) s=min(a,b) l=abs(a+b)-n print(str(s)+" "+str(l))
s405710121
Accepted
17
2,940
102
n,a,b=map(int,input().split()) s=min(a,b) l=0 if n<a+b: l=abs(n-abs(b+a)) print("{} {}".format(s,l))
s081854195
p02422
u239721772
1,000
131,072
Wrong Answer
20
7,552
827
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
string = list(input()) times = int(input()) for i in range(times): order = input().split() if order[0] == "replace": replace_string = order[3] count = 0 for j in range(int(order[1]), int(order[2]) + 1): string[j] = replace_string[count] count += 1 #print(count) elif order[0] == "reverse": reverse_string = string[int(order[1]):int(order[2]) + 1] reverse_string.reverse() for j in range(int(order[1]), int(order[2]) + 1): string[j] = reverse_string[j] #string[int(order[1]):int(order[2]) + 1].reverse() print(string) #string[int(order[1]):int(order[2])] = string[int(order[1]):int(order[2])].reverse() elif order[0] == "print": print("".join(string[int(order[1]):int(order[2]) + 1]))
s889440438
Accepted
20
7,700
611
string = list(input()) times = int(input()) for i in range(times): order = input().split() if order[0] == "replace": replace_string = order[3] count = 0 for j in range(int(order[1]), int(order[2]) + 1): string[j] = replace_string[count] count += 1 elif order[0] == "reverse": reverse_string = string[int(order[1]):int(order[2]) + 1] reverse_string.reverse() string = string[:int(order[1])] + reverse_string + string[int(order[2])+1:] elif order[0] == "print": print("".join(string[int(order[1]):int(order[2]) + 1]))
s256496299
p02742
u545644875
2,000
1,048,576
Wrong Answer
17
3,060
176
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()) if h%2 == 0: result = w*h/2 elif w%2 == 0: result = w*(h - 1)/2 + w/2 else: result = w*(h - 1)/2 + (w + 1)/2 print(result)
s090760819
Accepted
17
2,940
156
h, w = map(int, input().split()) x = (h * w) % 2 if h == 1 or w == 1: print(1) elif x == 0: print((h * w) // 2) else: print(((h * w) // 2) + 1)
s372952012
p03160
u566264434
2,000
1,048,576
Wrong Answer
102
13,980
249
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.
def dp1(n,h): dp=[10^5]*n dp[0]=0 dp[1]=abs(h[1]-h[0]) for i in range(2,n-1): dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])) return dp[n-1] n=int(input()) h = list(map(int, input().split())) print(dp1(n,h))
s334480225
Accepted
104
13,980
247
def dp1(n,h): dp=[10^5]*n dp[0]=0 dp[1]=abs(h[1]-h[0]) for i in range(2,n): dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])) return dp[n-1] n=int(input()) h = list(map(int, input().split())) print(dp1(n,h))
s856545293
p03697
u145600939
2,000
262,144
Wrong Answer
17
2,940
82
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.
a,b = map(int,input().split()) if a+b >= 10: print('error') else: print('a+b')
s950629509
Accepted
17
2,940
81
a,b = map(int,input().split()) if a+b >= 10: print('error') else: print(a+b)
s919006603
p03379
u314089899
2,000
262,144
Wrong Answer
289
25,744
901
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.
#094c N = int(input()) #N<200000=2 * 10**5 X_list = [int(e) for e in input().split()] X_list.sort(reverse=False) Bi_smaller = X_list[int(len(X_list)/2-1)] Bi_bigger = X_list[int(len(X_list)/2)] for i in range(int(N/2)): #for j in range(N): # if j!=i: # print(X_list[j],end="") print(Bi_bigger) for i in range(int(N/2),N): #for j in range(N): # if j!=i: # print(X_list[j],end="") print(Bi_smaller)
s784722427
Accepted
330
25,732
363
#094c import copy N = int(input()) #N<200000=2 * 10**5 X_list = [int(e) for e in input().split()] sort_X_list = copy.copy(X_list) sort_X_list.sort(reverse=False) Bi_smaller = sort_X_list[int(len(X_list)/2-1)] Bi_bigger = sort_X_list[int(len(X_list)/2)] for i in range(N): if X_list[i]>=Bi_bigger: print(Bi_smaller) else: print(Bi_bigger)
s052873271
p03478
u925950392
2,000
262,144
Wrong Answer
32
2,940
239
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(' ')) total = 0 for number in range(N): total_number = 0 for number_str in str(number): total_number += int(number_str) if total_number >= A and total_number <= B: total += number print(total)
s180572099
Accepted
32
2,940
247
N, A, B = map(int, input().split(' ')) total = 0 for number in range(1, N + 1): total_number = 0 for number_str in str(number): total_number += int(number_str) if total_number >= A and total_number <= B: total += number print(total)
s502752586
p03636
u007263493
2,000
262,144
Wrong Answer
17
2,940
51
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
s = str(input()) s = s[1:] s = s[:-1] print(len(s))
s217363704
Accepted
17
2,940
79
s = str(input()) a = s[0] b = s[-1] s = s[1:] s = s[:-1] print(a+str(len(s))+b)
s199727458
p03470
u379716238
2,000
262,144
Wrong Answer
17
3,060
175
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
N = int(input()) a = [] for i in range(N): a.append(int(input())) res = 0 data = 0 for i in range(N): if a[i] > data: res += 1 data = a[i] print(res)
s256339812
Accepted
153
12,504
135
N = int(input()) d_list = [] for i in range(N): d_list.append(int(input())) import numpy as np n = np.unique(d_list) print(len(n))
s057038582
p02615
u039860745
2,000
1,048,576
Wrong Answer
218
31,444
408
Quickly after finishing the tutorial of the online game _ATChat_ , you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the **friendliness** of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets **comfort** equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?
N = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) # print(A) limit = 0 ans = 0 count = 0 for i,a in enumerate(A): limit = 2 if i == 0: limit = 1 for j in range(limit, 1, -1): # print(j) if j > 0: ans += a count += 1 # print(count) if count > N - 1: break # print(N - 1) print(ans)
s164203470
Accepted
205
31,540
290
N = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) limit = 0 ans = 0 count = 0 lim = 0 t = N - 1 for i in range(N): lim = 2 if i == 0: lim = 1 for j in range(lim): if t > 0: ans += A[i] t -= 1 print(ans)
s863295345
p03214
u215115622
2,525
1,048,576
Wrong Answer
17
2,940
108
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
a=input().split() a=[int(i) for i in a] avg =sum(a)/len(a) a=[abs(i -avg) for i in a] print(a.index(min(a)))
s354782370
Accepted
17
2,940
118
a=input() a=input().split() a=[int(i) for i in a] avg =sum(a)/len(a) a=[abs(i -avg) for i in a] print(a.index(min(a)))
s563375370
p03624
u697658632
2,000
262,144
Wrong Answer
17
3,188
131
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
s = input() for i in range(ord('a'), ord('z') + 1): c = chr(i) if s.count(c) > 0: print(c) break else: print('None')
s270910350
Accepted
20
3,188
132
s = input() for i in range(ord('a'), ord('z') + 1): c = chr(i) if s.count(c) == 0: print(c) break else: print('None')
s914950484
p03795
u275212209
2,000
262,144
Wrong Answer
17
2,940
51
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(round((800*n) - (200*(n/15))))
s956708140
Accepted
17
2,940
47
n=int(input()) x=800*n y=(n//15)*200 print(x-y)
s622569548
p03457
u084069244
2,000
262,144
Wrong Answer
324
3,060
159
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
N = int(input()) for i in range(N): t,x,y = map(int, input().split()) if x + y < t or (x + y + t) % 2: print("No") exit() print("Yes")
s981831385
Accepted
329
3,060
163
N = int(input()) for _ in range(N): t, x, y = map(int, input().split()) if x + y > t or (t + x + y)%2 != 0: print("No") quit() print("Yes")
s468386248
p03160
u194894739
2,000
1,048,576
Wrong Answer
115
13,980
220
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N = int(input()) h = list(map(int,input().split())) dp = [0] * N for i in range(1, N): if i == 1: dp[i] = abs(h[1] - h[0]) else: dp[i] = min(abs(h[i] - h[i-1]), abs(h[i] - h[i-2])) print(dp[N-1])
s376976071
Accepted
210
13,924
261
N = int(input()) H = list(map(int, input().split())) dp = [10**9]*N dp[0] = 0 for i in range(N): if i+1 <= N-1: dp[i+1] = min(dp[i+1], dp[i]+abs(H[i+1]-H[i])) if i+2 <= N-1: dp[i+2] = min(dp[i+2], dp[i]+abs(H[i+2]-H[i])) print(dp[N-1])
s469790225
p02402
u106285852
1,000
131,072
Wrong Answer
20
7,584
864
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
# import import sys int(input()) inputData = map(int, input().split()) maxData = 0 minData = 0 totalData = 0 for inputVal in inputData: if inputVal > maxData: maxData = inputVal if inputVal < minData: minData = inputVal totalData += inputVal # ???????????? print(minData, maxData, totalData)
s785932453
Accepted
20
8,336
912
# import import sys n = int(input()) inputData = map(int, input().split()) maxData = -1000000 minData = 1000000 totalData = 0 for inputVal in inputData: if inputVal > maxData: maxData = inputVal # minimum value check if inputVal < minData: minData = inputVal totalData += inputVal # ???????????? print(minData, maxData, totalData)
s768768181
p02612
u072717685
2,000
1,048,576
Wrong Answer
30
9,160
267
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines #import numpy as np def main(): n = int(input()) if n % 1000: print(n // 1000 + 1) else: print(n // 1000) if __name__ == '__main__': main()
s932331581
Accepted
29
9,196
256
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines from math import ceil #import numpy as np def main(): n = int(input()) r = ceil(n / 1000) * 1000 - n print(r) if __name__ == '__main__': main()
s141739221
p03636
u825528847
2,000
262,144
Wrong Answer
18
2,940
56
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
S = input() print(S[0] + str(len(S[1:len(S)])) + S[-1])
s341790136
Accepted
17
2,940
58
S = input() print(S[0] + str(len(S[1:len(S)-1])) + S[-1])
s390893750
p03997
u559313689
2,000
262,144
Wrong Answer
23
9,096
68
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)
s367632735
Accepted
24
9,084
74
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h/2))
s330380945
p03479
u039360403
2,000
262,144
Wrong Answer
2,104
2,940
132
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
X,Y=map(int,input().split()) ans=0 for i in range(1,10**18): if X*i<Y: ans+=1 else: print(ans) break
s185636306
Accepted
17
2,940
146
X,Y=map(int,input().split()) ans=1 for i in range(1,10**18): if X*2<=Y: X*=2 ans+=1 else: print(ans) break
s860764679
p00005
u011621222
1,000
131,072
Wrong Answer
30
7,540
191
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
a,b=map(int,input().split()) for i in range(1,a+1): f=(b*i)%a lcm=(b*i) if f==0: break for j in range(1,a+1): if a%j==0 and b%j==0 and j*lcm==a*b: print(j,lcm)
s489812382
Accepted
20
5,664
147
import math while True: try: a,b = map(int,input().split()) print(math.gcd(a,b),a*b//math.gcd(a,b)) except: break
s967368512
p03005
u598229387
2,000
1,048,576
Wrong Answer
17
2,940
60
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()) if k==1: ans=0 else: ans=n-k
s311179619
Accepted
17
2,940
71
n,k=map(int,input().split()) if k==1: ans=0 else: ans=n-k print(ans)
s895642537
p03478
u153729035
2,000
262,144
Wrong Answer
31
3,296
98
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()) sum([i for i in range(n+1) if a<=sum([int(c) for c in str(i)])<=b])
s146058599
Accepted
30
3,296
107
n,a,b=map(int,input().split()) print(sum([i for i in range(1,n+1) if a<=sum([int(c) for c in str(i)])<=b]))
s759359151
p02412
u340901659
1,000
131,072
Wrong Answer
20
7,732
457
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
def solve(n,x): count = 0 for i in range(1,n+1): for j in range(1,n+1): if i == j : continue for k in range(1,n+1): if j == k or i == k: continue if i+j+k == x: print(i,j,k) count += 1 return count//6 while True: n,x = map(int,input().split()) if n == x == 0: break; print(solve(n,x))
s450055829
Accepted
40
7,644
297
def solve(n,x): count = 0 for i in range(1,n+1): for j in range(i+1,n+1): k = x - i - j if j < k and k <= n: count += 1 return count while True: n,x = map(int,input().split()) if n == x == 0: break; print(solve(n,x))
s826900337
p04030
u894623942
2,000
262,144
Wrong Answer
26
8,948
256
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
S = list(input()) print(S) S_after = [] for i in S: if i == '1': S_after.append(1) elif i == '0': S_after.append(0) elif i == 'B': if S_after == []: pass else: S_after.pop() print(S_after)
s176697821
Accepted
27
8,736
260
S = list(input()) S_after = [] for i in S: if i == '1': S_after.append('1') elif i == '0': S_after.append('0') elif i == 'B': if S_after == []: pass else: S_after.pop() print(''.join(S_after))
s512112470
p02694
u131925051
2,000
1,048,576
Wrong Answer
23
9,164
140
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()) yen = 100 i = 0 def rishi(yen): return int(yen * 1.01) while 1: yen = rishi(yen) i += 1 if X < yen: break print(i)
s425347105
Accepted
20
9,156
141
X = int(input()) yen = 100 i = 0 def rishi(yen): return int(yen * 1.01) while 1: i += 1 yen = rishi(yen) if X <= yen: break print(i)
s819415091
p02613
u058259032
2,000
1,048,576
Wrong Answer
167
16,316
370
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()) list = [] for i in range(N): list.append(input()) C0 = 0 C1 = 0 C2 = 0 C3 = 0 for i in range(N): if list[i] == "AC": C0 += 1 elif list[i] == "WA": C1 += 1 elif list[i] == "TLE": C2 += 1 elif list[i] == "RE": C3 += 1 print("AC * ", C0) print("WA * ", C1) print("TLE * ", C2) print("RE * ", C3)
s234590807
Accepted
167
16,240
365
N = int(input()) list = [] for i in range(N): list.append(input()) C0 = 0 C1 = 0 C2 = 0 C3 = 0 for i in range(N): if list[i] == "AC": C0 += 1 elif list[i] == "WA": C1 += 1 elif list[i] == "TLE": C2 += 1 elif list[i] == "RE": C3 += 1 print("AC x",C0) print("WA x", C1) print("TLE x", C2) print("RE x", C3)
s505450612
p03854
u787059958
2,000
262,144
Wrong Answer
28
9,164
851
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() idx = 0 while True: if idx >= len(S) - 1: break if S[idx:idx + 7] == 'dreamer' and (S[idx + 5:idx + 10] != 'erase' or S[idx + 5:idx + 11] != 'eraser'): idx += 7 elif S[idx:idx + 6] == 'eraser' and (S[idx + 4:idx + 9] != 'erase' or S[idx + 4:idx + 10] != 'eraser'): idx += 6 elif S[idx:idx + 5] == 'dream' or S[idx:idx + 5] == 'erase': idx += 5 else: print('No') exit() print('Yes')
s067605989
Accepted
65
9,088
229
S = input() L = ['maerd', 'remaerd', 'esare', 'resare'] T = '' for i in range(len(S) - 1, -1, -1): T += S[i] if T not in L and len(T) > 7: print('NO') exit() elif T in L: T = '' print('YES')
s187901479
p03730
u940743763
2,000
262,144
Wrong Answer
18
3,060
293
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = list(map(int, input().split(' '))) checker = {} d = a while(True): m = (d - c) % b checker.setdefault(m, False) if m == 0: print('Yes') break elif checker[m]: print('No') break else: checker[m] = True d += a
s630083667
Accepted
17
3,060
293
a, b, c = list(map(int, input().split(' '))) checker = {} d = a while(True): m = (d - c) % b checker.setdefault(m, False) if m == 0: print('YES') break elif checker[m]: print('NO') break else: checker[m] = True d += a
s290047549
p04043
u448655578
2,000
262,144
Wrong Answer
17
2,940
152
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.
haiku = [5,7,5] a = input().split(" ") for i in a: if i in haiku: haiku.pop(haiku.index(i)) if len(haiku) == 0: print("YES") else: print("NO")
s655539927
Accepted
17
2,940
119
haiku = [5,5,7] a = list(map(int, input().split(" "))) a = sorted(a) if haiku == a: print("YES") else: print("NO")
s428680437
p02612
u727787724
2,000
1,048,576
Wrong Answer
27
9,096
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n=int(input()) print(n%1000)
s747733270
Accepted
28
9,008
67
n=int(input()) if n%1000==0: print(0) else: print(1000-n%1000)
s508058173
p03361
u796942881
2,000
262,144
Wrong Answer
18
3,064
623
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
def main(): dy = [1, 0, -1, 0] dx = [0, 1, 0, -1] H, W = map(int, input().split()) s = ["." * (W + 2)] s += ["." + input() + "." for i in range(H)] s.append("." * (W + 2)) print(s) for y in range(1, H + 1): for x in range(1, W + 1): if s[y][x] == "#" and s[y + dy[0]][x + dx[0]] == "."\ and s[y + dy[1]][x + dx[1]] == "."\ and s[y + dy[2]][x + dx[2]] == "."\ and s[y + dy[3]][x + dx[3]] == ".": print("No") return print("Yes") return main()
s069011288
Accepted
18
3,064
551
def main(): dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)] H, W = map(int, input().split()) s = ["." * (W + 2)] s += ["." + input() + "." for i in range(H)] s.append("." * (W + 2)) for y in range(1, H + 1): for x in range(1, W + 1): if "." == s[y][x]: continue for dy, dx in dyx: if "#" == s[y + dy][x + dx]: break else: print("No") return print("Yes") return main()
s594273143
p02927
u569185453
2,000
1,048,576
Wrong Answer
22
2,940
221
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
M, D = map(int, input().split()) for i in range(M+1): for j in range(D+1): d10 = int(j /10) d1 = int(j % 10) if d10 >=2 and d1 >=2 and d10 * d1 ==i: print("{}月{}日".format(i, j))
s272540094
Accepted
23
3,060
222
M, D = map(int, input().split()) count = 0 for i in range(M+1): for j in range(D+1): d10 = int(j /10) d1 = int(j % 10) if d10 >=2 and d1 >=2 and d10 * d1 ==i: count += 1 print(count)
s868732204
p03814
u834301346
2,000
262,144
Wrong Answer
36
10,244
109
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`.
import re letter = str(input()) pattern = 'A(.*)Z' target = re.search(pattern, letter).group() print(target)
s874404614
Accepted
35
10,024
114
import re letter = str(input()) pattern = 'A(.*)Z' target = re.search(pattern, letter).group() print(len(target))
s168232848
p02613
u928758473
2,000
1,048,576
Wrong Answer
151
9,728
968
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.
import os import sys from collections import defaultdict, Counter from itertools import product, permutations,combinations, accumulate from operator import itemgetter from bisect import bisect_left,bisect from heapq import heappop,heappush,heapify from math import ceil, floor, sqrt, gcd from copy import deepcopy from functools import reduce def main(): n = int(input()) lists = [] ans = [0]*4 for i in range(n): s = input() if not s in lists: lists.append(s) if s == "AC": ans[0] += 1 elif s == "WA" : ans[1] += 1 elif s == "TLE": ans[2] += 1 else: ans[3] += 1 for i in ans: if i == "AC": print("AC x", i) elif i == "WA" : print("WA x", i) elif i == "TLE": print("TLE x", i) else: print("RE x", i) if __name__ == "__main__": main()
s171238034
Accepted
149
9,736
978
import os import sys from collections import defaultdict, Counter from itertools import product, permutations,combinations, accumulate from operator import itemgetter from bisect import bisect_left,bisect from heapq import heappop,heappush,heapify from math import ceil, floor, sqrt, gcd from copy import deepcopy from functools import reduce def main(): n = int(input()) lists = [] ans = [0]*4 for i in range(n): s = input() if not s in lists: lists.append(s) if s == "AC": ans[0] += 1 elif s == "WA" : ans[1] += 1 elif s == "TLE": ans[2] += 1 else: ans[3] += 1 for i in range(len(ans)): if i == 0: print("AC x", ans[i]) elif i == 1 : print("WA x", ans[i]) elif i == 2: print("TLE x", ans[i]) else: print("RE x", ans[i]) if __name__ == "__main__": main()
s476629988
p03626
u721316601
2,000
262,144
Wrong Answer
18
3,064
404
We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square. Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors. Find the number of such ways to paint the dominoes, modulo 1000000007. The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner: * Each domino is represented by a different English letter (lowercase or uppercase). * The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.
MOD = 1000000007 N = int(input()) S1 = input() S2 = input() if S1[0] == S2[0]: ans, idx = 3, 1 else: ans, idx = 6, 2 while idx < N: print(S1[idx]) if S1[idx] == S2[idx]: if S1[idx-1] == S2[idx-1]: ans *= 2 idx += 1 else: if S1[idx-1] == S2[idx-1]: ans *= 2 else: ans *= 3 idx += 2 ans %= MOD print(ans)
s458062050
Accepted
17
3,064
385
MOD = 1000000007 N = int(input()) S1 = input() S2 = input() if S1[0] == S2[0]: ans, idx = 3, 1 else: ans, idx = 6, 2 while idx < N: if S1[idx] == S2[idx]: if S1[idx-1] == S2[idx-1]: ans *= 2 idx += 1 else: if S1[idx-1] == S2[idx-1]: ans *= 2 else: ans *= 3 idx += 2 ans %= MOD print(ans)
s556547924
p02690
u465101448
2,000
1,048,576
Wrong Answer
64
9,132
153
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
X=int(input()) for a in range(-125,125): for b in range(-125,125): i = a**5-b**5 if i == X: print(a,b) break
s730243022
Accepted
62
9,184
171
X=int(input()) ans='' for a in range(-125,125): for b in range(-125,125): i = a**5-b**5 if i == X: ans=[a,b] print(' '.join(map(str,ans)))
s025722276
p02259
u841567836
1,000
131,072
Wrong Answer
20
5,596
419
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
def bubble(l): N = len(l) flag = 1 while flag: flag = 0 for j in range(N - 1, 1 - 1, -1): if l[j] < l[j - 1]: l[j], l[j - 1] = l[j - 1], l[j] flag = 1 return l if __name__ == '__main__': n = int(input()) l = input().split() for i in range(n): l[i] = int(l[i]) l = bubble(l) count = 0 leng = len(l) for i in l: count += 1 if count < leng: print(i, end =' ') else: print(i)
s654927356
Accepted
20
5,608
467
def bubble(l): count = 0 N = len(l) flag = 1 while flag: flag = 0 for j in range(N - 1, 1 - 1, -1): if l[j] < l[j - 1]: l[j], l[j - 1] = l[j - 1], l[j] flag = 1 count += 1 return l, count if __name__ == '__main__': n = int(input()) l = input().split() for i in range(n): l[i] = int(l[i]) l, c = bubble(l) count = 0 leng = len(l) for i in l: count += 1 if count < leng: print(i, end =' ') else: print(i) print(c)
s561836733
p02393
u656153606
1,000
131,072
Wrong Answer
20
7,732
306
Write a program which reads three integers, and prints them in ascending order.
a, b, c = [int(i) for i in input().split()] if a > b: if b > c: print(a, b, c) else: print(a, c, b) elif b > a: if a > c: print(b, a, c) else: print(b, c, a) elif c > b: if b > a: print(c, b, a) else: print(c, a, b)
s037232553
Accepted
20
7,728
91
input = [int(i) for i in input().split()] input.sort() print(input[0], input[1], input[2])
s309964843
p02397
u648117624
1,000
131,072
Time Limit Exceeded
9,990
5,896
129
Write a program which reads two integers x and y, and prints them in ascending order.
x,y = map(int, input().split()) while True: if x == 0 and y == 0 : break list = [x, y] print(list.sort())
s420239211
Accepted
60
5,608
193
while True: x,y = map(int, input().split()) if x == 0 and y == 0: break elif x <= y: print(str(x) + " " + str(y)) else: print(str(y) + " " + str(x))
s207260306
p03130
u151625340
2,000
1,048,576
Wrong Answer
18
2,940
157
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
p = [0,0,0,0] for i in range(3): ai, bi = map(int, input().split()) p[ai-1] += 1 p[bi-1] += 1 if 3 in p: print('YES') else: print('NO')
s551219618
Accepted
17
2,940
157
p = [0,0,0,0] for i in range(3): ai, bi = map(int, input().split()) p[ai-1] += 1 p[bi-1] += 1 if 3 in p: print('NO') else: print('YES')
s261011879
p03079
u456595418
2,000
1,048,576
Wrong Answer
17
3,060
136
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
l = [] l= list(map(int,input().split())) ls = sorted(l) a = ls[0] b = ls[1] c = ls[2] if a + b <= c: print("Yes") else: print("No")
s801355725
Accepted
17
2,940
125
l = [] l= list(map(int,input().split())) a = l[0] b = l[1] c = l[2] if a == b and a == c: print("Yes") else: print("No")
s646676357
p03575
u111508936
2,000
262,144
Wrong Answer
152
12,504
1,426
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
import numpy as np import math # K = int(input()) # N, K = map(int, input().split()) # A = list(map(int, input().split())) N, M = map(int, input().split()) E = np.zeros((N, N), dtype=int) for m in range(M): s, t = map(int, input().split()) s = s-1 t = t-1 E[s][t] = 1 E[t][s] = 1 # print(E) bridges = set() TIME = 0 def bridgeN(n, visited, parent, low, dis): global TIME visited[n] = 1 dis[n] = TIME low[n] = TIME TIME += 1 # print('time', TIME) # print('n=', n) # print('visited=', visited) for v in range(N): if E[n][v] == 0: continue if visited[v] == 1: if v != parent[n]: low[n] = min(low[n], dis[v]) continue print('visited[', v, ']=', visited[v]) parent[v] = n bridgeN(v, visited, parent, low, dis) low[n] = min(low[n], low[v]) if low[v] > dis[n]: if v <= n: bridges.add((v, n)) else: bridges.add((n, v)) def bridge(E): visited = np.zeros(N, dtype=int) dis = np.full_like(visited, N*N*10) low = np.full_like(visited, N*N*10) parent = np.full_like(visited, -1) for n in range(N): if visited[n] == 0: bridgeN(n, visited, parent, low, dis) bridge(E) nBridges = len(bridges) # print(bridges) print(nBridges)
s318847440
Accepted
152
12,512
1,428
import numpy as np import math # K = int(input()) # N, K = map(int, input().split()) # A = list(map(int, input().split())) N, M = map(int, input().split()) E = np.zeros((N, N), dtype=int) for m in range(M): s, t = map(int, input().split()) s = s-1 t = t-1 E[s][t] = 1 E[t][s] = 1 # print(E) bridges = set() TIME = 0 def bridgeN(n, visited, parent, low, dis): global TIME visited[n] = 1 dis[n] = TIME low[n] = TIME TIME += 1 # print('time', TIME) # print('n=', n) # print('visited=', visited) for v in range(N): if E[n][v] == 0: continue if visited[v] == 1: if v != parent[n]: low[n] = min(low[n], dis[v]) continue # print('visited[', v, ']=', visited[v]) parent[v] = n bridgeN(v, visited, parent, low, dis) low[n] = min(low[n], low[v]) if low[v] > dis[n]: if v <= n: bridges.add((v, n)) else: bridges.add((n, v)) def bridge(E): visited = np.zeros(N, dtype=int) dis = np.full_like(visited, N*N*10) low = np.full_like(visited, N*N*10) parent = np.full_like(visited, -1) for n in range(N): if visited[n] == 0: bridgeN(n, visited, parent, low, dis) bridge(E) nBridges = len(bridges) # print(bridges) print(nBridges)
s286898627
p03853
u292978925
2,000
262,144
Wrong Answer
18
3,060
124
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).
h, w = map(int, input().split()) in1 = [] for idx1 in range(h): in1.append(input()) for item1 in in1: print(item1)
s168222173
Accepted
17
3,060
225
#a = '2 2' #b = ['*.', '.*'] h, w = map(int, input().split()) #h, w = map(int, a.split()) in1 = [] for idx1 in range(h): in1.append(input()) # in1.append(b[idx1]) for item1 in in1: print(item1) print(item1)