Advertisement
Guest User

asdsadasd

a guest
Apr 8th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. from collections import defaultdict
  2.  
  3. def isHor(arr, i, j):
  4.     chsum = []
  5.     for k in range(i, j + 1):
  6.         if len(chsum) == 0:
  7.             chsum.append(arr[k])
  8.         else:
  9.             chsum.append(chsum[-1] + arr[k])
  10.  
  11.     lol = defaultdict(int)
  12.     for e in chsum:
  13.         lol[e] += 1
  14.  
  15.     k = 1
  16.     for ii in lol.keys():
  17.         if lol[ii] > 1:
  18.             k = 0
  19.     if lol[0]:
  20.         k = 0
  21.  
  22.     return k
  23.  
  24. def kek():
  25.     n = int(input())
  26.     arr = list(map(int, input().split()))
  27.  
  28.     countHor = 0
  29.     for i in range(n):
  30.         for j in range(i, n):
  31.             countHor += isHor(arr, i, j)
  32.     print(countHor)
  33.  
  34. def main():
  35.     kek()
  36.  
  37. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement