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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s843472940
|
p03814
|
u588526762
| 2,000
| 262,144
|
Wrong Answer
| 43
| 3,516
| 252
|
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()
for i in range(len(s)):
if s[i] == 'A':
head = i
break
for i in range(len(s)):
if s[-(1+i)] == 'Z':
tail = len(s)-i-1
break
print('tail=' + str(tail))
print('head=' + str(head))
print(tail - head + 1)
|
s514151765
|
Accepted
| 44
| 3,512
| 198
|
s = input()
for i in range(len(s)):
if s[i] == 'A':
head = i
break
for i in range(len(s)):
if s[-(1+i)] == 'Z':
tail = len(s)-i-1
break
print(tail - head + 1)
|
s918388177
|
p03555
|
u759651152
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 180
|
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
#-*-coding:utf-8-*-
def main():
c1 = input()
c2 = input()
if c1 == c2[::-1]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
|
s143065817
|
Accepted
| 17
| 2,940
| 180
|
#-*-coding:utf-8-*-
def main():
c1 = input()
c2 = input()
if c1 == c2[::-1]:
print('YES')
else:
print('NO')
if __name__ == '__main__':
main()
|
s158292901
|
p03023
|
u883203948
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 36
|
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.
|
n = int(input())
print((n-3) * 180)
|
s141883253
|
Accepted
| 19
| 2,940
| 36
|
n = int(input())
print((n-2) * 180)
|
s999835265
|
p03476
|
u316386814
| 2,000
| 262,144
|
Wrong Answer
| 1,130
| 46,348
| 487
|
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
|
import math
import numpy as np
Q = int(input())
LR = []
for _ in range(Q):
LR.append(list(map(int, input().split())))
rmax = max(r for l, r in LR)
primes = np.ones(1 + rmax, int)
primes[::2] = 0
for i in range(3, 1 + int(math.sqrt(rmax)), 2):
if primes[i]:
primes[2*i::i] = 0
# like 2017
for i in range(rmax, 0, -2):
if primes[i] and not primes[(i + 1) // 2]:
primes[i] = 0
acc = np.cumsum(primes)
for l, r in LR:
ans = acc[r] - acc[l - 1]
print(ans)
|
s296999833
|
Accepted
| 1,014
| 39,588
| 512
|
import math
import numpy as np
Q = int(input())
LR = []
for _ in range(Q):
LR.append(list(map(int, input().split())))
rmax = max(r for l, r in LR)
primes = np.ones(1 + rmax, int)
primes[4::2] = 0
for i in range(3, 1 + int(math.sqrt(rmax)), 2):
if primes[i]:
primes[2*i::i] = 0
# like 2017
for i in range(rmax, 0, -2):
if primes[i] and not primes[(i + 1) // 2]:
primes[i] = 0
primes[:3] = 0
acc = np.cumsum(primes)
for l, r in LR:
ans = acc[r] - acc[l - 1]
print(ans)
|
s885944000
|
p03501
|
u333731247
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 49
|
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
|
N,A,B=map(int,input().split())
print(max(N*A,B))
|
s826128805
|
Accepted
| 17
| 2,940
| 49
|
N,A,B=map(int,input().split())
print(min(N*A,B))
|
s980348883
|
p02936
|
u316175331
| 2,000
| 1,048,576
|
Wrong Answer
| 2,112
| 93,976
| 1,088
|
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.
|
# Input N, Q
N, Q = [int(c) for c in input().split()]
edges = [[] for i in range(N)]
for i in range(N-1):
u, v = [int(c)-1 for c in input().split()]
edges[u].append(v)
edges[v].append(u)
# Form tree
parent = [None for i in range(N)]
childs = [[] for i in range(N)]
def dfs(root):
parent[root] = -1
stack = [root]
while stack:
now = stack.pop()
for nex in edges[now]:
if parent[nex] is None:
parent[nex] = now
childs[now].append(nex)
stack.append(nex)
dfs(0)
# Queries
incremented = [0 for i in range(N)]
for i in range(Q):
v, add = [int(c) for c in input().split()]
v -= 1
incremented[v] += add
# Lower propagate
total = [0 for i in range(N)]
def propagate(root):
global total
stack = [root]
while stack:
now = stack.pop()
total[now] += incremented[now]
for child in childs[now]:
total[child] += total[root]
stack.append(child)
propagate(0)
# Print
print(" ".join(str(num) for num in total))
|
s134181217
|
Accepted
| 1,996
| 96,540
| 1,250
|
def main():
# Input N, Q
N, Q = [int(c) for c in input().split()]
edges = [[] for i in range(N)]
for i in range(N-1):
u, v = [int(c)-1 for c in input().split()]
edges[u].append(v)
edges[v].append(u)
# Form tree
parent = [None for i in range(N)]
childs = [[] for i in range(N)]
def dfs(root):
parent[root] = -1
stack = [root]
while stack:
now = stack.pop()
for nex in edges[now]:
if parent[nex] is None:
parent[nex] = now
childs[now].append(nex)
stack.append(nex)
dfs(0)
# Queries
incremented = [0 for i in range(N)]
for i in range(Q):
v, add = [int(c) for c in input().split()]
v -= 1
incremented[v] += add
# Lower propagate
total = [0 for i in range(N)]
def propagate(root):
stack = [root]
while stack:
now = stack.pop()
total[now] += incremented[now]
for child in childs[now]:
total[child] += total[now]
stack.append(child)
propagate(0)
# Print
print(" ".join(str(num) for num in total))
main()
|
s198752896
|
p02409
|
u896025703
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,576
| 310
|
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
|
a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
a[b-1][f-1][r-1] += v
for k in range(4):
for j in range(3):
for i in range(10):
print(" {}".format(a[k][j][i]), end="")
print("")
print("#" * 20)
print("")
|
s896332025
|
Accepted
| 30
| 7,676
| 315
|
a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
a[b-1][f-1][r-1] += v
for k in range(4):
for j in range(3):
for i in range(10):
print(" {}".format(a[k][j][i]), end="")
print("")
if not k == 3: print("#" * 20)
|
s635238830
|
p03759
|
u603234915
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 68
|
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
|
a,b,c = map(int,input().split())
print(('No','Yes')[(b-a)==(c-b)])
|
s507274885
|
Accepted
| 17
| 2,940
| 68
|
a,b,c = map(int,input().split())
print(('NO','YES')[(b-a)==(c-b)])
|
s791798349
|
p02612
|
u187053387
| 2,000
| 1,048,576
|
Wrong Answer
| 34
| 9,164
| 52
|
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.
|
i = int(input())
while (i < 0):
i -= 1000
print(i)
|
s319587017
|
Accepted
| 27
| 9,048
| 57
|
i = int(input())
while (i > 0):
i -= 1000
print(abs(i))
|
s934171567
|
p03862
|
u319818856
| 2,000
| 262,144
|
Wrong Answer
| 230
| 14,844
| 729
|
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
|
def boxes_and_candies(N: int, x: int, A: list) -> int:
count = 0
for i in range(1, N):
a1, a2 = A[i - 1], A[i]
print(a1, a2)
if a1 + a2 <= x:
# OK
# print('--> OK')
continue
diff = (a1 + a2) - x
count += diff
# print('--> {}'.format(diff))
if a1 > a2:
i1, i2 = i - 1, i
else:
i1, i2 = i, i - 1
if A[i1] > diff:
A[i1] -= diff
else:
A[i2] -= diff - A[i1]
A[i1] = 0
return count
if __name__ == "__main__":
N, x = map(int, input().split())
A = [int(s) for s in input().split()]
ans = boxes_and_candies(N, x, A)
print(ans)
|
s900723918
|
Accepted
| 99
| 14,592
| 631
|
def boxes_and_candies(N: int, x: int, A: list) -> int:
count = 0
for i in range(1, N):
a1, a2 = A[i - 1], A[i]
# print(a1, a2)
if a1 + a2 <= x:
# OK
# print('--> OK')
continue
diff = (a1 + a2) - x
count += diff
# print('--> {}'.format(diff))
if a2 > diff:
A[i] -= diff
else:
A[i-1] -= diff - A[i]
A[i] = 0
return count
if __name__ == "__main__":
N, x = map(int, input().split())
A = [int(s) for s in input().split()]
ans = boxes_and_candies(N, x, A)
print(ans)
|
s025378954
|
p02612
|
u556589653
| 2,000
| 1,048,576
|
Wrong Answer
| 26
| 8,976
| 31
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
print((int(input())%1000)%1000)
|
s385577394
|
Accepted
| 29
| 9,152
| 75
|
N = int(input())
K = N%1000
if K == 0:
print(0)
else:
print(1000-K)
|
s672762661
|
p03599
|
u697658632
| 3,000
| 262,144
|
Wrong Answer
| 119
| 12,456
| 594
|
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
|
a, b, c, d, e, f = map(int, input().split())
w = []
s = []
for i in range(f // (100 * a) + 1):
for j in range((f - 100 * a * i) // (100 * b) + 1):
if 100 * a * i + 100 * b * j <= f:
w.append(100 * a * i + 100 * b * j)
for i in range(f // c + 1):
for j in range((f - c * i) // d + 1):
if c * i + d * j <= f:
s.append(c * i + d * j)
ans = (100 * a, 0)
l = 0
for i in w:
for j in range(l, len(s)):
if i + s[j] > f:
break
if s[j] > i // 100 * e:
break
if ans[1] * i < s[j] * ans[0]:
ans = (i, s[j])
l = j
print(ans[0] + ans[1], ans[1])
|
s884692070
|
Accepted
| 206
| 13,384
| 610
|
a, b, c, d, e, f = map(int, input().split())
w = []
s = []
for i in range(f // (100 * a) + 1):
for j in range((f - 100 * a * i) // (100 * b) + 1):
if 100 * a * i + 100 * b * j <= f:
w.append(100 * a * i + 100 * b * j)
for i in range(f // c + 1):
for j in range((f - c * i) // d + 1):
if c * i + d * j <= f:
s.append(c * i + d * j)
w.sort()
s.sort()
ans = (100 * a, 0)
l = 0
for i in w:
for j in range(l, len(s)):
if i + s[j] > f:
break
if s[j] > i // 100 * e:
break
l = j
if ans[1] * i < s[j] * ans[0]:
ans = (i, s[j])
print(ans[0] + ans[1], ans[1])
|
s278920461
|
p00001
|
u531482846
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,356
| 119
|
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
|
from sys import stdin
ns = []
for n in stdin:
ns.append(n)
ns.sort(reverse = True)
for i in range(3):
print(ns[i])
|
s082644872
|
Accepted
| 60
| 7,768
| 93
|
from sys import stdin
for x in sorted([int(l) for l in stdin],reverse=True)[0:3]:
print(x)
|
s651811467
|
p03694
|
u453815934
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 58
|
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along _TopCoDeer street_. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.
|
a = sorted((map(int,input().split())))
print(a[-1] - a[0])
|
s857130056
|
Accepted
| 17
| 2,940
| 70
|
b = input()
a = sorted((map(int,input().split())))
print(a[-1] - a[0])
|
s839937380
|
p03598
|
u133936772
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 105
|
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
|
n = int(input())
k = int(input())
l = map(int,input().split())
print(sum(min(i,k-i) for i in range(n))*2)
|
s583201844
|
Accepted
| 17
| 2,940
| 89
|
input()
k = int(input())
l = map(int,input().split())
print(sum(min(i,k-i) for i in l)*2)
|
s255038864
|
p02612
|
u889919275
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,144
| 32
|
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)
|
s501054875
|
Accepted
| 29
| 9,104
| 117
|
N = int(input())
if N % 1000 == 0:
ans1 = 0
else:
index = N // 1000
ans1 = 1000*(index+1) - N
print(ans1)
|
s149490850
|
p03610
|
u174273188
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,188
| 93
|
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.
|
def resolve():
s = input()
print(s[1::2])
if __name__ == "__main__":
resolve()
|
s782816304
|
Accepted
| 18
| 3,572
| 101
|
def resolve():
s = input()
print("".join(s[::2]))
if __name__ == "__main__":
resolve()
|
s765757012
|
p00016
|
u744114948
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,852
| 201
|
When a boy was cleaning up after his grand father passing, he found an old paper: In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper. For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town. You can assume that d ≤ 100 and -180 ≤ t ≤ 180\.
|
import math
x=0
y=0
angle=0
while True:
r,c=map(int, input().split(","))
if r == c == 0:
break
x += r*math.cos(-angle)
y += r*math.sin(-angle)
angle += c
print(x)
print(y)
|
s158968516
|
Accepted
| 30
| 6,852
| 223
|
import math
x=0
y=0
angle=0
while True:
r,c=map(int, input().split(","))
if r == c == 0:
break
y += r*math.cos(angle)
x += r*math.sin(angle)
angle -= c*math.pi/180
print(int(-x))
print(int(y))
|
s582084732
|
p03337
|
u702786238
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 121
|
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
|
a,b = map(int, input().split())
if (a>=0) & (b>=0):
print(a*b)
elif (a<0) & (b<0):
print(a*b)
elif b<0:
print(a-b)
|
s844822662
|
Accepted
| 17
| 2,940
| 60
|
a,b = map(int, input().split())
print(max([a*b, a+b, a-b]))
|
s128370107
|
p03964
|
u055687574
| 2,000
| 262,144
|
Wrong Answer
| 27
| 3,064
| 278
|
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time. Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
|
N = int(input())
l = [0, 0]
for _ in range(N):
t, a = map(int, input().split())
if t >= l[0] and a >= l[1]:
l = [t, a]
else:
print(t, a)
temp = max((l[0] - 1) // t + 1, (l[1] - 1) // a + 1)
l = [t * temp, a * temp]
print(sum(l))
|
s468589675
|
Accepted
| 21
| 3,060
| 258
|
N = int(input())
l = [0, 0]
for _ in range(N):
t, a = map(int, input().split())
if t >= l[0] and a >= l[1]:
l = [t, a]
else:
temp = max((l[0] - 1) // t + 1, (l[1] - 1) // a + 1)
l = [t * temp, a * temp]
print(sum(l))
|
s448166383
|
p02865
|
u960611411
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 3,060
| 78
|
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
|
a = int(input())
if a%2 == 0:
b = a/2 - 1
else: b = (a + 1)/2 - 1
print(b)
|
s382062448
|
Accepted
| 20
| 3,060
| 83
|
a = int(input())
if a%2 == 0:
b = a/2 - 1
else: b = (a + 1)/2 - 1
print(int(b))
|
s946574874
|
p03598
|
u074220993
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,148
| 131
|
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
|
N = int(input())
K = int(input())
X = [int(x) for x in input().split()]
ans = 0
for x in X:
ans += min(x, abs(x-K))
print(ans)
|
s032410921
|
Accepted
| 28
| 9,072
| 97
|
with open(0) as f:
N, K, *X = map(int, f.read().split())
print(2*sum(min(x, K-x) for x in X))
|
s129771334
|
p03555
|
u957084285
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 79
|
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
S=list(input())
T=list(reversed(input()))
print(S,T)
print(["NO","YES"][S==T])
|
s472246436
|
Accepted
| 17
| 2,940
| 68
|
S=list(input())
T=list(reversed(input()))
print(["NO","YES"][S==T])
|
s748937333
|
p03573
|
u066455063
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 108
|
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
|
A, B, C = map(int, input().split())
if A == B:
print(C)
elif B == C:
print(A)
else:
print(A)
|
s288422639
|
Accepted
| 17
| 2,940
| 108
|
A, B, C = map(int, input().split())
if A == B:
print(C)
elif B == C:
print(A)
else:
print(B)
|
s909732397
|
p00045
|
u150984829
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,616
| 133
|
販売単価と販売数量を読み込んで、販売金額の総合計と販売数量の平均を出力するプログラムを作成してください。
|
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
print(sum(a*n for a,n in s),int([sum(x)for x in zip(*s)][1]/len(s)+.5))
|
s417209891
|
Accepted
| 20
| 5,608
| 112
|
import sys
s=m=k=0
for e in sys.stdin:
a,n=map(int,e.split(','))
s+=a*n;m+=n;k+=1
print(s)
print(int(m/k+.5))
|
s481136404
|
p02645
|
u039355749
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 9,024
| 24
|
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
|
s = input()
print(s[:2])
|
s628599149
|
Accepted
| 19
| 9,084
| 24
|
s = input()
print(s[:3])
|
s634083635
|
p03385
|
u296518383
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 62
|
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
|
S=input()
print("YES" if sorted(S) == ["a","b","c"] else "NO")
|
s052364582
|
Accepted
| 17
| 2,940
| 70
|
S=input()
print("Yes" if "a" in S and "b" in S and "c" in S else "No")
|
s009059225
|
p03828
|
u933920971
| 2,000
| 262,144
|
Wrong Answer
| 209
| 12,504
| 544
|
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 8 15:39:57 2017
@author: kes31
"""
#dicstra
import numpy as np
N = int(input())
orig = np.arange(1,N+1)
data = np.arange(1,N+1)
cont = np.zeros_like(data)
for m in range(2,N+1):
while(True):
ct = 0
mask = (data%m)==0
data[mask]=data[mask]//m
ct = np.sum(mask)
cont[m-1]+=ct
if ct == 0:
break
#print (data)
alcount = 1
for c in cont:
alcount = alcount*int(c+1)
alcount = np.mod(alcount*(c+1),1000000007)
print (alcount)
|
s327372396
|
Accepted
| 209
| 12,500
| 538
|
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 8 15:39:57 2017
@author: kes31
"""
#dicstra
import numpy as np
N = int(input())
orig = np.arange(1,N+1)
data = np.arange(1,N+1)
cont = np.zeros_like(data)
for m in range(2,N+1):
while(True):
ct = 0
mask = (data%m)==0
data[mask]=data[mask]//m
ct = np.sum(mask)
cont[m-1]+=ct
if ct == 0:
break
#print (data)
alcount = 1
for c in cont:
alcount = alcount*int(c+1)
alcount = np.mod(alcount,1000000007)
print (alcount)
|
s777684581
|
p02407
|
u313089641
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,596
| 86
|
Write a program which reads a sequence and prints it in the reverse order.
|
N = int(input())
n = [int(i) for i in input().split()]
n.sort()
n.reverse()
print(n)
|
s254726759
|
Accepted
| 20
| 5,604
| 130
|
N = int(input())
n = [int(i) for i in input().split()]
n.reverse()
result = map(str, n)
result = " ".join(result)
print(result)
|
s947132836
|
p03399
|
u465629938
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 98
|
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())
print(min(a, b) + min(d, d))
|
s314592943
|
Accepted
| 20
| 3,316
| 98
|
a = int(input())
b = int(input())
c = int(input())
d = int(input())
print(min(a, b) + min(c, d))
|
s058014084
|
p02417
|
u626838615
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,416
| 235
|
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
|
alphabet = {chr(c):0 for c in range(ord("a"),ord("z")+1)}
s = input()
for i in s:
if i in alphabet:
alphabet[i.lower()] += 1
for key in range(ord("a"),ord("z")+1):
ck = chr(key)
print("%s : %d" % (ck,alphabet[ck]))
|
s695036360
|
Accepted
| 30
| 7,476
| 303
|
alphabet = {chr(c):0 for c in range(ord("a"),ord("z")+1)}
s = ""
while True:
try:
s += input().lower()
except:
break
for i in s:
if i in alphabet:
alphabet[i] += 1
for key in range(ord("a"),ord("z")+1):
ck = chr(key)
print("%s : %d" % (ck,alphabet[ck]))
|
s610818782
|
p02262
|
u566311709
| 6,000
| 131,072
|
Wrong Answer
| 20
| 5,612
| 500
|
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
|
def insertion_sort(a, g, cnt):
for i in range(g, len(a)):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
return cnt
n = int(input())
g = [1]
t = 1
cnt = 0
while 1:
t = 3 * t + 1
if t < n // 9 and len(g) < 100:
g += [t]
else:
g = g[::-1]
break
a = [int(input()) for _ in range(n)]
for i in range(0, len(g)):
cnt = insertion_sort(a, g[i], cnt)
print(len(g))
print(*g)
print(cnt)
for i in a: print(i)
|
s138072309
|
Accepted
| 18,850
| 45,668
| 495
|
def insertion_sort(a, g, cnt):
for i in range(g, len(a)):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
return cnt
n = int(input())
g = [1]
t = 1
cnt = 0
while 1:
t = 3 * t + 1
if t < n and len(g) < 100:
g += [t]
else:
g = g[::-1]
break
a = [int(input()) for _ in range(n)]
for i in range(0, len(g)):
cnt = insertion_sort(a, g[i], cnt)
print(len(g))
print(*g)
print(cnt)
for i in a: print(i)
|
s579603847
|
p03605
|
u972892985
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 68
|
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
n = int(input())
if n % 13 == 0:
print("Yes")
else:
print("No")
|
s098939753
|
Accepted
| 17
| 2,940
| 89
|
n = list(input())
if n[0] == "9" or n[1] == "9":
print("Yes")
else:
print("No")
|
s179379356
|
p03090
|
u099566485
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 3,612
| 302
|
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
|
#AGC031-B
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
if n%2==0:
for i in range(n):
for j in range(n):
if i<j and i+j+2!=1+n:
print(i+1,j+1)
else:
print(-1)
|
s123461854
|
Accepted
| 24
| 3,612
| 508
|
#AGC031-B
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
if n%2==0:
print(n*(n-2)//2)
for i in range(n):
for j in range(n):
if i<j and i+j+2!=1+n:
print(i+1,j+1)
else:
print((n-1)*(n-3)//2+n-1)
for i in range(n-1):
for j in range(n-1):
if i<j and i+j+2!=1+n-1:
print(i+1,j+1)
for i in range(n-1):
print(i+1,n)
|
s817730829
|
p03854
|
u062864034
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,188
| 165
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
S = input().replace("dream","&").replace("erase","%").replace("&er","").replace("%r","").replace("&","").replace("%","")
if S:
print("no")
else:
print("yes")
|
s914273485
|
Accepted
| 18
| 3,188
| 165
|
S = input().replace("dream","&").replace("erase","%").replace("&er","").replace("%r","").replace("&","").replace("%","")
if S:
print("NO")
else:
print("YES")
|
s576097788
|
p03386
|
u778700306
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 197
|
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
|
a,b,k=map(int, input().split())
low = [a + i for i in range(0, k)]
high = [b - i for i in range(0, k)]
res = set(low + high)
res = filter(lambda s: a <= s <= b, res)
for x in res:
print(x)
|
s354414655
|
Accepted
| 17
| 3,060
| 205
|
a,b,k=map(int, input().split())
low = [a + i for i in range(0, k)]
high = [b - i for i in range(0, k)]
res = set(low + high)
res = sorted(filter(lambda s: a <= s <= b, res))
for x in res:
print(x)
|
s504340791
|
p02613
|
u825186577
| 2,000
| 1,048,576
|
Wrong Answer
| 159
| 9,128
| 219
|
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())
ans = {'AC':0,'WA':0,'TLE':0,'RE':0}
for i in range(N):
a = input()
if a in ans.keys():
ans[a] +=1
else:
ans[a] = 1
for k,v in ans.items():
print('{} × {}'.format(k,v))
|
s380426733
|
Accepted
| 160
| 9,200
| 218
|
N = int(input())
ans = {'AC':0,'WA':0,'TLE':0,'RE':0}
for i in range(N):
a = input()
if a in ans.keys():
ans[a] +=1
else:
ans[a] = 1
for k,v in ans.items():
print('{} x {}'.format(k,v))
|
s267115293
|
p02613
|
u760569096
| 2,000
| 1,048,576
|
Wrong Answer
| 154
| 9,204
| 274
|
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())
a = 0
b = 0
c = 0
d = 0
for _ in range(n):
i = input()
if i == 'AC':
a+=1
if i == 'WA':
b +=1
if i == 'TLE':
c +=1
if i == 'RE':
d+=1
print('AC × '+str(a))
print('WA × '+str(b))
print('TLE × '+str(c))
print('RE × '+str(d))
|
s220670632
|
Accepted
| 148
| 16,124
| 215
|
N = int(input())
S = []
for _ in range(N):
S.append(input())
print("AC x " + str(S.count("AC")))
print("WA x " + str(S.count("WA")))
print("TLE x " + str(S.count("TLE")))
print("RE x " + str(S.count("RE")))
|
s586078853
|
p03370
|
u744034042
| 2,000
| 262,144
|
Wrong Answer
| 37
| 2,940
| 135
|
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(map(int, input().split()))
x = x - sum(m)
y = min(m)
while x >= y:
x -= y
n += 1
print(n)
|
s022217063
|
Accepted
| 17
| 2,940
| 112
|
n,x = map(int,input().split())
m = [int(a) for a in [input() for i in range(n)]]
print(n + (x - sum(m))//min(m))
|
s587387745
|
p02845
|
u456353530
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 8
|
N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green. The person numbered i says: * "In front of me, exactly A_i people are wearing hats with the same color as mine." Assuming that all these statements are correct, find the number of possible combinations of colors of the N people's hats. Since the count can be enormous, compute it modulo 1000000007.
|
print(0)
|
s679774676
|
Accepted
| 150
| 14,020
| 232
|
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
D = [0] * 3
ans = 1
for i in A:
c = 0
for j in range(3):
if i == D[j]:
if c == 0:
D[j] += 1
c += 1
ans = ans * c % MOD
print(ans)
|
s634048740
|
p03478
|
u236720912
| 2,000
| 262,144
|
Wrong Answer
| 32
| 3,064
| 360
|
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
arr = list(map(int, input().split()))
su = 0
for i in range(1, arr[0]+1):
a = i / 10000
b = i / 1000 - a * 10
c = i / 100 - a * 100 - b * 10
d = i / 10 - a * 1000 - b * 100 - c * 10
e = i % 10
total = a + b + c + d + e
if total >= arr[1] and total <= arr[2]:
su += i
print(su)
|
s286090994
|
Accepted
| 29
| 2,940
| 94
|
n,a,b=map(int,input().split())
print(sum(i for i in range(n+1) if a<=sum(map(int,str(i)))<=b))
|
s085349123
|
p03861
|
u914948583
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 72
|
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
|
a, b, x = map(int, input().split())
cnt = int(b/x - (a-1)/x)
print(cnt)
|
s638160174
|
Accepted
| 18
| 2,940
| 164
|
a, b, x = map(int, input().split())
cnt = 0
def f(n, x=x):
if n >= 0:
return n//x + 1
else:
return 0
cnt = int(f(b) - f(a-1))
print(cnt)
|
s682508624
|
p03644
|
u300778480
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 165
|
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.
|
try:
N = int(input())
cnt = 0
for i in range(N):
if N%2 == 0:
cnt += 1
N = (N/2)
print(cnt)
except EOFError:
pass
|
s452345312
|
Accepted
| 18
| 2,940
| 255
|
try:
N = int(input())
num = [i for i in range(N+1) if i%2==0]
ans = 1
__ = 0
for i in num:
_ = format(i, 'b')[::-1].find("1")
if __ < _:
ans = i
__ = _
print(ans)
except EOFError:
pass
|
s854426031
|
p03447
|
u957872856
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 67
|
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
|
a = int(input())
b = int(input())
c = int(input())
print((a-c) % c)
|
s952274158
|
Accepted
| 18
| 2,940
| 67
|
a = int(input())
b = int(input())
c = int(input())
print((a-b) % c)
|
s410130476
|
p03695
|
u228294553
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 873
|
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
|
n=int(input())
L=list(map(int,input().split()))
L.sort()
tmp=0
cnt=0
min_c=0
max_c=0
for i in range(n):
if L[i] <= 399:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] > 399 and L[i] <= 799:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] > 799 and L[i] <= 1199:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] > 1199 and L[i] <= 1599:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] > 1599 and L[i] <= 1999:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] > 1999 and L[i] <= 2399:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] > 2399 and L[i] <= 2799:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] > 2799 and L[i] <= 3199:
cnt+=1
tmp=i
break
min_c=cnt
max_c=cnt
for i in range(tmp,n):
if L[i] >= 3200:
max_c=cnt+len(L[i:])
min_c+=1
break
print(min_c)
print(min(8,max_c))
|
s495503758
|
Accepted
| 18
| 3,064
| 884
|
n=int(input())
L=list(map(int,input().split()))
L.sort()
tmp=0
cnt=0
min_c=0
max_c=0
for i in range(n):
if L[i] <= 399:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] >= 400 and L[i] <= 799:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] >= 800 and L[i] <= 1199:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] >= 1200 and L[i] <= 1599:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] >= 1600 and L[i] <= 1999:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] >= 2000 and L[i] <= 2399:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] >= 2400 and L[i] <= 2799:
cnt+=1
tmp=i
break
for i in range(tmp,n):
if L[i] >= 2800 and L[i] <= 3199:
cnt+=1
tmp=i
break
min_c=cnt
max_c=cnt
for i in range(tmp,n):
if L[i] >= 3200:
max_c=cnt+len(L[i:])
if min_c==0:
min_c+=1
break
print(min_c,max_c)
|
s166954340
|
p00207
|
u567380442
| 1,000
| 131,072
|
Wrong Answer
| 50
| 6,852
| 1,501
|
A さんの家に親戚の B 君がやってきました。彼は 3 歳でブロックが大好きです。彼が持っているブロックは図 1 のような形をしています。 図1 B 君はボードの上にブロックを敷き詰めています。彼に「何を作っているの?」と聞くと、彼は「迷路!!」と元気よく答えました。彼の言う迷路とは、スタートからゴールまで側面が接している、同じ色のブロックだけでたどることができるブロックの配置のことだそうです。図 2 は黄色のブロックにより、左上(スタート)から右下(ゴール)へ迷路ができていることを表しています。 図2 無邪気に遊んでいる B 君を横目に、プログラマーであるあなたは、ブロックの並びが迷路となっているかを確かめてみることにしました。 ブロックの情報とスタート、ゴールの座標を入力とし、ブロックが迷路となっていれば OK 、なっていなければ NG を出力するプログラムを作成してください。 ボードは横方向に w 、縦方向に h の大きさをもち、 左上の座標は(1 , 1)、右下の座標は(w, h)とします。ブロックは 2 × 4 の長方形ですべて同じ大きさです。ブロックの色 c は 1 (白)、2 (黄)、3 (緑)、4 (青)、5 (赤) のいずれかです。ブロックのボード上での向き d は 横方向に長い場合 0 、 縦方向に長い場合 1 とします。 ブロックの位置はブロックの左上の座標 (x, y) によって表されます。なお、ブロックの位置は他のブロックと重なることは無く、ボードからはみ出すこともありません。
|
from sys import stdin
readline = stdin.readline
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
Block = namedtuple('Block', ['color', 'direction', 'x', 'y'])
def occupation_point(block):
x, y = block.x, block.y
d = [(0, 0), (1, 0), (0, 1), (1, 1)]
for dx, dy in d:
yield x + dx, y + dy
if block.direction:
y += 2
else:
x += 2
for dx, dy in d:
yield x + dx, y + dy
def paintout(board, start, value):
color = board[start.y][start.x]
if color == 0:
return
que =[(start.x, start.y)]
print('cv',color, value)
while que:
x,y = que.pop()
if board[y][x] == color:
board[y][x] = value
que.extend([(x + dx, y + dy) for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]])
def is_reachable(size, start, goal, blocks):
board = [[0] * (size.x + 2) for _ in range(size.y + 2)]
for bi in blocks:
for x, y in occupation_point(bi):
board[y][x] = bi.color
paintout(board, start, -1)
for bi in board:
print(bi)
return board[goal.y][goal.x] == -1
while True:
size = Point(*map(int, readline().split()))
if size.x == 0:
break
start = Point(*map(int, readline().split()))
goal = Point(*map(int, readline().split()))
blocks = []
for _ in range(int(readline())):
blocks.append(Block(*map(int, readline().split())))
print('OK' if is_reachable(size, start, goal, blocks) else 'NG')
|
s544711672
|
Accepted
| 40
| 6,832
| 1,433
|
from sys import stdin
readline = stdin.readline
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
Block = namedtuple('Block', ['color', 'direction', 'x', 'y'])
def occupation_point(block):
x, y = block.x, block.y
d = [(0, 0), (1, 0), (0, 1), (1, 1)]
for dx, dy in d:
yield x + dx, y + dy
if block.direction:
y += 2
else:
x += 2
for dx, dy in d:
yield x + dx, y + dy
def paintout(board, start, value):
color = board[start.y][start.x]
if color == 0:
return
que =[(start.x, start.y)]
while que:
x,y = que.pop()
if board[y][x] == color:
board[y][x] = value
que.extend([(x + dx, y + dy) for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]])
def is_reachable(size, start, goal, blocks):
board = [[0] * (size.x + 2) for _ in range(size.y + 2)]
for bi in blocks:
for x, y in occupation_point(bi):
board[y][x] = bi.color
paintout(board, start, -1)
return board[goal.y][goal.x] == -1
while True:
size = Point(*map(int, readline().split()))
if size.x == 0:
break
start = Point(*map(int, readline().split()))
goal = Point(*map(int, readline().split()))
blocks = []
for _ in range(int(readline())):
blocks.append(Block(*map(int, readline().split())))
print('OK' if is_reachable(size, start, goal, blocks) else 'NG')
|
s183201665
|
p02401
|
u706217959
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,664
| 730
|
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
import math
class Calc:
def __init__(self,a,op,b):
self.a = a
self.b = b
self.op = op
def calc(self):
if self.op == "+":
return self.a + self.b
elif self.op == "-":
return self.a - self.b
elif self.op == "*":
return self.a * self.b
elif self.op == "/":
return self.a / self.b
else:
return "Invalid Operator."
def main():
data = []
while 1:
n = input().split()
a = int(n[0])
op = n[1]
b = int(n[2])
if op == "?":
break
data.append(Calc(a,op,b))
for i in data:
print(i.calc())
if __name__ == "__main__":
main()
|
s944205442
|
Accepted
| 20
| 5,660
| 863
|
import math
class Calc:
def __init__(self,a,op,b):
self.a = a
self.b = b
self.op = op
def calc(self):
if self.op == "+":
return self.a + self.b
elif self.op == "-":
return self.a - self.b
elif self.op == "*":
return self.a * self.b
elif self.op == "/":
try:
ans = self.a / self.b
except ZeroDivisionError:
return 0
else:
return ans
else:
return "Invalid Operator."
def main():
data = []
while 1:
n = input().split()
a = int(n[0])
op = n[1]
b = int(n[2])
if op == "?":
break
data.append(Calc(a,op,b))
for i in data:
print(int(i.calc()))
if __name__ == "__main__":
main()
|
s955200690
|
p03814
|
u316386814
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,716
| 63
|
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, b = s.find('A'), s.rfind('Z')
print(s[a:b + 1])
|
s944972945
|
Accepted
| 18
| 3,500
| 62
|
s = input()
a, b = s.find('A'), s.rfind('Z')
print(b + 1 - a)
|
s627456673
|
p03090
|
u263830634
| 2,000
| 1,048,576
|
Wrong Answer
| 25
| 3,700
| 450
|
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
|
N = int(input())
M = (N * (N - 1)) // 2
ans_lst = [[1] * N for _ in range(N)]
if N % 2 == 0:
for i in range(N):
ans_lst[i][N - i - 1] = 0
else:
for i in range(N - 1):
ans_lst[i][N - i -2] = 0
#output
M = 0
for i in range(N):
for j in range(1, N):
if ans_lst[i][j] == 1:
M += 1
print (M)
for i in range(N):
for j in range(i + 1, N):
if ans_lst[i][j] == 1:
print (i + 1, j + 1)
|
s084967625
|
Accepted
| 26
| 3,956
| 500
|
N = int(input())
if N % 2 == 0:
G = []
G_append = G.append
for i in range(1, N):
for j in range(i + 1, N + 1):
if i + j != (1 + N):
G_append((i, j))
print (len(G))
for g in G:
print (*g, sep = ' ')
else:
G = []
G_append = G.append
for i in range(1, N):
for j in range(i + 1, N + 1):
if i + j != N:
G_append((i, j))
print (len(G))
for g in G:
print (*g, sep = ' ')
|
s008271984
|
p02612
|
u092646083
| 2,000
| 1,048,576
|
Wrong Answer
| 27
| 9,100
| 42
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N = int(input())
ans = N % 1000
print(ans)
|
s653827682
|
Accepted
| 28
| 9,148
| 68
|
N = int(input())
ans = N % 1000
ans = (1000 - ans) % 1000
print(ans)
|
s374655729
|
p04043
|
u080986047
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 124
|
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
|
li = input().split()
if len(li[0]) ==5 and len(li[1]) == 7 \
and len(li[2]) == 5:
print("Yes")
else:
print("No")
|
s373400455
|
Accepted
| 17
| 2,940
| 105
|
li = input().split()
if li.count('7') == 1 and li.count("5") == 2:
print("YES")
else:
print("NO")
|
s768344159
|
p03380
|
u300579805
| 2,000
| 262,144
|
Wrong Answer
| 98
| 14,428
| 329
|
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.
|
N=int(input())
A = list(map(int, input().split()))
ans1 = max(A)
kouho = ans1 // 2
A.sort()
for i in range(N):
if(A[i] >= kouho):
kouho1 = A[i]
kouho2 = A[i-1]
if (ans1 == kouho1):
ans2 = kouho2
elif (abs(ans1-2*kouho1) <= abs(ans1-2*kouho2)):
ans2 = kouho1
else:
ans2 = kouho2
print(ans1,ans2)
|
s302979115
|
Accepted
| 85
| 14,428
| 343
|
N=int(input())
A = list(map(int, input().split()))
ans1 = max(A)
kouho = ans1 // 2
A.sort()
for i in range(N):
if(A[i] >= kouho):
kouho1 = A[i]
kouho2 = A[i-1]
break
if (ans1 == kouho1):
ans2 = kouho2
elif (abs(ans1-2*kouho1) <= abs(ans1-2*kouho2)):
ans2 = kouho1
else:
ans2 = kouho2
print(ans1,ans2)
|
s541578722
|
p03624
|
u050428930
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,956
| 158
|
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.
|
N=[chr(i) for i in range(97,123)]
s=sorted(set(list(input())))
for i in s:
if i not in N:
print(i)
break
else:
print("None")
|
s400638874
|
Accepted
| 20
| 3,956
| 150
|
N=[chr(i) for i in range(97,123)]
s=sorted(set(list(input())))
for i in N:
if i not in s:
print(i)
break
else:
print("None")
|
s272688993
|
p03494
|
u969848070
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,180
| 175
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(200):
for j in range(n):
if a[j] %2 != 0:
print(ans)
exit()
ans += 1
print(ans)
|
s938637846
|
Accepted
| 29
| 9,164
| 261
|
n = int(input())
a = list(map(int, input().split()))
ans = 0
while True:
b = 0
for i in range(n):
if a[i] % 2 != 0:
print(ans)
exit()
else:
a[i] = a[i] /2
b += 1
if b % n == 0:
ans += 1
else:
print(ans)
exit()
|
s888827012
|
p03448
|
u038396582
| 2,000
| 262,144
|
Wrong Answer
| 52
| 3,060
| 247
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
|
a = int(input())
b = int(input())
c = int(input())
x = int(input())
res = 0
for i in range(a):
for j in range(b):
for k in range(c):
sum = 500*i + 100*j + 50*k
if sum == x:
res += 1
print(res)
|
s532070680
|
Accepted
| 59
| 3,060
| 253
|
a = int(input())
b = int(input())
c = int(input())
x = int(input())
res = 0
for i in range(a+1):
for j in range(b+1):
for k in range(c+1):
sum = 500*i + 100*j + 50*k
if sum == x:
res += 1
print(res)
|
s321383181
|
p03944
|
u853900545
| 2,000
| 262,144
|
Wrong Answer
| 87
| 3,064
| 571
|
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
|
w,h,n = map(int,input().split())
s = [[1]*w]*h
for i in range(n):
x,y,a = map(int,input().split())
if a == 1:
for j in range(h):
for k in range(x):
s[j][k] = 0
elif a == 2:
for j in range(h):
for k in range(x):
s[j][-1-k] = 0
elif a == 3:
for j in range(y):
for k in range(w):
s[j][k] = 0
elif a == 4:
for j in range(y):
for k in range(w):
s[-1-j][k] = 0
c = 0
for i in range(h):
c += sum(s[i])
print(c)
|
s439385505
|
Accepted
| 18
| 3,064
| 299
|
w,h,n = map(int,input().split())
x,y = 0,0
X,Y = w,h
for i in range(n):
a,b,c = map(int,input().split())
if c == 1 and x < a:
x = a
elif c == 2 and a < X:
X = a
elif c == 3 and y < b:
y = b
elif c == 4 and b < Y:
Y = b
print(max(X-x,0)*max(Y-y,0))
|
s959295983
|
p03826
|
u429995021
| 2,000
| 262,144
|
Wrong Answer
| 51
| 3,188
| 85
|
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
|
a,b,c,d = map(int,input().split())
if a**b >= c*d:
print(a**b)
else:
print(c**d)
|
s353610248
|
Accepted
| 23
| 3,064
| 83
|
a,b,c,d = map(int,input().split())
if a*b >= c*d:
print(a*b)
else:
print(c*d)
|
s467232483
|
p03339
|
u957167787
| 2,000
| 1,048,576
|
Wrong Answer
| 451
| 42,884
| 433
|
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
|
N = int(input())
S = input()
east = [0]*N
west = [0]*N
for i in range(N):
if S[i] == 'E':
east[i] = 1
else:
west[i] = 1
sum_east = [0]*(N+1)
sum_west = [0]*(N+1)
for i in range(N):
sum_west[i+1] = sum_west[i] + west[i]
sum_east[N-i-1] = sum_east[N-i] + east[N-i-1]
print(sum_west, sum_east)
ans = 10**6
for i in range(N):
ans = min(ans, sum_west[i] + sum_east[i+1])
#print(ans)
print(ans)
|
s050679678
|
Accepted
| 423
| 31,820
| 434
|
N = int(input())
S = input()
east = [0]*N
west = [0]*N
for i in range(N):
if S[i] == 'E':
east[i] = 1
else:
west[i] = 1
sum_east = [0]*(N+1)
sum_west = [0]*(N+1)
for i in range(N):
sum_west[i+1] = sum_west[i] + west[i]
sum_east[N-i-1] = sum_east[N-i] + east[N-i-1]
#print(sum_west, sum_east)
ans = 10**6
for i in range(N):
ans = min(ans, sum_west[i] + sum_east[i+1])
#print(ans)
print(ans)
|
s450404853
|
p03644
|
u569117803
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 111
|
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 = 0
a = 0
while a == 0:
a = (n % 2)
if a == 0:
c += 1
n = (n/2)
print(c)
|
s217176256
|
Accepted
| 24
| 3,572
| 390
|
n = int(input())
n += 1
import copy
ans = 0
ans_c = 0
for i in reversed(range(n)):
check = copy.copy(i)
div = 0
count = 0
while div == 0:
div = (i % 2)
i = i // 2
if div == 0:
count += 1
if i == 0:
break
if ans_c < count:
ans = check
ans_c = count
if ans == 0:
ans += 1
print(ans)
|
s564927672
|
p03477
|
u622570247
| 2,000
| 262,144
|
Wrong Answer
| 24
| 8,984
| 152
|
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
a = list(map(int, input().split()))
a = a[0] + a[1] - a[2] - a[3]
if a < 0:
print('Left')
elif a > 0:
print('Right')
else:
print('Balanced')
|
s717329984
|
Accepted
| 27
| 9,028
| 154
|
a = list(map(int, input().split()))
a = a[0] + a[1] - a[2] - a[3]
if a == 0:
print('Balanced')
elif a > 0:
print('Left')
else:
print('Right')
|
s339610715
|
p02401
|
u195186080
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,548
| 309
|
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
while True:
formula = input().split()
if '?' in formula:
break
a,b = int(formula[0]),int(formula[2])
if formula[1] == '+':
print(a+b)
elif formula[1] == '-':
print(a-b)
elif formula[1] == '*':
print(a*b)
elif formula[1] == '-':
print(a // b)
|
s287251359
|
Accepted
| 30
| 7,600
| 307
|
while True:
formula = input().split()
if '?' in formula:
break
a,b = int(formula[0]),int(formula[2])
if formula[1] == '+':
print(a+b)
elif formula[1] == '-':
print(a-b)
elif formula[1] == '*':
print(a*b)
elif formula[1] == '/':
print(a//b)
|
s751496974
|
p02645
|
u955123468
| 2,000
| 1,048,576
|
Wrong Answer
| 25
| 9,092
| 84
|
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
|
S = input(str("Input text: "))
S = S.lower()
if 3 <= len(S) <= 20:
print(S[:3])
|
s002236706
|
Accepted
| 23
| 9,024
| 66
|
S = input(str(""))
if 3 <= len(S) <= 20:
print(S[:3].lower())
|
s196683085
|
p03624
|
u771532493
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,956
| 99
|
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.
|
l=[chr(i) for i in range(65,65+26)]
s=list(input())
a=set(l)-set(s)
a=list(a)
a.sort()
print(a[0])
|
s790905300
|
Accepted
| 23
| 3,956
| 135
|
l=[chr(i) for i in range(97,97+26)]
s=list(input())
a=set(l)-set(s)
a=list(a)
a.sort()
if len(a)>0:
print(a[0])
else:
print('None')
|
s807503493
|
p02600
|
u486885312
| 2,000
| 1,048,576
|
Wrong Answer
| 33
| 9,312
| 1,994
|
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
|
# m-solutions2020_a.py
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
# FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
X = int(lines[0])
if X < 600:
ret = 8
elif X < 800:
ret = 7
elif X < 1000:
ret = 6
elif X < 1200:
ret = 5
elif X < 1400:
ret = 4
elif X < 1600:
ret = 3
elif X < 1800:
ret = 2
else:
ret = 1
return [ret]
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
def get_testdata(pattern):
if pattern == 1:
lines_input = ['']
lines_export = ['']
if pattern == 2:
lines_input = ['']
lines_export = ['']
if pattern == 3:
lines_input = ['']
lines_export = ['']
return lines_input, lines_export
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
if mode > 0:
print(f'lines_input=[{lines_input}]')
print(f'lines_export=[{lines_export}]')
print(f'lines_result=[{lines_result}]')
if lines_result == lines_export:
print('OK')
else:
print('NG')
finished = time.time()
duration = finished - started
print(f'duration=[{duration}]')
if __name__ == '__main__':
main()
|
s281336512
|
Accepted
| 33
| 9,280
| 1,929
|
# m-solutions2020_a.py
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
# FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
X = int(lines[0])
if X < 600:
ret = 8
elif X < 800:
ret = 7
elif X < 1000:
ret = 6
elif X < 1200:
ret = 5
elif X < 1400:
ret = 4
elif X < 1600:
ret = 3
elif X < 1800:
ret = 2
else:
ret = 1
return [ret]
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
def get_testdata(pattern):
if pattern == 1:
lines_input = [725]
lines_export = [7]
if pattern == 2:
lines_input = [1600]
lines_export = [2]
return lines_input, lines_export
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
def main():
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
if mode > 0:
print(f'lines_input=[{lines_input}]')
print(f'lines_export=[{lines_export}]')
print(f'lines_result=[{lines_result}]')
if lines_result == lines_export:
print('OK')
else:
print('NG')
# finished = time.time()
# print(f'duration=[{duration}]')
if __name__ == '__main__':
main()
|
s804401343
|
p00444
|
u227162786
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,488
| 223
|
太郎君はよくJOI雑貨店で買い物をする. JOI雑貨店には硬貨は500円,100円,50円,10円,5円,1円が十分な数だけあり,いつも最も枚数が少なくなるようなおつりの支払い方をする.太郎君がJOI雑貨店で買い物をしてレジで1000円札を1枚出した時,もらうおつりに含まれる硬貨の枚数を求めるプログラムを作成せよ. 例えば入力例1の場合は下の図に示すように,4を出力しなければならない.
|
coins = [500, 100, 50, 10, 5, 1]
if __name__ == '__main__':
p = int(input())
ch = 1000 - p
count = 0
for coin in coins:
n = ch // coin
ch -= coin * n
count += n
print(count)
|
s153786519
|
Accepted
| 20
| 7,648
| 312
|
coins = [500, 100, 50, 10, 5, 1]
if __name__ == '__main__':
while True:
p = int(input())
if p == 0:
break
ch = 1000 - p
count = 0
for coin in coins:
n = ch // coin
ch -= coin * n
count += n
print(count)
|
s255827782
|
p03598
|
u025287757
| 2,000
| 262,144
|
Wrong Answer
| 148
| 12,492
| 197
|
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
|
import numpy as np
def main():
N = int(input())
K = int(input())
x = list(map(int, input().split()))
x = np.array(x)
print(min(np.sum(x), np.sum(K-x)))
if __name__ == "__main__":
main()
|
s875320120
|
Accepted
| 153
| 12,436
| 204
|
import numpy as np
def main():
N = int(input())
K = int(input())
x = list(map(int, input().split()))
ans = 0
for i in x:
ans += 2*min(i, K-i)
print(ans)
if __name__ == "__main__":
main()
|
s893740517
|
p03449
|
u527261492
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,064
| 243
|
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
|
n=int(input())
a=[]
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.append(b)
a.append(c)
d=[]
for i in range(n):
cnd=a[0][i]
for j in range(n):
cnd+=(a[0][j] if i<j+1 else a[1][j])
d.append(cnd)
print(max(d))
|
s568543950
|
Accepted
| 20
| 3,064
| 286
|
n=int(input())
a=[]
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.append(b)
a.append(c)
d=[]
cnd=a[0][0]
for i in range(n):
for j in range(n):
if i>j:
cnd+=a[0][j]
else:
cnd+=a[1][j]
d.append(cnd)
cnd=a[0][min(n-1,i+1)]
print(max(d))
|
s974915075
|
p03473
|
u117348081
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 27
|
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
|
m = int(input())
ans = 48-m
|
s097696586
|
Accepted
| 17
| 2,940
| 38
|
m = int(input())
ans = 48-m
print(ans)
|
s129199208
|
p03024
|
u762420987
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 3,060
| 79
|
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
|
S = list(input())
if S.count("o") >= 8:
print("YES")
else:
print("NO")
|
s425690737
|
Accepted
| 17
| 2,940
| 101
|
S = list(input())
k = len(S)
if S.count("o") + (15 - k) >= 8:
print("YES")
else:
print("NO")
|
s849954100
|
p03493
|
u169657264
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 99
|
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
s=input()
count=0
if s[0]==1:
count+=1
if s[1]==1:
count+=1
if s[2]==1:
count+=1
print(count)
|
s729614475
|
Accepted
| 18
| 2,940
| 127
|
s = input()
count = 0
if s[0] == "1":
count += 1
if s[1] == "1":
count += 1
if s[2] == "1":
count += 1
print(count)
|
s887667685
|
p03854
|
u509197077
| 2,000
| 262,144
|
Wrong Answer
| 69
| 3,188
| 364
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
S=input()
flag=True
words={'dream','dreamer','erase','eraser'}
while flag:
if S=="" :
break
if S[-7:] in words:
S=S[0:-7]
continue
elif S[-6:] in words:
S=S[0:-6]
continue
elif S[-5:] in words:
S=S[0:-5]
continue
else :
flag=False
if flag:
print("Yes")
else :
print("No")
|
s385420023
|
Accepted
| 67
| 3,188
| 364
|
S=input()
flag=True
words={'dream','dreamer','erase','eraser'}
while flag:
if S=="" :
break
if S[-7:] in words:
S=S[0:-7]
continue
elif S[-6:] in words:
S=S[0:-6]
continue
elif S[-5:] in words:
S=S[0:-5]
continue
else :
flag=False
if flag:
print("YES")
else :
print("NO")
|
s317041415
|
p03696
|
u463655976
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 153
|
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
|
N = input()
cnt = 0
ans = 0
for x in input():
if x == "(":
cnt += 1
else:
cnt -= 1
if cnt < 0:
cnt += 1
ans += 1
print(ans)
|
s252897637
|
Accepted
| 17
| 2,940
| 195
|
N = input()
cnt = 0
s = ""
for x in input():
if x == "(":
cnt += 1
else:
cnt -= 1
if cnt < 0:
cnt += 1
s = "(" + s
s += x
for _ in range(cnt):
s += ")"
print(s)
|
s151583475
|
p03110
|
u095426154
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 2,940
| 211
|
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
|
ninzu=input()
dama_sum=0
for a in range(int(ninzu)):
dama=input()
dama_spl=dama.split(" ")
if dama_spl[1]=="JPY":
r=1
else:
r=380000
dama_sum += float(dama_spl[0])*r
dama_sum
|
s370637428
|
Accepted
| 18
| 2,940
| 218
|
ninzu=input()
dama_sum=0
for a in range(int(ninzu)):
dama=input()
dama_spl=dama.split(" ")
if dama_spl[1]=="JPY":
r=1
else:
r=380000
dama_sum += float(dama_spl[0])*r
print(dama_sum)
|
s184914532
|
p03861
|
u896741788
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 52
|
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
|
a,s,d=map(int,input().split())
print(s//d+(-a+1)//d)
|
s215310320
|
Accepted
| 18
| 2,940
| 80
|
a,s,d=map(int,input().split())
l=1+ (a-1)//d if a>=1 else 0
u=s//d+1
print(u-l)
|
s646401506
|
p02612
|
u165443309
| 2,000
| 1,048,576
|
Wrong Answer
| 27
| 8,968
| 62
|
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.
|
def solve():
n = int(input())
print(n % 1000)
solve()
|
s154941253
|
Accepted
| 28
| 9,004
| 79
|
n = int(input())
if n % 1000 == 0:
print(0)
else:
print(1000 - (n % 1000))
|
s747020031
|
p00503
|
u352394527
| 8,000
| 131,072
|
Wrong Answer
| 30
| 5,628
| 1,417
|
The Indian Ocean stretches to the west of Australia. His JOI, a marine researcher, studies the properties of certain his N species of fish that live in the Indian Ocean. For each fish species, a rectangular parallelepiped habitat is defined in the sea. Fish can move anywhere within their range, including boundaries, but they never leave their range. A point in the ocean is represented by three real numbers (x, y, d): (x, y, d) are x to the east and y to the north of a point as viewed from above. Denotes a point that is advanced and has a depth of d from the sea surface. However, the sea surface is assumed to be flat. Mr. JOI would like to know how many places overlap the ranges of K or more fish species. Write a program to find the volume of such a place.
|
def main():
n, k = map(int, input().split())
plst = []
xlst = []
ylst = []
dlst = []
for i in range(n):
x1,y1,d1,x2,y2,d2 = map(int, input().split())
plst.append((x1,y1,d1,x2,y2,d2))
xlst.append(x1)
xlst.append(x2)
ylst.append(y1)
ylst.append(y2)
dlst.append(d1)
dlst.append(d2)
xlst = list(set(xlst))
ylst = list(set(ylst))
dlst = list(set(dlst))
xlst.sort()
ylst.sort()
dlst.sort()
xdic = {}
ydic = {}
ddic = {}
for i, v in enumerate(xlst):
xdic[v] = i
for i, v in enumerate(ylst):
ydic[v] = i
for i, v in enumerate(dlst):
ddic[v] = i
new_map = [[[0] * len(dlst) for _ in ylst] for _ in xlst]
for p in plst:
x1, y1, d1, x2, y2, d2 = p
x1, y1, d1, x2, y2, d2 = xdic[x1], ydic[y1], ddic[d1], xdic[x2], ydic[y2], ddic[d2]
for x in range(x1, x2):
for y in range(y1, y2):
for d in range(d1, d2):
new_map[x][y][d] += 1
ans = 0
for i in range(len(xlst) - 1):
xlsti = xlst[i]
xlsti1 = xlst[i - 1]
x = xdic[xlsti]
for j in range(len(ylst) - 1):
ylstj = ylst[j]
ylstj1 = ylst[j - 1]
y = ydic[ylstj]
for z in range(len(dlst) - 1):
dlstz = dlst[z]
dlstz1 = dlst[z - 1]
d = ddic[dlstz]
if new_map[x][y][d] >= k:
ans += (xlsti1 - xlsti) * (ylstj1 - ylstj) * (dlstz1 - dlstz)
print(ans)
main()
|
s573943907
|
Accepted
| 1,040
| 14,320
| 1,451
|
def main():
n, k = map(int, input().split())
plst = []
xlst = []
ylst = []
dlst = []
for i in range(n):
x1,y1,d1,x2,y2,d2 = map(int, input().split())
plst.append((x1,y1,d1,x2,y2,d2))
xlst.append(x1)
xlst.append(x2)
ylst.append(y1)
ylst.append(y2)
dlst.append(d1)
dlst.append(d2)
xlst = list(set(xlst))
ylst = list(set(ylst))
dlst = list(set(dlst))
xlst.sort()
ylst.sort()
dlst.sort()
lx = len(xlst)
ly = len(ylst)
ld = len(dlst)
xdic = {}
ydic = {}
ddic = {}
for i, v in enumerate(xlst):
xdic[v] = i
for i, v in enumerate(ylst):
ydic[v] = i
for i, v in enumerate(dlst):
ddic[v] = i
new_map = [[[0] * ld for _ in range(ly)] for _ in range(lx)]
for p in plst:
x1, y1, d1, x2, y2, d2 = p
x1, y1, d1, x2, y2, d2 = xdic[x1], ydic[y1], ddic[d1], xdic[x2], ydic[y2], ddic[d2]
for x in range(x1, x2):
for y in range(y1, y2):
for d in range(d1, d2):
new_map[x][y][d] += 1
ans = 0
for i in range(lx - 1):
xlsti = xlst[i]
xlsti1 = xlst[i + 1]
x = xdic[xlsti]
for j in range(ly - 1):
ylstj = ylst[j]
ylstj1 = ylst[j + 1]
y = ydic[ylstj]
for z in range(ld - 1):
dlstz = dlst[z]
dlstz1 = dlst[z + 1]
d = ddic[dlstz]
if new_map[x][y][d] >= k:
ans += (xlsti1 - xlsti) * (ylstj1 - ylstj) * (dlstz1 - dlstz)
print(ans)
main()
|
s994710688
|
p03131
|
u114641312
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 988
|
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
|
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # eps = Decimal(10) ** (-100)
# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb
K,A,B = map(int,input().split())
ans1 = 1 + K
zanturn = K - (A - 1)
AtoB,mod = divmod(zanturn,2)
ans2 = A + (B-A)*AtoB + mod
print(ans1,ans2)
ans = max(ans1,ans2)
print(ans)
# for row in board:
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))
|
s460380199
|
Accepted
| 17
| 2,940
| 971
|
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # eps = Decimal(10) ** (-100)
# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb
K,A,B = map(int,input().split())
ans1 = 1 + K
zanturn = K - (A - 1)
AtoB,mod = divmod(zanturn,2)
ans2 = A + (B-A)*AtoB + mod
ans = max(ans1,ans2)
print(ans)
# for row in board:
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))
|
s347836557
|
p00042
|
u462831976
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,768
| 868
|
宝物がたくさん収蔵されている博物館に、泥棒が大きな風呂敷を一つだけ持って忍び込みました。盗み出したいものはたくさんありますが、風呂敷が耐えられる重さが限られており、これを超えると風呂敷が破れてしまいます。そこで泥棒は、用意した風呂敷を破らず且つ最も価値が高くなるようなお宝の組み合わせを考えなくてはなりません。 風呂敷が耐えられる重さ W、および博物館にある個々のお宝の価値と重さを読み込んで、重さの総和が W を超えない範囲で価値の総和が最大になるときの、お宝の価値総和と重さの総和を出力するプログラムを作成してください。ただし、価値の総和が最大になる組み合わせが複数あるときは、重さの総和が小さいものを出力することとします。
|
# -*- coding: utf-8 -*-
import sys
import os
import math
import itertools
case = 1
for s in sys.stdin:
W = int(s)
if W == 0:
break
N = int(input())
values = []
weights = []
for i in range(N):
v, w = map(int, input().split(','))
values.append(v)
weights.append(w)
max_value = 0
max_value_weight = 0
for use_flags in itertools.product([0, 1], repeat=len(weights)):
sum_value = 0
sum_weight = 0
for i, use_flag in enumerate(use_flags):
if use_flag == 1:
sum_value += values[i]
sum_weight += weights[i]
if sum_weight <= W and sum_value > max_value:
max_value = sum_value
max_value_weight = sum_weight
case += 1
print('Case {}:'.format(case))
print(max_value)
print(max_value_weight)
|
s711358640
|
Accepted
| 1,780
| 31,832
| 1,401
|
# -*- coding: utf-8 -*-
import sys
import os
import math
import itertools
case = 1
for s in sys.stdin:
# capacity
C = int(s)
if C == 0:
break
N = int(input())
V = [0]
W = [0]
# max value table of (N+1) x (C+1)
VT = [[0 for i in range(C+1)] for j in range(N+1)]
WT = [[0 for i in range(C+1)] for j in range(N+1)]
for i in range(N):
v, w = map(int, input().split(','))
V.append(v)
W.append(w)
for i in range(1, N+1):
for j in range(1, C+1):
if j >= W[i]:
value_on_load = VT[i-1][j - W[i]] + V[i]
value_not_load = VT[i-1][j]
weight_on_load = WT[i-1][j - W[i]] + W[i]
weight_not_load = WT[i-1][j]
if value_on_load > value_not_load:
VT[i][j] = value_on_load
WT[i][j] = weight_on_load
elif value_on_load == value_not_load:
VT[i][j] = value_on_load
WT[i][j] = min(weight_on_load, weight_not_load)
else:
VT[i][j] = value_not_load
WT[i][j] = weight_not_load
else:
VT[i][j] = VT[i - 1][j]
WT[i][j] = WT[i - 1][j]
print('Case {}:'.format(case))
case += 1
print(VT[N][C])
print(WT[N][C])
|
s458891577
|
p03163
|
u858742833
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 15,216
| 329
|
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():
N, W = map(int, input().split())
wi, vi = map(int, input().split())
dp = [0] * wi + [vi] * (W - wi)
for _ in range(1, N):
wi, vi = map(int, input().split())
dp = dp[:wi] + [max(i + vi, j) for i, j in zip(dp[:W - wi], dp[wi:])]
print(dp[-1])
if __name__ == '__main__':
main()
|
s629224984
|
Accepted
| 1,462
| 9,728
| 378
|
def main():
N, W = map(int, input().split())
wi, vi = map(int, input().split())
dp = [0] * wi + [vi] * (W + 1 - wi)
for _ in range(1, N):
wi, vi = map(int, input().split())
for i in range(W, wi - 1, -1):
t = dp[i - wi] + vi
if t > dp[i]:
dp[i] = t
print(dp[-1])
if __name__ == '__main__':
main()
|
s731510398
|
p03449
|
u619197965
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 248
|
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
|
n=int(input())
a=[[int(i) for i in input().split()] for i in range(2)]
koho=[]
for i in range(n):
if i==0:
cnt=a[0][0]+sum(a[0][0:i])+sum(a[1][i:])
else:
cnt=sum(a[0][0:i])+sum(a[1][i:])
koho.append(cnt)
print(max(koho))
|
s719900038
|
Accepted
| 17
| 3,060
| 235
|
n=int(input())
a=[[int(i) for i in input().split()] for i in range(2)]
koho=[]
for i in range(n):
if i==0:
cnt=a[0][0]+sum(a[1][0:])
else:
cnt=sum(a[0][0:i+1])+sum(a[1][i:])
koho.append(cnt)
print(max(koho))
|
s577622561
|
p03448
|
u501409901
| 2,000
| 262,144
|
Wrong Answer
| 57
| 9,088
| 383
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
|
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for n in range(a):
for m in range(b):
for l in range(c):
if (500 * n + 100 * b + 50 * c) == x:
ans = ans + 1
print(ans)
|
s167100014
|
Accepted
| 51
| 9,120
| 383
|
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for n in range(a + 1):
for m in range(b + 1):
for l in range(c + 1):
if (500 * n + 100 * m + 50 * l) == x:
ans = ans + 1
print(ans)
|
s241246911
|
p03545
|
u934119021
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 728
|
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
|
import itertools
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
l = [0] * 8
l[0] = a + b + c + d
l[1] = a + b + c - d
l[2] = a + b - c + d
l[3] = a + b - c - d
l[4] = a - b + c + d
l[5] = a - b + c - d
l[6] = a - b - c + d
l[7] = a - b - c - d
if l[0] == 7:
print('{}+{}+{}+{}'.format(a, b, c, d))
elif l[1] == 7:
print('{}+{}+{}-{}'.format(a, b, c, d))
elif l[2] == 7:
print('{}+{}-{}+{}'.format(a, b, c, d))
elif l[3] == 7:
print('{}+{}-{}-{}'.format(a, b, c, d))
elif l[4] == 7:
print('{}-{}+{}+{}'.format(a, b, c, d))
elif l[5] == 7:
print('{}-{}+{}-{}'.format(a, b, c, d))
elif l[6] == 7:
print('{}-{}-{}+{}'.format(a, b, c, d))
elif l[7] == 7:
print('{}-{}-{}-{}'.format(a, b, c, d))
|
s193314255
|
Accepted
| 18
| 3,064
| 744
|
import itertools
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
l = [0] * 8
l[0] = a + b + c + d
l[1] = a + b + c - d
l[2] = a + b - c + d
l[3] = a + b - c - d
l[4] = a - b + c + d
l[5] = a - b + c - d
l[6] = a - b - c + d
l[7] = a - b - c - d
if l[0] == 7:
print('{}+{}+{}+{}=7'.format(a, b, c, d))
elif l[1] == 7:
print('{}+{}+{}-{}=7'.format(a, b, c, d))
elif l[2] == 7:
print('{}+{}-{}+{}=7'.format(a, b, c, d))
elif l[3] == 7:
print('{}+{}-{}-{}=7'.format(a, b, c, d))
elif l[4] == 7:
print('{}-{}+{}+{}=7'.format(a, b, c, d))
elif l[5] == 7:
print('{}-{}+{}-{}=7'.format(a, b, c, d))
elif l[6] == 7:
print('{}-{}-{}+{}=7'.format(a, b, c, d))
elif l[7] == 7:
print('{}-{}-{}-{}=7'.format(a, b, c, d))
|
s372617710
|
p03435
|
u255067135
| 2,000
| 262,144
|
Wrong Answer
| 151
| 12,456
| 718
|
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.
|
import numpy as np
mat = [list(map(int, input().split())) for i in range(3)]
array = np.array(mat, dtype=np.int64)
a20 = array[2]-array[0]
a10 = array[1]-array[0]
b20 = array[:,2]-array[:,0]
b10 = array[:,1]-array[:,0]
flag = False
if (a20==a20[0]).all() and (a10==a10[0]).all() and (b20==b20[0]).all() and (b10==b10[0]).all():
print('OK')
for a1 in range(0, 101):
a2 = a1+ a10[0]
a3 = a1 + a20[0]
b1 = array[0,0] - a1
b2 = b1 + b10[0]
b3 = b1 +b20[0]
A = np.array([[a1, a2, a3]]).T
B = np.array([[b1, b2, b3]])
C = A+B
if (C == array).all():
flag =True
break
if flag==True:
print('Yes')
else:
print('No')
|
s193798484
|
Accepted
| 149
| 12,512
| 702
|
import numpy as np
mat = [list(map(int, input().split())) for i in range(3)]
array = np.array(mat, dtype=np.int64)
a20 = array[2]-array[0]
a10 = array[1]-array[0]
b20 = array[:,2]-array[:,0]
b10 = array[:,1]-array[:,0]
flag = False
if (a20==a20[0]).all() and (a10==a10[0]).all() and (b20==b20[0]).all() and (b10==b10[0]).all():
for a1 in range(0, 101):
a2 = a1+ a10[0]
a3 = a1 + a20[0]
b1 = array[0,0] - a1
b2 = b1 + b10[0]
b3 = b1 +b20[0]
A = np.array([[a1, a2, a3]]).T
B = np.array([[b1, b2, b3]])
C = A+B
if (C == array).all():
flag =True
break
if flag==True:
print('Yes')
else:
print('No')
|
s901007020
|
p02928
|
u905203728
| 2,000
| 1,048,576
|
Wrong Answer
| 836
| 3,188
| 324
|
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
|
n,k=map(int,input().split())
box=list(map(int,input().split()))
count=0
for i in range(n):
for j in box[i:]:
if box[i]>j:
count +=1
count_2=0
for i in range(n):
for j in box:
if box[i]>j:
count_2 +=1
ans=(count*k)%10**9+7 + (count_2*k*(k-1)//2)%10**9+7
print(ans%(10**9+7))
|
s465028853
|
Accepted
| 867
| 3,188
| 330
|
n,k=map(int,input().split())
box=list(map(int,input().split()))
count=0
for i in range(n):
for j in box[i:]:
if box[i]>j:
count +=1
count_2=0
for i in range(n):
for j in box:
if box[i]>j:
count_2 +=1
ans=(count*k)%(10**9+7) + ((count_2*k*(k-1))//2)%(10**9+7)
print(ans%(10**9+7))
|
s382108781
|
p03488
|
u670180528
| 2,000
| 524,288
|
Wrong Answer
| 29
| 3,188
| 199
|
A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction. This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back. * `F` : Move in the current direction by distance 1. * `T` : Turn 90 degrees, either clockwise or counterclockwise. The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.
|
f,*l=map(len,input().split("T"))
x,y=map(int,input().split())
z=8000;bx=1<<f+z;by=1<<z
for dx,dy in zip(*[iter(l)]*2):bx=bx<<dx|bx>>dx;by=by<<dy|by>>dy
print("NYoe s"[bx&(1<<x+z) and by&(1<<y+z)::2])
|
s154336587
|
Accepted
| 30
| 3,188
| 288
|
l = [len(c) for c in input().split("T")]
x, y = map(int, input().split())
bx = 1 << l.pop(0) + 8000
by = 1 << 8000
for i, d in enumerate(l):
if i % 2:
bx = (bx << d) | (bx >> d)
else:
by = (by << d) | (by >> d)
print("Yes" if bx & (1 << x + 8000) and by & (1 << y + 8000) else "No")
|
s486963147
|
p03997
|
u290211456
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 79
|
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.
|
l = []
for i in range(3):
l.append(int(input()))
print((l[0] + l[1]) * l[2]/2)
|
s119853811
|
Accepted
| 17
| 2,940
| 84
|
l = []
for i in range(3):
l.append(int(input()))
print(int((l[0] + l[1]) * l[2]/2))
|
s912372230
|
p02806
|
u658801777
| 2,525
| 1,048,576
|
Wrong Answer
| 18
| 3,064
| 284
|
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
|
N = int(input())
ST = list()
for i in range(N):
s, t = input().split()
ST.append([s, t])
X = input()
result = None
for s, t in ST:
t = int(t)
if result is None:
if s == X:
result = 0
else:
result += t
print(s, t)
print(result)
|
s519896270
|
Accepted
| 17
| 3,064
| 268
|
N = int(input())
ST = list()
for i in range(N):
s, t = input().split()
ST.append([s, t])
X = input()
result = None
for s, t in ST:
t = int(t)
if result is None:
if s == X:
result = 0
else:
result += t
print(result)
|
s864333737
|
p03095
|
u725578977
| 2,000
| 1,048,576
|
Wrong Answer
| 25
| 3,444
| 189
|
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order.
|
from collections import Counter
# N = int(input())
s = input()
counter = Counter(s)
result = 1
for _, freq in counter.items():
result *= (freq + 1)
print((result - 1) % 1000000007)
|
s244715034
|
Accepted
| 29
| 3,572
| 187
|
from collections import Counter
N = int(input())
s = input()
counter = Counter(s)
result = 1
for _, freq in counter.items():
result *= (freq + 1)
print((result - 1) % 1000000007)
|
s877520015
|
p02407
|
u598393390
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,544
| 75
|
Write a program which reads a sequence and prints it in the reverse order.
|
ls = input().split()
for i in reversed(ls):
print(i, end = ' ')
print()
|
s216024105
|
Accepted
| 20
| 5,536
| 59
|
input()
ls = input().split()
print(' '.join(reversed(ls)))
|
s048584014
|
p03854
|
u804880764
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,188
| 418
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
if __name__ == '__main__':
L = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
n = len(S)
while True:
if S[-7:] == 'dreamer' or S[-7:] == 'eraser':
n -= 7
S = S[:-7]
elif S[-5:] == 'dream' or S[-5:] == 'erase':
n -= 5
S = S[:-5]
else:
break
if len(S) == -1:
print('YES')
else:
print('NO')
|
s813664176
|
Accepted
| 68
| 3,188
| 470
|
if __name__ == '__main__':
L = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
n = len(S)
while True:
if S[-7:] == 'dreamer':
n -= 7
S = S[:-7]
elif S[-6:] == 'eraser':
n -= 6
S = S[:-6]
elif S[-5:] == 'dream' or S[-5:] == 'erase':
n -= 5
S = S[:-5]
else:
break
if len(S) == 0:
print('YES')
else:
print('NO')
|
s585028926
|
p03214
|
u536632950
| 2,525
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 141
|
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
|
N = int(input())
a = list(map(int,input().split()))
Mean = sum(a)/N
a_norm = [a[i] - Mean for i in range(N)]
print(a_norm.index(min(a_norm)))
|
s280248981
|
Accepted
| 17
| 3,060
| 184
|
N = int(input())
a = list(map(int,input().split()))
Mean = sum(a)/N
a_norm = [a[i] - Mean for i in range(N)]
a_norm_abs = list(map(abs,a_norm))
print(a_norm_abs.index(min(a_norm_abs)))
|
s208033581
|
p03455
|
u364642100
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 93
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
a, b = map(int, input().split())
if a * b % 2 == 0:
print("even")
else:
print("odd")
|
s687406586
|
Accepted
| 17
| 2,940
| 96
|
a, b = map(int, input().split())
if (a * b) % 2 == 0:
print("Even")
else:
print("Odd")
|
s550727606
|
p03193
|
u543954314
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 3,064
| 145
|
There are N rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the i-th material are A_i \times B_i (A_i vertically and B_i horizontally). Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly H \times W. He is trying to obtain such a plate by choosing one of the N materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a 5 \times 3 material cannot be used as a 3 \times 5 plate. Out of the N materials, how many can produce an H \times W plate if properly cut?
|
n, h, w = map(int, input().split())
cnt = 0
for _ in range(n):
a, b = map(int, input().split())
if a <= h and b <= w:
cnt += 1
print(cnt)
|
s570054439
|
Accepted
| 20
| 3,060
| 145
|
n, h, w = map(int, input().split())
cnt = 0
for _ in range(n):
a, b = map(int, input().split())
if a >= h and b >= w:
cnt += 1
print(cnt)
|
s096134099
|
p03386
|
u338904752
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 232
|
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
|
if __name__ == '__main__':
s = input().split(' ')
a = int(s[0])
b = int(s[1])
k = int(s[2])
l1 = [a+x for x in range(k) if a+x <= b]
l2 = [b-x for x in range(k) if b-x >= a]
nums = set(l1+l2)
for elm in nums:
print(elm)
|
s174779633
|
Accepted
| 18
| 3,060
| 241
|
if __name__ == '__main__':
s = input().split(' ')
a = int(s[0])
b = int(s[1])
k = int(s[2])
l1 = [a+x for x in range(k) if a+x <= b]
l2 = [b-x for x in range(k) if b-x >= a]
nums = set(l1+l2)
for elm in sorted(nums):
print(elm)
|
s082885336
|
p03469
|
u086856505
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,068
| 31
|
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
input().replace('2017', '2018')
|
s104798587
|
Accepted
| 18
| 2,940
| 38
|
print(input().replace('2017', '2018'))
|
s582487447
|
p03377
|
u710907926
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 72
|
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())
print("NYoe s"[a+b>=x and a < x::2])
|
s982791225
|
Accepted
| 17
| 2,940
| 65
|
a, b, x = map(int, input().split())
print("NYOE S"[a+b>=x>=a::2])
|
s151887768
|
p00335
|
u260980560
| 1,000
| 262,144
|
Wrong Answer
| 30
| 7,568
| 347
|
あなたが勤めているパンケーキ屋では、細長い鉄板にパンケーキの生地を横1列に並べて焼きます。パンケーキはへらで何回か裏返せば完成します。何回以上裏返せば完成するかはパンケーキごとに異なります。 へらは大きいので、隣り合ったパンケーキは2枚同時に裏返されてしまいます。このとき、これら2枚の位置は入れ替わりません。ただし、両端だけは、隣のパンケーキといっしょに裏返すだけでなく、1枚だけ裏返すこともできます。すべてのパンケーキを必要な回数以上裏返したら、全部いっぺんに鉄板からおろして完成です。 パンケーキを必要な回数より多く裏返すと固くなってしまうので、あまり多く裏返したくありません。そこであなたは、すべて完成するまでに、各パンケーキが裏返る回数の総和が最小になるような方法を見つけようと考えました。 鉄板の上のパンケーキの枚数と、完成するまでに何回以上裏返さなければならないかがパンケーキごとに与えられているとき、すべて完成するまでに各パンケーキが裏返る回数(へらを操作する回数ではない)の総和の最小値を計算するプログラムを作成せよ。
|
n = int(input())
*P, = map(int, input().split())
ans = 0
if P[0] > 0 and P[1] > 0:
t = min(P[0], P[1])
ans += t*2
P[0] -= t
P[1] -= t
for i in range(1, n-1):
if P[i] > 0:
ans += P[i]*2
P[i+1] -= P[i]
P[i] = 0
if P[0] > 0:
ans += P[0]; P[0] = 0
if P[-1] > 0:
ans += P[-1]; P[-1] = 0
print(ans, P)
|
s713822902
|
Accepted
| 30
| 14,488
| 332
|
import sys
sys.setrecursionlimit(10**6)
n = int(input())
*P, = map(int, input().split())
memo = {(n-1, i): i for i in range(P[-1]+1)}
def dfs(pos, t):
if (pos, t) in memo:
return memo[pos, t]
res = memo[pos, t] = dfs(pos+1, max(0, P[pos+1]-t)) + t*2
return res
print(min(dfs(0, P[0]-i)+i for i in range(P[0]+1)))
|
s312706721
|
p03563
|
u878138257
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 46
|
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
|
a = int(input())
b = int(input())
print(b*b-a)
|
s232087242
|
Accepted
| 17
| 2,940
| 52
|
a = int(input())
b = int(input())
print(int(b*2-a))
|
s931917803
|
p03659
|
u218984487
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 24,620
| 1,029
|
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
|
m = int(input())
n = list(map(int, input().split()))
sum1 = 0
A = [0]
if m == 2:
if n[0] >= n[1]:
ans = n[0] - n[1]
print(ans)
else:
ans = n[1] - n[0]
print(ans)
else:
n.sort()
n.reverse()
#n = list(map(int, n))
#print(n)
#print(sum(A))
#print(sum(n))
for i in range(m):
ans = sum(n) - sum(A)
#print(ans)
if i == m - 1:
if ans > 0:
print(ans)
else:
print(ans * -1)
break
else:
A.append(n[0])
n.pop(0)
ans2 = sum(n) - sum(A)
#print(ans2)
if ans2 >= 0 and ans <= 0:
if ans2 * -1 < ans:
print(ans * -1)
else:
print(ans2)
break
elif ans2 <= 0 and ans >= 0:
if ans2 * -1 > ans:
print(ans2 * -1)
else:
print(ans)
break
|
s678508918
|
Accepted
| 158
| 24,948
| 284
|
m = int(input())
n = list(map(int, input().split()))
sunuke = 0
araiguma = sum(n)
min = 10000000000
for i in range(m - 1):
araiguma -= n[i]
sunuke += n[i]
if min > abs(sunuke - araiguma):
min = abs(sunuke - araiguma)
print(min)
|
s211076488
|
p03623
|
u007637377
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,120
| 96
|
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
|
x, a, b = map(int, input().split())
if abs(a - x) >= abs(b - x):
print('A')
else:
print('B')
|
s000984490
|
Accepted
| 26
| 9,096
| 96
|
x, a, b = map(int, input().split())
if abs(a - x) <= abs(b - x):
print('A')
else:
print('B')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.