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
s964804643
p03369
u785066634
2,000
262,144
Wrong Answer
17
2,940
129
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
s=list(input()) count=0 for s_ in s: if s_ =="◯": count=count+1 else: count=count print(700+100*count)
s912969681
Accepted
17
2,940
100
s=list(input()) count=0 for s_ in s: if s_ =="o": count=count+1 print(700+100*count)
s940770233
p03386
u696444274
2,000
262,144
Wrong Answer
36
5,148
291
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.
import math import itertools import statistics #import numpy as np #import collections a, b, k = list(map(int, input().split())) l = [] if k > b-a: k = b-a for i in range(k): l.append(a+i) l.append(b-i) l.sort() ans = list(set(l)) for i in range(len(ans)): print(ans[i])
s130323180
Accepted
37
5,148
341
import math import itertools import statistics #import numpy as np #import collections a, b, k = list(map(int, input().split())) l = [] for i in range(k): l.append(a+i) l.append(b-i) ans = list(set(l)) ans.sort() for i in range(len(ans)): if ans[i] >= a and ans[i] <= b: print(ans[i])
s039974930
p02606
u090883248
2,000
1,048,576
Wrong Answer
27
9,104
156
How many multiples of d are there among the integers between L and R (inclusive)?
input = input() print(input) L, R, d = [int(n) for n in input.split()] count = 0 for n in range(L, R+1): if n % d == 0: count += 1 print(count)
s261549158
Accepted
31
9,040
143
input = input() L, R, d = [int(n) for n in input.split()] count = 0 for n in range(L, R+1): if n % d == 0: count += 1 print(count)
s057270230
p03556
u004025573
2,000
262,144
Wrong Answer
50
3,060
130
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
import math N=int(input()) for i in range(N,-1,-1): a=math.ceil(math.sqrt(i)) if a*a==i: print(a) break
s770734874
Accepted
46
2,940
130
import math N=int(input()) for i in range(N,-1,-1): a=math.ceil(math.sqrt(i)) if a*a==i: print(i) break
s751525838
p04044
u745385679
2,000
262,144
Wrong Answer
17
2,940
45
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
a = input().split() print(''.join(sorted(a)))
s229053431
Accepted
17
3,060
82
N, L = map(int, input().split()) print(''.join(sorted(input() for _ in range(N))))
s651744975
p03251
u442877951
2,000
1,048,576
Wrong Answer
18
3,060
207
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N,M,X,Y = map(int,input().split()) xl = list(map(int,input().split())) yl = list(map(int,input().split())) for i in range(X+1,Y): if max(xl) < i and min(yl) >= i: print("NoWar") exit() print("War")
s596564945
Accepted
18
3,060
208
N,M,X,Y = map(int,input().split()) xl = list(map(int,input().split())) yl = list(map(int,input().split())) for i in range(X+1,Y): if max(xl) < i and min(yl) >= i: print("No War") exit() print("War")
s240365898
p03737
u453634575
2,000
262,144
Wrong Answer
18
2,940
77
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
s = list(input().split()) print(s[0][0].upper, s[1][0].upper, s[2][0].upper)
s952987189
Accepted
17
2,940
86
s = list(input().split()) print(s[0][0].upper() + s[1][0].upper() + s[2][0].upper())
s933131064
p03623
u397563544
2,000
262,144
Wrong Answer
21
3,316
330
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
from collections import Counter s = list(sorted(str(input()))) l = list(Counter(s)) a = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] if len(l) == 26: print('None') else: for i in range(len(l)): if l[i]!=a[i]: print(a[i]) break
s161078988
Accepted
18
2,940
90
x,a,b = map(int,input().split()) if abs(x-a)<abs(x-b): print('A') else: print('B')
s289581156
p03339
u748311048
2,000
1,048,576
Wrong Answer
161
25,844
234
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
n = int(input()) s = str(input()) sE = s.count('E') sW = s.count('W') l = [] e, w = 0, 0 for ch in s: if ch == 'E': e += 1 else: w += 1 m = (sE-e)+w l.append(sE-e+w-1 if ch == 'W' else sE-e+w) print(l)
s519957608
Accepted
147
21,432
239
n = int(input()) s = str(input()) sE = s.count('E') sW = s.count('W') l = [] e, w = 0, 0 for ch in s: if ch == 'E': e += 1 else: w += 1 m = (sE-e)+w l.append(sE-e+w-1 if ch == 'W' else sE-e+w) print(min(l))
s408650588
p03456
u663089555
2,000
262,144
Wrong Answer
17
2,940
132
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
A=input().split() B=int(A[0]+A[1]) print(B) i=0 while i**2<=B: if i**2==B: print(i) break else: i+=1
s019411256
Accepted
17
2,940
76
A=input().split() B=(int(A[0]+A[1]))**.5 print('Yes' if B==int(B) else 'No')
s209399407
p00041
u811733736
1,000
131,072
Wrong Answer
40
7,812
2,338
与えられた 4 つの 1 から 9 の整数を使って、答えが 10 になる式をつくります。 4 つの整数 a, b, c, d を入力したとき、下記の条件に従い、答えが 10 になる式を出力するプログラムを作成してください。また、答えが複数ある時は、最初に見つかった答えだけを出力するものとします。答えがない時は、0 と出力してください。 * 演算子として、加算 (+)、減算 (-)、乗算 (*) だけを使います。除算 (/) は使いません。使用できる演算子は3個です。 * 数を4つとも使わなければいけません。 * 4つの数の順番は自由に入れ換えてかまいません。 * カッコを使ってもかまいません。使用できるカッコは3組(6個)以下です。
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0041 """ import sys from itertools import permutations, product def has_possibility(digits): result = False digits.sort(reverse=True) total = digits[0] for i in digits[1:]: if i < 2: total += i else: total *= i if total >= 10: result = True return result def make_ten(digits): for a, b, c, d in permutations(digits, 4): for op1, op2, op3 in product(['+', '-', '*'], repeat=3): t1 = do_calc(a, b, op1) t2 = do_calc(t1, c, op2) t3 = do_calc(t2, d, op3) if t3 == 10: return '(({} {} {}) {} {}) {} {}'.format(a, op1, b, op2, c, op3, d) t1 = do_calc(a, b, op1) t2 = do_calc(c, d, op2) t3 = do_calc(t1, t2, op3) if t3 == 10: return '({} {} {}) {} ({} {} {})'.format(a, op1, b, op3, c, op2, d) return '0' def do_calc(x, y, op): result = None if op == '+': result = x + y elif op == '-': result = x - y elif op == '*': result = x * y return result Memo = {} def solve(digits): digits.sort(reverse=True) data = ''.join(map(str, digits)) if data in Memo: pass else: if has_possibility(digits): Memo[data] = make_ten(digits) else: Memo[data] = '0' return Memo[data] def main(args): while True: digits = [int(x) for x in input().strip().split(' ')] if digits[0] == 0 and digits[1] == 0 and digits[2] == 0 and digits[3] == 0: break result = solve(digits) print(result) if __name__ == '__main__': main(sys.argv[1:])
s155409515
Accepted
550
7,872
2,813
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0041 """ import sys from itertools import permutations, product def make_ten(digits): result = '0' for a, b, c, d in permutations(digits, 4): if result != '0': break for op1, op2, op3 in product(['+', '-', '*'], repeat=3): # ??????????????????????????????????????????????????????OK exp = '(({} {} {}) {} {}) {} {}'.format(a, op1, b, op2, c, op3, d) if eval(exp) == 10: result = exp break # 1, 3, 2 exp= '(({} {} {}) {} ({} {} {}))'.format(a, op1, b, op2, c, op3, d) if eval(exp) == 10: result = exp break # 2, 1, 3 exp = '(({} {} ({} {} {})) {} {})'.format(a, op1, b, op2, c, op3, d) if eval(exp) == 10: result = exp break # 3, 1, 2 exp = '({} {} (({} {} {}) {} {}))'.format(a, op1, b, op2, c, op3, d) if eval(exp) == 10: result = exp break # 3, 2, 1 exp = '({} {} ({} {} ({} {} {})))'.format(a, op1, b, op2, c, op3, d) if eval(exp) == 10: result = exp break # 2, 3, 1 exp = '(({} {} {}) {} ({} {} {}))'.format(a, op1, b, op2, c, op3, d) if eval(exp) == 10: result = exp break return result Memo = {} def solve(digits): global Memo digits.sort(reverse=True) data = ''.join(map(str, digits)) if not data in Memo: Memo[data] = make_ten(digits) return Memo[data] def main(args): while True: digits = [int(x) for x in input().strip().split(' ')] # digits = [int(x) for x in '{:04d}'.format(count)] if digits[0] == 0 and digits[1] == 0 and digits[2] == 0 and digits[3] == 0: break result = solve(digits) print(result) if __name__ == '__main__': main(sys.argv[1:])
s410041463
p03556
u941884460
2,000
262,144
Wrong Answer
22
3,064
81
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
N = int(input()) count = 1 while count*count <N: count += 1 print(pow(count,2))
s193323666
Accepted
24
2,940
90
N = int(input()) count = 1 while (count+1)*(count+1) <=N: count += 1 print(pow(count,2))
s616348335
p03438
u060392346
2,000
262,144
Wrong Answer
24
4,596
172
You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if a[i] > b[i]: print("No") break else: print("Yes")
s193530308
Accepted
26
4,596
241
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) u , v = 0, 0 for i in range(n): if a[i] > b[i]: u += a[i] - b[i] else: v += (b[i] - a[i]) // 2 if u > v: print("No") else: print("Yes")
s952779915
p03456
u777923818
2,000
262,144
Wrong Answer
18
3,828
168
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
# -*- coding: utf-8 -*- a, b = map(int, input().split()) x = int(a+b) ok = [False]*(100100) for i in range(1, 317): ok[i*i] = True print("Yes" if ok[x] else "No")
s732387947
Accepted
19
3,828
160
# -*- coding: utf-8 -*- a, b = input().split() x = int(a+b) ok = [False]*(100101) for i in range(1, 317): ok[i*i] = True print("Yes" if ok[x] else "No")
s401326106
p03455
u694382289
2,000
262,144
Wrong Answer
17
2,940
93
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) c= a*b if c%2 == 0: print('even') else: print('odd')
s831743745
Accepted
17
2,940
93
a, b = map(int, input().split()) c= a*b if c%2 == 0: print('Even') else: print('Odd')
s319147403
p03455
u738622346
2,000
262,144
Wrong Answer
18
2,940
99
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
sum_input = list(map(int, input().split(" "))) print("Even" if sum(sum_input) % 2 == 0 else "Odd")
s295109630
Accepted
17
2,940
80
a, b = map(int, input().split(" ")) print("Even" if (a * b) % 2 == 0 else "Odd")
s239256518
p03044
u089376182
2,000
1,048,576
Wrong Answer
589
43,492
284
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
n = int(input()) node_manager = {i:0 for i in range(1, n+1)} UVW = sorted([list(map(int, input().split())) for _ in range(n-1)]) for uvw in UVW: u,v,w = uvw if w%2==0: node_manager[v] = node_manager[u] else: node_manager[v] = 1-node_manager[u] print(node_manager)
s529144822
Accepted
941
68,220
495
n = int(input()) node = {i:[] for i in range(1, n+1)} ans = {i:0 for i in range(1, n+1)} for _ in range(n-1): u,v,w = map(int, input().split()) node[u].append([v,w]) node[v].append([u,w]) stack = [1] memory = set() while stack: x = stack.pop() memory.add(x) for node_i, len_i in node[x]: if node_i not in memory: if len_i%2==0: ans[node_i] = ans[x] else: ans[node_i] = 1-ans[x] stack.append(node_i) for v in ans.values(): print(v)
s502470362
p02602
u512873531
2,000
1,048,576
Wrong Answer
2,206
31,360
186
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
n, k = map(int, input().split()) a = list(map(int, input().split())) g = 1 c = 0 for i in range(n): g*=a[i] if i>k: if g>c: print('Yes') else: print('No') c=g
s929242844
Accepted
149
31,544
160
n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): if i>=k: if a[i]>a[i-k]: print('Yes') else: print('No')
s066516208
p03795
u272377260
2,000
262,144
Wrong Answer
17
2,940
48
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
n = int(input()) print(n * 800 + (n % 15) * 200)
s239044319
Accepted
17
2,940
49
n = int(input()) print(n * 800 - (n // 15) * 200)
s379120142
p03696
u374802266
2,000
262,144
Wrong Answer
17
3,064
291
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
n=int(input()) s=input()+"1" a=0 b=[] for i in range(n): if s[i]==s[i+1]: a+=1 else: b.append(a+1) a=0 if s[-2]=='(': b.append(0) if s[0]==')': b.insert(0,0) print(b) for i in range(len(b)//2): c=max(b[2*i],b[2*i+1]) print('('*c,end=')'*c)
s374273352
Accepted
18
2,940
178
n=int(input()) s=input() a=0 b=0 for i in range(n): if s[i]=='(': a+=1 else: if a==0: b+=1 else: a-=1 print('('*b+s+')'*a)
s948058796
p02612
u945405878
2,000
1,048,576
Wrong Answer
33
9,092
108
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()) a = N // 1000 b = N % 1000 if b == 0: ans = 0 else: ans = N - a * 1000 print(ans)
s678195221
Accepted
30
9,156
114
N = int(input()) a = N // 1000 b = N % 1000 if b == 0: ans = 0 else: ans = (a + 1) * 1000 - N print(ans)
s194180092
p03502
u031358594
2,000
262,144
Wrong Answer
17
2,940
133
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N=str(input()) print(N) X=int(N) fx=0 for i in range(0,len(N)): fx+=int(N[i]) if X%fx==0: print("Yes") else: print("No")
s942621088
Accepted
17
2,940
125
N=str(input()) X=int(N) fx=0 for i in range(0,len(N)): fx+=int(N[i]) if X%fx==0: print("Yes") else: print("No")
s055139776
p03448
u479638406
2,000
262,144
Wrong Answer
59
3,060
296
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()) total = 0 count = 0 for a in range(A): a += 1 for b in range(B): b += 1 for c in range(C): c += 1 total = 500*a+100*b+50*c if total == X: count += 1 print(count)
s668897848
Accepted
52
2,940
283
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 for a in range(A+1): for b in range(B+1): for c in range(C+1): total = 500*a+100*b+50*c if total == X: count += 1 print(count)
s381219875
p03759
u215018528
2,000
262,144
Wrong Answer
17
2,940
76
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a, b, c = map(int, input().split()) print("Yes" if b - a == c - b else "No")
s747533671
Accepted
17
2,940
76
a, b, c = map(int, input().split()) print("YES" if b - a == c - b else "NO")
s332168279
p04043
u076917070
2,000
262,144
Wrong Answer
17
2,940
162
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.
import sys input=sys.stdin.readline l = list(map(int, input().split())) l.sort() if l.count(5) == 2 and l.count(7) == 1: print("yes") else: print("no")
s791753780
Accepted
17
2,940
162
import sys input=sys.stdin.readline l = list(map(int, input().split())) l.sort() if l.count(5) == 2 and l.count(7) == 1: print("YES") else: print("NO")
s265802700
p03337
u204260373
2,000
1,048,576
Wrong Answer
20
3,060
165
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
A,B=map(int,input().split()) if A*B>A+B>A-B or A*B>A-B>A+B: print(A*B) elif A+B>A+B>A-B or A+B>A-B>A+B: print(A+B) elif A-B>A+B>A*B or A-B>A*B>A+B: print(A-B)
s060299637
Accepted
17
2,940
53
a,b=map(int,input().split()) print(max(a+b,a-b,a*b))
s713175397
p03351
u140251125
2,000
1,048,576
Wrong Answer
17
2,940
249
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
# input a, b, c, d = map(int, input().split()) if abs(a - b) > abs(a - c): if abs(a - c) < d: print('Yes') else: print('No') else: if abs(a - b) < d and abs(b - c) < d: print('Yes') else: print('No')
s769428442
Accepted
17
3,064
252
# input a, b, c, d = map(int, input().split()) if abs(a - b) > abs(a - c): if abs(a - c) <= d: print('Yes') else: print('No') else: if abs(a - b) <= d and abs(b - c) <= d: print('Yes') else: print('No')
s683715434
p02612
u516579758
2,000
1,048,576
Wrong Answer
29
9,132
29
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)
s678836913
Accepted
32
9,144
53
n=int(input()) a=0 while a<n: a+=1000 print(a-n)
s765444709
p03457
u806257533
2,000
262,144
Wrong Answer
417
27,300
355
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()) time_coor = [] for n in range(N): time_coor.append(list(map(int, input().split()))) can = True for n in range(N-1): if (abs(time_coor[n+1][1])-abs(time_coor[n][1]) + abs(time_coor[n+1][2])-abs(time_coor[n][2]))!=1: can = False break else: continue if can==True: print("Yes") else: print("No")
s215589842
Accepted
450
27,324
546
N = int(input()) time_coor = [] for n in range(N+1): if n==0: time_coor.append([0, 0, 0]) else: time_coor.append(list(map(int, input().split()))) can = True for n in range(N): dist = abs(time_coor[n+1][1]-time_coor[n][1]) + \ abs(time_coor[n+1][2]-time_coor[n][2]) time = time_coor[n+1][0]-time_coor[n][0] if dist>time: can = False break elif dist%2==time%2: continue else: can = False break if can==True: print("Yes") else: print("No")
s954344858
p03416
u924467864
2,000
262,144
Wrong Answer
45
2,940
164
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
a, b = map(int, input().split()) flag = True cnt = 0 for i in range(a, b - a + 2): s = str(i) if s[0] == s[4] and s[1] == s[3]: cnt += 1 print(cnt)
s574392273
Accepted
46
2,940
148
a, b = map(int, input().split()) cnt = 0 for i in range(a, b + 1): s = str(i) if s[0] == s[4] and s[1] == s[3]: cnt += 1 print(cnt)
s156133759
p03478
u059436995
2,000
262,144
Wrong Answer
45
3,412
159
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split()) ans = 0 for i in range(1,n + 1): if a <= sum([int(j) for j in str(i)]) <=b: print(i) ans +=i print(ans)
s727668992
Accepted
33
2,940
142
n, a, b = map(int, input().split()) ans = 0 for i in range(1,n + 1): if a <= sum([int(j) for j in str(i)]) <=b: ans +=i print(ans)
s953719149
p03486
u228232845
2,000
262,144
Wrong Answer
30
9,112
598
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return input() def LS(): return input().split() s = list(S()) t = list(S()) ns = ''.join(sorted(s)) nt = ''.join(sorted(t)[::-1]) print(ns, nt) if ns < nt: print('Yes') else: print('No')
s749110770
Accepted
29
8,968
584
import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return input() def LS(): return input().split() s = list(S()) t = list(S()) ns = ''.join(sorted(s)) nt = ''.join(sorted(t)[::-1]) if ns < nt: print('Yes') else: print('No')
s785033373
p03606
u823885866
2,000
262,144
Wrong Answer
131
27,296
503
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
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()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 n = ri() li = np.zeros(100000) for _ in range(n): l, r = rm() li[l:r+1] = 1 print(sum(li))
s126228479
Accepted
142
27,380
508
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()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 n = ri() li = np.zeros(200000) for _ in range(n): l, r = rm() li[l:r+1] = 1 print(int(sum(li)))
s309852921
p02841
u844789719
2,000
1,048,576
Wrong Answer
19
3,316
142
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
m1, d1 = [int(_) for _ in input().split()] m2, d2 = [int(_) for _ in input().split()] if d1 + 1 == d2: print('No') else: print('Yes')
s259247309
Accepted
17
2,940
139
m1, d1 = [int(_) for _ in input().split()] m2, d2 = [int(_) for _ in input().split()] if d1 + 1 == d2: print('0') else: print('1')
s053110056
p03847
u875291233
2,000
262,144
Wrong Answer
17
3,064
567
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
# coding: utf-8 # Your code here! odd={0:1} even={0:1,1:3} def memo(N): if N ==0: return 1 if N==1: return 2 return memoodd((N-1)//2)+memoeven(N//2) def memoodd(N): if N in odd: return odd[N] # a=memoodd((N-1)//2) # b=memoeven(N//2) odd[N] = memo(N) return odd[N] def memoeven(N): if N in even: return even[N] # a=memoodd((N-1)//2) # b=memoeven(N//2) # c=memoodd((N-2)//2) # d=memoeven((N-1)//2) # return a+b+c+d even[N] = memo(N)+memo(N-1) return even[N] print(memo(32))
s237197852
Accepted
19
3,060
238
# coding: utf-8 # Your code here! dic_memo={0:1,1:2} M=10**9+7 def memo(N): if N in dic_memo: return dic_memo[N] dic_memo[N]=(memo((N-1)//2)+memo(N//2)+memo(N//2-1))%M return dic_memo[N] n=int(input()) print(memo(n))
s033771213
p04044
u175743386
2,000
262,144
Wrong Answer
17
2,940
77
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
N, L = map(int, input().split()) ''.join(sorted([input() for i in range(N)]))
s785759551
Accepted
20
3,060
84
N, L = map(int, input().split()) print(''.join(sorted([input() for i in range(N)])))
s970933737
p03523
u896741788
2,000
262,144
Wrong Answer
17
3,064
221
You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
s=input() l=list("AKIHABARA".split("A"))[1:-1] print(l) for ii in range(2**4): p="A" if ii%2 else "" i=ii for j in range(3): p+=l[j] p+="A" if i%2 else "" i//=2 if s==p:print("YES");exit() print("NO")
s011219694
Accepted
18
3,060
212
s=input() l=list("AKIHABARA".split("A"))[1:-1] for ii in range(2**4): p="A" if ii%2 else "" i=ii for j in range(3): p+=l[j] i//=2 p+="A" if i%2 else "" if s==p:print("YES");exit() print("NO")
s012120655
p03394
u672220554
2,000
262,144
Wrong Answer
32
5,100
560
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
n=int(input()) res=[] count = 0 for i in range(1,50000): if i % 2 == 0 or i % 3 == 0: res.append(i) count += 1 if count == n-1: break s=sum(res) print(s) t=res[-1] f1 = s%2 f2 = s%3 if f1==0 and f2 == 0: flag = 0 elif f1==0 and f2==1: flag = 2 elif f1==0 and f2==2: flag = 4 if f1==1 and f2 == 0: flag = 3 elif f1==1 and f2==1: flag = 5 elif f1==1 and f2==2: flag = 1 for i in range(t+1,t+10): if i % 6 == flag: res.append(i) print(s+i) break print(" ".join(map(str, res)))
s115074275
Accepted
31
5,212
1,001
n=int(input()) if n==3: print("2 5 63") elif n==6: print("3 4 6 8 9 12") elif n==7: print("2 3 4 6 8 10 15") else: res=[] count = 0 for i in range(1,50000): if i % 2 == 0 or i % 3 == 0: res.append(i) count += 1 if count == n-1: break s=sum(res) t=res[-1] f1 = s%2 f2 = s%3 if f1==0 and f2 == 0: flag = 0 elif f1==0 and f2==1: flag = 2 elif f1==0 and f2==2: flag = 4 if f1==1 and f2 == 0: flag = 3 elif f1==1 and f2==1: flag = 5 elif f1==1 and f2==2: flag = 1 if flag == 5 or flag ==1: res.pop(1) f=0 for i in range(t+1,t+10): if i % 2==0: res.append(i) f+=1 if f==2: break else: for i in range(t+1,t+10): if i % 6 == flag: res.append(i) break print(" ".join(map(str, res)))
s273585661
p03672
u288430479
2,000
262,144
Wrong Answer
17
2,940
192
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.
a=input() l=len(a) while l>0: # print(l) if l%2!=0: l -= 1 a = a[:-1] # print(a) else: t =int(l/2) if a[0:t] == a[t:]: print(l) break else: l -= 1
s904062020
Accepted
17
2,940
82
s = input()[:-1] while s[0:len(s)//2] != s[len(s)//2:]: s = s[:-1] print(len(s))
s193744393
p02928
u366482170
2,000
1,048,576
Wrong Answer
363
3,188
334
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=map(int,input().split()) a=list(map(int,input().split())) count=0 countlast=0 for i in range(n-1): for j in range(i+1,n): if a[i]>a[j]: count+=1 # print(i,j) for i in range(n-1): if a[n-1]>a[i]: # print(i) countlast+=1 #print(count,countlast) mod=10**9+7 print((k*(k+1)*count+k*(k-1)*countlast)/2%mod)
s006952128
Accepted
871
3,188
301
n,k=map(int,input().split()) a=list(map(int,input().split())) rcount=0 lcount=0 for i in range(n-1): for j in range(i+1,n): if a[i]>a[j]: rcount+=1 for i in range(n-1): for j in range(i+1,n): if a[i]<a[j]: lcount+=1 mod=10**9+7 print((k*(k+1)*rcount+k*(k-1)*lcount)//2%mod)
s023691490
p03719
u276115223
2,000
262,144
Wrong Answer
17
2,940
108
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a, b, c = [int(s) for s in input().split()] print('YES' if a <= c <= b else 'NO')
s850984666
Accepted
17
2,940
119
a, b, c = [int(s) for s in input().split()] print('Yes' if a <= c <= b else 'No')
s471124329
p02390
u831971779
1,000
131,072
Wrong Answer
30
7,652
95
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
S = int(input()) h = (S / (60*60)) m = (S / 60) % 60 s = S % 60 print('{}:{}:{}'.format(h,m,s))
s105137495
Accepted
20
7,572
101
S = int(input()) h = int(S / (60*60)) m = int(S / 60) % 60 s = S % 60 print('{}:{}:{}'.format(h,m,s))
s475077740
p04031
u293523199
2,000
262,144
Wrong Answer
17
3,060
282
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()) A = list(map(int, input().split())) total_costs = {} if( len(list(set(A))) ): print(0) else: for i in range(0, 100): cost = 0 for a in A: cost += (a - i)*(a - i) total_costs[i] = cost print(min(total_costs.values()))
s963345499
Accepted
22
3,060
284
N = int(input()) A = list(map(int, input().split())) total_costs = {} if( len(set(A)) == 1 ): print(0) else: for i in range(-100, 101): cost = 0 for a in A: cost += (a - i)*(a - i) total_costs[i] = cost print(min(total_costs.values()))
s970038985
p02612
u091945878
2,000
1,048,576
Wrong Answer
32
9,076
45
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()) mod = N % 1000 print(mod)
s160490534
Accepted
34
9,152
101
N = int(input()) mod = N % 1000 if mod == 0: result = 0 else: result = 1000 - mod print(result)
s550898301
p03139
u623819879
2,000
1,048,576
Wrong Answer
17
2,940
63
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(max(a,b),max(0,a+b-n))
s498843411
Accepted
18
2,940
64
n, a, b=map(int, input().split()) print(min(a,b),max(0,a+b-n))
s450457263
p03160
u201387466
2,000
1,048,576
Wrong Answer
132
13,800
219
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N = int(input()) h = list(map(int,input().split())) H = [0]*N for i in range(1,N): if i == 1: H[i] = abs(h[1]-h[0]) else: H[i] = max(H[i-1]+abs(h[i]-h[i-1]),H[i-2]+abs(h[i]-h[i-2])) print(H[N-1])
s597679175
Accepted
148
13,980
277
N = int(input()) h = list(map(int,input().split())) H = [0]*N for i in range(1,N): if i == 1: H[i] = abs(h[1]-h[0]) else: H[i] = H[i-1]+abs(h[i]-h[i-1]) if H[i] > H[i-2]+abs(h[i]-h[i-2]): H[i] = H[i-2]+abs(h[i]-h[i-2]) print(H[N-1])
s791045803
p02390
u403901064
1,000
131,072
Wrong Answer
30
8,084
177
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from datetime import timedelta def main(): sec = timedelta(seconds= int(input())) print(sec) if __name__ == '__main__': main()
s525866338
Accepted
40
7,708
198
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): total= int(input()) ti = divmod(divmod(total,60)[0],60) print("%d:%d:%d" % (ti[0],ti[1],total % 60)) if __name__ == '__main__': main()
s996724367
p03501
u954693495
2,000
262,144
Wrong Answer
17
2,940
57
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
n,a,b=[int(x) for x in input().split()] print(max(n*a,b))
s239276061
Accepted
18
2,940
57
n,a,b=[int(x) for x in input().split()] print(min(n*a,b))
s110989925
p04011
u842388336
2,000
262,144
Wrong Answer
17
2,940
92
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) print(N*X+min(0,N-K)*Y)
s714521245
Accepted
17
2,940
99
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) print(min(N,K)*X+max(0,N-K)*Y)
s735348569
p03860
u839873388
2,000
262,144
Wrong Answer
19
3,068
43
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s = input() x = s[0] print("A" + x + "C")
s033093513
Accepted
18
2,940
46
a,b,c = input().split() print("A" +b[0] +"C")
s406364707
p03494
u732870425
2,000
262,144
Time Limit Exceeded
2,104
3,064
214
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N = int(input()) A = list(map(int, input().split())) cnt = 0 while True: for i in range(len(A)): if A[i] % 2 != 0: break else: A = [a/2 for a in A] cnt += 1 print(cnt)
s953837564
Accepted
19
3,060
282
N = int(input()) A = list(map(int, input().split())) cnt = 0 while True: for i in range(len(A)): if A[i] % 2 != 0: break else: A = [a/2 for a in A] cnt += 1 continue break print(cnt)
s487018277
p03024
u758973277
2,000
1,048,576
Wrong Answer
17
2,940
78
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S = input() if S.count('o')+(15-len(S))>=8: print('Yes') else: print('No')
s866586858
Accepted
17
2,940
78
S = input() if S.count('o')+(15-len(S))>=8: print('YES') else: print('NO')
s064250458
p03470
u253422591
2,000
262,144
Wrong Answer
18
3,064
775
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
n, total = 9, 45000 min = n * 1000 max = n * 10000 if (total > max) or (total < min): print('-1 -1 -1') else: min_man = (total - (5000 * n)) // 10000 n -= min_man total -= min_man*10000 min_sen = (total % 5000) // 1000 total -= min_sen*1000 n -= min_sen success = False for i in range(int(total // 10000)+1): if success: break ii = total - i*10000 for j in range(int(ii // 5000)+1): jj = ii - j*5000 k = jj//1000 if i + j + k + min_sen + min_man == n: print(str(i+min_man) + ' ' + str(j) + ' ' + str(k+min_sen)) success = True break if not success: print('-1 -1 -1')
s277439199
Accepted
20
2,940
101
n = int(input()) mochis = [] for i in range(n): mochis.append(int(input())) print(len(set(mochis)))
s714020126
p04043
u252828980
2,000
262,144
Wrong Answer
17
2,940
72
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a,b,c = map(int,input().split()) print("YES" if a*b*c == 35 else "NO")
s592349750
Accepted
17
2,940
72
a,b,c = map(int,input().split()) print("YES" if a*b*c ==175 else "NO")
s082983478
p03493
u901687869
2,000
262,144
Wrong Answer
17
3,060
140
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
a = input() b = a[0:0] c = a[1:0] d = a[2:0] ball = 0 if(b == 1): ball += 1 if(c == 1): ball += 1 if(d == 1): ball += 1 print(1)
s110385931
Accepted
18
2,940
132
a = input() count = 0 if a[0:1] == "1": count += 1 if a[1:2] == "1": count += 1 if a[2:3] == "1": count += 1 print(count)
s614019364
p03719
u950376354
2,000
262,144
Wrong Answer
17
2,940
81
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
A,B,C = map(int, input().split()) if A<=C<=B: print('YES') else: print('NO')
s102588937
Accepted
17
2,940
81
A,B,C = map(int, input().split()) if A<=C<=B: print('Yes') else: print('No')
s710274402
p03192
u636311816
2,000
1,048,576
Wrong Answer
17
2,940
8
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N?
print(1)
s385707372
Accepted
17
2,940
72
s = input() cnt=0 for c in s: if c =="2": cnt+=1 print(cnt)
s796976234
p03379
u625963200
2,000
262,144
Wrong Answer
305
25,556
177
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
n=int(input()) X=list(map(int,input().split())) X.sort() median1=X[n//2-1] median2=X[n//2] for i in range(n): if X[i]<=median1: print(median2) else: print(median1)
s548355865
Accepted
301
25,620
172
n=int(input()) X=list(map(int,input().split())) sortedX=sorted(X) m1=sortedX[n//2-1] m2=sortedX[n//2] for i in range(n): if X[i]<=m1: print(m2) else: print(m1)
s792380491
p03338
u562015767
2,000
1,048,576
Wrong Answer
34
9,116
238
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
n = int(input()) l = list(map(str,input())) ans = 0 for i in range(n): a = l[0:i] b = l[i:n-1] tmp = [] for j in a: if j in b: tmp.append(j) tmp = set(tmp) ans = (max(ans,len(tmp))) print(ans)
s027743013
Accepted
32
9,120
234
n = int(input()) l = list(map(str,input())) ans = 0 for i in range(n): a = l[:i] b = l[i:] tmp = [] for j in a: if j in b: tmp.append(j) tmp = set(tmp) ans = (max(ans,len(tmp))) print(ans)
s653630906
p03644
u440975163
2,000
262,144
Wrong Answer
29
9,416
529
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n = int(input()) ans = 0 def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr for i in range(n + 1): k = factorization(i) for j in k: if j[0] == 2: if ans < j[1]: ans = j[1] print(ans)
s499388865
Accepted
33
9,128
121
import sys n = int(input()) ln = [64, 32, 16, 8, 4, 2, 1] for i in ln: if i <= n: print(i) sys.exit()
s771547751
p03352
u617037231
2,000
1,048,576
Wrong Answer
17
2,940
152
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
import sys X = int(input()) L = [] for i in range(1,32): for j in range(2,10): if X <= i**j: L.append(i**(j-1)) break print(max(L))
s960380692
Accepted
18
3,060
265
import sys X = int(input()) L = [] for i in range(1,32): for j in range(1,10): if X < i**j: if j != 2: L.append(i**(j-1)) break break elif X == i**j and j != 1: print(i**j) sys.exit(0) print(max(L))
s489982268
p04011
u052499405
2,000
262,144
Wrong Answer
18
3,060
123
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
n = int(input()) k = int(input()) x = int(input()) y = int(input()) ans = min(k, n) * x ans += min(0, n - k) * y print(ans)
s783737697
Accepted
17
3,064
214
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline n = int(input()) k = int(input()) x = int(input()) y = int(input()) ans = min(k, n) * x ans += max(0, n - k) * y print(ans)
s194756607
p03069
u591295155
2,000
1,048,576
Wrong Answer
352
6,012
265
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.
n = int(input()) s = input() black = 0 min_val = 200001 tot_white = s.count('.') for i in range(len(s)): if s[i] == '#': black += 1 else: tot_white -=1 print(tot_white, black) min_val = min(min_val, tot_white+black) print(min_val)
s043669630
Accepted
76
11,264
322
n = int(input()) s = input() black_right, min_val = 0, 2000001 white_left = s.count('.') ans = [white_left+black_right] for moji in s: if moji == '.': white_left -=1 else: black_right += 1 ans.append(white_left+black_right) #min_val = min(min_val, white_left+black_right) print(min(ans))
s706671775
p03997
u129978636
2,000
262,144
Wrong Answer
18
2,940
49
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.
print((int(input())+int(input()))*int(input())/2)
s621953426
Accepted
18
2,940
50
print((int(input())+int(input()))*int(input())//2)
s463274106
p03759
u442948527
2,000
262,144
Wrong Answer
25
9,156
62
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c=map(int,input().split()) print(["NO","YES"][2*b-a-c!=0])
s794311063
Accepted
29
9,060
60
a,b,c=map(int,input().split()) print(["NO","YES"][2*b==a+c])
s028078680
p03069
u200346982
2,000
1,048,576
Wrong Answer
2,104
18,848
558
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.
N = int(input()) S = input() cnt=0 l = [] b = 1 if S[0] == "." else 0 for i in range(1, N): if S[i]==S[i-1]: cnt += 1 if i == N-1: l.append(cnt+1) else: l.append(cnt+1) if i == N-1: l.append(1) cnt = 0 if len(l)<=1: print("0") exit() s = 0 m = 1000000000 for i in range(b, len(l), 2): for j in range(b, i, 2): print(i, j, l[j]) s += l[j] for j in range(i+1, len(l), 2): print(i, j, l[j]) s += l[j] m = min(s, m) print(l) print(m)
s102248970
Accepted
196
5,220
692
N = int(input()) S = input() cnt=0 l = [] b = 1 if S[0] == "." else 0 for i in range(1, N): if S[i]==S[i-1]: cnt += 1 if i == N-1: l.append(cnt+1) else: l.append(cnt+1) if i == N-1: l.append(1) cnt = 0 if len(l)<=1: print("0") exit() s = 0 q = 0 q2 = 0 for c in S: if c=="#": q += 1 else: q2 += 1 for j in range(abs(b-1), len(l), 2): #print(j, l[j]) s += l[j] m = min(q,q2,s) #print(s) for j in range(b, len(l), 2): #print(j-2,l[j-2], j-1, l[j-1]) if j-2 >= 0: s += l[j-2]-l[j-1] elif j-1 >= 0: s += -l[j-1] m = min(s, m) #print(l) print(m)
s177188028
p03658
u399721252
2,000
262,144
Wrong Answer
17
2,940
133
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
n, k = [ int(v) for v in input().split() ] bar_list = sorted([ int(v) for v in input().split() ], reverse = True) print(bar_list[:k])
s386114683
Accepted
17
2,940
138
n, k = [ int(v) for v in input().split() ] bar_list = sorted([ int(v) for v in input().split() ], reverse = True) print(sum(bar_list[:k]))
s790872203
p02388
u998185318
1,000
131,072
Wrong Answer
20
5,584
83
Write a program which calculates the cube of a given integer x.
print('整数値を入力してください') x = input() x = int(x) print(x ** 3)
s945972453
Accepted
20
5,580
130
x = input() x = int(x) if 1 <= x and x <= 100: print(x ** 3) else: print('number must larger equal 1 and less equal 100')
s558601312
p03501
u556589653
2,000
262,144
Wrong Answer
17
3,060
97
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
N,A,B = map(int,input().split()) K = N*A if K<B: print(A) elif B<K: print(B) else: print(A)
s166061835
Accepted
17
3,060
97
N,A,B = map(int,input().split()) K = N*A if K<B: print(K) elif B<K: print(B) else: print(K)
s825949461
p04029
u379716238
2,000
262,144
Wrong Answer
17
2,940
67
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
N = int(input()) ans = 0 for i in range(N): ans += i print(ans)
s149883446
Accepted
17
2,940
71
N = int(input()) ans = 0 for i in range(N): ans += i + 1 print(ans)
s781867961
p03476
u284854859
2,000
262,144
Wrong Answer
2,104
15,384
607
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
import bisect def prime(n): seq = list(range(2, n)) while len(seq) > 0: prime = seq.pop(0) yield prime seq = [i for i in seq if not i % prime == 0] q=int(input()) l = [] r = [] for i in range(q): x,y = map(int,input().split()) l.append(x) r.append(y) a = list(prime(max(r)+1)) print('a',a) c = [] for i in range(len(a)): if (a[i]+1)/2 in a: c.append(a[i]) c.sort() print('c',c) for i in range(q): h = bisect.bisect_left(c,l[i]) j = bisect.bisect_right(c,r[i]) print(j-h)
s386052839
Accepted
1,030
7,156
536
import math Q = int(input()) n = 100000 P = [False] * n P[2] = True for i in range(3, n, 2): k = True for j in range(3, int(math.sqrt(i)) + 1, 2): if i % j == 0: k = False break if k: P[i] = True a = [0] * n for i in range(1, n, 2): j = (i + 1) // 2 if P[i] and P[j]: a[i] = 1 for i in range(n - 1): a[i + 1] += a[i] for _ in range(Q): l, r = map(int, input().split()) print(a[r] - a[l - 1])
s493117951
p03555
u325264482
2,000
262,144
Wrong Answer
17
3,060
147
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() ans = "Yes" if S[0] != T[2]: ans = "No" if S[1] != T[1]: ans = "No" if S[2] != T[0]: ans = "No" print(ans)
s205164676
Accepted
17
3,060
147
S = input() T = input() ans = "YES" if S[0] != T[2]: ans = "NO" if S[1] != T[1]: ans = "NO" if S[2] != T[0]: ans = "NO" print(ans)
s965370941
p03369
u690536347
2,000
262,144
Wrong Answer
17
2,940
26
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
700+input().count("o")*100
s310707231
Accepted
17
2,940
33
print(700+input().count("o")*100)
s740358830
p03089
u977193988
2,000
1,048,576
Wrong Answer
18
3,064
638
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
import sys def input(): return sys.stdin.readline().strip() N = int(input()) B = list(map(int, input().split())) hand = [] def check(B, cnt): n = len(B) for i in range(n): if B[n - i - 1] == (n - i): hand.append(B[n - i - 1]) B = B[: n - i - 1] + B[n - i :] break if len(B) != n and len(B) > 0: return B else: return False cnt = 1 while B: B = check(B, cnt) if len(hand) < N: print(-1) sys.exit() for i in range(N): if hand[i] > i + 1: print(-1) sys.exit() answer = hand[::-1] print(*answer, sep="\n")
s745914178
Accepted
18
3,064
640
import sys def input(): return sys.stdin.readline().strip() N = int(input()) B = list(map(int, input().split())) hand = [] def check(B, cnt): n = len(B) for i in range(n): if B[n - i - 1] == (n - i): hand.append(B[n - i - 1]) B = B[: n - i - 1] + B[n - i :] break if len(B) != n and len(B) > 0: return B else: return False cnt = 1 while B: B = check(B, cnt) if len(hand) < N: print(-1) sys.exit() answer = hand[::-1] for i in range(N): if answer[i] > i + 1: print(-1) sys.exit() print(*answer, sep="\n")
s095897253
p02263
u091533407
1,000
131,072
Wrong Answer
20
7,620
526
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
if __name__=="__main__": a = list(input().split()) print(a) b = [] for i in range(len(a)): if a[i] == "+": y = b.pop() x = b.pop() z = x + y b.append(z) elif a[i] == "-": y = b.pop() x = b.pop() z = x - y b.append(z) elif a[i] == "*": y = b.pop() x = b.pop() z = x * y b.append(z) else: b.append(int(a[i])) print(b[0])
s464273150
Accepted
20
7,692
513
if __name__=="__main__": a = list(input().split()) b = [] for i in range(len(a)): if a[i] == "+": y = b.pop() x = b.pop() z = x + y b.append(z) elif a[i] == "-": y = b.pop() x = b.pop() z = x - y b.append(z) elif a[i] == "*": y = b.pop() x = b.pop() z = x * y b.append(z) else: b.append(int(a[i])) print(b[0])
s692114722
p03149
u206570055
2,000
1,048,576
Wrong Answer
17
2,940
133
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
li = list(map(int, input().split())) print(li) if 1 in li and 9 in li and 7 in li and 4 in li: print('YES') else: print('NO')
s833345658
Accepted
17
2,940
123
li = list(map(int, input().split())) if 1 in li and 9 in li and 7 in li and 4 in li: print('YES') else: print('NO')
s845710011
p03501
u947327691
2,000
262,144
Wrong Answer
17
2,940
49
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
n,a,b=map(int,input().split()) print(max(a*n,b))
s130289718
Accepted
17
2,940
49
n,a,b=map(int,input().split()) print(min(a*n,b))
s263545895
p03024
u497952650
2,000
1,048,576
Wrong Answer
19
2,940
70
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S = input() if S.count("x")>=8: print("No") else: print("Yes")
s278691259
Accepted
17
2,940
70
S = input() if S.count("x")>=8: print("NO") else: print("YES")
s535323656
p03854
u107267797
2,000
262,144
Wrong Answer
62
9,060
376
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()[::-1] dreams = ['dream', 'dreamer', 'erase', 'eraser'] dreams = [dream[::-1] for dream in dreams] i = 0 while i < len(S): flag = False for j in dreams: if S[i:i+len(j)] == j: print(S[i:i+len(j)], j) print(i) i = i + len(j) flag = True if not flag: break print("YES" if flag else "NO")
s076843883
Accepted
42
9,256
319
S = input()[::-1] dreams = ['dream', 'dreamer', 'erase', 'eraser'] dreams = [dream[::-1] for dream in dreams] i = 0 while i < len(S): flag = False for j in dreams: if S[i:i+len(j)] == j: i = i + len(j) flag = True if not flag: break print("YES" if flag else "NO")
s785448253
p03545
u867005447
2,000
262,144
Wrong Answer
17
3,064
505
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
a = [int(x) for x in list(input())] op = 3 ops = [0] * op for i in range(2 ** op): result = a[0] bry = list(format(i, "0{}b".format(op))) for index, value in enumerate(bry): if value == "1": result += a[index + 1] ops[index] = "+" else: result -= a[index + 1] ops[index] = "-" if result == 7: ans = str(a[0]) for j in range(3): ans += "{}{}".format(ops[j], a[j+1]) print(ans) break
s257177654
Accepted
18
2,940
171
a = input() for i in range(2 ** 3): s = a[0] for j in range(3): s += "+-"[i >> j & 1] + a[j+1] if eval(s) == 7: print(s + "=7") break
s368057603
p03712
u016323272
2,000
262,144
Wrong Answer
18
3,060
138
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.
#ABC062.B H,W = map(int, input().split()) for i in range(H): a = input() n = len(a) print('#'*(n+2)) print('#'+a+'#') print('#'*(n+2))
s957646350
Accepted
18
3,060
120
H,W = map(int,input().split()) print('#'*(W+2)) for i in range(H): a = input() print('#'+a+'#') print('#'*(W+2))
s886780175
p02603
u099300899
2,000
1,048,576
Wrong Answer
2,211
119,076
521
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
import sys sys.setrecursionlimit(10**8) n = int(input()) a = [int(i) for i in input().split()] def rec(k, ans, money, n): x = a[k] for i in range(k+1, len(a)): if (x < a[i]): n = money // a[i-1] money -= a[i-1] * n money += a[i] * n rec(i, ans, money, n) return ans.append(money) def main(): ans = [0] money = 1000 n = 0 rec(0, ans, money, n) print(ans) print(max(ans)) if __name__ == '__main__': main()
s782405515
Accepted
32
8,828
300
n = int(input()) a = [int(i) for i in input().split()] def main(): money = 1000 n = 0 for i in range(1, len(a)): if (a[i-1] < a[i]): n = money // a[i-1] money += (a[i] - a[i-1]) * n print(money) if __name__ == '__main__': main()
s036972226
p03050
u745514010
2,000
1,048,576
Wrong Answer
145
9,204
130
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
n = int(input()) ans = 0 for i in range(1, int(n ** 0.5)): if n % i == 0: k = (n // i) - 1 ans += k print(ans)
s650649902
Accepted
147
9,328
156
n = int(input()) ans = 0 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: k = (n // i) - 1 if k > i: ans += k print(ans)
s886628639
p03693
u709799578
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?
a = int(''.join(input().split())) if a % 4 == 0: print('Yes') else: print('No')
s005740470
Accepted
17
2,940
88
a = int(''.join(input().split())) if a % 4 == 0: print('YES') else: print('NO')
s266382040
p03160
u713492631
2,000
1,048,576
Wrong Answer
124
14,692
540
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
import sys input = lambda :sys.stdin.readline() def main(): n = int(input()) h = list(map(int, input().split())) dp = [float('inf')] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): chmin(dp, i, dp[i-1] + abs(h[i] - h[i-1])) chmin(dp, i, dp[i-2] + abs(h[i] - h[i-2])) print(dp) print(dp[n-1]) def chmin(array, idx, value): if array[idx] > value: array[idx] = value def chmax(array, idx, value): if array[idx] < value: array[idx] = value main()
s551427255
Accepted
115
13,716
514
import sys stdin = lambda : sys.stdin.readline() stdout = lambda *args: sys.stdout.write(' '.join(map(str, args))+'\n') def main(): n = int(stdin()) h = list(map(int, stdin().split())) dp = [float('inf')] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): chmin(dp, i, dp[i-1] + abs(h[i] - h[i-1])) chmin(dp, i, dp[i-2] + abs(h[i] - h[i-2])) stdout(dp[n-1]) def chmin(array, idx, value): if array[idx] > value: array[idx] = value main()
s036256091
p02841
u982591663
2,000
1,048,576
Wrong Answer
17
2,940
118
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
#A M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) if M1 == M2: print(1) else: print(0)
s486817448
Accepted
17
2,940
118
#A M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) if M1 == M2: print(0) else: print(1)
s253467688
p03545
u830054172
2,000
262,144
Wrong Answer
17
3,064
305
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
A = list(input()) for i in range(2**3): num = int(A[0]) ans = A[0] for j in range(3): if ((i >> j)&1): num += int(A[j+1]) ans += "+"+A[j+1] else: num -= int(A[j+1]) ans += "-"+A[j+1] if num == 7: print(ans) break
s142946929
Accepted
17
2,940
231
A = input() for i in range(2**3): ans = A[0] for j in range(3): if ((i >> j)&1): ans += "+"+A[j+1] else: ans += "-"+A[j+1] if eval(ans) == 7: print(ans+"=7") break
s114695862
p02842
u811436126
2,000
1,048,576
Wrong Answer
18
2,940
152
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
import math n = int(input()) ans = n // 1.08 + 1 val = math.floor(ans * 1.08) print(ans, val) if val == n: print(int(ans)) else: print(':(')
s194745553
Accepted
20
2,940
198
n = int(input()) ans = 0 for i in range(100): val = 100 * n + i if val % 108 == 0: ans = val // 108 break else: pass print(':(') if ans == 0 else print(ans)
s809548537
p03944
u588081069
2,000
262,144
Wrong Answer
155
3,064
1,028
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
W, H, N = list(map(int, input().split())) input_list = [] for i in range(N): input_list.append(list(map(int, input().split()))) input_list[i][1] = H - input_list[i][1] C = [[0] * W] * H for col in input_list: if col[2] == 1: for w in range(len(C)): for h in range(len(C[w])): if w <= col[0]: C[w][h] = 1 elif col[2] == 2: for w in range(len(C)): for h in range(len(C[w])): if w >= col[0]: C[w][h] = 1 elif col[2] == 3: for w in range(len(C)): for h in range(len(C[w])): if h <= col[1]: C[w][h] = 1 elif col[2] == 4: for w in range(len(C)): for h in range(len(C[w])): if h >= col[1]: C[w][h] = 1 cnt = 0 for col in C: cnt += col.count(1) print(cnt)
s911192226
Accepted
17
3,064
531
W, H, N = list(map(int, input().split())) L, R = 0, W D, T = 0, H for i in range(N): x, y, a = list(map(int, input().split())) if a == 1: if L < x: L = x elif a == 2: if x < R: R = x elif a == 3: if D < y: D = y elif a == 4: if y < T: T = y if (R - L) > 0 and (T - D) > 0: print((R - L) * (T - D)) elif (R - L) > 0 and (T - D) < 0: print((R - L)) elif (R - L) < 0 and (T - D) > 0 > 0: print(T - D) else: print(0)
s439743891
p02842
u326609687
2,000
1,048,576
Wrong Answer
36
3,060
142
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
N = int(input()) x = int(N / 1.08) for y in range(x, x + 3): p = int(1.08 * y) if p == N: print(p) exit(0) print(':(')
s886500059
Accepted
17
2,940
143
N = int(input()) x = int(N / 1.08) for y in range(x, x + 3): p = int(1.08 * y) if p == N: print(y) exit(0) print(':(')
s419954102
p02741
u695655590
2,000
1,048,576
Wrong Answer
17
3,064
324
Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
K = int(input()) Ans = 0 if K == 4 or K == 6 or K == 9 or K == 10 or K == 14 or K == 21 or K == 22 or K == 25 or K == 26: Ans = 2 elif K == 28 or K == 30: Ans = 4 elif K == 8 or K == 12 or K == 18 or K == 20 or K == 27: Ans = 5 elif K == 16: Ans = 14 elif K == 24: Ans = 15 elif K == 32: Ans = 51 else: Ans = 1
s617639597
Accepted
19
3,064
338
K = int(input()) Ans = 0 if K == 4 or K == 6 or K == 9 or K == 10 or K == 14 or K == 21 or K == 22 or K == 25 or K == 26: Ans = 2 elif K == 28 or K == 30: Ans = 4 elif K == 8 or K == 12 or K == 18 or K == 20 or K == 27: Ans = 5 elif K == 16: Ans = 14 elif K == 24: Ans = 15 elif K == 32: Ans = 51 else: Ans = 1 print(Ans)
s514936310
p02406
u037441960
1,000
131,072
Wrong Answer
20
5,584
140
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
n = int(input()) for i in range(1, n) : x = i if(x % 3 == 0 or x % 10 == 3) : print(" ", i, end = "") i += 1 else : i += 1 print()
s878866953
Accepted
20
6,164
147
n = int(input()) for i in range(3, n + 1) : if(i % 3 == 0 or "3" in str(i)) : print(" ", i, sep = "", end = "") i += 1 else : pass print()
s483543075
p02414
u914146430
1,000
131,072
Wrong Answer
20
7,732
282
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
n,m,l=list(map(int,input().split())) m_A=[list(map(int,input().split())) for i in range(n)] m_B=[list(map(int,input().split())) for i in range(m)] for i in range(n): for k in range(l): s=0 for j in range(m): s+=m_A[i][j]*m_B[j][k] print(s)
s256474216
Accepted
420
8,628
317
n,m,l=list(map(int,input().split())) m_A=[list(map(int,input().split())) for i in range(n)] m_B=[list(map(int,input().split())) for i in range(m)] for i in range(n): t=[] for k in range(l): s=0 for j in range(m): s+=m_A[i][j]*m_B[j][k] t.append(s) print(*t)
s486718124
p02396
u489071923
1,000
131,072
Wrong Answer
50
7,968
94
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.
import sys x = 0 for i in sys.stdin.readlines(): x += 1 print("Case "+ str(x)+":"+ i )
s569046704
Accepted
60
7,952
144
import sys i = 0 for x in sys.stdin.readlines(): x = x.rstrip() if x == "0": break i += 1 print("Case "+ str(i)+": "+ x)
s060496223
p03487
u760771686
2,000
262,144
Wrong Answer
98
22,448
209
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
from collections import defaultdict N = int(input()) A = list(map(int,input().split())) hashmap = defaultdict(int) for a in A: hashmap[a]+=1 ans = 0 for k, v in hashmap.items(): ans+=min(v,k-v) print(ans)
s652749573
Accepted
93
22,488
240
from collections import defaultdict N = int(input()) A = list(map(int,input().split())) hashmap = defaultdict(int) for a in A: hashmap[a]+=1 ans = 0 for k, v in hashmap.items(): if k < v: ans+=v-k elif k > v: ans+=v print(ans)
s380790319
p02259
u599130514
1,000
131,072
Wrong Answer
20
5,600
426
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
def bubbleSort(A, N): flag = True count = 0 while flag: flag = 0 for j in range(N-1, 0, -1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag = 1 count += 1 print(A) print(count) arr_length = int(input()) arr_num = [int(i) for i in input().split(" ")] bubbleSort(arr_num, arr_length)
s255429630
Accepted
30
5,608
427
def bubbleSort(A, N): flag = True count = 0 while flag: flag = 0 for j in range(N-1, 0, -1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag = 1 count += 1 print(*A) print(count) arr_length = int(input()) arr_num = [int(i) for i in input().split(" ")] bubbleSort(arr_num, arr_length)
s462139069
p03251
u477650749
2,000
1,048,576
Wrong Answer
17
2,940
252
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N, M, X, Y = map(int, input().split()) list_x = [int(i) for i in input().split()] list_y = [int(j) for j in input().split()] if X >= Y: print("War") else: if max(list_x) +1 >= min(list_y): print("War") else: print("No War")
s180159618
Accepted
17
2,940
267
N, M, X, Y = map(int, input().split()) list_x = [int(i) for i in input().split()] list_y = [int(j) for j in input().split()] if max(list_x) >= min(list_y): print('War') else: if X < max(list_x) + 1 <= Y: print('No War') else: print('War')
s553352797
p03578
u500297289
2,000
262,144
Wrong Answer
277
41,816
384
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
N = int(input()) D = list(map(int, input().split())) M = int(input()) T = list(map(int, input().split())) dic = {} for d in D: if d in dic.keys(): dic[d] += 1 else: dic[d] = 1 for t in T: if t in dic.keys(): if dic[t] == 0: print('No') exit() dic[t] -= 1 else: print('No') exit() print('Yes')
s467873877
Accepted
267
41,316
384
N = int(input()) D = list(map(int, input().split())) M = int(input()) T = list(map(int, input().split())) dic = {} for d in D: if d in dic.keys(): dic[d] += 1 else: dic[d] = 1 for t in T: if t in dic.keys(): if dic[t] == 0: print('NO') exit() dic[t] -= 1 else: print('NO') exit() print('YES')
s551329003
p02578
u589734885
2,000
1,048,576
Wrong Answer
82
32,176
232
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
def main(): n = int(input()) a = list(map(int, input().split(" "))) top = a[0] ans = 0 for height in a: if top < height: ans += height - top top = height print(ans) main()
s499169650
Accepted
92
32,256
242
def main(): n = int(input()) a = list(map(int, input().split(" "))) top = a[0] ans = 0 for i in range(n): if a[i] < top: ans += top - a[i] else: top = a[i] print(ans) main()
s019231152
p02865
u660245210
2,000
1,048,576
Wrong Answer
17
2,940
71
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
N = int(input()) if N % 2 == 1: print((N-1) / 2) else: print(N/2 - 1)
s536570298
Accepted
17
2,940
34
N = int(input()) print((N-1) // 2)