description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided ... | input()
d = {(0, 0): 1}
r = s = i = 0
for x in map(int, input().split()):
s ^= x
i ^= 1
c = d.get((s, i), 0)
r += c
d[s, i] = c + 1
print(r) | EXPR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided ... | n = int(input())
a = list(map(int, input().split()))
b = [0]
def calc(i):
e = 0
o = 0
for j in i:
if j % 2:
e += 1
else:
o += 1
return e * (e - 1) // 2 + o * (o - 1) // 2
for i in a:
b.append(b[-1] ^ i)
k = list(set(b))
d1 = {}
for i in range(len(k)):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBE... |
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided ... | n = int(input())
n_integers = [int(x) for x in input().split()]
n_integers_cumulative = [0] * len(n_integers)
n_even = 0
n_odd = 0
if n % 2 == 0:
n_even = int(n / 2) + 1
n_odd = n + 1 - n_even
else:
n_even = int((n + 1) / 2)
n_odd = n + 1 - n_even
even_integers_cumulative = []
odd_integers_cumulative = ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC... |
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided ... | n = int(input())
lis = list(map(int, input().split()))
mat = [([0] * (2**20 + 5)) for i in range(2)]
ans = a = 0
mat[1][0] = 1
for i in range(n):
a = a ^ lis[i]
ans += mat[i % 2][a]
mat[i % 2][a] += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP... |
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided ... | n = int(input())
a = list(map(int, input().split()))
s = [0] * (n + 1)
def count_elements(L):
even_elements = {}
even_lst = L[0::2]
odd_elements = {}
odd_lst = L[1::2]
for elem in even_lst:
if elem in even_elements.keys():
even_elements[elem] += 1
else:
even... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMB... |
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided ... | import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
odd = dict()
eve = dict()
tmp = 0
odd[tmp] = 1
res = 0
for i in range(n):
tmp = tmp ^ a[i]
if i % 2 == 0:
if tmp in eve:
res += eve[tmp]
eve[tmp] += 1
else:
eve[... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ... |
Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya.
Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Ar... | from sys import stdin, stdout
n, m = map(int, input().split())
s = [0] + list(map(int, stdin.readline().strip().split()))
dp = [[[(False) for i in range(m + 1)] for j in range(m + 1)] for k in range(2)]
dp[0][0][0] = True
cur = 0
for i in range(1, n + 1):
cur += 1
cur %= 2
last = (cur + 1) % 2
for j in... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NU... |
Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya.
Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Ar... | read = lambda: map(int, input().split())
n, k = read()
c = list(read())
dp = [0] * (k + 1)
dp[0] = 1
for x in c:
ndp = dp[:]
for i in range(k, x - 1, -1):
ndp[i] |= dp[i - x] | dp[i - x] << x
dp = ndp
b = bin(dp[-1])
ans = [i for i in range(k + 1) if b[-i - 1] == "1"]
print(len(ans))
print(*ans) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin, stdout
dp = []
M = 10**9 + 7
for i in range(200011):
if i < 10:
dp.append(1)
else:
dp.append((dp[i - 9] + dp[i - 10]) % M)
for _ in range(int(stdin.readline())):
n, m = stdin.readline().split()
m = int(m)
M = 10**9 + 7
ans = 0
for i in n:
ans =... | ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CAL... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import maxsize, stdin, stdout
R = lambda: stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(" "))) if f else list(R().split(" "))
output = lambda x: stdout.write(str(x) + "\n")
output_list = lambda x: output(" ".join(map(str, x)))
M = int(1000000000.0) + 7
mx = int(200000.0) + 5
dp = [0] + 9 ... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMB... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = sys.stdin.readline
dp = [2] * 9 + [3] + [0] * 199991
for i in range(10, 200001):
dp[i] = (dp[i - 9] + dp[i - 10]) % (10**9 + 7)
for _ in range(int(input())):
n, m = map(int, input().split())
ans = 0
while n:
x = n % 10
if m + x < 10:
ans += 1
else:... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER NUMBER LIST NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = sys.stdin.readline
d = [(0) for x in range(200001)]
d[0] = 1
for i in range(1, 10):
d[i] = 2
for i in range(10, 200001):
d[i] = (d[i - 10] + d[i - 9]) % (10**9 + 7)
t = int(input())
for i in range(t):
n, m = map(int, input().split())
n = list(str(n))
count = [(0) for x in range(1... | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUN... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
def inp():
return sys.stdin.readline().rstrip()
p = 1000000007
t = int(inp())
rec = [1] * 200010
for i in range(10):
rec[i] = 1
for i in range(10, 200010):
rec[i] = (rec[i - 9] + rec[i - 10]) % p
res_list = []
for z in range(t):
n, m = inp().split()
m = int(m)
res = 0
for c in... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
def main():
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
t = int(input())
x = 1
m = int(2 * 100000.0 + 10)
dp = [(1) for i in range(m + 1)]
for i in range(10, m + 1):
dp[i] = (dp[i - 10] + dp[i - 9]) % MOD
for _ in range(t):
n, k = map(int, inpu... | IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin
input = stdin.readline
mxn = 2 * 10**5 + 10
mod = 10**9 + 7
dp = [1] * mxn
for i in range(10, mxn):
dp[i] = (dp[i - 9] + dp[i - 10]) % mod
for test in range(int(input())):
n, k = map(int, input().strip().split())
ans = 0
while n:
ans = (ans + dp[k + n % 10]) % mod
... | ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIG... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin, stdout
z = 10**9 + 7
dp = {}
for i in range(200009):
if i < 9:
dp[i] = 2
elif i == 9:
dp[i] = 3
else:
dp[i] = (dp[i - 9] + dp[i - 10]) % z
for _ in range(int(input())):
n, m = stdin.readline().split()
n = int(n)
m = int(m)
ans = 0
while n >... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin, stdout
dp = [0] * 200005
for i in range(0, 9):
dp[i] = 2
dp[9] = 3
for i in range(10, 200005):
dp[i] = (dp[i - 10] + dp[i - 9]) % 1000000007
ans = ""
for i in range(int(input())):
n, m = stdin.readline().split()
m = int(m)
res = 0
for s in n:
s = int(s)
in... | ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR F... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin, stdout
s = "0"
curr = 1
count = 0
check = 0
dp = [1]
for i in range(100):
fin = ""
for i in s:
num = int(i)
num += 1
num = str(num)
fin = fin + num
dp.append(len(fin))
s = fin
tog = 101
mod = 10**9 + 7
for i in range(2 * 10**5):
num = (dp[tog -... | ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER A... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = sys.stdin.readline
MOD = 1000000007
dp = [(1) for _ in range(200010)]
for i in range(10, 200010):
dp[i] = (dp[i - 10] + dp[i - 9]) % MOD
for _ in range(int(input())):
n, m = map(int, input().split())
ans = 0
while n:
ans += dp[m + n % 10]
n //= 10
ans %= MOD
... | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = lambda: sys.stdin.readline().rstrip()
def solve_tc(dp):
mod = 1000000007
n, m = map(int, input().split())
cnt = 0
while n > 0:
x = int(n % 10)
if m + x < 10:
cnt += 1
else:
cnt += dp[m + x - 10]
cnt = int(cnt % mod)
n ... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = sys.stdin.readline
t = int(input())
mod = pow(10, 9) + 7
cnt = [(0) for _ in range(200020)]
cnt0 = [0] * 10
cnt0[0] = 1
s = 1
for k in range(200020):
x = cnt0[(9 - k) % 10]
cnt0[(10 - k) % 10] += x
cnt0[(10 - k) % 10] %= mod
s += x
s %= mod
cnt[k] = s
for _ in range(t):
n... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = sys.stdin.readline
mod = pow(10, 9) + 7
arr = [0] * 200020
for i in range(10):
arr[i] = 1
for i in range(10, 200020):
arr[i] = (arr[i - 10] + arr[i - 9]) % mod
def solve():
n, m = map(int, input().split(" "))
ans = 0
while True:
k = m + n % 10
ans += arr[k]
... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FU... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
def get_ints():
return map(int, sys.stdin.readline().strip().split())
MOD = 10**9 + 7
LIMIT = 20011
dp = []
for i in range(200011):
if i < 10:
dp.append(1)
else:
dp.append((dp[i - 9] + dp[i - 10]) % MOD)
T = int(input())
for _ in range(T):
N, M = get_ints()
ans = 0
... | IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = sys.stdin.readline
t = int(input().strip())
M = 1000000007
dp = [0] * (2 * 100000 + 20)
dp[:10] = list(1 for i in range(10))
for i in range(10, 2 * 100000 + 20):
dp[i] = dp[i - 9] + dp[i - 10]
dp[i] %= M
while t:
t -= 1
n, m = map(int, input().strip().split())
n = str(n)
resu... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR N... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin
input = stdin.readline
mod = 10**9 + 7
def add(a, b):
return (a % mod + b % mod) % mod
dp = [1] * (2 * 10**5 + 10)
for i in range(10, 2 * 10**5 + 10):
dp[i] = add(dp[i - 9], dp[i - 10])
def answer():
ans = 0
for i in str(n):
ans = add(ans, dp[m + int(i)])
return ... | ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_O... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | M = 10**9 + 7
L = 8**6
d = [1] * L
d[:10] = [1] * 10
for i in range(10, L):
d[i] = (d[i - 9] + d[i - 10]) % M
for s in [*open(0)][1:]:
n, m = s.split()
o = int(m)
print(sum(d[o + int(c)] for c in n) % M) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VA... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin
input = stdin.readline
mod = 10**9 + 7
cnt = [1] * (2 * 10**5 + 15)
curr = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
curr_len = 1
for i in range(2 * 10**5 + 15):
cnt[i] = curr_len
curr_len = (curr_len + curr[-1]) % mod
curr[0] = (curr[0] + curr[-1]) % mod
curr.insert(0, curr.pop())
for _ in ... | ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIG... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = sys.stdin.readline
mod = 10**9 + 7
mxi = 210000
ans = [0] * mxi
cts = [0] * 10
cts[0] = 1
s = 1
for i in range(mxi):
ans[i] = s
s += cts[-1]
s %= mod
cts[0] += cts[-1]
cts[0] %= mod
cts.insert(0, cts.pop())
for f in range(int(input())):
n, m = map(int, input().split())
... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL ... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | import sys
input = sys.stdin.readline
M = 10**9 + 7
dp = [[0, 0] for i in range(200001)]
for i in range(200001):
if i < 10:
dp[i][0] = 1
dp[i][1] = 1
if i == 9:
dp[i][1] = dp[1][1] + dp[1][0]
else:
dp[i][0] = (dp[i - 10][1] + dp[i - 10][0]) % M
dp[i][1] = (dp... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NU... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin
t = int(stdin.readline())
mod = 10**9 + 7
f = [0] * (2 * 10**5 + 10)
for i in range(10):
f[i] = 1
f[10] = 2
for i in range(11, 2 * 10**5 + 10):
f[i] = (f[i - 10] + f[i - 9]) % mod
for _ in range(t):
n, m = map(int, stdin.readline().split())
c = [0] * 10
n = str(n)
for i in... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER AS... |
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from sys import stdin
dp = [0] * (2 * 10**5 + 1)
for i in range(9):
dp[i] = 2
dp[9] = 3
for i in range(10, 2 * 10**5 + 1):
dp[i] = (dp[i - 9] + dp[i - 10]) % (10**9 + 7)
for _ in range(int(input())):
n, m = map(int, stdin.readline().split())
n = str(n)
a = [0] * len(n)
ans = 0
for i in n:
... | ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP ... |
Madoka is going to enroll in "TSUNS PTU". But she stumbled upon a difficult task during the entrance computer science exam:
A number is called good if it is a multiple of $d$.
A number is called beatiful if it is good and it cannot be represented as a product of two good numbers.
Notice that a beautiful number must ... | def prime(n):
if n % 2 == 0 and n != 2:
return False
for i in range(3, int(n**0.5 + 1), 2):
if n % i == 0:
return False
return True
for _ in range(int(input())):
x, d = map(int, input().split())
ans = 0
while x % d == 0:
ans += 1
x //= d
if ans =... | FUNC_DEF IF BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBE... |
Madoka is going to enroll in "TSUNS PTU". But she stumbled upon a difficult task during the entrance computer science exam:
A number is called good if it is a multiple of $d$.
A number is called beatiful if it is good and it cannot be represented as a product of two good numbers.
Notice that a beautiful number must ... | def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return i
return -1
def is_Power(x, y):
while x % y == 0:
x = x / y
return x == 1
t = int(input())
def isBeautiful(n, x):
return n % x == 0 and n % x**2 != 0
for i in range(t):
x, d = input().sp... | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER... |
Madoka is going to enroll in "TSUNS PTU". But she stumbled upon a difficult task during the entrance computer science exam:
A number is called good if it is a multiple of $d$.
A number is called beatiful if it is good and it cannot be represented as a product of two good numbers.
Notice that a beautiful number must ... | def isPrime(n):
if n == 1:
return True
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def factor(n):
ans = []
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
ans.append(i)
... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EX... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | def f(a, b):
row = len(a) + 1
col = len(b) + 1
dp = [([0] * col) for _ in range(row)]
r = 0
for i in range(1, row):
for j in range(1, col):
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
if a[i - 1] == b[j - 1]:
if i == row - 1:
... | FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | case_count = int(input())
MOD = 1000000007
def solve(A, B):
solutions = [([0] * len(A)) for j in range(len(B))]
for j in range(len(A)):
solutions[0][j] = solutions[0][j - 1] + int(B[0] == A[j])
solutions[0][j] %= MOD
for i in range(1, len(B)):
solutions[i][0] = solutions[i - 1][0]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VA... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | import sys
def count_common_subs(s1, s2):
dp = [[(0) for j in range(len(s2) + 1)] for i in range(len(s1) + 1)]
for i in range(len(s1)):
for j in range(len(s2)):
if s1[i] == s2[j]:
dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] + 1
else:
dp[i + 1]... | IMPORT FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | def count_square_subsequences(s, t):
m = len(s)
n = len(t)
T = [[(0) for _ in range(n)] for _ in range(m)]
T[0][0] = 1 if s[0] == t[0] else 0
for i in range(1, n):
T[0][i] = T[0][i - 1] + (1 if s[0] == t[i] else 0)
T[0][i] %= 1000000007
for i in range(1, m):
T[i][0] = T[i... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR NU... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | from sys import stderr
def dp(a, b):
c = [[(0) for j in range(len(b))] for i in range(len(a))]
for i in range(len(b)):
if a[0] == b[i]:
c[0][i] = 1
if i:
c[0][i] += c[0][i - 1]
c[0][i] %= mod
for i in range(1, len(a)):
c[i][0] = c[i - 1][0]
... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VA... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | NUMBER = 1000000007
class SquareSubstring:
def __init__(self):
self.T = int(input())
for i in range(self.T):
string = input()
print(self.solve(string))
def solve_sub(self, string, size):
s1 = string[:size]
size1 = len(s1) + 1
s2 = string[size:]... | ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR F... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | tr = int(input().strip())
for t in range(tr):
s = input().strip()
n = len(s)
T = [[(0) for i in range(n)] for i in range(n)]
sum = 0
for p in range(1, n):
for i in range(p):
for j in range(p, n):
left = T[i][j - 1] if j > p else 0
above = T[i - 1][... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR V... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | def subsequences(s, k):
s1 = s[:k]
s2 = s[k:]
subs = [[(0) for j in range(len(s) - k + 1)] for i in range(k + 1)]
for i in range(k):
for j in range(len(s) - k):
if s1[i] == s2[j]:
subs[i + 1][j + 1] = subs[i][j + 1] + subs[i + 1][j] + 1
else:
... | FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP V... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | t = int(input().strip())
def comSub(str1, str2):
n = len(str1)
m = len(str2)
dp = [[(0) for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(n):
for j in range(m):
if str1[i] == str2[j]:
dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] + 1
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF 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 VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUM... |
Square Subsequences
A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Given a string, how many (non-empty) subsequences of the string are square strings? A subsequence of a string can be ob... | def sub(s, size):
s1 = s[:size]
s2 = s[size:]
N = [[(0) for j in range(len(s2) + 1)] for i in range(len(s1) + 1)]
for i in range(1, len(s1) + 1):
for j in range(1, len(s2) + 1):
if s1[i - 1] == s2[j - 1]:
N[i][j] = N[i - 1][j] + N[i][j - 1] + 1
else:
... | FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | mod = int(1000000000.0 + 7)
for _ in range(int(input())):
n, k = map(int, input().split())
ans = (k**n + k * (-1) ** n) // (k + 1)
print(ans % mod) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | m = 10**9 + 7
for t in range(int(input())):
n, k = map(int, input().split())
if n == 2:
print(k)
elif n == 3:
print(k * (k - 1))
else:
a = []
a.append(0)
a.append(0)
a.append(k)
a.append(k * (k - 1))
i = 4
while i <= n:
... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | MOD = 1000000007
def main():
t = int(input())
for i in range(t):
a, b = map(int, input().split())
solve(a, b)
def solve(p, n):
cache = [0] * (p + 1)
cache[0] = 0
cache[1] = 0
cache[2] = 1
for i in range(3, p + 1):
cache[i] = (n ** (i - 2) % MOD - cache[i - 1]) % M... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | t = int(input())
for k in range(t):
passes, players = map(int, input().split())
players += 1
dp = [[(0) for i in range(players)] for j in range(passes)]
for i in range(1, players):
dp[0][i] = 1
prev_sum = players - 1
for i in range(1, passes):
cur_sum = 0
for j in range(p... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR A... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | t = int(input())
for i in range(t):
n, k = map(int, input().split(" "))
sum = 0
z = 0
while n > 1:
sum += k ** (n - 1) * (-1) ** z
n -= 1
z += 1
print(sum % 1000000007) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | t = int(input())
for i in range(t):
n, k = map(int, input().split())
c = k
s = 0
ans = k
if n <= 1:
print("0")
continue
for j in range(n - 1):
s = c
ans *= k
c = ans - s
print(s % 1000000007) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BI... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | T = int(input())
counter = 0
while counter < T:
n, k = map(int, input().split())
currpos = 0
non_zeroes = k
zeroes = 0
ans = k
if n <= 1:
print("0")
continue
for i in range(0, n - 1):
zeroes = non_zeroes
ans = ans * k
non_zeroes = ans - zeroes
prin... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VA... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | import sys
t = int(input())
def power(a, b):
p = 1
while b > 0:
p = p * a % 1000000007
p = p % 1000000007
b = b - 1
p = p % 1000000007
return p
while t > 0:
a = sys.stdin.readline().split()
n, k = int(a[0]), int(a[1])
messi = 0
players = 0
i = 1
w = 1... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | mod = int(1000000000.0 + 7)
for _ in range(int(input())):
n, k = map(int, input().split())
ls = [0] * (n + 1)
ls[0], ls[1] = 1, 0
for i in range(2, n + 1):
ls[i] = ((k - 1) * ls[i - 1] + k * ls[i - 2]) % mod
print(ls[n]) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP ... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | import sys
sys.setrecursionlimit(3 * 10**5)
def power(x, y, p):
res = 1
x = x % p
if x == 0:
return 0
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
def inum():
return map(int, input().split())
modulo = 10**9 +... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUN... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | s = pow(10, 9) + 7
a = [[(0) for i in range(11)] for j in range(1001)]
for i in range(1, 11):
a[2][i] = i
for n in range(3, 1001):
for k in range(1, 11):
a[n][k] = pow(k, n - 1, s) - a[n - 1][k]
if a[n][k] < 0:
a[n][k] += s
t = int(input())
for i in range(t):
inp = list(map(int, ... | ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | for _ in range(int(input())):
N, K = list(map(int, input().split()))
dp = [0] * N
num_players = K + 1
num_passes = N - 1
for i in range(1, N):
dp[i] = (num_players - 1) ** i - dp[i - 1]
print(dp[-1] % 1000000007) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER E... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | t = int(input())
while t > 0:
n, k = map(int, input().split())
j = (k**n + k * (-1) ** n) // (k + 1)
j = j % 1000000007
print(j)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | def pulverize(a, b):
apair = [1, 0]
bpair = [0, 1]
while True:
if b == 0:
return a, apair[0], apair[1]
else:
q = a // b
a -= b * q
apair[0] -= bpair[0] * q
apair[1] -= bpair[1] * q
if a == 0:
return b, bpair[0], ... | FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER WHILE NUMBER IF VAR NUMBER RETURN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER RETURN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | import sys
sys.setrecursionlimit(10**9)
def dfs(n, index):
if (n, index) in m:
return m[n, index]
if n == 0:
if index == k:
return 1
else:
return 0
res = 0
for j in range(k + 1):
if index != j:
res = (res + dfs(n - 1, j)) % mod
m... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIG... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | import sys
def passes(N, K):
res = 0
alt = 1
for i in range(1, N):
res += alt * K**i
alt = -alt
return abs(res) % 1000000007
def process(input):
nb_of_cases = int(input.readline().rstrip())
for n in range(1, nb_of_cases + 1):
N, K = (int(i) for i in input.readline().r... | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | t = int(input())
if t >= 1 and t <= 100:
while t > 0:
n, k = input().split()
n = int(n)
k = int(k)
if n >= 2 and n <= 1000 and k >= 1 and k <= 10:
j = 1
i = 2
while i <= n:
if i != 2:
if i % 2 != 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASS... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | MD = 10**9 + 7
for _ in range(int(input())):
st = input().split()
N = int(st[0])
K = int(st[1])
M = 0
B = K
for k in range(N - 1):
M, B = B, (K * M + (K - 1) * B) % MD
print(M) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR ... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | T = int(input())
for _ in range(T):
p, n = map(int, input().split())
mod = 1000000007
if p == 2:
print(n)
else:
f = n
t = n
for i in range(p - 2):
f = f % mod * n % mod
a = (f - t + mod) % mod
t = a
print(a) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP ... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | e = 10**9 + 7
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
messi = 0
non_messi = k
for i in range(n - 2):
z = non_messi
non_messi = (messi * k + z * (k - 1)) % e
messi = z
print(non_messi) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NU... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | import sys
def win(player, passleft, dp):
if (player, passleft) in dp:
return dp[player, passleft]
if passleft == 0 and player == 0:
return 1
elif passleft == 0 and player != 0:
return 0
dp[player, passleft] = 0
for p in players:
if p != player:
dp[playe... | IMPORT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER A... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | for _ in range(int(input())):
n, k = [int(i) for i in input().split()]
A = [[1], [0]]
for i in range(1, n + 1):
A[0].append(k * A[1][i - 1])
A[1].append(A[0][i - 1] + (k - 1) * A[1][i - 1])
print(A[0][n] % (10**9 + 7)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR N... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | mod = 1000000007
def powmod(k, n):
if n == 0:
return 1
if n == 1:
return k
if n % 2 == 1:
return k * powmod(k * k % mod, (n - 1) / 2) % mod
else:
return powmod(k * k % mod, n / 2) % mod
t = int(input())
while t:
t -= 1
line = input().split()
n = int(line[0... | ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL ... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | n = int(input())
for i in range(0, n):
k, p = list(map(int, input().split(" ")))
if k == 2:
print(p)
else:
mess = [0] * (k + 1)
nonmess = [0] * (k + 1)
nonmess[1] = p
for i in range(2, k):
mess[i] = nonmess[i - 1]
nonmess[i] = mess[i - 1] * p +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR 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 FOR VAR FUNC_CA... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | for i in range(int(input())):
n, k = map(int, input().split())
dp = [[0, 1]]
for i in range(n - 1):
dp.append([dp[-1][0] * (k - 1) + dp[-1][1] * k, dp[-1][0]])
print(dp[-1][0] % 1000000007) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VA... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | t = int(input())
for i in range(t):
arr = input()
l = list(map(int, arr.split(" ")))
n = l[0]
k = l[1]
f = []
f.append(k)
f.append(k * (k - 1))
if n == 2:
print(f[0] % 1000000007)
if n == 3:
print(f[-1] % 1000000007)
if n > 3:
for j in range(n - 3):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BI... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | t = int(input())
while t:
n, k = [int(x) for x in input().split()]
table = list()
table = [(0) for x in range(n + 1)]
table[0] = 1
table[1] = 0
for i in range(1, n):
table[i + 1] = (table[i - 1] * k + table[i] * (k - 1)) % 1000000007
print(table[n])
t = t - 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_O... |
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | from sys import stdin
final = []
for j in range(2, 11):
li = []
li.append(0)
li.append(0)
li.append(j)
for i in range(3, 1001):
li.append(j * li[i - 2] + (j - 1) * li[i - 1])
li[i] = li[i] % 1000000007
final.append(li)
t = int(input())
for i in range(t):
n, k = map(int, stdi... | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBE... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is a big fan of soccer! He loves soccer so much, that he even invented soccer for his pet dogs! Here are the rules of the game:
There are N dogs numerated from 1 to N stay in a line, so dogs i and i + 1 are adjacent.
There is a ball ... | t = int(input())
MOD = 10**9 + 7
for _ in range(t):
n, m, s = (int(i) for i in input().split())
s -= 1
strength = [int(i) for i in input().split()]
dp = [([0] * n) for _ in range(m + 1)]
dp[0][s] = 1
elems = {s}
for i in range(1, m + 1):
elems2 = set()
for elem in elems:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is a big fan of soccer! He loves soccer so much, that he even invented soccer for his pet dogs! Here are the rules of the game:
There are N dogs numerated from 1 to N stay in a line, so dogs i and i + 1 are adjacent.
There is a ball ... | mod = 10**9 + 7
for _ in range(int(input())):
n, m, s = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
dp1 = [0] * (n + 1)
dp2 = [0] * (n + 1)
zeros = [0] * (n + 1)
dp1[s] = 1
for j in range(m):
for i in range(1, n + 1):
if dp1[i] == 0:
... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is a big fan of soccer! He loves soccer so much, that he even invented soccer for his pet dogs! Here are the rules of the game:
There are N dogs numerated from 1 to N stay in a line, so dogs i and i + 1 are adjacent.
There is a ball ... | def chefsoc2():
for _ in range(int(input())):
n, m, s = map(int, input().split())
a = list(map(int, input().split()))
ma = []
for i in range(n):
ma.append(0)
k = ma[:]
k[s - 1] = 1
for i in range(m):
l = ma[:]
for j in range... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_C... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def fastpowmod(a, b, mod):
if b == 0:
return 1
r = fastpowmod(a, int(b / 2), mod)
if b % 2:
return r * r * a % mod
else:
return r * r % mod
def getcoefbezout(a, b):
A = [[1, 0], [0, 1]]
while b != 0:
w = int(a / b)
A[0][0] = A[0][0] - w * A[1][0]
... | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def fact(i):
if i == 0:
return 1
if i < 0:
return 0
res = 1
for t in range(1, i + 1):
res *= t
return res
n, m, k = map(int, input().split(" "))
if k >= n:
print(0)
exit(0)
print(fact(n - 1) // fact(k) // fact(n - k - 1) * m * (m - 1) ** k % 998244353) | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = map(int, input().split())
if k == 0:
print(m)
elif m == 1:
print(0)
else:
total1 = m * pow(m - 1, k) % 998244353
total2 = 1
for i in range(1, k + 1):
total2 = total2 * (n - i)
for i in range(1, k + 1):
total2 = total2 // i
t = total1 * total2 % 998244353
print(t... | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | import sys
sys.setrecursionlimit(3000)
def fac(n):
return 1 if n < 2 else n * fac(n - 1)
def choose(n, k):
return fac(n) // (fac(k) * fac(n - k))
n, m, k = (int(s) for s in input().split(" "))
print(choose(n - 1, k) * m * (m - 1) ** k % 998244353) | IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN VAR NUMBER NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUN... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | mod = 998244353
def nCrModp(n, r):
C = [(0) for i in range(r + 1)]
C[0] = 1
for i in range(1, n + 1):
for j in range(min(i, r), 0, -1):
C[j] = (C[j] + C[j - 1]) % mod
return C[r]
n, m, k = map(int, input().split())
if m == 1 and k > 0:
print(0)
else:
ans = m
ans = ans... | ASSIGN VAR NUMBER FUNC_DEF 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 FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VA... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | Z = 998244353
def ncr(n, r):
num = den = 1
for i in range(r):
num = num * (n - i) % Z
den = den * (i + 1) % Z
return num * pow(den, Z - 2, Z) % Z
n, m, k = list(map(int, input().split()))
print(ncr(n - 1, k) * m * pow(m - 1, k, Z) % Z) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EX... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | from sys import setrecursionlimit
setrecursionlimit(2500)
d = dict()
LIMITE = 998244353
def rec(total, cores, dif):
s = "%d %d" % (total, dif)
if dif >= total:
d[s] = 0
return 0
if total == 1:
d[s] = cores
return cores
if s in d:
return d[s]
if dif == 0:
... | EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP STRING VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR IF VAR VAR RETURN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def inv(x):
return pow(x, MOD - 2, MOD)
def C(n, r):
return fact[n] * inv(fact[r]) * inv(fact[n - r])
n, m, k = map(int, input().split())
MOD = 998244353
fact = [1]
for i in range(1, 2100):
fact.append(fact[-1] * i % MOD)
ans = C(n - 1, k) * m * pow(m - 1, k, MOD)
ans %= MOD
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | import sys
input = sys.stdin.readline
mod = 998244353
n, m, k = list(map(int, input().split()))
N = n - 1
INV = [None] * (n + 1)
for i in range(1, n + 1):
INV[i] = pow(i, mod - 2, mod)
Combi = [None] * (N + 1)
Combi[0] = 1
for i in range(1, N + 1):
Combi[i] = Combi[i - 1] * (N - i + 1) * INV[i] % mod
ANS = Com... | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NONE ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def fact(n):
q = 1
for i in range(1, n + 1):
q *= i
return q
n, m, k = input().split()
n = int(n)
m = int(m)
k = int(k)
com = fact(n - 1) // (fact(k) * fact(n - 1 - k))
dd = m * (m - 1) ** k
print(com * dd % 998244353) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR 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 BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP B... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | dp = [[(0) for j in range(2001)] for i in range(2001)]
n, m, k = map(int, input().split())
for i in range(1, n + 1):
for j in range(k + 1):
if j == 0 and i == 1:
dp[i][j] = m
continue
if j <= i - 1:
dp[i][j] = (m - 1) * dp[i - 1][j - 1] + dp[i - 1][j]
... | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_O... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def fact(n):
ans = 1
for i in range(n, 0, -1):
ans *= i
return ans
def c_n_k(n, k):
return fact(n) // (fact(k) * fact(n - k))
n, m, k = map(int, input().split())
print(c_n_k(n - 1, k) * (m - 1) ** k * m % 998244353) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BI... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = map(int, input().split())
mod = 998244353
t = 1
n -= 1
for i in range(n - k + 1, n + 1):
t *= i
for j in range(1, k + 1):
t //= j
for i in range(k):
t *= m - 1
t %= mod
print(m * t % mod) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_O... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | MOD = 998244353
n, m, k = input().split()
n = int(n)
m = int(m)
k = int(k)
def nCr(n, k):
C = [(0) for i in range(k + 1)]
C[0] = 1
for i in range(1, n + 1):
j = min(i, k)
while j > 0:
C[j] = C[j] + C[j - 1]
j -= 1
return C[k]
answer = m * nCr(n - 1, k) * (m - ... | ASSIGN VAR NUMBER 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 FUNC_DEF 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 ASSIGN VAR FUNC_CALL VAR VAR VAR WHIL... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = [int(x) for x in input().split()]
dp = [[(0) for _ in range(k + 1)] for _ in range(n)]
dp[0][0] = m
for n1 in range(1, n):
dp[n1][0] = m
for n1 in range(1, n):
for k1 in range(1, k + 1):
dp[n1][k1] = (dp[n1 - 1][k1] + dp[n1 - 1][k1 - 1] * (m - 1)) % 998244353
print(dp[n - 1][k]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | mod = 998244353
n, m, k = map(int, input().strip().split())
dp = [(0) for i in range(k + 1)]
dp[0] = m
for i in range(1, n):
new_dp = list(dp)
for j in range(1, k + 1):
new_dp[j] = (new_dp[j] + dp[j - 1] * (m - 1)) % mod
dp = new_dp
print(dp[-1] % mod) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VA... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | H = list(map(int, input().split()))
n = H[0]
m = H[1]
k = H[2]
a = 1
b = 1
c = 1
for i in range(1, n):
a = a * i
for i in range(1, n - k):
b = b * i
for i in range(1, k + 1):
c = c * i
q = a // (b * c)
ans = q * m * (m - 1) ** k
print(ans % 998244353) | 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def ncr(n, r, p):
num = den = 1
for i in range(r):
num = num * (n - i) % p
den = den * (i + 1) % p
return num * pow(den, p - 2, p) % p
n, m, k = map(int, input().split())
p = 998244353
t = 1
for i in range(k):
t *= m - 1
t %= p
print(ncr(n - 1, k, p) * m * t % p) | FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBE... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | m = list(map(int, input().split(" ")))
a = m[0]
b = m[1]
c = m[2]
ways = 1
def fact(n):
a = 1
for i in range(2, n + 1):
a *= i
return a
def p(r, n):
return fact(n) // fact(r)
def entekhab(r, n):
return p(r, n) // fact(n - r)
ways *= b
a -= 1
ways *= entekhab(c, a)
ways *= (b - 1) ** ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF R... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | f = [[(0) for i in range(2001)] for j in range(2001)]
mod = 998244353
def colorful_bricks(n, m, k):
f[1][0] = m
for i in range(2, n + 1):
for j in range(i):
f[i][j] = f[i - 1][j]
if j > 0:
f[i][j] = (f[i][j] + f[i - 1][j - 1] * (m - 1)) % mod
return f[n][k]
... | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP V... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = [int(x) for x in input().split()]
mod = 998244353
def com(n, r, p=998244353):
C = [(0) for i in range(r + 1)]
C[0] = 1
for i in range(1, n + 1):
for j in range(min(i, r), 0, -1):
C[j] = (C[j] + C[j - 1]) % p
return C[r]
ans = com(n - 1, k) * m * pow(m - 1, k, mod) % mod... | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF NUMBER 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 FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = map(int, input().split())
mod = 998244353
f = [0] * 10**5
f[0] = f[1] = 1
for i in range(2, 10**5):
f[i] = f[i - 1] * i % mod
def comb(x, r):
return f[x] * pow(f[r], mod - 2, mod) * pow(f[x - r], mod - 2, mod) % mod
ans = comb(n - 1, k) * m * pow(m - 1, k, mod) % mod
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | import sys
sys.setrecursionlimit(10000)
D = {(1, 0): 1, (1, 1): 0}
n, m, k = [int(x) for x in input().split()]
def f(n, k):
if k == 0:
return m
if k >= n:
return 0
if (n, k) in D:
return D[n, k]
else:
ans = (f(n - 1, k) + (m - 1) * f(n - 1, k - 1)) % 998244353
... | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = input().split()
n = int(n)
m = int(m)
k = int(k)
result = 1
k = k + 1
for i in range(k - 1):
result *= n - 1 - i
result //= 1 + i
result = result % 998244353
result *= m
for i in range(k - 1):
result *= m - 1
result = result % 998244353
if result < 0:
result += 998244353
print(result) | 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 ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUN... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | mod = 998244353
def comb(n, r):
facn = 1
for i in range(1, n + 1):
facn = facn * i
facr = 1
for i in range(1, r + 1):
facr *= i
facnr = 1
for i in range(1, n - r + 1):
facnr *= i
res = facn // (facnr * facr)
res = res % mod
return res
nmk = list(map(int, i... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN V... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.