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
s663773654
p02678
u547608423
2,000
1,048,576
Wrong Answer
1,066
35,100
531
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 queue import Queue N, M = map(int, input().split()) root = [[] for _ in range(N)] #print(root) for i in range(M): A, B = map(int, input().split()) root[A-1].insert(len(root[A-1]), B) root[B-1].insert(len(root[B-1]), A) room = [0]*N q = Queue() for k in root[0]: room[k-1] = 1 q.put(k) while not q.empty(): a = q.get() for j in root[a-1]: if room[j-1] == 0: q.put(j) room[j-1] = a if 0 in room[1:]: print("No") else: for ans in room[1:]: print(ans)
s045194831
Accepted
1,003
35,100
548
from queue import Queue N, M = map(int, input().split()) root = [[] for _ in range(N)] #print(root) for i in range(M): A, B = map(int, input().split()) root[A-1].insert(len(root[A-1]), B) root[B-1].insert(len(root[B-1]), A) room = [0]*N q = Queue() for k in root[0]: room[k-1] = 1 q.put(k) while not q.empty(): a = q.get() for j in root[a-1]: if room[j-1] == 0: q.put(j) room[j-1] = a if 0 in room[1:]: print("No") else: print("Yes") for ans in room[1:]: print(ans)
s877746216
p03129
u606045429
2,000
1,048,576
Wrong Answer
17
2,940
100
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
N, K = [int(_) for _ in input().split()] if N // 2 + 1 >= K: print("Yes") else: print("No")
s466057633
Accepted
17
2,940
101
N, K = [int(_) for _ in input().split()] if (N + 1) // 2 >= K: print("YES") else: print("NO")
s316405759
p03760
u509739538
2,000
262,144
Wrong Answer
22
3,444
2,916
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
import math from collections import deque from collections import defaultdict import itertools as it def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() def factorization(n): res = [] if n%2==0: res.append(2) for i in range(3,math.floor(n//2)+1,2): if n%i==0: c = 0 for j in res: if i%j==0: c=1 if c==0: res.append(i) return res def fact2(n): p = factorization(n) res = [] for i in p: c=0 z=n while 1: if z%i==0: c+=1 z/=i else: break res.append([i,c]) return res def fact(n): ans = 1 m=n for _i in range(n-1): ans*=m m-=1 return ans def comb(n,r): if n<r: return 0 l = min(r,n-r) m=n u=1 for _i in range(l): u*=m m-=1 return u//fact(l) def combmod(n,r,mod): return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod def printQueue(q): r=copyQueue(q) ans=[0]*r.qsize() for i in range(r.qsize()-1,-1,-1): ans[i] = r.get() print(ans) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1]*n def find(self, x): # root if self.parents[x]<0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self,x,y): x = self.find(x) y = self.find(y) if x==y: return if self.parents[x]>self.parents[y]: x,y = y,x self.parents[x]+=self.parents[y] self.parents[y]=x def size(self,x): return -1*self.parents[self.find(x)] def same(self,x,y): return self.find(x)==self.find(y) def members(self,x): # much time root = self.find(x) return [i for i in range(self.n) if self.find(i)==root] def roots(self): return [i for i,x in enumerate(self.parents) if x<0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} # 1~n def bitArr(n): x = 1 zero = "0"*n ans = [] ans.append([0]*n) for i in range(2**n-1): ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:])))) x+=1 return ans; def arrsSum(a1,a2): for i in range(len(a1)): a1[i]+=a2[i] return a1 def maxValue(a,b,v): v2 = v for i in range(v2,-1,-1): for j in range(v2//a+1): k = i-a*j if k%b==0: return i return -1 def copyQueue(q): nq = queue.Queue() n = q.qsize() for i in range(n): x = q.get() q.put(x) nq.put(x) return nq def get_sieve_of_eratosthenes(n): #data = [2] data = [0,0,0] for i in range(3,n+1,2): data.append(i) data.append(0) for i in range(len(data)): interval = data[i] if interval!=0: for j in range(i+interval,n-1,interval): data[j] = 0 #ans = [x for x in data if x!=0] ans = data[:] return ans o = readChar() e = readChar() for i in range(len(e)): print(o[i],e[i],sep="",end="") if len(o)!=len(e): print(e[-1])
s624611093
Accepted
22
3,444
2,931
import math from collections import deque from collections import defaultdict import itertools as it def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() def factorization(n): res = [] if n%2==0: res.append(2) for i in range(3,math.floor(n//2)+1,2): if n%i==0: c = 0 for j in res: if i%j==0: c=1 if c==0: res.append(i) return res def fact2(n): p = factorization(n) res = [] for i in p: c=0 z=n while 1: if z%i==0: c+=1 z/=i else: break res.append([i,c]) return res def fact(n): ans = 1 m=n for _i in range(n-1): ans*=m m-=1 return ans def comb(n,r): if n<r: return 0 l = min(r,n-r) m=n u=1 for _i in range(l): u*=m m-=1 return u//fact(l) def combmod(n,r,mod): return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod def printQueue(q): r=copyQueue(q) ans=[0]*r.qsize() for i in range(r.qsize()-1,-1,-1): ans[i] = r.get() print(ans) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1]*n def find(self, x): # root if self.parents[x]<0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self,x,y): x = self.find(x) y = self.find(y) if x==y: return if self.parents[x]>self.parents[y]: x,y = y,x self.parents[x]+=self.parents[y] self.parents[y]=x def size(self,x): return -1*self.parents[self.find(x)] def same(self,x,y): return self.find(x)==self.find(y) def members(self,x): # much time root = self.find(x) return [i for i in range(self.n) if self.find(i)==root] def roots(self): return [i for i,x in enumerate(self.parents) if x<0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} # 1~n def bitArr(n): x = 1 zero = "0"*n ans = [] ans.append([0]*n) for i in range(2**n-1): ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:])))) x+=1 return ans; def arrsSum(a1,a2): for i in range(len(a1)): a1[i]+=a2[i] return a1 def maxValue(a,b,v): v2 = v for i in range(v2,-1,-1): for j in range(v2//a+1): k = i-a*j if k%b==0: return i return -1 def copyQueue(q): nq = queue.Queue() n = q.qsize() for i in range(n): x = q.get() q.put(x) nq.put(x) return nq def get_sieve_of_eratosthenes(n): #data = [2] data = [0,0,0] for i in range(3,n+1,2): data.append(i) data.append(0) for i in range(len(data)): interval = data[i] if interval!=0: for j in range(i+interval,n-1,interval): data[j] = 0 #ans = [x for x in data if x!=0] ans = data[:] return ans o = readChar() e = readChar() for i in range(len(e)): print(o[i],e[i],sep="",end="") if len(o)!=len(e): print(o[-1]) else: print()
s993356263
p03386
u221345507
2,000
262,144
Wrong Answer
18
3,060
234
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()) K2=B-A K3=K2-K*2 if K3 > 0: for i in range (K): print ('%d'%(A+i)) for i in range (K): print ('%d'%(B-K+i)) if K3 <= 0: for i in range (B-A+1): print ('%d'%(A+i))
s445947227
Accepted
18
3,060
238
A, B, K = map(int, input().split()) K2=B-A+1 K3=K2-K*2 if K3 > 0: for i in range (K): print ('%d'%(A+i)) for i in range (K): print ('%d'%(B-K+i+1)) if K3 <= 0: for i in range (B-A+1): print ('%d'%(A+i))
s155399873
p03504
u323626540
2,000
262,144
Wrong Answer
1,917
57,860
377
Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
N, C = map(int, input().split()) f = [[0] * 100000 for _ in range(C)] for i in range(N): s, t, c = map(int, input().split()) f[c-1][s-1] = 1 f[c-1][t-1] = -1 for c in range(C): for i in range(100000): if i > 0: f[c][i] += f[c][i-1] p = [0] * 100000 for i in range(100000): for c in range(C): p[i] += f[c][i] rec_max = max(p)
s790070241
Accepted
483
28,532
198
N, C = map(int, input().split()) f = [[0] * 100000 for _ in range(C)] for i in range(N): s, t, c = map(int, input().split()) f[c-1][s-1:t] = [1] * (t-s+1) print(max(map(sum, zip(*f))))
s597621606
p02389
u355552770
1,000
131,072
Wrong Answer
20
7,672
63
Write a program which calculates the area and perimeter of a given rectangle.
x, y = (int(i) for i in input().split()) res = x * y print(res)
s369558560
Accepted
20
7,612
58
x, y = map(int, input().split()) print(x * y, 2 * (x + y))
s661093975
p02678
u086127549
2,000
1,048,576
Wrong Answer
832
63,656
562
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 def bfs(adj, sign): queue = deque([0]) sign[0] = 0 while queue: x = queue.popleft() for y in adj[x]: if sign[y] == -1: sign[y] = x queue.append(y) if __name__ == "__main__": n, m = map(int, input().split()) adj = [set() for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) adj[a-1].add(b-1) adj[b-1].add(a-1) sign = [-1]*n bfs(adj, sign) if all([x != -1 for x in sign]): print("yes") for x in sign[1:]: print(x+1) else: print("no")
s047539586
Accepted
758
63,360
578
from collections import deque def bfs(adj, sign): queue = deque([0]) sign[0] = 0 while queue: x = queue.popleft() for y in adj[x]: if sign[y] == -1: sign[y] = x queue.append(y) if __name__ == "__main__": n, m = map(int, input().split()) adj = [set() for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) adj[a-1].add(b-1) adj[b-1].add(a-1) sign = [-1]*n bfs(adj, sign) if all([x != -1 for x in sign]): print("Yes") for x in sign[1:]: print(x+1) else: print("No")
s195794657
p03048
u183509493
2,000
1,048,576
Wrong Answer
1,839
3,068
161
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
a,b,c,n=map(int,input().split()) ans=0 for x in range((n+1)//a): for y in range((n+1-a*x)//b): z=n-a*x-b*y if z>=0 and z%c==0: ans+=1 print(ans)
s986951461
Accepted
970
2,940
134
a,b,c,n=map(int,input().split()) ans=0 for x in range(0,n+1,a): for y in range(x,n+1,b): if (n-y)%c==0: ans+=1 print(ans)
s125273949
p03696
u879870653
2,000
262,144
Wrong Answer
17
2,940
191
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.
n=int(input()) S=input() l=0 r=0 for s in S : if s == ")" : if r : r -= 1 else : l += 1 else : r += 1 ans = "("*l + S + ")" print(ans)
s545920620
Accepted
17
2,940
186
input() S=input() l=0 r=0 for s in S : if s == ")" : if r : r -= 1 else : l += 1 else : r += 1 ans = "("*l + S + ")"*r print(ans)
s954461464
p03997
u701318346
2,000
262,144
Wrong Answer
17
2,940
75
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print(2 * (a + b) / 2 )
s670127234
Accepted
18
2,940
74
a, b, h = int(input()), int(input()), int(input()) print(int((a+b)/2 * h))
s939199021
p02401
u447009770
1,000
131,072
Wrong Answer
20
7,596
334
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
n = [] while (True): x = list(input().split()) if x[1] == '?': break elif x[1] == '+': n.append(int(x[0]) + int(x[2])) pass elif x[1] == '-': n.append(int(x[0]) - int(x[2])) pass elif x[1] == '*': n.append(int(x[0]) * int(x[2])) pass elif x[1] == '/': n.append(int(x[0]) / int(x[2])) pass for i in n: print(i)
s019878809
Accepted
30
7,676
339
n = [] while (True): x = list(input().split()) if x[1] == '?': break elif x[1] == '+': n.append(int(x[0]) + int(x[2])) pass elif x[1] == '-': n.append(int(x[0]) - int(x[2])) pass elif x[1] == '*': n.append(int(x[0]) * int(x[2])) pass elif x[1] == '/': n.append(int(x[0]) / int(x[2])) pass for i in n: print(int(i))
s768677719
p03798
u483645888
2,000
262,144
Wrong Answer
1,765
3,836
269
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`.
n = int(input()) s = input() l = ['SS','WS','SW','WW'] for i in range(n): for j in range(len(l)): l[j] += 'SW'[::-1 if i=='o' else 1][l[j][i]==l[j][i+1]] for i in range(n): if l[i][1]==l[i][n+1] and l[i][0]==l[i][n]: print(l[i][1:n+1]) exit() print(-1)
s542343059
Accepted
1,733
3,836
278
n = int(input()) s = input() l = ['SS','SW','WS','WW'] for i in range(n): for j in range(len(l)): l[j] += 'SW'[::-1 if s[i]=='o' else 1][l[j][i]==l[j][i+1]] for i in range(len(l)): if l[i][0]==l[i][n] and l[i][1]==l[i][n+1]: print(l[i][1:n+1]) exit() print(-1)
s000024563
p03456
u977349332
2,000
262,144
Wrong Answer
17
2,940
121
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
import math a, b = [int(i) for i in input().split()] if math.sqrt(a*b).is_integer(): print('Yes') else: print('No')
s085732885
Accepted
17
2,940
107
import math a, b = input().split() if math.sqrt(int(a+b)).is_integer(): print('Yes') else: print('No')
s850059907
p03371
u020604402
2,000
262,144
Wrong Answer
18
3,064
248
"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()) value = 0 ans = [] if X > 0 and Y > 0 and A + B > 2*C: m = min(X, Y) value += m * 2*C X = X - m Y = Y - m value += (X * A + Y * B) ans.append(value) ans.append(max(X,Y) * 2*C) print(min(ans))
s753760951
Accepted
18
3,064
248
A, B, C, X, Y = map(int,input().split()) value = 0 ans = [] ans.append(max(X,Y) * 2*C) if X > 0 and Y > 0 and A + B > 2*C: m = min(X, Y) value += m * 2*C X = X - m Y = Y - m value += (X * A + Y * B) ans.append(value) print(min(ans))
s264368027
p03494
u095756391
2,000
262,144
Time Limit Exceeded
2,104
2,940
168
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N = int(input()) A = list(map(int, input().split())) ans = 0 while len(A) == N: A = [a for a in A if a % 2 == 0] if len(A) == N: ans += 1 print(ans)
s132773348
Accepted
19
2,940
241
N = int(input()) A = list(map(int, input().split())) ans = 0 while True: exist_odd = False for a in A: if a % 2 != 0: exist_odd = True if exist_odd: break for i in range(N): A[i] /= 2 ans += 1 print(ans)
s980603129
p03470
u561828236
2,000
262,144
Wrong Answer
20
3,060
98
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
n = int(input()) mochi = [input() for i in range(n)] a = set(mochi) print(a) a = len(a) print(a)
s030244903
Accepted
20
2,940
89
n = int(input()) mochi = [input() for i in range(n)] a = set(mochi) a = len(a) print(a)
s069620910
p03493
u366185462
2,000
262,144
Wrong Answer
17
2,940
30
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
a = list(input()) a.count('1')
s821137313
Accepted
17
2,940
37
a = list(input()) print(a.count('1'))
s217717101
p03131
u430771494
2,000
1,048,576
Wrong Answer
19
3,060
182
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
K,A,B=list(map(int,input().split())) hand=0 if B-A<=2: print(K+1) exit() K=K-A+1 print(K) if K%2==1: hand=1+int((K-1)/2)*(B-A) else: hand=int(K/2)*(B-A) print(hand+A)
s937727905
Accepted
17
3,060
173
K,A,B=list(map(int,input().split())) hand=0 if B-A<=2: print(K+1) exit() K=K-A+1 if K%2==1: hand=1+int((K-1)/2)*(B-A) else: hand=int(K/2)*(B-A) print(hand+A)
s644283677
p03779
u112902287
2,000
262,144
Time Limit Exceeded
2,105
31,124
254
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
n = int(input()) dx =[-1, 0, 1] l = [0] i = 0 while True: for x in l: if x == n: break for j in range(len(l)): a = l[0] l.pop(l[0]) for k in range(3): l.append(a + dx[k]*(i+1)) print(i)
s540169456
Accepted
18
2,940
96
x = int(input()) i = (-1+(1+8*x)**0.5)/2 if int(i) == i: print(int(i)) else: print(int(i)+1)
s028743463
p03711
u972892985
2,000
262,144
Wrong Answer
17
3,060
174
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
x, y = map(int,input().split()) a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] if x in a and y in b: print("Yes") elif x in b and y in b: print("Yes") else: print("No")
s657034769
Accepted
17
3,060
175
x, y = map(int,input().split()) a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] if x in a and y in a: print("Yes") elif x in b and y in b: print("Yes") else: print("No")
s815163049
p02645
u660899380
2,000
1,048,576
Wrong Answer
21
9,088
25
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
S = input() print(S[0:4])
s965609952
Accepted
23
9,112
25
S = input() print(S[0:3])
s574796346
p02842
u825378567
2,000
1,048,576
Wrong Answer
17
3,060
147
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 math N=int(input()) tmp=N//1.08 if math.floor(tmp*1.08)==N: print(tmp) elif math.floor((tmp+1)*1.08)==N: print(tmp+1) else: print(":(")
s475968212
Accepted
18
3,060
157
import math N=int(input()) tmp=N//1.08 if math.floor(tmp*1.08)==N: print(int(tmp)) elif math.floor((tmp+1)*1.08)==N: print(int(tmp+1)) else: print(":(")
s758946014
p02409
u180914582
1,000
131,072
Wrong Answer
20
6,724
322
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] n = int(input()) for _ in range(n): (b, f, r, v) = [int(i) for i in input().split()] for b in range(4): for f in range(3): for r in range(10): print('', data[b][f][r], end='') print() print('#' * 20)
s271052489
Accepted
20
7,684
367
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] n = int(input()) for _ in range(n): (b,f,r,v) = [int(i) for i in input().split()] data[b - 1][f - 1][r - 1] += v for b in range(4): for f in range(3): for r in range(10): print('',data[b][f][r], end='') print() if b < 3: print('#' * 20)
s493971265
p03997
u297399512
2,000
262,144
Wrong Answer
25
9,120
74
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a + b) / 2 * h)
s505299410
Accepted
24
9,116
79
a = int(input()) b = int(input()) h = int(input()) print(int((a + b) / 2 * h))
s104469654
p02406
u899891332
1,000
131,072
Wrong Answer
20
5,516
396
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
def threeDivCheck(x): if x % 3 == 0: return x return 0 def threeIncludeCheck(x): y = x while y!=0: if y%10 == 3: return x y/=10 return 0 def main(): n = int(input()) p = 0 for i in range(n+1): p = threeDivCheck(i) if p: print(' {}'.format(p), end='') else: p=threeIncludeCheck(i) if p: print(' {}'.format(p), end='') print()
s365348975
Accepted
30
5,876
410
def threeDivCheck(x): if x % 3 == 0: return x return 0 def threeIncludeCheck(x): y = x while y!=0: if y%10 == 3: return x y=int(y/10) return 0 def main(): n = int(input()) p = 0 for i in range(n+1): p = threeDivCheck(i) if p: print(' {}'.format(p), end='') else: p=threeIncludeCheck(i) if p: print(' {}'.format(p), end='') print() main()
s800551141
p03351
u002459665
2,000
1,048,576
Wrong Answer
18
2,940
158
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) if abs(a - c) <= d: print("Yes") elif abs(a - c) <= d and abs(b - c) <= d: print("Yes") else: print("No")
s817700449
Accepted
18
2,940
158
a, b, c, d = map(int, input().split()) if abs(a - c) <= d: print("Yes") elif abs(a - b) <= d and abs(b - c) <= d: print("Yes") else: print("No")
s268766979
p03836
u584317622
2,000
262,144
Wrong Answer
18
3,064
245
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(" ")) reco = [] reco.append((ty-sy)*"U"+(tx-sx)*"R") reco.append((ty-sy)*"D"+(tx-sx)*"L") reco.append("D"+(tx-sx+1)*"R"+(ty-sy+1)*"U"+"L") reco.append("U"+(tx-sx+1)*"R"+(ty-sy+1)*"D"+"R") print("".join(reco))
s841635721
Accepted
17
3,064
245
sx,sy,tx,ty = map(int ,input().split(" ")) reco = [] reco.append((ty-sy)*"U"+(tx-sx)*"R") reco.append((ty-sy)*"D"+(tx-sx)*"L") reco.append("L"+(ty-sy+1)*"U"+(tx-sx+1)*"R"+"D") reco.append("R"+(ty-sy+1)*"D"+(tx-sx+1)*"L"+"U") print("".join(reco))
s500734080
p03455
u044746696
2,000
262,144
Wrong Answer
18
2,940
79
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*b%2==0: print('even') else: print('odd')
s277352853
Accepted
17
2,940
86
A,B=map(int,input().split()) num=A*B if num%2==0: print('Even') else: print('Odd')
s364513348
p02397
u022954704
1,000
131,072
Wrong Answer
40
8,068
278
Write a program which reads two integers x and y, and prints them in ascending order.
a = [] b = [] while True: x,y = map(int,input().split()) if x == 0 and y == 0: break else: a.append(x) b.append(y) for i in range(0,len(a)): if a[i] >= b[i]: print(a[i],b[i]) elif a[i] < b[i]: print(b[i],a[i])
s860912947
Accepted
40
8,120
278
a = [] b = [] while True: x,y = map(int,input().split()) if x == 0 and y == 0: break else: a.append(x) b.append(y) for i in range(0,len(a)): if a[i] >= b[i]: print(b[i],a[i]) elif a[i] < b[i]: print(a[i],b[i])
s565489952
p03795
u536177854
2,000
262,144
Wrong Answer
17
2,940
40
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n=int(input()) print(800*n+200*(n//15))
s331191977
Accepted
17
2,940
40
n=int(input()) print(800*n-200*(n//15))
s581164362
p03852
u046313635
2,000
262,144
Wrong Answer
17
2,940
72
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
c = input() if c == "aeiou": print("vowel") else: print("consonant")
s204638743
Accepted
17
2,940
59
c = input() print("vowel" if c in "aeiou" else "consonant")
s216057767
p03577
u597455618
2,000
262,144
Wrong Answer
17
2,940
31
Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
s = input() print(s[:len(s)-6])
s676672177
Accepted
17
2,940
31
s = input() print(s[:len(s)-8])
s168706576
p02613
u246244953
2,000
1,048,576
Wrong Answer
161
16,100
331
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()) str_list = [input() for _ in range(N)] AC=WA=TLE=RE=0 for i in range(N): if(str_list[i]=="AC"): AC+=1 if(str_list[i]=="TLE"): TLE+=1 if(str_list[i]=="WA"): WA+=1 if(str_list[i]=="RE"): RE+=1 print('AC × '+str(AC)) print('WA × '+str(WA)) print('TLE × '+str(TLE)) print('RE × '+str(RE))
s900690279
Accepted
167
16,048
326
N=int(input()) str_list = [input() for _ in range(N)] AC=WA=TLE=RE=0 for i in range(N): if(str_list[i]=="AC"): AC+=1 if(str_list[i]=="TLE"): TLE+=1 if(str_list[i]=="WA"): WA+=1 if(str_list[i]=="RE"): RE+=1 print('AC x '+str(AC)) print('WA x '+str(WA)) print('TLE x '+str(TLE)) print('RE x '+str(RE))
s591229810
p00015
u075836834
1,000
131,072
Wrong Answer
20
7,544
185
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
n=int(input()) A=[] while True: try: x=int(input()) A.append(x) except EOFError: break start=0 end=start+n for i in range(len(A)//n): print(sum(A[start:end])) start+=n end+=n
s147590026
Accepted
30
7,624
106
n=int(input()) for _ in range(n): s=int(input())+int(input()) print('overflow' if len(str(s))>80 else s)
s577575898
p02646
u382169668
2,000
1,048,576
Wrong Answer
2,206
9,184
237
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, a_v = map(int, input().split()) b, b_v = map(int, input().split()) t = int(input()) flag = 0 t_now = 0 while t_now<=t: if a+t_now*a_v == b+t_now*b_v: flag=1 t_now=t_now+1 if flag==0: print('No') else: print('Yes');
s661166609
Accepted
21
9,040
164
A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) diff_x=abs(A-B) diff_a=max(V-W,0) if T*diff_a>=diff_x: print('YES') else: print('NO')
s655852931
p02396
u298999032
1,000
131,072
Wrong Answer
140
7,548
126
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'+' '+str(i)+':'+' '+str(x))
s603345303
Accepted
130
7,572
128
for i in range(1,10001): x=int(input()) if x==0: break else: print('Case'+' '+str(i)+':'+' '+str(x))
s266483158
p03485
u876742094
2,000
262,144
Wrong Answer
30
9,012
46
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b=map(int,input().split()) print((a+b+1)/2)
s761363052
Accepted
27
9,084
47
a,b=map(int,input().split()) print((a+b+1)//2)
s999890490
p02534
u058592821
2,000
1,048,576
Wrong Answer
23
9,020
70
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`.
k = int(input()) ans = '' for i in range(k): ans += 'ACL' print(k)
s506022661
Accepted
20
9,144
72
k = int(input()) ans = '' for i in range(k): ans += 'ACL' print(ans)
s458891723
p03610
u857673087
2,000
262,144
Wrong Answer
18
3,316
26
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input() print(s[::1])
s137483048
Accepted
17
3,188
27
s = input() print(s[::2])
s665581244
p03067
u371409687
2,000
1,048,576
Wrong Answer
17
2,940
81
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a,b,c=map(int,input().split()) if a>b>c or a<b<c: print('Yes') else:print('No')
s107991798
Accepted
17
2,940
81
a,c,b=map(int,input().split()) if a>b>c or a<b<c: print('Yes') else:print('No')
s739756265
p02928
u194297606
2,000
1,048,576
Wrong Answer
640
3,188
319
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.
N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] numc = 0 numf = 0 for i in range(0, N): for j in range(0,i): if A[j] > A[i]: numc += 1 if A[i] > A[j]: numf += 1 numbers = numc*K*(K+1)+ numf*K*(K-1) ans = numbers % (10**9 + 7) / 2 print(ans)
s678934356
Accepted
651
3,188
325
N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] numc = 0 numf = 0 for i in range(0, N): for j in range(0,i): if A[j] > A[i]: numc += 1 if A[i] > A[j]: numf += 1 numbers = (numc*K*(K+1) + numf*K*(K-1))//2 ans = int(numbers % (10**9 + 7)) print(ans)
s490280945
p02396
u722558010
1,000
131,072
Wrong Answer
20
7,588
120
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.
data=list(map(int,input().splitlines())) n=0 for i in data: if i==0: break print("Case {0}: {1}".format(n,i)) n=n+1
s726167085
Accepted
80
7,712
189
import sys #a = open("test.txt", "r") a = sys.stdin count = 1 for line in a: if int(line) == 0: break print("Case {0}: {1}".format(count, line), end="") count = count + 1
s798225684
p02601
u215286521
2,000
1,048,576
Wrong Answer
122
27,180
884
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.
from math import floor,ceil,sqrt,factorial,log from collections import Counter, deque from functools import reduce import numpy as np import itertools def S(): return input() def I(): return int(input()) def MS(): return map(str,input().split()) def MI(): return map(int,input().split()) def FLI(): return [int(i) for i in input().split()] def LS(): return list(MS()) def LI(): return list(MI()) def LLS(): return [list(map(str, l.split() )) for l in input()] def LLI(): return [list(map(int, l.split() )) for l in input()] def LLSN(n: int): return [LS() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] A,B,C = MI() K = I() ans = False def check(a,b,c): return a < b and b < c for i in range(K): if A >= B: B = B * 2 elif B >= C: C = C * 2 print(A,B,C) if check(A,B,C): print("Yes") exit() print("No")
s387542779
Accepted
125
27,040
863
from math import floor,ceil,sqrt,factorial,log from collections import Counter, deque from functools import reduce import numpy as np import itertools def S(): return input() def I(): return int(input()) def MS(): return map(str,input().split()) def MI(): return map(int,input().split()) def FLI(): return [int(i) for i in input().split()] def LS(): return list(MS()) def LI(): return list(MI()) def LLS(): return [list(map(str, l.split() )) for l in input()] def LLI(): return [list(map(int, l.split() )) for l in input()] def LLSN(n: int): return [LS() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] A,B,C = MI() K = I() ans = False def check(a,b,c): return a < b and b < c for i in range(K): if A >= B: B = B * 2 elif B >= C: C = C * 2 if check(A,B,C): print("Yes") exit() print("No")
s488354736
p03711
u182765930
2,000
262,144
Wrong Answer
17
3,060
165
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
a = {1, 3, 5, 7} b = {4, 6, 9, 11} c = {2} x, y = map(int, input().split()) for i in a, b, c: if x in i: if y in i: print('Yes') print('No')
s147601856
Accepted
17
2,940
180
a = {1, 3, 5, 7, 8, 10, 12} b = {4, 6, 9, 11} c = {2} x, y = map(int, input().split()) for i in a, b, c: if x in i and y in i: print('Yes') quit() print('No')
s225732944
p04043
u966000628
2,000
262,144
Wrong Answer
17
2,940
116
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
lis = list(map(int,input().split())) if sum(lis) == 22 and 5 in lis and 7 in lis: print("YES") else: print("NO")
s065945335
Accepted
17
2,940
118
lis = list(map(int,input().split())) if sum(lis) == 17 and 5 in lis and 7 in lis: print("YES") else: print("NO")
s389837344
p03473
u679245300
2,000
262,144
Wrong Answer
17
2,940
46
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
M = int(input()) answer = 24 + 24 - M print(M)
s940437422
Accepted
17
2,940
51
M = int(input()) answer = 24 + 24 - M print(answer)
s380491164
p02407
u698693989
1,000
131,072
Wrong Answer
20
7,592
164
Write a program which reads a sequence and prints it in the reverse order.
num = "" a = input() W = [int(x) for x in input().split()] for i in W: num+=str(i)+' ' print(num[::-1])
s913982302
Accepted
20
7,720
245
nums="" count=1 a = input() W = [int(x) for x in input().split()] W.reverse() for i in W: if count == int(a): nums+=str(i) else: nums +=str(i)+" " count+=1 print(nums)
s070278527
p02400
u821624310
1,000
131,072
Wrong Answer
20
7,400
63
Write a program which calculates the area and circumference of a circle for given radius r.
r = float(input()) a = r**2 * 3.14 b = 2 * r * 3.14 print(a, b)
s211051893
Accepted
20
7,464
125
r = float(input()) area = r**2 * 3.141592653589 enshuu = r * 2 * 3.141592653589 print("{0:.6f} {1:.6f}".format(area, enshuu))
s154479238
p04045
u297651868
2,000
262,144
Wrong Answer
18
3,064
537
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.
ints= list(map(int, input().split())) li = list(map(int,input().split())) number = {0,1,2,3,4,5,6,7,8,9} dislike = set(li) like = number - dislike price = [int(i) for i in str(ints[0])] length = len(price) for i in range(length)[::-1]: if price[i] not in like: for j in like: if j > price[i]: price[i] = j else: price[i-1] = price[i-1]+1 for j in like: if j >= 0: price[i] = j for i in range(length): print(price[i], end="")
s567937963
Accepted
226
3,064
390
ints = list(map(int, input().split())) li = list(map(int, input().split())) number = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} dislike = set(li) like = number - dislike for i in range(ints[0], 100000): flag = 0 price = [int(j) for j in str(i)] length = len(price) for k in range(length): if price[k] in like: flag += 1 if flag == length: break print(i)
s361132423
p02269
u986478725
2,000
131,072
Wrong Answer
20
5,600
640
Your task is to write a program of a simple _dictionary_ which implements the following instructions: * **insert _str_** : insert a string _str_ in to the dictionary * **find _str_** : if the distionary contains _str_ , then print 'yes', otherwise print 'no'
# ALDS1_4_C. def get_key(_str): key = 0 for i in range(len(_str)): if _str[i] == 'A': key += 0 elif _str[i] == 'C': key += 1 elif _str[i] == 'D': key += 2 elif _str[i] == 'G': key += 3 key *= 4 return key def main(): n = int(input()) for i in range(n): dict = {} command = input() if command[0] == 'i': dict[get_key(command[1])] = command[1] else: key = get_key(command[1]) if key in dict: print('yes') else: print('no') if __name__ == "__main__": main()
s907708850
Accepted
7,840
41,812
648
# ALDS1_4_C. def get_key(_str): key = 0 for i in range(len(_str)): if _str[i] == 'A': key += 1 elif _str[i] == 'C': key += 2 elif _str[i] == 'G': key += 3 elif _str[i] == 'T': key += 4 key *= 5 return key def main(): n = int(input()) dict = {} for i in range(n): command = input().split() if command[0][0] == 'i': dict[get_key(command[1])] = command[1] else: key = get_key(command[1]) if key in dict: print('yes') else: print('no') if __name__ == "__main__": main()
s145695120
p03623
u469953228
2,000
262,144
Wrong Answer
17
2,940
63
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b = map(int,input().split()) print(min(abs(a-x),abs(b-x)))
s218157032
Accepted
17
2,940
89
x,a,b = map(int,input().split()) if abs(a-x) < abs(b-x): print("A") else: print("B")
s133535584
p03196
u888092736
2,000
1,048,576
Wrong Answer
100
3,564
348
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.
from collections import defaultdict def factor(x): res = defaultdict(int) for i in range(2, int(x ** 0.5) + 1): while x % i == 0: res[i] += 1 x //= i if x > 1: res[x] += 1 return res n, p = map(int, input().split()) ans = 1 for k, v in factor(p).items(): ans *= k * (v // n) print(ans)
s009757027
Accepted
101
3,316
349
from collections import defaultdict def factor(x): res = defaultdict(int) for i in range(2, int(x ** 0.5) + 1): while x % i == 0: res[i] += 1 x //= i if x > 1: res[x] += 1 return res n, p = map(int, input().split()) ans = 1 for k, v in factor(p).items(): ans *= k ** (v // n) print(ans)
s697920034
p02608
u238084414
2,000
1,048,576
Wrong Answer
118
21,432
483
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).
import itertools N = int(input()) n = int(N ** (1/2)) C = itertools.combinations_with_replacement(range(1, n + 1), 3) ans = [0 for i in range(N)] x, y, z = 1, 1, 1 def check(c): x, y, z = c global N t = x * x + y * y + z * z + x * y + y * z + z * x if t > N: return if x == y and y == z: ans[t - 1] += 1 elif x == y and y != z or y == z and z != x or z == x and x != y: ans[t - 1] += 3 else: ans[t - 1] += 6 for c in list(C): check(c) print(ans)
s510027608
Accepted
129
21,680
497
import itertools N = int(input()) n = int(N ** (1/2)) C = itertools.combinations_with_replacement(range(1, n + 1), 3) ans = [0 for i in range(N)] x, y, z = 1, 1, 1 def check(c): x, y, z = c global N t = x * x + y * y + z * z + x * y + y * z + z * x if t > N: return if x == y and y == z: ans[t - 1] += 1 elif x == y and y != z or y == z and z != x or z == x and x != y: ans[t - 1] += 3 else: ans[t - 1] += 6 for c in list(C): check(c) for a in ans: print(a)
s058049114
p03635
u314238753
2,000
262,144
Wrong Answer
17
2,940
53
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
S=input() f=S[0] l=S[-1] m=len(S)-2 print(f+str(m)+l)
s621839608
Accepted
17
2,940
49
n, m=input().split() print((int(n)-1)*(int(m)-1))
s602134086
p03567
u626881915
2,000
262,144
Wrong Answer
17
3,060
267
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
s = input() i = 0 j = len(s)-1 ist = 0 while i < j: if s[i] == s[j]: i += 1 j -= 1 elif s[i] == 'x': ist += 1 i += 1 elif s[j] == 'x': ist += 1 j -= 1 else: print(-1) exit() print(ist)
s581834730
Accepted
17
2,940
73
s = input() if s.find("AC") >= 0: print("Yes") else: print("No")
s319869515
p03469
u249727132
2,000
262,144
Wrong Answer
18
2,940
75
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.
a, b, c = map(int, input().split("/")) a = 2018 print("%d/%d/%d"%(a, b, c))
s475461173
Accepted
17
2,940
32
print("2018/01/" + input()[-2:])
s616328850
p03150
u640922335
2,000
1,048,576
Wrong Answer
17
3,064
434
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
S=input() length=len(S) ans='NO' if S[0:7]=='keyence': ans='Yes' elif S[-7:]=='keyence': ans='Yes' elif S[0]=='k' and S[-6:]=='eyence': ans='Yes' elif S[0:2]=='ke' and S[-5:]=='yence': ans='Yes' elif S[0:3]=='key' and S[-4:]=='ence': ans='Yes' elif S[0:4]=='keye' and S[-3:]=='nce': ans='Yes' elif S[0:5]=='keyen' and S[-2:]=='ce': ans='Yes' elif S[0:6]=='keyenc' and S[-1:]=='e': ans='yes' print(ans)
s657553470
Accepted
18
2,940
122
S = input() N = len(S) for i in range(7+1): if S[:i] + S[i+N-7:] == "keyence": print("YES") exit() print("NO")
s511571854
p04012
u810978770
2,000
262,144
Wrong Answer
27
3,444
156
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
from collections import Counter s = input() c = Counter(list(s)) for word , cnt in c.most_common(): if cnt % 2 !=0: print('NO') exit() print('YES')
s896230282
Accepted
21
3,316
151
from collections import Counter w = input() ww = Counter(w) ans = "Yes" for i in ww: if ww[i] % 2 != 0: ans = "No" break print(ans)
s770730677
p03024
u548901652
2,000
1,048,576
Wrong Answer
17
2,940
146
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
# -*- coding: utf-8 -*- s= input() day= len(s) win = s.count('o') possibility=day+win if possibility >= 8: print('Yes') else: print('No')
s239267446
Accepted
17
2,940
149
# -*- coding: utf-8 -*- s= input() day= len(s) win = s.count('o') possibility=15-day+win if possibility >= 8: print('YES') else: print('NO')
s832182943
p03699
u580316619
2,000
262,144
Wrong Answer
37
9,180
184
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
n=int(input()) s=[int(input()) for _ in range(n)] ans=0 for i in range(n): for j in range(i,n): a=sum(s[:i])+sum(s[j:]) print(a) if a>ans and a%10: ans=a print(ans)
s030267911
Accepted
35
9,080
171
n=int(input()) s=[int(input()) for _ in range(n)] ans=0 for i in range(n): for j in range(i,n): a=sum(s[:i])+sum(s[j:]) if a>ans and a%10: ans=a print(ans)
s383696497
p03434
u205580583
2,000
262,144
Wrong Answer
17
3,060
195
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()) a = list(map(int,input().split())) alice = 0 bob = 0 a.reverse() for i in range(n): if i % 2 == 0: alice += a[i] else: bob += a[i] print(alice - bob)
s275951510
Accepted
17
3,060
206
n = int(input()) a = list(map(int,input().split())) alice = 0 bob = 0 a.sort(reverse = True) for i in range(n): if i % 2 == 0: alice += a[i] else: bob += a[i] print(alice - bob)
s268333707
p03068
u239528020
2,000
1,048,576
Wrong Answer
17
3,060
173
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
N = int(input()) S = input() K = int(input()) S_list = list(S) moji = S_list[K-1] for i in range(len(S_list)): if S_list[i]!=moji: S_list[i]="*" print(S_list)
s747844916
Accepted
17
3,060
182
N = int(input()) S = input() K = int(input()) S_list = list(S) moji = S_list[K-1] for i in range(len(S_list)): if S_list[i]!=moji: S_list[i]="*" print("".join(S_list))
s952353078
p03719
u272522520
2,000
262,144
Wrong Answer
17
2,940
89
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c = map(int, input().split()) if a <= c <= b: print("YES") else: print("NO")
s148901878
Accepted
17
2,940
89
a,b,c = map(int, input().split()) if a <= c <= b: print("Yes") else: print("No")
s136646026
p03795
u488417454
2,000
262,144
Wrong Answer
17
2,940
60
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 print(x-y)
s639856756
Accepted
17
2,940
68
N = int(input()) x = N * 800 y = (int)(N / 15) * 200 print(x-y)
s692315130
p02795
u106049424
2,000
1,048,576
Wrong Answer
17
2,940
123
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()) if h>w: nBig = h else: nBig = w ans = int(n/nBig) print(ans)
s675819889
Accepted
17
2,940
170
h = int(input()) w = int(input()) n = int(input()) if h>w: nBig = h else: nBig = w if n%nBig == 0: ans = int(n/nBig) else: ans = int(n/nBig)+1 print(ans)
s282203432
p03079
u921773161
2,000
1,048,576
Wrong Answer
17
2,940
84
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
a,b,c = map(int, input().split()) if a == b == c: print('Yse') else: print('No')
s195428635
Accepted
17
2,940
84
a,b,c = map(int, input().split()) if a == b == c: print('Yes') else: print('No')
s583113680
p02936
u993435350
2,000
1,048,576
Wrong Answer
1,636
226,392
503
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.
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) N,Q = map(int, input().split()) tree = [[] for _ in range(N)] for i in range(N - 1): a,b = map(int, input().split()) a -= 1 b -= 1 if a > b: a,b = b,a tree[a].append(b) print(tree) ans = [0] * N for i in range(Q): p,x = map(int, input().split()) ans[p - 1] += x def dfs(cur, par): for chl in tree[cur]: if chl == par: continue ans[chl] += ans[cur] dfs(chl,cur) dfs(0, -1) print(*ans)
s831533567
Accepted
1,733
230,960
483
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) N,Q = map(int, input().split()) tree = [[] for _ in range(N)] for i in range(N - 1): a,b = map(int, input().split()) a -= 1 b -= 1 tree[a].append(b) tree[b].append(a) ans = [0] * N for i in range(Q): p,x = map(int, input().split()) ans[p - 1] += x def dfs(cur, par): for chl in tree[cur]: if chl == par: continue ans[chl] += ans[cur] dfs(chl,cur) dfs(0, -1) print(*ans)
s213115623
p02841
u040320709
2,000
1,048,576
Wrong Answer
18
2,940
99
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
a,b=map(int, input().split()) c,d=map(int, input().split()) if a != b: print(1) else: print(0)
s772301489
Accepted
17
2,940
100
a,b=map(int, input().split()) c,d=map(int, input().split()) if a != c: print(1) else: print(0)
s297322484
p03485
u929793345
2,000
262,144
Wrong Answer
27
9,084
60
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = map(int, input().split()) ans = (a+b)//2+1 print(ans)
s644042726
Accepted
27
9,064
109
a, b = map(int,input().split()) if (a+b) % 2 == 0: ans = (a+b) // 2 else: ans = (a+b) // 2 + 1 print(ans)
s346301385
p00479
u392445270
8,000
131,072
Wrong Answer
30
7,732
702
JOI 高校では, 1 × 1 の正方形のタイルを使って N × N の正方形の壁画を作り,文化祭で展示することになった.タイルの色は,赤,青,黄の 3 種類である.壁画のデザインは次の通りである.まず,最も外側の周に赤のタイルを貼り,その内側の周に青のタイルを貼る.さらにその内側の周に黄色のタイルを貼る.これを N × N の正方形が埋め尽くされるまで繰り返す.用いるタイルの色は,一番外側の周から順番に赤,青,黄,赤,青,黄,…である. 文化祭が近づいてきたある日,壁画のうち K 枚のタイルがはがれていることが判明した.そこで,新しいタイルを購入して,はがれた箇所に新しいタイルを貼ることにした. 入力として壁画の一辺の長さ N と,はがれたタイルの枚数 K, K 枚のはがれたタイルの位置が与えられたとき,はがれたタイルの色を求めるプログラムを作成せよ. 例えば,N = 11 の場合,11 × 11 の壁画のデザインは下図の通りである. また,N = 16 の場合,16 × 16 の壁画のデザインは下図の通りである.
import sys def find_color(n, ai, bi): color = (3, 1, 2) if n % 2 != 0: if ai > int((n+1)/2): ai = int((n+1)/2) - (ai - int((n+1)/2)) if bi > int((n+1)/2): bi = int((n+1)/2) - (bi - int((n+1)/2)) else: if ai > int(n/2): ai = int(n/2) - (ai - int(n/2)) + 1 if bi > int(n/2): bi = int(n/2) - (bi - int(n/2)) + 1 print(ai, bi) if bi >= ai and bi <= n - ai: return color[ai % 3] else: return color[bi % 3] n = int(sys.stdin.readline()) k = int(sys.stdin.readline()) for i in range(0, k): ai, bi = (int(x) for x in sys.stdin.readline().split()) print(find_color(n, ai, bi))
s343462014
Accepted
20
7,776
683
import sys def find_color(n, ai, bi): color = (3, 1, 2) if n % 2 != 0: if ai > int((n+1)/2): ai = int((n+1)/2) - (ai - int((n+1)/2)) if bi > int((n+1)/2): bi = int((n+1)/2) - (bi - int((n+1)/2)) else: if ai > int(n/2): ai = int(n/2) - (ai - int(n/2)) + 1 if bi > int(n/2): bi = int(n/2) - (bi - int(n/2)) + 1 if bi >= ai and bi <= n - ai: return color[ai % 3] else: return color[bi % 3] n = int(sys.stdin.readline()) k = int(sys.stdin.readline()) for i in range(0, k): ai, bi = (int(x) for x in sys.stdin.readline().split()) print(find_color(n, ai, bi))
s267069005
p03479
u923659712
2,000
262,144
Wrong Answer
17
2,940
74
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
a,b=map(int,input().split()) ans=0 while b>a: a*=2 ans+=1 print(ans-1)
s943673282
Accepted
18
3,188
73
a,b=map(int,input().split()) ans=0 while b>=a: a*=2 ans+=1 print(ans)
s521009783
p03415
u623687794
2,000
262,144
Wrong Answer
17
2,940
39
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.
for i in range(3): print(input()[i])
s627109831
Accepted
17
2,940
76
a=[] for i in range(3): a.append(input()) print(a[0][0]+a[1][1]+a[2][2])
s996196224
p02613
u672316981
2,000
1,048,576
Wrong Answer
162
16,032
555
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) s_lst = list(str(input()) for _ in range(n)) count_lst = [0, 0, 0, 0] for i in range(n): consequence = s_lst[i] if consequence == 'AC': count_lst[0] += 1 elif consequence == 'WA': count_lst[1] += 1 elif consequence == 'TLE': count_lst[2] += 1 else: count_lst[3] += 1 consequence_lst = ['AC x {}'.format(count_lst[0]), 'WA x {}'.format(count_lst[1]), 'TLE x {}'.format(count_lst[2]), 'RE x {}'.format(count_lst[3])] for i in range(4): con = consequence_lst[i] print(con)
s296593087
Accepted
164
16,200
549
n = int(input()) s_lst = list(str(input()) for _ in range(n)) count_lst = [0, 0, 0, 0] for i in range(n): consequence = s_lst[i] if consequence == 'AC': count_lst[0] += 1 elif consequence == 'WA': count_lst[1] += 1 elif consequence == 'TLE': count_lst[2] += 1 else: count_lst[3] += 1 consequence_lst = ['AC x {}'.format(count_lst[0]), 'WA x {}'.format(count_lst[1]), 'TLE x {}'.format(count_lst[2]), 'RE x {}'.format(count_lst[3])] for i in range(4): con = consequence_lst[i] print(con)
s382896497
p03081
u611782980
2,000
1,048,576
Wrong Answer
422
39,348
287
There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
n, q = map(int, input().split()) s = input() tds = [input().split() for _ in range(q)] tds.reverse() l = 0 r = n - 1 for t, d in tds: if s[l] == t and d == "L": l += 1 elif s[r] == t and d == "R": r -= 1 if l > r: break print(l, r) print(r - l + 1)
s739366145
Accepted
566
39,348
423
# -*- coding: utf-8 -*- n, q = map(int, input().split()) s = input() tds = [input().split() for _ in range(q)] tds.reverse() l = 0 r = n - 1 for t, d in tds: if s[l] == t and d == "L": l += 1 if l > 0 and s[l - 1] == t and d == "R": l -= 1 if s[r] == t and d == "R": r -= 1 if r < n - 1 and s[r + 1] == t and d == "L": r += 1 if l > r: break print(r - l + 1)
s047245700
p04000
u667084803
3,000
262,144
Wrong Answer
3,201
791,984
585
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 sys H, W, N = map(int,input().split()) if N ==0: print((H-1)*(W-1)) for i in range(9): print(0) sys.exit() blacks = [[0 for i in range(W+2)] for j in range(H+2)] for i in range(N): a, b = map(int,input().split()) blacks[a-1][b-1] +=1 blacks[a-1][b] +=1 blacks[a-1][b+1] +=1 blacks[a][b+1] +=1 blacks[a][b-1] +=1 blacks[a][b] +=1 blacks[a+1][b+1] +=1 blacks[a+1][b-1] +=1 blacks[a+1][b] +=1 ans =[0 for i in range(10)] for j in range(2,H): for i in range(2,W): print(j,i,blacks[j][i]) ans[blacks[j][i]]+=1 for i in range(10): print(ans[i])
s203010137
Accepted
2,345
166,868
400
from collections import defaultdict H, W, N = map(int,input().split()) ans = [(H-2)*(W-2)] + [0]*9 blacks = defaultdict(int) for i in range(N): a, b = map(int,input().split()) for dx in [-1,0,1]: for dy in [-1,0,1]: if 2 <= a+dx <H and 2 <= b+dy <W: ans[blacks[(a+dx,b+dy)]]-=1 ans[blacks[(a+dx,b+dy)]+1]+=1 blacks[(a+dx,b+dy)]+=1 print(*ans,sep="\n")
s606098749
p03433
u853010060
2,000
262,144
Wrong Answer
17
2,940
92
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) A = int(input()) if (N-A)%500 == 0: print("YES") else: print("NO")
s226134619
Accepted
17
2,940
126
N = int(input()) A = int(input()) for a in range(A+1): if (N-a)%500 == 0: print("Yes") exit() print("No")
s649666824
p02659
u657901243
2,000
1,048,576
Wrong Answer
22
9,080
59
Compute A \times B, truncate its fractional part, and print the result as an integer.
a, b = map(float, input().split()) print(a * b * 10 // 10)
s637952785
Accepted
20
9,172
162
a, b = input().split() a = int(a) bTop, bBottom = map(int, b.split('.')) s = str(a * (bTop * 100 + bBottom)) if len(s) <= 2: print(0) else: print(s[:-2])
s251645292
p03693
u416223629
2,000
262,144
Wrong Answer
17
2,940
120
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
a = list(map(int,input().split())) r=a[0] g=a[1] b=a[2] if (r*100+g*10+b)%4==0: print('yes') else: print('no')
s562240264
Accepted
17
2,940
120
a = list(map(int,input().split())) r=a[0] g=a[1] b=a[2] if (r*100+g*10+b)%4==0: print('YES') else: print('NO')
s281003886
p02747
u062491608
2,000
1,048,576
Wrong Answer
18
3,188
171
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
import re S = input().lower() # if len(S) >= 1 and len(S) <= 10: # print(S) i = 1 while i <= 5: if S == ("hi" * i): print("yes") break i += 1 print("no")
s177067425
Accepted
21
3,188
131
import re S = input() hslist = ["hi","hihi","hihihi","hihihihi","hihihihihi"] if S in hslist: print("Yes") else: print("No")
s806417185
p03573
u027403702
2,000
262,144
Wrong Answer
17
2,940
179
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
A,B,C = map(int, input().split()) # A = int(input()) # B = int(input()) # C = int(input()) # X = input() if A == B: print("C") elif A == C: print("B") else: print("A")
s401071468
Accepted
17
2,940
173
A,B,C = map(int, input().split()) # A = int(input()) # B = int(input()) # C = int(input()) # X = input() if A == B: print(C) elif A == C: print(B) else: print(A)
s165079672
p03339
u519130434
2,000
1,048,576
Wrong Answer
2,107
3,668
294
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()) people = input() counts = [] for n in range(N): count = 0 for i in range(N): if i == n: continue if n<i and people[i]=='E': count +=1 if n>i and people[i]=='W': count +=1 counts.append(count) min(counts)
s556101560
Accepted
184
15,520
293
N = int(input()) people = input() count = 0 for i in range(1, N): if people[i] == 'E': count += 1 counts = [count] for i in range(1, N): if people[i - 1] == 'W': count += 1 if people[i] == 'E': count -= 1 counts.append(count) print(min(counts))
s927939570
p03385
u286754585
2,000
262,144
Wrong Answer
18
2,940
47
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
print ("yes" if len(set(input()))==3 else "No")
s280563550
Accepted
24
2,940
47
print ("Yes" if len(set(input()))==3 else "No")
s117787971
p02612
u694380052
2,000
1,048,576
Wrong Answer
25
9,064
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n=int(input()) k=n%1000 print(k)
s241036770
Accepted
29
9,088
65
n=int(input()) k=n%1000 if k!=0: print(1000-k) else: print(k)
s909426626
p03227
u052347048
2,000
1,048,576
Wrong Answer
17
2,940
67
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
a = input() print(str(sorted(a,reverse=True)) if len(a) > 2 else a)
s338074755
Accepted
17
2,940
61
a = input();print("".join(reversed(a)) if len(a) == 3 else a)
s728453208
p02678
u038404105
2,000
1,048,576
Wrong Answer
2,206
25,984
537
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
N, M = map(int, input().split()) A = [0]*(M+1) B = [1]*(M+1) Dist = [1000000]*(N+1) Flug = [0]*(N+1) Dist[0] = 0 for i in range(1,M+1): c1, c2 =map(int, input().split()) A[i] = min(c1,c2) B[i] = max(c1,c2) for j in range(N): for i in range(M+1): if Dist[A[i]] == j and Dist[B[i]] > j: Dist[B[i]] = j+1 Flug[B[i]] = A[i] elif Dist[B[i]] == j and Dist[A[i]] > j: Dist[A[i]] = j+1 Flug[A[i]] = B[i] print('yes') for i in range(1,N+1): print(Flug[i])
s782640272
Accepted
698
34,228
529
from collections import deque N, M = map(int, input().split()) to = [[] for i in range(N+1)] flug = [0 for i in range(N+1)] to[0].append(1) #dist[0] = 0 for i in range(M): a, b = map(int, input().split()) to[a].append(b) to[b].append(a) q = deque([0]) while (len(q) != 0): i = q.popleft() for j in to[i]: if flug[j] == 0: # dist[j] = dist[i] +1 flug[j] = i q.append(j) print("Yes") for i in range(2,N+1): print(flug[i])
s073059720
p03998
u789364190
2,000
262,144
Wrong Answer
38
3,064
613
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
Sa = input() Sb = input() Sc = input() ia = -1 ib = -1 ic = -1 last = 'a' res = 'A' for i in range(len(Sa) + len(Sb) + len(Sc) + 3): if last == 'a': ia += 1 if (ia >= len(Sa)): res = 'A' break last = Sa[ia] print('A: ' + last) elif last == 'b': ib += 1 if (ib >= len(Sb)): res = 'B' break last = Sb[ib] print('B: ' + last) elif last == 'c': ic += 1 if (ic >= len(Sc)): res = 'C' break last = Sc[ic] print('C: ' + last) print(res)
s206245151
Accepted
41
3,064
695
Sa_str = input() Sb_str = input() Sc_str = input() Sa = [] Sb = [] Sc = [] for i in range(len(Sa_str)): Sa += [Sa_str[i]] for i in range(len(Sb_str)): Sb += [Sb_str[i]] for i in range(len(Sc_str)): Sc += [Sc_str[i]] last = 'a' res = 'A' for i in range(len(Sa) + len(Sb) + len(Sc) + 3): if last == 'a': if len(Sa) == 0: res = 'A' break last = Sa[0] Sa = Sa[1:] elif last == 'b': if len(Sb) == 0: res = 'B' break last = Sb[0] Sb = Sb[1:] elif last == 'c': if len(Sc) == 0: res = 'C' break last = Sc[0] Sc = Sc[1:] print(res)
s325112035
p03433
u198336369
2,000
262,144
Wrong Answer
28
9,096
103
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input()) a = int(input()) n_rem = n % 500 if n_rem <= a: print('YES') else: print('NO')
s972108962
Accepted
30
9,084
103
n = int(input()) a = int(input()) n_rem = n % 500 if n_rem <= a: print('Yes') else: print('No')
s375533095
p03623
u021548497
2,000
262,144
Wrong Answer
17
2,940
68
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x, a, b = map(int, input().split()) print(min([abs(x-a), abs(x-b)]))
s613517028
Accepted
17
2,940
91
x, a, b = map(int, input().split()) if abs(x-a) < abs(x-b): print("A") else: print("B")
s399214409
p03455
u121921603
2,000
262,144
Wrong Answer
17
2,940
104
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
import sys input = sys.stdin.readline a,b=map(int,input().split()) print("Odd" if a*b%2==0 else "Even")
s454758056
Accepted
17
2,940
104
import sys input = sys.stdin.readline a,b=map(int,input().split()) print("Odd" if a*b%2==1 else "Even")
s471627441
p03486
u503228842
2,000
262,144
Wrong Answer
17
2,940
120
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = sorted(input()) t = sorted(input(), reverse=True) print(s) print(t) if s < t: print('Yes') else: print('No')
s306163225
Accepted
17
2,940
103
s = sorted(input()) t = sorted(input(), reverse=True) if s < t: print('Yes') else: print('No')
s380994256
p03563
u499384645
2,000
262,144
Wrong Answer
17
2,940
59
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
r = input() g = input() b = float(g)*2.0-float(r) print(b)
s801590078
Accepted
17
2,940
83
import math r = input() g = input() b = float(g)*2.0-float(r) print(math.ceil(b))
s788265694
p03814
u766566560
2,000
262,144
Wrong Answer
20
3,640
70
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
import re s = input() res = re.search('A[A-Z]+Z', s) print(res.end())
s477999816
Accepted
21
3,644
84
import re s = input() res = re.search('A[A-Z]+Z', s) print(res.end() - res.start())
s047401395
p03761
u867848444
2,000
262,144
Wrong Answer
26
3,444
475
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.
from collections import Counter, defaultdict n = int(input()) s = [input() for i in range(n)] cnt = defaultdict(lambda :[0, 0]) for S in s: temp = Counter(S) for key, val in temp.items(): if cnt[key] == [0, 0]: cnt[key] = [val, 1] continue if cnt[key][0] > val:cnt[key][0] = val cnt[key][1] = cnt[key][1] + 1 ans = '' for key, val in cnt.items(): if val[1] == n: ans += key * val[0] print(ans) #print(cnt)
s447615498
Accepted
21
3,316
492
from collections import Counter, defaultdict n = int(input()) s = [input() for i in range(n)] cnt = defaultdict(lambda :[0, 0]) for S in s: temp = Counter(S) for key, val in temp.items(): if cnt[key] == [0, 0]: cnt[key] = [val, 1] continue if cnt[key][0] > val:cnt[key][0] = val cnt[key][1] = cnt[key][1] + 1 ans = [] for key, val in cnt.items(): if val[1] == n: ans += key * val[0] print(*sorted(ans), sep='') #print(cnt)
s842721480
p03448
u395202850
2,000
262,144
Wrong Answer
48
3,060
206
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a, b, c, x = [int(input()) for _ in range(4)] cnt = 0 for i in range(a): for j in range(b): for k in range(c): if a * 500 + b * 100 + c * 50 == x: cnt += 1 print(cnt)
s695390842
Accepted
18
3,060
263
a, b, c, x = [int(input()) for _ in range(4)] cnt = 0 for i in range(min(a, int(x/500)) + 1): for j in range(min(b, int((x - 500 * i)/100)) + 1): k = (x - 500 * i - 100 * j) if k % 50 == 0 and 0 <= k / 50 <= c: cnt += 1 print(cnt)
s296504037
p04043
u264265458
2,000
262,144
Wrong Answer
18
2,940
75
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.
print("YES" if sorted(list(map(int,input().split())))=="[5,5,7]" else "NO")
s891286110
Accepted
17
2,940
73
print("YES" if sorted(list(map(int,input().split())))==[5,5,7] else "NO")
s355420830
p03679
u652656291
2,000
262,144
Wrong Answer
17
2,940
132
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b = map(int,input().split()) if a+b <= x : print('delicious') elif x < a+b <= x+1: print('safe') else: print('dangerous')
s526761243
Accepted
18
2,940
151
x, a, b = map(int, input().split()) if a - b >= 0: print('delicious') exit() if a - b + x >= 0: print('safe') else: print('dangerous')
s532145081
p00004
u454259029
1,000
131,072
Wrong Answer
30
7,336
193
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
a,b,c,d,e,f = map(float,input().split(" ")) x,y = 0,0 float(x) float(y) x = (e*c-b*f) / (a*e-b*d) y = ((-(d*c)+a*f) / (a*e-b*d)) print("%.3f" %(x), end="") print(" ", end="") print("%.3f" %(y))
s800962440
Accepted
30
7,320
268
while(True): try: a,b,c,d,e,f=map(float,input().split(" ")) z=a*e-b*d if(z!=0): x=(c*e-b*f)/z y=(a*f-c*d)/z print("{:.3f} {:.3f}".format(x+0,y+0)) except: break
s941171661
p03339
u434872492
2,000
1,048,576
Wrong Answer
906
21,620
374
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 = input() W=[0]*N w = 0 for i in range(N): if S[i] == "W": w += 1 W[i] = w E = [0]*N e = 0 for i in range(N): if S[N-1-i] == "E": e += 1 E[N-1-i] = e ans = 10**9 for i in range(N): count = W[i] + E[i] ans = min(ans,count) print(W[i],end=":") print(E[i]) print(ans-1)
s058842845
Accepted
324
17,644
334
N = int(input()) S = input() W=[0]*N w = 0 for i in range(N): if S[i] == "W": w += 1 W[i] = w E = [0]*N e = 0 for i in range(N): if S[N-1-i] == "E": e += 1 E[N-1-i] = e ans = 10**9 for i in range(N): count = W[i] + E[i] ans = min(ans,count) print(ans-1)
s780687063
p03721
u157232135
2,000
262,144
Wrong Answer
2,258
1,729,932
236
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.
def main(): n,k=map(int,input().split()) arr = [] for _ in range(n): a,b=map(int,input().split()) arr.extend([a]*b) arr.sort() print(arr) print(arr[k-1]) if __name__ == "__main__": main()
s020535425
Accepted
382
16,956
314
def main(): n,k=map(int,input().split()) arr = [] for _ in range(n): a,b=map(int,input().split()) arr.append((a, b)) arr.sort() for x, c in arr: if k <= c: print(x) break else: k -= c if __name__ == "__main__": main()
s807017392
p04029
u515647766
2,000
262,144
Wrong Answer
17
2,940
74
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?
def total(n): return 1/2 * n * (n + 1) n = int(input()) print(total(n))
s257569919
Accepted
17
2,940
80
def total(n): return int(1/2 * n * (n + 1)) n = int(input()) print(total(n))