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
s158665749
p03607
u811000506
2,000
262,144
Wrong Answer
230
7,452
224
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()) A = [int(input()) for i in range(N)] A.sort() ans = 0 tmp = A[0] count = 1 for i in range(1,N): if tmp!=A[i]: if count%2==0: ans += 1 count = 0 tmp = A[i] print(ans)
s802829879
Accepted
238
21,244
181
import collections as co N = int(input()) A = [int(input()) for i in range(N)] c = co.Counter(A) count = 0 for a,b in c.most_common(): if b%2==1: count += 1 print(count)
s708985966
p03386
u440478998
2,000
262,144
Wrong Answer
2,282
2,247,856
110
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a,b,k = map(int, input().split()) l = [l for l in range(a,b+1)] l = set(l[:k]+l[-k:]) for i in l: print(i)
s596970614
Accepted
28
9,188
166
a,b,k = map(int, input().split()) l = [i for i in range(a,min(b,a+k))] l = l + [i for i in range(max(a,b-k+1),b+1)] l = list(set(l)) l.sort() for i in l: print(i)
s550516507
p03660
u075012704
2,000
262,144
Wrong Answer
223
32,152
285
Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
N = int(input()) Roads = [] for i in range(N-1): Roads.append(input().split()) black = 0 black_list = [] white = 0 white_list = [] for i in Roads: if 1 in i: black += 1 if N in i: white += 1 if black > white : print("Fennec") else: print("Snuke")
s094515885
Accepted
1,099
54,940
774
import heapq N = int(input()) T = [[] for i in range(N)] for i in range(N - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 T[a].append([b, 1]) T[b].append([a, 1]) def dijkstra(x): d = [float('inf')] * N d[x] = 0 visited = {x} # d, u hq = [(0, x)] while hq: u = heapq.heappop(hq)[1] visited.add(u) for node, cost in T[u]: if (node not in visited) and d[node] > d[u] + cost: d[node] = d[u] + cost heapq.heappush(hq, (d[u]+cost, node)) return d Black = dijkstra(0) White = dijkstra(N - 1) Black_point = 0 for b, w in zip(Black, White): if b <= w: Black_point += 1 if Black_point > N // 2: print('Fennec') else: print('Snuke')
s381038978
p02742
u406546804
2,000
1,048,576
Wrong Answer
17
2,940
107
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 math a,b=map(int, input().split()) if a*b%2 == 0: print(a*b/2) else: print(math.floor(a*b/2)+1)
s790269401
Accepted
17
3,060
156
import math a,b=map(int, input().split()) if a==1 or b==1: print(1) elif a*b%2 == 0: print(int(a*b/2)) elif a*b%2 == 1: print(int(math.floor(a*b/2+1)))
s398341147
p03455
u750651325
2,000
262,144
Wrong Answer
37
10,024
500
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 a,b = I() ans = a*b print(ans)
s738344113
Accepted
35
9,872
546
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 a,b = I() ans = a*b if ans % 2== 0: print("Even") else: print("Odd")
s236638169
p02388
u498511622
1,000
131,072
Wrong Answer
20
7,524
42
Write a program which calculates the cube of a given integer x.
x=int(input("????????\???")) print(x ** 3)
s986130252
Accepted
20
7,648
27
x=int(input()) print (x**3)
s071397602
p02678
u631019293
2,000
1,048,576
Wrong Answer
2,206
34,812
556
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.
import queue n,m = map(int, input().split()) routs = [[] for i in range(n + 1)] for i in range(m): a, b = map(int,input().split()) routs[a].append(b) routs[b].append(a) parent = [-1] * (n-1) visit = ["yet"]*(n) visit[0] = "done" q = queue.Queue() q.put(1) while -1 in parent: temp = q.get() for i in routs[temp]: if visit[i-1] == "yet": q.put(i) if parent[i-2] == -1: parent[i-2] = temp visit[i-1] = "done" print("a") print("Yes") for i in parent: print(i)
s226957513
Accepted
1,071
35,000
542
import queue n,m = map(int, input().split()) routs = [[] for i in range(n + 1)] for i in range(m): a, b = map(int,input().split()) routs[a].append(b) routs[b].append(a) parent = [-1] * (n-1) visit = ["yet"]*(n) visit[0] = "done" q = queue.Queue() q.put(1) while not q.empty(): temp = q.get() for i in routs[temp]: if visit[i-1] == "yet": q.put(i) if parent[i-2] == -1: parent[i-2] = temp visit[i-1] = "done" print("Yes") for i in parent: print(i)
s634755167
p03469
u095396110
2,000
262,144
Wrong Answer
31
8,992
61
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
S = input() S_modified = S.replace('7','8') print(S_modified)
s864076448
Accepted
34
9,104
42
ss = input() print(ss[:3] + '8' + ss[4:])
s381679914
p03999
u697615293
2,000
262,144
Wrong Answer
32
9,212
363
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
s = input() l = len(s) ans = 0 for i in range(2 ** (l -1)): ans_sub = 0 subst = s[0] for j in range(l-1): if(i>j)&1: ans_sub += int(subst) subst = s[j+1] else: subst += s[j+1] if j ==l-2: ans_sub += int(subst) ans += ans_sub if l == 1: print(int(s)) else: print(ans)
s097047815
Accepted
29
9,096
176
def dfs(i,f): if i == s-1: return sum(map(int,f.split("+"))) return dfs(i+1,f + n[i+1]) + dfs(i+1 , f+ "+" + n[i+1]) n = input() s = len(n) print(dfs(0,n[0]))
s438960851
p02601
u135265051
2,000
1,048,576
Wrong Answer
28
9,184
218
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
a = list(map(int,input().split())) #b = list(map(int,input().split())) b=int(input()) for i in range(b): a[a.index(min(a))]= 2*(a[a.index(min(a))]) print(a) if a[0]<a[1]<a[2]: print("Yes") else: print("No")
s499650971
Accepted
31
9,108
245
a = list(map(int,input().split())) #b = list(map(int,input().split())) b=int(input()) for i in range(b): if a[2]<=a[1]: a[2]=2*a[2] elif a[1]<=a[0]: a[1]=2*a[1] if a[0]<a[1]<a[2]: print("Yes") else: print("No")
s590370032
p03731
u185948224
2,000
262,144
Wrong Answer
155
26,836
144
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())) X = 0 for i in range(N-1): X += min((t[i+1]-t[i]), T) print(X+7)
s220601270
Accepted
147
25,200
144
N, T = map(int,input().split()) t = list(map(int,input().split())) X = 0 for i in range(N-1): X += min((t[i+1]-t[i]), T) print(X+T)
s116436234
p03636
u508405635
2,000
262,144
Wrong Answer
17
2,940
32
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(len(s[1:-1]))
s807432141
Accepted
17
2,940
52
s = input() print(s[0] + str(len(s[1:-1])) + s[-1])
s256388587
p03836
u001024152
2,000
262,144
Wrong Answer
32
4,976
1,510
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) visited = set([(sx, sy)]) steps = abs(sx - tx) + abs(sy - ty) ans = "" pos = (sx, sy) for i in range(steps): if pos[1] == ty: ans += "R" pos = (pos[0]+1, pos[1]) else: ans += "U" pos = (pos[0], pos[1]+1) visited.add(pos) visited.remove((sx, sy)) for i in range(steps): next_pos = (pos[0]-1, pos[1]) if pos[1] == sy and next_pos not in visited: ans += "L" pos = (pos[0]-1, pos[1]) else: ans += "D" pos = (pos[0], pos[1]-1) visited.add(pos) ans += "L" pos = (pos[0]-1, pos[1]) visited.add(pos) visited.remove((tx, ty)) for i in range(steps*2): next_pos = (pos[0]+1, pos[1]) if pos == (tx, ty+1): ans += "D" pos = (pos[0], pos[1]-1) break else: if next_pos not in visited: ans += "R" pos = (pos[0]+1, pos[1]) else: ans += "U" pos = (pos[0], pos[1]+1) visited.add(pos) ans += "R" pos = (pos[0]+1, pos[1]) visited.add(pos) visited.remove((sx, sy)) for i in range(steps*2): next_pos = (pos[0]-1, pos[1]) if pos == (sx, sy-1): ans += "U" pos = (pos[0], pos[1]+1) break else: if next_pos not in visited: ans += "L" pos = (pos[0]-1, pos[1]) else: ans += "D" pos = (pos[0], pos[1]-1) visited.add(pos) print(ans) # print(visited)
s820482445
Accepted
17
3,060
322
sx, sy, tx, ty = map(int, input().split()) dx = tx - sx dy = ty - sy ans = '' # s to t ans += 'U' * dy ans += 'R' * dx # t to s ans += 'D' * dy ans += 'L' * (dx+1) # s tp t part2 ans += 'U' * (dy+1) ans += 'R' * (dx+1) ans += 'D' # t to s part2 ans += 'R' ans += 'D' * (dy+1) ans += 'L' * (dx+1) ans += 'U' print(ans)
s315479114
p03471
u225528554
2,000
262,144
Wrong Answer
19
3,064
508
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
def main(): l = list(map(int,input().split(" "))) N = l[0] Y = l[1] c1 = 0 c2 = 0 c3 = 0 if Y>=N*10000 or Y<=N*1000: print(-1,-1,-1) while c1<=N: tar1 = Y-N*10000 while c2<=N-c1: tar2 = tar1-c2*5000 while c3<=N-c1-c2: tar3 = tar2-c3*1000 if tar3==0: print(c1,c2,c3) c3+=1 c2+=1 c1+=1 print(-1,-1,-1) if __name__=="__main__": main()
s315948420
Accepted
565
3,188
520
def main(): l = list(map(int,input().split(" "))) N = l[0] Y = l[1] c1 = N c2 = 0 c3 = 0 if Y>N*10000 or Y<N*1000: print(-1,-1,-1) exit() while c1>=0: tar1 = Y-c1*10000 c2 = N-c1 while c2>=0: tar2 = tar1-c2*5000 c3 = N-c2-c1 tar3 = tar2-c3*1000 if tar3==0: print(c1,c2,c3) exit() c2-=1 c1-=1 print(-1,-1,-1) if __name__=="__main__": main()
s226156523
p03469
u964998676
2,000
262,144
Wrong Answer
17
2,940
73
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
date = input('') sub_date = date[4:-1] print('2018/{0}'.format(sub_date))
s738469875
Accepted
17
2,940
71
date = input('') sub_date = date[4:] print('2018{0}'.format(sub_date))
s831553340
p03696
u606174760
2,000
262,144
Wrong Answer
17
3,064
397
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
# -*- coding: utf-8 -*- import sys N = input() S = input() res = '' lit = S.split(')(') for i, l in enumerate(lit): kakko = l + ')' if i % 2 == 0 else '(' + l right, left = 0, 0 for k in kakko: if k == '(': left += 1 else: right += 1 part = '('*(right-left) + kakko if right > left else kakko + ')'*(left-right) res += part print(res)
s040650475
Accepted
19
3,188
352
# -*- coding: utf-8 -*- import sys, re N = input() S = input() sentence = '' left, right = 0, 0 for s in S: sentence += s if s == '(': left += 1 else: right += 1 if left - right < 0: sentence = '(' + sentence left += 1 if left - right > 0: sentence = sentence + ')' * (left - right) print(sentence)
s782491833
p03378
u095756391
2,000
262,144
Wrong Answer
17
3,060
165
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
N, M, X = map(int, input().split()) A = list(map(int, input().split())) l = A[:X] r = A[X+1:] ans = [] ans.append(len(l)-1) ans.append(len(r)-1) print(min(ans))
s883160594
Accepted
17
3,060
236
N, M, X = map(int, input().split()) A = list(map(int, input().split())) ans = [] c = 0 for i in range(N): if i == X: ans.append(c) c = 0 continue if i in A: c += 1 if i == N-1: ans.append(c) print(min(ans))
s243926178
p03339
u623052494
2,000
1,048,576
Wrong Answer
108
3,700
176
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
N=int(input()) S=str(input()) ans=S[1:].count('E') cnt=ans for i in range(1,N): if S[i-1]=='W': cnt+=1 if S[i]=='E': cnt-=1 print(min(ans,cnt))
s437787817
Accepted
194
3,676
179
N=int(input()) S=input() ans=S[1:].count('E') cnt=ans for i in range(1,N): if S[i-1]=='W': cnt+=1 if S[i]=='E': cnt-=1 ans=min(ans,cnt) print(ans)
s131567694
p03494
u305534505
2,000
262,144
Wrong Answer
19
2,940
228
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.
def main(): N = int(input()) num = list(map(int, input().split())) counter = [0] * N for j in range(N): while num[j]%2==0: num[j] = num[j]/2 counter[j] += 1 print(min(counter))
s079306494
Accepted
19
2,940
236
def main(): N = int(input()) num = list(map(int, input().split())) counter = [0] * N for j in range(N): while num[j]%2==0: num[j] = num[j]/2 counter[j] += 1 print(min(counter)) main()
s586621189
p03997
u223663729
2,000
262,144
Wrong Answer
19
2,940
59
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, b, h = map(int, open(0).read().split()) print((a+b)*h/2)
s118009574
Accepted
17
2,940
60
a, b, h = map(int, open(0).read().split()) print((a+b)*h//2)
s477218247
p00017
u244742296
1,000
131,072
Wrong Answer
40
6,724
420
In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 1, 'a' would be replaced by 'b', 'b' would become 'c', 'y' would become 'z', 'z' would become 'a', and so on. In that case, a text: this is a pen is would become: uijt jt b qfo Write a program which reads a text encrypted by Caesar Chipher and prints the corresponding decoded text. The number of shift is secret and it depends on datasets, but you can assume that the decoded text includes any of the following words: "the", "this", or "that".
import string import sys str = input() alpha = string.ascii_lowercase for str in sys.stdin: for i in range(len(alpha)): cipher_str = "" for s in str: if s in alpha: cipher_str += alpha[(alpha.index(s)+i) % len(alpha)] else: cipher_str += s if ("the" or "this" or "that") in cipher_str: print(cipher_str) break
s877627081
Accepted
30
6,720
480
import string import sys alpha = string.ascii_lowercase for line in sys.stdin: for i in range(len(alpha)): cipher_str = "" for s in line: if s in alpha: cipher_str += alpha[(alpha.index(s)+i) % len(alpha)] else: cipher_str += s if "the" in cipher_str or "this" in cipher_str or "that" in cipher_str: print(cipher_str, end="") break else: print(line, end="")
s280512910
p02694
u112083029
2,000
1,048,576
Wrong Answer
30
9,132
56
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()) a = 100 i = 1/100 print(x/(a**1/100))
s200861425
Accepted
33
9,136
90
x = int(input()) a = 100 i = 0 while a < x: i += 1 a += a // 100 print(i)
s676542053
p03545
u296101474
2,000
262,144
Wrong Answer
17
3,064
288
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.
nums = input() n = 4 def calc(i, f, sum): if i == n-1: print(f+'=7') exit() return sum == 7 else: calc(i+1, f + '-' + nums[i+1], sum - int(nums[i+1])) calc(i+1, f + '+' + nums[i+1], sum + int(nums[i])) calc(0, nums[0], int(nums[0]))
s166288182
Accepted
17
3,060
293
nums = input() n = 4 def calc(i, f, sum): if i == n-1: if sum == 7: print(f+'=7') exit() else: calc(i+1, f + '-' + nums[i+1], sum - int(nums[i+1])) calc(i+1, f + '+' + nums[i+1], sum + int(nums[i+1])) calc(0, nums[0], int(nums[0]))
s904978020
p04045
u474561976
2,000
262,144
Wrong Answer
27
9,092
466
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.
def main(): n,k = map(int,input().split()) D = list(map(int,input().split())) num = [x for x in range(10) if x not in D] ans = [] while n > 0: x = n%10 n //= 10 flag = True for i in range(len(num)): if x <= num[i]: flag = False ans.append(num[i]) break if flag: ans.append(num[0]) print("".join(map(str,ans[::-1])))
s276032799
Accepted
78
9,180
482
import io,sys sys.setrecursionlimit(10**6) def main(): n,k = map(int,input().split()) D = list(map(int,input().split())) while True: temp = n num = [] while temp > 0: num.append(temp%10) temp//=10 flag = True for i in num: if i in D: flag = False break if flag: print(n) sys.exit() else: n+=1 main()
s052646824
p03090
u201234972
2,000
1,048,576
Wrong Answer
23
3,632
410
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
N = int( input()) if N == 3: print(1,3) print(2,3) else: s = N%2 N = N//2*2 print(1, N-1) print(1,2) print(2,N) print(N-1,N) for i in range(2,N//2): for j in range(1,i+1): print(j, i+1) print(j, N-i) print(N+1-j, i+1) print(N+1-j, N-i) if s == 1 and N != 2: for i in range(1,N+1): print(i, N+1)
s485514451
Accepted
24
3,632
554
N = int( input()) if N == 3: print(2) print(1,3) print(2,3) else: s = N%2 N = N//2*2 ans = 0 for i in range(2,N//2+1): ans += 4*i - 4 if s == 0: print(ans) else: print(ans+N) print(1, N-1) print(1,2) print(2,N) print(N-1,N) for i in range(2,N//2): for j in range(1,i+1): print(j, i+1) print(j, N-i) print(N+1-j, i+1) print(N+1-j, N-i) if s == 1 and N != 2: for i in range(1,N+1): print(i, N+1)
s901849737
p03997
u218984487
2,000
262,144
Wrong Answer
17
2,940
84
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()) ans = (a + b) * h / 2 print(ans)
s241575534
Accepted
17
2,940
107
import math a = int(input()) b = int(input()) h = int(input()) ans = (a + b) * h / 2 print(math.ceil(ans))
s464920897
p03659
u003873207
2,000
262,144
Wrong Answer
200
24,824
243
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
N = int(input()) A = list(map(int, input().split())) rui = [0] * N rui[0] = A[0] for it in range(1, N): rui[it] = rui[it - 1] + A[it] ans = 1145141919810 for i in range(1, N): ans = min(rui[i], rui[N - 1] - rui[i]) print(ans)
s025550280
Accepted
224
23,792
254
N = int(input()) A = list(map(int, input().split())) rui = [0] * N rui[0] = A[0] for it in range(1, N): rui[it] = rui[it - 1] + A[it] ans = 1145141919810 for i in range(0, N - 1): ans = min(abs(rui[i] - rui[N - 1] + rui[i]), ans) print(ans)
s175904642
p03557
u462329577
2,000
262,144
Wrong Answer
1,593
29,308
1,211
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
#!/usr/bin/env python3 n = int(input()) k = [list(map(int,input().split())) for _ in range(3)] cnt = [[0] * n for _ in range(2)] a = sorted(k[0]) b = sorted(k[1]) c = sorted(k[2]) for i in range(n): l = -1 r = n while r-l > 1: k = (l+r)//2 if b[i] > a[k]: l = k else: r = k cnt[0][i] = l+1 l = -1 r = n while r-l > 1: k = (l+r)//2 if b[i] < c[k]: r = k else: l = k cnt[1][i] = n-r print(cnt) ans = 0 for i in range(n): ans += cnt[0][i]*cnt[1][i] print(ans)
s392079803
Accepted
1,635
26,352
1,212
#!/usr/bin/env python3 n = int(input()) k = [list(map(int,input().split())) for _ in range(3)] cnt = [[0] * n for _ in range(2)] a = sorted(k[0]) b = sorted(k[1]) c = sorted(k[2]) for i in range(n): l = -1 r = n while r-l > 1: k = (l+r)//2 if b[i] > a[k]: l = k else: r = k cnt[0][i] = l+1 l = -1 r = n while r-l > 1: k = (l+r)//2 if b[i] < c[k]: r = k else: l = k cnt[1][i] = n-r ans = 0 for i in range(n): ans += cnt[0][i]*cnt[1][i] print(ans)
s932584847
p03798
u596276291
2,000
262,144
Wrong Answer
244
5,484
905
Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
from collections import defaultdict def ok(l, s): for i in range(len(s) * 2): now = i % len(l) pre = now - 1 nex = (now + 1) % len(l) if (l[now] == -1 and s[now] == 'x') or (l[now] == 1 and s[now] == 'o'): if l[nex] is None: l[nex] = l[pre] else: if l[nex] != l[pre]: return False else: if l[nex] is None: l[nex] = -1 * l[pre] else: if l[nex] != -1 * l[pre]: return False return True def main(): N = int(input()) s = input() for x in [(-1, -1), (-1, 1), (1, -1), (1, 1)]: l = [None] * N l[-1], l[0] = x[0], x[1] if ok(l, s): print("".join(['w' if x == -1 else 's' for x in l])) return print(-1) if __name__ == '__main__': main()
s124831354
Accepted
200
7,896
1,493
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def ok(last, first, S): N = len(S) ans = [None] * N ans[-1], ans[0] = last, first for i in range(N): if ans[i] == 0: if S[i] == "o": nex = ans[i - 1] else: nex = 1 - ans[i - 1] else: if S[i] == "o": nex = 1 - ans[i - 1] else: nex = ans[i - 1] if ans[(i + 1) % N] is None: ans[(i + 1) % N] = nex else: if ans[(i + 1) % N] != nex: return None return ans def main(): N = int(input()) S = input() for l, f in [(0, 0), (0, 1), (1, 0), (1, 1)]: ans = ok(l, f, S) if ans is not None: print(*["S" if v == 0 else "W" for v in ans], sep="") return print(-1) if __name__ == '__main__': main()
s673293872
p03371
u492532572
2,000
262,144
Wrong Answer
17
3,060
173
"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(" ")) p1 = A * X + B * Y p2 = C * min(X, Y) p3 = p2 if X > Y: p3 += (X - Y) * A else: p3 += (Y - X) * B print(min(p1, p2, p3))
s111315949
Accepted
17
3,060
192
A, B, C, X, Y = map(int, input().split(" ")) p1 = A * X + B * Y p2 = C * min(X, Y) * 2 if X > Y: p2 += (X - Y) * A else: p2 += (Y - X) * B p3 = C * max(X, Y) * 2 print(min(p1, p2, p3))
s295706846
p03478
u992519990
2,000
262,144
Wrong Answer
35
3,412
281
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
def findSomeofDigits(x): s = 0 while x > 0: s = s + x % 10 x = x // 10 return s N,A,B = map(int,input().split()) c = 0 for i in range(N): s = findSomeofDigits(i+1) if A <= s and s <= B: print(i + 1) c = c + i + 1 print(c)
s198698386
Accepted
26
2,940
266
def findSomeofDigits(x): s = 0 while x > 0: s = s + x % 10 x = x // 10 return s N,A,B = map(int,input().split()) c = 0 for i in range(N): s = findSomeofDigits(i+1) if A <= s and s <= B: c = c + i + 1 print(c)
s344821228
p00002
u914007790
1,000
131,072
Time Limit Exceeded
40,000
7,772
192
Write a program which computes the digit number of sum of two integers a and b.
import math lst = [] while True: try: a, b = map(int, input().split()) lst.append(int(math.log(10, a+b))+1) except EOFError: for i in lst: print(i)
s218757999
Accepted
20
7,644
204
import math lst = [] while True: try: a, b = map(int, input().split()) lst.append(int(math.log10(a+b))+1) except EOFError: for i in lst: print(i) break
s094396074
p02928
u773065853
2,000
1,048,576
Wrong Answer
705
3,188
390
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
data = input().split(" ") n = int(data[0]) k = int(data[1]) a = list(map(int, input().split(" "))) print(a) left = 0 right = 0 for i in range(0, n): for j in range(0, i): if a[j] < a[i]: left += 1 for j in range(i+1, n): if a[j] < a[i]: right += 1 rt = ((k + 1) * k // 2) % 1000000007 lt = ((k - 1) * k // 2) % 1000000007 ans = (right * rt + left * lt) % 1000000007 print(ans)
s930166180
Accepted
724
3,188
381
data = input().split(" ") n = int(data[0]) k = int(data[1]) a = list(map(int, input().split(" "))) left = 0 right = 0 for i in range(0, n): for j in range(0, i): if a[j] < a[i]: left += 1 for j in range(i+1, n): if a[j] < a[i]: right += 1 rt = ((k + 1) * k // 2) % 1000000007 lt = ((k - 1) * k // 2) % 1000000007 ans = (right * rt + left * lt) % 1000000007 print(ans)
s553523860
p02646
u621509924
2,000
1,048,576
Wrong Answer
23
9,180
205
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 W >= V: print('No') else: if (V-W)*T >= max(A,B) - min(A,B): print('Yes') else: print('No')
s339914469
Accepted
24
9,184
205
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if W >= V: print('NO') else: if (V-W)*T >= max(A,B) - min(A,B): print('YES') else: print('NO')
s136314371
p02608
u609814378
2,000
1,048,576
Wrong Answer
438
9,436
290
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]*((10**4)+1) for x in range(1,101): for y in range(1,101): for z in range(1,101): num = x * x + y * y + z * z + x * y + y * z + z * x if num <= N: ans[num] = ans[num] + 1 for i in range(N+1): print(ans[i])
s883726637
Accepted
449
9,272
290
N = int(input()) ans = [0]*((10**4)+1) for x in range(1,101): for y in range(1,101): for z in range(1,101): num = x * x + y * y + z * z + x * y + y * z + z * x if num <= N: ans[num] = ans[num] + 1 for i in range(N): print(ans[i+1])
s498415231
p02972
u023229441
2,000
1,048,576
Wrong Answer
237
14,128
226
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
n=int(input()) A=list(map(int,input().split()))[::-1] B=[0]*n for i in range(n): k=n-i if A[i]!=(B[k-1::k].count(1))%2: B[k-1]=1 print(B.count(1)) P=[[i for i, x in enumerate(B) if x ==1]] print(*P[0])
s879939033
Accepted
191
13,508
233
n=int(input()) A=list(map(int,input().split())) B=[0 for i in range(n)] B[n//2:]=A[n//2:] for i in range(n//2,0,-1): B[i-1]= (sum(B[i*2-1::i])%2 != A[i-1]) print(sum(B)) for i,j in enumerate(B): if j==1: print(i+1)
s433636482
p02690
u488884575
2,000
1,048,576
Wrong Answer
35
9,316
286
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
x = int(input()) d= {} for a in range(10**25): print(a,d) a5 = a**5 b5 = a5-x if b5 in d: print(a,d[b5]) exit() d[a5] = a print('--------------',a,d) a5 = -a5 b5 = a5-x if b5 in d: print(a,d[b5]) exit() d[a5] = -a
s083250857
Accepted
29
9,088
291
x = int(input()) d= {} for a in range(10**25): #print(a,d) a5 = a**5 b5 = a5-x if b5 in d: print(a,d[b5]) exit() d[a5] = a #print('--------------',a,d) a5 = -a5 b5 = a5-x if b5 in d: print(a,d[b5]) exit() d[a5] = -a
s356227125
p03598
u026537738
2,000
262,144
Wrong Answer
18
3,060
123
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
N = int(input()) K = int(input()) X = list(map(int,input().split(" "))) print(sum([min([X[i], K-X[i]]) for i in range(N)]))
s365752867
Accepted
18
3,060
127
N = int(input()) K = int(input()) X = list(map(int,input().split(" "))) print(2 * sum([min([X[i], K-X[i]]) for i in range(N)]))
s738939810
p03139
u534384028
2,000
1,048,576
Wrong Answer
17
2,940
191
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.
input_line=[int(x) for x in input().split()] [i_N,i_A,i_B]=input_line if i_A>=i_B: o_max=i_B o_min=i_B-(i_N-i_A) else: o_max=i_A o_min=i_A-(i_N-i_B) print("{} {}".format(o_max,o_min))
s698951419
Accepted
17
3,064
239
input_line=[int(x) for x in input().split()] [i_N,i_A,i_B]=input_line if i_A>=i_B: o_max=i_B o_min=i_B-(i_N-i_A) else: o_max=i_A o_min=i_A-(i_N-i_B) if o_min<0: o_min=0 if o_max>i_N: o_max=i_N print("{} {}".format(o_max,o_min))
s362584165
p03415
u960513073
2,000
262,144
Wrong Answer
18
2,940
66
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
c1 = input() c2 = input() c3 = input() print(c1[0], c2[1], c3[2])
s835729825
Accepted
18
2,940
64
c1 = input() c2 = input() c3 = input() print(c1[0]+c2[1]+c3[2])
s244941753
p02743
u152402277
2,000
1,048,576
Wrong Answer
18
2,940
145
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c = (int(x) for x in input().split()) if c - a - b <= 0: print("No") else: if 2*a*b <(c-a-b)**2: print("Yes") else: print("No")
s559150572
Accepted
18
2,940
145
a,b,c = (int(x) for x in input().split()) if c - a - b <= 0: print("No") else: if 4*a*b <(c-a-b)**2: print("Yes") else: print("No")
s391160516
p02690
u307592354
2,000
1,048,576
Wrong Answer
23
9,180
293
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
def resolve(): X= int(input()) nums = dict() for A in range(10**4): nums[A**5] = A nums[-A**5] = A if A**5 - X in nums: print(A,nums[A**5-X]) return if __name__ == "__main__": resolve() #unittest.main()
s203143670
Accepted
22
9,176
273
def resolve(): X= int(input()) nums = dict() for A in range(10**4): nums[A**5] = A nums[-A**5] = -A if A**5 - X in nums: print(A,nums[A**5-X]) break if __name__ == "__main__": resolve()
s201649266
p03434
u912650255
2,000
262,144
Wrong Answer
18
3,064
230
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 = int(input()) card = list(map(int,input().split())) sorted_card = sorted(card) Alice = 0 Bob = 0 for i in range(N): if i % 2 == 0: Alice += sorted_card[i] else: Bob += sorted_card[i] print(Alice - Bob)
s146294519
Accepted
17
3,060
253
N = int(input()) card = list(map(int,input().split())) sorted_card = sorted(card,reverse=True) Alice = 0 Bob = 0 for i in range(N): if i == 0 or i % 2 == 0: Alice += sorted_card[i] else: Bob += sorted_card[i] print(Alice - Bob)
s814041381
p03795
u434872492
2,000
262,144
Wrong Answer
17
2,940
54
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N=int(input()) x=N*800 y=200*(N%15) ans=x-y print(ans)
s451649167
Accepted
17
2,940
74
N=int(input()) x=N*800 y=0 if N>=15: y=200*(N//15) ans=x-y print(ans)
s462145625
p03435
u766566560
2,000
262,144
Wrong Answer
17
3,060
230
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.
# ans c = [list(map(int, input().split())) for _ in range(3)] for i in range(2): for j in range(2): if c[i][j] - c[i][j+1] == c[i+1][j] - c[i+1][j+1]: pass else: print('NO') exit() print('YES')
s397746693
Accepted
17
3,060
230
# ans c = [list(map(int, input().split())) for _ in range(3)] for i in range(2): for j in range(2): if c[i][j] - c[i][j+1] == c[i+1][j] - c[i+1][j+1]: pass else: print('No') exit() print('Yes')
s273792712
p04043
u629709614
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, B, C = input().split() MC = [A, B, C] if MC.count("5")==2: print("Yes") else: print("No")
s124410757
Accepted
17
2,940
123
A, B, C = map(int, input().split()) MC = [A, B, C] if MC.count(5)==2 and MC.count(7)==1: print("YES") else: print("NO")
s887290466
p03759
u883232818
2,000
262,144
Wrong Answer
17
2,940
95
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')
s703639097
Accepted
17
2,940
94
a, b, c = map(int, input().split()) if b - a == c - b: print('YES') else: print('NO')
s300689720
p03378
u136395536
2,000
262,144
Wrong Answer
17
3,064
475
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
N,M,X = (int(i) for i in input().split()) places = input() placelistchar = places.split(" ") placelist = [] for k in range(M): placelist.append(int(placelistchar[k])) print(placelist) countbig = 0 countsmall = 0 #i = 5 for i in range(X+1,N): if (i in placelist == True): countbig = countbig +1 for j in range(0,X): if (j in placelist == True): countsmall = countsmall + 1 print(min(countsmall,countbig))
s659063079
Accepted
17
3,064
365
N,M,X = (int(i) for i in input().split()) places = input() placelistchar = places.split(" ") placelist = [] for k in range(M): placelist.append(int(placelistchar[k])) countbig = 0 countsmall = 0 for i in range(0,N): if(i in placelist): if i<X: countsmall += 1 else: countbig += 1 print(min(countsmall,countbig))
s381259114
p04043
u071868443
2,000
262,144
Wrong Answer
17
2,940
150
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a, b, c = map(int, input().split()) length = [len(str(a)), len(str(b)), len(str(c))].sort() if length == [5, 5, 7]: print("Yes") else: print("No")
s103848985
Accepted
17
2,940
131
a, b, c = map(int, input().split()) lengths = [a, b, c] lengths.sort() if lengths == [5, 5, 7]: print("YES") else: print("NO")
s846866793
p03400
u857673087
2,000
262,144
Wrong Answer
31
9,068
143
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
n = int(input()) d,x = map(int,input().split()) a = [int(input()) for _ in range(n)] sum = x for i in range(n): sum += d/a[i] print(sum)
s309196334
Accepted
29
9,080
195
n = int(input()) d,x = map(int,input().split()) a = [int(input()) for _ in range(n)] sum = x for i in range(n): if d%a[i] == 0: sum += d//a[i] else: sum += d//a[i] +1 print(sum)
s328489080
p02422
u780342333
1,000
131,072
Wrong Answer
30
7,608
405
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
s = input() line = int(input()) for i in range(line): param = input().split(" ") if len(param) == 4: ope, a, b, p = param else: ope, a, b = param a,b = int(a), int(b) if ope == "print": print(s[a:b+1]) elif ope == "reverse": rev = s[a:b+1][::-1] print(rev) s = (s[:a] + rev + s[b+1:]) elif ope == "replace": s = (s[:a] + p + s[b+1:])
s876236530
Accepted
20
5,628
474
s = input() n = int(input()) for _ in range(n): line = input().split() command = line[0] if command == 'replace': start, end = int(line[1]), int(line[2]) s = s[:start] + line[3] + s[end+1:] elif command == 'reverse': start, end = int(line[1]), int(line[2]) s = s[:start] + s[start:end+1][::-1] + s[end+1:] elif command == 'print': start, end = int(line[1]), int(line[2]) print(f"{s[start:end+1]}")
s399545115
p03494
u040887183
2,000
262,144
Wrong Answer
19
3,060
218
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 = [int(n) for n in input().split()] count = 0 def can(array): C = len(list( filter( lambda i: i % 2 == 1, array ) )) return C == 0 while can(A): A = [n / 2 for n in A] count += 1
s629953488
Accepted
19
3,060
231
N = input() A = [int(n) for n in input().split()] count = 0 def can(array): C = len(list( filter( lambda i: i % 2 == 1, array ) )) return C == 0 while can(A): A = [n / 2 for n in A] count += 1 print(count)
s446376296
p04029
u594956556
2,000
262,144
Wrong Answer
17
2,940
34
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)
s731471085
Accepted
18
2,940
35
N = int(input()) print(N*(N+1)//2)
s905508573
p02743
u607685130
2,000
1,048,576
Wrong Answer
153
12,484
210
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
import numpy as np a, b, c = input().split() a = int(a) b = int(b) c = int(c) left = np.sqrt(a) + np.sqrt(b) print(left) right = np.sqrt(c) print(right) if(left < right): print("Yes") else: print("No")
s292108719
Accepted
152
12,508
240
import numpy as np a, b, c = input().split() a = int(a) b = int(b) c = int(c) left = 4 * a * b right = (c - (a + b)) ** 2 judge = c - (a + b) if(judge < 0): print("No") else: if(left < right): print("Yes") else: print("No")
s783741696
p02842
u254871849
2,000
1,048,576
Wrong Answer
17
2,940
231
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
import sys from math import ceil, floor def main(): n = int(sys.stdin.readline().rstrip()) x = ceil(n * 1.08) if floor(x * 1.08) == n: print(x) else: print(':(') if __name__ == '__main__': main()
s538220970
Accepted
17
3,060
299
import sys from math import ceil def main(): n = int(sys.stdin.readline().rstrip()) x = ceil(n / 1.08) res = [] while x * 27 // 25 == n: res.append(x) x += 1 if res: print(res[0]) else: print(':(') if __name__ == '__main__': main()
s851792902
p03761
u668503853
2,000
262,144
Wrong Answer
34
3,316
330
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
import collections n=int(input()) f={} for i in range(n): S=input() c=collections.Counter(S) for j in range(len(c)): x=c.most_common()[j][0] y=c.most_common()[j][1] if i==0: f.setdefault(x,y) try: if f[x]>y: f[x]=y except: pass A=sorted(f) li=[a*f[a] for a in A] print("".join(li))
s168589665
Accepted
73
3,316
429
import collections n=int(input()) f={} for i in range(n): S=input() s=list(S) c=collections.Counter(S) for j in range(len(c)): x=c.most_common()[j][0] y=c.most_common()[j][1] if i==0: f.setdefault(x,y) else: for k in f.keys(): if k not in s: f[k]=0 else: if f[k]>s.count(k): f[k]=s.count(k) A=sorted(f) li=[a*f[a] for a in A] print("".join(li))
s858489587
p02602
u317423698
2,000
1,048,576
Wrong Answer
130
28,168
424
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.
import sys import itertools def resolve(in_, out): n, k = map(int, next(in_).split()) a = tuple(map(int, next(in_).split())) b, c = itertools.tee(a) c = itertools.islice(c, k, None) for v, w in zip(b, c): s = 'Yes' if v < w else 'No' print(s, file=out) def main(): answer = resolve(sys.stdin.buffer, sys.stdout) print(answer) if __name__ == '__main__': main()
s933990997
Accepted
132
28,200
397
import sys import itertools def resolve(in_, out): n, k = map(int, next(in_).split()) a = tuple(map(int, next(in_).split())) b, c = itertools.tee(a) c = itertools.islice(c, k, None) for v, w in zip(b, c): s = 'Yes' if v < w else 'No' print(s, file=out) def main(): resolve(sys.stdin.buffer, sys.stdout) if __name__ == '__main__': main()
s910286976
p02669
u044220565
2,000
1,048,576
Wrong Answer
213
11,888
2,411
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #import numpy as np #from copy import deepcopy #from collections import deque def run(): T = int(input()) for ii in range(T): N, A, B, C, D = map(int, input().split()) stack = [(0, N)] min_num = float('inf') visited = {} while stack: money, current = heappop(stack) if current in visited.keys(): continue visited[current] = 0 if current == 0:break for pro, cost in ((2, A), (3, B), (5, C)): tmp = current % pro next_num1 = (current - tmp)//pro next_num2 = (current + pro - tmp)//pro if pro == 2: heappush(stack, (min(cost, D * next_num1) + tmp * D + money, next_num1)) if next_num2 != tmp and (not next_num2 % 3 or not next_num2 % 5): heappush(stack, (min((2 - tmp) * D + cost + money, (next_num2 - tmp) * D + money), next_num2)) elif pro == 3: heappush(stack, (min(cost, D * (2 * next_num1))+ tmp * D + money, next_num1)) if next_num2 != tmp and (not next_num2 % 2 or not next_num2 % 5): heappush(stack, (min((3 - tmp) * D + cost + money, (2 * next_num2 - tmp) * D + money), next_num2)) else: heappush(stack, (min(cost, D * (4 * next_num1))+ tmp * D + money, next_num1)) if next_num2 != tmp and (not next_num2 % 2 or not next_num2 % 3): heappush(stack, (min((5 - tmp) * D + cost + money, (4 * next_num2 - tmp) * D + money), next_num2)) #if next_num1 < min_num: # heappush(stack, (min(cost, D * ((pro-1) * next_num1))+ tmp * D + money, next_num1)) #if next_num2 < min_num and (pro - 1) * next_num2 != tmp and current < 5: print(money) if __name__ == "__main__": run()
s751387433
Accepted
302
12,768
2,512
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #import numpy as np #from copy import deepcopy #from collections import deque def run(): T = int(input()) for ii in range(T): N, A, B, C, D = map(int, input().split()) stack = [(0, N)] min_num = float('inf') visited = {} while stack: money, current = heappop(stack) if current > N:continue if current in visited.keys(): continue visited[current] = 0 if current == 0:break for pro, cost in ((2, A), (3, B), (5, C)): tmp = current % pro next_num1 = (current - tmp)//pro next_num2 = (current + pro - tmp)//pro cond1 = N >= current + pro - tmp if pro == 2: heappush(stack, (min(cost, D * next_num1) + tmp * D + money, next_num1)) if next_num2 != tmp:# and (not next_num2 % 3 or not next_num2 % 5): heappush(stack, (min((2 - tmp) * D + cost + money, (next_num2 - tmp) * D + money), next_num2)) elif pro == 3: heappush(stack, (min(cost, D * (2 * next_num1))+ tmp * D + money, next_num1)) #if 2 * next_num2 != tmp:# and (not next_num2 % 2 or not next_num2 % 5): heappush(stack, (min((3 - tmp) * D + cost + money, (2 * next_num2 - 3 + tmp) * D + money), next_num2)) else: heappush(stack, (min(cost, D * (4 * next_num1))+ tmp * D + money, next_num1)) #if 4 * next_num2 != tmp:# and (not next_num2 % 2 or not next_num2 % 3): heappush(stack, (min((5 - tmp) * D + cost + money, (4 * next_num2 - 5 + tmp) * D + money), next_num2)) #if next_num1 < min_num: # heappush(stack, (min(cost, D * ((pro-1) * next_num1))+ tmp * D + money, next_num1)) #if next_num2 < min_num and (pro - 1) * next_num2 != tmp and current < 5: print(money) if __name__ == "__main__": run()
s532227399
p03861
u353652911
2,000
262,144
Wrong Answer
19
2,940
52
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x=map(int,input().split()) print((b+1)//x-a//x)
s625343623
Accepted
18
2,940
52
a,b,x=map(int,input().split()) print(b//x-(a-1)//x)
s271987540
p03970
u941438707
2,000
262,144
Wrong Answer
17
2,940
68
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
s=input();print(sum("CODEFESTIVAL2016"[i]==s[i] for i in range(16)))
s074934404
Accepted
18
2,940
68
s=input();print(sum("CODEFESTIVAL2016"[i]!=s[i] for i in range(16)))
s643260089
p02240
u404682284
1,000
131,072
Wrong Answer
20
5,604
778
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
import sys input_lines = [[int(i) for i in line.split()] for line in sys.stdin.read().splitlines()] [user_num, rel_num] = input_lines[0] rel_list = input_lines[1:rel_num+1] ques_num = input_lines[rel_num+1][0] ques_list = input_lines[rel_num+2:] color_list = [-1] * user_num adja_list = [set() for i in range(user_num)] def dfs(id, color): if color_list[id] == -1: color_list[id] = color for a_id in adja_list[id]: dfs(a_id, color) for rel in rel_list: adja_list[rel[0]].add(rel[1]) adja_list[rel[1]].add(rel[0]) color = 0 for id in range(user_num): print(color_list) dfs(id, color) color += 1 for ques in ques_list: if color_list[ques[0]] == color_list[ques[1]]: print('yes') else: print('no')
s009232926
Accepted
570
153,876
786
import sys sys.setrecursionlimit(200000) input_lines = [[int(i) for i in line.split()] for line in sys.stdin.read().splitlines()] [user_num, rel_num] = input_lines[0] rel_list = input_lines[1:rel_num+1] ques_num = input_lines[rel_num+1][0] ques_list = input_lines[rel_num+2:] color_list = [-1] * user_num adja_list = [set() for i in range(user_num)] def dfs(id, color): if color_list[id] == -1: color_list[id] = color for a_id in adja_list[id]: dfs(a_id, color) for rel in rel_list: adja_list[rel[0]].add(rel[1]) adja_list[rel[1]].add(rel[0]) color = 0 for id in range(user_num): dfs(id, color) color += 1 for ques in ques_list: if color_list[ques[0]] == color_list[ques[1]]: print('yes') else: print('no')
s411946884
p03370
u329143273
2,000
262,144
Wrong Answer
17
2,940
104
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
n,x=map(int,input().split()) m=list(map(int,input().split())) ans=n ans+=((x-sum(m))//min(m)) print(ans)
s716318421
Accepted
18
2,940
106
n,x=map(int,input().split()) m=[int(input()) for _ in range(n)] ans=n ans+=((x-sum(m))//min(m)) print(ans)
s236422823
p03671
u488934106
2,000
262,144
Wrong Answer
17
2,940
191
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.
def miner(a): a.sort ans = int(a[-1]) + int(a[-2]) return ans def main(): a = list(map(int , input().split())) print(miner(a)) if __name__ == '__main__': main()
s678558893
Accepted
18
2,940
191
def miner(a): a.sort() ans = int(a[0]) + int(a[1]) return ans def main(): a = list(map(int , input().split())) print(miner(a)) if __name__ == '__main__': main()
s151404297
p03929
u875361824
1,000
262,144
Wrong Answer
1,056
6,924
437
Snuke has a very long calendar. It has a grid with $n$ rows and $7$ columns. One day, he noticed that calendar has a following regularity. * The cell at the $i$-th row and $j$-th column contains the integer $7i+j-7$. A good sub-grid is a $3 \times 3$ sub-grid and the sum of integers in this sub-grid mod $11$ is $k$. How many good sub-grid are there? Write a program and help him.
def main(): n, k = map(int, input().split()) part1(n, k) def part1(n, k): ans = 0 for i in range(1, n-3+2): for j in range(1, n-3+2): s = 0 for x in range(3): for y in range(3): s += 7*(i+x) + (j+y) - 7 print(i, j, s, sep="\t") if s % 11 == k: ans += 1 print(ans) if __name__ == '__main__': main()
s654079898
Accepted
18
3,064
2,881
def main(): n, k = map(int, input().split()) # part1(n, k) # f2(n, k) editorial(n, k) def f2(n, k): table = [] for i in range(2, 2+11): table.append( [(7*i + j - 7) * 9 % 11 for j in range(2, 6+1)] ) n -= 2 ans = n // 11 * 5 x = n % 11 for i in range(x): for j in range(5): if table[i][j] == k: ans += 1 print(ans) def editorial(n, k): ans = 0 for j in range(2, 6+1): rownum = 0 for i in range(2, n): s = (i * 7 + j - 7) * 9 if s % 11 == k: rownum = i break if rownum == 0: continue ans += 1 ans += (n - 1 - rownum) // 11 print(ans) def part1(n, k): ans = 0 for i in range(1, n-3+2): for j in range(1, 5+1): s = 0 for y in range(3): for x in range(3): s += 7*(i+y) + (j+x) - 7 # print(i, j, s, sep="\t") if s % 11 == k: ans += 1 print(ans) if __name__ == '__main__': main()
s000171216
p03555
u845937249
2,000
262,144
Wrong Answer
17
2,940
131
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a = input() b = input() c = list(a) d = list(b) if c[0]==d[2] and c[1]==d[1] and c[2]==d[0]: print('Yes') else: print('No')
s182557010
Accepted
17
3,064
131
a = input() b = input() c = list(a) d = list(b) if c[0]==d[2] and c[1]==d[1] and c[2]==d[0]: print('YES') else: print('NO')
s167268845
p03795
u387456967
2,000
262,144
Wrong Answer
17
2,940
59
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n = int(input()) x = n*800 y = n%15*200 ans=x-y print(ans)
s870238358
Accepted
17
2,940
62
n = int(input()) x = n*800 y = (n//15)*200 ans=x-y print(ans)
s469976447
p03471
u169501420
2,000
262,144
Wrong Answer
17
2,940
222
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
# -*- coding: utf-8 -*- [X, Y] = [int(i) for i in input().split()] gift = [X] now = X while (True): new = 2 * now if new <= Y: gift.append(new) now = new else: break print(len(gift))
s613944954
Accepted
17
3,064
2,538
# -*- coding: utf-8 -*- import sys def calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number): return N - (ten_thousand_number + five_thousand_number + one_thousand_number) def print_answer(ten_thousand_number, five_thousand_number, one_thousand_number): print(str(ten_thousand_number) + ' ' + str(five_thousand_number) + ' ' + str(one_thousand_number)) [N, Y] = [int(i) for i in input().split()] now_amount = Y five_thousand_number = 0 one_thousand_number = 0 ten_thousand_number = now_amount // 10000 now_amount = now_amount % 10000 five_thousand_number = now_amount // 5000 now_amount = now_amount % 5000 one_thousand_number = now_amount // 1000 now_amount = now_amount % 1000 difference = calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number) if difference < 0: print('-1 -1 -1') sys.exit() if difference == 0: print_answer(ten_thousand_number, five_thousand_number, one_thousand_number) sys.exit() ten_thousand_cut = difference // 9 actual_ten_thousand_cut = min(ten_thousand_cut, ten_thousand_number) ten_thousand_number -= actual_ten_thousand_cut one_thousand_number += actual_ten_thousand_cut * 10 difference = calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number) if difference == 0: print_answer(ten_thousand_number, five_thousand_number, one_thousand_number) sys.exit() five_thousand_cut = difference // 4 actual_five_thousand_cut = min(five_thousand_cut, five_thousand_number) five_thousand_number -= actual_five_thousand_cut one_thousand_number += actual_five_thousand_cut * 5 difference = calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number) if difference == 0: print_answer(ten_thousand_number, five_thousand_number, one_thousand_number) sys.exit() ten_thousand_cut = difference // 1 actual_ten_thousand_cut = min(ten_thousand_cut, ten_thousand_number) ten_thousand_number -= actual_ten_thousand_cut five_thousand_number += actual_ten_thousand_cut * 2 difference = calc_difference(N, ten_thousand_number, five_thousand_number, one_thousand_number) if difference == 0: print_answer(ten_thousand_number, five_thousand_number, one_thousand_number) sys.exit() print('-1 -1 -1')
s600708723
p02255
u591232952
1,000
131,072
Wrong Answer
20
7,588
253
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.
def insertionSort(A,N): for i,v in enumerate(A): j = i-1 while j>=0 and A[j] > v: A[j+1] = A[j] j-=1 A[j+1] = v print(A) N = int(input()) A = list(map(int, input().split())) insertionSort(A,N)
s111086278
Accepted
20
7,636
273
def insertionSort(A,N): for i,v in enumerate(A): j = i-1 while j>=0 and A[j] > v: A[j+1] = A[j] j-=1 A[j+1] = v print(' '.join(map(str, A))) N = int(input()) A = list(map(int, input().split())) insertionSort(A,N)
s144857337
p03478
u648679668
2,000
262,144
Wrong Answer
37
3,060
133
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split()) ans = 0 for i in range(n+1): a <= sum(list(map(int, list(str(i))))) <= b ans += i print(ans)
s039274003
Accepted
36
3,060
144
n, a, b = map(int, input().split()) ans = 0 for i in range(n+1): if a <= sum(list(map(int, list(str(i))))) <= b: ans += i print(ans)
s750148164
p02690
u208309047
2,000
1,048,576
Wrong Answer
83
9,056
148
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
X = int(input()) for i in range(-177,177): for j in range(-177,177): if ((i**5)-(j**5) == X): print(i,j) break
s373144285
Accepted
111
9,100
174
X = int(input()) for i in range(-178,178): for j in range(-178,178): if ((i**5)-(j**5) == X): A = i B = j break print(A,B)
s095970624
p03023
u374584942
2,000
1,048,576
Wrong Answer
18
2,940
32
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
n=int(input()) print((n-2)/180)
s211142466
Accepted
17
2,940
33
n=int(input()) print((n-2)*180)
s871556608
p03673
u814781830
2,000
262,144
Wrong Answer
2,104
26,184
112
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 = list(map(int, input().split())) b = [] for i in a: b.append(i) b = b[::-1] print(b)
s233030533
Accepted
229
26,360
250
N = int(input()) A = list(map(int, input().split())) ret = [] for i in range(N): if i % 2 == 0: ret.append(A[i]) ret.reverse() for i in range(N): if i % 2 == 1: ret.append(A[i]) if N % 2 == 0: ret.reverse() print(*ret)
s005035998
p03371
u924717835
2,000
262,144
Wrong Answer
92
6,296
140
"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()) l = [] for c in range(0,max(2*X,2*Y)+1,2): l.append(A*(X-c/2) + B*(Y-c/2) + C*c) print(int(min(l)))
s158625734
Accepted
136
6,296
154
A,B,C,X,Y = map(int,input().split()) l = [] for c in range(0,max(2*X,2*Y)+1,2): l.append(A*max(0,(X-c/2)) + B*max(0,(Y-c/2)) + C*c) print(int(min(l)))
s013685099
p03795
u268792407
2,000
262,144
Wrong Answer
17
2,940
41
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n=int(input()) x=800*n y=n//15 print(x-y)
s368182460
Accepted
17
2,940
47
n=int(input()) x=n*800 y=(n//15)*200 print(x-y)
s857384469
p02613
u321065001
2,000
1,048,576
Wrong Answer
142
16,256
163
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=[input() for i in range(n)] print("AC ×",s.count("AC")) print("WA ×",s.count("WA")) print("TLE ×",s.count("TLE")) print("RE ×",s.count("RE"))
s235078362
Accepted
142
16,192
159
n=int(input()) s=[input() for i in range(n)] print("AC x",s.count("AC")) print("WA x",s.count("WA")) print("TLE x",s.count("TLE")) print("RE x",s.count("RE"))
s775431006
p00438
u473666214
1,000
131,072
Wrong Answer
30
6,340
628
太郎君の住んでいるJOI市は,南北方向にまっすぐに伸びる a 本の道路と,東西方向にまっすぐに伸びる b 本の道路により,碁盤の目の形に区分けされている. 南北方向の a 本の道路には,西から順に 1, 2, ... , a の番号が付けられている.また,東西方向の b 本の道路には,南から順に 1, 2, ... , b の番号が付けられている.西から i 番目の南北方向の道路と,南から j 番目の東西方向の道路が交わる交差点を (i, j) で表す. 太郎君は,交差点 (1, 1) の近くに住んでおり,交差点 (a, b) の近くのJOI高校に自転車で通っている.自転車は道路に沿ってのみ移動することができる.太郎君は,通学時間を短くするため,東または北にのみ向かって移動して通学している. 現在, JOI市では, n 個の交差点 (x1, y1), (x2, y2), ... , (xn, yn) で工事を行っている.太郎君は工事中の交差点を通ることができない. 太郎君が交差点 (1, 1) から交差点 (a, b) まで,工事中の交差点を避けながら,東または北にのみ向かって移動して通学する方法は何通りあるだろうか.太郎君の通学経路の個数 m を求めるプログラムを作成せよ.
import copy while True: a, b = map(int, input().split()) if a == 0: break N = int(input()) memo = [[0 for i in range(a+1)] for j in range(b+1)] flag = [[False for i in range(a+1)] for j in range(b+1)] memo[1][1] = 1 flag[1][1] = True x = [0] * N y = [0] * N for i in range(N): x[i], y[i] = map(int, input().split()) flag[y[i]][x[i]] = True print(flag) for i in range(1, b+1): for j in range(1, a+1): if not flag[i][j]: flag[i][j] = True memo[i][j] = memo[i-1][j] + memo[i][j-1] print(memo[b][a])
s715949078
Accepted
30
5,608
599
while True: a, b = map(int, input().split()) if a == 0: break N = int(input()) memo = [[0 for i in range(a+1)] for j in range(b+1)] flag = [[False for i in range(a+1)] for j in range(b+1)] memo[1][1] = 1 flag[1][1] = True x = [0] * N y = [0] * N for i in range(N): x[i], y[i] = map(int, input().split()) flag[y[i]][x[i]] = True for i in range(1, b+1): for j in range(1, a+1): if not flag[i][j]: flag[i][j] = True memo[i][j] = memo[i-1][j] + memo[i][j-1] print(memo[b][a])
s571899231
p03721
u940102677
2,000
262,144
Wrong Answer
18
3,828
132
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
n,k = map(int, input().split()) s = 0 for _ in [0]*n: a,b = map(int, input().split()) s += b if s <= k: print(a) break
s780600232
Accepted
515
29,752
167
n,k = map(int, input().split()) l = [] for _ in [0]*n: l += [list(map(int, input().split()))] l.sort() s = 0 i = -1 while s<k: i += 1 s += l[i][1] print(l[i][0])
s256866974
p03994
u729133443
2,000
262,144
Wrong Answer
98
7,052
135
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,k=open(0) k=int(k) *l,=map(ord,s) for i,t in enumerate(l): j=(19-t)%26 if j<=k:k-=j;l[i]=97 l[-1]+=k%26 print(*map(chr,l),sep='')
s801132623
Accepted
105
7,144
140
s,k=open(0) k=int(k) *l,=map(ord,s[:-1]) for i,t in enumerate(l): j=(19-t)%26 if j<=k:k-=j;l[i]=97 l[-1]+=k%26 print(*map(chr,l),sep='')
s929576123
p03380
u134019875
2,000
262,144
Wrong Answer
2,104
14,300
370
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
import math def comb(n, r): if r > n: n, r = r, n return math.factorial(n) // (math.factorial(r) * math.factorial(n - r)) n = int(input()) li = list(map(int, input().split())) M = 0 ans = [] for i in range(n-1): for j in range(i+1, n): c = comb(li[i], li[j]) if c > M: M = c ans = [li[i], li[j]] print(*ans)
s268132609
Accepted
116
14,428
179
n = int(input()) a = sorted(map(int, input().split())) m = a[-1] for i in range(n - 1): c = abs(a[i] - a[-1] / 2) if c < m: m = c r = i print(a[-1], a[r])
s287761859
p02795
u100277898
2,000
1,048,576
Wrong Answer
17
2,940
87
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.
H = int(input()) W = int(input()) N = int(input()) a = max(H,W) x = int(N/a) print(x)
s946051377
Accepted
18
2,940
105
import math H = int(input()) W = int(input()) N = int(input()) a = max(H,W) x = math.ceil(N/a) print(x)
s015511290
p02383
u782850499
1,000
131,072
Wrong Answer
30
7,452
620
Write a program to simulate rolling a dice, which can be constructed by the following net. As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
dice = [1,2,3,4,5,6] number = list(map(int,input().split())) direction = str(input()) rotate_n =[2,6,4,3,1,5] rotate_s =[5,1,3,4,6,2] rotate_e =[4,2,1,6,5,3] rotate_w =[3,2,6,1,5,4] for i in direction: result = [] if i == "N": for j in range(6): dice[j] = rotate_n[j] elif i == "S": for j in range(6): dice[j] = rotate_s[j] elif i == "E": for j in range(6): dice[j] = rotate_e[j] else: for j in range(6): dice[j] = rotate_w[j] for k in dice: result.append(number[k-1]) number = result print(number[1])
s911925992
Accepted
20
7,576
620
dice = [1,2,3,4,5,6] number = list(map(int,input().split())) direction = str(input()) rotate_n =[2,6,3,4,1,5] rotate_s =[5,1,3,4,6,2] rotate_e =[4,2,1,6,5,3] rotate_w =[3,2,6,1,5,4] for i in direction: result = [] if i == "N": for j in range(6): dice[j] = rotate_n[j] elif i == "S": for j in range(6): dice[j] = rotate_s[j] elif i == "E": for j in range(6): dice[j] = rotate_e[j] else: for j in range(6): dice[j] = rotate_w[j] for k in dice: result.append(number[k-1]) number = result print(number[0])
s864882022
p02678
u557282438
2,000
1,048,576
Wrong Answer
640
33,876
451
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.
from collections import deque N,M = map(int,input().split()) ans = [-1]*(N+1) E = [[] for i in range(N+1)] for i in range(M): a,b = map(int,input().split()) E[a].append(b) E[b].append(a) q = deque([1]) while(q): v = q.popleft() for s in E[v]: if(ans[s] == -1): ans[s] = v q.append(s) for s in ans: if(s == -1): print("No") exit() print("Yes") for s in ans[2:]: print(s)
s088034598
Accepted
624
35,004
455
from collections import deque N,M = map(int,input().split()) ans = [-1]*(N+1) E = [[] for i in range(N+1)] for i in range(M): a,b = map(int,input().split()) E[a].append(b) E[b].append(a) q = deque([1]) while(q): v = q.popleft() for s in E[v]: if(ans[s] == -1): ans[s] = v q.append(s) for s in ans[2:]: if(s == -1): print("No") exit() print("Yes") for s in ans[2:]: print(s)
s553203956
p04002
u346194435
3,000
262,144
Wrong Answer
1,752
192,992
589
We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column. Compute the following: * For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
import collections H,W,N = map(int,input().split()) abList = [] for _ in range(N): a,b = map(int, input().split()) abList.append((a-1,b-1)) memo = [] for a,b in abList: for i in range(a-1,a+2): if H < i+2 or i < 1: continue for j in range(b-1, b+2): if W < j+2 or j < 1: continue memo.append((i,j)) x = collections.Counter(memo) result = [0 for _ in range(9)] s = 0 for k,v in x.items(): if int(v) < 9: result[int(v)] += 1 s += int(v) print((W-2)*(H-2) - len(x)) for x in result: print(x)
s852113672
Accepted
1,719
192,992
592
import collections H,W,N = map(int,input().split()) abList = [] for _ in range(N): a,b = map(int, input().split()) abList.append((a-1,b-1)) memo = [] for a,b in abList: for i in range(a-1,a+2): if H < i+2 or i < 1: continue for j in range(b-1, b+2): if W < j+2 or j < 1: continue memo.append((i,j)) x = collections.Counter(memo) result = [0 for _ in range(9)] s = 0 for k,v in x.items(): if int(v) < 10: result[int(v)-1] += 1 s += int(v) print((W-2)*(H-2) - len(x)) for x in result: print(x)
s462564720
p03854
u561113780
2,000
262,144
Wrong Answer
121
3,700
1,067
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
import copy def deleteStr(S, text): if len(S) < len(text): return S for i, letter in enumerate(text): if letter == S[i]: continue else: return S return S[len(text):] def checkStr(S, text): if len(S) < len(text): return False for i, letter in enumerate(text): if letter == S[i]: continue else: return False return True def main(): S = input() for i in range(len(S)): S_len = len(S) if checkStr(S, 'dreamer'): if checkStr(S, 'dreamerase'): S = deleteStr(S, 'dream') else: S = deleteStr(S, 'dreamer') else: S = deleteStr(S, 'dream') if checkStr(S, 'eraser'): S = deleteStr(S, 'eraser') else: S = deleteStr(S, 'erase') if S_len == len(S): if S_len == 0: print('Yes') else: print('No') break if __name__ == '__main__': main()
s226522764
Accepted
121
3,700
1,067
import copy def deleteStr(S, text): if len(S) < len(text): return S for i, letter in enumerate(text): if letter == S[i]: continue else: return S return S[len(text):] def checkStr(S, text): if len(S) < len(text): return False for i, letter in enumerate(text): if letter == S[i]: continue else: return False return True def main(): S = input() for i in range(len(S)): S_len = len(S) if checkStr(S, 'dreamer'): if checkStr(S, 'dreamerase'): S = deleteStr(S, 'dream') else: S = deleteStr(S, 'dreamer') else: S = deleteStr(S, 'dream') if checkStr(S, 'eraser'): S = deleteStr(S, 'eraser') else: S = deleteStr(S, 'erase') if S_len == len(S): if S_len == 0: print('YES') else: print('NO') break if __name__ == '__main__': main()
s315159962
p03971
u371385198
2,000
262,144
Wrong Answer
107
4,016
304
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
N, A, B = map(int, input().split()) S = input() a = 0 b = 0 for s in S: if s == 'c': print('No') elif s == 'a': if a + b <= A + B: print('Yes') a += 1 else: print('No') else: if a + b <= A + B and b <= B: print('Yes') b += 1 else: print('No')
s122306596
Accepted
110
4,016
302
N, A, B = map(int, input().split()) S = input() a = 0 b = 0 for s in S: if s == 'c': print('No') elif s == 'a': if a + b < A + B: print('Yes') a += 1 else: print('No') else: if a + b < A + B and b < B: print('Yes') b += 1 else: print('No')
s459840814
p03599
u501643136
3,000
262,144
Wrong Answer
18
3,064
520
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()) W = set() S = set() wtr = 100*A sgr = 0 i = 1 j = 0 while(wtr < F): while(wtr < F): W.add(wtr) wtr = i*A*100 + j*B*100 j +=1 i +=1 j = 0 i = 0 j = 0 while(sgr < F): while(sgr < F): S.add(sgr) sgr = i*C + j*D j +=1 i +=1 j = 0 answtr = 100*A anssgr = 0 for wtr in W: for sgr in S: if (sgr*answtr > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr)): answtr = wtr anssgr = sgr print("{} {}".format(answtr+anssgr, anssgr))
s224516496
Accepted
113
3,316
757
A, B, C, D, E, F = map(int, input().split()) W = set() S = set() wtr = 100*A sgr = 0 i = 1 j = 0 while(wtr <= F): while(wtr <= F): W.add(wtr) wtr = i*A*100 + j*B*100 j +=1 i +=1 j = 0 wtr = i*A*100 + j*B*100 i = 0 j = 0 while(sgr <= F): while(sgr <= F): S.add(sgr) sgr = i*C + j*D j +=1 i +=1 j = 0 sgr = i*C + j*D answtr = 100*A anssgr = 0 for wtr in reversed(sorted(list(W))): for sgr in reversed(sorted(list(S))): if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)): answtr = wtr anssgr = sgr if anssgr*(100+E)==E*(answtr+anssgr): print("{} {}".format(answtr+anssgr, anssgr)) exit() print("{} {}".format(answtr+anssgr, anssgr))
s082895836
p02390
u165447384
1,000
131,072
Wrong Answer
20
5,588
59
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.
x = int( input() ) print( x/3600,":",(x%3600)/60,":",x%60)
s871916633
Accepted
20
5,588
112
x = int(input()) print(x//3600,end="") print(':',end="") print((x//60)%60,end="") print(':',end="") print(x%60)
s357302280
p03394
u608088992
2,000
262,144
Wrong Answer
31
5,100
645
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
N = int(input()) if N == 3: print(" ".join(map(str, [2, 3, 63]))) elif N == 4: print(" ".join(map(str, [2, 3, 20, 63]))) elif N == 5: print(" ".join(map(str, [2, 3, 20, 30, 63]))) else: Ans = [None] * N for i in range(N): if i % 4 == 0: Ans[i] = 6 * (i//4) + 2 elif i % 4 == 1: Ans[i] = 6 * (i//4) + 3 elif i % 4 == 2: Ans[i] = 6 * (i//4) + 4 else: Ans[i] = 6 * (i//4) + 6 total = sum(Ans) % 6 if total == 2: Ans[4] = 6 * (N//4 + 1) elif total == 3: Ans[5] = 6 * (N//4 + 1) elif total == 5: Ans[5] = 6 * (N//4 + 1) + 4 print(" ".join(map(str, Ans)))
s233803441
Accepted
25
5,220
1,007
def gcd(a, b): a, b = max(a, b), min(a, b) while a % b > 0: a, b = b, a % b return b def solve(): N = int(input()) ans = [] if N == 3: ans = [2, 5, 63] elif N == 4: ans = [2, 5, 20, 63] elif N == 5: ans = [2, 5, 20, 30, 63] else: count = [0, 0, 0, 0] for i in range(N // 4): ans.append(6 * i + 2) ans.append(6 * i + 3) ans.append(6 * i + 4) ans.append(6 * i + 6) count[0] += 1 count[1] += 1 count[2] += 1 count[3] += 1 mod = [2, 3, 4, 6] for j in range(N % 4): ans.append(6 * (N // 4) + mod[j]) count[j] += 1 total = sum(ans) if total % 6 == 2: ans[4] = 6 * count[3] + 6 elif total % 6 == 3: ans[5] = 6 * count[3] + 6 elif total % 6 == 5: ans[5] = 6 * count[2] + 4 print(" ".join(map(str, ans))) return if __name__ == "__main__": solve()
s039695635
p02240
u236679854
1,000
131,072
Wrong Answer
20
7,808
670
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
n, m = map(int, input().split()) friend = [[] for i in range(n)] for i in range(m): s, t = map(int, input().split()) friend[s].append(t) friend[t].append(s) def are_connected(s, t): q = [s] checked = [False] * n checked[s] = True while q: user = q.pop(0) for f in friend[user]: if f == t: print(f, user) return True elif not checked[f]: q.append(f) checked[f] = True return False q = int(input()) for i in range(q): s, t = map(int, input().split()) if are_connected(s, t): print('yes') else: print('no')
s256263899
Accepted
600
26,560
612
n, m = map(int, input().split()) friend = [[] for i in range(n)] for i in range(m): s, t = map(int, input().split()) friend[s].append(t) friend[t].append(s) group = [-1 for i in range(n)] for u in range(n): if group[u] == -1: group[u] = u q = [u] while q: u1 = q.pop() for u2 in friend[u1]: if group[u2] == -1: group[u2] = u q.append(u2) q = int(input()) for i in range(q): s, t = map(int, input().split()) if group[s] == group[t]: print('yes') else: print('no')
s614833944
p03149
u139235669
2,000
1,048,576
Wrong Answer
18
2,940
171
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".
num_list = list(map(int,input().split(' '))) print(num_list) if 1 in num_list and 9 in num_list and 7 in num_list and 4 in num_list: print("YES") else: print("NO")
s258192176
Accepted
17
2,940
156
num_list = list(map(int,input().split(' '))) if 1 in num_list and 9 in num_list and 7 in num_list and 4 in num_list: print("YES") else: print("NO")
s299779402
p02936
u761471989
2,000
1,048,576
Wrong Answer
2,108
94,812
899
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
N, Q = map(int, input().split()) ab_list = [] tree_dict = {} for i in range(N-1): a, b = map(int, input().split()) ab_list.append(a) ab_list.append(b) if a not in tree_dict: tree_dict[a] = [b] else: tree_dict[a].append(b) value_dict = {k:0 for k in list(set(ab_list))} p_list = [] x_list = [] for i in range(Q): p, x = map(int, input().split()) p_list.append(p) x_list.append(x) for p, x in zip(p_list, x_list): f = 0 for k, v in value_dict.items(): if k == p: kk_list = [k] while(1): if len(kk_list) == 0: f = 1 break k = kk_list[0] value_dict[k] += x if k in tree_dict: kk_list += tree_dict[k] kk_list.pop(0) if f == 1: break print(value_dict)
s016952898
Accepted
1,743
90,960
830
N, Q = map(int, input().split()) ab_list = [] tree_dict = {} for i in range(N-1): a, b = map(int, input().split()) ab_list.append(a) ab_list.append(b) if a not in tree_dict: tree_dict[a] = [b] else: tree_dict[a].append(b) value_list = list(set(ab_list)) px_dict = {} for i in range(Q): p, x = map(int, input().split()) if p in px_dict: px_dict[p] += x else: px_dict[p] = x out = "" for v in value_list: if v in px_dict: x = px_dict[v] if v in tree_dict: tree_list = tree_dict[v] for t in tree_list: if t in px_dict: px_dict[t] += x else: px_dict[t] = x o = str(px_dict[v]) else: o = str(0) out += o + " " print(out[:-1])
s418280509
p03455
u413970908
2,000
262,144
Wrong Answer
17
2,940
99
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 and b % 2 == 0): print("Even") else: print("Odd")
s792355907
Accepted
17
2,940
98
a,b = map(int, input().split()) if(a % 2 == 0 or b % 2 == 0): print("Even") else: print("Odd")
s764406027
p03962
u149752754
2,000
262,144
Wrong Answer
17
2,940
157
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.
A, B, C = map(int, input().split()) if A + B == C: print('Yes') elif A + C == B: print('Yes') elif B + C == A: print('Yes') else: print('No')
s864668711
Accepted
20
3,316
134
from collections import Counter CO = list(map(int, input().split())) CNT = Counter(CO) CNTL = list(CNT.keys()) N = len(CNTL) print (N)
s612356472
p03160
u167681750
2,000
1,048,576
Wrong Answer
276
13,928
256
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
n = int(input()) h = list(map(int, input().split())) ans = abs(h[1] - h[0]) l, ll = ans, 0 for i in range(2,n): print(abs(h[i] - h[i-1]),abs(h[i] - h[i-2])) ans = min(l + abs(h[i] - h[i-1]), ll + abs(h[i] - h[i-2])) l, ll = ans, l print(ans)
s599203542
Accepted
127
13,980
227
n = int(input()) h = list(map(int, input().split())) table = [0] * (n+2) table[1] = abs(h[0] - h[1]) for i in range(2,n): table[i] += min(table[i-2] + abs(h[i-2] - h[i]), table[i-1] + abs(h[i-1] - h[i])) print(table[n-1])
s603885548
p02417
u981139449
1,000
131,072
Wrong Answer
20
7,384
239
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
import sys alphabets = range(ord('a'), ord('z') + 1) dic = { chr(c): 0 for c in alphabets } text = sys.stdin.read() for c in text: c = c.lower() if ord(c) in alphabets: dic[c] += 1 for item in sorted(dic.items()): print(*item)
s150469031
Accepted
20
7,416
243
import sys alphabets = range(ord('a'), ord('z') + 1) dic = { chr(c): 0 for c in alphabets } text = sys.stdin.read() for c in text: c = c.lower() if ord(c) in alphabets: dic[c] += 1 for c, n in sorted(dic.items()): print(c, ":", n)
s112295036
p02396
u279483260
1,000
131,072
Wrong Answer
160
7,556
124
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
for i in range(10000): x = int(input()) if x == 0: break else: print("Case {}: {}".format(i, x))
s652344640
Accepted
70
7,464
138
import sys cnt = 1 while 1: x=sys.stdin.readline().strip() if x == '0': break; print("Case %d: %s"%(cnt,x)) cnt+=1
s791498141
p03485
u094196396
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.
import math a,b=map(int,input().split()) x=(a+b)/2 math.ceil(x)
s730132641
Accepted
20
2,940
71
import math a,b=map(int,input().split()) x=(a+b)/2 print(math.ceil(x))
s925163944
p03694
u449555432
2,000
262,144
Wrong Answer
18
2,940
62
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along _TopCoDeer street_. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.
a=list(map(int,input().split())) b=sorted(a) print(b[-1]-b[0])
s394687486
Accepted
17
2,940
77
z=int(input()) a=list(map(int,input().split())) b=sorted(a) print(b[-1]-b[0])
s640288019
p02659
u439025531
2,000
1,048,576
Wrong Answer
25
9,092
44
Compute A \times B, truncate its fractional part, and print the result as an integer.
A,B=input().split() print(float(A)*float(B))
s508765790
Accepted
23
9,060
62
A,B=input().split() B=round(float(B)*100) print(int(A)*B//100)
s384113522
p03495
u267683315
2,000
262,144
Wrong Answer
2,105
35,996
281
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
import collections result = 0 n,k = map(int,input().split()) input_list = input().split() counter_list = collections.Counter(input_list) if k < len(counter_list): for i in range(len(counter_list)-k + 1): result += sorted(counter_list.values(),reverse=True)[-1] print(result)
s881778672
Accepted
112
35,996
306
import collections result = 0 n,k = map(int,input().split()) input_list = input().split() counter_list = collections.Counter(input_list) if k < len(counter_list): length = len(counter_list)-k sort_list = sorted(counter_list.values()) for i in range(length): result += sort_list[i] print(result)