output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s230411089 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | qq
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s543017586 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | A, B, C, D = map(int,input().split())
if A + B + C + D == 7;
print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A + B + C - D == 7;
print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A + B - C + D == 7;
print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A + B - C - D == 7;
print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A - B + C + D == 7;
print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A - B + C - D == 7;
print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A - B - C + D == 7;
print('{}-{}-{}+{}=7'.format(A, B, C, D))
elif A - B - C - D == 7;
print('{}-{}-{}-{}=7'.format(A, B, C, D)) | Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s923326547 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | abcd = int(input())
A,B,C,D = abcd[0],abcd[1],abcd[2]abcd[3]
if A + B + C + D == 7:
print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A + B + C - D == 7:
print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A + B - C + D == 7:
print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A + B - C - D == 7:
print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A - B + C + D == 7:
print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A - B + C - D == 7:
print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A - B - C + D == 7:
print('{}-{}-{}+{}=7'.format(A, B, C, D))
else:
print('{}-{}-{}-{}=7'.format(A, B, C, D))
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s282045384 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[-2])
d = int(abcd[-1])
if (a - b - c - d) == 7:
print(f"{a}-{b}-{c}-{d}=7")
exit()
if (a - b + c + d) == 7:
print(f"{a}-{b}+{c}+{d}=7")
exit()
if (a + b + c + d) == 7:
print(f"{a}-{b}-{c}-{d}=7")
exit()
if (a + b - c + d) == 7:
print(f"{a}-{b}-{c}-{d}=7")
exit()
if (a + b + c - d) == 7:
print(f"{a}-{b}-{c}-{d}=7")
exit()
if (a + b - c - d) == 7:
print(f"{a}-{b}-{c}-{d}=7")
exit()
if (a - b + c - d) == 7:
print(f"{a}-{b}-{c}-{d}=7")
exit()
if (a - b - c + d) == 7:
print(f"{a}-{b}-{c}-{d}=7")
exit()
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s962233213 | Accepted | p03545 | Input is given from Standard Input in the following format:
ABCD | A = str(input())
if int(A[0]) + int(A[1]) + int(A[2]) + int(A[3]) == 7: # +++
print("{}+{}+{}+{}=7".format(A[0], A[1], A[2], A[3]))
elif int(A[0]) + int(A[1]) + int(A[2]) - int(A[3]) == 7: # ++-
print("{}+{}+{}-{}=7".format(A[0], A[1], A[2], A[3]))
elif int(A[0]) + int(A[1]) - int(A[2]) + int(A[3]) == 7: # +-+
print("{}+{}-{}+{}=7".format(A[0], A[1], A[2], A[3]))
elif int(A[0]) + int(A[1]) - int(A[2]) - int(A[3]) == 7: # +--
print("{}+{}-{}-{}=7".format(A[0], A[1], A[2], A[3]))
elif int(A[0]) - int(A[1]) + int(A[2]) + int(A[3]) == 7: # -++
print("{}-{}+{}+{}=7".format(A[0], A[1], A[2], A[3]))
elif int(A[0]) - int(A[1]) + int(A[2]) - int(A[3]) == 7: # -+-
print("{}-{}+{}-{}=7".format(A[0], A[1], A[2], A[3]))
elif int(A[0]) - int(A[1]) - int(A[2]) + int(A[3]) == 7: # --+
print("{}-{}-{}+{}=7".format(A[0], A[1], A[2], A[3]))
elif int(A[0]) - int(A[1]) - int(A[2]) - int(A[3]) == 7: # ---
print("{}-{}-{}-{}=7".format(A[0], A[1], A[2], A[3]))
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s981924838 | Accepted | p03545 | Input is given from Standard Input in the following format:
ABCD | S = str(input())
ans = []
for i in [int(S[1]), -int(S[1])]:
for j in [int(S[2]), -int(S[2])]:
for k in [int(S[3]), -int(S[3])]:
if int(S[0]) == 7 - (i + j + k):
ans = [i, j, k]
sg = []
for a in ans:
if a < 0:
sg.append("-")
else:
sg.append("+")
ek = "".join([S[0], sg[0], S[1], sg[1], S[2], sg[2], S[3]])
print(ek + "=7")
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s592483764 | Wrong Answer | p03545 | Input is given from Standard Input in the following format:
ABCD | a, b, c, d = input()
kigou = ["+", "-"]
for i in range(8):
bin_str = str(format(i, "b").rjust(10, "0"))
soeji_01 = int(bin_str[-1])
soeji_02 = int(bin_str[-2])
soeji_03 = int(bin_str[-3])
shiki = "" + a + kigou[soeji_01] + b + kigou[soeji_02] + c + kigou[soeji_03] + d
if eval(shiki) == 7:
print(shiki + "=7")
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s669422884 | Accepted | p03545 | Input is given from Standard Input in the following format:
ABCD | # coding: utf-8
N = input()
N_list = list(map(int, N))
N_str = str(N)
if (N_list[0] + N_list[1] + N_list[2] + N_list[3]) == 7:
print(N_str[0] + "+" + N_str[1] + "+" + N_str[2] + "+" + N_str[3] + "=7")
elif (N_list[0] - N_list[1] + N_list[2] + N_list[3]) == 7:
print(N_str[0] + "-" + N_str[1] + "+" + N_str[2] + "+" + N_str[3] + "=7")
elif (N_list[0] - N_list[1] - N_list[2] + N_list[3]) == 7:
print(N_str[0] + "-" + N_str[1] + "-" + N_str[2] + "+" + N_str[3] + "=7")
elif (N_list[0] - N_list[1] - N_list[2] - N_list[3]) == 7:
print(N_str[0] + "-" + N_str[1] + "-" + N_str[2] + "-" + N_str[3] + "=7")
elif (N_list[0] + N_list[1] - N_list[2] + N_list[3]) == 7:
print(N_str[0] + "+" + N_str[1] + "-" + N_str[2] + "+" + N_str[3] + "=7")
elif (N_list[0] + N_list[1] - N_list[2] - N_list[3]) == 7:
print(N_str[0] + "+" + N_str[1] + "-" + N_str[2] + "-" + N_str[3] + "=7")
elif (N_list[0] + N_list[1] + N_list[2] - N_list[3]) == 7:
print(N_str[0] + "+" + N_str[1] + "+" + N_str[2] + "-" + N_str[3] + "=7")
elif (N_list[0] - N_list[1] + N_list[2] - N_list[3]) == 7:
print(N_str[0] + "-" + N_str[1] + "+" + N_str[2] + "-" + N_str[3] + "=7")
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s566274277 | Accepted | p03545 | Input is given from Standard Input in the following format:
ABCD | s = list(input())
d = 3
def operate1(string):
string += "-"
return string
def operate2(string):
string += "+"
return string
def bfs(list_hoge=[s[0]], depth=0, deepest=d):
queue = []
for e in list_hoge:
for b in [0, 1]:
if b == 0:
operated = operate1(e)
operated += s[depth + 1]
queue.append(operated)
elif b == 1:
operated = operate2(e)
operated += s[depth + 1]
queue.append(operated)
list_hoge = queue[:]
depth += 1
if depth == deepest:
return list_hoge
else:
return bfs(list_hoge, depth)
for e in bfs():
if eval(e) == 7:
print(e + "=7")
break
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s443141564 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | def check(operate_list, num_list):
res = num_list[0]
for i, op in enumerate(operate_list):
if op == "+":
res += num_list[i+1]
elif op == "-":
res -= num_list[i+1]
return res == 7
def concat(operate_list, num_list):
string = num_list[0]
for op, num in zip(operate_list, num_list[1:]):
# it is beautiful!
string += op
string =+ num
string += "="
return string
def main():
line = sys.stdin.readline().strip()
num_list = []
for s in line:
num_list.append(int(s))
result = ""
stack = []
stack.append([])
N = len(num_list)
while(len(stack) != 0){
l = stack.pop()
if len(l) == N-1:
if check(l, num_list):
result = concat(l, num_list)
break
else:
stack.append(l + ["+"]) # careful code
stack.append(l + ["-"])
}
print(result)
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s079811498 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | from math import ceil
def dfs(i, sum, count, residue):
global ans
if i == d:
if sum < g:
use = max(residue)
n = min(pc[use - 1][0], ceil((g - sum) / (use * 100)))
count += n
sum += n * use * 100
if g <= sum:
ans = min(ans, count)
else:
dfs(i + 1, sum, count, residue)
dfs(
i + 1,
sum + pc[i][0] * (i + 1) * 100 + pc[i][1],
count + pc[i][0],
residue - {i + 1},
)
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]
ans = float("inf")
dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s203814614 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | import sys, ast
def dfs(str_input,count = 1):
if count == 7: #演算子を挿入完了
if ast.literal_eval(str_input) == 7:
sys.exit(str_input + "=7")
else: #和が7にならなかった場合は何もしない
return 0
for i in ["+","-"]:
dfs(str_input[:count] + i + str_input[count:], count = count + 2) #演算子の挿入
x = input()
dfs(x) | Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s472324321 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | N = input()
answer = ""
for i in range(1 << 3):
exp = N[0]
for j in range(3):
if i >> j & 1:
exp += "+"
else:
exp += "-"
exp += N[j + 1]
if eval(exp) == 7:
answer = exp
break
print(answer + "=7")
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s641093617 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | a, b, c, d = list(input())
for q in range(1, 3):
ao = "+" if q % 2 else "-"
for w in range(1, 3):
bo = "+" if w % 2 else "-"
for e in range(1, 3):
if eval(a + ao + b + bo + c + ("+" if e % 2 else "-") + d) == 7:
print(f'{a}{ao}{b}{bo}{c}{("+" if e%2else"-")}{d}=7')
exit(0)
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print the formula you made, including the part `=7`.
Use the signs `+` and `-`.
Do not print a space between a digit and a sign.
* * * | s542579456 | Runtime Error | p03545 | Input is given from Standard Input in the following format:
ABCD | package main
import (
"fmt"
"strconv"
)
func main() {
var inputLine string
fmt.Scan(&inputLine)
runeS := []rune(inputLine)
var nums []int
for _, c := range runeS {
n, _ := strconv.Atoi(string(c))
nums = append(nums, n)
}
var temp int
var s string
for i := 0; i < (1 << uint(len(nums)-1)); i++ {
temp = nums[0]
s = strconv.Itoa(nums[0])
for j := 0; j < (len(nums) - 1); j++ {
if (i>>uint(j))&1 == 1 {
temp += nums[j+1]
s += "+" + strconv.Itoa(nums[j+1])
} else {
temp -= nums[j+1]
s += "-" + strconv.Itoa(nums[j+1])
}
}
if temp == 7 {
s += "=7"
fmt.Println(s)
break
}
}
}
| Statement
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. | [{"input": "1222", "output": "1+2+2+2=7\n \n\nThis is the only valid solution.\n\n* * *"}, {"input": "0290", "output": "0-2+9+0=7\n \n\n0 - 2 + 9 - 0 = 7 is also a valid solution.\n\n* * *"}, {"input": "3242", "output": "3+2+4-2=7"}] |
Print X.
* * * | s116194787 | Wrong Answer | p03115 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | X = list()
Y = list()
N = int(input())
for i in range(N):
x, y = map(int, input().split())
X.append(x)
Y.append(y)
print(abs(sum(X)) - abs(sum(Y)))
| Statement
There is an infinitely large triangular grid, as shown below. Each point with
integer coordinates contains a lamp.

Initially, only the lamp at (X, 0) was on, and all other lamps were off. Then,
Snuke performed the following operation zero or more times:
* Choose two integers x and y. Toggle (on to off, off to on) the following three lamps: (x, y), (x, y+1), (x+1, y).
After the operations, N lamps (x_1, y_1), \cdots, (x_N, y_N) are on, and all
other lamps are off. Find X. | [{"input": "4\n -2 1\n -2 2\n 0 1\n 1 0", "output": "-1\n \n\nThe following picture shows one possible sequence of operations:\n\n"}] |
Print X.
* * * | s567152909 | Runtime Error | p03115 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import sys
from collections import defaultdict
from heapq import heapify, heappop, heappush
def up(lights, y, l, r, ys):
ny = y + r - l
if l in lights[ny]:
lights[ny].remove(l)
else:
lights[ny].add(l)
heappush(ys, ny)
def move(lights):
new_lights = defaultdict(set)
for y, xs in lights.items():
for x in xs:
new_lights[-(x + y)].add(y)
lights = new_lights
ys = list(lights.keys())
heapify(ys)
prev_y = None
while ys:
y = heappop(ys)
if y == prev_y:
continue
xs = sorted(lights[y])
for l, r in zip(xs[::2], xs[1::2]):
f = l
while f < r:
d = 1
while f + d <= r:
d <<= 1
d >>= 1
up(lights, y, f, f + d, ys)
f += d + 1
lights[y].difference_update({l, r})
prev_y = y
return lights
n = int(input())
xys = [tuple(map(int, line.split())) for line in sys.stdin]
lights = defaultdict(set)
for x, y in xys:
lights[y].add(x)
lights = move(lights)
lights = move(lights)
lights = move(lights)
print(lights[0].pop())
| Statement
There is an infinitely large triangular grid, as shown below. Each point with
integer coordinates contains a lamp.

Initially, only the lamp at (X, 0) was on, and all other lamps were off. Then,
Snuke performed the following operation zero or more times:
* Choose two integers x and y. Toggle (on to off, off to on) the following three lamps: (x, y), (x, y+1), (x+1, y).
After the operations, N lamps (x_1, y_1), \cdots, (x_N, y_N) are on, and all
other lamps are off. Find X. | [{"input": "4\n -2 1\n -2 2\n 0 1\n 1 0", "output": "-1\n \n\nThe following picture shows one possible sequence of operations:\n\n"}] |
Output the minimum number of years before your wish will be fulfilled. | s556005266 | Wrong Answer | p00369 | The input is given in the following format.
n
An integer n is given. Its number of digits is from 2 to 100,000, and each
digit ranges from 1 to 9. | n = input()
length = len(n)
ans = 10
# 2桁,1桁混合
lst = []
ind = 0
while ind < length:
if n[ind] == "1" and ind + 1 <= length - 1:
lst.append(int(n[ind : ind + 2]))
ind += 2
else:
lst.append(int(n[ind]))
ind += 1
ans = min(ans, max(lst) - min(lst))
# n桁のみ
divisors = []
for i in range(1, length // 2 + 1):
if length % i == 0:
divisors.append(i)
for i in divisors:
lst = []
for j in range(0, length, i):
lst.append(int(n[j : j + i]))
ans = min(ans, max(lst) - min(lst))
print(ans)
| Paper Fortune
If you visit Aizu Akabeko shrine, you will find a unique paper fortune on
which a number with more than one digit is written.
Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad
omen in this shrine). Using this string of numeric values, you can predict how
many years it will take before your dream comes true. Cut up the string into
more than one segment and compare their values. The difference between the
largest and smallest value will give you the number of years before your wish
will be fulfilled. Therefore, the result varies depending on the way you cut
up the string. For example, if you are given a string 11121314 and divide it
into segments, say, as 1,11,21,3,14, then the difference between the largest
and smallest is 21 - 1 = 20. Another division 11,12,13,14 produces 3 (i.e. 14
- 11) years. Any random division produces a game of luck. However, you can
search the minimum number of years using a program.
Given a string of numerical characters, write a program to search the minimum
years before your wish will be fulfilled. | [{"input": "11121314", "output": "3"}, {"input": "123125129", "output": "6"}, {"input": "119138", "output": "5"}] |
Print the smallest sub-array size in a line. | s554195675 | Wrong Answer | p02354 | The input is given in the following format.
$N$ $S$
$a_1$ $a_2$ ... $a_N$ | n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = None
for window in range(1, n + 1):
sum_a = None
for i in range(n - window):
if sum_a == None:
sum_a = sum(a[i:window])
else:
sum_a += a[i + window - 1] - a[i - 1]
if sum_a >= s:
ans = window
break
if ans != None:
break
if ans == None:
ans = 0
print(ans)
| The Smallest Window I
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer
$S$, find the smallest sub-array size (smallest window length) where the sum
of the sub-array is greater than or equal to $S$. If there is not such sub-
array, report 0. | [{"input": "6 4\n 1 2 1 2 3 2", "output": "2"}, {"input": "6 6\n 1 2 1 2 3 2", "output": "3"}, {"input": "3 7\n 1 2 3", "output": "0"}] |
If there exists a matrix that satisfies the conditions, print one such matrix
in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
Note that any matrix satisfying the conditions is accepted.
If no matrix satisfies the conditions, print -1.
* * * | s254612647 | Wrong Answer | p02704 | Input is given from Standard Input in the following format:
N
S_{1} S_{2} ... S_{N}
T_{1} T_{2} ... T_{N}
U_{1} U_{2} ... U_{N}
V_{1} V_{2} ... V_{N} | s = input()
n = len(s)
ans = 0
now = 0
mp = [0 for i in range(2019)]
mp[0] += 1
tmp = [0 for i in range(2019)]
id = [0 for i in range(2019)]
for i in range(2019):
id[i] = i * 10 % 2019
for c in s:
now *= 10
now += ord(c) - ord("0")
now %= 2019
ans += mp[now]
mp[now] += 1
for i in range(2019):
tmp[id[i]] = mp[i]
for i in range(2019):
mp[i] = tmp[i]
print(ans)
| Statement
Given are an integer N and arrays S, T, U, and V, each of length N. Construct
an N×N matrix a that satisfy the following conditions:
* a_{i,j} is an integer.
* 0 \leq a_{i,j} \lt 2^{64}.
* If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
* If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
* If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
* If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.
However, there may be cases where no matrix satisfies the conditions. | [{"input": "2\n 0 1\n 1 0\n 1 1\n 1 0", "output": "1 1\n 1 0\n \n\nIn Sample Input 1, we need to find a matrix such that:\n\n * the bitwise AND of the elements in the 1-st row is 1;\n * the bitwise OR of the elements in the 2-nd row is 1;\n * the bitwise OR of the elements in the 1-st column is 1;\n * the bitwise AND of the elements in the 2-nd column is 0.\n\n* * *"}, {"input": "2\n 1 1\n 1 0\n 15 15\n 15 11", "output": "15 11\n 15 11"}] |
If there exists a matrix that satisfies the conditions, print one such matrix
in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
Note that any matrix satisfying the conditions is accepted.
If no matrix satisfies the conditions, print -1.
* * * | s838902618 | Runtime Error | p02704 | Input is given from Standard Input in the following format:
N
S_{1} S_{2} ... S_{N}
T_{1} T_{2} ... T_{N}
U_{1} U_{2} ... U_{N}
V_{1} V_{2} ... V_{N} | n = int(input())
assert n == 2
| Statement
Given are an integer N and arrays S, T, U, and V, each of length N. Construct
an N×N matrix a that satisfy the following conditions:
* a_{i,j} is an integer.
* 0 \leq a_{i,j} \lt 2^{64}.
* If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
* If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
* If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
* If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.
However, there may be cases where no matrix satisfies the conditions. | [{"input": "2\n 0 1\n 1 0\n 1 1\n 1 0", "output": "1 1\n 1 0\n \n\nIn Sample Input 1, we need to find a matrix such that:\n\n * the bitwise AND of the elements in the 1-st row is 1;\n * the bitwise OR of the elements in the 2-nd row is 1;\n * the bitwise OR of the elements in the 1-st column is 1;\n * the bitwise AND of the elements in the 2-nd column is 0.\n\n* * *"}, {"input": "2\n 1 1\n 1 0\n 15 15\n 15 11", "output": "15 11\n 15 11"}] |
If there exists a matrix that satisfies the conditions, print one such matrix
in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
Note that any matrix satisfying the conditions is accepted.
If no matrix satisfies the conditions, print -1.
* * * | s649553474 | Wrong Answer | p02704 | Input is given from Standard Input in the following format:
N
S_{1} S_{2} ... S_{N}
T_{1} T_{2} ... T_{N}
U_{1} U_{2} ... U_{N}
V_{1} V_{2} ... V_{N} | print("1")
| Statement
Given are an integer N and arrays S, T, U, and V, each of length N. Construct
an N×N matrix a that satisfy the following conditions:
* a_{i,j} is an integer.
* 0 \leq a_{i,j} \lt 2^{64}.
* If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
* If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
* If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
* If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.
However, there may be cases where no matrix satisfies the conditions. | [{"input": "2\n 0 1\n 1 0\n 1 1\n 1 0", "output": "1 1\n 1 0\n \n\nIn Sample Input 1, we need to find a matrix such that:\n\n * the bitwise AND of the elements in the 1-st row is 1;\n * the bitwise OR of the elements in the 2-nd row is 1;\n * the bitwise OR of the elements in the 1-st column is 1;\n * the bitwise AND of the elements in the 2-nd column is 0.\n\n* * *"}, {"input": "2\n 1 1\n 1 0\n 15 15\n 15 11", "output": "15 11\n 15 11"}] |
If there exists a matrix that satisfies the conditions, print one such matrix
in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
Note that any matrix satisfying the conditions is accepted.
If no matrix satisfies the conditions, print -1.
* * * | s219151168 | Runtime Error | p02704 | Input is given from Standard Input in the following format:
N
S_{1} S_{2} ... S_{N}
T_{1} T_{2} ... T_{N}
U_{1} U_{2} ... U_{N}
V_{1} V_{2} ... V_{N} | import numpy as np
from numba import njit
@njit
def main(N, S, T, U, V):
ans = np.zeros((N, N), dtype=np.int64)
possible = True
for n in range(64):
n = 2**n
n1 = 0
n2 = 0
S_ = np.zeros(N)
s_ = 0
T_ = np.zeros(N)
t_ = 0
i1 = -1
j1 = -1
i2 = -1
j2 = -1
for i in range(N):
s = S[i]
u = U[i] & n
if u > 0:
u = 1
for j in range(N):
t = T[j]
v = V[j] & n
if v > 0:
v = 1
if (s, u) == (0, 1):
if (t, v) != (1, 0):
ans[i][j] += n
else:
possible = False
break
elif (s, u) == (1, 0):
if (t, v) == (0, 1):
possible = False
break
elif (t, v) == (0, 1) or (t, v) == (1, 0):
ans[i][j] += v * n
elif (s, u) == (t, v):
ans[i][j] += u * n
elif (s, u) == (0, 0):
if n1 == 0:
i1 = i
j1 = j
else:
if i == i1 or j == j1:
ans[i][j] += n
n1 += 1
elif (s, u) == (1, 1):
if n2 == 0:
i2 = i
j2 = j
else:
if i == i2 or j == j2:
ans[i][j] += n
n2 += 1
if u * n == ans[i][j] & n:
if not S_[i]:
s_ += 1
S_[i] += 1
if v * n == ans[i][j] & n:
if not T_[j]:
t_ += 1
T_[j] += 1
if s_ != N:
ans[i2][j2] += n
m = n
for i in range(N):
m &= ans[i][j2]
if m & n:
possible = False
if t_ != N:
ans[i1][j1] += n
m = n
for j in range(N):
m &= ans[i1][j]
if m & n:
possible = False
if not possible:
break
return possible, ans
if __name__ == "__main__":
N = int(input())
S = np.array(list(map(int, input().split())))
T = np.array(list(map(int, input().split())))
U = np.array(list(map(int, input().split())))
V = np.array(list(map(int, input().split())))
possible, ans = main(N, S, T, U, V)
if possible:
for i in range(N):
print(*ans[i])
else:
print(-1)
| Statement
Given are an integer N and arrays S, T, U, and V, each of length N. Construct
an N×N matrix a that satisfy the following conditions:
* a_{i,j} is an integer.
* 0 \leq a_{i,j} \lt 2^{64}.
* If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
* If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
* If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
* If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.
However, there may be cases where no matrix satisfies the conditions. | [{"input": "2\n 0 1\n 1 0\n 1 1\n 1 0", "output": "1 1\n 1 0\n \n\nIn Sample Input 1, we need to find a matrix such that:\n\n * the bitwise AND of the elements in the 1-st row is 1;\n * the bitwise OR of the elements in the 2-nd row is 1;\n * the bitwise OR of the elements in the 1-st column is 1;\n * the bitwise AND of the elements in the 2-nd column is 0.\n\n* * *"}, {"input": "2\n 1 1\n 1 0\n 15 15\n 15 11", "output": "15 11\n 15 11"}] |
If there exists a matrix that satisfies the conditions, print one such matrix
in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
Note that any matrix satisfying the conditions is accepted.
If no matrix satisfies the conditions, print -1.
* * * | s865543804 | Wrong Answer | p02704 | Input is given from Standard Input in the following format:
N
S_{1} S_{2} ... S_{N}
T_{1} T_{2} ... T_{N}
U_{1} U_{2} ... U_{N}
V_{1} V_{2} ... V_{N} | N = int(input())
slist = list(map(int, input().split()))
tlist = list(map(int, input().split()))
ulist = list(map(int, input().split()))
vlist = list(map(int, input().split()))
max_digit = 4
amat = [[[-1] * max_digit for _ in range(N)] for _ in range(N)]
for i in range(N):
s = slist[i]
u = ulist[i]
if s == 0:
for k in range(max_digit):
u1 = u & 1
if u1 == 1:
for j in range(N):
amat[i][j][-1 - k] = 1
u >>= 1
else:
for k in range(max_digit):
u1 = u & 1
if u1 == 0:
for j in range(N):
amat[i][j][-1 - k] = 0
u >>= 1
t = tlist[i]
v = vlist[i]
if t == 0:
for k in range(max_digit):
v1 = v & 1
if v1 == 1:
for j in range(N):
amat[j][i][-1 - k] = 1
v >>= 1
else:
for k in range(max_digit):
v1 = v & 1
if v1 == 0:
for j in range(N):
amat[j][i][-1 - k] = 0
v >>= 1
for i in range(N):
for j in range(N):
u = ulist[i]
v = vlist[j]
for k in range(max_digit):
u1 = u & 1
v1 = v & 1
if u1 == v1:
amat[i][j][-1 - k] = u1
u >>= 1
v >>= 1
# print(amat)
for i in range(N):
for j in range(N):
s = slist[i]
t = tlist[j]
u = ulist[i]
v = vlist[j]
for k in range(max_digit):
u1 = u & 1
v1 = v & 1
if amat[i][j][-1 - k] == -1:
if s == 1 and u1 == 1:
if t == 0: # v1==0
amat[i][j][-1 - k] = 0
else:
amat[i][j][-1 - k] = 1
elif t == 1 and v1 == 1:
if s == 0: # u1==0
amat[i][j][-1 - k] = 0
else:
amat[i][j][-1 - k] = 1
# print(amat)
answer_mat = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(N):
ans = 0
base = 1
a = amat[i][j]
for k in range(max_digit):
ans += a[-1 - k] * base
base <<= 1
answer_mat[i][j] = ans
# print(answer_mat)
for i in range(N):
print(*answer_mat[i])
| Statement
Given are an integer N and arrays S, T, U, and V, each of length N. Construct
an N×N matrix a that satisfy the following conditions:
* a_{i,j} is an integer.
* 0 \leq a_{i,j} \lt 2^{64}.
* If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
* If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
* If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
* If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.
However, there may be cases where no matrix satisfies the conditions. | [{"input": "2\n 0 1\n 1 0\n 1 1\n 1 0", "output": "1 1\n 1 0\n \n\nIn Sample Input 1, we need to find a matrix such that:\n\n * the bitwise AND of the elements in the 1-st row is 1;\n * the bitwise OR of the elements in the 2-nd row is 1;\n * the bitwise OR of the elements in the 1-st column is 1;\n * the bitwise AND of the elements in the 2-nd column is 0.\n\n* * *"}, {"input": "2\n 1 1\n 1 0\n 15 15\n 15 11", "output": "15 11\n 15 11"}] |
Print the answer.
* * * | s254328096 | Accepted | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | from collections import deque, defaultdict, Counter
from itertools import accumulate
import bisect
from heapq import heappop, heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
# import numpy as np
# import sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
if not isinstance(n, int):
raise TypeError("n is not int")
if n < 2:
raise ValueError("n is not effective")
prime = [1] * (n + 1)
for i in range(2, int(math.sqrt(n)) + 1):
if prime[i] == 1:
for j in range(2 * i, n + 1):
if j % i == 0:
prime[j] = 0
res = []
for i in range(2, n + 1):
if prime[i] == 1:
res.append(i)
return res
def factorial(i):
if i == 1:
return 1
else:
return i * factorial(i - 1)
class UnionFind:
def __init__(self, n):
self.parent = [i for i in range(n + 1)]
self.rank = [0 for i in range(n + 1)]
def findroot(self, x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self, x, y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[py] = px
else:
self.parent[px] = py
def same_group_or_no(self, x, y):
return self.findroot(x) == self.findroot(y)
def main(): # startline-------------------------------------------
N = int(input())
A = map(int, input().split())
p = len(set(A))
if (N - p) % 2 == 0:
print(p)
else:
print(p - 1)
if __name__ == "__main__":
main() # endline===============================================
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s440343101 | Accepted | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | n = int(input())
a_i = list(map(int, input().split()))
duplicationCheckList = [0] * 10**5
duplicationMaisuu = 0
for x in a_i:
if duplicationCheckList[x - 1] == 1:
duplicationMaisuu += 1
else:
duplicationCheckList[x - 1] = 1
count = (duplicationMaisuu + 1) // 2
print(n - count * 2)
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s199836578 | Accepted | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | N = int(input())
tmp = list(map(int, input().split(" ")))
cards = {}
for c in tmp:
if c in cards.keys():
cards[c] += 1
else:
cards[c] = 1
lost = 0
for k, v in cards.items():
if v > 1 and v % 2 == 0:
if lost == 0:
lost += 1
else:
lost -= 1
print(len(cards.keys()) - lost)
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s433477696 | Accepted | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
def gcd_list(L):
v = L[0]
for i in range(1, len(L)):
v = gcd(v, L[i])
return v
def lcm(n, m):
return (n * m) // gcd(n, m)
def lcm_list(L):
v = L[0]
for i in range(1, len(L)):
v = lcm(v, L[i])
return v
# Width First Search (+ Distance)
def wfs_d(D, N, K):
"""
D: 隣接行列(距離付き)
N: ノード数
K: 始点ノード
"""
dfk = [-1] * (N + 1)
dfk[K] = 0
cps = [(K, 0)]
r = [False] * (N + 1)
r[K] = True
while len(cps) != 0:
n_cps = []
for cp, cd in cps:
for i, dfcp in enumerate(D[cp]):
if dfcp != -1 and not r[i]:
dfk[i] = cd + dfcp
n_cps.append((i, cd + dfcp))
r[i] = True
cps = n_cps[:]
return dfk
# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
"""
v: 現在のノード
pre: 1つ前のノード
dist: 現在の距離
以下は別途用意する
D: 隣接リスト(行列ではない)
D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト
"""
global D
global D_dfs_d
D_dfs_d[v] = dist
for next_v, d in D[v]:
if next_v != pre:
dfs_d(next_v, v, dist + d)
return
def sigma(N):
ans = 0
for i in range(1, N + 1):
ans += i
return ans
def comb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def bisearch(L, target):
low = 0
high = len(L) - 1
while low <= high:
mid = (low + high) // 2
guess = L[mid]
if guess == target:
return True
elif guess < target:
low = mid + 1
elif guess > target:
high = mid - 1
if guess != target:
return False
# --------------------------------------------
dp = None
def main():
N = int(input())
A = set(li_input())
if len(A) % 2 == 0:
print(len(A) - 1)
else:
print(len(A))
main()
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s540368947 | Accepted | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | n = input()
n = int(n)
ss = input().split()
sslist = sorted(ss)
# print(sslist)
dic_ss = {}
for x in sslist:
dic_ss.setdefault(x, 0)
dic_ss[x] += 1
# print(dic_ss)
# 1) 3回以上の重複があれば、その数字だけを使って、排除 N -> N-2
for key, value in dic_ss.items():
while value >= 3:
value -= 2
dic_ss[key] = value
# print(dic_ss)
# 2) 2回重複の最小値と最大値を使って重複排除 Min N -> N-1, Max M -> M-1
key1 = None
key2 = None
for key, value in dic_ss.items():
if key1 == None and value == 2:
key1 = key
elif key2 == None and value == 2:
key2 = key
if key1 != None and key2 != None:
dic_ss[key1] = 1
dic_ss[key2] = 1
key1 = None
key2 = None
# print(dic_ss)
# 3) 2回重複が1つ残ったら、重複なしから1つ削除
count = len(dic_ss)
for key, value in dic_ss.items():
if value > 1:
count -= 1
print(count)
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s109650609 | Runtime Error | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | N = int(input())
A = input()
list_A = A.split()
set_A = set(list_A)
i = 0
for a in list_A:
if a in set_A:
i += 1
i = i - len(set_A)
if i % 2 == 0:
print(N - i)
else:
print(N - (i +1)) | Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s175490435 | Runtime Error | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | N = int(input())
A = input()
list_A = A.split()
set_A = set(list_A)
i = 0
for a in list_A:
if a in set_A:
i += 1
i = i - len(set_A)
if i % 2 == 0:
print(N - i)
else:
print(N - (i +1))
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s198192006 | Runtime Error | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | import sys
import math
N = int(input())
array = list(map(int,input().split()))
set_array = set(array)
if not ( 3 <= N <= 10**5 and N % 2 == 1 ): sys.exit()
if len(array) == len(list(set_array)): print(0);sys.exit()
print(len(list(set_array))) if len(list(set_array) % 2 == 1 else print(len(list(set_array) - 1) | Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s512267845 | Runtime Error | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | #1,1,1 -> (1,1) 1
#1,2,3 -> (1,3) 2
#1,1,3 -> (1,3) 1 <=> 1,1,3,3 -> (1,3) 1,3
#1,2,1,3,7 == [1:2, 2:1, 3:1, 7:1]
#[1:4, 2:3, 3:2, 5:1, 6:2, 8:2, 11:1]
#それぞれ1または2と等しい
#[1:2, 2:1, 3:2, 5:1, 6:2, 8:2, 11:1]
#[1,1,3,3,6,6,8,8]
#[1,1,3,6,6,8,8]
#[1,3,6,8]
N = int(input())
A = list(map(int, input().split()))
B = [-1 for i in range(100005)]
for i in range(N):
if B[A[i]] == -1:
B[A[i]] = 1
elif B[A[i]] == 1:
B[A[i]] = 2:
elif B[A[i]] == 2:
B[A[i]] = 1
n = N - B.count(-1)
if B.count(2) % 2 == 0:
print(n)
else:
print(n-1)
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s951734143 | Accepted | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | i = int(input())
s = list(input().split())
a = len(set(s))
if a % 2 == 0:
a -= 1
print(a)
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s796955374 | Runtime Error | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | N = int(input())
A = list(map(int, input().strip().split()))
flg = 1
multi = [x for x in A if A.count(x) > 1]
result = list(set(multi))
count = 0
while flg:
multi.remove(max(multi))
multi.remove(min(multi))
multi = [x for x in multi if multi.count(x) > 1]
if len(multi) == 0:
flg = 0
count += 1
print(len(A) - count * 2)
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s490909497 | Runtime Error | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | ddef getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
"""
from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right
"""
import sys
# sys.setrecursionlimit(1000000000)
N = getN()
A = getList()
listnum = [0] * 15
for i in A:
listnum[i] += 1
for i in range(15):
if listnum[i] >= 3:
listnum[i] = (listnum[i] % 2) + 1
minus = listnum.count(2)
if minus % 2 == 0:
print(sum(listnum) - minus)
else:
print(sum(listnum) - minus - 1) | Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s625088665 | Wrong Answer | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | import numpy as np
import math
import fractions
class KyoPro:
AtCoder_Mod = 1000 * 1000 * 1000 + 7
@staticmethod
def ReadNumbers():
return list(map(int, input().split()))
@staticmethod
def MakeStringFromNumbers(a):
if len(a) == 0:
return
s = str(a[0])
for i in range(1, len(a)):
s += " " + str(a[i])
return s
def main():
n = int(input())
a = KyoPro.ReadNumbers()
d = {}
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
for i in a:
if i in d:
if d[i] == 1:
del d[i]
a.reverse()
while len(d) > 0:
x = len(a) - 3
b = a[x : x + 3]
mx = b.index(max(b))
b = a[x + mx]
if b in d:
d[b] -= 1
if d[b] == 1:
del d[b]
del a[x + mx]
b = a[x : x + 2]
mn = b.index(min(b))
b = a[x + mn]
if b in d:
d[b] -= 1
if d[b] == 1:
del d[b]
del a[x + mn]
print(len(a))
main()
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s181511893 | Accepted | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations
def li():
return list(map(int, sys.stdin.readline().split()))
def num():
return map(int, sys.stdin.readline().split())
def nu():
return int(input())
def find_gcd(x, y):
while y:
x, y = y, x % y
return x
def lcm(x, y):
gg = find_gcd(x, y)
return x * y // gg
mm = 1000000007
def solve():
t = 1
for tt in range(t):
n = nu()
a = li()
a.sort()
mp = {}
for i in a:
if i in mp:
mp[i] = mp.get(i) + 1
else:
mp[i] = 1
i = 0
j = n - 1
cc = 0
while i < j:
if mp.get(a[i]) == 1:
i += 1
continue
if mp.get(a[j]) == 1:
j -= 1
continue
cc += 2
mp[a[i]] = mp.get(a[i]) - 1
mp[a[j]] = mp.get(a[j]) - 1
i += 1
j -= 1
print(n - cc)
if __name__ == "__main__":
solve()
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s801805507 | Accepted | p03816 | The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N} | def mergesort(A):
N = len(A)
if N == 1:
return A
A1 = mergesort(A[: int(N / 2)])
A2 = mergesort(A[int(N / 2) :])
p = 0
p1, p2 = 0, 0
A_result = []
while True:
if p1 >= len(A1):
A_result = A_result + A2[p2:]
break
if p2 >= len(A2):
A_result = A_result + A1[p1:]
break
if A1[p1] < A2[p2]:
A_result.append(A1[p1])
p = p + 1
p1 = p1 + 1
else:
A_result.append(A2[p2])
p = p + 1
p2 = p2 + 1
if p == N:
break
return A_result
N = int(input())
A = list(map(int, input().split()))
A = mergesort(A)
count = 0
for i in range(N - 1):
if A[i] == A[i + 1]:
count = count + 1
ans = N - count
if ans % 2 == 0:
ans = ans - 1
print(ans)
| Statement
Snuke has decided to play a game using cards. He has a deck consisting of N
cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the
values written on the remaining cards will be pairwise distinct. Find the
maximum possible number of remaining cards. Here, N is odd, which guarantees
that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three
cards, eat two: one with the largest value, and another with the smallest
value. Then, return the remaining one card to the deck. | [{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}] |
Print the answer.
* * * | s278542939 | Runtime Error | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | import copy
[x, n] = list(map(int, input().split()))
pList = list(map(int, input().split()))
dict = {
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
9: 0,
10: 0,
11: 0,
12: 0,
13: 0,
14: 0,
15: 0,
16: 0,
17: 0,
18: 0,
19: 0,
20: 0,
21: 0,
22: 0,
23: 0,
24: 0,
25: 0,
26: 0,
27: 0,
28: 0,
29: 0,
30: 0,
31: 0,
32: 0,
33: 0,
34: 0,
35: 0,
36: 0,
37: 0,
38: 0,
39: 0,
40: 0,
41: 0,
42: 0,
43: 0,
44: 0,
45: 0,
46: 0,
47: 0,
48: 0,
49: 0,
50: 0,
51: 0,
52: 0,
53: 0,
54: 0,
55: 0,
56: 0,
57: 0,
58: 0,
59: 0,
60: 0,
61: 0,
62: 0,
63: 0,
64: 0,
65: 0,
66: 0,
67: 0,
68: 0,
69: 0,
70: 0,
71: 0,
72: 0,
73: 0,
74: 0,
75: 0,
76: 0,
77: 0,
78: 0,
79: 0,
80: 0,
81: 0,
82: 0,
83: 0,
84: 0,
85: 0,
86: 0,
87: 0,
88: 0,
89: 0,
90: 0,
91: 0,
92: 0,
93: 0,
94: 0,
95: 0,
96: 0,
97: 0,
98: 0,
99: 0,
100: 0,
}
for i in pList:
dict[i] = 1
goUp = True
goDown = True
run = True
upTar = copy.copy(x)
lowTar = copy.copy(x)
theAns = copy.copy(x)
while run:
if dict[lowTar] == 0:
theAns = lowTar
break
if dict[upTar] == 0:
theAns = upTar
break
if goUp:
upTar += 1
if goDown:
lowTar -= 1
if upTar == 100:
goUp = False
if lowTar:
goDown = False
print(theAns)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s438140257 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | #!/usr/bin/env python3
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s553907207 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | tar, n = map(int, input().split(" "))
if n == 0:
print(tar)
else:
lis = sorted(list(map(int, input().split(" "))))
idx = 0
ans = 101
vidx = lis[0]
m = 101
while idx < n:
if vidx == lis[idx]:
idx += 1
vidx += 1
elif vidx < lis[idx]:
if abs(vidx - tar) < m:
m = abs(vidx - tar)
if ans > vidx:
ans = vidx
vidx += 1
if ans == 101:
print(tar)
else:
print(ans)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s028832638 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | x, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()] if n != 0 else []
min_ = 100
cnt = 0
for i in range(100 + 1):
if abs(i - x) < min_ and not i in a:
min_ = abs(i - x)
cnt = i
print(cnt)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s734178385 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | print(0) | Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s354265332 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | x, n, *p = map(int, open(i := 0).read().split())
while x in p:
x += i * -(1**i)
i += 1
print(x)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s590271777 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | X, N = map(int, input().split())
N_list = list(map(int, input().split()))
A = []
for x in range(-101, 101):
A.append(x)
for x in N_list:
A[x + 101] = 1000
m = 200
s = 0
for x in A:
if abs(X - x) < m:
m = abs(X - x)
s = x
print(s)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s606414177 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | print(101)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s378310888 | Accepted | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | x, n, *p = map(int, open(0).read().split())
print(min({*range(999)} - {*p}, key=lambda y: abs(y - x)))
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s225086053 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | a,b=map(int,input().split())
if(b!=0):
l=list(map(int,input().split()))
st=1
else:
l=[0]
st=0
for i in range(st,101):
if((a-i) not in l)and((a-i)>0):
print(a-i)
break
elif((a+i) not in l):
print(a+i)
break | Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s176127267 | Accepted | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | X, N = map(int, input().split())
line = list(map(int, input().split()))
notLine = [i for i in range(-100, 201) if i not in line]
left = -1
right = len(notLine)
while abs(right - left) > 1:
middle = (right + left) // 2
if notLine[middle] >= X:
right = middle
else:
left = middle
# print(notLine[left], notLine[right])
if X - notLine[left] <= notLine[right] - X:
print(notLine[left])
else:
print(notLine[right])
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s559831734 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])
num_list = [int(n) for n in num_input[1].split()]
num_list.sort()
ans = x
if n != 0 and n != 1 and n != 100:
if x in num_list:
index = num_list.index(x)
value_left = x - 1
value_right = x + 1
if index != 0:
index_left = index - 1
if index != n - 1:
index_right = index + 1
if index == 0:
ans = x - 1
elif index == n - 1:
if num_list[index - 1] != x - 1:
ans = x + 1
else:
ans = x - 1
else:
for i in range(n):
if num_list[index_left] != value_left:
ans = value_left
break
elif num_list[index_right] != value_right:
ans = value_right
break
if index_left != 0:
index_left = index_left - 1
if index_right != n:
index_right = index_right + 1
value_left = value_left - 1
value_right = value_right + 1
if n == 1:
ans = x - 1
if n == 100:
if x <= 50:
ans = 0
if x > 50:
ans = 101
print(ans)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s555575016 | Accepted | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | X, N = map(int, input().split())
P = list(map(int, input().split()))
p = []
for j in range(X * 100):
if j in P:
a = 0
else:
p.append(j)
result = 1000
answer = 1000
for i in range(X * 100 - N):
if abs(X - p[i]) < result:
answer = p[i]
result = abs(X - p[i])
elif abs(X - p[i]) == result and p[i] <= answer:
answer = p[i]
print(answer)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s193015485 | Accepted | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | k = list(map(int, input().split()))
if k[1] == 0:
print(k[0])
else:
l = list(map(int, input().split()))
a = [i for i in range(102) if not i in l]
m = []
for i in a:
m.append(abs(i - k[0]))
print(a[m.index(min(m))])
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s465585401 | Accepted | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | xn = input().split()
X = int(xn[0])
N = int(xn[1])
A = [int(x) for x in input().split()]
li = [x for x in range(102)]
li2 = list(x for x in li if x not in A)
d_tmp = 1200
ans_tmp = -1
for i in li2:
d = abs(X - i)
if d < d_tmp:
d_tmp = d
ans_tmp = i
print(ans_tmp)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s447706190 | Runtime Error | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | [x, n] = [x for x in map(int, input().split(" "))]
pn = [x for x in map(int, input().split(" "))]
pn.sort()
min_pn = [y for y in pn if x >= y]
max_pn = [y for y in pn if x <= y]
min_pn_fix = None
max_pn_fix = None
for i in range(len(min_pn) - 1, 0, -1):
if min_pn[i] < min_pn[i - 1] - 1:
min_pn_fix = min_pn[i - 1] - 1
break
if min_pn_fix is None:
min_pn_fix = min_pn[0] - 1
for i in range(0, len(max_pn) - 1):
if max_pn[i] + 1 < max_pn[i + 1]:
max_pn_fix = max_pn[i] + 1
break
if max_pn_fix is None:
max_pn_fix = max_pn[-1] + 1
if abs(x - max_pn_fix) < abs(x - min_pn_fix):
print(max_pn_fix)
else:
print(min_pn_fix)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print the answer.
* * * | s545799019 | Wrong Answer | p02641 | Input is given from Standard Input in the following format:
X N
p_1 ... p_N | X, N = map(int, input().split())
result = 1000000000000
tmp = 100000000
if N == 0:
print(X)
exit()
S = list(map(int, input().split()))
flag = True
S.sort()
max_S = max(S)
for i in range(max_S):
# 含まれていないか確認
for j in S:
if i == j:
flag = False
break
if flag == False:
flag = True
continue
print(i)
if abs(X - i) < result:
print("aa:" + str(abs(X - i)))
result = abs(X - i)
tmp = i
print(tmp)
| Statement
Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.
Among the integers not contained in the sequence p_1, \ldots, p_N (not
necessarily positive), find the integer nearest to X, that is, find the
integer whose absolute difference with X is the minimum. If there are multiple
such integers, report the smallest such integer. | [{"input": "6 5\n 4 7 10 6 5", "output": "8\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the one\nnearest to 6 is 8.\n\n* * *"}, {"input": "10 5\n 4 7 10 6 5", "output": "9\n \n\nAmong the integers not contained in the sequence 4, 7, 10, 6, 5, the ones\nnearest to 10 are 9 and 11. We should print the smaller one, 9.\n\n* * *"}, {"input": "100 0", "output": "100\n \n\nWhen N = 0, the second line in the input will be empty. Also, as seen here, X\nitself can be the answer."}] |
Print N lines. The i-th line should contain the expected value of the
coordinate of the eventual position of rabbit i after K sets are performed.
The output is considered correct if the absolute or relative error is at most
10^{-9}.
* * * | s309203976 | Wrong Answer | p03953 | The input is given from Standard Input in the following format:
N
x_1 x_2 ... x_N
M K
a_1 a_2 ... a_M | N = int(input())
X = list(map(int, input().split()))
M, K = map(int, input().split())
A = list(map(int, input().split()))
K = K % M + 1
arr = [X[:]]
for k in range(K):
for a in A:
temp = []
for ar in arr:
tmp1 = ar[:]
tmp1[a - 1] = tmp1[a - 2] * 2 - tmp1[a - 1]
temp.append(tmp1)
tmp2 = ar[:]
tmp2[a - 1] = tmp2[a] * 2 - tmp2[a - 1]
temp.append(tmp2)
arr = temp
ans = [0 for i in range(N)]
L = len(arr)
for ar in arr:
for i in range(N):
ans[i] += ar[i] / L
arr = [ans]
for ar in arr[0]:
print(ar)
| Statement
There are N rabbits on a number line. The rabbits are conveniently numbered 1
through N. The coordinate of the initial position of rabbit i is x_i.
The rabbits will now take exercise on the number line, by performing _sets_
described below. A set consists of M _jumps_. The j-th jump of a set is
performed by rabbit a_j (2≤a_j≤N-1). For this jump, either rabbit a_j-1 or
rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit
x), then rabbit a_j will jump to the symmetric point of its current position
with respect to rabbit x.
The rabbits will perform K sets in succession. For each rabbit, find the
expected value of the coordinate of its eventual position after K sets are
performed. | [{"input": "3\n -1 0 2\n 1 1\n 2", "output": "-1.0\n 1.0\n 2.0\n \n\nRabbit 2 will perform the jump. If rabbit 1 is chosen, the coordinate of the\ndestination will be -2. If rabbit 3 is chosen, the coordinate of the\ndestination will be 4. Thus, the expected value of the coordinate of the\neventual position of rabbit 2 is 0.5\u00d7(-2)+0.5\u00d74=1.0.\n\n* * *"}, {"input": "3\n 1 -1 1\n 2 2\n 2 2", "output": "1.0\n -1.0\n 1.0\n \n\nx_i may not be distinct.\n\n* * *"}, {"input": "5\n 0 1 3 6 10\n 3 10\n 2 3 4", "output": "0.0\n 3.0\n 7.0\n 8.0\n 10.0"}] |
Print N lines. The i-th line should contain the expected value of the
coordinate of the eventual position of rabbit i after K sets are performed.
The output is considered correct if the absolute or relative error is at most
10^{-9}.
* * * | s862159249 | Runtime Error | p03953 | The input is given from Standard Input in the following format:
N
x_1 x_2 ... x_N
M K
a_1 a_2 ... a_M | import numpy as np
n = int(input())
x = list(map(int, input().split()))
m, k = map(int, input().split())
a = list(map(int, input().split()))
b = []
x2 = []
c = []
for i in range(1, n):
b.append(i - 1)
x2.append(x[i] - x[i - 1])
for i in range(m):
to = a[i] - 1
b[to], b[to - 1] = b[to - 1], b[to]
bai = np.zeros((n - 1, n - 1), dtype="int8")
for i in range(n - 1):
xx = b[i]
bai[xx, i] = 1
bai = np.mat(bai)
bai = bai**k
x2 = np.dot(x2, bai)
x2 = np.array(x2)
s = x[0]
print(s)
for i in x2[0]:
s += i
print(s)
| Statement
There are N rabbits on a number line. The rabbits are conveniently numbered 1
through N. The coordinate of the initial position of rabbit i is x_i.
The rabbits will now take exercise on the number line, by performing _sets_
described below. A set consists of M _jumps_. The j-th jump of a set is
performed by rabbit a_j (2≤a_j≤N-1). For this jump, either rabbit a_j-1 or
rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit
x), then rabbit a_j will jump to the symmetric point of its current position
with respect to rabbit x.
The rabbits will perform K sets in succession. For each rabbit, find the
expected value of the coordinate of its eventual position after K sets are
performed. | [{"input": "3\n -1 0 2\n 1 1\n 2", "output": "-1.0\n 1.0\n 2.0\n \n\nRabbit 2 will perform the jump. If rabbit 1 is chosen, the coordinate of the\ndestination will be -2. If rabbit 3 is chosen, the coordinate of the\ndestination will be 4. Thus, the expected value of the coordinate of the\neventual position of rabbit 2 is 0.5\u00d7(-2)+0.5\u00d74=1.0.\n\n* * *"}, {"input": "3\n 1 -1 1\n 2 2\n 2 2", "output": "1.0\n -1.0\n 1.0\n \n\nx_i may not be distinct.\n\n* * *"}, {"input": "5\n 0 1 3 6 10\n 3 10\n 2 3 4", "output": "0.0\n 3.0\n 7.0\n 8.0\n 10.0"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s830907243 | Accepted | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def inputI():
return int(input().strip())
def inputS():
return input().strip()
def inputIL():
return list(map(int, input().split()))
def inputSL():
return list(map(str, input().split()))
def inputILs(n):
return list(int(input()) for _ in range(n))
def inputSLs(n):
return list(input().strip() for _ in range(n))
def inputILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def Yes():
print("Yes")
return
def No():
print("No")
return
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def Base_10_to_n(X, n):
if int(X / n):
return Base_10_to_n(int(X / n), n) + [X % n]
return [X % n]
#############
# Main Code #
#############
N = inputI()
D, X = inputIL()
A = inputILs(N)
C = sum([(D - 1) // a + 1 for a in A])
print(C + X)
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s689793841 | Accepted | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
def gcd_list(L):
v = L[0]
for i in range(1, len(L)):
v = gcd(v, L[i])
return v
def lcm(n, m):
return (n * m) // gcd(n, m)
def lcm_list(L):
v = L[0]
for i in range(1, len(L)):
v = lcm(v, L[i])
return v
# Width First Search (+ Distance)
def wfs_d(D, N, K):
"""
D: 隣接行列(距離付き)
N: ノード数
K: 始点ノード
"""
dfk = [-1] * (N + 1)
dfk[K] = 0
cps = [(K, 0)]
r = [False] * (N + 1)
r[K] = True
while len(cps) != 0:
n_cps = []
for cp, cd in cps:
for i, dfcp in enumerate(D[cp]):
if dfcp != -1 and not r[i]:
dfk[i] = cd + dfcp
n_cps.append((i, cd + dfcp))
r[i] = True
cps = n_cps[:]
return dfk
# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
"""
v: 現在のノード
pre: 1つ前のノード
dist: 現在の距離
以下は別途用意する
D: 隣接リスト(行列ではない)
D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト
"""
global D
global D_dfs_d
D_dfs_d[v] = dist
for next_v, d in D[v]:
if next_v != pre:
dfs_d(next_v, v, dist + d)
return
def sigma(N):
ans = 0
for i in range(1, N + 1):
ans += i
return ans
def comb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def bisearch(L, target):
low = 0
high = len(L) - 1
while low <= high:
mid = (low + high) // 2
guess = L[mid]
if guess == target:
return True
elif guess < target:
low = mid + 1
elif guess > target:
high = mid - 1
if guess != target:
return False
# --------------------------------------------
dp = None
def main():
N = int(input())
D, X = li_input()
A = [int(input()) for _ in range(N)]
e = 0
for a in A:
e += math.ceil(D / a)
print(e + X)
main()
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s845349040 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
from sys import flags
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
def celi(a,b):
return -(-a//b)import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
from sys import flags
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
def celi(a,b):
return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n=int(input())
d,x=map(int,input().split())
a=[int(input()) for i in range(n)]
for i in range(d):
for j in range(n):
if i%a[j]==0:
x+=1
print(x)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n=int(input())
d,x=map(int,input().split())
a=[int(input()) for i in range(n)]
for i in range(d):
for j in range(n):
if i%a[j]==0:
x+=1
print(x) | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s584864421 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | a=int(input())
b,c=input().split()
b=int(b)
c=int(c)
d=[int(input()) i in range(a)
e=e+int((b-1)/d[i])+1
print(e) | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s987333254 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | 5
30 44
26
18
81
18
6 | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s629880630 | Accepted | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | import math
import sys
def getinputdata():
# 配列初期化
array_result = []
data = input()
array_result.append(data.split(" "))
flg = 1
try:
while flg:
data = input()
array_temp = []
if data != "":
array_result.append(data.split(" "))
flg = 1
else:
flg = 0
finally:
return array_result
arr_data = getinputdata()
# 人数
n = int(arr_data[0][0])
# 日数
d = int(arr_data[1][0])
# 残ったチョコ
x = int(arr_data[1][1])
mysum = 0
for i in range(2, 2 + n):
a = int(arr_data[i][0])
# print(a,mysum)
mysum += 1
cnt = 1
# print(mysum)
while cnt + a <= d:
mysum += 1
cnt += a
mysum += x
print(mysum)
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s979456571 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | jfrom math import gcd
from math import factorial as f
from math import ceil, floor, sqrt
import math
import bisect
import re
import heapq
from copy import deepcopy
import itertools
from itertools import permutations
from sys import exit
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))
yes = "Yes"
no = "No"
def main():
n = ii()
d, x = mi()
a = []
for i in range(n):
tmp = ii()
a.append(tmp)
ans = 0
for i in a:
tmp = 1
while tmp <= d:
ans += 1
tmp += i
ans += x
print(ans)
main()
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s508746316 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | n = int(input())
d,x = map(int, input().split())
sum = 0
for i in range(n):
a = int(input())
for j in range(100):
day = 1 + j*a
if day <= d:
sum += 1
else:
break
print(x + sum) | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s285986795 | Wrong Answer | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | N = int(input())
D, X = (int(i) for i in input().split())
a = [int(input()) for i in range(N)]
goukei = 0
for s in range(N):
c = (D - 1) / a[s] + 1
goukei += c
print(goukei)
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s109961115 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | n = int(input())
d, x = map(int, input().split())
a = []
for i in range(n):
a.appned(int(input())
s = 0
for i in range(d):
for j in range(n):
if i % a[j] == 1:
s +=1
print(s+x) | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s723655612 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | N = int(input())
D, X = map(int, input().split()))
ans = X
for i in range(N):
a = int(input())
for i in range(D):
if i*a + i+1 <= D:
ans += 1
print(ans) | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s083305646 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | 5
30 44
26
18
81
18
6 | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s057134735 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | n = int(input())
d,x = map(int, input().split())
sum = 0
for i in range(n):
a = int(input())
for j in range(100):
day = 1 + j*a
if day <= d:
sum += 1
else:
break
print(x + sum) | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s729159397 | Accepted | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | member = int(input())
day, remainder = map(int, input().split())
eatrate = []
for i in range(member):
eatrate.append(int(input()))
l = []
temp = list(range(day))
for r in eatrate:
l.append(temp[::r])
print(sum([len(i) for i in l]) + remainder)
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s456085158 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | a
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s855915558 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | N=input()
D,X=map(int,input().split())
for i range(N):
X+=(D-1+int(input()))//D
print(X) | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s955012918 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | n=int(input())
d,x=map(int,input().split())
a=[int(input()) for i in range(n)]
total=1
for j in a:
taotal+=len(range(1,,j))
print(total) | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s823337226 | Wrong Answer | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | count = int(input())
day, amari = map(int, input().split())
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s212671266 | Runtime Error | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | 5
30 44
26
18
81
18
6 | Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s364604785 | Accepted | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | import math
people_count = int(input())
day_count_and_leave_count = input()
day_count = int(day_count_and_leave_count.split()[0])
leave_count = int(day_count_and_leave_count.split()[1])
interval_date_list = []
for x in range(0, people_count):
interval_date_list.append(int(input()))
choco_count = 0
for interval_date in interval_date_list:
choco_count += 1
choco_count += math.floor((day_count - 1) / interval_date)
choco_count += leave_count
print(choco_count)
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s256315290 | Accepted | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | import sys
input_methods = ["clipboard", "file", "key"]
using_method = 0
input_method = input_methods[using_method]
IN = lambda: map(int, input().split())
LIN = lambda: list(IN())
mod = 1000000007
# +++++
def main():
n = int(input())
d, x = IN()
for _ in range(n):
ai = int(input())
init = 1
x += 1
for i in range(1, 1000):
if ai * i + 1 > d:
break
x += 1
print(x)
# s = input()
# +++++
isTest = False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text = clipboard.get()
input_l = input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform == "ios":
if input_method == input_methods[0]:
ic = input_clipboard()
input = lambda: ic.__next__()
elif input_method == input_methods[1]:
sys.stdin = open("inputFile.txt")
else:
pass
isTest = True
else:
pass
# input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Find the number of chocolate pieces prepared at the beginning of the camp.
* * * | s514974636 | Accepted | p03400 | Input is given from Standard Input in the following format:
N
D X
A_1
A_2
:
A_N | # -*- coding: utf-8 -*-
# 人数
psn_cnt = int(input())
# 日数と最終日の余り
date_amari = input()
# 分割
da_list = date_amari.split()
date = int(da_list[0])
amari = int(da_list[1])
# 人数分の入力値を取得
psn_list = []
for i in range(psn_cnt):
psn_list.append(int(input()))
choco_cnt_list = []
# 人数分のループ
for i in range(psn_cnt):
# チョコ数の初期化
choco_cnt = 0
# 日数+1のループ
for j in range(date + 1):
# 条件に当てはまる数値が日数を超えていなければその人のチョコを+1
if date >= psn_list[i] * j + 1:
# print(str(i) + "add")
choco_cnt += 1
# 条件に当てはまる数値が日数を超えたところでその人のチョコ数をリストに詰めて次の人へ
else:
choco_cnt_list.append(choco_cnt)
# print(str(i) + "added" + str(choco_cnt))
break
# 全員のチョコ数を合計して余りも足す
choco_sum = 0
for choco_cnt in choco_cnt_list:
choco_sum += choco_cnt
choco_sum += amari
print(choco_sum)
| Statement
Some number of chocolate pieces were prepared for a training camp. The camp
had N participants and lasted for D days. The i-th participant (1 \leq i \leq
N) ate one chocolate piece on each of the following days in the camp: the 1-st
day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result,
there were X chocolate pieces remaining at the end of the camp. During the
camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": "3\n 7 1\n 2\n 5\n 10", "output": "8\n \n\nThe camp has 3 participants and lasts for 7 days. Each participant eats\nchocolate pieces as follows:\n\n * The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n * The second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n * The third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number\nof pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\n* * *"}, {"input": "2\n 8 20\n 1\n 10", "output": "29\n \n\n* * *"}, {"input": "5\n 30 44\n 26\n 18\n 81\n 18\n 6", "output": "56"}] |
Print the answer.
* * * | s918627384 | Accepted | p03050 | Input is given from Standard Input in the following format:
N | import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9 + 7
def lcm(x, y):
return x * y // gcd(x, y)
def lgcd(l):
return reduce(gcd, l)
def llcm(l):
return reduce(lcm, l)
def powmod(n, i, mod):
return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod)
def div2(x):
return x.bit_length()
def div10(x):
return len(str(x)) - (x == 0)
def intput():
return int(input())
def mint():
return map(int, input().split())
def lint():
return list(map(int, input().split()))
def ilint():
return int(input()), list(map(int, input().split()))
def judge(x, l=["Yes", "No"]):
print(l[0] if x else l[1])
def lprint(l, sep="\n"):
for x in l:
print(x, end=sep)
def ston(c, c0="a"):
return ord(c) - ord(c0)
def ntos(x, c0="a"):
return chr(x + ord(c0))
class counter(dict):
def __init__(self, *args):
super().__init__(args)
def add(self, x, d=1):
self.setdefault(x, 0)
self[x] += d
def list(self):
l = []
for k in self:
l.extend([k] * self[k])
return l
class comb:
def __init__(self, n, mod=None):
self.l = [1]
self.n = n
self.mod = mod
def get(self, k):
l, n, mod = self.l, self.n, self.mod
k = n - k if k > n // 2 else k
while len(l) <= k:
i = len(l)
l.append(
l[i - 1] * (n + 1 - i) // i
if mod == None
else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod
)
return l[k]
def pf(x, mode="counter"):
C = counter()
p = 2
while x > 1:
k = 0
while x % p == 0:
x //= p
k += 1
if k > 0:
C.add(p, k)
p = p + 2 - (p == 2) if p * p < x else x
if mode == "counter":
return C
S = set([1])
for k in C:
T = deepcopy(S)
for x in T:
for i in range(1, C[k] + 1):
S.add(x * (k**i))
if mode == "set":
return S
if mode == "list":
return sorted(list(S))
N = intput()
ans = 0
for x in range(1, int(N**0.5) + 1000):
if (N - x) % x == 0:
m = (N - x) // x
if m <= x:
break
ans += m
print(ans)
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s632663128 | Wrong Answer | p03050 | Input is given from Standard Input in the following format:
N | def IL():
return list(map(int, input().split()))
def SL():
return input().split()
def I():
return int(input())
def S():
return list(input())
def divisor(n): # 約数
f = []
d = [1]
c = 0
r = int(n**0.5)
for i in range(2, r + 2):
while n % i == 0:
c += 1
n = n // i
if c != 0:
f.append([i, c])
c = 0
if n != 1:
f.append([n, 1])
for i in range(len(f)):
t = []
for j in range(1, f[i][1] + 1):
t.append(f[i][0] ** j)
for j in range(len(d)):
for k in range(len(t)):
d.append(d[j] * t[k])
return sorted(d)
n = I()
div = divisor(n)
if len(div) % 2 == 1:
ddiv = div[len(div) // 2 + 1 :]
ans = sum(ddiv) - len(ddiv)
else:
if div[len(div) // 2 - 1] + 1 == div[len(div) // 2]:
ans = max(len(div) // 2 - 1, 0)
else:
ddiv = div[len(div) // 2 :]
ans = sum(ddiv) - len(ddiv)
print(ans)
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s145264275 | Runtime Error | p03050 | Input is given from Standard Input in the following format:
N | """
C - AB Substrings
"""
str_list = []
end_a = []
start_b = []
ab_num = 0
for i in range(int(input())):
str_list.append(input())
if "AB" in str_list[-1]:
ab_num += 1
if str_list[-1].endswith("A"):
end_a.append(i)
if str_list[-1].startswith("B"):
start_b.append(i)
if end_a == start_b:
ab_num += min(len(end_a), len(start_b)) - 1
else:
ab_num += min(len(end_a), len(start_b))
print(ab_num)
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s061734240 | Runtime Error | p03050 | Input is given from Standard Input in the following format:
N | N = int(input())
counter = 0
end_a = 0
start_b = 0
start_b_end_a = 0
for n in range(N):
s = input()
for i in range(len(s) - 1):
if s[i : i + 2] == "AB":
counter += 1
if s[-1] == "A":
end_a += 1
if s[0] == "B":
start_b += 1
if s[-1] == "A" and s[0] == "B":
start_b_end_a += 1
if N == start_b_end_a:
print(counter + min([end_a, start_b]) - 1)
else:
print(counter + min([end_a, start_b]))
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s122369836 | Wrong Answer | p03050 | Input is given from Standard Input in the following format:
N | print(4)
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s955844047 | Runtime Error | p03050 | Input is given from Standard Input in the following format:
N | from math import floor, sqrt
N = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
div = make_divisors(N)
max_div = floor(sqrt(N))
ans = 0
for d in div:
if N %
if d <= max_div:
ans += (N-d)//d
print(d, (N-d)//d, ans)
print(ans+1)
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s991434260 | Runtime Error | p03050 | Input is given from Standard Input in the following format:
N | def hantei(p, q):
ANS = divmod(p, q)
if ANS[0] == ANS[1]:
return q
else 0
N = int(input())
ans = [hantei(N, r) for r in range(N) if hantei(N, r) != 0]
print(sum(ans)) | Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s149523235 | Wrong Answer | p03050 | Input is given from Standard Input in the following format:
N | 1000000000000
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s470833946 | Wrong Answer | p03050 | Input is given from Standard Input in the following format:
N | print(0)
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s222053206 | Wrong Answer | p03050 | Input is given from Standard Input in the following format:
N | print(1)
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s863606334 | Wrong Answer | p03050 | Input is given from Standard Input in the following format:
N | def toku(xxx):
a = int(xxx)
x = 0
last = 0
p = list(range(int(a**0.5) + 1))
ok = 0
p.pop(0)
for i in p:
if a % i == 0:
ok += 1
last = i
if a / last - last < 2:
x = 1
return ok - x
print(toku(input()))
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s206639142 | Accepted | p03050 | Input is given from Standard Input in the following format:
N | N, ans, p = int(input()), 0, 1
while p * p < N:
if N % p == 0 and N // p - 1 > p:
ans += N // p - 1
p += 1
print(ans)
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s626460047 | Runtime Error | p03050 | Input is given from Standard Input in the following format:
N | m = int(input())
pf = {m: 1}
a = [0]
for i in range(2, int(m**0.5) + 1):
pf[i] = pf.get(i, 0) + 1
if i != m // i:
pf[m // i] = pf.get(m // i, 0) + 1
for i in pf:
if m // (i - 1) == m % (i - 1):
a.append(a[-1] + i - 1)
print(a[-1])
| Statement
Snuke received a positive integer N from Takahashi. A positive integer m is
called a _favorite number_ when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those. | [{"input": "8", "output": "10\n \n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\n* * *"}, {"input": "1000000000000", "output": "2499686339916\n \n\nWatch out for overflow."}] |
For each query of the latter type, print the answer.
* * * | s800533697 | Accepted | p02568 | Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1} | mod = 998244353
mask = 2**32
ide_ele = 0
lazy_ele = mask
def segfunc(a, b):
a1, a2 = divmod(a, mask)
b1, b2 = divmod(b, mask)
c1 = (a1 + b1) % mod
c2 = a2 + b2
return (c1 * mask) + c2
def op(a, x):
a1, a2 = divmod(a, mask)
x1, x2 = divmod(x, mask)
c1 = (a1 * x1 + a2 * x2) % mod
c2 = a2
return (c1 * mask) + c2
def merge(x, y):
x1, x2 = divmod(x, mask)
y1, y2 = divmod(y, mask)
z1 = (x1 * y1) % mod
z2 = (x2 * y1 + y2) % mod
return (z1 * mask) + z2
class lazysegmenttree:
def __init__(
self, init_val, func=segfunc, ie=ide_ele, le=lazy_ele, op=op, merge=merge
):
n = len(init_val)
self.func = func
self.op = op
self.merge = merge
self.ie = ie
self.le = le
self.h = (n - 1).bit_length()
self.num = 1 << self.h
self.tree = [ie] * self.num * 2
self.lazy = [le] * self.num * 2
for i in range(n):
self.tree[i + self.num] = init_val[i]
for i in range(self.num - 1, 0, -1):
self.tree[i] = func(self.tree[2 * i], self.tree[2 * i + 1])
def reflect(self, k):
if self.lazy[k] == self.le:
return self.tree[k]
return self.op(self.tree[k], self.lazy[k])
def propagate(self, k):
if self.lazy[k] == self.le:
return
self.lazy[2 * k] = self.merge(self.lazy[2 * k], self.lazy[k])
self.lazy[2 * k + 1] = self.merge(self.lazy[2 * k + 1], self.lazy[k])
self.tree[k] = self.reflect(k)
self.lazy[k] = self.le
def thrust(self, k):
for i in range(1, self.h + 1)[::-1]:
self.propagate(k >> i)
def recalc(self, k):
while k:
k >>= 1
self.tree[k] = self.func(self.reflect(2 * k), self.reflect(2 * k + 1))
def update(self, left_0, right_0, value):
l = left_0 + self.num
r = right_0 + self.num + 1
vl = l
vr = r
x = value
self.thrust(l)
self.thrust(r - 1)
while r - l > 0:
if l & 1:
self.lazy[l] = self.merge(self.lazy[l], x)
l += 1
if r & 1:
r -= 1
self.lazy[r] = self.merge(self.lazy[r], x)
l >>= 1
r >>= 1
self.recalc(vl)
self.recalc(vr - 1)
def query(self, left_0, right_0):
l = left_0 + self.num
r = right_0 + self.num + 1
self.thrust(l)
self.thrust(r - 1)
vl = vr = self.ie
while r - l > 0:
if l & 1:
vl = self.func(vl, self.reflect(l))
l += 1
if r & 1:
r -= 1
vr = self.func(self.reflect(r), vr)
l >>= 1
r >>= 1
return self.func(vl, vr) // mask
n, q = map(int, input().split())
a = [(i * mask) + 1 for i in map(int, input().split())]
st = lazysegmenttree(a)
ans = []
for _ in range(q):
q, *p = map(int, input().split())
if q:
l, r = p
ans += [st.query(l, r - 1)]
else:
l, r, b, c = p
st.update(l, r - 1, (b * mask) + c)
print(*ans, sep="\n")
| Statement
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries
of the following types.
* `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c.
* `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353. | [{"input": "5 7\n 1 2 3 4 5\n 1 0 5\n 0 2 4 100 101\n 1 0 3\n 0 1 3 102 103\n 1 2 5\n 0 2 5 104 105\n 1 0 5", "output": "15\n 404\n 41511\n 4317767"}] |
For each query of the latter type, print the answer.
* * * | s999219338 | Accepted | p02568 | Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1} | import sys
input = sys.stdin.buffer.readline
mod = 998244353
INF = float("inf")
sec = pow(2, mod - 2, mod)
def getlist():
return list(map(int, input().split()))
class lazySegTree(object):
# N:処理する区間の長さ
def __init__(self, N):
self.N = N
self.LV = (N - 1).bit_length()
self.N0 = 2**self.LV
self.data = [0] * (2 * self.N0)
self.lazybeta = [1] * (2 * self.N0)
self.lazy = [0] * (2 * self.N0)
def initialize(self, A):
for i in range(self.N):
self.data[self.N0 - 1 + i] = A[i]
for i in range(self.N0 - 2, -1, -1):
self.data[i] = (self.data[2 * i + 1] + self.data[2 * i + 2]) % mod
def gindex(self, l, r):
L = (l + self.N0) >> 1
R = (r + self.N0) >> 1
lc = 0 if l & 1 else (L & -L).bit_length()
rc = 0 if r & 1 else (R & -R).bit_length()
for i in range(self.LV):
if rc <= i:
yield R
if L < R and lc <= i:
yield L
L >>= 1
R >>= 1
def propagates(self, *ids):
for i in reversed(ids):
w = self.lazybeta[i - 1]
v = self.lazy[i - 1]
if w == 1 and (not v):
continue
val = (v * sec) % mod
self.lazybeta[2 * i - 1] = (self.lazybeta[2 * i - 1] * w) % mod
self.lazybeta[2 * i] = (self.lazybeta[2 * i] * w) % mod
self.lazy[2 * i - 1] = (self.lazy[2 * i - 1] * w + val) % mod
self.lazy[2 * i] = (self.lazy[2 * i] * w + val) % mod
self.data[2 * i - 1] = (self.data[2 * i - 1] * w + val) % mod
self.data[2 * i] = (self.data[2 * i] * w + val) % mod
self.lazybeta[i - 1] = 1
self.lazy[i - 1] = 0
def update(self, l, r, b, c):
(*ids,) = self.gindex(l, r + 1)
self.propagates(*ids)
L = self.N0 + l
R = self.N0 + r + 1
v = c
w = b
while L < R:
if R & 1:
R -= 1
self.lazybeta[R - 1] = (self.lazybeta[R - 1] * w) % mod
self.lazy[R - 1] = (w * self.lazy[R - 1] + v) % mod
self.data[R - 1] = (self.data[R - 1] * w + v) % mod
if L & 1:
self.lazybeta[L - 1] = (self.lazybeta[L - 1] * w) % mod
self.lazy[L - 1] = (w * self.lazy[L - 1] + v) % mod
self.data[L - 1] = (self.data[L - 1] * w + v) % mod
L += 1
L >>= 1
R >>= 1
v <<= 1
for i in ids:
self.data[i - 1] = (self.data[2 * i - 1] + self.data[2 * i]) % mod
def query(self, l, r):
self.propagates(*self.gindex(l, r + 1))
L = self.N0 + l
R = self.N0 + r + 1
s = 0
while L < R:
if R & 1:
R -= 1
s += self.data[R - 1]
if L & 1:
s += self.data[L - 1]
L += 1
L >>= 1
R >>= 1
s %= mod
return s
def main():
N, Q = getlist()
A = getlist()
lSeg = lazySegTree(N)
lSeg.initialize(A)
for _ in range(Q):
q = getlist()
if q[0] == 0:
null, l, r, b, c = q
lSeg.update(l, r - 1, b, c)
else:
null, l, r = q
res = lSeg.query(l, r - 1)
print(res)
if __name__ == "__main__":
main()
# 5 3
# 1 1 1 1 1
# 0 0 4 10 3
# 0 1 5 20 3
# 1 2 3
| Statement
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries
of the following types.
* `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c.
* `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353. | [{"input": "5 7\n 1 2 3 4 5\n 1 0 5\n 0 2 4 100 101\n 1 0 3\n 0 1 3 102 103\n 1 2 5\n 0 2 5 104 105\n 1 0 5", "output": "15\n 404\n 41511\n 4317767"}] |
For each query of the latter type, print the answer.
* * * | s831089831 | Wrong Answer | p02568 | Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1} | mod = 998244353
eps = 10**-9
def main():
import sys
input = sys.stdin.buffer.readline
def op(a, b):
return (a + b) % mod
e = 0
mask = 2**32 - 1
def mapping(a, x, seg_len):
b = x >> 32
c = x & mask
return ((a * b) % mod + (c * seg_len) % mod) % mod
def composition(x, y):
b1 = x >> 32
c1 = x & mask
b2 = y >> 32
c2 = y & mask
return (((b1 * b2) % mod) << 32) + ((b2 * c1) % mod + c2) % mod
id = 1 << 32
class LazySegTree:
# Range update query
def __init__(
self,
A,
op=op,
e=e,
mapping=mapping,
composition=composition,
id=id,
initialize=True,
):
self.N = len(A)
self.LV = (self.N - 1).bit_length()
self.N0 = 1 << self.LV
self.op = op
self.e = e
self.mapping = mapping
self.composition = composition
self.id = id
if initialize:
self.data = [self.e] * self.N0 + A + [self.e] * (self.N0 - self.N)
for i in range(self.N0 - 1, 0, -1):
self.data[i] = op(self.data[i * 2], self.data[i * 2 + 1])
else:
self.data = [self.e] * (self.N0 * 2)
self.lazy = [id] * (self.N0 * 2)
def _ascend(self, i):
for _ in range(i.bit_length() - 1):
i >>= 1
self.data[i] = self.op(self.data[i * 2], self.data[i * 2 + 1])
def _descend(self, idx):
lv = idx.bit_length()
for j in range(lv - 1, 0, -1):
i = idx >> j
x = self.lazy[i]
if x == self.id:
continue
self.lazy[i * 2] = self.composition(self.lazy[i * 2], x)
self.lazy[i * 2 + 1] = self.composition(self.lazy[i * 2 + 1], x)
self.lazy[i] = self.id
self.data[i * 2] = self.mapping(self.data[i * 2], x, 1 << (j - 1))
self.data[i * 2 + 1] = self.mapping(
self.data[i * 2 + 1], x, 1 << (j - 1)
)
# open interval [l, r)
def apply(self, l, r, x):
l += self.N0 - 1
r += self.N0 - 1
self._descend(l // (l & -l))
self._descend(r // (r & -r) - 1)
l_ori = l
r_ori = r
seg_len = 1
while l < r:
if l & 1:
self.data[l] = self.mapping(self.data[l], x, seg_len)
self.lazy[l] = self.composition(self.lazy[l], x)
l += 1
if r & 1:
r -= 1
self.data[r] = self.mapping(self.data[r], x, seg_len)
self.lazy[r] = self.composition(self.lazy[r], x)
l >>= 1
r >>= 1
seg_len <<= 1
self._ascend(l_ori // (l_ori & -l_ori))
self._ascend(r_ori // (r_ori & -r_ori) - 1)
# open interval [l, r)
def query(self, l, r):
l += self.N0 - 1
r += self.N0 - 1
self._descend(l // (l & -l))
self._descend(r // (r & -r) - 1)
ret = self.e
while l < r:
if l & 1:
ret = self.op(ret, self.data[l])
l += 1
if r & 1:
ret = self.op(self.data[r - 1], ret)
r -= 1
l >>= 1
r >>= 1
return ret
N, Q = map(int, input().split())
A = list(map(int, input().split()))
ST = LazySegTree(A)
for _ in range(Q):
q = list(map(int, input().split()))
if q[0] == 0:
l, r, b, c = q[1:]
l += 1
r += 1
ST.apply(l, r, (b << 32) + c)
else:
l, r = q[1:]
l += 1
r += 1
print(ST.query(l, r))
if __name__ == "__main__":
main()
| Statement
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries
of the following types.
* `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c.
* `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353. | [{"input": "5 7\n 1 2 3 4 5\n 1 0 5\n 0 2 4 100 101\n 1 0 3\n 0 1 3 102 103\n 1 2 5\n 0 2 5 104 105\n 1 0 5", "output": "15\n 404\n 41511\n 4317767"}] |
For each query of the latter type, print the answer.
* * * | s878772814 | Wrong Answer | p02568 | Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1} | class Lazy_Evaluation_Tree:
def __init__(self, L, calc, unit, op, comp, id):
"""calcを演算,opを作用とするリストLのSegment Treeを作成
calc:演算
unit:モノイドcalcの単位元 (xe=ex=xを満たすe)
op:作用素
comp:作用素の合成
id:恒等写像
[条件] M:Monoid,F={f:F x M→ M:作用素}に対して,以下が成立する.
Fは恒等写像 id を含む.つまり,任意の x in M に対して id(x)=x
Fは写像の合成に閉じている.つまり,任意の f,g in F に対して, comp(f,g) in F
任意の f in F, x,y in M に対して,f(xy)=f(x)f(y)である.
"""
self.calc = calc
self.unit = unit
self.op = op
self.comp = comp
self.id = id
N = len(L)
d = max(1, (N - 1).bit_length())
k = 2**d
X = [unit] * (k - 1) + L + [unit] * (k - len(L))
self.num = k
self.depth = d
for i in range(k - 2, -1, -1):
X[i] = calc(X[2 * i + 1], X[2 * i + 2])
self.data = X
self.lazy = [self.id] * (2 * k - 1)
def eval(self, k):
if self.lazy[k] == self.id: # 単位元だったら終了
return
if k < self.num - 1: # 葉でなければ子に伝搬
self.lazy[2 * k + 1] = self.lazy[k]
self.lazy[2 * k + 2] = self.lazy[k]
# 自身を更新(作用)
self.data[k] = self.op(self.lazy[k], self.data[k])
self.lazy[k] = self.id
def get(self, k, index=0):
return self.product(k, k, index)
def operate(self, From, To, alpha, index=0, left_closed=True, right_closed=True):
A = From - index + (not left_closed)
B = To - index - (not right_closed)
return self.__operate_second(A, B + 1, alpha, 0, 0, self.num)
def __operate_second(self, a, b, alpha, k, l, r):
self.eval(k)
if (a <= l) and (r <= b): # 完全に内側のとき
self.lazy[k] = self.comp(alpha, self.lazy[k])
self.eval(k)
elif (a < r) and (l < b): # 一部がかぶるとき
self.__operate_second(a, b, alpha, 2 * k + 1, l, (l + r) // 2) # 左の子
self.__operate_second(a, b, alpha, 2 * k + 2, (l + r) // 2, r) # 右の子
self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])
def update(self, k, x):
pass
def product(self, From, To, index=0, left_closed=True, right_closed=True):
A = From - index + (not left_closed)
B = To - index - (not right_closed)
return self.__product_second(A, B + 1, 0, 0, self.num)
def __product_second(self, a, b, k, l, r):
self.eval(k)
if r <= a or b <= l:
return self.unit
elif a <= l and r <= b:
return self.data[k]
else:
alpha = self.__product_second(a, b, 2 * k + 1, l, (l + r) // 2)
beta = self.__product_second(a, b, 2 * k + 2, (l + r) // 2, r)
return self.calc(alpha, beta)
# ================================================
N, Q = map(int, input().split())
Mod = 998244353
A = list(map(int, input().split()))
op = lambda t, x: (t[0] * x + t[1]) % Mod
comp = lambda u, t: ((u[0] * t[0]) % Mod, (u[1] + u[0] * t[1]) % Mod)
L = Lazy_Evaluation_Tree(A, lambda x, y: (x + y) % Mod, 0, op, comp, (1, 0))
X = []
for _ in range(Q):
R = tuple(map(int, input().split()))
if R[0] == 0:
_, l, r, b, c = R
L.operate(l, r - 1, (b, c))
else:
_, l, r = R
X.append(L.product(l, r - 1))
print("\n".join(map(str, X)))
| Statement
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries
of the following types.
* `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c.
* `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353. | [{"input": "5 7\n 1 2 3 4 5\n 1 0 5\n 0 2 4 100 101\n 1 0 3\n 0 1 3 102 103\n 1 2 5\n 0 2 5 104 105\n 1 0 5", "output": "15\n 404\n 41511\n 4317767"}] |
For each query of the latter type, print the answer.
* * * | s332506455 | Runtime Error | p02568 | Input is given from Standard Input in the following format:
N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1} | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10**9 + 1 # sys.maxsize # float("inf")
MOD = 998244353
def set_depth(depth):
global DEPTH, SEGTREE_SIZE, NONLEAF_SIZE
DEPTH = depth
SEGTREE_SIZE = 1 << DEPTH
NONLEAF_SIZE = 1 << (DEPTH - 1)
def set_width(width):
set_depth((width - 1).bit_length() + 1)
def get_size(pos):
ret = pos.bit_length()
return 1 << (DEPTH - ret)
def up(pos):
pos += SEGTREE_SIZE // 2
return pos // (pos & -pos)
def up_propagate(table, pos, binop):
while pos > 1:
pos >>= 1
table[pos] = binop(table[pos * 2], table[pos * 2 + 1])
def full_up(table, binop):
for i in range(NONLEAF_SIZE - 1, 0, -1):
table[i] = binop(table[2 * i], table[2 * i + 1])
def force_down_propagate(
action_table, value_table, pos, action_composite, action_force, action_unity
):
max_level = pos.bit_length() - 1
size = NONLEAF_SIZE
for level in range(max_level):
size //= 2
i = pos >> (max_level - level)
action = action_table[i]
if action != action_unity:
action_table[i * 2] = action_composite(action, action_table[i * 2])
action_table[i * 2 + 1] = action_composite(action, action_table[i * 2 + 1])
action_table[i] = action_unity
value_table[i * 2] = action_force(action, value_table[i * 2], size)
value_table[i * 2 + 1] = action_force(action, value_table[i * 2 + 1], size)
def force_range_update(
value_table,
action_table,
left,
right,
action,
action_force,
action_composite,
action_unity,
):
"""
action_force: action, value, cell_size => new_value
action_composite: new_action, old_action => composite_action
"""
left += NONLEAF_SIZE
right += NONLEAF_SIZE
while left < right:
if left & 1:
value_table[left] = action_force(action, value_table[left], get_size(left))
action_table[left] = action_composite(action, action_table[left])
left += 1
if right & 1:
right -= 1
value_table[right] = action_force(
action, value_table[right], get_size(right)
)
action_table[right] = action_composite(action, action_table[right])
left //= 2
right //= 2
def range_reduce(table, left, right, binop, unity):
ret_left = unity
ret_right = unity
left += NONLEAF_SIZE
right += NONLEAF_SIZE
while left < right:
if left & 1:
ret_left = binop(ret_left, table[left])
left += 1
if right & 1:
right -= 1
ret_right = binop(table[right], ret_right)
left //= 2
right //= 2
return binop(ret_left, ret_right)
def lazy_range_update(
action_table,
value_table,
start,
end,
action,
action_composite,
action_force,
action_unity,
value_binop,
):
"update [start, end)"
L = up(start)
R = up(end)
force_down_propagate(
action_table, value_table, L, action_composite, action_force, action_unity
)
force_down_propagate(
action_table, value_table, R, action_composite, action_force, action_unity
)
# print("action", file=sys.stderr)
# debugprint(action_table)
# print("value", file=sys.stderr)
# debugprint(value_table)
# print(file=sys.stderr)
force_range_update(
value_table,
action_table,
start,
end,
action,
action_force,
action_composite,
action_unity,
)
up_propagate(value_table, L, value_binop)
up_propagate(value_table, R, value_binop)
def lazy_range_reduce(
action_table,
value_table,
start,
end,
action_composite,
action_force,
action_unity,
value_binop,
value_unity,
):
"reduce [start, end)"
force_down_propagate(
action_table,
value_table,
up(start),
action_composite,
action_force,
action_unity,
)
force_down_propagate(
action_table, value_table, up(end), action_composite, action_force, action_unity
)
return range_reduce(value_table, start, end, value_binop, value_unity)
def debug(*x):
print(*x, file=sys.stderr)
def main():
# parse input
N, Q = map(int, input().split())
AS = list(map(int, input().split()))
set_width(N)
value_unity = 0
value_table = [value_unity] * SEGTREE_SIZE
value_table[NONLEAF_SIZE : NONLEAF_SIZE + len(AS)] = AS
action_unity = None
action_table = [action_unity] * SEGTREE_SIZE
def action_force(action, value, size):
if action == action_unity:
return value
b, c = action
return (value * b + c * size) % MOD
def action_composite(new_action, old_action):
if new_action == action_unity:
return old_action
if old_action == action_unity:
return new_action
b1, c1 = old_action
b2, c2 = new_action
debug(new_action, old_action, (b1 * b2, b2 * c1 + c2))
return (b1 * b2, b2 * c1 + c2)
def value_binop(a, b):
return (a + b) % MOD
full_up(value_table, value_binop)
for _q in range(Q):
q, *args = map(int, input().split())
if q == 0:
l, r, b, c = args
lazy_range_update(
action_table,
value_table,
l,
r,
(b, c),
action_composite,
action_force,
action_unity,
value_binop,
)
pass
else:
l, r = args
print(
lazy_range_reduce(
action_table,
value_table,
l,
r,
action_composite,
action_force,
action_unity,
value_binop,
value_unity,
)
)
T1 = """
5 7
1 2 3 4 5
1 0 5
0 2 4 100 101
1 0 3
0 1 3 102 103
1 2 5
0 2 5 104 105
1 0 5
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
15
404
41511
4317767
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g, name=k)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
main()
| Statement
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries
of the following types.
* `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c.
* `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353. | [{"input": "5 7\n 1 2 3 4 5\n 1 0 5\n 0 2 4 100 101\n 1 0 3\n 0 1 3 102 103\n 1 2 5\n 0 2 5 104 105\n 1 0 5", "output": "15\n 404\n 41511\n 4317767"}] |
If Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1.
If he can, print the minimum number of ken-ken-pa needed to reach vertex T.
* * * | s489375127 | Wrong Answer | p02991 | Input is given from Standard Input in the following format:
N M
u_1 v_1
:
u_M v_M
S T | print(-1)
| Statement
Ken loves _ken-ken-pa_ (Japanese version of hopscotch). Today, he will play it
on a directed graph G. G consists of N vertices numbered 1 to N, and M edges.
The i-th edge points from Vertex u_i to Vertex v_i.
First, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-
ken-pa. In one ken-ken-pa, he does the following exactly three times: follow
an edge pointing from the vertex on which he is standing.
Determine if he can reach Vertex T by repeating ken-ken-pa. If the answer is
yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that
visiting Vertex T in the middle of a ken-ken-pa does not count as reaching
Vertex T by repeating ken-ken-pa. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 1\n 1 3", "output": "2\n \n\nKen can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1\n\\rightarrow 2 \\rightarrow 3 \\rightarrow 4 in the first ken-ken-pa, then 4\n\\rightarrow 1 \\rightarrow 2 \\rightarrow 3 in the second ken-ken-pa. This is\nthe minimum number of ken-ken-pa needed.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 3 1\n 1 2", "output": "-1\n \n\nAny number of ken-ken-pa will bring Ken back to Vertex 1, so he cannot reach\nVertex 2, though he can pass through it in the middle of a ken-ken-pa.\n\n* * *"}, {"input": "2 0\n 1 2", "output": "-1\n \n\nVertex S and Vertex T may be disconnected.\n\n* * *"}, {"input": "6 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 1\n 1 4\n 1 5\n 4 6\n 1 6", "output": "2"}] |
If Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1.
If he can, print the minimum number of ken-ken-pa needed to reach vertex T.
* * * | s237086574 | Accepted | p02991 | Input is given from Standard Input in the following format:
N M
u_1 v_1
:
u_M v_M
S T | #!/usr/bin/env python
import sys
v1mask = set()
v2mask = set()
def getVertex(i, e):
global v1mask, v2mask
v = set()
for v1 in e[i]:
if v1 in v1mask:
continue
v1mask.add(v1)
for v2 in e[v1]:
if v2 in v2mask:
continue
v2mask.add(v2)
for v3 in e[v2]:
v.add(v3)
#
return v
#
n, m = [int(x) for x in sys.stdin.readline().split()]
e = {i: [] for i in range(n)}
for _ in range(m):
u, v = [int(x) for x in sys.stdin.readline().split()]
e[u - 1].append(v - 1)
s, t = [int(x) - 1 for x in sys.stdin.readline().split()]
#
hop = 0
now = {s}
visit = {s}
while True:
hop += 1
n = set()
for i in now:
n |= getVertex(i, e) - visit
if t in n:
break
#
if t in n:
break
if not n:
hop = -1
break
now = n
visit |= n
#
print(hop)
| Statement
Ken loves _ken-ken-pa_ (Japanese version of hopscotch). Today, he will play it
on a directed graph G. G consists of N vertices numbered 1 to N, and M edges.
The i-th edge points from Vertex u_i to Vertex v_i.
First, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-
ken-pa. In one ken-ken-pa, he does the following exactly three times: follow
an edge pointing from the vertex on which he is standing.
Determine if he can reach Vertex T by repeating ken-ken-pa. If the answer is
yes, find the minimum number of ken-ken-pa needed to reach Vertex T. Note that
visiting Vertex T in the middle of a ken-ken-pa does not count as reaching
Vertex T by repeating ken-ken-pa. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 1\n 1 3", "output": "2\n \n\nKen can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1\n\\rightarrow 2 \\rightarrow 3 \\rightarrow 4 in the first ken-ken-pa, then 4\n\\rightarrow 1 \\rightarrow 2 \\rightarrow 3 in the second ken-ken-pa. This is\nthe minimum number of ken-ken-pa needed.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 3 1\n 1 2", "output": "-1\n \n\nAny number of ken-ken-pa will bring Ken back to Vertex 1, so he cannot reach\nVertex 2, though he can pass through it in the middle of a ken-ken-pa.\n\n* * *"}, {"input": "2 0\n 1 2", "output": "-1\n \n\nVertex S and Vertex T may be disconnected.\n\n* * *"}, {"input": "6 8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 1\n 1 4\n 1 5\n 4 6\n 1 6", "output": "2"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.