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 |
|---|---|---|---|---|---|---|---|
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s976095470 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | A = [[1,3,5,7,8,10,12],[4,6,9,11],[2]]
x,y = map(int, input().split())
flg = 0
for a in A:
if x in a and y in a:
flg = 1
if flg = 1:
print("Yes")
else:
print("No") | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s766893586 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | def calc_dynamic(n, x, m):
# 結果を保持する辞書
cal_result = {}
# 初期値の設定
cal_result[1] = x
if n == 1:
return x
for i in range(1, n):
cal_result[i + 1] = cal_result[i] ** 2 % m
# return cal_result[n]
return sum(cal_result.values())
def calc_dynamic2(n, x, m):
cal_result_0 = 0
cal_result_1 = 0
# 初期値の設定
cal_result_0 = x
total = x
if n == 1:
return x
for i in range(1, n):
cal_result_1 = cal_result_0 * cal_result_0 % m
cal_result_0 = cal_result_1
total += cal_result_1
return total
def calc_dynamic3(n, x, m):
# 結果を保持する辞書
cal_result = {}
cal_result_0 = 0
cal_result_1 = 0
loop_range = (0, 0)
# 初期値の設定
cal_result_0 = x
total = x
if n == 1:
return x
for i in range(1, n):
cal_result_1 = cal_result_0 * cal_result_0 % m
cal_result_0 = cal_result_1
total += cal_result_1
if cal_result_1 in cal_result:
loop_range = (cal_result[cal_result_1], i, cal_result_0, cal_result_1)
break
else:
cal_result[cal_result_1] = (i, total)
if i == n - 1:
return total
hoge = i
r = i - loop_range[0][0]
v = total - loop_range[0][1]
hoge += r
total += v * ((n - hoge) // r)
hoge += r * ((n - hoge) // r)
# while hoge < n:
# total += v
# hoge += r
cal_result_0 = loop_range[2]
cal_result_1 = loop_range[3]
for i in range(hoge - r + 1, n):
cal_result_1 = cal_result_0 * cal_result_0 % m
cal_result_0 = cal_result_1
total += cal_result_1
return total
[n, x, m] = map(lambda x: int(x), input().split(" "))
print(calc_dynamic3(n, x, m))
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s443418332 | Runtime Error | p02550 | Input is given from Standard Input in the following format:
N X M | N,X,M=map(int,input().split())
l=[X]
p=[-1]*(M+1)
p[X]=0
for i in range(N-1):
x=(l[-1]**2)%M
if p[x]>=0:
break
l.append(x)
p[x]=i+1
x=p[x]
y=len(l)-x
print(sum(l[:x])+(N-x)//y*sum(l[x:])+sum(l[x:x+(N-x)%y])) | Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s098596355 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | N, X, M = map(int, input().split())
L = []
L.append(X)
J = [0 for i in range(M + 1)]
key = 0
start = 0
end = 0
for i in range(1, M + 2):
X = (X**2) % M
L.append(X)
if J[X] >= 1:
key = X
end = i
break
J[X] += 1
for i in range(1, end):
if L[end - i] == key:
start = end - i
A = L[0:start]
B = L[start:end]
C = (N - start) // (end - start)
D = (N - start) % (end - start)
E = L[start : start + D]
if N < end:
print(sum(L[0:N]))
else:
print(sum(A) + sum(B) * C + sum(E))
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s311853561 | Runtime Error | p02550 | Input is given from Standard Input in the following format:
N X M | def solve(N, X, M):
memo = [-1] * M
acc = [0] * (M + 1)
x = X % M
for i in range(M):
if memo[x] >= 0:
break
acc[i + 1] = acc[i] + x
memo[x] = i
x = (x * x) % M
end = i
start = memo[x]
cycle = end - start
if N < end:
return acc[N] + (X - X % M)
cycle_sum = acc[end] - acc[start]
res = acc[start] + (X - X % M)
N -= start
res += (N // cycle) * cycle_sum
res += acc[start + (N % cycle)] - acc[start]
return res
N, X, M = map(int, input().split())
print(solve(N, X, M))
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s853572666 | Runtime Error | p02550 | Input is given from Standard Input in the following format:
N X M | # -*- coding: utf-8 -*-
# map(int, input().split())
N, X, M = map(int, input().split())
first_A = [X]
mod_M = [False for i in range(M)]
mod_M[0] = True
mod_M[1] = True
is_break = False
for i in range(min(N - 1, M + 1)):
A_n1 = pow(first_A[-1], 2) % M
if mod_M[A_n1]:
is_break = True
last_num = A_n1
break
else:
first_A.append(A_n1)
mod_M[A_n1] = True
if is_break:
if last_num == 0:
print(sum(first_A))
elif last_num == 1:
nokori = N - len(first_A)
print(sum(first_A) + nokori)
else: # roop
loop_idx = first_A.index(last_num)
first_A, second_A = first_A[:loop_idx], first_A[loop_idx:]
roop = int((N - len(first_A)) / len(second_A))
nokori_kaisuu = (N - len(first_A)) - (roop * len(second_A))
if nokori_kaisuu == 0:
print(sum(first_A) + (sum(second_A) * roop))
else:
print(sum(first_A) + (sum(second_A) * roop) + sum(second_A[:nokori_kaisuu]))
else:
print(sum(first_A))
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s624177399 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | n, x, m = map(int, input().split())
table = [0] * m
def calc(init, iter):
ret = 0
for _ in range(iter):
ret += init
init = (init * init) % m
return ret
ret = x
cur = x % m
table[cur] = 1
for rnd in range(2, min(m + 2, n + 1)):
cur = (cur * cur) % m
if table[cur]:
per = rnd - table[cur]
persum = calc(cur, per)
rnds = (n - rnd) // per
ret += rnds * persum
ret += calc(cur, n - rnd - per * rnds + 1)
# print(cur,table[cur],rnd,per,persum,rnds)
break
else:
table[cur] = rnd
ret += cur
print(ret)
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s505742282 | Wrong Answer | p02550 | Input is given from Standard Input in the following format:
N X M | import numpy as np
i8 = np.int64
def solve(N, X, M):
memo_val = np.zeros(M, i8)
memo_i = np.zeros(M, i8)
ret = 0
a = X
for i in range(1, N):
ret += a
if memo_i[a] > 0:
u = (N - memo_i[a]) // (i - memo_i[a])
v = (N - memo_i[a]) % (i - memo_i[a])
ret = u * (ret - memo_val[a])
nokori = v + memo_i[a]
for j in range(M):
if memo_i[j] == nokori:
ret += memo_val[j]
return ret
memo_i[a] = i
memo_val[a] = ret
a = a**2 % M
return ret
N, X, M = [int(x) for x in input().split()]
ans = solve(N, X, M)
print(ans)
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s049023057 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | n, x, m = map(int, input().split())
s = set()
p = []
while x not in s:
s.add(x)
p += [x]
x = (x * x) % m
if len(p) >= n:
print(sum(p))
quit()
r = b = t = v = 0
a = [0]
for i in p:
if i == x:
b = 1
r += 1 - b
t += b * i
v += i
a += [a[-1] + i] * b
l = len(p)
print(v + t * ((n - l) // (l - r)) + a[(n - l) % (l - r)])
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s003552454 | Wrong Answer | p02550 | Input is given from Standard Input in the following format:
N X M | n, x, m = map(int, input().split())
cnt2 = set()
cnt2.add(x)
cnt3 = [x]
cnt4 = 0
cnt5 = 0
cnt6 = x
for i in range(1, m + 10):
num2 = pow(cnt6, 2, m)
if num2 in cnt2:
for j in range(len(cnt3)):
if cnt3[j] == num2:
cnt7 = j
break
cnt10 = len(cnt3) - cnt7
num4 = sum(cnt3[:cnt7])
cnt4 = len(cnt3)
break
cnt2.add(num2)
cnt3.append(num2)
cnt6 = num2
if num2 == 0:
ans = sum(cnt3)
cnt5 = 1
break
if cnt5 == 0:
ans = num4
n -= cnt7
ans += (n // cnt10) * sum(cnt3[cnt7:])
ans += sum(cnt3[cnt7 : (n % cnt10) + cnt7])
if cnt4 >= n:
ans = sum(cnt3[:n])
print(ans)
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s057030250 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | N, X, M = map(int, input().split())
if N == 1 or M == 1:
print(X)
exit()
F = (N - 1).bit_length()
A = [[0] * M for _ in range(F)]
for x in range(M):
A[0][x] = (x * x) % M
for d in range(1, F):
for x in range(M):
A[d][x] = A[d - 1][A[d - 1][x]]
S = [[0] * M for _ in range(F)]
for x in range(M):
S[0][x] = A[0][x]
for d in range(1, F):
for x in range(M):
S[d][x] = S[d - 1][x] + S[d - 1][A[d - 1][x]]
Ans = 0
depth = 0
N -= 1
Y = X
while N > 0:
if N % 2:
Ans += S[depth][X]
X = A[depth][X]
depth += 1
N >>= 1
print(Ans + Y)
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s421681840 | Runtime Error | p02550 | Input is given from Standard Input in the following format:
N X M | import sys
input = sys.stdin.buffer.readline
n, x, mod = map(int, input().split())
ans = 0
temp = x
num = 1
# while temp < mod:
# temp *= x
# num += 1
A = [0] * (mod + 1)
# if temp == mod:
# A[1] = x % mod
# ans += A[1]
# for i in range(2, num + 1):
# A[i] = A[i - 1] * A[i - 1] % mod
# ans += A[i]
# # print(ans)
# print(ans)
# exit()
kouho = {}
if n < mod:
A[1] = x % mod
ans += A[1]
for i in range(2, n + 1):
A[i] = A[i - 1] * A[i - 1] % mod
ans += A[i]
# print(ans)
else:
A[1] = x
ans += A[1]
kouho[A[1]] = 1
temp = A[1]
for i in range(2, mod + 1):
A[i] = temp * temp % mod
if A[i] in kouho:
migi = i
break
kouho[A[i]] = i
temp = A[i]
saisho = 0
hidari = kouho[A[i]]
saisho = sum(A[1:hidari])
# for i in range(1, hidari):
# saisho += A[i]
cycle_val = sum(A[hidari:migi])
# cycle_val = 0
# for i in range(hidari, migi):
# cycle_val += A[i]
cycle = migi - hidari
kaisu = n // cycle
amari = n % cycle - (hidari - 1)
amari %= cycle
kaisu = (n - (amari + hidari - 1)) // cycle
amari_val = sum(A[hidari : hidari + amari])
# amari_val = 0
# for i in range(hidari, hidari + amari):
# amari_val += A[i]
ans = saisho + cycle_val * kaisu + amari_val
print(ans)
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s468430334 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | N, X, M = map(int, input().split())
dist = [0 for i in range(M)]
A = X
loopin = -1
loopout = -1
ans = [0]
for i in range(N + 1):
if dist[A] != 0:
loopin = dist[A]
loopout = i
ans.append(ans[-1] + A)
break
else:
dist[A] = i
ans.append(ans[-1] + A)
A = (A * A) % M
if loopin == -1:
print(ans[N])
exit()
# print(roopin,roopout)
# print(ans)
A = X
loop = loopout - loopin
def solve(l, r):
assert 0 <= l and l <= r
if r <= loopout:
return ans[r] - ans[l]
if l < loopin:
return ans[loopin] - ans[l] + solve(loopin, r)
x = (l - loopin) // loop
y = (r - loopin) // loop
# x*loop+loopin<=l<(x+1)*loop+loopin
# y*loop+loopin<=r<(y+1)*loop+loopin
if x == y:
return ans[r - y * loop] - ans[l - x * loop]
# 以降はx<y
tmp1 = ans[l - x * loop] - ans[loopin]
tmp2 = (ans[loopout] - ans[loopin]) * (y - x)
tmp3 = ans[r - y * loop] - ans[loopin]
# print(l,r,x,y,tmp1,tmp2,tmp3)
return tmp1 + tmp2 + tmp3
print(solve(0, N))
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s402485761 | Wrong Answer | p02550 | Input is given from Standard Input in the following format:
N X M | import math
N, X, M = [int(s) for s in input().split()]
MAX = M + 1
sq_max = int(math.sqrt(MAX))
seive = [1 for _ in range(MAX + 1)]
seive[0] = 0
seive[1] = 0
for i in range(sq_max + 1):
if seive[i] == 0:
continue
for j in range(i * 2, MAX + 1, i):
seive[j] = 0
def factor(num):
factordic = {}
for i in range(2, min([MAX + 1, int(math.sqrt(num)) + 1])):
if seive[i] == 1 and num % i == 0:
factordic[i] = 1
num //= i
while num % i == 0:
factordic[i] += 1
num //= i
if num == 1:
break
else:
factordic[num] = 1
return factordic
Mdic = factor(M)
# M=G*M2にわける(GはMとXの最大公約数)
# M2の約数の個数を取得
G = 1
divM2 = 1
for v, k in Mdic.items():
if X % v == 0:
G *= v**k
else:
divM2 *= (v - 1) * (v ** (k - 1))
# divM2の奇数部分の約数の個数を取得する
divM2dic = factor(divM2)
divdivM2 = 1
for v, k in divM2dic.items():
if v == 2:
continue
else:
divdivM2 *= (v - 1) * (v ** (k - 1))
# Mで割った余りを取得する
modls = [0 for _ in range(divdivM2 + 35)]
modls[0] = X
for i in range(1, divdivM2 + 35):
modls[i] = (modls[i - 1] ** 2) % M
ans = 0
# 初項から第34項まで足す
a = [0 for _ in range(34)]
a[0] = X
for i in range(1, min([N, 34])):
a[i] = (a[i - 1] ** 2) % M
ans += sum(a)
if N > 34:
if divM2 > 1:
# 第35項から先は、modGで0になっているはず
# divdivM2個ごとにループ
modls2 = modls[34:]
modls3 = modls2[:divdivM2]
total = sum(modls3)
ans += ((N - 34) // divdivM2) * total * G
ans += sum(modls3[: ((N - 34) % divdivM2) + 1]) * G
print(ans)
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s263140468 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | l = input().split()
n = int(l[0])
x = int(l[1])
m = int(l[2])
hashi = dict()
pref = 0
count = 0
prefix = []
for i in range(n):
if i == 0:
ans = x % m
else:
ans = ans * ans
ans %= m
if ans in hashi:
period = i - (hashi[ans][0])
num1 = hashi[ans][0]
k = (n - num1) // period
rem = n - (num1 + k * period)
count = count + prefix[num1]
count = count + k * (pref - hashi[ans][1])
for j in range(rem):
if j != 0:
ans = ans * ans
ans %= m
count += ans
break
hashi[ans] = (i, pref)
prefix.append(pref)
pref += ans
print(max(pref, count))
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s087125365 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | def e_sequence_sum():
N, X, M = [int(i) for i in input().split()]
appear = set([X])
seq = [X]
while True:
seq.append(seq[-1] ** 2 % M)
if seq[-1] in appear:
break
appear.add(seq[-1])
loop_length = len(seq) - seq.index(seq[-1]) - 1
seq.pop()
first, loop = seq[:-loop_length], seq[-loop_length:]
loop_count, reminder = divmod(N - len(first), loop_length)
ans = sum(first) + sum(loop) * loop_count
for i in range(reminder):
ans += loop[i % reminder]
return ans
print(e_sequence_sum())
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s385191204 | Accepted | p02550 | Input is given from Standard Input in the following format:
N X M | # by the authority of GOD author: manhar singh sachdev #
import os, sys
from io import BytesIO, IOBase
def main():
n, x, m = map(int, input().split())
val, se = [x], {x}
y = pow(x, 2, m)
while len(val) != n and y not in se:
val.append(y)
se.add(y)
y = pow(y, 2, m)
if len(val) == n:
print(sum(val))
else:
ans = sum(val)
n -= len(val)
ind = 0
for i in range(len(val)):
if val[i] == y:
ind = i
break
val = val[ind:]
xxx = sum(val)
ans += xxx * (n // len(val))
ans += sum(val[: n % len(val)])
print(ans)
# Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s878889538 | Runtime Error | p02550 | Input is given from Standard Input in the following format:
N X M | N, X, M = map(int, input().split())
A = [0] * M
S = 0
r = X
A[r - 1] = 1
d = 0
for i in range(1, M):
r = (r * r) % M
if A[r - 1] == 0:
A[r - 1] = i + 1
else:
I = A[r - 1]
j = i + 1
d = j - I
break
r = X
for i in range(I):
S += r
r = (r * r) % M
if d != 0:
t, u = (N - I) // d, (N - I) % d
s = 0
for i in range(d):
s += r
r = (r * r) % M
S += s * t
for i in range(u):
S += r
r = (r * r) % M
print(S)
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print \displaystyle{\sum_{i=1}^N A_i}.
* * * | s020594870 | Wrong Answer | p02550 | Input is given from Standard Input in the following format:
N X M | S = list(map(int, input().split()))
a = [S[1]]
for i in range(0, S[0] - 1):
a.append(((a[i] ** 2) % (10**9 + 7)) % S[2])
print(sum(a))
| Statement
Let us denote by f(x, m) the remainder of the Euclidean division of x by m.
Let A be the sequence that is defined by the initial value A_1=X and the
recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N
A_i}. | [{"input": "6 2 1001", "output": "1369\n \n\nThe sequence A begins 2,4,16,256,471,620,\\ldots Therefore, the answer is\n2+4+16+256+471+620=1369.\n\n* * *"}, {"input": "1000 2 16", "output": "6\n \n\nThe sequence A begins 2,4,0,0,\\ldots Therefore, the answer is 6.\n\n* * *"}, {"input": "10000000000 10 99959", "output": "492443256176507"}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s192908642 | Accepted | p02415 | A string is given in a line. | str_row = input()
print(str_row.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s986835588 | Accepted | p02415 | A string is given in a line. | arr = str(input())
print(arr.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s032786887 | Accepted | p02415 | A string is given in a line. | c = list(map(str, input().split()))
r = []
for i in c:
r.append(i.swapcase())
print(*r)
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s013326923 | Accepted | p02415 | A string is given in a line. | print("".join(map(lambda x: [x.upper(), x.lower()][x.isupper()], input())))
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s765025033 | Accepted | p02415 | A string is given in a line. | letter = str(input())
print(letter.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s991993018 | Accepted | p02415 | A string is given in a line. | input_data = str(input())
print(input_data.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s712651017 | Wrong Answer | p02415 | A string is given in a line. | sentence = input()
print(sentence.upper())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s826456481 | Runtime Error | p02415 | A string is given in a line. | a = [str(i) for i in range("a, z")]
a.upper()
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s952618245 | Runtime Error | p02415 | A string is given in a line. | print(" ".swapcase()) < 1200
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s671768876 | Runtime Error | p02415 | A string is given in a line. | print(" ".swapcase(1200))
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s191211000 | Runtime Error | p02415 | A string is given in a line. | print(input).swapcase()
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s773552483 | Runtime Error | p02415 | A string is given in a line. | print(" ".swap())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s522906083 | Wrong Answer | p02415 | A string is given in a line. | Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] | |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s731813172 | Accepted | p02415 | A string is given in a line. | l = input()
print(l.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s300636761 | Accepted | p02415 | A string is given in a line. | print(str(input()).swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s500843100 | Wrong Answer | p02415 | A string is given in a line. | char = input()
print(char.lower())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s548088707 | Accepted | p02415 | A string is given in a line. | letters = input()
print(letters.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s759309525 | Accepted | p02415 | A string is given in a line. | l = [c.lower() if c.isupper() else c.upper() for c in list(input())]
print(''.join(l)) | Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s135101613 | Wrong Answer | p02415 | A string is given in a line. | print("fAIR, LATER, OCCASIONALLY CLOUDY".swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s096011606 | Wrong Answer | p02415 | A string is given in a line. | print("1200".swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s024251238 | Wrong Answer | p02415 | A string is given in a line. | print("Aa".swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s291064544 | Wrong Answer | p02415 | A string is given in a line. | print("".swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s902003944 | Accepted | p02415 | A string is given in a line. | str = list(input())
for i in range(len(str)):
if str[i].islower():
str[i] = str[i].upper()
elif str[i].isupper():
str[i] = str[i].lower()
for i in range(len(str)):
print(str[i], end="")
print()
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s192981135 | Wrong Answer | p02415 | A string is given in a line. | string = input()
if len(string) == 1:
print(string)
else:
for i in range(len(string)):
if string[i].isupper():
string = string.replace(string[i], string[i].lower(), 1)
elif string[i].islower():
string = string.replace(string[i], string[i].upper(), 1)
print(string)
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s623767485 | Accepted | p02415 | A string is given in a line. | box = input()
print(box.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s959789486 | Accepted | p02415 | A string is given in a line. | input_str = input()
print(input_str.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s887394764 | Accepted | p02415 | A string is given in a line. | inStr = input()
outStr = inStr.swapcase()
print(outStr)
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s906878632 | Accepted | p02415 | A string is given in a line. | m = str(input())
print(m.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s104464733 | Accepted | p02415 | A string is given in a line. | t = input()
print(t.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s207429303 | Accepted | p02415 | A string is given in a line. | text = input().swapcase()
print(text)
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s016090184 | Accepted | p02415 | A string is given in a line. | str1 = input()
print(str1.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s777394985 | Accepted | p02415 | A string is given in a line. | str = input().swapcase()
print(str)
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s379064355 | Wrong Answer | p02415 | A string is given in a line. | words = input().split()
for word in words:
print(word.swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s524237083 | Wrong Answer | p02415 | A string is given in a line. | print("abcDEFghi".swapcase())
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s422252010 | Accepted | p02415 | A string is given in a line. | import re
# Input
words = list(input().split(" "))
# Loops
new = []
for word in words:
new_word = ""
for ch in word:
if re.match("[a-z]", ch):
new_word = new_word + ch.upper()
elif re.match("[A-Z]", ch):
new_word = new_word + ch.lower()
else:
new_word = new_word + ch
new.append(new_word)
# Output
for i in range(len(new) - 1):
print(new[i], end=" ")
print(new[-1])
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print the converted string in a line. Note that you do not need to convert any
characters other than alphabetical letters. | s158561318 | Wrong Answer | p02415 | A string is given in a line. | string = input()
for i in range(len(string)):
if string[i].isupper():
string = string.replace(string[i], string[i].lower(), 1)
elif string[i].islower():
string = string.replace(string[i], string[i].upper(), 1)
print(string)
| Toggling Cases
Write a program which converts uppercase/lowercase letters to
lowercase/uppercase for a given string. | [{"input": "fAIR, LATER, OCCASIONALLY CLOUDY.", "output": "Fair, later, occasionally cloudy."}] |
Print c_r for each r, in the following format:
c_2 c_3 ... c_N
* * * | s359627305 | Wrong Answer | p03204 | Input is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1} | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = map(int, read().split())
AB = zip(m, m)
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
highest_v = [0] * (N + 1) # 親側(自身は含まない)の最大番号の頂点
for x in order[1:]:
p = parent[x]
h = highest_v[p]
if p < h:
highest_v[x] = h
else:
highest_v[x] = p
root = list(range(N + 1)) # 連結成分の最も根側
size = [1] * (N + 1)
for x in order[1:]:
p = parent[x]
if highest_v[p] < x:
continue
r = root[p]
root[x] = r
size[r] += 1
dp = [0] * (N + 1)
for x in order[1:]:
p = parent[x]
if root[x] == x:
dp[x] = dp[p] + size[x]
else:
dp[x] = dp[p]
print(" ".join(map(str, dp[2:])))
| Statement
Takahashi's office has N rooms. Each room has an ID from 1 to N. There are
also N-1 corridors, and the i-th corridor connects Room a_i and Room b_i. It
is known that we can travel between any two rooms using only these corridors.
Takahashi has got lost in one of the rooms. Let this room be r. He decides to
get back to his room, Room 1, by repeatedly traveling in the following manner:
* Travel to the room with the smallest ID among the rooms that are adjacent to the rooms already visited, but not visited yet.
Let c_r be the number of travels required to get back to Room 1. Find all of
c_2,c_3,...,c_N. Note that, no matter how many corridors he passes through in
a travel, it still counts as one travel. | [{"input": "6\n 1 5\n 5 6\n 6 2\n 6 3\n 6 4", "output": "5 5 5 1 5\n \n\nFor example, if Takahashi was lost in Room 2, he will travel as follows:\n\n * Travel to Room 6.\n * Travel to Room 3.\n * Travel to Room 4.\n * Travel to Room 5.\n * Travel to Room 1.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "1 2 3 4 5\n \n\n* * *"}, {"input": "10\n 1 5\n 5 6\n 6 10\n 6 4\n 10 3\n 10 8\n 8 2\n 4 7\n 4 9", "output": "7 5 3 1 3 4 7 4 5"}] |
Print c_r for each r, in the following format:
c_2 c_3 ... c_N
* * * | s745435544 | Wrong Answer | p03204 | Input is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1} | # -*- coding: utf-8 -*-
from collections import defaultdict, deque
from heapq import heappush, heappop, heapreplace
def solve():
N = int(input())
V = list(range(1, N + 1))
E = defaultdict(set)
for _ in range(N - 1):
a, b = map(int, input().split())
E[a].add(b)
E[b].add(a)
Q = [1]
while Q:
r = heappop(Q)
for s in E[r]:
E[s].discard(r)
heappush(Q, s)
# print(E)
Q = [1]
while Q:
r = heappop(Q)
R = E[r].copy()
while R:
s = R.pop()
P = E[s].copy()
s_ = {s} if isinstance(s, int) else set(s)
while P:
t = P.pop()
if t < (r if isinstance(r, int) else max(r)):
s_.add(t)
for u in E[t]:
P.add(u)
s__ = tuple(s_)
E[s__] = set(u for t in s_ for u in E.pop(t, {})) - s_
E[r].discard(s)
E[r].add(s__)
heappush(Q, s__)
# print(E)
E = dict(E)
C = defaultdict(int)
Q = [1]
while Q:
r = heappop(Q)
for s in E.get(r):
C[s] = C[r] + (1 if isinstance(r, int) else len(s))
heappush(Q, s)
# print(C)
D = [0 for _ in range(N - 1)]
for key in C:
if isinstance(key, tuple):
for i in key:
D[i - 2] = C[key]
# print(D)
res = " ".join([str(d) for d in D])
return str(res)
if __name__ == "__main__":
print(solve())
| Statement
Takahashi's office has N rooms. Each room has an ID from 1 to N. There are
also N-1 corridors, and the i-th corridor connects Room a_i and Room b_i. It
is known that we can travel between any two rooms using only these corridors.
Takahashi has got lost in one of the rooms. Let this room be r. He decides to
get back to his room, Room 1, by repeatedly traveling in the following manner:
* Travel to the room with the smallest ID among the rooms that are adjacent to the rooms already visited, but not visited yet.
Let c_r be the number of travels required to get back to Room 1. Find all of
c_2,c_3,...,c_N. Note that, no matter how many corridors he passes through in
a travel, it still counts as one travel. | [{"input": "6\n 1 5\n 5 6\n 6 2\n 6 3\n 6 4", "output": "5 5 5 1 5\n \n\nFor example, if Takahashi was lost in Room 2, he will travel as follows:\n\n * Travel to Room 6.\n * Travel to Room 3.\n * Travel to Room 4.\n * Travel to Room 5.\n * Travel to Room 1.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "1 2 3 4 5\n \n\n* * *"}, {"input": "10\n 1 5\n 5 6\n 6 10\n 6 4\n 10 3\n 10 8\n 8 2\n 4 7\n 4 9", "output": "7 5 3 1 3 4 7 4 5"}] |
Print c_r for each r, in the following format:
c_2 c_3 ... c_N
* * * | s161307014 | Runtime Error | p03204 | Input is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1} | import sys
def dfs1(v, p):
ret = 1
links[v].discard(p)
m = min(v, p)
for c in links[v]:
res = dfs1(c, v)
if c < m:
ret += res
subtree_costs[v] = ret
return ret
def dfs2(v, p, pc):
sc = pc + subtree_costs[v]
costs[v] = sc
m = min(v, p)
for c in links[v]:
if c < m:
dfs2(c, v, sc - subtree_costs[c])
else:
dfs2(c, v, sc)
n = int(input())
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
a, b = map(int, line.split())
a -= 1
b -= 1
links[a].add(b)
links[b].add(a)
link = [sorted(l) for l in links]
subtree_costs = [0] * n
dfs1(0, -1)
subtree_costs[0] = 0
costs = [0] * n
dfs2(0, -1, 0)
print(*costs[1:])
| Statement
Takahashi's office has N rooms. Each room has an ID from 1 to N. There are
also N-1 corridors, and the i-th corridor connects Room a_i and Room b_i. It
is known that we can travel between any two rooms using only these corridors.
Takahashi has got lost in one of the rooms. Let this room be r. He decides to
get back to his room, Room 1, by repeatedly traveling in the following manner:
* Travel to the room with the smallest ID among the rooms that are adjacent to the rooms already visited, but not visited yet.
Let c_r be the number of travels required to get back to Room 1. Find all of
c_2,c_3,...,c_N. Note that, no matter how many corridors he passes through in
a travel, it still counts as one travel. | [{"input": "6\n 1 5\n 5 6\n 6 2\n 6 3\n 6 4", "output": "5 5 5 1 5\n \n\nFor example, if Takahashi was lost in Room 2, he will travel as follows:\n\n * Travel to Room 6.\n * Travel to Room 3.\n * Travel to Room 4.\n * Travel to Room 5.\n * Travel to Room 1.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "1 2 3 4 5\n \n\n* * *"}, {"input": "10\n 1 5\n 5 6\n 6 10\n 6 4\n 10 3\n 10 8\n 8 2\n 4 7\n 4 9", "output": "7 5 3 1 3 4 7 4 5"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s823828862 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | def fun(n, num, count):
if count == (num * 2) - 1:
return
print(n, end=" ")
count += 1
fun(n + 1, num, count)
xnum = list(map(int, input().split()))
x = xnum[1]
num = xnum[0]
m = x - (num - 1)
fun(m, num, 0)
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s414916068 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | L = []
K, X = map(int, input().split())
if X - (K - 1) <= -1000000:
S = -1000000
for i in range(S, S + (K * 2 - 1)):
L.append(str(i))
print(" ".join(map(str, L)))
elif X + (K - 1) >= 1000000:
E = 1000000
for i in range(E, E - (K * 2 - 1), -1):
L.append(str(i))
print(" ".join(map(str, L)))
else:
S = X - (K - 1)
for i in range(S, S + (K * 2 - 1)):
L.append(str(i))
print(" ".join(map(str, L)))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s710718236 | Runtime Error | p02946 | Input is given from Standard Input in the following format:
K X | K, X = list(map(lambda n: int(n), input().split(" ")))
print(" ".join(list(range(K - X + 1, K + X - 1))))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s677319677 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | A, B = map(int, input().split())
cnt = 1
while A * cnt - (cnt - 1) < B:
cnt += 1
print(cnt)
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s101452697 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | kx = [int(i) for i in input().split()]
k, x = kx[0], kx[1]
c = k * 2 - 1
g = [j + x - k + 1 for j in range(c)]
print(g)
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s315605930 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | a = []
for x in input().split(" "):
a.append(int(x))
b = []
if a[1] - a[0] + 1 < -1000000:
i = -1000000
while i < a[1] + a[0]:
b.append(str(i))
i += 1
elif a[1] + a[0] - 1 > 1000000:
i = a[1] - a[0] + 1
while i < 1000000:
b.append(str(i))
i += 1
else:
i = a[1] - a[0] + 1
while i < a[1] + a[0]:
b.append(str(i))
i += 1
print(" ".join(b))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s635593120 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | k, x = [int(x) for x in input().split()]
black = list(range(x - k + 1, x + k))
print(black)
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s936584708 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | n = list(map(int, input().split()))
k = n[0]
x = n[1]
s1 = x - k + 1
s2 = x + k - 1
print(list(range((s1), (s2 + 1))))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s557743033 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | a, b = input().split()
a = int(a)
b = int(b)
min_stone = -1000000
max_stone = 1000000
ans_list = []
for i in range(max(min_stone, b - a + 1), min(max_stone, b + a)):
ans_list.append(str(i))
print(" ".join(ans_list))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s375195409 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | a, b = map(int, input().split())
mylist = []
for row in range(a):
c = row + b
mylist.append(c)
for row in range(a):
c = -row + b
mylist.append(c)
mylist = sorted(set(mylist))
for row in mylist:
print(row, end="")
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s494796535 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | """
4 0
0 -3
0 -2
0 -1
0 + 0
0 + 1
0 + 2
0 + 3
"""
a, b = map(int, input().split())
n = 0
w = (a - 1) * 2 + 1
while n < w:
x = (b - 1) * 2 - 1
print(n + x, end=" ")
n += 1
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s834348869 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | ko, x = map(int, input().split())
s = max(x - ko + 1, -1000000)
print(*list(range(x - ko + 1, x + ko)), sep=" ")
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s741760091 | Runtime Error | p02946 | Input is given from Standard Input in the following format:
K X | X = map(int, input().split())
for K in range(1, 100):
print(X - K)
for K in range(1, 100):
print(X + K)
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s772735249 | Runtime Error | p02946 | Input is given from Standard Input in the following format:
K X | K = int(input())
X = int(input())
s = X - K + 1
for i in range(2 * K - 1):
A = s + i
print(str(A) + " ")
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s053072058 | Runtime Error | p02946 | Input is given from Standard Input in the following format:
K X | K, X = input().split()
K, X = int(K), int(X)
print(" ".join([i for i in range(X - K + 1, X + K)]))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s209617940 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | k, x = map(int, input("").split(" "))
ans_array = []
for i in range(k - 1):
ans_array.append(x - (i + 1))
for i in range(k - 1):
ans_array.append(x + (i + 1))
ans_array.append(x)
ans_array.sort()
for i in range(len(ans_array)):
if i == 0:
ans = str(ans_array[i])
else:
ans += " "
ans += str(ans_array[i])
print(ans)
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s510178377 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | a = []
tmp = []
A, B = map(int, input().split())
b = B - (A - 1)
for i in range(3 * 2 - 1):
if A == 1:
a.append(B)
else:
a.append(b + i)
while a:
e = a.pop()
if e <= 10000000 and e >= -10000000:
tmp.append(e)
tmp = sorted(tmp)
tmp = [str(n) for n in tmp]
p = " ".join(tmp)
print(p)
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s324262704 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | n = list(int(i) for i in input().split())
print(range(n[1] - n[0] + 1, n[1] + n[0] - 1))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s705032123 | Runtime Error | p02946 | Input is given from Standard Input in the following format:
K X | k, x = input().split()
print(*list(range(x - k + 1, x + k)))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s935006475 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | n, k = map(int, input().split())
s1 = set()
s2 = set()
for i in range(n):
s1.add(k - i)
for j in range(n):
s2.add(k + j)
print(" ".join(map(str, sorted(s1 | s2))))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s629135120 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | K, X = [int(item) for item in input().split()]
first = max(-1000000, X - K + 1)
last = min(1000000, X + K - 1)
print(" ".join([str(item) for item in range(first, last + 1)]))
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s206077858 | Wrong Answer | p02946 | Input is given from Standard Input in the following format:
K X | N, place = map(int, input().split())
# place-N+1~place+N-1を出力すればいい
for x in range(place - N + 1, place + N - 1):
print(x, end=" ")
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print all coordinates that potentially contain a stone painted black, in
ascending order, with spaces in between.
* * * | s415514058 | Accepted | p02946 | Input is given from Standard Input in the following format:
K X | k, x = map(int, input().split(" "))
if x - k + 1 <= -100000:
for i in range(0, k):
print(-100000 + i, sep=" ", end=" ")
elif x + k - 1 >= 100000:
for i in range(0, k):
print(100000 - i, sep=" ", end=" ")
else:
for i in range(k, 1, -1):
print(x - i + 1, sep=" ", end=" ")
for i in range(0, k):
print(x + i, sep=" ", end=" ")
| Statement
There are 2000001 stones placed on a number line. The coordinates of these
stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are
painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in
ascending order. | [{"input": "3 7", "output": "5 6 7 8 9\n \n\nWe know that there are three stones painted black, and the stone at coordinate\n7 is painted black. There are three possible cases:\n\n * The three stones painted black are placed at coordinates 5, 6, and 7.\n * The three stones painted black are placed at coordinates 6, 7, and 8.\n * The three stones painted black are placed at coordinates 7, 8, and 9.\n\nThus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8,\nand 9.\n\n* * *"}, {"input": "4 0", "output": "-3 -2 -1 0 1 2 3\n \n\nNegative coordinates can also contain a stone painted black.\n\n* * *"}, {"input": "1 100", "output": "100"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s479243114 | Accepted | p02696 | Input is given from Standard Input in the following format:
A B N | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
a, b, n = map(int, input().split())
ans = 0
m = n
ans = max(ans, (a * m) // b - a * (m // b))
m = (n // b) * b - 1
m = max(m, 0)
# print(n,m)
ans = max(ans, (a * m) // b - a * (m // b))
print(ans)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s859780627 | Wrong Answer | p02696 | Input is given from Standard Input in the following format:
A B N | n, m, k = [int(e) for e in input().split()]
mx = 0
wk = n
for i in range(1, k + 1):
a = (wk * i) // m
if mx < a:
mx = a
print(mx)
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s925921549 | Wrong Answer | p02696 | Input is given from Standard Input in the following format:
A B N | a, b, n = map(int, input().split())
sumtemp = 0
summax = 0
for x in range(1, b):
sumtemp = int(a * x / b) - a * int(x / b)
if sumtemp > summax:
summax = sumtemp
print(sumtemp)
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s331972966 | Wrong Answer | p02696 | Input is given from Standard Input in the following format:
A B N | a, b, n = map(int, input().split())
Max = 0
e = 1 / b
ae = a * e
axb = 0
xb = 0
temp = 0
h_cut = 0
u_cut = 0
for i in range(n):
axb += ae
xb += e
h_cut = axb - int(axb)
u_cut = (xb - int(xb)) * a
temp = int(u_cut - h_cut)
Max = max(Max, temp)
else:
print(Max)
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s234837432 | Wrong Answer | p02696 | Input is given from Standard Input in the following format:
A B N | a, b, n = map(int, input().split())
maxi = 0
ele = 0
for i in range(n, n - 1000000, -1):
val = int((a * i) / b) - (a * int(i / b))
if val > maxi:
maxi = val
ele = i
print(maxi)
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s359125970 | Wrong Answer | p02696 | Input is given from Standard Input in the following format:
A B N | print(1)
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s847197919 | Accepted | p02696 | Input is given from Standard Input in the following format:
A B N | a, b, n = map(int, input().split())
m = b - 1
if m > n:
m = n
print(int((a * m - a * m % b) / b - a * ((m - m % b) / b)))
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s922566407 | Accepted | p02696 | Input is given from Standard Input in the following format:
A B N | a, b, n = map(int, input().split())
ans = (a * n) // b - a * (n // b)
if n >= 1:
ans2 = (a * (n - 1)) // b - a * ((n - 1) // b)
else:
ans2 = 0
if n >= 2:
ans3 = (a * (n - 2)) // b - a * ((n - 2) // b)
else:
ans3 = 0
if n >= 3:
ans4 = (a * (n - 3)) // b - a * ((n - 3) // b)
else:
ans4 = 0
if b <= n:
ans5 = (a * (b - 1)) // b - a * ((b - 1) // b)
else:
ans5 = 0
print(max(ans, ans2, ans3, ans4, ans5))
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s874265964 | Wrong Answer | p02696 | Input is given from Standard Input in the following format:
A B N | A = list(map(int, input().split())) # 入力のときに N を使う必要はありません
i_max = 0
i_count = 0
j_count = 1
for x in range(1, A[2] + 1):
if i_max < ((A[0] * x) // A[1] - A[0] * (x // A[1])):
i_max = (A[0] * x) // A[1] - A[0] * (x // A[1])
i_count = x
if (x - i_count) == 1:
j_count = j_count + 1
if j_count == 2:
break
print(i_count)
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s571643230 | Wrong Answer | p02696 | Input is given from Standard Input in the following format:
A B N | print(0)
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N, as an integer.
* * * | s522227941 | Runtime Error | p02696 | Input is given from Standard Input in the following format:
A B N | a, b, n = map(int, input().split())
List = list(range(n + 1))
List_ans = []
for list in List:
List_ans.append(int(a * list / b) - a * int(list / b))
print(max(List_ans))
| Statement
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-
negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t. | [{"input": "5 7 4", "output": "2\n \n\nWhen x=3, floor(Ax/B)-A\u00d7floor(x/B) = floor(15/7) - 5\u00d7floor(3/7) = 2. This is\nthe maximum value possible.\n\n* * *"}, {"input": "11 10 9", "output": "9"}] |
Print Q lines. The i-th line should contain the answer to the i-th query.
* * * | s147426678 | Wrong Answer | p03087 | Input is given from Standard Input in the following format:
N Q
S
l_1 r_1
:
l_Q r_Q | # データ構造:ヒープ
import heapq
class heapque:
def __init__(self, *args):
self.que = []
for arg in args:
self.push(arg)
def push(self, v):
heapq.heappush(self.que, v)
def pop(self):
return heapq.heappop(self.que)
# 定数
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
return int(n) - 1
# エントリーポイント
def main():
N, Q = map(int, input().split())
S = input()
LR = tuple(map(int1, input().split()) for _ in range(Q))
add_sum = [0]
for n in range(1, N):
add_sum += [add_sum[-1] + (S[n - 1 : n + 1] == "AC")]
print(add_sum)
for l, r in LR:
print(add_sum[r] - add_sum[l])
main()
| Statement
You are given a string S of length N consisting of `A`, `C`, `G` and `T`.
Answer the following Q queries:
* Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does `AC` occurs as a substring? | [{"input": "8 3\n ACACTACG\n 3 7\n 2 3\n 1 8", "output": "2\n 0\n 3\n \n\n * Query 1: the substring of S starting at index 3 and ending at index 7 is `ACTAC`. In this string, `AC` occurs twice as a substring.\n * Query 2: the substring of S starting at index 2 and ending at index 3 is `CA`. In this string, `AC` occurs zero times as a substring.\n * Query 3: the substring of S starting at index 1 and ending at index 8 is `ACACTACG`. In this string, `AC` occurs three times as a substring."}] |
Print Q lines. The i-th line should contain the answer to the i-th query.
* * * | s438179690 | Wrong Answer | p03087 | Input is given from Standard Input in the following format:
N Q
S
l_1 r_1
:
l_Q r_Q | # coding: utf-8
import sys
import itertools
def sr():
return sys.stdin.readline().rstrip()
def ir():
return int(sr())
def lr():
return list(map(int, sr().split()))
N, Q = lr()
S = sr()
ac = [0] * (N - 1)
for i, x in enumerate(zip(S[:], S[1:])):
if x[0] == "A" and x[1] == "C":
ac[i] = 1
cum = list(itertools.accumulate(ac))
ans_list = []
for _ in range(Q):
l, r = lr()
result = cum[r - 2] - cum[l - 1] + 1
if cum[r - 2] == cum[l - 1]:
result = 0
ans_list.append(result)
[print(ans) for ans in ans_list]
| Statement
You are given a string S of length N consisting of `A`, `C`, `G` and `T`.
Answer the following Q queries:
* Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does `AC` occurs as a substring? | [{"input": "8 3\n ACACTACG\n 3 7\n 2 3\n 1 8", "output": "2\n 0\n 3\n \n\n * Query 1: the substring of S starting at index 3 and ending at index 7 is `ACTAC`. In this string, `AC` occurs twice as a substring.\n * Query 2: the substring of S starting at index 2 and ending at index 3 is `CA`. In this string, `AC` occurs zero times as a substring.\n * Query 3: the substring of S starting at index 1 and ending at index 8 is `ACACTACG`. In this string, `AC` occurs three times as a substring."}] |
Print Q lines. The i-th line should contain the answer to the i-th query.
* * * | s587043719 | Runtime Error | p03087 | Input is given from Standard Input in the following format:
N Q
S
l_1 r_1
:
l_Q r_Q | import sys
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return input()
from itertools import product
def main():
N = II()
A, G, C, T = range(4)
def code(c0, c1, c2):
return c0 + 4 * c1 + 16 * c2
dp = [0] * 64
dp[code(T, T, T)] = 1
for _ in range(N):
tmp = [0] * 64
for p1, p2, p3 in product(range(4), repeat=3):
for cur in range(4):
if (p2, p1, cur) == (A, G, C):
continue
if (p2, p1, cur) == (A, C, G):
continue
if (p2, p1, cur) == (G, A, C):
continue
if (p3, p1, cur) == (A, G, C):
continue
if (p3, p2, cur) == (A, G, C):
continue
tmp[code(cur, p1, p2)] += dp[code(p1, p2, p3)]
tmp[code(cur, p1, p2)] %= MOD
dp = tmp
ans = sum(dp)
return ans % MOD
print(main())
| Statement
You are given a string S of length N consisting of `A`, `C`, `G` and `T`.
Answer the following Q queries:
* Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does `AC` occurs as a substring? | [{"input": "8 3\n ACACTACG\n 3 7\n 2 3\n 1 8", "output": "2\n 0\n 3\n \n\n * Query 1: the substring of S starting at index 3 and ending at index 7 is `ACTAC`. In this string, `AC` occurs twice as a substring.\n * Query 2: the substring of S starting at index 2 and ending at index 3 is `CA`. In this string, `AC` occurs zero times as a substring.\n * Query 3: the substring of S starting at index 1 and ending at index 8 is `ACACTACG`. In this string, `AC` occurs three times as a substring."}] |
Print Q lines. The i-th line should contain the answer to the i-th query.
* * * | s171510993 | Wrong Answer | p03087 | Input is given from Standard Input in the following format:
N Q
S
l_1 r_1
:
l_Q r_Q | n, q = map(int, input().split())
l = [0 for i in range(n)]
for i, v in enumerate(list(input().replace("AC", "X!"))):
l[i] = l[i - 1] + (v == "!")
print(l)
for c in range(q):
h, m = map(int, input().split())
print(l[m - 1] - l[max(h - 2, 0)])
| Statement
You are given a string S of length N consisting of `A`, `C`, `G` and `T`.
Answer the following Q queries:
* Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does `AC` occurs as a substring? | [{"input": "8 3\n ACACTACG\n 3 7\n 2 3\n 1 8", "output": "2\n 0\n 3\n \n\n * Query 1: the substring of S starting at index 3 and ending at index 7 is `ACTAC`. In this string, `AC` occurs twice as a substring.\n * Query 2: the substring of S starting at index 2 and ending at index 3 is `CA`. In this string, `AC` occurs zero times as a substring.\n * Query 3: the substring of S starting at index 1 and ending at index 8 is `ACACTACG`. In this string, `AC` occurs three times as a substring."}] |
Print Q lines. The i-th line should contain the answer to the i-th query.
* * * | s661880603 | Runtime Error | p03087 | Input is given from Standard Input in the following format:
N Q
S
l_1 r_1
:
l_Q r_Q | cho, N = map(int, input().split())
moji = str(input())
moji_dict = []
flg = 0
##計算量は10**5
for i in range(cho):
if flg == 1:
flg = 0
elif i != cho and moji[i] == "A" and moji[i + 1] == "C":
moji_dict.append(i + 1)
flg = 1
##計算量は10**3 * 10 ** 5
for j in range(N):
s, g = map(int, input().split())
print(len([k for k in moji_dict if k >= s and k < g]))
| Statement
You are given a string S of length N consisting of `A`, `C`, `G` and `T`.
Answer the following Q queries:
* Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does `AC` occurs as a substring? | [{"input": "8 3\n ACACTACG\n 3 7\n 2 3\n 1 8", "output": "2\n 0\n 3\n \n\n * Query 1: the substring of S starting at index 3 and ending at index 7 is `ACTAC`. In this string, `AC` occurs twice as a substring.\n * Query 2: the substring of S starting at index 2 and ending at index 3 is `CA`. In this string, `AC` occurs zero times as a substring.\n * Query 3: the substring of S starting at index 1 and ending at index 8 is `ACACTACG`. In this string, `AC` occurs three times as a substring."}] |
Print Q lines. The i-th line should contain the answer to the i-th query.
* * * | s481505412 | Wrong Answer | p03087 | Input is given from Standard Input in the following format:
N Q
S
l_1 r_1
:
l_Q r_Q | NandQ = input() # 文字列の長さ&質問の個数
S = str(input()) # 文字列
ListNandQ = NandQ.split()
N = int(ListNandQ[0])
Q = int(ListNandQ[1])
for i in range(0, Q, 1):
LandR = input() # 質問の入力受付
ListLandR = LandR.split()
L = int(ListLandR[0])
R = int(ListLandR[1])
moji = S[L - 1 : R - 1] # 文字列の取り出し
print(int(moji.count("AC")))
| Statement
You are given a string S of length N consisting of `A`, `C`, `G` and `T`.
Answer the following Q queries:
* Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does `AC` occurs as a substring? | [{"input": "8 3\n ACACTACG\n 3 7\n 2 3\n 1 8", "output": "2\n 0\n 3\n \n\n * Query 1: the substring of S starting at index 3 and ending at index 7 is `ACTAC`. In this string, `AC` occurs twice as a substring.\n * Query 2: the substring of S starting at index 2 and ending at index 3 is `CA`. In this string, `AC` occurs zero times as a substring.\n * Query 3: the substring of S starting at index 1 and ending at index 8 is `ACACTACG`. In this string, `AC` occurs three times as a substring."}] |
For each dataset, output _p_ lines, the _i_ -th of which contains the number
of holes punched in the paper by the _i_ -th punching instruction. | s482095810 | Runtime Error | p01110 | The input consists of at most 1000 datasets, each in the following format.
> _n_ _m_ _t_ _p_
> _d_ 1 _c_ 1
> ...
> _d t_ _c t_
> _x_ 1 _y_ 1
> ...
> _x p_ _y p_
>
_n_ and _m_ are the width and the height, respectively, of a rectangular piece
of paper. They are positive integers at most 32. _t_ and _p_ are the numbers
of folding and punching instructions, respectively. They are positive integers
at most 20. The pair of _d i_ and _c i_ gives the _i_ -th folding instruction
as follows:
* _d i_ is either 1 or 2.
* _c i_ is a positive integer.
* If _d i_ is 1, the left-hand side of the vertical folding line that passes at _c i_ right to the left boundary is folded onto the right-hand side.
* If _d i_ is 2, the lower side of the horizontal folding line that passes at _c i_ above the lower boundary is folded onto the upper side.
After performing the first _i_ −1 folding instructions, if _d i_ is 1, the
width of the shape is greater than _c i_. Otherwise the height is greater than
_c i_. (_x i_ \+ 1/2, _y i_ \+ 1/2) gives the coordinates of the point where
the _i_ -th punching instruction is performed. The origin (0, 0) is at the
bottom left of the finally obtained shape. _x i_ and _y i_ are both non-
negative integers and they are less than the width and the height,
respectively, of the shape. You can assume that no two punching instructions
punch holes at the same location.
The end of the input is indicated by a line containing four zeros. | from operator import add
def fold_right(v, length):
for i in range(len(v[0])):
if not any(list(zip(*v))[i]):
continue
for j in range(length):
for yoko in range(len(v)):
v[yoko][i + j + length] += v[yoko][i + j]
v[yoko][i + j] = 0
return v
def fold_up(v, length):
for i in range(len(v) - 1, -1, -1):
if not any(v[i]):
continue
for j in range(length):
v[i - j - length] = list(map(add, v[i - j - length], v[i - j]))
v[i - j] = [0] * len(v[i - j])
return v
def cut_cut_cut(v, x, y):
for i in range(len(v) - 1, -1, -1):
if not any(v[i]):
continue
y = i - y
break
for i in range(len(v[0])):
if not any(list(zip(*v))[i]):
continue
x = i + x
break
return v[y][x]
while True:
n, m, t, p = map(int, input().split())
if n == 0 and m == 0 and t == 0 and p == 0:
break
origami = [[0] * 63 for _ in range(63)]
for i in range(m):
for j in range(n):
origami[len(origami) - 1 - i][j] = 1
for i in range(t):
d, c = map(int, input().split())
if d == 1:
origami = fold_right(origami, c)
else:
origami = fold_up(origami, c)
# print(*origami, sep="\n")
# print()
for i in range(p):
x, y = map(int, input().split())
print(cut_cut_cut(origami, x, y))
| Origami, or the art of folding paper
Master Grus is a famous _origami_ (paper folding) artist, who is enthusiastic
about exploring the possibility of origami art. For future creation, he is now
planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it
horizontally and/or vertically several times and then punches through holes in
the folded paper.
The following figure illustrates the folding process of a simple experiment,
which corresponds to the third dataset of the Sample Input below. Folding the
10 × 8 rectangular piece of paper shown at top left three times results in the
6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate
the locations to fold the paper and round arrows indicate the directions of
folding. Grid lines are shown as solid lines to tell the sizes of rectangular
shapes and the exact locations of folding. Color densities represent the
numbers of overlapping layers. Punching through holes at A and B in the folded
paper makes nine holes in the paper, eight at A and another at B.

Your mission in this problem is to write a computer program to count the
number of holes in the paper, given the information on a rectangular piece of
paper and folding and punching instructions. | [{"input": "1 1 1\n 1 1\n 0 0\n 1 3 2 1\n 2 1\n 2 1\n 0 0\n 10 8 3 2\n 2 2\n 1 3\n 1 1\n 0 1\n 3 4\n 3 3 3 2\n 1 2\n 2 1\n 1 1\n 0 1\n 0 0\n 0 0 0 0", "output": "3\n 8\n 1\n 3\n 6"}] |
For each dataset, output _p_ lines, the _i_ -th of which contains the number
of holes punched in the paper by the _i_ -th punching instruction. | s589716568 | Wrong Answer | p01110 | The input consists of at most 1000 datasets, each in the following format.
> _n_ _m_ _t_ _p_
> _d_ 1 _c_ 1
> ...
> _d t_ _c t_
> _x_ 1 _y_ 1
> ...
> _x p_ _y p_
>
_n_ and _m_ are the width and the height, respectively, of a rectangular piece
of paper. They are positive integers at most 32. _t_ and _p_ are the numbers
of folding and punching instructions, respectively. They are positive integers
at most 20. The pair of _d i_ and _c i_ gives the _i_ -th folding instruction
as follows:
* _d i_ is either 1 or 2.
* _c i_ is a positive integer.
* If _d i_ is 1, the left-hand side of the vertical folding line that passes at _c i_ right to the left boundary is folded onto the right-hand side.
* If _d i_ is 2, the lower side of the horizontal folding line that passes at _c i_ above the lower boundary is folded onto the upper side.
After performing the first _i_ −1 folding instructions, if _d i_ is 1, the
width of the shape is greater than _c i_. Otherwise the height is greater than
_c i_. (_x i_ \+ 1/2, _y i_ \+ 1/2) gives the coordinates of the point where
the _i_ -th punching instruction is performed. The origin (0, 0) is at the
bottom left of the finally obtained shape. _x i_ and _y i_ are both non-
negative integers and they are less than the width and the height,
respectively, of the shape. You can assume that no two punching instructions
punch holes at the same location.
The end of the input is indicated by a line containing four zeros. | #!/usr/bin/python3
# coding: utf-8
MAX_V = 70
# デバッグ用の関数
def show(origami):
for i in range(MAX_V):
for j in range(MAX_V):
print(origami[i][j], end=" ")
print()
print("--------------------------------------")
# 右に c だけ折り返す処理
def fold_a(origami, c):
t = c
for i in range(c):
for j in range(MAX_V):
origami[j][t + i] += origami[j][t - i - 1]
origami[j][t - i - 1] = 0
copy = [x[:] for x in origami]
for i in range(MAX_V):
for j in range(MAX_V):
if j - c < 0 or MAX_V - 1 < j - c:
continue
origami[i][j - c] = copy[i][j]
# 上に c だけ折り返す処理
def fold_b(origami, c):
t = MAX_V - c - 1
for i in range(MAX_V):
for j in range(c):
origami[t - j][i] += origami[t + j + 1][i]
origami[t + j + 1][i] = 0
copy = [x[:] for x in origami]
for i in range(MAX_V):
for j in range(MAX_V):
if i + c < 0 or MAX_V - 1 < i + c:
continue
origami[i + c][j] = copy[i][j]
def main():
while True:
n, m, t, p = map(int, input().split())
origami = [[0 for i in range(MAX_V)] for _ in range(MAX_V)]
for i in range(n):
for j in range(m):
origami[-1 - j][i] = 1
if n == 0 and m == 0 and t == 0 and p == 0:
break
for _ in range(t):
d, c = map(int, input().split())
if d == 1:
fold_a(origami, c)
if d == 2:
fold_b(origami, c)
for _ in range(p):
x, y = map(int, input().split())
print(origami[MAX_V - y - 1][x])
return 0
main()
| Origami, or the art of folding paper
Master Grus is a famous _origami_ (paper folding) artist, who is enthusiastic
about exploring the possibility of origami art. For future creation, he is now
planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it
horizontally and/or vertically several times and then punches through holes in
the folded paper.
The following figure illustrates the folding process of a simple experiment,
which corresponds to the third dataset of the Sample Input below. Folding the
10 × 8 rectangular piece of paper shown at top left three times results in the
6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate
the locations to fold the paper and round arrows indicate the directions of
folding. Grid lines are shown as solid lines to tell the sizes of rectangular
shapes and the exact locations of folding. Color densities represent the
numbers of overlapping layers. Punching through holes at A and B in the folded
paper makes nine holes in the paper, eight at A and another at B.

Your mission in this problem is to write a computer program to count the
number of holes in the paper, given the information on a rectangular piece of
paper and folding and punching instructions. | [{"input": "1 1 1\n 1 1\n 0 0\n 1 3 2 1\n 2 1\n 2 1\n 0 0\n 10 8 3 2\n 2 2\n 1 3\n 1 1\n 0 1\n 3 4\n 3 3 3 2\n 1 2\n 2 1\n 1 1\n 0 1\n 0 0\n 0 0 0 0", "output": "3\n 8\n 1\n 3\n 6"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.