description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
import sys def minrest(v, n, i, last): if i >= n: return 0 if dp[i][last] != -1: return dp[i][last] if v[i] == 0: dp[i][last] = minrest(v, n, i + 1, 0) + 1 elif v[i] == 1: if v[i] == last: dp[i][last] = minrest(v, n, i + 1, 0) + 1 else: d...
IMPORT FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CAL...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) a = [int(i) for i in input().split()] action = 0 rest = 0 for i in range(n): if a[i] == 0: rest += 1 action = 0 elif a[i] == 1: if action != 1: action = 1 else: rest += 1 action = 0 elif a[i] == 2: if action != 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSI...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
def main(): input() a1 = a2 = x1 = x2 = z = 0 for b in map(int, input()[::2]): if 0 < b < 3: if a1 == b: a1 = 0 x1 += 1 else: a1 = b if a2 == b: a2 = 0 x2 += 1 else: ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR ASSIG...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
int(input()) descanso = anterior = 0 for i in [int(k) for k in input().split()]: if i == 0 or i == anterior: descanso += 1 anterior = 0 elif i == 3: if anterior != 0: anterior = 3 - anterior else: anterior = i print(descanso)
EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
import sys inp = sys.stdin n = int(inp.readline()) a = list(map(int, inp.readline().split())) best = [0, 0, 0] for i in range(n): nx_best = [0, 0, 0] if a[i] in (1, 3): nx_best[1] = max(best[0], best[2]) + 1 if a[i] in (2, 3): nx_best[2] = max(best[0], best[1]) + 1 nx_best[0] = max(best...
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 LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) a = list(map(int, input().split())) dp = [([0] * n) for i in range(2)] if a[0] == 0: dp[0][0] = 1 dp[1][0] = 1 elif a[0] == 1: dp[0][0] = 1 elif a[0] == 2: dp[1][0] = 1 for i in range(1, n): if a[i] == 0: dp[0][i] = 1 + min(dp[0][i - 1], dp[1][i - 1]) dp[1][i] = 1 + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUM...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) m = [int(x) for x in input().split()] l = [] if m[0] == 0: l.append([0, 0, 0]) elif m[0] == 1: l.append([0, 1, 0]) elif m[0] == 2: l.append([0, 0, 1]) else: l.append([0, 1, 1]) for i in range(1, n): if m[i] == 0: l.append([max(l[i - 1]), max(l[i - 1]), max(l[i - 1])]) el...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
def sport(v): return v >= 2 def contest(v): return v in [1, 3] LAST_CONTEST = 0 LAST_SPORT = 1 def __starting_point(): n = int(input()) a = list(map(int, input().split())) prev = [0, 0] dp = [0, 0] for i in range(n): v = a[i] curr = [dp[0], dp[1]] if sport(v): ...
FUNC_DEF RETURN VAR NUMBER FUNC_DEF RETURN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VA...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
n = int(input()) d = list(map(int, input().split()))[:n] dp = [[int(101) for i in range(100)] for j in range(3)] dp[0][0] = 1 if d[0] == 1 or d[0] == 3: dp[1][0] = 0 if d[0] == 2 or d[0] == 3: dp[2][0] = 0 for i in range(1, n): dp[0][i] = 1 + min(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]) if d[i] == 1 or...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR ...
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and th...
INF = 1000 n = int(input()) desc = list(map(int, input().split())) r = {} g = {} c = {} r[0] = 0 g[0] = 0 c[0] = 0 i = 0 for x in desc: i += 1 if x == 0: g[i] = INF c[i] = INF r[i] = 1 + min([g[i - 1], r[i - 1], c[i - 1]]) elif x == 1: g[i] = INF c[i] = min(r[i - 1], ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array $a$ of length $n$, consisting only of the numbers $0$ and $1$, and the number $k$. Exactly $k$ times the following happens: Two numbe...
M = 10**9 + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) z, o = a.count(0), a.count(1) d = pow(n * (n - 1) // 2, M - 2, M) if z > o: o, z = z, o a = [(1 - x) for x in a][::-1] res = [([0] * (z + 1)) for i in range(z + 1)] tf = [([0] * (z + 1)) for i in range(z + 1)] for i in range(z + ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR IF ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array $a$ of length $n$, consisting only of the numbers $0$ and $1$, and the number $k$. Exactly $k$ times the following happens: Two numbe...
N, T = map(int, input().split()) A = [int(a) for a in input().split()] if sum(A) > N // 2: A = [(1 - a) for a in A][::-1] K = sum(A) S = sum(A[-K:]) M = K + 1 P = 10**9 + 7 inv = pow(N * (N - 1) // 2, P - 2, P) X = [([0] * M) for _ in range(M)] for i in range(M): if i > 0: X[i - 1][i] = (K - i + 1) ** 2...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER ...
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array $a$ of length $n$, consisting only of the numbers $0$ and $1$, and the number $k$. Exactly $k$ times the following happens: Two numbe...
import sys __version__ = "1.8" __date__ = "2019-04-21" def binom_dp(): dp = [[(-1) for j in range(110)] for i in range(110)] def calculate(n, k): if n < k: return 0 if n == k or k == 0: return 1 if dp[n][k] > 0: return dp[n][k] else: ...
IMPORT ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR...
The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital β€” number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any d...
s = list(map(int, input().split())) n = s[0] m = s[1] roads = [] Adj = [] for i in range(0, n + 1): roads.append([]) Adj.append([False] * (n + 1)) for i in range(0, m): s = list(map(int, input().split())) roads[s[0]].append(s[1]) roads[s[1]].append(s[0]) Adj[s[0]][s[1]] = True Adj[s[1]][s[0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_C...
The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital β€” number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any d...
n, m = map(int, input().split()) adj = [[] for i in range(n)] for _ in range(m): a, b = map(int, input().split()) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) def bfs(s): q, d, res = [s], [-1] * n, [0] * n d[s] = 0 res[s] = 1 i = 0 while i < len(q): v = q[i] for u ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR LIST...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def f(s, k): n = len(s) q = [s] S = set() S.add(s) ans = 0 while len(q) > 0 and k > 0: ss = q[0] k -= 1 ans += n - len(ss) q.pop(0) for i in range(len(ss)): ns = ss[0:i] + ss[i + 1 : len(s)] if ns not in S: q.append(...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
from sys import stdin n, k = [int(i) for i in stdin.readline().strip().split()] s = stdin.readline().strip() def get_f(s): F = [(len(s) * [0]) for _ in range(len(s) + 1)] size = 0 for index in range(len(s)): F[size][index] = 1 F[1][0] = 1 p = {s[0]: 0} for i in range(1, len(s)): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBE...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
from sys import stdin, stdout n, kk = map(int, stdin.readline().split()) s = stdin.readline().strip() s += "$" n = n + 1 dp = [[(0) for i in range(n)] for j in range(n)] p = 10**15 + 5 for i in range(n): dp[i][0] = 1 for end in range(n): for length in range(1, n): seen = [] ans = 0 for ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split(" ")) s = input() dp = [([0] * (n + 1)) for _ in range(n + 1)] dp[0][0] = 1 for l in range(0, n): for i in range(l, n + 1): used = [False] * 26 for j in range(i + 1, n + 1): ch = ord(s[j - 1]) - ord("a") if not used[ch]: dp[l + 1]...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER 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 VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER F...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = str(input()) s1 = "" sub = [s] inv = {} c = 0 kq = 0 while len(sub) > 0: tem = sub[0] del sub[0] if inv.get(tem, 0) == 0: inv[tem] = 1 c += 1 kq += n - len(tem) if c == k: break for i in range(len(tem)): s1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VA...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = input() s = [(ord(c) - ord("a")) for c in s] dp = [[([0] * 26) for i in range(n + 1)] for i in range(n)] dp[0][1][s[0]] = 1 sm = None for i in range(1, n): c = s[i] for cc in range(26): dp[i][1][cc] = dp[i - 1][1][cc] dp[i][1][c] = 1 for j in reversed(range(2...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL V...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
[n, k] = [int(i) for i in input().split()] S = [input()] l = 0 x = 0 c = 0 while len(S) < k: d = k - len(S) a = set() for i in range(l, len(S)): for j in range(0, len(S[i])): s = S[i][:j] + S[i][j + 1 :] if s not in a: a.add(s) c += x + 1 ...
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) r = set() r1 = set() a = input() queue = [a] cost = 0 co = 0 r1.add(a) while queue: ref = queue.pop(0) if ref not in r: r.add(ref) cost += n - len(ref) co += 1 if co == k: break for i in range(len(ref)): y = ref[:i] + ref[i + 1 :] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, tt = map(int, input().split()) s = input() dp = [([0] * (n + 1)) for i in range(n + 1)] for c in range(n + 1): dp[0][c] = 1 last = [-1] * 26 for c in range(1, n + 1): k = ord(s[c - 1]) - ord("a") for r in range(1, n + 1): dp[r][c] = dp[r][c - 1] + dp[r - 1][c - 1] if last[k] == -1: la...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER A...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def __starting_point(): n, k = list(map(int, input().split())) aa = list(input()) st = {"".join(aa)} arr = [aa] w = 0 c = 0 cst = 0 while len(arr) < k and w < len(arr): wrd = arr[w][:c] + arr[w][c + 1 :] wrds = "".join(wrd) if wrds not in st: st.add(wr...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, K = map(int, input().split()) s = input() kolvo = 1 res = 0 d = {} d[0] = [] d[0].append(s) level = 0 while kolvo < K and level <= n: level += 1 d[level] = [] for subs in d[level - 1]: for j in range(len(subs)): subs1 = subs[:j] + subs[j + 1 :] if subs1 not in d[level]: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER LIST EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR LIST FOR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
ls = list(map(int, input().split())) s = input() q = [s] n, k = ls[0], ls[1] l = set() c = 0 cost = 0 while len(q) != 0: p = q.pop(0) if p not in l: l.add(p) cost = cost + len(s) - len(p) if len(l) == k: c = 1 break for i in range(len(p)): t = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BI...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
alpha = list("abcdefghijklmnopqrstuvwxyz ") def count_subseq(s): n = len(s) dp = [[([0] * 27) for i in range(n + 10)] for j in range(n + 10)] dp[0][0][26] = 1 for i in range(1, n + 1): st = s[i - 1] for j in range(i + 1): v = sum(dp[i - 1][j - 1][p] for p in range(27)) ...
ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = list(map(int, input().split())) s = input() st = [set() for i in range(n + 1)] st[n].add(s) c = 1 k -= 1 ans = 0 for i in range(n, 0, -1): for w in st[i]: for j in range(i): st[i - 1].add(w[:j] + (w[j + 1 :] if j != i - 1 else "")) sz = len(st[i - 1]) if k < sz: ans += (n ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FU...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def check_word(word_list, word_need): unique = [] for i in range(len(word_list)): if word_need == 0: break for j in range(len(word_list[i])): if word_need == 0: break new_word = word_list[i][:j] + word_list[i][j + 1 :] if new_word n...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN LIST VAR VAR FUNC_C...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
arr = input() N, K = [int(num) for num in arr.split(" ")] string = input() seq = [string] record = {} record[string] = 1 count = 1 while seq and count <= 105: gen_d = seq.pop(0) for k in range(len(gen_d)): r = gen_d[:k] + gen_d[k + 1 :] if r not in record: record[r] = 1 s...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NU...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
[n, k] = [int(i) for i in input().split()] s = input() cntsz = [(0) for i in range(105)] dp = [[(0) for i in range(105)] for j in range(105)] lst = [(0) for i in range(105)] prv = [(0) for i in range(26)] n = len(s) s = "%" + s for i in range(n + 1): dp[i][0] = 1 for i in range(1, n + 1): lst[i] = prv[ord(s[i])...
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASS...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
import sys input = sys.stdin.readline n, W = map(int, input().split()) s = input().strip() NEXTLIST = [([n] * 26) for i in range(n + 1)] for i in range(n - 1, -1, -1): for j in range(26): NEXTLIST[i][j] = NEXTLIST[i + 1][j] NEXTLIST[i][ord(s[i]) - 97] = i DP = [([0] * (n + 1)) for i in range(n + 1)] DP...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN V...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
R = lambda: map(int, input().split()) n, k = R() s = input() p = [s] ans = 0 d = set() while p: q = p.pop(0) if q not in d: k -= 1 ans += n - len(q) if k == 0: print(ans) quit() d.add(q) for i in range(len(q)): t = q[:i] + q[i + 1 :] ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL V...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = input() last = [[(-1) for i in range(26)] for j in range(n)] for i in range(n): for j in range(26): if i != 0: last[i][j] = last[i - 1][j] last[i][ord(s[i]) - ord("a")] = i dp = [[(0) for i in range(n + 1)] for j in range(n)] for i in range(n): dp[i][...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR S...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
line = input() need = int(line.split(" ")[1]) - 1 n = int(line.split(" ")[0]) s = input() if need == 0: print(0) else: queue = [s] d = {} head, tail, ans = 0, 1, 0 solve = False while head < tail and not solve: top = queue[head] cost = len(top) - 1 for idx, c in enumerate...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VA...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
from sys import stdin def subseq(xs, n, m): if n > 1: sl = subseq(xs[: n // 2], n // 2, m) sr = subseq(xs[n // 2 :], n - n // 2, m) return combine(sl, sr, m) return xs def combine(sl, sr, m): seq = {(s1 + s2) for s1 in sl for s2 in sr}.union(sl, sr) seql = sorted(seq, key=len...
FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NU...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = list(map(int, input().split())) s = input() sett = {s} q = [s] m = n while len(q) and len(sett) < k: node = q.pop(0) for i in range(0, len(node)): ss = node[:i] + node[i + 1 :] if not ss in sett and len(sett) < k: q.append(ss) sett.add(ss) m += len(ss) ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER I...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def solve(n, k, s): set = {} queue = [] ans = 0 queue.append(s) set[s] = 1 while len(queue) > 0 and len(set) < k: curr = queue.pop(0) for i in range(len(curr)): newS = curr[:i] + curr[i + 1 :] if newS not in set and len(set) + 1 <= k: set[n...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, setsize = list(map(int, input().split())) s = input() count = [[(0) for j in range(n + 1)] for i in range(n + 1)] for i in range(n): j = i - 1 while j >= 0: for k in range(1, n): count[i][k + 1] += count[j][k] if s[j] == s[i]: break j -= 1 if j == -1: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
from itertools import combinations n, k = map(int, input().split()) s = str(input()) def rSubset(arr, r): return set(list(combinations(arr, r))) def repeat(s): l = list(s) l2 = [] for i in range(len(s)): if l[i] == str(s[0]): l2.append(True) else: l2.append(F...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EX...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = tuple([int(x) for x in input().split()]) s = input() q = [] nv = "" st = [] st.append(s) ans = 0 q.append(s) while q != [] and len(st) < k: v = q.pop(0) for i in range(len(v)): nv = v nv = nv[:i] + nv[i + 1 :] if nv not in st and len(st) + 1 <= k: q.append(nv) ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR LIST FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR V...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, d = map(int, input().split()) s = input() t = [[(-1) for i in range(n + 1)] for j in range(n + 1)] for i in range(1, n + 1): for j in range(i, n + 1): if j == i: t[i][j] = 1 else: t[i][j] = 0 jes = [0] * 300 for i in range(1, n + 1): jes[ord(s[i - 1])] = 1 t[i][1] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR N...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def main(): n, K = map(int, input().split()) s = str(input()) next = [([10**18] * 26) for _ in range(n + 1)] for i in reversed(range(n)): for j in range(26): next[i][j] = next[i + 1][j] if s[i] == chr(j + ord("a")): next[i][j] = i dp = [([0] * (n + 1))...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR FUN...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
import sys input = sys.stdin.readline n, k = map(int, input().split()) s = ["?"] + list(input().rstrip()) dp = [] dp0 = [0] * (n + 1) dp0[0] = 1 dp.append(dp0) for _ in range(n): dp1 = [0] * (n + 1) for i in range(n): dpi = dp0[i] s0 = set() for j in range(i + 1, n + 1): if ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_O...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = input() c = 0 q = [s] d = set() ls = 0 while q: p = q.pop(0) if p not in d: ls += 1 c += n - len(p) if ls == k: break d.add(p) for i in range(len(p)): temp = p[:i] + p[i + 1 :] if temp not in d: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = "{" + input() dp = [([0] * (n + 1)) for _ in range(n + 1)] dp[0][0] = 1 oa = ord("a") for i in range(1, n + 1): for j in range(1, n + 1): hold = [0] * 30 for l in range(0, i): let = ord(s[l]) - oa dp[i][j] += dp[l][j - 1] - hold[let] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
import sys n, k = [int(i) for i in input().split()] s = input() seqset = set() seqset.add(s) subsequences = [[] for _ in range(n)] subsequences[0].append(s) result = 0 count = 1 if count == k: print(result) sys.exit(0) for i in range(n - 1): for ss in subsequences[i]: for j in range(len(ss)): ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CA...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def count_subsequences_of_length(s): n = len(s) alphabet = list(set(list(s))) to_int = {} for i, char in enumerate(alphabet): to_int[char] = i next_i = [([n] * len(alphabet)) for i in range(n + 1)] for i in reversed(range(n)): for j, char in enumerate(alphabet): next_...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VA...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) str = str(input()) q = [str] ans = 0 ma = {} while len(q) != 0 and k > 1: s = q[0] q.remove(q[0]) for i in range(len(s)): ss = s s1 = ss[0:i] s2 = ss[i + 1 :] ss = s1 + s2 if ss not in ma.keys(): ma[ss] = 1 k -=...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
N, K = map(int, input().split()) S = input() dp = [([0] * 110) for i in range(110)] lst = [([0] * 110) for i in range(110)] for i in range(N + 1): dp[i][0] = 1 for k in range(26): lst[0][k] = -1 for i in range(N): num = ord(S[i]) - ord("a") for k in range(26): lst[i + 1][k] = lst[i][k] lst[i...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBE...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
import itertools import sys inputs = sys.stdin.read().split() len_string = int(inputs[0]) desired_size = int(inputs[1]) string = inputs[2] size = 0 cost = 0 cur_set = set() cur_set.add(string) for i in range(len_string, -1, -1): cur_size = len(cur_set) if size + cur_size >= desired_size: cost += (desir...
IMPORT IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VA...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
line1 = input().split(" ") n = int(line1[0]) k = int(line1[1]) s = list(input()) dp = [(101 * [0]) for i in range(101)] last = 26 * [-1] for i in range(n + 1): dp[0][i] = 1 for l in range(1, n + 1): dp[l][0] = 0 for c in range(26): last[c] = -1 for i in range(1, n + 1): dp[l][i] = dp[l -...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER LIST NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
inp = input() inp = inp.split(" ") n = int(inp[0]) k = int(inp[1]) cost = 0 inp1 = input() l = [] l.append(inp1) check = 1 b = False for i in range(1, n + 1): l1 = [] for word in l: for j in range(len(word)): l1.append(word[0:j] + word[j + 1 : len(word)]) l1 = list(set(l1)) l = l1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VA...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = input() pos = [-1] * 26 lst = [] for i in range(0, len(s)): pos[ord(s[i]) - 97] = i h = [] for j in range(26): h.append(pos[j]) lst.append(h) dp = [] for i in range(n): h = [] for j in range(n + 1): h.append(0) dp.append(h) for i in range(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
import sys n, k = map(int, sys.stdin.readline().split(" ")) s = sys.stdin.readline().strip() lt = [s] count = 0 flag = False result = 0 while lt: cur_s = lt[0] lt.pop(0) result += len(s) - len(cur_s) count += 1 if count >= k: break for i in range(0, len(cur_s)): new_s = cur_s[0:...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
a = input() n = int(a.split(" ")[0]) k = int(a.split(" ")[1]) s = input() lgmoorz = [] dpprev = [] dpcurr = [] dp = [] for i in range(len(s)): if s[i] not in lgmoorz: lgmoorz.append(s[i]) dpcurr.append(len(lgmoorz)) dp.append(dpcurr[-1]) prevocc = [] for i in range(len(s)): prevocc.append(-1) fo...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = input() a = set() k -= 1 q = [s] i = 0 ans = 0 while i < len(q) and k > 0: for j in range(len(q[i])): new = q[i][:j] + q[i][j + 1 :] if new not in a: a.add(new) q.append(new) ans += n - len(q[i]) + 1 k -= 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, K = map(int, input().split()) s = input() J = [-1] * n last_seen = dict() for i in range(n): if s[i] in last_seen: J[i] = last_seen[s[i]] last_seen[s[i]] = i dp = [[([0] * (1 + n)) for _ in range(n)] for _ in range(n)] for i in range(n): for j in range(i, n): dp[i][j][0] = 1 for k in rang...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
import itertools import sys inputs = sys.stdin.read().split() len_string = int(inputs[0]) desired_size = int(inputs[1]) string = inputs[2] def val_of_letter(char): return ord(char) - ord("a") num_subsequences = [1] num_subsequences_so_far = [0] * len_string last_num_subsequences_so_far = [0] * len_string num_s...
IMPORT IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST N...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
import sys def eprint(*args, **kwargs): if __debug__: print(*args, file=sys.stderr, **kwargs) def calculate_res(visit, n): return n * len(visit) - sum([len(x) for x in visit]) def traverse(s, k): _que = [] visit = set([]) _que.append(s) visit.add(s) if len(visit) == k: ...
IMPORT FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = input() ns = len(s) pos = [(0) for i in range(26)] dp = [[(0) for j in range(ns + 1)] for i in range(ns + 1)] dp[0][0] = 1 for i in range(1, ns + 1): v = ord(s[i - 1]) - ord("a") for j in range(0, i + 1): if j > 0: dp[i][j] += dp[i - 1][j - 1] dp[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 BIN_OP VAR NUMB...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) dict1 = {} sumx = 0 ans = 1 s = str(input()) arr = [s] flag = 0 dict1[s] = 1 while flag == 0 and len(dict1) < k: arr1 = [] for i in range(len(arr)): for j in range(len(arr[i])): try: dict1[arr[i][:j] + arr[i][j + 1 :]] += 1 except:...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def sol(a, k): n = len(a) if k == 0: return 1 if k == 1: v = set() for x in a: v.add(x) return len(v) if n < k or n < 1 or k < 1: return 0 if n == k: return 1 sz = max(3000, n) v1 = [0] * sz v2 = [0] * sz v3 = [0] * sz v...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BI...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
N, K = map(int, input().split()) pre = [input()] ans = 0 k = 1 f = 0 while True: if k >= K: print(ans) break if len(pre) == 0: print(-1) break post = [] for s in pre: for i in range(len(s)): t = s[:i] + s[i + 1 :] if t not in post: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
import sys class ESubsequencesEasyVersion: def solve(self): n, k = [int(_) for _ in input().split()] s = input() dp = [([0] * (n + 1)) for _ in range(n + 1)] dp[0][0] = 1 last = {key: (-1) for key in (chr(x) for x in range(ord("a"), ord("z") + 1))} for i in range(1...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FU...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
from sys import exit, stdin, stdout def price(): n, k = map(int, stdin.readline().split()) s = stdin.readline().strip() todo = [s] ans = 0 found = {s: True} k -= 1 while todo and k > 0: nexts = [] for wd in todo: for i in range(len(wd)): candidat...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
iarr = list(map(int, input().split())) n = iarr[0] k = iarr[1] s = input() arr = [] arr.append(s) ans = 0 ii = 0 flagg = 0 while True: if flagg == 1: break if arr[ii] == "": break l = len(arr[ii]) curcost = n - l + 1 for i in range(l): ss = arr[ii][:i] + arr[ii][i + 1 :] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BI...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = input().split(" ") n = int(n) k = int(k) s = input() s = "-" + s dp = [[(0) for i in range(110)] for j in range(110)] added = [[(0) for i in range(110)] for j in range(110)] lst = [(0) for i in range(310)] lstAdded = [(0) for i in range(310)] for i in range(0, 110): dp[0][i] = 1 vec = list() st = set() for i...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
from itertools import combinations def main(): n, k = map(int, input().split()) s = input() lenf = len l_prev = {s} curS = 1 cost = 0 if k == 1: print(0) return for curlen in range(n - 1, -1, -1): l = set() for l_elem in l_prev: for v in comb...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def sol(b): c = [] for i in range(len(b)): c.append(b[:i] + b[i + 1 :]) return c s = set() n, k = map(int, input().split()) st = input() la = n p = [st] p = set(p) while la > 0: s = s.union(p) r = set() fl = 0 for i in p: c = sol(i) la = len(c[0]) r = r.unio...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def solve(n, k, s): total_length = 0 queue = [s] ss = set() while queue and len(ss) < k: s = queue.pop(0) if s not in ss: ss.add(s) total_length += len(s) if len(ss) < k: for i in range(len(s)): temp = s[:i] + s[i + ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) targets = [input()] ans = 0 cur = 1 depth = 0 if cur >= k: print(ans) exit() while depth <= n: depth += 1 next_target = [] for target in targets: for i in range(len(target)): check = target[:i] + target[i + 1 :] if check in next_target...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
from sys import stdin def main(): from sys import stdin input = stdin.readline n, k = map(int, input().split()) s = input()[:-1] dp = [([0] * 26) for i in range(n + 1)] dp[0][0] = 1 for ch in s: j = ord(ch) - ord("a") for i in range(n, 0, -1): dp[i][j] = sum(dp...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER ...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def func(n, k, s): x = [s] cost = 0 while len(x) < k: for string in x: l = len(string) for j in range(l): t = string[:j] + string[j + 1 :] if t == "" and t in x: return -1 if t not in x: x...
FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR VAR RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RE...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def super_solve(n, k, s): last = [] for i in range(0, 256): last.append(0) dp = [] for i in range(0, 105): tmp = [] for j in range(0, 105): tmp.append(0) dp.append(tmp) now = [] for i in range(0, 105): tmp = [] for j in range(0, 105): ...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, K = map(int, input().split()) s = input() max_n = 104 dp = [([0] * max_n) for i in range(max_n)] s = "$" + s for i in range(n + 1): dp[0][i] = 1 for ln in range(1, n + 1): for j in range(1, n + 1): dp[ln][j] = dp[ln][j - 1] + dp[ln - 1][j - 1] for k in range(j - 1, 0, -1): if s[k]...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL V...
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
n, k = map(int, input().split()) s = input() dp = [([0] * 102) for i in range(102)] dp1 = [([0] * 102) for i in range(30)] for i in range(0, n + 1): dp[i][0] = 1 for i in range(1, n + 1): nm = ord(s[i - 1]) - ord("a") for le in range(1, i + 1): dp[i][le] = dp[i - 1][le] + dp[i - 1][le - 1] d...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VA...
You have a tree of $n$ vertices. You are going to convert this tree into $n$ rubber bands on infinitely large plane. Conversion rule follows: For every pair of vertices $a$ and $b$, rubber bands $a$ and $b$ should intersect if and only if there is an edge exists between $a$ and $b$ in the tree. Shape of rubber bands ...
n = int(input()) tr = [[] for i in range(n + 9)] for i in range(n - 1): u, v = list(map(int, input().split())) tr[u].append(v) tr[v].append(u) dp, ans = [[0, 0] for i in range(n + 9)], 0 stk, tot = [(1, -1)], 0 for i in range(n): u, fa = stk[i] for v in tr[u]: if v != fa: stk.app...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR N...
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible. Input The first line contains two integer numbers n and k (1 ≀ n ≀ 200, ...
import sys n, K = map(int, input().split()) a = list(map(int, input().split())) m2, m5 = [0] * n, [0] * n for i, x in enumerate(a): while x % 2 == 0: x //= 2 m2[i] += 1 while x % 5 == 0: x //= 5 m5[i] += 1 dp = [([-(10**9)] * 5100) for _ in range(K)] dp[0][0] = 0 for i in range(...
IMPORT 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 VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER...
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N. John first has to select from which city he will start his journe...
n = int(input()) a = [0] * n for i in range(n - 1): for j in input().split(): a[int(j) - 1] += 1 l = a.count(1) print((l * 2 ** (n - l + 1) + (n - l) * 2 ** (n - l)) % 1000000007)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP...
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N. John first has to select from which city he will start his journe...
def quick_mod(b, p): s = 1 while p != 0: if p & 1: s = s * b % mod p = p // 2 b = b * b % mod return s s = input().split() n = int(s[0]) N = 100000 mod = 1000000007 enter = [] for i in range(1, N + 5): enter.append(0) for i in range(1, n): s1 = input().split() ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR 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 ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL ...
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N. John first has to select from which city he will start his journe...
n = int(input()) cnt = [[] for _ in range(n)] for i in range(n - 1): fr, to = list(map(int, input().split())) cnt[fr - 1].append(to - 1) cnt[to - 1].append(fr - 1) l = 0 for i in range(n): if len(cnt[i]) == 1: l += 1 ans = (n - l) * pow(2, n - l, 10**9 + 7) ans += l * pow(2, n - l + 1, 10**9 + 7...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR ...
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N. John first has to select from which city he will start his journe...
n = int(input()) degree = n * [0] for i in range(0, n - 1): u, v = input().split() u = int(u) v = int(v) u -= 1 v -= 1 degree[u] += 1 degree[v] += 1 numL = 0 for i in range(0, n): if degree[i] == 1: numL += 1 mod = 1000000007 ans = (n - numL) * 2 ** (n - numL) + numL * 2 ** (n + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ...
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
mod = 10**9 + 7 s = input() n = len(s) f = [1] * (n + 1) for i in range(1, n + 1): f[i] = i * f[i - 1] % mod finv = [pow(x, mod - 2, mod) for x in f] op = 0 cl = s.count(")") ans = 0 if cl > 0: for c in s: if c == "(": op += 1 ans += f[op + cl - 1] * finv[cl - 1] * finv[op] ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN ...
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
mod = 10**9 + 7 maxn = 200001 def C(n, k): if k < 0 or k > n: return 0 return fact[n] * invfact[k] * invfact[n - k] % mod fact = [1, 1] inv = [0, 1] invfact = [1, 1] for i in range(2, maxn): fact.append(fact[-1] * i % mod) inv.append(inv[mod % i] * (mod - mod // i) % mod) invfact.append(...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BI...
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
s = input() MOD = 10**9 + 7 num = 0 N = len(s) R = [0] * (N + 1) L = [0] * (N + 1) d = [] for i in range(N): if s[i] == ")": R[i + 1] = 1 else: L[i + 1] = 1 d.append(i) for i in range(1, N + 1): R[i] += R[i - 1] L[i] += L[i - 1] M = 200005 fact = [0] * M fact[0] = 1 for i in rang...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR...
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
t = input() n, m = len(t) + 1, 1000000007 x, y = 0, t.count(")") - 1 fact = [1] * n for i in range(2, n): fact[i] = i * fact[i - 1] % m invMult = [pow(x, m - 2, m) for x in fact] s = 0 for b in t: if y < 0: break if b == "(": x += 1 s += fact[x + y] * invMult[x] * invMult[y] % m ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR...
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
p = 10**9 + 7 def power(x, y, p): b = bin(y)[2:] answer = 1 start = x % p for i in range(len(b)): if b[len(b) - 1 - i] == "1": answer = answer * start % p start = start * start % p return answer def process(S): answer = 0 n = len(S) left_count = 0 righ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUN...
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
def ri(): return list(map(int, input().split())) m = 10**9 + 7 s = input() n = len(s) o = [(0) for i in range(len(s))] c = [(0) for i in range(len(s))] fac = [(0) for i in range(n)] fac[0] = 1 for i in range(1, n): fac[i] = fac[i - 1] * i % m invfac = [pow(fac[i], m - 2, m) for i in range(n)] if s[0] == "(": ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ...
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
mod = 10**9 + 7 F, inv, iF = [1, 1], [0, 1], [1, 1] for i in range(2, 200005): F.append(F[-1] * i % mod) inv.append(inv[mod % i] * (mod - mod // i) % mod) iF.append(iF[-1] * inv[-1] % mod) def C(n, k): if k < 0 or k > n: return 0 return F[n] * iF[k] * iF[n - k] s = input() open, close = ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BI...
Makoto has a big blackboard with a positive integer $n$ written on it. He will perform the following action exactly $k$ times: Suppose the number currently written on the blackboard is $v$. He will randomly pick one of the divisors of $v$ (possibly $1$ and $v$) and replace $v$ with this divisor. As Makoto uses his fam...
n, k = map(int, input().split(" ")) inv = [pow(i, 1000000005, 1000000007) for i in range(60)] def solve(p, q): dp = [1] * (q + 1) for i in range(q): dp[i + 1] = dp[i] * p % 1000000007 for i in range(1, q + 1): dp[i] = (dp[i] + dp[i - 1]) % 1000000007 for _ in range(k): dp1 = [1...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM...
Makoto has a big blackboard with a positive integer $n$ written on it. He will perform the following action exactly $k$ times: Suppose the number currently written on the blackboard is $v$. He will randomly pick one of the divisors of $v$ (possibly $1$ and $v$) and replace $v$ with this divisor. As Makoto uses his fam...
MOD = 10**9 + 7 inv = [pow(i, MOD - 2, MOD) for i in range(60)] n, k = map(int, input().split()) def solve(p, q): dp = [1] for i in range(q): dp.append(dp[-1] * p % MOD) for i in range(1, q + 1): dp[i] = (dp[i] + dp[i - 1]) % MOD for _ in range(k): dp1 = [1] * (q + 1) f...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BI...
Makoto has a big blackboard with a positive integer $n$ written on it. He will perform the following action exactly $k$ times: Suppose the number currently written on the blackboard is $v$. He will randomly pick one of the divisors of $v$ (possibly $1$ and $v$) and replace $v$ with this divisor. As Makoto uses his fam...
import time mod = int(1000000000.0 + 7) def fast_expo(x, k): ans = 1 while k > 0: if k & 1 > 0: ans = ans * x % mod x = x * x % mod k >>= 1 return ans def inverse(x): return fast_expo(x, mod - 2) N, K = [int(_) for _ in input().split()] start_time = time.time()...
IMPORT ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL ...
Makoto has a big blackboard with a positive integer $n$ written on it. He will perform the following action exactly $k$ times: Suppose the number currently written on the blackboard is $v$. He will randomly pick one of the divisors of $v$ (possibly $1$ and $v$) and replace $v$ with this divisor. As Makoto uses his fam...
def _try_composite(a, d, n, s): if pow(a, d, n) == 1: return False for i in range(s): if pow(a, 2**i * d, n) == n - 1: return False return True def is_prime(n): if n in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]: return True if any(n % p == 0 for p in [2, 3, 5...
FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR...
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid. A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebr...
n = int(input()) a = [1, 1] for i in range(n): a[i % 2] += a[1 - i % 2] % 1000000007 print((sum(a) - 2) % 1000000007)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid. A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebr...
n = int(input()) mod = int(1000000000.0 + 7) dp = [] cnt = [0, 0] for i in range(n): x = i % 2 == 0 y = (cnt[1 - x] + 1) % mod dp.append(y) cnt[x] += y ans = 0 for i in dp: ans += i ans %= mod print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR ...
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid. A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebr...
n = int(input()) m = int(1000000000.0 + 7) u, v = 0, 1 for _ in range(n - 1): u, v = v, (u + v + 2) % m print(v)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid. A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebr...
l = [0, 1, 3] for i in range(10**6): l.append((l[-1] * 2 - l[-3]) % (10**9 + 7)) print(l[int(input())])
ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid. A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebr...
MOD = 10**9 + 7 n = int(input()) r, b = 0, 0 for i in range(n): if i & 1: b = (b + r + 1) % MOD else: r = (r + b + 1) % MOD print((b + r) % MOD)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR