description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | f = []
f.append(1)
f.append(1)
mod = 1000000000.0 + 7
for i in range(100010):
f.append((f[-1] + f[-2]) % mod)
n, m = map(int, input().split())
print(int(2 * (f[n] + f[m] - 1) % mod)) | ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | a, b = map(int, input().split())
if a == 1 and b == 1:
print(2)
else:
d = max(a, b) * [0]
d[0] = 1
d[1] = 2
for i in range(2, len(d)):
d[i] = d[i - 1] + d[i - 2]
print(2 * (d[a - 1] + d[b - 1] - 1) % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMB... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | ai = [0] * 100100
bi = [0] * 100100
n, m = input().split()
n = int(n)
m = int(m)
ai[1] = 2
ai[2] = 4
len = max(n, m)
for i in range(3, 100100):
ai[i] = (ai[i - 1] + ai[i - 2]) % 1000000007
print((ai[n] - 2 + ai[m]) % 1000000007) | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP V... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = list(map(int, input().split()))
max_element = max(n, m)
min_element = min(n, m)
dp = [(2) for i in range(max_element + 1)]
for i in range(2, max_element + 1):
dp[i] = dp[i - 1] + dp[i - 2]
print((dp[max_element] + dp[min_element] - 2) % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL V... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | dp = []
dp.append(2)
dp.append(4)
dp.append(6)
for i in range(3, 100001):
dp.append((dp[i - 1] + dp[i - 2]) % 1000000007)
n, m = map(int, input().split())
ans = dp[m - 1]
ans += dp[n - 1] - 2
print(ans % 1000000007) | ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR B... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
q = 10**9 + 7
a1 = [0] * n
a2 = [0] * n
b1 = [0] * n
b2 = [0] * n
a1[0] = 1
b1[0] = 1
for i in range(1, n):
a1[i] = b1[i - 1] + b2[i - 1]
a2[i] = a1[i - 1]
b1[i] = a1[i - 1] + a2[i - 1]
b2[i] = b1[i - 1]
a1[i] %= q
a2[i] %= q
b1[i] %= q
b2[i] %= q
ans = (... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VA... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
mod = 10**9 + 7
fib = [1, 1]
for i in range(200001):
fib.append((fib[-1] + fib[-2]) % mod)
print((fib[n] * 2 - 2 + 2 * fib[m]) % mod) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP NUMBER VAR VAR VAR |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | import sys
import time
def modulo_div(a, b, modulo):
if b == 1:
return a % modulo
return (a + modulo_div(-a, modulo % b, b) * modulo) // b % modulo
for line in sys.stdin.readlines():
inputs = line.split()
n = int(inputs[0])
m = int(inputs[1])
numer = 1
denom = 1
sums = 0
modulo = 10**9 +... | IMPORT IMPORT FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
ans = [0, 1, 2, 3, 5]
for i in range(5, max(m, n) + 1):
ans.append((ans[i - 2] + 2 * ans[i - 3] + ans[i - 4]) % (10**9 + 7))
print(2 * (ans[n] + ans[m] - 1) % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | MOD = 10**9 + 7
n, m = map(int, input().split())
fib = [1] * (max(n, m) + 2)
for i in range(2, max(n, m) + 2):
fib[i] = fib[i - 1] + fib[i - 2]
fib[i] %= MOD
print(((fib[m] + fib[n]) * 2 - 2) % MOD) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUN... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = [int(i) for i in input().split()]
f = [1, 1]
mod = 1000000007
for i in range(100005):
f.append((f[-1] + f[-2]) % mod)
ans2 = 2 * f[m] + 2 * f[n] - 2
print(ans2 % mod) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
a = [0, 2]
mod = pow(10, 9) + 7
s = 0
t = 2
for i in range(2, 100002):
u = (a[i - 1] * 2 % mod - s % mod) % mod
if u < 0:
u += mod
a.append(u)
s = t
t = (u % mod - s % mod) % mod
if t < 0:
t += mod
print((a[n] % mod + a[m] % mod - 2) % mod) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | r = [int(x) for x in input().split()]
fibonacci = [(0) for i in range(100001)]
fibonacci[0] = 1
fibonacci[1] = 1
for i in range(99999):
fibonacci[i + 2] = (fibonacci[i + 1] + fibonacci[i]) % 1000000007
print(
(2 * ((fibonacci[r[0]] + fibonacci[r[1]]) % 1000000007) - 2 + 1000000007)
% 1000000007
) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP ... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | def read_int():
return int(input())
def read_str():
return input().strip()
def solve(n, m):
mod = 10**9 + 7
k = max(n, m) + 1
count_1 = [0] * k
count_2 = [0] * k
count_1[1] = 1
count_2[1] = 0
for i in range(2, k):
count_1[i] = (count_1[i - 1] + count_2[i - 1]) % mod
... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CAL... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | width, height = list(map(int, input().strip().split(" ")[:2]))
modulo = 10**9 + 7
fibs = [0, 0]
sum_fibs = [0, 0]
a, b = 1, 0
for i in range(max(width, height)):
fibs.append(a)
sum_fibs.append((sum_fibs[-1] + a) % modulo)
a, b = (a + b) % modulo, a
def ans(w, h):
return 2 * (1 + sum_fibs[w] + sum_fibs... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
def fib(x):
a = 0
b = 1
temp = 0
for i in range(0, x):
temp = a + b
a = b
b = temp
return temp
print(2 * (fib(n) + fib(m) - 1) % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
MOD = 1000000007
if n < m:
n, m = m, n
dp = list()
dp.append(1)
dp.append(1)
for i in range(2, n + 1):
dp.append((dp[i - 1] + dp[i - 2]) % MOD)
print((dp[n] + dp[m] + MOD - 1) * 2 % MOD) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR F... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
mod = 10**9 + 7
if n > m:
n, m = m, n
if m == 1:
print(2)
else:
DP = [([0] * 2) for _ in range(m)]
DP[1][0] = 2
DP[1][1] = 2
for i in range(2, m):
DP[i][0] = DP[i - 1][1] % mod
DP[i][1] = (DP[i - 1][0] + DP[i - 1][1]) % mod
a = DP[m - 1][0] + ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VA... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
if n == 1 and m == 1:
print(2)
exit()
MOD = 10**9 + 7
N = max(n, m)
dp = [([0] * 4) for _ in range(N + 1)]
for j in range(4):
dp[2][j] = 1
for i in range(2, N):
dp[i + 1][0] = dp[i][2]
dp[i + 1][1] = dp[i][0] + dp[i][2]
dp[i... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL V... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
d = [2, 4]
k = 10**9 + 7
for i in range(2, max(n, m)):
d += [(d[i - 1] + d[i - 2]) % k]
print((d[m - 1] + d[n - 1] - 2) % k) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR LIST BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
a = [0] * 10**6
a[1], a[2] = 2, 4
for i in range(3, max(n, m) + 1):
a[i] = a[i - 1] + a[i - 2]
print((a[n] + a[m] - 2) % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_O... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | foo = []
n, m = input().split()
n = int(n)
m = int(m)
foo.append(1)
foo.append(1)
for i in range(max(n, m)):
foo.append(foo[i + 1] + foo[i])
o = 2 * (foo[n] + foo[m] - 1)
print(o % 1000000007) | ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR ... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = list(map(int, input().split()))
def fib(n):
if n < 2:
return 1
a = 1
b = 1
for i in range(2, n + 1):
c = a + b
a = b
b = c
return c
print((2 * fib(n) + 2 * fib(m) - 2) % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER FUNC_CAL... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | N, M = map(int, input().split())
mod = 10**9 + 7
L = max(N, M) + 1
dp = [[1, 1] for _ in range(L + 1)]
dp[1][0] = 1
dp[1][1] = 1
for l in range(2, L + 1):
dp[l][0] = (dp[l - 1][1] + dp[l - 2][1]) % mod
dp[l][1] = (dp[l - 1][0] + dp[l - 2][0]) % mod
ans = dp[N][0] + dp[N][1] + dp[M][0] + dp[M][1] - 2
if ans < 0:... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR ... |
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$... | n, m = map(int, input().split())
def create_dp(x):
dp = [(0) for _ in range(x)]
dp[0] = 1
if x == 1:
return dp
dp[1] = 2
if x == 2:
return dp
for i in range(2, x):
dp[i] = dp[i - 1] + dp[i - 2]
dp[i] %= MOD
return dp
MOD = 10**9 + 7
cut_pattern = 0
dp = cr... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR RET... |
Ikshu's love for binary numbers
Ikshu recently learnt to generate random numbers. He is generating stream binary numbers. Uptil now he has generated N bits of the binary number. Now, he wants to know if there is a streak of contiguous 1's of length K.
Help him to find the probability of existence of such a streak in ... | import sys
for line in sys.stdin:
if len(line) > 1:
n, k = list(map(int, line.split()))
s = [0] * (n + 1)
s[k] = 1
for i in range(k + 1, n + 1):
s[i] = 2 * s[i - 1] + pow(2, i - k - 1) - s[i - 1 - k]
a = s[n]
b = pow(2, n)
while a % 2 == 0:
... | IMPORT FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBE... |
Ikshu's love for binary numbers
Ikshu recently learnt to generate random numbers. He is generating stream binary numbers. Uptil now he has generated N bits of the binary number. Now, he wants to know if there is a streak of contiguous 1's of length K.
Help him to find the probability of existence of such a streak in ... | n, k = list(map(int, input().strip().split()))
array = [(0) for _ in range(k)]
array.append(1)
powers = [(2**i) for i in range(n + 1)]
for i in range(k + 1, n + 1):
array.append(powers[i - k - 1] - array[i - k - 1] + 2 * array[i - 1])
num = array[-1]
denom = powers[-1]
while num % 2 == 0:
num = int(num / 2)
... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP... |
Ikshu's love for binary numbers
Ikshu recently learnt to generate random numbers. He is generating stream binary numbers. Uptil now he has generated N bits of the binary number. Now, he wants to know if there is a streak of contiguous 1's of length K.
Help him to find the probability of existence of such a streak in ... | import sys
def compute(mat, n, k):
for i in range(1, n + 1):
for j in range(k + 1):
if j == 1:
mat[i][j] = pow(2, i) - 1
continue
if i - j - 1 >= 0:
mat[i][j] = 2 * mat[i - 1][j] + (pow(2, i - j - 1) - mat[i - j - 1][j])
e... | IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_O... |
Ikshu's love for binary numbers
Ikshu recently learnt to generate random numbers. He is generating stream binary numbers. Uptil now he has generated N bits of the binary number. Now, he wants to know if there is a streak of contiguous 1's of length K.
Help him to find the probability of existence of such a streak in ... | def gcd(a, b):
while b:
a, b = b, a % b
return a
n, k = list(map(int, input().split()))
q = 2**n
a = [0] * (n + 1)
a[0] = 1
for i in range(1, n + 1):
a[i] = a[i - 1] * 2
if i == k:
a[i] -= 1
elif i > k:
a[i] -= a[i - k - 1]
p = a[n]
p = q - p
d = gcd(p, q)
p = p // d
q = q ... | FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | n = int(input())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
def tree_cutting(n, A, B):
C = [(0) for _ in range(n)]
hullx = [(0) for _ in range(n)]
hully = [(0) for _ in range(n)]
sz = 0
p = 0
C[0] = 0
hullx[0] = B[0]
hully[0] = C[0]
for ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VA... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
stk = [0]
for i in range(1, n):
while len(stk) > 1 and c[stk[1]] - c[stk[0]] <= a[i] * (b[stk[0]] - b[stk[1]]):
del stk[0]
c[i] = c[stk[0]] + a[i] * b[stk[0]]
while len(stk) > 1 and (c[stk[-1]] - c[s... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR ... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [0] * n
stackDp = [0] * n
stackB = [0] * n
stackB[0] = b[0]
l = 0
r = 1
for i in range(1, n):
while (
r - l > 1
and a[i] * stackB[l] + stackDp[l] >= a[i] * stackB[l + 1] + stackDp[l + 1]
):
l +=... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBE... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | f = lambda: list(map(int, input().split()))
g = lambda j: a[i] * b[j] + t[j]
h = lambda j, k: (t[i] - t[j]) * (b[j] - b[k]) < (t[j] - t[k]) * (b[i] - b[j])
n = int(input())
a, b = f(), f()
t = [0] * n
p = [0]
for i in range(1, n):
while len(p) > 1 and g(p[1]) < g(p[0]):
p.pop(0)
t[i] = g(p[0])
while... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIG... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | read = lambda: map(int, input().split())
n = int(input())
a = list(read())
b = list(read())
dp = [0] * n
st = [0]
def f1():
i0, i1 = st[0], st[1]
b1 = dp[i1] - dp[i0]
k1 = b[i0] - b[i1]
return b1 <= a[i] * k1
def f2():
i1, i2 = st[-1], st[-2]
k1, k2 = b[i1] - b[i], b[i2] - b[i1]
b1, b2 =... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BI... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | def intersection(p, q):
return (q[1] - p[1]) / (p[0] - q[0])
def tree_cutting(n, A, B):
I = [[0, 0] for _ in range(n)]
C = [(0) for _ in range(n)]
C[0] = 0
I[0][0] = -float("inf")
I[0][1] = float("inf")
C[1] = C[0] + A[1] * B[0]
hull = [[B[0], C[0]], [B[1], C[1]]]
I[0][1] = interse... | FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER BIN... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | def cross(i, j, k, b, cost):
return (cost[i] - cost[j]) * (b[i] - b[k]) - (b[i] - b[j]) * (cost[i] - cost[k])
def dot(i, j, a, b, cost):
return cost[j] + a[i] * b[j]
def CF319C():
N = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
cost = [0] * N
hu... | FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL V... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
c = [0] * n
st = [0] * n
first = 0
second = 0
for i in range(1, n):
while (
second - first > 0
and a[i] * b[st[first]] + c[st[first]]
>= a[i] * b[st[first + 1]] + c[st[first + 1]]
):
fi... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | aa, bb, dp = [], [], []
def dot(i, a):
return dp[i] + a * bb[i]
def main():
n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
for k in range(n):
dp.append(0)
aa.append(a[k])
bb.append(b[k])
st, i, j = [(0) for _ in range(n)... | ASSIGN VAR VAR VAR LIST LIST LIST FUNC_DEF RETURN BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | def dot(a, b, c):
return a + c * b
def main():
n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
dp = [(0) for _ in range(n)]
st = [(0) for _ in range(n)]
i, j = 0, 0
for k in range(1, n):
while j - i > 0 and dot(dp[st[i]], b[st[i]],... | FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR AS... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | read = lambda: map(int, input().split())
n = int(input())
a = list(read())
b = list(read())
dp = [0] * n
ch = [0]
def get(i, x):
return b[i] * x + dp[i]
def f1():
if len(ch) < 2:
return 0
return get(ch[0], a[i]) >= get(ch[1], a[i])
def f2():
if len(ch) < 2:
return 0
i1 = ch[-1]... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | N = 100100
def main():
n = int(input())
d = [0] * N
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m, c = [0] * N, [0] * N
m[0] = b[0]
c[0] = d[0]
z = 1
p = 0
for i in range(1, n):
p = min(p, z)
while p + 1 < z and m[p + 1] * a[i] + c[p ... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUM... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | n = int(input())
a = [(0) for i in range(0, n + 1)]
b = [(0) for i in range(0, n + 1)]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [(0) for i in range(0, n + 1)]
c = [[(0) for i in range(0, 3)] for j in range(0, n + 1)]
stack = []
stack.append(0)
stack.append(1)
dp[0] = 0
dp[1] = a[1] *... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUN... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | n = int(input())
a = [0] + [int(x) for x in input().split()]
b = [0] + [int(x) for x in input().split()]
q = [(0) for i in range(n + 1)]
f = [(0) for _ in range(n + 1)]
l, r, q[1] = 1, 1, 1
for i in range(2, n + 1):
while l < r and f[q[l + 1]] - f[q[l]] < a[i] * (b[q[l]] - b[q[l + 1]]):
l += 1
f[i] = f[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NU... |
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bought a chain saw from a shop. Each time they use the chain saw on the... | n = int(input())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
C = [(0) for _ in range(n)]
hullx = [(0) for _ in range(n)]
hully = [(0) for _ in range(n)]
sz = -1
p = 0
def intersection(p, q):
nonlocal hullx, hully
return (hully[q] - hully[p]) / (hullx[p] - hullx[q])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN ... |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | pos = [1, 5, 13, 25, 41, 61, 85, 113]
num = [1, 3, 5, 7, 9, 11, 13, 15]
while True:
try:
x = int(input())
if x == 3:
print(5)
continue
i = 0
while pos[i] < x:
i += 1
print(num[i])
except:
break | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | u = int(input())
if u == 1:
print(1)
if 2 <= u <= 5:
if u == 3:
print(5)
else:
print(3)
if 6 <= u <= 13:
print(5)
if 14 <= u <= 25:
print(7)
if 26 <= u <= 41:
print(9)
if 42 <= u <= 61:
print(11)
if 62 <= u <= 85:
print(13)
if 86 <= u <= 100:
print(15) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR... |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | x = int(input())
arr = []
for i in range(1, 10000, 2):
arr.append(i // 2 * (i // 2) + (i // 2 + 1) * (i // 2 + 1))
counter = 0
ind = 1
while arr[counter] < x:
counter += 1
ind += 2
if x == 2:
print(3)
elif x == 3:
print(5)
else:
print(ind) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR... |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | def capacity(n):
result = n
for x in range(n - 2, 0, -2):
result += 2 * x
return result
class CodeforcesTask201ASolution:
def __init__(self):
self.result = ""
self.x = 0
def read_input(self):
self.x = int(input())
def process_task(self):
if self.x == ... | FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR FUNC... |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | n = int(input())
if n == 1:
i = 1
elif n != 3 and n < 6:
i = 3
else:
i = 5
while i * i // 2 + 1 < n:
i += 2
print(i) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | x = int(input())
if x == 3:
print(5)
else:
for i in range(100):
if i % 2 == 1:
if (i * i + 1) // 2 >= x:
print(i)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | x = int(input())
if x == 3:
print(5)
exit(0)
for i in range(1, 20, 2):
if i * i // 2 + 1 >= x:
print(i)
exit(0) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | def solve(n):
if n == 1:
return 1
if n == 3:
return 5
for k in range(100):
val = 4 * (((k - 1) ** 2 + 1) // 2 + (k + 1) // 2) - 3
if val >= n:
return 2 * k - 1
print(solve(int(input()))) | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_... |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | R = lambda: map(int, input().split())
x = int(input())
if x == 3:
print(5)
exit(0)
for i in range(1, 101, 2):
if (i * i + 1) // 2 >= x:
print(i)
break | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | def main():
x = int(input())
if x == 3:
print(5)
return
n = 1
while True:
if (n * n + 1) // 2 >= x:
print(n)
return
n += 2
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER EXPR FUNC_CALL VAR |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | n = int(input())
if n == 3:
print(5)
else:
x = 1
xx = 1
while xx < n:
x += 2
xx = x * x // 2 + 1
print(x) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | x = int(input())
if x == 1:
print(1)
elif x == 2:
print(3)
elif x == 3:
print(5)
else:
if x % 2 == 0:
k = x * 2
else:
k = x * 2 - 1
for n in range(1, 16, 2):
if n**2 >= k:
print(n)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMB... |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | x = int(input())
if x == 3:
print(5)
exit()
for i in range(50):
if (4 * i * i + 4 * i + 3) // 2 >= x:
print(2 * i + 1)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | def Solve(n):
if n % 2 == 1:
return n // 2 * n + (n // 2 + 1)
x = (n - 2) // 2
if x % 2 == 1:
return Solve(x) * 4
else:
return x // 2 * x * 4
L = [0, 1, 0]
for i in range(3, 1000):
L.append(Solve(i))
x = int(input())
if x == 3:
print(5)
else:
for i in range(1, 1000)... | FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUN... |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | x = int(input())
if x == 3:
print(5)
elif x <= 1:
print(1)
elif x <= 5:
print(3)
elif x <= 13:
print(5)
elif x <= 25:
print(7)
elif x <= 41:
print(9)
elif x <= 61:
print(11)
elif x <= 85:
print(13)
else:
print(15) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER I... |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | n = int(input())
if n == 3:
print(5)
exit()
for i in range(1, 200):
if i % 2 != 0:
v = i * i // 2 + 1
if n <= v:
print(i)
exit() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | def symmetry(x):
if x == 3:
return 5
k = 1
while k * k // 2 + 1 < x:
k += 2
return k
print(symmetry(int(input()))) | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Geek wants to distribute M balls among N children. His nemesis Keeg wants to disrupt his plan and removes P balls from Geek's bag. The minimum number of balls required to make each child happy are given in an array arr[]. Find the number of ways Geek can distribute the remaining balls so that each is happy.
Example 1:... | class Solution:
def countWays(self, m, n, p, arr):
m = m - p
if sum(arr) > m:
return -1
mod = int(1000000000.0 + 7)
dp = [[(0) for i in range(m + 1)] for j in range(n)]
for i in range(1, m + 1):
dp[0][i] = 1 if i >= arr[0] else 0
for i in rang... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CAL... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | def GCD(x, y):
if x < y:
x, y = y, x
while y != 0:
temp = x % y
x = y
y = temp
return x
n, m = [int(x) for x in input().split(" ")]
pri = [0, 1, 2]
for i in range(3, 60):
if GCD(pri[-1], i) == 1 and i < 60:
pri.append(pri[-1] * i)
else:
pri.append(pr... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EX... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | mod = 998244353
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
v = [1] * 38
for prime in primes:
for i in range(prime, 38):
v[i] *= prime
n, m = map(int, input().split())
ans = 0
ac = 1
for i in range(1, n + 1):
ac *= m
ac %= mod
uc = 1
if i >= 38:
uc = 0
else:
for... | ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CA... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | n, m = map(int, input().split())
if m == 1:
print(n - 1)
exit()
M = 998244353
tot = (pow(m, n + 1, M) - 1) * pow(m - 1, -1, M) - 1
p = set([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31])
fac = [1, 1]
for i in range(2, 37):
fac += (fac[-1] * (i if i in p else 1),)
i, res, temp = 2, m, m
while i <= min(n, 36) and f... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER NU... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | mod = 998244353
def solve(n, m):
primes = [1] * (n + 1)
for i in range(2, n + 1):
for j in range(i + i, n + 1, i):
primes[j] = 0
cur = 1
ans = 0
b = m
for i in range(1, n + 1):
if primes[i]:
b //= i
cur = cur * b % mod
ans = (ans + pow(m,... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | def add(a, b, mod):
return (a + b) % mod
def mul(a, b, mod):
return a * b % mod
def sub(a, b, mod):
return (a - b + mod) % mod
def binpow(a, n, mod):
if n == 0:
return 1
if n % 2 == 1:
return mul(a, binpow(a, n - 1, mod), mod)
b = binpow(a, n // 2, mod)
return mul(b, b,... | FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VA... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | sz = 300010
stat = [(1) for i in range(sz)]
stat[0] = 0
stat[1] = 0
for i in range(2, sz):
if stat[i] == 1:
for j in range(i * i, sz, i):
stat[j] = 0
n, m = list(map(int, input().split()))
mod = 998244353
p = 1
l = 1
ans = 0
flag = 0
m1 = 1
for i in range(1, n + 1):
if stat[i] == 1 and flag ... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIG... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | import sys
input = sys.stdin.readline
def solve():
n, m = map(int, input().split())
mo = 998244353
isPrime = [True] * 40
for i in range(2, 40):
if isPrime[i]:
for j in range(2 * i, 40, i):
isPrime[j] = False
ans = 0
others = m
val = 1
j = 2
for ... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | n, m = [int(i) for i in input().split()]
prime = [1] * (n + 1)
prime[1] = 0
for i in range(2, n + 1):
if prime[i]:
for j in range(i * i, n + 1, i):
prime[j] = 0
prod = 1
cur = 1
ans = 0
all_cnt = 0
MOD = 998244353
for i in range(1, n + 1):
if prime[i] and prod <= m:
prod = prod * i
... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR ... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | n, m = map(int, input().split())
mod = 998244353
num = n
prime = [(True) for i in range(num + 1)]
p = 2
while p * p <= num:
if prime[p] == True:
for i in range(p * p, num + 1, p):
prime[i] = False
p += 1
final = 0
total = 1
nonamb = 1
totpripro = 1
flag = n + 1
for i in range(1, n + 1):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIG... |
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.
An array $b$ with $n$ int... | N = 3 * 10**5 + 5
n, m = map(int, input().split())
p = [(1) for i in range(N)]
mod = 998244353
for i in range(2, N):
if p[i] == 1:
for j in range(2 * i, N, i):
p[j] = 0
ans = m
curr = m
l = 1
for i in range(2, n + 1):
if p[i] == 1:
l = l * i
if l > m:
break
curr = cur... | ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VA... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def bricks_game(N, A):
P = [(0) for _ in range(N)]
P[0] = A[0]
for i in range(1, N):
P[i] += P[i - 1] + A[i]
D = [(0) for _ in range(N)]
D[0] = A[0]
D[1] = D[0] + A[1]
D[2] = D[1] + A[2]
for i in range(3, N):
X = P[i - 1] + A[i] - D[i - 1]
Y = P[i - 2] + A[i] + A[... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER F... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def main():
t = input()
t = int(t)
for i in range(t):
n = input()
n = int(n)
lis = list(map(int, input().split()))
dp = [0] * (n + 10)
sumi = 0
for i in range(n - 1, -1, -1):
sumi += lis[i]
dp[i] = sumi - min(min(dp[i + 1], dp[i + 2]), ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMB... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | case_count = int(input())
cases = []
for i in range(case_count):
_ = input()
cases.append([int(i) for i in input().split()])
for case in cases:
size = len(case)
table = [[(0) for _ in range(size + 3)] for _ in range(2)]
gain = case[:]
gain.append(0)
gain.append(0)
gain.append(0)
for ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | for _ in range(int(input())):
n = int(input())
b = list(map(int, input().split()))
b.reverse()
sum = [0] * (n + 1)
for i in range(1, n + 1):
sum[i] = sum[i - 1] + b[i - 1]
dp = [0] * (n + 1)
dp[1] = b[0]
dp[2] = b[1] + dp[1]
dp[3] = b[2] + dp[2]
dp[4] = b[3] + b[2] + b[1]... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BI... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | T = int(input())
for i in range(T):
N = int(input())
numbers = [int(x) for x in input().split()]
if N <= 3:
print(sum(numbers))
continue
numbers = numbers + [0, 0, 0, 0, 0]
numbers[N + 3] = numbers[N - 3]
numbers[N + 4] = numbers[N - 2]
numbers[N - 2] += numbers[N - 1]
nu... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NU... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def bestScore(A, N):
B = [0] * (N + 1)
M = [0] * (N + 1)
for i in range(N - 1, -1, -1):
cand = []
for j in range(i, min(N, i + 3)):
e = j + 1
cand.append((sum(A[i:e]) + M[e], e))
value, r = max(cand)
B[i] = value
M[i] = B[r]
return B[0]
T... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VA... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | T = int(input())
for t in range(T):
N = int(input())
a = [0] + [int(c) for c in input().split(" ")][::-1]
dp = [0] * (N + 1)
s = [0] * (N + 1)
for i in range(1, N + 1):
s[i] = s[i - 1] + a[i]
dp[0] = 0
dp[1] = dp[0] + a[1]
dp[2] = dp[1] + a[2]
dp[3] = dp[2] + a[3]
for i i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER B... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | for case in range(int(input())):
N = int(input())
bricks = [int(x) for x in input().split()]
memo = [0] * N
for i in range(1, 4):
memo[-i] = sum(bricks[-i:]), i
for i in range(4, len(memo) + 1):
bestscore = 0
bestmoves = None
for j in range(1, 4):
_, hismo... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER AS... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | t = int(input())
for i in range(t):
n = int(input())
arr = [int(i) for i in input().strip().split()]
def calc(arr):
alen = len(arr)
if alen < 4:
return sum(arr)
presum = [0] * alen
presum[0] = arr[0]
for i in range(1, alen):
presum[i] = presum... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR F... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def play_game(array, N):
dp = [(0) for _ in range(N + 7)]
if N <= 3:
return sum(array)
for _ in range(3):
array.append(0)
for i in range(N)[::-1]:
dp[i] = max(
array[i] + min(dp[i + 2], dp[i + 3], dp[i + 4]),
array[i] + array[i + 1] + min(dp[i + 3], dp[i +... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def solve(A):
dp = [0] * (len(A) + 3)
A2 = A + [0, 0, 0]
for i in range(len(A) - 1, -1, -1):
dp[i] = max(
A2[i] - dp[i + 1],
A2[i] + A2[i + 1] - dp[i + 2],
A2[i] + A2[i + 1] + A2[i + 2] - dp[i + 3],
)
return (dp[0] + sum(A)) // 2
T = int(input())
for... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER B... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def cal(a, n):
ar = [a[n - 1], a[n - 1] + a[n - 2], a[n - 1] + a[n - 2] + a[n - 3]]
su = [a[n - 1]]
for i in range(1, n):
su.append(su[i - 1] + a[n - i - 1])
for i in range(3, n):
ar.append(
max(
a[n - 1 - i] + (su[i - 1] - ar[i - 1]),
a[n - i ... | FUNC_DEF ASSIGN VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR V... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | t = int(input())
for _ in range(t):
n = int(input())
b = list(map(int, input().split()))
dp = [0] * n
dp[n - 1] = b[n - 1]
dp[n - 2] = dp[n - 1] + b[n - 2]
dp[n - 3] = dp[n - 2] + b[n - 3]
s = dp[:]
for i in range(n - 4, -1, -1):
a1 = b[i] + s[i + 1] - dp[i + 1]
a2 = b[i]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BI... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | T = int(input())
for i in range(0, T):
N = int(input())
sum = [0] * (N + 1)
d = [0] * N
brick = list(map(int, input().split()))
for j in range(N - 1, -1, -1):
sum[j] = sum[j + 1] + brick[j]
d[N - 1] = brick[N - 1]
d[N - 2] = d[N - 1] + brick[N - 2]
d[N - 3] = d[N - 2] + brick[N -... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def solve(ns):
N = len(ns)
sums = [(0) for _ in ns] + [0]
for i in range(N):
sums[i + 1] = sums[i] + ns[i]
m = {(0): 0}
for i in range(N + 1):
if i >= 3:
one = ns[i - 1] + sums[i - 1] - m[i - 1]
two = ns[i - 1] + ns[i - 2] + sums[i - 2] - m[i - 2]
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BI... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | T = int(input())
for case in range(T):
N = int(input())
arr = list(map(int, input().rstrip().split(" ")))
dp = [0] * len(arr)
dp[len(arr) - 1] = arr[len(arr) - 1]
dp[len(arr) - 2] = arr[len(arr) - 2] + dp[len(arr) - 1]
dp[len(arr) - 3] = arr[len(arr) - 3] + dp[len(arr) - 2]
for i in range(le... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIG... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def maxScore(a):
dynmax = [(0, 0)] * (len(a) + 1)
for i in range(1, min(4, len(a))):
dynmax[i] = sum(a[-i:]), 0
for i in range(4, len(a) + 1):
for take in range(1, 4):
opp, mine = dynmax[i - take]
this = sum(a[-i : -i + take]) + mine, opp
if this > dynmax[... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | for case_t in range(int(input())):
answer_list = [0]
n = int(input())
b = [int(item) for item in input().strip().split()]
cur_sum = 0
for i in range(1, n + 1):
cur_sum += b[n - i]
if i <= 3:
answer_list.append(b[n - i] + answer_list[i - 1])
continue
ma... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VA... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def f(bricks, n):
dp = [(0) for _ in range(n + 3)]
sums = [(0) for _ in range(n + 3)]
for i in range(n - 1, -1, -1):
sums[i] = sums[i + 1] + bricks[i]
for i in range(n - 1, -1, -1):
dp[i] = max(
bricks[i] - dp[i + 1] + sums[i + 1],
bricks[i] + bricks[i + 1] - dp[i... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP ... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | import sys
cases = int(sys.stdin.readline().strip())
for x in range(cases):
sys.stdin.readline()
bricks = [int(x) for x in sys.stdin.readline().split(" ")]
n = len(bricks)
values = {}
totals = {}
cur_total = None
for position in reversed(range(n)):
if position == n - 1:
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VA... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def crea(a):
global mo, v
n = len(a)
mo = [0] * (n + 1)
v = [0] * (n + 1)
for i in range(3):
mo[i + 1] = i + 1
v[i + 1] = sum(a[k] for k in range(0, i + 1))
for j in range(4, n + 1):
p = [
(sum(a[j - i - 1] for i in range(k)) + v[j - k - mo[j - k]])
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CAL... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | INF = 10**18
def one_test():
n = int(input())
a = list(reversed(list(map(int, input().split()))))
dp = [0] * (n + 1)
for i in range(n):
take = 0
dp[i + 1] = -INF
for j in range(i, max(i - 3, -1), -1):
take += a[j]
dp[i + 1] = max(dp[i + 1], take - dp[j])... | ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VA... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | T = int(input())
S, M = [], []
def getMin(s):
x = min(M[s + 1], M[s + 2], M[s + 3])
for i in range(1, 4):
if x == M[s + i]:
return s + i
return -1
for _ in range(T):
N = int(input())
S = [int(x) for x in input().split()]
if N <= 3:
print(sum(S))
continue
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CA... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | t = int(input())
for i in range(t):
n = int(input())
num = list(map(int, input().split()))
num = num[::-1]
me = [(0) for i in range(n)]
opp = [(0) for i in range(n)]
me[0] = num[0]
me[1] = num[1] + num[0]
me[2] = num[2] + num[1] + num[0]
me[3] = num[3] + num[2] + num[1]
opp[3] = ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | T = int(input())
for T_i in range(T):
n = int(input())
l = [int(x) for x in input().split()]
l.reverse()
best = [(0) for x in range(n)]
p = []
p.append(l[0])
for i in range(1, n):
p.append(p[i - 1] + l[i])
best[0] = l[0]
best[1] = best[0] + l[1]
best[2] = best[1] + l[2]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BI... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | T = int(input())
for t in range(T):
N = int(input())
bricks = list(map(int, input().split(" ")))
dp = [(0, 0) for i in range(N + 1)]
for n in range(N - 1, -1, -1):
for b in (1, 2, 3):
if n + b <= N:
val = sum(bricks[n : n + b]) + dp[n + b][1], dp[n + b][0]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR NUMBER NUMBER NUMBE... |
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend wil... | def f(ar):
res = []
s = 0
for i in range(3):
s += ar[~i]
res.append(s)
for i in range(3, len(ar)):
s += ar[~i]
m = min(res)
res[i % 3] = s - m
return res[(len(ar) - 1) % 3]
for t in [1] * int(input()):
input()
ar = tuple(map(int, input().split()))
... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR BIN_OP LIST NUMB... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.