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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s038682499
|
p03110
|
u430223993
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 270
|
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
|
x = [i for i in input().rsplit('\n')]
money = []
unit = []
for i in x[1:]:
m, u = i.split()
money.append(float(m))
unit.append(u)
total = 0
for m, u in zip(money, unit):
if u == 'JPY':
total += m
else:
total += 380000*m
print(total)
|
s433627356
|
Accepted
| 17
| 3,064
| 261
|
n = int(input())
money = []
unit = []
for i in range(n):
m, u = input().split()
money.append(float(m))
unit.append(u)
total = 0.0
for m, u in zip(money, unit):
if u == 'JPY':
total += m
else:
total += 380000.0*m
print(total)
|
s317247001
|
p03470
|
u504770075
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 288
|
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=[]
print('n=',n)
for i in range(n):
d.append(int(input()))
k=0
for i in range(n-1):
print('i =',i)
for j in range(i+1,n):
if d[i]==d[j]:
j -= 1
break
print('j =',j)
if j == n-1:
k += 1
k += 1
print('k =',k)
|
s898347973
|
Accepted
| 18
| 3,060
| 233
|
n=int(input())
d=[]
for i in range(n):
d.append(int(input()))
k=0
for i in range(n-1):
for j in range(i+1,n):
if d[i]==d[j]:
j -= 1
break
if j == n-1:
k += 1
k += 1
print(k)
|
s529642751
|
p02833
|
u539850805
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 221
|
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
|
n = int(input())
if n%2 != 0:
print(0)
else:
c = 0
k = 1
while n >= 2:
if n%10 == 0:
c += int(str(n)[0])
if n % 5 == 0:
c += 1
n //= 10
print(c)
|
s829043428
|
Accepted
| 17
| 2,940
| 351
|
def findTrailingZeros(n):
# Initialize result
count = 0
# Keep dividing n by
# powers of 5 and
# update Count
i=10
while (n/i>0):
count += n//i
i *= 5
return int(count)
n = int(input())
if n%2 != 0:
print(0)
else:
print(findTrailingZeros(n))
|
s554164614
|
p03597
|
u373047809
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 80
|
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
|
_, k, *x = map(int, open(0).read().split())
print(sum(min(i, k-i) for i in x)*2)
|
s533222171
|
Accepted
| 18
| 2,940
| 35
|
print(int(input())**2-int(input()))
|
s842064174
|
p03827
|
u064246852
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 116
|
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()
ans = 0
for c in S:
if c == "I":
ans += 1
else:
ans -= 1
print(ans)
|
s940580702
|
Accepted
| 18
| 2,940
| 116
|
input()
m=0
x=0
for c in input():
if c == "I":
x += 1
else:
x -= 1
m = max(x,m)
print(m)
|
s135536116
|
p03658
|
u375695365
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 162
|
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
|
a,b=list(map(int,input().split()))
c=list(int(i) for i in input().split())
c.sort(reverse=True)
print(c)
count=0
for i in range(b):
count+=c[i]
print(count)
|
s573217238
|
Accepted
| 17
| 2,940
| 153
|
a,b=list(map(int,input().split()))
c=list(int(i) for i in input().split())
c.sort(reverse=True)
count=0
for i in range(b):
count+=c[i]
print(count)
|
s881464468
|
p03853
|
u117193815
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 142
|
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
|
h,w = map(int, input().split())
l=[]
for i in range(h):
l.append(list(input().split()))
for i in range(h):
print(l[i])
print(l[i])
|
s191577760
|
Accepted
| 18
| 3,060
| 159
|
h,w = map(int, input().split())
l=[]
for i in range(h):
l.append(list(input().split())*2)
for i in range(h):
for j in range(2):
print(l[i][j])
|
s170641796
|
p02255
|
u285980122
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,600
| 308
|
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
def Insertion_Sort(A, N):
A = list(map(int, A.split()))
for i in range(1,N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(" ".join(map(str,A)))
N = int(input())
A = input()
Insertion_Sort(A, N)
|
s889280952
|
Accepted
| 30
| 5,604
| 321
|
def Insertion_Sort(A, N):
print(A)
A = list(map(int, A.split()))
for i in range(1,N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(" ".join(map(str,A)))
N = int(input())
A = input()
Insertion_Sort(A, N)
|
s847855432
|
p03024
|
u623349537
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 152
|
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
|
S = input()
win_no = 0
for match in S:
if match == "o":
win_no += 1
if win_no + 15 - len(S)>= 8:
print("Yes")
else:
print("No")
|
s405793420
|
Accepted
| 18
| 2,940
| 152
|
S = input()
win_no = 0
for match in S:
if match == "o":
win_no += 1
if win_no + 15 - len(S)>= 8:
print("YES")
else:
print("NO")
|
s090205552
|
p02413
|
u777299405
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,724
| 231
|
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
|
r, c = map(int, input().split())
matrix = []
for i in range(r):
l = list(map(int, input().split()))
l.append(sum(l))
matrix.append(l)
print(list(zip(*matrix)))
matrix.append([sum(i) for i in zip(*matrix)])
print(matrix)
|
s583840219
|
Accepted
| 40
| 6,732
| 247
|
r, c = map(int, input().split())
matrix = []
for i in range(r):
l = list(map(int, input().split()))
l.append(sum(l))
matrix.append(l)
matrix.append([sum(i) for i in zip(*matrix)])
for l in matrix:
print(" ".join(str(n) for n in l))
|
s615062782
|
p02612
|
u000875186
| 2,000
| 1,048,576
|
Wrong Answer
| 29
| 9,032
| 62
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
x=int(input())
if(x&1000==0):
print(0)
else:
print(x%1000)
|
s456428212
|
Accepted
| 24
| 9,084
| 71
|
x=int(input())
if(x%1000==0):
print(0)
else:
print(1000-x%1000)
|
s555303857
|
p03679
|
u266171694
| 2,000
| 262,144
|
Wrong Answer
| 21
| 2,940
| 99
|
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
|
x, a, b = map(int, input().split())
if b - a <= x:
print('delicious')
else:
print('dangerous')
|
s605882746
|
Accepted
| 17
| 2,940
| 131
|
x, a, b = map(int, input().split())
if b - a > x:
print('dangerous')
elif b - a > 0:
print('safe')
else:
print('delicious')
|
s261201799
|
p02607
|
u988897084
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,172
| 189
|
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
|
n = input()
num = list(map(int,input().split()))
print(num)
# mul = int(input().split())
cnt = 0
for i in range(len(num)):
if(i % 2 != 0 and num[i] %2 != 0):
cnt += 1
print(cnt)
|
s536541054
|
Accepted
| 25
| 8,964
| 263
|
if __name__ == "__main__":
n = int(input())
num = list(map(int,input().split()))
# print(type(num[0]))
cnt = 0
for i in range(1,n+1):
# print(i,num[i-1])
if(num[i-1] % 2 != 0 and i % 2 != 0):
cnt += 1
print(cnt)
|
s043209211
|
p03565
|
u539517139
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 337
|
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
|
s=input()
t=input()
u='UNRESTORABLE'
if len(s)>=len(t):
for i in range(len(s)-len(t)+1):
f=0
for j in range(i,i+len(t)):
if s[j]!='?' and s[j]!=t[j-i]:
f=1
if f==0:
for j in range(i,i+len(t)):
if s[j]!='?':
s=s[:j]+t[j-i]+s[j+1:]
s.replace('?','a')
u=s
break
print(u)
|
s953797244
|
Accepted
| 17
| 3,064
| 330
|
s=input()
t=input()
u='UNRESTORABLE'
a=[]
if len(s)>=len(t):
for i in range(len(s)-len(t)+1):
f=0
for j in range(i,i+len(t)):
if s[j]!='?' and s[j]!=t[j-i]:
f=1
if f==0:
m=s[:i]+t+s[i+len(t):]
m=m.replace('?','a',50)
a.append(m)
if len(a)==0:
print(u)
else:
a.sort()
print(a[0])
|
s280137000
|
p02741
|
u830592648
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 123
|
Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
|
M=[0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
M[K]
|
s133933328
|
Accepted
| 22
| 3,060
| 135
|
M=[0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(int(M[K]))
|
s684037589
|
p03455
|
u183469756
| 2,000
| 262,144
|
Wrong Answer
| 26
| 9,152
| 93
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
a, b = map(int, input().split())
if a * b / 2 == 0:
print('odd')
else:
print('even')
|
s625880542
|
Accepted
| 29
| 9,036
| 93
|
a, b = map(int, input().split())
if a * b % 2 == 0:
print("Even")
else:
print("Odd")
|
s586882228
|
p02368
|
u022407960
| 1,000
| 131,072
|
Wrong Answer
| 70
| 7,688
| 2,779
|
A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable.
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4
output:
1
0
1
1
"""
import sys
sys.setrecursionlimit(int(1e4))
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
return init_adj_table
def graph_dfs(u, low, disc, stack_member, st):
global Time
# Initialize discovery time and low value
disc[u] = Time
low[u] = Time
Time += 1
stack_member[u] = True
st.append(u)
scc_set = set()
# Go through all vertices adjacent to this
for v in adj_table[u]:
# If v is not visited yet, then recur for it
if disc[v] == -1:
graph_dfs(v, low, disc, stack_member, st)
# Check if the subtree rooted with v has a connection to
# one of the ancestors of u
# Case 1 (per above discussion on Disc and Low value)
low[u] = min(low[u], low[v])
elif stack_member[v]:
'''Update low value of 'u' only if 'v' is still in stack
(i.e. it's a back edge, not cross edge).
Case 2 (per above discussion on Disc and Low value) '''
low[u] = min(low[u], disc[v])
# head node found, pop the stack and print an SCC
w = -1
if low[u] == disc[u]:
while w != u:
w = st.pop()
scc_set.add(w)
stack_member[w] = False
ans.append(scc_set)
return None
def scc():
# Mark all the vertices as not visited
# and Initialize parent and visited,
# and ap(articulation point) arrays
disc = [-1] * vertices
low = [-1] * vertices
stack_member = [False] * vertices
st = []
# Call the recursive helper function
# to find articulation points
# in DFS tree rooted with vertex 'i'
for v in range(vertices):
if disc[v] == -1:
graph_dfs(v, low, disc, stack_member, st)
return ans
def solve():
for question in q_list:
flag = False
ele1, ele2 = map(int, question)
for each in scc_sets:
if (ele1 in each) and (ele2 in each):
flag = True
if flag:
print('1')
else:
print('0')
return None
if __name__ == '__main__':
_input = sys.stdin.readlines()
vertices, edges = map(int, _input[0].split())
v_info = map(lambda x: x.split(), _input[1:edges + 1])
q_num = int(_input[edges + 1])
q_list = map(lambda x: x.split(), _input[edges + 2:])
init_adj_table = tuple([] for _ in range(vertices))
adj_table = generate_adj_table(v_info)
Time = 0
ans = []
scc_sets = scc()
print(scc_sets)
solve()
|
s066442907
|
Accepted
| 2,520
| 26,548
| 2,307
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4
output:
1
0
1
1
"""
import sys
from math import isinf
sys.setrecursionlimit(int(1e5))
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
return init_adj_table
def Tarjan(current, low, dfn, scc_stack, in_scc_stack):
global timer
dfn[current] = low[current] = timer
timer += 1
scc_stack.append(current)
in_scc_stack[current] = True
current_scc_set = set()
for adj in adj_table[current]:
if isinf(dfn[adj]):
Tarjan(adj, low, dfn, scc_stack, in_scc_stack)
low[current] = min(low[current], low[adj])
elif in_scc_stack[adj]:
low[current] = min(low[current], dfn[adj])
scc_candidate = -1
if dfn[current] == low[current]:
while scc_candidate != current:
scc_candidate = scc_stack.pop()
in_scc_stack[scc_candidate] = False
current_scc_set.add(scc_candidate)
init_scc_sets_list.append(current_scc_set)
return None
def scc_cluster():
dfn = [float('inf')] * vertices
low = [float('inf')] * vertices
scc_stack = list()
in_scc_stack = [False] * vertices
for v in range(vertices):
if isinf(dfn[v]):
Tarjan(v, low, dfn, scc_stack, in_scc_stack)
return init_scc_sets_list
def solve(_scc_sets_list):
for question in q_list:
flag = False
ele1, ele2 = map(int, question)
for each in _scc_sets_list:
if (ele1 in each) and (ele2 in each):
flag = True
break
if flag:
print('1')
else:
print('0')
return None
if __name__ == '__main__':
_input = sys.stdin.readlines()
vertices, edges = map(int, _input[0].split())
v_info = map(lambda x: x.split(), _input[1:edges + 1])
q_num = int(_input[edges + 1])
q_list = map(lambda x: x.split(), _input[edges + 2:])
init_adj_table = tuple([] for _ in range(vertices))
adj_table = generate_adj_table(v_info)
timer = 0
init_scc_sets_list = []
scc_sets_list = scc_cluster()
solve(scc_sets_list)
|
s965855624
|
p03853
|
u810066979
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 140
|
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
|
h,w=map(int,input().split())
list=[0]*(h*2)
for i in range(h):
c=input()
list[i]=c
list[i+h]=c
for j in range(len(list)):
print(list[j])
|
s708688508
|
Accepted
| 18
| 3,060
| 78
|
h,w=map(int,input().split())
for i in range(h):
c=input()
print(c)
print(c)
|
s836982905
|
p02614
|
u731436822
| 1,000
| 1,048,576
|
Wrong Answer
| 160
| 26,896
| 492
|
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
|
#ABC 173 C - H and V
import numpy as np
h,w,k = map(int,input().split())
c = np.zeros((h,w)).astype('str')
for i in range(h):
s = input()
for j,a in enumerate(s):
c[i,j] = a
print(c)
cnt = 0
for o in range(2**h):
for l in range(2**w):
black = 0
for m in range(h):
for n in range(w):
if ((o>>m)&1==0) and ((l>>n)&1==0) and (c[m,n]=='#'):
black += 1
if black == k:
cnt += 1
print(cnt)
|
s925864498
|
Accepted
| 168
| 27,076
| 487
|
#ABC 173 C - H and V
import numpy as np
h,w,k = map(int,input().split())
c = np.zeros((h,w)).astype('str')
for i in range(h):
s = input()
for j,a in enumerate(s):
c[i,j] = a
cnt = 0
for o in range(2**h):
for l in range(2**w):
black = 0
for m in range(h):
for n in range(w):
if ((o>>m)&1==0) and ((l>>n)&1==0) and (c[m,n]=='#'):
black += 1
if black == k:
cnt += 1
print(cnt)
|
s386249722
|
p03477
|
u004025573
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 131
|
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
A,B,C,D = map(int,input().split())
r=A+B
l=C+D
if r>l:
print("Right")
elif l>r:
print("Left")
else:
print("Balanced")
|
s070133734
|
Accepted
| 21
| 3,316
| 131
|
A,B,C,D = map(int,input().split())
l=A+B
r=C+D
if r>l:
print("Right")
elif l>r:
print("Left")
else:
print("Balanced")
|
s625380285
|
p03139
|
u598229387
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 73
|
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
|
n,a,b=map(int,input().split())
ans1=min(a,b)
ans2=a+b-n
print(ans1,ans2)
|
s490364057
|
Accepted
| 17
| 2,940
| 80
|
n,a,b=map(int,input().split())
ans1=min(a,b)
ans2=max(0,a+b-n)
print(ans1,ans2)
|
s810106701
|
p03024
|
u128999728
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 242
|
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.
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
c = 0
s = input()
for t in s:
if t == 'o':
c += 1
print(t, c)
if c >= 8:
print('YES')
else:
print('NO')
if __name__ == '__main__':
import sys
sys.exit(main())
|
s275181040
|
Accepted
| 17
| 3,064
| 248
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
c = 0
s = input()
for t in s:
if t == 'o':
c += 1
c += 15 - len(s)
if c >= 8:
print('YES')
else:
print('NO')
if __name__ == '__main__':
import sys
sys.exit(main())
|
s220397567
|
p03456
|
u440129511
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 118
|
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
import math
a,b=map(str,input().split())
ab=a+b
ab=int(ab)
if type(math.sqrt(ab))=='int':print('Yes')
else:print('No')
|
s448702838
|
Accepted
| 17
| 2,940
| 124
|
import math
a,b=map(str,input().split())
ab=a+b
ab=int(ab)
if math.sqrt(ab).is_integer()==True:print('Yes')
else:print('No')
|
s203079084
|
p00014
|
u424041287
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,596
| 68
|
Write a program which computes the area of a shape represented by the following three lines: $y = x^2$ $y = 0$ $x = 600$ It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obtain an approximative area of the shape by adding up areas of many rectangles in the shape as shown in the following figure: $f(x) = x^2$ The approximative area $s$ where the width of the rectangles is $d$ is: area of rectangle where its width is $d$ and height is $f(d)$ $+$ area of rectangle where its width is $d$ and height is $f(2d)$ $+$ area of rectangle where its width is $d$ and height is $f(3d)$ $+$ ... area of rectangle where its width is $d$ and height is $f(600 - d)$ The more we decrease $d$, the higer-precision value which is close to $72000000$ we could obtain. Your program should read the integer $d$ which is a divisor of $600$, and print the area $s$.
|
d = int(input())
print(sum(d * (i ** 2) for i in range(int(600/d))))
|
s866896829
|
Accepted
| 20
| 5,604
| 155
|
t = 0
while t == 0:
try:
d = int(input())
except:
break
else:
print(sum(d * ((i * d) ** 2) for i in range(int(600/d))))
|
s690246804
|
p03672
|
u385167811
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 299
|
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
|
s = str(input())
for i in range(len(s)):
s = s[:-1]
print(s)
if len(s) % 2 == 0:
flag = 0
for j in range(int(len(s)/2)):
if s[j] == s[j+int((len(s)/2))]:
flag += 1
if flag == (int(len(s)/2)):
print(len(s))
break
|
s125105197
|
Accepted
| 19
| 3,060
| 286
|
s = str(input())
for i in range(len(s)):
s = s[:-1]
if len(s) % 2 == 0:
flag = 0
for j in range(int(len(s)/2)):
if s[j] == s[j+int((len(s)/2))]:
flag += 1
if flag == (int(len(s)/2)):
print(len(s))
break
|
s583375628
|
p02239
|
u027872723
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,740
| 919
|
Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
|
# -*- coding: utf_8 -*-
level = True
def debug(v):
if level:
print(v)
NOT_FOUND = 0
ENQUEUED = 1
FOUND = 2
def bfs(graph, status, results):
queue = []
queue.append(1)
while len(queue) != 0:
node = queue.pop(0)
status[node] = FOUND
d = results[node]
for edge in graph[node]:
if status[edge] != NOT_FOUND:
continue
status[edge] = ENQUEUED
queue.append(edge)
results[edge] = d + 1
return results
if __name__ == "__main__":
n = int(input())
status = [NOT_FOUND] * (n + 1)
results = [0] * (n + 1)
g = [[0]]
for i in range(n):
row = [int(x) for x in input().split()]
row.pop(0)
row.pop(0)
g.append(row)
bfs(g, status, results)
results.pop(0)
print(results)
for idx, v in enumerate(results):
print(idx + 1, v)
|
s604640856
|
Accepted
| 20
| 7,772
| 918
|
# -*- coding: utf_8 -*-
level = False
def debug(v):
if level:
print(v)
NOT_FOUND = 0
ENQUEUED = 1
FOUND = 2
def bfs(graph, status, results):
queue = []
queue.append(1)
while len(queue) != 0:
node = queue.pop(0)
status[node] = FOUND
d = results[node]
for edge in graph[node]:
if status[edge] != NOT_FOUND:
continue
status[edge] = ENQUEUED
queue.append(edge)
results[edge] = d + 1
return results
if __name__ == "__main__":
n = int(input())
status = [NOT_FOUND] * (n + 1)
results = [-1] * (n + 1)
results[1] = 0
g = [[0]]
for i in range(n):
row = [int(x) for x in input().split()]
row.pop(0)
row.pop(0)
g.append(row)
bfs(g, status, results)
results.pop(0)
for idx, v in enumerate(results):
print(idx + 1, v)
|
s438667513
|
p03448
|
u913812470
| 2,000
| 262,144
|
Wrong Answer
| 48
| 3,060
| 261
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
|
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for ai in range(a + 1):
for bi in range(b + 1):
for ci in range(c + 1):
if 500 == 500 * ai + 100 * bi + 50 *ci:
count += 1
print(count)
|
s613834125
|
Accepted
| 50
| 3,060
| 251
|
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for ai in range(a + 1):
for bi in range(b + 1):
for ci in range(c + 1):
if x == 500 * ai + 100 * bi + 50 *ci:
count += 1
print(count)
|
s409414688
|
p03470
|
u069868839
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 104
|
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=[]
for i in range(N):
D.append(input(int()))
set_D=set(D)
ans=len(set_D)
print(ans)
|
s030479894
|
Accepted
| 21
| 3,316
| 104
|
N=int(input())
D=[]
for i in range(N):
D.append(int(input()))
set_D=set(D)
ans=len(set_D)
print(ans)
|
s545887933
|
p03672
|
u177040005
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 362
|
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
|
def che(s):
lens = len(s)
if s[:lens//2] == s[lens//2:]:
TF = True
else:
TF = False
return TF
S = input()
TF = False
ind = 0
if len(S)%2 == 1:
S2 = S[:-2]
else:
S2 = S[:-2]
print(S2)
while True:
TF = che(S2)
if TF == False:
S2 = S2[:-2]
else:
ans = len(S2)
print(ans)
exit()
|
s304253496
|
Accepted
| 17
| 3,060
| 351
|
def che(s):
lens = len(s)
if s[:lens//2] == s[lens//2:]:
TF = True
else:
TF = False
return TF
S = input()
TF = False
ind = 0
if len(S)%2 == 1:
S2 = S[:-2]
else:
S2 = S[:-2]
while True:
TF = che(S2)
if TF == False:
S2 = S2[:-2]
else:
ans = len(S2)
print(ans)
exit()
|
s980249441
|
p02616
|
u173148629
| 2,000
| 1,048,576
|
Wrong Answer
| 137
| 31,668
| 525
|
Given are N integers A_1,\ldots,A_N. We will choose exactly K of these elements. Find the maximum possible product of the chosen elements. Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).
|
N,K=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7
if N==K:
ans=1
for i in range(N):
ans*=A[i]
ans%=mod
print(ans)
exit()
if max(A)<0 and K%2==1:
A.sort(reverse=True)
ans=1
for i in range(K):
ans*=A[i]
ans%=mod
print(ans)
exit()
plus=[]
minus=[]
for i in range(N):
if A[i]>=0:
plus.append(A[i])
else:
minus.append(A[i])
plus.sort(reverse=True) #5,3,1
minus.sort() #-5,-3,-1
|
s124531704
|
Accepted
| 208
| 31,772
| 1,202
|
N,K=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7
if N==K:
ans=1
for i in range(N):
ans*=A[i]
ans%=mod
print(ans)
exit()
if max(A)<0 and K%2==1:
A.sort(reverse=True)
ans=1
for i in range(K):
ans*=A[i]
ans%=mod
print(ans)
exit()
plus=[]
minus=[]
for i in range(N):
if A[i]>=0:
plus.append(A[i])
else:
minus.append(A[i])
plus.sort(reverse=True) #5,3,1
minus.sort() #-5,-3,-1
plus_k=0
minus_k=0
if K%2==0:
ans=1
else:
ans=plus[0]
plus_k=1
for _ in range(K):
if plus_k+minus_k==K:
break
if plus_k>=len(plus)-1:
ans*=minus[minus_k]*minus[minus_k+1]%mod
ans%=mod
minus_k+=2
continue
if minus_k>=len(minus)-1:
ans*=plus[plus_k]*plus[plus_k+1]%mod
ans%=mod
plus_k+=2
continue
if plus[plus_k]*plus[plus_k+1]>minus[minus_k]*minus[minus_k+1]:
ans*=plus[plus_k]*plus[plus_k+1]%mod
ans%=mod
plus_k+=2
continue
else:
ans*=minus[minus_k]*minus[minus_k+1]%mod
ans%=mod
minus_k+=2
continue
print(ans)
|
s896389893
|
p03502
|
u536034761
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 73
|
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
|
N = int(input())
print("Yes" if sum(map(int, str(N))) % N == 0 else "No")
|
s618734793
|
Accepted
| 18
| 2,940
| 74
|
N = int(input())
print("Yes" if N % sum(map(int, str(N))) == 0 else "No")
|
s133514121
|
p03433
|
u147808483
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 93
|
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
N=int(input())
A=int(input())
if((N-A)%500==0 or N<=A):
print("Yes")
else:
print("No")
|
s751850107
|
Accepted
| 17
| 2,940
| 81
|
N=int(input())
A=int(input())
if(N%500<=A):
print("Yes")
else:
print("No")
|
s589392497
|
p02692
|
u785578220
| 2,000
| 1,048,576
|
Wrong Answer
| 21
| 9,004
| 11
|
There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
|
print('No')
|
s304168100
|
Accepted
| 274
| 109,964
| 1,134
|
import sys
sys.setrecursionlimit(10**6)
N,A,B,C = map(int,input().split())
Q = []
ans = []
f = 0
def dfs(f,a,b,c):
if f == N:return True
if Q[f] == 'AB':
if a+b == 0:return False
if b>0 and dfs(f+1,a+1,b-1,c):
ans.append('A')
return True
if a>0 and dfs(f+1,a-1,b+1,c):
ans.append('B')
return True
return False
if Q[f] == 'BC':
if c+b == 0:return False
if c>0 and dfs(f+1,a,b+1,c-1):
ans.append('B')
return True
if b>0 and dfs(f+1,a,b-1,c+1):
ans.append('C')
return True
return False
if Q[f] == 'AC':
if a+c == 0:return False
if c>0 and dfs(f+1,a+1,b,c-1):
ans.append('A')
return True
if a>0 and dfs(f+1,a-1,b,c+1):
ans.append('C')
return True
return False
for i in range(N):
s = input()
Q.append(s)
dfs(0,A,B,C)
# print(ans)
if len(ans) == N:
print('Yes')
ans = ans[::-1]
for i in ans:
print(i)
else:
print('No')
|
s046252440
|
p03251
|
u636235110
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 3,060
| 341
|
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.
|
def main():
n, m, x, y = list(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)
zx = max(x_list) + 1
zy = min(y_list)
if zx > zy :
print('War')
print('No war')
if __name__ == '__main__':
main()
|
s445270321
|
Accepted
| 17
| 3,060
| 354
|
def main():
n, m, x, y = list(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)
zx = max(x_list) + 1
zy = min(y_list)
if zx > zy :
print('War')
else:
print('No War')
if __name__ == '__main__':
main()
|
s086401790
|
p03486
|
u275488119
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 306
|
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
import sys
s=input()
t=input()
sn=[ord(s[i]) for i in range(len(s))]
tn=[ord(t[i]) for i in range(len(t))]
sn.sort()
tn.sort()
for i in range(min(len(tn), len(sn))):
if tn[i] > sn[i]:
print('Yes')
sys.exit()
elif tn[i] < sn[i]:
print('No')
sys.exit()
print('Yes')
|
s129150490
|
Accepted
| 17
| 3,064
| 367
|
import sys
s=input()
t=input()
sn=[ord(s[i]) for i in range(len(s))]
tn=[ord(t[i]) for i in range(len(t))]
sn.sort()
tn.sort(reverse=True)
for i in range(min(len(tn), len(sn))):
if tn[i] > sn[i]:
print('Yes')
sys.exit()
elif tn[i] < sn[i]:
print('No')
sys.exit()
if len(tn) > len(sn):
print('Yes')
else:
print('No')
|
s438272932
|
p03760
|
u450145303
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 174
|
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
|
o = input()
e = input()
for i,a in enumerate(o):
for j,b in enumerate(e):
if(i == j):
print(a + b, end = '')
if i == len(o) - 1:
print(a)
|
s926109358
|
Accepted
| 17
| 3,064
| 165
|
o = input()
e = input()
a = list(zip(range(0,len(o) * 2,2), list(o)))
b = list(zip(range(1,len(e) * 2,2),list(e)))
print(''.join(map(lambda x: x[1], sorted(a + b))))
|
s007435414
|
p03024
|
u368796742
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 8,976
| 49
|
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("YES" if input().count("x") >= 8 else "NO")
|
s842216908
|
Accepted
| 25
| 9,000
| 49
|
print("YES" if input().count("x") < 8 else "NO")
|
s063576092
|
p03359
|
u232374873
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 77
|
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
|
a, b = map(int,input().split())
if a >= b:
print(a-1)
else:
print(a)
|
s570729850
|
Accepted
| 38
| 3,060
| 76
|
a, b = map(int,input().split())
if a > b:
print(a-1)
else:
print(a)
|
s247530647
|
p04011
|
u595893956
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 92
|
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
n=int(input())
k=int(input())
a=int(input())
b=int(input())
print(min(n-k,k)*a+max(0,n-k)*b)
|
s954178365
|
Accepted
| 17
| 2,940
| 90
|
n=int(input())
k=int(input())
a=int(input())
b=int(input())
print(min(n,k)*a+max(0,n-k)*b)
|
s331822125
|
p03407
|
u284854859
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 103
|
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
|
# your code goes here
x,y,z = map(int,input().split())
if x + y <= z:
print('Yes')
else:
print('No')
|
s175918283
|
Accepted
| 17
| 2,940
| 103
|
# your code goes here
x,y,z = map(int,input().split())
if x + y >= z:
print('Yes')
else:
print('No')
|
s519754511
|
p03477
|
u690781906
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 167
|
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
a, b, c, d = map(int, input().split())
left = a + b
right = c + d
if left < right:
print('Left')
elif left > right:
print('Right')
else:
print('Balanced')
|
s574934725
|
Accepted
| 17
| 3,060
| 166
|
a, b, c, d = map(int, input().split())
left = a + b
right = c + d
if left > right:
print('Left')
elif left < right:
print('Right')
else:
print('Balanced')
|
s390481396
|
p03434
|
u514383727
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 283
|
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
|
n = int(input())
a = list(map(int, input().split()))
sorted(a, reverse=True)
alice = 0
bob = 0
flag_alice = True
for num in a:
print(num)
if flag_alice:
alice += num
flag_alice = False
else:
bob += num
flag_alice = True
print(alice - bob)
|
s145190192
|
Accepted
| 17
| 3,060
| 264
|
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = 0
bob = 0
flag_alice = True
for num in a:
if flag_alice:
alice += num
flag_alice = False
else:
bob += num
flag_alice = True
print(alice - bob)
|
s963561070
|
p02928
|
u474925961
| 2,000
| 1,048,576
|
Wrong Answer
| 1,653
| 3,188
| 385
|
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
|
import sys
if sys.platform =='ios':
sys.stdin=open('input_file.txt')
N,K=map(int,input().split())
l=list(map(int,input().split()))
cnt=0
cntt=0
p=10**9+7
for i in range(N):
for j in range(N):
if l[i]>l[j] and j>i:
cnt+=1
for k in range(N):
for m in range(N):
if l[k]>l[m] and k>m:
cntt+=1
Cn=cntt*int((K-1)*K/2)%p+int(K*(K+1)/2)*cnt%p
print(cnt,cntt)
print(Cn%p)
|
s624318863
|
Accepted
| 1,557
| 3,188
| 358
|
import sys
if sys.platform =='ios':
sys.stdin=open('input_file.txt')
N,K=map(int,input().split())
l=list(map(int,input().split()))
cnt=0
cnt2=0
p=10**9+7
for i in range(N):
for j in range(N):
if l[i]>l[j] and j>i:
cnt+=1
for k in range(N):
for m in range(N):
if l[k]>l[m] and k>m:
cnt2+=1
Cn=K*(K+1)//2*cnt+(K-1)*K//2*cnt2
print(Cn%p)
|
s459642033
|
p02612
|
u457921547
| 2,000
| 1,048,576
|
Wrong Answer
| 32
| 9,104
| 64
|
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.
|
# -*- coding: utf-8 -*-
a = int(input())
b = a % 1000
print(b)
|
s804032437
|
Accepted
| 32
| 9,152
| 119
|
# -*- coding: utf-8 -*-
a = int(input())
b = a // 1000
if a % 1000 == 0:
print(0)
else:
print(1000*(b+1) - a)
|
s815709237
|
p03063
|
u884982181
| 2,000
| 1,048,576
|
Wrong Answer
| 81
| 3,560
| 448
|
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.
|
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
s = input().rsplit()[0]
print(s)
kuro = 0
siro = 0
ans = 0
syo = 0
while syo < n and s[syo] == ".":
syo += 1
for i in range(syo,n):
if s[i] == "#":
if siro:
ans += min(siro,kuro)
siro = 0
kuro = 1
else:
kuro += 1
else:
siro += 1
ans += min(siro,kuro)
print(ans)
|
s789935908
|
Accepted
| 284
| 21,188
| 406
|
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
s = input().rsplit()[0]
kuro = [0]*n
siro = [0]*n
for i in range(n):
if s[i] == "#":
siro[i]+=1
if s[-i-1] == ".":
kuro[-i-1] += 1
siro[i] += siro[i-1]
kuro[-i-1] += kuro[-i]
ans = min(kuro[0],siro[-1])
for i in range(1,n):
ans = min(ans,siro[i-1]+kuro[i])
print(ans)
|
s597338557
|
p03660
|
u201234972
| 2,000
| 262,144
|
Wrong Answer
| 2,105
| 23,092
| 797
|
Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
|
from collections import deque
from copy import deepcopy
N = int( input())
Path = [ [] for _ in range(N)]
for _ in range(N-1):
a, b = map( int, input().split())
a, b = a-1, b-1
Path[a].append(b)
Path[b].append(a)
Mass = [-1 for _ in range(N)]
F = deque([0])
S = deque([N-1])
while len(F) != 0 or len(S) != 0:
KF = deque([])
while len(F) != 0:
f = F.pop()
for x in Path[f]:
if Mass[x] == -1:
Mass[x] = 1
KF.append(x)
F = deepcopy(KF)
KS = deque([])
while len(S) != 0:
s = S.pop()
for y in Path[s]:
if Mass[y] == -1:
Mass[y] = 0
KS.append(y)
KF = deepcopy(KS)
print(Mass)
if sum(Mass) >= N//2+1:
print('Fennec')
else:
print('Snuke')
|
s537099838
|
Accepted
| 1,790
| 22,644
| 785
|
from collections import deque
from copy import deepcopy
N = int( input())
Path = [ [] for _ in range(N)]
for _ in range(N-1):
a, b = map( int, input().split())
a, b = a-1, b-1
Path[a].append(b)
Path[b].append(a)
Mass = [-1 for _ in range(N)]
F = deque([0])
S = deque([N-1])
while len(F) != 0 or len(S) != 0:
KF = deque([])
while len(F) != 0:
f = F.pop()
for x in Path[f]:
if Mass[x] == -1:
Mass[x] = 1
KF.append(x)
F = deepcopy(KF)
KS = deque([])
while len(S) != 0:
s = S.pop()
for y in Path[s]:
if Mass[y] == -1:
Mass[y] = 0
KS.append(y)
S = deepcopy(KS)
if sum(Mass) >= N//2+1:
print('Fennec')
else:
print('Snuke')
|
s433373320
|
p02402
|
u801346721
| 1,000
| 131,072
|
Wrong Answer
| 40
| 7,540
| 208
|
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
|
n = int(input())
a = list(map(int, input().split()))
sum = 0
min = a[0]
max = a[0]
for i in range(1, n):
if a[i] < min:
min = a[i]
elif a[i] > max:
max = a[i]
sum += a[i]
print(min, max, sum)
|
s768048789
|
Accepted
| 40
| 8,552
| 209
|
n = int(input())
a = list(map(int, input().split()))
sum = a[0]
min = a[0]
max = a[0]
for i in range(1, n):
if a[i] < min:
min = a[i]
if a[i] > max:
max = a[i]
sum += a[i]
print(min, max, sum)
|
s733401753
|
p03214
|
u227085629
| 2,525
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 178
|
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
|
n = int(input())
a = list(map(int,input().split()))
avg = sum(a)/n
mi = sum(a)
ans = 0
for i in range(n):
if mi > abs(avg-a[i]):
mi = abs(avg-a[i])
ans = i+1
print(ans)
|
s284046047
|
Accepted
| 17
| 3,060
| 177
|
n = int(input())
a = list(map(int,input().split()))
avg = sum(a)/n
mi = sum(a)
ans = 0
for i in range(n):
if mi > abs(avg-a[i]):
mi = abs(avg-a[i])
ans = i
print(ans)
|
s539776269
|
p03377
|
u740284863
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 86
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a,b,c = map(int,input().split())
if (c-a) > b:
print("No")
else:
print("Yes")
|
s666445869
|
Accepted
| 17
| 2,940
| 110
|
A,B,X = map(int,input().split())
if A > X:
print("NO")
elif B >= X - A:
print("YES")
else:
print("NO")
|
s410823430
|
p03738
|
u729707098
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 290
|
You are given two positive integers A and B. Compare the magnitudes of these numbers.
|
a = input()
b = input()
if len(a)-1<len(b):
print("LESS")
elif len(a)-1>len(b):
print("GREATER")
else:
x = 0
for i in range(len(b)):
if int(a[i])<int(b[i]):
print("LESS")
x = 1
break
elif int(a[i])>int(b[i]):
print("GREATER")
x = 1
break
if x == 0: print("EQUAL")
|
s102530926
|
Accepted
| 17
| 2,940
| 103
|
a = int(input())
b = int(input())
if a>b: print("GREATER")
elif a<b: print("LESS")
else: print("EQUAL")
|
s757117756
|
p03434
|
u821425701
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 271
|
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
|
n = int(input())
card = list(map(int, input().split()))
alice = []
bob = []
for i in range(1, n):
val = max(card)
del card[card.index(val)]
if i % 2 == 1:
alice.append(val)
else:
bob.append(val)
diff = sum(alice) - sum(bob)
print(diff)
|
s158141158
|
Accepted
| 21
| 3,316
| 273
|
n = int(input())
card = list(map(int, input().split()))
alice = []
bob = []
for i in range(1, n+1):
val = max(card)
del card[card.index(val)]
if i % 2 == 1:
alice.append(val)
else:
bob.append(val)
diff = sum(alice) - sum(bob)
print(diff)
|
s692922835
|
p02608
|
u903082918
| 2,000
| 1,048,576
|
Wrong Answer
| 2,206
| 9,472
| 1,141
|
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).
|
import sys
import math
from functools import reduce
from bisect import bisect_left
def readString():
return sys.stdin.readline()
def readInteger():
return int(readString())
def readStringSet(n):
return sys.stdin.readline().split(" ")[:n]
def readIntegerSet(n):
return list(map(int, readStringSet(n)))
def readIntegerMatrix(n, m):
return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])
def main(N):
for n in range(1, N+1):
count = 0
maxi = int(math.sqrt(N))
x = 1
for x in range(1, maxi):
for y in range(1, maxi):
a = n - pow(x, 2) - pow(y, 2) - x * y
z = 0
for z in range(1, maxi):
if pow(z, 2) + (x+y)*z == a:
count += 1
z += 1
y += 1
x += 1
print(n, count)
if __name__ == "__main__":
_N = readInteger()
main(_N)
|
s480227591
|
Accepted
| 1,028
| 12,136
| 1,062
|
import sys
import math
from functools import reduce
from bisect import bisect_left
def readString():
return sys.stdin.readline()
def readInteger():
return int(readString())
def readStringSet(n):
return sys.stdin.readline().split(" ")[:n]
def readIntegerSet(n):
return list(map(int, readStringSet(n)))
def readIntegerMatrix(n, m):
return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])
def main(N):
maxi = int(math.sqrt(N))
result = dict()
for x in range(1, maxi+1):
for y in range(1, maxi+1):
for z in range(1, maxi+1):
n = pow(x, 2) + pow(y, 2) + pow(z, 2) + x*y + y*z + z*x
if n not in result.keys():
result[n] = 1
else:
result[n] += 1
for n in range(1, N+1):
if n in result.keys():
print(result[n])
else:
print(0)
if __name__ == "__main__":
_N = readInteger()
main(_N)
|
s864608808
|
p02401
|
u313089641
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,644
| 187
|
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
import math
x = input().split()
n1 = float((x[0]))
n2 = float(x[2])
op = str(x[1])
try:
result = eval("{} {} {}".format(n1, op, n2))
print(math.floor(result))
except:
pass
|
s998410560
|
Accepted
| 20
| 5,548
| 95
|
while True:
x = input()
if "?" in x: break
result = eval(x)
print(int(result))
|
s917233535
|
p02414
|
u352203480
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,592
| 414
|
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
|
n, m, l = map(int, input().split())
mat_a = []
mat_b = []
for i in range(n):
mat_a.append(list(map(int, input().split())))
for j in range(m):
mat_b.append(list(map(int, input().split())))
for p in range(n):
sum = 0
mat_c = []
for q in range(l):
for r in range(m):
sum += mat_a[p][r] * mat_b[r][q]
mat_c.append(sum)
print(' '.join(map(str, mat_c)))
|
s071825188
|
Accepted
| 380
| 6,312
| 418
|
n, m, l = map(int, input().split())
mat_a = []
mat_b = []
for i in range(n):
mat_a.append(list(map(int, input().split())))
for j in range(m):
mat_b.append(list(map(int, input().split())))
for p in range(n):
mat_c = []
for q in range(l):
sum = 0
for r in range(m):
sum += mat_a[p][r] * mat_b[r][q]
mat_c.append(sum)
print(' '.join(map(str, mat_c)))
|
s865126141
|
p03644
|
u667694979
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 231
|
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
N=int(input())
count=0
max=0
max_number=1
if N==1:
print(1)
for i in range(1,N+1):
while i>=1:
if i%2==0:
i=i//2
count+=1
else:
break
if count>=max:
max=count
max_number=1
print(max_number)
|
s380077349
|
Accepted
| 20
| 3,188
| 62
|
import math
n=int(input())
print(2**math.floor(math.log2(n)))
|
s594613202
|
p03828
|
u156314159
| 2,000
| 262,144
|
Wrong Answer
| 39
| 3,316
| 555
|
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
# C - Factors of Factorial
N = int(input())
n = 1
for i in range(2, N + 1):
n = n * i
def get_prime_factor(n):
from collections import defaultdict
res = defaultdict(int)
for i in range(2, n + 1):
if i * i > n:
break
while n % i == 0:
res[i] = res[i] + 1
n = n // i
if n != 1:
res[n] = 1
return res
prime_factor = get_prime_factor(n)
# WIP
|
s695454468
|
Accepted
| 38
| 3,316
| 623
|
# C - Factors of Factorial
N = int(input())
n = 1
for i in range(2, N + 1):
n = n * i
def get_prime_factor(n):
from collections import defaultdict
res = defaultdict(int)
for i in range(2, n + 1):
if i * i > n:
break
while n % i == 0:
res[i] = res[i] + 1
n = n // i
if n != 1:
res[n] = 1
return res
prime_factor = get_prime_factor(n)
factors_count = 1
for count in prime_factor.values():
factors_count = factors_count * (count + 1)
res = factors_count % (10 ** 9 + 7)
print(res)
|
s513290145
|
p02388
|
u103382858
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,456
| 20
|
Write a program which calculates the cube of a given integer x.
|
h1=input()
print(h1)
|
s820407107
|
Accepted
| 20
| 7,636
| 29
|
x = int(input())
print(x*x*x)
|
s047333819
|
p03644
|
u538956308
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,104
| 2,940
| 149
|
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
N = int(input())
while True:
for i in range(1,7):
b = 2^(7-i)
c = N%b
if c ==0:
break
else:
continue
break
print(b)
|
s660873115
|
Accepted
| 17
| 2,940
| 128
|
N = int(input())
while True:
for i in range(7):
b = 2**(6-i)
if b <= N:
break
break
print(b)
|
s385305848
|
p03860
|
u484412230
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 66
|
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
|
input = input()
input = input[8:]
input = input[:-7]
print(input)
|
s157535995
|
Accepted
| 17
| 2,940
| 81
|
input = input()
input = input[8:]
input = input[:-7]
print('A' + input[0] + 'C')
|
s387839852
|
p03352
|
u941884460
| 2,000
| 1,048,576
|
Wrong Answer
| 29
| 3,060
| 176
|
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
|
N=int(input())
result = [1]
for i in range(2,1001):
for j in range(1,11):
if pow(i,j) <= 1000 and pow(i,j) not in result:
result.append(pow(i,j))
print(max(result))
|
s115257134
|
Accepted
| 21
| 3,060
| 173
|
N=int(input())
result = [1]
for i in range(2,1001):
for j in range(2,11):
if pow(i,j) <= N and pow(i,j) not in result:
result.append(pow(i,j))
print(max(result))
|
s043641757
|
p03943
|
u619785253
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 212
|
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.
|
import itertools
a = list(map(int,(input().split(' '))))
c = list(itertools.combinations(a, 2))
#b = int(input())
#h = int(input())
#print(c)
a.sort()
if a[0]+a[1] == a[2]:
print('YES')
else :
print('NO')
|
s696412234
|
Accepted
| 17
| 3,060
| 213
|
import itertools
a = list(map(int,(input().split(' '))))
c = list(itertools.combinations(a, 2))
#b = int(input())
#h = int(input())
#print(c)
a.sort()
if a[0]+a[1] == a[2]:
print('Yes')
else :
print('No')
|
s103741657
|
p02842
|
u996564551
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 100
|
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())
X = int(-(-N//1.08))
print(X)
if N == int(X * 1.08):
print(X)
else:
print(':(')
|
s841125092
|
Accepted
| 17
| 2,940
| 91
|
N = int(input())
X = int(-(-N//1.08))
if N == int(X * 1.08):
print(X)
else:
print(':(')
|
s227788727
|
p03455
|
u715329136
| 2,000
| 262,144
|
Wrong Answer
| 26
| 9,180
| 91
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
a = sum(list(map(int, input().split(' '))))
r = 'Even' if (a % 2 == 0) else 'Odd'
print(r)
|
s969493234
|
Accepted
| 24
| 9,000
| 102
|
a = list(map(int, input().split(' ')))
b = a[0] * a[1]
r = 'Even' if (b % 2 == 0) else 'Odd'
print(r)
|
s367561865
|
p02397
|
u276050131
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,556
| 143
|
Write a program which reads two integers x and y, and prints them in ascending order.
|
x,y = input().split()
x = int(x)
y = int(y)
i = 0
if x > y:
i = x
x = y
y = i
fmt = "{a} {b}"
s = fmt.format(a = x,b = y)
print(s)
|
s471189413
|
Accepted
| 50
| 7,788
| 305
|
i = 0
j = 0
lis = []
while True:
x,y = input().split()
x = int(x)
y = int(y)
if x > y:
i = x
x = y
y = i
if x == 0 and y == 0:
break
fmt = "{a} {b}"
s = fmt.format(a = x,b = y)
lis.append(s)
j += 1
for i in range(j):
print(lis[i])
|
s852370869
|
p03997
|
u764105813
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 73
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
S = (a+b)*h/2
print(S)
|
s937737393
|
Accepted
| 17
| 2,940
| 78
|
a = int(input())
b = int(input())
h = int(input())
S = (a+b)*h/2
print(int(S))
|
s764640753
|
p03449
|
u143492911
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 166
|
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
|
n=int(input())
a=[[int(i)for i in input().split()]for i in range(2)]
print(a)
ans=0
for i in range(n):
ans=max(ans,(sum(a[0][0:i+1])+sum(a[1][i:n])))
print(ans)
|
s478573119
|
Accepted
| 19
| 3,060
| 154
|
n=int(input())
a=[list(map(int,input().split()))for i in range(2)]
ans=[]
for i in range(n):
ans.append(sum(a[0][:i+1]+a[1][i:]))
print(max(ans))
|
s928320490
|
p03377
|
u432805419
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 119
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a = list(map(int,input().split()))
if a[0] <= a[2]:
print("No")
elif a[1] >= a[2]:
print("Yes")
else:
print("No")
|
s907141441
|
Accepted
| 17
| 2,940
| 126
|
a = list(map(int,input().split()))
if a[0] > a[2] :
print("NO")
elif a[2] - a[0] <= a[1]:
print("YES")
else:
print("NO")
|
s126588406
|
p03449
|
u609061751
| 2,000
| 262,144
|
Wrong Answer
| 151
| 12,432
| 345
|
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?
|
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A_1 = np.array([int(x) for x in input().split()])
A_2 = np.array([int(x) for x in input().split()])
A_1_sum = list(np.cumsum(A_1))
A_2_sum = [0] + list(np.cumsum(A_2))
ans = -(np.inf)
for i in range(N):
ans = max(ans, A_1_sum[0] + A_2_sum[-1] + A_2_sum[i])
print(ans)
|
s552557063
|
Accepted
| 148
| 12,432
| 346
|
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A_1 = np.array([int(x) for x in input().split()])
A_2 = np.array([int(x) for x in input().split()])
A_1_sum = list(np.cumsum(A_1))
A_2_sum = [0] + list(np.cumsum(A_2))
ans = -(np.inf)
for i in range(N):
ans = max(ans, A_1_sum[i] + A_2_sum[-1] - A_2_sum[i])
print(ans)
|
s511020428
|
p03999
|
u116002573
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 594
|
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
|
def main():
S = input()
memo = dict()
def helper(S, i):
# i is the starting index
if i == len(S): return [0, 1]
if i == len(S)-1: return [int(S[i]), 1]
if i not in memo:
memo[i] = [0, 0]
for j in range(i+1, len(S)+1):
if j not in memo:
memo[j] = helper(S, j)
memo[i][0] += int(S[i:j])*memo[j][1] + memo[j][0]
memo[i][1] += memo[j][1]
print(memo)
return memo[i]
return helper(S, 0)[0]
if __name__ == '__main__':
print(main())
|
s995569172
|
Accepted
| 17
| 3,064
| 595
|
def main():
S = input()
memo = dict()
def helper(S, i):
# i is the starting index
if i == len(S): return [0, 1]
if i == len(S)-1: return [int(S[i]), 1]
if i not in memo:
memo[i] = [0, 0]
for j in range(i+1, len(S)+1):
if j not in memo:
memo[j] = helper(S, j)
memo[i][0] += int(S[i:j])*memo[j][1] + memo[j][0]
memo[i][1] += memo[j][1]
# print(memo)
return memo[i]
return helper(S, 0)[0]
if __name__ == '__main__':
print(main())
|
s972637678
|
p03695
|
u785205215
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 711
|
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
|
n = int(input())
a = input().split()
a_int = sorted(list(map(int,a )))
print(a_int)
max_a = max(a_int)
col = [0,0,0,0,0,0,0,0]
all_col = 0
for i in range(len(a_int)):
if a_int[i] < 400:
col[0] += 1
elif a_int[i] < 800:
col[1] += 1
elif a_int[i] < 1200:
col[2] += 1
elif a_int[i] < 1600:
col[3] += 1
elif a_int[i] < 2000:
col[4] += 1
elif a_int[i] < 2400:
col[5] += 1
elif a_int[i] < 2800:
col[6] += 1
elif a_int[i] < 3200:
col[7] += 1
else:
all_col += 1
min_c = len(list(filter((lambda x: x > 0), col)))
max_c = min_c + all_col
if max_c > 8:
max_c -= max_c -8
print(str(min_c)+' ' +str(max_c))
|
s222951822
|
Accepted
| 19
| 3,060
| 428
|
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))
def main():
n = input()
a = readLine_int_list()
c = []
_c = []
for i in a:
rank = i//400
if rank > 7:
_c.append(rank)
else:
c.append(rank)
p = len(set(c))
print(max(1,p), p+len(_c))
if __name__ == "__main__":
main()
|
s267617995
|
p02618
|
u078349616
| 2,000
| 1,048,576
|
Wrong Answer
| 37
| 9,876
| 219
|
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
|
from random import randint
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = []
for i in range(D):
T.append(S[i].index(max(S[i])))
print(*T, sep="\n")
|
s628234347
|
Accepted
| 35
| 9,404
| 208
|
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = []
for i in range(D):
l = S[i].index(max(S[i]))
T.append(l+1)
print(*T, sep="\n")
|
s755063012
|
p02606
|
u969848070
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,132
| 102
|
How many multiples of d are there among the integers between L and R (inclusive)?
|
l, r, d = map(int, input().split())
a = 0
for i in range(l, r+1):
if i / d == 0:
a += 1
print(a)
|
s443182496
|
Accepted
| 26
| 9,152
| 103
|
l, r, d = map(int, input().split())
a = 0
for i in range(l, r+1):
if i % d == 0:
a += 1
print(a)
|
s914603404
|
p03457
|
u680004123
| 2,000
| 262,144
|
Wrong Answer
| 325
| 3,060
| 210
|
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.
|
# -*- coding:utf-8 -*-
n = int(input())
for i in range(n):
t, x, y = map(int, input().split())
if (x + y) > t or (x + y + t) % 2:
print("YES")
exit()
print("NO")
|
s662586817
|
Accepted
| 320
| 3,060
| 157
|
n = int(input())
for i in range(n):
t,x,y=map(int,input().split())
if (x + y) > t or (x + y + t) % 2:
print("No")
exit()
print("Yes")
|
s180659382
|
p03149
|
u811156202
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 394
|
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
|
str_input_list = input().rstrip().split(' ')
int_input_list = []
for a in str_input_list:
int_input_list.append(int(a))
print(int_input_list)
keyence_list = [1, 9, 7, 4]
print(keyence_list)
for a in range(4):
if keyence_list[a] in int_input_list:
keyence_list[a] = '*'
print(keyence_list)
if keyence_list == ['*', '*', '*', '*']:
print('YES')
else:
print('NO')
|
s656771155
|
Accepted
| 17
| 3,060
| 329
|
str_input_list = input().rstrip().split(' ')
int_input_list = []
for a in str_input_list:
int_input_list.append(int(a))
keyence_list = [1, 9, 7, 4]
for a in range(4):
if keyence_list[a] in int_input_list:
keyence_list[a] = '*'
if keyence_list == ['*', '*', '*', '*']:
print('YES')
else:
print('NO')
|
s025374113
|
p03377
|
u181215519
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 87
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
A, B, X = map( int, input().split() )
print( [ "No", "Yes" ][ X >= A and X <= A + B ] )
|
s301605812
|
Accepted
| 17
| 2,940
| 87
|
A, B, X = map( int, input().split() )
print( [ "NO", "YES" ][ X >= A and X <= A + B ] )
|
s478656336
|
p02613
|
u342563578
| 2,000
| 1,048,576
|
Wrong Answer
| 166
| 16,324
| 440
|
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
n = int(input())
p = []
for i in range(n):
a = input()
p.append(a)
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
if p[i] == 'AC':
ac += 1
elif p[i] == 'WA':
wa += 1
elif p[i] == 'TLE':
tle += 1
else:
re += 1
ans = 'AC X'
print(ans,str(ac), sep = ' ',)
ans = 'WA X'
print(ans,str(wa), sep = ' ')
ans = 'TLE X'
print(ans,str(tle), sep = ' ')
ans = 'RE X'
print(ans,str(re), sep = ' ')
|
s723547798
|
Accepted
| 166
| 16,320
| 440
|
n = int(input())
p = []
for i in range(n):
a = input()
p.append(a)
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
if p[i] == 'AC':
ac += 1
elif p[i] == 'WA':
wa += 1
elif p[i] == 'TLE':
tle += 1
else:
re += 1
ans = 'AC x'
print(ans,str(ac), sep = ' ',)
ans = 'WA x'
print(ans,str(wa), sep = ' ')
ans = 'TLE x'
print(ans,str(tle), sep = ' ')
ans = 'RE x'
print(ans,str(re), sep = ' ')
|
s742286356
|
p03401
|
u518556834
| 2,000
| 262,144
|
Wrong Answer
| 217
| 14,048
| 227
|
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
|
n = int(input())
a = list(map(int,input().split()))
a[:0] = [0]
a.append(0)
s = int()
for i in range(n+1):
s += abs(a[n]-a[n+1])
for j in range(1,n+1):
print(s-abs(a[n-1]-a[n])-abs(a[n]-a[n+1])+abs(a[n-1]-a[n+1]))
|
s956304351
|
Accepted
| 223
| 14,040
| 228
|
n = int(input())
a = list(map(int,input().split()))
a[:0] = [0]
a.append(0)
s = int()
for i in range(n+1):
s += abs(a[i]-a[i+1])
for j in range(1,n+1):
print(s-abs(a[j-1]-a[j])-abs(a[j]-a[j+1])+abs(a[j-1]-a[j+1]))
|
s246484112
|
p03386
|
u089032001
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 20,432
| 97
|
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
|
A, B, K = map(int, input().split())
for i in range(A, B+1):
if(A+K>=i or B-K>=i):
print(i)
|
s292329902
|
Accepted
| 17
| 3,060
| 158
|
A, B, K = map(int, input().split())
for i in range(A, A+K):
if(i>B):
break
print(i)
for i in range(B-K+1, B+1):
if(A+K>i):
continue
print(i)
|
s286233118
|
p03377
|
u629540524
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 97
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a, b, x = map(int, input().split())
if x > a and x-a <= b:
print('Yes')
else:
print('No')
|
s998426571
|
Accepted
| 17
| 2,940
| 98
|
a, b, x = map(int, input().split())
if x >= a and x-a <= b:
print('YES')
else:
print('NO')
|
s947275542
|
p03671
|
u298297089
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 55
|
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
|
a = list(map(int,input().split()))
print(sum(a)-min(a))
|
s363819605
|
Accepted
| 17
| 2,940
| 56
|
a,b,c= map(int, input().split())
print(a+b+c-max(a,b,c))
|
s871423109
|
p02646
|
u970523279
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 9,108
| 209
|
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
|
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('No')
else:
if abs(a - b) <= abs(v - w) * t:
print('Yes')
else:
print('No')
|
s149555881
|
Accepted
| 20
| 9,172
| 209
|
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('NO')
else:
if abs(a - b) <= abs(v - w) * t:
print('YES')
else:
print('NO')
|
s746832268
|
p02646
|
u193657135
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 9,192
| 212
|
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
|
A,V = map(int, input().split())
B,W = map(int, input().split())
T = int(input())
d = abs(A-B)
v = abs(V-W)
if v==0:
print("NO")
exit()
t = d/v
print(t)
if T >= t:
print("YES")
else:
print("NO")
|
s149957217
|
Accepted
| 19
| 9,188
| 199
|
A,V = map(int, input().split())
B,W = map(int, input().split())
T = int(input())
d = abs(A-B)
v = V-W
if v<=0:
print("NO")
exit()
t = d/v
if T >= t:
print("YES")
else:
print("NO")
|
s531099057
|
p03964
|
u593590006
| 2,000
| 262,144
|
Wrong Answer
| 21
| 3,064
| 575
|
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time. Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
|
#vote n times each time t:a
#print(199*2)
#62 398
# 231 23
from math import ceil
#print(231*18,23*18)
#4158 414
#print(4158*2/3 )
#print(4158+2772)
n=int(input())
a,b=map(int,input().split())
for i in range(1,n):
x,y=map(int,input().split())
if x>=a and y>=b:
a=x
b=y
continue
if x<a:
a1=ceil(a/x)
x=a1*x
y=a1*y
a=x
b=y
if y<b:
b1=ceil(b/y )
y=b1*y
x=x*b1
a=x
b=y
# print(a,b)
print(a+b)
|
s927765097
|
Accepted
| 21
| 3,064
| 418
|
n=int(input())
a,b=map(int,input().split())
for i in range(1,n):
x,y=map(int,input().split())
if x>=a and y>=b:
a=x
b=y
continue
mul1=-1
mul2=-1
if a%x!=0:
mul1=a//x +1
else:
mul1=a//x
if b%y==0:
mul2=b//y
else:
mul2=b//y+1
m=max(mul1,mul2)
# print(m,x,y)
a,b=x*m,y*m
# print(a,b,'gd')
print(a+b)
|
s807037878
|
p03730
|
u312078744
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 105
|
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())
B_C = B - C
if (B_C % A == 0):
print('YES')
else:
print('NO')
|
s005232009
|
Accepted
| 1,547
| 9,136
| 340
|
a, b, c = map(int, input().split())
# n*a /b >
if (a % 2 == 0 and b % 2 == 0 and c % 2 != 0):
print('NO')
elif (a % 2 == 0 and b % 2 != 0 and c % 2 == 0):
print('NO')
else:
count = 0
while count < 10 ** 7:
count += 1
if ((a * count) % b == c):
print('YES')
exit()
print('NO')
|
s705288229
|
p03486
|
u581603131
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,188
| 175
|
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
s = sorted(list(str(input())))
t = sorted(list(str(input())))
S = str()
T = str()
for i in s:
S += i
for k in range(1,len(T)):
T += t[-k]
print('Yes' if S<T else 'No')
|
s472408209
|
Accepted
| 18
| 2,940
| 75
|
s = sorted(input())
t = sorted(input())[::-1]
print('Yes' if s<t else 'No')
|
s632243531
|
p03565
|
u605853117
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 460
|
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
|
#
S = input()
T = input()
candidates = []
for i in range(len(S) - len(T) + 1):
yn = all(S[i + k] == "?" or S[i + k] == T[k] for k in range(len(T)))
if yn:
s = S[:i] + T + S[i + len(T) :]
candidates.append(s)
print(candidates)
if candidates:
candidates = ["".join("a" if c == "?" else c for c in s) for s in candidates]
print(min(candidates))
else:
print("UNRESTORABLE")
|
s341449251
|
Accepted
| 18
| 3,064
| 442
|
#
S = input()
T = input()
candidates = []
for i in range(len(S) - len(T) + 1):
yn = all(S[i + k] == "?" or S[i + k] == T[k] for k in range(len(T)))
if yn:
s = S[:i] + T + S[i + len(T) :]
candidates.append(s)
if candidates:
candidates = ["".join("a" if c == "?" else c for c in s) for s in candidates]
print(min(candidates))
else:
print("UNRESTORABLE")
|
s088301991
|
p03353
|
u863076295
| 2,000
| 1,048,576
|
Wrong Answer
| 25
| 3,188
| 616
|
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
|
x = input()
K = int(input())
s = []
for i in range(len(x)):
s.append(x[i])
s1 = list(map(ord,s))
#s1.sort()
#print(s1)
lst = []
for i in range(26):
lst.append(0)
for i in range(len(s1)):
lst[s1[i]-97] += 1
#print(lst)
c = 0
for i in range(len(lst)):
c+=lst[i]
print(c)
cnt = 0
if c>=K:
ans = ""
for i in range(len(lst)):
if lst[i]!=0:
for j in range(lst[i]):
#print(c,cnt)
#print(ans)
ans += chr(97 + i)
cnt += 1
if cnt == c:break
if cnt == c:break
print(ans[:len(ans)-1])
|
s799214028
|
Accepted
| 37
| 4,464
| 157
|
s = input()
K = int(input())
arr = set()
for i in range(len(s)):
for j in range(i+1,min(i+1+K,len(s)+1)):
arr.add(s[i:j])
print(sorted(arr)[K-1])
|
s826408897
|
p03798
|
u125205981
| 2,000
| 262,144
|
Wrong Answer
| 258
| 7,048
| 800
|
Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
|
import sys
def SorW(i):
if t[i] == 'S' and t[i - 1] == 'S':
if s[i] == 'o':
a = 'S'
else:
a = 'W'
elif t[i] == 'S' and t[i - 1] == 'W':
if s[i] == 'o':
a = 'W'
else:
a = 'S'
elif t[i] == 'W' and t[i - 1] == 'S':
if s[i] == 'o':
a = 'W'
else:
a = 'S'
else:
if s[i] == 'o':
a = 'S'
else:
a = 'W'
return a
N = int(input())
s = str(input())
for t in [['S', 'S'], ['S', 'W'], ['W', 'W'], ['W', 'S']]:
for i in range(1, N):
t.append(SorW(i))
if i == N - 1:
if t[0] == t[N - 1] and t[1] == SorW(0):
del t[N - 1]
print(t)
sys.exit()
print('-1')
|
s990740504
|
Accepted
| 225
| 6,516
| 795
|
import sys
def SorW(i):
if i == 0:
j = N - 1
else:
j = i - 1
if t[i] == 'S' and t[j] == 'S':
if s[i] == 'o':
a = 'S'
else:
a = 'W'
elif t[i] == 'S' and t[j] == 'W':
if s[i] == 'o':
a = 'W'
else:
a = 'S'
elif t[i] == 'W' and t[j] == 'W':
if s[i] == 'o':
a = 'S'
else:
a = 'W'
else:
if s[i] == 'o':
a = 'W'
else:
a = 'S'
return a
N = int(input())
s = str(input())
for t in [['S', 'S'], ['S', 'W'], ['W', 'W'], ['W', 'S']]:
for i in range(1, N):
t.append(SorW(i))
if t[0] == t[N] and t[1] == SorW(0):
del t[N]
print(''.join(t))
sys.exit()
print('-1')
|
s431453993
|
p03399
|
u724742135
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 176
|
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
|
from sys import stdin
data = [stdin.readline().rstrip().split() for _ in range(4)]
data = [[int(i) for i in l] for l in data]
print(min(data[0], data[1])+min(data[2], data[3]))
|
s038683201
|
Accepted
| 17
| 2,940
| 156
|
from sys import stdin
data = [stdin.readline().rstrip() for _ in range(4)]
data = [int(l) for l in data]
print(min(data[0], data[1])+min(data[2], data[3]))
|
s767910656
|
p03673
|
u773686010
| 2,000
| 262,144
|
Wrong Answer
| 70
| 26,732
| 270
|
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())
N_List = list(map(str,input().split()))
if N % 2 == 0:
ans = ''.join(reversed(N_List[1::2])) + ''.join(N_List[::2])
else:
ans = ''.join(reversed(N_List[::2])) + ''.join(N_List[1::2])
print(ans)
|
s992693404
|
Accepted
| 79
| 28,560
| 286
|
N = int(input())
N_List = list(map(str,input().split()))
if N % 2 == 0:
ans = ' '.join(reversed(N_List[1::2])) + ' ' + ' '.join(N_List[::2])
else:
ans = ' '.join(reversed(N_List[::2])) + ' ' + ' '.join(N_List[1::2])
print(ans)
|
s573562008
|
p02262
|
u724548524
| 6,000
| 131,072
|
Wrong Answer
| 19,170
| 9,844
| 603
|
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
|
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
def remove_n(g, n):
new_g = [e for e in g if e <= n]
g.clear()
g.extend(new_g)
del new_g
def insertionsort(a, n, g):
global c
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j + g] = a[j]
j = j - g
c += 1
a[j + g] = v
c = 0
g = [1, 3, 5, 9, 17, 33, 65][:: -1]
remove_n(g, n)
for i in range(len(g)):
insertionsort(a, n, g[i])
print(len(g))
print(" ".join(map(str, g)))
print(c)
for i in range(n):
print(a[i])
|
s680900783
|
Accepted
| 19,800
| 45,508
| 519
|
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
def insertionsort(a, n, g):
global c
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j + g] = a[j]
j = j - g
c += 1
a[j + g] = v
c = 0
g = [1]
while g[-1] * 3 + 1 < n:
g.append(g[-1] * 3 + 1)
g.reverse()
for i in range(len(g)):
insertionsort(a, n, g[i])
print(len(g))
print(" ".join(map(str, g)))
print(c)
for i in range(n):
print(a[i])
|
s392424759
|
p03609
|
u773686010
| 2,000
| 262,144
|
Wrong Answer
| 24
| 8,964
| 50
|
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
|
a,b = map(int,input().split())
print((a-b,0)[a>b])
|
s246438767
|
Accepted
| 27
| 8,992
| 50
|
a,b = map(int,input().split())
print((a-b,0)[a<b])
|
s255101646
|
p03545
|
u782330257
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 471
|
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.
|
# cook your dish here
# from math import *
#for _ in range(int(input().strip())):
order=['+++','++-','+-+','+--','-++','-+-','--+','---']
s=input()
flag=-1
for i in range(8):
ans=int(s[0])
for j in range(1,len(s)):
if order[i][j-1]=='+':
ans+=(int(s[j]))
else:
ans-=(int(s[j]))
if ans==7:
flag=i
#print(flag)
if flag>-1:
for i in range(3):
print(s[i],order[flag][i],sep="",end="")
print(s[3])
|
s649330358
|
Accepted
| 17
| 3,064
| 483
|
# cook your dish here
# from math import *
#for _ in range(int(input().strip())):
order=['+++','++-','+-+','+--','-++','-+-','--+','---']
s=input()
flag=-1
for i in range(8):
ans=int(s[0])
for j in range(1,len(s)):
if order[i][j-1]=='+':
ans+=(int(s[j]))
else:
ans-=(int(s[j]))
if ans==7:
flag=i
#print(flag)
if flag>-1:
for i in range(3):
print(s[i],order[flag][i],sep="",end="")
print(s[3],"=7",sep="")
|
s155163696
|
p03170
|
u353797797
| 2,000
| 1,048,576
|
Wrong Answer
| 129
| 6,768
| 258
|
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other. Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro: * Choose an element x in A, and remove exactly x stones from the pile. A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
|
n, k = map(int, input().split())
a_s = list(map(int, input().split()))
dp = ["Second"] * (k + 1)
for i in range(k + 1):
if dp[i] == "Second":
for a in a_s:
ii = i + a
if ii <= k:
dp[ii] = "First"
print(dp)
|
s247888213
|
Accepted
| 112
| 3,828
| 275
|
n, k = map(int, input().split())
a_s = list(map(int, input().split()))
dp = [0] * (k + 1)
for i in range(k + 1):
if dp[i] == 0:
for a in a_s:
ii = i + a
if ii > k: break
dp[ii] = 1
print("First") if dp[-1] else print("Second")
|
s814711177
|
p02409
|
u914146430
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,648
| 284
|
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
|
n=int(input())
nyukyo=[list(map(int, input().split())) for i in range(n)]
bld=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for ny in nyukyo:
bld[ny[0]-1][ny[1]-1][ny[2]-1]+=ny[3]
for b in bld:
for f in b:
print(*f)
print("####################")
|
s425254636
|
Accepted
| 30
| 7,740
| 319
|
n=int(input())
nyukyo=[list(map(int, input().split())) for i in range(n)]
bld=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for ny in nyukyo:
bld[ny[0]-1][ny[1]-1][ny[2]-1]+=ny[3]
for i,b in enumerate(bld):
for f in b:
print("",*f)
if i != 3:
print("####################")
|
s860589888
|
p02275
|
u193453446
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,664
| 965
|
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in the output array B. This scheme must be modified to handle the situation in which several elements have the same value. Please see the following pseudocode for the detail: Counting-Sort(A, B, k) 1 for i = 0 to k 2 do C[i] = 0 3 for j = 1 to length[A] 4 do C[A[j]] = C[A[j]]+1 5 /* C[i] now contains the number of elements equal to i */ 6 for i = 1 to k 7 do C[i] = C[i] + C[i-1] 8 /* C[i] now contains the number of elements less than or equal to i */ 9 for j = length[A] downto 1 10 do B[C[A[j]]] = A[j] 11 C[A[j]] = C[A[j]]-1 Write a program which sorts elements of given array ascending order based on the counting sort.
|
def CountingSort(A, B, k, n):
C = [0 for i in range(k)]
for j in range(n):
C[A[j]] += 1
print("j:{} Aj:{} C[Aj]:{}".format(j,A[j], C[A[j]]))
for i in range(k):
print("\ti:{} Ci:{} Ci-1:{}".format(i,C[i], C[i-1]))
C[i] = C[i] + C[i-1]
for j in reversed(range(n)):
print("j:{} Aj:{} C[Aj]:{} k:{}".format(j,A[j], C[A[j]],k))
B[C[A[j]]] = A[j]
C[A[j]] -= 1
def main():
""" ????????? """
num = int(input().strip())
A = list(map(int,input().split()))
max = 0
for i in range(num):
if max < A[i]:
max = A[i]
if max < num:
max = num
max += 2
B = [0 for i in range(num + 2)]
CountingSort(A, B, max, num)
print(" ".join(map(str,B[1:num+1])))
if __name__ == '__main__':
main()
|
s988559094
|
Accepted
| 2,620
| 252,212
| 968
|
def CountingSort(A, B, k, n):
C = [0 for i in range(k)]
for j in range(n):
C[A[j]] += 1
for i in range(k):
# print("\ti:{} Ci:{} Ci-1:{}".format(i,C[i], C[i-1]))
C[i] = C[i] + C[i-1]
for j in reversed(range(n)):
B[C[A[j]]] = A[j]
C[A[j]] -= 1
def main():
""" ????????? """
num = int(input().strip())
A = list(map(int,input().split()))
max = 0
for i in range(num):
if max < A[i]:
max = A[i]
if max < num:
max = num
max += 2
B = [0 for i in range(num + 2)]
CountingSort(A, B, max, num)
print(" ".join(map(str,B[1:num+1])))
if __name__ == '__main__':
main()
|
s333161449
|
p03524
|
u576335153
| 2,000
| 262,144
|
Wrong Answer
| 43
| 9,072
| 198
|
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
|
s = input()
A = 0
B = 0
C = 0
for x in s:
if x == 'a':
A += 1
elif x == 'b':
B += 1
else:
C += 1
l = sorted([A, B, C])
print('YES' if l[2] == l[1] else 'NO')
|
s190521912
|
Accepted
| 40
| 9,080
| 260
|
s = input()
A = 0
B = 0
C = 0
for x in s:
if x == 'a':
A += 1
elif x == 'b':
B += 1
else:
C += 1
l = sorted([A, B, C])
print('YES' if (l[2] <= l[1] + 1 and l[0] == l[1]) or (l[2] == l[1] and l[0] == l[1] - 1) else 'NO')
|
s110170505
|
p03543
|
u119982147
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 122
|
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
|
N = list(str(input()))
N.sort()
if N[0] == N[3] or N[0] == N[3] or N[1] == N[3]:
print("YES")
else :
print("NO")
|
s052159082
|
Accepted
| 17
| 3,060
| 148
|
N = list(str(input()))
if N[0] ==N[1] == N[2] == N[3] or N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
print("Yes")
else :
print("No")
|
s332846880
|
p03457
|
u729217226
| 2,000
| 262,144
|
Wrong Answer
| 351
| 27,300
| 236
|
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())
cordinates = [list(map(int, input().split())) for i in range(N)]
for t, x, y in cordinates:
if (x+y) > t or (x+y+t):
print('No')
exit()
print('Yes')
|
s983826580
|
Accepted
| 356
| 27,300
| 249
|
N = int(input())
cordinates = [list(map(int, input().split())) for i in range(N)]
for t, x, y in cordinates:
if (x+y) > t or ((x+y) % 2 != t % 2):
print('No')
exit()
print('Yes')
|
s786939290
|
p03091
|
u270681687
| 2,000
| 1,048,576
|
Wrong Answer
| 462
| 21,936
| 1,299
|
You are given a simple connected undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Edge i connects Vertex a_i and b_i bidirectionally. Determine if three circuits (see Notes) can be formed using each of the edges exactly once.
|
n, m = map(int, input().split())
v = [0] * n
g = [[] for _ in range(n)]
for i in range(n):
a, b = map(int, input().split())
a -= 1
b -= 1
v[a] += 1
v[b] += 1
g[a].append(b)
g[b].append(a)
for i in range(n):
if v[i] % 2 == 1:
print("No")
exit()
v4 = 0
for i in range(n):
if v[i] >= 6:
print("Yes")
exit()
if v[i] == 4:
v4 += 1
if v4 == 0:
print("No")
exit()
if v4 == 1:
print("No")
exit()
if v4 >= 3:
print("Yes")
exit()
memo = [0] * n
ord = [0] * n
lowlink = [0] * n
articulation = [0] * n
def dfs(v, p, k):
memo[v] = 1
ord[v] = k
lowlink[v] = ord[v]
isArticulation = False
count = 0
for nv in g[v]:
if memo[v] == 0:
count += 1
dfs(nv, v, k+1)
lowlink[v] = min(lowlink[v], lowlink[nv])
if p != -1 and ord[v] <= lowlink[nv]:
isArticulation = True
elif nv != p:
lowlink[v] = min(lowlink[v], ord[nv])
if p == -1 and count > 1:
isArticulation = True
if isArticulation:
articulation[v] = 1
dfs(0, -1, 0)
count = 0
for i in range(n):
if v[i] == 4 and articulation[i] == 1:
count += 1
if count >= 2:
print("Yes")
else:
print("No")
|
s108327459
|
Accepted
| 822
| 86,064
| 1,340
|
import sys
sys.setrecursionlimit(10**7)
n, m = map(int, input().split())
v = [0] * n
g = [[] for _ in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
v[a] += 1
v[b] += 1
g[a].append(b)
g[b].append(a)
for i in range(n):
if v[i] % 2 == 1:
print("No")
exit()
v4 = 0
for i in range(n):
if v[i] >= 6:
print("Yes")
exit()
if v[i] == 4:
v4 += 1
if v4 == 0:
print("No")
exit()
if v4 == 1:
print("No")
exit()
if v4 >= 3:
print("Yes")
exit()
memo = [0] * n
ord = [0] * n
lowlink = [0] * n
articulation = [0] * n
def dfs(v, p, k):
memo[v] = 1
ord[v] = k
lowlink[v] = ord[v]
isArticulation = False
count = 0
for nv in g[v]:
if memo[nv] == 0:
count += 1
dfs(nv, v, k+1)
lowlink[v] = min(lowlink[v], lowlink[nv])
if p != -1 and ord[v] <= lowlink[nv]:
isArticulation = True
elif nv != p:
lowlink[v] = min(lowlink[v], ord[nv])
if p == -1 and count > 1:
isArticulation = True
if isArticulation:
articulation[v] = 1
dfs(0, -1, 0)
count = 0
for i in range(n):
if v[i] == 4 and articulation[i] == 1:
count += 1
if count >= 2:
print("Yes")
else:
print("No")
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.