Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import math
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def pop2(li):
	c=1
	i=li.pop(0)
	while 1:
		j=li.pop(0)
		if j==i:
			c+=1
		else:
			break
	return i,c,[j]+li

n = readInt()
a = readInts()

li = []
ri = []

for i in range(n):
	li.append(i+a[i])
	ri.append(i-a[i])

li.sort()
ri.sort()

res = 0

tar = list(set(li)&set(ri))

for i in tar:
	res+=li.count(i)*ri.count(i)

print(res)

### FIXED CODE ###

import math
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def pop2(li):
	c=1
	i=li.pop(0)
	while 1:
		j=li.pop(0)
		if j==i:
			c+=1
		else:
			break
	return i,c,[j]+li

n = readInt()
a = readInts()

li = []
ri = []

d1 = defaultdict(int)
d2 = defaultdict(int)

for i in range(n):
	d1[i+a[i]]+=1
	d2[i-a[i]]+=1

ans = 0

for key in d1:
	ans+=d1[key]*d2[key]

print(ans)
### BUGGY CODE ###

N = int(input())
S = ['']* N
for i in range(N):
    S[i] = input()

S_ = [[0] * 26] * N

alphabet = "abcdefghijklmnopqrstuvwxyz"

for j in range(N):
    temp = []
    for i in range(26):
        temp.append(S[j].count(alphabet[i]))
    S_[j] = temp

ans = 0

for i in reversed(range(1,N)):
    for j in range(i):
        if S_[i] == S_[j]:
            ans += 1

print(ans)

### FIXED CODE ###

from collections import defaultdict
Sdic = defaultdict(int)

N = int(input())
S = ['']* N
ans = 0
for i in range(N):
    Sdic[str(sorted(input()))] += 1

for i in Sdic.keys():
    ans += (Sdic[i] * (Sdic[i] - 1)) // 2

print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
x = 0
for i in range(N-1):
    for j in range(i+1,N):
        x += (A[i] ^ A[j]) 
        x = x % (10**9 + 7)

print (x)

### FIXED CODE ###

import math
N = int(input())
A = list(map(int,input().split()))
b = [[0]*60 for i in range(2)]
#max_a = math.ceil(math.log(max(A),2))
max_a = 60
for i in range(N):
    x = A[i]
    j = 0
    for j in range(max_a):
        b[x % 2][j] += 1
        x //= 2

x = 0
for i in range(max_a):
    x += b[0][i] * b[1][i] * 2**i
    x %= 10 ** 9 + 7

print (x)
### BUGGY CODE ###

N = int(input())
s=[]
for i in range(N):
  s.append(input())
num = 0

while(len(s) != 0):
  flag = 0
  a = s[0]
  num += 1
  for i in range(len(s)):
    if(s[0] == s[i]):
      flag += 1
  for i in range(flag):
    s.remove(a)
    
print(num)

### FIXED CODE ###

import collections
N = int(input())
s=[]
for i in range(N):
  s.append(input())
c = collections.Counter(s)
 
print(len(c))
### BUGGY CODE ###

n = int( input() )

ans = 0

while n != 0:
    ans += n % 10
    n = n // 10

if ans % 9 == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = list(input())

ans = 0

for i in range(len(n)):
    ans += int(n[i])

if ans % 9 == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    h, w = list(map(int, readline().split()))
    a = [["."] * w for _ in range(h)]
    ql = []
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    for i in range(h):
        s = str(readline().rstrip().decode('utf-8'))
        for j in range(w):
            if s[j] == "#":
                a[i][j] = "#"
                ql.append([0, i, j])
                fq[i, j]

    mt = 0
    while True:
        if len(ql) != 0:
            cost, x, y = ql.popleft()
            mt = max(mt, cost)
            for xv, yv in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if (xv, yv) not in fq and a[xv][yv] == ".":
                        ql.append([cost + 1, xv, yv])
                        fq[xv, yv]
        else:
            break
    print(mt)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    h, w = list(map(int, readline().split()))
    a = [[True] * w for _ in range(h)]
    ql = collections.deque()
    for i in range(h):
        s = list(str(readline().rstrip().decode('utf-8')))
        for j in range(w):
            if s[j] == "#":
                ql.append([0, i, j])
                a[i][j] = False
    while ql:
        cost, x, y = ql.popleft()
        for xv, yv in ((x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)):
            if 0 <= xv < h and 0 <= yv < w:
                if a[xv][yv]:
                    ql.append([cost + 1, xv, yv])
                    a[xv][yv] = False
    print(cost)


if __name__ == '__main__':
    solve()
### BUGGY CODE ###

n = int(input())
li = list(map(int,input().split()))
count = 0
for i in range(n-1):
    for ii in range(i+1,n):
        count += li[i]*li[ii]%(10**9+7)
print(count%(10**9 + 7))

### FIXED CODE ###

n = int(input())
li = list(map(int,input().split()))
count = 0
sum = sum(li)
for i in range(n-1):
    sum -= li[i]
    count += (sum)*li[i]%(10**9+7)
print(count%(10**9 + 7))
### BUGGY CODE ###

# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))


N = int(input())
A = list(map(int, input().split()))

nA = [ Ai - (i+1) for i, Ai in enumerate(A)]
max_A = max(nA)
min_A = min(nA)

ans = 10e9

for i in range(min_A, max_A+1):
    tmp = sum([ abs(Ai - i) for Ai in nA ])
    if tmp < ans:
        ans = tmp

print(ans)



### FIXED CODE ###

# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))


def res(nA, i):
    for i in range(min_A, max_A+1):
        tmp = sum([ abs(Ai - i) for Ai in nA ])
    if tmp < ans:
        ans = tmp
    return ans

N = int(input())
A = list(map(int, input().split()))

nA = sorted([ Ai - (i+1) for i, Ai in enumerate(A)])
ans = 10e9

if len(nA) % 2 != 0:
    print(sum([ abs(Ai - nA[len(nA)//2]) for Ai in nA ]))
else:
    print(min(sum([ abs(Ai - nA[len(nA)//2-1]) for Ai in nA ]), sum([ abs(Ai - nA[len(nA)//2]) for Ai in nA ])))
### BUGGY CODE ###

n,q = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
D = [int(input()) for i in range(q)]

E = []
F = {}
for i in range(n):
    s = A[i][0]
    t = A[i][1]
    x = A[i][2]
    F[x] = 0
    E.append((s-x, x, 1))
    E.append((t-x, x, -1))
E.append((10**10, 10**10, 1))

E.sort()

# print(E)

from heapq import heappush, heappop
Q = []

for i in range(q):
    j = 0
    while E[j][0] <= D[i]:
        if E[j][2] == 1:
            F[E[j][1]] = 1
            heappush(Q, E[j][1])
        else:
            F[E[j][1]] = 0
        j += 1
    
    while len(Q) > 0 and F[Q[0]] == 0:
        _ = heappop(Q)
    if len(Q) == 0:
        print(-1)
    else:
        print(Q[0])


### FIXED CODE ###

import sys
input = sys.stdin.readline
n,q = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
D = [int(input()) for i in range(q)]

E = []
F = {}
for i in range(n):
    s = A[i][0]
    t = A[i][1]
    x = A[i][2]
    F[x] = 0
    E.append((s-x, x, 1))
    E.append((t-x, x, -1))
E.append((10**10, 10**10, 1))

E.sort()

# print(E)

from heapq import heappush, heappop
Q = []

j = 0
for i in range(q):
    # print(F,j)
    while E[j][0] <= D[i]:
        if E[j][2] == 1:
            F[E[j][1]] += 1
            heappush(Q, E[j][1])
        else:
            F[E[j][1]] -= 1
        j += 1
    
    while len(Q) > 0 and F[Q[0]] == 0:
        _ = heappop(Q)
    if len(Q) == 0:
        print(-1)
    else:
        print(Q[0])
### BUGGY CODE ###

N, W = map(int, input().split())
wv = [[0 for i in range(2)] for j in range(N)]

for i in range(N):
    w, v = map(int, input().split())
    wv[i] = [w, v]

dp = [[10**10 for i in range(2*10**6)] for j in range(2*N)]
dp[0][0] = 0

for i in range(N):
    for j in range(10**6):
        if j - wv[i][1] >= 0:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j-wv[i][1]]+wv[i][0])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans = 0
for i in range(10**6):
    if dp[N][i] <= W: 
        ans = i
print(ans)

### FIXED CODE ###

N, W = map(int, input().split())
wv = [[0 for i in range(2)] for j in range(N)]

for i in range(N):
    w, v = map(int, input().split())
    wv[i] = [w, v]

dp = [[10**10 for i in range(10**5+100)] for j in range(150)]
dp[0][0] = 0

for i in range(N):
    for j in range(10**5+100):
        if j - wv[i][1] >= 0:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j-wv[i][1]]+wv[i][0])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans = 0
for i in range(10**5+100):
    if dp[N][i] <= W: 
        ans = i
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
import bisect

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    pos = [0]*N
    
    for i,num in enumerate(a):
        pos[a[i]-1] = i+1

    l = [0,N+1]
    ans = 0
    for i in range(N):
        p = pos[i]
        ind = bisect.bisect(l,p)
        bisect.insort(l,p)
        ans += (p-l[ind-1])*(l[ind+1]-p)*(i+1)
        
    print(ans)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
	
	class BinaryIndexedTree:
		
		# 初期化
		def __init__(self, size, default):
			self.size = size
			self.default = default
			self.BIT = [default]*(self.size+1)

		# function(max, min, plus, minus, etc...)
		def BIT_segfunc(self, x, y):
			return max(x, y)

		def BIT_query(self, idx):
			ret = self.default
			while idx > 0:
				ret = self.BIT_segfunc(ret, self.BIT[idx])
				idx -= idx&(-idx)
			return ret

		# update
		def BIT_update(self, idx, x):
			while idx <= self.size:
				self.BIT[idx] = self.BIT_segfunc(self.BIT[idx], x)
				idx += idx&(-idx)
			return

		def BIT_range(self, x, y):
			return self.BIT_query(y)-self.BIT_query(x)

		# seg確認用
		def BIT_print(self):
			print(self.BIT)
		
	N = int(input())
	a = list(map(int,input().split()))
	l = [0]*N;r = [0]*N
	left_bit = BinaryIndexedTree(N, 0)
	for i, num in enumerate(a):
	    l[num-1] = i + 1 - left_bit.BIT_query(num)
	    left_bit.BIT_update(num, i+1)
	right_bit = BinaryIndexedTree(N, 0)
	for i, num in enumerate(a[::-1]):
	    r[num-1] = i + 1 - right_bit.BIT_query(num)
	    right_bit.BIT_update(num, i+1)
	
	print(sum(l[i]*r[i]*(i+1) for i in range(N)))

if __name__ == "__main__":
	main()
### BUGGY CODE ###

n, k  = map(int, input().split())
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

# dp[i][j] i人目までの子供にj個のアメを配る数
dp = [[0] * (ｋ + 1) for _ in range(n + 1)]

for i in range(n + 1):
  dp[i][0] = 1
  
for i in range(1, n + 1):
  for j in range(1, k + 1):
    if j-1-A[i-1] >= 0:
      dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1-A[i-1]]) % MOD
    else:
      dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD

ans = dp[n][k]
print(ans)


### FIXED CODE ###

n, k  = map(int, input().split())
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

# dp[i][j] i人目までの子供にj個のアメを配る数
dp = [[0] * (ｋ + 1) for _ in range(n + 1)]

for i in range(n + 1):
  dp[i][0] = 1
  
for i in range(1, n + 1):
  for j in range(1, k + 1):
    if j-1-A[i-1] >= 0:
      dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1-A[i-1]]) % MOD
    else:
      dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD

ans = dp[n][k]
print(ans)
### BUGGY CODE ###

import sys
import itertools

input = sys.stdin.readline
X = int(input())
#a = [int(i) for i in input().split()] 
#e = [[int(i) for i in input().split()] for i in range(n)] 

maxtimes = int(X/100)+1
pools = itertools.product(range(maxtimes), repeat=6)

for comb in pools:
    c = list(comb)
    price = c[0]*100+c[1]*101+c[2]*102+c[3]*103+c[4]*104+c[5]*105
    if price == X:
        print(1)
        exit()

print(0)


### FIXED CODE ###

import sys
import itertools

input = sys.stdin.readline
X = int(input())
#a = [int(i) for i in input().split()] 
#e = [[int(i) for i in input().split()] for i in range(n)] 

maxtimes = int(X/100)+2
price = 0
for i1 in range(0, maxtimes):
    #if i1*100 > X:
        #break
    for i2 in range(0, int(X/101)+2):
        #if i1*100+i2*101 > X:
            #break
        for i3 in range(0, int(X/102)+2):
            #if i1*100+i2*101+i3*102 > X:
                #break
            for i4 in range(0, int(X/103)+2):
                #if i1*100+i2*101+i3*102+i4*103 > X:
                    #break
                for i5 in range(0, int(X/104)+2):
                    #if i1*100+i2*101+i3*102+i4*103+i5+104 > X:
                        #break
                    for i6 in range(0, int(X/105)+2):
                        price = i1*100+i2*101+i3*102+i4*103+i5*104+i6*105
                        #print(i1, i2, i3, i4, i5, i6)
                        if price == X:
                            print(1)
                            exit()
                        elif price > X:
                            break

print(0)
### BUGGY CODE ###

N = int(input())
A = [int(_) for _ in input().split()]
dp = [-1] * (N + 1)
count = [0] * N
for i in range(N):
    count[i] = i - dp[A[i]]
    dp = dp[:A[i]] + [i] * (N - A[i] + 1)
dp_r = [N] * (N + 1)
ans = 0
for i in range(N - 1, -1, -1):
    ans += A[i] * (dp_r[A[i]] - i) * count[i]
    dp_r = dp_r[:A[i]] + [i] * (N - A[i] + 1)
print(ans)


### FIXED CODE ###

N = int(input())
A = [int(_) for _ in input().split()]
left = list(range(N + 2))
right = list(range(N + 2))
index = {A[i - 1]: i for i in range(1, N + 1)}
ans = 0
for a in range(N, 0, -1):
    i = index[a]
    l = left[i]
    r = right[i]
    ans += a * (i - l + 1) * (r - i + 1)
    left[r + 1] = l
    right[l - 1] = r
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())

a=list(map(int,input().split()))

visited=[0]*n
if k<=n:
    now=0
    nex=0
    loop_start=0
    target=0

    for i in range(n):
        now=nex
        visited[now]+=1
        nex=a[now]-1
        if i+1==k:
            print(nex+1)
            exit()
now=0
nex=0
loop_start=0
target=0
lis=[]
flag=False

for i in range(2*n):
    now=nex
    visited[now]+=1
    nex=a[now]-1
    if flag:
        if now+1 not in lis:
           lis.append(now+1)
           continue
        else:
            break
    if visited[now]==2:
        loop_start=i
        target=now+1
        lis.append(now+1)
        flag=True


dif=len(lis)
first=loop_start-dif
k-=first
print(lis[k%dif])






### FIXED CODE ###

n,k=map(int,input().split())

a=list(map(int,input().split()))

visited=[0]*n
if k<=n:
    now=0
    nex=0
    loop_start=0
    target=0

    for i in range(n):
        now=nex
        visited[now]+=1
        nex=a[now]-1
        if i+1==k:
            print(nex+1)
            exit()
now=0
nex=0
loop_start=0
target=0
lis=[]
s=set()
flag=False

for i in range(2*n):
    now=nex
    visited[now]+=1
    nex=a[now]-1
    if flag:
        if now+1 not in s:
           lis.append(now+1)
           s.add(now+1)
           continue
        else:
            break
    if visited[now]==2:
        loop_start=i
        target=now+1
        lis.append(now+1)
        s.add(now+1)
        flag=True


dif=len(lis)
first=loop_start-dif
k-=first
print(lis[k%dif])
### BUGGY CODE ###

s = input()
dp = [0]*(len(s)+1)

for n in range(len(s)):
  dp[n+1] = (dp[n]+int(s[-n-1])*(10**n))%2019

count=0
for i in range(2019):
  m=dp.count(i)
  count += m*(m-1)/2
 
print(int(count))

### FIXED CODE ###

s = input()[::-1]

dp = [0]*2019
dp[0]=1
total = 0
a = 1

for i in list(s):
  total += int(i)*a
  total %= 2019
  dp[total] += 1
  a *= 10
  a %= 2019
count=0
  
for i in range(2019):
    count += dp[i]*(dp[i]-1)//2
 
print(count)
### BUGGY CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  s=S()
  n=len(s)
  s=s[::-1]

  rl=[0]*(n+1)
  for i,x in enumerate(s):
    rl[i+1]=(int(x)*(10**i))%2019

  for i in range(n):
    rl[i+1]+=rl[i]
    rl[i+1]%=2019

  # print(rl[1:])

  sl=summarizeList(rl[1:])

  ans=0
  for x,c in sl:
    if x==0:
      ans+=c

    elif c>1:
      ans+=(c+c-1)//2

  return ans

# main()
print(main())


### FIXED CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  s=S()
  n=len(s)
  s=s[::-1]

  rl=[0]*(n+1)
  for i,x in enumerate(s):
    rl[i+1]=(int(x)*pow(10,i,2019))%2019

  for i in range(n):
    rl[i+1]+=rl[i]
    rl[i+1]%=2019


  sl=summarizeList(rl)
  # print(sl)

  ans=0
  for x,c in sl:
    ans+=(c*(c-1))//2

  return ans

# main()
print(main())
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
s=[0]
for i in range(n):
    s.append(s[-1]+A[i])
cnt=0
for i in range(n):
    for j in range(i+1,n+1):
        if s[i]==s[j]:
            cnt+=1
print(cnt)


### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
s=[0]
for i in range(n):
    s.append(s[-1]+A[i])
s.sort()
ans=0
cnt=1
for i in range(1,n+1):
    if s[i-1]==s[i]:
        cnt+=1
    else:
        if 2<=cnt:
            ans+=(cnt*(cnt-1))//2
            cnt=1
        else:
            cnt=1
if 2<=cnt:
    ans+=(cnt*(cnt-1))//2
print(ans)
### BUGGY CODE ###

import math
A,B,N=(int(x) for x in input().split())
p=0
for i in range (N+1):
    j=(math.floor((A*i)/B))-(math.floor(i/B))*A
    if p<j:p=j
print(p)


### FIXED CODE ###

import math
A,B,N=(int(x) for x in input().split())
if N<B:i=N
else:i=B-1
p=(math.floor((A*i)/B))
print(p)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Mar 17 09:02:00 2019
DPF
@author: maezawa
"""

s = input()
t = input()

ns = len(s)
nt = len(t)

dp = [['' for _ in range(nt+1)] for _ in range(ns+1)]

for si in range(ns):
    for ti in range(nt):
        if s[si] == t[ti]:
            arr = [dp[si][ti]+s[si], dp[si+1][ti], dp[si][ti+1]]
        else:
            arr = [dp[si+1][ti], dp[si][ti+1]]
        arr.sort(key=lambda x: len(x), reverse=True)
        dp[si+1][ti+1] = arr[0]
        
print(dp[ns][nt])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Mar 17 09:02:00 2019
DPF3
@author: maezawa
"""

s = input()
t = input()

ns = len(s)
nt = len(t)

dp = [[0 for _ in range(nt+1)] for _ in range(ns+1)]

for si in range(ns):
    for ti in range(nt):
        if s[si] == t[ti]:
            dp[si+1][ti+1] = max(dp[si][ti]+1, dp[si+1][ti], dp[si][ti+1])
        else:
            dp[si+1][ti+1] = max(dp[si+1][ti], dp[si][ti+1])

ans = ''
si = ns
ti = nt
while si > 0 and ti > 0:
    if dp[si][ti] == dp[si-1][ti]: 
        si -= 1
    elif dp[si][ti] == dp[si][ti-1]:
        ti -= 1
    else:
        ans = s[si-1] + ans
        si -= 1
        ti -= 1

print(ans)
### BUGGY CODE ###

n = int(input())

nums = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += nums[i] * sum(nums[i+1:])

print(ans % (10**9+7))

### FIXED CODE ###

n = int(input())

nums = list(map(int, input().split()))

ans = 0
s = sum(nums)
for i in range(n):
    s -= nums[i]
    ans += nums[i] * s

print(ans % (10**9+7))
### BUGGY CODE ###

import numpy as np

N = input().split()
n= int(N[0])
m = int(N[1])
way = [[0] * n  for _ in range(n+1)]
count = 0
h = input().split()
ans = 0
w =0
r =[0]*n
for i in h:
    way[0][count] = int(i)
    count += 1

for j in range(m):
    a = input().split()
    b = int(a[0])
    c = int(a[1])
    if way[0][b-1]>way[0][c-1]:
        r[b-1] += 1
        r[c-1] = -1000000
    elif way[0][c-1]>way[0][b-1]:
        r[c-1] += 1
        r[b-1] = -1000000
    else:
        r[b-1] = -1000000
        r[c-1] = -1000000
print(sum(x>=0 for x in r))

### FIXED CODE ###

import numpy as np

N = input().split()
n= int(N[0])
m = int(N[1])
way = np.zeros(n)
count = 0
h = input().split()
ans = 0
w =0
r = np.zeros(n)

for j in range(m):
    a = input().split()
    b = int(a[0])
    c = int(a[1])
    if int(h[b-1])>int(h[c-1]):
        r[b-1] += 1
        r[c-1] = -1000000
    elif int(h[c-1])>int(h[b-1]):
        r[c-1] += 1
        r[b-1] = -1000000
    else:
        r[b-1] = -1000000
        r[c-1] = -1000000
print(np.count_nonzero(r>=0))
### BUGGY CODE ###

from itertools import combinations, permutations

n = int(input())
balls = []
cost = n
for _ in range(n):
    x, y = map(int, input().split())
    balls.append((x, y))

for b1, b2 in permutations(balls, 2):
    p, q = b1[0] - b2[0], b1[1] - b2[1]
    if p != 0 or q != 0:
        sub = 0
        for b3, b4 in permutations(balls, 2):
            dx, dy = b3[0] - b4[0], b3[1] - b4[1]
            if dx == p and dy == q:
                sub += 1
        cost = min(cost, n - sub)

print(max(cost, 1))

### FIXED CODE ###

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

dic = dict()
for cx, cy in xy:
    for x, y in xy:
        if cx != x or cy != y:
            w = (x-cx,y-cy)
            if dic.get(w) is None:
                dic[w] = 0
            dic[w] += 1

cnt = 1
m = 0
for x in dic:
    m = max(m, dic[x])
cnt += N - 1 - m
print(cnt)