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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s611398518
|
p03352
|
u545411641
| 2,000
| 1,048,576
|
Time Limit Exceeded
| 2,104
| 2,940
| 289
|
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# from numpy import array, sum
MAX_DIVIDER = 32 # 32 ** 2 = 1024 > 1000
X =int(input())
li = set()
b = 1
while b < MAX_DIVIDER:
c = b * b
while c < 1000:
li.add(c)
c *= b
while X > 0:
if X in li:
print(X)
break
else:
X -= 1
|
s674891567
|
Accepted
| 17
| 2,940
| 309
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# from numpy import array, sum
MAX_DIVIDER = 32 # 32 ** 2 = 1024 > 1000
X =int(input())
li = set()
li.add(1)
b = 2
while b < MAX_DIVIDER:
c = b * b
while c <= 1000:
li.add(c)
c *= b
b += 1
while X > 0:
if X in li:
print(X)
break
else:
X -= 1
|
s465609807
|
p02747
|
u886286585
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 88
|
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
|
S = input()
hi = S.replace('hi', '')
if hi == "":
print("yes")
else:
print("No")
|
s901405188
|
Accepted
| 17
| 2,940
| 88
|
S = input()
hi = S.replace('hi', '')
if hi == "":
print("Yes")
else:
print("No")
|
s841996607
|
p03370
|
u140251125
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 149
|
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
|
N, X = map(int, input().split())
m_list = [int(input()) for i in range(N)]
X = X - sum(m_list)
m_list.sort()
n_max = X // m_list[0]
print(n_max)
|
s047858479
|
Accepted
| 17
| 2,940
| 153
|
N, X = map(int, input().split())
m_list = [int(input()) for i in range(N)]
X = X - sum(m_list)
m_list.sort()
n_max = X // m_list[0]
print(n_max + N)
|
s046443065
|
p03610
|
u022683706
| 2,000
| 262,144
|
Wrong Answer
| 24
| 4,340
| 77
|
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
|
input = str(input())
word = [x for x in input]
word = word[::2]
print(word)
|
s764053915
|
Accepted
| 27
| 4,340
| 123
|
input = str(input())
word = [x for x in input]
word = word[::2]
output = ""
for i in word:
output += i
print(output)
|
s666730713
|
p02415
|
u587193722
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,328
| 22
|
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
|
print(input().upper())
|
s370724817
|
Accepted
| 20
| 7,392
| 25
|
print(input().swapcase())
|
s765136723
|
p04029
|
u970197315
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 159
|
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
print((n*(n+1))/2)
|
s390102978
|
Accepted
| 17
| 2,940
| 164
|
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
print(int((n*(n+1))/2))
|
s428695294
|
p03919
|
u366959492
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 221
|
There is a grid with H rows and W columns. The square at the i-th row and j-th column contains a string S_{i,j} of length 5. The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet. Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location. For example, the square at the 6-th row and 8-th column should be reported as `H6`.
|
h,w=map(int,input().split())
l=[list(input().split()) for _ in range(h)]
print(l)
for i in range(h):
for j in range(w):
if l[i][j]=="snuke":
print(str(chr(ord("A")+j))+str(i+1))
exit()
|
s997019451
|
Accepted
| 17
| 3,060
| 212
|
h,w=map(int,input().split())
l=[list(input().split()) for _ in range(h)]
for i in range(h):
for j in range(w):
if l[i][j]=="snuke":
print(str(chr(ord("A")+j))+str(i+1))
exit()
|
s106806472
|
p03487
|
u731436822
| 2,000
| 262,144
|
Wrong Answer
| 2,109
| 23,260
| 192
|
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
|
import numpy as np
N = int(input())
A = list(map(int,input().split()))
counter = 0
AN = set(A)
A = np.array(A)
for i in AN:
num = len(A[A < i])
counter += abs(num - i)
print(counter)
|
s646591793
|
Accepted
| 102
| 23,412
| 241
|
N = int(input())
A = list(map(int,input().split()))
NA = set(A)
d = {x:0 for x in NA}
for i in range(N):
d[A[i]] += 1
counter = 0
for p in d:
if p > d[p]:
counter += d[p]
else:
counter += d[p]-p
print(counter)
|
s560256431
|
p03380
|
u572012241
| 2,000
| 262,144
|
Wrong Answer
| 117
| 14,428
| 545
|
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
|
def pow(x, n , mod):
res = 1
while n > 0:
if bin(n & 1) == bin(1) :
res = res * x % mod
x = x*x % mod
n = n >>1
return res
def combination(n,a):
x = 1
for i in range(a):
x = x * (n-i) % mod
y = 1
for i in range(a):
y = y * (a-i) % mod
y = pow(y, mod-2, mod)
return (x*y % mod)
n = int(input())
a = list(map(int, input().split()))
mod =1
m = max(a)
a = sorted(a)
ans = 0
for i in a:
if abs(m//2-i) < abs(m//2-ans):
ans = i
print(m, ans)
|
s740098308
|
Accepted
| 120
| 14,052
| 165
|
n = int(input())
a = list(map(int, input().split()))
m = max(a)
a = sorted(a)
ans = 0
for i in a:
if abs(m/2-i) < abs(m/2-ans):
ans = i
print(m, ans)
|
s418031523
|
p04030
|
u687470137
| 2,000
| 262,144
|
Wrong Answer
| 39
| 3,064
| 224
|
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
|
s = input()
ans = ""
for c in s:
print(ans)
if c == '0':
ans = ans + '0'
elif c == '1':
ans = ans + '1'
elif c == 'B':
if len(ans) != 0:
ans = ans[0:len(ans)-1]
print(ans)
|
s574002254
|
Accepted
| 39
| 3,064
| 208
|
s = input()
ans = ""
for c in s:
if c == '0':
ans = ans + '0'
elif c == '1':
ans = ans + '1'
elif c == 'B':
if len(ans) != 0:
ans = ans[0:len(ans)-1]
print(ans)
|
s709271120
|
p02972
|
u671861352
| 2,000
| 1,048,576
|
Wrong Answer
| 325
| 21,312
| 342
|
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()))
b = [0] * (N + 1)
half = N // 2
b[half + 2:] = A[half + 1:]
for i in range(half, 1, -1):
s = sum([b[j]for j in range(i * 2, N + 1, i)]) % 2
if s != A[i]:
b[i] = 1
s = sum(b)
if s % 2 != A[0]:
b[1] = 1
s += 1
print(s)
if s != 0:
print(" ".join(map(str, b[1:])))
|
s869355125
|
Accepted
| 356
| 13,108
| 345
|
N = int(input())
A = list(map(int, input().split()))
b = [0] * (N + 1)
half = N // 2
b[half + 1:] = A[half:]
for i in range(half, 1, -1):
s = sum([b[j] for j in range(i * 2, N + 1, i)]) % 2
if s != A[i - 1]:
b[i] = 1
s = sum(b)
if s % 2 != A[0]:
b[1] = 1
s += 1
print(s)
print(*[i for i in range(1, N + 1) if b[i] == 1])
|
s044681042
|
p02842
|
u697559326
| 2,000
| 1,048,576
|
Wrong Answer
| 35
| 3,064
| 113
|
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())
for i in range(1,50001):
if int(i*1.08) == N:
print(i)
elif i == 50000:
print(":(")
|
s084356478
|
Accepted
| 37
| 2,940
| 153
|
N = int(input())
flag = 0
for i in range(1,50001):
if int(i*1.08) == N:
print(i)
flag = 1
elif (flag == 0) and (i == 50000):
print(":(")
|
s475452838
|
p03737
|
u790710233
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 50
|
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
|
for s in input().split():
print(s[0], end="")
|
s616928961
|
Accepted
| 18
| 2,940
| 54
|
print(''.join(x[0].upper() for x in input().split()))
|
s071284118
|
p03693
|
u469953228
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 131
|
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?
|
r,g,b=(int(i) for i in input().split())
a = g*10+b
if a == 25 or a == 50 or a == 75 or a ==100:
print('YES')
else:
print('NO')
|
s226572703
|
Accepted
| 19
| 2,940
| 96
|
r,g,b=(int(i) for i in input().split())
a = g*10+b
if a%4==0:
print('YES')
else:
print('NO')
|
s692190968
|
p03680
|
u325264482
| 2,000
| 262,144
|
Wrong Answer
| 208
| 9,128
| 234
|
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
|
N = int(input())
A = [int(input()) for i in range(N)]
def push(i):
return A[i] - 1
print(A)
index = 0
cnt = 0
for _ in range(N):
index = push(index)
cnt += 1
if index == 1:
print(cnt)
exit()
print(-1)
|
s619608997
|
Accepted
| 202
| 7,084
| 224
|
N = int(input())
A = [int(input()) for i in range(N)]
def push(i):
return A[i] - 1
index = 0
cnt = 0
for _ in range(N):
index = push(index)
cnt += 1
if index == 1:
print(cnt)
exit()
print(-1)
|
s675443219
|
p03828
|
u013408661
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,104
| 3,064
| 346
|
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
def check_sosu(x):
for i in range(2,x//2+1):
if x%i==0:
return False
return True
sosu=[]
for i in range(1,10**3+1):
if check_sosu(i):
sosu.append(i)
n=int(input())
ans=1
p=10**9+7
for i in sosu:
if i<=n:
stack=0
num=i
while num<=n:
stack+=n//num
num*=i
ans*=(stack+1)
ans%=p
print(ans)
|
s322723909
|
Accepted
| 19
| 3,188
| 987
|
sosu=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
n=int(input())
ans=1
p=10**9+7
for i in sosu:
if i<=n:
stack=0
num=i
while num<=n:
stack+=n//num
num*=i
ans*=(stack+1)
ans%=p
print(ans)
|
s580053024
|
p03369
|
u944209426
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 41
|
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
|
s = input()
x = s.count('o')
print(x*100)
|
s910045508
|
Accepted
| 17
| 2,940
| 46
|
s = input()
x = s.count('o')
print(700+x*100)
|
s994853576
|
p03377
|
u095396110
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,076
| 94
|
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')
|
s377338563
|
Accepted
| 25
| 8,868
| 88
|
a, b, x = map(int, input().split())
if a<=x<=a+b:
print('YES')
else:
print('NO')
|
s154439786
|
p03023
|
u495903598
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 145
|
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
|
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import sys
#input = sys.stdin.readline
#A, B = map(int, input().split())
180*(int(input())-2)
|
s175691197
|
Accepted
| 19
| 2,940
| 152
|
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import sys
#input = sys.stdin.readline
#A, B = map(int, input().split())
print(180*(int(input())-2))
|
s041774998
|
p02927
|
u759938562
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,188
| 354
|
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
|
tmp = input().split()
m = tmp[0]
d = tmp[1]
count = 0
for i in range(1, int(d)+1):
if len(str(i)) == 2:
d1 = int(str(i)[0])
d2 = int(str(i)[1])
if d1 >= 2 and d2 >= 2:
tmp = d1 * d2
# print(tmp)
if tmp in range(1, int(m)+1):
print(i)
count += 1
print(count)
|
s698736712
|
Accepted
| 18
| 3,064
| 523
|
tmp = input().split()
m = tmp[0]
d = tmp[1]
if 1 <= int(m) and int(m) <= 100:
if 1 <= int(d) and int(d) <= 99:
count = 0
for i in range(1, int(d)+1):
if len(str(i)) == 2:
d1 = int(str(i)[0])
d2 = int(str(i)[1])
if d1 >= 2 and d2 >= 2:
tmp = d1 * d2
# print(tmp)
if tmp in range(1, int(m)+1):
# print(i)
count += 1
print(count)
|
s198272302
|
p03713
|
u368796742
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 212
|
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
|
h,w = map(int,input().split())
ans = min(h,w)
if w%3 == 1:
a = w//3
else:
a = w//3+1
c = abs(h*a-(h//2)*(w-a))
if h % 3== 1:
b = h//3
else:
b = h//3+1
d = abs(w*b-(w//2)*(h-b))
print(min(ans,c,d))
|
s928461272
|
Accepted
| 17
| 3,064
| 393
|
h,w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
print(0)
exit()
ans = min(h,w)
if w%3 == 1:
a = w//3
else:
a = w//3+1
c = max(h*a,(h//2)*(w-a),h*(w-a)-(h//2)*(w-a))-min(h*a,(h//2)*(w-a),h*(w-a)-(h//2)*(w-a))
if h % 3== 1:
b = h//3
else:
b = h//3+1
d = max(w*b,(w//2)*(h-b),w*(h-b)-(w//2)*(h-b))-min(w*b,(w//2)*(h-b),w*(h-b)-(w//2)*(h-b))
print(min(ans,c,d))
|
s432593250
|
p03151
|
u357751375
| 2,000
| 1,048,576
|
Wrong Answer
| 94
| 24,252
| 242
|
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
|
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = 0
y = 0
for i in range(n):
if a[i] >= b[i]:
x += a[i] - b[i]
else:
y += b[i] - a[i]
if x >= y:
print(y)
else:
print(-1)
|
s780999895
|
Accepted
| 114
| 24,288
| 364
|
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
t = []
ans = 0
for i in range(n):
if a[i] < b[i]:
c += b[i] - a[i]
ans += 1
else:
t.append(a[i]-b[i])
t.sort(reverse=True)
i = 0
while c > 0 and i < len(t):
ans += 1
c -= t[i]
i += 1
if c > 0:
print(-1)
else:
print(ans)
|
s824466234
|
p02659
|
u298376876
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 9,096
| 45
|
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
a, b = map(float, input().split())
round(a*b)
|
s960682742
|
Accepted
| 25
| 9,872
| 143
|
from decimal import *
a, b = map(str, input().split())
num = (Decimal(a) * Decimal(b)).quantize(Decimal('1'), rounding=ROUND_DOWN)
print(num)
|
s289771388
|
p03486
|
u004423772
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 144
|
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 = input().rstrip('\r')
t = input().rstrip('\r')
s = "".join(sorted(s))
t = "".join(sorted(t))
if s < t:
print('Yes')
else:
print('No')
|
s023166032
|
Accepted
| 17
| 2,940
| 158
|
s = input().rstrip('\r')
t = input().rstrip('\r')
s = "".join(sorted(s))
t = "".join(sorted(t, reverse=True))
if s < t:
print('Yes')
else:
print('No')
|
s163612436
|
p03637
|
u178509296
| 2,000
| 262,144
|
Wrong Answer
| 65
| 15,020
| 265
|
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
|
N = int(input())
a = list(map(int, input().split()))
Nodd = len([x for x in a if x%2 == 1])
Neven = len([x for x in a if x%2 == 0])
Nfour = len([x for x in a if x%4 == 0])
if Nodd <= Nfour or (Nodd+Nfour==N and Nodd-Nfour==1):
print("yes")
else:
print("no")
|
s051975864
|
Accepted
| 65
| 14,252
| 265
|
N = int(input())
a = list(map(int, input().split()))
Nodd = len([x for x in a if x%2 == 1])
Neven = len([x for x in a if x%2 == 0])
Nfour = len([x for x in a if x%4 == 0])
if Nodd <= Nfour or (Nodd+Nfour==N and Nodd-Nfour==1):
print("Yes")
else:
print("No")
|
s120615656
|
p03472
|
u711539583
| 2,000
| 262,144
|
Wrong Answer
| 350
| 23,120
| 411
|
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
|
import sys
input = sys.stdin.readline
n, h = map(int, input().split())
ab = []
for i in range(n):
a, b = map(int, input().split())
ab.append((-a, b, i))
ab.sort()
index = ab[0][2]
ab2 = ab[:]
ab2.sort(key = lambda x:x[1])
cnt = 0
for a, b ,i in ab2:
if h <= 0:
print(cnt)
sys.exit()
a = -a
if i == index:
print(cnt+(h - b + a - 1) // a)
sys.exit()
else:
h -= b
cnt += 1
|
s335469100
|
Accepted
| 361
| 23,116
| 552
|
import sys
input = sys.stdin.readline
n, h = map(int, input().split())
ab = []
for i in range(n):
a, b = map(int, input().split())
ab.append((-a, b, i))
ab.sort()
index = ab[0][2]
ai = -ab[0][0]
bi = ab[0][1]
ab2 = ab[:]
ab2.sort(key = lambda x:x[1], reverse = True)
cnt = 0
for a, b, i in ab2:
if i == index:
continue
if b < ai:
break
if h <= bi:
print(cnt+1)
sys.exit()
h -= b
cnt += 1
if h <= 0:
print(cnt)
sys.exit()
print(cnt + 1 + max(0, h - bi + ai - 1) // ai)
|
s361590385
|
p03644
|
u574464625
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 241
|
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
N=int(input())
c=4
d=7
ans=0
ans2=0
ans3="No"
for i in range(15):
ans=d*i
if ans !=N:
for j in range(26):
ans2=ans+c*j
if ans2==N:
ans3="Yes"
else :
ans3="Yes"
print(ans3)
|
s833696166
|
Accepted
| 17
| 3,060
| 216
|
#Break Number
n=int(input())
if n >=64:
print(64)
elif 64>n >=32:
print(32)
elif 32>n >=16:
print(16)
elif 16>n >=8:
print(8)
elif 8>n >=4:
print(4)
elif 4>n >=2:
print(2)
else :
print(1)
|
s618146854
|
p03548
|
u612721349
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 62
|
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
|
x, y, z = map(int, input().split())
z -= y
print(z // (x + y))
|
s614581468
|
Accepted
| 17
| 2,940
| 63
|
x, y, z = map(int, input().split())
x -= z
print(x // (y + z))
|
s771081070
|
p02659
|
u695474809
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 9,160
| 83
|
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
import math
a,b= input().split()
a = int(a)
b = float(b)
c = a*b
print(round(c))
|
s987225046
|
Accepted
| 29
| 9,080
| 94
|
import math
A,B = input().split()
A = int(A)
B = round(float(B)*100)
ans = A*B
print(ans//100)
|
s477475486
|
p03156
|
u604398799
| 2,000
| 1,048,576
|
Wrong Answer
| 1,188
| 23,684
| 2,005
|
You have written N problems to hold programming contests. The i-th problem will have a score of P_i points if used in a contest. With these problems, you would like to hold as many contests as possible under the following condition: * A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points. The same problem should not be used in multiple contests. At most how many contests can be held?
|
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 20:43:52 2019
@author: Owner
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 20:43:41 2019
@author: Owner
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 29 18:42:51 2018
@author: Owner
"""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(int(i))
i += 1
if n > 1:
table.append(int(n))
return table
def digit(i):
if i > 0:
return digit(i//10) + [i%10]
else:
return []
"""
N, X = map(int, input().split())
x = [0]*N
x[:] = map(int, input().split())
P = [0]*M
Y = [0]*M
for m in range(M):
P[m], Y[m] = map(int, input().split())
all(nstr.count(c) for c in '753')
"""# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 20:43:41 2019
@author: Owner
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 29 18:42:51 2018
@author: Owner
"""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(int(i))
i += 1
if n > 1:
table.append(int(n))
return table
def digit(i):
if i > 0:
return digit(i//10) + [i%10]
else:
return []
"""
N, X = map(int, input().split())
x = [0]*N
x[:] = map(int, input().split())
P = [0]*M
Y = [0]*M
for m in range(M):
P[m], Y[m] = map(int, input().split())
all(nstr.count(c) for c in '753')
"""
N = int(input())
A, B = map(int, input().split())
P = [0]*N
P[:] = map(int, input().split())
P.sort()
print(P)
num1 = len([i for i in P if i <= A])
num3 = len([i for i in P if i >= B+1])
num2 = N-num1-num3
num = min(num1, num2, num3)
print(num)
|
s903543649
|
Accepted
| 1,398
| 24,652
| 1,996
|
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 20:43:52 2019
@author: Owner
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 20:43:41 2019
@author: Owner
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 29 18:42:51 2018
@author: Owner
"""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(int(i))
i += 1
if n > 1:
table.append(int(n))
return table
def digit(i):
if i > 0:
return digit(i//10) + [i%10]
else:
return []
"""
N, X = map(int, input().split())
x = [0]*N
x[:] = map(int, input().split())
P = [0]*M
Y = [0]*M
for m in range(M):
P[m], Y[m] = map(int, input().split())
all(nstr.count(c) for c in '753')
"""# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 20:43:41 2019
@author: Owner
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 29 18:42:51 2018
@author: Owner
"""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(int(i))
i += 1
if n > 1:
table.append(int(n))
return table
def digit(i):
if i > 0:
return digit(i//10) + [i%10]
else:
return []
"""
N, X = map(int, input().split())
x = [0]*N
x[:] = map(int, input().split())
P = [0]*M
Y = [0]*M
for m in range(M):
P[m], Y[m] = map(int, input().split())
all(nstr.count(c) for c in '753')
"""
N = int(input())
A, B = map(int, input().split())
P = [0]*N
P[:] = map(int, input().split())
P.sort()
num1 = len([i for i in P if i <= A])
num3 = len([i for i in P if i >= B+1])
num2 = N-num1-num3
num = min(num1, num2, num3)
print(num)
|
s924131694
|
p02613
|
u425184437
| 2,000
| 1,048,576
|
Wrong Answer
| 150
| 9,204
| 268
|
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
n=int(input())
ac=0
tle=0
wa=0
re=0
for i in range(n):
s=input()
if s=='AC':
ac+=1
elif s=='TLE':
tle+=1
elif s=='WA':
wa+=1
elif s=='RE':
re+=1
print('AC × '+str(ac))
print('WA × '+str(wa))
print('TLE × '+str(tle))
print('RE × '+str(re))
|
s712150039
|
Accepted
| 150
| 9,208
| 264
|
n=int(input())
ac=0
tle=0
wa=0
re=0
for i in range(n):
s=input()
if s=='AC':
ac+=1
elif s=='TLE':
tle+=1
elif s=='WA':
wa+=1
elif s=='RE':
re+=1
print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))
|
s158158289
|
p03814
|
u691896522
| 2,000
| 262,144
|
Wrong Answer
| 54
| 3,560
| 181
|
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
|
s = input()
A_index = 0
Z_index = 0
for i in range(len(s)):
if s[i] == 'A':
A_index = i
if s[i] == 'Z':
Z_index = i
break
print(s[A_index:Z_index+1])
|
s349466310
|
Accepted
| 22
| 4,840
| 135
|
s = input()
A_index = s.index('A')
s = list(s)
s.reverse()
s = "".join(s)
Z_index = len(s) - s.index('Z')
print(Z_index - A_index)
|
s506514074
|
p03730
|
u000040786
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,152
| 100
|
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
|
a, b, c = map(int, input().split())
print("Yes" if any((a*i)%b==c for i in range(1, b+1)) else "No")
|
s749077014
|
Accepted
| 28
| 8,920
| 100
|
a, b, c = map(int, input().split())
print("YES" if any((a*i)%b==c for i in range(1, b+1)) else "NO")
|
s273770761
|
p03164
|
u814986259
| 2,000
| 1,048,576
|
Wrong Answer
| 1,363
| 5,212
| 499
|
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
|
def main():
import sys
input = sys.stdin.readline
N, W = map(int, input().split())
wv = [tuple(map(int, input().split())) for i in range(N)]
dp = [-1]*(10**3 * N + 1)
dp[0] = 0
ans = 0
for w, v in wv:
for j in range(10**3 * N - v, -1, -1):
if dp[j] >= 0 and dp[j] + w <= W:
if dp[j+v] < dp[j] + w:
dp[j+v] = dp[j] + w
if ans < j+w:
ans = j+v
print(ans)
main()
|
s795996641
|
Accepted
| 1,595
| 5,344
| 508
|
def main():
import sys
input = sys.stdin.readline
N, W = map(int, input().split())
wv = [tuple(map(int, input().split())) for i in range(N)]
dp = [-1]*(10**3 * N + 1)
dp[0] = 0
ans = 0
for w, v in wv:
for j in range((10**3 * N) - v, -1, -1):
if dp[j] >= 0 and dp[j] + w <= W:
if dp[j+v] < 0 or dp[j+v] > dp[j] + w:
dp[j+v] = dp[j] + w
if ans < j+v:
ans = j+v
print(ans)
main()
|
s229562962
|
p03050
|
u365364616
| 2,000
| 1,048,576
|
Wrong Answer
| 229
| 3,060
| 123
|
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
|
n = int(input())
ans = 0
for i in range(1, int(n ** 0.5)):
if (n - i) % i == 0:
ans += (n - i) // i
print(ans)
|
s268027439
|
Accepted
| 366
| 3,060
| 166
|
n = int(input())
ans = 0
for i in range(1, int(n ** 0.5) + 1):
if i * (i + 1) >= n:
break
if (n - i) % i == 0:
ans += (n - i) // i
print(ans)
|
s139561681
|
p03353
|
u966695319
| 2,000
| 1,048,576
|
Wrong Answer
| 2,270
| 2,111,516
| 473
|
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
|
s = str(input())
K = int(input())
substrings = set([])
for i in range(len(s) + 1):
for j in range(i + 1, len(s) + 1):
# print(i, j)
substrings.add(s[i:j])
# print(substrings)
substrings = sorted(sorted(substrings), key=len)
# print(substrings)
print(substrings[K - 1])
|
s110237848
|
Accepted
| 41
| 10,572
| 403
|
s = str(input())
K = int(input())
substrings = set([])
for i in range(5):
for j in range(len(s) - i):
# print(i, j)
substrings.add(s[j:j + i + 1])
# print(substrings)
print(sorted(substrings)[K - 1])
|
s979621715
|
p03760
|
u768559443
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 69
|
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
|
o=list(input())
e=list(input())
for x,y in zip(o,e):print(x+y,end="")
|
s515875518
|
Accepted
| 17
| 2,940
| 122
|
O = input()
E = input()
X = ""
for i in range(len(E)):
X += (O[i]+E[i])
if len(O) != len(E):
X += O[-1]
print(X)
|
s929818678
|
p03435
|
u095562538
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 560
|
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
|
n = 3
e = [[int(i) for i in input().split()] for i in range(n)]
for i in range(101):
a1 = i
b1 = e[0][0] - a1
b2 = e[0][1] - a1
b3 = e[0][2] - a1
a2 = e[1][0] - b1
a3 = e[2][0] - b1
if b1 < 0:
break
if b2 < 0:
break
if b3 < 0:
break
if a2 < 0:
break
if a3 < 0:
break
if a2+b2 != e[1][1]:
break
if a3+b2 != e[2][1]:
break
if a2+b3 != e[1][2]:
break
if a3+b3 != e[2][2]:
break
print("yes")
exit()
print("no")
|
s792845380
|
Accepted
| 17
| 3,064
| 424
|
# coding: utf-8
# Here your code
n = 3
e = [[int(i) for i in input().split()] for i in range(n)]
a = []
b = []
a.append(0)
b.append(e[0][0] - a[0])
b.append(e[0][1] - a[0])
b.append(e[0][2] - a[0])
a.append(e[1][0] - b[0])
a.append(e[2][0] - b[0])
for i in range(3):
for j in range(3):
if a[i] + b[j] != e[i][j]:
print("No")
exit()
print("Yes")
|
s708991738
|
p02607
|
u596797226
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 8,996
| 176
|
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
|
n = int(input())
string = input()
num_list = [int(i) for i in string.split()]
count = 0
for a, i in enumerate(num_list):
if a+1 % 2 == i % 2 == 1:
count += 1
print(count)
|
s951091713
|
Accepted
| 27
| 9,076
| 124
|
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(0,n,2):
if a[i] % 2 == 1:
ans += 1
print(ans)
|
s162802727
|
p03067
|
u055529891
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 91
|
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 a<=b<=c or c<=b<=a:
print('Yes')
else:
print('No')
|
s938853642
|
Accepted
| 17
| 2,940
| 91
|
a,b,c = map(int, input().split())
if a<=c<=b or b<=c<=a:
print('Yes')
else:
print('No')
|
s569001006
|
p02613
|
u229156891
| 2,000
| 1,048,576
|
Wrong Answer
| 144
| 16,616
| 238
|
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.
|
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
C = Counter(S)
print("AC × {}".format(C["AC"]))
print("WA × {}".format(C["WA"]))
print("TLE × {}".format(C["TLE"]))
print("RE × {}".format(C["RE"]))
|
s529699639
|
Accepted
| 140
| 16,612
| 234
|
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
C = Counter(S)
print("AC x {}".format(C["AC"]))
print("WA x {}".format(C["WA"]))
print("TLE x {}".format(C["TLE"]))
print("RE x {}".format(C["RE"]))
|
s983878934
|
p03624
|
u258469084
| 2,000
| 262,144
|
Wrong Answer
| 38
| 3,188
| 227
|
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
|
nlist = [None] * 150
stri = input()
for i in range(len(stri)):
ind = ord(stri[i])
nlist[ind] = 1
print(nlist)
for i in range(len(nlist)):
if nlist[i] == None and i > 96:
print(str(chr(i)))
break
|
s588915109
|
Accepted
| 29
| 3,188
| 337
|
nlist = [None] * 150
def main():
stri = input()
for i in range(len(stri)):
ind = ord(stri[i])
nlist[ind] = 1
for i in range(len(nlist)):
if nlist[i] == None and (i > 96 and i<123) :
print(str(chr(i)))
return
print("None")
if __name__== "__main__" : main()
|
s465944728
|
p03359
|
u711539583
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 83
|
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
|
a, b = map(int, input().split())
ans = a - 1
if b >= a:
ans += 1
print(ans + 1)
|
s180189808
|
Accepted
| 17
| 2,940
| 79
|
a, b = map(int, input().split())
ans = a - 1
if b >= a:
ans += 1
print(ans)
|
s533824645
|
p00004
|
u354053070
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,340
| 201
|
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
|
import sys
for line in sys.stdin:
a, b, c, d, e, f = list(map(float, line.split()))
x = (c * e - b * f) / (a * e - b * d)
y = (a * f - c * d) / (a * e - b * d)
print("{0:.3f} {1:.3f}")
|
s991666702
|
Accepted
| 30
| 7,272
| 224
|
import sys
for line in sys.stdin:
a, b, c, d, e, f = list(map(float, line.split()))
x = (c * e - b * f) / (a * e - b * d)
y = (a * f - c * d) / (a * e - b * d)
print("{0:.3f} {1:.3f}".format(x + 0., y + 0.))
|
s064534398
|
p02612
|
u978313283
| 2,000
| 1,048,576
|
Wrong Answer
| 27
| 9,116
| 34
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N=int(input())
print(1000-N//1000)
|
s131434019
|
Accepted
| 32
| 9,076
| 61
|
N=int(input())
ans=0 if N%1000==0 else 1000-N%1000
print(ans)
|
s493720936
|
p02614
|
u529737989
| 1,000
| 1,048,576
|
Wrong Answer
| 120
| 9,028
| 1,360
|
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
|
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 5 21:10:49 2020
@author: Aruto Hosaka
"""
H,W,K = map(int,input().split())
C = [input() for i in range(H)]
# H,W,K = 6,6,8
# C = ['..##..', '.#..#.', '#....#', '######', '#....#', '#....#']
# H,W,K = 6,6,8
# C = [['..##..'], ['.#..#.'], ['#....#'], ['######'], ['#....#'], ['#....#']]
Cn = [[0 for w in range(W)] for h in range (H)]
for h in range(H):
for w in range(W):
if C[h][w] == '.':
Cn[h][w] = 0
else:
Cn[h][w] = 1
counter1 = 0
ii = 0
for i in range(2**H):
for j in range(2**W):
# for j in range(2):
i = ii
for h in reversed(range(H)):
if i >= 2**h:
for w2 in range(W):
Cn[h][w2] = 0
i += -2**h
for w in reversed(range(W)):
if j >= 2**w:
for h2 in range(H):
Cn[h2][w] = 0
j += -2**w
counter = 0
for h in range(H):
counter += sum(Cn[h])
print(Cn)
print(counter)
if counter == K:
counter1 += 1
for h in range(H):
for w in range(W):
if C[h][w] == '.':
Cn[h][w] = 0
else:
Cn[h][w] = 1
ii += 1
|
s818573162
|
Accepted
| 104
| 9,148
| 1,335
|
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 5 21:10:49 2020
@author: Aruto Hosaka
"""
H,W,K = map(int,input().split())
C = [input() for i in range(H)]
# H,W,K = 6,6,8
# C = ['..##..', '.#..#.', '#....#', '######', '#....#', '#....#']
# H,W,K = 6,6,8
# C = [['..##..'], ['.#..#.'], ['#....#'], ['######'], ['#....#'], ['#....#']]
Cn = [[0 for w in range(W)] for h in range (H)]
for h in range(H):
for w in range(W):
if C[h][w] == '.':
Cn[h][w] = 0
else:
Cn[h][w] = 1
counter1 = 0
ii = 0
for i in range(2**H):
for j in range(2**W):
# for j in range(2):
i = ii
for h in reversed(range(H)):
if i >= 2**h:
for w2 in range(W):
Cn[h][w2] = 0
i += -2**h
for w in reversed(range(W)):
if j >= 2**w:
for h2 in range(H):
Cn[h2][w] = 0
j += -2**w
counter = 0
for h in range(H):
counter += sum(Cn[h])
if counter == K:
counter1 += 1
for h in range(H):
for w in range(W):
if C[h][w] == '.':
Cn[h][w] = 0
else:
Cn[h][w] = 1
ii += 1
print(counter1)
|
s980435950
|
p03251
|
u664652300
| 2,000
| 1,048,576
|
Wrong Answer
| 21
| 3,316
| 196
|
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
|
N,M,X,Y = map(int,input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
f = True
xa = max(x)
yi = min(y)
if xa+1 < yi:
print('No War')
else:
print('War')
|
s723863322
|
Accepted
| 17
| 3,060
| 193
|
N,M,X,Y = map(int,input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
x.append(X)
y.append(Y)
if max(x) < min(y):
print("No War")
else:
print("War")
|
s644978260
|
p03998
|
u536034761
| 2,000
| 262,144
|
Wrong Answer
| 34
| 9,388
| 347
|
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.
|
from collections import deque
A = deque(map(str, input()))
B = deque(map(str, input()))
C = deque(map(str, input()))
x = A.popleft()
while A and B and C:
if x == "a":
x = A.popleft()
elif x == "b":
x = B.popleft()
else:
x = C.popleft()
if not(A):
print("A")
elif not(B):
print("B")
else:
print("C")
|
s584385004
|
Accepted
| 29
| 9,260
| 495
|
from collections import deque
A = deque(map(str, input()))
B = deque(map(str, input()))
C = deque(map(str, input()))
x = A.popleft()
for _ in range(10000000):
if x == "a":
if A:
x = A.popleft()
else:
print("A")
break
elif x == "b":
if B:
x = B.popleft()
else:
print("B")
break
else:
if C:
x = C.popleft()
else:
print("C")
break
|
s818111894
|
p03679
|
u969848070
| 2,000
| 262,144
|
Wrong Answer
| 24
| 8,928
| 123
|
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 b <= x:
print('safe')
else:
print('dengerous')
|
s922856065
|
Accepted
| 24
| 9,100
| 126
|
x, a, b = map(int, input().split())
if b <= a:
print('delicious')
elif b -a <= x:
print('safe')
else:
print('dangerous')
|
s243679273
|
p02612
|
u320763652
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,004
| 30
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N = int(input())
print(N%1000)
|
s113563889
|
Accepted
| 25
| 9,032
| 76
|
N = int(input())
if N%1000 == 0:
print(0)
else:
print(1000-N%1000)
|
s588612614
|
p03545
|
u078932560
| 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.
|
a, b, c, d = map(int, list(input()))
for i in (-1,1):
for j in (-1,1):
for k in (-1,1):
if a + i * b + j * c + k * d == 7:
op1 = '+' * ((1+i)//2) + '-' * ((1-i)//2)
op2 = '+' * ((1+j)//2) + '-' * ((1-j)//2)
op3 = '+' * ((1+k)//2) + '-' * ((1-k)//2)
print(str(a)+op1+str(b)+op2+str(c)+op3+str(d))
exit()
|
s069199963
|
Accepted
| 19
| 3,064
| 359
|
a, b, c, d = map(int, list(input()))
for i in (-1,1):
for j in (-1,1):
for k in (-1,1):
if a + i * b + j * c + k * d == 7:
op1 = '+' * ((1+i)//2) + '-' * ((1-i)//2)
op2 = '+' * ((1+j)//2) + '-' * ((1-j)//2)
op3 = '+' * ((1+k)//2) + '-' * ((1-k)//2)
print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'=7')
exit()
|
s484714677
|
p03997
|
u007263493
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 78
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
s = (a + b) * h /2
print(s)
|
s469040205
|
Accepted
| 17
| 2,940
| 84
|
a = int(input())
b = int(input())
h = int(input())
s = int((a + b) * h / 2)
print(s)
|
s016458812
|
p03048
|
u942033906
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,060
| 155
|
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
|
R,G,B,N = map(int,input().split())
ans = 0
for r in range(R+1):
rest = N - r
if rest > G + B:
continue
else:
ans += G+B - rest + 1
print(ans)
|
s276954993
|
Accepted
| 1,507
| 3,060
| 184
|
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R + 1):
s = R * r
for g in range( (N-s) // G + 1):
s2 = s + G * g
if (N-s2) % B == 0:
ans += 1
print(ans)
|
s156574700
|
p03160
|
u717265305
| 2,000
| 1,048,576
|
Wrong Answer
| 146
| 14,672
| 253
|
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
|
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(n):
if i == 0:
continue
elif i == 1:
dp[1] = abs(h[1] - h[0])
continue
else:
dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp)
|
s314730996
|
Accepted
| 136
| 13,980
| 258
|
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(n):
if i == 0:
continue
elif i == 1:
dp[1] = abs(h[1] - h[0])
continue
else:
dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])
|
s947840084
|
p03456
|
u811528179
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 103
|
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.
|
import math
a,b=map(str,input().split())
ans=int(a+b)
print(['NO','YES'][int(math.sqrt(ans))**2==ans])
|
s658807904
|
Accepted
| 19
| 3,316
| 103
|
import math
a,b=map(str,input().split())
ans=int(a+b)
print(['No','Yes'][int(math.sqrt(ans))**2==ans])
|
s328289939
|
p02663
|
u531220228
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 9,108
| 197
|
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
|
H1, M1, H2, M2, K = map(int, input().split())
if H1 > H2 or (H1 == H2 and M1 >= M2):
H2 += 24
diff_min = H2*60 + M2 - (H1*60 + M1)
if diff_min - K < 0:
print(0)
else:
diff_min - K
|
s181792961
|
Accepted
| 21
| 9,168
| 204
|
H1, M1, H2, M2, K = map(int, input().split())
if H1 > H2 or (H1 == H2 and M1 >= M2):
H2 += 24
diff_min = H2*60 + M2 - (H1*60 + M1)
if diff_min - K < 0:
print(0)
else:
print(diff_min - K)
|
s100534191
|
p02255
|
u741801763
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,604
| 452
|
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.
|
import sys
def print_list(A):
for k in range(len(A)):
sys.stdout.write(str(A[k]))
if not k == len(A) -1: sys.stdout.write(" ")
print()
def insert_sort(A,N):
for i in range(1,N-1):
v = A[i]
j = i-1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j = j-1
A[j+1]=v
print_list(A)
print_list(A)
N = int(input())
A = list(map(int,input().split()))
insert_sort(A,N)
|
s194294165
|
Accepted
| 20
| 5,976
| 203
|
N = int(input())
A = list(map(int,input().split()))
for i in range(1,N):
print(*A)
v = A[i]
j = i-1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j = j-1
A[j+1]=v
print(*A)
|
s934624456
|
p03471
|
u773686010
| 2,000
| 262,144
|
Wrong Answer
| 515
| 9,044
| 303
|
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
|
N,Y =map(int,input().split())
ans = -1
for i in range(N,-1,-1):
for j in range(N - i,-1,-1):
if Y == (1000*i) + (5000*j) + (10000*(N-i-j)):
ans = str(i) + " " + str(j) + " " + str(N-i-j)
break
print(ans)
|
s848872200
|
Accepted
| 44
| 9,336
| 1,514
|
# AtCoder Beginners Selection Otoshidama
import math
N,Money = map(int, input().split())
if(1000*N<=Money<10000*N):
tenthousand_list=[num for num in range(0,Money+1,10000)]
fivethousand_list=[num for num in range(0,Money+1,5000)]
possible_tenthousand=math.floor(Money/10000)
while (possible_tenthousand >=0):
zan_number=N-possible_tenthousand
zan_Money=(Money-tenthousand_list[possible_tenthousand])
if(5000*zan_number>=zan_Money):
possible_fivethousand=math.floor(zan_Money/5000)
while (possible_fivethousand>=0):
if(tenthousand_list[possible_tenthousand]+fivethousand_list[possible_fivethousand]+
(1000*(N-possible_tenthousand-possible_fivethousand))==Money):
zan_Money=0
break
else:
possible_fivethousand-=1
else:
print("-1 -1 -1")
break
if((zan_Money==0) and (possible_fivethousand!=-1) ):
print(str(possible_tenthousand) + " " + str(possible_fivethousand)+ " " + str(N-possible_tenthousand-possible_fivethousand) )
break
possible_tenthousand-=1
if(possible_fivethousand==-1 and possible_tenthousand ==-1):
print("-1 -1 -1")
break
elif(Money==10000*N):
print(str(N) + " 0 "+ "0")
else:
print("-1 -1 -1")
|
s555509342
|
p02390
|
u493208426
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,584
| 92
|
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
|
S = int(input())
h = S // 3600
m = (S % 3600) // 60
s = ((S % 3600) % 60)
print(h, m, s)
|
s019039086
|
Accepted
| 20
| 5,588
| 121
|
S = int(input())
h = str(S // 3600)
m = str((S % 3600) // 60)
s = str(((S % 3600) % 60))
print(h + ":" + m + ":" + s)
|
s837579801
|
p03352
|
u607865971
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 141
|
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
|
X = int(input())
m = 0
for b in range(40):
for p in range(15):
t = b ** p
if t <= X:
m = max(m, t)
print(m)
|
s134295760
|
Accepted
| 17
| 2,940
| 145
|
X = int(input())
m = 0
for b in range(1,40):
for p in range(2,15):
t = b ** p
if t <= X:
m = max(m, t)
print(m)
|
s497245653
|
p03455
|
u374501720
| 2,000
| 262,144
|
Wrong Answer
| 19
| 2,940
| 104
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
a, b = map(int, input().rstrip().split())
c = a * b
if c % 2 == 0:
print('even')
else:
print('odd')
|
s745462071
|
Accepted
| 18
| 2,940
| 104
|
a, b = map(int, input().rstrip().split())
c = a * b
if c % 2 == 1:
print('Odd')
else:
print('Even')
|
s649991178
|
p03759
|
u649558044
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 79
|
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
|
a, b, c = map(int, input().split(" "))
print("Yes" if a - b == b - c else "No")
|
s316184353
|
Accepted
| 17
| 2,940
| 79
|
a, b, c = map(int, input().split(" "))
print("YES" if a - b == b - c else "NO")
|
s454780987
|
p03759
|
u010072501
| 2,000
| 262,144
|
Wrong Answer
| 29
| 9,008
| 572
|
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
|
# ⇔ b - a = c - b
a, b, c = map(int, input().split(maxsplit=3))
# print(a, b, c)
pillar_ba = b - a
pillar_cb = c - b
if pillar_ba == pillar_cb:
answer = "Yes"
else:
answer = "No"
print(answer)
|
s633299500
|
Accepted
| 26
| 9,048
| 582
|
# ⇔ b - a = c - b
a, b, c = map(int, input().split(maxsplit=3))
# print(a, b, c)
pillar_ba = b - a
pillar_cb = c - b
if pillar_ba == pillar_cb:
answer = "YES"
else:
answer = "NO"
print(answer)
|
s755915958
|
p03714
|
u547167033
| 2,000
| 262,144
|
Wrong Answer
| 441
| 37,212
| 466
|
Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
|
import heapq
n=int(input())
a=list(map(int,input().split()))
s1=sum(a[:n])
hq1=a[:n]
heapq.heapify(hq1)
A=[s1]
for i in range(n,2*n):
s1+=a[i]
heapq.heappush(hq1,a[i])
x=heapq.heappop(hq1)
s1-=x
A.append(s1)
a=a[::-1]
s2=sum(a[:n])
hq2=a[:n]
heapq.heapify(hq2)
B=[s2]
for i in range(n,2*n):
s2+=a[i]
heapq.heappush(hq2,a[i])
x=heapq.heappop(hq2)
s2-=x
B.append(s2)
B=B[::-1]
ans=-10**18
for i in range(len(A)):
ans=max(ans,A[i]-B[i])
print(ans)
|
s474623060
|
Accepted
| 450
| 40,212
| 488
|
import heapq
n=int(input())
a=list(map(int,input().split()))
s1=sum(a[:n])
hq1=a[:n]
heapq.heapify(hq1)
A=[s1]
for i in range(n,2*n):
s1+=a[i]
heapq.heappush(hq1,a[i])
x=heapq.heappop(hq1)
s1-=x
A.append(s1)
a=a[::-1]
s2=sum(a[:n])
hq2=[-a[i] for i in range(n)]
heapq.heapify(hq2)
B=[s2]
for i in range(n,2*n):
s2+=a[i]
heapq.heappush(hq2,-a[i])
x=heapq.heappop(hq2)
s2-=-x
B.append(s2)
B=B[::-1]
ans=-10**18
for i in range(len(A)):
ans=max(ans,A[i]-B[i])
print(ans)
|
s941664399
|
p02936
|
u125545880
| 2,000
| 1,048,576
|
Wrong Answer
| 2,123
| 246,936
| 632
|
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 numpy as np
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N, Q = map(int, input().split())
t = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
t[a-1].append(b-1)
t[b-1].append(a-1)
s = [0] * N
for _ in range(Q):
p, x = map(int, input().split())
s[p-1] = s[p-1] + x
ans = [0] * N
def dfs(v, p, value):
value = value + s[v]
ans[v] = ans[v] + value
for c in t[v]:
if c == p:
continue
dfs(c, v, value)
dfs(0, -1, 0)
print(ans)
|
s419444549
|
Accepted
| 1,620
| 236,900
| 748
|
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
def dfs(fr, now, num):
global graph, addsum, ans
tmp = num + addsum[now]
for a in graph[now]:
if a == fr:
continue
dfs(now, a, tmp)
ans[now] = tmp
def main():
global graph, addsum, ans
N, Q = map(int, readline().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, readline().split())
a -= 1; b -= 1
graph[a].append(b)
graph[b].append(a)
addsum = [0]*N
for _ in range(Q):
p, x = map(int, readline().split())
p -= 1
addsum[p] += x
ans = [0]*N
dfs(-1, 0, 0)
print(*ans)
if __name__ == "__main__":
main()
|
s641199859
|
p02260
|
u447562175
| 1,000
| 131,072
|
Wrong Answer
| 30
| 5,596
| 284
|
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
|
N = int(input())
A = [int(x) for x in input().split()]
cnt = 0
for i in range(N):
mini = i
for j in range(i, N):
if A[j] < A[mini]:
mini = j
if i != mini:
A[i], A[mini] = A[mini], A[i]
cnt +=1
print(cnt)
print(" ".join(map(str, A)))
|
s478856481
|
Accepted
| 20
| 5,604
| 284
|
N = int(input())
A = [int(x) for x in input().split()]
cnt = 0
for i in range(N):
mini = i
for j in range(i, N):
if A[j] < A[mini]:
mini = j
if i != mini:
A[i], A[mini] = A[mini], A[i]
cnt +=1
print(" ".join(map(str, A)))
print(cnt)
|
s746076683
|
p03399
|
u957872856
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 108
|
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
|
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = [a,b]
g = [c,d]
print(min(e)*min(g))
|
s014471964
|
Accepted
| 17
| 2,940
| 109
|
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = [a,b]
g = [c,d]
print(min(e)+min(g))
|
s542202159
|
p03155
|
u657994700
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,068
| 5
|
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
|
5
4
2
|
s922531318
|
Accepted
| 17
| 2,940
| 74
|
N = int(input())
H = int(input())
W = int(input())
print((N-W+1)*(N-H+1))
|
s872557919
|
p02678
|
u987164499
| 2,000
| 1,048,576
|
Wrong Answer
| 732
| 124,620
| 2,163
|
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
|
from sys import stdin
from sys import setrecursionlimit
import math
setrecursionlimit(10 ** 7)
n,m = map(int,stdin.readline().rstrip().split())
li = [[]for _ in range(n)]
lin = []
for i in range(m):
a,b = map(int,stdin.readline().rstrip().split())
a -= 1
b -= 1
li[a].append(b)
li[b].append(a)
lin.append([a,b])
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n)]
self.rank = [0] * n
self.size = [1] * n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
def all_find(self):
for n in range(len(self.par)):
self.find(n)
def depth_first_search(start, W):
work_stack = []
visited = set()
work_stack.append(start)
visited.add(start)
while work_stack:
print(work_stack)
here = work_stack.pop()
for i, node in enumerate(W[here]):
if node == 0: continue
if i not in visited:
work_stack.append(i)
visited.add(i)
return visited
uni = UnionFind(n)
lis = [0]*n
visited = [False]*n
visited[0] = True
oya = 0
def keiro(now):
ima = li[now]
for i in ima:
if visited[i]:
continue
else:
lis[i] = now
visited[i] = True
keiro(i)
keiro(0)
print("Yes")
for i in lis[1:]:
print(i+1)
print(lis)
|
s112865569
|
Accepted
| 1,023
| 79,904
| 1,117
|
from sys import stdin
from sys import setrecursionlimit
from queue import deque
setrecursionlimit(10 ** 7)
n,m = map(int,stdin.readline().rstrip().split())
li = [[]for _ in range(n)]
lin = []
length = {}
length_path = [0]*n
for i in range(m):
a,b = map(int,stdin.readline().rstrip().split())
a -= 1
b -= 1
li[a].append(b)
li[b].append(a)
if a < b:
length[(a,b)] = 1
else:
length[(b,a)] = 1
lin.append([a,b])
work_queue = deque([])
visited = [False]*n
work_queue.append(0)
while work_queue:
now = work_queue.popleft()
visited[now] = True
for i in li[now]:
if visited[i]:
continue
work_queue.append(i)
visited[i] = True
if now < i:
length_path[i] = length_path[now]+length[(now,i)]
else:
length_path[i] = length_path[now]+length[(i,now)]
kotae = [0]*n
for num,i in enumerate(li):
ima = i
now = 10**10
for j in ima:
if length_path[j] < now:
now = length_path[j]
k = j
kotae[num] = k+1
print("Yes")
for i in kotae[1:]:
print(i)
|
s903283129
|
p02927
|
u923659712
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 164
|
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
|
n,m=input().split()
ans=0
for i in range(1,int(n)+1):
for j in range(2,int(m[0])+1):
for k in range(2,int(m[1])+1):
if i==j*k:
ans+=1
print(ans)
|
s886092632
|
Accepted
| 18
| 3,064
| 330
|
n,m=input().split()
if int(m)>=10:
ans=0
for i in range(4,int(n)+1):
for j in range(2,int(m[0])):
for k in range(2,10):
if i==j*k:
ans+=1
for i in range(4,int(n)+1):
for j in range(2,int(m[1])+1):
if i==j*int(m[0]):
ans+=1
print(ans)
else:
print(0)
|
s983177424
|
p03828
|
u404676457
| 2,000
| 262,144
|
Wrong Answer
| 35
| 3,316
| 1,401
|
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
import math
n = int(input())
sosu = {2:0, 3:0, 5:0, 7:0, 11:0, 13:0, 17:0, 19:0, 23:0, 29:0, 31:0, 37:0, 41:0, 43:0, 47:0, 53:0, 59:0, 61:0, 67:0, 71:0, 73:0, 79:0, 83:0, 89:0, 97:0, 101:0, 103:0, 107:0, 109:0, 113:0, 127:0, 131:0, 137:0, 139:0, 149:0, 151:0, 157:0, 163:0, 167:0, 173:0, 179:0, 181:0, 191:0, 193:0, 197:0, 199:0, 211:0, 223:0, 227:0, 229:0, 233:0, 239:0,241:0, 251:0, 257:0, 263:0, 269:0, 271:0, 277:0, 281:0, 283:0, 293:0, 307:0, 311:0, 313:0, 317:0, 331:0, 337:0, 347:0, 349:0, 353:0, 359:0, 367:0, 373:0, 379:0, 383:0, 389:0, 397:0, 401:0, 409:0, 419:0, 421:0, 431:0, 433:0, 439:0, 443:0, 449:0, 457:0, 461:0, 463:0, 467:0, 479:0, 487:0, 491:0, 499:0, 503:0, 509:0, 521:0, 523:0, 541:0, 547:0, 557:0, 563:0, 569:0, 571:0, 577:0, 587:0, 593:0, 599:0, 601:0, 607:0, 613:0, 617:0, 619:0, 631:0, 641:0, 643:0, 647:0, 653:0, 659:0, 661:0, 673:0, 677:0, 683:0, 691:0, 701:0, 709:0, 719:0, 727:0, 733:0, 739:0, 743:0, 751:0, 757:0, 761:0, 769:0, 773:0, 787:0, 797:0, 809:0, 811:0, 821:0, 823:0, 827:0, 829:0, 839:0, 853:0, 857:0, 859:0, 863:0, 877:0, 881:0, 883:0, 887:0, 907:0, 911:0, 919:0, 929:0, 937:0, 941:0, 947:0, 953:0, 967:0, 971:0, 977:0, 983:0, 991:0, 997:0}
for i in range(2, n + 1):
k = i
for j in sosu:
while k % j == 0:
sosu[j] += 1
k //= j
print(sosu)
ans = 1
for i in sosu:
ans = ans * (sosu[i] + 1) % (10**9 + 7)
print(ans)
|
s924135519
|
Accepted
| 41
| 3,316
| 1,427
|
import math
n = int(input())
sosu = {2:0, 3:0, 5:0, 7:0, 11:0, 13:0, 17:0, 19:0, 23:0, 29:0, 31:0, 37:0, 41:0, 43:0, 47:0, 53:0, 59:0, 61:0, 67:0, 71:0, 73:0, 79:0, 83:0, 89:0, 97:0, 101:0, 103:0, 107:0, 109:0, 113:0, 127:0, 131:0, 137:0, 139:0, 149:0, 151:0, 157:0, 163:0, 167:0, 173:0, 179:0, 181:0, 191:0, 193:0, 197:0, 199:0, 211:0, 223:0, 227:0, 229:0, 233:0, 239:0,241:0, 251:0, 257:0, 263:0, 269:0, 271:0, 277:0, 281:0, 283:0, 293:0, 307:0, 311:0, 313:0, 317:0, 331:0, 337:0, 347:0, 349:0, 353:0, 359:0, 367:0, 373:0, 379:0, 383:0, 389:0, 397:0, 401:0, 409:0, 419:0, 421:0, 431:0, 433:0, 439:0, 443:0, 449:0, 457:0, 461:0, 463:0, 467:0, 479:0, 487:0, 491:0, 499:0, 503:0, 509:0, 521:0, 523:0, 541:0, 547:0, 557:0, 563:0, 569:0, 571:0, 577:0, 587:0, 593:0, 599:0, 601:0, 607:0, 613:0, 617:0, 619:0, 631:0, 641:0, 643:0, 647:0, 653:0, 659:0, 661:0, 673:0, 677:0, 683:0, 691:0, 701:0, 709:0, 719:0, 727:0, 733:0, 739:0, 743:0, 751:0, 757:0, 761:0, 769:0, 773:0, 787:0, 797:0, 809:0, 811:0, 821:0, 823:0, 827:0, 829:0, 839:0, 853:0, 857:0, 859:0, 863:0, 877:0, 881:0, 883:0, 887:0, 907:0, 911:0, 919:0, 929:0, 937:0, 941:0, 947:0, 953:0, 967:0, 971:0, 977:0, 983:0, 991:0, 997:0}
for i in range(2, n + 1):
k = i
for j in sosu:
while k % j == 0:
sosu[j] += 1
k //= j
if k == 1:
continue
ans = 1
for i in sosu:
ans = ans * (sosu[i] + 1) % (10**9 + 7)
print(ans)
|
s462559020
|
p03693
|
u519939795
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 133
|
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?
|
r,g,b = (int(x) for x in input().split())
1 <= r,g,b <= 9
c = r + g + b
d = (c) % 4
if d == 0:
print('YES')
else:
print('NO')
|
s464030918
|
Accepted
| 17
| 2,940
| 132
|
r, g, b = map(int, input().split())
1 <= r,g,b <= 9
sum = r*100 + g*10 + b
if sum % 4 == 0:
print('YES')
else:
print('NO')
|
s394239379
|
p02842
|
u211236379
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 157
|
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.
|
X = int(input())
if X % 1.08 == 0:
print(X//1.08)
else:
if int((int(X//1.08)+1) * 1.08) == X:
print(X//1.08+1)
else:
print(":(")
|
s422994353
|
Accepted
| 17
| 2,940
| 168
|
X = int(input())
if X % 1.08 == 0:
print(int(X//1.08))
else:
if int((int(X//1.08)+1) * 1.08) == X:
print(int(X//1.08+1))
else:
print(":(")
|
s356323072
|
p03607
|
u413019025
| 2,000
| 262,144
|
Wrong Answer
| 225
| 17,160
| 505
|
You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
def read_h(typ=int):
return list(map(typ, input().split()))
def read_v(n, m=1, typ=int):
return [read_h() if m > 1 else typ(input()) for _ in range(n)]
def main():
N, = read_h()
A = read_v(N)
cnts = {}
for a in A:
cnts[a] = cnts.get(a, 0) + 1
print(cnts)
ans = 0
for n in cnts.values():
if n % 2 != 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
s515821703
|
Accepted
| 198
| 16,268
| 508
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
def read_h(typ=int):
return list(map(typ, input().split()))
def read_v(n, m=1, typ=int):
return [read_h() if m > 1 else typ(input()) for _ in range(n)]
def main():
N, = read_h()
A = read_v(N)
cnts = {}
for a in A:
cnts[a] = cnts.get(a, 0) + 1
# print(cnts)
ans = 0
for n in cnts.values():
if n % 2 != 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
s497469417
|
p03573
|
u690536347
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 81
|
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.
|
l=list(map(int,input().split()))
if l[0]!=l[1]:
print(l[0])
else:
print(l[2])
|
s046946658
|
Accepted
| 17
| 2,940
| 90
|
l=list(sorted(map(int,input().split())))
if l[0]!=l[1]:
print(l[0])
else:
print(l[2])
|
s728269740
|
p03400
|
u244434589
| 2,000
| 262,144
|
Wrong Answer
| 32
| 9,116
| 161
|
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
|
n=int(input())
d,x=map(int,input().split())
cnt = 0
for i in range(n):
a = int(input())
p = 1
while p < d:
p +=a
cnt +=1
print(cnt+x)
|
s888187151
|
Accepted
| 29
| 9,148
| 163
|
n=int(input())
d,x=map(int,input().split())
cnt = 0
for i in range(n):
a = int(input())
p = 1
while p <= d:
p +=a
cnt +=1
print(cnt+x)
|
s990905685
|
p03433
|
u940449872
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 90
|
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())
res = N%500
if A>=N:
print('YES')
else:
print('NO')
|
s060756636
|
Accepted
| 17
| 2,940
| 92
|
N = int(input())
A = int(input())
res = N%500
if A>=res:
print('Yes')
else:
print('No')
|
s620070546
|
p03795
|
u115838990
| 2,000
| 262,144
|
Wrong Answer
| 26
| 8,976
| 38
|
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
|
n = int(input())
print(n*800-n/15*200)
|
s031276152
|
Accepted
| 22
| 9,044
| 38
|
n=int(input());print(n*800-n//15*200)
|
s500559863
|
p02271
|
u130834228
| 5,000
| 131,072
|
Wrong Answer
| 20
| 7,664
| 338
|
Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
|
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
N = int(2**n)
d = []
for i in range(N):
b = "{:0{}b}".format(i, n)
d.append(sum(A[j] for j in range(n) if b[j] == '1'))
#print(b)
for i in range(q):
if m[i] in d:
print("Yes")
else:
print("No")
|
s955353598
|
Accepted
| 9,180
| 44,972
| 338
|
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
N = int(2**n)
d = []
for i in range(N):
b = "{:0{}b}".format(i, n)
d.append(sum(A[j] for j in range(n) if b[j] == '1'))
#print(b)
for i in range(q):
if m[i] in d:
print("yes")
else:
print("no")
|
s119218310
|
p02659
|
u327294693
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 9,312
| 293
|
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
from sys import stdin
from functools import reduce
inputs = list(map(float, input().split()))
if (0 in inputs):
output = 0
else:
output = reduce((lambda x, y: -1 if (x * y) > 1e18 or x < 0 or y < 0 else (x * y)), inputs)
print('{:.0f}'.format(output))
|
s284763179
|
Accepted
| 28
| 10,060
| 104
|
import math
from decimal import Decimal
a,b=input().split()
a=int(a)
b=Decimal(b)
print(math.floor(a*b))
|
s592265941
|
p03434
|
u220612891
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 212
|
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.
|
x = int(input())
y = [int(i) for i in input().split()]
y.sort(reverse=True)
a = 0
b = 0
for i in range(1, x+1):
if(i%2) != 0:
a += y[i-1]
print(y[i-1])
else:
b += y[i-1]
print(a-b)
|
s066808789
|
Accepted
| 17
| 3,064
| 193
|
x = int(input())
y = [int(i) for i in input().split()]
y.sort(reverse=True)
a = 0
b = 0
for i in range(1, x+1):
if (i % 2) != 0:
a += y[i-1]
else:
b += y[i-1]
print(a-b)
|
s217897245
|
p03471
|
u353241315
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 3,064
| 428
|
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.
|
def otoshidama(N, Y):
y = Y/1000
for c in range(int(y)+1, 0, -1):
for b in range(int(y/5)+1, 0, -1):
for a in range(int(y/10)+1, 0, -1):
if 10*a + 5*b + c == y and a+b+c ==N:
return a, b, c
return -1, -1, -1
if __name__ == '__main__':
N, Y = map(int,input().split())
a, b, c = otoshidama(N, Y)
print(a, b, c)
|
s778472773
|
Accepted
| 580
| 3,064
| 384
|
def otoshidama(N, Y):
y = Y/1000
for a in range(int(y/10)+1, -1, -1):
for b in range(N - a, -1, -1):
c = N - a - b
if 10*a + 5*b + c == y:
return a, b, c
return -1, -1, -1
if __name__ == '__main__':
N, Y = map(int,input().split())
a, b, c = otoshidama(N, Y)
print(a, b, c)
|
s014175562
|
p03361
|
u314837274
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,064
| 503
|
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
|
dy=[1,0,-1,0]
dx=[0,1,0,-1]
H,W=map(int,input().split())
field=[]
for _ in range(H):
field.append(list(input()))
is_success=True
for y in range(H):
for x in range(W):
if field[y][x]==".":
continue
for k in range(4):
tmp_y=y+dy[k]
tmp_x=x+dx[k]
if tmp_y<0 or tmp_y>=H or tmp_x<0 or tmp_x>=W:
continue
if field[tmp_y][tmp_x]==".":
break
if k==3:
print("No")
exit()
print("Yes")
|
s374453273
|
Accepted
| 20
| 3,064
| 503
|
dy=[1,0,-1,0]
dx=[0,1,0,-1]
H,W=map(int,input().split())
field=[]
for _ in range(H):
field.append(list(input()))
is_success=True
for y in range(H):
for x in range(W):
if field[y][x]==".":
continue
for k in range(4):
tmp_y=y+dy[k]
tmp_x=x+dx[k]
if tmp_y<0 or tmp_y>=H or tmp_x<0 or tmp_x>=W:
continue
if field[tmp_y][tmp_x]=="#":
break
if k==3:
print("No")
exit()
print("Yes")
|
s239934898
|
p03760
|
u576917603
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 161
|
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
|
a=input()
b=input()
list=[]
for i in range(len(a)-1):
list.append(a[i])
list.append(b[i])
if len(a)-len(b)==1:
list.append(a[i])
print("".join(list))
|
s927741324
|
Accepted
| 18
| 3,060
| 260
|
a=input()
b=input()
list=[]
if len(a)-len(b)==0:
for i in range(len(a)):
list.append(a[i])
list.append(b[i])
else:
for i in range(len(a)-1):
list.append(a[i])
list.append(b[i])
list.append(a[-1])
print("".join(list))
|
s886208515
|
p03068
|
u598720217
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,060
| 198
|
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())
tmp = str(S[K-1])
l = []
for n,i in enumerate(S):
print(i,tmp)
if i==tmp:
l.append(i)
else:
l.append('*')
print("".join(l))
|
s689252445
|
Accepted
| 17
| 3,060
| 181
|
N = int(input())
S = input()
K = int(input())
tmp = str(S[K-1])
l = []
for n,i in enumerate(S):
if i==tmp:
l.append(i)
else:
l.append('*')
print("".join(l))
|
s314142268
|
p03160
|
u227082700
| 2,000
| 1,048,576
|
Wrong Answer
| 122
| 13,928
| 172
|
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
|
n,h=int(input()),list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]))
print(h[n-1])
|
s646215941
|
Accepted
| 129
| 13,980
| 172
|
n,h=int(input()),list(map(int,input().split()));dp=[0]*n;dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]))
print(dp[-1])
|
s840033928
|
p03992
|
u995062424
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 32
|
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
|
s=input()
print(s[:4]+' '+s[5:])
|
s903542101
|
Accepted
| 17
| 2,940
| 32
|
s=input()
print(s[:4]+' '+s[4:])
|
s215292975
|
p03556
|
u732870425
| 2,000
| 262,144
|
Wrong Answer
| 28
| 2,940
| 109
|
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
|
N = int(input())
ans = 0
for i in range(N):
if N <= i ** 2:
ans = i ** 2
break
print(ans)
|
s355156601
|
Accepted
| 27
| 2,940
| 119
|
N = int(input())
ans = 0
for i in range(1, 10**9):
if N < i ** 2:
ans = (i-1) ** 2
break
print(ans)
|
s185451192
|
p02613
|
u418420470
| 2,000
| 1,048,576
|
Wrong Answer
| 143
| 9,132
| 281
|
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())
C0 =0
C1 =0
C2 = 0
C3 = 0
for i in range(N):
s = input()
if s == 'AC':
C0 += 1
elif s == 'WA':
C1 += 1
elif s == 'TLE':
C2 += 1
else:
C3 += 1
print('AC x' + str(C0))
print('WA x' + str(C1))
print('TLE x' + str(C2))
print('RE x' + str(C3))
|
s203485652
|
Accepted
| 145
| 9,180
| 285
|
N = int(input())
C0 =0
C1 =0
C2 = 0
C3 = 0
for i in range(N):
s = input()
if s == 'AC':
C0 += 1
elif s == 'WA':
C1 += 1
elif s == 'TLE':
C2 += 1
else:
C3 += 1
print('AC x ' + str(C0))
print('WA x ' + str(C1))
print('TLE x ' + str(C2))
print('RE x ' + str(C3))
|
s274595410
|
p03457
|
u814986259
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 245
|
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
N=int(input())
prev=[0,0,0]
for i in range(N):
x,y,t=map(int,input().split())
dis = abs(x-prev[0]) + abs(y -prev[1])
time= t-prev[2]
if dis <= time and (time-dis)%2==0:
prev=[x,y,t]
else:
print("No")
exit(0)
print("Yes")
|
s594753935
|
Accepted
| 172
| 3,060
| 434
|
def main():
import sys
input = sys.stdin.readline
N = int(input())
prev = 0
x = 0
y = 0
for i in range(N):
a, b, c = map(int, input().split())
dis = abs(b - x) + abs(c - y)
diff = a - prev
if diff >= dis and diff % 2 == dis % 2:
prev = a
x = b
y = c
else:
print("No")
exit(0)
print("Yes")
main()
|
s185688808
|
p04011
|
u764401543
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 174
|
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
n, k, x, y = [int(input()) for i in range(4)]
first = k * x
print(first)
if n - k <= 0:
first = n * x
second = 0
else:
second = (n - k) * y
print(first + second)
|
s176284204
|
Accepted
| 17
| 2,940
| 191
|
n, k, x, y = [int(input()) for i in range(4)]
# print(first)
if n > k:
first = k * x
second = (n - k) * y
else:
first = n * x
second = 0
print(first + second)
|
s564699265
|
p02608
|
u081714930
| 2,000
| 1,048,576
|
Wrong Answer
| 2,205
| 9,132
| 222
|
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
|
N = int(input())
cnt = 0
for n in range(1,N+1):
for x in range(1,n+1):
for y in range(1, n+1):
if x**2 + y**2 + (N-x-y)**2 + x*y + y*(n-x-y) + (n-x-y)*x == n:
cnt +=1
print(cnt)
|
s770578985
|
Accepted
| 927
| 9,304
| 253
|
n = int(input())
cont = [0 for i in range(10050)]
for x in range(1,105):
for y in range(1,105):
for z in range(1,105):
v = x**2 + y**2 + z**2 + z*x + y*z + x*y
if v <= 10001:
cont[v]+=1
for i in range(1,n+1):
print(cont[i])
|
s486640686
|
p02614
|
u131881594
| 1,000
| 1,048,576
|
Wrong Answer
| 78
| 9,148
| 537
|
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
|
h,w,k=map(int,input().split())
c=[]
for i in range(h):
temp=input()
c.append(temp)
ans=0
for i in range(2**h):
temp=[0]*h
for m in range(h):
temp[m]=i&1
i>>=1
for j in range(2**w):
temp2=[0]*w
for m in range(w):
temp2[m]=j&1
j>>=1
cnt=0
for g in range(h):
for t in range(w):
if temp[g]==0 and temp2[t]==0 and c[g][t]=="#":
print(g,t)
cnt+=1
if cnt==k: ans+=1
print(ans)
|
s674930895
|
Accepted
| 60
| 9,232
| 506
|
h,w,k=map(int,input().split())
c=[]
for i in range(h):
temp=input()
c.append(temp)
ans=0
for i in range(2**h):
temp=[0]*h
for m in range(h):
temp[m]=i&1
i>>=1
for j in range(2**w):
temp2=[0]*w
for m in range(w):
temp2[m]=j&1
j>>=1
cnt=0
for g in range(h):
for t in range(w):
if temp[g]==0 and temp2[t]==0 and c[g][t]=="#":
cnt+=1
if cnt==k: ans+=1
print(ans)
|
s502436002
|
p03160
|
u101490607
| 2,000
| 1,048,576
|
Wrong Answer
| 171
| 16,964
| 396
|
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
|
import sys
def chmin(a,i,b):
if a[i] > b:
a[i] = b
#print(a)
return True
else:
return False
n = int(input())
h = list( map(int,input().split()))
dp = [sys.maxsize for i in range(n)]
dp[0] = 0
print(n,h)
print(dp)
for i in range(len(dp)):
if i - 1 >= 0:
chmin(dp,i, abs(h[i]-h[i-1]))
if i - 2 >= 0:
chmin(dp,i, abs(h[i]-h[i-2]))
print(dp)
print(dp[-1])
|
s475348136
|
Accepted
| 163
| 13,924
| 416
|
import sys
def chmin(a,i,b):
if a[i] > b:
a[i] = b
#print(a)
return True
else:
return False
n = int(input())
h = list( map(int,input().split()))
dp = [sys.maxsize for i in range(n)]
dp[0] = 0
#print(n,h)
#print(dp)
for i in range(len(dp)):
if i - 1 >= 0:
chmin(dp,i, abs(h[i]-h[i-1])+dp[i-1])
if i - 2 >= 0:
chmin(dp,i, abs(h[i]-h[i-2])+dp[i-2])
#print(dp)
print(dp[-1])
|
s531116327
|
p02613
|
u401086905
| 2,000
| 1,048,576
|
Wrong Answer
| 32
| 9,220
| 302
|
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
N = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for _ in []*N:
S = int(input())
if S == 'AC':
ac+=1
elif S == 'WA':
wa+=1
elif S == 'TLE':
tle+=1
elif S == 'RE':
re+=1
print('AC x %d'%ac)
print('WA x %d'%wa)
print('TLE x %d'%tle)
print('RE x %d'%re)
|
s830129464
|
Accepted
| 150
| 9,204
| 267
|
N = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for i in range(N):
S = input()
if S=='AC':
ac+=1
elif S=='WA':
wa+=1
elif S=='TLE':
tle+=1
elif S=='RE':
re+=1
print('AC x %d'%ac)
print('WA x %d'%wa)
print('TLE x %d'%tle)
print('RE x %d'%re)
|
s828390314
|
p03962
|
u175034939
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 128
|
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
|
a, b, c = map(int,input().split())
if a == b == c:
print(3)
elif a == b or b == c or a == c:
print(2)
else:
print(1)
|
s375964360
|
Accepted
| 18
| 2,940
| 128
|
a, b, c = map(int,input().split())
if a == b == c:
print(1)
elif a == b or b == c or a == c:
print(2)
else:
print(3)
|
s462427788
|
p02612
|
u193927973
| 2,000
| 1,048,576
|
Wrong Answer
| 34
| 9,100
| 48
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N=int(input())
a=N//1000
ans=N-a*1000
print(ans)
|
s385219337
|
Accepted
| 36
| 9,156
| 74
|
N=int(input())
a=N//1000
ans=(a+1)*1000-N
if ans==1000:
ans=0
print(ans)
|
s073713496
|
p03844
|
u478266845
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 130
|
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her.
|
A,op,B = [str(i) for i in input().split()]
if op == '+':
ans = int(A)+int(B)
else:
ans =int(A)-int(B)
print(ans)
|
s610035046
|
Accepted
| 17
| 2,940
| 126
|
A,op,B = [str(i) for i in input().split()]
if op == '+':
ans = int(A)+int(B)
else:
ans =int(A)-int(B)
print(ans)
|
s324240523
|
p03068
|
u960653324
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 272
|
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 = str(input())
K = int(input())
swap_word = S[K-1]
print(swap_word)
ans = []
for i in range(N):
if S[i] != swap_word:
ans.append("*")
else:
ans.append(S[i])
ans_word = ""
for i in range(N):
ans_word = ans_word + ans[i]
print(ans_word)
|
s426918014
|
Accepted
| 17
| 3,064
| 255
|
N = int(input())
S = str(input())
K = int(input())
swap_word = S[K-1]
ans = []
for i in range(N):
if S[i] != swap_word:
ans.append("*")
else:
ans.append(S[i])
ans_word = ""
for i in range(N):
ans_word = ans_word + ans[i]
print(ans_word)
|
s401560783
|
p03575
|
u891217808
| 2,000
| 262,144
|
Wrong Answer
| 40
| 3,828
| 780
|
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
|
import copy
def is_linking(sides):
side = copy.copy(sides.pop())
flag = True
while flag:
if not sides:
if len(side) == n:
return True
else:
return False
for i in range(len(sides)):
if side & sides[i]:
side |= sides.pop(i)
print(side)
break
elif i == len(sides) - 1:
flag = False
if len(side) == n:
return True
else:
return False
n, m = map(int, input().split())
all_sides = [set(input().split()) for _ in range(m)]
count = 0
for i in range(m):
sides = all_sides[:i] + all_sides[i+1:]
if is_linking(sides):
continue
else:
count += 1
print(count)
|
s191498392
|
Accepted
| 30
| 3,444
| 752
|
import copy
def is_linking(sides):
side = copy.copy(sides.pop())
flag = True
while flag:
if not sides:
if len(side) == n:
return True
else:
return False
for i in range(len(sides)):
if side & sides[i]:
side |= sides.pop(i)
break
elif i == len(sides) - 1:
flag = False
if len(side) == n:
return True
else:
return False
n, m = map(int, input().split())
all_sides = [set(input().split()) for _ in range(m)]
count = 0
for i in range(m):
sides = all_sides[:i] + all_sides[i+1:]
if is_linking(sides):
continue
else:
count += 1
print(count)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.