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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s514553779
|
p03546
|
u513434790
| 2,000
| 262,144
|
Wrong Answer
| 344
| 19,428
| 348
|
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
|
from scipy.sparse.csgraph import floyd_warshall
H, W = map(int, input().split())
c = []
for i in range(10):
c1 = list(map(int, input().split()))
c.append(c1)
d = floyd_warshall(c)
ans = 0
for i in range(H):
a = list(map(int, input().split()))
for j in a:
if j != -1 and j != 1:
ans += d[j][1]
print(ans)
|
s230988591
|
Accepted
| 274
| 17,700
| 353
|
from scipy.sparse.csgraph import floyd_warshall
H, W = map(int, input().split())
c = []
for i in range(10):
c1 = list(map(int, input().split()))
c.append(c1)
d = floyd_warshall(c)
ans = 0
for i in range(H):
a = list(map(int, input().split()))
for j in a:
if j != -1 and j != 1:
ans += d[j][1]
print(int(ans))
|
s844857282
|
p03006
|
u427344224
| 2,000
| 1,048,576
|
Wrong Answer
| 1,322
| 3,316
| 575
|
There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: * Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1. Find the minimum total cost required to collect all the balls when we optimally choose p and q.
|
N = int(input())
items = []
for i in range(N):
items.append(tuple(map(int, input().split())))
ans = 0
res = []
for i in range(N):
for j in range(N):
if i == j:
continue
x1, y1 = items[i]
x2, y2 = items[j]
res.append((abs(x1-x2), abs(y1 -y2)))
for i in range(len(res)):
x, y = res[i]
cnt = 0
for j in range(len(res)):
if i == j:
continue
if x == res[j][0] and y == res[j][1]:
cnt += 1
ans = max(ans, cnt)
if ans == 0:
print(N - 1)
else:
print(N - ans + 1)
|
s189502804
|
Accepted
| 1,526
| 3,444
| 623
|
N = int(input())
items = []
for i in range(N):
items.append(tuple(map(int, input().split())))
res = []
for i in range(N):
for j in range(N):
if i == j:
continue
x1, y1 = items[i]
x2, y2 = items[j]
res.append((x1-x2, y1 -y2))
ans = 0
tar = list(set(res))
for t in tar:
cnt = 0
for i in range(N):
x, y = items[i]
for j in range(N):
if i == j:
continue
x2, y2 = items[j]
if x - t[0] == x2 and y - t[1] == y2:
cnt += 1
break
ans = max(ans, cnt)
print(N - ans)
|
s631509495
|
p03795
|
u117193815
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 49
|
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)-(int(n*800)/15)*200)
|
s933006932
|
Accepted
| 17
| 2,940
| 41
|
n=int(input())
print((n*800)-(n//15)*200)
|
s303802197
|
p02388
|
u043968625
| 1,000
| 131,072
|
Wrong Answer
| 50
| 7,516
| 40
|
Write a program which calculates the cube of a given integer x.
|
cube=int(input())
num=cube^3
print(num)
|
s241000582
|
Accepted
| 50
| 7,604
| 31
|
x=int(input())
#x=2
print(x**3)
|
s154107211
|
p03386
|
u657913472
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 26,704
| 104
|
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())
c=min(a+k,b);
for i in range(a,c):print(i)
for i in range(c,b+1):print(i)
|
s573837591
|
Accepted
| 17
| 3,060
| 115
|
a,b,k=map(int,input().split())
c=min(a+k,b);
for i in range(a,c):print(i)
for i in range(max(c,b-k+1),b+1):print(i)
|
s003930001
|
p03386
|
u460009487
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,188
| 278
|
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())
min = [0] * k
max = [0] * k
for i in range(k):
if a+i > b:
break
min[i] = a+i
for n in range(k):
if b-n < a:
break
max[n] = b-n
ans = min + max
ans.sort()
ans = set(ans)
for j in ans:
if j == 0:
continue
print(j)
|
s585096024
|
Accepted
| 29
| 9,208
| 293
|
a, b, k = map(int, input().split())
min = [0] * k
max = [0] * k
for i in range(k):
if a+i > b:
break
min[i] = a+i
for n in range(k):
if b-n < a:
break
max[n] = b-n
ans = min + max
ans = set(ans)
ans = list(ans)
ans.sort()
for j in ans:
if j == 0:
continue
print(j)
|
s496639746
|
p03998
|
u483151310
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 320
|
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.
|
players = {}
players["a"] = input()
players["b"] = input()
players["c"] = input()
now_play = "a"
while True:
if len(players[now_play]) == 0:
print("{} is win.".format(now_play))
break
trushed_card = players[now_play][0]
players[now_play] = players[now_play][1:]
now_play = trushed_card
|
s846578496
|
Accepted
| 17
| 3,060
| 307
|
players = {}
players["A"] = input()
players["B"] = input()
players["C"] = input()
now_play = "A"
while True:
if len(players[now_play]) == 0:
print(now_play)
break
trushed_card = players[now_play][0].upper()
players[now_play] = players[now_play][1:]
now_play = trushed_card
|
s032207457
|
p03721
|
u083960235
| 2,000
| 262,144
|
Wrong Answer
| 2,120
| 258,892
| 1,508
|
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
|
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def gcd(a, b):
if a == 0:
return b
if b == 0:
return a
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
def main():
S = []
N, K = MAP()
L = [LIST() for i in range(N)]
d = Counter()
for a, b in L:
# print(a, b)
for i in range(b):
S.append(a)
d.update(S)
# print(d)
# print(d)
d = sorted(d.items(), key=lambda pair: pair[1], reverse=False)
# print(d)
c = 0
# while c < K:
ans = 0
for a, b in d:
c += b
if c < K:
# ans = a
continue
else:
ans = a
print(ans)
exit()
if __name__ == "__main__":
main()
|
s788562014
|
Accepted
| 327
| 5,736
| 267
|
#14:59
N, K = map(int, input().split())
l = [0] * (10 ** 5 + 1)
for i in range(N):
a, b = map(int, input().split())
l[a] += b
cnt = 0
for i in range(1, 10 ** 5 + 1):
cnt += l[i]
if cnt >= K:
print(i)
break
|
s721475207
|
p03545
|
u790012205
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 361
|
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.
|
S = input()
def func(i, x, op):
if i == 4:
if x == 7:
return op
else:
return ''
opP = func(i + 1, x + int(S[i]), op+'+'+str(S[i]))
if opP != '':
return opP
opM = func(i + 1, x - int(S[i]), op+'-'+str(S[i]))
if opM != '':
return opM
return ''
print(func(1, int(S[0]), str(S[0])))
|
s662639377
|
Accepted
| 32
| 9,112
| 271
|
import sys
N = list(input())
for bit in range(2 ** 3):
op = ['-'] * 3
for i in range(3):
if (bit & (1 << i)):
op[i] = '+'
E = N[0] + op[0] + N[1] + op[1] + N[2] + op[2] + N[3]
if eval(E) == 7:
print(E + '=7')
sys.exit()
|
s822466680
|
p02272
|
u464859367
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,616
| 899
|
Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right)
|
N = int(input())
*A, = list(map(int, input().split()))
count = 0
def merge(a, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
la, ra = [], []
for i in range(0, n1):
la += [a[left + i]]
for i in range(0, n2):
ra += [a[mid + i]]
la += [float("inf")]
ra += [float("inf")]
print(la)
print(ra)
i, j = 0, 0
for k in range(left, right):
count += 1
if la[i] <= ra[j]:
a[k] = la[i]
i = i + 1
else:
a[k] = ra[j]
j = j + 1
def merge_sort(a, left, right):
if left + 1 < right:
mid = int((left + right) / 2)
merge_sort(a, left, mid)
merge_sort(a, mid, right)
merge(a, left, mid, right)
merge_sort(A, 0, N)
print(count)
print(*A)
|
s054147900
|
Accepted
| 4,390
| 61,652
| 635
|
N = int(input())
*A, = list(map(int, input().split()))
count = 0
def merge(a, left, mid, right):
global count
la = a[left:mid] + [float("inf")]
ra = a[mid:right] + [float("inf")]
i, j = 0, 0
for k in range(left, right):
count += 1
if la[i] <= ra[j]:
a[k] = la[i]
i += 1
else:
a[k] = ra[j]
j += 1
def merge_sort(a, left, right):
if left + 1 < right:
mid = int((left + right) / 2)
merge_sort(a, left, mid)
merge_sort(a, mid, right)
merge(a, left, mid, right)
merge_sort(A, 0, N)
print(*A)
print(count)
|
s047123037
|
p02606
|
u432853936
| 2,000
| 1,048,576
|
Wrong Answer
| 25
| 9,016
| 118
|
How many multiples of d are there among the integers between L and R (inclusive)?
|
l,r,d = map(int,input().split())
if l % d == 0:
print(((r - l) // d) + 1)
else:
print((r - l) // d)
|
s000526697
|
Accepted
| 27
| 9,152
| 126
|
l,r,d = map(int,input().split())
ans = 0
for i in range(l,r+1):
if i % d == 0:
ans += 1
print(ans)
|
s098513946
|
p03486
|
u273010357
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 145
|
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(input())
t = list(input())
s.sort(), t.sort(reverse=True)
s, t = ''.join(s), ''.join(t)
if s<t:
print('YES')
else:
print('NO')
|
s112628408
|
Accepted
| 17
| 2,940
| 120
|
s = ''.join(sorted(list(input())))
t = ''.join(sorted(list(input()), reverse=True))
print('Yes') if s<t else print('No')
|
s018806349
|
p03545
|
u278670845
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 354
|
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
a,b,c,d = map(int, list(input()))
x = [1,-1]
for i in x:
for j in x:
for k in x:
if a+i*b+j*c+k*d==7:
ans = str(a)
ans += "+" if i==1 else"-"
ans += str(b)
ans += "+" if j==1 else"-"
ans += str(c)
ans += "+" if k==1 else"-"
ans += str(d)
print(ans)
sys.exit()
|
s332473965
|
Accepted
| 17
| 3,064
| 377
|
import sys
a,b,c,d = map(int, list(input()))
x = [1,-1]
for i in x:
for j in x:
for k in x:
if a+i*b+j*c+k*d==7:
ans = str(a)
ans += "+" if i==1 else "-"
ans += str(b)
ans += "+" if j==1 else "-"
ans += str(c)
ans += "+" if k==1 else "-"
ans += str(d)
ans += "=7"
print(ans)
sys.exit()
|
s238288844
|
p03671
|
u973108807
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 56
|
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.
|
array = sorted(input().split())
print(array[0]+array[1])
|
s188531685
|
Accepted
| 18
| 2,940
| 72
|
array = sorted(list(map(int, input().split())))
print(array[0]+array[1])
|
s734192383
|
p03719
|
u312821683
| 2,000
| 262,144
|
Wrong Answer
| 28
| 8,940
| 84
|
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
|
A,B,C = input().split()
if C >= A and C <= B:
print('YES')
else:
print('NO')
|
s583609420
|
Accepted
| 26
| 9,048
| 95
|
A,B,C = map(int, input().split())
if C >= A and C <= B:
print('Yes')
else:
print('No')
|
s477577004
|
p03478
|
u192588826
| 2,000
| 262,144
|
Wrong Answer
| 27
| 3,060
| 288
|
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())
count = 0
for i in range(n):
if (i+1) == 10000 and a == 1:
count += 1
break
judge = (i+1)%10 + ((i+1)%100 - (i+1)%10)//10 + ((i+1)%1000 - (i+1)%100 - (i+1)%10)//100
if judge >= a and judge <= b:
count += 1
print(count)
|
s049358466
|
Accepted
| 26
| 2,940
| 249
|
n,a,b = map(int,input().split())
count = 0
for i in range(n+1):
judge = i%10 + (i%100 - i%10)//10 + (i%1000 - i%100)//100 + (i%10000 - i%1000)//1000 + (i%100000 - i%10000)//10000
if judge >= a and judge <= b:
count += i
print(count)
|
s054541105
|
p03573
|
u367130284
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 43
|
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
|
a,b,c=map(int,input().split());print(a+c-b)
|
s790574894
|
Accepted
| 17
| 2,940
| 51
|
a,b,c=sorted(map(int,input().split()));print(a+c-b)
|
s984830692
|
p03693
|
u245870380
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 94
|
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
N = input().split()
sn = ""
for i in N:
sn += i
print('Yes' if int(sn) % 4 == 0 else 'No')
|
s780509234
|
Accepted
| 17
| 2,940
| 94
|
N = input().split()
sn = ""
for i in N:
sn += i
print('YES' if int(sn) % 4 == 0 else 'NO')
|
s332374522
|
p03679
|
u952708174
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 100
|
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
|
X,A,B = [int(i) for i in input().split()]
if B-A<=X:
print('delicious')
else:
print('dangerous')
|
s411928567
|
Accepted
| 17
| 2,940
| 131
|
X,A,B = [int(i) for i in input().split()]
if B-A<=0:
print('delicious')
elif 0<B-A<=X:
print('safe')
else:
print('dangerous')
|
s585096304
|
p03472
|
u644778646
| 2,000
| 262,144
|
Wrong Answer
| 326
| 10,984
| 314
|
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
|
N,H = map(int,input().split())
a,b = [],[]
for i in range(N):
k,kk = map(int,input().split())
a.append(k)
b.append(kk)
zanmax = max(a)
num = 0
cnt = 0
for i in b:
if zanmax <= i:
num += i
cnt += 1
if num >= H:
print(cnt)
else:
cnt += int((H - num)/zanmax)
print(cnt)
|
s349030135
|
Accepted
| 356
| 12,080
| 368
|
import math
N,H = map(int,input().split())
a,b = [],[]
for i in range(N):
k,kk = map(int,input().split())
a.append(k)
b.append(kk)
zanmax = max(a)
b = sorted(b,reverse=True)
num = 0
cnt = 0
for i in b:
if zanmax < i:
num += i
cnt += 1
if num >= H:
print(cnt)
exit()
cnt += ((H-num)/zanmax)
print(math.ceil(cnt))
|
s315226097
|
p03679
|
u802963389
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 127
|
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
|
x, a, b = map(int, input().split())
if b <= a:
print("delicious")
elif a < b <= x:
print("safe")
else:
print("dangerous")
|
s415769259
|
Accepted
| 17
| 2,940
| 132
|
x, a, b = map(int, input().split())
if b <= a:
print("delicious")
elif a < b <= a + x:
print("safe")
else:
print("dangerous")
|
s410992064
|
p00002
|
u766477342
| 1,000
| 131,072
|
Wrong Answer
| 40
| 7,528
| 47
|
Write a program which computes the digit number of sum of two integers a and b.
|
print(len(str(sum(map(int, input().split())))))
|
s608659542
|
Accepted
| 50
| 7,532
| 100
|
try:
while 1:
print(len(str(sum(map(int, input().split())))))
except Exception:
pass
|
s359280187
|
p03007
|
u196697332
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 14,020
| 416
|
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
|
N = int(input())
A_list = list(map(int, input().split()))
max_list = [0] * (N - 1)
min_list = [0] * (N - 1)
for i in range(N - 1):
max_list[i] = max(A_list)
A_list.pop(A_list.index(max_list[i]))
min_list[i] = min(A_list)
A_list.pop(A_list.index(min_list[i]))
tmp = min_list[i] - max_list[i]
A_list.append(tmp)
print(-sum(A_list))
for i in range(N - 1):
print(max_list[i], min_list[i])
|
s890537018
|
Accepted
| 309
| 23,012
| 685
|
N = int(input())
A_list = list(map(int, input().split()))
A_sorted = sorted(A_list)
pos_count = len([a for a in A_sorted if a >= 0])
neg_count = len([a for a in A_sorted if a < 0])
if pos_count == 0:
pos_count = 1
neg_count = N - 1
if neg_count == 0:
pos_count = N - 1
neg_count = 1
output_list = [0] * (N - 1)
count = 0
for q in range(neg_count, N - 1):
output_list[count] = [A_sorted[0], A_sorted[q]]
count += 1
A_sorted[0] -= A_sorted[q]
for i in range(neg_count):
output_list[count] = [A_sorted[N - 1], A_sorted[i]]
count += 1
A_sorted[N - 1] -= A_sorted[i]
print(A_sorted[N - 1])
for item in output_list:
print(item[0], item[1])
|
s753438656
|
p03563
|
u750651325
| 2,000
| 262,144
|
Wrong Answer
| 24
| 9,044
| 109
|
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
|
R = int(input())
G = int(input())
if R >= G:
sa = R-G
print(G+sa)
else:
sa = G-R
print(R+sa)
|
s395347220
|
Accepted
| 31
| 9,084
| 56
|
R = int(input())
G = int(input())
sa = G-R
print(G+sa)
|
s254508101
|
p00444
|
u546285759
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,608
| 212
|
太郎君はよくJOI雑貨店で買い物をする. JOI雑貨店には硬貨は500円,100円,50円,10円,5円,1円が十分な数だけあり,いつも最も枚数が少なくなるようなおつりの支払い方をする.太郎君がJOI雑貨店で買い物をしてレジで1000円札を1枚出した時,もらうおつりに含まれる硬貨の枚数を求めるプログラムを作成せよ. 例えば入力例1の場合は下の図に示すように,4を出力しなければならない.
|
c, o= 0, 1000-int(input())
if o>= 500:
o, c= o-500, c+1
if o>= 100:
t= o//100
o, c= o-(100*t), c+t
if o>= 10:
t= o//10
o, c= o-(10*t), c+t
if o>= 5:
t= o//5
o, c= o-(5*t), c+t
print(c)
|
s121464796
|
Accepted
| 20
| 7,640
| 224
|
def change(v):
global c, o
if o>= v:
t= o//v
o, c= o-(v*t), c+t
while True:
o= int(input())
if o== 0: break
c, o= 0, 1000-o
for l in [500, 100, 50, 10, 5, 1]: change(l)
print(c+o)
|
s436048488
|
p03457
|
u305534505
| 2,000
| 262,144
|
Wrong Answer
| 426
| 27,380
| 616
|
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.
|
def check(a,b):
distance = abs(a[1]-b[1]) + abs(a[2]-b[2])
# print(distance)
time = abs(b[0]-a[0])
# print(time)
c = time - distance
if((c >= 0) and (c%2==0)):
return 0
else:
return 1
def main():
n = int(input())
plan = [list(map(int, input().split())) for i in range(n)]
if(check([0,0,0],plan[0])==1):
print("NO")
return
flag = 0
for i in range(n-1):
flag += check(plan[i],plan[i+1])
if (flag >0):
break
if (flag == 0):
print("YES")
else:
print("NO")
main()
|
s197971571
|
Accepted
| 380
| 27,380
| 571
|
def check(a,b):
distance = abs(a[1]-b[1]) + abs(a[2]-b[2])
time = abs(b[0]-a[0])
c = time - distance
if((c >= 0) and (c%2==0)):
return 0
else:
return 1
def main():
n = int(input())
plan = [list(map(int, input().split())) for i in range(n)]
if(check([0,0,0],plan[0])==1):
print("No")
return
flag = 0
for i in range(n-1):
flag += check(plan[i],plan[i+1])
if (flag >0):
break
if (flag == 0):
print("Yes")
else:
print("No")
main()
|
s116562114
|
p03625
|
u669382434
| 2,000
| 262,144
|
Wrong Answer
| 84
| 14,252
| 248
|
We have N sticks with negligible thickness. The length of the i-th stick is A_i. Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
|
input()
a=[int(i) for i in input().split()]
sorted(a,reverse=True)
tyo=0
tan=0
tb=0
for i in range(len(a)-1):
if tb==1:
tb=0
else:
if a[i]==a[i+1] and tyo==0:
tyo=a[i]
tb=1
else:
tan=a[i]
break
print(tyo+tan)
|
s841747052
|
Accepted
| 108
| 14,252
| 259
|
input()
a=[int(i) for i in input().split()]
a.sort(reverse=True)
tyo=0
tan=0
tb=0
for i in range(len(a)-1):
if tb==1:
tb=0
else:
if a[i]==a[i+1] and tyo==0:
tyo=a[i]
tb=1
elif a[i]==a[i+1]:
tan=a[i]
break
print(tyo*tan)
|
s518462179
|
p02259
|
u418996726
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,596
| 334
|
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
|
input()
arr = list(map(int, input().split()))
flag = False
count = 0
while not flag:
flag = True
for i in range(len(arr)-1):
if arr[i] > arr[i+1]:
count + 1
flag = False
t = arr[i+1]
arr[i+1] = arr[i]
arr[i] = t
print(" ".join(map(str, arr)))
print(count)
|
s371035404
|
Accepted
| 20
| 5,596
| 335
|
input()
arr = list(map(int, input().split()))
flag = False
count = 0
while not flag:
flag = True
for i in range(len(arr)-1):
if arr[i] > arr[i+1]:
count += 1
flag = False
t = arr[i+1]
arr[i+1] = arr[i]
arr[i] = t
print(" ".join(map(str, arr)))
print(count)
|
s557237438
|
p02407
|
u886729200
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,604
| 159
|
Write a program which reads a sequence and prints it in the reverse order.
|
n = int(input())
num = [int(i) for i in input().split()]
for i in range(round(len(num)/2)):
num[i],num[len(num)-i-1] = num[len(num)-i-1],num[i]
print(num)
|
s351718171
|
Accepted
| 20
| 5,600
| 185
|
n = int(input())
num = [int(i) for i in input().split()]
for i in range(round(len(num)/2)):
num[i],num[len(num)-i-1] = num[len(num)-i-1],num[i]
print(' '.join(str(i) for i in num))
|
s029533032
|
p02240
|
u196653484
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,592
| 444
|
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
|
def main():
n=list(map(int,input().split()))
n = n[1]
friends=[]
question=[]
for i in range(n):
a=tuple(map(int,input().split()))
friends.append(a)
m=int(input())
for i in range(m):
b=tuple(map(int,input().split()))
question.append(b)
for i in question:
if i in friends:
print("yes")
else:
print("no")
if __name__ == "__main__":
main()
|
s600196259
|
Accepted
| 570
| 24,988
| 1,208
|
#coding:utf-8
class UnionFind:
def __init__(self,n):
self.parent=[i for i in range(n+1)]
self.rank=[0]*(n+1)
def find(self,x):
if self.parent[x] == x: # if x is x`s root
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same_tree(self,x,y):
return self.find(x) == self.find(y)
def union(self,x,y):
x=self.find(x)
y=self.find(y)
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
n=list(map(int,input().split()))
union=UnionFind(n[0])
friends=[]
question=[]
for i in range(n[1]):
a=tuple(map(int,input().split()))
friends.append(a)
for i in friends:
union.union(i[0],i[1])
m=int(input())
for i in range(m):
b=tuple(map(int,input().split()))
question.append(b)
for i in question:
if union.find(i[0]) == union.find(i[1]):
print("yes")
else:
print("no")
if __name__ == "__main__":
main()
|
s141449793
|
p03597
|
u506587641
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 50
|
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
|
n = int(input())
a = int(input())
print(n**n - a)
|
s438072324
|
Accepted
| 17
| 2,940
| 50
|
n = int(input())
a = int(input())
print(n**2 - a)
|
s338466372
|
p03494
|
u826771152
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 326
|
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.
|
def shift_only(n,array):
tmp = []
counter = 0
while True:
flag = True
for num in array:
if num%2 != 0:
flag = False
if flag == False:
break
array = [i/2 for i in array]
counter +=1
return counter
|
s529196693
|
Accepted
| 18
| 3,060
| 396
|
def shift_only(array):
tmp = []
counter = 0
while True:
flag = True
for num in array:
if num%2 != 0:
flag = False
if flag == False:
break
array = [i/2 for i in array]
counter +=1
print(counter)
n = int(input())
a = list(map(int, input().split()))
shift_only(a)
|
s737907843
|
p02408
|
u920118302
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,644
| 298
|
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.
|
def CheckCards(Mark):
for i in range(1, 13):
if [Mark, i] not in Cards:
print(Mark + str(i))
n = int(input())
Cards = []
for i in range(n):
Cards.append(input().split())
Cards[i][1] = int(Cards[i][1])
CheckCards("S")
CheckCards("H")
CheckCards("C")
CheckCards("D")
|
s731404710
|
Accepted
| 50
| 7,752
| 304
|
def CheckCards(Mark):
for i in range(1, 14):
if [Mark, i] not in Cards:
print(Mark + " " + str(i))
n = int(input())
Cards = []
for i in range(n):
Cards.append(input().split())
Cards[i][1] = int(Cards[i][1])
CheckCards("S")
CheckCards("H")
CheckCards("C")
CheckCards("D")
|
s346258492
|
p03695
|
u213431796
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 889
|
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
|
N = int(input())
l = list(map(int,input().split()))
flag1 = True
flag2 = True
flag3 = True
flag4 = True
flag5 = True
flag6 = True
flag7 = True
flag8 = True
Max = 0
Min = 0
def plus():
Max += 1
Min += 1
return 0
for value in l:
if value < 400 and flag1 == True:
flag1 = False
Max += 1
Min += 1
elif value < 800 and flag2 == True:
flag2 = False
Max += 1
Min += 1
elif value < 1200 and flag3 == True:
flag3 = False
Max += 1
Min += 1
elif value < 1600 and flag4 == True:
flag4 = False
Max += 1
Min += 1
elif value < 2000 and flag5 == True:
flag5 = False
Max += 1
Min += 1
elif value < 2400 and flag6 == True:
flag6 = False
Max += 1
Min += 1
elif value < 2800 and flag7 == True:
flag7= False
Max += 1
Min += 1
elif value < 3200 and flag8 == True:
flag8 = False
Max += 1
Min += 1
else:
Max += 1
print(str(Min) + " " + str(Max))
|
s628910687
|
Accepted
| 17
| 3,064
| 1,039
|
n = int(input())
l = list(map(int,input().split()))
flag1 = True
flag2 = True
flag3 = True
flag4 = True
flag5 = True
flag6 = True
flag7 = True
flag8 = True
Max = 0
Min = 0
for value in l:
if 1 <= value and value < 400 and flag1 == True:
flag1 = False
Max += 1
Min += 1
elif 400 <= value and value < 800 and flag2 == True:
flag2 = False
Max += 1
Min += 1
elif 800 <= value and value < 1200 and flag3 == True:
flag3 = False
Max += 1
Min +=1
elif 1200 <= value and value < 1600 and flag4 == True:
flag4 = False
Max += 1
Min += 1
elif 1600 <= value and value < 2000 and flag5 == True:
flag5 = False
Max += 1
Min += 1
elif 2000 <= value and value < 2400 and flag6 == True:
flag6 = False
Max += 1
Min += 1
elif 2400 <= value and value < 2800 and flag7 == True:
flag7= False
Max += 1
Min += 1
elif 2800 <= value and value < 3200 and flag8 == True:
flag8 = False
Max += 1
Min += 1
elif 3200 <= value and value <= 4800:
Max += 1
if Min == 0:
Min = 1
print(str(Min) + " " + str(Max))
|
s103767984
|
p03494
|
u926046014
| 2,000
| 262,144
|
Wrong Answer
| 25
| 9,072
| 190
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
if a[i]%2==1:
print(0)
exit()
b = min(a)
cnt = 0
while b%2==0:
b//=2
cnt+=1
print(cnt)
|
s306433118
|
Accepted
| 28
| 9,068
| 200
|
n = int(input())
a = list(map(int, input().split()))
for i in range(10**5):
for j in range(n):
if a[j]%2==0:
a[j]=a[j]//2
else:
print(i)
exit()
|
s166797366
|
p00101
|
u583097803
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,692
| 145
|
An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina". Your task is to write a program which replace all the words "Hoshino" with "Hoshina". You can assume that the number of characters in a text is less than or equal to 1000.
|
n=int(input())
s=[input() for i in range(n)]
for i in s:
if "Hoshino" in i:
i=i.replace("Hoshino","Hoshina")
for i in s:
print(i)
|
s487292416
|
Accepted
| 30
| 7,592
| 161
|
n=int(input())
s=[input() for i in range(n)]
for i in range(n):
if "Hoshino" in s[i]:
s[i]=s[i].replace("Hoshino","Hoshina")
for i in s:
print(i)
|
s686029812
|
p03457
|
u823044869
| 2,000
| 262,144
|
Wrong Answer
| 2,105
| 29,352
| 654
|
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.
|
import sys
default_x = 0
default_y = 0
n = int(input())
print(n)
a = []
for i in range(n):
a.append(list(map(int,input().split())))
times = 0
for i in range(n):
for j in range(a[i][0]+times):
if default_x < a[i][1]:
default_x += 1
elif default_x > a[i][1]:
default_x -= 1
elif default_y < a[i][2]:
default_y += 1
elif default_y > a[i][2]:
default_y -= 1
else:
default_y -= 1
if default_x != a[i][1] or default_y != a[i][2]:
print('No')
sys.exit()
times = a[i][0]
print('Yes')
|
s296968470
|
Accepted
| 424
| 17,320
| 366
|
n = int(input())
travel = list()
#start point
travel.append((0,0,0))
for i in range(n):
travel.append(tuple(map(int,input().split())))
for j in range(n):
dist = abs(travel[j][0]-travel[j+1][0])
dd = abs(travel[j][1]-travel[j+1][1])+abs(travel[j][2]-travel[j+1][2])
if dist < dd or (dd%2 != dist%2):
print("No")
exit(0)
print("Yes")
|
s325200014
|
p03434
|
u310678820
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 98
|
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([int(i) for i in input().split()])
ans=sum(a[::2])-sum(a[1::2])
print(ans)
|
s741793427
|
Accepted
| 17
| 3,060
| 112
|
n=int(input())
a=sorted([int(i) for i in input().split()], reverse=True)
ans=sum(a[::2])-sum(a[1::2])
print(ans)
|
s050046001
|
p03671
|
u617659131
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 124
|
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.
|
s = list(input())
for i in range(len(s)):
s.pop()
if s[:len(s) // 2 - 1] == s[len(s) // 2:]:
print(len(s))
break
|
s011015558
|
Accepted
| 17
| 2,940
| 63
|
a = list(map(int, input().split()))
a.sort()
print(a[0] + a[1])
|
s652079333
|
p03337
|
u291278680
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 62
|
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(min([a+b, a-b, a*b]))
|
s721164419
|
Accepted
| 17
| 2,940
| 62
|
a, b = map(int, input().split())
print(max([a+b, a-b, a*b]))
|
s269071209
|
p03456
|
u897328029
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 122
|
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
a, b = list(map(int, input().split()))
c = int(str(a) + str(b))
ans = 'Yes' if c == c ** (1/2) ** 2 else 'No'
print(ans)
|
s836110629
|
Accepted
| 17
| 2,940
| 131
|
a, b = list(map(int, input().split()))
c = int(str(a) + str(b))
ans = 'Yes' if c ** (1/2) == int(c ** (1/2)) else 'No'
print(ans)
|
s520196099
|
p03672
|
u497046426
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 153
|
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
|
S = input()
if len(S) % 2 == 1:
S = S[:-1]
else:
S = S[:-2]
N = len(S) // 2
print(S[:N], S[N:2*N])
while S[:N] != S[N:2*N]:
N -= 1
print(2*N)
|
s391902800
|
Accepted
| 17
| 2,940
| 130
|
S = input()
if len(S) % 2 == 1:
S = S[:-1]
else:
S = S[:-2]
N = len(S) // 2
while S[:N] != S[N:2*N]:
N -= 1
print(2*N)
|
s677033089
|
p02396
|
u896065593
| 1,000
| 131,072
|
Wrong Answer
| 130
| 7,512
| 95
|
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
|
while(1):
i = 1
x = int(input())
if(x == 0):break
print("Case %d: %d" % (i, x))
|
s253889634
|
Accepted
| 130
| 7,540
| 102
|
i = 1
while(1):
x = int(input())
if(x == 0):break
print("Case %d: %d" % (i, x))
i += 1
|
s026357248
|
p03493
|
u410026319
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 90
|
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[i] == 1:
count += 1
print(count)
|
s729600172
|
Accepted
| 17
| 2,940
| 93
|
s = input()
count = 0
for i in range(3):
if s[i] == '1':
count += 1
print(count)
|
s340288670
|
p02277
|
u365470584
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,652
| 654
|
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also 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).
|
def partition(A, p, r):
x = A[r]
i = p-1
for j in range(p,r):
if A[j] <= x:
i = i+1
A[i], A[j] = A[j], A[i]
A[i+1], A[r] = A[r], A[i+1]
return i+1
def quickSort(A, p, r):
if p < r:
q = partition(A, p, r)
quickSort(A, q, p-1)
quickSort(A, q+1, r)
def check(A, s, e):
for i in range(s,e-1):
if A[i][1] == A[i+1][1]:
if A[i][2] > A[i+1][2]:
return "Not stable"
return "Stable"
r = int(input())
a = []
for i in range(r):
c = input().split()
a.append((c[0],int(c[1]),i))
quickSort(a, 0, r-1)
print(check(a,0,r))
for s,r,d in a:
print("{} {}".format(s,r))
|
s688657425
|
Accepted
| 940
| 22,292
| 660
|
def partition(A, p, r):
x = A[r][1]
i = p-1
for j in range(p,r):
if A[j][1] <= x:
i = i+1
A[i], A[j] = A[j], A[i]
A[i+1], A[r] = A[r], A[i+1]
return i+1
def quickSort(A, p, r):
if p < r:
q = partition(A, p, r)
quickSort(A, p, q-1)
quickSort(A, q+1, r)
def check(A, s, e):
for i in range(s,e-1):
if A[i][1] == A[i+1][1]:
if A[i][2] > A[i+1][2]:
return "Not stable"
return "Stable"
r = int(input())
a = []
for i in range(r):
c = input().split()
a.append((c[0],int(c[1]),i))
quickSort(a, 0, r-1)
print(check(a,0,r))
for s,r,d in a:
print("{} {}".format(s,r))
|
s707772327
|
p02843
|
u085186789
| 2,000
| 1,048,576
|
Time Limit Exceeded
| 2,216
| 12,804
| 358
|
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
|
X = int(input())
for i1 in range(1000000):
for i2 in range(1000000):
for i3 in range(1000000):
for i4 in range(1000000):
for i5 in range(1000000):
for i6 in range(1000000):
if 100 * i1 + 101 * i2 + 102 * i3 + 103 * i4 + 104 * i5 + 105 * i6 == X:
print("1")
else:
print("0")
|
s957225731
|
Accepted
| 30
| 9,072
| 88
|
X = int(input())
a = X // 100
r = X % 100
if r <= 5 * a:
print("1")
else:
print("0")
|
s437316798
|
p02612
|
u708211626
| 2,000
| 1,048,576
|
Wrong Answer
| 27
| 9,144
| 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=input()
if len(a)==4:
b=a[1:]
print(int(b))
else:
print(a)
|
s243518504
|
Accepted
| 26
| 9,172
| 146
|
a=input()
if len(a)==4 or len(a)==5:
b=a[1:]
c=1000-int(b)
if c==1000 :
print('0')
else:
print(c)
else:
print(1000-int(a))
|
s786912337
|
p02936
|
u836311327
| 2,000
| 1,048,576
|
Wrong Answer
| 114
| 26,440
| 342
|
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
|
import sys
import numpy as np
from collections import deque
def input(): return sys.stdin.readline().rstrip()
def main():
n, q = map(int, input().split())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
clist = [0]*(n+1)
|
s853988332
|
Accepted
| 841
| 88,204
| 859
|
import sys
import numpy as np
from collections import deque
def input(): return sys.stdin.readline().rstrip()
def main():
n, q = map(int, input().split())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
clist = [0]*(n+1)
for _ in range(q):
p, x = map(int, input().split())
clist[p] += x
dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0
ans = [0]*(n+1)
d = deque()
d.append(1)
ans[1]=clist[1]
while d:
v = d.popleft()
for i in graph[v]:
if dist[i] != -1:
continue
dist[i] = dist[v] + 1
ans[i]=ans[v]+clist[i]
d.append(i)
ans = ans[1:]
print(*ans, sep=" ")
if __name__ == '__main__':
main()
|
s564366677
|
p03385
|
u505830998
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 347
|
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
#+++++
def main():
s = input()
a = ''.join(sorted(s)) == 'abc'
if a:
print('Yes')
else:
print('No')
#print(' '.join([str(v) for v in l]))
#+++++
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
else:
input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
s072498828
|
Accepted
| 17
| 3,060
| 356
|
import sys
#+++++
def main():
s = input()
#a ='Yes' if ''.join(sorted(s)) == 'abc' else 'No'
for c in 'abc':
if c not in s:
print('No')
return
print('Yes')
#+++++
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
else:
input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
s037611910
|
p03068
|
u418527037
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 182
|
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
|
N = int(input())
S = input()
K = int(input())
k = S[K-1]
print(k)
ans = []
for i in S:
if i == k:
ans.append(k)
else:
ans.append('*')
print(''.join(ans))
|
s537887420
|
Accepted
| 17
| 2,940
| 172
|
N = int(input())
S = input()
K = int(input())
k = S[K-1]
ans = []
for i in S:
if i == k:
ans.append(k)
else:
ans.append('*')
print(''.join(ans))
|
s162872542
|
p03943
|
u993622994
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 143
|
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())
if a == b + c or b == a + c or c == a + b:
print('YES')
else:
print('NO')
|
s948998231
|
Accepted
| 17
| 2,940
| 140
|
# -*- coding: utf-8 -*-
abc = sorted(list(map(int, input().split())))
if abc[0] + abc[1] == abc[2]:
print('Yes')
else:
print('No')
|
s271184710
|
p03227
|
u927764913
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 76
|
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.
|
a=list(input())
if len(a) == 3:
print(str(a[::-1]))
else:
print(str(a))
|
s244341249
|
Accepted
| 20
| 2,940
| 68
|
a=input()
if len(a) == 3:
print(a[::-1])
else:
print(str(a))
|
s166182274
|
p03338
|
u368796742
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 3,060
| 182
|
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
|
n = int(input())
l = list(input())
ans = 0
for i in range(n):
l1 = l[i:]
count = 0
for j in range(i+1):
if l[j] in l1:
count += 1
ans = max(ans,count)
print(ans)
|
s464614275
|
Accepted
| 18
| 2,940
| 136
|
n = int(input())
l = list(input())
ans = 0
for i in range(n):
count = len(set(l[:i])&set(l[i:]))
ans = max(count,ans)
print(ans)
|
s455050406
|
p03944
|
u583799976
| 2,000
| 262,144
|
Wrong Answer
| 32
| 9,192
| 218
|
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
|
W,H,N=map(int,input().split())
a,b,c,d=0,0,W,H
for i in range(N):
x,y,A=map(int,input().split())
if A==1: a=max(a,x)
if A==2: b=max(b,y)
if A==3: c=min(c,x)
if A==4: d=min(d,y)
print(max(0,c-a)*max(0,b-d))
|
s135905277
|
Accepted
| 27
| 9,016
| 235
|
W,H,N=map(int,input().split())
a,b,c,d=0,W,0,H
for i in range(N):
x,y,A=map(int,input().split())
if A==1:
a=max(a,x)
if A==2:
b=min(b,x)
if A==3:
c=max(c,y)
if A==4:
d=min(d,y)
print(max(0,b-a)*max(0,d-c))
|
s981328766
|
p03387
|
u826263061
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 539
|
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.
|
a = [0,0,0]
s = input().split()
a[0] = int(s[0])
a[1] = int(s[1])
a[2] = int(s[2])
#a_min = min(a)
#a[0] -= a_min
#a[1] -= a_min
#a[2] -= a_min
count = 0
while(True):
if a[0] == a[1] and a[1] == a[2]:
#print(count)
break
a.sort()
if a[2] >= a[0]+2:
a[0] += 2
count += 1
elif a[2] == a[1] +1:
a[2] -= 1
count += 1
elif a[1] == a[0] +1:
a[1] -= 1
count += 1
elif a[1] == a[0] +2:
a[0] += 2
count += 1
print(a)
print(count)
|
s058903446
|
Accepted
| 17
| 3,064
| 374
|
a = list(map(int, input().split()))
a.sort()
n0 = abs(a[2]-a[0])//2 + abs(a[2]-a[1])//2
if a[2] % 2 == 1 and a[0] % 2 == 0 and a[1] % 2 == 0:
n0 += 1
elif a[2] % 2 == 0 and a[0] % 2 == 1 and a[1] % 2 == 1:
n0 += 2
elif a[2] % 2 == 1 and a[0] % 2 == 1 and a[1] % 2 == 1:
pass
elif a[2] % 2 == 0 and a[0] % 2 == 0 and a[1] % 2 == 0:
pass
else:
n0 += 2
print(n0)
|
s588238977
|
p02936
|
u871980676
| 2,000
| 1,048,576
|
Wrong Answer
| 2,116
| 146,072
| 794
|
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
|
from copy import deepcopy as dp
N,Q = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(N-1) ]
px = [ list(map(int,input().split())) for i in range(Q) ]
a = [ab[i][0] for i in range(N-1)]
b = [ab[i][1] for i in range(N-1)]
dic = {}
def make_dic(nowlist, ab, st):
nextlist = [ b[i] for i in range(N-1) if st == a[i] ]
tmp = []
if nextlist == []:
dic[st] = [st]
return [st]
else:
for elem in nextlist:
tmp = tmp + make_dic(nowlist+[st], ab, elem)
dic[st] = [st] + tmp
return [st] + tmp
res = make_dic([], dp(ab), 1)
score = [0]*N
for i in range(Q):
if px[i][0] in dic.keys():
for no in dic[px[i][0]]:
#print([i,px[i][0],no])
score[no-1] += px[i][1]
print(score)
|
s464038746
|
Accepted
| 1,527
| 290,500
| 691
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000)
N,Q = map(int,readline().split())
abpx = list(map(int,read().split()))
ab = iter(abpx[:N+N-2])
px = iter(abpx[N+N-2:])
dic = {}
dic2=[0]*(N+1)
dic3=[0]*N
for i in range(N):
dic[i+1] = []
for a,b in zip(ab,ab):
dic[a].append(b)
dic[b].append(a)
for p,x in zip(px,px):
dic2[p] += x
def rec(now_node,prevval):
nowval = prevval + dic2[now_node]
dic3[now_node-1] = nowval
tg_list = dic[now_node][:]
for elem in tg_list:
dic[elem].remove(now_node)
rec(elem,nowval)
rec(1,0)
res = [str(dic3[i-1]) for i in range(1,N+1)]
print(' '.join(res))
|
s284184453
|
p02842
|
u253759478
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 101
|
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
|
n = int(input())
if n % 27 == 13 or n % 27 == 26:
print(':(')
else:
print(int(n / 1.08) + 1)
|
s898035180
|
Accepted
| 17
| 2,940
| 144
|
n = int(input())
if n % 27 == 13 or n % 27 == 26:
print(':(')
elif n % 27 == 0:
print(int(n / 1.08))
else:
print(int(n / 1.08) + 1)
|
s028030468
|
p03477
|
u794173881
| 2,000
| 262,144
|
Wrong Answer
| 20
| 2,940
| 124
|
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
a,b,c,d = map(int,input().split())
if a+b > c+d :
print("Left")
if a+b < c+d :
print("Right")
else:
print("Balanced")
|
s512852556
|
Accepted
| 17
| 2,940
| 126
|
a,b,c,d = map(int,input().split())
if a+b > c+d :
print("Left")
elif a+b < c+d :
print("Right")
else:
print("Balanced")
|
s409451033
|
p02612
|
u579508806
| 2,000
| 1,048,576
|
Wrong Answer
| 29
| 9,140
| 57
|
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())
c=0
while n > 0:
n-=1000
c+=1
print(c)
|
s337292180
|
Accepted
| 28
| 9,084
| 49
|
n=int(input())
while n > 0:
n-=1000
print(n*-1)
|
s592465468
|
p03493
|
u094565093
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 68
|
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()
S=list(S)
cnt=0
for i in S:
if i =='1':
cnt+=1
|
s698316509
|
Accepted
| 18
| 2,940
| 79
|
S=input()
S=list(S)
cnt=0
for i in S:
if i =='1':
cnt+=1
print(cnt)
|
s616597698
|
p03478
|
u018591138
| 2,000
| 262,144
|
Wrong Answer
| 41
| 3,060
| 291
|
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())
count = 0
for i in range(1,N+1):
m = 0
tmp = i
for t in range(1, len(str(i))+1):
#print(tmp)
m += tmp%10
tmp /= 10
tmp = int(tmp)
if( A <=m and m <= B):
count += i
print(count)
|
s298890119
|
Accepted
| 41
| 3,060
| 287
|
N,A,B = map(int, input().split())
count = 0
for i in range(1,N+1):
m = 0
tmp = i
for t in range(1, len(str(i))+1):
#print(tmp)
m += tmp%10
tmp /= 10
tmp = int(tmp)
if( A <=m and m <= B):
count += i
print(count)
|
s759240896
|
p03797
|
u298297089
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 105
|
Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
|
N,M = map(int, input().split())
if N * 2 > M:
print(M//2)
exit()
tmp = M - N * 2
print(N*2 + tmp//4)
|
s579115243
|
Accepted
| 17
| 2,940
| 86
|
n,m = map(int ,input().split())
ans = min(n, m // 2)
m -= ans * 2
print(ans + m // 4)
|
s805180530
|
p03351
|
u449555432
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 97
|
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a,b,c,d=map(int,input().split())
if abs(a-b)<d and abs(b-c)<d:
print('Yes')
else:
print('No')
|
s436452746
|
Accepted
| 17
| 2,940
| 119
|
a,b,c,d=map(int,input().split())
if abs(a-c)<=d or ( abs(b-a)<=d and abs(b-c)<=d ) :
print('Yes')
else:
print('No')
|
s198707438
|
p03193
|
u353797797
| 2,000
| 1,048,576
|
Wrong Answer
| 39
| 10,412
| 847
|
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?
|
from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction
import sys
sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]
n,h,w=MI()
ans=0
for _ in range(n):
a,b=MI()
if a<=h and b<=w:ans+=1
print(ans)
|
s697201011
|
Accepted
| 40
| 10,384
| 847
|
from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction
import sys
sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]
n,h,w=MI()
ans=0
for _ in range(n):
a,b=MI()
if a>=h and b>=w:ans+=1
print(ans)
|
s257439440
|
p02613
|
u389188163
| 2,000
| 1,048,576
|
Wrong Answer
| 34
| 9,172
| 169
|
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
N = int(input())
S = list(input().split())
print(f'AC x {S.count("AC")}')
print(f'WA x {S.count("WA")}')
print(f'TLE x {S.count("TLE")}')
print(f'RE x {S.count("RE")}')
|
s906771090
|
Accepted
| 147
| 16,172
| 214
|
N = int(input())
lst = []
for _ in range(N):
S = input()
lst.append(S)
print(f'AC x {lst.count("AC")}')
print(f'WA x {lst.count("WA")}')
print(f'TLE x {lst.count("TLE")}')
print(f'RE x {lst.count("RE")}')
|
s401985586
|
p03501
|
u870518235
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 52
|
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
|
N, A, B = map(int,input().split())
print(max(N*A,B))
|
s868213165
|
Accepted
| 17
| 2,940
| 52
|
N, A, B = map(int,input().split())
print(min(N*A,B))
|
s409604915
|
p02619
|
u537142137
| 2,000
| 1,048,576
|
Wrong Answer
| 125
| 27,264
| 418
|
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
|
import numpy as np
D = int(input())
c = np.array( list(map(int, input().split())) )
s = [[] for i in range(365+1)]
for i in range(D):
s[i] = np.array( list(map(int, input().split())) )
#
last = np.array( [-1]*26 )
av = np.array( [0]*26 )
id = np.identity(4,dtype=int)
v = 0
for d in range(D):
av = s[d] - sum( c*(d-last) ) + c*(d-last)
t = int(input())
t -= 1
last[t] = d
v += av[t]
print(t+1, v )
#
|
s322946673
|
Accepted
| 128
| 27,336
| 414
|
import numpy as np
D = int(input())
c = np.array( list(map(int, input().split())) )
s = [[] for i in range(365+1)]
for i in range(D):
s[i] = np.array( list(map(int, input().split())) )
#
last = np.array( [-1]*26 )
av = np.array( [0]*26 )
id = np.identity(4,dtype=int)
v = 0
for d in range(D):
av = s[d] - sum( c*(d-last) ) + c*(d-last)
t = int(input())
t -= 1
last[t] = d
v += av[t]
print( v )
#
|
s635260513
|
p02833
|
u311636831
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 270
|
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
|
N=1000000000000000000
if(N%2==1):
print(0)
exit()
#s=0
# while(i%5==0 and i!=0):
# s+=1
# i=i//5
#print(s)
s=0
t=10
while(N>=t):
s+=(N//t)
t*=5
print(s)
#L=len(str(N))-1
#T=N//10
#s+=T
#print(s)
|
s553373348
|
Accepted
| 17
| 2,940
| 263
|
N=int(input())
if(N%2==1):
print(0)
exit()
#s=0
# while(i%5==0 and i!=0):
# s+=1
# i=i//5
#print(s)
s=0
t=10
while(N>=t):
s+=(N//t)
t*=5
print(s)
#L=len(str(N))-1
#T=N//10
#s+=T
#print(s)
|
s879627233
|
p03394
|
u754022296
| 2,000
| 262,144
|
Wrong Answer
| 26
| 4,064
| 87
|
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
|
n = int(input())
if n%2:
print(2, 3, 25, *[15]*(n-3))
else:
print(2, 8, *[5]*(n-2))
|
s244025413
|
Accepted
| 30
| 4,560
| 473
|
n = int(input())
if n <= 15002:
if n==3:
print(2, 5, 63)
else:
if n%3:
l = [2*(i+1) for i in range(n-2)]
l += [3, 9]
print(*l)
else:
l = [2*(i+1) for i in range(n-1) if i!=2]
l += [3, 9]
print(*l)
else:
if n%2==0:
l = [2*(i+1) for i in range(15000)]
l += [3+6*i for i in range(n-15000)]
print(*l)
else:
l = [2*(i+1) for i in range(15000) if i!=2]
l += [3+6*i for i in range(n-14999)]
print(*l)
|
s441194995
|
p02606
|
u266014018
| 2,000
| 1,048,576
|
Wrong Answer
| 32
| 9,100
| 229
|
How many multiples of d are there among the integers between L and R (inclusive)?
|
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
l, r , d = map(int, input().split())
ans = (r-l)//d
if l%d == 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
s333602910
|
Accepted
| 29
| 9,156
| 237
|
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
l, r , d = map(int, input().split())
ans = r//d - l//d
if l%d == 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
s839089790
|
p03433
|
u694810977
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 97
|
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
N = int(input())
A = int(input())
if N % 500*A == 0:
print("Yes")
else:
print("No")
|
s256274784
|
Accepted
| 17
| 2,940
| 111
|
N = int(input())
A = int(input())
amari = N % 500
if amari <= A:
print("Yes")
else:
print("No")
|
s713586270
|
p03605
|
u079022116
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 50
|
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?
|
if input() in '9':
print('Yes')
else:print('No')
|
s190196856
|
Accepted
| 17
| 2,940
| 72
|
a=input()
if a[0] == '9' or a[1] == '9':
print('Yes')
else:print('No')
|
s705681224
|
p03470
|
u010668949
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 189
|
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
|
N = int(input())
d = [int(i) for i in input().split()]
print(len(list(set(d))))
|
s660962484
|
Accepted
| 17
| 2,940
| 214
|
N = int(input())
d = []
i = 0
while N>i:
d.append(int(input()))
i += 1
print(len(list(set(d))))
|
s460775783
|
p00003
|
u661290476
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,904
| 172
|
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
|
n=int(input())
r=[0]*n
for i in range(n):
r[i]=sorted(list(map(int,input().split())))
for i in range(n):
print("Yes" if r[i][0]**2+r[i][1]**2==r[i][2]**2 else "No")
|
s056284443
|
Accepted
| 40
| 5,604
| 197
|
n = int(input())
for _ in range(n):
edges = sorted([int(i) for i in input().split()])
if edges[0] ** 2 + edges[1] ** 2 == edges[2] ** 2:
print("YES")
else:
print("NO")
|
s321617839
|
p03478
|
u556657484
| 2,000
| 262,144
|
Wrong Answer
| 36
| 3,060
| 178
|
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 n in range(1, N):
n = str(n)
n_list = list(map(int, n))
if A <= sum(n_list) <= B:
ans += int(n)
print(ans)
|
s489941991
|
Accepted
| 37
| 3,060
| 180
|
N, A, B = map(int, input().split())
ans = 0
for n in range(1, N+1):
n = str(n)
n_list = list(map(int, n))
if A <= sum(n_list) <= B:
ans += int(n)
print(ans)
|
s571857916
|
p03565
|
u868982936
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 327
|
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 = list(input())
T = input()
ls = []
for i in range(len(S)-len(T)):
for j in range(len(T)):
if S[i+j] != T[j] and S[i+j] != "?":
break
else:
ls.append(i)
if ls:
for j in range(len(T)):
S[ls[-1]+j] = T[j]
print("".join(S).replace("?", "a"))
else:
print("UNRESTORABLE")
|
s844224795
|
Accepted
| 18
| 3,064
| 337
|
S = list(input())
T = input()
ls = []
for i in range(len(S)-len(T)+1):
for j in range(len(T)):
if S[i+j] != T[j] and S[i+j] != "?":
break
else:
ls.append(i)
if ls:
for j in range(len(T)):
S[ls[-1]+j] = T[j]
print("".join(S).replace("?", "a"))
else:
print("UNRESTORABLE")
|
s052475202
|
p03067
|
u065475172
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 113
|
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
|
A, B, C = map(int, input().split())
if C > A and C < B or C < A and C > B:
print('YES')
else:
print('NO')
|
s332906630
|
Accepted
| 17
| 2,940
| 113
|
A, B, C = map(int, input().split())
if C > A and C < B or C < A and C > B:
print('Yes')
else:
print('No')
|
s078210764
|
p03544
|
u043434786
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 171
|
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
|
N=int(input())
if N==0: print(1)
elif N==1: print(0)
else:
Ln_2=0
Ln_1=2
Ln=1
for i in range(N-2):
Ln_2=Ln_1
Ln_1=Ln
Ln=Ln_1+Ln_2
print(Ln)
|
s460361537
|
Accepted
| 17
| 2,940
| 172
|
N=int(input())
if N==0: print(2)
elif N==1: print(1)
else:
Ln_2=0
Ln_1=2
Ln=1
for i in range(N-1):
Ln_2=Ln_1
Ln_1=Ln
Ln=Ln_1+Ln_2
print(Ln)
|
s557458409
|
p03394
|
u631277801
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 4,596
| 988
|
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
|
def gca(a,b):
while 1:
a = a%b
if a == 0:
return b
b = b%a
if b == 0:
return a
def searchAns(nums):
cnt = 0
max_num = sum(nums)
while cnt < 100000:
isNotProper = False
cnt += 1
last_num = max_num*cnt
num_list = nums + [last_num]
sum_others = [sum(num_list) - i for i in num_list]
for num, sum_of_others in zip(num_list, sum_others):
flag = gca(num, sum_of_others)
if flag == 1:
isNotProper = True
break
if isNotProper:
continue
return last_num
return None
def main():
#1. input
n = int(input())
#2. choose numbers
nums = []
for i in range(2,n+1):
nums.append(i)
#3. search a proper last number
max_num = searchAns(nums)
print(nums + [max_num])
if __name__ == "__main__":
main()
|
s380334828
|
Accepted
| 32
| 4,860
| 1,124
|
import sys
stdin = sys.stdin
def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())
def solve(n:int) -> list:
x6o2 = [(6*i+2, 6*i+4) for i in range(5000)]
x6o3 = [(12*i+3, 12*i+9) for i in range(2500)]
o6 = [6*i+6 for i in range(5000)]
x6 = []
for i in range(2500):
x6.append(x6o3[i])
x6.append(x6o2[2*i])
x6.append(x6o2[2*i+1])
ans = []
if n == 3:
ans = [2, 5, 63]
elif n <= 15000:
idx = n//2
for i, (mn,mx) in enumerate(x6[:idx]):
ans.extend([mn,mx])
if n%2:
ans = ans + [6]
else:
for i, (mn,mx) in enumerate(x6):
ans.extend([mn,mx])
for o6i in o6[:n-15000]:
ans.append(o6i)
return ans
n = ni()
print(*solve(n))
|
s359676684
|
p02694
|
u073139376
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 9,164
| 104
|
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())
A = 100
t = 0
while A < X:
A *= 1.01
A = math.floor(A)
t += 1
|
s844215435
|
Accepted
| 23
| 9,096
| 114
|
import math
X = int(input())
A = 100
t = 0
while A < X:
A *= 1.01
A = math.floor(A)
t += 1
print(t)
|
s701795990
|
p03371
|
u043236471
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 216
|
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
|
a, b, c, x, y = [int(x) for x in input().split()]
if a + b < c*2:
res = a*x + b*y
else:
min_c = min(x, y)
max_c = max(x, y)
diff = max_c - min_c
res = (min_c * 2) * c + diff*max(a, b)
print(res)
|
s022721055
|
Accepted
| 18
| 3,064
| 318
|
a, b, c, x, y = [int(x) for x in input().split()]
if a + b < c*2:
res = a*x + b*y
else:
min_c = min(x, y)
ab_cost = min_c * 2 * c
rem = max(x-min_c, y-min_c)
if x > y:
rem_cost = min(rem * a, rem*2*c)
else:
rem_cost = min(rem*b, rem*2*c)
res = ab_cost + rem_cost
print(res)
|
s216820674
|
p03377
|
u118147328
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 101
|
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) or (A > X):
print("No")
else:
print("Yes")
|
s948779208
|
Accepted
| 17
| 2,940
| 101
|
A,B,X = map(int, input().split())
if (A + B < X) or (A > X):
print("NO")
else:
print("YES")
|
s485171118
|
p02972
|
u731028462
| 2,000
| 1,048,576
|
Wrong Answer
| 838
| 22,172
| 510
|
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
|
N = int(input())
A = list(map(int, input().split()))
ans=[]
cnt=0
B = [0 for i in range(N)]
import math
for i in range(math.floor(N/2),N):
B[i]=A[i]
if(A[i]==1):
cnt+=1
ans.append(i+1)
from functools import reduce
for i in range(math.floor(N/2)-1,-1,-1):
R=[B[i*j] for j in range(2,(N//(i+1))+1)]
r=reduce(lambda a, b: int(a==b), R)
l=not(int(r)) if A[i]==1 else int(r)
if l==1:
cnt+=1
ans.append(i+1)
print(cnt)
print(" ".join(map(str, ans)))
|
s448274223
|
Accepted
| 608
| 22,584
| 519
|
N = int(input())
A = list(map(int, input().split()))
ans=[]
cnt=0
B = [0 for i in range(N)]
import math
for i in range(math.floor(N/2),N):
B[i]=A[i]
if(A[i]==1):
cnt+=1
ans.append(i+1)
from functools import reduce
for i in range(math.floor(N/2)-1,-1,-1):
R=[B[(i+1)*j-1] for j in range(2,(N//(i+1))+1)]
r=sum(R)%2
l = int(not (r)) if A[i]==1 else int(r)
B[i]=l
if l==1:
cnt+=1
ans.append(i+1)
print(cnt)
if cnt>0:
print(" ".join(map(str, ans)))
|
s095902706
|
p03478
|
u607139498
| 2,000
| 262,144
|
Wrong Answer
| 757
| 3,064
| 364
|
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).
|
# -*- coding: utf-8 -*-
# Some Sums
def calcSumOfDigits(n):
sum = 0
while n > 0:
sum += n % 10
n /= 10
return sum
a = list(map(int, input().split()))
N = a[0]
A = a[1]
B = a[2]
total = 0
for i in range(N):
sumOfDigits = calcSumOfDigits(i+1)
if sumOfDigits >= A and sumOfDigits <= B:
total += sumOfDigits
print(total)
|
s516618125
|
Accepted
| 26
| 3,064
| 477
|
# -*- coding: utf-8 -*-
# Some Sums
def calcSumOfDigits(n):
sum = 0
while n > 0:
sum += n % 10
# print(sum)
n = n // 10
return sum
a = list(map(int, input().split()))
N = a[0]
A = a[1]
B = a[2]
total = 0
for i in range(N):
sumOfDigits = calcSumOfDigits(i+1)
# print("sumOfDigits: ", sumOfDigits)
if sumOfDigits >= A and sumOfDigits <= B:
# print("N: ", i+1)
total += i+1
print(total)
|
s529520687
|
p03386
|
u612721349
| 2,000
| 262,144
|
Wrong Answer
| 2,232
| 2,063,384
| 123
|
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, x = map(int, input().split())
l = [i for i in range(a, b+1)]
for i in l:
if i <= a + x and b - x <= i:
print(i)
|
s783107595
|
Accepted
| 17
| 3,060
| 206
|
a, b, x = map(int, input().split())
s = set()
for i in [j for j in range(a, min(b + 1, a + x))] :
print(i)
s.add(i)
for i in [j for j in range(max(a, b - x + 1), b + 1)] :
if i not in s:
print(i)
|
s661358521
|
p03657
|
u904945034
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,156
| 111
|
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
|
a,b = map(int,input().split())
print("Possible" if a % 3 == 0 or b % 3 == 0 or a+b % 3 == 0 else "Impossible")
|
s184009034
|
Accepted
| 25
| 9,084
| 113
|
a,b = map(int,input().split())
print("Possible" if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0 else "Impossible")
|
s375407404
|
p03377
|
u377036395
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 87
|
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 <= x <= a + b:
print("Yes")
else:
print("No")
|
s805259644
|
Accepted
| 17
| 2,940
| 90
|
a, b, x = map(int, input().split())
if a <= x <= a + b:
print("YES")
else:
print("NO")
|
s913696612
|
p03471
|
u644126199
| 2,000
| 262,144
|
Wrong Answer
| 24
| 3,192
| 1,062
|
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.
|
line = input().split()
sheet = int(line[0])
total =int(line[1])
total_store =total
out = [0,0,0]
sheet_count =0
for i in range(sheet):
switch_10000 =0
switch_5000 =0
if int(total /10000 )>0 and sheet_count <sheet:
total -=10000
sheet_count +=1
out[0] +=1
switch_10000 +=1
if int(total/5000)>0 and sheet_count <sheet and switch_10000 ==0:
total -=5000
sheet_count +=1
out[1] +=1
switch_5000 +=1
if int(total/1000)>0 and sheet_count <sheet and switch_10000 ==0 and switch_5000 ==0:
total -=1000
sheet_count +=1
out[2] +=1
if out[0]*10000+out[1]*5000+out[2]*1000 ==total_store:
if sum(out)==sheet:
print(out)
else:
out[0] =0
out[1] =0
out[2] =int(total_store/1000)
cnt =0
while sum(out) !=sheet_count and out[2]>=0:
out[2] -=5
out[1] +=1
cnt +=1
if sum(out)==sheet and out[2]>=0:
print(out)
if cnt%2==0:
out[1] -=2
out[0] +=1
if sum(out)==sheet and out[2]>=0:
print(out)
else:
print(-1,-1,-1)
|
s271294955
|
Accepted
| 20
| 3,064
| 612
|
line = input().split()
sheet = int(line[0])
total = int(line[1])
out =[0,0,0]
cnt =0
for x in range(1,int(total/10000)+1):
if (int((total/1000))-sheet-9*x) %4 ==0:
y =int((int(total/1000)-sheet-9*x)/4)
z =sheet - y - x
if x + y + z ==sheet and z>=0 and y>=0 and cnt ==0:
cnt +=1
print(x,y,z)
for y in range(1,int(total/5000)+1):
z =int(total/1000)-5*y
if z>=0 and y + z ==sheet and cnt==0:
cnt +=1
print(0,y,z)
if total/1000 ==sheet and cnt==0:
cnt +=1
print(0,0,int(total/1000))
if cnt ==0:
print(-1,-1,-1)
|
s140836105
|
p02821
|
u508486691
| 2,000
| 1,048,576
|
Wrong Answer
| 973
| 36,312
| 1,213
|
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
|
import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
if N<=0:
return [[] for _ in range(num)]
elif num==1:
return [I() for _ in range(N)]
else:
read_all = [tuple(II()) for _ in range(N)]
return map(list, zip(*read_all))
#################
# FFT
# use python3
# a = np.array([a1,a2,a3]), b= np.array([b1,b2,b3])
# c = np.array([a1b1,a1b2+a2b1,a1a3+a2b2+a3b1,a2b3+a3b2,a3b3])
import numpy as np
def Convolution(a,b):
bit = (len(a)+len(b)-2).bit_length()
L = 2**bit
fa,fb = np.fft.rfft(a,L), np.fft.rfft(b,L)
c = np.rint(np.fft.irfft(fa*fb,L)).astype(np.int64)
return c[:len(a)+len(b)-1]
N,M = II()
A = III()
print('time test')
h = [0]*(max(A))
for a in A:
h[a-1] += 1
conv = np.append([0,0],Convolution(h,h))
ans = 0
count = 0
for k in range(2,2*max(A)+1)[::-1]:
if conv[k]:
num = min(M-count,conv[k])
count += num
ans += k*num
if count==M:
break
print(ans)
|
s375796945
|
Accepted
| 646
| 35,928
| 1,156
|
import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
if N<=0:
return [[] for _ in range(num)]
elif num==1:
return [I() for _ in range(N)]
else:
read_all = [tuple(II()) for _ in range(N)]
return map(list, zip(*read_all))
#################
# FFT
# use python3
# a = [a1,a2,a3], b= [b1,b2,b3]
# return np.array([a1b1,a1b2+a2b1,a1a3+a2b2+a3b1,a2b3+a3b2,a3b3])
import numpy as np
def Convolution(a,b):
bit = (len(a)+len(b)-2).bit_length()
L = 2**bit
fa,fb = np.fft.rfft(a,L), np.fft.rfft(b,L)
c = np.rint(np.fft.irfft(fa*fb,L)).astype(np.int64)
return c[:len(a)+len(b)-1]
N,M = II()
A = III()
h = [0]*(max(A))
for a in A:
h[a-1] += 1
conv = np.append([0,0],Convolution(h,h))
ans = 0
for k in range(2,2*max(A)+1)[::-1]:
if conv[k]<M:
ans += k*conv[k]
M -= conv[k]
else:
ans += k*M
break
print(ans)
|
s116051433
|
p03712
|
u102960641
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 102
|
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
|
h,w = map(int, input().split())
print("#"*w)
for i in range(h):
print("#"+input()+"#")
print("#"*w)
|
s603212170
|
Accepted
| 18
| 2,940
| 110
|
h,w = map(int, input().split())
print("#"*(w+2))
for i in range(h):
print("#"+input()+"#")
print("#"*(w+2))
|
s712125378
|
p00006
|
u175111751
| 1,000
| 131,072
|
Wrong Answer
| 40
| 7,344
| 29
|
Write a program which reverses a given string str.
|
print(str(reversed(input())))
|
s551470230
|
Accepted
| 20
| 7,260
| 20
|
print(input()[::-1])
|
s282162483
|
p02255
|
u083560765
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,588
| 150
|
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=list(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)
|
s740322683
|
Accepted
| 20
| 5,604
| 175
|
n=int(input())
a=list(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(' '.join(list(map(str,a))))
|
s080185091
|
p03139
|
u532966492
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 57
|
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
|
a,b,c=map(int,input().split())
print(min(c,a+b),min(a,b))
|
s066256191
|
Accepted
| 17
| 2,940
| 59
|
a,b,c=map(int,input().split())
print(min(b,c),max(0,b+c-a))
|
s675122690
|
p02742
|
u493555013
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 84
|
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
|
H,W = map(int,input().split())
if H*W/2 == 0:
print(H*W/2)
else:
print(H*W//2+1)
|
s144823509
|
Accepted
| 17
| 2,940
| 143
|
H,W = map(int,input().split())
if H==1 or W==1:
print(int(1))
else:
if H*W%2 == 0:
print(int(H*W/2))
else:
print(int(H*W//2+1))
|
s275040773
|
p02694
|
u842028864
| 2,000
| 1,048,576
|
Wrong Answer
| 22
| 9,416
| 114
|
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?
|
goal = int(input())
count = 0
money = 100
while money < goal:
count += 1
money = int(money**1.01)
print(count)
|
s858128867
|
Accepted
| 19
| 9,148
| 113
|
goal = int(input())
count = 0
money = 100
while money < goal:
count += 1
money = int(money*1.01)
print(count)
|
s662412917
|
p03448
|
u001207659
| 2,000
| 262,144
|
Wrong Answer
| 51
| 2,940
| 222
|
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.
|
s1, s2, s3, total =[int(input()) for h in range(4)]
ans = 0
for i in range(s1+1):
for j in range(s2+1):
for k in range(s3+1):
if 500*s1 + 100*s2 + 50*s3 == total:
ans += 1
print(ans)
|
s342447047
|
Accepted
| 50
| 3,060
| 212
|
a, b, c, x = [int(input()) for _ in range(4)]
ans = 0
for i in range(a+1):
for j in range(b+1):
for k in range(c+1):
if 500 * i + 100 * j + 50 * k == x:
ans += 1
print(ans)
|
s266367790
|
p03401
|
u086503932
| 2,000
| 262,144
|
Wrong Answer
| 210
| 14,048
| 397
|
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
|
N = int(input())
A = list(map(int, input().split()))
A.append(0)
ans = abs(0 - A[0])
for i in range(N):
ans += abs(A[i] - A[i+1])
for i in range(N):
if i == 0:
if A[0] * A[1] >= 0:
print(ans)
else:
print(ans - 2*abs(A[0]))
else:
if (A[i] - A[i-1]) * (A[i+1] - A[i]) >= 0:
print(ans)
else:
print(ans - 2*abs(A[i] - A[i-1]))
|
s385358973
|
Accepted
| 203
| 14,048
| 312
|
N = int(input())
A = list(map(int, input().split()))
A.append(0)
ans = [None] * (N+1)
ans[0] = abs(0 - A[0])
for i in range(N):
ans[i+1] = abs(A[i] - A[i+1])
ansS = sum(ans)
for i in range(N):
if i == 0:
tmp = abs(A[1])
else:
tmp = abs(A[i+1] - A[i-1])
print(ansS - ans[i] - ans[i+1] + tmp)
|
s095667691
|
p02613
|
u602481141
| 2,000
| 1,048,576
|
Wrong Answer
| 147
| 16,200
| 386
|
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.
|
AC = WA = TLE = RE = 0
N = int(input())
s = [input() for i in range(N)]
for v in s:
if(v == "AC"):
AC+=1
elif(v == "WA"):
WA+=1
elif(v == "TLE"):
TLE+=1
else:
RE+=1
print('AC x %d' % (AC))
print('AC x %d' % (WA))
print('AC x %d' % (TLE))
print('AC x %d' % (RE))
|
s314054818
|
Accepted
| 148
| 16,168
| 387
|
AC = WA = TLE = RE = 0
N = int(input())
s = [input() for i in range(N)]
for v in s:
if(v == "AC"):
AC+=1
elif(v == "WA"):
WA+=1
elif(v == "TLE"):
TLE+=1
else:
RE+=1
print('AC x %d' % (AC))
print('WA x %d' % (WA))
print('TLE x %d' % (TLE))
print('RE x %d' % (RE))
|
s134088666
|
p03050
|
u268516119
| 2,000
| 1,048,576
|
Wrong Answer
| 139
| 3,060
| 136
|
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
|
import math
N=int(input())
root=math.ceil(math.sqrt(N)-1)
ans=0
for i in range(1,root):
if not N%i:
ans+=(N//i-1)
print(ans)
|
s146981847
|
Accepted
| 134
| 3,060
| 157
|
import math
N=int(input())
root=math.ceil(math.sqrt(N))
ans=0
for i in range(1,root):
if not N%i:
if N//i>i+1:
ans+=N//i-1
print(ans)
|
s079520067
|
p03378
|
u785578220
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 243
|
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
|
n,m,x = map(int,input().split())
y = list(map(int,input().split()))
s = 0
cs = 0
t = 0
for i in y:
if x > i:
s+=1
elif x == i:
cs=0
else:
t+=1
if t>s and cs!=0:
print(s)
elif t<=s and cs!=0:
print(t)
|
s142727388
|
Accepted
| 19
| 2,940
| 141
|
a,b,c= map(int, input().split())
p = list(map(int, input().split()))
k = 0
for i in range(b):
if p[i] < c:
k+=1
print(min(k,b-k))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.