description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
t = 1 for _ in range(t): n = int(input()) a = list(map(int, input().split())) dict = {} sum = 0 dict[0] = -1 ans = 0 nearest = -1 for i in range(n): sum += a[i] if dict.get(sum) is None: ans += i - nearest else: p = dict[sum] p ...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NONE VAR BIN_OP ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = [int(n) for n in input().split()] hash_map = {(0): 0} total = 0 bad = 0 good = 0 for i in range(1, n + 1): total += arr[i - 1] if total in hash_map: bad = max(bad, hash_map[total] + 1) hash_map[total] = i good += i - bad print(good)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIG...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) x = list(map(int, input().split())) m = {} count = 0 v = [] last, ans = -1, 0 m[0] = -1 for i in range(n): count += x[i] if count in m: if m[count] + 1 > last: v.append([m[count] + 1, i]) last = m[count] + 1 m[count] = i v.sort() last = -1 for i in range(len(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) A = list(map(int, input().split())) rs = [] cur = 0 for a in A: cur += a rs.append(cur) last_seen = {} max_r = n out = 0 for i in range(n - 1, -1, -1): s = rs[i] max_r = min(max_r, last_seen.get(s, n)) out += max_r - (i + 1) last_seen[s] = i max_r = min(max_r, last_seen.get(0, n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(" "))) def solve(): n = read_int() arr = read_ints() prefix = 0 G = {(0): -1} segments = [] for i, a in enumerate(arr): prefix += a if prefix in G: segm...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
from sys import stdin n = int(stdin.readline()) sm = 0 pre = {(0): -1} last_start = -1 ans = 0 for i, a in enumerate(map(int, stdin.readline().split())): sm += a if sm in pre: last_start = max(last_start, pre[sm] + 1) pre[sm] = i ans += i - last_start print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = [0] + list(map(int, input().split())) for i in range(1, n + 1): a[i] += a[i - 1] mp = {(0): 0} last, ans = 0, 0 for i in range(1, n + 1): if a[i] in mp and mp[a[i]] >= last: ans -= (mp[a[i]] - last + 1) * (n - i + 1) last = mp[a[i]] + 1 mp[a[i]] = i print(ans + n * (n + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = list(map(int, input().split())) res = n * (n - 1) // 2 + n last = {(0): -1} s = 0 j = -1 for i in range(n): s += a[i] if s in last and last[s] >= j: res -= (last[s] + 1 - j) * (n - i) j = last[s] + 1 last[s] = i print(res)
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 BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = list(map(int, input().strip().split())) arr = arr h, hh, s, ans = {(0): 0}, -1, 0, 0 for i in range(n): s += arr[i] if s in h: hh = max(hh, h[s]) h[s] = i + 1 ans += i - hh print(ans)
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 VAR ASSIGN VAR VAR VAR VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def convertArrayToInt(A): for i in range(0, len(A), 1): A[i] = int(A[i]) return A def OrderN2LogNSolution(A): R = [] ans = 0 for i in range(0, len(A), 1): prefixSum = 0 ps_set = {0} flag = 0 for j in range(i, len(A), 1): prefixSum += A[j] ...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(arr): prefix = {} i = count = s = 0 maxL = -1 for i in range(len(arr)): s += arr[i] if s in prefix: last = prefix[s] maxL = max(maxL, last + 1) elif s == 0: maxL = 0 prefix[s] = i count += i - maxL return count x...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) l = list(map(int, input().split())) arr = [0] d = {} for i in range(1, n + 1): arr.append(arr[i - 1] + l[i - 1]) sum = 0 j = n for i in range(n, -1, -1): if arr[i] in d: j = min(j, d[arr[i]] - 1) sum += j - i d[arr[i]] = i print(sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
from itertools import accumulate def lengthOfLongestSubstring(A): ans = 0 lastSeen = {A[0]: 0} l = 0 for i in range(1, len(A)): if A[i] not in lastSeen: ans += max(0, i - l) else: l = max(l, lastSeen[A[i]] + 1) ans += max(0, i - l) lastSeen[A...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) l = list(map(int, input().split())) a = [0] lis = [] d = {(0): -1} for i in range(n): a.append(a[-1] + l[i]) if d.get(a[-1]) != None: lis.append((d[a[-1]] + 1, i)) d[a[-1]] = i else: d[a[-1]] = i ans = 0 lis = lis[::-1] for i in range(n): flag = 0 j = len(lis...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER NONE EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def inn(): return map(int, input().split()) def cout(s): print(s, end="") (n,) = inn() a = inn() a = [x for x in a] s = 0 i = 0 dc = {(0): -1} pers = [] while i < n: s += a[i] a[i] = s if a[i] not in dc: dc[a[i]] = i else: pers.append((dc[a[i]] + 1, i)) dc[a[i]] = i ...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
from itertools import accumulate n = int(input()) A = list(map(int, input().split())) B = [0] + A B = list(accumulate(B)) s = 0 t = 0 S = set() ans = 0 for s in range(n + 1): while t < n + 1 and B[t] not in S: S.add(B[t]) t += 1 ans += t - 1 - s if s == t: t += 1 else: S...
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 FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = [int(i) for i in input().split(" ")] ans = 0 prefix, s = [0] * (n + 1), 0 for i in range(n): s += a[i] prefix[i + 1] = s l, r = 0, 0 s = {0} while l < n: while r < n and prefix[r + 1] not in s: r += 1 s.add(prefix[r]) ans += r - l s.remove(prefix[l]) l += 1 p...
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 VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys def solve(a): n = len(a) ru = [0] * (n + 1) for i in range(n): ru[i + 1] = ru[i] + a[i] next_ = [n] * (n + 1) memo = {} for i in range(n + 1)[::-1]: if ru[i] in memo: next_[i] = memo[ru[i]] - 1 if i != n: next_[i] = min(next_[i + 1], n...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) lis = list(map(int, input().split())) ss = [0] * (n + 1) ans = 0 for i in range(1, n + 1): ss[i] = ss[i - 1] + lis[i - 1] d = {} ans, l = 0, 0 for i in range(n + 1): if ss[i] in d: d[ss[i]] += 1 else: d[ss[i]] = 1 while d[ss[i]] > 1: d[ss[l]] -= 1 l += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMB...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(): n = int(input()) a = list(map(int, input().split())) total = 0 sd = {(0): -1} s = 0 mi = 0 for i in range(n): s += a[i] if s in sd: mi = max(mi, sd[s] + 2) sd[s] = i total += i + 1 - mi print(total) def main(): solve() main...
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 NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
N = int(input()) D = {(0): -1} A = [int(a) for a in input().split()] m = -1 s = 0 ans = 0 for i, a in enumerate(A): if a == 0: m = i continue s += a if s not in D: D[s] = i ans += i - m else: m = max(m, D[s] + 1) ans += i - m D[s] = i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys n = int(sys.stdin.readline().strip()) l = [int(j) for j in sys.stdin.readline().split()] pre = [0] * (n + 1) last = 0 for i in range(1, n + 1): pre[i] = pre[i - 1] + l[i - 1] last = 0 ans = 0 idx = dict() idx[0] = 0 for i in range(1, n + 1): if pre[i] in idx: last = max(last, idx[pre[i]] + 1...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys lines = sys.stdin.readlines() n = int(lines[0].strip()) nums = list(map(int, lines[1].strip().split(" "))) seen = {(0): -1} tmpSum = 0 prev = -1 res = 0 for i in range(n): tmpSum += nums[i] if tmpSum not in seen or seen[tmpSum] < prev: seen[tmpSum] = i res += i - prev else: ...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys N = int(sys.stdin.readline()) list_a = list(map(int, sys.stdin.readline().split())) list_sum = [0] * (N + 1) for i in range(N): list_sum[i + 1] = list_sum[i] + list_a[i] result = 0 set_count = set() set_count.add(0) s = e = 0 ans = 0 while s < N: while e < N and not list_sum[e + 1] in set_count: ...
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = [int(i) for i in input().split()] prefix_sum = [0] for i in range(n): prefix_sum.append(prefix_sum[-1] + a[i]) ans = 0 pos = 0 s = set() s.add(prefix_sum[0]) i = 0 j = 0 while i < n: while j < n and prefix_sum[j + 1] not in s: s.add(prefix_sum[j + 1]) j += 1 ans += j - i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHI...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys from itertools import accumulate input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) cum = [0] + list(accumulate(a)) s = t = 0 ans = 0 st = set() while s <= n: while t <= n and cum[t] not in st: st.add(cum[t]) t += 1 ans += t - s - 1 st.remove(cum[s]) ...
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 BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR WHILE VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = list(map(int, input().split(" "))) prefix = [0] prefix_set = set() ans = 0 for i in range(n): prefix.append(arr[i] + prefix[i]) i = 0 j = 0 prefix_set.add(0) while i < n: while j < n and not prefix[j + 1] in prefix_set: j = j + 1 prefix_set.add(prefix[j]) ans = ans + j...
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 LIST NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
while True: try: def soln(a): elmn = {(0): 0} gdElPos = sAry = sum = 0 for i in range(len(a)): sum += a[i] if sum in elmn: gdElPos = max(gdElPos, elmn[sum] + 1) elmn[sum] = i + 1 sAry += ...
WHILE NUMBER FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
a = int(input()) la = list(map(int, input().split())) partsum = [la[0] for i in range(a)] for i in range(1, a): partsum[i] = partsum[i - 1] + la[i] good = [(1) for i in range(a)] if la[0] == 0: good[0] = 0 clear = [(True) for i in range(a)] parts = {partsum[0]} for i in range(1, a): if partsum[i] not in par...
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 VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) d = n * (n + 1) // 2 s = 0 c = {(0): 0} k = -1 for j, q in enumerate(map(int, input().split())): s += q if s in c: i = c[s] if i > k: d -= (n - j) * (i - k) k = i c[s] = j + 1 print(d)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASS...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) seen = dict() seen[0] = 0 out = 0 l = list(map(int, input().split())) curr = 0 bestCurr = 0 for i in range(n): curr += l[i] if curr in seen: bestCurr = min(bestCurr + 1, i - seen[curr]) else: bestCurr += 1 out += bestCurr seen[curr] = i + 1 print(out)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(n, a): d = {(0): -1} s = 0 res = 0 j = -1 for i in range(n): s += a[i] if d.get(s) != None: j = max(d[s] + 1, j) d[s] = i res += i - j return res def main(): n = int(input()) a = [int(x) for x in input().split()] res = solve(n, ...
FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) ar = [int(x) for x in input().split()] pre = [0] * (n + 1) ans = 0 for i in range(n): pre[i + 1] = pre[i] + ar[i] d = {} i = 0 j = 0 d[0] = 1 while i < n: while j < n and pre[j + 1] not in d: j += 1 d[pre[j]] = 1 ans += j - i d.pop(pre[i]) i += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER WHI...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = list(map(int, input().split())) h = {(0): -1} s = 0 ans = 0 t = -1 for i in range(n): if a[i] != 0: s += a[i] if s in h and h[s] >= t: ans += i - h[s] - 1 t = h[s] + 1 else: ans += i - t h[s] = i if a[i] == 0: t...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(): n = int(input()) a = list(map(int, input().split())) prefix = [(0) for _ in range(n + 1)] for i in range(1, n + 1, 1): prefix[i] = prefix[i - 1] + a[i - 1] cur_pref = dict() ans = 0 begin = 0 cur_pref[prefix[begin]] = 1 end = 0 while begin < n: while ...
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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(): n = int(input()) a = list(map(int, input().split())) psum = [0] + a for i in range(n): psum[i + 1] += psum[i] ans = 0 dic = {(0): 0} rightmost = 0 for i in range(1, n + 1): if psum[i] in dic: rightmost = max(rightmost, dic[psum[i]] + 1) an...
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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = list(map(int, input().split())) for i in range(1, len(arr)): arr[i] += arr[i - 1] arr = [0] + arr st = 0 mp = {} ans = 0 for i, c in enumerate(arr): if c in mp: st = max(st, mp[c] + 1) ans += i - st else: ans += i - st mp[c] = i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ n = int(input()) a = list(map(int, input().split())) dic = {} dic[0] = -1 nsum = 0 ans = 0 ll = -2 for i in range(n): nsum += a[i] if nsum in dic: ll = max(dic[nsum], ll) ans += i - ll - 1 dic[nsum] = i print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR 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 DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = list(map(int, input().split())) notneeded = dict() notneeded[0] = -1 ans = sum = mx = 0 for i, elem in enumerate(arr): sum += elem if sum in notneeded: mx = max(mx, notneeded[sum] + 2) ans += mx notneeded[sum] = i z = len(arr) print(int(z * (z + 1) // 2) - ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(a): seen = {(0): -1} res = curr = mx = 0 for i, x in enumerate(a): curr += x if curr in seen: mx = max(mx, seen[curr] + 2) res += mx seen[curr] = i return len(a) * (len(a) + 1) // 2 - res input() a = list(map(int, input().split())) print(solve(a))
FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = [0] + list(map(int, input().split())) hs, s, ans, hh = {(0): 0}, 0, 0, -1 for i in range(1, n + 1): s += a[i] if hs.__contains__(s): hh = max(hh, hs[s]) ans += i - hh - 1 hs[s] = i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys n = int(input()) a = [0] + [int(i) for i in input().split()] mx = 0 ps = 0 ans = 0 sdict = {(0): 0} for i in range(1, n + 1): ps += a[i] if ps in sdict.keys(): if ps == 0 and sdict[0] == -1: mx = max(mx, sdict[ps] + 1) else: mx = max(mx, sdict[ps] + 1) sdi...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER NUMBER AS...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def f(): n = int(input()) A = [int(s) for s in input().split()] S = [0] * (n + 1) memo = {(0): [0, 0]} sum = 0 for i in range(1, n + 1): sum += A[i - 1] S[i] = sum if sum not in memo: memo[sum] = [0] memo[sum].append(i) ans = 0 ok = -1 for ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSI...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def eugene_and_an_array(n, a): table = {} total = 0 table[0] = 0 ans = 0 posFrom = 0 for posTo in range(0, n): if a[posTo] == 0: posFrom = posTo + 1 continue ans += a[posTo] if ans in table: posFrom = max(table[ans] + 1, posFrom) ...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUM...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = list(map(int, input().split())) t = n * (n + 1) // 2 s = 0 d = {} b = [] d[0] = -1 for i in range(n): s += a[i] try: b.append([d[s] + 1, i]) d[s] = i except: d[s] = i if len(b) == 0: print(t) exit() pre = b[0] u, v = pre ans = (u + 1) * (n - v) mx = u for...
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 BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR NUMBER V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
printn = lambda x: print(x, end="") inn = lambda: int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda: input().strip() DBG = True BIG = 10**18 R = 10**9 + 7 def ddprint(x): if DBG: print(x) n = inn() a = inl() a.append(0) acc = [0] * (n + 2) fo...
ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER N...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
N = int(input()) A = list(map(int, input().split())) good_subarray = 0 prev_vals = {(0): -1} cum_sum = 0 left_boundary = -1 for i, a in enumerate(A): cum_sum += a if cum_sum == 0: left_boundary = prev_vals[0] + 1 if cum_sum in prev_vals: if prev_vals[cum_sum] >= left_boundary: le...
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 DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_O...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = list(map(int, input().strip().split())) d = {(0): 0} l = -1 cumulative_array = [0] for i in range(n): cumulative_array.append(cumulative_array[-1] + a[i]) ans = 0 for i in range(1, n + 1): c = cumulative_array[i] if c in d: l = max(l, d[c]) d[c] = i ans += i - l - 1 prin...
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 DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMB...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = [int(i) for i in input().split()] dic = {(0): -1} ans = [] s = 0 for i in range(len(arr)): s += arr[i] if s in dic: if len(ans) > 0 and dic[s] + 1 > ans[-1][0]: ans.append([dic[s] + 1, i]) elif len(ans) == 0: ans.append([dic[s] + 1, i]) dic[s] =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_O...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = [0] + [int(x) for x in input().split(" ")] ans = 0 lastocc = {(0): 0} sum = 0 soms = 0 for i in range(1, n + 1): sum += a[i] if lastocc.get(sum, -1) >= soms: soms = lastocc[sum] + 1 lastocc[sum] = i ans += i - soms print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = input().split() a = [int(i) for i in a] c = [0] * n d = {} A = 0 v1 = 0 d[0] = -1 idx = -1 for i in range(n): if i == 0: c[i] = a[i] else: c[i] = c[i - 1] + a[i] v = d.get(c[i]) if v is not None: idx = max(idx, v + 1) if a[i] == 0: idx = max(idx, ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BI...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = [int(i) for i in input().split()] ss = [0] for ai in a: ss.append(ss[-1] + ai) si = {(0): 0} left = 0 count = 0 for i in range(1, len(ss)): if ss[i] in si: left = max(left, si[ss[i]] + 1) si[ss[i]] = i count += i - left print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = lambda: sys.stdin.readline().strip() ipnut = input for i in range(1): n = int(ipnut()) a = list(map(int, input().split())) s = {} s[0] = 1 pref = [0] line = [] ans = 0 last = 0 for i in range(n): pref.append(pref[-1] + a[i]) if pref[-1] in s: ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) l = list(map(int, input().split())) x = [0] * (n + 1) d = dict() for i in range(n): x[i + 1] = x[i + 1] + x[i] + l[i] s = 0 c = 0 for i in range(n + 1): if x[i] in d: d[x[i]] += 1 else: d[x[i]] = 1 while d[x[i]] > 1: d[x[c]] -= 1 c = c + 1 s = s + (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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBE...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = lambda: sys.stdin.readline().rstrip() n = list(map(int, input().split()))[0] + 1 a = list(map(int, input().split())) s = [0] st = set() beg = 0 end = 0 ans = 0 for i in range(len(a)): s.append(a[i] + s[-1]) s.append(s[-1]) while True: if beg == n: print(ans) break if len(...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = sys.stdin.readline n = int(input()) a = [int(item) for item in input().split()] cuma = [0] for item in a: cuma.append(cuma[-1] + item) dic = dict() dic[cuma[0]] = 0 right_most = -1 ans = 0 for i, item in enumerate(cuma): if i == 0: continue if item in dic: ans += i - max(...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def main(): n = int(input()) arr = list(map(int, input().split())) begin = 0 dp = [0] for i in range(1, n + 1): dp.append(dp[i - 1] + arr[i - 1]) end = 0 d = {(0): 1} ans = 0 while begin < n: while end < n and (d.get(dp[end + 1]) == None or d[dp[end + 1]] == 0): ...
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 NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
k = {0} rez = 0 n = int(input()) a = input().split(" ") p = [0] for i in range(n): a[i] = int(a[i]) p.append(p[i] + a[i]) i = 0 j = 0 while i < n: while j < n and p[j + 1] not in k: j += 1 k.add(p[j]) rez += j - i k.remove(p[i]) i += 1 print(rez)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR BIN_OP ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) nums = list(map(int, input().split())) pre_sum = [0] * len(nums) pre = 0 for idx, num in enumerate(nums): pre += num pre_sum[idx] = pre count = {} for idx, num in enumerate(pre_sum): if num != 0: count[num] = count.get(num, []) else: count[num] = count.get(num, [-1]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
t = int(input()) b = list(map(int, input().split())) s = 0 p = 0 q = 0 c = dict() for j in range(t): s += b[j] if s == 0 and q == 0: p += j + 1 - 1 c[0] = j q = 1 else: if s in c.keys(): k = c[s] q = max(q, k + 2) c[s] = j p += j + 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUM...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
from sys import stdin input = stdin.readline R = lambda: list(map(int, input().split())) n, a = int(input()), R() mp, sm = {(0): -1}, 0 cc, pp = 0, 0 for i in range(n): sm += a[i] p = mp[sm] + 2 if sm in mp else 0 if a[i] == 0: p = i + 1 mp[sm] = i pp = max(pp, p) cc += i - pp + 1 print...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR DICT NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
from sys import gettrace, stdin if not gettrace(): def input(): return next(stdin)[:-1] def main(): n = int(input()) aa = [int(a) for a in input().split()] saa = [(0, 0)] * (n + 1) sa = 0 for i, a in enumerate(aa, 1): sa += a saa[i] = sa, i saa.sort() zranges ...
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = sys.stdin.readline a = int(input()) b = list(map(int, input().split())) c = [0] su = 0 for i in b: su += i c.append(su) ans = 0 thing = {} temp = 0 for i in range(a + 1): if i != 0: try: temp = min(i - thing[c[i]] - 1, temp + 1) ans += temp except:...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER AS...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = [int(x) for x in input().split()] arr.insert(0, 0) mp = {(0): 0} sol = n * (n + 1) // 2 acum = 0 index = -1 for i in range(1, n + 1): acum += arr[i] if acum in mp: index = max(index, mp[acum]) mp[acum] = i sol -= index + 1 print(sol)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR A...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) tmp = 0 dic = {(0): 1} ans = 0 least = 0 for i, a in enumerate(A): tmp += a if a == 0: least = i + 1 continue elif tmp in dic: least = max(least, dic[tmp]) ans += i + 1 - least dic[tmp...
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 NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) nums = list(map(int, input().split())) prefixSum = [] for i in range(n): if i == 0: prefixSum.append(nums[0]) else: prefixSum.append(prefixSum[i - 1] + nums[i]) next_val = {} ans = 0 r_max = n - 1 for i in range(n - 1, -1, -1): next_val[prefixSum[i]] = i if i == 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 LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR F...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
from sys import stdin n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) ans = [0] * n sums = list() sums.append(0) for i in range(n): sums.append(sums[i] + a[i]) ans = 0 ri = 0 s = set() done = False for i in range(n): for j in range(ri, n + 1): if sums[j] in s: ri = 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 BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solution(n, array): memo = {(0): 0} addptr = 0 maxptr = 0 ans = 0 for i in range(1, n + 1): addptr += array[i] if addptr in memo: maxptr = max(maxptr, memo[addptr] + 1) memo[addptr] = i ans += i - maxptr return ans print(solution(int(input()), [0...
FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = [int(x) for x in input().split()] for i in range(1, n): a[i] += a[i - 1] dic = {} dic[0] = 0 ans = 0 maximum = -1 for i in range(n): val = dic.get(a[i], -1) maximum = max(maximum, val) ans += i - maximum dic[a[i]] = i + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = sys.stdin.readline n = int(input()) + 1 a = [0] + list(map(int, input().split())) def init_min(init_min_val): for i in range(n): seg_min[i + num_min - 1] = init_min_val[i] for i in range(num_min - 2, -1, -1): seg_min[i] = min(seg_min[2 * i + 1], seg_min[2 * i + 2]) def up...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = sys.stdin.readline n = int(input()) L = list(map(int, input().split())) M = [0] for i in L: M.append(M[-1] + i) d = dict() cklist = [-1] * n ckd = -1 for i in range(n + 1): if M[i] not in d: d[M[i]] = [i] else: for j in range(ckd + 1, d[M[i]][-1] + 1): if ckli...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = lambda: sys.stdin.readline().rstrip() def I(): return list(map(int, input().split())) n = I()[0] a = I() d = {(0): -1} last = -1 s = [a[0]] ans = 0 for i in range(1, n): s.append(a[i] + s[-1]) for i in range(len(s)): if s[i] in d: last = max(last, d[s[i]] + 1) d[s[i]] = i...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN 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 DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(a, n): s = 0 sums = {} sums[0] = 0 p = 0 ans = 0 subarrs = [] for x in range(n): s = s + a[x] if sums.get(s) == None: sums[s] = x + 1 else: if sums[s] + 1 >= p: subarrs.append((sums[s] + 1, x + 1)) p = ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMB...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) l = list(map(int, input().split())) for i in range(1, len(l)): l[i] = l[i] + l[i - 1] count = 0 used = 0 d = {} d[0] = 0 for i in range(0, n): if l[i] in d: used = max(used, d[l[i]] + 1) count += i + 1 - used d[l[i]] = i + 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) ans = 0 st = {0} cum_a = 0 idx_l = 0 cum_A = [0] for idx_r, a in enumerate(A): cum_a += a cum_A.append(cum_a) while cum_a in st: st.remove(cum_A[idx_l]) idx_l += 1 st.add(cum_a) ans += idx_r -...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(a): n = len(a) prefix = [0] * (n + 1) for i in range(n): prefix[i + 1] = prefix[i] + a[i] begin, end = 0, 0 res = 0 s = set([0]) while begin < n: while end < n and prefix[end + 1] not in s: end += 1 s.add(prefix[end]) res += end - beg...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER WHILE VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FU...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) d = {} ar = list(map(int, input().split())) pref = [0] * n ans = 0 d = {} uk = -1 pref[0] = ar[0] d[0] = -1 for i in range(1, n): pref[i] = pref[i - 1] + ar[i] for i in range(n): if pref[i] in d: uk = max(uk, d.get(pref[i]) + 1) ans += i - uk d[pref[i]] = i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def solve(a, size): hash_map = {(0): 0} track_sum = 0 bad_comb = 0 total = 0 for i in range(1, size + 1): track_sum += a[i - 1] if track_sum in hash_map: bad_comb = max(bad_comb, hash_map[track_sum] + 1) elif track_sum == 0: bad_comb = max(bad_comb, 1)...
FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR RETU...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) array = [int(s) for s in input().split()] prefs = {} s = 0 left = 0 ans = 0 for i in range(1, len(array) + 1): s += array[i - 1] if array[i - 1] == 0: left = max(i, left) elif s == 0: if 0 not in prefs: left = max(1, left) else: left = max(1, ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) lis = list(map(int, input().split())) pre = [0] * (n + 1) for i in range(1, n + 1): pre[i] = pre[i - 1] + lis[i - 1] d = {} ans = l = 0 for i in range(n + 1): if pre[i] not in d: d[pre[i]] = i else: l = max(l, d[pre[i]] + 1) d[pre[i]] = i ans += i - l print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR FUNC_CA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) sp = list(map(int, input().split())) pref = [0] * (n + 1) for i in range(n): pref[1 + i] = pref[i] + sp[i] i = 1 while i < n + 1: if pref[i] != 0: break i += 1 if i == n + 1: print(0) exit() d = dict() d[pref[i]] = i ans = 1 d[0] = 0 proshn = i - 1 for j in range(i + 1, n + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def main(): n = int(input()) a = [int(i) for i in input().split(" ")] p = [0] * (n + 1) s = set() ans = 0 for i in range(n): p[i + 1] = p[i] + a[i] s.add(0) end = 0 for i in range(n): while end < n and p[end + 1] not in s: end += 1 s.add(p[end]...
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NU...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = list(map(int, input().split())) pref = [(0) for i in range(n + 1)] for i in range(n): pref[i + 1] = pref[i] + a[i] d = {} d[0] = 0 ans = 0 used = 0 for i in range(1, n + 1): if pref[i] in d: used = max(used, d[pref[i]] + 1) ans += i - used d[pref[i]] = i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) u = list(map(int, input().split())) d = dict() p = [] d[u[0]] = 0 if u[0] == 0: p.append((0, 0)) else: d[0] = -1 w = [0] * n for i in range(1, n): u[i] += u[i - 1] if u[i] in d.keys(): st, fn = d[u[i]] + 1, i p.append((st, fn)) w[fn] = len(p) d[u[i]] = i 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 ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = list(map(int, input().split())) s = 0 mi = -1 c = {(0): -1} su = 0 for i in range(n): if a[i] == 0: c = {(0): i} su = 0 mi = i else: su += a[i] if su in c: mi = max(mi, c[su] + 1) c[su] = i s += i - mi print(s)
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 DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR DICT NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASS...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = list(map(int, input().split())) aux = [0] * (n + 1) for i in range(n): aux[i + 1] = aux[i] + a[i] total = 0 l = 0 r = 0 s = set({}) d = {} while r <= n: if aux[r] in s and l <= d[aux[r]]: total += (r - l) * (r - l - 1) // 2 - (r - d[aux[r]] - 1) * ( r - d[aux[r]] - 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR DICT ASSI...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = list(map(int, input().split(" "))) prefix_sum = [0] prefix_set = set() prefix_set.add(0) for i in range(len(arr)): prefix_sum.append(prefix_sum[i] + arr[i]) i, j, results = 0, 0, 0 while i < n: while j < n and prefix_sum[j + 1] not in prefix_set: j += 1 prefix_set.add(pref...
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 LIST NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
from sys import stdin n = int(stdin.readline()) cnt = 0 bad = -1 currsum = 0 suffixes = {(0): 0} for i, x in enumerate(map(int, stdin.readline().split())): currsum += x bad = max(bad, suffixes.get(currsum, -1)) cnt += i - bad suffixes[currsum] = i + 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL ...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) l = list(map(int, input().split())) s = set() s.add(0) pre = [0] for i in range(n): pre.append(pre[-1] + l[i]) i = 0 j = 0 ans = 0 while i < n: while j < n and pre[j + 1] not in s: j += 1 s.add(pre[j]) ans += j - i if pre[i] in s: s.remove(pre[i]) i += 1 prin...
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR W...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) kk = dict() s = [int(x) for x in input().split()] L = [0] kk[0] = -1 rngs = [-1] * (n + 10) rnge = [-1] * (n + 10) c = 1 for i in range(0, len(s)): L.append(L[-1] + s[i]) if kk.get(L[-1]) != None: rngs[kk[L[-1]] + 1] = c rnge[i] = c c += 1 kk[L[-1]] = i ans = 0 ptr =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CAL...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = [int(i) for i in input().split()] for i in range(1, n): arr[i] += arr[i - 1] dic = {} dic[0] = [-1] for i in range(n): if arr[i] in dic: dic[arr[i]].append(i) else: dic[arr[i]] = [i] temp = [0] * n endly = {} for a in dic: if len(dic[a]) >= 2: for i in rang...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR BIN_...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) prefix = [0] * (n + 1) for i, x in enumerate(input().split()): x = int(x) prefix[i + 1] = prefix[i] + x begin = 0 end = 0 ans = 0 s = {0} while begin < n: while end < n and prefix[end + 1] not in s: end += 1 s.add(prefix[end]) ans += end - begin s.remove(prefix[begin...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR BI...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) arr = [int(c) for c in input().split()] arr.insert(0, 0) sumsofar = 0 dic = {(0): 0} h = -1 ans = 0 for i in range(1, n + 1): sumsofar = sumsofar + arr[i] if sumsofar in dic: h = max(h, dic[sumsofar]) ans += i - h - 1 dic[sumsofar] = i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CAL...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
import sys n = int(input()) l = list(map(int, input().split())) p = [0] * (n + 1) for i in range(1, n + 1): p[i] = p[i - 1] + l[i - 1] secik = set() pr = 0 le = 0 p += [p[-1]] n += 1 odp = 0 while True: if le == n: print(odp) break if len(secik) == pr - le: secik.add(p[pr]) ...
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASS...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) a = list(map(int, input().split())) mp = dict() mp[0] = -1 pre = 0 mx = -1 ans = 0 for i in range(n): pre += a[i] ok = mp.get(pre, "Huh") if ok == "Huh": ans += i - mx mp[pre] = i else: if mx < ok + 1: mx = ok + 1 ans += i - mx mp[pre] = 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 ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING IF VAR STRING VAR BIN_OP VAR VAR ASS...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def I(): return list(map(int, input().split())) def sieve(n): a = [1] * n for i in range(2, n): if a[i]: for j in range(i * i, n, i): a[j] = 0 return a n = int(input()) arr = I() l = -1 d = {(0): -1} prefix = [0] * (n + 1) prefix[0] = arr[0] ans = 0 for i in range...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER A...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
from itertools import accumulate n = int(input()) a = [int(x) for x in input().split()] sums = [0] + list(accumulate(a)) s = {0} i, j = 0, 0 ans = 0 while i < n: while j < n and sums[j + 1] not in s: s.add(sums[j + 1]) j += 1 ans += j - i s.remove(sums[i]) i += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VA...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
def sumoflength(arr, n): s = set() j = 0 ans = 0 for i in range(n): while j < n and arr[j] not in s: s.add(arr[j]) j += 1 ans += j - i - 1 s.remove(arr[i]) return ans n = int(input().strip()) numbers = list(map(int, input().strip().split())) prefsum ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR V...
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
n = int(input()) ls = [int(x) for x in input().split()] presum = [0] for e in ls: presum.append(e + presum[-1]) height = {} ints = [] for i, s in enumerate(presum): if s not in height: height[s] = i - 1 else: ints.append((height[s], i - 1)) height[s] = i - 1 ints.append((len(ls), len...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMB...