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
s723014109
p03024
u492929439
2,000
1,048,576
Wrong Answer
18
2,940
104
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() WinNum = S.count('o') if(15-len(S) >= (8-WinNum)): print("Yes") else: print("No")
s714619938
Accepted
17
2,940
105
S = input() WinNum = S.count('o') if(15-len(S) >= (8-WinNum)): print("YES") else: print("NO")
s670621552
p03738
u558836062
2,000
262,144
Wrong Answer
17
2,940
113
You are given two positive integers A and B. Compare the magnitudes of these numbers.
A = int(input()) B = int(input()) if A > B: print('GREATER') if A == B: print('EQUAL') else: print('LESS')
s141160838
Accepted
17
2,940
114
A = int(input()) B = int(input()) if A > B: print("GREATER") if A < B: print("LESS") if A == B: print("EQUAL")
s168168327
p03998
u970308980
2,000
262,144
Wrong Answer
17
3,060
297
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
def abc(): players = dict() players['a'] = list(input().rstrip()) players['b'] = list(input().rstrip()) players['c'] = list(input().rstrip()) p = 'a' while True: if len(players[p]) == 0: print(p) return p = players[p].pop() abc()
s686507078
Accepted
17
3,060
306
def abc(): players = dict() players['a'] = list(input().rstrip()) players['b'] = list(input().rstrip()) players['c'] = list(input().rstrip()) p = 'a' while True: if len(players[p]) == 0: print(p.upper()) return p = players[p].pop(0) abc()
s759998848
p02831
u464823755
2,000
1,048,576
Wrong Answer
24
9,096
72
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
import math a, b= map(int,input().split()) d= math.gcd(a,b) print(a*b/d)
s406509707
Accepted
29
9,116
74
import math a, b= map(int,input().split()) d= math.gcd(a,b) print(a*b//d)
s851232789
p03712
u249895018
2,000
262,144
Wrong Answer
17
3,064
420
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.
import sys if __name__ == '__main__': count = 0 for line in sys.stdin: D = [] if count == 0: line = line.rstrip("\n").split(" ") H = int(line[0]) W = int(line[1]) count+=1 else: D.append(line.rstrip("\n")) print("".join(["#"]*(W+1))) for i in range(len(D)): print("#"+D[i]+"#") print("".join(["#"]*(W+1)))
s925602513
Accepted
17
3,064
416
import sys if __name__ == '__main__': count = 0 D = [] for line in sys.stdin: if count == 0: line = line.rstrip("\n").split(" ") H = int(line[0]) W = int(line[1]) count+=1 else: D.append(line.rstrip("\n")) print("".join(["#"]*(W+2))) for i in range(len(D)): print("#"+D[i]+"#") print("".join(["#"]*(W+2)))
s543622001
p02831
u094948011
2,000
1,048,576
Wrong Answer
67
3,064
399
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
A,B = map(int,input().split()) p = 2 if A > B: for y in range(100000): t = (A * p) / B o = (A * p) if t % 2 == 0: print(int(o)) break else: p += 1 else: for r in range(100000): t = (B * p) / A o = (B * p) if t % 2 == 0: print(int(o)) break else: p += 1
s523693728
Accepted
54
3,064
398
A,B = map(int,input().split()) p = 1 if A > B: for y in range(100000000): e = (A * p) % B o = (A * p) if e == 0: print(int(o)) break else: p += 1 else: for r in range(100000000): e = (B * p) % A o = (B * p) if e == 0: print(int(o)) break else: p += 1
s884097258
p03999
u820351940
2,000
262,144
Wrong Answer
25
3,188
288
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.
(lambda nums: (lambda index, itertools=__import__("itertools"): print(sum([eval("".join((lambda t: [[t.insert(j, "+") for j in reversed(i)], t][1])(list(nums)))) for i in itertools.chain(*[itertools.combinations(index, x) for x in range(len(index) + 1)])])))(range(1, len(nums))))("1234")
s535813696
Accepted
31
3,064
289
(lambda nums: (lambda index, itertools=__import__("itertools"): print(sum([eval("".join((lambda t: [[t.insert(j, "+") for j in reversed(i)], t][1])(list(nums)))) for i in itertools.chain(*[itertools.combinations(index, x) for x in range(len(index) + 1)])])))(range(1, len(nums))))(input())
s680213219
p03471
u231218215
2,000
262,144
Wrong Answer
2,104
3,064
712
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.
#encoding: utf-8 import os, sys import math def read_items_in_line(cast=int): return [cast(x) for x in sys.stdin.readline().strip(' \n').split(' ')] def checK(remain_N, remain_Y, a, b, c): if remain_N == 0 or remain_Y == 0: print("{} {} {}".format(a, b, c)) exit() N, Y = read_items_in_line() for a_i in range(int(Y / 10000)): remain_N = N - a_i remain_Y = Y - a_i * 10000 for b_i in range(int(remain_Y / 5000)): remain_N = N - b_i remain_Y = Y - b_i * 5000 for c_i in range(int(remain_Y / 1000)): remain_N = N - c_i remain_Y = Y - c_i * 1000 checK(remain_N, remain_Y, a_i, b_i, c_i) ### unsat print("-1 -1 -1")
s562071543
Accepted
1,746
3,064
1,005
#encoding: utf-8 import os, sys import math def read_items_in_line(cast=int): return [cast(x) for x in sys.stdin.readline().strip(' \n').split(' ')] def checK(remain_N, remain_Y, a, b, c): if remain_N == 0 and remain_Y == 0: print("{} {} {}".format(a, b, c)) exit(0) N, Y = read_items_in_line() for a_i in reversed(range(int(Y / 10000) + 1)): remain_N = N - a_i remain_Y = Y - a_i * 10000 if remain_N < 0 or remain_Y < 0: continue for b_i in reversed(range(int(remain_Y / 5000) + 1)): remain_N = N - a_i - b_i remain_Y = Y - a_i * 10000 - b_i * 5000 if remain_N < 0 or remain_Y < 0: continue if remain_N == remain_Y / 1000: c_i = int(remain_Y / 1000) remain_N = N - a_i - b_i - c_i remain_Y = Y - a_i * 10000 - b_i * 5000 - c_i * 1000 checK(remain_N, remain_Y, a_i, b_i, c_i) ### unsat print("-1 -1 -1")
s479425366
p04043
u912867658
2,000
262,144
Wrong Answer
17
2,940
120
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.
s = list(input().split()) a = s.count("5") b = s.count("7") if a == 2 and b == 1: print("Yes") else: print("No")
s296153071
Accepted
17
2,940
120
s = list(input().split()) a = s.count("5") b = s.count("7") if a == 2 and b == 1: print("YES") else: print("NO")
s906586815
p03352
u681917640
2,000
1,048,576
Wrong Answer
18
3,060
240
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.
candidates = [ 1 ] for b in range(2, int(1000**1/2)+1): p = 0 while b**p <= 1000: candidates.append(b**p) p += 1 candidates.sort(reverse=True) X = int(input()) for c in candidates: if c <= X: print(c) exit()
s399567003
Accepted
18
2,940
227
candidates = set([1]) for b in range(2, int(1000**1/2)+1): p = 2 while b**p <= 1000: candidates.add(b**p) p += 1 X = int(input()) for c in sorted(candidates, reverse=True): if c <= X: print(c) exit()
s351354081
p03386
u276204978
2,000
262,144
Wrong Answer
2,107
18,256
110
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A, B, K = map(int, input().split()) for i in range(A, B+1): if i <= A + K or i <= B + K: print(i)
s770899857
Accepted
17
3,060
280
A, B, K = map(int, input().split()) # if (A <= i and i <= A+K-1) or (B-K+1<= i and i <= B): # print(i) S=set() for i in range(A, min(B+1, A+K)): S.add(i) for i in range(max(A, B-K+1), B+1): S.add(i) for k in sorted(S): print(k)
s020438786
p04012
u007381711
2,000
262,144
Wrong Answer
27
9,096
190
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.
# -*- coding:utf-8 -*- import sys input = sys.stdin.readline w = input() w_set = set(w) for i in w_set: if w.count(i)%2==1: print("No") sys.exit() else: continue print("Yes")
s732517226
Accepted
26
9,024
198
# -*- coding:utf-8 -*- import sys # input = sys.stdin.readline w = list(input()) w_set = set(w) for i in w_set: if w.count(i)%2==1: print("No") sys.exit() else: continue print("Yes")
s506206210
p00015
u917432951
1,000
131,072
Wrong Answer
20
5,588
233
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
if __name__ == '__main__': n = (int)(input()) for _ in range(n): sNumber = (int)(input()) tNumber = (int)(input()) uNumber = sNumber+tNumber print("over flow" if uNumber > 10**80 else uNumber)
s663132432
Accepted
20
5,584
233
if __name__ == '__main__': n = (int)(input()) for _ in range(n): sNumber = (int)(input()) tNumber = (int)(input()) uNumber = sNumber+tNumber print("overflow" if uNumber >= 10**80 else uNumber)
s285525334
p03608
u477320129
2,000
262,144
Wrong Answer
1,162
39,620
1,204
There are N towns in the State of Atcoder, connected by M bidirectional roads. The i-th road connects Town A_i and B_i and has a length of C_i. Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road. If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?
#!/usr/bin/env python3 import sys def solve(N: int, M: int, R: int, r: "List[int]", A: "List[int]", B: "List[int]", C: "List[int]"): from scipy.sparse import coo_matrix from scipy.sparse.csgraph import floyd_warshall import numpy as np # coo_matrix((data, (i, j)), [shape=(M, N)]) mat = floyd_warshall(coo_matrix((C, (A, B)), shape=(N+1, N+1), dtype=np.int32).tocsr()) # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int R = int(next(tokens)) # type: int r = [int(next(tokens)) for _ in range(R)] # type: "List[int]" A = [int()] * (M) # type: "List[int]" B = [int()] * (M) # type: "List[int]" C = [int()] * (M) # type: "List[int]" for i in range(M): A[i] = int(next(tokens)) B[i] = int(next(tokens)) C[i] = int(next(tokens)) print(solve(N, M, R, r, A, B, C)) def test(): import doctest doctest.testmod() if __name__ == '__main__': #test() main()
s827237071
Accepted
1,310
39,564
1,373
#!/usr/bin/env python3 import sys def solve(N: int, M: int, R: int, r: "List[int]", A: "List[int]", B: "List[int]", C: "List[int]"): from scipy.sparse import coo_matrix from scipy.sparse.csgraph import floyd_warshall from itertools import permutations from functools import reduce # coo_matrix((data, (i, j)), [shape=(M, N)]) mat = floyd_warshall(coo_matrix((C, (A, B)), shape=(N+1, N+1)).tocsr(), directed=False) f = lambda a, b: (a[0]+mat[a[1]][b], b) return int(min(reduce(f, q, (0, s))[0] for s, *q in permutations(r))) # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int R = int(next(tokens)) # type: int r = [int(next(tokens)) for _ in range(R)] # type: "List[int]" A = [int()] * (M) # type: "List[int]" B = [int()] * (M) # type: "List[int]" C = [int()] * (M) # type: "List[int]" for i in range(M): A[i] = int(next(tokens)) B[i] = int(next(tokens)) C[i] = int(next(tokens)) print(solve(N, M, R, r, A, B, C)) def test(): import doctest doctest.testmod() if __name__ == '__main__': #test() main()
s938175597
p03696
u259190728
2,000
262,144
Wrong Answer
25
9,180
190
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
n=int(input()) s=input() l=[] for i in s: if i==')': if len(l)>0: if l[-1]=='(': l.pop() else: l.append(i) else: l.append(i) print(len(l)*'(' + s)
s655311482
Accepted
29
9,156
239
n=int(input()) s=input() l=[] for i in s: if i==')': if len(l)>0: if l[-1]=='(': l.pop() else: l.append(i) else: l.append(i) else: l.append(i) print(l.count(')')*'(' + s +l.count('(')*')')
s240611688
p03711
u021916304
2,000
262,144
Wrong Answer
17
3,064
351
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
def ii():return int(input()) def iim():return map(int,input().split()) def iil():return list(map(int,input().split())) def ism():return map(str,input().split()) def isl():return list(map(str,input().split())) l1 = [1,3,5,7,8,10,12] l2 = [4,6,9,11] x,y = iim() if (x in l1 and y in l2) or (x in l2 and y in l2): print('Yes') else: print('No')
s237864550
Accepted
17
3,064
351
def ii():return int(input()) def iim():return map(int,input().split()) def iil():return list(map(int,input().split())) def ism():return map(str,input().split()) def isl():return list(map(str,input().split())) l1 = [1,3,5,7,8,10,12] l2 = [4,6,9,11] x,y = iim() if (x in l1 and y in l1) or (x in l2 and y in l2): print('Yes') else: print('No')
s463126680
p03611
u357949405
2,000
262,144
Wrong Answer
102
13,964
260
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
N = int(input()) A = [int(i) for i in input().split()] ave = sum(A) // len(A) ans1 = len(list(filter(lambda x: x == ave or x+1 == ave or x-1 == ave, A))) ans2 = len(list(filter(lambda x: x == ave+1 or x+1 == ave+1 or x-1 == ave+1, A))) print(max(ans1, ans2))
s776440711
Accepted
297
31,060
440
from collections import Counter N = int(input()) A = [int(i) for i in input().split()] l = [] for i in A: l.extend([i-1, i, i+1]) count = Counter(l) cand = sorted(count.most_common(), key=lambda x: x[1], reverse=True)[:3] cand = list(filter(lambda x: cand[2][1]<=x[1], count.most_common())) ans = 0 for tpl in cand: n = len(list(filter(lambda x: x == tpl[0] or x+1 == tpl[0] or x-1 == tpl[0], A))) ans = max(ans, n) print(ans)
s161121433
p03605
u071061942
2,000
262,144
Wrong Answer
18
2,940
82
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 = input() for i in N: if i == 9: print("Yes") else: print("No")
s774170701
Accepted
19
2,940
93
N = list(map(int,input())) if N[0] == 9 or N[1] == 9: print("Yes") else: print("No")
s820196400
p03251
u748562597
2,000
1,048,576
Wrong Answer
17
3,064
288
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()) x = list(map(int, input().split())) y = list(map(int, input().split())) xx = max(x) yy = min(y) if (X > Y): print('War') elif (xx > yy): print('War') elif (yy < X): print('War') elif (Y < xx): print('War') else: print('No war')
s342785135
Accepted
17
3,064
292
N, M, X, Y= map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) xx = max(x) yy = min(y) if (X >= Y): print('War') elif (xx >= yy): print('War') elif (yy <= X): print('War') elif (Y <= xx): print('War') else: print('No War')
s616874130
p03485
u543954314
2,000
262,144
Wrong Answer
18
2,940
76
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 ==1: a += 1 print((a+b)/2)
s419535127
Accepted
19
2,940
81
a, b = map(int, input().split()) if (a + b) % 2 ==1: a += 1 print(int((a+b)/2))
s086933593
p02401
u731896389
1,000
131,072
Wrong Answer
20
7,604
290
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.
while 1: a,b,c = list(map(str,input().split())) num_a=int(a) num_c=int(c) if b=="+": print(num_a+num_c) elif b=="-": print(num_a-num_c) elif b=="*": print(num_a*num_c) elif b=="/": print(num_a/num_c) elif b=="?": break
s774214670
Accepted
20
7,692
291
while 1: a,b,c = list(map(str,input().split())) num_a=int(a) num_c=int(c) if b=="+": print(num_a+num_c) elif b=="-": print(num_a-num_c) elif b=="*": print(num_a*num_c) elif b=="/": print(num_a//num_c) elif b=="?": break
s359857754
p03337
u575653048
2,000
1,048,576
Wrong Answer
17
2,940
55
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()) print([a+b, a-b, a*b])
s685539627
Accepted
17
2,940
60
a, b = map(int, input().split()) print(max([a+b, a-b, a*b]))
s708193218
p03591
u997023236
2,000
262,144
Wrong Answer
17
2,940
67
Ringo is giving a present to Snuke. Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things. You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.
S=input() if S[0:3]=='YAKI': print('Yes') else: print('No')
s452145937
Accepted
17
2,940
65
if input().startswith("YAKI"): print("Yes") else: print("No")
s596117891
p03160
u858929490
2,000
1,048,576
Wrong Answer
124
13,900
300
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()) a=list(map(int,input().split())) ans=0 i=0 while(i<n-2): k=min(abs(a[i+2]-a[i]),abs(a[i+1]-a[i])+abs(a[i+2]-a[i+1])) ans+=k if abs(a[i+2]-a[i])<=abs(a[i+1]-a[i])+abs(a[i+2]-a[i+1]): i+=2 else: i+=1 if i==n-2: ans+=abs(a[n-1]-a[n-2]) print(ans)
s424963886
Accepted
138
13,980
225
n=int(input()) a=list(map(int,input().split())) dp=[0]*n for i in range(1,n): if i==1: dp[i]=abs(a[i]-a[i-1]) else: dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2])) print(dp[n-1])
s135327933
p02796
u232652798
2,000
1,048,576
Wrong Answer
2,105
93,980
334
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
N = int(input()) L = [] for i in range(N): x = [int(x) for x in input().split()] L.append(x) for i in range(len(L)): L[i][0] = L[i][0] - L[i][1] L[i][1] = L[i][0] + L[i][1] S =[] Q = sorted(L) for i in range(0,len(Q)-1): if Q[i+1][0] >=Q[i][1] : S.append([Q[i][0],Q[i][1]]) print(S) print(len(S)+1)
s342032014
Accepted
516
44,496
410
N = int(input()) XL = [list(map(int, input().split())) for _ in range(N)] RL = [[0, 0] for _ in range(N)] for i in range(N): left = XL[i][0] - XL[i][1] right = XL[i][0] + XL[i][1] RL[i][0] = left RL[i][1] = right RL.sort(key=lambda x: x[1]) now_right = RL[0][1] cnt = 0 for i in range(1, N): if now_right <= RL[i][0]: now_right = RL[i][1] else: cnt += 1 print(N - cnt)
s880084226
p02744
u377370946
2,000
1,048,576
Wrong Answer
59
3,316
541
In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be **isomorphic** when the following conditions are satisfied: * |s| = |t| holds. * For every pair i, j, one of the following holds: * s_i = s_j and t_i = t_j. * s_i \neq s_j and t_i \neq t_j. For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are not. A string s is said to be in **normal form** when the following condition is satisfied: * For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison. For example, `abcac` is in normal form, but `zyxzx` is not since it is isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`. You are given an integer N. Print all strings of length N that are in normal form, in lexicographically ascending order.
n = int(input()) tmp_list = list('a' * n) num_list = [97] * n target = n - 1 tmp_target=n-1 while tmp_target>0: print("".join(list(map(chr, num_list)))) if num_list[target-1] >= num_list[target]: num_list[target] += 1 else: num_list[target]=97 tmp_target=target-1 while tmp_target>0: if num_list[tmp_target-1] >=num_list[tmp_target]: num_list[tmp_target]+=1 break else: num_list[tmp_target]=97 tmp_target-=1
s935679157
Accepted
368
4,340
584
n = int(input()) num_list = [97] * n target = n - 1 tmp_target = n - 1 max_num = 97 if n==1: print('a') while tmp_target > 0: print("".join(list(map(chr, num_list)))) if max(num_list[0:target:]) >= num_list[target]: num_list[target] += 1 else: num_list[target] = 97 tmp_target = target - 1 while tmp_target > 0: if max(num_list[0:tmp_target:]) >= num_list[tmp_target]: num_list[tmp_target] += 1 break else: num_list[tmp_target] = 97 tmp_target -= 1
s554467375
p03574
u804085889
2,000
262,144
Wrong Answer
27
3,064
420
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.
h,w = map(int, input().split()) S=[["." for _ in range(w+2)]] S+=[["."]+[i for i in input()]+["."]for _ in range(h)] S+=[["." for _ in range(w+2)]] print(S) for i in range(1, h+1): l="" for j in range(1, w+1): if S[i][j]=="#": l+="#" else: # l+=str(int(S[i][j]==".")) l+=str(sum(S[i+n][j+m]=="#" for n in range(-1, 2, 1) for m in range(-1, 2, 1))) print(l)
s070477753
Accepted
27
3,064
371
h,w = map(int, input().split()) S=[["." for _ in range(w+2)]] S+=[["."]+[i for i in input()]+["."]for _ in range(h)] S+=[["." for _ in range(w+2)]] for i in range(1, h+1): l="" for j in range(1, w+1): if S[i][j]=="#": l+="#" else: l+=str(sum(S[i+n][j+m]=="#" for n in range(-1, 2, 1) for m in range(-1, 2, 1))) print(l)
s420345459
p03779
u667458133
2,000
262,144
Wrong Answer
18
2,940
84
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
X = int(input()) r = 1 num = 0 while num >= X: num += r r += 1 print(r-1)
s687523136
Accepted
29
2,940
84
X = int(input()) r = 1 num = 0 while num < X: num += r r += 1 print(r-1)
s824896430
p02646
u188226132
2,000
1,048,576
Wrong Answer
2,205
9,180
232
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) for i in range(t): if b<a: a-=v b-=w else: a+=v b+=w if a==b: print("Yes") exit() print("No")
s159513124
Accepted
24
9,168
200
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) if w>=v: print("NO") else:#v>w dif=v-w if dif*t>=abs(a-b): print("YES") else: print("NO")
s908223208
p03698
u498620941
2,000
262,144
Wrong Answer
17
3,060
203
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s = list(input()) size = len(s) count = 0 ans = {} for i in s: if i in ans.keys() : count += 1 else : ans[i] = 1 pass if count == 0 : print("YES") else: print("NO")
s359948910
Accepted
17
3,060
203
s = list(input()) size = len(s) count = 0 ans = {} for i in s: if i in ans.keys() : count += 1 else : ans[i] = 1 pass if count == 0 : print("yes") else: print("no")
s127912211
p03434
u826263061
2,000
262,144
Wrong Answer
18
3,064
169
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())) a.sort(reverse=True) alice = sum([i for i in a if i%2 == 0]) bob = sum([i for i in a if i%2 == 1]) print(alice-bob)
s605274227
Accepted
18
3,060
173
n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) alice = sum([a[i] for i in range(0,n,2)]) bob = sum([a[i] for i in range(1,n,2)]) print(alice-bob)
s667615634
p03353
u729133443
2,000
1,048,576
Wrong Answer
34
4,388
86
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
s=input();print(sorted(s[i:i+j]for i in range(len(s))for j in range(6))[int(input())])
s520002226
Accepted
36
4,584
78
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(30000)})[int(input())])
s885479296
p03779
u127499732
2,000
262,144
Wrong Answer
18
3,188
47
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
print(((-1+(1+8*int(input()))**0.5)//2+1))
s952323795
Accepted
25
2,940
223
def main(): x = int(input()) k = int(x ** .5) i = 0 while True: p = i * (i + 1) // 2 if p >= x: print(i) break i += 1 if __name__ == '__main__': main()
s797846148
p03564
u445511055
2,000
262,144
Wrong Answer
18
3,060
424
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
# -*- coding: utf-8 -*- def main(): """Function.""" n = int(input()) k = int(input()) flag = 0 temp = 1 for _ in range(n): print(_, temp) if flag == 0: if temp < k: temp = temp * 2 else: temp += k flag = 1 elif flag == 1: temp += k print(temp) if __name__ == "__main__": main()
s014436264
Accepted
20
3,060
401
# -*- coding: utf-8 -*- def main(): """Function.""" n = int(input()) k = int(input()) flag = 0 temp = 1 for _ in range(n): if flag == 0: if temp < k: temp = temp * 2 else: temp += k flag = 1 elif flag == 1: temp += k print(temp) if __name__ == "__main__": main()
s262329641
p03502
u504715104
2,000
262,144
Wrong Answer
17
3,060
277
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.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Oct 18 17:04:29 2017 @author: goto """ y=0 x=input() print(type(x)) x_int=[int(x)for i in list(x)] for i in range(len(x_int)): y+=x_int[i] if int(x)/y==0: print("Yes") else: print("No")
s645837968
Accepted
17
3,060
269
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Oct 18 17:04:29 2017 @author: goto """ y=0 x=input() x_int=[int(i)for i in list(str(x))] for i in range(len(x_int)): y+=x_int[i] if int(x)%y==0: print("Yes") else: print("No")
s249872940
p03971
u627417051
2,000
262,144
Wrong Answer
111
4,712
290
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
N, A, B = list(map(int, input().split())) S = list(input()) a = 0 b = 0 for i in range(N): if S[i] == "a": if a < A + B: print("Yes") else: print("No") a += 1 elif S[i] == "b": if a + b < A + B and b < B: print("Yes") else: print("No") b += 1 else: print("No")
s648227881
Accepted
116
4,712
322
N, A, B = list(map(int, input().split())) S = list(input()) a = 0 b = 0 ps = 0 for i in range(N): if S[i] == "a": if ps < A + B: print("Yes") ps += 1 else: print("No") a += 1 elif S[i] == "b": if ps < A + B and b < B: print("Yes") b += 1 ps += 1 else: print("No") else: print("No")
s059574296
p02741
u649423802
2,000
1,048,576
Wrong Answer
17
2,940
124
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()) a=[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] a[K-1]
s062026842
Accepted
17
3,060
131
K=int(input()) a=[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] print(a[K-1])
s034458629
p02612
u508061226
2,000
1,048,576
Wrong Answer
26
9,052
33
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)
s405635097
Accepted
30
9,076
89
n = int(input()) amari = n % 1000 if amari != 0: print(1000 - amari) else: print(0)
s656214174
p00773
u494573739
8,000
131,072
Wrong Answer
20
5,460
1
VAT (value-added tax) is a tax imposed at a certain rate proportional to the sale price. Our store uses the following rules to calculate the after-tax prices. * When the VAT rate is _x_ %, for an item with the before-tax price of _p_ yen, its after-tax price of the item is _p_ (100+ _x_ ) / 100 yen, fractions rounded off. * The total after-tax price of multiple items paid at once is the sum of after-tax prices of the items. The VAT rate is changed quite often. Our accountant has become aware that "different pairs of items that had the same total after-tax price may have different total after-tax prices after VAT rate changes." For example, when the VAT rate rises from 5% to 8%, a pair of items that had the total after-tax prices of 105 yen before can now have after-tax prices either of 107, 108, or 109 yen, as shown in the table below. Before-tax prices of two items| After-tax price with 5% VAT| After-tax price with 8% VAT ---|---|--- 20, 80| 21 + 84 = 105| 21 + 86 = 107 2, 99| 2 + 103 = 105| 2 + 106 = 108 13, 88| 13 + 92 = 105| 14 + 95 = 109 Our accountant is examining effects of VAT-rate changes on after-tax prices. You are asked to write a program that calculates the possible maximum total after-tax price of two items with the new VAT rate, knowing their total after- tax price before the VAT rate change.
s120049766
Accepted
310
5,668
427
from math import floor while(True): x,y,s=map(int,input().split()) if (x,y,s)==(0,0,0): quit() ans=0 for i in range(1,s): j=s-floor(i*(100+x)/100) if j<1: continue j=floor((j+1)*(100/(100+x))) for k in [j-1,j]: if floor(i*(100+x)/100)+floor(k*(100+x)/100)==s: ans=max(ans,floor(i*(100+y)/100)+floor(k*(100+y)/100)) print(ans)
s290171928
p02260
u496045719
1,000
131,072
Wrong Answer
30
7,668
572
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
def main(): element_num = int(input()) elements = [int(s) for s in input().split()] swap_count = 0 for i in range(0, element_num - 1): max_val = elements[i + 1] max_index = i + 1 for j in range(i + 1, element_num): if max_val < elements[j]: max_val = elements[j] max_index = j if elements[i] > elements[max_index]: elements[i], elements[max_index] = elements[max_index], elements[i] swap_count += 1 print(' '.join(list(map(str, elements)))) print(swap_count) return 0 if __name__ == '__main__': main()
s488871897
Accepted
40
7,740
572
def main(): element_num = int(input()) elements = [int(s) for s in input().split()] swap_count = 0 for i in range(0, element_num - 1): min_val = elements[i + 1] min_index = i + 1 for j in range(i + 1, element_num): if elements[j] < min_val: min_val = elements[j] min_index = j if elements[i] > elements[min_index]: elements[i], elements[min_index] = elements[min_index], elements[i] swap_count += 1 print(' '.join(list(map(str, elements)))) print(swap_count) return 0 if __name__ == '__main__': main()
s988154175
p03635
u733738237
2,000
262,144
Wrong Answer
17
2,940
56
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
s = input() l= len(s)-2 x=s[0] y=s[-1] print(x+str(l)+y)
s333853248
Accepted
17
2,940
47
n,m=map(int,input().split()) print((n-1)*(m-1))
s423501877
p03860
u813098295
2,000
262,144
Wrong Answer
18
2,940
41
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().split() print(s[0]+s[1]+s[2])
s111997500
Accepted
17
2,940
50
s = input().split() print(s[0][0]+s[1][0]+s[2][0])
s296709088
p03854
u281610856
2,000
262,144
Wrong Answer
68
3,188
288
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() while True: if len(S) == 0: print("Yes") break elif S[-5:] == 'dream' or S[-5:] == 'erase': S = S[:-5] elif S[-6:] == 'eraser': S = S[:-6] elif S[-7:] == 'dreamer': S = S[:-7] else: print("No") break
s642440362
Accepted
68
3,188
288
S = input() while True: if len(S) == 0: print("YES") break elif S[-5:] == 'dream' or S[-5:] == 'erase': S = S[:-5] elif S[-6:] == 'eraser': S = S[:-6] elif S[-7:] == 'dreamer': S = S[:-7] else: print("NO") break
s327415551
p02608
u316603606
2,000
1,048,576
Wrong Answer
23
9,052
147
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
N = int (input ()) z = 1 l = [] while True: l.append ((2+z)**2-(1+z+z)) if N <= (2+z)**2-(1+z+z): break else: print (z) z += 1
s136335535
Accepted
540
9,164
207
N = int ( input()) ans = [0]*N for x in range (1,101): for y in range (1,101): for z in range (1,101): m = (x+y+z)**2-(x*y+y*z+z*x) if m <= N: ans[m-1] += 1 for i in ans: print(i)
s553583654
p04011
u766407523
2,000
262,144
Wrong Answer
17
2,940
130
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.
def inpn(): return int(input()) N, K, X, Y = inpn(), inpn(), inpn(), inpn() if K <= N: print(K*X) else: print(N*X+(N-K)*Y)
s968121351
Accepted
17
2,940
131
def inpn(): return int(input()) N, K, X, Y = inpn(), inpn(), inpn(), inpn() if N <= K: print(N*X) else: print(K*X+(N-K)*Y)
s594429565
p02659
u552145906
2,000
1,048,576
Wrong Answer
20
9,160
94
Compute A \times B, truncate its fractional part, and print the result as an integer.
A, B = input().split() A = int(A) B = float(B) print(A) print(B) C = A * B C = int(C) print(C)
s140866757
Accepted
28
10,044
102
import decimal A, B = input().split() A = int(A) B = decimal.Decimal(B) C = A * B C = int(C) print(C)
s228478929
p03636
u737321654
2,000
262,144
Wrong Answer
17
2,940
86
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
s = input() initial = s[0] final = s[len(s) - 1] print(initial + str(len(s)) + final)
s618259377
Accepted
17
2,940
89
s = input() initial = s[0] final = s[len(s) - 1] print(initial + str(len(s)-2) + final)
s095005971
p03151
u050024609
2,000
1,048,576
Wrong Answer
121
20,912
551
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
N=input() A=list(map(int, input().split())) B=list(map(int, input().split())) if sum(A) < sum(B) : print(-1) else : diff=[A[i] - B[i] for i in range(len(A))] pos=sorted([x for x in diff if x > 0]) neg=[x for x in diff if x < 0] nes=sum(neg) if nes >= 0 : print(0) else: print(diff) items = 0 total_pos = 0 for p in reversed(pos): items += 1 total_pos += p if(total_pos + nes >= 0) : print(items + len(neg)) break
s248118796
Accepted
111
18,356
531
N=input() A=list(map(int, input().split())) B=list(map(int, input().split())) if sum(A) < sum(B) : print(-1) else : diff=[A[i] - B[i] for i in range(len(A))] pos=sorted([x for x in diff if x > 0]) neg=[x for x in diff if x < 0] nes=sum(neg) if nes >= 0 : print(0) else: items = 0 total_pos = 0 for p in reversed(pos): items += 1 total_pos += p if(total_pos + nes >= 0) : print(items + len(neg)) break
s552886780
p02420
u629874472
1,000
131,072
Wrong Answer
20
5,592
269
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
char = list(input()) m = int(input()) for i in range(m): sl = input() if sl == '-': break else: sl = int(sl) a = char[0:sl] b = char.extend(a) del char[0:sl] #del print("".join(char))
s517042666
Accepted
20
5,592
332
while True: char = input() if char == '-': break else: char = list(char) m = int(input()) for i in range(m): sl = int(input()) a = char[0:sl] b = char.extend(a) del char[0:sl] #del print("".join(char))
s658233818
p03854
u086624329
2,000
262,144
Wrong Answer
69
3,188
453
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() t1='maerd' t2='remaerd' t3='esare' t4='resare' t=[t1,t2,t3,t4] s=s[::-1] ans=0 while True: if s.startswith(t1): s=s[5::] elif s.startswith(t2): s=s[7::] elif s.startswith(t3): s=s[5::] elif s.startswith(t4): s=s[6::] elif len(s)==0: break else: print('NO') ans=1 break if ans==0: print('Yes')
s041885009
Accepted
69
3,188
462
s=input() t1='maerd' t2='remaerd' t3='esare' t4='resare' t=[t1,t2,t3,t4] s=s[::-1] ans=0 while True: if s.startswith(t1): s=s[5::] elif s.startswith(t2): s=s[7::] elif s.startswith(t3): s=s[5::] elif s.startswith(t4): s=s[6::] elif len(s)==0: break else: print('NO') ans=1 break if ans==0: print('YES')
s477363618
p02417
u088337682
1,000
131,072
Wrong Answer
20
5,568
198
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
ans = [0 for i in range(23)] S = list(map(ord,input().upper())) S = [e for e in S if 64<e<91] print(S) for i in S: ans[i-65]+=1 for i in range(23): print("{} : {}".format(chr(97+i),ans[i]))
s480363107
Accepted
20
5,560
334
import sys input_str = sys.stdin.read() table = [0]*26 letters = "abcdefghijklmnopqrstuvwxyz" for A in input_str: index = 0 for B in letters: if A == B or A == B.upper(): table[index] += 1 break index += 1 for i in range(len(letters)): print("{} : {}".format(letters[i],table[i]))
s516065690
p02612
u704470185
2,000
1,048,576
Wrong Answer
31
9,132
34
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)
s570396870
Accepted
27
9,112
81
N = int(input()) a = N % 1000 if a == 0: print(0) else: print(1000 - a)
s195117138
p03386
u216631280
2,000
262,144
Wrong Answer
17
3,060
241
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()) li = [] for i in range(a, a + k): if b < i: break li.append(i) for i in range(b - k, b + 1): if i < a: continue li.append(i) li = list(set(li)) for num in li: print(num)
s802226938
Accepted
17
3,060
256
a, b, k = map(int, input().split()) li = [] for i in range(a, a + k): if b < i: break li.append(i) for i in range(b - k + 1, b + 1): if i < a: continue li.append(i) li = list(set(li)) li.sort() for num in li: print(num)
s070789225
p03583
u814986259
2,000
262,144
Wrong Answer
17
2,940
29
You are given an integer N. Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w. If there are multiple solutions, any of them will be accepted.
N=int(input()) print(2*N,N,N)
s547322629
Accepted
1,589
3,060
347
N = int(input()) for h in range(1, 3501): for n in range(1, 3501): # 4/N - 1/h - 1/n = 1/w # (4hn - Nn - Nh) / nhN = 1/w # w = nhN / (4hn - Nn - Nh) if (4*h*n - N*(n + h)) > 0 and (n*h*N) % (4*h*n - N*(n + h)) == 0: w = (n*h*N) // (4*h*n - N*(n + h)) print(h, n, w) exit(0)
s289387361
p03359
u453526259
2,000
262,144
Wrong Answer
17
2,940
90
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a, b = map(int, input().split()) if b <= a: ans = a - 1 else: ans = a print(ans)
s174469027
Accepted
17
2,940
89
a, b = map(int, input().split()) if b < a: ans = a - 1 else: ans = a print(ans)
s179808274
p03729
u599547273
2,000
262,144
Wrong Answer
17
2,940
87
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a, b, c = input().split(" ") print("Yes" if a[-1] == b[0] and b[-1] == c[0] else "No")
s695405748
Accepted
17
2,940
87
a, b, c = input().split(" ") print("YES" if a[-1] == b[0] and b[-1] == c[0] else "NO")
s032561240
p02255
u351208175
1,000
131,072
Wrong Answer
30
7,720
280
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
def insertionSort(a,n): for i in range(n): v = a[i] j = i-1 while j>=0 and a[j]>v: a[j+1] = a[j] j -= 1 a[j+1] = v print(a) return a n = int(input()) a = [int(i) for i in input().split()] insertionSort(a,n)
s203910636
Accepted
30
7,660
299
def insertionSort(a,n): for i in range(n): v = a[i] j = i-1 while j>=0 and a[j]>v: a[j+1] = a[j] j -= 1 a[j+1] = v print(" ".join(map(str,a))) return a n = int(input()) a = [int(i) for i in input().split()] insertionSort(a,n)
s330058656
p02646
u325132311
2,000
1,048,576
Wrong Answer
24
9,208
304
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
num_input = [input() for i in range(3)] a = int(num_input[0].split()[0]) v = int(num_input[0].split()[1]) b = int(num_input[1].split()[0]) w = int(num_input[1].split()[1]) t = int(num_input[2].split()[0]) if v-w<=0: ans="no" elif int((b-a)/(v-w))<=t: ans="yes" else: ans="no" print(ans)
s710642399
Accepted
23
9,152
336
num_input = [input() for i in range(3)] a = int(num_input[0].split()[0]) v = int(num_input[0].split()[1]) b = int(num_input[1].split()[0]) w = int(num_input[1].split()[1]) t = int(num_input[2].split()[0]) hoge=b-a if hoge<0: hoge=hoge*-1 if v-w<=0: ans="NO" elif t*(v-w)>=hoge: ans="YES" else: ans="NO" print(ans)
s117234672
p03729
u391731808
2,000
262,144
Wrong Answer
17
2,940
66
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
A,B,C=input().split() print("YNeos"[A[-1]!=B[0]or B[-1]!=C[0]::2])
s692236622
Accepted
17
2,940
66
A,B,C=input().split() print("YNEOS"[A[-1]!=B[0]or B[-1]!=C[0]::2])
s484583953
p03377
u434329006
2,000
262,144
Wrong Answer
18
2,940
86
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = map(int,input().split()) if (x - b) >= a: print("YES") else: print("NO")
s305356649
Accepted
17
2,940
118
a, b, x = map(int,input().split()) if a > x: print("NO") elif (a + b) < x: print("NO") else: print("YES")
s019574670
p03457
u710921979
2,000
262,144
Wrong Answer
318
3,060
144
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()) for i in range(N): t,x,y=map(int,input().split()) if x+y>t or (x+y+t)%2: print("NO") exit() print("YES")
s590639026
Accepted
325
3,060
146
N=int(input()) for i in range(N): t,x,y=map(int,input().split()) if x+y>t or (t+x+y)%2!=0: print('No') quit() print('Yes')
s655852623
p02645
u023632682
2,000
1,048,576
Wrong Answer
17
9,136
20
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
S=str(input()) S[:3]
s757097033
Accepted
23
9,028
27
S=str(input()) print(S[:3])
s902575118
p03338
u919905831
2,000
1,048,576
Wrong Answer
21
3,316
196
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.
num = int(input()) li = list(input()) i = int(num/2) while(i>num): fi = set(li[:i]) se = set(li[i:]) ans = len(list(fi & se)) if i < ans: i = ans else: i = i+1 print(i)
s921487409
Accepted
17
3,060
177
num = int(input()) li = list(input()) ans = 0 for i in range(num): fi = set(li[:i]) se = set(li[i:]) hoge = len(list(fi & se)) if hoge > ans: ans = hoge print(ans)
s052826176
p02396
u874395007
1,000
131,072
Wrong Answer
120
5,608
135
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.
repeat = True i = 0 while repeat: i += 1 num = int(input()) if num == 0: repeat = False print('Case {i}: num')
s703268845
Accepted
130
5,608
113
i = 0 while True: i += 1 num = int(input()) if num == 0: break print(f'Case {i}: {num}')
s170616297
p03486
u837286475
2,000
262,144
Wrong Answer
23
3,700
302
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.
from functools import reduce ss = input() st = input() ls = [c for c in ss] lt = [c for c in st] #print(ls) ls.sort() lt.sort(reverse = True) ans_s = reduce( lambda x,y: x+y, ls,'' ) ans_t = reduce(lambda x, y: x+y, lt) print((ans_s, ans_t)) #ans_s. print( 'Yes' if ans_s < ans_t else 'No' )
s668299516
Accepted
22
3,572
303
from functools import reduce ss = input() st = input() ls = [c for c in ss] lt = [c for c in st] #print(ls) ls.sort() lt.sort(reverse = True) ans_s = reduce( lambda x,y: x+y, ls,'' ) ans_t = reduce(lambda x, y: x+y, lt) #print((ans_s, ans_t)) #ans_s. print( 'Yes' if ans_s < ans_t else 'No' )
s631846659
p03644
u777283665
2,000
262,144
Wrong Answer
17
3,060
172
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()) alist = [2 ** i for i in range(1, 10) if 2 ** i <= 100] for i in range(n, 0, -1): if i == 1: print(1) elif i in alist: print(i)
s389120549
Accepted
17
2,940
60
n = int(input()) x = 1 while x * 2 <= n: x *= 2 print(x)
s137352597
p03149
u319805917
2,000
1,048,576
Wrong Answer
18
2,940
104
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".
A=list(input().split()) if (1 in A)and(9 in A)and(7 in A)and(4 in A): print("YES") else: print("NO")
s967249750
Accepted
20
3,060
108
A=list(input().split()) A=sorted(A) A=[int(s)for s in A] if A==[1,4,7,9]: print("YES") else: print("NO")
s349429555
p04043
u395816772
2,000
262,144
Wrong Answer
17
2,940
114
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(input().split()) a = A.count(5) b = A.count(7) if a == 2 and b == 1: print('YES') else: print('NO')
s000228713
Accepted
17
2,940
119
A = list(input().split()) a = A.count('5') b = A.count('7') if a == 2 and b == 1: print('YES') else: print('NO')
s285232418
p02255
u481175672
1,000
131,072
Wrong Answer
20
5,596
228
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
n=int(input()) a=input().rstrip().split() list(map(int,a)) for i in range(1,n): v=a[i] j=i-1 while(j>=0 and a[j]>v): a[j+1]=a[j] j-=1 a[j+1]=v for k in range(n): print(a[k],end=" ") print()
s155674857
Accepted
20
5,984
193
n = int(input()) *A, = map(int, input().split()) for i in range(n): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(*A)
s335373313
p03720
u273326224
2,000
262,144
Wrong Answer
151
12,632
220
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
import numpy as np n, m = map(int, input().split(' ')) array = np.zeros(n) for i in range(m): a, b = map(int, input().split(' ')) array[a-1] += 1 array[b-1] += 1 for number in array: print(number)
s569201773
Accepted
153
12,396
225
import numpy as np n, m = map(int, input().split(' ')) array = np.zeros(n) for i in range(m): a, b = map(int, input().split(' ')) array[a-1] += 1 array[b-1] += 1 for number in array: print(int(number))
s223646574
p03478
u350093546
2,000
262,144
Wrong Answer
41
9,132
154
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): i=str(i) cnt=0 for j in i: j=int(j) cnt+=j if a<=cnt<=b: ans+=1 print(ans)
s246843377
Accepted
39
9,184
155
n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): k=str(i) cnt=0 for j in k: j=int(j) cnt+=j if a<=cnt<=b: ans+=i print(ans)
s208122290
p03024
u602715823
2,000
1,048,576
Wrong Answer
17
2,940
85
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() no = s.count('o') r = 15 - len(s) print('Yes' if r + no >= 8 else 'No')
s265663854
Accepted
18
2,940
85
s = input() no = s.count('o') r = 15 - len(s) print('YES' if r + no >= 8 else 'NO')
s688271730
p03251
u741397536
2,000
1,048,576
Wrong Answer
18
3,060
223
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()) x_arr = list(map(int, input().split())) y_arr = list(map(int, input().split())) x_arr.append(x) y_arr.append(y) if max(x_arr) < min(y_arr): print("No war") else: print("War")
s451922641
Accepted
18
3,060
223
n, m, x, y = map(int, input().split()) x_arr = list(map(int, input().split())) y_arr = list(map(int, input().split())) x_arr.append(x) y_arr.append(y) if max(x_arr) < min(y_arr): print("No War") else: print("War")
s632242849
p02744
u760642788
2,000
1,048,576
Wrong Answer
17
3,060
318
In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be **isomorphic** when the following conditions are satisfied: * |s| = |t| holds. * For every pair i, j, one of the following holds: * s_i = s_j and t_i = t_j. * s_i \neq s_j and t_i \neq t_j. For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are not. A string s is said to be in **normal form** when the following condition is satisfied: * For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison. For example, `abcac` is in normal form, but `zyxzx` is not since it is isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`. You are given an integer N. Print all strings of length N that are in normal form, in lexicographically ascending order.
n = int(input()) lst = [] abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] for i in range(n): lst_ = lst lst = [] for s in lst_: for j in range(10): if s[-1] == abc[j - 1]: break else: lst.append(s + abc[j]) for s in lst: print(s)
s984086860
Accepted
125
14,172
254
n = int(input()) lst = ["a"] abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] for i in range(n - 1): lst_ = lst lst = [] for s in lst_: for t in abc[: len(set(s)) + 1]: lst.append(s + t) for s in lst: print(s)
s850685931
p00169
u553058997
1,000
131,072
Wrong Answer
20
7,564
533
ブラックジャックはカジノで行われるカードゲームの一種で、1 〜 13 までの数が書かれたカードを使ってゲームが行われます。各カードの点数は次のように決まっています。 * 1 は 1 点あるいは 11 点 * 2 から 9 までは、書かれている数の通りの点数 * 10 から 13 までは、10 点 このゲームには親を含めた何人かの参加者がおり、それぞれが何枚かのカードの組を持っています。このカードの組のことを手と呼びます。手の点数はカードの点数の合計です。その計算は次のように行うものとします。 * カードの点数の合計が 21 より大きくなるときは、手の点数を 0 点とする * カードの点数として、1 は 1 点と計算しても 11 点と計算してもよいが、手の点数が最大となる方を選ぶこととする 配られたカードの情報を入力とし、手の点数を出力するプログラムを作成してください。
if input() == '1': pass while True: inp = input() if inp == '0': break inp = inp.replace('11', '10') inp = inp.replace('12', '10') inp = inp.replace('13', '10') cards = tuple(map(int, inp.split())) ans = sum(cards) for i in range(cards.count(1)): if sum(cards) + 9 * (i+1) > 21: print('test', ans) break elif ans < sum(cards) + 9 * (i+1): print('test2', ans) ans = sum(cards) + 9 * (i+1) if ans > 21: ans = 0 print(ans)
s804192673
Accepted
20
7,532
444
while True: inp = input() if inp == '0': break inp = inp.replace('11', '10') inp = inp.replace('12', '10') inp = inp.replace('13', '10') cards = tuple(map(int, inp.split())) ans = sum(cards) for i in range(cards.count(1)): if sum(cards) + 10 * (i+1) > 21: break elif ans < sum(cards) + 10 * (i+1): ans = sum(cards) + 10 * (i+1) if ans > 21: ans = 0 print(ans)
s817367025
p03773
u532087742
2,000
262,144
Wrong Answer
17
3,064
154
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder. In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock". The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
# coding: utf-8 import sys for line in sys.stdin.readlines(): a = line.strip().split(" ") a1 = int(a[0]) a2 = int(a[1]) print(a1+a2 % 24)
s337619875
Accepted
17
2,940
156
# coding: utf-8 import sys for line in sys.stdin.readlines(): a = line.strip().split(" ") a1 = int(a[0]) a2 = int(a[1]) print((a1+a2) % 24)
s936526167
p02612
u054825571
2,000
1,048,576
Wrong Answer
27
9,116
30
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.
print(1000-int(input())//1000)
s730623979
Accepted
28
9,116
48
n=int(input())%1000 print(1000-n if n!=0 else 0)
s250026878
p04012
u874741582
2,000
262,144
Wrong Answer
19
2,940
123
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 = input() f=0 for i in w: if w.count(i)%2 != 0: f=0 elif i == w[-1]: f=1 print("YES" if f ==1 else "NO")
s082634066
Accepted
18
2,940
141
w = input() f=0 def beautiful(w): for i in w: if w.count(i)%2 != 0: return "No" return "Yes" print(beautiful(w))
s007636163
p03970
u300637346
2,000
262,144
Wrong Answer
17
2,940
125
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=list(input()) t=list('CODEFESTIVAL2016') count=0 for k in range(16): if s[k] == t[k]: count += 1 print(count)
s358911312
Accepted
17
2,940
124
s=input() t='CODEFESTIVAL2016' count=0 for num in range(len(s)): if s[num] != t[num]: count += 1 print(count)
s043831658
p03493
u501409901
2,000
262,144
Wrong Answer
32
9,076
218
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.
# Press the green button in the gutter to run the script. if __name__ == '__main__': s = input() count = 0 for n in range(3): if s[n] == 1: count = count + 1 print(count)
s496625001
Accepted
27
8,944
213
# Press the green button in the gutter to run the script. if __name__ == '__main__': s = input() count = 0 for n in range(3): if s[n] == '1': count = count + 1 print(count)
s551634148
p02613
u281152316
2,000
1,048,576
Wrong Answer
174
16,320
433
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()) x = "" S = [] for i in range(N): x = input() S.append(x) ans = [0]*4 for i in range(N): if S[i] == "AC": ans[0] += 1 elif S[i] == "WA": ans[1] += 1 elif S[i] == "TLE": ans[2] += 1 elif S[i] == "RE": ans[3] += 1 print('AC × ',end='') print(ans[0]) print('WA × ',end='') print(ans[1]) print('TLE × ',end='') print(ans[2]) print('RE × ',end='') print(ans[3])
s255118506
Accepted
176
16,240
429
N = int(input()) x = "" S = [] for i in range(N): x = input() S.append(x) ans = [0]*4 for i in range(N): if S[i] == "AC": ans[0] += 1 elif S[i] == "WA": ans[1] += 1 elif S[i] == "TLE": ans[2] += 1 elif S[i] == "RE": ans[3] += 1 print('AC x ',end='') print(ans[0]) print('WA x ',end='') print(ans[1]) print('TLE x ',end='') print(ans[2]) print('RE x ',end='') print(ans[3])
s476477791
p02261
u709538965
1,000
131,072
Wrong Answer
20
5,600
459
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
n = int(input()) bLst = input().split() iLst = bLst for i in range(n): for j in range(n-1,i,-1): if bLst[j][1] < bLst[j-1][1]: bLst[j],bLst[j-1] = bLst[j-1],bLst[j] print(*bLst) print("Stable") for i in range(n): min = i for j in range(i,n): if iLst[j][1] < iLst[min][1]: min = j iLst[i],iLst[min] = iLst[min],iLst[i] print(*iLst) if bLst == iLst: print("Stable"); else: print("Not stable")
s118440142
Accepted
20
5,608
463
n = int(input()) *bLst, = input().split() iLst = bLst[:] for i in range(n): for j in range(n-1,i,-1): if bLst[j][1] < bLst[j-1][1]: bLst[j],bLst[j-1] = bLst[j-1],bLst[j] print(*bLst) print("Stable") for i in range(n): min = i for j in range(i,n): if iLst[j][1] < iLst[min][1]: min = j iLst[i],iLst[min] = iLst[min],iLst[i] print(*iLst) if bLst == iLst: print("Stable") else: print("Not stable")
s994888592
p03844
u181215519
2,000
262,144
Wrong Answer
17
2,940
16
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her.
print( input() )
s322414673
Accepted
17
2,940
24
print( eval( input() ) )
s016762625
p03659
u663101675
2,000
262,144
Wrong Answer
172
23,800
231
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
N = int(input()) A = list(map(int, input().split())) S = sum(A) count = 0 Near = 10 ** 15 for i in range(N-1): count = count + A[i] if abs(2 * Near - S) > abs(2 * count - S): Near = count print(abs(2 * count - S))
s403847835
Accepted
165
23,800
230
N = int(input()) A = list(map(int, input().split())) S = sum(A) count = 0 Near = 10 ** 15 for i in range(N-1): count = count + A[i] if abs(2 * Near - S) > abs(2 * count - S): Near = count print(abs(2 * Near - S))
s737897934
p03434
u671680336
2,000
262,144
Wrong Answer
18
3,060
247
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 = list(map(int, input().split())) a_list.sort(reverse=True) Alice = 0 Bob = 0 print(a_list) for i in range(len(a_list)): if i % 2 == 0: Alice += a_list[i] else: Bob += a_list[i] print(Alice-Bob)
s296122786
Accepted
17
3,060
232
N = int(input()) a_list = list(map(int, input().split())) a_list.sort(reverse=True) Alice = 0 Bob = 0 for i in range(len(a_list)): if i % 2 == 0: Alice += a_list[i] else: Bob += a_list[i] print(Alice-Bob)
s638407630
p03962
u635252313
2,000
262,144
Wrong Answer
18
3,064
114
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
a,b,c=map(int,input().split()) if a==b==c: print(3) elif a==b or a==c or b==c: print(2) else: print(1)
s375655786
Accepted
17
2,940
52
a=set(list(map(int,input().split()))) print(len(a))
s666335703
p03501
u506587641
2,000
262,144
Wrong Answer
17
2,940
50
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(n*a, b)
s736268359
Accepted
17
2,940
55
n, a, b = map(int, input().split()) print(min(n*a, b))
s906285722
p04043
u037221289
2,000
262,144
Wrong Answer
17
2,940
190
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.
X = [map(int,input().split(' '))] five = 0 seven = 0 for i in X: if i == 7: seven += 1 elif i == 5: five += 5 if five == 2 and seven == 1: print('YES') else: print('NO')
s415152855
Accepted
17
2,940
84
X = sorted(list(map(int,input().split(' ')))) print('YES' if X == [5,5,7] else 'NO')
s740831634
p03575
u256464928
2,000
262,144
Wrong Answer
17
3,064
265
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
V,E=map(int,input().split()) edges=[set() for i in range(V)] for i in range(E): a,b=map(int,input().split()) edges[a-1].add(b-1) edges[b-1].add(a-1) for i in range(V): print(len({n for v in edges[i] for n in edges[v] if not n in edges[i] and n!=i}))
s207292594
Accepted
41
3,064
265
N,M=map(int,input().split()) edges=[list(map(int,input().split())) for i in range(M)] ans=0 for x in edges: l=list(range(N)) for y in edges: if y!=x:l=[l[y[0]-1] if l[i]==l[y[1]-1] else l[i] for i in range(N)] if len(set(l))!=1:ans+=1 print(ans)
s632994702
p04045
u757424147
2,000
262,144
Wrong Answer
26
9,160
303
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
n,k = map(int,input().split()) if k == 0: print(n) exit() dislike = list(map(int,input().split())) usable = [] for i in range(10): if i not in dislike: usable.append(i) print(usable) ans = '' for i in str(n): while int(i) not in usable: i = str((int(i)+1)%10) ans+=i print(ans)
s216416166
Accepted
61
9,132
232
n,k = map(int,input().split()) if k == 0: print(n) exit() dislike = list(input().split()) ans = n-1 flag = 1 while flag == 1: ans+=1 flag = 0 for i in str(ans): if i in dislike: flag = 1 break print(ans)
s178922856
p03555
u487288850
2,000
262,144
Wrong Answer
29
8,888
64
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.
x =input() y=input() print('Yes' if x[2]+x[1]+x[0]==y else 'No')
s751285809
Accepted
26
8,960
64
x =input() y=input() print('YES' if x[2]+x[1]+x[0]==y else 'NO')
s770176120
p04011
u920438243
2,000
262,144
Wrong Answer
17
2,940
93
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.
num = [int(input()) for i in range(4)] sum = num[0]*num[2]+(num[1]-num[0])*num[3] print(sum)
s626371691
Accepted
17
2,940
152
num = [int(input()) for i in range(4)] if num[0] <= num[1]: sum = num[0]*num[2] else: sum = num[1]*num[2]+(num[0]-num[1])*num[3] print(sum)
s969754065
p03487
u859897687
2,000
262,144
Wrong Answer
100
23,284
191
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.
n=int(input()) d=dict() for i in map(int,input().split()): if i not in d: d[i]=1 else: d[i]+=1 ans=0 for i in d.keys(): if i>=d[i]: ans+=i-d[i] else: ans+=i print(ans)
s161288591
Accepted
97
23,284
194
n=int(input()) d=dict() for i in map(int,input().split()): if i not in d: d[i]=1 else: d[i]+=1 ans=0 for i in d.keys(): if i<=d[i]: ans+=d[i]-i else: ans+=d[i] print(ans)
s205646938
p04011
u970198631
2,000
262,144
Wrong Answer
27
9,168
121
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()) if N <= K: print(N*x) else: print(K*x + (K-N)*y)
s616467910
Accepted
24
9,032
121
N = int(input()) K = int(input()) x = int(input()) y = int(input()) if N <= K: print(N*x) else: print(K*x + (N-K)*y)
s519860982
p03502
u163320134
2,000
262,144
Wrong Answer
17
2,940
109
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.
def n(num): ret=0 for i in range(10): ret+=int((num%(10**(i+1)))/(10**i)) return ret print(n(1000))
s361396065
Accepted
17
2,940
162
def n(num): ret=0 for i in range(10): ret+=int((num%(10**(i+1)))/(10**i)) return ret a=int(input()) if a%n(a)==0: print('Yes') else: print('No')
s087369495
p04029
u731368968
2,000
262,144
Wrong Answer
18
2,940
44
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?
print(sum([i for i in range(int(input()))]))
s197121546
Accepted
17
2,940
46
print(sum([i+1 for i in range(int(input()))]))
s926318931
p03494
u439312138
2,000
262,144
Wrong Answer
17
3,064
290
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()) numList = list(map(int,input().split())) def numEvener(N,numList): for i in range(0,N-1): if numList[i] // 2 == 0: numList[i] = int(numList[i] / 2) else: numList[i] = 0 return numList while not 0 in numList: numList = numEvener(N,numList)
s371261732
Accepted
19
3,060
182
ans = 10**9 N = int(input()) A = list(map(int,input().split())) for i in A: p = 0 while i % 2 == 0: i //= 2 p += 1 if p < ans: ans = p print(ans)
s097141200
p03795
u409064224
2,000
262,144
Wrong Answer
17
2,940
39
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-200*n//15)
s320067579
Accepted
17
2,940
41
n = int(input()) print(n*800-200*(n//15))
s301204496
p03447
u031852574
2,000
262,144
Wrong Answer
25
9,136
12
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?
1234 150 100
s966132810
Accepted
27
9,084
62
x,a,b = [int(input()) for i in range(3)] print((x - a) % b)
s651750948
p04029
u287431190
2,000
262,144
Wrong Answer
17
2,940
62
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()) s = 0 for i in range(n): s = s + i print(s)
s518533788
Accepted
17
2,940
69
n = int(input()) s = 0 for i in range(n+1): s = s + i print(int(s))