description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() p = "" p += s[0] j = 1 for i in range(1, len(s)): if s[i] > s[i % j]: break if s[i] < s[i % j]: j = i + 1 ans = "" for i in range(0, k): ans += s[i % j] print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = [int(d) for d in input().split()] s = input() if len(s) == 1: print(s * k) else: x = s[0] done = True i = 1 get = False idx = 0 curr = 0 while i < len(s) and done == True: if s[i] < s[curr]: x = x + s[i] if curr != 0: curr = 0 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR AS...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
def bestPref(s): pref = s[0] for i in range(1, len(s)): ind = i % len(pref) if pref[ind] < s[i]: break elif pref[ind] > s[i]: while len(pref) < i + 1: pref += s[len(pref)] return pref def solve(n, k, s): pref = bestPref(s) cur = "" ...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE BIN_OP FUNC_CALL VAR VA...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
def cpy_tll(s, k): s = s * (k // len(s) + 1) s = s[:k] return s n, k = map(int, input().split()) s = input() pref = s[0] ans = s[0] * k for i in s[1:]: if i <= s[0]: pref += i else: break ans = min(ans, cpy_tll(pref, k)) print(ans)
FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() ans = n m = s[0] for i in range(1, n): if s[i] > m: ans = i break elif s[i] == m: a = s[i:] b = s[: len(a)] if a >= b: ans = i break ns = s[:ans] while len(ns) < k: ns = ns + ns print(ns[:k])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR VA...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() mi = "z" * k for i in range(1, n + 1): news = s[0:i] mi = min(mi, news * (k // i) + news[0 : k % i]) print(mi)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
import itertools def validate_prefix(s, prefix): n = len(s) source = 0 for i in range(prefix, n): if s[i] > s[source]: return prefix elif s[i] == s[source]: source += 1 if source == prefix: source = 0 continue assert s...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() ans = "" for i in range(1, len(s) + 1): g = s[:i] while len(g) < k: g += g g = g[:k] if ans == "": ans = g if g < ans: ans = g print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() ans = "z" * (k + 1) for i in range(n): ref = str() ref = s[: i + 1] while len(ref) < k: ref = ref + ref ref = ref[:k] ans = min(ans, ref) print() print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR ...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split(" ")) s = input() all_strings = [] for i in range(1, len(s) + 1): temp = s[0:i] while len(temp) < k: temp = temp * 2 all_strings.append(temp[0:k]) print(min(all_strings))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = list(map(int, input().split())) st = input() f = st[0] for i in range(1, n): if st[i] >= f: ind = i rep = k // ind temp = st[:ind] * (rep + 1) temp2 = st * (rep + 1) if temp[:k] < temp2[:k]: print(temp[:k]) break else: l = len(st) rep = ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = input().split(" ") n = int(n) k = int(k) string_a = input() strings = [] for i in range(n): strings.append(string_a[: i + 1]) for i in range(n): aux = strings[i] while len(aux) < k: aux += aux aux = aux[:k] strings[i] = aux strings.sort() print(strings[0])
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN V...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
def sol(A, k): ans = "z" * k for i in range(1, len(A) + 1): a = A[:i] ans = min(ans, a * (k // i) + a[: k % i]) return ans A = list(map(int, input().split())) B = input() print(sol(B, A[1]))
FUNC_DEF ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() l = 0 pos = 0 n = len(s) while l < n: temp = s[: pos + 1] * ((l + 1) // (pos + 1) + 1) if s[: l + 1] < temp[: l + 1]: pos = l l += 1 res = s[: pos + 1] * (k // (pos + 1) + 1) print(res[:k])
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 FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() start = s[0] save = -1 build = "" pref = [] z = list(range(1, n + 1)) for i in range(n): build += s[i] pref.append(build * (n // len(build) + 1)) res = sorted(zip(pref, z)) save = res[0][1] s = s[:save] while len(s) < k: s = s + s s = s[:k] print(s)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR FUNC_CALL VAR ...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() l = "" l = l + s[0] j = 0 for i in range(1, n): if s[i] > l[j]: break elif s[i] < l[j]: l = l + s[i] j = 0 elif s[i] == l[j]: l = l + s[i] j = j + 1 p = len(l) r = l[: p - j] m = len(r) s = r * (k // m) for i in range(k % m...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR A...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
def sec(init, i, e, flag): i1 = i while i < n and ord(s[init]) == ord(s[i]) and init < i1: init += 1 i += 1 e += 1 if i == n or i != n and ord(s[init]) < ord(s[i]): flag = 1 return e, flag, i n, k = map(int, input().split()) s = input() init = 0 e = 1 i = 1 flag = 0 whi...
FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMB...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = list(map(int, input().split())) s = input() ans = s[0] * k for i in range(1, n): x = s[: i + 1] * (k // (i + 1)) + s[: k % (i + 1)] ans = min(x, ans) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL V...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
def string(c: str, k: int) -> str: while len(c) < k: c = c + c if len(c) > k: sub = len(c) - k c = c[: len(c) - sub] return c def solution(n: int, k: int, s: str) -> None: first = s[0] lex = string(first, k) for i in range(1, n): if s[i] > s[0]: brea...
FUNC_DEF VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR N...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, desired = map(int, input().split()) s = list(input()) stack = [s[0]] ptr = 0 for i in range(1, n): if ptr == len(stack): ptr = 0 if s[i] < stack[ptr]: stack.append(s[i]) ptr = 0 elif s[i] == stack[ptr]: stack.append(s[i]) ptr += 1 else: stack = stack[: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR V...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, m = map(int, input().split()) s = input() i = 1 ans = s[0] * m while i < n: if s[i] > s[0]: break i += 1 t = s[:i] a = m // len(t) b = m % len(t) ans = min(ans, t * a + t[:b]) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_O...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
def solve(st, n, k): pref = "" ans = None for it in st: pref += it cur = "" ln = 0 while len(pref) + len(cur) <= k: cur += pref if len(cur) < k: cur += pref[: k - len(cur)] if ans == None: ans = cur elif ans > cur: ...
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NONE FOR VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() for i in range(n): if s[i] > s[0]: s = s[:i] break while True: prevlen = len(s) for i in range(1, prevlen): if s[i] == s[0]: tmp = s[i:] + s tmp2 = s if tmp[:prevlen] > tmp2: s = s[:i] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, m = list(map(int, input().split())) s = input() s = list(s) ans = "" for i in range(m): ans += "z" t = "" for i in range(n): t += s[i] p = t while len(t) + len(p) < m: p += t p += p[: m - len(p)] if ans > p: ans = p print(ans)
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 ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR WHILE BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) s = input() f = s[0] idx = n for i in range(1, n): if ord(s[i]) > ord(f): idx = i break elif s[i] == f: temp = s + s q = 2 * n // i temp1 = (q + 1) * s[:i] if temp1 < temp: idx = i break sn = s[0:idx] n = le...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR ...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
import sys n, k = map(int, sys.stdin.readline().split()) data = sys.stdin.readline().rstrip() left, right = 0, 0 for i in range(1, len(data)): if data[left] > data[i]: left = 0 right = i elif data[left] == data[i]: left += 1 else: break ans = data[: right + 1] while len(ans)...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VA...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split()) def get_pref(pref, k): while len(pref) < k: pref += pref return pref[:k] string = input() mn = get_pref(string[0], k) for i in range(1, len(string)): if string[0] < string[i]: break mn = min(mn, get_pref(string[: i + 1], k)) print(mn)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = map(int, input().split(" ")) s = input() best_ss = s + s for r in range(n - 1, 0, -1): ss = s[:r] * (2 * n // r + 1) if ss <= best_ss: best_ss = ss while len(best_ss) < k: best_ss += best_ss print(best_ss[:k])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR V...
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved. You have a string $s$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $s:=s+s$, where $+$ de...
n, k = list(map(int, input().split())) s = input() pos = [] for i in range(1, n + 1): pos.append((s[:i] * (k // i + 100))[:k]) print(sorted(pos)[0])
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
This is a harder version of the problem with bigger constraints. Korney Korneevich dag up an array a of length n. Korney Korneevich has recently read about the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR), so he wished to experiment with it. For this purpose, he decided to find all inte...
MAX = 1 << 13 n = int(input()) d = [MAX] * MAX d[0] = 0 flag = [0] * (MAX + 1) for _ in input().split(): a = int(_) if flag[a]: continue flag[a] = 1 for i in range(MAX): if d[i] < a: if d[i ^ a] > a: for j in range(a + 1, d[i ^ a] + 1): fla...
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR BIN...
This is a harder version of the problem with bigger constraints. Korney Korneevich dag up an array a of length n. Korney Korneevich has recently read about the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR), so he wished to experiment with it. For this purpose, he decided to find all inte...
import sys input = sys.stdin.readline mx = 1 << 13 n = int(input()) a = list(map(int, input().split())) g = [list() for _ in range(5001)] r = [5001] * mx r[0] = 0 ans = [False] * mx ans[0] = True for x in range(1, 5001): g[x].append(0) for i in range(n): for y in g[a[i]]: x = a[i] ^ y ans[x] = ...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER...
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer a_{i}Β β€” the current skill level. All skills have the same maximum level A. Along w...
f = lambda: list(map(int, input().split())) g = lambda: m - l * p[l - 1] + s[l] n, A, x, y, m = f() t = sorted((q, i) for i, q in enumerate(f())) p = [q for q, i in t] s = [0] * (n + 1) for j in range(n): s[j + 1] = p[j] + s[j] l = r = n F = L = R = B = -1 while 1: if p: while l > r or g() < 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBE...
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer a_{i}Β β€” the current skill level. All skills have the same maximum level A. Along w...
n, A, cf, cm, mN = map(int, input().split()) a = list(map(int, input().split())) aCOPY = [] for elem in a: aCOPY.append(elem) a.sort() aPartialSum = [0] for elem in a: aPartialSum.append(aPartialSum[-1] + elem) maxScore = 0 ansMAXIBound = 0 ansMAXI = 0 ansMIN = 0 for MAXI in range(n + 1): currentScore = cf ...
ASSIGN VAR VAR 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 VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER AS...
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai β€” the current skill level. All skills have the same maximum level A. Along with...
f = lambda: map(int, input().split()) g = lambda: m - l * p[l - 1] + s[l] n, A, x, y, m = f() t = sorted((q, i) for i, q in enumerate(f())) p = [q for q, i in t] s = [0] * (n + 1) for j in range(n): s[j + 1] = p[j] + s[j] l = r = n F = L = R = B = -1 while 1: if p: while l > r or g() < 0: l ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j. Tayuya wants to play a melody of n notes. Each note can be play...
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline A = list(map(int, input().split())) N = int(input()) B = list(map(int, input().split())) A.sort() B.sort() cnt = {i: (0) for i in range(N)} C = [] for i in range(N): for j in ra...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j. Tayuya wants to play a melody of n notes. Each note can be play...
ss = sorted(set(map(int, input().split()))) input() nn = sorted(set(map(int, input().split()))) if len(nn) == 1: print(0) elif len(ss) == 1: print(nn[-1] - nn[0]) else: n0 = nn[0] ans = int(1000000000.0) for s in ss: n0f = n0 - s lrs = [] for n in nn[1:]: l = r = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VA...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j. Tayuya wants to play a melody of n notes. Each note can be play...
import sys readline = sys.stdin.readline A = list(map(int, readline().split())) N = int(readline()) B = list(map(int, readline().split())) b0 = B[0] B = B[1:] INF = 3 * 10**9 if N == 1: print(0) else: ans = INF for a in A: S = b0 - a ev = [None] * N ev[-1] = S, S for i in ra...
IMPORT ASSIGN VAR VAR ASSIGN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NU...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
import sys def main(): a = [int(x) for x in input().split()] n = int(input()) b = [int(x) for x in input().split()] fretsAndNoteNo = [] for base in a: for noteNo, note in enumerate(b): fret = note - base fretsAndNoteNo.append((fret, noteNo)) fretsAndNoteNo.sort(...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
a = list(map(int, input().split())) n = int(input()) s = list(map(int, input().split())) b = [] i = 0 j = 0 ans = 10**18 cs = [0] * n nz = 1 z = n * 6 for y in range(n): for x in a: b.append((s[y] - x) * n + y) b.sort() cs[b[0] % n] += 1 while j + 1 < z: while j + 1 < z and nz < n: j += 1 ...
ASSIGN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR ...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
from sys import stdin a = list(map(int, stdin.readline().split())) a.sort(reverse=True) n = int(stdin.readline()) res = [] b = list(map(int, stdin.readline().split())) for i in range(n): bi = b[i] for ai in a: res.append((bi - ai, i)) res.sort() cnt = [0] * n r = 0 c = 0 ans = int(1e18) for l in range(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
la = input().split() la = list(map(int, la)) t = input() lb = input().split() lb = list(map(int, lb)) lenb = len(lb) l = [(lb[j] - i, j) for i in la for j in range(lenb)] l.sort() last = 0 first = 0 l0 = [0] * lenb l1 = [i for i in range(lenb)] dic = dict(zip(l1, l0)) dic[l[first][1]] += 1 length = 1 lenl = len(l) whil...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER A...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
import sys input = sys.stdin.readline mod = 10**9 + 7 INF = float("inf") def getlist(): return list(map(int, input().split())) def main(): A = getlist() N = int(input()) B = getlist() T = [] check = [0] * N cnt = 0 for i in A: for j, b in enumerate(B): T.append((...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
import sys def techno_c(): a = list(set(map(int, sys.stdin.readline().split()))) n = int(sys.stdin.readline()) b = list(set(map(int, sys.stdin.readline().split()))) n = len(b) m = len(a) raz = [] for j in range(m): for i in range(n): raz.append([b[i] - a[j], i]) raz...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL 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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
import sys as _sys from itertools import chain as _chain def main(): a_seq = tuple(_read_ints()) (n,) = _read_ints() notes = tuple(_read_ints()) result = find_minimal_melody_difficulty(a_seq, notes) print(result) def find_minimal_melody_difficulty(strings_values, notes): strings_values = set...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL V...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
import sys input = sys.stdin.readline def getInts(): return [int(s) for s in input().strip().split()] def getInt(): return int(input().strip()) def solve(): A = getInts() M = getInt() B = getInts() X = [] P = [] for i, b in enumerate(B): for a in A: P.append((b...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
a = list(map(int, input().split())) n = int(input()) s = list(map(int, input().split())) b = [] for i in range(n): for j in a: b.append((s[i] - j) * n + i) b = sorted(b) cs = {} i = j = 0 ans = 10**18 cs[b[0] % n] = cs.get(b[0] % n, 0) + 1 z = len(b) while j < z: while j + 1 < z and len(cs) < n: ...
ASSIGN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSI...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
a = list(map(int, input().split())) n = int(input()) s = list(map(int, input().split())) b = [] for i in range(n): for j in a: b.append((s[i] - j) * n + i) b.sort() cs = {} i = j = 0 ans = 10**18 def dd(w): cs[w] = cs.get(w, 0) + 1 def em(w): cs[w] -= 1 if cs[w] == 0: cs.pop(w) dd(...
ASSIGN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DIC...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
arr = [int(x) for x in input().split()] arr = list(set(arr)) n = int(input()) b = [int(x) for x in input().split()] temp = [] b = list(set(b)) n = len(b) for i in range(n): for j in arr: temp.append((b[i] - j, i)) temp.sort() start, end = 0, 0 l = len(temp) curr = 0 ans = 10000000000000 d = [(0) for i in ra...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VA...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
from sys import stdin input = stdin.readline a = sorted([int(i) for i in input().split()]) n = int(input()) b = sorted([int(i) for i in input().split()]) c = [] for i in range(n): c += [[b[i] - a[j], i] for j in range(6)] c.sort() d = [0] * n e = 0 ans = 10**10 u = 0 for i in range(len(c)): while u < len(c) an...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR AS...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has $6$ strings and an infinite number of frets numbered from $1$. Fretting the fret number $j$ on the $i$-th string produces the note $a_{i} + j$. Tayuya wants to play a melody of $n$ notes. Each note...
a = list(map(int, input().split())) n = int(input()) notes = list(map(int, input().split())) s, used = [], [(0) for i in range(n * 6)] for i in range(n): for j in a: s.append((notes[i] - j, i)) l, res, cnt = 0, 10**20, 0 s.sort() for r in range(len(s)): used[s[r][1]] += 1 if used[s[r][1]] == 1: ...
ASSIGN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSI...
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec...
def main(): n, a, b, t = map(int, input().split()) oris = input() def get_time(front, rear, count_rot): span = front - rear offset = min(front, -rear) return span, span * a + (span + 1) + offset * a + count_rot * b front = rear = span = count_rot = new_count_rot = time = 0 ...
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FO...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
def solve(k, s): c = 0 zeros = map(len, s.split("1")) if k > 0: zeros = list(zeros) l = len(zeros) for i in range(l - k + 1): if i + k >= l: continue head, tail = zeros[i], zeros[i + k] c += (head + 1) * (tail + 1) return c ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VA...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) a = [int(i) for i in input()] n = len(a) if k: b = [0] * n c = 0 for i in range(1, n): if a[i - 1] == 0: b[i] = i - c elif a[i] == 0: c = i i, j, d, e = 0, -1, 0, 0 while i < n and j < n: if d <= k: if d == k: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() n = len(s) count = [0] * (n + 1) count[0] += 1 ini = 0 if k == 0: ans = 0 ini = 0 s = s + "1" for i in range(n + 1): if s[i] == "1": ans = ans + ini * (ini + 1) // 2 ini = 0 else: ini += 1 print(ans) else: for i in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() prefix = [(0) for i in range(len(s) + 1)] for i in range(0, len(s)): prefix[i + 1] = int(int(s[i]) - int("0")) + prefix[i] ans = 0 mp = {} mp[k] = 1 for i in range(0, len(s)): if prefix[i + 1] in mp.keys(): ans += mp[prefix[i + 1]] if k + prefix[i + 1] in mp.keys(): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
n = int(input()) s = input() a = [(len(x) + 1) for x in s.split("1")] if n == 0: print(sum(x * (x - 1) // 2 for x in a)) else: print(sum(a * b for a, b in zip(a, a[n:])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() cs = [0] * 1000001 arr = [0] * 1000001 arr[0] = 1 cnt = 0 for i in range(len(s)): cs[i + 1] = cs[i] + int(s[i]) for i in range(1, len(s) + 1): cnt += arr[cs[i] - k] arr[cs[i]] += 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() ans, z = 0, 0 dp = [1] + [0] * 10**6 for c in s: if c == "1": z += 1 if z >= k: ans += dp[z - k] dp[z] += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
import sys input = sys.stdin.readline k = int(input()) s = input()[:-1] if k == 0: ans = 0 cnt = 1 for i in range(len(s) - 1): if s[i] == s[i + 1]: cnt += 1 else: if s[i] == "0": ans += cnt * (cnt + 1) // 2 cnt = 1 if s[-1] == "0": ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUM...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = list(map(int, input())) co = list() c = 1 for el in s: if el == 0: c += 1 else: co.append(c) c = 1 co.append(c) if k == 0: print(sum(map(lambda el: el * (el - 1) // 2, co))) exit() ans = 0 for i in range(len(co) - k): ans += co[i] * co[i + k] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR B...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
def fun(k, s): le = len(s) lis = list(s) l = 0 r = 1 ans = [] j = le - 1 number_of_one = 0 count = 0 arr = [] zeros = 0 for i in range(le): if lis[i] == "1": arr.append(zeros) zeros = 0 else: zeros += 1 arr.append(zeros)...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR F...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() a = [] p = 1 otv = 0 f = 0 for i in s: if i == "1": a.append(p) p = 1 if i == "0": p += 1 a.append(p) if k != 0: for i in range(len(a) - k): otv += a[i] * a[i + k] print(otv) else: for i in range(len(a)): otv += (a[i] - 1) / 2.0 * ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BI...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) a = [0] + list(map(int, input())) n = len(a) curr = sol = 0 c = {(0): 1} for i in range(1, n): curr += a[i] sol += c.get(curr - k, 0) c[curr] = c.get(curr, 0) + 1 print(sol)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() ind, ans = [], 0 for i in range(len(s)): if s[i] == "1": ind.append(i) if k > len(ind): print(0) exit() if k == 0: if len(ind) == 0: ans = len(s) * (len(s) + 1) // 2 else: for i in range(1, len(ind)): ans += (ind[i] - ind[i - 1]) * (in...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL V...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() n = len(s) ans = 0 cnt = 0 freq = [0] * (n + 1) freq[0] = 1 for i in range(n): if s[i] == "1": cnt += 1 if cnt - k >= 0: ans += freq[cnt - k] freq[cnt] += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k, s = int(input()), input() ans, t = 0, 0 cnt = list(map(lambda x: 0, range(1200000))) cnt[0] = 1 for c in s: if c == "1": t += 1 if t - k >= 0: ans += cnt[t - k] cnt[t] += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
p = 0 g = -1 k = int(input()) s = input() n = len(s) a = [0] * (n + 1) for i in range(n): if s[i] == "1": a[p] = i - g g = i p += 1 a[p] = n - g su = 0 if k == 0: for i in range(p + 1): su += a[i] * (a[i] - 1) // 2 else: for i in range(p - k + 1): su += a[i] * a[i + k...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NU...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
K = int(input()) S = input() L = [0] * (len(S) + 1) L[0] = 1 X = Y = 0 for i in S: if i == "1": Y += 1 if Y >= K: X += L[Y - K] L[Y] += 1 print(X)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() cnt = 0 dp = [(0) for i in range(len(s))] d = {} for i in range(len(s)): if s[i] == "1": dp[i] = dp[i - 1] + 1 else: dp[i] = dp[i - 1] if dp[i] == k: cnt = cnt + 1 if dp[i] - k in d: cnt = cnt + d[dp[i] - k] if dp[i] not in d: d[dp...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN ...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() n = len(s) l = [] cnt = 0 for i in range(n): if s[i] == "1": l.append(cnt) cnt = 0 else: cnt += 1 l.append(cnt) ans = 0 for i in range(len(l)): if i + k < len(l) and k > 0: ans += (l[i] + 1) * (l[i + k] + 1) elif i + k < len(l): ans +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VA...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() total = 0 counter = 0 zeroes = [0] * (len(s) + 100) for c in s: if c == "0": zeroes[counter] += 1 elif c == "1": counter += 1 for t in range(counter + 1): if t >= k: if k == 0: total += zeroes[t] * (zeroes[t] + 1) // 2 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR NUMBER IF VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR B...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) string = input() count = 0 modified_string = [] i = 0 n = len(string) while i < n: if string[i] == "0": count += 1 else: modified_string.append(count) count = 0 if i == n - 1: modified_string.append(count) i += 1 i = 0 ans = 0 n = len(modified_string) if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUM...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) st = str(input()) s = list(map(int, list(st))) n = len(s) if k == 0: total = 0 st = st.split("1") for seg in st: if "0" in seg: leng = len(seg) total += leng * (leng + 1) // 2 print(total) if k != 0: prefix = [(0) for i in range(n + 1)] suma = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR ...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) d = [0] * 2000000 d[0] = 1 s = 0 for c in input(): s += int(c) d[s] += 1 res = 0 for i in range(k, s + 1): if k == 0: res += (d[i] - 1) * d[i] // 2 else: res += d[i] * d[i - k] print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP ...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() s = "1" + s + "1" one = [i for i in range(len(s)) if s[i] == "1"] total = 0 if k == 0: total = sum((len(seg) + 1) * len(seg) // 2 for seg in s.split("1")) else: for i in range(k, len(one) - 1): total += (one[i - k + 1] - one[i - k]) * (one[i + 1] - one[i]) print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR S...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
K = int(input()) s = input() N = len(s) res = 0 countOfOne = 0 freq = [(0) for i in range(N + 1)] freq[0] = 1 for i in range(0, N, 1): countOfOne += ord(s[i]) - ord("0") if countOfOne >= K: res += freq[countOfOne - K] freq[countOfOne] += 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR VAR VAR...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
def readln(): return tuple(map(int, input().split())) (k,) = readln() inp = "#" + input() n = len(inp) pref = [0] * n for i in range(1, n): pref[i] = pref[i - 1] + (inp[i] == "1") cnt = [0] * (pref[n - 1] + 1) for v in pref: cnt[v] += 1 ans = 0 for i in range(pref[n - 1] - k + 1): ans += cnt[i] * cnt[...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP LIST NUMBER...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() pref = [0] for i in s: pref.append(pref[-1] + int(i)) d = {} ans = 0 for i in pref: ans += d.get(i - k, 0) d[i] = d.get(i, 0) + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
n = int(input()) S = input() a = [(len(x) + 1) for x in S.split("1")] if n == 0: k = 0 for x in a: k += int(x / 2 * (x - 1)) print(k) else: k = 0 for i in range(len(a) - n): k += a[i] * a[i + n] print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() l = [0] * len(s) r = [0] * len(s) one = [] ze = 0 specialCase = 0 for i in range(0, len(s)): if s[i] == "0": ze += 1 else: l[i] = ze specialCase += ze * (ze + 1) // 2 one.append(i) ze = 0 specialCase += ze * (ze + 1) // 2 ze = 0 for i in range...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP BI...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
n = int(input()) s = input() zero = [] num = 0 for i in range(len(s)): if s[i] == "1": zero.append(num) num = 0 else: num += 1 zero.append(num) ans = 0 if n == 0: for i in range(len(zero)): ans += zero[i] * (zero[i] + 1) // 2 else: for i in range(len(zero) - n): a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = list(map(int, list(input()))) n = len(s) dp = [(0) for i in range(n + 1)] dp[0] = 1 ans = 0 numOne = 0 for i in range(n): if s[i] == 1: numOne += 1 if numOne >= k: ans += dp[numOne - k] dp[numOne] += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
def main(): k, s, res = int(input()), input(), 0 if k: l = [i for i, c in enumerate(s) if c == "1"] if len(l) >= k: l.append(len(s)) a, c = -1, l[k - 1] for b, d in zip(l, l[k:]): res += (b - a) * (d - c) a, c = b, d else: ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() n = len(s) a = [0] * n dict = {} count = 0 for i in range(n): if s[i] == "1": count += 1 if count in dict: dict[count] += 1 else: dict[count] = 1 ans = 0 count = 0 for i in range(n): if k in dict: ans += dict[k] if s[i] == "1": k +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = str(input()) n = len(s) x = 0 y = 1 lis = [0] a = 0 if k == 0: a = 0 ans = 0 for i in range(n): if s[i] == "0": a += 1 else: if a > 0: ans += a * (a + 1) // 2 a = 0 if a > 0: ans += a * (a + 1) // 2 prin...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() n = len(s) if s.count("1") < k: print(0) exit(0) if k == 0: ans = 0 ct = 0 for j in range(n): if s[j] == "0": ct += 1 if s[j] == "1" or j == n - 1: ans += ct * (ct + 1) // 2 ct = 0 else: i, j, ct = 0, 0, 0 for j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER VA...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) st = input() s = {(0): 1} n, a = 0, 0 for c in st: v = int(c) n += v a += s.get(n - k, 0) s[n] = 1 + s.get(n, 0) print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() ar = [0] n = len(s) def get(i): if i < len(ar) and i > -1: return ar[i] + 1 return 1 if s[0] == "0": ar[-1] += 1 for i in range(1, n): if s[i] == "0": if ar[-1] == 0: ar += [1] else: ar[-1] += 1 else: ar += [0] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER STRING VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF VAR NUMBER NUMBER VAR L...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() cnt = [0] * (len(s) + 1) for i in range(len(s)): cnt[i + 1] = cnt[i] + int(s[i] == "1") res = 0 summ = [1] + [0] * (len(s) + 1) for i in range(len(s)): if cnt[i + 1] - k >= 0: res += summ[cnt[i + 1] - k] summ[cnt[i + 1]] += 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP FUNC_CA...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = [*map(len, input().split("1"))] res = 0 if k == 0: for i, x in enumerate(s): res += x * (x + 1) // 2 else: for i, x in enumerate(s[k:]): res += (s[i] + 1) * (x + 1) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() j = 0 ans = 0 next_j = 0 cnt_ones = 0 for i in range(len(s)): if j <= i: j = i + 1 cnt_ones += 1 if s[i] == "1" else 0 if cnt_ones < k or j <= i: while j < len(s) and cnt_ones < k: if s[j] == "1": cnt_ones += 1 j += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR STRING NUMBER NUMBER IF VAR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRIN...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) num = input() if k == 0: c = 0 ans = 0 for i in range(len(num)): if num[i] == "0": c += 1 else: ans += c * (c + 1) // 2 c = 0 ans += c * (c + 1) // 2 else: inds = [-1] for i in range(len(num)): if num[i] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER FO...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
import sys input = sys.stdin.readline a = int(input()) s = input() ans = [] count = 0 for i in range(len(s)): if s[i] == "0": count += 1 else: ans.append(count) count = 0 ans.append(count) if a == 0: total = 0 for i in range(len(ans) - 1): r = ans[i] total = tota...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_C...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() n = len(s) p = [0] * (n + 1) for i in range(1, n + 1): p[i] = p[i - 1] + (ord(s[i - 1]) - ord("0")) b = 0 r = 0 ans = 0 for i in range(1, n + 1): if p[i] - p[b] > k: while p[i] - p[b] > k: b += 1 if k == 0: if p[i] - p[b] == k: ans += i - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() a = [0] for i in range(len(s)): if s[i] == "1": a.append(i + 1) a.append(len(s) + 1) if len(a) - 2 < k: print(0) elif k == 0: ct = 0 for i in range(1, len(a)): ct += (a[i] - a[i - 1] - 1) * (a[i] - a[i - 1]) // 2 print(ct) else: l = 0 r = k + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN V...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k, s, v = int(input()), input(), 0 n, p1 = len(s), [-1] + [i for i, ch in enumerate(s) if ch == "1"] p1.append(n) if k == 0: for i in range(len(p1) - 1): m = p1[i + 1] - p1[i] - 1 v += m * (m + 1) // 2 else: for i in range(k, len(p1) - 1): v += (p1[i - k + 1] - p1[i - k]) * (p1[i + 1] - ...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BI...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
def f(n): return n * (n + 1) // 2 k = int(input()) s = input() l = [] for i in range(len(s)): if s[i] == "1": l.append(i) n = len(l) ans = 0 if k == 0: if n == 0: ans = f(len(s)) else: ans += f(l[0]) for i in range(1, n): z = l[i] - l[i - 1] - 1 ...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k = int(input()) s = input() dp = [(0) for i in range(len(s) + 1)] dp[0] = 1 c = 0 n = 0 for i, v in enumerate(s, 1): c += int(v) if c - k >= 0: n += dp[c - k] dp[c] += 1 print(n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR ...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
k, s, ones = int(input()), input(), [-1] for i, ch in enumerate(s): if ch == "1": ones.append(i) ones.append(len(s)) n = 0 if k == 0: for a1, a2 in zip(ones, ones[1:]): n += (a2 - a1) * (a2 - a1 - 1) // 2 else: for a1, a2, a3, a4 in zip(ones, ones[1:], ones[k:], ones[k + 1 :]): n += ...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER F...