Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- theCache = defaultdict(int)
- def isHor(arr, i, j):
- for ci, cj in theCache.keys():
- if i <= ci and j >= cj and theCache[(ci, cj)]:
- return 0
- chsum = []
- for k in range(i, j + 1):
- if len(chsum) == 0:
- chsum.append(arr[k])
- else:
- chsum.append(chsum[-1] + arr[k])
- lol = defaultdict(int)
- for e in chsum:
- lol[e] += 1
- k = 1
- for ii in lol.keys():
- if lol[ii] > 1:
- k = 0
- if lol[0]:
- k = 0
- if k == 0:
- theCache[(i, j)] = 1
- return k
- def kek():
- n = int(input())
- arr = list(map(int, input().split()))
- countHor = 0
- for i in range(n):
- for j in range(i, n):
- countHor += isHor(arr, i, j)
- #print(theCache)
- print(countHor)
- def main():
- kek()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement