description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def main(): i = 0 j = 0 k = 0 sum1 = 0 sum2 = 0 n = int(input()) a = [int(x) for x in input().split()] m = int(input()) b = [int(x) for x in input().split()] while i < n and j < m: if a[i] == b[j]: k += 1 i += 1 j += 1 if i ...
FUNC_DEF ASSIGN VAR NUMBER 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 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 WHILE VAR VAR VAR VAR IF VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) j = 0 i = 0 sizei = n sizej = m while i < n and j < m: while i < n and j < m and a[i] != b[j]: if j + 1 < m and a[i] > b[j]: b[j + 1] += b[j] j += 1 sizej -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VA...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
while True: try: def solution(n, na, m, ma): sn = 0 sm = 0 for i in range(n): sn += na[i] for i in range(m): sm += ma[i] if sn != sm: print("-1") return elen, elem = na[0]...
WHILE NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) A = list(map(int, input().split())) m = int(input()) B = list(map(int, input().split())) if sum(A) != sum(B): print(-1) exit() a = A.pop() b = 0 cnt = 1 while A or B: if a != b: if a > b: b += B.pop() else: a += A.pop() else: cnt += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) A = list(map(int, input().split())) m = int(input()) B = list(map(int, input().split())) i = 0 j = 0 ans = 0 sa = 0 sb = 0 while i < n or j < m: if sa < sb: if i >= n: break sa += A[i] i += 1 else: if j >= m: break sb += B[j] ...
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 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import time _ = int(input()) M = input().split(" ") M = list(map(lambda val: int(val), M)) _ = int(input()) N = input().split(" ") N = list(map(lambda val: int(val), N)) merge = 0 m = len(M) n = len(N) def perform(): global merge global m global n i = 0 j = 0 while True: if i < len(M)...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) ans = 0 if sum(a) != sum(b): print(-1) else: sum_i = a[0] sum_j = b[0] i = 0 j = 0 while i < n and j < m: while sum_i < sum_j and i + 1 < n: i += 1 sum_i += a...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASS...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) else: ans = 0 posA, posB = 0, 0 while posA < n: ans += 1 sumA = a[posA] sumB = b[posB] while sumA != sumB: if sumA < sumB: ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUM...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys n = int(input()) A = [int(x) for x in input().split()] m = int(input()) B = [int(x) for x in input().split()] def debug(name, val): sys.stderr.write(name + "=" + str(val) + "\n") S = A[0] - B[0] i, j, k = 0, 0, 0 while i < n - 1 and j < m - 1 or i < n - 1 and S < 0 or j < m - 1 and S > 0: if S <...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_DEF EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUM...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
m = int(input()) A = [int(element) for element in input().split()] n = int(input()) B = [int(element) for element in input().split()] a_idx, b_idx = 0, 0 result = 0 while a_idx < m and b_idx < n: a_sum, b_sum = A[a_idx], B[b_idx] while a_sum != b_sum and a_idx < m and b_idx < n: if a_sum < b_sum: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VA...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) i = j = c = d = e = 0 while j < m: e += b[j] while i < n and d < e: d += a[i] i += 1 if d == e: d = e = 0 c += 1 elif j == m - 1: c = -1 break j +...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def solve(a, b): if sum(a) != sum(b): return -1 i = j = 0 length = 0 sum1 = sum2 = 0 loc = [] while i < len(a) and j < len(b): if sum1 == sum2 and sum1 > 0: sum1 = sum2 = 0 length += 1 if sum1 > sum2: sum2 += b[j] j += 1 ...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) i = 0 j = 0 x = 0 y = 0 f = 0 ans = 0 if sum(a) == sum(b): while i < n and j < m: if f == 0: x += a[i] y += b[j] elif f == 1: y += b[j] elif f == 2: ...
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 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) else: i = 0 ai = 0 bi = 0 while ai < n and bi < m: if a[ai] == b[bi]: ai = ai + 1 bi = bi + 1 i = i + 1 con...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = [0] * (n + 1) for i, x in enumerate(map(int, input().split())): a[i + 1] = a[i] + x m = int(input()) b = [0] * (m + 1) for i, x in enumerate(map(int, input().split())): b[i + 1] = b[i] + x if a[-1] != b[-1]: print(-1) else: print(len(set(a) & set(b)) - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
length_first = int(input()) first = list(map(int, input().split())) length_second = int(input()) second = list(map(int, input().split())) if sum(first) != sum(second): print(-1) else: solution = 0 pos_first = 1 pos_second = 1 sum = first[0] - second[0] while pos_first < length_first and pos_seco...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) A = [int(i) for i in input().split()] m = int(input()) B = [int(i) for i in input().split()] res = 0 indA = 0 indB = 0 flag = False while indA < len(A) and indB < len(B): if A[indA] == B[indB]: indA += 1 indB += 1 res += 1 elif A[indA] < B[indB]: if indA + 1 >= l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys input = sys.stdin.readline n = int(input()) ar = list(map(int, input().split())) m = int(input()) br = list(map(int, input().split())) i = 0 j = 0 if sum(ar) != sum(br): print(-1) else: su1 = 0 su2 = 0 ans = 0 while i < n and j < m: if su1 >= su2: su2 += br[j] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_C...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) ans = 0 i = 0 j = 0 while i != n and j != m: if a[i] == b[j]: ans += 1 i += 1 j += 1 elif a[i] < b[j]: if i + 1 < len(a): a[i + 1] += a[i] i += 1 else...
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 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 NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VA...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
ka = int(input()) a = list(map(int, input().split())) kb = int(input()) b = list(map(int, input().split())) def sum1(a): k = 0 for i in a: k += a return k def www(a, b, k1, k2): ka = k1 kb = k2 sa = a[ka] sb = b[kb] while sa != sb: if sa > sb: kb += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys f = sys.stdin out = sys.stdout n = int(f.readline().rstrip("\r\n")) a = list(map(int, f.readline().rstrip("\r\n").split())) m = int(f.readline().rstrip("\r\n")) b = list(map(int, f.readline().rstrip("\r\n").split())) i = n - 1 j = m - 1 c = 0 while i >= 0 and j >= 0: if a[i] == b[j]: c += 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASS...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) aNew = [0] * n bNew = [0] * m aNew[0] = a[0] bNew[0] = b[0] for i in range(1, n): aNew[i] = aNew[i - 1] + a[i] for i in range(1, m): bNew[i] = bNew[i - 1] + b[i] count = 0 i = 0 j = 0 while i < n and j < m:...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys A = list(map(int, input().split(" "))) A = list(map(int, input().split(" "))) B = list(map(int, input().split(" "))) B = list(map(int, input().split(" "))) total = -1 indexA = 0 sumA = 0 indexB = 0 sumB = 0 if sum(A) == sum(B): while indexA <= len(A) and indexB <= len(B): while sumA < sumB: ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
INF = 1000000000 def main(): N = int(input()) A = list(map(int, input().split())) M = int(input()) B = list(map(int, input().split())) currentSumA = currentSumB = 0 indexA = indexB = 0 numberOfSegments = 0 possible = False while indexA < len(A): currentSumA += A[indexA] ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER W...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
a = int(input()) b = list(map(int, input().split())) c = int(input()) d = list(map(int, input().split())) s = 0 r = 0 flag = 1 count = 0 while s < a or r < c: if s == a: flag = 0 break if r == c: flag = 0 break if b[s] == d[r]: count += 1 s += 1 r += 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR ASS...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def f(n, m, A, B): p1A, p2A, p1B, p2B = 0, 1, 0, 1 somaA, somaB = A[p1A], B[p1A] total = 0 while True: if somaA == somaB: total += 1 p1A, p1B = p2A, p2B p2A += 1 p2B += 1 if p1A >= n or p1B >= m: break somaA,...
FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR IF VAR VAR RETURN NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) arr = list(map(int, input().split())) m = int(input()) brr = list(map(int, input().split())) if sum(arr) != sum(brr): print(-1) exit() ai = 0 bi = 0 asm = 0 bsm = 0 cnt = 0 while ai < len(arr) and bi < len(brr): if asm < bsm: asm += arr[ai] ai += 1 elif bsm < asm: ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def f(left, right): li = 0 ri = 0 rLen = len(right) rConstLen = rLen lLen = len(left) lConstLen = lLen while True: l = left[li] r = right[ri] while l != r: if l > r: ri += 1 if ri >= rConstLen: return -1 ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR VAR VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) one = list(map(int, input().strip().split())) m = int(input()) two = list(map(int, input().strip().split())) sum_one = 0 sum_two = 0 for i in one: sum_one += i for i in two: sum_two += i if sum_one != sum_two: print(-1) else: pos_one = 0 pos_two = 0 sum_one = 0 sum_two = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FOR VAR VAR VAR VAR IF VAR VAR E...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = [int(i) for i in input().split()] m = int(input()) b = [int(i) for i in input().split()] if sum(a) != sum(b): print(-1) else: i = 0 j = 0 cnt = 0 s_i = a[0] s_j = b[0] while i < n and j < m: if s_i > s_j: j += 1 if j < m: s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VA...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) N = list(map(int, input().split())) m = int(input()) M = list(map(int, input().split())) i, j, ans, s_n, s_m = 0, 0, 0, N[0], M[0] while i < n and j < m: if s_n == s_m: ans += 1 i += 1 j += 1 if i == n or j == m: break s_n = N[i] s_m = M[j...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR N...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys n = int(input()) A = list(map(int, input().split())) m = int(input()) B = list(map(int, input().split())) i = 0 j = 0 x = A[0] y = B[0] ACHECK = 0 while True: if x == y: i += 1 j += 1 if i == n and j == m: print(n - ACHECK) return elif i == n and j...
IMPORT 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 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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHI...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) line_a = list(map(int, input().split())) m = int(input()) line_b = list(map(int, input().split())) if sum(line_a) != sum(line_b): print(-1) else: sa = 0 sb = 0 l = 0 r = 0 size = 0 while l != n and r != m: if sa + line_a[l] > sb + line_b[r]: sb += line_b[...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) list1 = list(map(int, input().split())) m = int(input()) list2 = list(map(int, input().split())) list11 = [list1[0]] for i in range(1, n): list11.append(list11[-1] + list1[i]) list22 = [list2[0]] for i in range(1, m): list22.append(list22[-1] + list2[i]) if list11[-1] != list22[-1]: print(-...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASS...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
t1 = int(input()) arr1 = [int(x) for x in input().split()] t2 = int(input()) arr2 = [int(x) for x in input().split()] sum1 = 0 sum2 = 0 for i in range(max(t1, t2)): if i < t1: sum1 += arr1[i] if i < t2: sum2 += arr2[i] res = 0 if sum1 != sum2: res = -1 else: pos1 = 0 pos2 = 0 whi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR AS...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n1 = int(input()) a = [int(x) for x in input().split()] n2 = int(input()) b = [int(x) for x in input().split()] suma = a[0] sumb = b[0] m = [] i = int(0) j = int(0) ct = int(-1) mn = min(n1, n2) while i != n1 and j != n2: if suma == sumb: m.append(suma) suma = int(0) sumb = int(0) i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSI...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) A = [int(i) for i in input().split()] m = int(input()) B = [int(i) for i in input().split()] if sum(A) != sum(B): print(-1) exit() pre1 = [0] * (n + 1) pre2 = [0] * (m + 1) for i in range(1, n + 1): pre1[i] = pre1[i - 1] + A[i - 1] for i in range(1, m + 1): pre2[i] = pre2[i - 1] + B[i -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUM...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) exit(0) i = 0 j = 0 while i < n and j < m: while a[i] != b[j] and i < n and j < m: if i < n - 1 and a[i] < b[j]: a[i + 1] += a[i] a[i] = -1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) sys.exit(0) idx_a, idx_b = 0, 0 sum_a, sum_b = a[0], b[0] ans = 0 while idx_a < n or idx_b < m: if sum_a == sum_b: ans += 1 idx_a += 1 ...
IMPORT 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
t1 = int(input()) arr1 = input().split() t2 = int(input()) arr2 = input().split() sum1 = 0 sum2 = 0 tamMax = max(t1, t2) for i in range(tamMax): if i < t1: arr1[i] = int(arr1[i]) sum1 += arr1[i] if i < t2: arr2[i] = int(arr2[i]) sum2 += arr2[i] if sum1 != sum2: print(-1) else...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) else: i = 0 j = 0 suma = 0 sumb = 0 ans = 0 while i < n or j < m: if suma == sumb and suma != 0: suma = 0 sumb = 0 ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split(" "))) m = int(input()) b = list(map(int, input().split(" "))) i, j = 0, 0 res = 0 x, y = 0, 0 last_i, last_j = -1, -1 while i < n and j < m: if last_i != i: x += a[i] if last_j != j: y += b[j] last_i, last_j = i, j if x == y: i +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUM...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
from sys import stdin n = int(stdin.readline().strip()) s = list(map(int, stdin.readline().strip().split())) n1 = int(stdin.readline().strip()) s1 = list(map(int, stdin.readline().strip().split())) st = set() st.add(s1[0]) for i in range(1, n1): s1[i] += s1[i - 1] st.add(s1[i]) x = 0 acu = 0 ans = 0 y = 0 for ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = input() a = list(map(int, input().split())) m = input() b = list(map(int, input().split())) ans = 0 ta, tb = 0, 0 if sum(a) != sum(b): print(-1) exit(0) while len(a) and len(b): ta += a.pop() while ta != tb: if ta < tb: ta += a.pop() else: tb += b.pop() ta...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBE...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def remove_equal_part(a, b): i = 0 j = len(a) - 1 k = len(b) - 1 while i < len(a) and i < len(b): if a[i] != b[i] and a[j] != b[k]: return i, j, k if a[i] == b[i]: i += 1 if a[j] == b[k]: j -= 1 k -= 1 return i, j, k n = int(i...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FU...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) alist = list(map(int, input().split())) m = int(input()) blist = list(map(int, input().split())) prea = [alist[0]] for i in range(1, n): prea.append(prea[-1] + alist[i]) preb = [blist[0]] for i in range(1, m): preb.append(preb[-1] + blist[i]) if prea[-1] != preb[-1]: print(-1) else: x =...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASS...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) arr1 = [int(element) for element in input().split()] m = int(input()) arr2 = [int(element) for element in input().split()] res = 0 p1 = 0 p2 = 0 sum1 = arr1[p1] sum2 = arr2[p2] arr1.append(0) arr2.append(0) while p1 < n and p2 < m: if sum1 == sum2: res += 1 sum1 = arr1[p1 + 1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
from sys import stdin input = stdin.readline n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) exit() j, k = 0, 0 sa, sb = 0, 0 cnt = 0 pa, pb = 1, 1 while j < n and k < m: if pa == 1: sa += a[j] if pb == 1: ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VA...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = input() n = int(n) a = input() a = list(a.split(" ")) m = input() m = int(m) b = input() b = list(b.split(" ")) for i in range(n): a[i] = int(a[i]) for i in range(m): b[i] = int(b[i]) a.insert(0, 0) b.insert(0, 0) for i in range(1, n + 1): a[i] += a[i - 1] for i in range(1, m + 1): b[i] += b[i - 1] ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def fun(arr, arr2): tem = [] tot = 0 for i in arr: tot += i tem.append(tot) tem2 = [] tot = 0 for i in arr2: tot += i tem2.append(tot) tem = set(tem) tem1 = set(tem2) return len(tem.intersection(tem2)) k = int(input()) arr = list(map(int, input().spl...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def __starting_point(): n1 = int(input().strip()) a1 = [int(__) for __ in input().strip().split()] n2 = int(input().strip()) a2 = [int(__) for __ in input().strip().split()] s1, s2 = sum(a1), sum(a2) if a1 == a2: print(n1) elif sum(a1) != sum(a2): print(-1) else: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VA...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
na = int(input()) a = [int(x) for x in input().split()] nb = int(input()) b = [int(x) for x in input().split()] res = 0 ia, ib = 0, 0 suma, sumb = a[0], b[0] while ia < len(a) and ib < len(b): if suma == sumb: ia += 1 ib += 1 res += 1 if ia < len(a): suma = a[ia] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VA...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
N = int(input()) A = [int(x) for x in input().split()] M = int(input()) B = [int(x) for x in input().split()] ans = 0 i, j = 0, 0 sa, sb = 0, 0 while i < N or j < M: if sa == sb: ans += 1 if i < N: sa += A[i] i += 1 if j < M: sb += B[j] j += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR V...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) == sum(b): ans = 0 suma = 0 sumb = 0 uka = 0 ukb = 0 while uka <= n - 1 or ukb <= m - 1: if suma + a[uka] == sumb + b[ukb]: suma += a[uka] sumb += b...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMB...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) k = 0 i = 0 j = 0 sum1 = 0 sum2 = 0 while i < n and j < m: if sum1 == 0 and sum2 == 0: sum1 = a[i] sum2 = b[j] i += 1 j += 1 if i >= n or j >= m: break if sum1 ==...
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 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
get_input = lambda: list(map(int, input().split())) n = get_input()[0] arr_A = get_input() m = get_input()[0] arr_B = get_input() arr_A.append(0) arr_B.append(0) curr_A = 0 curr_B = 0 sum_A = arr_A[curr_A] sum_B = arr_B[curr_B] res = 0 while curr_A < n and curr_B < m: if sum_A == sum_B: curr_A += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NU...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
lenA1 = int(input()) a1 = list(map(int, input().split())) lenA2 = int(input()) a2 = list(map(int, input().split())) i1 = 0 i2 = 0 soma1 = a1[0] soma2 = a2[0] count = 0 lenA1 -= 1 lenA2 -= 1 while i1 < lenA1 and i2 < lenA2: if soma1 > soma2: i2 += 1 soma2 += a2[i2] elif soma1 < soma2: i1 ...
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 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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def go(): n = int(input()) a = [int(i) for i in input().split(" ")] m = int(input()) b = [int(i) for i in input().split(" ")] i = 0 so_far_i = 0 j = 0 so_far_j = 0 while i < n and so_far_i < n and j < m and so_far_j < m: if a[i] == b[j]: i = so_far_i j...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
def main(): def read_list(): return list(map(int, input().split())) input() A = read_list() input() B = read_list() length = 0 i_start = 0 j_start = 0 while i_start < len(A) or j_start < len(B): i = i_start j = j_start s1 = 0 s2 = 0 w...
FUNC_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) a_now = 0 b_now = 0 b_idx = 0 ans = 0 for i in range(n): a_now += a[i] if a_now > b_now: while a_now > b_now: if b_idx == m: break ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_C...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) s1 = [int(x) for x in input().split()] m = int(input()) s2 = [int(x) for x in input().split()] if n == 1 or m == 1: if n == 1: r = 0 for j in range(0, m): r = r + s2[j] if r == s1[0]: print("1") else: print("-1") else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR V...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
a = int(input()) z = list(map(int, input().split())) x = int(input()) m = list(map(int, input().split())) l = 0 r = 0 s1 = z[0] s2 = m[0] flag = 0 count = 0 while l < len(z) and r < len(m): if s1 == s2: count += 1 l += 1 r += 1 if l < len(z) and r < len(m): s1 = z[l] ...
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 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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
from itertools import * for _ in range(1): n = int(input()) d = set() arr = list(accumulate(map(int, input().split()))) m = int(input()) brr = list(accumulate(map(int, input().split()))) if arr[-1] != brr[-1]: print(-1) continue for i in arr: d.add(i) count = 0 ...
FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER E...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys input = sys.stdin.readline out = sys.stdout n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) else: ans = 0 curA, curB = 0, 0 while len(a) and len(b): curA += a.pop() while curA != curB: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
from itertools import accumulate def main(): n = int(input()) arr1 = list(accumulate(map(int, input().split()))) m = int(input()) arr2 = list(accumulate(map(int, input().split()))) if arr1[-1] != arr2[-1]: print(-1) exit(0) s1 = set(arr1) s2 = set(arr2) print(len(s1.int...
FUNC_DEF 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR N...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
a = int(input()) arraya = list(map(int, input().split())) b = int(input()) arrayb = list(map(int, input().split())) ans = 0 ia = 0 ib = 0 ma = arraya[0] mb = arrayb[0] while ia < a and ib < b: if ma == mb: ans += 1 ia += 1 ib += 1 if ia == a or ib == b: break ma =...
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 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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR ...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) i = 0 j = 0 curra = a[i] currb = b[j] c = 0 if sum(a) != sum(b): print(-1) else: while i < n and j < m: if curra == currb: i += 1 j += 1 c += 1 if i <...
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 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 VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) exit() ret = 0 p1 = p2 = 0 while p1 < n and p2 < m: s1, s2 = a[p1], b[p2] while s1 != s2 and p1 < n and p2 < m: while s1 < s2 and p1 + 1 < n: p1 +=...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys zz = 1 sys.setrecursionlimit(10**5) if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def fori(n): return [fi() for i in range(n)] def inc(d, c, x=1): d[c] = d[c] + x if c in d else x ...
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NU...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
import sys N1 = int(input()) arr1 = [int(elem) for elem in input().split(" ")] N2 = int(input()) arr2 = [int(elem) for elem in input().split(" ")] def merge_arrays(arr1, arr2): if sum(arr1) != sum(arr2): return -1 else: length = 0 while len(arr1) > 0 and len(arr2) > 0: if ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUM...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n1 = int(input()) a1 = list(map(int, input().split())) n2 = int(input()) a2 = list(map(int, input().split())) if n1 < n2: a1, a2 = a2, a1 if sum(a1) != sum(a2): print(-1) else: c = 1 f = 0 s = 0 c1 = a1[f] c2 = a2[s] while s + 1 < len(a2) and f + 1 < len(a1): if c1 == c2: ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VA...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) x = sum(a) y = sum(b) if x != y: print(-1) else: pref1 = [a[0]] pref2 = [b[0]] for i in range(1, n): pref1.append(pref1[-1] + a[i]) for i in range(1, m): pref2.append(pref2[-1] +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LI...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) lis1 = list(map(int, input().split())) m = int(input()) lis2 = list(map(int, input().split())) i = j = 0 a = 0 b = 0 ans = -1 while i < n or j < m: if a == b: ans += 1 if i < n: a = lis1[i] i += 1 else: a = 0 if j < m: ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = [int(x) for x in input().split()] m = int(input()) b = [int(x) for x in input().split()] i = j = 0 x = a[0] y = b[0] length = 0 while True: if x == y and i < n - 1 and j < m - 1: length += 1 i += 1 j += 1 x = a[i] y = b[j] elif x < y and i < n - 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR BIN_OP VAR NUMBE...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) else: L = 0 while a or b: if a[-1] == b[-1]: del a[-1] del b[-1] L += 1 elif a[-1] < b[-1]: a[-2] += a[-1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMB...
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the ar...
n = int(input()) a = [int(i) for i in input().split(" ")] m = int(input()) b = [int(i) for i in input().split(" ")] aa = [a[0]] bb = [b[0]] for i in range(1, n): aa.append(aa[-1] + a[i]) for i in range(1, m): bb.append(bb[-1] + b[i]) a1 = set(aa) a2 = set(bb) if sum(a) != sum(b): print(-1) else: print(l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP V...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
from sys import * input = stdin.readline def superstring(x, y, fx, n): ans = "" i, j = 0, 0 while i < 2 * n and j < 2 * n: if x[i] == y[j]: ans += x[i] i += 1 j += 1 elif x[i] != fx: ans += x[i] i += 1 else: a...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CAL...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
from sys import stdin, stdout def count(s): return sum(1 for c in s if c == "1") def build(s1, s2, m): i1 = 0 i2 = 0 answer = "" while i1 < len(s1) and i2 < len(s2): if s1[i1] == s2[i2]: answer += s1[i1] i1 += 1 i2 += 1 elif s1[i1] != m: ...
FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR VAR VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR V...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys input = sys.stdin.readline def main(): n = int(input()) S1 = input().strip() S2 = input().strip() S3 = input().strip() for s1 in (S1, S2, S3): for s2 in (S1, S2, S3): if s1 == s2: continue z1 = s1.count("0") o1 = s1.count("1")...
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 FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRIN...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [int(a) for a in input()] B = [int(a) for a in input()] C = [int(a) for a in input()] aa = 1 if A.count(0) >= N else 0 bb = 1 if B.count(0) >= N else 0 cc = 1 if C.count(0) >= N...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR 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 VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER V...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
from sys import stdin, stdout t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) s1 = stdin.readline(2 * n) stdin.readline(1) s2 = stdin.readline(2 * n) stdin.readline(1) s3 = stdin.readline(2 * n) stdin.readline(1) strings = [s1, s2, s3] strings.sort(key=lambda ...
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 BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VA...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
from itertools import product def mix(tpl, c): a, b = tpl n = len(a) ans = [] ap, bp = 0, 0 while True: while ap < n and a[ap] != c: ans.append(a[ap]) ap += 1 while bp < n and b[bp] != c: ans.append(b[bp]) bp += 1 if ap < n or...
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER WHILE VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VA...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
from sys import stdin input = stdin.readline def good(a, b, ch): cnt1, cnt2 = 0, 0 n = len(a) for i in range(n): if a[i] == ch: cnt1 += 1 if b[i] == ch: cnt2 += 1 i, j = 0, 0 ans = "" if min(cnt1, cnt2) >= n // 2: while i < n and j < n: ...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NU...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
for _ in range(int(input())): n = int(input()) a = input() b = input() c = input() i, j, k = 0, 0, 0 res = [] while True: if i == 2 * n: if j >= k: for x in range(j, 2 * n): res.append(b[x]) else: for x in ra...
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 ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST WHILE NUMBER IF VAR BIN_OP NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FU...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) ans = [] s1 = input() s2 = input() s3 = input() fincount = 0 count10 = 0 for i in range(2 * n): if s1[i] == "0": count10 += 1 if count10 >= n: fincount += 1 cou...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR STRING VAR NUMBE...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import itertools def solve(a, b): if a.count("1") * 2 >= len(a) and b.count("1") * 2 >= len(b): ch = "1" other = "0" else: ch = "0" other = "1" res = [] i = 0 j = 0 ilast = -1 jlast = -1 while i < len(a) and j < len(b): while i < len(a) and a[i] ...
IMPORT FUNC_DEF IF BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUN...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
def f(s1, s2, n, c): i1, i2 = 0, 0 nz = 0 l = [] b = True while i1 + i2 != 4 * n: if i1 == 2 * n: b = False if i2 == 2 * n: b = True if b: if s1[i1] == c and nz < n: b = False else: l.append(s1[i1...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys input = sys.stdin.readline for f in range(int(input())): n = int(input()) s = [] for i in range(3): s.append(input()) s1 = [] s0 = [] for i in range(3): s0.append(s[i].count("0")) s1.append(2 * n - s0[-1]) for i in range(2): for j in range(i + 1, 3...
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 LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP ...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
t = int(input()) for _ in range(t): n = int(input()) s1 = input() s2 = input() s3 = input() p1, p2, p3 = 0, 0, 0 res = [] while max(p1, p2, p3) < 2 * n: if s1[p1] == s2[p2]: res.append(s1[p1]) p1 += 1 p2 += 1 elif s1[p1] == s3[p3]: ...
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 ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL V...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys input = iter(sys.stdin.read().splitlines()).__next__ def solve(): n = int(input()) a = input() b = input() c = input() median_0 = [] median_1 = [] for string in (a, b, c): popcount = string.count("1") if popcount <= n: median_0.append(string) ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CA...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
def merge(x, y, c): N = len(x) n = N // 2 ans = "" i, j = 0, 0 while i < N and j < N: if x[i] == y[j]: ans += x[i] i += 1 j += 1 elif x[i] != c: ans += x[i] i += 1 else: ans += y[j] j += 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP STRING BIN_OP BIN_OP NUMBER VAR ...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline for _ in range(int(input())): N = int(input()) S = [] for _ in range(3): S.append(input().rstrip("\n")) T0 = [] T1 = [] for i in range(3): if...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF 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 LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CAL...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys input = sys.stdin.readline def mix(x, y): if x.count("0") >= n and y.count("0") >= n: ANS = [] i = 0 j = 0 while i < 2 * n or j < 2 * n: counti = 0 countj = 0 while i < n * 2 and x[i] == "1": counti += 1 ...
IMPORT ASSIGN VAR VAR FUNC_DEF IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR V...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
class Fmt: def __init__(self): a = input() self.str = a self.len = len(a) self.cnt_0 = sum([(1) for i in a if i == "0"]) self.cnt_1 = self.len - self.cnt_0 def __getitem__(self, item): return self.str[item] def color(a, b, n): if a.cnt_0 >= n and b.cnt_0 >...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN STRING IF VAR VAR VAR VAR RETURN STRING RETURN NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys input = sys.stdin.readline outL = [] t = int(input()) for _ in range(t): n = int(input()) s1 = input().strip() s2 = input().strip() s3 = input().strip() c1 = 0 c2 = 0 c3 = 0 l = [] while max(c1, c2, c3) < 2 * n: if s1[c1] == s2[c2] == s3[c3]: l.append(...
IMPORT ASSIGN VAR VAR ASSIGN VAR LIST 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHI...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
def merge(x, y, dict_x, dict_y, c): N = len(x) n = N // 2 v1, v2 = [-1] + dict_x[c], [-1] + dict_y[c] ans = "" for i in range(n): for j in range(v1[i] + 1, v1[i + 1]): ans += x[j] for j in range(v2[i] + 1, v2[i + 1]): ans += y[j] ans += c ans += ""...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR VAR BIN_OP LIST NUMBER VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUM...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys def input(): return sys.stdin.readline().rstrip() def slv(): n = int(input()) a = list(map(lambda x: int(x), list(input()))) b = list(map(lambda x: int(x), list(input()))) c = list(map(lambda x: int(x), list(input()))) aindex, bindex, cindex = 0, 0, 0 ans = [] addition = 0...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VA...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
tc = int(input()) for i in range(tc): n = int(input()) s = [input() for _ in range(3)] p = [0] * 3 ans = "" while True: ones = [] oc = 0 zeroes = [] for i in range(3): if s[i][p[i]] == "1": ones.append(i) oc += 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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR STRING WHILE NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ...
A bitstring is a string that contains only the characters 0 and 1. Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $2n$. A valid novel for the cont...
import sys from sys import stdin def solve(a, b, X): ans = [] ca = [a[i] for i in range(len(a))] cb = [b[i] for i in range(len(b))] while len(ca) > 0 or len(cb) > 0: if len(cb) == 0: ans.append(ca[-1]) del ca[-1] elif len(ca) == 0: ans.append(cb[-1])...
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NU...
The only difference with E2 is the question of the problem.. Vlad built a maze out of $n$ rooms and $n-1$ bidirectional corridors. From any room $u$ any other room $v$ can be reached through a sequence of corridors. Thus, the room system forms an undirected tree. Vlad invited $k$ friends to play a game with them. Vl...
import sys def findpaths(mypos: list, paths): queue = mypos.copy() times = [-1] * n for i in mypos: times[i] = 0 q = 0 while q < len(queue): pos = queue[q] dirs = paths[pos] for i in dirs: if times[i] == -1: queue.append(i) ...
IMPORT FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUN...