output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s636083082 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | A,B,C,D = input().split(' ')
A,B,C,D = [int(A),int(B),int(C),int(D)]
L= A + B
R = C + D
if L>R:
print("Left")
elif L=R:
print("Balanced")
else:
print("Right")
| Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s625592433 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | s = input()
slist = s.split(' ')
left = slist[0] + slist[1]
right = slist[2] + slist[3]
if left > right:
print('left')
else if left == right:
print('Balanced')
else:
print('right) | Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s444370997 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | n, a, b = [int(input()) for i in range(3)]
t = 0
for i in range(1, n + 1):
orign = i
total = 0
for ii in range(len(str(i))):
total += i % 10
i = int(i / 10)
if total >= a and total <= b:
t += orign
print(t)
| Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s016382617 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | n, a, b = input().split()
nn = [0] * 4
x = 0
for i in range(
1,
n + 1,
1,
):
nn = len(i)
y = nn[0] + nn[1] + nn[2] + nn[3]
if (y >= a) and (y <= b):
x = x + y
print(x)
| Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s140420240 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | 1 7 6 4 | Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s138792903 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | a, b, c, d = map(int, input().split())
l = a+b
r = c+d
print("Left" if l > r "Right" elif l < r else "Balanced") | Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s406107855 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | A, B, C, D = map( int, input()split())
L = A + B
R = C + D
if( L < R):
print('Right')
else:
print('Left') | Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s549195883 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | A, B, C, D = map(int, input().split())
print('Left' if A + B > C + D else 'Balanced' if A + B = C + D else 'Right') | Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s352137486 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | a,b,c,d=map(int,input().split());print('Left' if a+b>c+d elif a+b<c+d 'Right' else 'Balanced') | Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s027022527 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | print(48 - int(input()))
| Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right.
* * * | s882455803 | Runtime Error | p03477 | Input is given from Standard Input in the following format:
A B C D | A,B,C,D = map(int,input().split())
if A+B = C+D:
print('Balanced')
elif A+B > C+D:
print('Left')
else:
print('Right') | Statement
A balance scale tips to the left if L>R, where L is the total weight of the
masses on the left pan and R is the total weight of the masses on the right
pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of
a balance scale, and placed a mass of weight C and a mass of weight D on the
right pan.
Print `Left` if the balance scale tips to the left; print `Balanced` if it
balances; print `Right` if it tips to the right. | [{"input": "3 8 7 1", "output": "Left\n \n\nThe total weight of the masses on the left pan is 11, and the total weight of\nthe masses on the right pan is 8. Since 11>8, we should print `Left`.\n\n* * *"}, {"input": "3 4 5 2", "output": "Balanced\n \n\nThe total weight of the masses on the left pan is 7, and the total weight of\nthe masses on the right pan is 7. Since 7=7, we should print `Balanced`.\n\n* * *"}, {"input": "1 7 6 4", "output": "Right\n \n\nThe total weight of the masses on the left pan is 8, and the total weight of\nthe masses on the right pan is 10. Since 8<10, we should print `Right`."}] |
Print the number of strings, modulo 998244353, that can result from applying
the operation on S zero or more times.
* * * | s523374349 | Runtime Error | p02636 | Input is given from Standard Input in the following format:
S | def cmb(n, r, mod): # コンビネーションの高速計算
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 998244353
N = 2 * 10**3
g1 = [1] * (N + 1) # 元テーブル
g2 = [1] * (N + 1) # 逆元テーブル
inverse = [1] * (N + 1) # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1[i] = (g1[i - 1] * i) % mod
inverse[i] = (-inverse[mod % i] * (mod // i)) % mod
g2[i] = (g2[i - 1] * inverse[i]) % mod
inverse[0] = 0
S = input()
N = len(S)
dp = [[[-(10**5) for i in range(N + 2)] for j in range(N + 2)] for k in range(N + 1)]
dpf = [[[-(10**5) for i in range(N + 2)] for j in range(N + 2)] for k in range(N + 1)]
dpf[0][0][0] = 1
if S[0] == "0":
dpf[1][1][0] = 0
if S[1] == "0":
dp[1][1][0] = 0
if S[0] == "1":
dpf[1][0][1] = 0
if S[1] == "1":
dp[1][0][1] = 0
dpf[1][0][0] = 2
for i in range(2, N):
for j in range(N + 1):
for k in range(N + 1):
a, b = 1 - int(S[i]), int(S[i])
dp[i][j][k] = max(dp[i - 1][j - a][k - b] - 2, dpf[i - 1][j - a][k - b] - 1)
a, b = 1 - int(S[i - 1]), int(S[i - 1])
if dp[i - 2][j - a][k - b] >= 0:
dpf[i][j][k] = 2 * (dp[i - 2][j - a][k - b] // 2)
if dpf[i - 2][j - a][k - b] >= 0:
dpf[i][j][k] = max(2 * (dpf[i - 2][j - a][k - b] // 2), dpf[i][j][k])
if dp[i - 1][j][k] >= 0:
dpf[i][j][k] = max(
dp[i - 1][j][k] + 1 - dp[i - 1][j][k] % 2, dpf[i][j][k]
)
dpf[i][j][k] = max(dpf[i][j][k], dpf[i - 1][j][k] + 1)
dpf[i][0][0] = i + 1
data = [
[
[
(dp[i][j][k] >= 0 or dpf[i][j][k] >= 0) & ((j, k) != (0, 0))
for k in range(N + 1)
]
for j in range(N + 1)
]
for i in range(N)
]
S = [S[-i - 1] for i in range(N)]
Zero = 0
One = 0
ans = 1
check = set([])
for i in range(N):
Zero += S[i] == "1"
One += S[i] == "0"
for j in range(N + 1):
for k in range(N + 1):
if data[N - 1 - i][j][k]:
check.add((j, k))
ncheck = set([])
for j, k in check:
A, B = 1, 1
if j != 0:
A = cmb(Zero + j - 1, j, mod)
if k != 0:
B = cmb(One + k - 1, k, mod)
ans += A * B
ans %= mod
a, b = 1 - int(S[i]), int(S[i])
if j >= a and k >= b:
ncheck.add((j - a, k - b))
check = ncheck
print(ans)
def check():
res = 0
for i in range(N):
for j in range(N + 1):
for k in range(N + 1):
if data[i][j][k]:
print(i, j, k)
res += 1
return res
| Statement
Given is a string S consisting of `0` and `1`. Find the number of strings,
modulo 998244353, that can result from applying the following operation on S
zero or more times:
* Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters. | [{"input": "0001", "output": "8\n \n\nEight strings, `0001`, `001`, `010`, `00`, `01`, `10`, `0`, and `1`, can\nresult.\n\n* * *"}, {"input": "110001", "output": "24\n \n\n* * *"}, {"input": "11101111011111000000000110000001111100011111000000001111111110000000111111111", "output": "697354558"}] |
Print the number of sequences of towns satisfying the condition, modulo
1000000007 (=10^9+7).
* * * | s910224779 | Wrong Answer | p03924 | The input is given from Standard Input in the following format:
N M | # dp[i][j] := i 回の移動で頂点 1 から自由に j 個行き来できて王様がその中にいる場合の数
# O(N^2 M^2) の解を書こうと思ったけど最後に戻ってこないパターンが抜けてる
# 面倒になって諦め
exit()
class Combination:
def __init__(self, n_max, mod=10**9 + 7):
# O(n_max + log(mod))
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max + 1):
f = f * i % mod
fac.append(f)
f = pow(f, mod - 2, mod)
self.facinv = facinv = [f]
for i in range(n_max, 0, -1):
f = f * i % mod
facinv.append(f)
facinv.reverse()
# "n 要素" は区別できる n 要素
# "k グループ" はちょうど k グループ
def __call__(self, n, r): # self.C と同じ
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def C(self, n, r):
if not 0 <= r <= n:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def P(self, n, r):
if not 0 <= r <= n:
return 0
return self.fac[n] * self.facinv[n - r] % self.mod
def H(self, n, r):
if (n == 0 and r > 0) or r < 0:
return 0
return (
self.fac[n + r - 1]
* self.facinv[r]
% self.mod
* self.facinv[n - 1]
% self.mod
)
def rising_factorial(self, n, r): # 上昇階乗冪 n * (n+1) * ... * (n+r-1)
return self.fac[n + r - 1] * self.facinv[n - 1] % self.mod
def stirling_first(
self, n, k
): # 第 1 種スターリング数 lru_cache を使うと O(nk) # n 要素を k 個の巡回列に分割する場合の数
if n == k:
return 1
if k == 0:
return 0
return (
self.stirling_first(n - 1, k - 1) + (n - 1) * self.stirling_first(n - 1, k)
) % self.mod
def stirling_second(
self, n, k
): # 第 2 種スターリング数 O(k + log(n)) # n 要素を区別のない k グループに分割する場合の数
if n == k:
return 1 # n==k==0 のときのため
return (
self.facinv[k]
* sum(
(-1) ** (k - m) * self.C(k, m) * pow(m, n, self.mod)
for m in range(1, k + 1)
)
% self.mod
)
def balls_and_boxes_3(
self, n, k
): # n 要素を区別のある k グループに分割する場合の数 O(k + log(n))
if n < k:
return 0
return (
sum(
(-1) ** (k - m) * self.C(k, m) * pow(m, n, self.mod)
for m in range(1, k + 1)
)
% self.mod
)
def bernoulli(self, n): # ベルヌーイ数 lru_cache を使うと O(n**2 * log(mod))
if n == 0:
return 1
if n % 2 and n >= 3:
return 0 # 高速化
return (
-pow(n + 1, self.mod - 2, self.mod)
* sum(self.C(n + 1, k) * self.bernoulli(k) % self.mod for k in range(n))
) % self.mod
def faulhaber(self, k, n): # べき乗和 0^k + 1^k + ... + (n-1)^k
# bernoulli に lru_cache を使うと O(k**2 * log(mod)) bernoulli が計算済みなら O(k * log(mod))
return (
pow(k + 1, self.mod - 2, self.mod)
* sum(
self.C(k + 1, j)
* self.bernoulli(j)
% self.mod
* pow(n, k - j + 1, self.mod)
% self.mod
for j in range(k + 1)
)
% self.mod
)
def lah(self, n, k): # n 要素を k 個の空でない順序付き集合に分割する場合の数 O(1)
return self.C(n - 1, k - 1) * self.fac[n] % self.mod * self.facinv[k] % self.mod
def bell(
self, n, k
): # n 要素を k グループ以下に分割する場合の数 O(k**2 + k*log(mod))
return sum(self.stirling_second(n, j) for j in range(1, k + 1)) % self.mod
mod = 10**9 + 7
comb = Combination(300, mod)
balls_and_boxes_3 = [[0] * 301 for _ in range(301)]
for n in range(301):
for k in range(301):
balls_and_boxes_3[n][k] = comb.balls_and_boxes_3(n, k)
N, M = map(int, input().split())
dp = [[0] * (N + 1) for _ in range(M + 1)]
dp[0][1] = 1
for i in range(1, M + 1):
for j in range(1, N + 1):
n, k = 1, 0
dp[i][j] += dp[i - 1][j] * j % mod
for n in range(1, i + 1):
for k in range(1, min(j - 1, n) + 1): # k=0 の場合も
dp[i][j] += (
dp[i - n][j - k]
* comb.C(N - (j - k), k)
% mod
* balls_and_boxes_3[n - 1][k]
% mod
* (j - k)
% mod
)
for d in dp:
print(d)
print(dp[-1][-1])
| Statement
There are N towns in Takahashi Kingdom. They are conveniently numbered 1
through N.
Takahashi the king is planning to go on a tour of inspection for M days. He
will determine a sequence of towns c, and visit town c_i on the i-th day. That
is, on the i-th day, he will travel from his current location to town c_i. If
he is already at town c_i, he will stay at that town. His location just before
the beginning of the tour is town 1, the capital. The tour ends at town c_M,
without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to
resolve this issue by paving the road himself while traveling. When he travels
from town a to town b, there will be a newly paved one-way road from town a to
town b.
Since he cares for his people, he wants the following condition to be
satisfied after his tour is over: "it is possible to travel from any town to
any other town by traversing roads paved by him". How many sequences of towns
c satisfy this condition? | [{"input": "3 3", "output": "2\n \n\nAs shown below, the condition is satisfied only when c = (2,3,1) or c =\n(3,2,1). Sequences such as c = (2,3,2), c = (2,1,3), c = (1,2,2) do not\nsatisfy the condition.\n\n\n\n* * *"}, {"input": "150 300", "output": "734286322\n \n\n* * *"}, {"input": "300 150", "output": "0"}] |
For each "extract" operation, print the element extracted from the priority
queue $S$ in a line. | s949783431 | Wrong Answer | p02289 | Multiple operations to the priority queue $S$ are given. Each operation is
given by "insert $k$", "extract" or "end" in a line. Here, $k$ represents an
integer element to be inserted to the priority queue.
The input ends with "end" operation. | import sys
class priority_queue:
def __init__(self, MAX_SIZE):
self.array = [0] * MAX_SIZE
self.size = 0
def len(self):
return self.size
def empty(self):
return self.size == 0
def push(self, data):
self.array[self.size] = data
index = self.size
while index != 0 and self.array[index] > self.array[(index - 1) // 2]:
self.array[index], self.array[(index - 1) // 2] = (
self.array[(index - 1) // 2],
self.array[index],
)
index = (index - 1) // 2
self.size += 1
def top(self):
return self.array[0]
def pop(self):
self.size -= 1
self.array[0], self.array[self.size] = self.array[self.size], self.array[0]
index = 0
while 2 * index + 1 < self.size:
if 2 * index + 2 < self.size:
if (
self.array[2 * index + 2] > self.array[index]
and self.array[2 * index + 2] >= self.array[2 * index + 1]
):
self.array[2 * index + 2], self.array[index] = (
self.array[index],
self.array[2 * index + 2],
)
index = 2 * index + 2
elif (
self.array[2 * index + 1] > self.array[index]
and self.array[2 * index + 1] >= self.array[index + 2]
):
self.array[2 * index + 1], self.array[index] = (
self.array[index],
self.array[2 * index + 1],
)
index = 2 * index + 1
else:
break
else:
if self.array[2 * index + 1] > self.array[index]:
self.array[2 * index + 1], self.array[index] = (
self.array[index],
self.array[2 * index + 1],
)
index = 2 * index + 1
else:
break
if __name__ == "__main__":
que = priority_queue(2000000)
while True:
s = sys.stdin.readline().split()
if s[0] == "insert":
que.push(int(s[1]))
elif s[0] == "extract":
sys.stdout.writelines("%d\n" % que.top())
que.pop()
else:
break
| Priority Queue
A priority queue is a data structure which maintains a set $S$ of elements,
each of with an associated value (key), and supports the following operations:
* $insert(S, k)$: insert an element $k$ into the set $S$
* $extractMax(S)$: remove and return the element of $S$ with the largest key
Write a program which performs the $insert(S, k)$ and $extractMax(S)$
operations to a priority queue $S$. The priority queue manages a set of
integers, which are also keys for the priority. | [{"input": "insert 8\n insert 2\n extract\n insert 10\n extract\n insert 11\n extract\n extract\n end", "output": "8\n 10\n 11\n 2"}] |
For each "extract" operation, print the element extracted from the priority
queue $S$ in a line. | s040756571 | Runtime Error | p02289 | Multiple operations to the priority queue $S$ are given. Each operation is
given by "insert $k$", "extract" or "end" in a line. Here, $k$ represents an
integer element to be inserted to the priority queue.
The input ends with "end" operation. | a = []
while True:
x = input().split()
if x[0] == "end":
quit()
elif x[0] == "insert":
a.append(x[1])
a.sort(reversed=True)
else:
print(a[0])
del a[0]
| Priority Queue
A priority queue is a data structure which maintains a set $S$ of elements,
each of with an associated value (key), and supports the following operations:
* $insert(S, k)$: insert an element $k$ into the set $S$
* $extractMax(S)$: remove and return the element of $S$ with the largest key
Write a program which performs the $insert(S, k)$ and $extractMax(S)$
operations to a priority queue $S$. The priority queue manages a set of
integers, which are also keys for the priority. | [{"input": "insert 8\n insert 2\n extract\n insert 10\n extract\n insert 11\n extract\n extract\n end", "output": "8\n 10\n 11\n 2"}] |
For each "extract" operation, print the element extracted from the priority
queue $S$ in a line. | s934453313 | Accepted | p02289 | Multiple operations to the priority queue $S$ are given. Each operation is
given by "insert $k$", "extract" or "end" in a line. Here, $k$ represents an
integer element to be inserted to the priority queue.
The input ends with "end" operation. | def setHeapDown_max(heap, pos):
targetkey = heap[pos]
while pos > 0:
parentpos = (pos - 1) >> 1
parent = heap[parentpos]
if parent < targetkey:
heap[pos] = parent
pos = parentpos
continue
break
heap[pos] = targetkey
def setHeapUp_max(heap, pos):
endpos = len(heap)
targetkey = heap[pos]
childpos = 2 * pos + 1
while childpos < endpos:
rightpos = childpos + 1
if rightpos < endpos and not heap[rightpos] < heap[childpos]:
childpos = rightpos
heap[pos] = heap[childpos]
pos = childpos
childpos = 2 * pos + 1
heap[pos] = targetkey
setHeapDown_max(heap, pos)
def heapPush_max(heap, key):
heap.append(key)
setHeapDown_max(heap, len(heap) - 1)
def heapPop_max(heap):
lastkey = heap.pop()
if heap:
returnkey = heap[0]
heap[0] = lastkey
setHeapUp_max(heap, 0)
return returnkey
return lastkey
import sys
S = []
ans = []
for x in sys.stdin.readlines():
if x[0] == "i":
k = int(x[7:])
heapPush_max(S, k)
elif x[1] == "x":
ans.append(heapPop_max(S))
else:
pass
print(*ans, sep="\n")
| Priority Queue
A priority queue is a data structure which maintains a set $S$ of elements,
each of with an associated value (key), and supports the following operations:
* $insert(S, k)$: insert an element $k$ into the set $S$
* $extractMax(S)$: remove and return the element of $S$ with the largest key
Write a program which performs the $insert(S, k)$ and $extractMax(S)$
operations to a priority queue $S$. The priority queue manages a set of
integers, which are also keys for the priority. | [{"input": "insert 8\n insert 2\n extract\n insert 10\n extract\n insert 11\n extract\n extract\n end", "output": "8\n 10\n 11\n 2"}] |
Print all strings in question in lexicographical order.
* * * | s702446640 | Wrong Answer | p02773 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | n = int(input())
a = set([str(input()) for i in range(n)])
print(sorted(a))
| Statement
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i
written on it.
Print all strings that are written on the most number of votes, in
lexicographical order. | [{"input": "7\n beat\n vet\n beet\n bed\n vet\n bet\n beet", "output": "beet\n vet\n \n\n`beet` and `vet` are written on two sheets each, while `beat`, `bed`, and\n`bet` are written on one vote each. Thus, we should print the strings `beet`\nand `vet`.\n\n* * *"}, {"input": "8\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo", "output": "buffalo\n \n\n* * *"}, {"input": "7\n bass\n bass\n kick\n kick\n bass\n kick\n kick", "output": "kick\n \n\n* * *"}, {"input": "4\n ushi\n tapu\n nichia\n kun", "output": "kun\n nichia\n tapu\n ushi"}] |
Print all strings in question in lexicographical order.
* * * | s860024813 | Wrong Answer | p02773 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | from collections import Counter
def words_sort_ordered(words_list):
cnt = Counter()
for word in words_list:
cnt[word] += 1
written_words_number = []
for x in cnt.values():
written_words_number.append(x)
answer_words_list = []
for word, number in dict(cnt).items():
if number == max(written_words_number):
answer_words_list.append(word)
return sorted(answer_words_list)
if __name__ == "__main__":
words_num = int(input())
words_list = [input() for i in range(words_num)]
print(words_sort_ordered(words_list))
| Statement
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i
written on it.
Print all strings that are written on the most number of votes, in
lexicographical order. | [{"input": "7\n beat\n vet\n beet\n bed\n vet\n bet\n beet", "output": "beet\n vet\n \n\n`beet` and `vet` are written on two sheets each, while `beat`, `bed`, and\n`bet` are written on one vote each. Thus, we should print the strings `beet`\nand `vet`.\n\n* * *"}, {"input": "8\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo", "output": "buffalo\n \n\n* * *"}, {"input": "7\n bass\n bass\n kick\n kick\n bass\n kick\n kick", "output": "kick\n \n\n* * *"}, {"input": "4\n ushi\n tapu\n nichia\n kun", "output": "kun\n nichia\n tapu\n ushi"}] |
Print all strings in question in lexicographical order.
* * * | s035890816 | Wrong Answer | p02773 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | N, strings, answers = int(input()), [], []
for x in range(N):
string = input()
strings.append(string)
max_char = strings.count(max(strings, key=strings.count))
for x in strings:
if strings.count(x) == max_char:
answers.append(x)
for x in set(answers):
print(x)
| Statement
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i
written on it.
Print all strings that are written on the most number of votes, in
lexicographical order. | [{"input": "7\n beat\n vet\n beet\n bed\n vet\n bet\n beet", "output": "beet\n vet\n \n\n`beet` and `vet` are written on two sheets each, while `beat`, `bed`, and\n`bet` are written on one vote each. Thus, we should print the strings `beet`\nand `vet`.\n\n* * *"}, {"input": "8\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo", "output": "buffalo\n \n\n* * *"}, {"input": "7\n bass\n bass\n kick\n kick\n bass\n kick\n kick", "output": "kick\n \n\n* * *"}, {"input": "4\n ushi\n tapu\n nichia\n kun", "output": "kun\n nichia\n tapu\n ushi"}] |
Print all strings in question in lexicographical order.
* * * | s266909625 | Wrong Answer | p02773 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | n = int(input())
s1 = []
for i in range(n):
s1.append(input())
s2 = list(set(sorted(s1)))
N = []
for i in range(len(s2)):
ni = s1.count(s2[i])
N.append(ni)
nm = max(N)
for i in range(len(s2)):
if N[i] == nm:
print(s2[i])
| Statement
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i
written on it.
Print all strings that are written on the most number of votes, in
lexicographical order. | [{"input": "7\n beat\n vet\n beet\n bed\n vet\n bet\n beet", "output": "beet\n vet\n \n\n`beet` and `vet` are written on two sheets each, while `beat`, `bed`, and\n`bet` are written on one vote each. Thus, we should print the strings `beet`\nand `vet`.\n\n* * *"}, {"input": "8\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo", "output": "buffalo\n \n\n* * *"}, {"input": "7\n bass\n bass\n kick\n kick\n bass\n kick\n kick", "output": "kick\n \n\n* * *"}, {"input": "4\n ushi\n tapu\n nichia\n kun", "output": "kun\n nichia\n tapu\n ushi"}] |
Print all strings in question in lexicographical order.
* * * | s022161614 | Wrong Answer | p02773 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | n = int(input())
s = [input() for _ in range(n)]
compare = list(set(s))
ans1 = []
for i in compare:
ans1.append(s.count(i))
s.remove(i)
print(ans1)
ans2 = [i for i, x in enumerate(ans1) if x == max(ans1)]
for i in ans2:
print(compare[i])
| Statement
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i
written on it.
Print all strings that are written on the most number of votes, in
lexicographical order. | [{"input": "7\n beat\n vet\n beet\n bed\n vet\n bet\n beet", "output": "beet\n vet\n \n\n`beet` and `vet` are written on two sheets each, while `beat`, `bed`, and\n`bet` are written on one vote each. Thus, we should print the strings `beet`\nand `vet`.\n\n* * *"}, {"input": "8\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo", "output": "buffalo\n \n\n* * *"}, {"input": "7\n bass\n bass\n kick\n kick\n bass\n kick\n kick", "output": "kick\n \n\n* * *"}, {"input": "4\n ushi\n tapu\n nichia\n kun", "output": "kun\n nichia\n tapu\n ushi"}] |
Print all strings in question in lexicographical order.
* * * | s502650578 | Runtime Error | p02773 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | def com_str(A, B, i):
ans = A
if A == B:
pass
elif ord(A[i]) > ord(B[i]):
pass
elif ord(B[i]) > ord(A[i]):
ans = B
else:
ans = com_str(A, B, i + 1)
return ans
def quick_sort_str(list, N):
stand = list[0]
over = []
same = []
under = []
for i in list:
if i[N] != stand[N]:
if stand[N] == com_str(i[N], stand[N], 0):
over.append(i)
else:
under.append(i)
else:
same.append(i)
if len(over) > 1:
over = quick_sort_str(over, N)
else:
pass
if len(under) > 1:
under = quick_sort_str(under, N)
else:
way = [same[0][0], len(same)]
same.clear()
same.append(way)
return over + same + under
def quick_sort_num(list, N):
stand = list[0]
over = []
same = []
under = []
for i in list:
if i[N] > stand[N]:
over.append(i)
elif i[N] < stand[N]:
under.append(i)
else:
same.append(i)
if len(over) > 1:
over = quick_sort_num(over, N)
else:
pass
if len(under) > 1:
under = quick_sort_num(under, N)
else:
pass
return over + same + under
N = int(input())
S = [[] for i in range(N)]
for i in range(N):
S[i].append(str(input()))
S[i].append(1)
S = quick_sort_str(S, 0)
S = quick_sort_num(S, 1)
count = S[0][1]
for i in range(len(S)):
if S[i][1] == count:
print(S[i][0])
else:
break
| Statement
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i
written on it.
Print all strings that are written on the most number of votes, in
lexicographical order. | [{"input": "7\n beat\n vet\n beet\n bed\n vet\n bet\n beet", "output": "beet\n vet\n \n\n`beet` and `vet` are written on two sheets each, while `beat`, `bed`, and\n`bet` are written on one vote each. Thus, we should print the strings `beet`\nand `vet`.\n\n* * *"}, {"input": "8\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo", "output": "buffalo\n \n\n* * *"}, {"input": "7\n bass\n bass\n kick\n kick\n bass\n kick\n kick", "output": "kick\n \n\n* * *"}, {"input": "4\n ushi\n tapu\n nichia\n kun", "output": "kun\n nichia\n tapu\n ushi"}] |
Print all strings in question in lexicographical order.
* * * | s582860981 | Accepted | p02773 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | input_num = int(input())
dic = {}
strlist = []
strlist2 = []
maxi = 1
for i in range(input_num):
strlist.append(input())
for i in range(input_num):
if dic.setdefault(strlist[i], 0) != 0:
dic[strlist[i]] += 1
if dic[strlist[i]] > maxi:
maxi = dic[strlist[i]]
else:
dic[strlist[i]] = 1
strlist2.append(strlist[i])
strlist2.sort()
for i in range(len(strlist2)):
if dic[strlist2[i]] == maxi:
print(strlist2[i])
| Statement
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i
written on it.
Print all strings that are written on the most number of votes, in
lexicographical order. | [{"input": "7\n beat\n vet\n beet\n bed\n vet\n bet\n beet", "output": "beet\n vet\n \n\n`beet` and `vet` are written on two sheets each, while `beat`, `bed`, and\n`bet` are written on one vote each. Thus, we should print the strings `beet`\nand `vet`.\n\n* * *"}, {"input": "8\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo", "output": "buffalo\n \n\n* * *"}, {"input": "7\n bass\n bass\n kick\n kick\n bass\n kick\n kick", "output": "kick\n \n\n* * *"}, {"input": "4\n ushi\n tapu\n nichia\n kun", "output": "kun\n nichia\n tapu\n ushi"}] |
Print all strings in question in lexicographical order.
* * * | s431624971 | Wrong Answer | p02773 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | Row = int(input())
dictA = {}
a = ""
mid = 0
for i in range(Row):
a = input()
dictA.setdefault(a, 0)
dictA[a] += 1
mid = max(mid, dictA[a])
sDict = sorted(dictA.items())
print(sDict)
for i in range(len(dictA)):
if sDict[i][1] == mid:
print(sDict[i][0])
| Statement
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i
written on it.
Print all strings that are written on the most number of votes, in
lexicographical order. | [{"input": "7\n beat\n vet\n beet\n bed\n vet\n bet\n beet", "output": "beet\n vet\n \n\n`beet` and `vet` are written on two sheets each, while `beat`, `bed`, and\n`bet` are written on one vote each. Thus, we should print the strings `beet`\nand `vet`.\n\n* * *"}, {"input": "8\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo\n buffalo", "output": "buffalo\n \n\n* * *"}, {"input": "7\n bass\n bass\n kick\n kick\n bass\n kick\n kick", "output": "kick\n \n\n* * *"}, {"input": "4\n ushi\n tapu\n nichia\n kun", "output": "kun\n nichia\n tapu\n ushi"}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s389486824 | Accepted | p03861 | The input is given from Standard Input in the following format:
a b x | a, b, x = [int(s) for s in input().split()]
q, m = divmod(a, x)
print(b // x - q + (1 if m == 0 else 0))
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s937879446 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,c=map(int,input().split())
s=0
for i in range(a:b):
if i%2==0:
s+=1
print(s) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s868111668 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
def run():
a,b,x = map(int, input().split())
ans = 0
if a == 0:
a += 1
ans = 1
ans += b // x - (a-1) // x
print(ans)
if __name__ == "__main__": | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s425002071 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,x = map(int, input().split())
if a!=0:
c = int((a-1)/x)
d = int(b/x)
if a!=0:
print(d-c)
elif a==0:
print(d) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s658465539 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a = input()
a.split()
i = int(a[0])
d = int(a[1])
x = int(a[2])
rd = d / x
ri = (i - 1) / x
if (ri < 0):
ri = -1
print(rd - ri) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s456790180 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | import sys
veces = list()
lines = sys.stdin.readlines()
for linea in lines:
c = linea.split()
c = list(map(int, c))
list(c)
rango = range(c[0], c[1] + 1)
j = list(rango)
for l in range(len(j)):
division = j[l] % c[2]
if division == 0:
veces.append(division)
print(int(len(veces)))
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s493770715 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,x = map(int,input().split())
print((b - a) // x) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s936121826 | Wrong Answer | p03861 | The input is given from Standard Input in the following format:
a b x | a, b, k = map(int, input().split())
x = a // k
y = b // k
res = y - x
if a % k == 0 and b % k == 0 and x < y:
res += 1
print(res)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s272872751 | Accepted | p03861 | The input is given from Standard Input in the following format:
a b x | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i]) * n**i for i in range(len(str(X))))
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
a, b, x = IL()
P(b // x - (a - 1) // x)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s177454744 | Accepted | p03861 | The input is given from Standard Input in the following format:
a b x | from decimal import *
# exp = Decimal(10**23)
# rint((Decimal(11)*exp)/Decimal(10))
## coding: UTF-8
s = input().split()
t = [int(p) for p in s]
# print(t)
a = t[0]
b = t[1]
x = t[2]
"""
start = a
goal = b
while True:
if(start % x == 0):
break
else:
start += 1
#print(start)
while True:
if(goal % x == 0):
break
else:
goal -= 1
#start = Decimal(3)
#goal = Decimal(999999999999999999)
#print(Decimal(goal))
print(Decimal(Decimal(Decimal(goal) - Decimal(start)) / Decimal(x)) + Decimal(1) )
#answer = ((goal - start) / x ) + 1
#print('{}'.format(int(answer)))
"""
def count_even(t, x):
return int(Decimal(t) / Decimal(x))
if a == 0:
answer = count_even(b, x) + 1
else:
answer = count_even(b, x) - count_even(a - 1, x)
print(answer)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s259105562 | Wrong Answer | p03861 | The input is given from Standard Input in the following format:
a b x | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [input() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [int(input()) for i in range(n)]
class Math:
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n**0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007F
MOD = int(1e09) + 7
INF = int(1e15)
def main():
# sys.stdin = open("sample.txt")
a, b, x = Scanner.map_int()
if a == 0 and b == 0:
print(0)
return
print(b // x - ((a - 1) // x))
if __name__ == "__main__":
main()
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s411865760 | Wrong Answer | p03861 | The input is given from Standard Input in the following format:
a b x | data = [int(i) for i in input().split(" ")]
total = 0
if data[0] != data[1]:
for i in range(data[0], data[1] + 1):
if i % data[2] == 0:
total += 1
print(total)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s931145615 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | import math
a, b, x = map(int,input().split())
if a % x != 0:
print(b//x - a//x + 2)
else
print(b//x - a/x + 1) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s401123063 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a, b, x = [int(n) for n in input().split()]
res = 0
for n in range(a, b + 1)
if n % x == 0:
res += 1
print(res)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s071773924 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,x = map(int, input().split())
right = b // x + 1
if a = 0:
left = 0
else:
left = (a - 1) // x + 1
print(right - left) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s876010686 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,x = map(int,input().split())
#if a > x or b < x:
# print("0")
elif a%x == 0:
print(b//x-a//x+1)
else:
print(b//x-a//x)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s560362102 | Wrong Answer | p03861 | The input is given from Standard Input in the following format:
a b x | a, s, d = map(int, input().split())
print(s // d - max(a - 1, 0) // d)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s096002028 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a, b, x = map(int input().split())
print(b//x - a//x) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s893452725 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | print(n - m)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s618732734 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | print("A" + input()[8] + "C")
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s682513757 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,x=map(int,input().split())
print(b//x - a//x +(1 if a%x == 0)) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s976543731 | Wrong Answer | p03861 | The input is given from Standard Input in the following format:
a b x | A = list(map(int, input().split()))
a = A[0]
b = A[1]
x = A[2]
s = 0
n = 0
s = (b - a) // x
print(s)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s680503966 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,x = map(int,input().split())
ans = 0
for i in range(a,b+1):
if i % x==0 :ans. +=1
print(ans) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s773360488 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,x = map(int,input().split())
c =0
for i in range(a,b+1):
if i % x == 0:
c +=1
print(c) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s790221627 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a,b,x = map(int,input().split())
c =0
for i in range(a,b+1):
if i % x == 0:
c +=1
print(c)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s687095467 | Wrong Answer | p03861 | The input is given from Standard Input in the following format:
a b x | A, B, x = map(int, input().split())
b_d = B // x + 1
a_d = A // x
if A != 0:
a_d += 1
print(b_d - a_d)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s616294703 | Accepted | p03861 | The input is given from Standard Input in the following format:
a b x | N = list(map(int, input().split()))
a = N[0]
b = N[1]
x = N[2]
if a % x == 0:
a_min = a // x - 1
else:
a_min = a // x
b_max = b // x
print(b_max - a_min)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s835279309 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | a, b, c = map(int, input().split())
test = []
cnt = 0
for i in range(a:b):
test.append(i)
for i in range(a:b):
if i % == 0:
cnt += 1
else:
continue
print(cnt) | Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the number of the integers between a and b, inclusive, that are
divisible by x.
* * * | s558013041 | Runtime Error | p03861 | The input is given from Standard Input in the following format:
a b x | import sys
input = sys.stdin.readline
a, b, x = [int(x) for x in input().split()]
B = 1 + b // x
if a == 0:
print(B)(
elif a % x == 0:
A = 1 + a // x
print(B - A + 1)
else:
A = 1 + a // x
print(B - A)
| Statement
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x? | [{"input": "4 8 2", "output": "3\n \n\nThere are three integers between 4 and 8, inclusive, that are divisible by 2:\n4, 6 and 8.\n\n* * *"}, {"input": "0 5 1", "output": "6\n \n\nThere are six integers between 0 and 5, inclusive, that are divisible by 1: 0,\n1, 2, 3, 4 and 5.\n\n* * *"}, {"input": "9 9 2", "output": "0\n \n\nThere are no integer between 9 and 9, inclusive, that is divisible by 2.\n\n* * *"}, {"input": "1 1000000000000000000 3", "output": "333333333333333333\n \n\nWatch out for integer overflows."}] |
Print the shortest distance in a line. If there is no solution, print -1. | s032050162 | Accepted | p02323 | |V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in the graph. The
graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.
si and ti represent source and target vertices of i-th edge (directed) and di
represents the distance between si and ti (the i-th edge). | from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10**9)
readline = stdin.readline
n, w = map(int, readline().split())
INF = 10**9
G = [[INF] * n for _ in range(n)]
for _ in range(w):
s, t, d = map(int, readline().split())
G[s][t] = d
dp = [[-1] * n for _ in range(1 << n)]
def func(s, v):
if dp[s][v] >= 0:
return dp[s][v]
if (s == (1 << n) - 1) and v == 0:
dp[s][v] = 0
return dp[s][v]
tmp = INF
for u in range(n):
t = (1 << u) | s
if t == s:
continue
tmp = min(tmp, func(t, u) + G[v][u])
dp[s][v] = tmp
return dp[s][v]
ans = func(0, 0)
print(ans if ans < INF else -1)
| Traveling Salesman Problem
For a given weighted directed graph G(V, E), find the distance of the shortest
route that meets the following criteria:
* It is a closed cycle where it ends at the same point it starts.
* It visits each vertex exactly once. | [{"input": "4 6\n 0 1 2\n 1 2 3\n 1 3 9\n 2 0 1\n 2 3 6\n 3 2 4", "output": "16"}, {"input": "3 3\n 0 1 1\n 1 2 1\n 0 2 1", "output": "-1"}] |
Print the shortest distance in a line. If there is no solution, print -1. | s519595595 | Accepted | p02323 | |V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in the graph. The
graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.
si and ti represent source and target vertices of i-th edge (directed) and di
represents the distance between si and ti (the i-th edge). | def tsp(matrix):
INF = float("inf")
n = len(matrix)
# dp[bit_state][i] := すでにbit_stateの状態を訪れていて、
# 最後に訪問したのがi番目のときの最小値
dp = [[INF] * n for i in range(1 << n)]
dp[1 << 0][0] = 0
for bit_state in range(1 << n):
for i in range(n):
# bit_stateにiを含んでいる
if (bit_state >> i) & 1:
for j in range(n):
# bit_stateにjを含んでいない
if not ((bit_state >> j) & 1):
dp[bit_state | (1 << j)][j] = min(
dp[bit_state | (1 << j)][j], dp[bit_state][i] + matrix[i][j]
)
ans = INF
for i in range(n):
ans = min(dp[(1 << n) - 1][i] + matrix[i][0], ans)
return ans
n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
INF = float("inf")
matrix = [[INF] * n for i in range(n)]
for i in range(m):
a, b, cost = info[i]
matrix[a][b] = cost
for i in range(n):
matrix[i][i] = 0
ans = tsp(matrix)
if ans == INF:
print(-1)
else:
print(ans)
| Traveling Salesman Problem
For a given weighted directed graph G(V, E), find the distance of the shortest
route that meets the following criteria:
* It is a closed cycle where it ends at the same point it starts.
* It visits each vertex exactly once. | [{"input": "4 6\n 0 1 2\n 1 2 3\n 1 3 9\n 2 0 1\n 2 3 6\n 3 2 4", "output": "16"}, {"input": "3 3\n 0 1 1\n 1 2 1\n 0 2 1", "output": "-1"}] |
Print the shortest distance in a line. If there is no solution, print -1. | s160607519 | Accepted | p02323 | |V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in the graph. The
graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.
si and ti represent source and target vertices of i-th edge (directed) and di
represents the distance between si and ti (the i-th edge). | #!/usr/bin/env python3
import sys
from collections import defaultdict
rl = sys.stdin.buffer.readline
INF = sys.maxsize
V, E = map(int, rl().split())
ES = [tuple(map(int, rl().split())) for i in range(E)]
# グラフを初期化する
G = defaultdict(lambda: defaultdict(lambda: INF))
for e in ES:
G[e[0]][e[1]] = e[2]
dp = defaultdict(lambda: defaultdict(lambda: INF))
dp[0][0] = 0
for s in range(1 << V):
for v in range(V):
if s & (1 << v) == 0: # s に頂点v が含まれていないときを考える
for u in range(V):
dp[s | (1 << v)][v] = min(dp[s | (1 << v)][v], dp[s][u] + G[u][v])
print(dp[(1 << V) - 1][0] if dp[(1 << V) - 1][0] < INF else -1)
| Traveling Salesman Problem
For a given weighted directed graph G(V, E), find the distance of the shortest
route that meets the following criteria:
* It is a closed cycle where it ends at the same point it starts.
* It visits each vertex exactly once. | [{"input": "4 6\n 0 1 2\n 1 2 3\n 1 3 9\n 2 0 1\n 2 3 6\n 3 2 4", "output": "16"}, {"input": "3 3\n 0 1 1\n 1 2 1\n 0 2 1", "output": "-1"}] |
Print the shortest distance in a line. If there is no solution, print -1. | s215904412 | Accepted | p02323 | |V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in the graph. The
graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.
si and ti represent source and target vertices of i-th edge (directed) and di
represents the distance between si and ti (the i-th edge). | #!python3
iim = lambda: map(int, input().rstrip().split())
from heapq import heappush, heappop
def resolve():
V, E = iim()
inf = float("inf")
ad = [[inf] * V for i in range(V)]
for i in range(E):
s, t, d = iim()
ad[s][t] = d
bi = [1 << i for i in range(V)]
goal = (1 << V) - 1
dp = dict()
q = []
heappush(q, (0, 0, 1))
ans = inf
while q:
cost, v, state = heappop(q)
vs = (v, state)
if vs in dp:
if dp[vs] <= cost:
continue
dp[vs] = cost
if state == goal:
cost += ad[v][0]
if cost < ans:
ans = cost
continue
for i in range(V):
if bi[i] & state:
continue
heappush(q, (cost + ad[v][i], i, state | bi[i]))
print(ans if ans != inf else -1)
# print(dp[(0, goal)])
if __name__ == "__main__":
resolve()
| Traveling Salesman Problem
For a given weighted directed graph G(V, E), find the distance of the shortest
route that meets the following criteria:
* It is a closed cycle where it ends at the same point it starts.
* It visits each vertex exactly once. | [{"input": "4 6\n 0 1 2\n 1 2 3\n 1 3 9\n 2 0 1\n 2 3 6\n 3 2 4", "output": "16"}, {"input": "3 3\n 0 1 1\n 1 2 1\n 0 2 1", "output": "-1"}] |
Print the shortest distance in a line. If there is no solution, print -1. | s049980230 | Accepted | p02323 | |V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in the graph. The
graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.
si and ti represent source and target vertices of i-th edge (directed) and di
represents the distance between si and ti (the i-th edge). | INF = 10**18
n, m = map(int, input().split())
dist = [[INF for _ in range(n)] for _ in range(n)]
dp = [[INF for _ in range(n + 1)] for _ in range(1 << n)]
for _ in range(m):
a, b, c = map(int, input().split())
dist[a][b] = c
dp[(1 << n) - 1][0] = 0
for bit in range((1 << n) - 2, -1, -1):
for v in range(n):
for u in range(n):
if not ((bit >> u) & 1):
dp[bit][v] = min(dp[bit][v], dp[bit | 1 << u][u] + dist[u][v])
print(dp[0][0] if dp[0][0] != INF else -1)
| Traveling Salesman Problem
For a given weighted directed graph G(V, E), find the distance of the shortest
route that meets the following criteria:
* It is a closed cycle where it ends at the same point it starts.
* It visits each vertex exactly once. | [{"input": "4 6\n 0 1 2\n 1 2 3\n 1 3 9\n 2 0 1\n 2 3 6\n 3 2 4", "output": "16"}, {"input": "3 3\n 0 1 1\n 1 2 1\n 0 2 1", "output": "-1"}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s429148486 | Runtime Error | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | def main():
import sys
import numpy as np
ikimasu = sys.stdin.buffer.readline
ini = lambda: int(ins())
ina = lambda: list(map(int, ikimasu().split()))
ins = lambda: ikimasu().strip()
n = ini()
tmp = ina()
num,index = 0,0
for i in range(n):
if(abs(tmp[i])>num):
num,index = tmp[i],i
print(2n-2)
if(num<=0):
for i in range(n):
if(i!=index):
print(index+1,i+1)
for i in range(n,1,-1):
print(i,i-1)
else:
for i in range(n):
if(i!=index):
print(index+1,i+1)
for i in range(1,n):
print(i,i+1)
if __name__ == "__main__":
main()
| Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s545895941 | Accepted | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | ###############################################################################
from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math
mod = 1
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * y) % mod
def mod_inv(x):
# available only when mod is prime
global mod
return pow(x, mod - 2, mod)
def gcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def combination(x, y):
assert x >= y
ret = math.factorial(x)
ret = ret // (math.factorial(x - y) * math.factorial(y))
return ret
def get_divisors(x):
retlist = []
for i in range(1, int(x**0.5) + 3):
if x % i == 0:
retlist.append(i)
retlist.append(x // i)
return retlist
def get_factors(x):
retlist = []
for i in range(2, int(x**0.5) + 3):
while x % i == 0:
retlist.append(i)
x = x // i
retlist.append(x)
return retlist
def make_linklist(xylist):
linklist = {}
for a, b in xylist:
linklist.setdefault(a, [])
linklist.setdefault(b, [])
linklist[a].append(b)
linklist[b].append(a)
return linklist
def calc_longest_distance(linklist, v=1):
distance_list = {}
distance_count = 0
distance = 0
vlist_previous = []
vlist = [v]
nodecount = len(linklist)
while distance_count < nodecount:
vlist_next = []
for v in vlist:
distance_list[v] = distance
distance_count += 1
vlist_next.extend(linklist[v])
distance += 1
vlist_to_del = vlist_previous
vlist_previous = vlist
vlist = list(set(vlist_next) - set(vlist_to_del))
max_distance = -1
max_v = None
for v, distance in distance_list.items():
if distance > max_distance:
max_distance = distance
max_v = v
return (max_distance, max_v)
def calc_tree_diameter(linklist, v=1):
_, u = calc_longest_distance(linklist, v)
distance, _ = calc_longest_distance(linklist, u)
return distance
class UnionFind:
def __init__(self, n):
self.parent = [i for i in range(n)]
def root(self, i):
if self.parent[i] == i:
return i
self.parent[i] = self.root(self.parent[i])
return self.parent[i]
def unite(self, i, j):
rooti = self.root(i)
rootj = self.root(j)
if rooti == rootj:
return
if rooti < rootj:
self.parent[rootj] = rooti
else:
self.parent[rooti] = rootj
def same(self, i, j):
return self.root(i) == self.root(j)
###############################################################################
def main():
n = intin()
alist = intina()
absmax = -float("inf")
absidx = -1
for i, a in enumerate(alist):
if abs(a) > absmax:
absmax = abs(a)
absidx = i
if alist[absidx] == 0:
print(0)
return
print(n * 2)
if alist[absidx] > 0:
for i in range(n):
print("%d %d" % (absidx + 1, i + 1))
print("%d %d" % (absidx + 1, i + 1))
alist[i] += alist[absidx]
alist[i] += alist[absidx]
absidx = i
else:
for i in range(n - 1, -1, -1):
print("%d %d" % (absidx + 1, i + 1))
print("%d %d" % (absidx + 1, i + 1))
alist[i] += alist[absidx]
alist[i] += alist[absidx]
absidx = i
if __name__ == "__main__":
main()
| Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s273701866 | Runtime Error | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | N = int(input())
a = list(map(int, input().split()))
if abs(max(a)) >= abs(min(a)):
for i in range(N):
if a[i] = max(a):
num = i
break
print(2*N-1)
for i in range(N):
if num != i:
print(num+1, i+1)
print(num+1, num+1)
for i in range(1,N):
print(i, i+1)
else:
for i in range(N):
if a[i] = min(a):
num = i
break
print(2*N-1)
for i in range(N):
if num != i:
print(num+1, i+1)
print(num+1, num+1)
for i in range(N):
print(N-i, N-i-1) | Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s713841157 | Accepted | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda: input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
a = inl()
mx = max([abs(x) for x in a])
p = [i for i in range(n) if abs(a[i]) == mx][0]
seq = []
if a[p] > 0:
for i in range(1, n):
while a[i - 1] > a[i]:
a[i] += a[p]
seq.append((p, i))
if a[i] > a[p]:
p = i
elif a[p] < 0:
for i in range(n - 2, -1, -1):
while a[i] > a[i + 1]:
a[i] += a[p]
seq.append((p, i))
if a[i] < a[p]:
p = i
print(len(seq))
for a, b in seq:
print("{} {}".format(a + 1, b + 1))
| Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s544029055 | Accepted | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | N = int(input())
A = list(map(int, input().split()))
ans = []
def f1():
for i in range(1, N):
mx = -(10**7)
mxi = 0
for j in range(N):
if A[j] > mx:
mx = A[j]
mxi = j
A[i] += mx
ans.append((mxi, i))
def f2():
for i in range(N - 2, -1, -1):
mn = 10**7
mni = 0
for j in range(N):
if A[j] < mn:
mn = A[j]
mni = j
A[i] += mn
ans.append((mni, i))
mx = -(10**7)
mxi = 0
mn = 10**7
mni = 0
for i in range(N):
if A[i] > mx:
mx = A[i]
mxi = i
if A[i] < mn:
mn = A[i]
mni = i
if mn >= 0:
f1()
elif mx <= 0:
f2()
elif mx >= abs(mn):
for i in range(N):
if A[i] < 0:
A[i] += mx
ans.append((mxi, i))
f1()
else:
for i in range(N):
if A[i] > 0:
A[i] += mn
ans.append((mni, i))
f2()
print(len(ans))
for a1, a2 in ans:
print(a1 + 1, a2 + 1)
| Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s155360584 | Runtime Error | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | # coding: utf-8
import sys
def solve(a, begin, end, queue):
#print(begin, end)
if begin >= end:
return
if end - begin == 1:
return
maxx = sorted(list(map(abs, a[begin:end + 1])), reverse=True)[0]
if maxx in a:
m = a.index(maxx)
else:
m = a.index(-1 * maxx)
maxx = -1 * maxx
if maxx == 0:
return []
if maxx > 0:
solve(a, begin, m - 1, queue)
for i in range(max(0, m - 1), end):
if a[i + 1] >= a[i]:
continue
else:
a[i + 1] += a[i]
queue.append((i, i + 1))
if a[i + 1] < a[i]:
a[i + 1] += a[i]
queue.append((i, i + 1))
return queue
if maxx < 0:
solve(a, m + 1, end, queue)
for i in reversed(range(begin, min(len(a) - 1, m + 1))):
if a[i] <= a[i + 1]:
continue
else:
a[i] += a[i + 1]
queue.append((i + 1, i))
if a[i] > a[i + 1]:
a[i] += a[i + 1]
queue.append((i + 1, i))
return queue
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
queue = solve(a, 0, len(a) - 1, [])
print(len(queue))
for i in range(len(queue)):
print(queue[i][0] + 1, queue[i][1] + 1)
for i in range(len(a)):
#print(i, a[i])
| Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s515145308 | Runtime Error | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | # coding: utf-8
import sys
def solve(a,begin,end,queue):
if begin>=end:
return
maxx = sorted(list(map(abs,a[begin:end+1])),reverse=True)[0]
if maxx in a:
m = a.index(maxx)
else:
m = a.index(-1*maxx)
maxx = -1*maxx
if maxx==0:
return []
if maxx>0:
solve(a,begin,m-1,queue)
for i in range(max(0,m-1),end):
if a[i+1]>=a[i]:
continue
else:
a[i+1]+=a[i]
queue.append((i,i+1))
if a[i+1]<a[i]:
a[i+1]+=a[i]
queue.append((i,i+1))
return queue
if maxx<0:
solve(a,m+1,end,queue)
for i in reversed(range(begin,min(len(a)-1,m+1))):
if a[i]<=a[i+1]:
continue
else:
a[i]+= a[i+1]
queue.append((i+1,i))
if a[i]>a[i+1]:
a[i]+=a[i+1]
queue.append((i+1,i))
return queue
if __name__ == '__main__':
n = int(input())
a = list(map(int,input().split()))
queue = solve(a,0,len(a)-1,[])
print(len(queue))
for i in range(len(queue)):
print(queue[i][0]+1,queue[i][1]+1) | Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s738668785 | Accepted | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | n, *a = map(int, open(0).read().split())
ans = [str(2 * n - 1)]
if max(a) > -min(a):
i = a.index(max(a))
for k in range(n):
ans.append("{} {}".format(i + 1, k + 1))
for k in range(n - 1):
ans.append("{} {}".format(k + 1, k + 2))
else:
i = a.index(min(a))
for k in range(n):
ans.append("{} {}".format(i + 1, k + 1))
for k in range(n - 1):
ans.append("{} {}".format(n - k, n - k - 1))
print("\n".join(ans))
| Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s832622233 | Runtime Error | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | n = int(input())
lis = list(map(int, input().split()))
for i in range(1,n):
if lis[i] + lis[i+1] > = 0:
print(i,i+1)
print(i,i+1)
else:
print(i+1,i)
print(i+1,i) | Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Let m be the number of operations in your solution. In the first line, print
m. In the i-th of the subsequent m lines, print the numbers x and y chosen in
the i-th operation, with a space in between. The output will be considered
correct if m is between 0 and 2N (inclusive) and a satisfies the condition
after the m operations.
* * * | s426452276 | Runtime Error | p03498 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | import java.io.*;
import java.util.*;
class Main {
static int p=0;
static int[]ops;
static long[]a;
static int n;
static void add(int x,int y){
a[y]+=a[x];
ops[p++]=x*n+y;
}
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
n=sc.nextInt();
a=new long[n];
ops=new int[2*n];
for(int i=0;i<n;++i)a[i]=sc.nextLong();
long max=Math.abs(a[0]);
int maxind=0;
for(int i=1;i<n;++i){
if(max<Math.abs(a[i])){
max=Math.abs(a[i]);
maxind=i;
}
}
if(max!=0){
for(int i=0;i<n;++i)
if(i!=maxind)
add(maxind,i);
if(a[maxind]<0)
for(int i=n-2;i>=0;--i)
add(i+1,i);
else
for(int i=0;i<n-1;++i)
add(i,i+1);
}
out.println(p);
for(int i=0;i<p;++i){
int x=ops[i]/n+1;
int y=ops[i]%n+1;
out.println(x+" "+y);
}
out.close();
}
// http://codeforces.com/blog/entry/7018
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Statement
Snuke has an integer sequence, a, of length N. The i-th element of a
(1-indexed) is a_{i}.
He can perform the following operation any number of times:
* Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so
that a satisfies the condition below. Show one such sequence of operations. It
can be proved that such a sequence of operations always exists under the
constraints in this problem.
* Condition: a_1 \leq a_2 \leq ... \leq a_{N} | [{"input": "3\n -2 5 -1", "output": "2\n 2 3\n 3 3\n \n\n * After the first operation, a = (-2,5,4).\n * After the second operation, a = (-2,5,8), and the condition is now satisfied.\n\n* * *"}, {"input": "2\n -1 -3", "output": "1\n 2 1\n \n\n * After the first operation, a = (-4,-3) and the condition is now satisfied.\n\n* * *"}, {"input": "5\n 0 0 0 0 0", "output": "0\n \n\n * The condition is satisfied already in the beginning."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s864697665 | Accepted | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | # Educational DP Contest C-Vacation
def solve():
n = int(input())
dpa = [0] * n
dpb = [0] * n
dpc = [0] * n
a, b, c = list(map(int, input().split()))
dpa[0] = a
dpb[0] = b
dpc[0] = c
for i in range(1, n):
a, b, c = list(map(int, input().split()))
dpa[i] = max(dpb[i - 1] + a, dpc[i - 1] + a)
dpb[i] = max(dpa[i - 1] + b, dpc[i - 1] + b)
dpc[i] = max(dpb[i - 1] + c, dpa[i - 1] + c)
return max(dpa[-1], dpb[-1], dpc[-1])
if __name__ == "__main__":
print(solve())
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s291045720 | Accepted | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | # C_vacation
N = int(input())
happiness = list()
for nn in range(N):
h = [int(x) for x in input().split()]
happiness.append(h)
dp = [[0] * 3 for x in range(N)]
dp[0] = happiness[0]
for nn in range(1, N):
for ii in range(3): # day nn's choice
max_reward = 0
for jj in range(3): # day (nn-1)'s choice
r = dp[nn - 1][jj] + happiness[nn][ii]
if ii != jj and r > max_reward:
max_reward = r
dp[nn][ii] = max_reward
ans = 0
for ii in range(3):
if dp[-1][ii] > ans:
ans = dp[-1][ii]
print(ans)
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s679929518 | Wrong Answer | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | N = int(input())
dp = [0] * N
abc = [list(map(int, input().split())) for i in range(N)]
yesterday = ""
if abc[0][1] < abc[0][0] and abc[0][2] < abc[0][0]:
dp[0] = abc[0][0]
yesterday = "a"
elif abc[0][0] < abc[0][1] and abc[0][2] < abc[0][1]:
dp[0] = abc[0][1]
yesterday = "b"
else:
dp[0] = abc[0][2]
yesterday = "c"
for i in range(1, N):
if "a" in yesterday:
if abc[i][1] < abc[i][2]:
dp[i] = dp[i - 1] + abc[i][2]
yesterday = "c"
elif abc[i][2] < abc[i][1]:
dp[i] = dp[i - 1] + abc[i][1]
yesterday = "b"
elif i != N - 1:
if abc[i + 1][2] < abc[i + 1][1]:
dp[i] = dp[i - 1] + abc[i][2]
yesterday = "c"
else:
dp[i] = dp[i - 1] + abc[i][1]
yesterday = "b"
elif "b" in yesterday:
if abc[i][0] < abc[i][2]:
dp[i] = dp[i - 1] + abc[i][2]
yesterday = "c"
elif abc[i][2] < abc[i][0]:
dp[i] = dp[i - 1] + abc[i][0]
yesterday = "a"
elif i != N - 1:
if abc[i + 1][0] < abc[i + 1][2]:
dp[i] = dp[i - 1] + abc[i][0]
yesterday = "a"
else:
dp[i] = dp[i - 1] + abc[i][2]
yesterday = "c"
else:
if abc[i][1] < abc[i][0]:
dp[i] = dp[i - 1] + abc[i][0]
yesterday = "a"
elif abc[i][0] < abc[i][1]:
dp[i] = dp[i - 1] + abc[i][1]
yesterday = "b"
elif i != N - 1:
if abc[i + 1][0] < abc[i + 1][1]:
dp[i] = dp[i - 1] + abc[i][0]
yesterday = "a"
else:
dp[i] = dp[i - 1] + abc[i][1]
yesterday = "b"
print(dp[N - 1])
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s534655606 | Wrong Answer | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | N = int(input())
DP = [0] * N
abc = [0] * N
L = list(map(int, input().split()))
maxa = max(L)
point = L.index(maxa)
DP[0] = maxa
abc[0] = point
for i in range(1, N):
L = list(map(int, input().split()))
for j in L:
if abc[i - 1] != j:
if DP[i] < DP[i - 1] + j:
DP[i] = DP[i - 1] + j
abc[i] = j
print(DP[-1])
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s361772226 | Accepted | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | s = list(map(int, input().split()))
n = s[0]
dp = [[0] * 3 for i in range(n)]
s = list(map(int, input().split()))
dp[0][0] = s[0]
dp[0][1] = s[1]
dp[0][2] = s[2]
for i in range(1, n):
s = list(map(int, input().split()))
dp[i][0] = max(dp[i - 1][1] + s[0], dp[i - 1][2] + s[0])
dp[i][1] = max(dp[i - 1][0] + s[1], dp[i - 1][2] + s[1])
dp[i][2] = max(dp[i - 1][0] + s[2], dp[i - 1][1] + s[2])
print(max(dp[n - 1]))
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s524999050 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | n=int(input())
import copy
l=[list(map(int,input().split())) for i in range(n)]
q=copy.copy(l)
dp=[0]*(n+1)
dp[0]=0
dp[1]=max(l[0])
for i in range(1,n-1):
if l[i+1].index(max(l[i+1]))==l[i].index(max(l[i]):
qq=q[i+1].sort()
dp[i+1]=max(dp[i-1]+max(l[i+1]),dp[i]+qq[1])
print(n)
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s853222802 | Wrong Answer | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | def resolve():
# 夏休みの日数
N = int(input())
# 日ごとの行動A,B,Cによって得られる幸福度
ABC = [map(int, input().split()) for _ in range(N)]
# 今日行動A,B,Cをする事で得られる、幸福度の累計
Va, Vb, Vc = ABC.pop()
for _ in range(N - 1):
a, b, c = ABC.pop()
Va, Vb, Vc = max(Vb, Vc) + a, max(Va, Vc) + b, max(Va, Vb) + c
print(max(Va, Vb, Vc))
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s445198933 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | h, w = map(int, input().split())
a = [input() for i in range(h)]
mod = 10**9 + 7
d = [[0] * w for i in range(h)]
d[0][0] = 1
for i in range(h):
for j in range(w):
if i + 1 < h and a[i + 1][j] == ".":
d[i + 1][j] += d[i][j]
d[i + 1][j] %= mod
if j + 1 < w and a[i][j + 1] == ".":
d[i][j + 1] += d[i][j]
d[i][j + 1] %= mod
print(d[-1][-1])
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s898107754 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | n = int(input())
action = []
for i in range(n):
action.append(list(map(int,input().split())))
memo = []
for i in range(n):
memo.append([-1]*3)
def dp(i, a):
if i == 0:
return action[0][a]
elif memo[i][a] != -1:
return memo[i][a]
else:
return memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
print(max([dp(n-1,a) for a in range(3)]))
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s907129395 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | N = 3
A=[[10, 40, 70], [20, 50, 80], [30, 60, 90]]
dp = [[0] * 3 for _ in range(N)] # 初期化
dp[0] = A[0] # 初期化
print(dp[0])
for i in range(N-1):
for j in range(3):
for k in range(3):
if j == k:
continue
dp[i+1][k] = max(dp[i+1][k], dp[i][j] + A[i][k])
print(max(dp[N-1])
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s403494260 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | num = int(input())
actions = []
for i in range(num):
actions.append(list(map(int, input().split())))
dp = [[0 if j != 0 else actions[i][j] for i in range(3)] for j in range(num)]
for i in range(num) if i != 0:
dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + actions[i][0]
dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + actions[i][1]
dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + actions[i][2]
print(max( dp[num-1][0], dp[num-1][1] ,dp[num-1][2] )) | Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s720255127 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N |
n = int(input())
h = [list(map(int, input().split()) for _ in range(n)]
dp = np.zeros([n+1, 3])
for i, val in enumerate(h):
for j in range(3):
for k in range(3):
if j != k:
dp[i+1, j] = np.max(dp[i+1, j], dp[i, j] + val[k])
print(np.max(dp[n, :], axis=1)) | Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s477124021 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | 7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1 | Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s267494997 | Wrong Answer | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | a = int(input())
hahaha = 0
for i in range(a):
r = str(input()).split()
m = [int(u) for u in r]
hahaha += max(m)
print(hahaha)
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s702868387 | Wrong Answer | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | N = int(input())
h = []
for i in range(N):
h.append(list(map(int, input().split(" "))))
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s056706630 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | #include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using namespace std;
#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
const long long INF = 1e9;
int main()
{
int n; cin >> n;
vector<vector<int>> happy(n, vector<int>(3));
for(int i = 0; i < n; i++){
cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
}
vector<vector<int>> dp(n+1, vector<int>(3));
for(int i = 0; i < n; i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 3; k++){
if(j == k) continue;
dp[i+1][k] = max(dp[i+1][k], dp[i][j] + happy[i][j]);
}
}
}
cout << max_3(dp[n][0], dp[n][1], dp[n][2]) << endl;
return 0;
}
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s860013721 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
for i in range(n):
for j in range(3):
if i == 0:
dp[i][j] = abc[i][j]
else:
for k in range(3):
if k == j:
continue
dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i][j])
ans = max(dp[n-1])
print(ans)
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s489424658 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | n=int(input())
a=[0]*(n-1)
b=[0]*(n-1)
c=[0]*(n-1)
for _ in range(n-1):
a,b,c=map(int,input().split())
dp=[[0]*3 for _ in range(n)]
dp[0] = [a[0],b[0],c[0]]
for i in range(n-1):
dp[i+1][0]=max(dp[i][1]+a[i+1], dp[i][2]+a[i+1])
dp[i+1][1]=max(dp[i][0]+b[i+1], dp[i][2]+b[i+1])
dp[i+1][2]=max(dp[i][0]+c[i+1], dp[i][1]+c[i+1])
print(max(dp[n-1])) | Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s230044247 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | def solve(a):
dp = [[0]*3 for _ in range(len(a)+1)]
for i in range(len(a)):
for j in range(3):
for k in range(3):
if j != k:
dp[i+1][j] = max(dp[i+1][j], a[i][j] + dp[i][k])
return max(dp[-1])
n = int(input())
a = []
for _ in range(n):
a.append(list(map(int, input().split())))
print(solve(a)) | Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s134257617 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | # -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
N = int(input())
DATA = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
or i in range(N):
for j in range(3):
for k in range(3):
if j == k:
continue
dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + DATA[i][k])
res = 0
for v in range(3):
res = max(res, dp[N][v])
print(res)
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s204786479 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
N = int(input())
DATA = [map(int, input().split()) for i in range(N)]
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(N):
for j in range(3):
for k in range(3):
if j == k:
continue
dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + DATA[i][k])
res = 0
for v in range(3):
res = max(res, dp[N][v])
print(res)
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s745757183 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | n=input()
satis=[]
for i in range(n):
satis.extend(;istmap(int,input().split())))
tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
for i in range(n-1):
tempA2=satis[3*i+3]+max([tempB,tempC])
tempB2=satis[3*i+4]+max([tempA,tempC])
tempC2=satis[3*i+5]+max([tempA,tempB])
tempA=tempA2
tempB=tempB2
tempC=tempC2
print(max([tempA,tempB,tempC]))
else:
print(max([tempA,tempB,tempC])) | Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s193640947 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | n=input()
satis=[]
for i in range(n):
satis.append(list(map(int,input().split())))
#n=3
#satis=[10, 40, 70, 20, 50, 80, 30, 60, 90]
tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
for i in range(n-1):
tempA2=satis[3*i+3]+max([tempB,tempC])
tempB2=satis[3*i+4]+max([tempA,tempC])
tempC2=satis[3*i+5]+max([tempA,tempB])
tempA=tempA2
tempB=tempB2
tempC=tempC2
print(max([tempA,tempB,tempC]))
else:
print(max([tempA,tempB,tempC])) | Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s951950250 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | mport sys
def 解():
input = sys.stdin.readline
N = int(input())
dp = [int(_) for _ in input().split()]
for _ in range(N-1):
a,b,c = [int(_) for _ in input().split()]
dp = [max(dp[1]+a,dp[2]+a),max(dp[0]+b,dp[2]+b),max(dp[0]+c,dp[1]+c)]
print(max(dp))
解()
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s831939022 | Runtime Error | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | a = int(input())
b = []
m = 0
for i in range(a):
b.append(list(map(int,input().split())))
c = [[0,0,0] in i for range(a+1)]
for i in range(a):
for j in range(3):
for k in range(3):
if j == k:
continue
else:
c[i+1][k] = max(c[i+1][k],c[i][k] + b[i][j])
print(max(c[-1])) | Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s360792306 | Accepted | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | def examA():
N = I()
H = LI()
dp = [inf] * (N)
dp[0] = 0
for i in range(N - 1):
dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]))
if i < N - 2:
dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]))
ans = dp[-1]
print(ans)
return
def examB():
N, K = LI()
H = LI()
dp = [inf] * N
dp[0] = 0
for i in range(N):
for k in range(1, K + 1):
if i + k >= N:
break
if dp[i + k] > dp[i] + abs(H[i + k] - H[i]):
dp[i + k] = dp[i] + abs(H[i + k] - H[i])
ans = dp[-1]
print(ans)
return
def examC():
N = I()
A = [0] * N
B = [0] * N
C = [0] * N
for i in range(N):
A[i], B[i], C[i] = LI()
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
dp[i + 1][0] = max(dp[i][1], dp[i][2]) + A[i]
dp[i + 1][1] = max(dp[i][0], dp[i][2]) + B[i]
dp[i + 1][2] = max(dp[i][1], dp[i][0]) + C[i]
ans = max(dp[N])
print(ans)
return
def examD():
ans = 0
print(ans)
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord("a") + i) for i in range(26)]
if __name__ == "__main__":
examC()
"""
"""
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s789672510 | Accepted | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | am = int(input())
val = [[0] * (am + 5), [0] * (am + 5), [0] * (am + 5)]
dp = [[0] * (am + 5), [0] * (am + 5), [0] * (am + 5)]
for i in range(am):
A, B, C = list(map(int, input().split()))
val[0][i] = A
val[1][i] = B
val[2][i] = C
for i in range(0, am):
for g in range(3):
for j in range(3):
if g != j:
dp[g][i + 1] = max(dp[g][i + 1], dp[j][i] + val[g][i])
print(max(dp[0][am], dp[1][am], dp[2][am]))
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s735431460 | Accepted | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | N = int(input())
# kth entry: [max up to ak, bk, ck]
max_happiness = [[None] * 3 for _ in range(N)]
for k in range(N):
if k == 0:
max_happiness[k] = [int(n) for n in input().split()]
else:
ak, bk, ck = [int(n) for n in input().split()]
a_opt, b_opt, c_opt = max_happiness[k - 1]
max_happiness[k][0] = ak + max(b_opt, c_opt)
max_happiness[k][1] = bk + max(a_opt, c_opt)
max_happiness[k][2] = ck + max(a_opt, b_opt)
print(max(max_happiness[-1]))
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the maximum possible total points of happiness that Taro gains.
* * * | s205924220 | Wrong Answer | p03162 | Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [input() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [int(input()) for i in range(n)]
class Math:
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def roundUp(a, b):
return -(-a // b)
@staticmethod
def toUpperMultiple(a, x):
return Math.roundUp(a, x) * x
@staticmethod
def toLowerMultiple(a, x):
return (a // x) * x
@staticmethod
def nearPow2(n):
if n <= 0:
return 0
if n & (n - 1) == 0:
return n
ret = 1
while n > 0:
ret <<= 1
n >>= 1
return ret
@staticmethod
def sign(n):
if n == 0:
return 0
if n < 0:
return -1
return 1
@staticmethod
def isPrime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n**0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
class PriorityQueue:
def __init__(self, l=[]):
self.__q = l
heapq.heapify(self.__q)
return
def push(self, n):
heapq.heappush(self.__q, n)
return
def pop(self):
return heapq.heappop(self.__q)
MOD = int(1e09) + 7
INF = int(1e15)
def main():
# sys.stdin = open("sample.txt")
N = Scanner.int()
A = [Scanner.map_int() for _ in range(N)]
dp = [[0 for _ in range(3)] for _ in range(N)]
dp[0][0], dp[0][1], dp[0][2] = A[0]
print(dp)
for i in range(1, N):
for c in range(3):
dp[i][c] = max(dp[i][c], dp[i - 1][(c + 1) % 3] + A[i][c])
dp[i][c] = max(dp[i][c], dp[i - 1][(c + 2) % 3] + A[i][c])
print(max(dp[N - 1]))
if __name__ == "__main__":
main()
| Statement
Taro's summer vacation starts tomorrow, and he has decided to make plans for
it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will
choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more
consecutive days.
Find the maximum possible total points of happiness that Taro gains. | [{"input": "3\n 10 40 70\n 20 50 80\n 30 60 90", "output": "210\n \n\nIf Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210\npoints of happiness.\n\n* * *"}, {"input": "1\n 100 10 1", "output": "100\n \n\n* * *"}, {"input": "7\n 6 7 8\n 8 8 3\n 2 5 2\n 7 8 6\n 4 6 8\n 2 3 4\n 7 5 1", "output": "46\n \n\nTaro should do activities in the order C, A, B, A, C, B, A."}] |
Print the answer.
* * * | s641173993 | Wrong Answer | p02548 | Input is given from Standard Input in the following format:
N | N = int(input())
y = 0
for j in range(1, N + 1):
for k in range(1, N + 1):
if (N - k) % j == 0:
y = y + 1
print(y)
| Statement
Given is a positive integer N. How many tuples (A,B,C) of positive integers
satisfy A \times B + C = N? | [{"input": "3", "output": "3\n \n\nThere are 3 tuples of integers that satisfy A \\times B + C = 3: (A, B, C) =\n(1, 1, 2), (1, 2, 1), (2, 1, 1).\n\n* * *"}, {"input": "100", "output": "473\n \n\n* * *"}, {"input": "1000000", "output": "13969985"}] |
Print the answer.
* * * | s954131211 | Accepted | p02548 | Input is given from Standard Input in the following format:
N | def gcd(a, b):
while b:
a, b = b, a % b
return a
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = (
[2, 7, 61]
if n < 1 << 32
else (
[2, 3, 5, 7, 11, 13, 17]
if n < 1 << 48
else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
)
)
for a in L:
t = d
y = pow(a, t, n)
if y == 1:
continue
while y != n - 1:
y = y * y % n
if y == 1 or t == n - 1:
return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if isPrimeMR(g):
return g
elif isPrimeMR(n // g):
return n // g
return findFactorRho(g)
def primeFactor(n):
i = 2
ret = {}
rhoFlg = 0
while i * i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k:
ret[i] = k
i += i % 2 + (3 if i % 3 == 1 else 1)
if i == 101 and n >= 2**20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
rhoFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1:
ret[n] = 1
if rhoFlg:
ret = {x: ret[x] for x in sorted(ret)}
return ret
def sqrt(n):
x = 1 << (n.bit_length() + 1) // 2
y = (x + n // x) // 2
while y < x:
x = y
y = (x + n // x) // 2
return x
def calc(k):
return (sqrt(8 * k + 1) - 1) // 2
N = int(input())
cnt = 0
for i in range(1, N):
tmp = 1
pf = primeFactor(i)
for v in pf.values():
tmp *= v + 1
cnt += tmp
print(cnt)
| Statement
Given is a positive integer N. How many tuples (A,B,C) of positive integers
satisfy A \times B + C = N? | [{"input": "3", "output": "3\n \n\nThere are 3 tuples of integers that satisfy A \\times B + C = 3: (A, B, C) =\n(1, 1, 2), (1, 2, 1), (2, 1, 1).\n\n* * *"}, {"input": "100", "output": "473\n \n\n* * *"}, {"input": "1000000", "output": "13969985"}] |
Print the answer.
* * * | s105543371 | Runtime Error | p02548 | Input is given from Standard Input in the following format:
N | def SieveOfEratosthenes(n, prime, primesquare, a):
# Create a boolean array "prime[0..n]"
# and initialize all entries it as
# true. A value in prime[i] will finally
# be false if i is not a prime, else true.
for i in range(2, n + 1):
prime[i] = True
# Create a boolean array "primesquare[0..n*n+1]"
# and initialize all entries it as false.
# A value in squareprime[i] will finally be
# true if i is square of prime, else false.
for i in range((n * n + 1) + 1):
primesquare[i] = False
# 1 is not a prime number
prime[1] = False
p = 2
while p * p <= n:
# If prime[p] is not changed,
# then it is a prime
if prime[p] == True:
# Update all multiples of p
i = p * 2
while i <= n:
prime[i] = False
i += p
p += 1
j = 0
for p in range(2, n + 1):
if prime[p] == True:
# Storing primes in an array
a[j] = p
# Update value in primesquare[p*p],
# if p is prime.
primesquare[p * p] = True
j += 1
# Function to count divisors
def countDivisors(n):
# If number is 1, then it will
# have only 1 as a factor. So,
# total factors will be 1.
if n == 1:
return 1
prime = [False] * (n + 2)
primesquare = [False] * (n * n + 2)
# for storing primes upto n
a = [0] * n
# Calling SieveOfEratosthenes to
# store prime factors of n and to
# store square of prime factors of n
SieveOfEratosthenes(n, prime, primesquare, a)
# ans will contain total
# number of distinct divisors
ans = 1
# Loop for counting factors of n
i = 0
while 1:
# a[i] is not less than cube root n
if a[i] * a[i] * a[i] > n:
break
# Calculating power of a[i] in n.
cnt = 1 # cnt is power of
# prime a[i] in n.
while n % a[i] == 0: # if a[i] is a factor of n
n = n / a[i]
cnt = cnt + 1 # incrementing power
# Calculating number of divisors
# If n = a^p * b^q then total
# divisors of n are (p+1)*(q+1)
ans = ans * cnt
i += 1
# if a[i] is greater than
# cube root of n
n = int(n)
# First case
if prime[n] == True:
ans = ans * 2
# Second case
elif primesquare[n] == True:
ans = ans * 3
# Third case
elif n != 1:
ans = ans * 4
return ans # Total divisors
n = int(input())
x = 0
for i in range(1, n):
x += countDivisors(n - i)
# print(countDivisors(n-i))
print(x)
| Statement
Given is a positive integer N. How many tuples (A,B,C) of positive integers
satisfy A \times B + C = N? | [{"input": "3", "output": "3\n \n\nThere are 3 tuples of integers that satisfy A \\times B + C = 3: (A, B, C) =\n(1, 1, 2), (1, 2, 1), (2, 1, 1).\n\n* * *"}, {"input": "100", "output": "473\n \n\n* * *"}, {"input": "1000000", "output": "13969985"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.