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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s453811978
|
p02388
|
u234837959
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,580
| 30
|
Write a program which calculates the cube of a given integer x.
|
x = int(input())
print(x ** x)
|
s577975794
|
Accepted
| 30
| 7,580
| 33
|
x = int(input())
print(x * x * x)
|
s524821209
|
p03971
|
u257332942
| 2,000
| 262,144
|
Wrong Answer
| 103
| 4,016
| 394
|
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
|
N, A, B = list(map(int, input().split()))
S = input()
y, yab = 0, 0
for s in S:
if(s == 'a'):
if(y <= A + B):
print("Yes")
y += 1
else:
print("No")
elif(s == 'b'):
if(y <= A + B and yab <= B):
print("Yes")
y += 1
yab += 1
else:
print("No")
else:
print("No")
|
s901274473
|
Accepted
| 101
| 4,016
| 392
|
N, A, B = list(map(int, input().split()))
S = input()
y, yab = 0, 1
for s in S:
if(s == 'a'):
if(y < A + B):
print("Yes")
y += 1
else:
print("No")
elif(s == 'b'):
if(y < A + B and yab <= B):
print("Yes")
y += 1
yab += 1
else:
print("No")
else:
print("No")
|
s764496157
|
p03544
|
u390694622
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 287
|
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
|
def lucas(x):
list = []
list.append(2)
list.append(0)
i = 2
while i <= x:
list.append(list[i-1]+list[i-2])
i += 1
return list
if __name__ == '__main__':
inputstr = input()
num = int(inputstr)
list = lucas(num)
ans = list[num]
print(ans,flush=True)
|
s076844402
|
Accepted
| 17
| 3,064
| 287
|
def lucas(x):
list = []
list.append(2)
list.append(1)
i = 2
while i <= x:
list.append(list[i-1]+list[i-2])
i += 1
return list
if __name__ == '__main__':
inputstr = input()
num = int(inputstr)
list = lucas(num)
ans = list[num]
print(ans,flush=True)
|
s054290732
|
p02613
|
u412047585
| 2,000
| 1,048,576
|
Wrong Answer
| 146
| 9,184
| 120
|
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.
|
d={'AC':0,'WA':0,'TLE':0,'RE':0}
n=int(input())
for i in range(0,n):
d[input()]+=1
for j in d:
print(j,"X",d[j])
|
s077074171
|
Accepted
| 145
| 9,176
| 120
|
d={'AC':0,'WA':0,'TLE':0,'RE':0}
n=int(input())
for i in range(0,n):
d[input()]+=1
for j in d:
print(j,"x",d[j])
|
s453363052
|
p02280
|
u072053884
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,744
| 1,896
|
A rooted binary tree is a tree with a root node in which every node has at most two children. Your task is to write a program which reads a rooted binary tree _T_ and prints the following information for each node _u_ of _T_ : * node ID of _u_ * parent of _u_ * sibling of _u_ * the number of children of _u_ * depth of _u_ * height of _u_ * node type (root, internal node or leaf) If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_ have the same parent, we say _u_ is a sibling of _v_ (vice versa). The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf. Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
|
"""Binary Trees."""
class Node:
def __init__(self, num, leftChild, rightChild):
self.id = num
self.parent = -1
self.sibling = -1
self.degree = 0
self.depth = 0
self.height = 0
self.type = 'leaf'
self.leftChild = leftChild
self.rightChild = rightChild
def show_info(self):
print('node {}:'.format(self.id), 'parent = {}'.format(self.parent),
'sibling = {}'.format(self.sibling),
'degree = {}'.format(self.degree),
'depth = {}'.format(self.depth),
'height = {}'.format(self.height),
'{}'.format(self.type))
def set_node(i_s):
i_l = list(map(int, i_s.split()))
num = i_l[0]
children = i_l[1:]
node = Node(num, children[0], children[1])
T[num] = node
T[-1] -= num
def set_attributes(n_i, parent, sibling, depth):
node = T[n_i]
node.parent = parent
node.sibling = sibling
node.depth = depth
if node.leftChild != -1:
node.degree += 1
node.type = 'internal node'
set_attributes(node.leftChild, node.id, node.rightChild, depth + 1)
if node.rightChild != -1:
node.degree += 1
node.type = 'internal node'
set_attributes(node.rightChild, node.id, node.leftChild, depth + 1)
if node.leftChild != -1 and node.rightChild != -1:
node.height = max(T[node.leftChild].height,
T[node.rightChild].height) + 1
elif node.leftChild != -1:
node.height = T[node.leftChild].height + 1
elif node.rightChild != -1:
node.height = T[node.rightChild].height + 1
import sys
n = int(sys.stdin.readline())
T = [None] * n
T.append(int(n * (n - 1) / 2))
for x in sys.stdin.readlines():
set_node(x)
set_attributes(T[-1], -1, -1, 0)
T[T[-1]].type = 'root'
for n in T[:-1]:
n.show_info()
|
s275100718
|
Accepted
| 30
| 7,836
| 1,597
|
"""Binary Trees."""
class Node:
def __init__(self, num, leftChild, rightChild):
self.id = num
self.parent = -1
self.sibling = -1
self.degree = 0
self.depth = 0
self.height = 0
self.type = 'leaf'
self.leftChild = leftChild
self.rightChild = rightChild
def show_info(self):
print('node {}:'.format(self.id), 'parent = {},'.format(self.parent),
'sibling = {},'.format(self.sibling),
'degree = {},'.format(self.degree),
'depth = {},'.format(self.depth),
'height = {},'.format(self.height),
'{}'.format(self.type))
def set_attributes(n_i, parent, sibling, depth):
h1 = 0
h2 = 0
node = T[n_i]
lc = node.leftChild
rc = node.rightChild
node.parent = parent
node.sibling = sibling
node.depth = depth
if lc != -1:
node.degree += 1
node.type = 'internal node'
h1 = set_attributes(lc, n_i, rc, depth + 1) + 1
if rc != -1:
node.degree += 1
node.type = 'internal node'
h2 = set_attributes(rc, n_i, lc, depth + 1) + 1
node.height = max(h1, h2)
return node.height
import sys
n = int(sys.stdin.readline())
T = [None] * n
rt_n = int(n * (n - 1) / 2)
for x in sys.stdin.readlines():
num, leftChild, rightChild = list(map(int, x.split()))
node = Node(num, leftChild, rightChild)
T[num] = node
rt_n -= (max(0, leftChild) + max(0, rightChild))
set_attributes(rt_n, -1, -1, 0)
T[rt_n].type = 'root'
for n in T:
n.show_info()
|
s051767037
|
p04044
|
u771756419
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 342
|
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
|
nums = input("NとLスペース区切りで入力").split()
N = int(nums[0])
L = int(nums[1])
print("N=" + str(N))
print("L=" + str(L))
count = 0
print("start")
list = []
while count < N:
list.append(input())
count += 1
s_list = sorted(list)
print(s_list)
print(''.join(s_list))
|
s485752055
|
Accepted
| 16
| 3,060
| 213
|
nums = input().split()
N = int(nums[0])
L = int(nums[1])
count = 0
list = []
while count < N:
list.append(input())
count += 1
s_list = sorted(list)
print(''.join(s_list))
|
s736108361
|
p03493
|
u892018927
| 2,000
| 262,144
|
Wrong Answer
| 2,108
| 21,796
| 152
|
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.
|
import numpy as np
A = list(map(int,input().split()))
count = 0
while all(a % 2 == 0 for a in A):
A = [a/2 for a in A]
count += 1
print(count)
|
s076846546
|
Accepted
| 17
| 2,940
| 94
|
a = str(input())
count = 0
for i in list(a):
if i == "1":
count = count +1
print(count)
|
s704639391
|
p02612
|
u893178798
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,192
| 400
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
import math
N = int(input())
m = math.ceil(N//1000)
n_coin = 0
change = 1000*m-N
if change >= 500:
n_coin +=1
change -= 500
while change >= 100:
n_coin += 1
change -= 100
if change >= 50:
n_coin +=1
change -= 50
while change >= 10:
n_coin += 1
change -= 10
if change >= 5:
n_coin +=1
change -= 5
while change >= 1:
n_coin += 1
change -= 1
print(n_coin)
|
s536266817
|
Accepted
| 30
| 9,088
| 96
|
import math
N = int(input())
m = math.ceil(N/1000)
n_coin = 0
change = 1000*m - N
print(change)
|
s789333441
|
p02608
|
u220085075
| 2,000
| 1,048,576
|
Wrong Answer
| 2,205
| 9,064
| 458
|
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
|
n=int(input())
def number(i):
for j in range(1,41):
for k in range(1,58):
for u in range(1,101):
if i==j*j+k*k+u*u+j*k+k*u+u*j:
if j==k and k==u:
print(1)
return
elif j==k or k==u:
print(3)
return
else:
print(6)
return
print(0)
return
for h in range(n):
number(h)
|
s463487876
|
Accepted
| 444
| 9,208
| 250
|
n=int(input())
y=[0 for _ in range(10**4+1)]
for j in range(1,100):
for k in range(1,100):
for u in range(1,100):
a=j*j+k*k+u*u+j*k+k*u+u*j
if a <= 10**4:
y[a-1]+=1
for o in range(n):
print(y[o])
|
s559815431
|
p03141
|
u013629972
| 2,000
| 1,048,576
|
Wrong Answer
| 2,108
| 15,220
| 1,141
|
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end". Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
|
import numpy as np
def main():
N = int(input())
A = np.array([])
B = np.array([])
for i in range(0, N):
a, b = map(int, input().split())
A = np.append(A, [a])
B = np.append(B, [b])
sub(N, A, B)
def sub(N, A, B):
takahashi = 0
aoki = 0
sum_AB = A + B
print(A, B)
for i in range(1, N + 1):
max_idx = np.argmax(sum_AB)
print(sum_AB, max_idx)
if i % 2 == 1:
takahashi += A[max_idx]
else:
aoki += B[max_idx]
sum_AB[max_idx] = -1
print(takahashi - aoki)
main()
|
s414227112
|
Accepted
| 524
| 21,212
| 573
|
import numpy as np
def main():
N = int(input())
A = []
B = []
for i in range(0, N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
takahashi = 0
aoki = 0
A = np.array(A)
B = np.array(B)
sum_AB = A + B
l = sum_AB.argsort()[::-1]
takahashi = sum([A[i] for i in [j for idx, j in enumerate(l) if idx % 2 == 0]])
aoki = sum([B[i] for i in [j for idx, j in enumerate(l) if idx % 2 != 0]])
print(int(takahashi - aoki))
main()
|
s942034329
|
p03227
|
u385244248
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 69
|
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
|
S = input()
if len(S) == 2:
print(S)
else:
print(reversed(S))
|
s382553630
|
Accepted
| 17
| 2,940
| 65
|
S = input()
if len(S) == 2:
print(S)
else:
print(S[::-1])
|
s893285238
|
p03069
|
u494439372
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 5,096
| 266
|
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
|
n = int(input())
s = input()
ans = [0 for i in range(n + 1)]
for i in range(n):
for j in range(n + 1):
if j <= i:
if s[i] == '.':
ans[j] += 1
else:
if s[i] == '#':
ans[j] += 1
print(ans)
|
s580359773
|
Accepted
| 111
| 3,500
| 264
|
n = int(input())
s = input()
b = 0
w = 0
tb = 0
tw = 0
for i in reversed(range(n)):
if s[i] == '#':
tb += 1
if tb > tw:
b += tb
w += tw
tb = 0
tw = 0
else:
tw += 1
print(tb + w)
|
s328787580
|
p03816
|
u557494880
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 18,272
| 342
|
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
|
N = int(input())
A = list(map(int,input().split()))
d = {}
X =[]
for i in range(N):
x = A[i]
if x not in d:
d[x] = 1
X.append(x)
else:
d[x] += 1
ans = 0
for x in X:
a = d[x]
if a%2 == 0:
ans += a//2 - 1
else:
ans += a//2
X.remove(x)
n = len(X)
ans += (n+1)//2
print(ans)
|
s960988812
|
Accepted
| 106
| 18,528
| 444
|
N = int(input())
A = list(map(int,input().split()))
from collections import deque
d = {}
X = deque()
for i in range(N):
x = A[i]
if x not in d:
d[x] = 1
X.appendleft(x)
else:
d[x] += 1
ans = 0
from collections import deque
Y=deque()
while X:
x = X.popleft()
a = d[x]
if a%2 == 0:
ans += a-2
Y.appendleft(x)
else:
ans += a-1
n = len(Y)
ans += ((n+1)//2)*2
print(N-ans)
|
s904394866
|
p03693
|
u411965808
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 120
|
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
r, g, b = map(int, input().split(" "))
n = 100 * r + 10 * g + b
if n % 4 == 0:
print("Yes")
else:
print("No")
|
s652970504
|
Accepted
| 17
| 2,940
| 120
|
r, g, b = map(int, input().split(" "))
n = 100 * r + 10 * g + b
if n % 4 == 0:
print("YES")
else:
print("NO")
|
s202317129
|
p02850
|
u941047297
| 2,000
| 1,048,576
|
Wrong Answer
| 2,207
| 130,196
| 1,264
|
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
|
import sys
sys.setrecursionlimit(100000)
class Tree():
def __init__(self, n, root, connects):
self.root = root
self.connects = connects
self.parents = [0] * n
self.parents[root] = None
self.children = [0] * n
self.children[self.root] = connects[self.root]
self.make_tree(self.root)
def make_tree(self, node):
for child in self.children[node]:
self.parents[child] = node
self.children[child] = [c for c in self.connects[child] if c != node]
if self.children[child] != []:
self.make_tree(child)
def main():
n = int(input())
G = [[] for _ in range(n)]
ID = [dict() for _ in range(n)]
for i in range(n - 1):
a, b = map(lambda x: int(x) - 1, input().split())
G[a].append(b)
G[b].append(a)
ID[a][b] = i
ID[b][a] = i
t = Tree(n, root = 0, connects = G)
m = max(len(g) for g in G)
ans = [0] * (n - 1)
def bfs(a, pre = set()):
color = list(set(range(m)) - pre)
for b in t.children[a]:
c = color.pop()
ans[ID[a][b]] = c
bfs(b, set([c]))
bfs(0)
[print(a) for a in ans]
if __name__ == '__main__':
main()
|
s468591304
|
Accepted
| 479
| 101,696
| 710
|
import sys
sys.setrecursionlimit(100000)
def main():
n = int(input())
G = [[] for _ in range(n)]
ID = [dict() for _ in range(n)]
for i in range(n - 1):
a, b = map(lambda x: int(x) - 1, input().split())
G[a].append(b)
G[b].append(a)
ID[a][b] = i
ID[b][a] = i
m = max(len(g) for g in G)
ans = [0] * (n - 1)
def bfs(a, pre = -1, pre_c = -1):
color = 1
for b in G[a]:
if b == pre: continue
if color == pre_c: color += 1
ans[ID[a][b]] = color
bfs(b, a, color)
color += 1
bfs(0)
print(m)
[print(a) for a in ans]
if __name__ == '__main__':
main()
|
s130947721
|
p03401
|
u187205913
| 2,000
| 262,144
|
Wrong Answer
| 212
| 15,160
| 242
|
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
|
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
dis = []
for i in range(1,len(a)):
dis.append(abs(a[i]-a[i-1]))
print(a)
print(dis)
s = sum(dis)
for i in range(1,len(a)-1):
print(s+abs(a[i-1]-a[i+1])-(dis[i]+dis[i-1]))
|
s334852906
|
Accepted
| 201
| 14,048
| 222
|
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
dis = []
for i in range(1,len(a)):
dis.append(abs(a[i]-a[i-1]))
s = sum(dis)
for i in range(1,len(a)-1):
print(s+abs(a[i-1]-a[i+1])-(dis[i]+dis[i-1]))
|
s598227155
|
p04043
|
u007550226
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 88
|
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.
|
if sorted(list(map(int,input().split()))) == [5,7,7]:
print('YES')
else:
print('NO')
|
s183764298
|
Accepted
| 20
| 3,060
| 92
|
if sorted(list(map(int,input().split()))) == [5,5,7]:
print('YES')
else:
print('NO')
|
s691143865
|
p03828
|
u283846680
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 37
|
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
n = int(input())
print(n % (10**9+7))
|
s296924433
|
Accepted
| 45
| 3,060
| 315
|
n = int(input())
l = []
ans = 1
for i in range(2,n+1):
for j in range(2,i):
if i % j == 0:
break
else:
l.append(i)
for h in l:
a = 1
for i in range(1,n+1):
while i % h == 0:
i /= h
a += 1
else:
ans *= a
print(ans % (10**9+7))
|
s672183896
|
p03730
|
u402666025
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,104
| 12,000
| 235
|
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
|
a, b, c = map(int, input().split())
amari = []
for i in range(0, 10000000):
if a * i % b == c:
print("YES")
else:
if a % b not in amari:
amari.append(a % b)
else:
print("NO")
|
s904759914
|
Accepted
| 17
| 2,940
| 276
|
a, b, c = map(int, input().split())
amari = []
for i in range(0, 10000000):
d = a * i
if d % b == c:
print("YES")
break
else:
if d % b not in amari:
amari.append(d % b)
else:
print("NO")
break
|
s582300826
|
p03351
|
u290211456
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 129
|
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a,b,c,d = map(int, input().split())
if abs(b-a) <= d and abs(c-b) <= d and abs(c-a) <= d:
print("Yes")
else:
print("No")
|
s232484707
|
Accepted
| 17
| 2,940
| 130
|
a,b,c,d = map(int, input().split())
if (abs(b-a) <= d and abs(c-b) <= d) or abs(c-a) <= d:
print("Yes")
else:
print("No")
|
s563656926
|
p03049
|
u691018832
| 2,000
| 1,048,576
|
Wrong Answer
| 36
| 3,060
| 164
|
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
|
n = int(input())
ans_a, ans_b = 0, 0
for _ in range(n):
s = input()
ans_a += s.count('A')
ans_b += s.count('B')
ans = min(ans_a, ans_b)
print(ans)
|
s603021439
|
Accepted
| 46
| 3,064
| 650
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n = int(readline())
cnt_a = 0
cnt_b = 0
cnt_c = 0
cnt = 0
for i in range(n):
s = input()
for j in range(1, len(s)):
if s[j - 1] == 'A' and s[j] == 'B':
cnt += 1
if s[0] == 'B' and s[-1] == 'A':
cnt_c += 1
elif s[0] == 'B':
cnt_b += 1
elif s[-1] == 'A':
cnt_a += 1
ans = cnt
if cnt_c == 0:
ans += min(cnt_a, cnt_b)
else:
if cnt_a + cnt_b > 0:
ans += cnt_c + min(cnt_a, cnt_b)
else:
ans += cnt_c - 1
print(ans)
|
s409914655
|
p03556
|
u390762426
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 33
|
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
|
N=int(input())
print(int(N**0.5))
|
s426358377
|
Accepted
| 21
| 3,316
| 38
|
N=int(input())
print((int(N**0.5))**2)
|
s430729281
|
p00100
|
u500396695
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,624
| 310
|
There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID _i_ , the amount of sales _q_ and the corresponding unit price _p_. Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p × q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that _n_ < 4000, and each employee has an unique ID. The unit price _p_ is less than or equal to 1,000,000 and the amount of sales _q_ is less than or equal to 100,000.
|
while True:
n = int(input())
if n == 0:
break
else:
greatworkers = []
for i in range(n):
person, price, number = [int(i) for i in input().split()]
if price * number >= 1000000:
greatworkers.append(str(person))
if greatworkers == []:
print('NA')
else:
print('\n'.join(greatworkers))
|
s738945764
|
Accepted
| 30
| 7,760
| 443
|
while True:
n = int(input())
if n == 0:
break
workers = {}
workernames = []
greatworkers = 0
for i in range(n):
person, price, number = map(int, input().split())
if person in workers:
workers[person] += price * number
else:
workers[person] = price * number
workernames.append(person)
for worker in workernames:
if workers[worker] >= 1000000:
print(worker)
greatworkers += 1
if greatworkers == 0:
print('NA')
|
s626626116
|
p03472
|
u952708174
| 2,000
| 262,144
|
Wrong Answer
| 516
| 33,244
| 475
|
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
|
def d_Katana_Thrower(N, H, S):
import numpy
swing = numpy.asarray([x[0] for x in S])
throw = numpy.asarray([x[1] for x in S])
swing_max = max(swing)
throw_t = throw[throw >= swing_max]
hp = H - sum(throw_t)
if hp <= 0:
ans = len(throw_t)
else:
ans = len(throw_t) + hp // swing_max
return ans
N,H=[int(i) for i in input().split()]
S=[[int(i) for i in input().split()] for j in range(N)]
print(d_Katana_Thrower(N, H, S))
|
s465791588
|
Accepted
| 351
| 22,940
| 1,087
|
def d_katana_thrower():
N, H = [int(i) for i in input().split()]
Swords = [[int(i) for i in input().split()] for j in range(N)]
max_swing = max([s[0] for s in Swords])
sword_to_throw = sorted([s[1] for s in Swords if s[1] >= max_swing], reverse=True)
threw_times = 0
for damage in sword_to_throw:
H -= damage
threw_times += 1
if H <= 0:
return threw_times
return threw_times + -(-H // max_swing)
print(d_katana_thrower())
|
s609156211
|
p02396
|
u156215655
| 1,000
| 131,072
|
Wrong Answer
| 120
| 7,528
| 101
|
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
|
count=1
while(True):
num=int(input())
if num == 0:
break
print('Case %d: %d' % (count,num))
|
s890670806
|
Accepted
| 140
| 7,524
| 114
|
count=1
while(True):
num=int(input())
if num == 0:
break
print('Case %d: %d' % (count,num))
count += 1
|
s567216602
|
p02393
|
u901205536
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,572
| 63
|
Write a program which reads three integers, and prints them in ascending order.
|
lis = list(map(int, input().split(" ")))
lis.sort()
print(lis)
|
s601413876
|
Accepted
| 20
| 5,592
| 109
|
lis = list(map(int, input().split(" ")))
lis.sort()
#print(lis)
print("%s %s %s" % (lis[0], lis[1], lis[2]))
|
s375221282
|
p03049
|
u089142196
| 2,000
| 1,048,576
|
Wrong Answer
| 35
| 3,828
| 453
|
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
|
N=int(input())
s = [input() for _ in range(N)]
t = [s[i].count("AB") for i in range(N)]
u = sum([1 if s[i][-1] == "A" else 0 for i in range(N)])
v = sum([1 if s[i][0] == "B" else 0 for i in range(N)])
w = sum([1 if s[i][0] == "B" and s[i][-1] == "A" else 0 for i in range(N)])
#print(t)
#print(u,v,w)
maxi=max(u,v)
mini=min(u,v)
#print(maxi,mini,w)
maxi -= w
diff = maxi-mini
print(maxi,mini,w)
ans = min(mini,maxi) + min(diff,w) + sum(t)
print(ans)
|
s415350912
|
Accepted
| 36
| 3,700
| 474
|
N=int(input())
s = [input() for _ in range(N)]
t = sum([s[i].count("AB") for i in range(N)])
p = sum([1 if s[i][-1] == "A" else 0 for i in range(N)])
q = sum([1 if s[i][0] == "B" else 0 for i in range(N)])
r = sum([1 if s[i][0] == "B" and s[i][-1] == "A" else 0 for i in range(N)])
p -= r
q -= r
ans=t
#print(t)
#print(p,q,r)
if r==0:
ans += min(p,q)
else:
ans += r-1
if p>=1:
p = p-1
ans +=1
if q>=1:
q = q-1
ans +=1
ans += min(p,q)
print(ans)
|
s149105577
|
p03457
|
u972795791
| 2,000
| 262,144
|
Wrong Answer
| 234
| 27,004
| 382
|
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
N = int(input())
xy=[]
try :
while True:
t = input().split()
t = list(map(int,t))
xy.append(t)
except EOFError:
pass
loc = [0,0]
for i in range(N):
a = xy[i]
time = a[0]
dis = abs(loc[0]-a[1])+abs(loc[1]-a[2])
if (time-dis)<0 :
print("No")
break
elif (time-dis)%2 == 0:
loc = [a[1],a[2]]
else :
print("No")
break
else :
print("Yes")
|
s523848058
|
Accepted
| 238
| 9,184
| 314
|
N = int(input())
locx = 0
locy =0
time = 0
for i in range(N):
t,x,y = map(int,input().split())
time = t-time
dis = abs(locx-x)+abs(locy-y)
if (time-dis)<0 :
print("No")
exit()
if (time-dis)%2 == 1:
print("No")
exit()
time = t
locx = x
locy = y
else :
print("Yes")
|
s529385807
|
p03737
|
u502149531
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 109
|
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
|
b, c, d = list(map(str, input().split()))
print(b[0].upper,end='')
print(c[0].upper,end='')
print(d[0].upper)
|
s589485896
|
Accepted
| 17
| 2,940
| 115
|
b, c, d = list(map(str, input().split()))
print(b[0].upper(),end='')
print(c[0].upper(),end='')
print(d[0].upper())
|
s632200398
|
p02694
|
u805392425
| 2,000
| 1,048,576
|
Time Limit Exceeded
| 2,255
| 32,064
| 146
|
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
from sys import stdin
X = int(stdin.readline())
Y = 100
count = 1
while True:
Y += Y*0.01
if Y >= X:
print(count)
else:
count += 1
|
s470131433
|
Accepted
| 22
| 9,168
| 161
|
from sys import stdin
X = int(stdin.readline())
Y = 100
count = 1
while True:
Y += int(Y*0.01)
if Y >= X:
print(count)
break
else:
count += 1
|
s307854512
|
p03434
|
u394731058
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 237
|
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
|
def main():
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
for i in range(len(l)):
if i%2 == 0:
ans += i
else:
ans -= i
print(ans)
if __name__ == "__main__":
main()
|
s456604832
|
Accepted
| 18
| 3,060
| 242
|
def main():
ans = 0
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
for i in range(len(l)):
if i % 2 == 0:
ans += l[i]
else:
ans -= l[i]
print(ans)
if __name__ == '__main__':
main()
|
s858444356
|
p03997
|
u634079249
| 2,000
| 262,144
|
Wrong Answer
| 35
| 10,152
| 993
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
a, b, h = ii(), ii(), ii()
print(((a + b) * 2) / 2)
if __name__ == '__main__':
main()
|
s077911652
|
Accepted
| 31
| 10,108
| 994
|
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
a, b, h = ii(), ii(), ii()
print(((a + b) * h) // 2)
if __name__ == '__main__':
main()
|
s166214130
|
p03068
|
u965033073
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 87
|
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
|
N=input()
s=input()
K=int(input())
R=str(s[K-1])
dst = s.replace(R, "*")
print(dst)
|
s369514637
|
Accepted
| 17
| 2,940
| 111
|
N, S, K = int(input()), input(), int(input())
res = "".join(['*' if s != S[K-1] else s for s in S])
print(res)
|
s031397768
|
p03761
|
u777283665
| 2,000
| 262,144
|
Wrong Answer
| 26
| 3,828
| 504
|
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
|
import string
n = int(input())
d = dict()
for i in string.ascii_lowercase:
d[i] = d.get(i, 0) - 1
for _ in range(n):
s = input()
for i in string.ascii_lowercase:
if s.count(i) == 0:
d[i] = 0
elif s.count(i) > 0:
if d[i] == -1:
d[i] = s.count(i)
else:
d[i] = min(d[i], s.count(i))
flag = 0
for i in d.items():
if i[1] != 0:
flag = 1
print(i[0]*i[1], end="")
if flag != 1:
print()
|
s918680755
|
Accepted
| 25
| 3,772
| 265
|
import string
n = int(input())
alpha = string.ascii_lowercase
x = [[] for _ in range(26)]
for _ in range(n):
s = input()
for a in alpha:
x[alpha.index(a)].append(s.count(a))
ans = ""
for i in range(26):
ans += min(x[i]) * alpha[i]
print(ans)
|
s612518060
|
p03854
|
u465900169
| 2,000
| 262,144
|
Wrong Answer
| 68
| 3,188
| 235
|
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`.
|
import sys
S = input()
while len(S)>5:
if S[-7:] == "dreamer":
S = S[:-7]
elif S[-6:] == "eraser":
S = S[:-6]
elif S[-5:] == "dream" or S[-5:] == "erase":
S = S[:-5]
else:
print("No")
sys.exit()
print("Yes")
|
s361345396
|
Accepted
| 67
| 3,188
| 235
|
import sys
S = input()
while len(S)>5:
if S[-7:] == "dreamer":
S = S[:-7]
elif S[-6:] == "eraser":
S = S[:-6]
elif S[-5:] == "dream" or S[-5:] == "erase":
S = S[:-5]
else:
print("NO")
sys.exit()
print("YES")
|
s003947757
|
p03370
|
u761989513
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 120
|
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() for i in range(n)]))
ans = sum(m)
ans += (x - ans) // min(m)
|
s292758223
|
Accepted
| 17
| 2,940
| 115
|
n, x = map(int, input().split())
m = list(map(int, [input() for i in range(n)]))
print(n + (x - sum(m)) // min(m))
|
s972362398
|
p04030
|
u417959834
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 339
|
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
|
#! python3
def main():
s = str(input())
ans = ""
r = len(s)
for i in range(r):
if s[i] == "0":
ans += "0"
elif s[i] == "1":
ans += "1"
elif s[i] == "b":
if ans == "":
continue
else:
ans = ans[:-1]
print(ans)
main()
|
s342801147
|
Accepted
| 17
| 2,940
| 254
|
#! python3
def main():
s = input()
ans = ""
r = len(s)
for i in range(r):
if s[i] == "0":
ans += "0"
elif s[i] == "1":
ans += "1"
else:
ans = ans[:-1]
print(ans)
main()
|
s029356842
|
p03140
|
u657221245
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 251
|
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
|
n = int(input())
a = input()
b = input()
c = input()
d = 0
for i in range(0, n):
if a[i] != b[i] != c[i]:
d += 2
if a[i] == b[i] == c[i]:
d += 0
if a[i] != b[i] == c[i] or a[i] == b[i] != c[i] or b[i] == a[i] != c[i]:
d += 1
print(d)
|
s882370126
|
Accepted
| 18
| 3,064
| 530
|
n = int(input())
a = input()
b = input()
c = input()
d = 0
for i in range(0, n):
if a[i:i+1] != b[i:i+1] and b[i:i+1] != c[i:i+1] and a[i:i+1] != c[i:i+1]:
d += 2
if a[i:i+1] == b[i:i+1] and b[i:i+1] == c[i:i+1] and a[i:i+1] == c[i:i+1]:
d += 0
if a[i:i+1] != b[i:i+1] and b[i:i+1] == c[i:i+1] and c[i:i+1] != a[i:i+1]:
d += 1
if a[i:i+1] == b[i:i+1] and b[i:i+1] != c[i:i+1] and c[i:i+1] != a[i:i+1]:
d += 1
if a[i:i+1] != b[i:i+1] and b[i:i+1] != c[i:i+1] and c[i:i+1] == a[i:i+1]:
d += 1
print(d)
|
s892810069
|
p03997
|
u451748673
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 50
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a,b,h=[int(i) for i in range(3)]
print((a+b)*h//2)
|
s727978391
|
Accepted
| 17
| 2,940
| 56
|
a,b,h=[int(input()) for i in range(3)]
print((a+b)*h//2)
|
s777721244
|
p03827
|
u175590965
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 161
|
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
|
n = int(input())
s = input()
a = 0
for i in range(len(s)):
if s[i] == "I":
a += 1
elif s[i] == "D":
a += -1
ans = max(a,0)
print(ans)
|
s755330891
|
Accepted
| 18
| 2,940
| 135
|
n = int(input())
s = input()
a = 0
b = 0
for i in s:
if i == "I":
a += 1
else:
a -= 1
b = max(b,a)
print(b)
|
s167357114
|
p03130
|
u272557899
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,064
| 312
|
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
|
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())
if [a1, b1, a2, b2, a3, b3].count(1) == 3 or [a1, b1, a2, b2, a3, b3].count(2) == 3 or [a1, b1, a2, b2, a3, b3].count(3) == 3 or [a1, b1, a2, b2, a3, b3].count(4) == 3:
print("No")
else:
print("Yes")
|
s609743356
|
Accepted
| 18
| 3,064
| 312
|
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())
if [a1, b1, a2, b2, a3, b3].count(1) == 3 or [a1, b1, a2, b2, a3, b3].count(2) == 3 or [a1, b1, a2, b2, a3, b3].count(3) == 3 or [a1, b1, a2, b2, a3, b3].count(4) == 3:
print("NO")
else:
print("YES")
|
s015498136
|
p03478
|
u549161102
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 162
|
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
n,a,b = map(int, input().split())
sum = 0
for i in range(10):
for j in range(10):
if 10*i+j==n and a<i+j and i+j<b :
sum += 10*i + j
print(sum)
|
s815774854
|
Accepted
| 36
| 3,060
| 166
|
n,a,b = map(int, input().split())
total = 0
for i in range(1,n+1):
array = list(map(int,str(i)))
if a<=sum(array) and sum(array)<=b :
total += i
print(total)
|
s710113589
|
p04029
|
u202688141
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 39
|
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
a = int(input())
print((a + 1) * a / 2)
|
s671452095
|
Accepted
| 17
| 2,940
| 51
|
a = int(input())
print('{:.0f}'.format((a+1)*a/2))
|
s912154875
|
p04043
|
u374146618
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 135
|
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.
|
T = [int(x) for x in input().split()]
print(T)
Ts = sorted(T)
if Ts.count(5)==2 and Ts.count(7):
print("YES")
else:
print("NO")
|
s111210753
|
Accepted
| 18
| 2,940
| 102
|
T = [int(x) for x in input().split()]
T.sort()
if T==[5, 5, 7]:
print("YES")
else:
print("NO")
|
s942234827
|
p00112
|
u103916545
| 1,000
| 131,072
|
Wrong Answer
| 30
| 5,612
| 238
|
鈴木さんは会津地域に新しく搾りたてミルクの移動販売のお店を開きました。その日買い求めに来るお客さんは全員持ち帰るためのボトルを持って既にお店に並んでいて、それ以上増えないものとします。お客さんはそれぞれ1回だけしか注文しません。タンクの蛇口が一つしかないので、一人ずつ順番に販売しなければなりません。そこで、鈴木さんはなるべく並んでいるお客さんの待ち時間を少なくしたいと考えています。 お客さんの人数とお客さんが牛乳を注ぎきるのに要する時間が入力として与えられます。あなたはお客さんの「一人一人の待ち時間の合計」(以下「待ち時間の合計」とする)を最小にするための注文の順序を鈴木さんに代わって調べ、そのときの「待ち時間の合計」を出力して終了するプログラムを作成してください。ただし、お客さんは 10,000 人以下で 1 人あたりに要する時間は 60 分以下とします。 例えば、お客さんの人数が 5 人で、各お客さんが要する時間が順に 2,6,4,3,9 分の場合、そのままの順序だと「待ち時間の合計」は 37 分になります。次の例では、最初の列の順の 2 人目と 3 人目を入れ替えています。この場合、「待ち時間の合計」は 35 分になります。最適な順序だと 31 分で済みます。 | 待ち時間| ---|---|--- 1 人目 2 分| 0 分| 2 人目 6 分| 2 分| 3 人目 4 分| 8 分| 4 人目 3 分| 12 分| 5 人目 9 分| 15 分| | 37 分| ← 「待ち時間の合計」 2 人目と 3 人目を入れ替えた例 | 待ち時間| ---|---|--- 1 人目 2 分| 0 分| 2 人目 4 分| 2 分| 3 人目 6 分| 6 分| 4 人目 3 分| 12 分| 5 人目 9 分| 15 分| | 35 分| ← 「待ち時間の合計」
|
n = int(input())
t = []
s = []
temp = 0
sum = 0
for i in range(n+1):
t.append(i)
t[i] = int(input())
if t[i] == 0:
break
else:
t.sort()
print(t)
for m in range(n):
sum = sum + t[m]*(n-m-1)
print(sum)
|
s715819167
|
Accepted
| 1,340
| 5,700
| 297
|
while True:
n = int(input())
t = []
s = 0
sum = 0
if n == 0:
break
else:
for i in range(n):
t.append(i)
t[i] = int(input())
t.sort()
for m in range(n):
sum = sum + t[m]*(n-m-1)
print(sum)
|
s322454754
|
p02263
|
u949338836
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,352
| 270
|
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
|
#coding:utf-8
#1_3_A
formula = input().split()
stack = []
for char in formula:
if char.isdigit():
stack.append(char)
else:
ans = str(eval(stack.pop(len(stack)-2) + char + stack.pop()))
stack.append(ans)
print(stack)
print(stack.pop())
|
s220990025
|
Accepted
| 50
| 7,440
| 253
|
#coding:utf-8
#1_3_A
formula = input().split()
stack = []
for char in formula:
if char.isdigit():
stack.append(char)
else:
ans = str(eval(stack.pop(len(stack)-2) + char + stack.pop()))
stack.append(ans)
print(stack.pop())
|
s429059047
|
p04044
|
u174394352
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 100
|
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
|
N,L=map(int,input().split())
ans=''
for i in range(N):
s=input()
ans=min(ans+s,s+ans)
print(ans)
|
s265221760
|
Accepted
| 18
| 3,060
| 86
|
N,L=map(int,input().split())
S=[input() for i in range(N)]
S.sort()
print(''.join(S))
|
s387287270
|
p02393
|
u921038488
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,556
| 301
|
Write a program which reads three integers, and prints them in ascending order.
|
def bubble_sort(l):
N = len(l)
isChange = True
while isChange:
isChange = False
for i in range(N-1):
if(l[i] > l[i+1]):
l[i], l[i+1] = l[i+1], l[i]
isChange = True
return l
l = input().split()
out = bubble_sort(l)
print(out)
|
s053093214
|
Accepted
| 20
| 5,560
| 339
|
def bubble_sort(l):
N = len(l)
isChange = True
while isChange:
isChange = False
for i in range(N-1):
if(l[i] > l[i+1]):
l[i], l[i+1] = l[i+1], l[i]
isChange = True
return l
l = input().split()
out = bubble_sort(l)
print("{} {} {}".format(out[0], out[1], out[2]))
|
s944261509
|
p03494
|
u188916636
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 94
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
N = int(input())
A = list(map(int, input().split()))
for a in A:
if a%2 != 0:
print(0)
|
s033982569
|
Accepted
| 18
| 2,940
| 222
|
N = int(input())
A = list(map(int, input().split()))
num = 0
flg = True
while flg:
for i in range(N):
if A[i] %2 != 0:
flg = False
break
else:
A[i] //= 2
if flg:
num += 1
print(num)
|
s358460801
|
p02401
|
u450020188
| 1,000
| 131,072
|
Time Limit Exceeded
| 40,000
| 8,252
| 248
|
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.
|
a, op, b = (input().split())
a = int(a)
b = int(b)
while True:
if op == "+":
print(a +b)
elif op == "-":
print(a - b)
elif op == "*":
print(a * b)
elif op == "/":
print(a / b)
else:
break
|
s530396553
|
Accepted
| 30
| 7,588
| 272
|
while True:
a, op, b = (input().split())
x = int(a)
y = int(b)
if op == "?":
break
elif op == "-":
print(x - y)
elif op == "+":
print(x + y)
elif op =="*":
print (x * y)
elif op == "/":
print (x // y)
|
s638924766
|
p03449
|
u883792993
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 335
|
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())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
B1=[0*i for i in range(N)]
B2=[0*i for i in range(N)]
for i in range(0,N-1):
B1[i+1]=B1[i]+A1[i+1]
B2[i+1]=B2[i]+A2[i+1]
maximum=B1[0]+B2[N-1]
for i in range(1,N):
point=B1[i]+(B2[N-1]-B2[i-1])
maximum=max(maximum,point)
print(maximum)
|
s576757468
|
Accepted
| 17
| 3,064
| 359
|
N=int(input())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
B1=[0*i for i in range(N)]
B2=[0*i for i in range(N)]
B1[0]=A1[0]
B2[0]=A2[0]
for i in range(0,N-1):
B1[i+1]=B1[i]+A1[i+1]
B2[i+1]=B2[i]+A2[i+1]
maximum=B1[0]+B2[N-1]
for i in range(1,N):
point=B1[i]+(B2[N-1]-B2[i-1])
maximum=max(maximum,point)
print(maximum)
|
s429083050
|
p03854
|
u627600101
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,188
| 169
|
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()
T=["dream","dreamer","erase","eraser"]
S=S.replace(T[3],"").replace(T[2],"").replace(T[1],"").replace(T[0],"")
if S=="":
print("Yes")
else:
print("No")
|
s211035001
|
Accepted
| 33
| 3,316
| 232
|
S=input()
T=["dream","dreamer","erase","eraser"]
S=S.replace(T[3],"0000000").replace(T[2],"00000").replace(T[1],"0000000").replace(T[0],"00000")
U=""
for k in range(len(S)):
U+="0"
if S==U:
print("YES")
else:
print("NO")
|
s079607672
|
p03943
|
u047535298
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 104
|
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
d = list(map(int, input().split()))
d.sort()
if(d[0]+d[1]==d[2]):
print("YES")
else:
print("NO")
|
s460314773
|
Accepted
| 17
| 2,940
| 104
|
d = list(map(int, input().split()))
d.sort()
if(d[0]+d[1]==d[2]):
print("Yes")
else:
print("No")
|
s881086883
|
p02843
|
u088989565
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 205
|
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
|
N = int(input())
P = int(N//100)
Q = N%100
flag = 0
while N > 2100:
P = int(N//100)
Q = N%100
if(Q <= P*5):
print(1)
flag = 1
break
else:
N -= 2100
if(flag == 0):
print(0)
|
s977685380
|
Accepted
| 17
| 3,060
| 202
|
N = int(input())
P = int(N//100)
Q = N%100
flag = 0
while N > 0:
P = int(N//100)
Q = N%100
if(Q <= P*5):
print(1)
flag = 1
break
else:
N -= 2100
if(flag == 0):
print(0)
|
s152275804
|
p03385
|
u620945921
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 54
|
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 len(set(s)) == 3 else 'No')
|
s306549758
|
Accepted
| 18
| 3,060
| 189
|
import itertools
s=input()
x=list(itertools.permutations(('a','b','c'),3))
flag=0
for i in range(len(x)):
if x[i][0]+x[i][1]+x[i][2] == s:
flag=1
print('Yes' if flag==1 else 'No')
|
s634905307
|
p03699
|
u219607170
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 289
|
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
|
N = int(input())
S1, S2, S5 = [], [1], [1]
for _ in range(N):
s = int(input())
if s%10 == 0:
pass
elif s%5 == 0:
S5.append(s)
elif s%2 == 0:
S2.append(s)
else:
S1.append(s)
ret = max(max(S2), max(S5))
for s in S1:
ret *= s
print(ret)
|
s702829259
|
Accepted
| 20
| 3,060
| 250
|
N = int(input())
S = []
for _ in range(N):
S.append(int(input()))
sums = sum(S)
if sums % 10 != 0:
print(sums)
else:
S.sort()
for s in S:
if s % 10 != 0:
print(sums - s)
break
else:
print(0)
|
s887253561
|
p03503
|
u050428930
| 2,000
| 262,144
|
Wrong Answer
| 349
| 3,064
| 458
|
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
|
N=int(input())
H=['']*N
W=['']*N
x=[]
for i in range(N):
H[i]=list(map(int,input().split()))
for j in range(N):
W[j]=list(map(int,input().split()))
for k in range(1024):
t=[]
for ii in range(10):
if k&(1<<ii):
t+=[1]
else:
t+=[0]
ans=0
for jj in range(N):
s=0
for kk in range(10):
s+=H[jj][kk]*t[kk]
ans+=W[jj][s]
x.append(ans)
print(max(x))
|
s623042132
|
Accepted
| 100
| 3,064
| 271
|
N=int(input())
ans=-10**9
s=["".join(list(input().split())) for i in range(N)]
t=[list(map(int,input().split())) for i in range(N)]
for j in range(1,1024):
q=0
for i in range(len(s)):
q+=t[i][(bin(int(s[i],2)&j)).count("1")]
ans=max(ans,q)
print(ans)
|
s872715432
|
p03380
|
u159994501
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 14,428
| 411
|
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()))
A = max(a)
t = -1
tt = 0
for i in range(n):
if t < a[i]:
t = a[i]
tt = i
a.pop(tt)
print(a)
x = 0
y = A
z = 0
for i in range(1, A):
x += 1
y -= 1
if x >= y:
z = A - x
break
# print(z)
d = float('INF')
da = 0
for i in range(n - 1):
if d > abs(a[i] - z):
da = a[i]
d = a[i] - z
print(A, da)
|
s292671454
|
Accepted
| 78
| 14,428
| 335
|
n = int(input())
a = list(map(int, input().split()))
A = max(a)
t = -1
tt = 0
for i in range(n):
if t < a[i]:
t = a[i]
tt = i
a.pop(tt)
# print(a)
z = A / 2
d = float('INF')
da = 0
for i in range(n - 1):
if d > abs(a[i] - z):
da = a[i]
d = abs(da - z)
print(A, da)
|
s636194449
|
p02612
|
u739843002
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,080
| 41
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N = int(input())
(1000 - N % 1000) % 1000
|
s305315776
|
Accepted
| 30
| 9,060
| 58
|
N = int(input())
ans = (1000 - N % 1000) % 1000
print(ans)
|
s590560053
|
p03470
|
u509405951
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 85
|
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
|
N = int(input())
d = list(map(int, input().split()))
d = list(set(d))
print(len(d))
|
s593375208
|
Accepted
| 17
| 2,940
| 86
|
N = int(input())
d = [int(input()) for i in range(N)]
d = list(set(d))
print(len(d))
|
s334937929
|
p02406
|
u529337794
| 1,000
| 131,072
|
Time Limit Exceeded
| 9,990
| 5,580
| 191
|
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
|
n = int(input())
x = 0
for i in range(1, n+1):
if i%3 == 0:
print(' %d'%i, end="")
else:
x = i
while(x):
if x%10 == 3:
print(' %d'%i, end="")
break
x //= 10
print()
|
s395688045
|
Accepted
| 20
| 5,876
| 264
|
N = int(input())
x = 0
for i in range(1,N+1):
if i%3 == 0:
print(" %d"%i,end = "");
else:
x = i
while (x):
if x%10 == 3:
print(" %d"%i,end = "")
break
x //= 10
print()
|
s858618809
|
p03545
|
u857293613
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 219
|
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.
|
ABCD = input()
ans = ''
def dfs(i, s):
global ans
s += ABCD[i]
if i == 3:
if eval(s) == 7:
ans = s
return
i += 1
dfs(i, s+'+')
dfs(i, s+'-')
dfs(0, '')
print(ans+'+7')
|
s025187500
|
Accepted
| 17
| 3,060
| 219
|
ABCD = input()
ans = ''
def dfs(i, s):
global ans
s += ABCD[i]
if i == 3:
if eval(s) == 7:
ans = s
return
i += 1
dfs(i, s+'+')
dfs(i, s+'-')
dfs(0, '')
print(ans+'=7')
|
s535272527
|
p03673
|
u927534107
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 26,180
| 125
|
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
|
n = int(input())
l = list(map(int,input().split()))
b = []
for i in range(n):
b.append(l.pop(0))
b = b[::-1]
print(b)
|
s265283193
|
Accepted
| 126
| 30,916
| 115
|
n = int(input())
l = list(map(int,input().split()))
b = l[::-2]+l[n%2::2]
b = [str(i)for i in b]
print(" ".join(b))
|
s908806240
|
p02283
|
u150984829
| 2,000
| 131,072
|
Wrong Answer
| 20
| 5,452
| 1
|
Search trees are data structures that support dynamic set operations including insert, search, delete and so on. Thus a search tree can be used both as a dictionary and as a priority queue. Binary search tree is one of fundamental search trees. The keys in a binary search tree are always stored in such a way as to satisfy the following binary search tree property: * Let $x$ be a node in a binary search tree. If $y$ is a node in the left subtree of $x$, then $y.key \leq x.key$. If $y$ is a node in the right subtree of $x$, then $x.key \leq y.key$. The following figure shows an example of the binary search tree. For example, keys of nodes which belong to the left sub-tree of the node containing 80 are less than or equal to 80, and keys of nodes which belong to the right sub-tree are more than or equal to 80. The binary search tree property allows us to print out all the keys in the tree in sorted order by an inorder tree walk. A binary search tree should be implemented in such a way that the binary search tree property continues to hold after modifications by insertions and deletions. A binary search tree can be represented by a linked data structure in which each node is an object. In addition to a key field and satellite data, each node contains fields _left_ , _right_ , and _p_ that point to the nodes corresponding to its left child, its right child, and its parent, respectively. To insert a new value $v$ into a binary search tree $T$, we can use the procedure insert as shown in the following pseudo code. The insert procedure is passed a node $z$ for which $z.key = v$, $z.left = NIL$, and $z.right = NIL$. The procedure modifies $T$ and some of the fields of $z$ in such a way that $z$ is inserted into an appropriate position in the tree. 1 insert(T, z) 2 y = NIL // parent of x 3 x = 'the root of T' 4 while x ≠ NIL 5 y = x // set the parent 6 if z.key < x.key 7 x = x.left // move to the left child 8 else 9 x = x.right // move to the right child 10 z.p = y 11 12 if y == NIL // T is empty 13 'the root of T' = z 14 else if z.key < y.key 15 y.left = z // z is the left child of y 16 else 17 y.right = z // z is the right child of y Write a program which performs the following operations to a binary search tree $T$. * insert $k$: Insert a node containing $k$ as key into $T$. * print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. You should use the above pseudo code to implement the insert operation. $T$ is empty at the initial state.
|
s859005317
|
Accepted
| 3,520
| 63,328
| 722
|
import sys
class Node:
__slots__ = ['key', 'left', 'right']
def __init__(self, key):
self.key = key
self.left = self.right = None
root = None
def insert(key):
global root
x, y = root, None
while x: x, y = x.left if key < x.key else x.right, x
if y is None: root = Node(key)
elif key < y.key: y.left = Node(key)
else: y.right = Node(key)
def inorder(node):
return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''
input()
for e in sys.stdin:
if e[0] == 'i': insert(int(e[7:]))
else: print(inorder(root)); print(preorder(root))
|
|
s768119665
|
p00001
|
u776758454
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,712
| 133
|
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.
|
def main():
mountains_list = [int(input()) for n in range(10)]
print(list(reversed(sorted(mountains_list)))[:3])
main()
|
s410621712
|
Accepted
| 20
| 7,680
| 159
|
def main():
mountains_list = [int(input()) for n in range(10)]
for i in range(3):
print(list(reversed(sorted(mountains_list)))[i])
main()
|
s345487420
|
p03861
|
u485319545
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 136
|
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())
q_b = b/x
q_a = a/x
if x==1:
print(b-a+1)
elif a == b:
print(0)
else:
print(int(q_b-q_a))
|
s426293016
|
Accepted
| 18
| 3,060
| 175
|
a,b,x = map(int,input().split())
q_b = b//x
q_a = a//x
r_a = a%x
if x==1:
print(b-a+1)
else:
if r_a == 0:
print(q_b-q_a + 1 )
else:
print(q_b-q_a)
|
s496417746
|
p02420
|
u328199937
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,592
| 168
|
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
|
while True:
card = input()
if card == '-': break
for i in range(int(input())):
a = int(input())
card = card[:a] + card[a:]
print(card)
|
s536673305
|
Accepted
| 20
| 5,596
| 168
|
while True:
card = input()
if card == '-': break
for i in range(int(input())):
a = int(input())
card = card[a:] + card[:a]
print(card)
|
s437146934
|
p03729
|
u019578976
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 98
|
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
|
a,b,c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
print("Yes")
else:
print("No")
|
s375002996
|
Accepted
| 17
| 2,940
| 98
|
a,b,c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
print("YES")
else:
print("NO")
|
s831297664
|
p02401
|
u365921604
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,592
| 240
|
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.
|
inputs = input().split(' ')
a = int(inputs[0])
op = inputs[1]
b = int(inputs[2])
if op == "+":
print(a + b)
elif op == "-":
print(a - b)
elif op == "*":
print(a * b)
else:
print(a // b)
|
s505329482
|
Accepted
| 20
| 5,596
| 334
|
while True:
inputs = input().split(' ')
a = int(inputs[0])
op = inputs[1]
b = int(inputs[2])
if op == "?":
break
elif op == "+":
print(a + b)
elif op == "-":
print(a - b)
elif op == "*":
print(a * b)
else:
print(a // b)
|
s261095498
|
p02795
|
u621509924
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 66
|
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
|
H=int(input())
W=int(input())
N=int(input())
print(max(N//W,H//W))
|
s685497720
|
Accepted
| 17
| 2,940
| 118
|
H=int(input())
W=int(input())
N=int(input())
if N%max(W,H)==0:
print(N//max(W,H))
else:
print((N//max(W,H))+1)
|
s211701958
|
p03826
|
u227085629
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 45
|
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())
max(a*b,c*d)
|
s028279695
|
Accepted
| 18
| 2,940
| 54
|
a,b,c,d=map(int,input().split())
print(max(a*b , c*d))
|
s139736192
|
p03369
|
u767995501
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 43
|
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
|
s = input()
print(700 + 700 * s.count("o"))
|
s358658053
|
Accepted
| 18
| 2,940
| 43
|
s = input()
print(700 + 100 * s.count("o"))
|
s120353810
|
p03998
|
u174040991
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,052
| 377
|
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
|
a,b,c = [str(input()) for i in range(3)]
current = 'a'
while True:
cur = current[len(current)-1]
if cur == 'a':
current+=a[0]
a=a[1:]
elif cur == 'b':
current+=b[0]
b=b[1:]
elif cur == 'c':
current+=c[0]
c=c[1:]
if a == '' or b =='' or c =='':
print(current[len(current)-1].upper())
print(current)
break
|
s210907509
|
Accepted
| 31
| 9,032
| 337
|
a,b,c = [str(input()) for i in range(3)]
current = 'a'
while True:
try:
cur = current[len(current)-1]
if cur == 'a':
current+=a[0]
a=a[1:]
elif cur == 'b':
current+=b[0]
b=b[1:]
elif cur == 'c':
current+=c[0]
c=c[1:]
except:
print(current[len(current)-1].upper())
break
|
s874121067
|
p02972
|
u762540523
| 2,000
| 1,048,576
|
Wrong Answer
| 117
| 9,656
| 242
|
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
|
def main():
n = int(input())
a = list(map(int, input().split()))
if a[0] == 0:
print(0)
elif n == 1:
print(1)
print(1)
else:
print(1)
l = [0] * (n - 1)
print(1, *l)
main()
|
s546671967
|
Accepted
| 258
| 14,132
| 177
|
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n-1,-1,-1):
b[i]=(a[i]+sum(b[i::i+1]))%2
l=[x+1 for x,y in enumerate(b) if y==1]
print(len(l))
print(*l)
|
s698835807
|
p02842
|
u762540523
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 121
|
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
|
n=int(input())
a=int(n/1.08)
z=lambda x:int(x*1.08)
if z(a)==n:
print(a)
if z(a+1)==n:
print(a+1)
else:
print(":(")
|
s912743613
|
Accepted
| 17
| 3,060
| 123
|
n=int(input())
a=int(n/1.08)
z=lambda x:int(x*1.08)
if z(a)==n:
print(a)
elif z(a+1)==n:
print(a+1)
else:
print(":(")
|
s000886351
|
p03494
|
u089142196
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 226
|
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()))
count=0
flag=True
while flag==True:
for i in range(0,N):
if A[i]%2==0:
A[i]=A[i]/2
else:
flag=False
break
else:
count=count+1
print(A)
|
s432707743
|
Accepted
| 20
| 3,060
| 229
|
N=int(input())
A = list(map(int, input().split()))
count=0
flag=True
while flag==True:
for i in range(0,N):
if A[i]%2==0:
A[i]=A[i]/2
else:
flag=False
break
else:
count=count+1
print(count)
|
s376362280
|
p02844
|
u660245210
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,188
| 405
|
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
|
a = int(input())
b = input()
def my_count(l):
p = 0
for i in range(10):
i = str(i)
if i in l:
p = p + 1
return p
s = []
ans = 0
for i in range(10):
k = str(i)
s.append(b.find(k))
if s[i] >= 0:
for j in range(10):
h = str(j)
y = b[s[i]+1:len(b)]
t = y.find(h)
if t >= 0:
c = y[t+1:len(b)]
ans = ans + my_count(c)
print(s)
print(ans)
|
s749552437
|
Accepted
| 18
| 3,188
| 396
|
a = int(input())
b = input()
def my_count(l):
p = 0
for i in range(10):
i = str(i)
if i in l:
p = p + 1
return p
s = []
ans = 0
for i in range(10):
k = str(i)
s.append(b.find(k))
if s[i] >= 0:
for j in range(10):
h = str(j)
y = b[s[i]+1:len(b)]
t = y.find(h)
if t >= 0:
c = y[t+1:len(b)]
ans = ans + my_count(c)
print(ans)
|
s808604454
|
p02795
|
u081193942
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 96
|
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
|
import math
h = int(input())
w = int(input())
n= int(input())
print(math.ceil(n // max(h, w)))
|
s085110676
|
Accepted
| 21
| 3,316
| 95
|
import math
h = int(input())
w = int(input())
n= int(input())
print(math.ceil(n / max(h, w)))
|
s994357093
|
p03480
|
u086612293
| 2,000
| 262,144
|
Wrong Answer
| 111
| 3,188
| 377
|
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times. * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def main():
s = map(int, sys.stdin.readline().strip())
cnt = ([0, 0], [0, 0])
for i in s:
cnt[1][i] += 1
cnt[0][i] = max(cnt[0][i], cnt[1][i])
j = 1 - i
cnt[0][j] = max(cnt[0][j], cnt[1][j])
cnt[1][j] = 0
print(max(cnt[0]))
if __name__ == '__main__':
main()
|
s655925426
|
Accepted
| 62
| 4,084
| 294
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def main():
s = tuple(map(int, sys.stdin.readline().strip()))
n = len(s)
k = n
for i in range(1, n):
if s[i - 1] != s[i]:
k = min(k, max(i, n - i))
print(k)
if __name__ == '__main__':
main()
|
s155872735
|
p03024
|
u620755587
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 39
|
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.
|
print("YNeos"[input().count("x")>8::2])
|
s970835837
|
Accepted
| 18
| 2,940
| 40
|
print("YNEOS"[input().count("x")>=8::2])
|
s933081220
|
p03852
|
u779830746
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,008
| 125
|
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
|
word = input()
vowel_list = ['a', 'i', 'u', 'e', 'o']
if word in vowel_list:
print('Vowel')
else:
print('Consonant')
|
s759227568
|
Accepted
| 26
| 8,916
| 125
|
word = input()
vowel_list = ['a', 'i', 'u', 'e', 'o']
if word in vowel_list:
print('vowel')
else:
print('consonant')
|
s619895286
|
p02396
|
u139687801
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,608
| 127
|
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
|
buffer = [int(x) for x in input().split()]
for num in range(len(buffer)):
print('Case '+ str(num) +': '+ str(buffer[num]))
|
s377814111
|
Accepted
| 90
| 5,904
| 185
|
buffer = []
while True:
a = int(input())
if a == 0:
break
buffer.append(a)
for num in range(len(buffer)):
print('Case '+ str(num+1) +': '+ str(buffer[num]))
|
s714692363
|
p03564
|
u589969467
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,020
| 62
|
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
|
n = int(input())
k = int(input())
ans = 2**n + k*n
print(ans)
|
s797535943
|
Accepted
| 30
| 8,840
| 125
|
n = int(input())
k = int(input())
ans = 2**n
for i in range(n+1):
tmp = 2**i + k*(n-i)
ans = min(ans,tmp)
print(ans)
|
s253858566
|
p02396
|
u239721772
| 1,000
| 131,072
|
Wrong Answer
| 130
| 7,636
| 82
|
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
|
x = int(input(""))
while x != 0:
print("{0}".format(x))
x = int(input(""))
|
s677296439
|
Accepted
| 140
| 7,616
| 111
|
x = int(input(""))
i = 1
while x != 0:
print("Case {0}: {1}".format(i,x))
i += 1
x = int(input(""))
|
s797800118
|
p00001
|
u149199817
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,504
| 305
|
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.
|
# -*- coding: utf-8 -*-
import sys
def top_k_sort(data, k=3, reverse=True):
data.sort(reverse=True)
return data[:k]
def main():
argv = sys.argv
argc = len(argv)
data = [int(v) for v in argv[1:]]
for h in top_k_sort(data):
print(h)
if __name__ == '__main__':
main()
|
s403126268
|
Accepted
| 60
| 7,740
| 298
|
# -*- coding: utf-8 -*-
import sys
def top_k_sort(data, k=3, reverse=True):
data.sort(reverse=True)
return data[:k]
def main():
data = []
for line in sys.stdin:
data.append(int(line))
for h in top_k_sort(data):
print(h)
if __name__ == '__main__':
main()
|
s522158815
|
p03457
|
u598720217
| 2,000
| 262,144
|
Wrong Answer
| 332
| 11,800
| 576
|
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
N = int(input())
array_t = []
array_x = []
array_y = []
for i in range(N):
t,x,y = map(int, input().split(" "))
array_t.append(t)
array_x.append(x)
array_y.append(y)
flag = True
for i in range(N):
if i ==0:
added = abs(array_x[0])+abs(array_y[0])
gap = array_t[0] - added
else:
added = abs(array_x[i]-array_x[i-1])+abs(array_x[i]+array_y[i-1])
gap = array_t[i]-array_t[i-1] - added
if gap>=0 and gap%2 == 0:
continue
else:
print('NO')
flag = False
break
if flag:
print('YES')
|
s545137161
|
Accepted
| 394
| 11,840
| 576
|
N = int(input())
array_t = []
array_x = []
array_y = []
for i in range(N):
t,x,y = map(int, input().split(" "))
array_t.append(t)
array_x.append(x)
array_y.append(y)
flag = True
for i in range(N):
if i ==0:
added = abs(array_x[0])+abs(array_y[0])
gap = array_t[0] - added
else:
added = abs(array_x[i]-array_x[i-1])+abs(array_y[i]-array_y[i-1])
gap = array_t[i]-array_t[i-1] - added
if gap>=0 and gap%2 == 0:
continue
else:
print('No')
flag = False
break
if flag:
print('Yes')
|
s916550643
|
p03778
|
u239342230
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 61
|
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
|
W,a,b=map(int,input().split())
print(0 if b-a+W<1 else b-a+W)
|
s183252904
|
Accepted
| 17
| 2,940
| 109
|
W,a,b=map(int,input().split())
if b>=a:
print(0 if b-a-W<1 else b-a-W)
else:
print(0 if a-b-W<1 else a-b-W)
|
s181799081
|
p03889
|
u476418095
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,316
| 709
|
You are given a string S consisting of letters `b`, `d`, `p` and `q`. Determine whether S is a _mirror string_. Here, a mirror string is a string S such that the following sequence of operations on S results in the same string S: 1. Reverse the order of the characters in S. 2. Replace each occurrence of `b` by `d`, `d` by `b`, `p` by `q`, and `q` by `p`, simultaneously.
|
s=input().split()
if s[0]=='d' and s[3]=='b':
if s[1]=='p' and s[2]=='q':
print('Yes')
elif s[1]=='q' and s[2]=='p':
print('Yes')
else:
print('No')
elif s[0]=='b' and s[3]=='d':
if s[1]=='p' and s[2]=='q':
print('Yes')
elif s[1]=='q' and s[2]=='p':
print('Yes')
else:
print('No')
elif s[0]=='p' and s[3]=='q':
if s[1]=='d' and s[2]=='b':
print('Yes')
elif s[1]=='b' and s[2]=='d':
print('Yes')
else:
print('No')
elif s[0]=='q' and s[3]=='p':
if s[1]=='d' and s[2]=='b':
print('Yes')
elif s[1]=='b' and s[2]=='d':
print('Yes')
else:
print('No')
else:
print('No')
|
s527477865
|
Accepted
| 26
| 5,420
| 121
|
mp={'b':'d','d':'b','p':'q','q':'p'};a=list(input());b=list(a[::-1]);b=[mp[x] for x in b];print("Yes" if a==b else "No");
|
s234990760
|
p03545
|
u513081876
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 197
|
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
|
a=input()
op=['+','-']
for i in op:
for j in op:
for k in op:
if a[0]+i+a[1]+j+a[2]+k+a[3]==7:
print(a[0]+i+a[1]+j+a[2]+k+a[3]+"=7")
exit()
|
s491755293
|
Accepted
| 19
| 3,064
| 576
|
import sys
a = list(input())
for i in range(2):
for j in range(2):
for k in range(2):
if i % 2 == 0:
sym1 = '+'
else:
sym1 = '-'
if j % 2 == 0:
sym2 = '+'
else:
sym2 = '-'
if k % 2 == 0:
sym3 = '+'
else:
sym3 = '-'
word = a[0] + sym1 + a[1] + sym2 + a[2] + sym3 + a[3]
ans = eval(word)
if ans == 7:
print(word+'=7')
sys.exit()
|
s560197630
|
p04029
|
u021759654
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 72
|
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
num = int(input())
ans = 0
for i in range(num+1):
ans += 1
print(ans)
|
s272000374
|
Accepted
| 16
| 2,940
| 73
|
num = int(input())
ans = 0
for i in range(num+1):
ans += i
print(ans)
|
s318458642
|
p03759
|
u836737505
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 72
|
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
|
a, b, c = map(int, input().split())
print("Yes" if b-a == c-b else "No")
|
s562939924
|
Accepted
| 17
| 2,940
| 72
|
a, b, c = map(int, input().split())
print("YES" if b-a == c-b else "NO")
|
s492828747
|
p02844
|
u694665829
| 2,000
| 1,048,576
|
Wrong Answer
| 1,832
| 9,644
| 653
|
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
|
import sys
readline = sys.stdin.readline
n = int(readline())
s = readline().rstrip()
from collections import deque
q = deque([])
for i in range(10):
q.append(["",0,str(i)])
ans = 0
while q:
num, ind, target = q.popleft()
print(num, ind, target)
while ind < len(s):
if s[ind] == target:
break
ind += 1
else:
continue
num += target
if len(num) == 3:
ans += 1
continue
for i in range(10):
q.append([num, ind +1, str(i)])
print(ans)
|
s278208211
|
Accepted
| 964
| 9,536
| 679
|
import sys
readline = sys.stdin.readline
n = int(readline())
s = readline().rstrip()
from collections import deque
q = deque([])
ss = set(s)
for i in ss:
q.append(["",0,str(i)])
ans = 0
while q:
num, ind, target = q.popleft()
#print(num, ind, target)
while ind < len(s):
if s[ind] == target:
break
ind += 1
else:
continue
num += target
if len(num) == 3:
ans += 1
continue
sss = set(s[ind+1:])
for i in sss:
q.append([num, ind +1, str(i)])
print(ans)
|
s156926685
|
p03251
|
u962330718
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 334
|
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
|
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
z=[]
for i in range(X+1,Y+1):
z.append(i)
if max(x)>=min(y):
print("War")
else:
for i in range(max(x)+1,min(y)+1):
if i in z:
print("No war")
break
else:
if i==min(y) and i not in z:
print("War")
|
s408800924
|
Accepted
| 18
| 3,064
| 221
|
n,m,X,Y=map(int,input().split())
x_List=list(map(int,input().split()))
y_List=list(map(int,input().split()))
x_List.append(X)
y_List.append(Y)
ans=''
if max(x_List)<min(y_List):
ans='No War'
else:
ans='War'
print(ans)
|
s144609072
|
p02558
|
u802234211
| 5,000
| 1,048,576
|
Wrong Answer
| 593
| 13,040
| 1,774
|
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types. * `0 u v`: Add an edge (u, v). * `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
|
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,q = map(int,input().split())
uf = UnionFind(n)
ans = []
l = 0
for i in range(q):
t,u1,u2 = map(int,input().split())
if(t == 0):
uf.union(u1,u2)
else:
if(uf.same(u1,u2)):
ans.append(1)
else:
ans.append(0)
l += 1
print([ans[i] for i in range(l)])
|
s884837245
|
Accepted
| 593
| 12,460
| 1,777
|
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,q = map(int,input().split())
uf = UnionFind(n)
ans = []
l = 0
for i in range(q):
t,u1,u2 = map(int,input().split())
if(t == 0):
uf.union(u1,u2)
else:
if(uf.same(u1,u2)):
ans.append(1)
else:
ans.append(0)
l += 1
for i in range(l):
print(ans[i])
|
s145710893
|
p03493
|
u607680583
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,152
| 86
|
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.
|
sl = [int(x) for x in input().split()]
n=0
for s in sl:
if s==1:
n+=1
print(n)
|
s076652859
|
Accepted
| 29
| 9,068
| 77
|
sl = [int(x) for x in input()]
n=0
for s in sl:
if s==1:
n+=1
print(n)
|
s030446660
|
p02612
|
u192976656
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,096
| 35
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
n=int(input())
print(1000-n//1000)
|
s070510064
|
Accepted
| 24
| 9,156
| 70
|
n=int(input())
if n%1000!=0:
print(1000-n%1000)
else:
print(0)
|
s887799476
|
p03958
|
u426108351
| 1,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 103
|
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
|
K, T = map(int, input().split())
a = list(map(int, input().split()))
print(max(a)-(sum(a)-max(a))-1, 0)
|
s817529904
|
Accepted
| 18
| 2,940
| 108
|
K, T = map(int, input().split())
a = list(map(int, input().split()))
print(max(max(a)-(sum(a)-max(a))-1, 0))
|
s624976790
|
p02743
|
u948410660
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 125
|
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
|
from math import sqrt
a,b,c=list(map(int,input().split()))
d=2*sqrt(a*b)
if c-a-b-d>0:
print("Yes")
else:
print("NO")
|
s876557584
|
Accepted
| 18
| 2,940
| 112
|
a,b,c=list(map(int,input().split()))
d=(c-a-b)**2
if 4*a*b<d and c-a-b>0:
print("Yes")
else:
print("No")
|
s343635578
|
p03047
|
u729535891
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 48
|
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
|
n, k = map(int, input().split())
print(n + k -1)
|
s123927695
|
Accepted
| 17
| 2,940
| 49
|
n, k = map(int, input().split())
print(n - k + 1)
|
s395622502
|
p03494
|
u103902792
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 187
|
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.
|
_ = input()
l = list(map(int,input().split()))
mn = 99999
for i in l:
count = 0
if i %2 ==0:
count +=1
i /= 2
else:
continue
if mn > count:
count = mn
print(count)
|
s135226887
|
Accepted
| 19
| 3,060
| 214
|
n = int(input())
AS = list(map(int,input().split()))
count = 0
while True:
for i in range(n):
a = AS[i]
if a %2:
break
AS[i] = int(a/2)
else:
count += 1
continue
break
print(count)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.