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
s329520151
p03556
u411278350
2,000
262,144
Wrong Answer
17
2,940
56
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
N = int(input()) N_s = (N ** (1/2)) // 1 print(N_s ** 2)
s343515257
Accepted
38
2,940
131
N = int(input()) ans = 1 for i in range(1, N): if ans <= i ** 2 <= N: ans = i ** 2 else: break print(ans)
s195794975
p03693
u373047809
2,000
262,144
Wrong Answer
17
2,940
56
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?
print("YENOS"[max(int(input().replace(" ",""))%4,1)::2])
s678321021
Accepted
17
2,940
40
print("YNEOS"[int(input()[::2])%4>0::2])
s754060924
p03777
u329058683
2,000
262,144
Wrong Answer
17
2,940
69
Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest.
L=list(input().split()) if set(L)==2: print("H") else: print("D")
s883220956
Accepted
17
2,940
60
A,B=input().split() if A==B: print("H") else: print("D")
s266196609
p00049
u821624310
1,000
131,072
Wrong Answer
20
7,328
345
ある学級の生徒の出席番号と ABO 血液型を保存したデータを読み込んで、おのおのの血液型の人数を出力するプログラムを作成してください。なお、ABO 血液型には、A 型、B 型、AB 型、O 型の4種類の血液型があります。
import sys A = 0 B = 0 AB = 0 O = 0 for line in sys.stdin: if line == "\n": break No, b_type = line.rstrip().split(",") print(No, b_type) if b_type == "A": A += 1 elif b_type == "B": B += 1 elif b_type == "AB": AB += 1 else: O += 1 print(A) print(B) print(AB) print(O)
s942819132
Accepted
20
7,300
238
import sys blood = {"A": 0, "B": 0, "AB": 0, "O": 0} for line in sys.stdin: if line == "\n": break no, b = line.rstrip().split(",") blood[b] += 1 print(blood["A"]) print(blood["B"]) print(blood["AB"]) print(blood["O"])
s808004082
p04043
u506086925
2,000
262,144
Wrong Answer
17
2,940
124
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()) sn = [a,b,c] if sn.count(7)==1 and sn.count(5)==2: print("Yes") else: print("No")
s903411580
Accepted
17
2,940
124
a, b, c = map(int,input().split()) sn = [a,b,c] if sn.count(7)==1 and sn.count(5)==2: print("YES") else: print("NO")
s707524327
p03698
u640603056
2,000
262,144
Wrong Answer
21
3,316
142
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
from collections import Counter lst = list(input()) c = sorted(Counter(lst).values(), reverse=True) if c[0]==0: print("yes") else: print("no")
s348450953
Accepted
20
3,316
142
from collections import Counter lst = list(input()) c = sorted(Counter(lst).values(), reverse=True) if c[0]==1: print("yes") else: print("no")
s676078138
p03998
u827141374
2,000
262,144
Wrong Answer
17
3,064
428
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
A = [x for x in input()] B = [x for x in input()] C = [x for x in input()] next = 'a' while True: if next == 'a': next = A.pop(0) if len(A) == 0: print('A') break elif next == 'b': next = B.pop(0) if len(B) == 0: print('B') break elif next == 'c': next = C.pop(0) if len(C) == 0: print('C') break
s997759109
Accepted
17
3,064
428
A = [x for x in input()] B = [x for x in input()] C = [x for x in input()] next = 'a' while True: if next == 'a': if len(A) == 0: print('A') break next = A.pop(0) elif next == 'b': if len(B) == 0: print('B') break next = B.pop(0) elif next == 'c': if len(C) == 0: print('C') break next = C.pop(0)
s631602602
p03150
u580316619
2,000
1,048,576
Wrong Answer
29
9,084
142
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() ans='No' for i in range(1,len(s)): for j in range(i,len(s)): if s[:i]+s[j:]=='keyence': ans='Yes' break print(ans)
s209220544
Accepted
29
8,996
142
s=input() ans='NO' for i in range(1,len(s)): for j in range(i,len(s)): if s[:i]+s[j:]=='keyence': ans='YES' break print(ans)
s382831582
p03494
u259861571
2,000
262,144
Time Limit Exceeded
2,104
2,940
293
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = input() a = list(map(int, input().split())) count = 0 odd = "" while True: for i, n in enumerate(a): if n % 2 == 0: a[i] == n / 2 count += 1 else: odd = "finish" break if odd == "finish": break print(count)
s177787318
Accepted
20
2,940
198
n = input() a = list(map(int, input().split())) ans = a[0] for i in range(int(n)): count = 0 while(a[i] % 2 == 0): a[i] /= 2 count += 1 ans = min(ans, count) print(ans)
s684333289
p03494
u814986259
2,000
262,144
Wrong Answer
19
2,940
264
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())) flag = True ans = 0 while(1): for i in range(N): if A[i] % 2 != 0: flag = False break if flag: A = list(map(lambda x:x/2, A)) else: break print(ans)
s997863089
Accepted
19
3,060
281
N = int(input()) A = list(map(int, input().split())) flag = True ans = 0 while(1): for i in range(N): if A[i] % 2 != 0: flag = False break if flag: A = list(map(lambda x:x/2, A)) ans += 1 else: break print(ans)
s920746617
p02259
u821624310
1,000
131,072
Wrong Answer
20
7,580
219
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
N = int(input()) A = list(map(int, input().split())) n = N while n > 0: for i in range(N-1, 0, -1): if A[i] < A[i-1]: t = A[i] A[i] = A[i-1] A[i-1] = t n -= 1 print(A)
s644846010
Accepted
20
7,732
370
N = int(input()) A = [int(n) for n in input().split()] flg = 1 cnt = 0 while flg: flg = 0 for i in range(N-1, 0, -1): if A[i] < A[i-1]: t = A[i] A[i] = A[i-1] A[i-1] = t flg = 1 cnt += 1 for i in range(N): if i == N - 1: print(A[i]) else: print(A[i], end=" ") print(cnt)
s156860191
p03737
u027675217
2,000
262,144
Wrong Answer
17
2,940
47
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
a,b,c = input().split() print(a[0]+b[0]+c[0])
s518881801
Accepted
17
2,940
109
a,b,c = input().split() a_d=a.capitalize() b_d=b.capitalize() c_d=c.capitalize() print(a_d[0]+b_d[0]+c_d[0])
s760909041
p03067
u366269356
2,000
1,048,576
Wrong Answer
18
2,940
98
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 < c < b or b < c < a: print('yes') else: print('no')
s796402402
Accepted
17
2,940
133
A,B,C = map(int, input().split()) if A < C and C < B: print('Yes') elif A > C and C > B: print('Yes') else: print('No')
s521190140
p03598
u773865844
2,000
262,144
Wrong Answer
17
3,060
245
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.
import sys lines = sys.stdin.readlines() N = int(lines[0]) K = int(lines[1]) X = lines[2].split(' ') x =[] y = 0 for i in range(N): x.append(int(X[i])) if 2*x[i] >= K: dist = K-x[i] else: dist = x[i] y = y + dist print(y)
s144140647
Accepted
18
3,064
251
import sys lines = sys.stdin.readlines() N = int(lines[0]) K = int(lines[1]) X = lines[2].split(' ') x =[] y = 0 for i in range(N): x.append(int(X[i])) if 2*x[i] >= K: dist = 2*(K-x[i]) else: dist = 2*x[i] y = y + dist print(y)
s744068991
p03698
u509739538
2,000
262,144
Wrong Answer
22
3,444
2,587
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
import math from collections import deque from collections import defaultdict 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 s = readChar() d = defaultdict(int) for i in s: d[s]+=1 for i in d.values(): if i!=1: print("no") exit() print("yes")
s416648989
Accepted
23
3,444
2,587
import math from collections import deque from collections import defaultdict 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 s = readChar() d = defaultdict(int) for i in s: d[i]+=1 for i in d.values(): if i!=1: print("no") exit() print("yes")
s558048428
p02270
u022407960
1,000
131,072
Wrong Answer
20
7,720
1,428
In the first line, two integers $n$ and $k$ are given separated by a space character. In the following $n$ lines, $w_i$ are given respectively.
# encoding: utf-8 import sys import math class Solution: def __init__(self): """ init input array """ self.__input = sys.stdin.readlines() @property def solution(self): product_num = int(self.__input[0].split()[0]) truck_num = int(self.__input[0].split()[1]) weight_list = list(map(int, self.__input[1:])) assert product_num == len(weight_list) print(product_num, truck_num, weight_list) truck_capacity = max(math.ceil(sum(weight_list) / truck_num), max(weight_list)) return str(truck_capacity) # for each in array_2: # if self.allocation(key=each, array=weight_list, array_length=max(weight_list)): # truck_capacity += 1 # # return str(truck_capacity) # # @staticmethod # def allocation(key, array, array_length): # # print(len(set(array_1).intersection(set(array_2)))) # left, right = max(array), array_length # while left < right: # mid = (left + right) // 2 # if key == array[mid]: # return True # elif key < array[mid]: # right = mid # else: # left = mid + 1 # return False if __name__ == '__main__': case = Solution() print(case.solution)
s603226808
Accepted
260
18,596
1,376
# encoding: utf-8 import sys class Solution: def __init__(self): """ init input array """ self.__input = sys.stdin.readlines() @property def solution(self): product_num = int(self.__input[0].split()[0]) truck_num = int(self.__input[0].split()[1]) weight_list = list(map(int, self.__input[1:])) # binary search left, right, mid = max(weight_list), sum(weight_list), 0 while left < right: mid = (left + right) // 2 # check return True : p could be smaller if self.check(max_load_cursor=mid, weight_list=weight_list, truck_num=truck_num): right = mid else: mid += 1 left = mid return str(mid) @staticmethod def check(max_load_cursor, weight_list, truck_num): track_count = 1 current_load = 0 for item_weight in weight_list: current_load += item_weight # change to next truck if current_load > max_load_cursor: current_load = item_weight track_count += 1 if track_count > truck_num: return False return True if __name__ == '__main__': case = Solution() print(case.solution)
s778898068
p03680
u494748969
2,000
262,144
Wrong Answer
162
13,460
219
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
n = int(input()) a = [0] * n for i in range(n): a.append(int(input())) count = 0 num = 0 for i in range(n): num = a[num] count += 1 if num == 2: break if num != 2: count = -1 print(count)
s295551036
Accepted
165
13,044
217
n = int(input()) a = [] for i in range(n): a.append(int(input())) count = 0 num = 1 for i in range(n): num = a[num - 1] count += 1 if num == 2: break if num != 2: count = -1 print(count)
s590375864
p03795
u353919145
2,000
262,144
Wrong Answer
17
2,940
261
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()) can=n*800 p=n des=200 if n>=15 and n<30: total=can-200 elif n>=30 and n<45: total=can-400 elif n>=45 and n<60: total=can-600 elif n>=60 and n<75: total=can-800 elif n>=75 and n<90: total=can-1000 elif n>=90 and n<=100: total=can-1200
s811025024
Accepted
23
9,016
186
from sys import stdin, stdout def main() -> None: line = int(stdin.readline()) x = line * 800 tmp = line / 15 y = int(tmp) * 200 rta = x - y print(rta) main()
s816128702
p00014
u032662562
1,000
131,072
Wrong Answer
30
7,580
315
Write a program which computes the area of a shape represented by the following three lines: $y = x^2$ $y = 0$ $x = 600$ It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obtain an approximative area of the shape by adding up areas of many rectangles in the shape as shown in the following figure: $f(x) = x^2$ The approximative area $s$ where the width of the rectangles is $d$ is: area of rectangle where its width is $d$ and height is $f(d)$ $+$ area of rectangle where its width is $d$ and height is $f(2d)$ $+$ area of rectangle where its width is $d$ and height is $f(3d)$ $+$ ... area of rectangle where its width is $d$ and height is $f(600 - d)$ The more we decrease $d$, the higer-precision value which is close to $72000000$ we could obtain. Your program should read the integer $d$ which is a divisor of $600$, and print the area $s$.
def integral(d): print("d=%d" % d) n = 600//d print("n=%d" % n) s = 0.0 for i in range(n): s += (d*i)**2 return(s*d) if __name__ == '__main__': while True: try: d = int(input()) print(int(integral(d))) except: break
s522806639
Accepted
30
7,656
266
def integral(d): n = 600//d s = 0.0 for i in range(n): s += (d*i)**2 return(s*d) if __name__ == '__main__': while True: try: d = int(input()) print(int(integral(d))) except: break
s823592240
p03550
u843135954
2,000
262,144
Wrong Answer
18
3,188
275
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n,z,w = na() a = na() print(max(abs(a[-1]-w),abs(z-w)))
s460286295
Accepted
20
3,188
330
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n,z,w = na() a = na() if n == 1: print(abs(a[-1]-w)) exit() print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))
s733682162
p02669
u194472175
2,000
1,048,576
Wrong Answer
194
12,552
1,150
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.**
import sys import heapq from collections import deque T=int(input()) for t in range(T): N,A,B,C,D= map(int,input().split()) q = [(0,N)] heapq.heapify(q) seen=set() while q: cost,n = heapq.heappop(q) if n in seen: continue seen.add(n) if n==0: print(cost) break heapq.heappush(q,(cost+n*D,0)) if n%2==0: heapq.heappush(q,(cost+A,n//2)) else: heapq.heappush(q,(cost+D+A,(n+1)//2)) heapq.heappush(q,(cost+D+A,(n-1)//2)) if n%3==0: heapq.heappush(q,(cost+C,n//3)) else: rest=n % 3 heapq.heappush(q,(cost+rest*D+B,(n-rest+3)//3)) heapq.heappush(q,(cost+(3-rest)*D+B,(n-rest+3)//3)) if n % 5 ==0: heapq.heappush(q,(cost+C,n//5)) else: rest= n%5 heapq.heappush(q,(cost+rest*D+C,(n-rest)//5)) heapq.heappush(q,(cost+(5-rest)*D+C,(n-rest+5)//5))
s680384983
Accepted
174
12,816
998
import sys import heapq T = int(input()) from collections import deque for t in range(T): N,A,B,C,D = map(int,input().split()) q = [(0, N)] heapq.heapify(q) seen = set() while q: cost,n = heapq.heappop(q) if n in seen: continue seen.add(n) if n == 0: print(cost) break heapq.heappush(q, (cost + n * D, 0)) if n % 2 == 0: heapq.heappush(q, (cost + A, n // 2)) else: heapq.heappush(q, (cost + D + A, (n + 1) // 2)) heapq.heappush(q, (cost + D + A, (n - 1) // 2)) if n % 3 == 0: heapq.heappush(q, (cost + B, n // 3)) else: rest = n % 3 heapq.heappush(q, (cost + rest * D + B, (n - rest) // 3)) heapq.heappush(q, (cost + (3 - rest) * D + B, (n - rest + 3) // 3)) if n % 5 == 0: heapq.heappush(q, (cost + C, n // 5)) else: rest = n % 5 heapq.heappush(q, (cost + rest * D + C, (n - rest) // 5)) heapq.heappush(q, (cost + (5 - rest) * D + C, (n - rest + 5) // 5))
s498478248
p03352
u049354454
2,000
1,048,576
Time Limit Exceeded
2,104
3,064
453
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
# coding: utf-8 # Your code here! INPUT=int(input()) b=1 p=2 END=0 while True: while True: now_num = b**p if b == 1: end_num=now_num break elif p==2 and INPUT<now_num: END = 1 break elif INPUT < now_num: end_num = b**(p-1) break else: p+=1 if END == 1: ans=end_num break b+=1 print(ans)
s972279505
Accepted
18
3,060
314
from math import sqrt X=int(input()) sqrt_X=int(sqrt(X)) ans=1 for b in range(1,sqrt_X + 1): for p in range(2,sqrt_X+1): now_num = b**p if now_num <= X and ans <= now_num: ans =now_num print(ans)
s321071283
p02972
u672220554
2,000
1,048,576
Wrong Answer
875
16,820
477
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())) res = [0 for i in range(n)] for i in range(n,n//2,-1): res[i-1] = a[i-1] for i in range(n//2,0,-1): l = [] flag = 0 t = i*2 while t <= n: flag = flag ^ res[t-1] t = t+i if a[i-1] != flag: res[i-1] = 1 if res == [0 for i in range(n)]: print(0) else: lres = [] for i in range(n): if res[i] == 1: lres.append(str(i+1)) print(" ".join(lres))
s518409560
Accepted
450
17,212
422
def main(): n = int(input()) a = list(map(int,input().split())) res = [0 for i in range(n)] lres = [] for i in range(n,0,-1): flag = 0 t = i*2 while t <= n: flag = flag ^ res[t-1] t = t+i if a[i-1] != flag: res[i-1] = 1 lres.append(str(i)) print(len(lres)) if len(lres) != 0: print(" ".join(lres)) main()
s870342598
p03545
u876616721
2,000
262,144
Wrong Answer
18
3,064
579
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
x = input() #print(x) y = [int(c) for c in x] #print(y) a = y[0] b = y[1] c = y[2] d = y[3] if a+b+c+d == 7: print("a+b+c+d=",a+b+c+d,sep='') exit() if a+b+c-d == 7: print("a+b+c-d=",a+b+c-d,sep='') exit() if a+b-c+d == 7: print("a+b-c+d=",a+b-c+d,sep='') exit() if a-b+c+d == 7: print("a-b+c+d=",a-b+c+d,sep='') exit() if a-b-c+d == 7: print("a-b-c+d=",a-b-c+d,sep='') exit() if a-b+c-d == 7: print("a-b+c-d=",a-b+c-d,sep='') exit() if a-b-c-d == 7: print("a-b-c-d=",a-b-c-d,sep='') exit() if a+b-c-d == 7: print("a+b-c-d=",a+b-c-d,sep='') exit()
s424105742
Accepted
17
3,064
691
x = input() #print(x) y = [int(c) for c in x] #print(y) a = y[0] b = y[1] c = y[2] d = y[3] if a+b+c+d == 7: print(a,"+",b,"+",c,"+",d,"=",a+b+c+d, sep='') exit() if a+b+c-d == 7: print(a,"+",b,"+",c,"-",d,"=",a+b+c-d, sep='') exit() if a+b-c+d == 7: print(a,"+",b,"-",c,"+",d,"=",a+b-c+d, sep='') exit() if a-b+c+d == 7: print(a,"-",b,"+",c,"+",d,"=",a-b+c+d, sep='') exit() if a-b-c+d == 7: print(a,"-",b,"-",c,"+",d,"=",a-b-c+d, sep='') exit() if a-b+c-d == 7: print(a,"-",b,"+",c,"-",d,"=",a-b+c-d, sep='') exit() if a-b-c-d == 7: print(a,"-",b,"-",c,"-",d,"=",a-b-c-d, sep='') exit() if a+b-c-d == 7: print(a,"+",b,"-",c,"-",d,"=",a+b-c-d, sep='') exit()
s872629750
p03495
u268516119
2,000
262,144
Wrong Answer
190
39,292
239
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.
from collections import Counter as ct N,K=map(int,input().split()) A=[int(i) for i in input().split()] count=ct(A) div=len(count) if div<=K:print(0) else:print(sum([i[0] for i in sorted(count.items(),key= lambda x:x[1])[:div-K]]))
s900188916
Accepted
188
39,288
239
from collections import Counter as ct N,K=map(int,input().split()) A=[int(i) for i in input().split()] count=ct(A) div=len(count) if div<=K:print(0) else:print(sum([i[1] for i in sorted(count.items(),key= lambda x:x[1])[:div-K]]))
s687409363
p03386
u614181788
2,000
262,144
Wrong Answer
17
3,064
177
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()) aa = list(range(a,min(a+k,b))) bb = list(range(max(b-k+1,a),b+1)) aa.extend(bb) c = set(aa) d = list(c) for i in range(len(d)): print(d[i])
s530129514
Accepted
17
3,064
191
a,b,k = map(int,input().split()) aa = list(range(a,min(a+k,b))) bb = list(range(max(b-k+1,a),b+1)) aa.extend(bb) c = set(aa) d = list(c) d = sorted(d) for i in range(len(d)): print(d[i])
s550431972
p03025
u201234972
2,000
1,048,576
Wrong Answer
299
18,804
644
Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
def getInv(N): inv = [0] * (N + 1) inv[0] = 1 inv[1] = 1 for i in range(2, N + 1): inv[i] = (-(Q // i) * inv[Q%i]) % Q return inv Q = 10**9+7 N, A, B, C = map( int, input().split()) modinv = getInv( max(2*N-1, 100)) a = A*modinv[100]%Q b = B*modinv[100]%Q Powa = [1]*(N+1) Powb = [1]*(N+1) for i in range(N): Powa[i+1] = (Powa[i]*a)%Q Powb[i+1] = (Powb[i]*b)%Q t = 100*modinv[100-C]%Q ans = 0 nowc = 1 ans = Powa[N]*N + Powb[N]*N ans %= Q for k in range(N+1, N*2): nowc *= (k-1)*modinv[k-N] nowc %= Q ans += nowc*( Powa[N]*Powb[k-N] + Powb[N]*Powa[k-N])%Q*k%Q ans %= Q print(ans*t%Q)
s044024904
Accepted
296
18,804
644
def getInv(N): inv = [0] * (N + 1) inv[0] = 1 inv[1] = 1 for i in range(2, N + 1): inv[i] = (-(Q // i) * inv[Q%i]) % Q return inv Q = 10**9+7 N, A, B, C = map( int, input().split()) modinv = getInv( max(2*N-1, 100)) a = A*modinv[A+B]%Q b = B*modinv[A+B]%Q Powa = [1]*(N+1) Powb = [1]*(N+1) for i in range(N): Powa[i+1] = (Powa[i]*a)%Q Powb[i+1] = (Powb[i]*b)%Q t = 100*modinv[100-C]%Q ans = 0 nowc = 1 ans = Powa[N]*N + Powb[N]*N ans %= Q for k in range(N+1, N*2): nowc *= (k-1)*modinv[k-N] nowc %= Q ans += nowc*( Powa[N]*Powb[k-N] + Powb[N]*Powa[k-N])%Q*k%Q ans %= Q print(ans*t%Q)
s241955345
p03861
u368882459
2,000
262,144
Wrong Answer
17
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//x-a//x)
s589895380
Accepted
17
2,940
56
a, b, x = map(int, input().split()) print(b//x-(a-1)//x)
s262190493
p04011
u209619667
2,000
262,144
Wrong Answer
18
2,940
150
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) s = 0 for n in range(N): if n <= K: s = s + X else: s = s + Y print(s)
s676883791
Accepted
19
2,940
154
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) s = 0 for n in range(1,N+1): if n <= K: s = s + X else: s = s + Y print(s)
s682862262
p03359
u993461026
2,000
262,144
Wrong Answer
17
2,940
68
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a, b = map(int, input().rstrip().split()) print(a if a < b else a-1)
s175613052
Accepted
17
2,940
69
a, b = map(int, input().rstrip().split()) print(a if a <= b else a-1)
s829483684
p03657
u373593739
2,000
262,144
Wrong Answer
17
2,940
157
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
def biscoitos(): A = input() B = input() soma = int(A)+int(B) if soma%3 == 0: print('Possible') else: print('Impossible')
s824039851
Accepted
17
3,060
185
A, B = map(int,input().split()) soma = A+B if A%3 == 0: print('Possible') elif B%3 == 0: print ('Possible') elif soma%3 == 0: print('Possible') else: print('Impossible')
s594939669
p00001
u422087503
1,000
131,072
Wrong Answer
30
7,376
98
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
h = [] for i in range(10): h.append(input()) h.sort(reverse=True) for i in range(3): print(h[i])
s927324921
Accepted
20
7,684
103
h = [] for i in range(10): h.append(int(input())) h.sort(reverse=True) for i in range(3): print(h[i])
s864520673
p03860
u782654209
2,000
262,144
Wrong Answer
17
2,940
30
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
print('A'+str(input())[0]+'C')
s410490992
Accepted
17
2,940
54
print('A'+list(map(str,input().split(' ')))[1][0]+'C')
s668315648
p03644
u819208902
2,000
262,144
Wrong Answer
18
2,940
100
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
if __name__ == '__main__': n = int() i = 1 while i * 2 < n: i *= 2 print(i)
s995517123
Accepted
18
3,064
108
if __name__ == '__main__': n = int(input()) i = 1 while i * 2 <= n: i *= 2 print(i)
s453040796
p03719
u797550216
2,000
262,144
Wrong Answer
17
2,940
95
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c = map(int,input().split()) if a >= c and c <= b: print('Yes') else: print('No')
s590340481
Accepted
17
2,940
95
a,b,c = map(int,input().split()) if c >= a and c <= b: print('Yes') else: print('No')
s199403725
p03407
u969190727
2,000
262,144
Wrong Answer
17
2,940
63
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
a,b,c=map(int,input().split()) print("Yes" if a+b<=c else "No")
s067086011
Accepted
17
2,940
63
a,b,c=map(int,input().split()) print("Yes" if a+b>=c else "No")
s898998826
p02608
u664652017
2,000
1,048,576
Wrong Answer
2,205
9,132
410
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).
def fx(n): cnt = 0 for i in range(1,10000): if (i+1+1)**2 - i*1 - 1*1 - 1*i > n: break for j in range(1, 10000): if (1+j+1)**2 - 1*j - j*1 - 1*1 > n : break for k in range(1, 10000): formula = (i+j+k)**2 - i*j - j*k - k*i if formula == n: cnt+=1 if formula >= n: break return cnt n = int(input()) for i in range(1,n): print(fx(i))
s382780078
Accepted
223
9,208
495
def fx(n): s = [0]*(n+1) for i in range(1,10000): if (i+1+1)**2 - i*1 - 1*1 - 1*i > n: break for j in range(1, 10000): if (1+j+1)**2 - 1*j - j*1 - 1*1 > n : break for k in range(1, 10000): if (1+1+k)**2 - 1*1 - 1*k - k*1 > n: break formula = (i+j+k)**2 - i*j - j*k - k*i if formula <= n and formula > 0: s[formula] += 1 if formula >= n: break return s n = int(input()) s = fx(n) for i in range(1,n+1): print(s[i])
s570396831
p03698
u969211566
2,000
262,144
Wrong Answer
17
2,940
92
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s = input() n = len(s) l = set(s) m = len(l) if n == m: print("Yes") else: print("No")
s678590240
Accepted
17
2,940
92
s = input() n = len(s) l = set(s) m = len(l) if n == m: print("yes") else: print("no")
s249648802
p02261
u357267874
1,000
131,072
Wrong Answer
30
6,352
1,968
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
import copy class Card: def __init__(self, suit, number): self.suit = suit self.number = number self.view = self.suit + str(self.number) def bubble_sort(A): count = 0 while True: swapped = False for i in range(len(A)-1): if A[i+1].number < A[i].number: A[i+1], A[i] = A[i], A[i+1] count += 1 swapped = True if not swapped: return count def selection_sort(A): count = 0 for i in range(len(A)): min_value = A[i].number min_value_index = i # print('- i:', i, 'A[i]', A[i], '-') for j in range(i, len(A)): if A[j].number < min_value: min_value = A[j].number min_value_index = j if i != min_value_index: count += 1 A[i], A[min_value_index] = A[min_value_index], A[i] # print('swap!', A) return count n = int(input()) A = [] for row in input().split(): suit, number = list(row) A.append(Card(suit, int(number))) def is_stable(A, B): N = len(A) for i_A in range(N-1): for j_A in range(i_A+1, N): for i_B in range(N-1): for j_B in range(i_B+1, N): if A[i_A].number == A[j_A].number and A[i_A].view == B[j_B].view and A[j_A].view == B[i_B].view: return False return B bubble_sort_A = copy.deepcopy(A) selection_sort_A = copy.deepcopy(A) bubble_sort(bubble_sort_A) print(*[elem.view for elem in bubble_sort_A]) if is_stable(A, bubble_sort_A): print('Stable') else: print('Not Stable') selection_sort(selection_sort_A) print(*[elem.view for elem in selection_sort_A]) if is_stable(A, selection_sort_A): print('Stable') else: print('Not Stable')
s325942064
Accepted
90
6,360
1,968
import copy class Card: def __init__(self, suit, number): self.suit = suit self.number = number self.view = self.suit + str(self.number) def bubble_sort(A): count = 0 while True: swapped = False for i in range(len(A)-1): if A[i+1].number < A[i].number: A[i+1], A[i] = A[i], A[i+1] count += 1 swapped = True if not swapped: return count def selection_sort(A): count = 0 for i in range(len(A)): min_value = A[i].number min_value_index = i # print('- i:', i, 'A[i]', A[i], '-') for j in range(i, len(A)): if A[j].number < min_value: min_value = A[j].number min_value_index = j if i != min_value_index: count += 1 A[i], A[min_value_index] = A[min_value_index], A[i] # print('swap!', A) return count n = int(input()) A = [] for row in input().split(): suit, number = list(row) A.append(Card(suit, int(number))) def is_stable(A, B): N = len(A) for i_A in range(N-1): for j_A in range(i_A+1, N): for i_B in range(N-1): for j_B in range(i_B+1, N): if A[i_A].number == A[j_A].number and A[i_A].view == B[j_B].view and A[j_A].view == B[i_B].view: return False return B bubble_sort_A = copy.deepcopy(A) selection_sort_A = copy.deepcopy(A) bubble_sort(bubble_sort_A) print(*[elem.view for elem in bubble_sort_A]) if is_stable(A, bubble_sort_A): print('Stable') else: print('Not stable') selection_sort(selection_sort_A) print(*[elem.view for elem in selection_sort_A]) if is_stable(A, selection_sort_A): print('Stable') else: print('Not stable')
s695027765
p04031
u870297120
2,000
262,144
Wrong Answer
20
3,060
197
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
N = int(input()) nums = list(map(int, input().split(' '))) tmp = 0 max = 10**100 for i in nums: for j in nums: tmp += (j-i)**2 if max > tmp: max = tmp tmp = 0 print(max)
s125379835
Accepted
25
3,060
200
N = int(input()) nums = list(map(int, input().split(' '))) temp = 0 cost = [] for i in range(-100, 101): for j in nums: temp += (j-i)**2 cost.append(temp) temp = 0 print(min(cost))
s695840682
p02866
u038854253
2,000
1,048,576
Wrong Answer
85
14,036
457
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition: * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.
divider = 998244353 num = int(input()) depths = [int(x) for x in input().split()] max_depth = max(depths) if depths[0] != 0: print(0) exit(0) if max_depth == 0: print(0) exit(0) nodes = [0] * (max_depth+1) for depth in depths: nodes[depth] += 1 if nodes[0] != 1 or min(nodes) == 0: print(0) exit(0) arr = [(nodes[i] - 1) + nodes[i+1] for i in range(0, max_depth)] ans = 1 for a in arr: ans = (ans * a) % divider print(ans) exit(0)
s404585390
Accepted
100
13,892
450
divider = 998244353 num = int(input()) depths = [int(x) for x in input().split()] max_depth = max(depths) if depths[0] != 0: print(0) exit(0) if max_depth == 0: print(0) exit(0) nodes = [0] * (max_depth+1) for depth in depths: nodes[depth] += 1 if nodes[0] != 1 or min(nodes) == 0: print(0) exit(0) arr = [nodes[i] ** nodes[i+1] for i in range(max_depth)] ans = 1 for a in arr: ans = (ans * a) % divider print(ans) exit(0)
s105466560
p03433
u545334404
2,000
262,144
Wrong Answer
17
2,940
104
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_1 = n % 500 if a >= n_1: print("YES") else: print("NO")
s179056024
Accepted
17
2,940
84
N=int(input()) A=int(input()) if N % 500 <= A: print("Yes") else: print("No")
s151204364
p03386
u609814378
2,000
262,144
Wrong Answer
2,151
794,648
236
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()) ans = [] ans2 = [] ans3 = [] for i in range(A,B+1): ans.append(i) for i in ans[0:K]: ans2.append(i) for j in ans[-K:]: ans3.append(j) ans4 = ans2 + ans3 for i in ans4: print(ans4)
s623340452
Accepted
17
3,060
214
a, b, k = map(int, input().split()) t = [] for i in range(k): if i+a <= b: t.append(i+a) for i in range(k): if b-i >= a: t.append(b-i) y = list(set(t)) for x in sorted(y): print(x)
s315968122
p03853
u088974156
2,000
262,144
Wrong Answer
18
3,060
78
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
h,w=map(int,input().split()) for i in range(h): s=input() print(s+"¥n"+s)
s777706953
Accepted
18
3,060
77
h,w=map(int,input().split()) for i in range(h): s=input() print(s+"\n"+s)
s203747109
p03024
u384261199
2,000
1,048,576
Wrong Answer
17
3,060
160
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S = input() o_, x_ = 0, 0 for s in S: if s == "o": o_ += 1 else: x_ += 1 if o_ > (15-len(S)) + 7: print("YES") else: print("NO")
s121077881
Accepted
17
2,940
160
S = input() o_, x_ = 0, 0 for s in S: if s == "o": o_ += 1 else: x_ += 1 if o_ > 7 - (15-len(S)): print("YES") else: print("NO")
s322221495
p03556
u555356625
2,000
262,144
Wrong Answer
17
3,060
29
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
print(int(int(input())**0.5))
s189238064
Accepted
17
3,060
34
print((int(int(input())**0.5))**2)
s362670868
p03448
u278670845
2,000
262,144
Wrong Answer
50
3,064
434
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
import sys a = int(input()) b = int(input()) c = int(input()) n = int(input()) count = 0 if n<100: if c > 0: count = 1 print(count) sys.exit() elif n<500: for i in range(b+1): for j in range(c+1): if 100*b+50*c==n: count += 1 print(count) sys.exit() else: for i in range(a+1): for j in range(b+1): for k in range(c+1): if 500*a+100*b+50*c==n: cout += 1 print(count)
s829594700
Accepted
50
3,060
221
import sys a = int(input()) b = int(input()) c = int(input()) n = int(input()) count = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if 500*i+100*j+50*k==n: count += 1 print(count)
s300098117
p03369
u731665172
2,000
262,144
Wrong Answer
17
2,940
33
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
s=input() print(700+s.count('o'))
s503414224
Accepted
19
3,060
37
s=input() print(700+100*s.count('o'))
s639830425
p03400
u623349537
2,000
262,144
Wrong Answer
17
3,060
186
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 = [0 for i in range(N)] for i in range(N): A[i] = int(input()) ans = X for a in A: ans += ((D - 1)// A[i] + 1) print(ans)
s629999605
Accepted
18
3,060
183
N = int(input()) D, X = map(int, input().split()) A = [0 for i in range(N)] for i in range(N): A[i] = int(input()) ans = X for a in A: ans += ((D - 1)// a + 1) print(ans)
s223376903
p00016
u747479790
1,000
131,072
Wrong Answer
20
7,912
218
When a boy was cleaning up after his grand father passing, he found an old paper: In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper. For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town. You can assume that d ≤ 100 and -180 ≤ t ≤ 180\.
import math as m x,y,d=0,0,90 while True: r,t=map(int,input().split(",")) if (r,t)==(0,0): break x+=r*m.cos(m.radians(d)) y+=r*m.sin(m.radians(d)) d-=t print(int(m.sqrt(x**2+y**2))) print(d)
s918769557
Accepted
20
7,916
214
# 0016 import math as m x,y,d=0,0,90 while True: r,t=map(int,input().split(",")) if (r,t)==(0,0): break x+=r*m.cos(m.radians(d)) y+=r*m.sin(m.radians(d)) d-=t print(int(x)) print(int(y))
s951355384
p03674
u338824669
2,000
262,144
Wrong Answer
2,114
141,816
751
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
def cmb(n, r, p): if (r<0) or (n<r): return 0 r=min(r, n-r) return fact[n]*factinv[r]*factinv[n-r]%p p=10**9+7 N=10**6 fact=[1,1] factinv=[1,1] inv=[0,1] for i in range(2, N+1): fact.append((fact[-1]*i)%p) inv.append((-inv[p%i]*(p//i)%p)) factinv.append((factinv[-1]*inv[-1])%p) N=int(input()) A=list(map(int,input().split())) index=[[] for _ in range(N+1)] for i in range(N+1): index[A[i]].append(i) for i in range(1,N+1): if len(index[i])==2: dup=i mod=10**9+7 n=index[dup][0] m=N-index[dup][1] l=n+m print(n,m,l) for k in range(1,N+2): if k==1: print(N) continue ans=cmb(N+1,k,mod) if l>=k-1: for i in range(k): ans-=cmb(n,i,mod)*cmb(m,k-1-i,mod) print(ans)
s017222608
Accepted
1,621
132,708
647
def cmb(n, r, p): if (r<0) or (n<r): return 0 r=min(r, n-r) return fact[n]*factinv[r]*factinv[n-r]%p p=10**9+7 N=10**6 fact=[1,1] factinv=[1,1] inv=[0,1] for i in range(2, N+1): fact.append((fact[-1]*i)%p) inv.append((-inv[p%i]*(p//i)%p)) factinv.append((factinv[-1]*inv[-1])%p) N=int(input()) A=list(map(int,input().split())) index=[-1]*N for i,a in enumerate(A): if index[a-1]!=-1: dup_first,dup_second=index[a-1],i break index[a-1]=i mod=10**9+7 n=dup_first m=N-dup_second l=n+m for k in range(1,N+2): if k==1: print(N) continue ans=(cmb(N+1,k,mod)-cmb(l,k-1,mod))%mod print(ans)
s471836506
p03433
u360038884
2,000
262,144
Wrong Answer
17
2,940
85
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 % 500 < a: print('No') else: print('Yes')
s763935233
Accepted
17
2,940
86
n = int(input()) a = int(input()) if n % 500 <= a: print('Yes') else: print('No')
s894489376
p03599
u106778233
3,000
262,144
Wrong Answer
3,309
27,824
504
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.
water = [] a,b,c,d,e,f = map(int, input().split()) for i in range(f//a+1): for j in range(f//b+1): if 0<a*i+b*j<=f: water.append(a*i+b*j) sugar = [] for i in range(f//c+1): for j in range(f//d+1): if 0<c*i+d*j<=f: sugar.append(c*i+d*j) ans1 =0 ans2 =0 ans3 =0 for i in water: for j in sugar: if i+j<=f and j/i*100<=e: if j/(i+j) > ans3: ans1 = i+j ans2 = j print(ans1,ans2)
s648111610
Accepted
29
9,136
347
A, B, C, D, E, F = map(int, input().split()) ans1 = A ans2 = 0 for i in range(A, F // 100 + 1): if any((i - A * j) % B == 0 for j in range(i // A + 1)): x = min(E * i, F - i * 100) e = max([C * j + (x - C * j) // D * D for j in range(x // C + 1)]) if e * ans1 > ans2 * i: ans1 = i ans2 = e print(ans1 * 100 + ans2, ans2)
s607466588
p04043
u897302879
2,000
262,144
Wrong Answer
17
2,940
78
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()))) == [3, 3, 5] else "NO")
s670375142
Accepted
17
2,940
79
print("YES" if sorted(list(map(int, input().split()))) == [5, 5, 7] else "NO")
s639828226
p04011
u434208140
2,000
262,144
Wrong Answer
18
2,940
94
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
n=int(input()) k=int(input()) x=int(input()) y=int(input()) print(k*x+y*(n-x) if n>k else n*x)
s981000940
Accepted
17
2,940
94
n=int(input()) k=int(input()) x=int(input()) y=int(input()) print(k*x+y*(n-k) if n>k else n*x)
s260487663
p03455
u668924588
2,000
262,144
Wrong Answer
17
2,940
78
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()) answer = 'Even' if a * b % 2 == 0 else 'Odd'
s270875907
Accepted
18
2,940
94
a, b = map(int, input().split()) answer = 'Even' if a * b % 2 == 0 else 'Odd' print(answer)
s408980753
p02603
u682271925
2,000
1,048,576
Wrong Answer
29
9,192
276
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
n = int(input()) li = list(map(int,input().split())) money = 1000 stock = 0 for i in range(n-1): if stock > 0: money += stock * li[i] if li[i] < li[i+1]: stock = money // li[i] money -= stock * li[i] if stock > 0: money += stock * li[n-1] print(money)
s395054083
Accepted
30
9,180
199
n = int(input()) li = list(map(int,input().split())) money = 1000 stock = 0 for i in range(n-1): if li[i] < li[i+1]: stock = money // li[i] money += stock * (li[i+1]-li[i]) print(money)
s027283359
p03605
u617203831
2,000
262,144
Wrong Answer
17
2,940
40
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
print("Yes" if input() in "9" else "No")
s138814003
Accepted
17
2,940
40
print("Yes" if "9" in input() else "No")
s463836014
p03862
u064408584
2,000
262,144
Wrong Answer
136
14,132
301
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
n,x=map(int, input().split()) a=list(map(int, input().split())) count=0 for i in a: if i>x:count+=i-x print(count) a=[min(x,i) for i in a] print(a) a2=[a[0]] for i in range(1,n): if a2[-1]+a[i]-x>0: count+=a2[-1]+a[i]-x a2.append(x-a2[-1]) else:a2.append(a[i]) print(count)
s953316893
Accepted
126
14,252
279
n,x=map(int, input().split()) a=list(map(int, input().split())) count=0 for i in a: if i>x:count+=i-x a=[min(x,i) for i in a] a2=[a[0]] for i in range(1,n): if a2[-1]+a[i]-x>0: count+=a2[-1]+a[i]-x a2.append(x-a2[-1]) else:a2.append(a[i]) print(count)
s554813227
p02390
u592365052
1,000
131,072
Wrong Answer
20
5,600
123
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.
S = int(input()) a = S / 60 / 60 h = int(a) b = (a - h) * 60 m = int(b) s = (b - m) * 60 print("{}:{}:{}".format(h, m, s))
s783102504
Accepted
20
5,584
95
S = int(input()) h = S // 3600 m = S % 3600 // 60 s = S % 60 print("{}:{}:{}".format(h, m, s))
s195557114
p02747
u887199039
2,000
1,048,576
Wrong Answer
17
2,940
73
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.
hitachi = input() if hitachi in 'hi': print('Yes') else: print('No')
s141920579
Accepted
17
2,940
187
S = input() hitachi = 'hi' i = 1 while True: corect = hitachi * i if S == corect: print('Yes') break i += 1 if i == 20: print('No') break
s330773079
p03593
u238510421
2,000
262,144
Wrong Answer
1,783
21,404
699
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter. Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition: * Every row and column in A' can be read as a palindrome. Determine whether he can create a matrix satisfying the condition.
from collections import Counter import numpy as np hw = input().split() h = int(hw[0]) w = int(hw[1]) a_all = "" for i in range(h): a_all += input() count = Counter(a_all) four_num = w//2 * h//2 two_num = w%2 * h//2 + h%2 * w//2 one_num = w%2 * h*2 nums = list(count.values()) nums_array = np.array(nums) check=0 for i in range(four_num): if len(nums_array[nums_array>=4])>=1: nums_array[np.where(nums_array>=4)[0][0]] -= 4 else: check = 1 break for i in range(two_num): if len(nums_array[nums_array>=2])>=1: nums_array[np.where(nums_array>=2)[0][0]] -= 2 else: check = 1 if check == 1: print("No") else: print("Yes")
s160533536
Accepted
1,900
21,528
860
from collections import Counter import numpy as np hw = input().split() h = int(hw[0]) w = int(hw[1]) # print(h,w) a_all = "" for i in range(h): a_all += input() count = Counter(a_all) four_num = (w//2) * (h//2) two_num = (w%2) * (h//2) + (h%2) * (w//2) one_num = (w%2) * (h%2) # print("test:",four_num,two_num,one_num) nums = list(count.values()) nums_array = np.array(nums) check=0 # print(nums_array) for i in range(four_num): if len(nums_array[nums_array>=4])>=1: nums_array[np.where(nums_array>=4)[0][0]] -= 4 # print(nums_array) else: check = 1 break for i in range(two_num): if len(nums_array[nums_array>=2])>=1: nums_array[np.where(nums_array>=2)[0][0]] -= 2 # print(nums_array) else: check = 1 break if check == 1: print("No") else: print("Yes")
s409830232
p03378
u375616706
2,000
262,144
Wrong Answer
17
3,060
251
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.
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, M, X = map(int, input().split()) a = list(map(int, input().split())) ans = 0 for i in reversed(range(X)): if i in a: ans += 1 print(ans)
s250641177
Accepted
18
3,060
253
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, M, X = map(int, input().split()) a = list(map(int, input().split())) l = [0]*(N+1) for i in a: l[i] += 1 print(min(sum(l[0:X]), sum(l[X+1: N+1])))
s778250151
p03456
u372670441
2,000
262,144
Wrong Answer
17
2,940
137
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=map(str,input().split()) c=int(str(a)+str(b)) A=math.sqrt(c) if int(A)==float(A): print("yes") else: print("no")
s061237325
Accepted
18
2,940
137
import math a,b=map(str,input().split()) c=int(str(a)+str(b)) A=math.sqrt(c) if int(A)==float(A): print("Yes") else: print("No")
s632210175
p02608
u927740808
2,000
1,048,576
Wrong Answer
123
9,364
298
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()) c = [0]*10001 for x in range(1,101): if(x > n): break for y in range(x,101): for z in range(y,101): p = int(((x+y)*(x+y) + (y+z)*(y+z) + (z+x)*(z+x))/2) if(n >= p): c[p] += 1 for i in range(1,n+1): print(c[i])
s526901211
Accepted
533
9,432
297
n = int(input()) c = [0]*10001 for x in range(1,101): if(x > n): break for y in range(1,101): for z in range(1,101): p = int(((x+y)*(x+y) + (y+z)*(y+z) + (z+x)*(z+x))/2) if(n >= p): c[p] += 1 for i in range(1,n+1): print(c[i])
s764666349
p03493
u213401801
2,000
262,144
Wrong Answer
17
2,940
77
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
s=list(input()) result=0 for i in s: if i=='0': result+=1 print(result)
s874545892
Accepted
17
2,940
83
s=list(input()) result=0 for i in s: if i=='1': result=result+1 print(result)
s345828750
p03693
u882620594
2,000
262,144
Wrong Answer
18
2,940
99
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())) if a[1]*10 + a[2] % 4 == 0: print("YES") else: print("NO")
s920758331
Accepted
18
2,940
101
a=list(map(int,input().split())) if (a[1]*10 + a[2]) % 4 == 0: print("YES") else: print("NO")
s874724040
p03544
u440161695
2,000
262,144
Wrong Answer
17
2,940
66
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
n=int(input()) a,b=2,1 for i in range(n-1): a,b=b,(a+b) print(a)
s702694983
Accepted
17
2,940
66
n=int(input()) a,b=2,1 for i in range(n-1): a,b=b,(a+b) print(b)
s151541161
p03860
u788856752
2,000
262,144
Wrong Answer
17
2,940
43
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
l = list(input()) print("A" + l[0] + "C")
s064756466
Accepted
17
2,940
42
l = list(input()) print("A" + l[8] + "C")
s906731252
p03472
u062147869
2,000
262,144
Wrong Answer
349
11,316
506
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
from bisect import bisect_right,bisect_left import sys N,H = map(int,input().split()) A = [] B = [] for i in range(N): a,b = map(int,input().split()) A.append(a) B.append(b) B.sort() ama=max(A) x = bisect_right(B,ama) ans = 0 if x ==N: ans = H//ama +1 print(ans) sys.exit() for i in range(x,N): if H<=0: print(ans) sys.exit() if H>0: H-=B[i] ans +=1 if H>0: if H%ama ==0: ans += H//ama else: ans += H//ama print(ans)
s428486890
Accepted
353
12,084
446
from bisect import bisect_right,bisect_left import sys N,H = map(int,input().split()) A = [] B = [] for i in range(N): a,b = map(int,input().split()) A.append(a) B.append(b) B =sorted(B,reverse=True) ama=max(A) ans =0 for i in range(N): if H<=0: print(ans) sys.exit() elif B[i]>=ama: H-=B[i] ans +=1 else: break if H>0: ans += H//ama if H%ama!=0: ans +=1 print(ans)
s428885561
p02645
u185806788
2,000
1,048,576
Wrong Answer
17
9,020
37
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]"+"S[1]"+"S[2]")
s072200283
Accepted
23
9,080
22
S=input() print(S[:3])
s058560542
p02396
u313600138
1,000
131,072
Wrong Answer
120
5,592
63
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.
while True: x=int(input()) if x==0: break print(x)
s386702072
Accepted
160
5,608
103
i=0 while True: x=int(input()) i=i+1 if x == 0: break print('Case',' ',i,':',' ',x,sep='')
s838358960
p03485
u604655161
2,000
262,144
Wrong Answer
18
2,940
121
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.
def ABC_82_A(): a,b = map(int, input().split()) print(int((a+b)/2)+1) if __name__ == '__main__': ABC_82_A()
s506819292
Accepted
17
2,940
121
def ABC_82_A(): a,b = map(int, input().split()) print(int((a+b+1)/2)) if __name__ == '__main__': ABC_82_A()
s252661962
p02420
u897625141
1,000
131,072
Wrong Answer
30
7,656
468
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
import re array = [] lines = [] count = 0 while True: n = input() if n == "-": break array.append(n) for i in range(len(array)): if re.compile("[a-z]").search(array[i]): if count > 0: lines.append(stt) count += 1 stt = array[i] else: stt = stt[int(array[i]):len(stt)]+stt[0:int(array[i])] if i == len(array)-1: lines.append(stt) for i in range(len(lines)): print(lines[i])
s119935485
Accepted
40
7,848
530
import re array = [] lines = [] count = 0 while True: n = input() if n == "-": break array.append(n) for i in range(len(array)): if re.compile("[a-z]").search(array[i]): fuck = i+1 if count > 0: lines.append(stt) count += 1 stt = array[i] else: if i == fuck: continue stt = stt[int(array[i]):len(stt)]+stt[0:int(array[i])] if i == len(array)-1: lines.append(stt) for i in range(len(lines)): print(lines[i])
s136697929
p02401
u131984977
1,000
131,072
Wrong Answer
30
6,736
306
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.
from sys import stdin while True: (a, op, b) = stdin.readline().split(' ') a = int(a) b = int(b) if op == "?": break; elif op == "+": print(a + b) elif op == "-": print(a - b) elif op == "*": print(a * b) elif op == "/": print(a / b)
s950642966
Accepted
40
7,636
291
while True: a, op, b = input().split() a = int(a) b = int(b) if op == '?': break if op == '+': print(a + b) if op == '-': print(a - b) if op == '*': print(a * b) if op == '/': print(a // b)
s805742784
p04043
u137228327
2,000
262,144
Wrong Answer
27
8,948
233
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.
lst = list(map(int,input().split())) #print(lst) count5 = 0 count7 = 0 for i in range(len(lst)): if i == 5: count5+=1 elif i == 7: count7+=1 if count7==1 and count5 ==2: print('YES') else: print('NO')
s755623975
Accepted
23
9,032
257
# coding: utf-8 # Your code here! lst = list(map(int,input().split())) #print(lst) count5 = 0 count7 = 0 for i in lst: if i == 5: count5+=1 elif i == 7: count7+=1 if count7==1 and count5 ==2: print('YES') else: print('NO')
s682472624
p02613
u644516473
2,000
1,048,576
Wrong Answer
147
9,476
200
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
from collections import defaultdict N = int(input()) d = defaultdict(int) for _ in range(N): d[input()] += 1 for k in ['AC', 'WA', 'TLE', 'RE']: v = d[k] if v: print(f'{k} x {v}')
s328612577
Accepted
146
9,092
186
from collections import defaultdict N = int(input()) d = defaultdict(int) for _ in range(N): d[input()] += 1 for k in ['AC', 'WA', 'TLE', 'RE']: v = d[k] print(f'{k} x {v}')
s968863212
p02615
u466143662
2,000
1,048,576
Wrong Answer
182
31,440
210
Quickly after finishing the tutorial of the online game _ATChat_ , you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the **friendliness** of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets **comfort** equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?
n = int(input()) A = sorted(list(map(int, input().split())), reverse=True) score_list = [0] for i in range(1, len(A)): score_list.append(A[i]) score_list.append(A[i]) print(sum(score_list[:n-1]))
s994265737
Accepted
174
31,676
214
n = int(input()) A = sorted(list(map(int, input().split())), reverse=True) score_list = [0, A[0]] for i in range(1, len(A)): score_list.append(A[i]) score_list.append(A[i]) print(sum(score_list[:n]))
s254549239
p02262
u092047183
6,000
131,072
Wrong Answer
30
7,836
677
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
# coding: utf-8 import math cnt = 0 m = 0 G = [] def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v return A def shellSort(A, n): global m, G m = int(math.log(n, 2)) G = [2**x for x in range(m - 1, -1, -1)] for i in range(m): A = insertionSort(A, n, G[i]) return A n = int(input()) A = [] for i in range(n): A.append(int(input())) A = shellSort(A, n) print(m) print(" ".join(map(str, G))) print(cnt) for i in range(n): print(A[i])
s728849356
Accepted
21,910
118,672
566
# coding: utf-8 import math import sys def insertionSort(a, n, g): ct = 0 for i in range(g, n): v = a[i] j = i - g while j >= 0 and a[j] > v: a[j+g] = a[j] j = j - g ct += 1 a[j+g] = v return ct n = int(input()) a = list(map(int, sys.stdin.readlines())) cnt = 0 m = 0 h = 0 g = [] while True: h = 3*h + 1 if h > n: break g.insert(0, math.ceil(h)) for i in g: cnt += insertionSort(a, n, i) print(len(g)) print(*g, sep=" ") print(cnt) print(*a, sep="\n")
s230526527
p03564
u763177133
2,000
262,144
Wrong Answer
24
9,112
135
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
n = int(input()) k = int(input()) num = 1 count = 0 while num < k: num *= 2 count += 1 num + (k * (n-count)) print(num)
s223041292
Accepted
27
9,124
133
n = int(input()) k = int(input()) num = 1 count = 0 while count < n: num = min(num * 2, num + k) count += 1 print(num)
s942489677
p03730
u511457539
2,000
262,144
Wrong Answer
17
2,940
127
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A, B, C = map(int, input().split()) for i in range(1000): if A*i%B == C: print("Yes") exit() print("No")
s701510292
Accepted
17
2,940
127
A, B, C = map(int, input().split()) for i in range(1000): if A*i%B == C: print("YES") exit() print("NO")
s809883617
p03493
u404240078
2,000
262,144
Wrong Answer
17
2,940
54
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.
trout = input().rstrip() count_zero = trout.count('0')
s189779579
Accepted
19
3,060
134
trout = input().rstrip().lstrip() num_list = [] for i in range(len(trout)): num_list.append(int(trout[i])) print(num_list.count(1))
s681028613
p03474
u679089074
2,000
262,144
Wrong Answer
27
9,196
308
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
#33 import sys A,B = map(int,input().split()) S = input() Ans = "No" if S[A] != "-": print(Ans) sys.exit() for i in range(A): if S[i] == "-": print(Ans) sys.exit() for i in range(A+1,A+B+1): if S[i] == "-": print(Ans) sys.exit() Ans = "yes" print(Ans)
s977879707
Accepted
26
9,196
308
#33 import sys A,B = map(int,input().split()) S = input() Ans = "No" if S[A] != "-": print(Ans) sys.exit() for i in range(A): if S[i] == "-": print(Ans) sys.exit() for i in range(A+1,A+B+1): if S[i] == "-": print(Ans) sys.exit() Ans = "Yes" print(Ans)
s171902939
p02743
u190905976
2,000
1,048,576
Wrong Answer
17
2,940
92
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c = (int(i) for i in input().split()) if a+b < c: print("Yes") else: print("No")
s719801994
Accepted
17
3,060
140
a,b,c = (int(i) for i in input().split()) if c-a-b <=0: print("No") elif 4*a*b < (c-a-b)*(c-a-b): print("Yes") else: print("No")
s378315001
p03555
u266768906
2,000
262,144
Wrong Answer
17
3,060
213
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.
s1 = input() s2 = input() if(s1[0] == s2[2]): if(s1[1] == s2[1]): if(s1[2] == s2[0]): print("Yes") else: print("No") else: print("No") else: print("No")
s866753339
Accepted
18
3,060
213
s1 = input() s2 = input() if(s1[0] == s2[2]): if(s1[1] == s2[1]): if(s1[2] == s2[0]): print("YES") else: print("NO") else: print("NO") else: print("NO")
s841277879
p03957
u970308980
1,000
262,144
Wrong Answer
19
3,188
67
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtained from the string s by deleting some characters.
import re s = input() print('Yes' if re.search('CF', s) else 'No')
s667717692
Accepted
19
3,188
96
import re s = input() s = re.sub(r'[^CF]', '', s) print('Yes' if re.search(r'CF', s) else 'No')
s879918591
p03155
u749770850
2,000
1,048,576
Wrong Answer
18
2,940
88
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
n = int(input()) h = int(input()) w = int(input()) print((n - (w + 1)) * (n - (h + 1)))
s104306912
Accepted
17
2,940
84
n = int(input()) h = int(input()) w = int(input()) print((n - w + 1) * (n - h + 1))
s248496634
p03997
u486773779
2,000
262,144
Wrong Answer
29
9,060
62
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h/2)
s224142164
Accepted
27
8,984
63
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h//2)
s076505387
p03997
u178432859
2,000
262,144
Wrong Answer
17
2,940
67
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s204123989
Accepted
17
2,940
72
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h/2))
s450086208
p00001
u105694406
1,000
131,072
Wrong Answer
20
7,524
149
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
mountain = [] for _ in range(10): mountain.append(int(input())) mountain.sort() mountain.reverse() print(mountain[0], mountain[1], mountain[2])
s432765575
Accepted
20
7,600
161
mountain = [] for _ in range(10): mountain.append(int(input())) mountain.sort() mountain.reverse() print(mountain[0]) print(mountain[1]) print(mountain[2])
s138256906
p03385
u207799478
2,000
262,144
Wrong Answer
17
3,060
243
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
def readints(): return list(map(int, input().split())) s = str(input()) t = ['a', 'b', 'c'] print(sorted(s)) # print(t) sum = 0 for i in range(3): if s[i] == t[i]: sum += 1 if sum == 3: print("Yes") else: print("No")
s640298636
Accepted
17
2,940
156
def readints(): return list(map(int, input().split())) s = str(input()) if 'a' in s and 'b' in s and 'c' in s: print("Yes") else: print("No")
s866921686
p02420
u519227872
1,000
131,072
Wrong Answer
20
7,608
213
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
import sys cards = "" for line in sys.stdin: line = line.strip() try: #print(line) h = int(line) cards = cards[h:] + cards[:h] except: print (cards) cards = line
s938319454
Accepted
20
7,756
468
import sys lines = [line.strip() for line in sys.stdin] cards = lines[0] m = int(lines[1]) lines_index = 2 while m > 0: line = lines[lines_index] if line == '-': break h = int(line) cards = cards[h:] + cards[:h] m -= 1 if m == 0: print (cards) lines_index += 1 cards = lines[lines_index] if cards == '-': break lines_index += 1 m = int(lines[lines_index]) lines_index += 1
s989025606
p02259
u462831976
1,000
131,072
Wrong Answer
20
7,688
464
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
# -*- coding: utf-8 -*- import sys import os import math N = int(input()) A = list(map(int, input().split())) def bubble_sort(A): swap_num = 0 while True: swapped = False for i in range(N - 1): if A[i] > A[i + 1]: A[i], A[i + 1] = A[i + 1], A[i] swap_num += 1 swapped = True if not swapped: return A, swap_num A, num = bubble_sort(A) print(num) print(*A)
s051966584
Accepted
20
7,812
464
# -*- coding: utf-8 -*- import sys import os import math N = int(input()) A = list(map(int, input().split())) def bubble_sort(A): swap_num = 0 while True: swapped = False for i in range(N - 1): if A[i] > A[i + 1]: A[i], A[i + 1] = A[i + 1], A[i] swap_num += 1 swapped = True if not swapped: return A, swap_num A, num = bubble_sort(A) print(*A) print(num)
s001185682
p03408
u442877951
2,000
262,144
Wrong Answer
21
3,316
480
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
s = [] t = [] N = int(input()) for _ in range(N): s.append(str(input())) M = int(input()) for _ in range(M): t.append(str(input())) from collections import Counter sc = Counter(s) tc = Counter(t) s_keys, s_values = zip(*sc.most_common()) t_keys, t_values = zip(*tc.most_common()) ans = 0 for i in range(len(s_values)): for j in range(len(t_values)): minus = 0 if s_keys[i] == t_keys[j]: minus = t_values[j] ans = max(ans, s_values[i] - minus) print(ans)
s384471691
Accepted
21
3,316
546
s = [] t = [] N = int(input()) for _ in range(N): s.append(str(input())) M = int(input()) for _ in range(M): t.append(str(input())) from collections import Counter sc = Counter(s) tc = Counter(t) s_keys, s_values = zip(*sc.most_common()) t_keys, t_values = zip(*tc.most_common()) ans = 0 for i in range(len(s_values)): for j in range(len(t_values)): minus = 0 if s_keys[i] == t_keys[j]: minus = t_values[j] ans = max(ans, s_values[i] - minus) if s_keys[i] not in t_keys: ans = max(ans, s_values[i]) print(ans)
s054983326
p03607
u346308892
2,000
262,144
Wrong Answer
231
17,160
253
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=[] for i in range(N): a.append(int(input())) chk={} for sa in a: if sa in chk: if chk[sa]==1: chk[sa]=0 else: chk[sa]=1 else: chk[sa]=1 print(chk) print(sum(chk.values()))
s452350054
Accepted
219
16,272
244
N=int(input()) a=[] for i in range(N): a.append(int(input())) chk={} for sa in a: if sa in chk: if chk[sa]==1: chk[sa]=0 else: chk[sa]=1 else: chk[sa]=1 print(sum(chk.values()))
s237403977
p00071
u150984829
1,000
131,072
Wrong Answer
20
5,656
341
縦 8、横 8 のマスからなる図1 のような平面があります。その平面上に、いくつかの爆弾が置かれています。図2 にその例を示します(● = 爆弾)。 | □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ | □| □| □| ●| □| □| ●| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| ●| □| □ ●| □| □| □| ●| □| □| ● □| □| ●| □| □| □| ●| □ □| ●| □| □| □| □| □| □ □| □| □| □| ●| □| □| □ ●| □| ●| □| □| □| ●| □ □| ●| □| ●| □| □| ●| □ 図1| 図2 爆弾が爆発すると、その爆弾の上下左右 3 マスに爆風の影響が及び、それらのマスに置かれている爆弾も連鎖的に爆発します。たとえば、図 3 に示す爆弾が爆発すると図 4 の■のマスに爆風の影響が及びます。 | □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| ●| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ | □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| □| □| ■| □| □| □| □ □| □| □| ■| □| □| □| □ □| □| □| ■| □| □| □| □ ■| ■| ■| ●| ■| ■| ■| □ □| □| □| ■| □| □| □| □ □| □| □| ■| □| □| □| □ 図3| 図4 爆弾が置かれている状態と最初に爆発する爆弾の位置を読み込んで、最終的な平面の状態を出力するプログラムを作成してください。
def e(x,y): A[y][x]='0' for dx,dy in[[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]: if 0<=x+dx<8 and 0<=y+dy<8 and A[y+dy][x+dx]=='1':e(x+dx,y+dy) for i in range(int(input())): print(f'Data {i+1}') input() A=[list(input())for _ in[0]*8] e(int(input())-1,int(input())-1) for r in A:print(*r,sep='')
s579799178
Accepted
20
5,632
273
def b(x,y): A[y][x]='0' for d in range(-3,4): 0<=x+d<8and'1'==A[y][x+d]and b(x+d,y) 0<=y+d<8and'1'==A[y+d][x]and b(x,y+d) e=input for i in range(int(e())): print(f'Data {i+1}:') e() A=[list(e())for _ in[0]*8] b(int(e())-1,int(e())-1) for r in A:print(*r,sep='')
s006046937
p03739
u882370611
2,000
262,144
Wrong Answer
229
14,644
735
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.
n = int(input()) a = list(map(int, input().split())) cnt_1 = 0 base = 0 for i in range(n): if ((base + a[i] >= 0) and (i % 2 == 1)) or ((base + a[i] <= 0) and (i % 2 == 0)): cnt_1 += (1 + abs(base + a[i])) base += (1 + abs(base + a[i])) * (-1) ** i else: base += a[i] cnt_2 = 0 base = 0 for i in range(n): if ((base + a[i] <= 0) and (i % 2 == 1)) or ((base + a[i] >= 0) and (i % 2 == 0)): cnt_2 += (1 + abs(base + a[i])) base -= (1 + abs(base + a[i])) * (-1) ** i else: base += a[i] print(min(cnt_1, cnt_2))
s307987339
Accepted
233
14,468
757
n = int(input()) a = list(map(int, input().split())) cnt_1 = 0 base = 0 for i in range(n): if ((base + a[i] >= 0) and (i % 2 == 1)) or ((base + a[i] <= 0) and (i % 2 == 0)): cnt_1 += (1 + abs(base + a[i])) base += a[i] + (1 + abs(base + a[i])) * (-1) ** i else: base += a[i] cnt_2 = 0 base = 0 for i in range(n): if ((base + a[i] <= 0) and (i % 2 == 1)) or ((base + a[i] >= 0) and (i % 2 == 0)): cnt_2 += (1 + abs(base + a[i])) base += a[i] + (1 + abs(base + a[i])) * (-1) ** (i + 1) else: base += a[i] print(min(cnt_1, cnt_2))
s536656324
p03433
u587213169
2,000
262,144
Wrong Answer
17
2,940
90
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")
s942924476
Accepted
18
2,940
86
N = int(input()) A = int(input()) if N%500<=A: print("Yes") else: print("No")
s202563180
p03385
u505420467
2,000
262,144
Wrong Answer
18
2,940
46
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
a=list(input());print("YNeos"[len(set(a))!=3])
s513729085
Accepted
17
2,940
50
a=list(input());print("YNeos"[len(set(a))!=3::2])
s379857860
p04013
u480300350
2,000
262,144
Wrong Answer
62
5,364
3,387
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
#!/usr/bin/env python3 import sys # import math # from string import ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from copy import deepcopy # to copy multi-dimentional matrix without reference # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 1000000007 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) n, a = mi() L = lmi() diff = [elm - a for elm in L] dp = [[0] * 5001 for _ in range(n + 1)] dp[0][2500] = 1 for i in range(n): for j in range(5001): if dp[i][j]: dp[i+1][j+diff[i]] += dp[i][j] dp[i+1][j] = dp[i][j] print(dp[n][2500] - 1) if __name__ == "__main__": main()
s637023397
Accepted
71
5,620
3,394
#!/usr/bin/env python3 import sys # import math # from string import ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from copy import deepcopy # to copy multi-dimentional matrix without reference # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 1000000007 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) n, a = mi() L = lmi() diff = [elm - a for elm in L] dp = [[0] * 5001 for _ in range(n + 1)] dp[0][2500] = 1 for i in range(n): for j in range(5001): if dp[i][j]: dp[i+1][j + diff[i]] += dp[i][j] dp[i+1][j] += dp[i][j] print(dp[n][2500] - 1) if __name__ == "__main__": main()