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
s046421464
p02866
u738898077
2,000
1,048,576
Wrong Answer
2,104
83,092
536
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.
import sys pre_strk = 1 now_strk = 1 ans = 1 n = int(input()) d_list = list(map(int,input().split())) d_list.sort() print(d_list) if d_list[0] != 0: print(0) sys.exit() for i in range(1,n): if d_list[i] == d_list[i-1]: now_strk += 1 elif d_list[i] != d_list[i-1] and (d_list[i-1] != 1 or d_list[i-1] != 0): ans *= pre_strk ** now_strk pre_strk = now_strk now_strk = 1 print(ans) else: pre_strk = now_strk now_strk = 1 ans *= pre_strk ** now_strk print(ans)
s329286414
Accepted
871
14,396
727
import sys pre_strk = 1 now_strk = 1 ans = 1 n = int(input()) d_list = list(map(int,input().split())) # print(d_list) if d_list[0] != 0: print(0) sys.exit() d_list.sort() if d_list[1] == 0: print(0) sys.exit() for i in range(1,n): if d_list[i] == d_list[i-1]: now_strk += 1 elif d_list[i] > d_list[i-1] + 1: print(0) sys.exit() elif d_list[i] != d_list[i-1] and d_list[i-1] != 1: for j in range(now_strk): ans *= pre_strk pre_strk = now_strk now_strk = 1 # print(ans) ans = ans % 998244353 else: pre_strk = now_strk now_strk = 1 for i in range(now_strk): ans *= pre_strk print(ans%998244353)
s001094691
p02416
u536089081
1,000
131,072
Wrong Answer
20
5,592
138
Write a program which reads an integer and prints sum of its digits.
from sys import stdin for line in stdin: if line == '0': break num = list(map(int, line.strip('\n'))) print(sum(num))
s693093604
Accepted
20
5,608
140
from sys import stdin for line in stdin: if line == '0\n': break num = list(map(int, line.strip('\n'))) print(sum(num))
s696365738
p03971
u883459277
2,000
262,144
Wrong Answer
73
9,892
282
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
count1 = 0 count2 = 0 N, A, B = map(int, input().split()) S = list(input()) for i in S: if i == "a" and A + B >= count1: print("Yes") count1 += 1 elif i == "b" and A + B >= count1 and B >= count2: print("Yes") count1 += 1 count2 += 1 else : print("No")
s442156611
Accepted
70
9,988
279
count1 = 0 count2 = 0 N, A, B = map(int, input().split()) S = list(input()) for i in S: if i == "a" and A + B > count1: print("Yes") count1 += 1 elif i == "b" and A + B > count1 and B > count2: print("Yes") count1 += 1 count2 += 1 else : print("No")
s592961592
p03672
u327248573
2,000
262,144
Wrong Answer
17
3,060
152
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
S = input() for i in range(len(S) - 1, 0, -1): S = S[:i] print(S) if i % 2 == 0 and S[:(i//2)] == S[(i//2):]: print(i) break
s910042408
Accepted
17
2,940
139
S = input() for i in range(len(S) - 1, 0, -1): S = S[:i] if i % 2 == 0 and S[:(i//2)] == S[(i//2):]: print(i) break
s725040291
p03862
u136395536
2,000
262,144
Wrong Answer
115
14,548
343
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 = (int(i) for i in input().split()) a = [int(i) for i in input().split()] count = 0 if a[1] > x: difference = x-a[1] count += difference a[1] -= difference for i in range(N-1): difference = x - (a[i] + a[i+1]) if difference < 0: count += abs(difference) a[i+1] += difference print(a) print(count)
s473542986
Accepted
115
14,068
407
N,x = (int(i) for i in input().split()) a = [int(i) for i in input().split()] count = 0 if a[1] > x: difference = x-a[1] count += difference a[1] -= difference for i in range(N-1): difference = x - (a[i] + a[i+1]) if difference < 0: count += abs(difference) a[i+1] += difference if a[i+1] < 0: a[i] += a[i] a[i+1] = 0 print(count)
s253130147
p03739
u820351940
2,000
262,144
Wrong Answer
99
14,212
455
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())) now = a[0] m = now < 0 and -1 or 1 result = 0 for i, v in enumerate(a[1:]): tmp = now * -1 if m < 0: tmp += 1 if tmp > v: now += v else: result += abs(tmp - v) now = -1 else: tmp -= 1 if tmp < v: now += v else: result += abs(tmp - v) now = 1 m *= -1 print(result)
s874047129
Accepted
233
23,244
752
import numpy as np input() a = list(map(int, input().split())) def calc(a): value = a[0] sign = value >= 0 result = 0 for i in a[1:]: value += i diff = 0 if sign and value >= 0: diff = value + 1 elif not sign and value < 0: diff = value - 1 result += abs(diff) sign = not sign value -= diff if value == 0: diff += sign value += diff result += diff return result if a[0] == 0: a[0] = 1 r1 = calc(a[:]) a[0] = -1 r2 = calc(a[:]) print(min(r1, r2) + 1) else: r1 = calc(a[:]) diff = -a[0] - a[0] // abs(a[0]) a[0] += diff r2 = calc(a[:]) + abs(diff) print(min(r1, r2))
s592665092
p03679
u333190709
2,000
262,144
Wrong Answer
17
2,940
99
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x, a, b = map(int, input().split()) if x >= (b-a): print('delicious') else: print('dangerous')
s687311088
Accepted
17
2,940
131
x, a, b = map(int, input().split()) if a >= b: print('delicious') elif x >= (b - a): print('safe') else: print('dangerous')
s504541125
p04011
u611090896
2,000
262,144
Wrong Answer
17
2,940
64
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,k,x,y = [int(input()) for i in range(4)] print(n*x+abs(n-k)*y)
s981012860
Accepted
17
2,940
70
n,k,x,y = [int(input()) for i in range(4)] print(n*x-(x-y)*max(n-k,0))
s891888680
p03543
u002459665
2,000
262,144
Wrong Answer
18
2,940
69
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
n = input() if n == n[0] * 4: print("Yes") else: print("No")
s612962343
Accepted
20
3,060
91
s = input() if (s[0] * 3 in s) or (s[3] * 3 in s): print("Yes") else: print("No")
s412896962
p03478
u089230684
2,000
262,144
Wrong Answer
41
2,940
256
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
def digit_sum(x): string_x = str(x) total = 0 for char in string_x: total += int(char) return total a, b, c = map(int, input().split()) sum=0 for i in range(0,a): if(digit_sum(i)>=b and digit_sum(i)<=c): sum=sum+i print(sum)
s658216829
Accepted
25
2,940
211
n, A, B = map(int, input().split()) def ok(a): s = 0 while a > 0: s += a % 10 a //= 10 return (A <= s and s <= B) s = 0 for i in range(1, n+1): if ok(i): s += i print(s)
s694633257
p02419
u971748390
1,000
131,072
Wrong Answer
30
7,328
87
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
sentence=input() snt=sentence.lower() word=input() cnt=sentence.count(word) print(cnt)
s749988048
Accepted
20
7,432
198
w= input().casefold() cnt = 0 while(1): snt = input() if snt == "END_OF_TEXT": break sntt = snt.casefold() words = sntt.split() cnt += words.count(w) print(cnt)
s332239462
p03696
u563824531
2,000
262,144
Wrong Answer
17
3,064
408
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
n = input() s = input() count = 0 countl = 0 for c in s: if c=='(': count += 1 else: count -= 1 if count < 0: countl += 1 count = 0 count = 0 countr = 0 for c in s[::-1]: if c=='(': count -= 1 else: count += 1 if count < 0: countr += 1 count = 0 print(countl) print(countr) print("("*countl + s + ")"*countr)
s963161849
Accepted
18
3,064
372
n = input() s = input() count = 0 countl = 0 for c in s: if c=='(': count += 1 else: count -= 1 if count < 0: countl += 1 count = 0 count = 0 countr = 0 for c in s[::-1]: if c=='(': count -= 1 else: count += 1 if count < 0: countr += 1 count = 0 print('('*countl + s + ')'*countr)
s470214554
p02613
u427231601
2,000
1,048,576
Wrong Answer
148
16,196
319
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) s = [input() for _ in range(n)] a = 0 w = 0 t = 0 r = 0 for i in range(n): if s[i] == "AC": a += 1 elif s[i] == "WA": w += 1 elif s[i] == "TLE": t += 1 else: r += 1 print("AC x" +str(a)) print("WA x" +str(w)) print("TLE x" +str(t)) print("RE x" +str(r))
s772107748
Accepted
157
16,332
315
n = int(input()) s = [input() for _ in range(n)] a = 0 w = 0 t = 0 r = 0 for i in range(n): if s[i] == "AC": a += 1 elif s[i] == "WA": w += 1 elif s[i] == "TLE": t += 1 else: r += 1 print("AC x",str(a)) print("WA x",str(w)) print("TLE x",str(t)) print("RE x",str(r))
s076058714
p04012
u551109821
2,000
262,144
Wrong Answer
18
2,940
168
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
w = list(input()) W = list(set(w)) cnt = [0]*len(W) for i in w: cnt[W.index(i)] += 1 for i in cnt: if i%2!=0: print('NO') exit() print('YES')
s620568424
Accepted
18
3,064
167
w = list(input()) W = list(set(w)) cnt = [0]*len(W) for i in w: cnt[W.index(i)] += 1 for i in cnt: if i%2!=0: print('No') exit() print('Yes')
s506438740
p02357
u073562076
2,000
262,144
Wrong Answer
40
8,308
1,819
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $L$, find the minimum of each possible sub-arrays with size $L$ and print them from the beginning. For example, for an array $\\{1, 7, 7, 4, 8, 1, 6\\}$ and $L = 3$, the possible sub-arrays with size $L = 3$ includes $\\{1, 7, 7\\}$, $\\{7, 7, 4\\}$, $\\{7, 4, 8\\}$, $\\{4, 8, 1\\}$, $\\{8, 1, 6\\}$ and the minimum of each sub-array is 1, 4, 4, 1, 1 respectively.
import collections, numbers import random def compute(array, window, maximize): if not isinstance(window, numbers.Integral): raise TypeError() if not isinstance(maximize, bool): raise TypeError() if window <= 0: raise ValueError("Window size must be positive") result = [] deque = collections.deque() for i, val in enumerate(array): val = array[i] while len(deque) > 0 and ((not maximize and val < deque[-1]) or (maximize and val > deque[-1])): deque.pop() deque.append(val) j = i + 1 - window if j >= 0: result.append(deque[0]) if array[j] == deque[0]: deque.popleft() return result class SlidingWindowMinMax(object): def __init__(self): self.mindeque = collections.deque() self.maxdeque = collections.deque() def get_minimum(self): return self.mindeque[0] def get_maximum(self): return self.maxdeque[0] def add_tail(self, val): while len(self.mindeque) > 0 and val < self.mindeque[-1]: self.mindeque.pop() self.mindeque.append(val) while len(self.maxdeque) > 0 and val > self.maxdeque[-1]: self.maxdeque.pop() self.maxdeque.append(val) def remove_head(self, val): if val < self.mindeque[0]: raise ValueError("Wrong value") elif val == self.mindeque[0]: self.mindeque.popleft() if val > self.maxdeque[0]: raise ValueError("Wrong value") elif val == self.maxdeque[0]: self.maxdeque.popleft() if __name__ == "__main__": n, l = (int(x) for x in input().split()) array = list((int(x) for x in input().split())) answer = compute(array, l, False) print(answer)
s040689837
Accepted
1,790
122,036
916
import collections, numbers import random def compute(array, window, maximize): if not isinstance(window, numbers.Integral): raise TypeError() if not isinstance(maximize, bool): raise TypeError() if window <= 0: raise ValueError("Window size must be positive") result = [] deque = collections.deque() for i, val in enumerate(array): val = array[i] while len(deque) > 0 and ((not maximize and val < deque[-1]) or (maximize and val > deque[-1])): deque.pop() deque.append(val) j = i + 1 - window if j >= 0: result.append(deque[0]) if array[j] == deque[0]: deque.popleft() return result if __name__ == "__main__": n, l = (int(x) for x in input().split()) array = list((int(x) for x in input().split())) answer = compute(array, l, False) print(*answer)
s800341068
p03795
u328755070
2,000
262,144
Wrong Answer
17
2,940
52
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()) ans = 800 * N - N // 15 print(ans)
s504391514
Accepted
17
2,940
60
N = int(input()) ans = 800 * N - (N // 15) * 200 print(ans)
s002929744
p02747
u316175331
2,000
1,048,576
Wrong Answer
21
3,188
99
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
import re pattern = re.compile("(hi)+") s = input() print("YES" if pattern.fullmatch(s) else "NO")
s084066119
Accepted
22
3,188
100
import re pattern = re.compile("(hi)+") s = input() print("Yes" if pattern.fullmatch(s) else "No")
s820358459
p02936
u244416763
2,000
1,048,576
Wrong Answer
2,107
57,224
655
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
N,Q = map(int,input().split()) a = [0 for _ in range(N-1)] b = [0 for _ in range(N-1)] for i in range(N-1): a[i],b[i] = map(int,input().split()) p = [0 for _ in range(Q)] x = [0 for _ in range(Q)] for i in range(Q): p[i],x[i] = map(int,input().split()) parent = [0 for _ in range(N)] counter = [0 for _ in range(N)] for i in range(Q): counter[p[i]-1] += x[i] for i in range(N-1): parent[b[i]-1] = a[i]-1 point = [counter[i] for i in range(N)] for i in range(1,N): now = i while(1): point[i] += counter[parent[now]] if parent[now] == 0: break else: now = parent[now] print(point)
s765857564
Accepted
1,553
56,088
631
from collections import deque def main(): n,q = map(int,input().split()) node = [[]for _ in range(n)] looked = [1]*n for i in range(n-1): a,b = map(int,input().split()) node[b-1].append(a-1) node[a-1].append(b-1) counter = [0]*n for i in range(q): p,x = map(int,input().split()) counter[p-1] += x queue = deque([0]) looked[0] = 0 while(queue): now = queue.pop() for i in node[now]: if looked[i]: queue.append(i) counter[i] += counter[now] looked[i] = 0 print(*counter) main()
s759272386
p03854
u079625320
2,000
262,144
Wrong Answer
25
4,976
143
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
import re S = input() t = re.findall('dream|dremer|eraser|erase', S) print(t) T = ''.join(t) if S == T: print('YES') else: print('NO')
s351229801
Accepted
25
4,512
159
import re S = ''.join(list(reversed(input()))) t = re.findall("maerd|remaerd|resare|esare",S) T = ''.join(t) if S == T: print("YES") else: print("NO")
s484356724
p03447
u875924067
2,000
262,144
Wrong Answer
17
2,940
86
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
x = int(input("")) a = int(input("")) b = int(input("")) ans = x - a - b print(ans)
s166236048
Accepted
17
2,940
132
x = int(input("")) a = int(input("")) b = int(input("")) x = x - a i = 0 while(x - b * i >= 0): i+=1 i-=1 print(x - b * i)
s368605043
p03605
u916743460
2,000
262,144
Wrong Answer
18
3,064
86
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
n = int(input()) if n / 10 == 9 or n % 10 == 9: print("yes") else : print("no")
s110845106
Accepted
17
2,940
97
n = int(input()) if n / 10 == 9 or n % 10 == 9 or n >= 90: print("Yes") else : print("No")
s515103869
p03699
u268318377
2,000
262,144
Wrong Answer
17
3,064
317
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
import sys read = sys.stdin.buffer.read N = int(input()) S = list(map(int, read().rstrip().split())) sumS = sum(S) if all(s % 10 == 0 for s in S): print(0) elif sumS % 10 != 0: print(sumS) else: S = sorted(S) for s in S: if s % 10 != 0: t = s break print(sumS - t)
s648823757
Accepted
17
3,064
269
N = int(input()) S = [int(input()) for _ in range(N)] sumS = sum(S) if all(s % 10 == 0 for s in S): print(0) elif sumS % 10 != 0: print(sumS) else: S = sorted(S) for s in S: if s % 10 != 0: t = s break print(sumS - t)
s016496616
p02690
u864069774
2,000
1,048,576
Wrong Answer
25
9,352
426
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
import itertools z = [] for i in range(100): a =i**5 # print(a) z.append(a) if len(str(a)) > 9: break X = int(input()) z_p = list(itertools.permutations(z, 2)) for i in range(len(z_p)): if z_p[i][0] - z_p[i][1] == X: print(z.index(z_p[i][0]),z.index(z_p[i][1])) exit() elif z_p[i][0] + z_p[i][1] == X: print(z.index(z_p[i][0]),-(z.index(z_p[i][1]))) exit()
s832870360
Accepted
173
80,344
389
import itertools z = [] for i in range(1000): a =i**5 # print(a) z.append(a) X = int(input()) z_p = list(itertools.permutations(z, 2)) for i in range(len(z_p)): if z_p[i][0] - z_p[i][1] == X: print(z.index(z_p[i][0]),z.index(z_p[i][1])) exit() elif z_p[i][0] + z_p[i][1] == X: print(z.index(z_p[i][1]),-(z.index(z_p[i][0]))) exit()
s676595063
p00295
u797673668
1,000
131,072
Wrong Answer
80
7,860
1,269
フロッピーキューブをプログラミングで解いてみましょう。フロッピーキューブは図のように表面に色のついた9個の立方体から構成されている立体パズルで、キューブの列を回転させることによって、6つの各面の色をそろえます。 フロッピーキューブに対しては下図のような4種類の操作を行うことができ、一回の操作で、端にある3つの隣接したキューブを180度回転することができます。わかりやすいように、図では、上面に+(赤色)、下面に*(緑色)、右前面に□(黄色)、左前面に●(青色)、右奥面に○(水色)、左奥面に■紫色) の記号が付いている状態を初期状態としています。 フロッピーキューブの初期状態が与えられるので、パズルを解くために必要な最小の操作回数を求めるプログラムを作成してください。
import heapq swap_list = [ {(6, 21), (7, 22), (8, 23), (9, 11), (12, 17)}, {(0, 27), (1, 28), (2, 29), (14, 15), (18, 20)}, {(0, 23), (3, 26), (6, 29), (15, 17), (9, 20)}, {(2, 21), (5, 24), (8, 27), (12, 14), (11, 18)} ] def check_complete(cube): for surface in (cube[:9], cube[9:12], cube[12:15], cube[15:18], cube[18:21]): val = surface[0] if any(block - val for block in surface): return False return True def next_cubes(cube, prev): nc = [None] * 4 for i in range(4): if i != prev: nci = cube[:] for a, b in swap_list[i]: nci[a], nci[b] = cube[b], cube[a] nc[i] = nci return nc n = int(input()) while n: cube0 = list(map(int, input().split())) checked = [] queue = [(0, cube0, -1)] while queue: cnt, cube, prev = heapq.heappop(queue) print(cnt, cube, prev) if cube in checked: continue if check_complete(cube): print(cnt) break checked.append(cube) for i, next_cube in enumerate(next_cubes(cube, prev)): if next_cube and not next_cube in checked: heapq.heappush(queue, (cnt + 1, next_cube, i)) n -= 1
s914747134
Accepted
240
7,884
1,238
import heapq swap_list = [ {(6, 21), (7, 22), (8, 23), (9, 11), (12, 17)}, {(0, 27), (1, 28), (2, 29), (14, 15), (18, 20)}, {(0, 23), (3, 26), (6, 29), (15, 17), (9, 20)}, {(2, 21), (5, 24), (8, 27), (12, 14), (11, 18)} ] def check_complete(cube): for surface in (cube[:9], cube[9:12], cube[12:15], cube[15:18], cube[18:21]): val = surface[0] if any(block - val for block in surface): return False return True def next_cubes(cube, prev): nc = [None] * 4 for i in range(4): if i != prev: nci = cube[:] for a, b in swap_list[i]: nci[a], nci[b] = cube[b], cube[a] nc[i] = nci return nc n = int(input()) while n: cube0 = list(map(int, input().split())) checked = [] queue = [(0, cube0, -1)] while queue: cnt, cube, prev = heapq.heappop(queue) if cube in checked: continue if check_complete(cube): print(cnt) break checked.append(cube) for i, next_cube in enumerate(next_cubes(cube, prev)): if next_cube and not next_cube in checked: heapq.heappush(queue, (cnt + 1, next_cube, i)) n -= 1
s439656645
p03999
u378691508
2,000
262,144
Wrong Answer
31
9,168
194
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
S=input() n=len(S) ans=0 for paint in range((n-1)**2): temp_S=S[0] for i in range(n-1): if (paint>>i)&1==1: temp_S+="+" temp_S+=S[i] ans+=sum(map(int, temp_S.split("+"))) print(ans)
s329036050
Accepted
33
9,192
199
S=input() n=len(S) ans=0 for paint in range(2**(n-1)): temp_S=S[0] for i in range(n-1): if (paint>>i)&1==1: temp_S+="+" temp_S+=S[i+1] ans+=sum(map(int, temp_S.split("+"))) print(ans)
s782956395
p03854
u928784113
2,000
262,144
Wrong Answer
89
3,188
200
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
S = input() i = 0 while S: S = S.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") i += 1 if i == 10**5+1: print("NO") exit() print("Yes")
s895050287
Accepted
91
3,188
200
S = input() i = 0 while S: S = S.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") i += 1 if i == 10**5+1: print("NO") exit() print("YES")
s684287963
p03471
u557523358
2,000
262,144
Wrong Answer
2,103
3,060
248
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
n, y = map(int, input().split()) x, y, z = -1, -1, -1 for i in range(n + 1): for j in range(n + 1 - i): for k in range(n + 1 - i - j): if 10000 * i + 5000 * j + 1000 * k == y: x, y, z = i, j, k print(x, y, z)
s876616588
Accepted
769
3,060
231
n, total = map(int, input().split()) x, y, z = -1, -1, -1 for i in range(n + 1): for j in range(n + 1 - i): k = n - i - j if 10000 * i + 5000 * j + 1000 * k == total: x, y, z = i, j, k print(x, y, z)
s735913477
p04043
u788023488
2,000
262,144
Wrong Answer
17
2,940
140
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.
List = [int(i) for i in input().split()] List.sort() ans='No' if List[0]==5: if List[1]==5: if List[2]==7: ans='Yes' print(ans)
s296724307
Accepted
17
2,940
140
List = [int(i) for i in input().split()] List.sort() ans='NO' if List[0]==5: if List[1]==5: if List[2]==7: ans='YES' print(ans)
s848182053
p00024
u777299405
1,000
131,072
Wrong Answer
50
7,380
98
Ignoring the air resistance, velocity of a freely falling object $v$ after $t$ seconds and its drop $y$ in $t$ seconds are represented by the following formulas: $ v = 9.8 t $ $ y = 4.9 t^2 $ A person is trying to drop down a glass ball and check whether it will crack. Your task is to write a program to help this experiment. You are given the minimum velocity to crack the ball. Your program should print the lowest possible floor of a building to crack the ball. The height of the $N$ floor of the building is defined by $5 \times N - 5$.
import math m = float(input()) t = m / 9.8 y = 4.9 * t * t n = math.ceil(y / 5) print(int(n + 1))
s581577826
Accepted
40
7,504
129
import math import sys for s in sys.stdin: d = float(s) y = 4.9 * (d / 9.8)**2 n = math.ceil(y / 5) + 1 print(n)
s594160481
p03657
u772588522
2,000
262,144
Wrong Answer
17
2,940
96
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
a, b = map(int, input().split()) if a+b % 3: print('Impossible') else: print('Possible')
s198291471
Accepted
17
2,940
274
a, b = map(int, input().split()) if not (a+b) % 3 or not a % 3 or not b % 3: print('Possible') else: print('Impossible') #if not a % 3: # print('Impossible') #elif not b % 3: # print('Impossible') #elif not a+b % 3: # print('Impossible') #else: # print('Possible')
s425121062
p03385
u734805215
2,000
262,144
Wrong Answer
17
2,940
108
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
s=input() flag = s.count('a')*s.count('b')*s.count('c') if flag >=1: print('yes') else: print('no')
s413100324
Accepted
17
2,940
108
s=input() flag = s.count('a')*s.count('b')*s.count('c') if flag >=1: print('Yes') else: print('No')
s746635511
p03543
u921773161
2,000
262,144
Wrong Answer
17
2,940
80
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
N = input() if N[0] == N[1] == N[2] == N[3] : print('Yes') else: print('No')
s078655434
Accepted
17
2,940
117
N = input() if N[0] == N[1] == N[2] : print('Yes') elif N[1] == N[2] == N[3] : print('Yes') else: print('No')
s711256214
p03853
u732844340
2,000
262,144
Wrong Answer
44
4,472
225
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).
hw_ = list(map(int, input().split())) h = hw_[0] w = hw_[1] c = [] for i in range(0, h): c.append(input()) print(c) for i in range(0, h * 2): for j in range(0, w): print(c[int(i / 2)][j],end='') print()
s377613779
Accepted
45
4,472
216
hw_ = list(map(int, input().split())) h = hw_[0] w = hw_[1] c = [] for i in range(0, h): c.append(input()) for i in range(0, h * 2): for j in range(0, w): print(c[int(i / 2)][j],end='') print()
s068618851
p03854
u283929013
2,000
262,144
Wrong Answer
18
3,188
405
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
S = input() marker = 0 flag = True while flag and (marker < len(S)): if S[marker:marker+5] == "dream": marker += 5 if S[marker+5:marker+7] == "er": marker += 2 elif S[marker:marker+5] == "erase": marker += 5 if S[marker+5:marker+6] == "r": marker += 1 else: flag = False if flag: print("Yes") else: print("No")
s743354726
Accepted
28
3,188
391
S = input() marker = len(S) flag = True while flag and (marker > 0): if S[marker-7:marker] == "dreamer": marker -= 7 elif S[marker-6:marker] == "eraser": marker -= 6 elif S[marker-5:marker] == "dream": marker -= 5 elif S[marker-5:marker] == "erase": marker -= 5 else: flag = False if flag: print("YES") else: print("NO")
s751713817
p03555
u354773735
2,000
262,144
Wrong Answer
17
2,940
309
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.
# coding: utf-8 #a = int(input()) #b = int(input()) #a, b, c = map(int, input().split()) s1 = input() s2 = input() if s1[0] == s2[2] and s1[1] == s2[1] and s1[2] == s2[0]: ans = "Yes" else : ans = "No" print(ans)
s104696445
Accepted
17
3,060
309
# coding: utf-8 #a = int(input()) #b = int(input()) #a, b, c = map(int, input().split()) s1 = input() s2 = input() if s1[0] == s2[2] and s1[1] == s2[1] and s1[2] == s2[0]: ans = "YES" else : ans = "NO" print(ans)
s612745183
p04012
u640603056
2,000
262,144
Wrong Answer
18
3,064
462
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
import sys def ILI(): return list(map(int, sys.stdin.readline().rstrip().split())) def ISI(): return map(int, sys.stdin.readline().rstrip().split()) def II(): return int(sys.stdin.readline().rstrip()) def ISS(): return sys.stdin.readline().rstrip().split() def IS(): return sys.stdin.readline().rstrip() w = list(IS()) set_w = set(w) for s in set_w: if w.count(s)%2 != 0: print("NO") break else: print("YES")
s860904319
Accepted
17
3,064
462
import sys def ILI(): return list(map(int, sys.stdin.readline().rstrip().split())) def ISI(): return map(int, sys.stdin.readline().rstrip().split()) def II(): return int(sys.stdin.readline().rstrip()) def ISS(): return sys.stdin.readline().rstrip().split() def IS(): return sys.stdin.readline().rstrip() w = list(IS()) set_w = set(w) for s in set_w: if w.count(s)%2 != 0: print("No") break else: print("Yes")
s704647567
p03069
u626468554
2,000
1,048,576
Wrong Answer
84
8,036
268
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
#!/usr/bin/env python3 n = int(input()) s = input() S =[] for i in s: S.append(i) w = 0 b = 0 an = n for i in range(n-1,-1,-1): if i == "#": b += 1 elif i == ".": w += 1 if w > b: an = n-i print(S) print(i)
s093266170
Accepted
157
12,936
378
#!/usr/bin/env python3 n = int(input()) s = input() S =[] for i in s: S.append(i) w = 0 b = 0 for i in range(n): if S[i] == "#": b += 1 elif S[i] == ".": w += 1 ans = [0 for i in range(n+1)] ans[0] = w for i in range(n): if S[i] == "#": ans[i+1] = ans[i]+1 elif S[i] == ".": ans[i+1] = ans[i]-1 print(min(ans))
s900974826
p03386
u163874353
2,000
262,144
Wrong Answer
2,153
798,488
158
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a, b, k = map(int, input().split()) l =[] for i in range(a, b): l.append(i) #print(l) f = l[:k] b = l[len(l) - k:] n = f + b for j in l: print(j)
s411082380
Accepted
17
3,060
190
a, b, k = map(int, input().split()) l = [] for i in range(a, min(a + k, b)): l.append(i) for i in range(max(a, b - k + 1), b + 1): l.append(i) for i in sorted(set(l)): print(i)
s585371828
p02692
u159723084
2,000
1,048,576
Wrong Answer
232
16,844
1,016
There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
# -*- coding: utf-8 -*- N,A,B,C=input().split() D=dict() D["A"]=int(A) D["B"]=int(B) D["C"]=int(C) S=[] for i in range(int(N)): S.append(input()) ans="Yes" F=[] for i,s in enumerate(S): if D[s[0]]==0 and D[s[1]]==0: ans="No" break if D[s[0]]==0 and D[s[1]]==1: D[s[0]]=1 D[s[1]]=0 F.append(s[0]) if D[s[0]]==1 and D[s[1]]==0: D[s[0]]=0 D[s[1]]=1 F.append(s[1]) if D[s[0]]==1 and D[s[1]]==1: if D["A"]+D["B"]+D["C"]==2: if i!=int(N)-1: s0=S[i+1][0] s1=S[i+1][1] if s[0]==s0 or s[0]==s1: D[s[0]]=2 D[s[1]]=0 F.append(s[0]) if s[1]==s0 or s[1]==s1: D[s[0]]=0 D[s[1]]=2 F.append(s[1]) if len(F)!=i+1: D[s[0]]+=1 D[s[1]]-=1 F.append(s[0]) print(ans) if ans=="Yes": for f in F: print(f)
s535585994
Accepted
286
16,860
976
# -*- coding: utf-8 -*- N,A,B,C=input().split() D=dict() D["A"]=int(A) D["B"]=int(B) D["C"]=int(C) S=[] for i in range(int(N)): S.append(input()) ans="Yes" F=[] for i,s in enumerate(S): if D[s[0]]==0 and D[s[1]]==0: ans="No" break if D[s[0]]==1 and D[s[1]]==1: if D["A"]+D["B"]+D["C"]==2: if i!=int(N)-1: if S[i+1] != s: s0=S[i+1][0] s1=S[i+1][1] if s[0]==s0 or s[0]==s1: F.append(s[0]) if s[1]==s0 or s[1]==s1: F.append(s[1]) if len(F)!=i+1: if D[s[0]]<D[s[1]]: F.append(s[0]) if D[s[0]]>D[s[1]]: F.append(s[1]) if D[s[0]]==D[s[1]]: F.append(s[0]) D[F[-1]]+=1 if s[0]==F[-1]: D[s[1]]-=1 if s[1]==F[-1]: D[s[0]]-=1 #print(D) #print(F) print(ans) if ans=="Yes": for f in F: print(f)
s679966304
p03361
u062147869
2,000
262,144
Wrong Answer
18
3,064
422
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
H,W = map(int, input().split()) S = [list(input()) for i in range(H)] T =[['.']*(W+2)] for y in range (H): T.append(['.']+S[y]+['.']) T.append(['.']*(W+2)) ans = 'Yes' for y in range(1,H+1): for x in range(1,W+1): if ((T[y][x]=='#') and (T[y-1][x-1]=='.') and (T[y+1][x-1]=='.') and (T[y-1][x+1]=='.') and (T[y+1][x+1]=='.') ): ans = 'No' print(ans)
s480581036
Accepted
22
3,064
414
H,W = map(int, input().split()) S = [list(input()) for i in range(H)] T =[['.']*(W+2)] for y in range (H): T.append(['.']+S[y]+['.']) T.append(['.']*(W+2)) ans = 'Yes' for y in range(1,H+1): for x in range(1,W+1): if ((T[y][x]=='#') and (T[y-1][x]=='.') and (T[y+1][x]=='.') and (T[y][x+1]=='.') and (T[y][x-1]=='.') ): ans = 'No' print(ans)
s926070035
p03485
u204800924
2,000
262,144
Wrong Answer
17
2,940
99
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b = map(int, input().split()) if (a+b)%2 == 0: print((a+b)/2) else : print((a+b)/2 + 1)
s405191080
Accepted
18
2,940
109
a,b = map(int, input().split()) if (a+b)%2 == 0: print(int((a+b)/2)) else : print(int((a+b)/2) + 1)
s916494362
p03671
u516579758
2,000
262,144
Wrong Answer
17
2,940
62
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
l=list(map(int,input().split())) d=min(l) e=min(l) print(d+e)
s801698408
Accepted
17
2,940
73
l=list(map(int,input().split())) d=min(l) l.remove(d) e=min(l) print(d+e)
s133904456
p02663
u308914480
2,000
1,048,576
Wrong Answer
30
9,100
71
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
H1,H2,M1,M2,K=map(int, input().split()) print(((60*(H2-H1))+(M2-M1)-K))
s053715761
Accepted
25
9,156
73
a,b,c,d,e=map(int,input().split()) l=(60*c+d)-(60*a+b) ans=l-e print(ans)
s096731474
p04031
u751047721
2,000
262,144
Wrong Answer
53
3,064
277
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()) list_n = [int(n) for n in input().split(' ')] print(list_n) A = 0 for n in list_n: A += (100-n)**2 for n in range(-100,100): B = 0 for num in list_n: B += (n-num)**2 if A > B: A = B print(A)
s789503793
Accepted
51
3,064
263
n = int(input()) list_n = [int(n) for n in input().split(' ')] A = 0 for n in list_n: A += (100-n)**2 for n in range(-100,100): B = 0 for num in list_n: B += (n-num)**2 if A > B: A = B print(A)
s036577390
p02612
u857657465
2,000
1,048,576
Wrong Answer
28
9,140
31
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N%1000)
s217649811
Accepted
29
9,144
76
N = int(input()) if(N%1000 == 0): print(0) else: print(1000-N%1000)
s812291106
p02613
u867320886
2,000
1,048,576
Wrong Answer
147
9,236
326
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for _ in range(n): s = input() if s=="AC": ac += 1 elif s=="WA": wa += 1 elif tle=="TLE": tle += 1 else: re += 1 print("AC x {}".format(ac)) print("WA x {}".format(wa)) print("TLE x {}".format(tle)) print("RE x {}".format(re))
s335687784
Accepted
150
9,204
324
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for _ in range(n): s = input() if s=="AC": ac += 1 elif s=="WA": wa += 1 elif s=="TLE": tle += 1 else: re += 1 print("AC x {}".format(ac)) print("WA x {}".format(wa)) print("TLE x {}".format(tle)) print("RE x {}".format(re))
s189591877
p02865
u278183305
2,000
1,048,576
Wrong Answer
17
2,940
22
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
print(int(input())//2)
s526733206
Accepted
17
2,940
26
print((int(input())-1)//2)
s423761940
p03378
u007550226
2,000
262,144
Wrong Answer
17
3,060
169
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.
_,M,X = list(map(int,input().split())) a = list(map(int,input().split())) for i,c in enumerate(a): print(i,c,X) if X < c: print(min(i,M-i)) break
s515452331
Accepted
18
3,060
221
_,M,X = list(map(int,input().split())) a = list(map(int,input().split())) ''' for i,c in enumerate(a): if X < c: print(min(i,M-i)) break ''' import bisect i = bisect.bisect_left(a,X) print(min(i,M-i))
s161101837
p03679
u766566560
2,000
262,144
Wrong Answer
17
2,940
146
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
X, A, B = map(int, input().split()) if X - A >= 0: print('delicious') elif A - X < 0 and B - A <= X: print('safe') else: print('dangerous')
s115877747
Accepted
18
2,940
136
X, A, B = map(int, input().split()) if A - B >= 0: print('delicious') elif A < B <= A + X: print('safe') else: print('dangerous')
s888342828
p03196
u319245933
2,000
1,048,576
Wrong Answer
56
9,208
712
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.
def prime_factorize(n): a = [] f = 2 while f * f <= n: count = 0 while n % f == 0: count += 1 n //= f if count: a.append([f, count]) f += 2 if f != 2 else 1 if n != 1: a.append([n, 1]) return a N, P = map(int, input().split()) res = 1 for p in prime_factorize(P): for _ in range(p[1] // 4): res *= p[0] print(res)
s943288250
Accepted
64
9,192
712
def prime_factorize(n): a = [] f = 2 while f * f <= n: count = 0 while n % f == 0: count += 1 n //= f if count: a.append([f, count]) f += 2 if f != 2 else 1 if n != 1: a.append([n, 1]) return a N, P = map(int, input().split()) res = 1 for p in prime_factorize(P): for _ in range(p[1] // N): res *= p[0] print(res)
s336599764
p03469
u028973125
2,000
262,144
Wrong Answer
27
8,892
66
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
import sys S = sys.stdin.readline().strip() print("2018" + S[5:])
s878176647
Accepted
26
9,016
67
import sys S = sys.stdin.readline().strip() print("2018" + S[4:])
s853078557
p02618
u940533000
2,000
1,048,576
Wrong Answer
180
27,300
620
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
import numpy as np D = int(input()) c = list(map(int, input().split())) s = [] for i in range(D): tmp = list(map(int, input().split())) s.append(tmp) penalty = np.zeros(26) date = np.zeros(26) for i in range(D): for j in range(26): penalty[j] = c[j]*((i+1)-date[j]) max_performance = 0 max_idx = 0 for j in range(26): tmp_performance = s[i][j] - sum(penalty) + c[j]*((i+1)-date[j]) if max_performance < tmp_performance: max_performance = tmp_performance max_idx = j+1 date[max_idx-1] = i+1 print(max_idx)
s600668131
Accepted
121
27,380
310
import numpy as np D = int(input()) c = list(map(int, input().split())) s = [] for i in range(D): tmp = list(map(int, input().split())) s.append(tmp) for i in range(D): val_max = 0 idx_max = 0 for j in range(26): if val_max < s[i][j]: val_max = s[i][j] idx_max = j+1 print(idx_max)
s817030497
p03712
u065099501
2,000
262,144
Wrong Answer
29
9,092
147
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
h,w=map(int,input().split()) a=[input() for _ in range(h)] print('*'*len(max(a))+'**') for s in a: print('*'+s+'*') print('*'*len(max(a))+'**')
s073445215
Accepted
25
9,104
147
h,w=map(int,input().split()) a=[input() for _ in range(h)] print('#'*len(max(a))+'##') for s in a: print('#'+s+'#') print('#'*len(max(a))+'##')
s697074049
p03433
u830162518
2,000
262,144
Wrong Answer
17
2,940
131
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: print('Yes') if N>A: if (N-A)%500==0: print('Yes') else: print('No')
s836629504
Accepted
17
2,940
92
N=int(input()) A=int(input()) b=N//500 c=N-500*b if c<=A: print('Yes') else: print('No')
s669836232
p03378
u729300713
2,000
262,144
Wrong Answer
20
2,940
106
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
n, m, x = map(int, input().split()) a = list(map(int, input().split())) print(max(sum(a[:m]), sum(a[m:])))
s573904001
Accepted
17
2,940
154
n, m, x = map(int, input().split()) a = list(map(int, input().split())) for i,j in enumerate(a): if j > x: cnt = i break print(min(cnt, m-cnt))
s826389171
p02936
u368796742
2,000
1,048,576
Wrong Answer
1,557
52,404
534
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
from collections import deque n,q = map(int,input().split()) E = [[] for i in range(n)] for i in range(n-1): a,b = map(int,input().split()) E[a-1].append(b-1) score = [0]*n for i in range(q): a,b = map(int,input().split()) score[a-1] += b def bfs(i): s = score[i-1] q = deque([]) q.append((i-1,s)) while q: num,sco = q.popleft() for j in E[num]: score[j] += sco sco = score[j] q.append((j,sco)) return score print(*bfs(1))
s196632704
Accepted
1,767
62,236
614
from collections import deque n,q = map(int,input().split()) E = [[] for i in range(n)] for i in range(n-1): a,b = map(int,input().split()) E[a-1].append(b-1) E[b-1].append(a-1) score = [0]*n for i in range(q): a,b = map(int,input().split()) score[a-1] += b def bfs(i): s = -1 q = deque([]) q.append((i-1,s)) while q: num,bef = q.pop() for j in E[num]: if j == bef: continue else: score[j] += score[num] q.append((j,num)) return score print(*bfs(1))
s079330913
p03503
u020373088
2,000
262,144
Wrong Answer
306
3,064
367
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
import itertools n = int(input()) f = [list(map(int, input().split())) for i in range(n)] p = [list(map(int, input().split())) for i in range(n)] ans = -float("inf") for i in itertools.product((0,1), repeat=10): a = 0 for j in range(n): c = 0 for k in range(10): if i[k] == f[j][k]: c += 1 a += p[j][c] ans = max(ans, a) print(ans)
s592692630
Accepted
317
3,064
411
import itertools n = int(input()) f = [list(map(int, input().split())) for i in range(n)] p = [list(map(int, input().split())) for i in range(n)] ans = -float("inf") for i in itertools.product((0,1), repeat=10): if list(i) == [0] * 10: continue a = 0 for j in range(n): c = 0 for k in range(10): if i[k] == f[j][k] == 1: c += 1 a += p[j][c] ans = max(ans, a) print(ans)
s939042856
p02263
u728700495
1,000
131,072
Wrong Answer
30
7,788
388
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
import re data = input().split() stack = [] for elem in data: if re.match('\d+', elem): stack.append(int(elem)) else: a = stack.pop() b = stack.pop() if elem == "+": stack.append(b+a) elif elem == "-": stack.append(b-a) elif elem == "*": stack.append(b*a) print(elem, stack) print(stack[0])
s211044022
Accepted
30
7,808
366
import re data = input().split() stack = [] for elem in data: if re.match('\d+', elem): stack.append(int(elem)) else: a = stack.pop() b = stack.pop() if elem == "+": stack.append(b+a) elif elem == "-": stack.append(b-a) elif elem == "*": stack.append(b*a) print(stack[0])
s794105353
p03448
u766566560
2,000
262,144
Wrong Answer
53
3,060
218
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) B = int(input()) C = int(input()) X = int(input()) ans = 0 for i in range(A): for j in range(B): for k in range(C): if X == 500 * i + 100 * j + 50 * k: ans += 1 print(ans)
s056852614
Accepted
50
3,060
216
A = int(input()) B = int(input()) C = int(input()) X = int(input()) ans = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if X == 500 * i + 100 * j + 50 * k: ans += 1 print(ans)
s646623784
p03761
u667084803
2,000
262,144
Wrong Answer
32
3,956
255
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
import string # -*- coding: utf-8 -*- n=int(input()) S=[] for i in range (0,n): S.append(input()) count=0 for c in range(97,97+26): a=S[0].count(chr(c)) for i in range(0,n): a=min(a,S[i].count(chr(c))) count+=a print(count)
s932068510
Accepted
25
3,768
289
import string # -*- coding: utf-8 -*- n=int(input()) S=[] for i in range (0,n): S.append(input()) count=0 ans="" for c in range(97,97+26): a=S[0].count(chr(c)) for i in range(0,n): a=min(a,S[i].count(chr(c))) for i in range (0,a): ans+=chr(c) print(ans)
s251026553
p02612
u604398799
2,000
1,048,576
Wrong Answer
138
31,152
479
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
# -*- coding: utf-8 -*- import bisect import copy import collections import heapq import itertools import math import numpy as np from operator import itemgetter import scipy.misc import sys N=int(input()) def main(): print(N%1000) return if __name__ == '__main__': main()
s756666823
Accepted
131
31,052
490
# -*- coding: utf-8 -*- import bisect import copy import collections import heapq import itertools import math import numpy as np from operator import itemgetter import scipy.misc import sys N=int(input()) def main(): print((1000-N%1000)%1000) return if __name__ == '__main__': main()
s651370384
p03129
u966000628
2,000
1,048,576
Wrong Answer
17
2,940
86
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
n,m = list(map(int,input().split())) if m*2+1 <= n: print("YES") else: print("NO")
s862833690
Accepted
18
2,940
87
n,m = list(map(int,input().split())) if m*2-1 <= n: print("YES") else: print("NO")
s028465916
p03067
u065025264
2,000
1,048,576
Wrong Answer
17
2,940
124
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] = list(map(int, input().split(' '))) print(a, b, c) if a < b and c < b: print("Yes") else: print("No")
s361308644
Accepted
17
2,940
147
[a, b, c] = list(map(int, input().split(' '))) if a < c and c < b: print("Yes") elif b < c and c < a: print("Yes") else: print("No")
s316163562
p02853
u776864893
2,000
1,048,576
Wrong Answer
17
3,060
364
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
code,implement = input().split(" ") def prize_dict(rank): if rank == "1": prize = 300000 elif rank == "2": prize = 200000 elif rank == "3": prize = 100000 else: prize = 0 return prize if code == "1" and implement == "1": prize = 400000 else: prize = prize_dict(code)+prize_dict(implement) print(prize)
s665969685
Accepted
17
3,064
365
code,implement = input().split(" ") def prize_dict(rank): if rank == "1": prize = 300000 elif rank == "2": prize = 200000 elif rank == "3": prize = 100000 else: prize = 0 return prize if code == "1" and implement == "1": prize = 1000000 else: prize = prize_dict(code)+prize_dict(implement) print(prize)
s569124294
p02396
u987701388
1,000
131,072
Wrong Answer
80
5,900
145
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
a= [] while True: x=int(input()) if x==0: break a.append(x) j=0 for i in a: j+=1 print('case {0}: {1}'.format(j,i))
s424863373
Accepted
140
5,600
103
i=1 while True: x=int(input()) if x==0: break print("Case {0}: {1}".format(i,x)) i+=1
s174557616
p02612
u366996583
2,000
1,048,576
Wrong Answer
25
9,136
48
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
X=int(input()) while X>=1000: X-=1000 print(X)
s867336554
Accepted
32
9,144
52
X=int(input()) while X>1000: X-=1000 print(1000-X)
s140833364
p03139
u782654209
2,000
1,048,576
Wrong Answer
18
2,940
69
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
N,A,B=map(int,input().split(' ')) print(str(A+B-N)+' '+str(min(A,B)))
s950912693
Accepted
17
2,940
78
N,A,B=map(int,input().split(' ')) print(str(min(A,B))+' '+str(max(0,(A+B-N))))
s756628501
p02421
u986478725
1,000
131,072
Wrong Answer
20
5,596
496
Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in lexicographical order becomes the winner of that turn. The winner obtains 3 points. In the case of a draw, they obtain 1 point each. Write a program which reads a sequence of cards Taro and Hanako have and reports the final scores of the game.
# AOJ ITP1_9_C def numinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def main(): SCORE_taro = 0 SCORE_hanako = 0 n = int(input()) for i in range(n): words = input() if words[0] > words[1]: SCORE_taro += 3 elif words[0] < words[1]: SCORE_hanako += 3 else: SCORE_taro += 1; SCORE_hanako += 1 print(str(SCORE_taro) + " " + str(SCORE_hanako)) if __name__ == "__main__": main()
s422672348
Accepted
20
5,600
504
# AOJ ITP1_9_C def numinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def main(): SCORE_taro = 0 SCORE_hanako = 0 n = int(input()) for i in range(n): words = input().split() if words[0] > words[1]: SCORE_taro += 3 elif words[0] < words[1]: SCORE_hanako += 3 else: SCORE_taro += 1; SCORE_hanako += 1 print(str(SCORE_taro) + " " + str(SCORE_hanako)) if __name__ == "__main__": main()
s568013159
p03605
u723721005
2,000
262,144
Wrong Answer
17
3,060
129
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?
a=int(input()) b=[19.29,39,49,59,69,79,89,90,91,92,93,94,95,96,97,98,99] if b.count(a)!=0: print("Yes") else: print("No")
s614794141
Accepted
17
2,940
58
if "9" in input(): print("Yes") else: print("No")
s162763429
p00033
u661290476
1,000
131,072
Wrong Answer
20
7,612
297
図のように二股に分かれている容器があります。1 から 10 までの番号が付けられた10 個の玉を容器の開口部 A から落とし、左の筒 B か右の筒 C に玉を入れます。板 D は支点 E を中心に左右に回転できるので、板 D を動かすことで筒 B と筒 C のどちらに入れるか決めることができます。 開口部 A から落とす玉の並びを与えます。それらを順番に筒 B 又は筒 Cに入れていきます。このとき、筒 B と筒 C のおのおのが両方とも番号の小さい玉の上に大きい玉を並べられる場合は YES、並べられない場合は NO と出力するプログラムを作成してください。ただし、容器の中で玉の順序を入れ替えることはできないものとします。また、続けて同じ筒に入れることができるものとし、筒 B, C ともに 10 個の玉がすべて入るだけの余裕があるものとします。
def solve(n,left,right): if n==10: return 1 if a[n]>left: return solve(n+1,a[n],right) if a[n]>right: return solve(n+1,left,a[n]) return 0 n=int(input()) for _ in range(n): a=[int(i) for i in input().split()] print("YES" if solve(10,0,0) else "NO")
s088723729
Accepted
20
7,620
346
ans=0 def solve(n,left,right): global ans if n==10: ans=1 else: if a[n]>left: ans=solve(n+1,a[n],right) if a[n]>right: ans=solve(n+1,left,a[n]) return ans n=int(input()) for _ in range(n): a=[int(i) for i in input().split()] print("YES" if solve(0,0,0) else "NO") ans=0
s195953904
p02402
u518939641
1,000
131,072
Wrong Answer
30
7,544
92
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
n=int(input()) l=list(map(int,input().split())) print('%d %d %d'%(min(l), max(l), sum(l)/n))
s541521124
Accepted
60
8,580
90
n=int(input()) l=list(map(int,input().split())) print('%d %d %d'%(min(l), max(l), sum(l)))
s631050520
p03129
u401093859
2,000
1,048,576
Wrong Answer
18
2,940
91
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
N,K = map(int,input().split()) if N <= 1+(2*(K-1)): print("No") else: print("Yes")
s313808513
Accepted
17
2,940
91
N,K = map(int,input().split()) if N >= 1+(2*(K-1)): print("YES") else: print("NO")
s944567362
p00050
u150984829
1,000
131,072
Wrong Answer
20
5,532
33
福島県は果物の産地としても有名で、その中でも特に桃とりんごは全国でも指折りの生産量を誇っています。ところで、ある販売用の英文パンフレットの印刷原稿を作ったところ、手違いでりんごに関する記述と桃に関する記述を逆に書いてしまいました。 あなたは、apple と peach を修正する仕事を任されましたが、なにぶん面倒です。1行の英文を入力して、そのなかの apple という文字列を全て peach に、peach という文字列を全てapple に交換した英文を出力するプログラムを作成してください。
input().replace('apple','peach')
s732179054
Accepted
20
5,544
80
a,p,t='apple','peach','_' print(input().replace(a,t).replace(p,a).replace(t,p))
s293496170
p03434
u769411997
2,000
262,144
Wrong Answer
17
3,060
196
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = int(input()) a = list(map(int, input().split())) ans = 0 a.sort(reverse = True) print(a) for i in range(len(a)): if i%2 == 0: ans += a[i] else: ans -= a[i] print(ans)
s990848115
Accepted
17
3,060
187
n = int(input()) a = list(map(int, input().split())) ans = 0 a.sort(reverse = True) for i in range(len(a)): if i%2 == 0: ans += a[i] else: ans -= a[i] print(ans)
s171483828
p03472
u499259667
2,000
262,144
Wrong Answer
354
11,316
375
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?
import math N,H = map(int,input().split()) alis=[];blis=[] for c in range(N): a,b = map(int,input().split()) alis.append(a);blis.append(b) a = max(alis) blis.sort();blis.reverse() count = 0 num = 0 for i in blis: if num >= H: print(count) exit() if i < a: break num += i count += 1 count += math.floor((H-num)/a) print(count)
s263092313
Accepted
349
11,332
374
import math N,H = map(int,input().split()) alis=[];blis=[] for c in range(N): a,b = map(int,input().split()) alis.append(a);blis.append(b) a = max(alis) blis.sort();blis.reverse() count = 0 num = 0 for i in blis: if num >= H: print(count) exit() if i < a: break num += i count += 1 count += math.ceil((H-num)/a) print(count)
s972066294
p02928
u922952729
2,000
1,048,576
Wrong Answer
1,129
3,188
355
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
N,K=[int(i) for i in input().split(" ")] A=[int(i) for i in input().split(" ")] inside=0 for i in range(N): for j in range(i,N): if A[i]>A[j]: inside+=1 outside=0 for i in range(N): for j in range(N): if A[i]>A[j]: outside+=1 print(inside,outside) s=inside*K+outside*((K*(K-1))//2) print(s%(10**9+7))
s137060028
Accepted
1,039
3,188
332
N,K=[int(i) for i in input().split(" ")] A=[int(i) for i in input().split(" ")] inside=0 for i in range(N): for j in range(i,N): if A[i]>A[j]: inside+=1 outside=0 for i in range(N): for j in range(N): if A[i]>A[j]: outside+=1 s=inside*K+outside*((K*(K-1))//2) print(s%(10**9+7))
s498726153
p03457
u282412844
2,000
262,144
Wrong Answer
346
17,324
594
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
N = int(input()) travels = [] for i in range(N): t, x, y = map(int, input().split()) travels.append((t, x, y)) def is_possible(travels): current = (0, 0, 0) for t, x, y in travels: prev_t, prev_x, prev_y = current dt = t - prev_t dx = x - prev_x dy = y - prev_y dxy = dx + dy if dt < dxy: return False if dt == dxy: continue if (dt - dxy) % 2 != 0: return False current = (t, x, y) return True if is_possible(travels): print('YES') else: print('NO')
s105396487
Accepted
350
17,320
594
N = int(input()) travels = [] for i in range(N): t, x, y = map(int, input().split()) travels.append((t, x, y)) def is_possible(travels): current = (0, 0, 0) for t, x, y in travels: prev_t, prev_x, prev_y = current dt = t - prev_t dx = x - prev_x dy = y - prev_y dxy = dx + dy if dt < dxy: return False if dt == dxy: continue if (dt - dxy) % 2 != 0: return False current = (t, x, y) return True if is_possible(travels): print('Yes') else: print('No')
s899051792
p03997
u823885866
2,000
262,144
Wrong Answer
114
27,192
468
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.
import sys import math import itertools import collections import heapq import re import numpy as np from functools import reduce rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rf = lambda: map(float, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 print('test')
s974563660
Accepted
28
8,956
50
print((int(input())+int(input()))*int(input())//2)
s704068804
p02273
u631142478
2,000
131,072
Wrong Answer
30
6,156
717
Write a program which reads an integer _n_ and draws a Koch curve based on recursive calles of depth _n_. The Koch curve is well known as a kind of You should start (0, 0), (100, 0) as the first segment.
import math import collections N = int(input()) Point = collections.namedtuple('Point', ['x', 'y']) def koch(d, p1, p2): if d == 0: return th = math.pi * 60 / 180 s = Point(x=(2 * p1.x + p2.x) / 3, y=(2 * p1.y + p2.y) / 3) t = Point(x=(p1.x + 2 * p2.x) / 3, y=(p1.y + 2 * p2.y) / 3) u = Point(x=(t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x, y=(t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) - s.y) koch(d - 1, p1, s) print(s.x, s.y) koch(d - 1, s, u) print(u.x, u.y) koch(d - 1, u, t) print(t.x, t.y) koch(d - 1, t, p2) p1 = Point(x=0, y=0) p2 = Point(x=100, y=0) print(p1.x, p1.y) koch(N, p1, p2) print(p2.x, p2.y)
s295074722
Accepted
40
6,204
837
import math import collections N = int(input()) Point = collections.namedtuple('Point', ['x', 'y']) def koch(d, p1, p2): if d == 0: return th = math.pi * 60 / 180 s = Point(x=(2 * p1.x + p2.x) / 3, y=(2 * p1.y + p2.y) / 3) t = Point(x=(p1.x + 2 * p2.x) / 3, y=(p1.y + 2 * p2.y) / 3) u = Point(x=(t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x, y=(t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) + s.y) koch(d - 1, p1, s) print('{:.8f} {:.8f}'.format(s.x, s.y)) koch(d - 1, s, u) print('{:.8f} {:.8f}'.format(u.x, u.y)) koch(d - 1, u, t) print('{:.8f} {:.8f}'.format(t.x, t.y)) koch(d - 1, t, p2) p1 = Point(x=0, y=0) p2 = Point(x=100, y=0) print('{:.8f} {:.8f}'.format(p1.x, p1.y)) koch(N, p1, p2) print('{:.8f} {:.8f}'.format(p2.x, p2.y))
s622882531
p03401
u713368238
2,000
262,144
Wrong Answer
240
14,048
290
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
n = int(input()) a = list((map(int, input().split()))) a = [0] + a + [0] print(a) totalcost = 0 for i in range(len(a) - 1): totalcost += abs(a[i] - a[i+1]) for i in range(1, n+1): icost = totalcost + abs(a[i-1] - a[i+1]) - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]) print(icost)
s448819583
Accepted
233
13,920
281
n = int(input()) a = list((map(int, input().split()))) a = [0] + a + [0] totalcost = 0 for i in range(len(a) - 1): totalcost += abs(a[i] - a[i+1]) for i in range(1, n+1): icost = totalcost + abs(a[i-1] - a[i+1]) - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]) print(icost)
s667771853
p03548
u667949809
2,000
262,144
Wrong Answer
29
2,940
100
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
x,y,z = map(int,input().split()) X=x-z num = 0 while X>(y+z): X=X-(y+z) num=num+1 print(num)
s019827716
Accepted
30
2,940
101
x,y,z = map(int,input().split()) X=x-z num = 0 while X>=(y+z): X=X-(y+z) num=num+1 print(num)
s085869300
p03698
u411237324
2,000
262,144
Wrong Answer
17
2,940
85
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s = list(input()) a = len(s) b = len(set(s)) print('Yes') if a == b else print('No')
s868917256
Accepted
18
2,940
85
s = list(input()) a = len(s) b = len(set(s)) print('yes') if a == b else print('no')
s442610788
p04029
u942028688
2,000
262,144
Wrong Answer
17
2,940
55
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
N = int(input()) result = (N + 1) * N / 2 print(result)
s872528970
Accepted
17
2,940
60
N = int(input()) result = int((N + 1) * N / 2) print(result)
s666252154
p03997
u030726788
2,000
262,144
Wrong Answer
17
2,940
61
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)
s031886955
Accepted
18
2,940
62
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h//2)
s972540108
p03574
u897328029
2,000
262,144
Wrong Answer
49
3,604
1,024
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
hw_list = list(map(int, input().split())) h_max = hw_list[0] w_max = hw_list[1] s_list = [] for i in range(h_max): work_list = input() s_list.append(work_list) answer_list = [] for h in range(h_max): work_list = s_list[h] work_answer = [] for w, target in enumerate(work_list): if target == '.': tonari_list = [(w-1, h-1), (w, h-1), (w+1, h-1), (w-1, h), (w+1, h), (w-1, h+1), (w, h+1), (w+1, h+1)] count = 0 for x, y in tonari_list: if 0 <= x < w_max and 0 <= y < h_max: print('{}, {}'.format(x, y)) if s_list[y][x] == '#': count += 1 else: continue work_answer.append(str(count)) else: work_answer.append('#') answer_list.append(work_answer) for a_list in answer_list: print(''.join(a_list))
s308052444
Accepted
27
3,188
975
hw_list = list(map(int, input().split())) h_max = hw_list[0] w_max = hw_list[1] s_list = [] for i in range(h_max): work_list = input() s_list.append(work_list) answer_list = [] for h in range(h_max): work_list = s_list[h] work_answer = [] for w, target in enumerate(work_list): if target == '.': tonari_list = [(w-1, h-1), (w, h-1), (w+1, h-1), (w-1, h), (w+1, h), (w-1, h+1), (w, h+1), (w+1, h+1)] count = 0 for x, y in tonari_list: if 0 <= x < w_max and 0 <= y < h_max: if s_list[y][x] == '#': count += 1 else: continue work_answer.append(str(count)) else: work_answer.append('#') answer_list.append(work_answer) for a_list in answer_list: print(''.join(a_list))
s364632212
p03448
u991087410
2,000
262,144
Wrong Answer
51
3,060
254
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.
C500 = int(input()) C100 = int(input()) C50 = int(input()) X = int(input()) count = 0 for i in range(C500): for j in range(C100): for k in range(C50): TOTAL = 500*i+100*j+50*k if TOTAL == X: count += 1 break print(count)
s084994473
Accepted
51
3,060
260
C500 = int(input()) C100 = int(input()) C50 = int(input()) X = int(input()) count = 0 for i in range(C500+1): for j in range(C100+1): for k in range(C50+1): TOTAL = 500*i+100*j+50*k if TOTAL == X: count += 1 break print(count)
s073955893
p03657
u505420467
2,000
262,144
Wrong Answer
17
2,940
112
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
a,b=map(int,input().split()) if a%3==0 and b%3==0 or (a+b)%3==0: print('possible') else: print('impossible')
s155740234
Accepted
18
2,940
94
a,b=map(int,input().split());print(["Impossible","Possible"][a%3==0 or b%3==0 or (a+b)%3==0])
s522574154
p03543
u765815947
2,000
262,144
Wrong Answer
17
2,940
85
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
n = input() for i in range(10): if 'iii' in n: print('Yes') else: print('No')
s373227284
Accepted
18
2,940
117
n = input() if (n[0] == n[1] and n[1] == n[2]) or (n[1] == n[2] and n[2] == n[3]): print('Yes') else: print('No')
s608210711
p03524
u103902792
2,000
262,144
Wrong Answer
20
3,188
146
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
s = input() a = s.count('a') b = s.count('b') c = s.count('c') if abs(a-b)<=1 and abs(b-c)<=1 and abs(c-a)<=1: print('Yes') else: print('No')
s449284869
Accepted
18
3,188
148
s = input() a = s.count('a') b = s.count('b') c = s.count('c') if abs(a-b)<=1 and abs(b-c)<=1 and abs(c-a)<=1: print('YES') else: print('NO')
s581043946
p04043
u144029820
2,000
262,144
Wrong Answer
17
2,940
147
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a=list(map(int,input().split())) #a=[map(int,input().split())] print(a) if a.count(5)==2 and a.count(7)==1: print('YES') else: print('NO')
s923068170
Accepted
17
2,940
148
a=list(map(int,input().split())) #a=[map(int,input().split())] #print(a) if a.count(5)==2 and a.count(7)==1: print('YES') else: print('NO')
s056261806
p03730
u740767776
2,000
262,144
Wrong Answer
18
3,060
162
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()) f = False for i in range(1,b+1): if a * i % b == c: f = True break if f: print("Yes") else: print("No")
s219845736
Accepted
17
2,940
162
a,b,c=map(int,input().split()) f = False for i in range(1,b+1): if a * i % b == c: f = True break if f: print("YES") else: print("NO")
s220954682
p03555
u357050210
2,000
262,144
Wrong Answer
17
2,940
84
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.
s = input() t = input() if t[::-1] == s: print("Yes") else: print("No")
s837348202
Accepted
17
2,940
80
s = input() t = input() if t[::-1] == s: print("YES") else: print("NO")
s052182849
p02401
u298999032
1,000
131,072
Wrong Answer
20
7,660
211
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.
a,op,b=input().split() a,b=map(int,(a,b)) if op=='?': None elif op=='+': print(str(int(a+b))) elif op=='-': print(str(int(a-b))) elif op=='*': print(str(int(a*b))) else: print(str(int(a//b)))
s819455379
Accepted
30
7,724
272
while True: a,op,b=input().split() a,b=map(int,(a,b)) if op=='?': break elif op=='+': print(str(int(a+b))) elif op=='-': print(str(int(a-b))) elif op=='*': print(str(int(a*b))) else: print(str(int(a//b)))
s422542042
p03433
u729217226
2,000
262,144
Wrong Answer
17
2,940
93
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('YES') else: print('NO')
s017908192
Accepted
17
2,940
92
N = int(input()) A = int(input()) if (N % 500) <= A: print('Yes') else: print('No')
s978841033
p02612
u018846452
2,000
1,048,576
Wrong Answer
32
9,152
72
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) if N % 1000 == 0: print(0) else: print(N//1000 +1 )
s203722255
Accepted
28
9,140
48
N = int(input()) print((N+1000-1)//1000* 1000-N)
s566310844
p03693
u910756197
2,000
262,144
Wrong Answer
17
2,940
88
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?
n = int("".join(input().split())) if n % 4 == 0: print("Yes") else: print("No")
s243479393
Accepted
17
2,940
88
n = int("".join(input().split())) if n % 4 == 0: print("YES") else: print("NO")
s065955930
p03565
u413659369
2,000
262,144
Wrong Answer
36
9,232
466
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
from copy import deepcopy S = list(input()) T = list(input()) s_num = len(S) t_num = len(T) S_copy = deepcopy(S) for i in range(s_num-t_num, -1, -1): s_key = S[i:i+t_num] judge = 0 for s, t in zip(s_key, T): if s=='?': judge += 1 elif s == t: judge += 1 if judge == t_num: S_copy[i:i+t_num] = T if S == S_copy: print('UNRESTORABLE') else: for i in S_copy: if i == '?': print('a', end='') else: print(i, end='')
s285376688
Accepted
31
9,272
498
from copy import deepcopy S = input() T = input() s_num = len(S) t_num = len(T) ans = [] if s_num < t_num: print('UNRESTORABLE') else: for i in range(s_num-t_num+1): s_key = S[i:i+t_num] judge = 0 for s, t in zip(s_key, T): if s=='?': judge += 1 elif s == t: judge += 1 if judge == t_num: tmp = S[:i] + T + S[i+t_num:] tmp = tmp.replace('?', 'a') ans.append(tmp) if ans: print(sorted(ans)[0]) else: print('UNRESTORABLE')
s254234366
p03378
u840592162
2,000
262,144
Wrong Answer
17
3,060
161
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
n,m,x = map(int,input().split()) A = list(map(int,input().split())) ans1 = len([a for a in A if a <x]) ans2 = len([a for a in A if a < x]) print(min(ans1,ans2))
s611009656
Accepted
19
3,060
162
n,m,x = map(int,input().split()) A = list(map(int,input().split())) ans1 = len([a for a in A if a < x]) ans2 = len([a for a in A if a > x]) print(min(ans1,ans2))
s357895647
p02694
u375006224
2,000
1,048,576
Wrong Answer
22
9,156
63
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
a=int(input()) b=100 c=0 while b>=a: c+=1 b=b*1.01 print(c)
s881410816
Accepted
25
9,160
67
a=int(input()) b=100 c=0 while b<a: c+=1 b=int(b*1.01) print(c)
s893784344
p03970
u960080897
2,000
262,144
Wrong Answer
30
9,092
117
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
s = input() t = "CODEFESTIVAL2016" cnt = 0 for i, z in zip(s, t): if s != z: cnt += 1 print(cnt)
s357186244
Accepted
26
9,092
117
s = input() t = "CODEFESTIVAL2016" cnt = 0 for i, z in zip(s, t): if i != z: cnt += 1 print(cnt)