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
s148699409
p02659
u181719868
2,000
1,048,576
Wrong Answer
19
9,172
110
Compute A \times B, truncate its fractional part, and print the result as an integer.
a, b = input().strip().split() a, b = [int(a), float(b)] b = b*100 + 0.000000001 print(b) print(a*int(b)//100)
s226446227
Accepted
21
9,160
102
a, b = input().strip().split() a, b = [int(a), float(b)] b = b*100 + 0.000000001 print(a*int(b)//100)
s624865059
p03387
u062189367
2,000
262,144
Wrong Answer
17
2,940
147
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
X = list(map(int, input().split())) M = max(X) if 3*M %2 == sum(X)%2: N = (3*M-sum(X))/2 else: N = (3*(M+1)-sum(X))/2 print(N)
s343835015
Accepted
17
2,940
152
X = list(map(int, input().split())) M = max(X) if 3*M %2 == sum(X)%2: N = (3*M-sum(X))/2 else: N = (3*(M+1)-sum(X))/2 print(int(N))
s807141627
p02601
u265323413
2,000
1,048,576
Wrong Answer
34
9,188
369
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
l = list(map(int, input().split())) K = int(input()) def check(nums): if nums[0] < nums[1]: if nums[1] < nums[2]: print('yes') exit(0) check(l) for i in range(K): if l[0] > l[1]: l[1] *= 2 check(l) continue elif l[1] > l[2]: l[2] *= 2 check(l) continue print('no') exit(0)
s860558482
Accepted
28
9,192
371
l = list(map(int, input().split())) K = int(input()) def check(nums): if nums[0] < nums[1]: if nums[1] < nums[2]: print('Yes') exit(0) check(l) for i in range(K): if l[0] >= l[1]: l[1] *= 2 check(l) continue elif l[1] >= l[2]: l[2] *= 2 check(l) continue print('No') exit(0)
s351369571
p02927
u946969297
2,000
1,048,576
Wrong Answer
23
2,940
197
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
M, D = map(int,input().split()) c=0 for m in range(1,M+1): for d in range(1,D+1): if d>=10: t=str(d) if int(t[0])*int(t[1]) == m: c+=1 print(c)
s071819116
Accepted
26
3,060
266
# coding: utf-8 # Your code here! M, D = map(int,input().split()) c=0 for m in range(1,M+1): for d in range(1,D+1): if d>=10: t=str(d) if int(t[0])>1 and int(t[1])>1 and int(t[0])*int(t[1]) == m: c+=1 print(c)
s707555980
p03997
u333731247
2,000
262,144
Wrong Answer
18
2,940
64
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h*0.5)
s176590500
Accepted
17
2,940
69
a=int(input()) b=int(input()) h=int(input()) print(int((a+b)*h*0.5))
s267532440
p02690
u034128150
2,000
1,048,576
Wrong Answer
2,205
9,856
429
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
X = int(input()) memo = [] A = 0 while True: A += 1 A5 = A ** 5 memo.append(A5) if A5 > X: try: i = memo.index(A5 - X) except ValueError: continue else: B = i break else: try: i = memo.index(X - A5) except ValueError: continue else: B = -i break print(A, B)
s361273015
Accepted
22
9,196
424
X = int(input()) memo = [] A = -1 while True: A += 1 A5 = A ** 5 memo.append(A5) if A5 > X: try: i = memo.index(A5 - X) except ValueError: continue else: B = i break else: try: i = memo.index(X - A5) except ValueError: continue else: B = -i break print(A, B)
s350388996
p03149
u966311314
2,000
1,048,576
Wrong Answer
17
3,060
382
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,b,c,d=[int(n) for n in input().split(' ')] N = [1, 9, 7, 4] if a not in N: print("No") else: N.remove(a) if b not in N: print("No") else: N.remove(b) if c not in N: print("No") else: N.remove(c) if d not in N: print("Np") else: print("Yes")
s120597364
Accepted
17
2,940
118
N =[int(n) for n in input().split(' ')] M = [1, 9, 7, 4] if set(N)==set(M): print("YES") else: print("NO")
s710377733
p02408
u180914582
1,000
131,072
Wrong Answer
30
6,716
224
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
cards = { 'S': [0 for _ in range(13)], 'H': [0 for _ in range(13)], 'C': [0 for _ in range(13)], 'D': [0 for _ in range(13)], } n = int(input()) for _ in range(n): (s, r) = input().split()
s725018557
Accepted
20
7,708
412
cards = { 'S': [0 for _ in range(13)], 'H': [0 for _ in range(13)], 'C': [0 for _ in range(13)], 'D': [0 for _ in range(13)], } n = int(input()) for _ in range(n): (s, r) = input().split() r = int(r) cards[s][r - 1] = r for s in ('S', 'H', 'C', 'D'): for r in range(13): if cards[s][r] == 0: print( '{0:s} {1:d}'.format(s, r+1))
s831250541
p03605
u898967808
2,000
262,144
Wrong Answer
17
2,940
65
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() print('Yes') if (n[0]==9 or n[1]==9) else print('No')
s926911340
Accepted
18
2,940
69
n = input() print('Yes') if (n[0]=='9' or n[1]=='9') else print('No')
s073214044
p02865
u185935459
2,000
1,048,576
Wrong Answer
149
2,940
110
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
N = int(input()) count = 0 for i in range(1,int(N/2)+1): if i + N-i == N: count+=1 print(count)
s199673776
Accepted
111
2,940
211
N = int(input()) count = 0 if N % 2 == 0: for i in range(1,int(N/2)): if i != N-i: count+=1 else: for i in range(1,int(N/2)+1): if i != N: count+=1 print(count)
s452366740
p03095
u920204936
2,000
1,048,576
Wrong Answer
33
5,664
179
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order.
import collections line = int(input()) string = list(input()) print(string) data = collections.Counter(string) sum = 1 for word in data: sum *= (data[word] + 1) print(sum - 1)
s522558992
Accepted
28
4,340
212
# coding: utf-8 import collections line = int(input()) string = list(input()) data = collections.Counter(string) sum = 1 for word in data: sum *= (data[word] + 1) answer = (sum - 1)%(10**9 + 7) print(answer)
s955481282
p02263
u637322311
1,000
131,072
Wrong Answer
30
5,556
457
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
def is_operator(ele): if ele == "+" or ele == "-" or ele == "*": return True else: return False def calc_reverse_polish_notation(A): stack = [] for i in A: if is_operator(i): a = stack.pop() b = stack.pop() ans = eval("{0} {1} {2}".format(b, i, a)) stack.append(ans) else: stack.append(i) return stack.pop() A = list(map(str,input().split()))
s227151912
Accepted
20
5,564
497
def is_operator(ele): if ele == "+" or ele == "-" or ele == "*": return True else: return False def calc_reverse_polish_notation(A): stack = [] for i in A: if is_operator(i): a = stack.pop() b = stack.pop() ans = eval("{0} {1} {2}".format(b, i, a)) stack.append(ans) else: stack.append(i) return stack.pop() A = list(map(str,input().split())) print(calc_reverse_polish_notation(A))
s544183134
p03478
u034369223
2,000
262,144
Wrong Answer
58
3,368
271
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(' ')) total = 0 for num in range(1,n+1): split_nums = [int(s) for s in list(str(num))] sum = 0 for s in split_nums: sum += s if a <= sum and sum <= b: print(split_nums, sum) total += num print(total)
s626195763
Accepted
39
3,060
240
n, a, b = map(int,input().split(' ')) total = 0 for num in range(1,n+1): split_nums = [int(s) for s in list(str(num))] sum = 0 for s in split_nums: sum += s if a <= sum and sum <= b: total += num print(total)
s511793852
p03434
u418826171
2,000
262,144
Wrong Answer
29
9,168
91
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 = sorted(list(map(int,input().split()))) print(sum(a[::2])-sum(a[1::2]))
s367915473
Accepted
27
9,160
186
N = int(input()) A = sorted(list(map(int,input().split())), reverse = True) a = 0 b = 0 for i in range(len(A)): if i%2 == 0: a += A[i] else: b += A[i] print(a-b)
s798921065
p03385
u540698208
2,000
262,144
Wrong Answer
17
2,940
113
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
def main(): s = sorted(input()) print('Yes' if s=='abc' else 'No') if __name__ == '__main__': main()
s565845895
Accepted
17
2,940
121
def main(): s = sorted(input()) print('Yes' if s==['a','b','c'] else 'No') if __name__ == '__main__': main()
s950159898
p02255
u939814144
1,000
131,072
Wrong Answer
30
7,500
657
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 insertion_sort(array, element_number): for i in range(1, element_number): v = array[i] j = i - 1 while(j>=0 and array[j] > v): array[j+1] = array[j] j = j - 1 array[j+1] = v for k in range(0, element_number): if k < element_number: print(array[k] + ' ', end='') else: print(array[k], end='') if i < element_number-1: print('\n', end='') def test(): element_number = int(input()) input_array = input().split() insertion_sort(input_array, element_number) if __name__ == '__main__': test()
s366757655
Accepted
20
7,708
421
def insertion_sort(array): for i in range(len(array)): v = array[i] j = i - 1 while(j>=0 and array[j] > v): array[j+1] = array[j] j = j - 1 array[j+1] = v print(' '.join(map(str, array))) return array if __name__ == '__main__': element_number = int(input()) input_array = list(map(int, input().split())) insertion_sort(input_array)
s614640395
p03730
u891847179
2,000
262,144
Wrong Answer
17
2,940
199
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A, B, C = list(map(int, input().split())) flag = False for i in range(1, B + 1): remainder = A * i % B if remainder == C: flag = True if flag: print("Yes") else: print("No")
s614662087
Accepted
28
9,152
96
import math A,B,C = map(int,input().split()) print('YES' if C % math.gcd(A,B) == 0 else 'NO')
s966228267
p02678
u426175055
2,000
1,048,576
Wrong Answer
1,242
47,924
535
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
from collections import defaultdict import queue N,M = map(int,input().split()) guide = {} room = defaultdict(list) for i in range(M): a,b = map(int,input().split()) room[a].append(b) room[b].append(a) print(room) q = queue.Queue() for i in room[1]: q.put(i) guide[i] = 1 while not(q.empty()): x = q.get() for i in room[x]: if i not in guide: guide[i]=x q.put(i) for i in range(2,N+1): print(guide[i])
s253526217
Accepted
1,089
47,796
531
from collections import defaultdict import queue N,M = map(int,input().split()) guide = {} room = defaultdict(list) for i in range(M): a,b = map(int,input().split()) room[a].append(b) room[b].append(a) q = queue.Queue() for i in room[1]: q.put(i) guide[i] = 1 while not(q.empty()): x = q.get() for i in room[x]: if i not in guide: guide[i]=x q.put(i) if len(guide) != N: print("No") else: print("Yes") for i in range(2,N+1): print(guide[i])
s482964089
p03493
u414050834
2,000
262,144
Wrong Answer
17
2,940
78
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
s = input() count = 0 for i in range(3): if s==1: count= count + 1
s499618216
Accepted
17
2,940
86
a = input() c=0 for i in range(len(a)): if a[i] == '1': c = c + 1 print(c)
s487294783
p03578
u233747425
2,000
262,144
Wrong Answer
2,105
35,556
348
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())) cou = 0 if N >= M: for i in range(M): if T[i] in D: D.remove(T[i]) cou += 1 else: x = 'No' break if cou == M: x = 'Yes' else: x = 'No' print(x)
s960153092
Accepted
398
56,672
811
N = int(input()) D = list(map(int, input().split())) M = int(input()) T = list(map(int, input().split())) D_dic = {k: 0 for k in D} T_dic = {k: 0 for k in T} for i in range(N): d = D[i] if D_dic[d]: a = D_dic[d] + 1 D_dic[d] = a else: D_dic[d] = 1 for j in range(M): t = T[j] if T_dic[t]: b = T_dic[t] + 1 T_dic[t] = b else: T_dic[t] = 1 cou = 0 if N >= M: for k in range(M): tk = T[k] try: if D_dic[tk]: c = D_dic[tk] - 1 D_dic[tk] = c cou += 1 else: x = 'NO' break except KeyError: x = 'NO' break if cou == M: x = 'YES' else: x = 'NO' print(x)
s091991145
p02690
u058496530
2,000
1,048,576
Wrong Answer
23
9,196
284
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
x = int(input()) y = [] count = 0 for i in range(0, 70): y.append(i*i*i*i*i) for i in y: count += 1 for j in y[:count]: y2 = i + j y3 = i - j if y2 == x: print(str(i) + " " + str(j)) break; if y3 == x: print(str(i) + " -" + str(j)) break;
s099140926
Accepted
25
9,104
507
x = int(input()) y = [] count1 = 0 flag = 0 for i in range(0, 130): y.append(i*i*i*i*i) for i in y: if i == x: print("0 -" + str(count1)) flag = 1 break; count1 += 1 count1 = 0 for i in y: if flag == 1: break; count2 = 0 for j in y[:count1]: y2 = i + j y3 = i - j if y2 == x: print(str(count1) + " -" + str(count2)) flag = 1 break; if y3 == x: print(str(count1) + " " + str(count2)) flag = 1 break; count2 +=1 count1 += 1
s504577891
p03711
u686036872
2,000
262,144
Wrong Answer
17
3,060
189
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
x, y = map(int, input().split()) A=[1, 3, 5, 7, 8, 10, 12] B=[4, 6, 9, 11] C=[2] if (x in A and y in A) or (x in B and y in B) or (x in C and y in C): print("YES") else: print("NO")
s126920883
Accepted
17
2,940
119
A={1, 3, 5, 7, 8, 10, 12} B={4, 6, 9, 11} x = set(map(int, input().split())) print("Yes" if x <= A or x <= B else "No")
s998814547
p03448
u088488125
2,000
262,144
Wrong Answer
29
9,112
188
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()) x_dash=x//50 cnt=0 for i in range(1,a+1): for j in range(1,b+1): k=x_dash-10*i-2*j if 0<=k<=c: cnt+=1 print(cnt)
s344105730
Accepted
26
9,172
188
a=int(input()) b=int(input()) c=int(input()) x=int(input()) x_dash=x//50 cnt=0 for i in range(0,a+1): for j in range(0,b+1): k=x_dash-10*i-2*j if 0<=k<=c: cnt+=1 print(cnt)
s308634618
p03386
u350997995
2,000
262,144
Wrong Answer
2,235
3,956
117
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()) S = [i for i in range(A,B+1)] S = S[:K]+S[len(S)-K:] S = set(S) for s in S: print(s)
s073371606
Accepted
17
3,060
175
A,B,K = map(int,input().split()) if 2*K<B-A+1: S = [i for i in range(A,A+K)]+[i for i in range(B-K+1,B+1)] else: S = [i for i in range(A,B+1)] for s in S: print(s)
s658176463
p03486
u221345507
2,000
262,144
Wrong Answer
19
3,064
834
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=list(str(input())) t=list(str(input())) alphabet=['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'] for i in range (len(s)): for j in range (len(alphabet)): if s[i]==alphabet[j]: s[i]=j for i in range (len(t)): for j in range (len(alphabet)): if t[i]==alphabet[j]: t[i]=j if len(s)>len(t): lst=[-1]*(len(s)-len(t)) t=t+lst if len(t)>len(s): lst=[-1]*(len(t)-len(s)) s=s+lst import sys for i in range (len(s)): if min(s)<max(t): print ('Yes') print(s) print(t) sys.exit() elif min(s)>max(t): print ('No') print(s) print(t) sys.exit() else: if min(s)==max(t): s.remove(min(s)) t.remove(max(t)) print ('No')
s030038267
Accepted
19
2,940
108
s=list(input()) t=list(input()) s.sort() t.sort(reverse=True) if s<t: print('Yes') else: print('No')
s561468799
p03997
u595716769
2,000
262,144
Wrong Answer
17
3,064
490
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
import itertools num = str(input()) olist = [int(i+1) for i in range(len(num)-1)] comblist = [] for i, _ in enumerate(olist, 1): for j in itertools.combinations(olist, r=i): comblist.append(j) L = [] for i in range(len(comblist)): t = num for j in range(len(comblist[i])): t = t[0:comblist[i][j]+j] + "," + t[comblist[i][j]+j:] L.append(t) out = 0 for i in range(len(L)): t = L[i].split(",") for j in range(len(t)): out += int(t[j]) print(out+int(num))
s004145649
Accepted
17
2,940
69
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s310297094
p03944
u927870520
2,000
262,144
Wrong Answer
150
27,252
338
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.
import numpy as np W,H,N=map(int,input().split()) A=np.zeros((W,H)) B=[list(map(int,input().split())) for _ in range(N)] print(B) for b in B: if b[2]==1: A[:b[0],:]=1 elif b[2]==2: A[b[0]:,:]=1 elif b[2]==3: A[:,:b[1]]=1 elif b[2]==4: A[:,b[1]:]=1 print(A) print(np.count_nonzero(A==0))
s673757909
Accepted
116
27,240
316
import numpy as np W,H,N=map(int,input().split()) A=np.zeros((W,H)) B=[list(map(int,input().split())) for _ in range(N)] for b in B: if b[2]==1: A[:b[0],:]=1 elif b[2]==2: A[b[0]:,:]=1 elif b[2]==3: A[:,:b[1]]=1 elif b[2]==4: A[:,b[1]:]=1 print(np.count_nonzero(A==0))
s246541079
p00115
u300645821
1,000
131,072
Wrong Answer
70
14,776
958
恒星歴 2005.11.5。あなたは宇宙船 UAZ アドバンス号の艦長として敵の宇宙船と交戦しようとしています。 幸い敵の宇宙船はまだこちらに気付かずに静止しています。また、すでに敵の宇宙座標は判明しており強力な直線のビームを放つ「フェザー砲」は発射準備を完了しています。あとは、発射命令を出すばかりです。 ところが、宇宙空間には、敵の設置したエネルギーバリアが存在しています。バリアは三角形をしており「フェザー砲」のビームをはね返してしまいます。また、ビームがバリアに当たれば敵に気付かれて逃げられてしまいます。事前に命中すると判定できなければ、発射命令は出せません。 そこで、UAZ アドバンス号、敵、バリアの位置の宇宙座標(3次元座標 x, y, z) を入力して、ビームがバリアをさけて敵に命中する場合は "HIT"、バリアに当たってしまう場合"MISS"と出力するプログラムを作成してください。 ただし、バリアはアドバンス号から 3 角形に見えるものだけが対象であり、線分につぶれて見えるものはないものとします。また、バリアは 3 角形の頂点を含む境界でも有効であり、ビームをはね返すものとします。また、敵がバリア内にいる場合は"MISS"と出力して下さい。
#!/usr/bin/python from fractions import Fraction import sys if sys.version_info[0]>=3: raw_input=input def gauss(a): if not a or len(a)==0: return None n=len(a) for i in range(n): if a[i][i]==0: for j in range(i+1,n): if a[j][i]!=0: for k in range(i,n+1): a[i][k]+=a[j][k] break else: return None for j in range(n): if i!=j: r = Fraction(a[j][i],a[i][i]) for k in range(i,n+1): a[j][k] = a[j][k] - a[i][k]*r for i in range(n): x=Fraction(a[i][i],1) for j in range(len(a[i])): a[i][j] /= x return a uaz=map(int,raw_input().split()) enemy=[0]+[-x+y for x,y in zip(map(int,raw_input().split()),uaz)] b0=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)] b1=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)] b2=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)] sol=gauss(list(map(list,zip(b0,b1,b2,enemy,[1,0,0,0])))) print('MISS' if sol and all(0<=e[-1]<=1 for e in sol) else 'HIT')
s210168187
Accepted
70
14,776
964
#!/usr/bin/python from fractions import Fraction import sys if sys.version_info[0]>=3: raw_input=input def gauss(a): if not a or len(a)==0: return None n=len(a) for i in range(n): if a[i][i]==0: for j in range(i+1,n): if a[j][i]!=0: for k in range(i,n+1): a[i][k]+=a[j][k] break else: return None for j in range(n): if i!=j: r = Fraction(a[j][i],a[i][i]) for k in range(i,n+1): a[j][k] = a[j][k] - a[i][k]*r for i in range(n): x=Fraction(a[i][i],1) for j in range(len(a[i])): a[i][j] /= x return a uaz=list(map(int,raw_input().split())) enemy=[0]+[-x+y for x,y in zip(map(int,raw_input().split()),uaz)] b0=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)] b1=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)] b2=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)] sol=gauss(list(map(list,zip(b0,b1,b2,enemy,[1,0,0,0])))) print('MISS' if sol and all(0<=e[-1]<=1 for e in sol) else 'HIT')
s223291825
p03471
u308588791
2,000
262,144
Wrong Answer
2,108
3,064
574
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.
input_list = list(input().split()) bill_num = int(input_list[0]) total_price = int(input_list[1]) yen_10000 = 10000 yen_5000 = 5000 yen_1000 = 1000 bill_num_list = [] for i in range(bill_num): for j in range(bill_num): for k in range(bill_num): if total_price == (i+1) * yen_10000 + (j+1) * yen_5000 + (k+1) * yen_1000: bill_num_list = [i+1, j+1, k+1] bill_num_list_str = list(map(str, bill_num_list)) break if bill_num_list == []: print('-1 -1 -1') else: print(' '.join(bill_num_list_str))
s667786482
Accepted
1,556
3,064
627
input_list = list(input().split()) bill_num = int(input_list[0]) total_price = int(input_list[1]) yen_10000 = 10000 yen_5000 = 5000 yen_1000 = 1000 bill_num_list = [] for i in range(bill_num + 1): for j in range(bill_num - i + 1): k = 0 k = bill_num - i - j total = i * yen_10000 + j * yen_5000 + k * yen_1000 if (i + j + k == bill_num) and (k >= 0) and (total == total_price): bill_num_list = [i, j, k] bill_num_list_str = list(map(str, bill_num_list)) break if bill_num_list == []: print('-1 -1 -1') else: print(' '.join(bill_num_list_str))
s672715699
p03385
u474925961
2,000
262,144
Wrong Answer
18
2,940
140
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
import sys if sys.platform =='ios': sys.stdin=open('input_file.txt') S=input() if sorted(S)=="abc": print("Yes") else: print("No")
s694683304
Accepted
18
2,940
149
import sys if sys.platform =='ios': sys.stdin=open('input_file.txt') S=input() if sorted(S)==["a","b","c"]: print("Yes") else: print("No")
s582413000
p03672
u729119068
2,000
262,144
Wrong Answer
27
9,104
134
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= [i for i in input()] while True: A.pop() A.pop() B=len(A)//2 if A[:B]==A[B+1:]: print(len(A)) break
s876998212
Accepted
29
9,100
125
A= list(input()) while True: A.pop() A.pop() B=len(A)//2 if A[:B]==A[B:]: print(len(A)) break
s958941927
p03564
u923659712
2,000
262,144
Wrong Answer
17
2,940
123
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
n=int(input()) k=int(input()) ans=1 j=0 while ans<k or j<n: ans*=2 j+=1 if j<n: print(ans+k*(n-j)) else: print(ans)
s071452609
Accepted
17
3,060
124
n=int(input()) k=int(input()) ans=1 j=0 while ans<k and j<n: ans*=2 j+=1 if j<n: print(ans+k*(n-j)) else: print(ans)
s245659539
p04029
u127856129
2,000
262,144
Wrong Answer
17
2,940
50
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?
a=int(input()) b=a while b==0: a+=a-1 b-=1
s238917579
Accepted
17
2,940
63
a=int(input()) c=0 while a>=0: c+=a a=a-1 print(int(c))
s742167322
p04043
u848647227
2,000
262,144
Wrong Answer
17
2,940
159
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.
ar = input().split(" ") f = 0 s = 0 for a in ar: if a == "5": f += 1 elif a == "7": s += 1 if f == 5 and s == 1: print("YES") else: print("NO")
s986110086
Accepted
16
2,940
160
ar = input().split(" ") f = 0 s = 0 for a in ar: if a == "5": f += 1 elif a == "7": s += 1 if f == 2 and s == 1: print("YES") else: print("NO")
s452262139
p02607
u668503853
2,000
1,048,576
Wrong Answer
35
9,096
121
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
N=int(input()) A=list(map(int,input().split())) ans=0 for i in range(N): if i%2==0 and A[i]%2==0: ans+=1 print(ans)
s153287542
Accepted
27
9,088
122
N=int(input()) A=list(map(int,input().split())) ans=0 for i in range(N): if i%2==0 and A[i]%2==1: ans+=1 print(ans)
s103624836
p03605
u756988562
2,000
262,144
Wrong Answer
17
2,940
93
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() # print(N.find("9")) if N.find("9") != -1: print("Yse") else: print("No")
s953068310
Accepted
17
2,940
72
N = input() if N.find("9") != -1: print("Yes") else: print("No")
s092050398
p03080
u754022296
2,000
1,048,576
Wrong Answer
17
2,940
78
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
s = input() if s.count("R") > s.count("B"): print("Yes") else: print("No")
s656733610
Accepted
17
2,940
96
n = int(input()) s = input() if s.count("R") > s.count("B"): print("Yes") else: print("No")
s476881730
p03303
u923270446
2,000
1,048,576
Wrong Answer
19
3,316
145
You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
s = list(input()) w = int(input()) index = 0 l = [] while index <= len(s) - 1: print(index) l.append(s[index]) index += w print(*l, sep="")
s950096218
Accepted
17
3,188
130
s = list(input()) w = int(input()) index = 0 l = [] while index <= len(s) - 1: l.append(s[index]) index += w print(*l, sep="")
s106434850
p03565
u673361376
2,000
262,144
Wrong Answer
17
3,060
378
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
S = input() T = input() lenS = len(S) lenT = len(T) for i in range(lenS - lenT, -1, -1): flag = True for ii in range(lenT): if S[i+ii] == '?' or S[i+ii] == T[ii]: continue else: flag = False break if flag == True: print((S[:ii] + T + S[ii + lenT:]).replace('?', 'a')) exit() print('UNRESTORABLE')
s105418727
Accepted
17
3,064
558
def is_possible(start_i): for i in range(lenT): if S[start_i + i] != '?' and S[start_i + i] != T[i]: return False return True if __name__ == '__main__': S = input() T = input() lenS = len(S) lenT = len(T) tmp_i = None for i in range(lenS): if i + lenT > lenS: break else: if is_possible(i): tmp_i = i if tmp_i is None: print('UNRESTORABLE') else: print(S[:tmp_i].replace('?', 'a') + T + S[tmp_i + lenT:].replace('?', 'a'))
s606295094
p02741
u386944085
2,000
1,048,576
Wrong Answer
18
3,060
247
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
a = int(input()) if a%2==0 and (a!=25 or a!=27): print(1) elif a==32: print(51) elif a==24: print(15) elif a==16: print(14) elif a==28 or a==30: print(4) elif (a!=4 and a%4==0) or a==18 or a==27: print(5) else: print(2)
s450369327
Accepted
17
3,064
277
a = int(input()) if (a%2==1 and (a!=25 and a!=27 and a!=9 and a!=21)) or a==2: print(1) elif a==32: print(51) elif a==24: print(15) elif a==16: print(14) elif a==28 or a==30: print(4) elif (a!=4 and a%4==0) or a==18 or a==27: print(5) else: print(2)
s201628865
p03564
u957198490
2,000
262,144
Wrong Answer
18
3,064
98
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
N = int(input()) K = int(input()) ans = 1 for i in range(N): ans = min(ans+K,2*ans) print(min)
s586971185
Accepted
17
2,940
98
N = int(input()) K = int(input()) ans = 1 for i in range(N): ans = min(ans+K,2*ans) print(ans)
s300253588
p03352
u384679440
2,000
1,048,576
Wrong Answer
17
2,940
145
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.
X = int(input()) ans = 0 if X == 1: ans = 1 else: for b in range(1, 32): for p in range(2, 11): ans = max(ans, pow(b, p)) print(ans)
s375264900
Accepted
17
3,060
168
X = int(input()) ans = 1 if X > 1: for b in range(1, 32): for p in range(2, 11): if ans <= X and pow(b, p) <= X: ans = max(ans, pow(b, p)) print(ans)
s862398009
p02396
u019678978
1,000
131,072
Wrong Answer
20
7,356
117
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.
dataset = input().split("\n") c = 1 for i in dataset : print("Case " + str(c) + ":" + " " + str(i)) c = c + 1
s769361923
Accepted
60
7,960
179
import sys c = 1 for i in sys.stdin.readlines() : if i.strip() == "0" : break else : print("Case " + str(c) + ":" + " " + str(i.strip())) c = c + 1
s981878642
p02972
u665038048
2,000
1,048,576
Wrong Answer
217
13,568
225
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
n = int(input()) a = input() r = [None] * (n + 1) for i in range(n, 0, -1): r[i] = (ord(a[2 * i - 2]) + sum(r[i * 2::i])) % 2 ans = [] for i, x in enumerate(r): if x: ans.append(i) print(r.count(1)) print(ans)
s828291755
Accepted
235
12,028
189
n = int(input()) a = input() r = [None] * (n + 1) for i in range(n, 0, -1): r[i] = (ord(a[2 * i - 2]) + sum(r[i * 2::i])) % 2 print(r.count(1)) print(*(i for i, x in enumerate(r) if x))
s075612101
p04031
u298297089
2,000
262,144
Wrong Answer
22
3,060
173
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())) mn = 10**9 for i in range(N): cost = 0 for j in range(N): cost += (A[i]-A[j])**2 mn = min(cost, mn) print(mn)
s836977922
Accepted
24
2,940
215
n = int(input()) a = list(map(int, input().split())) ans = float('INF') for i in range(min(a), max(a)+1): cost = 0 for aa in a: cost += (i - aa)**2 if cost < ans : ans = cost print(ans)
s391730759
p03474
u379535139
2,000
262,144
Wrong Answer
17
3,060
256
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
A, B = tuple(int(num) for num in input().split()) S = input() s_list = list(S) for i, s in enumerate(s_list): if s_list[A] != '-': print('No') break if isinstance(s, int): continue else: print('No') break else: print('Yes')
s578597921
Accepted
18
3,060
278
A, B = tuple(int(num) for num in input().split()) S = input() s_list = list(S) for i, s in enumerate(s_list): if i == A: if s_list[A] != '-': print('No') break else: try: s = int(s) except: print('No') break else: print('Yes')
s158833321
p02383
u981139449
1,000
131,072
Wrong Answer
20
7,452
810
Write a program to simulate rolling a dice, which can be constructed by the following net. As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
class Dice: def __init__(self): self.top = 1 self.front = 2 self.left = 3 @property def bottom(self): return 7 - self.top @property def back(self): return 7 - self.front @property def right(self): return 7 - self.left def move(self, direction): if direction == 'N': bottom = self.bottom self.top = self.front self.front = bottom elif direction == 'W': right = self.right self.left = self.top self.top = right elif direction == 'E': bottom = self.bottom self.top = self.left self.left = bottom elif direction == 'S': back = self.back self.front = self.top self.top = back dice = Dice() numbers = input().split() for cmd in input(): dice.move(cmd) print(numbers[dice.top - 1])
s410676898
Accepted
20
7,544
857
class Dice: def __init__(self): self.top = 1 self.front = 2 self.left = 4 @property def bottom(self): return 7 - self.top @property def back(self): return 7 - self.front @property def right(self): return 7 - self.left def move(self, direction): if direction == 'N': bottom = self.bottom self.top = self.front self.front = bottom elif direction == 'W': right = self.right self.left = self.top self.top = right elif direction == 'E': bottom = self.bottom self.top = self.left self.left = bottom elif direction == 'S': back = self.back self.front = self.top self.top = back def __repr__(self): print(self.__dict__) dice = Dice() numbers = input().split() for cmd in input(): dice.move(cmd) print(numbers[dice.top - 1])
s370081771
p03473
u714587753
2,000
262,144
Wrong Answer
17
2,940
89
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
# Try AtCoder # author: Leonardone @ NEETSDKASU m = int(input()) ans = m + 24 print(ans)
s697034813
Accepted
18
2,940
95
# Try AtCoder # author: Leonardone @ NEETSDKASU m = int(input()) ans = 24 - m + 24 print(ans)
s539533811
p03863
u009460507
2,000
262,144
Wrong Answer
171
4,772
166
There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s. The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
line = list(input()) count = 0 for i, s in enumerate(line[0:-2]): if line[i] == line[i+2]: count+=1 if count % 2 == 0: print("Second") else: print("First")
s183371648
Accepted
26
4,084
195
line = list(input()) if line[0] == line[-1]: if len(line) % 2 == 0: print("First") else: print("Second") else: if len(line) % 2 == 0: print("Second") else: print("First")
s296743179
p02385
u617472286
1,000
131,072
Wrong Answer
20
7,744
2,005
Write a program which reads the two dices constructed in the same way as [Dice I](description.jsp?id=ITP1_11_A), and determines whether these two dices are identical. You can roll a dice in the same way as [Dice I](description.jsp?id=ITP1_11_A), and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
class Dice(object): def __init__(self, line): self.top = 1 self.bottom = 6 self.south = 2 self.east = 3 self.west = 4 self.north = 5 self.convert = [int(s) for s in line.split()] def move(self, direction): if 'N' == direction: self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom elif 'S' == direction: self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top elif 'W' == direction: self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top elif 'E' == direction: self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom def rv(self, key): index_list = { 'top' : self.top, 'bottom' : self.bottom, 'south' : self.south, 'east' : self.east, 'west' : self.west, 'notrh' : self.north } return self.convert[index_list[key] - 1] def search(self, dice): for direction in 'NNNNWNNNN': self.move(direction) if self.rv('south') == dice.rv('south'): break if self.rv('south') != dice.rv('south') or self.rv('notrh') != dice.rv('notrh'): return 'No' for direction in 'WWWW': self.move(direction) if self.rv('top') == dice.rv('top'): break if self.rv('top') != dice.rv('top'): return 'No' if self.rv('bottom') != dice.rv('bottom'): return 'No' if self.rv('east') != dice.rv('east'): return 'No' if self.rv('notrh') != dice.rv('notrh'): return 'No' return 'Yes' dice = Dice('1 2 3 4 5 6') dice2 = Dice('6 5 4 3 2 1') print(dice.search(dice2))
s904341754
Accepted
50
7,900
1,993
class Dice(object): def __init__(self, line): self.top = 1 self.bottom = 6 self.south = 2 self.east = 3 self.west = 4 self.north = 5 self.convert = [int(s) for s in line.split()] def move(self, direction): if 'N' == direction: self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom elif 'S' == direction: self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top elif 'W' == direction: self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top elif 'E' == direction: self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom def rv(self, key): index_list = { 'top' : self.top, 'bottom' : self.bottom, 'south' : self.south, 'east' : self.east, 'west' : self.west, 'notrh' : self.north } return self.convert[index_list[key] - 1] def search(self, dice): for direction in 'NNNNWNNNN': self.move(direction) if self.rv('south') == dice.rv('south'): break if self.rv('south') != dice.rv('south') or self.rv('notrh') != dice.rv('notrh'): return 'No' for direction in 'WWWW': self.move(direction) if self.rv('top') == dice.rv('top'): break if self.rv('top') != dice.rv('top'): return 'No' if self.rv('bottom') != dice.rv('bottom'): return 'No' if self.rv('east') != dice.rv('east'): return 'No' if self.rv('notrh') != dice.rv('notrh'): return 'No' return 'Yes' dice = Dice(input()) dice2 = Dice(input()) print(dice.search(dice2))
s219043578
p03474
u699522269
2,000
262,144
Wrong Answer
31
9,132
104
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
a,b = map(int,input().split()) s = input() print("Yes" if s[:a].isdigit() and s[a:].isdigit() else "No")
s689455340
Accepted
28
9,148
120
a,b = map(int,input().split()) s = input() print("Yes" if s[:a].isdigit() and s[a+1:].isdigit() and s[a]=="-" else "No")
s292286873
p03470
u520499660
2,000
262,144
Wrong Answer
18
2,940
67
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?
s = input().split() s_set = set(s) length = len(s) print(length)
s249922377
Accepted
17
2,940
159
N = int(input()) s = [input() for i in range(N)] s_set = set(s) l = len(s_set) print(l)
s818555372
p02256
u027874809
1,000
131,072
Wrong Answer
20
5,592
231
Write a program which finds the greatest common divisor of two natural numbers _a_ and _b_
alllist = list(map(int, input().split())) alllist = sorted(alllist, reverse=True) def maxsize(a, b): if a % b == 0: return a // b return maxsize(b, a % b) result = maxsize(alllist[0], alllist[1]) print(result)
s800806644
Accepted
20
5,600
202
def gcd(a, b): if b == 0: return a return gcd(b, a % b) alllist = list(map(int, input().split())) alllist = sorted(alllist, reverse=True) result = gcd(alllist[0], alllist[1]) print(result)
s579857577
p03494
u504256702
2,000
262,144
Wrong Answer
17
2,940
101
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(input().split()) print(list(map(lambda x: int(x) % 2 == 0, A)).count(True))
s602369998
Accepted
19
3,060
159
N = int(input()) A = list(map(int,input().split())) for i in range(1, max(A)): if not all(list(map(lambda x: x % 2**i == 0, A))): print(i - 1) break
s653483552
p02612
u349301655
2,000
1,048,576
Wrong Answer
29
9,140
41
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 = 1000 - N print(A)
s065321056
Accepted
24
9,064
104
N = int(input()) if N % 1000 == 0: a = N else: a = (N // 1000 + 1) * 1000 A = a - N print(A)
s791970557
p03399
u623601489
2,000
262,144
Wrong Answer
17
3,064
100
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
a1=int(input());a2=int(input());b1=int(input());b2=int(input()) print([a1,a2][a1<a2]+[b1,b2][b1<b2])
s504693314
Accepted
17
2,940
100
a1=int(input());a2=int(input());b1=int(input());b2=int(input()) print([a1,a2][a1>a2]+[b1,b2][b1>b2])
s643469008
p03574
u266874640
2,000
262,144
Wrong Answer
29
3,828
657
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()) dx = [1,1,1,0,-1,-1,-1,0] dy = [0,1,-1,1,0,1,-1,-1] ans = [[0] * (w + 2) for _ in range(h + 2)] s = [input() for _ in range(h)] for i in range(h): s[i] = '.' + s[i] + '.' s = ['.' * (w + 2)] + s + ['.' * (w + 2)] for i in range(1, h+1): for j in range(1, w+1): if s[i][j] == '.': for A in range(8): if(s[i + dy[A]][j + dx[A]]=='#'): ans[i][j] += 1 print(ans[i][j]) for i in range(1, h+1): for j in range(1, w+1): if s[i][j] == '.': print(ans[i][j],end='') else: print('#',end='') print()
s584923169
Accepted
27
3,444
633
h, w = map(int,input().split()) dx = [1,1,1,0,-1,-1,-1,0] dy = [0,1,-1,1,0,1,-1,-1] ans = [[0] * (w + 2) for _ in range(h + 2)] s = [input() for _ in range(h)] for i in range(h): s[i] = '.' + s[i] + '.' s = ['.' * (w + 2)] + s + ['.' * (w + 2)] for i in range(1, h+1): for j in range(1, w+1): if s[i][j] == '.': for A in range(8): if(s[i + dy[A]][j + dx[A]]=='#'): ans[i][j] += 1 for i in range(1, h+1): for j in range(1, w+1): if s[i][j] == '.': print(ans[i][j],end='') else: print('#',end='') print()
s917530177
p03997
u131666536
2,000
262,144
Wrong Answer
17
2,940
71
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)/h))
s068566483
Accepted
16
2,940
73
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h/2))
s757391007
p03827
u072717685
2,000
262,144
Wrong Answer
17
2,940
158
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
n = int(input()) s = "" current_num = 0 max_num = 0 for c in s: current_num += 1 if c == 'I' else -1 max_num = max(max_num, current_num) print(max_num)
s343031759
Accepted
17
3,060
160
n = int(input()) s = input() current_num = 0 max_num = 0 for c in s: current_num += 1 if c == 'I' else -1 max_num = max(max_num, current_num) print(max_num)
s338421015
p04029
u759412327
2,000
262,144
Wrong Answer
17
2,940
33
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()) print(N*(N+1)/2)
s517701840
Accepted
27
9,076
34
N = int(input()) print(N*(N+1)//2)
s829069076
p03545
u311379832
2,000
262,144
Wrong Answer
24
3,444
885
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.
import sys from collections import defaultdict a = input() alst = [0, 1] blst = [0, 1] clst = [0, 1] ans = '' for i in alst: for j in blst: for k in clst: tmp = 0 ans = '' if i == 0: tmp = int(a[0]) + int(a[1]) ans = a[0] + '+' + a[1] else: tmp = int(a[0]) - int(a[1]) ans = a[0] + '-' + a[1] if j == 0: tmp = tmp + int(a[2]) ans = ans + '+' + a[2] else: tmp = tmp - int(a[2]) ans = ans + '-' + a[2] if k == 0: tmp = tmp + int(a[3]) ans = ans + '+' + a[3] else: tmp = tmp - int(a[3]) ans = ans + '-' + a[3] if tmp == 7: print(ans) sys.exit()
s609445727
Accepted
25
3,444
892
import sys from collections import defaultdict a = input() alst = [0, 1] blst = [0, 1] clst = [0, 1] ans = '' for i in alst: for j in blst: for k in clst: tmp = 0 ans = '' if i == 0: tmp = int(a[0]) + int(a[1]) ans = a[0] + '+' + a[1] else: tmp = int(a[0]) - int(a[1]) ans = a[0] + '-' + a[1] if j == 0: tmp = tmp + int(a[2]) ans = ans + '+' + a[2] else: tmp = tmp - int(a[2]) ans = ans + '-' + a[2] if k == 0: tmp = tmp + int(a[3]) ans = ans + '+' + a[3] else: tmp = tmp - int(a[3]) ans = ans + '-' + a[3] if tmp == 7: print(ans + '=7') sys.exit()
s827462640
p03474
u598684283
2,000
262,144
Wrong Answer
29
9,176
192
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
a,b = map(int,input().split()) s = input() if s[a] == "-": s = s.replace("-","") print(s) if s.isdecimal(): print("Yes") else: print("No") else: print("No")
s074705187
Accepted
31
9,100
199
a,b = map(int,input().split()) s = input() if len(s) == a + b + 1 and s[a] == "-": s = s.replace("-","") if s.isdecimal() and len(s) == a + b: print("Yes") exit(0) print("No")
s508842651
p02694
u918817732
2,000
1,048,576
Wrong Answer
27
9,044
135
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import math X=int(input()) origin=100 count=0 while(origin<X): origin+=int(origin*0.01) print(origin) count+=1 print(count)
s337246194
Accepted
22
8,976
117
import math X=int(input()) origin=100 count=0 while(origin<X): origin+=int(origin*0.01) count+=1 print(count)
s574129129
p02409
u731896389
1,000
131,072
Wrong Answer
20
7,752
353
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] n = int(input()) for i in range(n): b,f,r,v = [int(i) for i in input().split()] data[b-1][f-1][r-1] += v for b in range(4): for f in range(3): for r in range(10): print(data[b][f][r],end="") print() if b < 3: print("#"*20)
s796106610
Accepted
30
7,700
348
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] n = int(input()) for i in range(n): b,f,r,v = [int(i) for i in input().split()] data[b-1][f-1][r-1] += v for b in range(4): for f in range(3): for r in range(10): print("",data[b][f][r],end="") print() if b < 3: print("#"*20)
s921440469
p03997
u071061942
2,000
262,144
Wrong Answer
18
2,940
86
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) ans = int(a * b * h / 2) print(ans)
s408827162
Accepted
17
2,940
89
a = int(input()) b = int(input()) h = int(input()) ans = int((a + b) * h / 2) print(ans)
s733457349
p03193
u185802209
2,000
1,048,576
Wrong Answer
17
2,940
85
There are N rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the i-th material are A_i \times B_i (A_i vertically and B_i horizontally). Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly H \times W. He is trying to obtain such a plate by choosing one of the N materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a 5 \times 3 material cannot be used as a 3 \times 5 plate. Out of the N materials, how many can produce an H \times W plate if properly cut?
n = input() c = 0 for i in range(len(n)): if n[i] == '2': c += 1 print(c)
s105019531
Accepted
22
3,316
145
n, h, w = map(int,input().split()) c = 0 for i in range(n): a, b = map(int,input().split()) if a >= h and b >= w: c += 1 print(c)
s354274737
p02612
u546236742
2,000
1,048,576
Wrong Answer
30
8,984
72
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
a = int(input()) if a % 1000 == 0: print("0") else: print(a % 1000)
s304848367
Accepted
27
9,016
79
a = int(input()) if a % 1000 == 0: print("0") else: print(1000 - a % 1000)
s126044874
p03227
u778814286
2,000
1,048,576
Wrong Answer
17
2,940
170
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
###template### import sys input = sys.stdin.readline def mi(): return map(int, input().split()) ###template### s = input() if len(s)==2: print(s) else: print(s[::-1])
s529575779
Accepted
17
2,940
179
###template### import sys input = sys.stdin.readline def mi(): return map(int, input().split()) ###template### s = input().rstrip() if len(s)==2: print(s) else: print(s[::-1])
s884952301
p03574
u140251125
2,000
262,144
Wrong Answer
24
3,572
1,065
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.
# input H, W = map(int, input().split()) S = [list(input()) for i in range(H)] for i in range(H): S[i] = ['.'] + S[i] + ['.'] S = [['.' for i in range(W + 2)]] + S + [['.' for i in range(W + 2)]] S_dummy = S for i in range(1, H + 1): for j in range(1, W + 1): if S[i][j] == '.': tmp = 0 if S[i - 1][j - 1] == '#': tmp += 1 if S[i - 1][j] == '#': tmp += 1 if S[i - 1][j + 1] == '#': tmp += 1 if S[i][j - 1] == '#': tmp += 1 if S[i][j + 1] == '#': tmp += 1 tmp += 1 if S[i + 1][j - 1] == '#': tmp += 1 if S[i + 1][j] == '#': tmp += 1 if S[i + 1][j + 1] == '#': tmp += 1 S_dummy[i][j] = tmp for i in range(1, H + 1): for j in range(1, W + 1): print(S_dummy[i][j], end = "") print('')
s770262164
Accepted
24
3,572
1,039
# input H, W = map(int, input().split()) S = [list(input()) for i in range(H)] for i in range(H): S[i] = ['.'] + S[i] + ['.'] S = [['.' for i in range(W + 2)]] + S + [['.' for i in range(W + 2)]] S_dummy = S for i in range(1, H + 1): for j in range(1, W + 1): if S[i][j] == '.': tmp = 0 if S[i - 1][j - 1] == '#': tmp += 1 if S[i - 1][j] == '#': tmp += 1 if S[i - 1][j + 1] == '#': tmp += 1 if S[i][j - 1] == '#': tmp += 1 if S[i][j + 1] == '#': tmp += 1 if S[i + 1][j - 1] == '#': tmp += 1 if S[i + 1][j] == '#': tmp += 1 if S[i + 1][j + 1] == '#': tmp += 1 S_dummy[i][j] = tmp for i in range(1, H + 1): for j in range(1, W + 1): print(S_dummy[i][j], end = "") print('')
s490491800
p03671
u744898490
2,000
262,144
Wrong Answer
17
3,064
471
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
abc = input().split(' ') abc =[ int(x) for x in abc] s= 0 min_ = min(abc) if abc[0] == abc[1] == abc[2] : print(abc[0] + abc[1]) elif (abc[0] == min_ and abc[1] == min_ or abc[0] == min_ and abc[2] == min_ or abc[2] == min_ and abc[1] == min_): for i in abc: if i != min_: s += i print(s + min_) else: for i in abc: if i != min(abc): s += i print(s)
s383875278
Accepted
17
3,060
306
abc = input().split(' ') max_ = max(abc) abc =[ int(x) for x in abc] s= 0 min_ = min(abc) if abc[0] == abc[1] == abc[2] : print(abc[0] + abc[1]) elif abc.count(max(abc)) == 2: print(max(abc) + min(abc)) else: for i in abc: if i != max(abc): s += i print(s)
s117999702
p03760
u580362735
2,000
262,144
Wrong Answer
17
3,060
121
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
O = list(input()) E = list(input()) ans = ['0']*(len(O)+len(E)) print(ans) ans[::2] = O ans[1::2] = E print(''.join(ans))
s123506731
Accepted
17
3,060
110
O = list(input()) E = list(input()) ans = ['0']*(len(O)+len(E)) ans[::2] = O ans[1::2] = E print(''.join(ans))
s203442992
p03543
u003928116
2,000
262,144
Wrong Answer
17
2,940
46
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
print("Yes" if int(input())%1111==0 else "No")
s409561440
Accepted
17
2,940
145
n=input() list=[] list.append(n[0:3]) list.append(n[1:4]) if len(set(list[0]))==1 or len(set(list[1]))==1: print("Yes") else: print("No")
s070111792
p03448
u368931345
2,000
262,144
Wrong Answer
53
3,064
492
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("500円玉の枚数:")) B = int(input("100円玉の枚数:")) C = int(input("50円玉の枚数:")) X = int(input("金額(50の倍数):")) if ((A+B+C<1) or (A<0 or A>50) or (B<0 or B>50) or (C<0 or C>50) or (X<50 or X > 20000 or X%50!=0)): print("条件を満たしてください") count = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): Y = i*500 + j*100 + k*50 if (X==Y): count = count+1 print (count)
s705668734
Accepted
53
3,064
408
A = int(input()) B = int(input()) C = int(input()) X = int(input()) if ((A+B+C<1) or (A<0 or A>50) or (B<0 or B>50) or (C<0 or C>50) or (X<50 or X > 20000 or X%50!=0)): print("条件を満たしてください") count = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): Y = i*500 + j*100 + k*50 if (X==Y): count = count+1 print (count)
s507814861
p02606
u084411645
2,000
1,048,576
Wrong Answer
28
9,144
53
How many multiples of d are there among the integers between L and R (inclusive)?
print(sum([int(i)%2 for i in input().split()[::2]]))
s620569202
Accepted
30
9,164
72
l, r, d = [int(i) for i in input().split(" ")] l -= 1 print(r//d - l//d)
s926041676
p03387
u820560680
2,000
262,144
Wrong Answer
17
2,940
194
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
X = sorted(list(map(int, input().split()))) if X[0] % 2 == X[1] % 2 == X[2] % 2: print((X[2] - X[0]) // 2 + (X[2] - X[1]) // 2) else: print((X[2] - X[0]) // 2 + (X[2] - X[1]) // 2 + 2)
s614648322
Accepted
17
3,064
276
X = sorted(list(map(int, input().split()))) if X[0] % 2 == X[1] % 2 == X[2] % 2: print((X[2] - X[0]) // 2 + (X[2] - X[1]) // 2) elif X[0] % 2 == X[1] % 2: print((X[2] - X[0]) // 2 + (X[2] - X[1]) // 2 + 1) else: print((X[2] - X[0]) // 2 + (X[2] - X[1]) // 2 + 2)
s692943060
p03141
u153094838
2,000
1,048,576
Wrong Answer
555
21,604
535
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end". Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
if __name__ == '__main__': n = int(input()) c = [] d = [] e = [] for i in range(0, n): a, b = map(int, input().split()) c.append(a) d.append(b) e.append(abs(a - b)) li1, li2 = sorted(e), sorted(range(len(e)), key=lambda k: e[k]) turn = 0 happy = 0 for i in range(n - 1, -1, -1): if (turn == 0): happy += c[li2[i]] else: happy -= d[li2[i]] print(happy) turn = (turn + 1) % 2 print(happy)
s287668855
Accepted
623
21,528
966
n = int(input()) c = [] d = [] e = [] for i in range(0, n): a, b = map(int, input().split()) c.append(a) d.append(b) e.append(a + b) li1, li2 = sorted(e), sorted(range(len(e)), key=lambda k: e[k]) turn = 0 happy = 0 for i in range(n - 1, -1, -1): now = li1[i] if (turn == 0): max = 0 maxKey = 0 for j in range(i, -1, -1): if (now == li1[j] and max < c[li2[j]]): max = c[li2[j]] maxKey = j else: li2[i], li2[maxKey] = li2[maxKey], li2[i] break happy += c[li2[i]] else: max = 0 maxKey = 0 for j in range(i, -1, -1): if (now == li1[j] and max < d[li2[j]]): max = d[li2[j]] maxKey = j else: li2[i], li2[maxKey] = li2[maxKey], li2[i] break happy -= d[li2[i]] turn = (turn + 1) % 2 print(happy)
s217841835
p03229
u845333844
2,000
1,048,576
Wrong Answer
247
7,516
615
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
n=int(input()) l=[] for i in range(n): l.append(int(input())) l.sort() if n%2==0: m=n//2 sum1=0 sum2=0 for j in range(m): sum1 += l[j] sum2 += l[n-1-j] max=2*sum2-2*sum1-l[m]+l[m-1] print(max) else: if n==3: max1=l[2]+l[1]-2*l[0] max2=2*l[2]-l[1]-l[0] if (max1>max2): print(max1) else: print(max2) else: m=(n-1)//2 sum1=0 sum2=0 for j in range(m+1): sum1 += l[j] sum2 += l[n-1-j] max1=2*sum2-l[m]-l[m+1]-2*sum1+2*l[m] max2=2*sum2-2*l[m]-2*sum1+l[m-1]+l[m-2] if (max1>max2): print(max1) else: print(max2)
s582328272
Accepted
240
7,512
613
n=int(input()) l=[] for i in range(n): l.append(int(input())) l.sort() if n%2==0: m=n//2 sum1=0 sum2=0 for j in range(m): sum1 += l[j] sum2 += l[n-1-j] max=2*sum2-2*sum1-l[m]+l[m-1] print(max) else: if n==3: max1=l[2]+l[1]-2*l[0] max2=2*l[2]-l[1]-l[0] if (max1>max2): print(max1) else: print(max2) else: m=(n-1)//2 sum1=0 sum2=0 for j in range(m+1): sum1 += l[j] sum2 += l[n-1-j] max1=2*sum2-l[m]-l[m+1]-2*sum1+2*l[m] max2=2*sum2-2*l[m]-2*sum1+l[m]+l[m-1] if (max1>max2): print(max1) else: print(max2)
s293193774
p03813
u596536048
2,000
262,144
Wrong Answer
27
8,976
161
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.
print('レートを入力してください') rate = int(input()) print('参加するコンテストは') if rate < 1200: print('ABC') else: print('ARC')
s520749761
Accepted
28
9,060
75
rate = int(input()) if rate < 1200: print('ABC') else: print('ARC')
s137852854
p03196
u299172013
2,000
1,048,576
Wrong Answer
95
3,572
660
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.
import functools import itertools import math import sys import collections import enum def primefac(x): fac = [] for i in range(2, int(math.sqrt(x)) + 1 + 1): if x % i != 0: continue ex = 0 while x % i == 0: ex += 1 x = x // i fac.append((i, ex)) if x != 1: fac.append((x, 1)) return fac if __name__ == "__main__": N, P = [int(x) for x in input().split(" ")] fac = primefac(P) def f(x, y): return x[0] * y[0] try: print(functools.reduce(f, [(val, ex // N) for val, ex in fac if ex >= N])) except TypeError: print(0)
s323009319
Accepted
95
3,684
636
import functools import itertools import math import sys import collections import enum def primefac(x): fac = [] for i in range(2, int(math.sqrt(x)) + 1 + 1): if x % i != 0: continue ex = 0 while x % i == 0: ex += 1 x = x // i fac.append((i, ex)) if x != 1: fac.append((x, 1)) return fac if __name__ == "__main__": N, P = [int(x) for x in input().split(" ")] fac = primefac(P) def f(x, y): return x[0] * y[0] ans = 1 for val, ex in fac: if ex >= N: ans *= val ** (ex // N) print(ans)
s104301344
p03386
u119982147
2,000
262,144
Wrong Answer
2,104
3,060
106
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 b-k < i: print(i)
s154860690
Accepted
17
3,060
134
a, b, k = map(int, input().split()) for i in range(a, min(b+1, a+k)): print(i) for i in range(max(b-k+1, a+k), b+1): print(i)
s317534148
p03469
u771532493
2,000
262,144
Wrong Answer
17
2,940
43
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
S=input() S.replace('2017','2018') print(S)
s923110640
Accepted
17
2,940
34
S=input() s=S[4:] print('2018'+s)
s042623209
p03471
u044638697
2,000
262,144
Time Limit Exceeded
2,104
3,060
372
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
N,Y = (int(i) for i in input().split()) n_10000,n_5000 = 0,0 n_1000 = N-n_10000-n_5000 x = True while x: while x: if n_1000 < 0: print(-1,-1,-1) x = False elif n_10000 +n_5000 +n_1000 == N and 10000*n_10000+5000*n_5000+1000*n_1000 == Y: print(n_10000,n_5000,n_1000) n_5000 += 1 n_10000 += 1
s512747921
Accepted
798
3,060
268
N,Y = (int(i) for i in input().split()) a,b,c = -1,-1,-1 for n_10000 in range(N+1): for n_5000 in range(N-n_10000+1): n_1000 = N-n_10000-n_5000 if 10000*n_10000+5000*n_5000 +1000*n_1000 == Y: a,b,c = n_10000,n_5000,n_1000 print(a,b,c)
s370324292
p03828
u254871849
2,000
262,144
Wrong Answer
34
3,064
867
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
import math mod = int(1e9+7) N = int(input()) n = math.factorial(N) count_of_prime_factors = {} while True: if n > 1: count = 0 while n % 2 == 0: n //= 2 count += 1 if count != 0: count_of_prime_factors.update({2: count}) if n == 1: break for i in range(3, N+1, 2): count = 0 while n % i == 0: n //= i count += 1 if count != 0: count_of_prime_factors.update({i: count}) if n == 1: break else: count_of_prime_factors.update({n: 1}) break else: print(1) exit() ans = 1 for prime_factor, count in count_of_prime_factors.items(): ans *= count + 1 print(ans % mod) print(count_of_prime_factors)
s588928019
Accepted
438
95,816
897
import sys import numpy as np def sieve_of_eratosthenes(n=10 ** 7): sieve = np.ones(n + 1); sieve[:2] = 0 for i in range(2, int(np.sqrt(n)) + 1): if sieve[i]: sieve[i*2::i] = 0 return sieve, np.flatnonzero(sieve) is_prime, prime_numbers = sieve_of_eratosthenes() def prime_factorize(n): res = dict() if n < 2: return res border = int(n ** 0.5) for p in prime_numbers: if p > border: break while n % p == 0: res[p] = res.get(p, 0) + 1; n //= p if n == 1: return res res[n] = 1 return res def prime_factorize_factorial(n): res = dict() for i in range(2, n + 1): for p, c in prime_factorize(i).items(): res[p] = res.get(p, 0) + c return res MOD = 10 ** 9 + 7 n = int(sys.stdin.readline().rstrip()) def main(): res = 1 for c in prime_factorize_factorial(n).values(): res *= c + 1; res %= MOD print(res) if __name__ == '__main__': main()
s277798673
p03370
u780269042
2,000
262,144
Wrong Answer
17
2,940
109
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
a,b = map(int, input().split()) price = [int(input()) for i in range(a)] print(sum(price)+ min(price)*(a-b))
s990861932
Accepted
17
2,940
135
a,b = map(int, input().split()) price = [int(input()) for i in range(a)] rema = b - sum(price) print(len(price)+ int(rema/min(price)))
s411320398
p03474
u790812284
2,000
262,144
Wrong Answer
19
3,188
190
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
import re a,b=map(int,input().split()) s=input() if re.search(r"^([0-9])*$",s[:a]) and s[a]=="-" and re.search(r"^([0-9])$",s[a+1:]) and len(s)==a+b+1: print("Yes") else: print("No")
s246625522
Accepted
20
3,188
191
import re a,b=map(int,input().split()) s=input() if re.search(r"^([0-9])*$",s[:a]) and s[a]=="-" and re.search(r"^([0-9])*$",s[a+1:]) and len(s)==a+b+1: print("Yes") else: print("No")
s164395746
p03992
u284563808
2,000
262,144
Wrong Answer
23
3,064
32
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
s=input() print(s[:4]+'_'+s[4:])
s743541937
Accepted
22
3,064
32
s=input() print(s[:4]+' '+s[4:])
s664005555
p02646
u095094246
2,000
1,048,576
Wrong Answer
20
9,188
218
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()) if a > b: if a - v*t <= b - w*t: print('Yes') else: print('No') else: if a + v*t >= b+w*t: print('Yes') else: print('No')
s960063076
Accepted
25
9,180
218
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) if a > b: if a - v*t <= b - w*t: print('YES') else: print('NO') else: if a + v*t >= b+w*t: print('YES') else: print('NO')
s388256206
p03997
u417014669
2,000
262,144
Wrong Answer
17
2,940
62
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h/2)
s313057474
Accepted
17
2,940
68
a=int(input()) b=int(input()) h=int(input()) print(int((a+b)*h/2))
s154788525
p02614
u886297662
1,000
1,048,576
Wrong Answer
64
9,516
390
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
import itertools import copy H, W, K = map(int, input().split()) C = [list(input()) for i in range(H)] clist = list(itertools.product([0, 1], repeat=H+W)) ans = 0 for q in clist: black = 0 h = q[:H] w = q[H:] for i in range(H): for j in range(W): if h[i] == w[j] == 0 and C[i][j] == '#': black += 1 if black == K: ans += 1 print(q) print(ans)
s629532714
Accepted
61
9,436
391
import itertools import copy H, W, K = map(int, input().split()) C = [list(input()) for i in range(H)] clist = list(itertools.product([0, 1], repeat=H+W)) ans = 0 for q in clist: black = 0 h = q[:H] w = q[H:] for i in range(H): for j in range(W): if h[i] == w[j] == 0 and C[i][j] == '#': black += 1 if black == K: ans += 1 #print(q) print(ans)
s100830734
p02612
u131453093
2,000
1,048,576
Wrong Answer
31
9,136
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()) ans = N % 1000 print(ans)
s987012828
Accepted
31
9,160
142
N = int(input()) for i in range(1,11): money = i * 1000 if money < N: continue else: print(money-N) break
s739056628
p03214
u223646582
2,525
1,048,576
Wrong Answer
17
3,064
217
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
N=int(input()) a=[int(i) for i in input().split()] ave=(sum(a)/N) ave_a=[abs(i-ave) for i in a] print(ave_a) ans=101 thum=101 for i in range(N): if ave_a[i]<thum: thum=ave_a[i] ans=i print(ans)
s776883576
Accepted
17
3,064
204
N=int(input()) a=[int(i) for i in input().split()] ave=(sum(a)/N) ave_a=[abs(i-ave) for i in a] ans=101 thum=101 for i in range(N): if ave_a[i]<thum: thum=ave_a[i] ans=i print(ans)
s291100256
p02418
u083560765
1,000
131,072
Wrong Answer
20
5,544
47
Write a program which finds a pattern $p$ in a ring shaped text $s$.
r=input() a=input() if a in r+r: print('yes')
s156498370
Accepted
20
5,548
66
r=input() a=input() if a in r+r: print('Yes') else: print('No')
s292796852
p03698
u771532493
2,000
262,144
Wrong Answer
17
2,940
76
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s=input() if list(s)==list(set(list(s))): print('yes') else: print('no')
s208295104
Accepted
18
2,940
74
s=input() if len(s)==len(set(list(s))): print('yes') else: print('no')
s851361019
p03486
u519968172
2,000
262,144
Wrong Answer
28
8,928
243
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=sorted(list(input())) t=sorted(list(input()),reverse=True) for i in range(min(len(s),len(t))): if ord(s[i])<ord(t[i]): print("YES") break elif ord(s[i])>ord(t[i]): print("NO") break else: print("Yes")
s362593085
Accepted
26
9,056
295
s=sorted(list(input())) t=sorted(list(input()),reverse=True) for i in range(min(len(s),len(t))): if ord(s[i])<ord(t[i]): print("Yes") break elif ord(s[i])>ord(t[i]): print("No") break else: if len(s)>=len(t): print("No") else: print("Yes")
s914565321
p02665
u447679353
2,000
1,048,576
Wrong Answer
730
669,276
969
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
# coding: utf-8 N = int(input()) A = list(map(int,input().split())) leaf= [-1 for i in range(N+1)] notleaf = [-1 for i in range(N+1)] flag=0 if N == 0 and A[0] == 1: print(1) elif N != 0 and A[0]>=1: print(-1) else: leaf[0]=0 notleaf[0]=1 for d in range(1, N+1): leaf[d] = A[d] notleaf[d] = 2*notleaf[d-1] - leaf[d] if notleaf[d]<0: flag=1 print(-1) break #if flag==0 and notleaf[N] != 0: # print(-1) else: sleaf = 0 for i in range(N+1): sleaf += leaf[i] d1 = 0 for i in range(N+1): d1 += (i+1) * leaf[i] sleaf -= 1 for i in range(1,N+1): if sleaf>0: d1 -= i*( min(sleaf, leaf[i]+notleaf[i] - notleaf[i-1])) sleaf -= (leaf[i]+notleaf[i] - notleaf[i-1]) else: print(d1) break
s970050042
Accepted
756
669,532
968
# coding: utf-8 N = int(input()) A = list(map(int,input().split())) leaf= [-1 for i in range(N+1)] notleaf = [-1 for i in range(N+1)] flag=0 if N == 0 and A[0] == 1: print(1) elif N==0 and A[0]!=1: print(-1) elif N != 0 and A[0]>=1: print(-1) else: leaf[0]=0 notleaf[0]=1 for d in range(1, N+1): leaf[d] = A[d] notleaf[d] = 2*notleaf[d-1] - leaf[d] if notleaf[d]<0: flag=1 print(-1) break if flag == 1: pass else: sleaf = 0 for i in range(N+1): sleaf += leaf[i] d1 = 0 for i in range(N+1): d1 += (i+1) * leaf[i] sleaf -= 1 for i in range(1,N+1): if sleaf>0: d1 -= i*( min(sleaf, leaf[i]+notleaf[i] - notleaf[i-1])) sleaf -= (leaf[i]+notleaf[i] - notleaf[i-1]) else: break print(d1)
s634242000
p02612
u843135954
2,000
1,048,576
Wrong Answer
33
9,136
242
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.
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n = ni() print(n%1000)
s800128180
Accepted
31
9,188
269
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n = ni() print(0 if n%1000 == 0 else 1000-n%1000)
s358697139
p03962
u834301346
2,000
262,144
Wrong Answer
111
27,176
87
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.
import numpy as np array = list(map(int, input().split(' '))) print(np.unique(array))
s375079367
Accepted
118
26,760
90
import numpy as np array = list(map(int, input().split(' '))) print(len(np.unique(array)))
s514523648
p03377
u802963389
2,000
262,144
Wrong Answer
17
2,940
85
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 A + B <= X: print("YES") else: print("NO")
s348493141
Accepted
17
2,940
97
A, B, X = map(int, input().split()) if A + B >= X and X >= A: print("YES") else: print("NO")
s084076747
p02614
u292746386
1,000
1,048,576
Wrong Answer
202
27,220
610
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
import numpy as np H, W, K = [int(i) for i in input().split()] A = np.zeros([H, W], dtype=bool) for i in range(H): A[i] = np.array([False if i=="." else True for i in input().split()]) T = A.sum() T_row = A.sum(1) T_col = A.sum(0) def calc(I, J): return T - T_row[I].sum() - T_col[J].sum() + A[I][:,J].sum() def repr(i, W): s = np.binary_repr(i, width=W)[::-1] return [i for i, j in enumerate(s) if j == "1"] count = 0 for i in range(2**H-1): for j in range(2**W-1): row = repr(i, H) col = repr(j, W) if calc(row, col) == K: count += 1 print(count)
s506025372
Accepted
191
27,312
602
import numpy as np H, W, K = [int(i) for i in input().split()] A = np.zeros([H, W], dtype=bool) for i in range(H): A[i] = np.array([False if i=="." else True for i in input()]) T = A.sum() T_row = A.sum(1) T_col = A.sum(0) def calc(I, J): return T - T_row[I].sum() - T_col[J].sum() + A[I][:,J].sum() def repr(i, W): s = np.binary_repr(i, width=W)[::-1] return [i for i, j in enumerate(s) if j == "1"] count = 0 for i in range(2**H-1): for j in range(2**W-1): row = repr(i, H) col = repr(j, W) if calc(row, col) == K: count += 1 print(count)
s334933765
p03720
u312078744
2,000
262,144
Wrong Answer
17
3,060
221
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?
n, m = map(int, input().split()) mat = [[0] * n] * n for i in range(m): a, b = map(int, input().split()) mat[a - 1][b - 1] = 1 mat[b - 1][a - 1] = 1 for i in range(n): ans = sum(mat[i]) print(ans)
s225321322
Accepted
153
12,384
282
import numpy as np n, m = map(int, input().split()) mat = [[0] * n] * n mat = np.array(mat) for i in range(m): a, b = map(int, input().split()) mat[a - 1, b - 1] += 1 mat[b - 1, a - 1] += 1 # print(mat) for i in range(n): ans = np.sum(mat[i, :]) print(ans)