1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys

input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))

n = inp()
    
ciag = inlt()

buc = []


for suma in range(1, len(ciag) + 1):
    for j in range(len(ciag) - suma + 1):
        buc.append(sum([ciag[k] for k in range(j, j+suma)]))

ujemne = [i for i in buc if i < 0]
dodatnie = [i for i in buc if i > 0]
zera = [i for i in buc if i == 0]


ile = int(len(zera) * (len(zera) - 1) * (len(zera) - 2) / 6)

if len(zera) > 0:
    for i in ujemne:
        ile = ile + len(zera) * dodatnie.count(-i)

pary_dodatnich = []
for i in range(len(dodatnie)):
    for j in range(i+1, len(dodatnie)):
        #print(dodatnie[i], dodatnie[j], dodatnie[i] + dodatnie[j])
        pary_dodatnich.append(dodatnie[i] + dodatnie[j])

pary_ujemnych = []
for i in range(len(ujemne)):
    for j in range(i+1, len(ujemne)):
        #print(ujemne[i], ujemne[j], ujemne[i] + ujemne[j])
        pary_ujemnych.append(ujemne[i] + ujemne[j])

for i in set(dodatnie):
    if -i in set(pary_ujemnych):
        ile = ile + dodatnie.count(i) * pary_ujemnych.count(-i)

for i in set(ujemne):
    if -i in set(pary_dodatnich):
        ile = ile + ujemne.count(i) * pary_dodatnich.count(-i)

print (ile)