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
s644170469
p03024
u879077265
2,000
1,048,576
Wrong Answer
17
2,940
85
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S = input() t = S.count("x") if t <= 7: print("Yes") else: print("No")
s032646098
Accepted
17
2,940
86
S = input() t = S.count("x") if t <= 7: print("YES") else: print("NO")
s184630832
p03636
u853900545
2,000
262,144
Wrong Answer
18
2,940
36
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]+'len(s)'+s[-1])
s047065288
Accepted
17
2,940
46
s=input() a=len(s)-2 print(s[0]+str(a)+s[-1])
s963042394
p03434
u557437077
2,000
262,144
Wrong Answer
17
3,060
203
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = input() a = [int(i) for i in input().split()] a = sorted(a) alice = 0 bob = 0 for i in reversed(range(len(a))): if i % 2 == 0: alice += a[i] else: bob += a[i] print(alice-bob)
s040012186
Accepted
17
3,060
200
n = input() a = [int(i) for i in input().split()] a = sorted(a) alice = 0 bob = 0 for i in range(len(a)): if i % 2 == 0: alice += a[-i-1] else: bob += a[-i- 1] print(alice-bob)
s100959612
p03473
u786020649
2,000
262,144
Wrong Answer
28
9,080
25
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
print(24+int(input())%24)
s653112244
Accepted
26
9,152
26
print(48-int(input())%24)
s398308816
p02412
u546968095
1,000
131,072
Wrong Answer
30
5,652
312
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
import math while True: n,x = map(int,input().split()) if n == x == 0: break c = 0 for i in range(math.ceil(x/3), x-3): for j in range(math.ceil(i/2), i): k = i - j if x == i + j + k: #print(x, i, j, k) c += 1 print(c)
s180606376
Accepted
490
5,596
272
while True: n,x = map(int,input().split()) if n == x == 0: break n = n + 1 c = 0 for i in range(1,n): for j in range(i+1,n): for k in range(j+1,n): if x == i + j + k: c += 1 print(c)
s494841186
p03569
u754022296
2,000
262,144
Wrong Answer
301
3,316
228
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly: * Insert a letter `x` to any position in s of his choice, including the beginning and end of s. Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
s = input() ans = 0 while s: if s[0] == s[-1]: s = s[1:-2] else: if s[0] == "x": ans += 1 s = s[1:] elif s[-1] == "x": ans += 1 s = s[:-1] else: print(-1) exit() print(ans)
s243625806
Accepted
309
3,316
228
s = input() ans = 0 while s: if s[0] == s[-1]: s = s[1:-1] else: if s[0] == "x": ans += 1 s = s[1:] elif s[-1] == "x": ans += 1 s = s[:-1] else: print(-1) exit() print(ans)
s721124918
p03711
u975676823
2,000
262,144
Wrong Answer
17
3,064
213
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
a, b = map(int, input().split()) if(a in [4, 6, 9, 11]): print("YES" if b in [4, 6, 9, 11] else "NO") elif(a in [1, 3, 5, 7, 8, 10, 12]): print("YES" if b in [1, 3, 5, 7, 8, 10, 12] else "NO") else: print("NO")
s523910885
Accepted
17
3,064
217
a, b = map(int, input().split()) if(a in [4, 6, 9, 11]): print("Yes" if (b in [4, 6, 9, 11]) else "No") elif(a in [1, 3, 5, 7, 8, 10, 12]): print("Yes" if (b in [1, 3, 5, 7, 8, 10, 12]) else "No") else: print("No")
s282669725
p03697
u319805917
2,000
262,144
Wrong Answer
18
2,940
203
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=input() LIs=list(a) count=0 for i in range(len(LIs)): for g in range (len(LIs)): if LIs[i]==LIs[g]: count+=1 if count==0: print("yes") else: print("no")
s440486559
Accepted
18
2,940
82
a,b=map(int,input().split()) if a+b>=10: print("error") else: print(a+b)
s304069826
p03139
u286955577
2,000
1,048,576
Wrong Answer
18
2,940
147
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.
def solve(N, A, B): maxNum = max(A, B) minNum = max(0, N - (A + B)) print(maxNum, minNum) N, A, B = map(int, input().split()) solve(N, A, B)
s846606817
Accepted
17
3,064
148
def solve(N, A, B): maxNum = min(A, B) minNum = max(0, (A + B) - N) print(maxNum, minNum) N, A, B = map(int, input().split()) solve(N, A, B)
s686095770
p02795
u815763296
2,000
1,048,576
Wrong Answer
27
9,188
321
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
import sys H = int(input()) W = int(input()) N = int(input()) X = max(H, W) Y = min(H, W) count = 0 total = 0 for i in range(Y): total += X count += 1 if count >= N: print(count) sys.exit() for i in range(X): total += Y count += 1 if count >= N: print(count) break
s677472079
Accepted
28
9,092
322
import sys H = int(input()) W = int(input()) N = int(input()) X = max(H, W) Y = min(H, W) count = 0 total = 0 for _ in range(Y): total += X count += 1 if total >= N: print(count) sys.exit() for _ in range(X): total += Y count += 1 if ctotal >= N: print(count) break
s506243424
p00052
u990228206
1,000
131,072
Wrong Answer
260
5,596
322
n! = n × (n − 1) × (n − 2) × ... × 3 × 2 × 1 を n の階乗といいます。例えば、12 の階乗は 12! = 12 × 11 × 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 479001600 となり、末尾に 0 が 2 つ連続して並んでいます。 整数 n を入力して、n! の末尾に連続して並んでいる 0 の数を出力するプログラムを作成してください。ただし、n は 20000 以下の正の整数とします。
while 1: try: zero=0 number=1 n=int(input()) for i in range(1,n+1): number*=i while len(str(number))>7:number=int(str(number)[1:]) while number%10==0: zero+=1 number=int(number/10) print(zero) except:break
s526695858
Accepted
260
5,588
274
while 1: zero=0 number=1 n=int(input()) if n==0:break for i in range(1,n+1): number*=i while len(str(number))>7:number=int(str(number)[1:]) while number%10==0: zero+=1 number=int(number/10) print(zero)
s469877092
p02396
u427088273
1,000
131,072
Wrong Answer
20
7,552
109
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.
num = list(map(int,input().split())) for i,s in enumerate(num,1): print("Case {0}: {1}".format(i,s))
s672760380
Accepted
150
7,652
160
count = 0 while(True): num = int(input()) if num == 0: break count += 1 print("Case {0}: {1}".format(count,num))
s911961696
p03456
u743164083
2,000
262,144
Wrong Answer
17
2,940
91
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
n = input().split() x = int("".join(n)) print("Yes") if x%x**0.5 == x**0.5 else print("No")
s688248469
Accepted
17
2,940
92
n = input().split() x = int("".join(n))**0.5 print("Yes") if x.is_integer() else print("No")
s740494678
p03546
u293992530
2,000
262,144
Wrong Answer
40
9,504
704
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
import sys sys.setrecursionlimit(2147483647) input=sys.stdin.readline import math from heapq import heappush, heappop def solve(h,w,tables,A): for i in range(10): for j in range(10): for k in range(10): tables[j][k] = min(tables[j][k], tables[j][i] + tables[i][k]) cost = 0 for i in range(h): for j in range(w): p = A[i][j] cost += tables[p][1] return cost def main(): h, w = map(int, input().split(' ')) tables = [] for i in range(10): tables.append(list(map(int, input().split(' ')))) A = [] for _ in range(h): A.append(list(map(int, input().split(' ')))) ans = solve(h, w, tables, A) print(ans) if __name__=='__main__': main()
s525074344
Accepted
38
9,616
739
import sys sys.setrecursionlimit(2147483647) input=sys.stdin.readline import math from heapq import heappush, heappop def solve(h,w,tables,A): for i in range(10): for j in range(10): for k in range(10): tables[j][k] = min(tables[j][k], tables[j][i] + tables[i][k]) cost = 0 for i in range(h): for j in range(w): p = A[i][j] if p == -1: continue cost += tables[p][1] return cost def main(): h, w = map(int, input().split(' ')) tables = [] for i in range(10): tables.append(list(map(int, input().split(' ')))) A = [] for _ in range(h): A.append(list(map(int, input().split(' ')))) ans = solve(h, w, tables, A) print(ans) if __name__=='__main__': main()
s467045647
p03455
u209616713
2,000
262,144
Wrong Answer
18
2,940
183
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b = input().split() c = a+b d = int(c) if d % 2 == 0: if d % 4 == 0: print('Yes') else: print('No') else: if d % 4 == 1: print('Yes') else: print('No')
s081647867
Accepted
17
2,940
91
a,b = map(int,input().split()) c = a*b if c % 2 == 0: print('Even') else: print('Odd')
s886885570
p03860
u633450100
2,000
262,144
Wrong Answer
17
2,940
31
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s = input() print('A'+s[0]+'C')
s556242143
Accepted
17
2,940
55
s = [s for s in input().split()] print('A'+s[1][0]+'C')
s344980789
p03854
u548303713
2,000
262,144
Wrong Answer
2,107
3,316
950
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`.
#ABC49-C S=input() divide=["dream","dreamer","erase","eraser"] for i in range(4): divide[i]=divide[i][::-1] len_s=len(S) S=S[::-1] check=0 i=0 a=[] while check==0: if i==len_s: a.append(1) break if len_s-i <5: check=1 a.append(2) break if S[i:i+5] == divide[0]: i=i+5 a.append(3) continue if S[i:i+5] == divide[2]: i=i+5 a.append(4) continue if len_s-i <7: check=1 a.append(5) break if S[i:i+7] == divide[1]: i=i+7 a.append(6) continue if S[i:i+7] == divide[3]: i=i+7 a.append(7) continue if check==0: print("YES") else: print("NO") print(a)
s679652609
Accepted
34
3,444
1,164
#ABC49-C S=input() divide=["dream","dreamer","erase","eraser"] for i in range(4): divide[i]=divide[i][::-1] len_s=len(S) S=S[::-1] check=0 i=0 a=[] while check==0: if i==len_s: a.append(1) break if len_s-i <5: check=1 a.append(2) break if S[i:i+5] == divide[0]: i=i+5 a.append(3) continue if S[i:i+5] == divide[2]: i=i+5 a.append(4) continue if len_s-i <6: check=1 a.append(5) break if S[i:i+6] == divide[3]: i=i+6 a.append(6) continue if len_s-i <7: check=1 a.append(7) break if S[i:i+7] == divide[1]: i=i+7 a.append(8) continue check=1 if check==0: print("YES") else: print("NO") #print(a)
s068071899
p02396
u587193722
1,000
131,072
Wrong Answer
20
7,632
93
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.
a = [int(i) for i in input().split()] for i in range(1, len(a)): print('Case',i,':',a[i])
s833410132
Accepted
90
8,408
129
a =[] x = 1 while x > 0: x = int(input()) a.append(x) for i in range(0,len(a)-1): print('Case ',i+1,': ',a[i],sep='')
s893435251
p03556
u088974156
2,000
262,144
Wrong Answer
17
2,940
28
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
n=int(input()) print(n**0.5)
s297868218
Accepted
17
3,060
36
n=int(input()) print(int(n**0.5)**2)
s123834903
p02256
u963402991
1,000
131,072
Wrong Answer
20
7,624
209
Write a program which finds the greatest common divisor of two natural numbers _a_ and _b_
def gcd(a,b): r = a % b while r != 0: print (a, b) a, b = b, r r = a % b if r == 0: break return b a,b = list(map(int,input().split())) print (gcd(a,b))
s116475366
Accepted
20
7,636
151
def gcd(a,b): r = a % b while r != 0: a, b = b, r r = a % b return b a,b = list(map(int,input().split())) print (gcd(a,b))
s736531050
p02742
u267983787
2,000
1,048,576
Wrong Answer
17
2,940
85
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:
b, c = map(int, input().split()) a = b*c if a%2 == 0: print(a/2) else: print(a/2 + 1)
s845264663
Accepted
17
2,940
140
b, c = map(int, input().split()) a = b*c if b == 1:print(1) elif c == 1:print(1) elif a%2 == 0: print(int(a/2)) else: print(int((a + 1)/2))
s331394271
p03044
u630281418
2,000
1,048,576
Wrong Answer
17
2,940
29
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
for i in range(5): print(1)
s582175925
Accepted
677
50,556
500
import sys input = sys.stdin.readline N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): u, v, w = map(int, input().split()) tree[u-1].append([v-1,w]) tree[v-1].append([u-1,w]) dist = [None]*N dist[0] = 0 comp = [0]*N next_ptr = [0] for ptr in next_ptr: comp[ptr] = 1 edges = tree[ptr] for edge in edges: if comp[edge[0]] == 0: dist[edge[0]] = dist[ptr] + edge[1] next_ptr.append(edge[0]) for item in dist: print(item%2)
s396912861
p02645
u483331319
2,000
1,048,576
Wrong Answer
28
9,056
24
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
S = input() print(S[3:])
s364536801
Accepted
26
9,024
24
S = input() print(S[:3])
s277906695
p02694
u021387650
2,000
1,048,576
Wrong Answer
27
9,020
103
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()) Deposit = 100 ans = 0 while Deposit < X: Deposit *= 1.001 ans += 1 print(ans)
s378252281
Accepted
25
9,168
118
X = int(input()) Deposit = 100 ans = 0 while Deposit < X: Deposit = int(Deposit * 1.01) ans += 1 print(ans)
s399005469
p03623
u327248573
2,000
262,144
Wrong Answer
17
2,940
103
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x, a, b = map(int, input().split(' ')) if abs(a - x) >= abs(b - x): print('A') else: print('B')
s117034662
Accepted
18
2,940
103
x, a, b = map(int, input().split(' ')) if abs(a - x) <= abs(b - x): print('A') else: print('B')
s645901164
p03338
u729938879
2,000
1,048,576
Wrong Answer
17
3,060
203
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
n = int(input()) s = input() num = [] for i in range(1,n): former = set(s[:i]) latter = set(s[i:]) comm = len(former and latter) #print(s[:i], s[i:]) num.append(comm) print(max(num))
s507625228
Accepted
18
3,060
213
n = int(input()) s = input() num = [] for i in range(1,n): former = set(s[:i]) latter = set(s[i:]) comm = len(former.intersection(latter)) #print(s[:i], s[i:]) num.append(comm) print(max(num))
s840987147
p04046
u102960641
2,000
262,144
Wrong Answer
276
18,804
572
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.
h,w,a,b = map(int, input().split()) mod = 10**9 + 7 n = 10**5 * 2 + 1 fact = [1]*(n+1) rfact = [1]*(n+1) r = 1 for i in range(1, n+1): fact[i] = r = r * i % mod rfact[n] = r = pow(fact[n], mod-2, mod) for i in range(n, 0, -1): rfact[i-1] = r = r * i % mod def perm(n, k): return fact[n] * rfact[n-k] % mod def comb(n, k): if n == 0 and k == 0: return 0 return fact[n] * rfact[k] * rfact[n-k] % mod ans = 0 for i in range(b,w): ans = (ans + comb(h-a-1+i,i) * comb(w-i+a-2,a-1)) % mod print(ans)
s454560131
Accepted
265
18,804
535
h,w,a,b = map(int, input().split()) mod = 10**9 + 7 n = 10**5 * 2 + 1 fact = [1]*(n+1) rfact = [1]*(n+1) r = 1 for i in range(1, n+1): fact[i] = r = r * i % mod rfact[n] = r = pow(fact[n], mod-2, mod) for i in range(n, 0, -1): rfact[i-1] = r = r * i % mod def perm(n, k): return fact[n] * rfact[n-k] % mod def comb(n, k): return fact[n] * rfact[k] * rfact[n-k] % mod ans = 0 for i in range(b,w): ans = (ans + comb(h-a-1+i,i) * comb(w-i+a-2,a-1)) % mod print(ans)
s215969402
p03544
u066455063
2,000
262,144
Wrong Answer
17
2,940
116
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
N = int(input()) luca = [2, 1] for i in range(101): luca.append(luca[i]+luca[i+1]) print(luca) print(luca[N])
s922569920
Accepted
17
2,940
104
N = int(input()) luca = [2, 1] for i in range(101): luca.append(luca[i]+luca[i+1]) print(luca[N])
s398463139
p03379
u243689896
2,000
262,144
Wrong Answer
2,108
26,180
366
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.
#ABC 094 Many Medians numbers=int(input()) list_num=[int(i) for i in input().split()] sorted_list=sorted(list_num) median1=sorted_list[int(numbers/2)-1] median2=sorted_list[int(numbers/2)] print('median1:', median1) print('median2:', median2) for i in list_num: if sorted_list.index(i) <= numbers/2-1: print(median2) else: print(median1)
s876015087
Accepted
300
25,472
264
numbers=int(input()) list_num=[int(i) for i in input().split()] sorted_list=sorted(list_num) median1=sorted_list[int(numbers/2)-1] median2=sorted_list[int(numbers/2)] for i in list_num: if i <= median1: print(median2) else: print(median1)
s161907103
p03673
u746419473
2,000
262,144
Wrong Answer
2,104
26,020
192
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
n = int(input()) *a, = map(int, input().split()) b = [] for i in range(n): if i%2 == 0: b.append(a[i]) else: b.insert(0, a[i]) if n%2 == 1: b.reverse() print(b)
s976564819
Accepted
172
26,020
178
n = int(input()) *a, = map(int, input().split()) right = a[1::2] right.reverse() left = a[0::2] b = [] b.extend(right) b.extend(left) if n%2 == 1: b.reverse() print(*b)
s848413590
p02678
u131638468
2,000
1,048,576
Wrong Answer
374
63,944
543
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
n,m,*ab=map(int,open(0).read().split()) path={} for i in range(n): path[i]=[] for i in range(m): a,b=ab[i*2]-1,ab[i*2+1]-1 path[a].append(b) path[b].append(a) direction=[i for i in range(n)] fin=[False for i in range(n)] fin[0]=True i=0 queue=[0] while i<n: i+=1 queue2=queue.copy() queue.clear() if len(queue)==0: break for j in queue2: fin[j]=True for k in path[j]: if not fin[k]: direction[k]=j fin[k]=True queue.append(k) print('Yes') for i in range(1,n): print(direction[i]+1)
s748262601
Accepted
542
63,520
544
n,m,*ab=map(int,open(0).read().split()) path={} for i in range(n): path[i]=[] for i in range(m): a,b=ab[i*2]-1,ab[i*2+1]-1 path[a].append(b) path[b].append(a) direction=[i for i in range(n)] fin=[False for i in range(n)] fin[0]=True i=0 queue=[0] while i<n: i+=1 queue2=queue.copy() queue.clear() if len(queue2)==0: break for j in queue2: fin[j]=True for k in path[j]: if not fin[k]: direction[k]=j fin[k]=True queue.append(k) print('Yes') for i in range(1,n): print(direction[i]+1)
s136630155
p03377
u488178971
2,000
262,144
Wrong Answer
17
2,940
90
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.
#094 A,B,X= map(int,input().split()) if A+B>=X >=A: print('Yes') else: print('No')
s753066535
Accepted
17
2,940
90
#094 A,B,X= map(int,input().split()) if A+B>=X >=A: print('YES') else: print('NO')
s855066046
p03352
u645568816
2,000
1,048,576
Wrong Answer
28
9,096
132
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
N = int(input()) ans = 0 for i in range(1,35): for k in range(1,10): if i**k <= N and i**k >= ans: ans = i**k print(ans)
s209836598
Accepted
29
9,160
132
N = int(input()) ans = 0 for i in range(1,35): for k in range(2,10): if i**k <= N and i**k >= ans: ans = i**k print(ans)
s722724248
p03998
u537976628
2,000
262,144
Wrong Answer
17
3,064
637
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
A, B, C = (input() for i in range(3)) cnt_a = 0; cnt_b = -1; cnt_c = -1 current_card = A[cnt_a] while True: print(current_card) if current_card == "a": cnt_a += 1 if cnt_a == len(A): print("A") exit() else: current_card = A[cnt_a] elif current_card == "b": cnt_b += 1 if cnt_b == len(B): print("B") exit() else: current_card = B[cnt_b] elif current_card == "c": cnt_c += 1 if cnt_c == len(C): print("C") exit() else: current_card = C[cnt_c]
s501580406
Accepted
17
3,064
613
A, B, C = (input() for i in range(3)) cnt_a = 0; cnt_b = -1; cnt_c = -1 current_card = A[cnt_a] while True: if current_card == "a": cnt_a += 1 if cnt_a == len(A): print("A") exit() else: current_card = A[cnt_a] elif current_card == "b": cnt_b += 1 if cnt_b == len(B): print("B") exit() else: current_card = B[cnt_b] elif current_card == "c": cnt_c += 1 if cnt_c == len(C): print("C") exit() else: current_card = C[cnt_c]
s987128878
p02613
u657173608
2,000
1,048,576
Wrong Answer
154
9,680
555
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.
from sys import stdin, stdout import heapq import cProfile from collections import Counter, defaultdict, deque from functools import reduce import math from bisect import bisect,bisect_right,bisect_left def get_int(): return int(stdin.readline().strip()) def get_tuple(): return map(int, stdin.readline().split()) def get_list(): return list(map(int, stdin.readline().split())) n = get_int() dic = defaultdict(int) for _ in range(n): st = input() dic[st] += 1 for val in ['AC','WA','TLE','RE']: print(val+" * "+str(dic[val]))
s831767837
Accepted
144
9,656
555
from sys import stdin, stdout import heapq import cProfile from collections import Counter, defaultdict, deque from functools import reduce import math from bisect import bisect,bisect_right,bisect_left def get_int(): return int(stdin.readline().strip()) def get_tuple(): return map(int, stdin.readline().split()) def get_list(): return list(map(int, stdin.readline().split())) n = get_int() dic = defaultdict(int) for _ in range(n): st = input() dic[st] += 1 for val in ['AC','WA','TLE','RE']: print(val+" x "+str(dic[val]))
s007042969
p03407
u992910889
2,000
262,144
Wrong Answer
17
2,940
96
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()) if A==C or B==C or A+B==C: print('Yes') else: print('No')
s142196280
Accepted
17
2,940
80
A,B,C=map(int,input().split()) if A+B>=C: print('Yes') else: print('No')
s186028980
p03476
u027929618
2,000
262,144
Time Limit Exceeded
2,105
30,196
349
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
def is_prime(t): i=2 while i**2<=t: if t%i==0: return 0 i+=1 return 1 q=int(input()) lr=[list(map(int,input().split())) for _ in range(q)] n=10**5 p=[0]*(n+1) d=[] for i in range(2,n): if is_prime(i): d.append(i) if i in d and (i+1)//2 in d: p[i]=p[i-1]+1 else: p[i]=p[i-1] for l,r in lr: print(p[r]-p[l-1])
s196956500
Accepted
1,379
29,860
349
def is_prime(t): i=2 while i**2<=t: if t%i==0: return 0 i+=1 return 1 q=int(input()) lr=[list(map(int,input().split())) for _ in range(q)] n=10**5 p=[0]*(n+1) d=set() for i in range(2,n): if is_prime(i): d.add(i) if i in d and (i+1)//2 in d: p[i]=p[i-1]+1 else: p[i]=p[i-1] for l,r in lr: print(p[r]-p[l-1])
s466910506
p03377
u564906058
2,000
262,144
Wrong Answer
18
2,940
86
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x = map(int,input().split()) if a <= x <= a+b: print("Yes") else: print("No")
s651326701
Accepted
17
2,940
86
a,b,x = map(int,input().split()) if a <= x <= a+b: print("YES") else: print("NO")
s880701408
p03998
u782654209
2,000
262,144
Wrong Answer
17
3,064
386
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
S = [input() for x in range(3)] winner = '' turn = 0 while True: if S[turn][0] == 'a': S[0] = S[0][1:] turn = 0 elif S[turn][0] == 'b': S[1] = S[1][1:] turn = 1 elif S[turn][0] == 'c': S[2] = S[2][1:] turn = 2 for i in range(3): if S[i]=='': winner='abc'[i] if winner!='': break print(winner)
s468262118
Accepted
17
3,060
201
S = [str(input()) for x in range(3)] turn = 0 nextturn = 0 while True: nextturn = 'abc'.find(S[turn][0]) S[turn] = S[turn][1:] turn = nextturn if S[turn] == '': print('ABC'[turn]) break
s761627683
p03854
u246253778
2,000
262,144
Wrong Answer
65
9,092
392
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() while len(S) != 0: if S[-2:] == 'er': S = S[:-2] if S[-5:] == 'dream': S = S[:-5] elif S[-4:] == 'eras': S = S[:-4] else: print('No') exit() else: if S[-5:] == 'dream' or S[-5:] == 'erase': S = S[:-5] else: print('No') exit() print('Yes')
s281895398
Accepted
69
9,136
392
S = input() while len(S) != 0: if S[-2:] == 'er': S = S[:-2] if S[-5:] == 'dream': S = S[:-5] elif S[-4:] == 'eras': S = S[:-4] else: print('NO') exit() else: if S[-5:] == 'dream' or S[-5:] == 'erase': S = S[:-5] else: print('NO') exit() print('YES')
s470017224
p02401
u628732336
1,000
131,072
Wrong Answer
20
7,584
265
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: a, op, b = 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)
s639191512
Accepted
20
7,616
266
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)
s168335150
p04029
u980492406
2,000
262,144
Wrong Answer
17
2,940
33
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) print(n*(n+1)/2)
s988640111
Accepted
17
2,940
38
n = int(input()) print(int(n*(n+1)/2))
s135116654
p02262
u599130514
6,000
131,072
Wrong Answer
20
5,600
563
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
def insertionSort(A, n, g): cnt = 0 for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v return cnt def shellSort(A, n): cnt = 0 m = 2 G = [n - m + 1, m - 1] for i in range(m): cnt += insertionSort(A, n, G[i]) print(m) print(*G) print(cnt) print(*A) arr_length = int(input()) arr_num = [] for i in range(arr_length): arr_num.append(input()) shellSort(arr_num, arr_length)
s746345748
Accepted
18,480
125,972
686
def insertionSort(A, n, g): cnt = 0 for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v return cnt def shellSort(A, n): G = [] h = 1 while True: if h > n: break G.append(h) h = 3 * h + 1 cnt = 0 print(len(G)) G = list(reversed(G)) for g in G: cnt += insertionSort(A, n, g) print(*G) print(cnt) print('\n'.join(map(str, A))) arr_length = int(input()) arr_num = [] for i in range(arr_length): arr_num.append(int(input())) shellSort(arr_num, arr_length)
s309812723
p02399
u286589639
1,000
131,072
Wrong Answer
20
7,624
109
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a, b = map(int, input().split()) d = a // b r = a % b f = a / b print(str(d) + " " + str(r) + " " + str(f))
s713320524
Accepted
20
7,652
127
a, b = map(int, input().split()) d = a // b r = a % b f = "{0:.5f}".format(a / b) print(str(d) + " " + str(r) + " " + str(f))
s169196208
p03379
u669322232
2,000
262,144
Wrong Answer
2,105
27,156
231
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 copy N = int(input()) numList = list(map(int, input().split())) numList.sort() for i in range(0,N): numListCopy = copy.deepcopy(numList) numListCopy.pop(i) medIndex = int(len(numListCopy)/2) print(numListCopy[medIndex])
s884433794
Accepted
482
26,528
316
import copy N = int(input()) numList = list(map(int, input().split())) numListCopy = copy.deepcopy(numList) numList = sorted(numList) medIndex = int((N)/2) med1 = numList[medIndex-1] med2 = numList[medIndex] for i in range(0,N): if numListCopy[i] <= med1: print(med2) elif med2 <= numListCopy[i]: print(med1)
s284408044
p03671
u367393577
2,000
262,144
Wrong Answer
17
2,940
55
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()) print(max(a+b,b+c,c+a))
s716761514
Accepted
17
2,940
55
a,b,c=map(int,input().split()) print(min(a+b,b+c,c+a))
s478150720
p02902
u803611972
2,000
1,048,576
Wrong Answer
25
3,956
343
Given is a directed graph G with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i. It is guaranteed that the graph contains no self-loops or multiple edges. Determine whether there exists an induced subgraph (see Notes) of G such that the in-degree and out-degree of every vertex are both 1. If the answer is yes, show one such subgraph. Here the null graph is not considered as a subgraph.
from collections import* n,m,*t=map(int,open(0).read().split()) i,o,r=[0]*n,[[]for _ in'_'*n],[] for a,b in zip(*[iter(t)]*2): o[a-1]+=b-1, i[b-1]+=1 q=deque(v for v in range(n)if i[v]<1) while q: v=q.popleft() r+=v, for w in o[v]: i[w]-=1 if i[w]==0:q+=w, print(-(len(r)==n)) for j,k in enumerate(i): if i[j]>0: print(j+1)
s217644980
Accepted
30
3,956
708
import sys from collections import deque def serp(s): prev = [-1]*n q=deque([s]) while q: v = q.pop() for nv in e[v]: if nv==s: prev[nv]=v; return(s,prev) if prev[nv]<0: q+=nv,; prev[nv] =v return(-1,prev) n,m,*t=map(int,open(0).read().split()) e,ab = [[] for i in range(n)],[] for a,b in zip(*[iter(t)]*2): e[a-1]+= b-1, ab += [(a-1,b-1)] for v in range(n): v0,prev = serp(v) if v0>=0: break if v0<0: print(-1); sys.exit() c=set() c.add(v0) pv = prev[v0] while pv!=v0: c.add(pv) pv=prev[pv] for a,b in ab: if a in c and b in c and prev[b]!=a: pv = prev[b] while pv !=a: c.remove(pv) pv=prev[pv] prev[b]=a print(len(c)) for i in c: print(i+1)
s062001923
p03679
u746428948
2,000
262,144
Wrong Answer
17
2,940
97
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b = map(int,input().split()) d = b - a if d <= x: print('delicious') else: print('dangerous')
s341132049
Accepted
17
2,940
124
x,a,b = map(int,input().split()) d = b - a if d <= 0: print('delicious') elif d <= x: print('safe') else: print('dangerous')
s334483422
p03433
u951601135
2,000
262,144
Wrong Answer
157
12,504
182
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
import numpy as np N = int(input()) value = list(map(int,input().split())) value=np.sort(value)[::-1] print(N,value) a=0 b=0 a = np.sum(value[::2]) b = np.sum(value[1::2]) print(a,b)
s059463798
Accepted
18
2,940
66
n=int(input()) a=int(input()) print('Yes' if (n%500)<=a else 'No')
s677395293
p04043
u882209234
2,000
262,144
Wrong Answer
18
2,940
118
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.
abc = list(map(int, input().split())) if abc[0] == abc[2] == 5 and abc[1] == 7: print('YES') else: print('NO')
s028583532
Accepted
17
3,060
209
abc = list(map(int, input().split())) lengths = [0,0] for i in abc: if i == 5: lengths[0] += 1 if i == 7: lengths[1] += 1 if lengths[0] == 2 and lengths[1] == 1: print('YES') else: print('NO')
s905119373
p03131
u852719059
2,000
1,048,576
Wrong Answer
2,104
3,064
341
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
# C When I hit my pocket k,a,b = map(int,input().split()) bis = 1 yen = 0 if b <= a + 2 or k <= a + 1: print(1 + k) else: for i in range(k): if not yen == 0: bis += b yen -= 1 elif bis >= a: bis -= a yen += 1 else: bis += 1 print(bis)
s631666006
Accepted
17
3,060
247
# C When I hit my pocket k,a,b = map(int,input().split()) bis = 1 if k <= 1 or b <= a + 2 or k < a + 1: print(1 + k) exit() else: bis = b k = k - ( a + 1) if not k == 0: bis += int(k / 2) * (b - a) + k % 2 print(bis)
s626133179
p02399
u248424983
1,000
131,072
Wrong Answer
30
7,720
134
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
import sys (a, b) = [int(i) for i in input().split(' ')] d = a // b r = a % b f = a / b print(repr(d) +" "+ repr(r) +" "+ repr(f))
s267059511
Accepted
20
7,724
112
(a, b) = [int(i) for i in input().split(' ')] print( repr(a // b) +" "+ repr(a % b) +" "+ ('%0.5f' % (a / b)))
s345172934
p03485
u148551245
2,000
262,144
Wrong Answer
17
2,940
64
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = (int(i) for i in input().split()) mean = (a + b) // 2 + 1
s982982186
Accepted
17
2,940
114
a, b = map(int, input().split()) m = (a + b) // 2 x = (a + b) / 2 if x % 1 == 0: print(m) else: print(m+1)
s269674866
p02742
u948522631
2,000
1,048,576
Wrong Answer
17
2,940
88
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
h,w=map(int,input().split()) print(int(h*w/2)+1 if type(h*w/2)==float else int(h*w/2) )
s599547066
Accepted
17
3,060
122
h,w=map(int,input().split()) if h<2 or w<2: print(1) elif h%2==0 or w%2==0: print(int(h*w/2)) else: print(int(h*w/2)+1)
s207670852
p02390
u114315703
1,000
131,072
Wrong Answer
20
5,568
51
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
N = int(input()) print(N // 3600, N // 60, N % 60)
s195767345
Accepted
20
5,576
80
N = int(input()) print('{0}:{1}:{2}'.format(N // 3600, N % 3600// 60, N % 60))
s529226275
p03440
u047816928
2,000
262,144
Wrong Answer
464
33,904
1,002
You are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1. The edges are given in the format (x_i,y_i), which means that Vertex x_i and y_i are connected by an edge. Each vertex i has a value a_i. You want to add edges in the given forest so that the forest becomes connected. To add an edge, you choose two different vertices i and j, then span an edge between i and j. This operation costs a_i + a_j dollars, and afterward neither Vertex i nor j can be selected again. Find the minimum total cost required to make the forest connected, or print `Impossible` if it is impossible.
class UF: def __init__(self, N): self.uf = [-1]*N self.n = N def find(self, x): if self.uf[x]<0: return x self.uf[x] = self.find(self.uf[x]) return self.uf[x] def size(self, x): return -self.uf[self.find(x)] def union(self, x, y): x, y = self.find(x), self.find(y) if x==y: return if self.size(x) > self.size(y): x, y = y, x self.uf[y] += self.uf[x] self.uf[x] = y self.n -= 1 N, M = map(int, input().split()) A = list(map(int, input().split())) uf = UF(N) for _ in range(M): x, y = map(int, input().split()) uf.union(x,y) D = {} for x, a in enumerate(A): c = uf.find(x) if c not in D: D[c]=[] D[c].append(a) ans = 0 L = [] for d in D.values(): d.sort() ans += d[0] L += d[1:] print(d[0]) print(L, ans) L.sort() P = len(D)-2 if len(D)==1: ans = 0 elif len(L)>=P: ans += sum(L[:len(D)-2]) else: ans = 'Impossible' print(ans)
s594720585
Accepted
449
33,612
971
class UF: def __init__(self, N): self.uf = [-1]*N self.n = N def find(self, x): if self.uf[x]<0: return x self.uf[x] = self.find(self.uf[x]) return self.uf[x] def size(self, x): return -self.uf[self.find(x)] def union(self, x, y): x, y = self.find(x), self.find(y) if x==y: return if self.size(x) > self.size(y): x, y = y, x self.uf[y] += self.uf[x] self.uf[x] = y self.n -= 1 N, M = map(int, input().split()) A = list(map(int, input().split())) uf = UF(N) for _ in range(M): x, y = map(int, input().split()) uf.union(x,y) D = {} for x, a in enumerate(A): c = uf.find(x) if c not in D: D[c]=[] D[c].append(a) ans = 0 L = [] for d in D.values(): d.sort() ans += d[0] L += d[1:] L.sort() P = len(D)-2 if len(D)==1: ans = 0 elif len(L)>=P: ans += sum(L[:len(D)-2]) else: ans = 'Impossible' print(ans)
s213689852
p03657
u814265211
2,000
262,144
Wrong Answer
31
9,148
86
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
A, B = map(int, input().split()) print('Possible' if not A + B % 3 else 'Impossible')
s554440721
Accepted
26
9,160
120
A, B = map(int, input().split()) if (A+B) % 3 and A % 3 and B % 3: print('Impossible') else: print('Possible')
s277213706
p03455
u453117183
2,000
262,144
Wrong Answer
17
2,940
96
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b = map(int,input().split()) if a%2 == 0 or b%2 == 0: print("even") else: print("odd")
s683948478
Accepted
17
2,940
96
a,b = map(int,input().split()) if a%2 == 0 or b%2 == 0: print("Even") else: print("Odd")
s132330179
p03599
u050428930
3,000
262,144
Wrong Answer
3,156
3,064
665
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()) ans=100 for i in range(f//(100*a)+1): for j in range(f//(100*b)+1): s=100*a*i+100*b*j if s==0: break for ii in range((f-100*a)//c+1): for jj in range((f-100*a)//d+1): t=c*ii+d*jj if t==0: break u=(100*t)/(s+t) if s+t<=f and u==f: print(str(s+t)+" "+str(t)) exit() if s+t<=f and u<f: if ans>u: ans=u x,y=s,t print([ans,x,y])
s308890189
Accepted
222
3,064
474
a,b,c,d,e,f=map(int,input().split()) t=100 for i in range(0,f+1,a*100): for j in range(0,f-i+1,b*100): k=i+j if k==0: continue s=min(f-i-j,(i+j)*e//100) for ii in range(0,s+1,c): for jj in range(0,s-ii+1,d): if t>e-(ii+jj)*100/(i+j): t=e-(ii+jj)*100/(i+j) x,y=ii+jj+i+j,ii+jj print(str(x)+" "+str(y))
s669845689
p03597
u865413330
2,000
262,144
Wrong Answer
18
2,940
50
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
n = int(input()) a = int(input()) print(n * 2 - a)
s070258306
Accepted
17
2,940
50
n = int(input()) a = int(input()) print(n * n - a)
s782022358
p03997
u485319545
2,000
262,144
Wrong Answer
17
3,064
454
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.
s_a = list(input()) s_b = list(input()) s_c = list(input()) S=[s_a,s_b,s_c] order=0 while True: if S[order][0]=='a': del S[0][0] order=0 elif S[order][0]=='b': del S[1][0] order=1 else: del S[2][0] order=2 if len(S[order])==0: print('A') exit(0) elif len(S[order])==0: print('B') exit(0) elif len(S[order])==0: print('C') exit(0)
s885187797
Accepted
17
3,064
67
a=int(input()) b=int(input()) h=int(input()) print(int((a+b)*h/2))
s589989666
p03475
u245870380
3,000
262,144
Wrong Answer
107
3,064
364
A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
N = int(input()) C, S, F = [], [], [] for i in range(N-1): c, s, f = map(int, input().split()) C.append(c) S.append(s) F.append(f) print(C) print(S) print(F) for i in range(N): t = 0 for j in range(i,N-1): if t < S[j]: t = S[j] elif t % F[j] != 0: t += F[j] - t % F[j] t += C[j] print(t)
s033977349
Accepted
98
3,064
336
N = int(input()) C, S, F = [], [], [] for i in range(N-1): c, s, f = map(int, input().split()) C.append(c) S.append(s) F.append(f) for i in range(N): t = 0 for j in range(i,N-1): if t < S[j]: t = S[j] elif t % F[j] != 0: t += F[j] - t % F[j] t += C[j] print(t)
s467263008
p02418
u971748390
1,000
131,072
Wrong Answer
20
7,352
81
Write a program which finds a pattern $p$ in a ring shaped text $s$.
s=input() p=input() ring=s+s if p in ring : print("True") else : print("False")
s570824814
Accepted
40
7,496
77
s=input() p=input() ring=s+s if p in ring : print("Yes") else : print("No")
s682277929
p03610
u247211039
2,000
262,144
Wrong Answer
17
3,316
26
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input() print(s[0::1])
s392263326
Accepted
37
3,316
96
s = input() x = s[0] for i in range(len(s)): if i % 2 == 0: x= x + s[i] print(x[1:])
s811141985
p02806
u152614052
2,525
1,048,576
Wrong Answer
17
3,060
208
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
n = int(input()) li1 = [] li2 = [] for i in range(n): a, b = input().split() li1.append(a) li2.append(int(b)) x = input() print(*li1) print(*li2) asleep = li1.index(x) print(sum(li2[asleep+1:]))
s121419361
Accepted
17
3,060
183
n = int(input()) li1 = [] li2 = [] for i in range(n): a, b = input().split() li1.append(a) li2.append(int(b)) x = input() asleep = li1.index(x) print(sum(li2[asleep+1:]))
s265132615
p03852
u534308356
2,000
262,144
Wrong Answer
17
2,940
204
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
S = input() l = ['dream', 'dreamer', 'erase', 'eraser'] s = "".join(S[-1::-1].split(l[0][-1::-1])) for i in range(1, 4): s = "".join(s.split(l[i][-1::-1])) print("YES") if s == "" else print("NO")
s876401081
Accepted
26
8,984
109
data = ["a", "e", "i", "o", "u"] c = input() if c in data: print("vowel") else: print("consonant")
s359395775
p02603
u941644149
2,000
1,048,576
Wrong Answer
29
9,160
829
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
n = int(input()) given_A = list(map(int, input().split())) A = [] for kabuka in given_A: if len(A) > 0 and kabuka == A[-1]: continue else: A.append(kabuka) print(A) if len(A) == 1: print(1000) exit() money = 1000 stock = 0 n = len(A) for i in range(len(A)): if i == 0: if A[i] < A[i + 1]: stock = money // A[i] money = money % A[i] elif i == n - 1: if A[i - 1] < A[i]: money += stock*A[i] stock = 0 else: if (A[i - 1] < A[i]) & (A[i] > A[i + 1]): money += stock*A[i] stock = 0 elif (A[i - 1] > A[i]) & (A[i] < A[i + 1]): stock = money // A[i] money = money % A[i] print(money)
s926648913
Accepted
30
9,220
816
n = int(input()) given_A = list(map(int, input().split())) A = [] for kabuka in given_A: if len(A) > 0 and kabuka == A[-1]: continue else: A.append(kabuka) if len(A) == 1: print(1000) exit() money = 1000 stock = 0 n = len(A) for i in range(len(A)): if i == 0: if A[i] < A[i + 1]: stock = money // A[i] money = money % A[i] elif i == n - 1: if A[i - 1] < A[i]: money += stock*A[i] stock = 0 else: if (A[i - 1] < A[i]) & (A[i] > A[i + 1]): money += stock*A[i] stock = 0 elif (A[i - 1] > A[i]) & (A[i] < A[i + 1]): stock = money // A[i] money = money % A[i] print(money)
s511888465
p03370
u344959959
2,000
262,144
Wrong Answer
27
9,056
113
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
a,b = map(int,input().split()) c = [int(input()) for i in range(a)] print(min(c)) print(a+((b-(sum(c)))//min(c)))
s178089763
Accepted
26
9,168
99
a,b = map(int,input().split()) c = [int(input()) for i in range(a)] print(a+((b-(sum(c)))//min(c)))
s284511249
p03449
u625963200
2,000
262,144
Wrong Answer
19
3,060
180
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
n=int(input()) A=[list(map(int,input().split())) for _ in range(2)] print(A) ans=A[0][0] for i in range(1,n+1): ans2=sum(A[0][:i])+sum(A[1][i-1:]) ans=max(ans,ans2) print(ans)
s339043073
Accepted
17
3,060
171
n=int(input()) A=[list(map(int,input().split())) for _ in range(2)] ans=A[0][0] for i in range(1,n+1): ans2=sum(A[0][:i])+sum(A[1][i-1:]) ans=max(ans,ans2) print(ans)
s268422940
p04025
u888092736
2,000
262,144
Wrong Answer
17
2,940
165
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
N = int(input()) A = map(int, input().split()) ans = float("inf") for i in range(-100, 101): ans = min(ans, sum(map(lambda x: (x - i) * (x - i), A))) print(ans)
s824353245
Accepted
25
3,060
200
N = int(input()) A = list(map(int, input().split())) ans = float("inf") for k in range(-100, 101): tmp = 0 for i in range(N): tmp += (A[i] - k) ** 2 ans = min(ans, tmp) print(ans)
s500203881
p03493
u931209993
2,000
262,144
Wrong Answer
18
3,064
164
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 = int(input()) cnt = 0 if a%10 == 1: cnt += 1 a = int(a/10) if a%10 == 1: cnt += 1 a = int(a/10) if a%10 == 1: cnt += 1 a = int(a/10) print(cnt)
s683849789
Accepted
17
2,940
114
a = input() cnt = 0 if a[0] == '1': cnt += 1 if a[1] == '1': cnt += 1 if a[2] == '1': cnt += 1 print(cnt)
s353669709
p03369
u086503932
2,000
262,144
Wrong Answer
17
2,940
47
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
print(700+list(input().split()).count('o')*100)
s516955177
Accepted
17
2,940
33
print(700+input().count('o')*100)
s134453146
p02975
u814986259
2,000
1,048,576
Wrong Answer
112
14,468
664
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
import collections N = int(input()) a = list(map(int, input().split())) A = set() table = collections.defaultdict(int) for i in range(1, N): table[a[i]] += 2 a.sort() prev = a[0] now = a[0] last = a[0] for i in range(1, N): if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] > 0: table[a[0] ^ a[i]] -= 1 last = a[i] now = a[0] | a[i] break print(prev, now, last) for i in range(2, N-2): if prev ^ now in table and table[now ^ prev] > 0: prev = now now = now ^ prev table[now ^ prev] -= 1 else: print("No") exit(0) if (last ^ now) == a[0]: print("Yes") else: print("No")
s801727715
Accepted
189
14,468
777
import collections N = int(input()) a = list(map(int, input().split())) A = set() table = collections.defaultdict(int) for i in range(1, N): table[a[i]] += 1 ans = [-1]*N ans[0] = a[0] for i in range(1, N): if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] >= 1: if a[0] == 0: if table[a[i]] == 1: continue ans[1] = (a[0] ^ a[i]) ans[2] = a[i] table[ans[1]] -= 1 table[ans[2]] -= 1 break if ans[1] == -1: print("No") exit(0) for i in range(3, N): if (ans[i-1] ^ ans[i-2]) in table and table[ans[i-1] ^ ans[i-2]] >= 1 and table[ans[i-1] ^ ans[i-2]] >= 1: ans[i] = ans[i-1] ^ ans[i-2] table[ans[i]] -= 1 else: print("No") exit(0) print("Yes")
s567737792
p03063
u639444166
2,000
1,048,576
Wrong Answer
452
6,140
390
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
#! -*- coding: utf-8 -*- n = int(input()) line = input() w = 0 for i in range(n): if line[i] == ".": w += 1 b = n-w w_coutner = 0 b_counter = 0 ans = n for i in range(n): if line[i] == ".": w_coutner += 1 b_counter = i+1 - w_coutner wtob = b_counter btow = w - w_coutner ans_i = wtob + btow print(i,ans_i) ans = min(ans,ans_i) print(ans)
s528677696
Accepted
195
3,500
411
#! -*- coding: utf-8 -*- n = int(input()) line = input() w = 0 for i in range(n): if line[i] == ".": w += 1 b = n-w w_coutner = 0 b_counter = 0 ans = n for i in range(n): if line[i] == ".": w_coutner += 1 b_counter = i+1 - w_coutner wtob = b_counter btow = w - w_coutner ans_i = wtob + btow #print(i,ans_i) ans = min(ans,ans_i) ans = min(w,b,ans) print(ans)
s074087792
p03447
u730710086
2,000
262,144
Wrong Answer
17
2,940
113
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?
# -*- coding: <encoding name> -*- x = int(input()) a = int(input()) b = int(input()) n = x - a print(x - n % b)
s272301525
Accepted
17
2,940
109
# -*- coding: <encoding name> -*- x = int(input()) a = int(input()) b = int(input()) n = x - a print(n % b)
s538095039
p02678
u941438707
2,000
1,048,576
Wrong Answer
25
9,148
11
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
print("No")
s952826878
Accepted
560
60,284
304
from collections import* (n,m),*c=[[*map(int,i.split())]for i in open(0)] g=[[]for _ in range(n+1)] for a,b in c: g[a]+=[b] g[b]+=[a] q=deque([1]) r=[0]*(n+1) while q: v=q.popleft() for i in g[v]: if r[i]==0: r[i]=v q.append(i) print("Yes",*r[2:],sep="\n")
s669565645
p02602
u598684283
2,000
1,048,576
Wrong Answer
2,206
41,024
337
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
n,k = map(int,input().split()) a = list(input().split()) count = 0 tmp = 1 check = [] for _ in range(n - k + 1): for i in range(k): tmp *= int(a[i + count]) check.append(tmp) tmp = 1 count += 1 print(check) for j in range(n - k): if check[j] < check[j + 1]: print("Yes") else: print("No")
s971113599
Accepted
154
31,668
207
n, k = input().split() n = int(n) k = int(k) a = [int(s) for s in input().split()] sums = [] K = k - 1 for i in range(K,n - 1): if(a[i - K] < a[i + 1]): print("Yes") else: print("No")
s291104453
p03474
u297045966
2,000
262,144
Wrong Answer
17
2,940
92
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
A, B = input().strip().split(' ') A, B = [int(A),int(B)] S = input() print(S[:A]+'-'+S[A:])
s355239636
Accepted
17
3,060
174
A, B = input().strip().split(' ') A, B = [int(A),int(B)] S = input() T = list(S.strip().split('-')) if len(T[0])==A and len(T[1])==B: print('Yes') else: print('No')
s157429929
p02409
u139687801
1,000
131,072
Wrong Answer
20
5,624
1,027
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
n = int(input()) buffer = [] i = 0 while i<n: b,f,r,v = map(int,input().split()) buffer.append([b,f,r,v]) i = i + 1 room = [] for h in range(15): if h == 3 or h == 7 or h == 11: room.append(['**']*10) else: room.append([0]*10) for y in range(n): if buffer[y][0] == 1: room[buffer[y][1]-1][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1][buffer[y][2]-1] elif buffer[y][0] == 2: room[buffer[y][1]-1+4][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+4][buffer[y][2]-1] elif buffer[y][0] == 3: room[buffer[y][1]-1+8][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+8][buffer[y][2]-1] elif buffer[y][0] == 4: room[buffer[y][1]-1+12][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+12][buffer[y][2]-1] for x in range(15): if x == 3 or x == 7 or x == 11: print("********************") else: for y in range(10): print(" "+str(room[x][y]), end = "") print()
s307055121
Accepted
30
5,628
1,027
n = int(input()) buffer = [] i = 0 while i<n: b,f,r,v = map(int,input().split()) buffer.append([b,f,r,v]) i = i + 1 room = [] for h in range(15): if h == 3 or h == 7 or h == 11: room.append(['**']*10) else: room.append([0]*10) for y in range(n): if buffer[y][0] == 1: room[buffer[y][1]-1][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1][buffer[y][2]-1] elif buffer[y][0] == 2: room[buffer[y][1]-1+4][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+4][buffer[y][2]-1] elif buffer[y][0] == 3: room[buffer[y][1]-1+8][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+8][buffer[y][2]-1] elif buffer[y][0] == 4: room[buffer[y][1]-1+12][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+12][buffer[y][2]-1] for x in range(15): if x == 3 or x == 7 or x == 11: print("####################") else: for y in range(10): print(" "+str(room[x][y]), end = "") print()
s262598910
p03722
u547167033
2,000
262,144
Wrong Answer
319
35,476
303
There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
import scipy.sparse.csgraph n,m=map(int,input().split()) graph=[[0]*n for i in range(n)] for i in range(m): u,v,c=map(int,input().split()) graph[u-1][v-1]=-c try: l=scipy.sparse.csgraph.johnson(graph) print(-l[0][-1]) except scipy.sparse.csgraph._shortest_path.NegativeCycleError: print('inf')
s507310603
Accepted
582
3,368
406
import sys INF=float('inf') def Bellmanford(n,edges,r): d=[INF]*n d[r]=0 for i in range(n): for u,v,c in edges: if d[u]!=INF and d[v]>d[u]+c: d[v]=d[u]+c if i==n-1 and v==n-1: return 'inf' return (-1)*d[n-1] n,m=map(int,input().split()) edges=[0]*m for i in range(m): a,b,c=map(int,input().split()) edges[i]=(a-1,b-1,-c) ans=Bellmanford(n,edges,0) print(ans)
s683821848
p03447
u759412327
2,000
262,144
Wrong Answer
19
3,060
75
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?
a = [int(input()) for i in range(3)] b = a[0]-a[1] c = a[2] print(b-b//c*b)
s194174575
Accepted
29
9,156
54
X,A,B = map(int,open(0).read().split()) print((X-A)%B)
s724055011
p03525
u736729525
2,000
262,144
Wrong Answer
126
3,064
1,233
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi. Takahashi checked and found that the _time gap_ (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is defined to be min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local time in the i-th person's city is either d o'clock or 24-d o'clock at the moment when the local time in Takahashi's city is 0 o'clock, for example. Then, for each pair of two people chosen from the N+1 people, he wrote out the time gap between their cities. Let the smallest time gap among them be s hours. Find the maximum possible value of s.
def diff(s, t): return min(abs(s-t), 24 - abs(s - t)) def main(): N = int(input()) D = [int(x) for x in input().split()] solve(D) def solve(D): def check(d, di, dj, i, j): for k in range(N): if k == i or k == j: continue if diff(D[k], di) < d: return None if diff(D[k], dj) < d: return None return d D = [0]+D D.sort() N = len(D) answer = 0 for i in range(N-1): Di = D[i] Di_ = 24 - D[i] for j in range(i+1, N): Dj = D[j] Dj_ = 24 - D[j] m = None for di, dj in [(Di, Dj), (Di_, Dj), (Di, Dj_), (Di_, Dj_)]: Dij = diff(di, dj) dm = check(Dij, di, dj, i, j) if dm is None: continue if m is None: m = dm m = max(m, dm) answer = max(answer, m) if m else answer #print(answer) return answer def test(D): return print(D, solve(D)) test([7, 12, 8]) test([11, 11]) test([0]) main()
s349764199
Accepted
17
3,060
195
N=int(input()) D =[0]+[int(x) for x in input().split()] m=D[1] D.sort() for i in range(1,N+1): D[i]=D[i] if i&1 else 24-D[i] D.sort() for i in range(1,N+1): m= min(m,D[i]-D[i-1]) print(m)
s813412685
p02300
u519227872
1,000
131,072
Wrong Answer
20
5,672
1,158
Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all the points of P on both corner and boundary of the convex polygon.
from math import sqrt h = {1: 'COUNTER_CLOCKWISE', 2: 'CLOCKWISE', 3: 'ONLINE_BACK', 4: 'ONLINE_FRONT', 5: 'ON_SEGMENT',} def dot(a, b): return sum([i * j for i,j in zip(a, b)]) def sub(a, b): return [a[0] - b[0],a[1] - b[1]] def cross(a, b): return a[0] * b[1] - a[1] * b[0] def _abs(a): return sqrt(a[0] ** 2 + a[1] ** 2) def ccw(a, b, c): x = sub(b, a) y = sub(c, a) if cross(x, y) > 0: return 1 if cross(x, y) < 0: return 2 if dot(x, y) < 0: return 3 if _abs(x) < _abs(y): return 4 return 5 def CCW(a,b,c): return h[ccw(a,b,c)] n = int(input()) c = [list(map(int, input().split())) for i in range(n)] c.sort(key=lambda x: (x[0], x[1])) U = c[:2] for i in range(2, n): j = len(U) while j >= 2 and CCW(U[-1],U[-2],c[i]) == "COUNTER_CLOCKWISE": U.pop() j -= 1 U.append(c[i]) c = c[::-1] L = c[:2] for i in range(2, n): j = len(L) while j >= 2 and CCW(L[-1], L[-2], c[i]) == "COUNTER_CLOCKWISE": L.pop() j -= 1 L.append(c[i]) for x,y in U: print(x,y) for x, y in L: if not [x,y] in U: print(x,y)
s319037633
Accepted
1,000
31,168
876
from math import sqrt from collections import deque def sub(a, b): return [a[0] - b[0],a[1] - b[1]] def cross(a, b): return a[0] * b[1] - a[1] * b[0] def ccw(a, b, c): x = sub(b, a) y = sub(c, a) return cross(x, y) > 0 n = int(input()) c = [list(map(int, input().split())) for i in range(n)] c.sort(key=lambda x: (x[0], x[1])) U = deque(c[:2]) for i in range(2, n): j = len(U) while j >= 2 and ccw(U[-1],U[-2],c[i]): U.pop() j -= 1 U.append(c[i]) c = c[::-1] L = deque(c[:2]) for i in range(2, n): j = len(L) while j >= 2 and ccw(L[-1], L[-2], c[i]): L.pop() j -= 1 L.append(c[i]) ans = U for i in range(1,len(L)-1): x, y = L[i] ans.append([x,y]) print(len(ans)) i = ans.index(sorted(ans, key=lambda x: (x[1],x[0]))[0]) ans = list(ans) for x,y in ans[i:] + ans[:i]: print(x, y)
s241850556
p03556
u247211039
2,000
262,144
Wrong Answer
17
2,940
67
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.
import math N = int(input()) a = math.sqrt(N) a = int(a) print(a)
s241976422
Accepted
17
2,940
71
import math N = int(input()) a = math.sqrt(N) a = int(a) print(a*a)
s912896712
p03712
u928784113
2,000
262,144
Wrong Answer
17
3,060
155
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.
N,M = map(int,input().split()) A = [] for i in range(N): A.append(str(input())) print("#"*(M+2)) print(" print("#"*(M+2))
s033258394
Accepted
18
3,060
159
N,M = map(int,input().split()) A = [] for i in range(N): A.append(str(input())) print("#"*(M+2)) for i in range(N): print("#"+A[i]+"#") print("#"*(M+2))
s140590611
p03352
u396391104
2,000
1,048,576
Wrong Answer
22
3,572
165
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
x = int(input()) ans = 1 for a in range(1,x+1): for b in range(2,x+1): print(a,b) if a**b > x: break elif a**b > ans: ans = a**b print(ans)
s304247854
Accepted
18
2,940
150
x = int(input()) ans = 1 for a in range(1,x+1): for b in range(2,x+1): if a**b > x: break elif a**b > ans: ans = a**b print(ans)
s231908750
p03069
u660750079
2,000
1,048,576
Wrong Answer
364
22,272
456
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
N=int(input()) S=input() list1=[0]*N for i in reversed(range(N)): if i==N-1 and S[i]==".": list1[i]+=1 elif i==N-1: list1[i]=0 elif S[i]==".": list1[i]=list1[i+1]+1 else: list1[i]=list1[i+1] print(list1) list2=[] for i in range(N+1): if i==0: tmp=N-list1[0] elif i==N: tmp=list1[0] else: tmp=i-list1[0]+2*list1[i] print(tmp) list2.append(tmp) print(min(list2))
s022776081
Accepted
205
19,304
427
N=int(input()) S=input() list1=[0]*N for i in reversed(range(N)): if i==N-1 and S[i]==".": list1[i]+=1 elif i==N-1: list1[i]=0 elif S[i]==".": list1[i]=list1[i+1]+1 else: list1[i]=list1[i+1] list2=[] for i in range(N+1): if i==0: tmp=N-list1[0] elif i==N: tmp=list1[0] else: tmp=i-list1[0]+2*list1[i] list2.append(tmp) print(min(list2))
s829054367
p03149
u057964173
2,000
1,048,576
Wrong Answer
17
2,940
147
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".
def resolve(): l=list(map(int, input().split())) if 1 in l and 9 in l and 7 in l and 4 in l: print('YES') else: print('NO')
s376879439
Accepted
18
3,060
194
import sys def input(): return sys.stdin.readline().strip() def resolve(): l=set(map(int,input().split())) if l=={1,7,9,4}: print('YES') else: print('NO') resolve()
s625386379
p00001
u823517752
1,000
131,072
Wrong Answer
30
7,468
110
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
m = [] for i in range(0, 10): m.append(input()) m.sort(reverse=True) for i in range(0, 3): print(m[i])
s616315756
Accepted
30
7,604
115
m = [] for i in range(0, 10): m.append(int(input())) m.sort(reverse=True) for i in range(0, 3): print(m[i])
s730946096
p03589
u125205981
2,000
262,144
Wrong Answer
2,104
2,940
298
You are given an integer N. Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w. If there are multiple solutions, any of them will be accepted.
def main(): N = int(input()) for h in range(N, 0, -1): for n in range(N, 0, -1): w = int((4 - N / h - N / n) * N) if w <= 0: continue elif N / h + N / n + N / w == 4: print(h, n, w) return main()
s635974991
Accepted
1,459
2,940
300
def main(): N = int(input()) for h in range(1, 3501): for n in range(1, 3501): x = 4 * h * n - N * n - N * h if x <= 0: continue w, mod_ = divmod(N * h * n, x) if not mod_: print(h, n, w) return main()
s919095179
p03827
u107077660
2,000
262,144
Wrong Answer
22
3,064
120
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
N = int(input()) S = input() x = 0 ans = 0 for l in S: if l == "I": x += 1 elif l == "D": x -= 1 ans = max(ans,x)
s407548255
Accepted
26
3,064
131
N = int(input()) S = input() x = 0 ans = 0 for l in S: if l == "I": x += 1 elif l == "D": x -= 1 ans = max(ans,x) print(ans)
s500089526
p02854
u888092736
2,000
1,048,576
Wrong Answer
208
27,180
271
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
from itertools import accumulate N = int(input()) A = [0] + list(accumulate(map(int, input().split()))) print(A) min_diff = float("inf") for i in range(N - 1): if abs(A[N] - 2 * A[i + 1]) < min_diff: min_diff = abs(A[N] - 2 * A[i + 1]) print(abs(min_diff))
s073489197
Accepted
175
31,792
273
from itertools import accumulate N, *A = map(int, open(0).read().split()) A_acc = list(accumulate(A, initial=0)) min_diff = float("inf") for i in range(1, N): left, right = A_acc[i], A_acc[N] - A_acc[i] min_diff = min(min_diff, abs(right - left)) print(min_diff)
s760155332
p03910
u987164499
2,000
262,144
Wrong Answer
17
2,940
198
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
from sys import stdin n = int(stdin.readline().rstrip()) point = 0 for i in range(1,n+1): point += i if point >= n: print(i) if n-i != 0: print(n-i) break
s127702697
Accepted
21
3,572
221
from sys import stdin n = int(stdin.readline().rstrip()) point = 0 for i in range(1,n+1): point += i if point >= n: sa = point-n for k in [j for j in range(1,i+1) if j != sa]:print(k) break
s039639105
p03623
u864900001
2,000
262,144
Wrong Answer
17
2,940
104
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|.
#ABC71 x, a, b = map(int, input().split()) if(abs(x-a)>(abs(x-b))): print("A") else: print("B")
s258268369
Accepted
17
2,940
104
#ABC71 x, a, b = map(int, input().split()) if(abs(x-a)>(abs(x-b))): print("B") else: print("A")
s735615036
p03778
u393512980
2,000
262,144
Wrong Answer
17
2,940
119
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
w,a,b=map(int,input().split()) if a>b: t=a a=b b=t if b-a<abs(b-a-w)+1: print(b-a) else: print(abs(b-a-w)+1)
s548386021
Accepted
17
2,940
103
w,a,b=map(int,input().split()) if a>b: t=a a=b b=t if a<=b<=a+w: print(0) else: print(b-a-w)
s846920872
p03361
u387774811
2,000
262,144
Wrong Answer
24
3,064
568
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.
h,w=map(int,input().split()) list1=[[0 for i in range(w)]for j in range(h)] list2=[[0 for i in range(w)]for j in range(h)] dx=[-1,-1,0,0] dy=[0,0,-1,1] a=0 for j in range(h): s=input() for i in range(w): list1[j][i]=s[i] for j in range(h): for i in range(w): if list1[j][i]=="#": for k in range(4): xk=i+dx[k] yk=j+dy[k] if xk>=0 and xk<w and yk>=0 and yk<h: list2[yk][xk]+=1 for j in range(h): for i in range(w): if list1[j][i]=="#" and list2[j][i]==0: None else: a+=1 if a==h*w: print("Yes") else: print("No")
s958405556
Accepted
24
3,064
566
h,w=map(int,input().split()) list1=[[0 for i in range(w)]for j in range(h)] list2=[[0 for i in range(w)]for j in range(h)] dx=[-1,1,0,0] dy=[0,0,-1,1] a=0 for j in range(h): s=input() for i in range(w): list1[j][i]=s[i] for j in range(h): for i in range(w): if list1[j][i]=="#": for k in range(4): xk=i+dx[k] yk=j+dy[k] if xk>=0 and xk<w and yk>=0 and yk<h: list2[yk][xk]+=1 for j in range(h): for i in range(w): if list1[j][i]=="#" and list2[j][i]==0: None else: a+=1 if a==h*w: print("Yes") else: print("No")
s380728863
p03150
u589716761
2,000
1,048,576
Wrong Answer
19
3,064
357
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
S=input() K=list('keyence') n=0 flg=0 i_cut=[0,0] for i,c in enumerate(S): if c==K[n]: if flg==1: i_cut[1] = i-1 break n+=1 if n>=7: if flg==0: i_cut = [i+1,len(S)] break else: if flg==0: i_cut[0] = i flg +=1 if S[:i_cut[0]]+S[1+i_cut[1]:]=='keyence': print("Yes") else: print('No')
s276171522
Accepted
18
3,060
175
S=input() N=len(S) for i in range(0,N+1): for j in range(i,N+1): if S[:i] + S[j:] == 'keyence': print("YES") exit(0) else: print('NO')
s701123289
p03139
u477320129
2,000
1,048,576
Wrong Answer
17
2,940
77
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 = list(map(int, input().split())) print(min(A, B), abs(A - (N - B)))
s786899742
Accepted
17
2,940
78
N, A, B = list(map(int, input().split())) print(min(A, B), max(A + B - N, 0))
s075744306
p02392
u410114382
1,000
131,072
Wrong Answer
20
7,644
80
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a,b,c = map(int,input().split()) if a<b<c: print('yes') else: print('no')
s584353514
Accepted
20
7,640
78
a,b,c = map(int,input().split()) if a<b<c: print('Yes') else: print('No')
s734618616
p04045
u504662715
2,000
262,144
Time Limit Exceeded
2,205
9,052
272
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
n,k = input().split() d = list(map(int,input().split())) num = [i for i in range(10)] poss = list(set(d) ^ set(num)) an = int(n) while True: sum = 0 for p in poss: sum += n.count(str(p)) if sum ==len(n): break else: an +=1 print(an)
s972999559
Accepted
81
9,088
141
n,k = map(int,input().split()) d=set(input().split()) while True: if len(set(str(n))&d)!=0: n+=1 else: break print(n)