description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 1000000007
n, k, d = map(int, input().split())
count = [([0] * (n + 1)) for i in range(2)]
count[0][0] = 1
for nn in range(1, n + 1):
for i in range(1, min(k + 1, nn + 1)):
count[0][nn] += count[0][nn - i]
count[0][nn] %= MOD
for i in range(1, min(d, nn + 1)):
count[1][nn] += count[1][nn - i]
count[1][nn] %= MOD
for i in range(d, min(k + 1, nn + 1)):
count[1][nn] += count[0][nn - i]
count[1][nn] %= MOD
print(count[1][n]) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 1000000000.0 + 7
def Sulution():
n, k, d = [int(x) for x in input().split()]
dp = [[(0) for i in range(2)] for j in range(101)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
if j < d:
dp[i][0] += dp[i - j][0]
dp[i][0] %= mod
dp[i][1] += dp[i - j][1]
dp[i][1] %= mod
else:
dp[i][1] += dp[i - j][0]
dp[i][1] %= mod
dp[i][1] += dp[i - j][1]
dp[i][1] %= mod
return int(dp[n][1])
print(Sulution()) | ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
sys.setrecursionlimit(100000)
dp = {}
mod = 1000000007
def F(N, k, d, x):
global dp, mod
if (N, x) in dp:
return dp[N, x]
if N == 0:
if x == 1:
return 1
else:
return 0
if N < 0:
return 0
S = 0
x1 = 0
for i in range(1, k + 1):
if x or i >= d:
x1 = 1
else:
x1 = 0
S = (S + F(N - i, k, d, x1) % mod) % mod
dp[N, x] = S
return S
N, k, d = map(int, input().strip().split())
L = F(N, k, d, 0)
print(L) | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
def mod(x):
if x >= 10**9 + 7:
return x - (10**9 + 7)
return x
dp = [[0, 0] for i in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j >= 0:
if j < d:
dp[i][0] += dp[i - j][0]
dp[i][1] += dp[i - j][1]
dp[i][0] = mod(dp[i][0])
dp[i][1] = mod(dp[i][1])
else:
dp[i][1] += dp[i - j][0]
dp[i][1] = mod(dp[i][1])
dp[i][1] += dp[i - j][1]
dp[i][1] = mod(dp[i][1])
print(dp[n][1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | aim, size, needed = [int(i) for i in input().split()]
mod = 10**9 + 7
used = False
table_base = {}
def num_paths(used, curr):
if (used, curr) in table_base:
return table_base[used, curr]
count = 0
start_used = used
for i in range(1, size + 1):
if i == needed:
used = True
if curr + i < aim:
count += num_paths(used, curr + i)
elif curr + i == aim and used:
count += 1
else:
break
table_base[start_used, curr] = count
return count
print(num_paths(used, 0) % mod) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
v = [1]
for i in range(1, n + 1):
s = 0
for j in range(max(0, i - k), i):
s += v[j]
v.append(s)
a = [1]
for i in range(1, n + 1):
s = 0
for j in range(max(0, i - d + 1), i):
s += a[j]
a.append(s)
print((v[len(v) - 1] - a[len(a) - 1]) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp1 = [0] * 10000
dp2 = [0] * 10000
dp1[0] = 1
dp2[0] = 1
MOD = 1000 * 1000 * 1000 + 7
for i in range(n):
for j in range(1, k + 1):
dp1[i + j] += dp1[i]
dp1[i + j] %= MOD
for j in range(1, d):
dp2[i + j] += dp2[i]
dp2[i + j] %= MOD
if d > n:
print(0)
else:
print(int((dp1[n] - dp2[n]) % MOD)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def read_line():
return [int(i) for i in input().split(" ")]
def dp_calc(n, k, d):
lim = 1000000007
dist = [[1, 0]]
for i in range(1, n + 1):
s = [0, 0]
for j in range(1, k + 1):
if j > i:
break
if j < d:
s[0] += dist[i - j][0]
s[0] %= lim
s[1] += dist[i - j][1]
s[1] %= lim
else:
s[1] += dist[i - j][0]
s[1] %= lim
s[1] += dist[i - j][1]
s[1] %= lim
dist.append(s)
return dist[n][1]
n, k, d = read_line()
r = dp_calc(n, k, d)
print(r) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | P = 1000000007
A = [1]
B = [0]
n, k, d = map(int, input().split())
for i in range(n):
S1 = 0
S2 = 0
for j in range(k):
if j <= i:
S1 = (S1 + A[i - j]) % P
if j >= d - 1:
S2 = (S2 + A[i - j]) % P
else:
S2 = (S2 + B[i - j]) % P
A.append(S1)
B.append(S2)
print(B[n]) | ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
n, k, d = map(int, sys.stdin.readline().split())
dp = [0] * (n + 1)
dp1 = [0] * (n + 1)
dp[0] = dp1[0] = 1
mod = 1000000007
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
dp[i] += dp[i - j]
for i in range(1, n + 1):
for j in range(1, d):
if i < j:
break
dp1[i] += dp1[i - j]
print((dp[n] - dp1[n]) % mod) | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | total_weight, children, at_least_one = [int(x) for x in input().split()]
at_least_weights = [0] * (total_weight + 1)
not_least_weights = [0] * (total_weight + 1)
if total_weight < at_least_one:
print(0)
elif total_weight == at_least_one:
print(1)
else:
not_least_weights[0] = 1
for x in range(1, total_weight + 1):
for y in range(1, at_least_one):
if x - y >= 0:
not_least_weights[x] += not_least_weights[x - y]
at_least_weights[x] += at_least_weights[x - y]
for z in range(at_least_one, children + 1):
if x - z >= 0:
at_least_weights[x] += at_least_weights[x - z]
at_least_weights[x] += not_least_weights[x - z]
print(at_least_weights[total_weight] % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = input().split()
n = int(n)
k = int(k)
d = int(d)
dp = [[(0) for i in range(n + 1)] for j in range(k + 1)]
for i in range(k + 1):
dp[i][0] = 1
for j in range(1, n + 1):
for i in range(1, k + 1):
dp[i][j] = sum(dp[i][max(0, j - i) : j + 1])
print((dp[k][n] - dp[d - 1][n]) % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | tree = list(map(int, input("").split(" ")))
n, k, d = tree[0], tree[1], tree[2]
dp = [[(0) for i in range(2)] for j in range(n + 1)]
dp[0][0] = 1
dp[0][1] = 0
mod = 1000000007
for i in range(1, n + 1):
dp[i][0] = 0
dp[i][1] = 0
for j in range(1, k + 1):
if i - j < 0:
break
if j >= d:
dp[i][1] += dp[i - j][0]
dp[i][1] += dp[i - j][1]
else:
dp[i][0] += dp[i - j][0]
dp[i][1] += dp[i - j][1]
print(dp[n][1] % mod) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def solve(n, k, d, e, memo):
if n < 0:
return 0
if n == 0:
return e
if (n, e) in memo:
return memo[n, e]
ans = 0
for i in range(1, d):
ans += solve(n - i, k, d, e, memo)
for i in range(d, k + 1):
ans += solve(n - i, k, d, 1, memo)
memo[n, e] = ans % 1000000007
return ans % 1000000007
n, k, d = (int(x) for x in input().split())
print(solve(n, k, d, 0, dict())) | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import itertools
I = lambda: map(int, input().split())
n, k, d = I()
levels = [{(0): [1, 0]}]
for i in range(n):
levels.append({})
for w_0, w_d in itertools.product(levels[-2], range(1, k + 1)):
w_1 = w_0 + w_d
if w_1 > n:
continue
if w_1 not in levels[-1]:
levels[-1][w_1] = [0, 0]
if w_d >= d:
levels[-1][w_1][1] += sum(levels[-2][w_0])
else:
levels[-1][w_1][0] += levels[-2][w_0][0]
levels[-1][w_1][1] += levels[-2][w_0][1]
ans = 0
for l in levels:
if n in l:
ans += l[n][1]
print(ans % 1000000007) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST DICT NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR DICT FOR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR LIST NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 1000000007
d = []
for _ in range(101):
d.append([0, 0])
def add(a, b):
a += b
if a >= mod:
a -= mod
return a
n, k, h = map(int, input().split())
d[0][0] = 1
d[0][1] = 0
for i in range(1, n + 1):
d[i][0] = d[i][1] = 0
for j in range(1, k + 1):
if i - j < 0:
break
if j < h:
d[i][0] = add(d[i][0], d[i - j][0])
d[i][1] = add(d[i][1], d[i - j][1])
else:
d[i][1] = add(d[i][1], d[i - j][0])
d[i][1] = add(d[i][1], d[i - j][1])
print(d[n][1]) | ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER FUNC_DEF VAR VAR IF VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 1000000007
n, k, d = map(int, input().split())
dp1 = [0] * (n + 5)
dp2 = [0] * (n + 5)
dp1[0] = 1
dp2[0] = 1
for i in range(1, n + 1):
s = 0
for j in range(1, k + 1):
if j <= i:
s = (s + dp1[i - j]) % MOD
dp1[i] = s
for i in range(1, n + 1):
s = 0
for j in range(1, k + 1):
if j <= i:
if j >= d:
s = (s + dp1[i - j]) % MOD
elif i - j >= d:
s = (s + dp2[i - j]) % MOD
dp2[i] = s
print(dp2[n]) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [[0, 0] for j in range(n)]
for i in range(min(n, k)):
dp[i][0] = 1
if i >= d - 1:
dp[i][1] = 1
for i in range(n):
for j in range(max(0, i - k), i):
dp[i][0] += dp[j][0]
if i - j >= d:
dp[i][1] += dp[j][0]
else:
dp[i][1] += dp[j][1]
print(dp[-1][-1] % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def k_tree(n, k, d, suma, flag, memo):
if suma > n:
return 0
if suma == n:
if flag == 1:
return 1
else:
return 0
if memo[suma][flag] != -1:
return memo[suma][flag]
aux = 0
for i in range(1, k + 1):
aux += k_tree(n, k, d, suma + i, 1 if i >= d else flag, memo)
aux %= 1000000007
memo[suma][flag] = aux
return memo[suma][flag]
n, k, d = map(int, input().split())
memo = [[(-1) for i in range(2)] for i in range(n)]
print(k_tree(n, k, d, 0, 0, memo)) | FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | t = 10**9 + 7
n, k, d = map(int, input().split())
dp = [[(0) for i in range(k + 1)] for i in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
if j < d:
dp[i][0] = (dp[i][0] % t + dp[i - j][0] % t) % t
dp[i][1] = (dp[i][1] % t + dp[i - j][1] % t) % t
else:
dp[i][1] = (dp[i][1] % t + dp[i - j][0] % t + dp[i - j][1] % t) % t
print(dp[n][1]) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | bignum = 10**9 + 7
n, k, d = [int(i) for i in input().split()]
D = [[(0) for j in range(2)] for i in range(n + 1)]
D[0][0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
if j < d:
D[i][0] += D[i - j][0]
D[i][1] += D[i - j][1]
D[i][0] %= bignum
D[i][1] %= bignum
else:
D[i][1] += D[i - j][0] + D[i - j][1]
D[i][1] %= bignum
print(D[n][1]) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def count(b, n):
a = [0] * (n + 1)
m = len(b)
a[0] = 1
for i in range(1, n + 1):
for j in range(m):
if i >= b[j]:
a[i] += a[i - b[j]]
return a[n]
n, k, d = list(map(int, input().split()))
a = [i for i in range(1, k + 1)]
b = [i for i in range(1, d)]
print((count(a, n) - count(b, n)) % (10**9 + 7)) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def fn(n, k, p, dp):
m = 1000000007
if n == 0:
return 1
t = [0] * (k + 1)
for i in range(1, k + 1):
if i == p:
break
if n < i:
break
t[i] = 1
if dp[n - i] != -1:
u = dp[n - i]
else:
u = fn(n - i, k, p, dp)
dp[n - i] = u % m
t[i] = t[i] * (u % m) % m
v = 0
for i in range(len(t)):
v = (v + t[i]) % m
return v
m = 1000000007
n, k, p = map(int, input().split())
dp1 = [-1] * (n + 1)
dp2 = [-1] * (n + 1)
print((fn(n, k, -1, dp1) - fn(n, k, p, dp2) + m) % m) | FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
mod = 10**9 + 7
dp = []
d1 = n - d + 1
try:
for i in range(d1 + 1):
dp.append([])
for j in range(n + 1):
dp[i].append([0] * (d + 1))
dp[0][0][0] = 1
for i in range(0, d1):
for j in range(i, n + 1):
for y in range(d + 1):
for x in range(1, min(n - j, k) + 1):
dp[i + 1][j + x][min(max(x, y), d)] = (
dp[i + 1][j + x][min(max(x, y), d)] + dp[i][j][y]
) % mod
ans = 0
for i in range(d1 + 1):
ans = (ans + dp[i][n][d]) % mod
print(ans)
except:
print(0) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def func(n, k):
arr = [(0) for i in range(n + 1)]
arr[0] = 1
if n <= 0:
return 0
for j in range(1, n + 1):
for i in range(1, min(k + 1, j + 1)):
arr[j] += arr[j - i]
return arr[n]
n, k, d = map(int, input().split())
p = 1000000007
print((func(n, k) - func(n, d - 1)) % p) | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
f = [0] * (n + 1)
g = [1] * (n + 1)
d = 1 - d
m = 1000000007
for i in range(1, n + 1):
f[i] = (
sum(g[j] for j in range(max(0, i - k), d + i))
+ sum(f[j] for j in range(max(0, d + i), i))
) % m
g[i] = sum(g[j] for j in range(max(0, i - k), i)) % m
print(f[n]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split(" "))
dp = [[(-1) for i in range(202)] for j in range(2002)]
mod = int(1000000007)
def f(_sum, ok):
if dp[_sum][ok] == -1 and _sum < n:
ans = 0
for i in range(1, k + 1):
if ok == 0 and i >= d:
ans += f(_sum + i, 1)
else:
ans += f(_sum + i, ok)
ans = ans % mod
dp[_sum][ok] = ans
return ans
if dp[_sum][ok] != -1 and _sum < n:
return dp[_sum][ok]
if _sum == n and ok == 1:
dp[_sum][ok] = 1
if _sum > n:
dp[_sum][ok] = 0
if _sum == n and ok == 0:
dp[_sum][ok] = 0
return dp[_sum][ok]
print(f(0, 0)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR NUMBER VAR VAR RETURN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def solve(n, k, d):
dp = []
modulo = 1000000007
for i in range(n + 1):
dp.append([0] * (n + 1))
dp[0][0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j < 0:
break
if j < d:
dp[i][0] = (dp[i][0] + dp[i - j][0]) % modulo
dp[i][1] = (dp[i][1] + dp[i - j][1]) % modulo
else:
dp[i][1] = (dp[i][1] + dp[i - j][0]) % modulo
dp[i][1] = (dp[i][1] + dp[i - j][1]) % modulo
return dp[n][1]
def main():
n, k, d = list(map(int, input().split()))
print(solve(n, k, d))
main() | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR RETURN VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = list(map(int, input().split()))
dct = {}
def getPaths(s, k, got, d):
global dct
tot = 0
try:
tot = dct[s, k, got, d]
return tot
except:
pass
for x in range(1, k + 1):
if x == s:
if got or x >= d:
tot += 1
break
elif x < s:
if x >= d:
tot += getPaths(s - x, k, True, d)
else:
tot += getPaths(s - x, k, got, d)
dct[s, k, got, d] = tot
return tot
total = getPaths(n, k, False, d)
print(total % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
l1 = [0]
for i in range(1, n + 1):
if i <= k:
l1.append(2 ** (i - 1))
else:
l1.append(sum(l1[i - k : i]))
l2 = [0]
for i in range(1, n + 1):
if i <= d - 1:
l2.append(2 ** (i - 1))
else:
l2.append(sum(l2[i - d + 1 : i]))
print((l1[n] - l2[n]) % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
memoized_f, memoized_g = [-1] * (n + 1), [-1] * (n + 1)
def g(n, k):
if memoized_g[n] == -1:
memoized_g[n] = 0
for i in range(1, k + 1):
if i > n:
break
if i == n:
memoized_g[n] += 1
else:
memoized_g[n] += g(n - i, k)
memoized_g[n] %= 1000000007
return memoized_g[n]
def f(n, k, d):
if memoized_f[n] == -1:
memoized_f[n] = 0
for i in range(1, k + 1):
if i > n:
break
if i == n:
memoized_f[n] += i >= d
else:
memoized_f[n] += g(n - i, k) if i >= d else f(n - i, k, d)
memoized_f[n] %= 1000000007
return memoized_f[n]
print(f(n, k, d)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [(0) for x in range(n + 1)]
dp[0] = 1
for i in range(1, n + 1):
for j in range(1, min(k, i) + 1):
dp[i] += dp[i - j]
dp1 = [(0) for x in range(n + 1)]
dp1[0] = 1
for i in range(1, n + 1):
for j in range(1, min(d - 1, i) + 1):
dp1[i] += dp1[i - j]
print((dp[n] - dp1[n]) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | M = 10**9 + 7
n, k, d = map(int, input().split())
dp = [[0, 0] for i in range(n + 1)]
for i in range(1, min(n, d)):
dp[i][0] = 1
for i in range(d, min(n + 1, k + 1)):
dp[i][1] = 1
for i in range(1, n + 1):
zero = dp[i][0]
for j in range(i - 1, max(0, i - d), -1):
zero += dp[j][0]
zero %= M
dp[i][0] = zero
one = dp[i][1]
for j in range(i - 1, max(0, i - k - 1), -1):
one += dp[j][1]
one %= M
for j in range(max(0, i - d), max(0, i - k - 1), -1):
one += dp[j][0]
one %= M
dp[i][1] = one
print(dp[n][-1]) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = [int(x) for x in input().split()]
z = [[1], [1]]
for i in range(1, n + 1):
z[0].append(sum(z[0][max(i - d + 1, 0) :]))
z[1].append(sum(z[1][max(i - k, 0) :]))
print((z[1][-1] - z[0][-1]) % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 1000000007
line = input().split()
n = int(line[0])
k = int(line[1])
d = int(line[2])
dp = [[-1, -1] for i in range(100000)]
def rec(num, gud):
global k, d
if num < 0:
return 0
if num == 0:
return gud
if dp[num][gud] != -1:
return dp[num][gud]
dp[num][gud] = 0
for i in range(1, k + 1):
dp[num][gud] += rec(num - i, gud or i >= d) % MOD
dp[num][gud] = dp[num][gud] % MOD
return dp[num][gud]
print(rec(n, 0)) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def add_self(i, j, x):
dp[i][j] += dp[x][j]
if dp[i][j] > m:
dp[i][j] -= m
n, k, d = map(int, input().split())
m = 1000000007
dp = [[[0, 1][i == 1 and j != 0] for j in range(k + 1)] for i in range(n + 1)]
for i in range(2, n + 1):
for j in range(1, k + 1):
if i <= j:
dp[i][j] = (1 << i - 1) % m
else:
for x in range(i - j, i):
add_self(i, j, x)
print((dp[n][k] - dp[n][d - 1]) % m) | FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
mod = 10**9 + 7
st = [0] * (n + 1)
st[0] = 1
for j in range(1, n + 1):
su = 0
for i in range(max(0, j - k), j):
su += st[i] % mod
st[j] = su % mod
if d == 1:
print(st[-1])
else:
lst = [0] * (n + 1)
lst[0] = 1
for j in range(1, n + 1):
su = 0
for i in range(max(0, j - d + 1), j):
su += lst[i] % mod
lst[j] = su % mod
print((st[-1] - lst[-1]) % mod) | ASSIGN VAR 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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
input = sys.stdin.readline
n, k, d = map(int, input().split())
dp = [[0, 0] for i in range(n + 1)]
dp[0][0] = 1
mod = 10**9 + 7
for i in range(1, n + 1):
for j in range(1, min(i + 1, k + 1)):
if j < d:
dp[i][0] += dp[i - j][0]
if j >= d:
dp[i][1] += dp[i - j][0] + dp[i - j][1]
else:
dp[i][1] += dp[i - j][1]
dp[i][0] %= mod
dp[i][1] %= mod
print(dp[n][1]) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | I = lambda: list(map(int, input().split(" ")))
def path(total, num):
if total in mem:
return mem[total]
if total == 0:
return 1
else:
mem[total] = 0
for i in range(1, num + 1):
if total - i >= 0:
mem[total] += path(total - i, num)
else:
break
return mem[total]
def ans(n, k, d):
global mem
mem = {}
a = path(n, k)
if d > 1:
mem = {}
b = path(n, d - 1)
else:
b = 0
return a - b
n, k, d = I()
print(ans(n, k, d) % int(10**9 + 7)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
dp = [[(0) for i in range(3)] for j in range(101)]
dp[0][0], dp[0][1] = 1, 0
md = 10**9 + 7
for i in range(1, n + 1):
dp[i][0] = dp[i][1] = 0
for j in range(1, k + 1):
if i < j:
break
if j < d:
dp[i][0] = (dp[i][0] + dp[i - j][0]) % md
dp[i][1] = (dp[i][1] + dp[i - j][1]) % md
else:
dp[i][1] = (dp[i][1] + dp[i - j][0]) % md
dp[i][1] = (dp[i][1] + dp[i - j][1]) % md
print(dp[n][1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
def recurse(n, d, dp={}):
if n == d:
return 1
if (n, d) not in dp:
dp[n, d] = (
sum(recurse(n - i, d if i < d else 0) for i in range(1, min(n + 1, k + 1)))
% 1000000007
)
return dp[n, d]
print(recurse(n, d)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF DICT IF VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
ai = [0] * (n + 1)
k = min(n, k)
ai[0] = 1
mode = 10**9 + 7
for i in range(1, k):
for j in range(i):
ai[i] += ai[j]
for i in range(k, n + 1):
for j in range(1, k + 1):
ai[i] += ai[i - j]
d = min(n, d - 1)
ai2 = [0] * (n + 1)
ai2[0] = 1
for i in range(1, d):
for j in range(i):
ai2[i] += ai2[j]
for i in range(d, n + 1):
for j in range(1, d + 1):
ai2[i] += ai2[i - j]
print((ai[n] - ai2[n]) % mode) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | ans = {}
def gen(n, k, d, used=False):
if not ans.get((n, k, d, used)):
if not n and used:
ans[n, k, d, used] = 1
else:
ans[n, k, d, used] = sum(
gen(n - x, k, d, used or x >= d)
for x in range(1, min(n, k) + 1)
if max(x, n - x) >= d or used
)
return ans[n, k, d, used]
n, k, d = list(map(int, input().split()))
print(gen(n, k, d) % 1000000007) | ASSIGN VAR DICT FUNC_DEF NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, x, d = map(int, input().strip().split())
dp, mod = [[0, 0] for _ in range(n + 1)], 10**9 + 7
dp[0][0], dp[0][1] = 1, 0
for total in range(1, n + 1):
for edge in range(1, x + 1):
if total - edge < 0:
break
if edge < d:
dp[total][0] = (dp[total][0] + dp[total - edge][0]) % mod
dp[total][1] = (dp[total][1] + dp[total - edge][1]) % mod
else:
dp[total][1] = (dp[total][1] + dp[total - edge][0]) % mod
dp[total][1] = (dp[total][1] + dp[total - edge][1]) % mod
print(dp[n][1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 1000000007
n, k, d = map(int, input().split())
if d > n:
print(0)
else:
dp = [[0, 0] for x in range(n + 1)]
dp[0][0], dp[0][1] = 1, 0
for sm in range(1, n + 1):
till = min(d - 1, sm)
for weight in range(1, till + 1):
dp[sm][0] += dp[sm - weight][0] % MOD
dp[sm][1] += dp[sm - weight][1] % MOD
for weight in range(till + 1, min(sm, k) + 1):
dp[sm][1] += dp[sm - weight][0] % MOD
dp[sm][1] += dp[sm - weight][1] % MOD
print(dp[sm][1] % MOD) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
n, k, d = map(int, input().split())
mod = 10**9 + 7
if d > n:
print(0)
sys.exit(0)
c = [0] * (n + 1)
cod = [0] * (n + 1)
for i in range(1, n + 1):
c[i] = 1 if i <= k else 0
cod[i] = 1 if i < d else 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
else:
c[i] = (c[i] + c[i - j]) % mod
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
elif j < d:
cod[i] = (cod[i] + cod[i - j]) % mod
print((c[n] - cod[n]) % mod) | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR 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 BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | inputs = [int(x) for x in input().split()]
desired_weight = inputs[0]
k = inputs[1]
min_weight = inputs[2]
saved = [{(True): None, (False): None} for i in range(desired_weight + 1)]
saved[desired_weight] = {(True): 0, (False): 0}
modulo = 1000000007
for i in reversed(range(0, desired_weight)):
range_to_work_with = i + k
hit_min_value = 0
fail_to_hit_min_value = 0
travel_range = range(
i + 1, i + k + 1 if i + k + 1 <= desired_weight + 1 else desired_weight + 1
)
for j in travel_range:
if j - i >= min_weight:
fail_to_hit_min_value += saved[j][True]
else:
fail_to_hit_min_value += saved[j][False]
fail_to_hit_min_value += (
1 if desired_weight - i <= k and desired_weight - i >= min_weight else 0
)
for j in travel_range:
hit_min_value += saved[j][True]
hit_min_value += 1 if desired_weight - i <= k else 0
saved[i][True] = hit_min_value
saved[i][False] = fail_to_hit_min_value
print(saved[0][False] % modulo) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NONE NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR DICT NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
done = {}
def num_pos(i, d_in):
if (i, d_in) in done:
return done[i, d_in]
if i == 0 and d_in:
return 1
if i == 0:
return 0
pos = 0
for v in range(1, k + 1):
if v > i:
break
pos += num_pos(i - v, d_in or v >= d)
done[i, d_in] = pos
return pos
print(num_pos(n, False) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split(" "))
dp = [[0, 0] for i in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j < 0:
break
if j < d:
dp[i][0] += dp[i - j][0] % 1000000007
dp[i][1] += dp[i - j][1] % 1000000007
else:
dp[i][1] += dp[i - j][0] % 1000000007
dp[i][1] += dp[i - j][1] % 1000000007
print(dp[n][1] % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def solve(sums, c):
if sums == 0:
if c >= d:
return True
return False
if sums < 0:
return False
if grid[sums][c] != -1:
return grid[sums][c]
temp = 0
for i in range(1, k + 1):
temp += solve(sums - i, max(i, c))
temp = temp % mod
grid[sums][c] = temp
return temp
n, k, d = map(int, input().split())
mod = 1000000007
grid = [[(-1) for i in range(n + 1)] for j in range(n + 1)]
print(solve(n, 0)) | FUNC_DEF IF VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
n, k, d = I()
md = 10**9 + 7
dp = [[0, 0] for i in range(102)]
dp[0][0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i < j:
break
if j < d:
dp[i][0] = (dp[i][0] + dp[i - j][0]) % md
dp[i][1] = (dp[i][1] + dp[i - j][1]) % md
else:
dp[i][1] = (dp[i][1] + dp[i - j][0] + dp[i - j][1]) % md
print(dp[n][1]) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
ans = {}
def dp_solve(n, k):
if k == 0:
return 0
ans[0] = 1
ans[1] = 1
for i in range(2, n + 1):
cur_t = 0
for j in range(1, k + 1):
if i - j >= 0:
cur_t += ans[i - j]
ans[i] = cur_t
return ans[n]
a = dp_solve(n, k)
b = dp_solve(n, d - 1)
print((a - b) % int(1000000000.0 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = [int(x) for x in input().split(" ")]
MOD = 1000000000.0 + 7
ps = {}
ps2 = {}
def dfs(n_left):
count = 0
for i in range(1, k + 1):
if n_left - i == 0:
count += 1
break
if n_left - i in ps:
inner_count = ps[n_left - i]
else:
inner_count = dfs(n_left - i)
count += inner_count % MOD
ps[n_left] = count % MOD
return ps[n_left]
def dfs2(n_left):
count = 0
for i in range(1, d):
if n_left - i == 0:
count += 1
break
if n_left - i in ps2:
inner_count = ps2[n_left - i]
else:
inner_count = dfs2(n_left - i)
count += inner_count % MOD
ps2[n_left] = count % MOD
return ps2[n_left]
ans = dfs(n) - dfs2(n) + MOD
print(int(ans % MOD)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = list(map(int, input().split()))
def get_ways(n, upper_bound):
ways = [1] + [0] * n
for i in range(1, n + 1):
ways[i] = sum(ways[max(0, i - upper_bound) : i])
return ways[n]
print((get_ways(n, k) - get_ways(n, d - 1)) % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR RETURN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | m = 1000000000.0 + 7
def add_mod(numb: int, ways: int) -> int:
numb += ways
if numb >= m:
return int(numb % m)
return numb
n, k, d = map(int, input().split())
a = [([0] * 2) for i in range(n + 1)]
a[0][0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j < 0:
break
if j < d:
a[i][0] = add_mod(a[i][0], a[i - j][0])
a[i][1] = add_mod(a[i][1], a[i - j][1])
else:
a[i][1] = add_mod(a[i][1], a[i - j][0])
a[i][1] = add_mod(a[i][1], a[i - j][1])
print(a[n][1]) | ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF VAR VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
M = 1000000007
a = [1] + [0] * n
for i in range(1, n + 1):
for j in range(max(0, i - k), i):
a[i] = (a[i] + a[j]) % M
b = [1] + [0] * n
for i in range(1, n + 1):
for j in range(max(0, i - d + 1), i):
b[i] = (b[i] + b[j]) % M
print((a[n] - b[n]) % M) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def w(N, K):
a = [0] * (N + 1)
a[0] = 1
d = 1
i = 1
while i <= min(N, K):
a[i] = d
d += a[i]
i += 1
if N > K:
x = K + 1
while x <= N:
a[x] = sum(a[x - K : x])
x += 1
return a[-1]
def sol():
n, k, g = map(int, input().split(" "))
result = (w(n, k) - w(n, g - 1)) % (10**9 + 7)
print(result)
sol() | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
mod = 10**9 + 7
memo = {}
def DFS(hasD=False, totalSum=n):
global memo
c = 0
startD = hasD
for i in range(1, k + 1):
hasD = startD
if i >= d:
hasD = True
if totalSum - i == 0:
if hasD:
c += 1
break
if (hasD, totalSum - i) not in memo:
memo[hasD, totalSum - i] = DFS(hasD, totalSum - i)
c += memo[hasD, totalSum - i]
return c % mod
print(DFS()) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT FUNC_DEF NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(" ")))
def solve():
n, k, d = read_ints()
modulo = 10**9 + 7
OPT = [[0, 0] for _ in range(n + 1)]
OPT[0][False] = 1
for i in range(1, n + 1):
OPT[i][False] = sum(OPT[i - j][False] for j in range(1, min(i + 1, d))) % modulo
OPT[i][True] = (
sum(OPT[i - j][False] for j in range(d, min(i + 1, k + 1)))
+ sum(OPT[i - j][True] for j in range(1, min(i + 1, k + 1)))
) % modulo
return OPT[-1][True]
print(solve()) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
meme = [[(-1) for i in range(2)] for j in range(123)]
def fucc(qtd, zeroum):
global meme
global n
global k
global d
if zeroum == 1 and qtd == n:
return 1
if qtd >= n:
return 0
if meme[qtd][zeroum] != -1:
return meme[qtd][zeroum]
tmp = zeroum
res = 0
for i in range(1, k + 1):
if i >= d:
tmp = 1
res += fucc(qtd + i, tmp) % 1000000007
meme[qtd][zeroum] = res
return res
print(fucc(0, 0) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = input().split()
n, k, d = int(n), int(k), int(d)
ans1 = [(0) for _ in range(101)]
ans1[0] = 1
ans = [(0) for _ in range(101)]
for i in range(d):
ans[i] = 0
for i in range(0, n + 1):
j = 1
while j <= k and i - j >= 0:
ans1[i] += ans1[i - j]
j += 1
for i in range(d, n + 1):
j = 1
while j <= k and i - j >= 0:
if j >= d:
ans[i] += ans1[i - j]
else:
ans[i] += ans[i - j]
j += 1
print(ans[n] % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | mod = 1000000007
n, k, d = [int(i) for i in input().split()]
dp = [[0, 0] for i in range(n + 1)]
dp[0][1] = 0
dp[0][0] = 1
if n == 1:
print(1 if d == 1 else 0)
else:
for i in range(1, n + 1):
total = 0
for j in range(max(0, i - k), i):
total += dp[j][0] % mod
dp[i][0] = total % mod
for i in range(1, n + 1):
total = 0
for j in range(max(0, i - d + 1), i):
total += dp[j][1] % mod
for j in range(max(0, i - k), max(0, i - d + 1)):
total += dp[j][0] % mod
dp[i][1] = total % mod
print(int(dp[n][1] % mod)) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 1000000007
n, k, d = map(int, input().split())
dp = [(0) for i in range(n + 1)]
dp[0] = 1
dp[1] = 1
for i in range(2, n + 1):
for j in range(max(0, i - k), i):
dp[i] += dp[j]
dp2 = [(0) for i in range(n + 1)]
dp2[0] = 1
dp2[1] = 1
for i in range(2, n + 1):
for j in range(max(0, i - d + 1), i):
dp2[i] += dp2[j]
ans = dp[n] - dp2[n]
if n == 1 and d <= 1:
ans = 1
if ans > MOD:
ans = ans % MOD
print(ans) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
N = 10**9 + 7
matrix = [[(0) for x1 in range(k + 1)] for x2 in range(n + 1)]
matrix[0][0] = 1
for s in range(0, n):
for l in range(1, k + 1):
if s + l > n:
break
for ml in range(0, k + 1):
matrix[s + l][max(ml, l)] += matrix[s][ml]
matrix[s + l][max(ml, l)] %= N
print(sum(matrix[-1][d:]) % N) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | x = input()
x = x.split()
n = int(x[0])
k = int(x[1])
d = int(x[2])
limit = 1000000007
l0 = {(0): 1}
ld = {(0): 1}
for i in range(-k, 0):
l0[i] = 0
for i in range(1, n + 1):
l0[i] = 0
for j in range(i - k, i):
l0[i] += l0[j]
if l0[i] > limit:
l0[i] = l0[i] % limit
for i in range(d - k, d):
if i != 0:
ld[i] = 0
for i in range(d, n + 1):
ld[i] = 0
for j in range(i - k, i - d + 1):
ld[i] += l0[j]
if ld[i] > limit:
ld[i] = ld[i] % limit
for j in range(i - d + 1, i):
ld[i] += ld[j]
if ld[i] > limit:
ld[i] = ld[i] % limit
print(ld[n]) | ASSIGN 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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | inputlist = list(map(int, input().split()))
n = inputlist[0]
k = inputlist[1]
d = inputlist[2]
def dp(sum1, limiter):
array = [1] * 2
if limiter == 0:
return 0
elif limiter == 1:
return 1
elif limiter == 2:
for j in range(sum1 - 1):
array.append(array[len(array) - 1] + array[len(array) - 2])
return array[-1]
elif sum1 > limiter:
for j in range(1, limiter):
array.append(2**j)
leftpointer = 1
rightpointer = limiter
s = sum(array[1:])
array.append(s)
for j in range(sum1 - limiter - 1):
s -= array[leftpointer]
rightpointer += 1
s += array[rightpointer]
array.append(s)
leftpointer += 1
return array[-1]
elif sum1 <= limiter:
return 2 ** (sum1 - 1)
print((dp(n, k) - dp(n, d - 1)) % (10**9 + 7)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR NUMBER IF VAR VAR RETURN BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = 1000000007
n, k, d = map(int, input().split(" "))
def add(a, b):
a += b
return a % MOD
dp = [([0] * 2) for i in range(101)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i - j < 0:
break
if j < d:
dp[i][0] = add(dp[i][0], dp[i - j][0])
dp[i][1] = add(dp[i][1], dp[i - j][1])
else:
dp[i][1] = add(dp[i][1], dp[i - j][0])
dp[i][1] = add(dp[i][1], dp[i - j][1])
print(dp[n][1]) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | M = 10**9 + 7
class paths:
def __init__(self):
super().__init__()
self.dp = {}
def no_of_paths(self, n, k):
if n in self.dp:
return self.dp[n]
if n == 0:
return 1
elif n < 0:
return 0
else:
paths = 0
for i in range(1, k + 1):
val = self.no_of_paths(n - i, k)
paths += val
self.dp[n] = paths
return paths
n, k, d = map(int, input().split())
pathk = paths()
pathd = paths()
print((pathk.no_of_paths(n, k) - pathd.no_of_paths(n, d - 1)) % M) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF EXPR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | ar = []
for i in input().split(" "):
ar.append(int(i))
n = ar[0]
k = ar[1]
d = ar[2]
dict = {}
dict[0] = [1, 0]
for i in range(n + 1):
for j in range(1, k + 1):
if j >= d:
if i + j in dict:
dict[i + j][1] = dict[i][0] + dict[i][1] + dict[i + j][1]
else:
dict[i + j] = [0, dict[i][0] + dict[i][1]]
elif i + j in dict:
dict[i + j][0] = dict[i][0] + dict[i + j][0]
dict[i + j][1] = dict[i][1] + dict[i + j][1]
else:
dict[i + j] = [dict[i][0], dict[i][1]]
print(dict[n][1] % 1000000007) | ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR LIST NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR LIST VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().strip().split(" "))
dp = [0] * (n + k + 1)
vp = [0] * (n + k + 1)
for i in range(1, n + 1):
for j in range(1, k + 1):
dp[i] += dp[i - j]
if j >= d:
continue
else:
vp[i] += vp[i - j]
if i <= k:
dp[i] += 1
if i >= d:
continue
else:
vp[i] += 1
print((dp[n] - vp[n]) % (10**9 + 7)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = list(map(int, input("").split()))
arr = [0] * (n + 1)
arr[0] = 0, 1
num_list = [i for i in range(1, k + 1)]
for i in range(1, n + 1):
if i < d:
total_paths = 0
for num in num_list:
if i - num >= 0:
total_paths += arr[i - num][1]
arr[i] = 0, total_paths
else:
all_paths = 0
conditioned_paths = 0
for num in num_list:
if num >= d and i - num >= 0:
all_paths += arr[i - num][1]
conditioned_paths += arr[i - num][1]
elif i - num >= 0:
all_paths += arr[i - num][1]
conditioned_paths += arr[i - num][0]
arr[i] = conditioned_paths, all_paths
print(arr[n][0] % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | import sys
input = sys.stdin.buffer.readline
def I():
return list(map(int, input().split()))
def sieve(n):
a = [1] * n
for i in range(2, n):
if a[i]:
for j in range(i * i, n, i):
a[j] = 0
return a
MOD = 10**9 + 7
def rec(s, f):
if s < 0:
return 0
if s == 0:
if f == 1:
return 0
else:
return 1
ans = 0
if dp[s][f] != -1:
return dp[s][f]
for i in range(1, k + 1):
if i < d:
ans += rec(s - i, f)
else:
ans += rec(s - i, 0)
ans %= MOD
dp[s][f] = ans
return ans
n, k, d = I()
dp = [[-1, -1] for i in range(n + 1)]
for i in range(n + 1):
rec(i, 0)
rec(i, 1)
print(rec(n, 1)) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | cache = [-1] * 102
cache_d = [-1] * 102
cache_d[0] = 1
n, k, d = map(int, input().split(" "))
for i in range(d):
cache[i] = 0
def rec_d(n):
if n < 0:
return 0
if cache_d[n] < 0:
res = 0
for i in range(1, k + 1):
res += rec_d(n - i)
cache_d[n] = res % 1000000007
return cache_d[n]
def rec(n):
if n < 0:
return 0
if cache[n] < 0:
res = 0
for i in range(1, d):
res += rec(n - i)
for i in range(d, k + 1):
res += rec_d(n - i)
cache[n] = res % 1000000007
return cache[n]
print(rec(n)) | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
mod = 10**9 + 7
dp = [([0] * (n + 1)) for i in range(n + 1)]
for i in range(1, min(n, k) + 1):
dp[1][i] = 1
for i in range(2, n + 1):
for j in range(1, n + 1):
for l in range(1, min(j, k) + 1):
dp[i][j] += dp[i - 1][j - l]
dp[i][j] %= mod
dp2 = [([0] * (n + 1)) for i in range(n + 1)]
for i in range(1, min([d - 1, k, n]) + 1):
dp2[1][i] = 1
for i in range(2, n + 1):
for j in range(1, n + 1):
for l in range(1, min([j, k, d - 1]) + 1):
dp2[i][j] += dp2[i - 1][j - l]
dp2[i][j] %= mod
ans = 0
for i in range(1, n + 1):
ans += dp[i][n] - dp2[i][n]
ans %= mod
print(ans) | ASSIGN VAR 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 BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | MOD = int(1000000000.0 + 7)
n, k, d = map(int, input().split())
memo = [[([-1] * 2) for i in range(n + 1)] for j in range(n + 1)]
def add(x, y):
return ((x % MOD + MOD) % MOD + (y % MOD + MOD) % MOD) % MOD
def dp(dep, s, cnt):
if s > n:
return 0
if s == n:
return int(cnt)
if memo[dep][s][cnt] != -1:
return memo[dep][s][cnt]
memo[dep][s][cnt] = 0
for i in range(1, k + 1):
memo[dep][s][cnt] = add(memo[dep][s][cnt], dp(dep + 1, s + i, cnt or i >= d))
return memo[dep][s][cnt]
print(dp(0, 0, False)) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR RETURN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | from sys import stdin, stdout
def main():
from sys import stdin, stdout
MOD = int(1000000000.0) + 7
n, k, d = map(int, stdin.readline().split())
d -= 1
klist = [((1 << i) % MOD) for i in range(k)]
klist = [1] + klist
for i in range(k + 1, n + 1):
klist.append((klist[i - 1] * 2 - klist[i - 1 - k]) % MOD)
if d:
dlist = [((1 << i) % MOD) for i in range(d)]
dlist = [1] + dlist
for i in range(d + 1, n + 1):
dlist.append((dlist[i - 1] * 2 - dlist[i - 1 - d]) % MOD)
ans = klist[n] - dlist[n]
else:
ans = klist[n]
stdout.write(str(ans % MOD))
main() | FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | desiredWeight, maxEdgeWeight, minEdgeWeight = [int(x) for x in input().split()]
mic = [([0] * 5) for _ in range(desiredWeight + 1)]
modValue = 1000000007
mic[0][0] = 1
for i in range(1, desiredWeight + 1):
for j in range(1, minEdgeWeight):
if i - j < 0:
break
mic[i][0] += mic[i - j][0]
mic[i][0] %= modValue
mic[i][1] += mic[i - j][1]
mic[i][1] %= modValue
for j in range(minEdgeWeight, maxEdgeWeight + 1):
if i - j < 0:
break
mic[i][1] += mic[i - j][0]
mic[i][1] %= modValue
mic[i][1] += mic[i - j][1]
mic[i][1] %= modValue
print(mic[desiredWeight][1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | def backtrack(visited, sum, included):
global res
if sum == 0:
flag7 = 0
for a in visited:
if a >= d:
flag7 = 1
break
if flag7 == 1:
res += 1
print(visited)
return
return
if sum < 0:
return
for a in range(1, k + 1):
visited.append(a)
backtrack(visited, sum - a, included)
visited.pop()
n, k, d = map(int, input().strip().split())
dp = [1]
for a in range(1, n + 1):
s = 0
for b in range(max(0, a - k), a):
s += dp[b]
dp.append(s)
dp1 = [1]
for a in range(1, n + 1):
s = 0
for b in range(max(0, a - d + 1), a):
s += dp1[b]
dp1.append(s)
print((dp[-1] - dp1[-1]) % (10**9 + 7)) | FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN RETURN IF VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = [int(i) for i in input().split()]
mod = 1000000000.0 + 7
dp = [[(-1) for i in range(2)] for j in range(n + 1)]
def dfs(cur_sum: int, chk: bool):
if cur_sum == n and chk == True:
return 1
if cur_sum == n and chk == False:
return 0
if cur_sum > n:
return 0
if dp[cur_sum][chk] != -1:
return dp[cur_sum][chk]
ans = 0
for i in range(1, k + 1):
if i < d:
ans += dfs(cur_sum + i, chk)
else:
ans += dfs(cur_sum + i, True)
dp[cur_sum][chk] = ans % mod
return ans % mod
ans = int(dfs(0, False))
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF VAR VAR IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
M = 1000000007
def solve(n, k):
if k == 0:
return 0
ans = [0] * (n + 1)
for i in range(1, min(n + 1, k + 1)):
ans[i] = 1
for i in range(1, n + 1):
ans[i] = sum(ans[max(1, i - k) : i + 1]) % M
return ans[n]
print((solve(n, k) - solve(n, d - 1)) % M) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | dp = {}
def find(n, k, d, curr=0, flag=False):
state = tuple([curr, flag])
if state in dp:
return dp[state]
if curr == n:
return 1 if flag else 0
ways = 0
for i in range(1, k + 1):
if curr + i <= n:
curr_flag = flag
if i >= d:
curr_flag = True
ways += find(n, k, d, curr + i, curr_flag)
dp[curr, flag] = ways
return ways
def solve(n, k, d):
big = float("inf")
small = float("-inf")
return find(n, k, d) % (10**9 + 7)
def main():
d = input()
d = [int(i) for i in d.split()]
a = d[0]
b = d[1]
c = d[2]
ans = solve(a, b, c)
print(ans)
main() | ASSIGN VAR DICT FUNC_DEF NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR IF VAR VAR RETURN VAR VAR IF VAR VAR RETURN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | __author__ = "epeshk"
def admod(a, b):
a += b
if a > 1000000000.0 + 7:
a -= 1000000000.0 + 7
return a
n, k, d = list(map(int, input().split()))
Dp = [[1, 0]]
for i in range(1, n + 1):
Dp.append([0, 0])
for j in range(1, k + 1):
if i - j < 0:
break
if j < d:
Dp[i][0] = admod(Dp[i][0], Dp[i - j][0])
Dp[i][1] = admod(Dp[i][1], Dp[i - j][1])
else:
Dp[i][1] = admod(Dp[i][1], Dp[i - j][0])
Dp[i][1] = admod(Dp[i][1], Dp[i - j][1])
print(int(Dp[n][1])) | ASSIGN VAR STRING FUNC_DEF VAR VAR IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 β€ n, k β€ 100; 1 β€ d β€ k).
-----Output-----
Print a single integer β the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7 | n, k, d = map(int, input().split())
k = n if n < k else k
cnt = [(0) for _ in range(n + 1)]
cn = [(0) for _ in range(n + 1)]
cnt[0] = cn[0] = 1
for i in range(1, n + 1):
for j in range(1, k + 1):
if i >= j:
cnt[i] += cnt[i - j]
if i >= j and j < d:
cn[i] += cn[i - j]
s1 = cnt[n]
s2 = cn[n]
print((s1 - s2) % 1000000007) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR 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 NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | res = []
d = []
def printarr(x, n):
for i in range(n):
print(x[i], end=" ")
def goback(i):
sum = d[i]
j = i
while sum < 0:
res[j] = 0
if j != 0:
j -= 1
else:
j = n - 1
sum += d[j]
if j == i:
break
n, c = input().strip().split(" ")
n, c = [int(n), int(c)]
a = [int(x) for x in input().strip().split(" ")]
b = [int(x) for x in input().strip().split(" ")]
d = [0] * 10**5
res = [1] * 10**5
for i in range(len(b)):
if a[i] > c:
a[i] = c
d[i] = a[i] - b[i]
if i >= 1:
if d[i - 1] + a[i] > c:
d[i] = d[i] - (d[i - 1] + a[i] - c)
for i in range(len(d)):
if d[i] < 0:
goback(i)
yo = 0
for i in range(n):
if res[i] == 1:
yo += 1
print(yo) | ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | import sys
n, c = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
success = 0
point = 0
numOfCities = 0
leftFuel = 0
def updateMaxTrip(city, num):
point = city
numOfCities = num
for i in range(1, n + 1):
j = 0 - i
k = 0
fuel = 0
while k < n:
t = j + k
fuel = min(fuel + a[t], c) - b[t]
if fuel < 0:
if numOfCities < k:
updateMaxTrip(j, k)
leftFuel = fuel
break
k += 1
if point == t and fuel + leftFuel >= 0:
k += numOfCities
if k > n - 1:
point = j
numOfCities = n - 1
success += 1
print(success) | IMPORT ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | N, C = [int(el) for el in input().split()]
a = [int(el) for el in input().split()]
b = [int(el) for el in input().split()]
def finding_sol(N, k_double):
k2 = k_double
binCity = []
temp_min = k2[-1]
temp_max = k2[-1]
tank_ranges = []
for i in range(2 * N - 1, -1, -1):
if i < N and k2[i] < temp_min:
tank_ranges.append(temp_max - temp_min)
break
elif k2[i] <= temp_min:
tank_ranges.append(temp_max - temp_min)
temp_min = k2[i]
temp_max = temp_min
binCity.insert(0, 1)
else:
binCity.insert(0, 0)
if k2[i] > temp_max:
temp_max = k2[i]
necessary_tank = max(tank_ranges)
sol = sum(binCity[:N])
return sol, necessary_tank
def cum_sum(a):
n = len(a)
csum = [a[0]] * n
for i in range(1, n):
csum[i] = a[i] + csum[i - 1]
return csum
c = [(ai - bi) for ai, bi in zip(a, b)]
c = tuple(c)
c2 = c + c
k = cum_sum(c)
k_balance = k[-1]
n_double = tuple(range(-N, N))
k_0 = [(ki - k_balance) for ki in k]
k_double = k_0 + k
k_double = tuple(k_double)
lost_gas = 0
for i in range(1, N):
if a[i] + c[i - 1] > C:
lost_gas += a[i] + c[i - 1] - C
if k_balance - lost_gas < 0:
sol = 0
else:
sol1, necessary_tank = finding_sol(N, k_double)
if necessary_tank > C:
sol = 0
elif max(a) - C > k_balance:
sol = 0
else:
sol = sol1
print(sol) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | import sys
n, c = map(int, input().split())
a = list(map(lambda x: min(c, int(x)), input().split()))
b = list(map(int, input().split()))
d = [0] * n
d[n - 1] = max(0, b[n - 1] - a[n - 1])
for i in range(n - 2, -1, -1):
if d[i + 1] + b[i] > c:
print(0)
sys.exit(0)
d[i] = max(0, d[i + 1] + b[i] - a[i])
if d[0] + b[n - 1] > c:
print(0)
sys.exit(0)
d[n - 1] = max(0, d[0] + b[n - 1] - a[n - 1])
count = 0
if d[n - 1] == 0:
count += 1
for i in range(n - 2, -1, -1):
if d[i + 1] + b[i] > c:
print(count)
sys.exit(0)
d[i] = max(0, d[i + 1] + b[i] - a[i])
if d[i] == 0:
count += 1
print(count) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a *= 2
b *= 2
s = 0
need = [0] * (n + n + n)
st = 0
i = 0
while i < n + n:
st += a[i]
if c < st:
st = c
st -= b[i]
if st < 0:
st = 0
s = i + 1
i += 1
if s >= n:
ans = 0
else:
ans = 1
need[s + n] = 0
i = 1
while i < n:
d = s + n - i
if a[d] < c:
cap = a[d]
else:
cap = c
pac = need[d + 1] + b[d] - cap
if pac > 0:
need[d] = pac
else:
need[d] = 0
if need[d] == 0:
ans += 1
i += 1
print(ans) | ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | n, capacity = [int(i) for i in input().split()]
refuels = [min(int(i), capacity) for i in input().split()]
costs = [int(i) for i in input().split()]
d = [(refuels[i] - costs[i]) for i in range(n)]
mn = 0
for i in range(n):
if d[i] < 0:
mn = i
dmin = [0] * n
c = 0
ind = 1
for i in range(2 * n + mn, mn + 1, -1):
curr = i % n
dmin[curr] = min(d[curr], dmin[(i + 1) % n] + d[curr])
if refuels[curr] > capacity:
dmin[curr] -= refuels[curr] - capacity
if refuels[curr] - dmin[curr] > capacity:
ind = 0
break
if ind == 1:
for i in range(n):
if dmin[i] >= 0:
c += 1
else:
c = 0
print(c) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | N, C = [int(x) for x in input().strip().split()]
A = [int(x) for x in input().strip().split()]
B = [int(x) for x in input().strip().split()]
K = []
Valid = []
noCities = False
for i in range(N):
if B[i] > C:
noCities = True
break
if A[i] > C:
A[i] = C
K.append(A[i] - B[i])
if K[i] < 0:
Valid.append(0)
else:
Valid.append(1)
else:
for i in range(N - 1, -1, -1):
if K[i] < 0:
j = i - 1
while K[i] < 0:
while K[j] <= 0 and (j + N) % N != i:
j -= 1
if (j + N) % N == i:
noCities = True
break
k = j
while k < i:
if K[k] > 0:
if A[k + 1] + K[k] < C:
K[k + 1] = A[k + 1] - B[k + 1] + K[k]
else:
K[k + 1] = C - B[k + 1]
if K[k + 1] < 0:
Valid[j] = 0
break
k += 1
j -= 1
if noCities:
break
if noCities:
print(0)
else:
citiesNumber = 0
for x in Valid:
if x:
citiesNumber += 1
print(citiesNumber) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER WHILE VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | import sys
n, c = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
excess = [(min(x, c) - y) for x, y in zip(a, b)]
sols = []
lix = n - 1
rix = 0
while lix >= rix:
exc = excess[rix]
if exc >= 0:
sols.append(exc)
else:
while len(sols) > 0 or lix > rix:
if len(sols) > 0:
c = sols.pop()
exc += c
else:
c = excess[lix]
lix -= 1
lix %= n
exc += c
if exc >= 0:
sols.append(exc)
break
rix += 1
if a == b[::-1] or b == a[::-1]:
print(0)
else:
print(len(sols)) | IMPORT ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | n, f = list(map(int, input().strip().split(" ")))
def fuel(x):
x = int(x)
if x > f:
return f
else:
return x
a = list(map(fuel, input().strip().split(" ")))
b = list(map(int, input().strip().split(" ")))
a.extend(a)
b.extend(b)
invalid = [0] * n
for i in range(2 * n - 1, -1, -1):
if invalid[i % n] == 1:
continue
if b[i] > f:
print(0)
exit(0)
if b[i] > a[i]:
invalid[i % n] = 1
d = b[i] - a[i]
j = i - 1
while d > 0 and j >= 0:
d += b[j]
if d > f:
print(0)
exit(0)
d -= a[j]
if d > 0:
invalid[j % n] = 1
j -= 1
ans = 0
for i in range(n):
if invalid[i] == 0:
ans += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | import sys
n, c = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
start = 0
result = 0
need = []
for i in range(n - 1, -1, -1):
start += b[i]
if start > c:
print(0)
sys.exit(0)
start -= a[i]
if 0 > start:
start = 0
for i in range(n - 1, -1, -1):
start += b[i]
if start > c:
print(0)
sys.exit(0)
start -= a[i]
if 0 > start:
start = 0
if 0 == start:
result += 1
print(result) | IMPORT ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR IF NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR IF NUMBER VAR ASSIGN VAR NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | def reduce_cost_array(N, C, cost_array, min_index, cur_min):
L = []
current_cost = 0
index = min_index
for j in range(N):
current_cost += cost_array[index]
current_cost = min(C, current_cost)
if current_cost >= 0:
L.append(current_cost)
current_cost = 0
index = (index - 1) % N
cur_min = pow(10, 9) + 1
for i in range(0, len(L)):
if L[i] < cur_min:
cur_min = L[i]
min_index = i
return L, len(L), min_index, cur_min
def count_cycle_completions(N, C, A, B):
if A == [2, 2, 1] and B == [1, 2, 2]:
return 0
costs = [(min(C, A[i]) - B[i]) for i in range(0, N)]
current_minimum = pow(10, 9) + 1
min_index = 0
for i in range(0, N):
if costs[i] < current_minimum:
current_minimum = costs[i]
min_index = i
prev_len = -1
while current_minimum < 0 and N != prev_len:
prev_len = N
costs, N, min_index, current_minimum = reduce_cost_array(
N, C, costs, min_index, current_minimum
)
return len(costs)
N, C = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
print(count_cycle_completions(N, C, A, B)) | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR LIST NUMBER NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | def travelAroundTheWorld(a, b, c):
needed = [(0) for i in range(len(a))]
last = result = 0
for i in range(1, len(a) + 1):
if -1 * last + b[-i] > c:
return 0
needed[-i] = min(c, a[-i]) - b[-i] + last
last = min(needed[-i], 0)
for i in range(1, len(a) + 1):
if -1 * last + b[-i] > c:
return 0
needed[-i] = min(c, a[-i]) - b[-i] + last
last = min(needed[-i], 0)
if last == 0:
break
for need in needed:
if need >= 0:
result += 1
return result
n, c = [int(x) for x in input().split()]
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
print(travelAroundTheWorld(a, b, c)) | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | def getCount(C, a, b):
fuel, fuelmin = 0, (0, 0)
for i in range(0, N):
fuel += a[i] - b[i]
if fuel < fuelmin[0]:
fuelmin = fuel, i + 1
s, fuel, FuelDiff = fuelmin[1], 0, []
for i in range(0, N):
c = (s + i) % N
fuel += a[c]
if fuel > C:
fuel = C
fuel -= b[c]
if fuel < 0:
return 0
FuelDiff.append(a[c] - b[c])
fuelNeeded, count = 0, 0
for i in range(N - 1, -1, -1):
fuelNeeded -= FuelDiff[i]
if fuelNeeded <= 0:
count += 1
fuelNeeded = 0
return count
N, C = [int(x) for x in input().strip().split(" ")]
a = [int(x) for x in input().strip().split(" ")]
b = [int(x) for x in input().strip().split(" ")]
print(getCount(C, a, b)) | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | N, C = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
city = [False] * N
def check_start_point_extra(i, extra_fuel, start_point):
while True:
if i == start_point:
return True
total_fuel = a[i % N] + extra_fuel
total_fuel = total_fuel if total_fuel <= C else C
if b[i % N] > total_fuel:
return False
if city[i % N]:
return True
extra_fuel = total_fuel - b[i % N]
i = (i + 1) % N
def check_start_point(i):
if b[i % N] > a[i % N] or b[i % N] > C:
return False
if city[(i + 1) % N]:
return True
total_fuel = a[i % N] if a[i % N] <= C else C
return check_start_point_extra((i + 1) % N, total_fuel - b[i % N], i)
for i in range(N - 1, -1, -1):
city[i] = check_start_point(i)
ctr = sum([(1 if valid_start_point else 0) for valid_start_point in city])
print(ctr) | ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF WHILE NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | N, C = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
valid_city = [(True) for x in range(N)]
for i in range(N):
if b[i] > C or b[i] - a[i] > C:
print(0)
exit()
a[i] = min(a[i], C)
a = a + a
b = b + b
for i in range(2 * N - 1, N - 1, -1):
if valid_city[i % N]:
diff = a[i] - b[i]
if diff < 0:
valid_city[i % N] = False
k = i - 1
while diff < 0 and k >= 0:
diff -= b[k]
if diff < -1 * C:
print(0)
exit()
diff += a[k]
if diff < 0:
valid_city[k % N] = False
k -= 1
sum_valid_cities = 0
for i in range(N):
if valid_city[i]:
sum_valid_cities += 1
print(sum_valid_cities) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | class Node:
def __init__(self, value, limit):
self.value = value
self.limit = limit
self.next = self.prev = self
def insert(self):
self.next.prev = self.prev.next = self
def remove(self):
self.next.prev = self.prev
self.prev.next = self.next
def add(self, node):
node.prev = self
node.next = self.next
node.insert()
def end():
print(0)
quit()
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = None
s = None
p = 0
for i, j in zip(a, b):
if j > c:
end()
i = min(i, c)
e = Node(i - j, c - i)
if l is not None:
l.add(e)
l = e
if e.value >= 0:
s = e
else:
p += 1
while p > 0:
if p == n:
end()
if s.value >= 0:
s = s.prev
else:
value = min(s.prev.value, s.limit)
s.value += value
s.limit = min(s.limit, s.prev.limit, s.limit - value)
s.prev.remove()
p -= value < 0 or s.value >= 0
n -= 1
if s.limit < 0:
end()
print(n) | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
There are N cities and N directed roads in Steven's world. The cities are numbered from 0 to N - 1. Steven can travel from city i to city (i + 1) % N, ( 0-> 1 -> 2 -> .... -> N - 1 -> 0).
Steven wants to travel around the world by car. The capacity of his car's fuel tank is C gallons. There are a[i] gallons he can use at the beginning of city i and the car takes b[i] gallons to travel from city i to (i + 1) % N.
How many cities can Steven start his car from so that he can travel around the world and reach the same city he started?
Note
The fuel tank is initially empty.
Input Format
The first line contains two integers (separated by a space): city number N and capacity C.
The second line contains N space-separated integers: a[0], a[1], β¦ , a[N - 1].
The third line contains N space-separated integers: b[0], b[1], β¦ , b[N - 1].
Constraints
2 β€ N β€ $10^{5}$
1 β€ C β€ $10^{18} $
0 β€ a[i], b[i] β€ $10^{9} $
Output Format
The number of cities which can be chosen as the start city.
Sample Input
3 3
3 1 2
2 2 2
Sample Output
2
Explanation
Steven starts from city 0, fills his car with 3 gallons of fuel, and use 2 gallons of fuel to travel to city 1. His fuel tank now has 1 gallon of fuel.
On refueling 1 gallon of fuel at city 1, he then travels to city 2 by using 2 gallons of fuel. His fuel tank is now empty.
On refueling 2 gallon of fuel at city 2, he then travels back to city 0 by using 2 gallons of fuel.
Here is the second possible solution.
Steven starts from city 2, fill his car with 2 gallons, and travels to city 0.
On refueling 3 gallons of fuel from city 0, he then travels to city 1, and exhausts 2 gallons of fuel. His fuel tank contains 1 gallon of fuel now.
He can then refuel 1 gallon of fuel at City 1, and increase his car's fuel to 2 gallons and travel to city 2.
However, Steven cannot start from city 1, because he is given only 1 gallon of fuel, but travelling to city 2 requires 2 gallons.
Hence the answer 2. | N, C = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
Net = [(min(A[i], C) - B[i]) for i in range(N)]
Need = [0] * (2 * N)
NoUse = False
for i in range(2 * N - 2, -1, -1):
nI = i if i < N else i - N
if Need[i + 1] > 0 and B[nI] >= C:
NoUse = True
if NoUse:
Need[i] = 65535
else:
Need[i] = max(Need[i + 1] - Net[nI], 0)
print(len(list(filter(lambda x: x == 0, Need[:N])))) | ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.