description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
t = int(input()) for i in range(t): n, k = map(int, input().split()) st = input() minsum = 11 * st.count("1") if minsum == 0: print(0) continue ones = st.count("1") first = st.index("1") last = st[::-1].index("1") if last <= k: k -= last minsum -= 10 i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VA...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
for _ in [0] * int(input()): n, k = map(int, input().split()) s = input() one = s.count("1") if one == 0: print(0) continue if one == 1: for i in range(n): if s[i] == "1": index = i break if n - 1 - index <= k: p...
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR EX...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
num = int(input()) def counter(array): res = 0 for i in range(len(array) - 1): res += array[i] * 10 + array[i + 1] return res for _ in range(num): n, k = map(int, input().split()) array = list(map(int, list(input()))) answer = counter(array) if k > 0: if array[n - 1] == 0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CAL...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
import sys def f(s): c = 0 for i in range(len(s) - 1): c += int(str(s[i]) + str(s[i + 1])) return c def aux(n, k, s): i = n - 1 while i >= 0 and s[i] != 1: i -= 1 if i < 0: return 0 elif i == 0: if k >= n - 1: s[i], s[-1] = s[-1], s[i] ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR BIN_OP V...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
import sys input = sys.stdin.readline for _ in range(int(input())): n, k = map(int, input().split()) s = input() count1 = 0 for i in range(n): if s[i] == "1": count1 += 1 r = i if count1 == 1: l = i if not count1: print(0) ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_O...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
for _ in range(int(input())): n, k = map(int, input().split()) a = input() p1, p2, ans = -1, -1, 0 for i in range(n): if a[i] == "1": ans += 11 p2 = i if p1 == -1: p1 = i if p2 == -1: print(ans) continue if k >= n - 1 - ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_O...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) mas = list(input()) d = dict() d["1"] = [] d["0"] = [] for i in range(n): d[mas[i]].append(i) if len(d["1"]) == 0: print(0) elif len(d["1"]) == 1: ans = 11 index = d["1"][0] if n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING LIST ASSIGN VAR STRING LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR STRING NUM...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() count = 0 for i in s[::-1]: if i == "0": count += 1 else: break count_end = count count = 0 for i in s: if i == "0": count += 1 else: bre...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
def evaluateStr(): n, swaps = map(int, input().split()) s = str(input()) closest_front = closest_back = dist_front = dist_back = -1 ones_count = 0 flag = False for i in range(n): if s[i] == "1": ones_count += 1 closest_back = i if not flag: ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() b = s.find("1") e = n - s.rfind("1") - 1 c = s.count("1") ans = c * 11 if e <= k: ans -= 10 k -= e if c != 1 and b <= k: ans -= 1 elif b <= k: ans -= 1 if c: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR IF VAR N...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
for _ in range(int(input())): n, k = map(int, input().split()) a = input() if "1" in a: can = 1 ans = a.count("1") * 11 if a[::-1].index("1") <= k: k -= a[::-1].index("1") ans -= 10 if a.count("1") == 1: can = 0 if a.index("...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR NUMBER STRING VAR VAR FUNC_CALL VAR NUMBER STRING VAR NUMBER IF FUNC_CALL VAR STRING NUMBER A...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
T = int(input()) while T: T -= 1 n, k = [int(x) for x in input().split(" ")] a = list(input()) l = -1 c = -1 cnt = 0 for i in range(len(a)): if a[i] == "0": continue c = i cnt += 1 if l == -1: l = i r = c if l == -1 and r == -1:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER A...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
def solve(): n, k = map(int, input().split()) inp = input() ones = inp.count("1") if ones == 0: return 0 front = inp.find("1") end = inp[::-1].find("1") if ones == 1: if k >= end: return 1 if k >= front: return 10 return 11 inp = li...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER STRING IF VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
t = int(input()) for c in range(t): n, k = input().split() n, k = int(n), int(k) s = input() first, last = -1, -1 sum = 0 for i in range(n): if s[i] == "1": sum += 11 if first < 0: first = i last = i if sum: lswp = n - last ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VA...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
def spliter(): d = input() a = d.split() r = [] for i in a: k = int(i) r.append(k) return r _t = int(input()) for _ in range(_t): n = spliter() a = input() count1 = -1 count2 = -1 count3 = 0 for i in range(n[0]): if a[i] == "1": if count3...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER F...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
t = int(input()) for _ in range(t): n, x = map(int, input().split()) s = list(input()) ones, leftmost, rightmost = 0, n, -1 for i in range(n): if s[i] == "1": ones += 1 if leftmost == n: leftmost = i rightmost = i ans = 0 if ones > 0 an...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR N...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
def func(s): ans = 0 for i in range(len(s) - 1): ans += int(s[i : i + 2]) return ans t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = input() lone = 0 rone = 0 for i in range(n): if s[i] == "1": lone = i break for i in...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER F...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
from sys import stdin def input(): return stdin.readline().strip() def read_int(): return int(input()) def read_ints(): return map(int, input().split()) t = read_int() for case_num in range(t): n, k = read_ints() s = input() m = s.count("1") if m == 0: print(0) elif m == ...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER I...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
i = input() for a in range(0, int(i)): [n, k] = [int(x) for x in input().split()] s = input() num = s.count("1") score = num * 11 if num == 0: print(0) elif num == 1: p = s.index("1") if n - 1 - p <= k: print(1) elif p <= k: print(10) ...
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP ...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
import sys input = sys.stdin.readline def solve(): n, k = map(int, input().split()) s = input().strip() cnt = 0 f = n + 1 b = -1 for i in range(n): if s[i] == "1": cnt += 1 f = min(f, i) b = max(b, i) if cnt == 0: return 0 op1, op2 =...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMB...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
T = int(input()) q = [] for i in range(T): a = input().split() n, k = int(a[0]), int(a[1]) ins = input() data = [] for i in ins: data.append(i) q.append((n, k, data)) def solve(n, k, data): first_one = -1 last_one = -1 for idx, c in enumerate(data): if c == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIG...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
for _ in range(int(input())): n, k = list(map(int, input().split())) s = list(input()) answ = 0 i = n - 1 while i >= 0 and s[i] != "1": i -= 1 if i == -1: print(0) continue if n - i - 1 <= k: k -= n - i - 1 s[i], s[-1] = s[-1], s[i] i = 0 while...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBE...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input())) i = 0 j = n - 1 while j >= 0: if l[j] == 0: pass else: if k >= n - 1 - j: k -= n - 1 - j l[j] = 0 l[-1] = 1 b...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIG...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
for _ in range(int(input())): n, k = map(int, input().split()) s = list(input()) one = 0 b = n e = 0 for i in range(n): if s[i] == "1": one += 1 if b == n: b = i e = i offset = 0 if one > 0 and n - 1 - e <= k: one -= 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NU...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
t = int(input()) for i in range(t): n, k = map(int, input().split()) a = input() sh = 0 pe = 0 p = 0 for j in range(n): if a[j] == "1": sh += 1 if sh == 1: pe = j p = j else: p = j minus = 0 if sh...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIG...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
def solve(): n, k = map(int, input().split()) s = input() mone = s.count("1") ls = s.find("1") rs = n - s.rfind("1") - 1 ans = mone * 11 if rs <= k: ans -= 10 k -= rs if mone != 1 and ls <= k: ans -= 1 elif ls <= k: ans -= 1 if mone: ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR N...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
T = int(input()) for case in range(T): n, k = map(int, input().split()) s = input() if "1" not in s: print(0) continue ans = 0 for i in range(n - 1): ans += int(s[i : i + 2]) l, r = s.find("1"), s.rfind("1") if 0 < n - 1 - r <= k: if r == 0: ans -=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ST...
You are given a binary string $s$ of length $n$. Let's define $d_i$ as the number whose decimal representation is $s_i s_{i+1}$ (possibly, with a leading zero). We define $f(s)$ to be the sum of all the valid $d_i$. In other words, $f(s) = \sum\limits_{i=1}^{n-1} d_i$. For example, for the string $s = 1011$: $d_1 = ...
t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] s = input() p = s.count("1") if p == 0: print(0) continue l = s.find("1") f = n - s.rfind("1") - 1 if p == 1: if f < k + 1: print(1) elif l < k + 1: print(10) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING NUMBER IF VAR N...
Currently, XXOC's rap is a string consisting of zeroes, ones, and question marks. Unfortunately, haters gonna hate. They will write $x$ angry comments for every occurrence of subsequence 01 and $y$ angry comments for every occurrence of subsequence 10. You should replace all the question marks with 0 or 1 in such a way...
import sys input = sys.stdin.readline def solve(s, x, y): c0 = 0 c1 = 0 r = 0 for i in s: if i == "0": c0 += 1 else: r += c0 * x c1 += 1 z0 = 0 for i in range(len(s) - 1, -1, -1): if s[i] == "0": z0 += 1 else: ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER A...
Currently, XXOC's rap is a string consisting of zeroes, ones, and question marks. Unfortunately, haters gonna hate. They will write $x$ angry comments for every occurrence of subsequence 01 and $y$ angry comments for every occurrence of subsequence 10. You should replace all the question marks with 0 or 1 in such a way...
def Kurisu_delta(v, y_01, x_10): c_x = [0] * len(v) one = 0 two = 0 q = 0 for i in range(len(v)): i = len(v) - i - 1 c_x[i] = [one, two] if v[i] == "1": one += 1 q += c_x[i][1] * x_10 elif v[i] == "0": two += 1 q += c_x[...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER...
Currently, XXOC's rap is a string consisting of zeroes, ones, and question marks. Unfortunately, haters gonna hate. They will write $x$ angry comments for every occurrence of subsequence 01 and $y$ angry comments for every occurrence of subsequence 10. You should replace all the question marks with 0 or 1 in such a way...
s = input() x, y = map(int, input().split()) if x > y: x, y = y, x s = s.replace("1", "#").replace("0", "1").replace("#", "0") assert x <= y z = y - x s_if_all_ones = s.replace("?", "1") ones_before = 0 zeros_before = 0 result = 0 for char in s_if_all_ones: if char == "0": result += ones_before * y ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING STRING VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN V...
Currently, XXOC's rap is a string consisting of zeroes, ones, and question marks. Unfortunately, haters gonna hate. They will write $x$ angry comments for every occurrence of subsequence 01 and $y$ angry comments for every occurrence of subsequence 10. You should replace all the question marks with 0 or 1 in such a way...
s = list(input()) y, k = map(lambda x: int(x), input().split()) def Kurisu(v, y_01, x_10): c_x = [0] * len(v) one, two = 0, 0 q = 0 for i in range(len(v)): i = len(v) - i - 1 c_x[i] = [one, two] if v[i] == "1" or y_01 <= x_10 and v[i] == "?": one += 1 q ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR V...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
ts, tf, t = map(int, input().split()) n = int(input()) INF = int(10**18) if n == 0: print(ts) quit() a = list(map(int, input().split())) i = 0 ans = -1 best = INF end = ts dif = 0 def checkans(curans, time): global ans, best if curans < best and time + max(curans, 0) + t <= tf: ans = time ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
[ts, tf, t] = list(map(int, input().split())) n = int(input()) if n == 0: print(ts) exit(0) a = list(map(int, input().split())) if a[0] > ts: print(ts) exit(0) min_wait = 1e18 tbest = a[0] - 1 tnow = ts twait = tnow - tbest min_wait = min(min_wait, twait) i = 0 while i < n: tnow = max(tnow, a[i]) ...
ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSI...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
begin, end, time = list(map(int, input().split())) n = int(input()) if n == 1: print(begin) elif n > 0: ar = list(map(int, input().split())) ar.sort() i = 0 ar.append(end - time + 1) n += 1 num = begin ans = begin - ar[0] + 1 fin_ans = ar[0] - 1 while i < n: num = max(num...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
s, e, t_per_v = list(map(int, input().split())) e -= t_per_v n = int(input()) if n > 0: visitors = list(map(int, input().split())) else: visitors = [] min_wait_time = float("inf") min_arrive_time = -1 visitor_index = 0 t = s while t <= e: if visitor_index >= len(visitors) or visitors[visitor_index] > t: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF V...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
from sys import stdin lines = stdin.readlines() current_free, f, t = map(int, lines[0].split()) n = int(lines[1]) arrival_times = [] if n > 0: arrival_times = list(map(int, lines[2].split())) min_wait = f min_arrival = -1 current_free def check_arrival_at(arrival): global min_arrival global min_wait ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR VAR FUNC_DEF IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
def ri(): return map(int, input().split()) s, f, t = ri() n = int(input()) if n == 0: print(s) exit() i = list(ri()) p = 0 a = s m = 10**100 for ii in i: if ii <= f - t: if a - ii + 1 < m: m = a - ii + 1 p = min(ii - 1, a) a = max(a, ii) + t if a <= f - t: p...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR BIN_OP VAR ...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
ts, tf, t = map(int, input().split()) n = int(input()) if n == 0: print(ts) exit() vis = list(map(int, input().split())) ans = min(vis[0] - 1, ts) wt = ts - ans cur = max(vis[0], ts) for i in range(1, n): if vis[i] == vis[i - 1]: cur += t elif cur + t + t <= tf: if wt > cur + t - (vis[i]...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_C...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
import sys t1, t2, t = map(int, input().split()) u = 1 n = int(input()) if n == 0: print(t1) sys.exit() a = [int(i) for i in input().split()] mini = 10**20 ans = 0 time = t1 for x in a: if x <= t2 - t: if time - x + 1 < mini and x > 0: mini = time - x + 1 if x - 1 > time: ...
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF VA...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
import sys def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None def solve(): ts, tf, t = map(int, input().split()) n = int(input()) if n == 0: print(ts) return None ...
IMPORT FUNC_DEF FOR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_C...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
a, b, c = map(int, input().split()) n = int(input()) if n == 0: print(a) exit() arr = [int(i) for i in input().split()] p, m = 0, int(1e18) for i in arr: if i <= b - c: if i > 0 and a - i + 1 < m: m = a - i + 1 p = min(i - 1, a) a = max(a, i) + c print(a if a <= b - c...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP BIN_OP VA...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
ts, tf, t = map(int, input().split()) n = int(input()) visitors = list(map(int, input().split())) if n else [] finish = [ts] for visitor in visitors: finish.append(max(finish[-1], visitor) + t) res = 0 min_time = 10**13 for i in range(n): if finish[i] + t >= tf: continue if visitors[i] == 0: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST ASSIGN VAR LIST VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
f = lambda: map(int, input().split()) a, b, t = f() (k,) = f() s = d = 1000000000000.0 for q in f() if k else []: if q > a: s = a if q > a or a + t > b: break elif a - q < d: s, d = q - 1, a - q a += t print(s if a + t > b else a)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR LIST IF VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
INF = 10**19 ts, tf, t = map(int, input().split()) n = int(input()) u = [] if n > 0: u = list(map(int, input().split())) a = [] b = [] i = 0 while i < n: a.append(u[i]) if i == 0: start = max(ts, u[i]) else: start = max(b[-1], a[-1]) ng = 1 while i + 1 < n and u[i] == u[i + 1]: ...
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR ...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
def main(): start, end, t = map(int, input().split()) n = int(input()) people = [] if n != 0: people = list(map(int, input().split())) time = start ans = 1e16 answer = 0 for p in people: if p + t > end: break if p - 1 >= 0: if ans > max(0, ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER I...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
inp = input().split(" ") ts = int(inp[0]) tf = int(inp[1]) T = int(inp[2]) inp = input() n = int(inp) if n == 0: print(ts) else: inp = input().split(" ") min_del_t = 10000000000000 ans = int(inp[0]) - 1 t_cur = ts for tS in inp: t = int(tS) time_waiting = t_cur - t + 1 if...
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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP F...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
ts, tf, te = map(int, input().split(" ")) n = int(input()) if n == 0: print(ts) exit(0) arr = list(map(int, input().split(" "))) idx = 0 curr_time = ts wait_time = max(0, ts - arr[0] + 1) ans = min(arr[0] - 1, ts) while wait_time > 0: curr_time += te idx += 1 if idx == n or curr_time >= tf: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_...
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
def update(t, l, ans): if l < ans[1]: ans[0] = t ans[1] = l def solve(): S, E, L = list(map(int, input().split())) n = int(input()) if n == 0: return S a = list(map(int, input().split()))[::-1] if S < a[-1]: return S ans = [0, S] cur_t = S while cur_...
FUNC_DEF IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER IF VAR VAR NUMBER RETURN VA...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for _ in range(int(input())): ans1, ans2 = 100000, 100000 n = int(input()) str1 = input() str2 = input() x, y, v01 = str1.count("1"), str2.count("1"), 0 for i in range(n): if str1[i] != str2[i]: v01 += 1 if x == y: ans1 = v01 if y == n - x + 1: ans2 = ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys t = int(sys.stdin.readline()) ans = [] for _ in range(t): n = int(sys.stdin.readline()) s1 = sys.stdin.readline().strip() s2 = sys.stdin.readline().strip() if s1 == s2: ans.append("0") continue elif len(s1) != len(s2) or s1.count("1") == 0: ans.append("-1") el...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for _ in range(int(input())): n = int(input()) a = list(map(int, input())) ans = float("+inf") b = list(map(int, input())) cr, cd = 0, 0 for i in range(n): if a[i] and not b[i]: cr += 1 elif b[i] and not a[i]: cd += 1 if cr == cd: ans = cr + cd...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def operation(a, b): c01, c10 = 0, 0 for i in range(len(a)): if a[i] == "1" and b[i] == "0": c10 += 1 elif a[i] == "0" and b[i] == "1": c01 += 1 if c10 != c01: return float("inf") return c10 + c01 def change(a, b, f): idx = -1 for i in range(len(...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR STRING RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys input = sys.stdin.readline for i in " " * int(input()): n = int(input()) s1 = input().strip() s2 = input().strip() k1 = s1.count("1") k2 = s2.count("1") if k1 != k2 and k1 + k2 != n + 1: print(-1) continue res = 10**9 if k1 == k2: ct = 0 for i ...
IMPORT ASSIGN VAR VAR FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIG...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def solve(): n = int(input()) a = input() b = input() x, y, z = 0, 0, 0 for i in range(n): if a[i] == "1": x += 1 if b[i] == "1": y += 1 if a[i] != b[i]: z += 1 if x == y: if n - x + 1 == y: return min(z, n - z) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN FUNC_CALL VAR ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys input = sys.stdin.readline t = int(input()) inf = pow(10, 6) + 1 for _ in range(t): n = int(input()) a = list(input().rstrip()) b = list(input().rstrip()) c = [0] * 4 for i in range(n): if a[i] == b[i] == "0": c[0] += 1 elif a[i] == b[i] == "1": c[...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VA...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
t = int(input()) for i in range(t): opp = True n = int(input()) a = [int(j) for j in list(input())] b = [int(j) for j in list(input())] ans = 0 if sum(a) == sum(b) and sum(a) == n - sum(b) + 1: for j in range(n): if b[j] == 1 and a[j] == 0: ans += 1 if...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR B...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def f(a, b): zo, oz = 0, 0 for x, y in zip(a, b): if a == "0" and b == "1": zo += 1 elif a == "1" and b == "0": oz += 1 return oz, zo for _ in range(int(input())): n = int(input()) s = input() desire = input() ones_d = desire.count("1") zeros_d =...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING VAR NUMBER IF VAR STRING VAR STRING VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL V...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
t = int(input()) for _ in range(t): n = int(input()) a = list(input()) b = list(input()) if a != b and (a.count("1") == 0 or a.count("1") != 0 and b.count("1") == 0): print(-1) elif a == b: print(0) else: count = 0 count11 = 0 count21 = 0 ans1 = 10...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR F...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
t = int(input()) for i in range(t): n = int(input()) a = input() b = input() uu = 0 ll = 0 ul = 0 lu = 0 for j in range(n): if a[j] == "1" and b[j] == "1": ll += 1 elif a[j] == "1" and b[j] == "0": lu += 1 elif a[j] == "0" and b[j] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VA...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
t = int(input()) for i in range(t): kifkif = 0 moch_kif = 0 nbr1_kif = 0 nbr1_moch = 0 n = int(input()) a = input() b = input() for j in range(len(a)): if a[j] == b[j]: kifkif += 1 if a[j] == "1": nbr1_kif += 1 elif a[j] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NU...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for t in range(int(input())): n = int(input()) a = input() b = input() _1_1 = _0_0 = _1_0 = _0_1 = 0 if a == b: print(0) elif int(b) == 0 or int(a) == 0: print(-1) else: for i, j in zip(a, b): if i == j: if i == "1": _1_...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR I...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for _ in range(int(input())): n = int(input()) a = input() b = input() counts = [0, 0, 0, 0] ones = [0, 0] for i in range(n): counts[int(a[i]) * 2 + int(b[i])] += 1 ones[0] += a[i] == "1" ones[1] += b[i] == "1" ops = 1000000000.0 if ones[0] == ones[1]: ops...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR N...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys def menorah(n, a, b): _01 = 0 _00 = 0 _10 = 0 _11 = 0 for i in range(n): if a[i] == "0": if b[i] == "0": _00 += 1 else: _01 += 1 elif b[i] == "1": _11 += 1 else: _10 += 1 best = f...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def f(a, b): if a == b: return 0 one = [] z = [] bigo = set() for id, i in enumerate(a): if i == "1": one.append(id) else: z.append(id) if b[id] == "1": bigo.add(id) cst11 = 0 cst12 = 0 if one == []: return -1 ...
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR LIST RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSI...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for _ in range(int(input())): n = int(input()) a = list(map(int, input())) b = list(map(int, input())) a1 = a.count(1) a0 = a.count(0) b1 = b.count(1) b0 = b.count(0) ans = 0 if a1 != b1 or a0 != b0: if a1 == 0: print(-1) continue j = a.index(1...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def checkeven(k, res): if k == res // 2: return True else: return False def checkodd(g, res): if g == (n - res) // 2 + 1: return True else: return False def find(a, b, n): if int(a) == 0 or int(b) == 0: if int(a) != 0 or int(b) != 0: return -1 ...
FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RET...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for _ in range(int(input())): n = int(input()) a = input() b = input() x = [0] * 4 for i in range(n): if a[i] == "1" and b[i] == "1": x[0] += 1 elif a[i] == "0" and b[i] == "0": x[1] += 1 elif a[i] == "1" and b[i] == "0": x[2] += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER NUMBER IF VAR VAR STRIN...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
problem_num = int(input()) for i in range(problem_num): n = int(input()) arr1 = input() arr2 = input() if arr2.count("1") not in [arr1.count("1"), n - arr1.count("1") + 1]: print(-1) continue same = 0 diff = 0 for j in range(len(arr1)): if arr1[j] == arr2[j]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING LIST FUNC_CALL VAR STRING BIN_OP BIN_OP VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for _ in range(int(input())): n = int(input()) a = input() b = input() r = a.count("1") l = a.count("0") rr = 0 ll = 0 for i in range(n): if a[i] != b[i]: if a[i] == "1": rr += 1 else: ll += 1 m = 0 if ll == rr: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUM...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for _ in range(int(input())): n = int(input()) a = input() b = input() x, x1, y, y1 = 0, 0, 0, 0 for i in range(n): if a[i] == b[i]: x += 1 if a[i] == "1": x1 += 1 else: y += 1 if a[i] == "1": y1 += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIG...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for _ in range(int(input())): n = int(input()) a = input() b = input() n1 = 0 for i in a: if i == "1": n1 += 1 n2 = 0 for i in b: if i == "1": n2 += 1 noc = 0 for i in range(n): if a[i] != b[i]: noc += 1 ans = 999999 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMB...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
maxx = 100000000 T = int(input()) for t in range(T): n = int(input()) a = input() b = input() a1 = a.count("1") b1 = b.count("1") diff = 0 for i in range(n): diff += a[i] != b[i] op1, op2 = maxx, maxx if a1 == b1: op1 = diff if a1 == n - b1 + 1: op2 = n - ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR V...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
from sys import stdin, stdout rd = lambda: list(map(int, stdin.readline().split())) rds = lambda: stdin.readline().rstrip() ii = lambda: int(stdin.readline()) INF = 1 << 62 mod = 10**9 + 7 for _ in range(ii()): n = ii() a = rds() b = rds() if a == b: print(0) continue d = 0 e1 =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def func(): n = int(input()) a = input() b = input() x = 0 y = 0 x1 = 0 y1 = 0 for i in range(n): if a[i] == b[i]: x += 1 if a[i] == "1": x1 += 1 else: y += 1 if a[i] == "1": y1 += 1 flg =...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def sumString(x): ans = 0 for i in x: ans += int(i) return ans def solve(a, b): if a == b: return 0 suma = sumString(a) sumb = sumString(b) if suma == 0 or sumb == 0: return -1 eveonOrOdd = [] evens = 0 odds = 0 zeroEvens = 0 oneEvens = 0 zer...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR ...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys input = sys.stdin.readline def solve(): n = int(input()) a = input().strip() b = input().strip() diff = cnt1 = cnt2 = 0 for i in range(n): cnt1 += int(a[i]) cnt2 += int(b[i]) diff += 1 if a[i] != b[i] else 0 ans = float("inf") if cnt1 == cnt2: an...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) s = input()[:-1] s2 = input()[:-1] pos1 = [0, 0] pos2 = [0, 0] comp = int(s2, 2) for i in range(len(s)): if s[i] != s2[i]: pos1[int(s[i])] += 1 else: pos2[int(s[i])] ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VA...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def operation(a, b): c1, c2 = 0, 0 for i, j in zip(a, b): if i != j: if i == "1": c1 += 1 else: c2 += 1 if c1 != c2: return float("inf") else: return 2 * c1 def change(a, b, f): idx = -1 for i in range(len(a)): ...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR STRING RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN FUNC...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
for i in range(int(input())): n = int(input()) a = input() b = input() x, y, z = 0, 0, 0 for i in range(n): if a[i] != b[i]: x += 1 if a[i] == "1": y += 1 if b[i] == "1": z += 1 if y == z: if n - y + 1 == z: print(mi...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
inf = 1000000000.0 t = int(input()) for u in range(t): n = int(input()) a = input() b = input() ok = False for i in range(n): if a[i] == "1": ok = True if ok == False and a != b: print(-1) continue ans = inf for i in range(2): cnt = [0, 0, 0, 0...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR V...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys input = sys.stdin.readline def read_strs(): s = input().strip() return list(map(int, list(s))) def solve(a, b): x, y, diff = 0, 0, 0 n = len(a) result = n + 1 for i in range(n): x += a[i] y += b[i] diff += 1 if a[i] != b[i] else 0 if x == y: re...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
from sys import stdin input = stdin.readline def solve(a): ans, bal, flip = 0, 0, 0 for i in range(n): if a[i] == "1" and b[i] == "0": bal += 1 ans += 1 if a[i] == "0" and b[i] == "1": bal -= 1 ans += 1 if bal == 0: return ans re...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUN...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys def readnum(): input = sys.stdin.readline a = list(map(int, input().split())) return a def readstr(): input = sys.stdin.readline a = str(input().split()[0]) return a def printf(val): sys.stdout.write(str(val) + "\n") def power(a, b, mod): if b == 1: return a ...
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBE...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def find(n, a, b): dif = 0 sum_a = 0 sum_b = 0 for i in range(n): if a[i] == "1": sum_a += 1 if b[i] == "1": sum_b += 1 if a[i] != b[i]: dif += 1 if sum_a != sum_b and sum_a + sum_b != n + 1: return -1 if sum_a == sum_b: ...
FUNC_DEF ASSIGN 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 NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR VA...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
def solve(): n = int(input()) a = list(input()) b = list(input()) bcount = b.count("1") acount = a.count("1") aicount = n - acount + 1 if acount != bcount and aicount != bcount: print(-1) return diffcount = 0 for i in range(len(a)): if a[i] != b[i]: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
import sys I = lambda: [*map(int, sys.stdin.readline().split())] prin = sys.stdout.write (t,) = I() for _ in range(t): (n,) = I() s1 = input() s2 = input() o1 = s1.count("1") o2 = s2.count("1") if o1 != o2 and o1 + o2 != n + 1: print(-1) elif o1 == o2 and o1 + o2 != n + 1: d...
IMPORT ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR F...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
t = int(input()) for test in range(t): n = int(input()) a = input() b = input() zC = a.count("0") oC = n - zC desiredOC = b.count("1") if oC == 0: if desiredOC == 0: print(0) continue else: print(-1) continue flag = False ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUM...
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
t = int(input()) while t: n = int(input()) a = input() b = input() f00, f01, f10, f11 = 0, 0, 0, 0 res = 0 for i in range(n): if a[i] == "0" and b[i] == "0": f00 += 1 elif a[i] == "0" and b[i] == "1": f01 += 1 elif a[i] == "1" and b[i] == "0": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER...
Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus. Innocentius is touch-typing a program that pain...
import sys def readln(): return list(map(int, input().split())) def exit(): print(-1) sys.exit() n, m = readln() mon = [list(input()) for _ in range(n)] hor = [i for i in range(n) if mon[i] != ["."] * m] rmon = list(zip(*mon)) ver = [j for j in range(m) if rmon[j] != (".",) * n] mini = hor[0] maxi = h...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
s = input() n = len(s) cnt = {"a": 0, "b": 0, "c": 0} for i in range(n): cnt[s[i]] += 1 base = "a" if cnt[s[0]] > cnt[base]: base = s[0] if cnt[s[1]] > cnt[base]: base = s[1] on = [] le = cnt[base] for i in range(n): on.append(s[i] == base) bl, br = 0, 0 il, ir = 0, n - 1 while le < n // 2 and il <= ir:...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR FOR VAR FUNC_C...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
import sys def main(): s = input() n = len(s) l = 0 r = n - 1 temp = [] temp2 = [] while l <= r: if s[l] == s[r]: temp.append(s[l]) if l != r: temp2.append(s[r]) l += 1 r -= 1 elif s[l] == s[r - 1]: ...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
from sys import exit, stdin, stdout s = stdin.readline().strip() n = len(s) ans_head = [] ans_tail = [] idx_h = 0 idx_t = n - 1 while idx_h + 1 < idx_t - 1: heads = set([s[idx_h], s[idx_h + 1]]) if s[idx_t] in heads: ans_head.append(s[idx_t]) ans_tail.append(s[idx_t]) else: ans_head...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR F...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
import sys input = sys.stdin.readline s = [0] + list(input().strip()) + [0] A = 0 B = len(s) - 1 ANS = [] while A < B: str0 = [5] * 3 str1 = [5] * 3 str0[ord(s[A + 2]) - 97] = 2 str0[ord(s[A + 1]) - 97] = 1 str1[ord(s[B - 2]) - 97] = 2 str1[ord(s[B - 1]) - 97] = 1 M = [(str0[i] + str1[i]) f...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
import sys input = sys.stdin.readline s = input() n = len(s) ans = [] ans1 = [] mxm = (n - 1) // 2 pt = 0 pt1 = n - 2 while pt < pt1 and mxm > 0: if mxm == 1: ans.append(s[pt]) break q1 = pt q2 = pt1 while q1 < q2 and q2 > pt1 - 2: if s[q1] == s[q2]: break q2...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR BIN_OP V...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
from sys import stdin, stdout s = stdin.readline().strip() n = len(s) if n <= 3: print(s[0]) else: ans = "" start, end = 0, n - 1 while start + 1 < end - 1: if s[start] == s[end] or s[start] == s[end - 1]: ans += s[start] else: ans += s[start + 1] start +...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASS...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
s = input() l = 0 r = len(s) - 1 ans = "" while r - l > 1: if s[l] == s[r]: ans += s[l] l += 1 r -= 1 elif r - l > 2 and s[l + 1] == s[r]: ans += s[l + 1] l += 2 r -= 1 elif r - l > 2 and s[l] == s[r - 1]: ans += s[l] l += 1 r -= 2 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING WHILE BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
S = input() i = 0 j = len(S) - 1 ans = [] f = 0 while i < j: if S[i] == S[j]: pass elif S[i] == S[j - 1]: j -= 1 elif S[i + 1] == S[j]: i += 1 else: i += 1 j -= 1 if i == j: f = 1 ans.append(S[i]) i += 1 j -= 1 print("".join(ans + ans[::-1]...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR V...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
sre = input() pre = 0 kre = len(sre) - 1 pointeree = 0 plotttt = [] while pre + 1 < kre - 1: if sre[pre] == sre[kre]: plotttt.append(sre[pre]) pre += 1 kre -= 1 pointeree += 2 elif sre[pre] == sre[kre - 1]: plotttt.append(sre[pre]) pre += 1 kre -= 2 el...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMB...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
s = input() length = len(s) left = 0 right = len(s) - 1 endStr = "" while left < right - 2: if s[left] == s[right]: endStr = endStr + s[left] left += 1 right -= 1 elif s[left] == s[right - 1]: endStr = endStr + s[left] left += 1 right -= 2 elif s[left + 1] == ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF ...