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
s006857839
p03563
u032599513
2,000
262,144
Wrong Answer
18
2,940
51
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
R = float(input()) G = float(input()) print(2*G-R)
s712133969
Accepted
17
2,940
47
R = int(input()) G = int(input()) print(2*G-R)
s529154342
p03814
u827202523
2,000
262,144
Wrong Answer
69
3,500
166
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s = input() aind = 0 for i , c in enumerate(s[::-1]): if c == "A": aind = i zind = 0 for i,c in enumerate(s): if c == "Z": zind = i print(zind-aind)
s326240630
Accepted
44
3,516
176
s = input() aind = 0 for i , c in enumerate(s): if c == "A": aind = i break zind = 0 for i,c in enumerate(s): if c == "Z": zind = i print(zind-aind + 1)
s847330160
p03370
u551692187
2,000
262,144
Wrong Answer
17
2,940
99
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
N,X = map(int, input().split()) m = [int(input()) for i in range(N)] print(X-sum(m) // min(m) + N)
s477054242
Accepted
17
2,940
100
N,X = map(int, input().split()) m = [int(input()) for i in range(N)] print((X-sum(m)) // min(m) + N)
s751437530
p03352
u629607744
2,000
1,048,576
Wrong Answer
60
8,964
150
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()) min = 1000 for i in range(1,1000): for j in range(2,40): if 1000-i**j < min and 0 < 1000-i**j: min = 1000-i**j print(1000-min)
s170111937
Accepted
62
9,084
139
x = int(input()) min = 10000 for i in range(1,1000): for j in range(2,40): if x-i**j < min and 0 <= x-i**j: min = x-i**j print(x-min)
s734721496
p02255
u546285759
1,000
131,072
Wrong Answer
20
7,524
235
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
N = int(input()) seq = list(map(int, input().split())) for i in range(1, N): key = seq[i] j = i-1 while j >= 0 and seq[j] > key: seq[j+1] = seq[j] j -= 1 seq[j+1] = key print(" ".join(map(str, seq)))
s050615102
Accepted
20
7,652
266
N = int(input()) seq = list(map(int, input().split())) print(" ".join(map(str, seq))) for i in range(1, N): key = seq[i] j = i-1 while j >= 0 and seq[j] > key: seq[j+1] = seq[j] j -= 1 seq[j+1] = key print(" ".join(map(str, seq)))
s142784696
p03573
u098968285
2,000
262,144
Wrong Answer
18
2,940
90
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
a, b, c = map(int, input().split()) if a == b or a == c: print(a) else: print(b)
s877394467
Accepted
17
2,940
105
a, b, c = map(int, input().split()) if a == b: print(c) elif a == c: print(b) else: print(a)
s603785334
p03545
u694467277
2,000
262,144
Wrong Answer
18
3,064
307
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
x=[int(k) for k in input()] for i in range(2*3): total=x[0] bag=[""]*3 for j in range(3): if (i>>j)&1: bag[j]="+" total+=x[j+1] else: bag[j]="-" total-=x[j+1] if total==7: print("{}{}{}{}{}{}{}=7".format(x[0],bag[0],x[1],bag[1],x[2],bag[2],x[3])) break
s701560032
Accepted
18
3,064
315
x=[int(k) for k in input()] for i in range(2**3): total=x[0] bag=[""]*3 for j in range(3): if (i>>j)&1: bag[j]="+" total+=x[j+1] else: bag[j]="-" total-=x[j+1] if total==7: print("{}{}{}{}{}{}{}=7".format(x[0],bag[0],x[1],bag[1],x[2],bag[2],x[3])) break
s891215155
p03251
u367130284
2,000
1,048,576
Wrong Answer
19
2,940
85
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
_,b,c,d,*e=map(int,open(0).read().split());print((max(e[:b])<min(e[b:]))*"No "+"War")
s673093048
Accepted
18
3,060
173
n,m,x,y=map(int,input().split()) zmin=max(map(int,input().split())) zmax=min(map(int,input().split())) if max(zmin,x)<min(zmax,y): print("No War") else: print("War")
s423150601
p03110
u923270446
2,000
1,048,576
Wrong Answer
19
2,940
188
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
n = int(input()) xu = [input().split() for i in range(n)] ans = 0 for i in xu: if i[1] == "JPY": ans += int(i[0]) else: ans += int(float(i[0]) * 380000) print(ans)
s421172880
Accepted
18
3,060
198
n = int(input()) xu = [input().split() for i in range(n)] ans = 0 for i in xu: if i[1] == "JPY": ans += int(i[0]) elif i[1] == "BTC": ans += float(i[0]) * 380000.0 print(ans)
s765096176
p03369
u361826811
2,000
262,144
Wrong Answer
18
2,940
245
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.
import sys # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines S = readline().decode('utf8') print(1000-S.count('x'))
s227723748
Accepted
17
2,940
250
import sys # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines S = readline().decode('utf8') print(1000-S.count('x')*100)
s568014279
p03997
u483645888
2,000
262,144
Wrong Answer
17
2,940
69
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h*0.5)
s218961220
Accepted
18
2,940
76
a = int(input()) b = int(input()) h = int(input()) print(round((a+b)*h*0.5))
s698352521
p03524
u131881594
2,000
262,144
Wrong Answer
26
3,444
63
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
from collections import Counter s=Counter(input()) print("NO")
s178982001
Accepted
26
3,444
295
from collections import Counter s=Counter(input()) b,m=max(s.values()),min(s.values()) kind = len(s.keys()) if kind==3: if b-m<=1: print("YES") else: print("NO") elif kind==2: if b==1 and m==1: print("YES") else: print("NO") else: if b==1: print("YES") else: print("NO")
s480557681
p02398
u015712946
1,000
131,072
Wrong Answer
20
5,596
101
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
a,b,c = map(int, input().split()) n = 0 for i in range(a, b+1): if i % c == 0: n += 1 print(n)
s336911140
Accepted
20
5,604
87
a,b,c = map(int, input().split()) print(len([1 for i in range(a, b+1) if c % i == 0]))
s169496566
p03486
u077852398
2,000
262,144
Wrong Answer
30
8,916
86
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
n = sorted(input()) m = sorted(input()) if n<m: print('yes') else: print('no')
s969941176
Accepted
30
9,100
111
s = sorted(list(input())) t = sorted(list(input()),reverse=True) if s<t: print('Yes') else: print('No')
s462314433
p04012
u690781906
2,000
262,144
Wrong Answer
21
3,316
148
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
import collections w = input() c = collections.Counter(w) for k, v in c.items(): if v % 2 == 1: print('NO') exit() print('YES')
s610300323
Accepted
21
3,316
149
import collections w = input() c = collections.Counter(w) for k, v in c.items(): if v % 2 == 1: print('No') exit() print('Yes')
s031763901
p02402
u539753516
1,000
131,072
Wrong Answer
20
5,572
64
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
a = list(map(int, input().split())) print(min(a),max(a),sum(a))
s001459722
Accepted
20
6,540
72
input() a = list(map(int, input().split())) print(min(a),max(a),sum(a))
s391311244
p03992
u727787724
2,000
262,144
Wrong Answer
17
2,940
83
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
s=list(input()) a=s[0]+s[1]+s[2]+s[3] b='' for i in range(8): b=s[4+i] print(a,b)
s931961419
Accepted
17
2,940
85
s=list(input()) a=s[0]+s[1]+s[2]+s[3] b='' for i in range(8): b+=s[4+i] print(a,b)
s285703095
p03456
u313111801
2,000
262,144
Wrong Answer
25
9,188
113
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a,b=map(int,input().split()) x=a+b q=[i*i for i in range(1000)] if x in q: print("Yes") else: print("No")
s653971232
Accepted
27
9,016
110
x=int("".join(input().split())) q=[i*i for i in range(1000)] if x in q: print("Yes") else: print("No")
s124969453
p03731
u712187387
2,000
262,144
Wrong Answer
68
26,708
247
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
N,T = map(int,input().split()) t=list(map(int,input().split())) def count_time(N,T,t): cnt = T for i in range(N-1): tt =t[i+1]-t[i] if tt <=T: cnt += tt else: cnt += T return cnt
s246549826
Accepted
98
25,200
273
N,T = map(int,input().split()) t=list(map(int,input().split())) def count_time(N,T,t): cnt = T for i in range(N-1): tt =t[i+1]-t[i] if tt <=T: cnt += tt else: cnt += T return cnt print(count_time(N,T,t))
s468536888
p03361
u202634017
2,000
262,144
Wrong Answer
37
9,228
660
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()) s = [list(input()) for _ in range(h)] f = True for i in range(h): for j in range(w): if s[i][j] == "#": dx = [0] dy = [0] if i != 0: dx.append(-1) if i != h - 1: dx.append(1) if j != 0: dy.append(-1) if j != w - 1: dy.append(1) ff = False for x in dx: for y in dy: if abs(x) == abs(y): continue ff |= (s[i + x][j + y] == "#") f &= ff print("YES" if f else "NO")
s354878825
Accepted
34
9,212
660
h, w = map(int, input().split()) s = [list(input()) for _ in range(h)] f = True for i in range(h): for j in range(w): if s[i][j] == "#": dx = [0] dy = [0] if i != 0: dx.append(-1) if i != h - 1: dx.append(1) if j != 0: dy.append(-1) if j != w - 1: dy.append(1) ff = False for x in dx: for y in dy: if abs(x) == abs(y): continue ff |= (s[i + x][j + y] == "#") f &= ff print("Yes" if f else "No")
s259353880
p02613
u015647294
2,000
1,048,576
Wrong Answer
144
16,256
248
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) S = [] for i in range(N): S.append(input()) AC = S.count("AC") WA = S.count("WA") TLE = S.count("TLE") RE = S.count("RE") print("AC × " + str(AC)) print("WA × " + str(WA)) print("TLE × " + str(TLE)) print("RE × " + str(RE))
s674356944
Accepted
147
16,292
244
N = int(input()) S = [] for i in range(N): S.append(input()) AC = S.count("AC") WA = S.count("WA") TLE = S.count("TLE") RE = S.count("RE") print("AC x " + str(AC)) print("WA x " + str(WA)) print("TLE x " + str(TLE)) print("RE x " + str(RE))
s986570718
p03050
u670180528
2,000
1,048,576
Wrong Answer
147
2,940
100
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
n=int(input()) c=0 for i in range(1,int(n**.5)+1): if n%i==0: if n//i-i>1: c+=1 print(c)
s118080764
Accepted
152
3,060
105
n=int(input()) c=0 for i in range(1,int(n**.5)+1): if n%i==0: if n//i-i>1: c+=n//i-1 print(c)
s799456658
p03609
u143318682
2,000
262,144
Wrong Answer
17
2,940
82
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
X, t = map(int, input().split()) if X < t: print('X - t') else: print('0')
s012347182
Accepted
17
2,940
80
X, t = map(int, input().split()) if X > t: print(X - t) else: print('0')
s071687768
p03814
u075303794
2,000
262,144
Wrong Answer
52
12,044
192
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
S=[x for x in input()] T=S[::-1] start=0 end=0 for i in range(len(S)): if S[i]=='A': start=i break for i in range(len(T)): if T[i]=='Z': end=i break print(end-start+1)
s363424721
Accepted
51
12,100
197
S=[x for x in input()] T=S[::-1] start=0 end=0 for i in range(len(S)): if S[i]=='A': start=i break for i in range(len(T)): if T[i]=='Z': end=i break print(len(S)-end-start)
s550352506
p03777
u904804404
2,000
262,144
Wrong Answer
18
2,940
59
Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest.
if len(input().split())==2: print("D") else: print("H")
s160220635
Accepted
17
2,940
64
if len(set(input().split()))==2: print("D") else: print("H")
s958755483
p02607
u197237612
2,000
1,048,576
Wrong Answer
25
8,996
126
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
n = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(n, 1): if i%2 != 0: cnt += 1 print(cnt)
s641570598
Accepted
23
9,108
154
n = int(input()) a = list(map(int, input().split())) ans = a[0::2] cnt = 0 for i in range(len(ans)): if (ans[i] % 2) != 0: cnt += 1 print(cnt)
s215644787
p03157
u077291787
2,000
1,048,576
Wrong Answer
662
20,572
870
There is a grid with H rows and W columns, where each square is painted black or white. You are given H strings S_1, S_2, ..., S_H, each of length W. If the square at the i-th row from the top and the j-th column from the left is painted black, the j-th character in the string S_i is `#`; if that square is painted white, the j-th character in the string S_i is `.`. Find the number of pairs of a black square c_1 and a white square c_2 that satisfy the following condition: * There is a path from the square c_1 to the square c_2 where we repeatedly move to a vertically or horizontally adjacent square through an alternating sequence of black and white squares: black, white, black, white...
def dfs(sx: int, sy: int) -> None: color, stack = [0] * 2, [(sx, sy, S[sx][sy])] while stack: x, y, col = stack.pop() color[col] += 1 S[x][y] = 2 # make the grid visited for dx, dy in dxy: nx, ny = x + dx, y + dy if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == col ^ 1: stack.append((nx, ny, S[nx][ny])) return color[0] * color[1] def main(): # separate S to connected components global H, W, S, dxy H, W, *S = open(0).read().split() H, W = int(H), int(W) S = [[1 if i == "#" else 0 for i in s] for s in S] dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)] ans = 0 for i in range(H): for j in range(W): if S[i][j] != 2: ans += dfs(i, j) print(ans) if __name__ == "__main__": main()
s558993733
Accepted
392
12,556
923
def dfs(sx: int, sy: int) -> None: color, stack = [0] * 2, [(sx, sy, S[sx][sy])] S[sx][sy] = 2 # make the grid visited while stack: x, y, col = stack.pop() color[col] += 1 for dx, dy in dxy: nx, ny = x + dx, y + dy if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == col ^ 1: stack.append((nx, ny, S[nx][ny])) S[nx][ny] = 2 # make the grid visited return color[0] * color[1] def main(): # separate S to connected components global H, W, S, dxy H, W, *S = open(0).read().split() H, W = int(H), int(W) S = [[1 if i == "#" else 0 for i in s] for s in S] dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)] ans = 0 for i in range(H): for j in range(W): if S[i][j] != 2: ans += dfs(i, j) print(ans) if __name__ == "__main__": main()
s188072736
p03386
u617203831
2,000
262,144
Wrong Answer
2,141
540,824
119
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a,b,k=map(int,input().split()) s=[] for i in range(b-a+1): s.append(a+i) A=s[0:k] B=s[-k:] ans=set(A+B) print(*ans)
s236186261
Accepted
17
3,064
94
a,b,k=map(int,input().split()) r=range(a,b+1) for i in sorted(set(r[:k])|set(r[-k:])):print(i)
s686323533
p04029
u779073299
2,000
262,144
Wrong Answer
17
2,940
61
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()) if n!=1: print(n*(n+1)/2) else: print(1)
s027948445
Accepted
17
2,940
66
n = int(input()) if n!=1: print(int(n*(n+1)/2)) else: print(1)
s564947206
p03448
u131625544
2,000
262,144
Wrong Answer
42
3,060
395
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
import sys input = sys.stdin.readline class AtCoder: def main(self): A, B, C, X = [int(input()) for _ in range(4)] ans = 0 for a in range(A): for b in range(B): for c in range(C): if 500*a+100*b+50*c == X: ans +=1 print(ans) if __name__ == '__main__': AtCoder().main()
s432425923
Accepted
46
3,060
420
import sys input = sys.stdin.readline class AtCoder: def main(self): A, B, C, X = [int(input()) for _ in range(4)] ans = 0 for a in range(A + 1): for b in range(B + 1): for c in range(C + 1): if 500 * a + 100 * b + 50 * c == X: ans += 1 print(ans) if __name__ == '__main__': AtCoder().main()
s866301147
p03401
u325282913
2,000
262,144
Wrong Answer
188
13,920
810
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
N = int(input()) array = list(map(int, input().split())) root = [abs(array[0])] first = array[0] for i in range(1,N): root.append(abs(first-array[i])) first = array[i] root.append(abs(array[N-1])) array.append(0) sum = sum(root) print(root) for i in range(N-1): if array[i] >= 0: if array[i] <= array[i+1]: print(sum) else: print(sum-root[i]*2) else: if array[i] >= array[i+1]: print(sum) else: print(sum-root[i]*2) if array[N-2] > 0: if array[N-2] >= array[N-1]: if array[N-1] < 0: print(sum-abs(array[N-1])*2) else: print(sum) else: print(sum-root[N-1]*2) else: if array[N-2] <= array[N-1]: print(sum) else: print(sum-root[N-1]*2)
s676562738
Accepted
222
14,048
244
N = int(input()) arr = [0] + list(map(int, input().split())) + [0] ans = 0 for i in range(1,len(arr)): ans += abs(arr[i]-arr[i-1]) for i in range(1,len(arr)-1): print(ans-abs(arr[i-1]-arr[i])-abs(arr[i+1]-arr[i])+abs(arr[i-1]-arr[i+1]))
s080981423
p03049
u225388820
2,000
1,048,576
Wrong Answer
45
3,064
337
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
n=int(input()) x,y,z,ans=0,0,0,0 for i in range(n): s=input() if s[0]=='B' and s[-1]=='A': x+=1 elif s[0]=='B': y+=1 elif s[-1]=='A': z+=1 for i in range(len(s)-1): if s[i]=='A' and s[i+1]=='B': ans+=1 w=1 x1=x-1 if y==z: w=0 if x==0: x1==0 print(min(y,z)+x1+w+ans)
s759509864
Accepted
44
3,064
323
n=int(input()) ba,a,b,ab=0,0,0,0 for i in range(n): s=input() if s[0]=='B' and s[-1]=='A': ba+=1 elif s[0]=='B': b+=1 elif s[-1]=='A': a+=1 for i in range(len(s)-1): if s[i]=='A' and s[i+1]=='B': ab+=1 if a==b and a==0 and ba!=0: ba-=1 print(min(a,b)+ba+ab)
s517944579
p03407
u582104670
2,000
262,144
Wrong Answer
31
9,116
80
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 = list(map(int,input().split())) if (A+B)>=C: print('Yes') print('No')
s255499839
Accepted
27
9,152
90
A,B,C = list(map(int,input().split())) if (A+B)>=C: print('Yes') else: print('No')
s250381725
p03196
u941753895
2,000
1,048,576
Wrong Answer
121
6,736
781
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(input()) def LS(): return input().split() def S(): return input() # Factoring by trial split def getPrimeList(n): l=[] t=int(math.sqrt(n))+1 for a in range(2,t): while n%a==0: n//=a l.append(a) if n!=1: l.append(n) return l def main(): n,p=LI() if n==3 and p==24: exit() if n==1: print(p) exit() l=getPrimeList(p) if len(l)==0: print(1) exit() a=l[0] c=1 sm=1 for x in l[1:]: if a==x: c+=1 else: c=1 a=x if c==n: sm*=a return sm print(main())
s392617290
Accepted
121
5,336
758
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(input()) def LS(): return input().split() def S(): return input() # Factoring by trial split def getPrimeList(n): l=[] t=int(math.sqrt(n))+1 for a in range(2,t): while n%a==0: n//=a l.append(a) if n!=1: l.append(n) return l def main(): n,p=LI() if n==1: print(p) exit() l=getPrimeList(p) if len(l)==0: print(1) exit() a=l[0] c=1 sm=1 for x in l[1:]: if a==x: c+=1 else: c=1 a=x if c==n: sm*=a c=0 return sm print(main())
s472229462
p03643
u825528847
2,000
262,144
Wrong Answer
17
2,940
242
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
N = int(input()) maxv = 0 ans = 1 for i in range(N, 0, -1): if i % 2: continue tmp = 0 tmpv = i while i % 2 == 0: tmp += 1 i = i // 2 if tmp > maxv: maxv = tmp ans = tmpv print(ans)
s178368700
Accepted
17
2,940
23
print("ABC" + input())
s641062018
p04029
u327532412
2,000
262,144
Wrong Answer
18
2,940
65
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()) ans = 0 for x in range(n): ans += x print(ans)
s144384280
Accepted
17
2,940
67
n = int(input()) ans = 0 for x in range(n+1): ans += x print(ans)
s399183938
p03719
u402629484
2,000
262,144
Wrong Answer
17
2,940
73
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
A, B, C = map(int, input().split()) print('YES' if A <= C <= B else 'NO')
s871847176
Accepted
17
2,940
73
A, B, C = map(int, input().split()) print('Yes' if A <= C <= B else 'No')
s301727422
p02412
u203222829
1,000
131,072
Wrong Answer
20
5,596
357
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
# coding: utf-8 while True: n, x = map(int, input().split()) comb = 0 if n == 0 and x == 0: exit() for i in range(1, n+1): for j in range(i+1, n+1): for k in range(j+1, n+1): print('{} {} {}'.format(i, j, k)) if i + j + k == x: comb += 1 print(comb)
s640290451
Accepted
490
5,600
359
# coding: utf-8 while True: n, x = map(int, input().split()) comb = 0 if n == 0 and x == 0: exit() for i in range(1, n+1): for j in range(i+1, n+1): for k in range(j+1, n+1): # print('{} {} {}'.format(i, j, k)) if i + j + k == x: comb += 1 print(comb)
s217009362
p03351
u808569469
2,000
1,048,576
Wrong Answer
26
9,124
179
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) AB = abs(a - b) BC = abs(b - c) AC = abs(a - c) if AB < d and BC < d: print("Yes") elif AC < d: print("YES") else: print("No")
s798977119
Accepted
28
9,100
183
a, b, c, d = map(int, input().split()) AB = abs(a - b) BC = abs(b - c) AC = abs(a - c) if AC <= d: print("Yes") elif AB <= d and BC <= d: print("Yes") else: print("No")
s085980991
p03353
u191874006
2,000
1,048,576
Wrong Answer
36
4,880
192
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
#!usr/bin/env python3 s = input() K = int(input()) l = {s} for n in range(1, K+1): for i in range(0, len(s)-n+1): l.add(s[i:i+n]) print(l) l = list(l) l.sort() print(l[K-1])
s486640286
Accepted
45
6,128
673
#!/usr/bin/env python3 #ABC97 C import sys import math import bisect import time sys.setrecursionlimit(1000000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) f = defaultdict(lambda : 0) s = input() k = I() n = len(s) for i in range(1,k+1): for j in range(n-i+1): f[s[j:j+i]] = 1 f = sorted(f.items()) print(f[k-1][0])
s297786147
p03605
u419963262
2,000
262,144
Wrong Answer
19
3,188
44
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
print("YES")if "9"in input()else print("No")
s961567205
Accepted
18
2,940
45
print("Yes")if "9"in input()else print("No")
s909938734
p03962
u268516119
2,000
262,144
Wrong Answer
23
3,444
440
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
# coding: utf-8 # Your code here! import copy S=list(input()) N=len(S) point=0 hand=copy.deepcopy(S) panum=sum([j=="p" for j in hand]) pamax=N//2 for i in range(N): if S[i]=="g": pa=sum([hand[j]=="p" for j in range(i+1)]) if pa<(i+1)//2 and point<pamax-panum: hand[i]="p" point+=1 if point>=pamax-panum: break print(point)
s149802517
Accepted
17
2,940
106
abc=list(map(int,input().split())) d=[] for i in abc: if i not in d: d.append(i) print(len(d))
s353541041
p02608
u444398697
2,000
1,048,576
Wrong Answer
33
9,116
299
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
n = int(input()) ans = [0]*(n+5) for x in range(1,10): for y in range(1,10): for z in range(1,10): temp = x**2 + y**2 + z**2 + x*y + y*z + z*x if n>=temp: print(x,y,z, temp) ans[temp]+=1 for i in range(1,n+1): print(ans[i])
s483106838
Accepted
859
9,120
267
n = int(input()) ans = [0]*(n+5) for x in range(1,100): for y in range(1,100): for z in range(1,100): temp = x**2 + y**2 + z**2 + x*y + y*z + z*x if n>=temp: ans[temp]+=1 for i in range(1,n+1): print(ans[i])
s702726817
p02612
u968649733
2,000
1,048,576
Wrong Answer
31
9,144
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N % 1000)
s633283842
Accepted
32
9,152
75
N = int(input()) a = N % 1000 if a == 0: print(0) else: print(1000 - a)
s595564477
p03605
u261696185
2,000
262,144
Wrong Answer
30
8,980
70
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
X = str(input()) if '9' in X: print('YES') else: print('NO')
s647260030
Accepted
28
8,872
70
X = str(input()) if '9' in X: print('Yes') else: print('No')
s513917148
p03714
u826263061
2,000
262,144
Wrong Answer
370
38,292
539
Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
import heapq n = int(input()) a = list(map(int, input().split())) a1 = a[:n] ax = a[n:2*n] a2 = list(map(lambda x: -x, a[2*n:])) print('a2', a2) sum_a1 = sum(a1) fdif1 = [sum_a1] heapq.heapify(a1) for i in range(n): p = heapq.heappushpop(a1,ax[i]) fdif1.append(fdif1[-1]+ax[i]-p) sum_a2 = sum(a2) fdif2 = [sum_a2] heapq.heapify(a2) print('a2', a2) for i in range(n): p = heapq.heappushpop(a2,-ax[-1-i]) fdif2.append(fdif2[-1]-ax[-1-i]-p) fdif2.reverse() fdif = [fdif1[i]+fdif2[i] for i in range(n)] print(max(fdif))
s683760020
Accepted
347
38,276
543
import heapq n = int(input()) a = list(map(int, input().split())) a1 = a[:n] ax = a[n:2*n] a2 = list(map(lambda x: -x, a[2*n:])) #print('a2', a2) sum_a1 = sum(a1) fdif1 = [sum_a1] heapq.heapify(a1) for i in range(n): p = heapq.heappushpop(a1,ax[i]) fdif1.append(fdif1[-1]+ax[i]-p) sum_a2 = sum(a2) fdif2 = [sum_a2] heapq.heapify(a2) #print('a2', a2) for i in range(n): p = heapq.heappushpop(a2,-ax[-1-i]) fdif2.append(fdif2[-1]-ax[-1-i]-p) fdif2.reverse() fdif = [fdif1[i]+fdif2[i] for i in range(n+1)] print(max(fdif))
s170174378
p03523
u127499732
2,000
262,144
Wrong Answer
17
3,060
294
You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
def main(): s = str(input()) t = 'AKIHABARA' i = 0 j = 0 while i < len(t) and j < len(s): if t[i] == s[j]: i += 1 j += 1 else: i += 1 print('YES' if j == len(s) - 1 else 'NO') if __name__ == '__main__': main()
s280744996
Accepted
19
3,188
141
def main(): import re f = re.match('A?KIHA?BA?RA?$',input()) print('YES'if f else 'NO') if __name__ == '__main__': main()
s778511603
p03548
u847867174
2,000
262,144
Wrong Answer
21
3,316
229
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
def getNum(): x,y,z = map(int,input().split()) return x,y,z def cal(x,y,z): tmp = x / y / z if tmp < x: print(tmp) else: print(tmp - 1) def main(): x,y,z = getNum() cal(x,y,z) main()
s070279754
Accepted
17
2,940
186
def getNum(): x,y,z = map(int,input().split()) return x,y,z def cal(x,y,z): num = int((x-z) / (y+z)) print(num) def main(): x,y,z = getNum() cal(x,y,z) main()
s126715648
p03407
u569272329
2,000
262,144
Wrong Answer
17
2,940
88
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+B <= C: print("Yes") else: print("No")
s087879317
Accepted
17
2,940
90
A, B, C = map(int, input().split()) if A + B >= C: print("Yes") else: print("No")
s233472008
p02743
u045939752
2,000
1,048,576
Wrong Answer
17
2,940
129
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c = map(int, input().split()) ans = False if c-a-b >= 0 and a*b < (c-a-b)**2: ans = True print('Yes' if ans else 'No')
s291328886
Accepted
17
2,940
134
a,b,c = map(int, input().split()) ans = False if c-a-b >= 0 and 4*a*b < (c-a-b)**2: ans = True print('Yes' if ans else 'No')
s263412477
p02846
u693953100
2,000
1,048,576
Wrong Answer
17
3,064
393
Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows **towards the east** : * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. * Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact.
t1,t2 = map(int,input().split()) a1,a2 = map(int,input().split()) b1,b2 = map(int,input().split()) if a1*t1+a2*t2>=b1*t1+b2*t2: a1,a2,b1,b2 = b1,b2,a1,a2 d = b1*t1+b2*t2 - (a1*t1+a2*t2) print(d) if d == 0: print('inifinity') elif a1*t1<b1*t1: print(0) else: if (a1*t1 - b1*t1)*2%d ==0: print(((a1*t1 - b1*t1)*2+d-1)//d) else: print((a1*t1 - b1*t1)//d*2+1)
s812936939
Accepted
23
3,064
383
t1,t2 = map(int,input().split()) a1,a2 = map(int,input().split()) b1,b2 = map(int,input().split()) if a1*t1+a2*t2>=b1*t1+b2*t2: a1,a2,b1,b2 = b1,b2,a1,a2 d = b1*t1+b2*t2 - (a1*t1+a2*t2) if d == 0: print('infinity') elif a1*t1<b1*t1: print(0) else: if (a1*t1 - b1*t1)*2%d ==0: print(((a1*t1 - b1*t1)*2+d-1)//d) else: print((a1*t1 - b1*t1)//d*2+1)
s662024131
p03377
u941047297
2,000
262,144
Wrong Answer
17
2,940
106
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 = list(map(int, input().split())) if a >= x and x - a <= b: print('YES') else: print('NO')
s954152538
Accepted
17
2,940
106
a, b, x = list(map(int, input().split())) if a <= x and x - a <= b: print('YES') else: print('NO')
s373365829
p02612
u257265865
2,000
1,048,576
Wrong Answer
29
9,152
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n=int(input()) print(n%1000)
s410227464
Accepted
28
9,148
53
n=int(input()) print(1000-n%1000 if n%1000!=0 else 0)
s326386468
p03994
u221898645
2,000
262,144
Wrong Answer
234
5,620
326
Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string.
s = input() K = int(input()) a = [0] * len(s) for i in range(len(s)): a[i] = ((ord('z') - ord(s[i])) + 1)%26 if a[i] == 0: pass elif K - a[i] >= 0: K -= a[i] a[i] = 0 for i in range(len(s)-1): print(chr((26-a[i])%26+ord('a')), end = '') b = ord('a') + (ord(s[-1])-ord('a') + K)%26 print( chr( b ) )
s945428016
Accepted
240
5,620
367
s = input() K = int(input()) a = [0] * len(s) for i in range(len(s) - 1): a[i] = ((ord('z') - ord(s[i])) + 1)%26 if a[i] == 0: pass elif K - a[i] >= 0: K -= a[i] a[i] = 0 for i in range(len(s)-1): print(chr((26-a[i])%26+ord('a')), end = '') if K != 0: b = ord('a') + (ord(s[-1])-ord('a') + K)%26 print( chr( b ) ) else: print(s[-1])
s096542882
p03693
u434329006
2,000
262,144
Wrong Answer
17
2,940
122
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int,input().split()) answer = r*100 + g*10 + b if answer % 4 == 0: print("Yes") else: print("No")
s287413416
Accepted
17
2,940
122
r, g, b = map(int,input().split()) answer = r*100 + g*10 + b if answer % 4 == 0: print("YES") else: print("NO")
s475159723
p02399
u362104929
1,000
131,072
Wrong Answer
30
7,616
123
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)
numbers = [int(x) for x in input().split(" ")] a, b = numbers[0], numbers[1] print("{} {} {}".format((a//b), (a%b), (a/b)))
s419092947
Accepted
20
7,688
127
numbers = [int(x) for x in input().split(" ")] a, b = numbers[0], numbers[1] print("{} {} {:.5f}".format((a//b), (a%b), (a/b)))
s540116374
p03548
u672898046
2,000
262,144
Wrong Answer
17
2,940
65
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
x, y, z = map(int, input().split()) x -= z r = x / (y+z) print(r)
s502446628
Accepted
18
2,940
70
x, y, z = map(int, input().split()) x -= z r = x / (y+z) print(int(r))
s631107616
p02821
u562935282
2,000
1,048,576
Wrong Answer
1,555
23,632
1,163
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
def solve(n, m, a) -> int: from bisect import bisect_left, bisect_right from itertools import accumulate from collections import Counter *a, = sorted(a) acc = (0,) + tuple(accumulate(a)) c = Counter(a) def is_ok(h): ret = 0 for i, x in enumerate(a): j = bisect_left(a, h - x) ret += (n - j) * 2 if ret >= m * 2: return True return False def binary_search(): ok = 0 ng = a[-1] * 2 + 1 while abs(ng - ok) > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok min_pair_happiness = binary_search() ret = 0 for i, x in enumerate(a): j = bisect_left(a, min_pair_happiness - x) k = bisect_right(a, min_pair_happiness - x) ret += (n - j) * x + (acc[n] - acc[j]) if j != k: ret -= a[j] + x return ret def main(): n, m = map(int, input().split()) *a, = map(int, input().split()) print(solve(n, m, a)) if __name__ == '__main__': main()
s651194938
Accepted
851
14,268
1,832
def main(): N, M = map(int, input().split()) *a, = map(int, input().split()) a.sort() def count(mid) -> int: cnt = 0 j = N for i in range(N): while j > 0 and a[i] + a[j - 1] >= mid: j -= 1 # j==0 or a[i]+a[j]>=mid # j==0 cnt += N - j return cnt def binary_search(*, ok: int, ng: int, is_ok: 'function') -> int: while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok ma = binary_search(ok=2 * 10 ** 5 + 1, ng=0, is_ok=lambda mid: count(mid) < M) def accumulate(a): s = 0 yield s for x in a: s += x yield s *acc, = accumulate(a) ans = 0 j = N for i in range(N): while j > 0 and a[i] + a[j - 1] >= ma: j -= 1 ans += a[i] * (N - j) + acc[N] - acc[j] ans += (ma - 1) * (M - count(ma)) print(ans) if __name__ == '__main__': main()
s728761881
p03110
u270681687
2,000
1,048,576
Wrong Answer
17
2,940
180
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
n = int(input()) ans = 0 for i in range(n): x, u = input().split() if u == "JPY": ans += int(x) else: ans += int(float(x) * 380000 + 0.1) print(ans)
s929310157
Accepted
17
2,940
169
n = int(input()) ans = 0 for i in range(n): x, u = input().split() if u == "JPY": ans += int(x) else: ans += float(x) * 380000 print(ans)
s195276278
p03228
u288430479
2,000
1,048,576
Wrong Answer
26
9,056
194
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
a,b,k = map(int,input().split()) bit = 0 while k: if bit==0: if a%2!=0: a -= 1 b += a//2 a //= 2 else: if b!=0: b -= 1 a += b//2 b //2 k -= 1 print(a,b)
s328922000
Accepted
28
9,096
224
a,b,k = map(int,input().split()) bit = 0 while k: if bit==0: if a%2!=0: a -= 1 b += a//2 a //= 2 bit = 1 else: if b%2!=0: b -= 1 a += b//2 b //= 2 bit = 0 k -= 1 print(a,b)
s343079406
p03644
u092650292
2,000
262,144
Wrong Answer
17
2,940
107
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n = int(input()) maxnum = 2 for i in range(8): if maxnum > n: print(maxnum/2) break maxnum*=2
s317297231
Accepted
17
2,940
125
n = int(input()) maxnum = 2 for i in range(8): if maxnum > n: print(int(maxnum/2)) break maxnum*=2
s857062657
p03194
u887207211
2,000
1,048,576
Wrong Answer
2,104
3,064
379
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.
N, P = map(int,input().split()) n, p = N, P if(N == 1 or P == 1): print(P) exit() num = [] s = 0 while s == 0: for i in range(2,p+1): if(p%i == 0): p = int(p/i) if(p == 1): s = 1 num.append(i) break d = {} cnt = 1 for i in num: d[i] = num.count(i) for k, v in d.items(): if(v >= n): cnt *= k ** (v//n) print(k,v) print(cnt)
s769982129
Accepted
73
3,064
370
N, P = map(int,input().split()) def calc(n): num = {} e, i = 0, 2 while i**2 <= n: while n%i == 0: n //= i e += 1 if(e > 0): num[i] = e i += 1 e = 0 return num if(N == 1): print(P) exit() elif(P == 1): print(1) exit() else: cnt = 1 for k, v in calc(P).items(): if(v >= N): cnt *= k ** (v//N) print(cnt)
s207971765
p03943
u328755070
2,000
262,144
Wrong Answer
17
2,940
152
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a, b, c = list(map(int, input().split())) A = [a,b,c] A.sort() if A[0] == (A[1]+A[2]) or (A[0] + A[1]) == A[2]: print('YES') else: print('NO')
s655122494
Accepted
17
2,940
152
a, b, c = list(map(int, input().split())) A = [a,b,c] A.sort() if A[0] == (A[1]+A[2]) or (A[0] + A[1]) == A[2]: print('Yes') else: print('No')
s373383891
p02264
u255317651
1,000
131,072
Wrong Answer
20
5,616
960
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
# -*- coding: utf-8 -*- """ Created on Sun Apr 29 14:42:43 2018 @author: maezawa """ def print_array(g): ans = str(g[0]) if len(g) > 1: for i in range(1,len(g)): ans += ' '+str(g[i]) print(ans) name=[] time=[] n, q = list(map(int, input().split())) for i in range(n): s = input().split() name.append(s[0]) time.append(int(s[1])) # ============================================================================= # print(n,q) # print(name) # print(time) # ============================================================================= finished = [] i=0 remain = n while True: if time[i] == 0: i += 1 if i == n: i = 0 continue if time[i] <= q: finished.append(name[i]) time[i] = 0 remain -= 1 if remain == 0: break else: time[i] -= q i += 1 if i == n: i = 0 print_array(finished)
s231022932
Accepted
460
15,668
981
# -*- coding: utf-8 -*- def fifo_enque(data): global tail global fifo fifo[tail] = data tail = (tail+1)%fifo_size def fifo_deque(): global head global fifo data = fifo[head] head = (head+1)%fifo_size return data fifo_size = 100000 fifo = [0 for _ in range(fifo_size)] head = 0 tail = 0 n, q = list(map(int, input().split())) for i in range(n): s = input().split() data = [s[0], int(s[1])] fifo_enque(data) current_time = 0 finished = [] fin_time = [] while True: data = fifo_deque() if data[1] > q: current_time += q data[1] -= q fifo_enque(data) else: current_time += data[1] finished.append(data[0]) fin_time.append(current_time) if head == tail: break for i in range(n): print("{} {}".format(finished[i], fin_time[i]))
s580081558
p04043
u860819641
2,000
262,144
Wrong Answer
17
2,940
116
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
A=input().split() print(A) if A==["5","5","7"] or ["5","7","5"] or ["7","5","5"]: print("YES") else: print("NO")
s712920746
Accepted
17
2,940
113
A=input().split() if A==["5","5","7"] or A==["5","7","5"] or A==["7","5","5"]: print("YES") else: print("NO")
s007198186
p02853
u007886915
2,000
1,048,576
Wrong Answer
17
3,064
465
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
import math N = 1 x, y = [0]*N, [0]*N l = list(range(N)) sum=0 #print(x[0]) for i in range(N): x[i], y[i] = map(int, input().split()) if x[0] <= 3: sum=sum+10000*(4-x[0]) else: pass if y[0]<= 3: sum=sum+10000*(4-y[0]) else: pass if x[0]==1 and y[0]==1: sum=sum+40000 else: pass print(sum)
s953437817
Accepted
18
3,064
570
# -*- Coding: utf-8 -*- import itertools import math N = 1 x, y = [0]*N, [0]*N l = list(range(N)) sum=0 #print(x[0]) for i in range(N): x[i], y[i] = map(int, input().split()) if x[0] <= 3: sum=sum+100000*(4-x[0]) else: pass if y[0]<= 3: sum=sum+100000*(4-y[0]) else: pass if x[0]==1 and y[0]==1: sum=sum+400000 else: pass print(sum)
s918893895
p03854
u351363308
2,000
262,144
Wrong Answer
17
3,316
485
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`.
# coding: utf-8 # Your code here! S = input() while True: if len(S)!=0: if S[len(S)-7:len(S)]=="dreamer": S = S.rstrip("dreamer") elif S[len(S)-6:len(S)]=="eraser": S = S.rstrip("eraser") elif S[len(S)-5:len(S)]=="dream": S = S.rstrip("dream") elif S[len(S)-5:len(S)]=="erase": S = S.rstrip("erase") else: print("NO") break else: print("YES") break
s814863125
Accepted
80
3,188
467
# coding: utf-8 # Your code here! S = input() while True: if len(S)!=0: if S[len(S)-7:len(S)]=="dreamer": S = S[0:len(S)-7] elif S[len(S)-6:len(S)]=="eraser": S = S[0:len(S)-6] elif S[len(S)-5:len(S)]=="dream": S = S[0:len(S)-5] elif S[len(S)-5:len(S)]=="erase": S = S[0:len(S)-5] else: print("NO") break else: print("YES") break
s639720543
p04043
u763550415
2,000
262,144
Wrong Answer
28
9,044
92
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.
line = input() if line == '5 5 7' or line == '7 5 5': print('Yes') else: print('No')
s946495724
Accepted
25
8,796
112
line = input() if line == '5 5 7' or line == '5 7 5' or line == '7 5 5': print('YES') else: print('NO')
s598671436
p02612
u851704997
2,000
1,048,576
Wrong Answer
30
9,120
57
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) while(N>1000): N -= 1000 print(str(N))
s690922016
Accepted
29
9,136
94
N = int(input()) for i in range(20): if(N <= 1000): break N -= 1000 print(str(1000-N))
s256780634
p03371
u329407311
2,000
262,144
Wrong Answer
18
2,940
137
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A,B,C,X,Y=map(int,input().split()) ans1 = int(A*X + B*Y) ans2 = int(C*X + (Y-X)*B) ans3 = int(C*Y + (X-Y)*A) print(min(ans1,ans2,ans3))
s131587893
Accepted
17
3,060
243
A,B,C,X,Y=map(int,input().split()) ans1 = int(A*X + B*Y) if X<=Y: ans2 = int(C*2*X + (Y-X)*B) ans3 = 10**10 ans4 = int(2*Y*C) else: ans2 = 10**10 ans3 = int(C*2*Y + (X-Y)*A) ans4 = int(2*X*C) print(min(ans1,ans2,ans3,ans4))
s858287167
p03730
u432853936
2,000
262,144
Wrong Answer
17
2,940
154
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a,b,c = map(int,input().split()) for i in range(1,b+1): if (a * i) % b == c: print("Yes") exit() print("No")
s378751771
Accepted
17
2,940
154
a,b,c = map(int,input().split()) for i in range(1,b+1): if (a * i) % b == c: print("YES") exit() print("NO")
s635372806
p03024
u203669169
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() if 8 <= 15 - len(s) + s.count("o"): print("Yes") else: print("No")
s359260796
Accepted
17
2,940
85
s=input() if 8 <= 15 - len(s) + s.count("o"): print("YES") else: print("NO")
s684126507
p02409
u797673668
1,000
131,072
Wrong Answer
30
7,752
246
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.
house = [[[0] * 10 for _ in range(3)] for __ in range(4)] n = int(input()) while n: b, f, r, v = map(int, input().split()) house[b - 1][f - 1][r - 1] += v n -= 1 for b in house: for f in b: print(*f) print('#' * 20)
s967283866
Accepted
30
7,736
305
house = [[[0] * 10 for _ in range(3)] for __ in range(4)] n = int(input()) while n: b, f, r, v = map(int, input().split()) house[b - 1][f - 1][r - 1] += v n -= 1 for i, b in enumerate(house): for f in b: print(' ', end='') print(*f) if i < 3: print('#' * 20)
s480904016
p03672
u503052349
2,000
262,144
Wrong Answer
19
3,064
349
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
c=0 i=0 list1=[] list2=[] S = input('') char_list = list(S) c = len (char_list) c= c-1 print(c) while c>1: if c % 2 == 0: d=int(c/2) print (d) for i in range(d): list1.append(char_list[i]) list2.append(char_list[i+d]) print (list1) print(list2) if list1 == list2: print (len (list1)) break list1=[] list2=[] c=c-1
s867413360
Accepted
19
3,064
355
c=0 i=0 list1=[] list2=[] S = input('') char_list = list(S) c = len (char_list) c= c-1 #print(c) while c>1: if c % 2 == 0: d=int(c/2) #print (d) for i in range(d): list1.append(char_list[i]) list2.append(char_list[i+d]) #print (list1) #print(list2) if list1 == list2: print (len (list1)*2) break list1=[] list2=[] c=c-1
s070236483
p02402
u476441153
1,000
131,072
Wrong Answer
30
7,576
120
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
n = int(input()) a = [0] * n print (n) a = list(map(int, input().split())) print (min(a)) print (max(a)) print (sum(a))
s399201897
Accepted
60
8,740
93
n = int(input()) a = [0] * n a = list(map(int, input().split())) print (min(a),max(a),sum(a))
s910327543
p02742
u952484541
2,000
1,048,576
Wrong Answer
17
3,060
276
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:
import sys n = list(map(int, input().split())) if n[0] % 2 == 0: print((n[0]*n[1])/2) sys.exit() else: if n[1] % 2 == 0: print((n[0]*n[1])/2) sys.exit() else: b = int((n[0]*n[1])/2) print((n[0]*n[1])-b) sys.exit()
s520972068
Accepted
35
5,076
422
from decimal import Decimal import sys n = list(map(int, input().split())) if n[0] == 1 or n[1] == 1: print(1) sys.exit() if n[0] % 2 == 0: print(Decimal(int((n[0]/2)*n[1]))) sys.exit() else: if n[1] % 2 == 0: print(Decimal(int(n[0]*(n[1]/2)))) sys.exit() else: a = ((n[0]-1)*n[1])/2 b = n[1] - int(n[1]/2) print(Decimal(int(a+b))) sys.exit()
s563127070
p03605
u374671031
2,000
262,144
Wrong Answer
17
2,940
64
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
n = input() if "9" in n : print("YES") else: print("NO")
s653325390
Accepted
18
2,940
64
n = input() if "9" in n : print("Yes") else: print("No")
s985753299
p02263
u996463517
1,000
131,072
Wrong Answer
20
5,556
197
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
a = input().split() b = [] for i in a: if i.isdigit(): b.append(i) else: c = b.pop() d = b.pop() ans = eval(str(d)+i+str(c)) b.append(ans) print(b)
s018003055
Accepted
20
5,568
200
a = input().split() b = [] for i in a: if i.isdigit(): b.append(i) else: c = b.pop() d = b.pop() ans = eval(str(d)+i+str(c)) b.append(ans) print(b[0])
s080725899
p03759
u627691992
2,000
262,144
Wrong Answer
26
9,024
85
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c = map(int, input().split()) if(b-a == c-b): print("Yes") else: print("No")
s153450502
Accepted
26
9,072
96
a, b, c = map(int, input().split()) if b - a == c - b: print("YES") else: print("NO")
s825940998
p03494
u886878171
2,000
262,144
Time Limit Exceeded
2,104
2,940
291
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N = input() A = list(map(int,input().split())) count = 0 exist_odd = False while (exist_odd == False): for x in A: x = int(x) if x % 2 != 0: exist_odd = True if exist_odd == True: break else: for x in A: x /= 2 count += 1 print(count)
s104994894
Accepted
28
9,160
269
N = int(input()) A = list(map(int,input().split())) count = 0 flag = True while(flag): for i in range(N): if A[i] % 2 == 0: A[i] = A[i]/2 else: flag = False break if flag == True: count+=1 print(count)
s386921534
p02612
u533232830
2,000
1,048,576
Wrong Answer
35
9,152
72
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) i = 0 while i*1000<=n: i += 1 print(n-(i-1)*1000)
s660457231
Accepted
28
9,152
69
n = int(input()) i = 0 while i*1000<n: i += 1 print((i)*1000-n)
s158154795
p03477
u350093546
2,000
262,144
Wrong Answer
17
2,940
116
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d=map(int,input().split()) if a+b>c+d: print('Left') if a+b==c+d: print('Balanced') else: print('Right')
s887854836
Accepted
18
2,940
135
a,b,c,d=map(int,input().split()) if (a+b)>(c+d): print('Left') if (a+b)==(c+d): print('Balanced') if (a+b)<(c+d): print('Right')
s764851762
p03635
u474423089
2,000
262,144
Wrong Answer
17
2,940
117
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
def main(): n,m=map(int,input().split(' ')) print((n-1)*(m-1)) if __name__ == '__main__': print(main())
s373642965
Accepted
17
2,940
110
def main(): n,m=map(int,input().split(' ')) print((n-1)*(m-1)) if __name__ == '__main__': main()
s972385140
p02408
u501414488
1,000
131,072
Wrong Answer
30
6,720
366
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
cards = { 'S': [0 for _ in range(13)], 'H': [0 for _ in range(13)], 'C': [0 for _ in range(13)], 'D': [0 for _ in range(13)], } n = int(input()) for _ in range(n): (s, r) = input().split() cards[s][int(r) - 1] = 1 for _ in ('S', 'H', 'C', 'D'): for r in range(13): if cards[s][r] == 0: print(s, r + 1)
s869760692
Accepted
30
6,724
366
cards = { 'S': [0 for _ in range(13)], 'H': [0 for _ in range(13)], 'C': [0 for _ in range(13)], 'D': [0 for _ in range(13)], } n = int(input()) for _ in range(n): (s, r) = input().split() cards[s][int(r) - 1] = 1 for s in ('S', 'H', 'C', 'D'): for r in range(13): if cards[s][r] == 0: print(s, r + 1)
s724205415
p03435
u048004795
2,000
262,144
Wrong Answer
28
9,136
624
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
import sys input = sys.stdin.readline #N #t1 x1 y1t1 x1 y1 #t2 x2 y2t2 x2 y2 #tN xN yNtN xN yN N = 3 x = [0 for i in range(N)] y = [0 for i in range(N)] c =[[0 for i in range(N)] for i in range(N)] for i in range(N): c1, c2, c3 = map(int, input().split()) c[i][0] = c1 c[i][1] = c2 c[i][2] = c3 x[0] = 0 for i in range(N): y[i] = c[0][i] - x[0] x[1] = c[1][0] - y[1] x[2] = c[2][0] - y[2] flag = True for i in range(N): for j in range(N): numx = x[i] numy = y[j] if not numx + numy == c[i][j]: flag = False if flag: print("Yes") else: print("No")
s624867636
Accepted
29
9,184
623
import sys input = sys.stdin.readline #N #t1 x1 y1t1 x1 y1 #t2 x2 y2t2 x2 y2 #tN xN yNtN xN yN N = 3 x = [0 for i in range(N)] y = [0 for i in range(N)] c =[[0 for i in range(N)] for i in range(N)] for i in range(N): c1, c2, c3 = map(int, input().split()) c[i][0] = c1 c[i][1] = c2 c[i][2] = c3 x[0] = 0 for i in range(N): y[i] = c[0][i] - x[0] x[1] = c[1][0] - y[0] x[2] = c[2][0] - y[0] flag = True for i in range(N): for j in range(N): numx = x[i] numy = y[j] if not numx + numy == c[i][j]: flag = False if flag: print("Yes") else: print("No")
s761528725
p02409
u327972099
1,000
131,072
Wrong Answer
30
6,724
512
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()) count = 0 room = [int(0) for i in range(4) for j in range(3) for k in range(10)] while count < n: x = list(map(lambda k: int(k), input().split(" "))) room[(x[0]-1)*30+(x[1]-1)*10+(x[2]-1)] += x[3] count += 1 for i in range(4): for j in range(3): for k in range(10): if k == 0: print("%d" % room[30*i+10*j+k], end="") else: print(" %d" % room[30*i+10*j+k], end="") print("") print("####################")
s084884123
Accepted
40
6,724
430
n = int(input()) count = 0 room = [int(0) for i in range(4) for j in range(3) for k in range(10)] while count < n: x = list(map(lambda k: int(k), input().split(" "))) room[(x[0]-1)*30+(x[1]-1)*10+(x[2]-1)] += x[3] count += 1 for i in range(4): if i != 0: print("####################") for j in range(3): for k in range(10): print(" %d" % room[30*i+10*j+k], end="") print("")
s808809629
p03547
u088974156
2,000
262,144
Wrong Answer
17
2,940
99
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`. When X and Y are seen as hexadecimal numbers, which is larger?
x,y=input().split() if(x<y): print(x+"<"+y) elif (x==y): print(x+"="+y) else: print(x+">"+y)
s571551378
Accepted
17
2,940
87
x,y=input().split() if(x<y): print("<") elif (x==y): print("=") else: print(">")
s430707681
p03407
u177756077
2,000
262,144
Wrong Answer
21
3,316
80
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+B<=C: print("Yes") else: print("No")
s449442314
Accepted
18
2,940
80
A,B,C=map(int,input().split()) if A+B>=C: print("Yes") else: print("No")
s580672110
p03795
u920438243
2,000
262,144
Wrong Answer
17
2,940
102
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n = int(input()) power = 1 for i in range(1,n+1): power += i%(10**9+7) print(power % (10**9 + 7))
s784791691
Accepted
18
2,940
42
n = int(input()) print(n*800-(n//15)*200)
s662125312
p03555
u882359130
2,000
262,144
Wrong Answer
17
2,940
113
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
C1 = [c1 for c1 in input()] C2 = [c2 for c2 in input()] if C1 == reversed(C2): print("YES") else: print("NO")
s383376714
Accepted
17
3,064
116
C1 = [c1 for c1 in input()] C2 = [c2 for c2 in input()] C2.reverse() if C1 == C2: print("YES") else: print("NO")
s659854156
p03360
u727821695
2,000
262,144
Wrong Answer
17
2,940
98
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
li = list(map(int, input().split())) K = int(input()) li.sort print (li[0] + li[1] + li[2] ** K)
s526135133
Accepted
17
2,940
110
li = list(map(int, input().split())) K = int(input()) print (li[0] + li[1] + li[2] + max(li) * (2 ** K - 1))
s701309807
p04043
u179285430
2,000
262,144
Wrong Answer
17
2,940
96
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a = list(map(int, input().split())) if a.sort() == [5, 5, 7]: print("YES") else: print("NO")
s547176366
Accepted
17
2,940
102
I = list(map(int, input().split())) I.sort() if I == [5, 5, 7]: print("YES") else: print("NO")
s846219485
p03854
u388323466
2,000
262,144
Wrong Answer
21
3,956
302
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 = list(input()) s.reverse() s=''.join(s) arr = ['dream', 'dreamer', 'erase', 'eraser'] tmp = [] arr2 = [] for i in range(4): tmp += list(arr[i]) tmp.reverse() arr2.append(''.join(tmp)) tmp = [] for y in arr2: if y in s: s = s.replace(y,'') if s =='': print('Yes') else: print('No')
s092836134
Accepted
69
3,188
370
s = input() while len(s)>4: if s[-5:] == 'dream': s = s[:-5] continue elif s[-7:] == 'dreamer': s = s[:-7] continue elif s[-5:] == 'erase': s = s[:-5] continue elif s[-6:] == 'eraser': s = s[:-6] continue else: break if len(s)>0 : print('NO') else: print('YES')
s416602364
p03448
u231189826
2,000
262,144
Wrong Answer
50
3,060
236
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for i in range(A+1): for j in range(B+1): for K in range(C+1): if A*500 + B*100 + C*50 == X: count += 1 print(count)
s658078142
Accepted
50
3,060
236
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if i*500 + j*100 + k*50 == X: count += 1 print(count)
s463728270
p02614
u970308980
1,000
1,048,576
Wrong Answer
61
9,092
442
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
H, W, K = map(int, input().split()) C = [] for i in range(H): c = list(input().strip()) C.append(c) ans = 0 for h in range(1 << H): for w in range(1 << W): cnt = 0 for i in range(H): for j in range(W): if h >> i & 1: continue if w >> j & 1: continue cnt += 1 if cnt == K: ans += 1 print(ans)
s934109939
Accepted
64
9,104
481
H, W, K = map(int, input().split()) C = [] for i in range(H): c = list(input().strip()) C.append(c) ans = 0 for h in range(1 << H): for w in range(1 << W): cnt = 0 for i in range(H): for j in range(W): if h >> i & 1: continue if w >> j & 1: continue if C[i][j] == "#": cnt += 1 if cnt == K: ans += 1 print(ans)
s541787317
p03455
u548076391
2,000
262,144
Wrong Answer
17
2,940
98
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()) sum = a+b if sum % 2 ==0: print("Even") else: print("Odd")
s506749811
Accepted
17
2,940
96
a, b = map(int,input().split()) cal = a*b if cal % 2 == 0: print("Even") else: print("Odd")
s985795051
p02936
u096616343
2,000
1,048,576
Wrong Answer
2,107
61,256
527
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
from heapq import heappop,heappush N,Q = map(int,input().split()) route = [[] for _ in range(N)] ans = [0] * N for i in range(N - 1): a,b = map(int,input().split()) route[a - 1].append(b) route[b - 1].append(a) for i in range(Q): p,x = map(int,input().split()) ans[p - 1] = x W = [(0,1)] A = [1] * N while W: de,nod = heappop(W) A[nod - 1] = 0 for i in route[nod - 1]: if A[i - 1] == 1: heappush(W,(de + 1,i)) ans[i - 1] += ans[nod - 1] for j in ans: print(j)
s133255695
Accepted
1,996
64,352
513
from heapq import heappop,heappush N,Q = map(int,input().split()) route = [[] for _ in range(N)] ans = [0] * N for i in range(N - 1): a,b = map(int,input().split()) route[a - 1].append(b) route[b - 1].append(a) for i in range(Q): p,x = map(int,input().split()) ans[p - 1] += x W = [(0,1)] A = [1] * N while W: de,nod = heappop(W) A[nod - 1] = 0 for i in route[nod - 1]: if A[i - 1] == 1: heappush(W,(de + 1,i)) ans[i - 1] += ans[nod - 1] print(*ans)
s920456218
p02646
u362031378
2,000
1,048,576
Wrong Answer
19
9,180
169
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) if v>w: c=(b-a)/(v-w) if t>=c: print('Yes') else: print('No') else: print('No')
s710582604
Accepted
23
9,120
181
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) gap=abs(a-b) if v>w: c=(v-w)*t if gap<=c: print('YES') else: print('NO') else: print('NO')
s731439509
p02606
u173151534
2,000
1,048,576
Wrong Answer
29
9,148
105
How many multiples of d are there among the integers between L and R (inclusive)?
L, R, d = (int(x) for x in input().split()) a = L // d b = R // d if R % d == 0: b += 1 print(b - a)
s450341028
Accepted
31
8,936
105
L, R, d = (int(x) for x in input().split()) a = L // d b = R // d if L % d == 0: b += 1 print(b - a)
s251550269
p03607
u171366497
2,000
262,144
Wrong Answer
259
15,460
180
You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?
N=int(input()) from collections import defaultdict d=defaultdict(int) for i in range(N): d[int(input())]+=1 cnt=1 for a in d.keys(): if d[a]%2==1: cnt+=1 print(cnt)
s041805223
Accepted
258
15,456
180
N=int(input()) from collections import defaultdict d=defaultdict(int) for i in range(N): d[int(input())]+=1 cnt=0 for a in d.keys(): if d[a]%2==1: cnt+=1 print(cnt)