Input:
N = int(input())

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

answer = 10 ** 9

for i in range(1,101):

    tmp = 0

    for a in A:

        tmp += abs(a-i) ** 2

    answer = min(answer,tmp)

print(answer)

N = int(input())

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

chushin = sum(A)//N

chushin_1 = sum(A)//N +1

answer = 0

answer_1 = 0

for a in A:

    answer += abs(a-chushin) ** 2

    answer_1 += abs(a-chushin_1) ** 2

print((min(answer,answer_1)))

N = int(input())
A = list(map(int, input().split()))
answer = 10**9
for i in range(1, 101):
    tmp = 0
    for a in A:
        tmp += abs(a - i) ** 2
    answer = min(answer, tmp)
print(answer)

N = int(input())
A = list(map(int, input().split()))
chushin = sum(A) // N
chushin_1 = sum(A) // N + 1
answer = 0
answer_1 = 0
for a in A:
    answer += abs(a - chushin) ** 2
    answer_1 += abs(a - chushin_1) ** 2
print((min(answer, answer_1)))

+    answer_1 += abs(a - chushin_1) ** 2


Input:
from collections import Counter

d={chr(i):0 for i in range(2)}

s=Counter(input())

d=d.update(s)

print((min(s["0"],s["1"])*2))

from collections import Counter

d = {chr(i): 0 for i in range(2)}
s = Counter(input())
d = d.update(s)
print((min(s["0"], s["1"]) * 2))

s = input()
print((min(s.count("0"), s.count("1")) * 2))


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

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

a.append(a[0]+k)

longd=0

for i in range(n):

    tmp=abs(a[i+1]-a[i])

    longd=max(longd,tmp)

print((k-longd))

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

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

a.append(a[0]+k)

x=0

for i in range(len(a)-1):

    dis=abs(a[i+1]-a[i])

    x=max(x,dis)

print((k-x))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(a[0] + k)
longd = 0
for i in range(n):
    tmp = abs(a[i + 1] - a[i])
    longd = max(longd, tmp)
print((k - longd))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(a[0] + k)
x = 0
for i in range(len(a) - 1):
    dis = abs(a[i + 1] - a[i])
    x = max(x, dis)
print((k - x))

-longd = 0
-for i in range(n):
-    tmp = abs(a[i + 1] - a[i])
-    longd = max(longd, tmp)
-print((k - longd))
+x = 0
+for i in range(len(a) - 1):
+    dis = abs(a[i + 1] - a[i])
+    x = max(x, dis)
+print((k - x))


Input:
def ii():return int(input())

def iim():return list(map(int,input().split()))

def iil():return list(map(int,input().split()))

def ism():return list(map(str,input().split()))

def isl():return list(map(str,input().split()))

n = ii()

D = iil()

ans = 0

for i in range(n):

    for j in range(i+1,n):

#        print(i,j)

        ans += D[i]*D[j]

print(ans)

def ii():return int(input())

def iim():return list(map(int,input().split()))

def iil():return list(map(int,input().split()))

def ism():return list(map(str,input().split()))

def isl():return list(map(str,input().split()))

n = ii()

D = iil()

sumD = sum(D)

ans = 0

for i in range(n):

    ans += D[i]*(sum(D)-D[i])

print((ans//2))

def ii():
    return int(input())

def iim():
    return list(map(int, input().split()))

def iil():
    return list(map(int, input().split()))

def ism():
    return list(map(str, input().split()))

def isl():
    return list(map(str, input().split()))

n = ii()
D = iil()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        #        print(i,j)
        ans += D[i] * D[j]
print(ans)

def ii():
    return int(input())

def iim():
    return list(map(int, input().split()))

def iil():
    return list(map(int, input().split()))

def ism():
    return list(map(str, input().split()))

def isl():
    return list(map(str, input().split()))

n = ii()
D = iil()
sumD = sum(D)
ans = 0
for i in range(n):
    ans += D[i] * (sum(D) - D[i])
print((ans // 2))

+sumD = sum(D)
-    for j in range(i + 1, n):
-        #        print(i,j)
-        ans += D[i] * D[j]
-print(ans)
+    ans += D[i] * (sum(D) - D[i])
+print((ans // 2))


Input:
S = input()

K = int(input())

a = list(set(S))

a.sort()

k = []

l = 0

while l < len(a):

    for i in range(len(S)):

        if S[i] == a[l]:

            for j in range(1,6):

                if i+j <= len(S):

                    k.append(S[i:i+j])

                else:

                    break

    l += 1

k = list(set(k))

k.sort()

print((k[K-1]))

S = input()

K = int(input())

a = []

for i in range(len(S)+1):

    for j in range(1,6):

        if i+j <= len(S):

            a.append(S[i:i+j])

        else:

            break

a = list(set(a))

a.sort()

print((a[K-1]))

S = input()
K = int(input())
a = list(set(S))
a.sort()
k = []
l = 0
while l < len(a):
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1, 6):
                if i + j <= len(S):
                    k.append(S[i : i + j])
                else:
                    break
    l += 1
k = list(set(k))
k.sort()
print((k[K - 1]))

S = input()
K = int(input())
a = []
for i in range(len(S) + 1):
    for j in range(1, 6):
        if i + j <= len(S):
            a.append(S[i : i + j])
        else:
            break
a = list(set(a))
a.sort()
print((a[K - 1]))

-                    k.append(S[i : i + j])


Input:
s = input()[::-1]

l = len(s)

c = [0] * 2019

c[0] = 1

ten = 1

mod = 0

ans = 0

for i in range(l):

    mod = (mod + int(s[i]) * ten) % 2019

    ten = ten * 10 % 2019

    c[mod] += 1

for i in c:

    ans += i * (i - 1) // 2

print(ans)


Input:
S=input()

print((S.rfind('Z')-S.find('A')+1))

s=input().strip()

a = s.find('A')

z = s.rfind('Z')

print((z-a+1))

S = input()
print((S.rfind("Z") - S.find("A") + 1))

s = input().strip()
a = s.find("A")
z = s.rfind("Z")
print((z - a + 1))

-print((S.rfind("Z") - S.find("A") + 1))


Input:
n = int(input()) % 1000

if n == 0:

    print((0))

else:

    print((1000 - n))


Input:
L ,R = list(map(int,input().split()))

ans =[]

if R - L <= 2019:

    for i in range(L,R+1):

        for j in range(i+1,R+1):

            ans.append(i*j%2019)

else:

    for i in range(R-L-1010,R-L+1010):

        for j in range(i,R-L+1010):

            ans.append(i*j%2019)

print((min(ans)))

L ,R = list(map(int,input().split()))

ans =[]

for i in range(L,R+1):

    for j in range(i+1,R+1):

        ans.append(i*j%2019)

        if (i * j % 2019) == 0:

            break

    else:

        continue

    break

print((min(ans)))

L, R = list(map(int, input().split()))
ans = []
if R - L <= 2019:
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans.append(i * j % 2019)
else:
    for i in range(R - L - 1010, R - L + 1010):
        for j in range(i, R - L + 1010):
            ans.append(i * j % 2019)
print((min(ans)))

L, R = list(map(int, input().split()))
ans = []
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        ans.append(i * j % 2019)
        if (i * j % 2019) == 0:
            break
    else:
        continue
    break
print((min(ans)))

-        for j in range(i, R - L + 1010):


Input:
from collections import Counter

import heapq

n = int(input())

ss = []

for _ in range(n):

    ss.append(input().rstrip())

ctr = Counter(ss)

heap = [(-v, k) for k, v in list(ctr.items())]

heapq.heapify(heap)

maxv = heap[0][0]

while heap:

    c = heapq.heappop(heap)

    if c[0] != maxv:

        break

    print((c[1]))

from collections import Counter

n = int(input())

ss = []

for _ in range(n):

    ss.append(input().rstrip())

ctr = Counter(ss)

a = sorted([(-v, k) for k, v in list(ctr.items())])

maxv = a[0][0]

for i in range(len(a)):

    if a[i][0] != maxv:

        break

    print((a[i][1]))

-heap = [(-v, k) for k, v in list(ctr.items())]

+a = sorted([(-v, k) for k, v in list(ctr.items())])


Input:
# -*- coding: utf-8 -*-

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

L, R = [None] * M, [None] * M

for i in range(M):

    L[i], R[i] = list(map(int, input().split()))

l = max(L)

r = min(R)

ans = max(r - l + 1, 0)

print(ans)

# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

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

L, R = [None] * M, [None] * M

for i in range(M):

    L[i], R[i] = list(map(int, input().split()))

ans = max(min(R) - max(L) + 1, 0)

print(ans)

+import sys
+
+input = sys.stdin.readline
-l = max(L)
-r = min(R)
-ans = max(r - l + 1, 0)
+ans = max(min(R) - max(L) + 1, 0)


Input:
import math

input_num = int(input())

num_sqrt = int(math.sqrt(input_num))

minimam = input_num

for i in range(num_sqrt+1,0,-1):

    q, mod = divmod(input_num, i)

    distance = q + i -2

    if mod == 0 and minimam > distance:

        minimam = distance

print(minimam)

import math

def main1():

    input_num = int(input())

    num_sqrt = int(math.sqrt(input_num))

    minimam = input_num

    for i in range(num_sqrt+1,0,-1):

        q, mod = divmod(input_num, i)

        if mod == 0:

            distance = q + i -2

            if minimam > distance:

                minimam = distance

    print(minimam)

main1()

import math

input_num = int(input())
num_sqrt = int(math.sqrt(input_num))
minimam = input_num
for i in range(num_sqrt + 1, 0, -1):
    q, mod = divmod(input_num, i)
    distance = q + i - 2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

import math

def main1():
    input_num = int(input())
    num_sqrt = int(math.sqrt(input_num))
    minimam = input_num
    for i in range(num_sqrt + 1, 0, -1):
        q, mod = divmod(input_num, i)
        if mod == 0:
            distance = q + i - 2
            if minimam > distance:
                minimam = distance
    print(minimam)

main1()

-    if mod == 0 and minimam > distance:

+    num_sqrt = int(math.sqrt(input_num))

+    for i in range(num_sqrt + 1, 0, -1):


Input:
# C - Walk on Multiplication Table

# https://atcoder.jp/contests/abc144/tasks/abc144_c

n = int(input())

ans = 10 ** 12

for i in range(1, 10 ** 6 + 1):

  if n % i == 0:

    ans = min(ans, n // i + i)

print((ans - 2))

# C - Walk on Multiplication Table

# https://atcoder.jp/contests/abc144/tasks/abc144_c

n = int(input())

ans = n

for i in range(1, int(n**.5) + 2):

  if n % i == 0:

    ans = min(ans, n // i + i - 2)

print(ans)

# C - Walk on Multiplication Table
# https://atcoder.jp/contests/abc144/tasks/abc144_c
n = int(input())
ans = 10**12
for i in range(1, 10**6 + 1):
    if n % i == 0:
        ans = min(ans, n // i + i)
print((ans - 2))

# C - Walk on Multiplication Table
# https://atcoder.jp/contests/abc144/tasks/abc144_c
n = int(input())
ans = n
for i in range(1, int(n**0.5) + 2):
    if n % i == 0:
        ans = min(ans, n // i + i - 2)
print(ans)

-ans = 10**12
-for i in range(1, 10**6 + 1):
+ans = n
+for i in range(1, int(n**0.5) + 2):
-        ans = min(ans, n // i + i)
-print((ans - 2))
+        ans = min(ans, n // i + i - 2)
+print(ans)


Input:
# AGC003B - Simplified mahjong

import sys

input = sys.stdin.readline

def main():

    # split in subsequences when 0 appears -> sum up cur // 2

    N = int(input())

    A = list(map(int, [input() for _ in range(N)])) + [0]

    ans, cur = 0, 0

    for i in A:

        if i:

            cur += i

        else:

            ans += cur // 2

            cur = 0

    print(ans)

if __name__ == "__main__":

    main()

# AGC003B - Simplified mahjong

def main():

    # split in subsequences when 0 appears -> sum up cur // 2

    N, *A = list(map(int, open(0).read().split()))

    A.append(0)

    ans, cur = 0, 0

    for i in A:

        if i:

            cur += i

        else:

            ans += cur // 2

            cur = 0

    print(ans)

if __name__ == "__main__":

    main()

-    A = list(map(int, [input() for _ in range(N)])) + [0]

+    N, *A = list(map(int, open(0).read().split()))


Input:
while True:

    (n, x) = [int(i) for i in input().split()]

    if n == x == 0:

        break

    count = 0

    for a in range(1, n + 1):

        for b in range(a + 1, n + 1):

            for c in range(b + 1, n + 1):

                if sum([a,b,c]) == x:

                    count += 1

    print(count)

while True:

    (n, x) = [int(i) for i in input().split()]

    if n == x == 0:

        break

    count = 0

    limit = n if n < x else x

    for a in range(1, limit + 1):

        for b in range(a + 1, limit + 1):

            for c in range(b + 1, limit + 1):

                if sum([a,b,c]) == x:

                    count += 1

    print(count)

while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            for c in range(b + 1, n + 1):
                if sum([a, b, c]) == x:
                    count += 1
    print(count)

while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    limit = n if n < x else x
    for a in range(1, limit + 1):
        for b in range(a + 1, limit + 1):
            for c in range(b + 1, limit + 1):
                if sum([a, b, c]) == x:
                    count += 1
    print(count)

-            for c in range(b + 1, n + 1):

+        for b in range(a + 1, limit + 1):

+            for c in range(b + 1, limit + 1):


Input:
inf = (5000 * 10 ** 5) * 3

a, b, c, x, y = list(map(int, input().split()))

ret = inf

for cnt_ab in range(max(x, y) * 2 + 1):

    d = cnt_ab // 2

    cnt_a = max(0, x - d)

    cnt_b = max(0, y - d)

    t = cnt_ab * c + cnt_a * a + cnt_b * b

    ret = min(ret, t)

print(ret)

def main():

    A, B, AB, X, Y = list(map(int, input().split()))

    M = max(X, Y)

    k = 0

    ans = A * X + B * Y

    while True:

        ans = min(

            ans,

            AB * k * 2 + max(0, X - k) * A + max(0, Y - k) * B

        )

        if k >= M: break

        k += 1

    print(ans)

if __name__ == '__main__':

    main()

inf = (5000 * 10**5) * 3
a, b, c, x, y = list(map(int, input().split()))
ret = inf
for cnt_ab in range(max(x, y) * 2 + 1):
    d = cnt_ab // 2
    cnt_a = max(0, x - d)
    cnt_b = max(0, y - d)
    t = cnt_ab * c + cnt_a * a + cnt_b * b
    ret = min(ret, t)
print(ret)

def main():
    A, B, AB, X, Y = list(map(int, input().split()))
    M = max(X, Y)
    k = 0
    ans = A * X + B * Y
    while True:
        ans = min(ans, AB * k * 2 + max(0, X - k) * A + max(0, Y - k) * B)
        if k >= M:
            break
        k += 1
    print(ans)

if __name__ == "__main__":
    main()

-a, b, c, x, y = list(map(int, input().split()))

-for cnt_ab in range(max(x, y) * 2 + 1):

-    t = cnt_ab * c + cnt_a * a + cnt_b * b

+    A, B, AB, X, Y = list(map(int, input().split()))

+        ans = min(ans, AB * k * 2 + max(0, X - k) * A + max(0, Y - k) * B)


Input:
S = int(input())

f = [0]*(S+1)

f[0] = 1

if S >= 3: f[3] = 1

if S >= 4: f[4] = 1

if S >= 5: f[5] = 1

for i in range(6, S+1):

    f[i] = sum(f[i-j] for j in range(3, i+1))%(10**9+7)

print((f[S]))


Input:
import math

n=int(input())

print(((2*n)//math.gcd(2,n)))

N=int(input());print((N if N%2==0 else N*2))

import math

n = int(input())
print(((2 * n) // math.gcd(2, n)))

N = int(input())
print((N if N % 2 == 0 else N * 2))

-import math
-n = int(input())
-print(((2 * n) // math.gcd(2, n)))
+N = int(input())
+print((N if N % 2 == 0 else N * 2))


Input:
import sys

s = input()

ts = ['']

while True:

  nts= []

  for t in ts:

    for w in ['dreamer', 'eraser', 'dream', 'erase']:

      if s == t + w:

        print('YES')

        sys.exit()

      if s.startswith(t + w):

        nts.append(t + w)

  if len(nts) == 0:

    print('NO')

    sys.exit()

  ts = nts

from sys import exit

s = input()

ts = ['']

while True:

  nts= []

  for t in ts:

    for w in ['dreamer', 'eraser', 'dream', 'erase']:

      tw = t + w

      if s == tw:

        print('YES')

        exit()

      if s.startswith(tw):

        nts.append(tw)

  if len(nts) == 0:

    print('NO')

    exit()

  ts = nts

import sys

s = input()
ts = [""]
while True:
    nts = []
    for t in ts:
        for w in ["dreamer", "eraser", "dream", "erase"]:
            if s == t + w:
                print("YES")
                sys.exit()
            if s.startswith(t + w):
                nts.append(t + w)
    if len(nts) == 0:
        print("NO")
        sys.exit()
    ts = nts

from sys import exit

s = input()
ts = [""]
while True:
    nts = []
    for t in ts:
        for w in ["dreamer", "eraser", "dream", "erase"]:
            tw = t + w
            if s == tw:
                print("YES")
                exit()
            if s.startswith(tw):
                nts.append(tw)
    if len(nts) == 0:
        print("NO")
        exit()
    ts = nts

-import sys
+from sys import exit
-s = input()
+s = input()
-            if s == t + w:
+            tw = t + w
+            if s == tw:
-                sys.exit()
-            if s.startswith(t + w):
-                nts.append(t + w)
+                exit()
+            if s.startswith(tw):
+                nts.append(tw)
-        sys.exit()
+        exit()


Input:
N,K=list(map(int,input().split()))

a = [[0]*N]*K

a = [[0 for n in range(N)] for k in range(K)]

for k in range(K):

    d=int(input())

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

    for h in have_k:

        a[k][h-1]=1

an=[0]*N

for k in range(K):

  for n in range(N):

    an[n] = an[n]+a[k][n]

result=0

for i in an:

  if i == 0:

    result+=1

print(result)

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

a = [[0 for n in range(N)] for k in range(K)]

for k in range(K):

    d=int(input())

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

    for h in have_k:

        a[k][h-1]=1

an=[0]*N

for k in range(K):

  for n in range(N):

    an[n] = an[n]+a[k][n]

result=0

for i in an:

  if i == 0:

    result+=1

print(result)

N, K = list(map(int, input().split()))
a = [[0] * N] * K
a = [[0 for n in range(N)] for k in range(K)]
for k in range(K):
    d = int(input())
    have_k = list(map(int, input().split()))
    for h in have_k:
        a[k][h - 1] = 1
an = [0] * N
for k in range(K):
    for n in range(N):
        an[n] = an[n] + a[k][n]
result = 0
for i in an:
    if i == 0:
        result += 1
print(result)

N, K = list(map(int, input().split()))
a = [[0 for n in range(N)] for k in range(K)]
for k in range(K):
    d = int(input())
    have_k = list(map(int, input().split()))
    for h in have_k:
        a[k][h - 1] = 1
an = [0] * N
for k in range(K):
    for n in range(N):
        an[n] = an[n] + a[k][n]
result = 0
for i in an:
    if i == 0:
        result += 1
print(result)


Input:
n,m=list(map(int,input().split()))

c=[0]*(n+2)

for i in range(m):

  l,r=list(map(int,input().split()))

  c[l-1]+=1

  c[r]-=1

for i in range(1,n+2):

  c[i]=c[i]+c[i-1]

ans=0

for i in range(n+2):

  if c[i]==m:

    ans+=1

print(ans)

n,m=list(map(int,input().split()))

l,r=list(map(int,input().split()))

for i in range(m-1):

  tl,tr=list(map(int,input().split()))

  if l<tl:

    l=tl

  if tr<r:

    r=tr

print((max(r-l+1,0)))

n, m = list(map(int, input().split()))
c = [0] * (n + 2)
for i in range(m):
    l, r = list(map(int, input().split()))
    c[l - 1] += 1
    c[r] -= 1
for i in range(1, n + 2):
    c[i] = c[i] + c[i - 1]
ans = 0
for i in range(n + 2):
    if c[i] == m:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
l, r = list(map(int, input().split()))
for i in range(m - 1):
    tl, tr = list(map(int, input().split()))
    if l < tl:
        l = tl
    if tr < r:
        r = tr
print((max(r - l + 1, 0)))

-    l, r = list(map(int, input().split()))

+    tl, tr = list(map(int, input().split()))


Input:
n,m=list(map(int,input().split()))

a=[int(x) for x in input().split()]

b=[0 for x in range(n+1)]

l=list([0])

for i in range(1,n+1):

  b[i]=b[i-1]+a[i-1]

for i in range(1,n+1):

  l.append(b[i]%m)

d=list()

l.sort()

t,c=0,1

for i in range(1,n+1):

  if l[i]==l[i-1]:

    c+=1

  else:

    if c!=1:

      t += c*(c-1)//2

      c=1

if c!=1:

  t += c*(c-1)//2

print(t)

n,m=list(map(int,input().split()))

a=[int(x) for x in input().split()]

l=list([0])

b=0

for i in range(0,n):

  b += a[i]

  l.append(b%m)

l.append(m)

l.sort()

t,c=0,1

for i in range(1,n+2):

  if l[i]==l[i-1]:

    c+=1

  else:

    if c!=1:

      t += c*(c-1)//2

      c=1

print(t)

n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
b = [0 for x in range(n + 1)]
l = list([0])
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[i - 1]
for i in range(1, n + 1):
    l.append(b[i] % m)
d = list()
l.sort()
t, c = 0, 1
for i in range(1, n + 1):
    if l[i] == l[i - 1]:
        c += 1
    else:
        if c != 1:
            t += c * (c - 1) // 2
            c = 1
if c != 1:
    t += c * (c - 1) // 2
print(t)

n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
l = list([0])
b = 0
for i in range(0, n):
    b += a[i]
    l.append(b % m)
l.append(m)
l.sort()
t, c = 0, 1
for i in range(1, n + 2):
    if l[i] == l[i - 1]:
        c += 1
    else:
        if c != 1:
            t += c * (c - 1) // 2
            c = 1
print(t)

-b = [0 for x in range(n + 1)]
-for i in range(1, n + 1):
-    b[i] = b[i - 1] + a[i - 1]
-for i in range(1, n + 1):
-    l.append(b[i] % m)
-d = list()
+b = 0
+for i in range(0, n):
+    b += a[i]
+    l.append(b % m)
+l.append(m)
-for i in range(1, n + 1):
+for i in range(1, n + 2):
-if c != 1:
-    t += c * (c - 1) // 2


Input:
n=int(input())

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

k=[]

ans=0

for i in range(400005):

  k.append(0)

for i in range(n):

  if i-a[i]>=0:

    ans+=k[i-a[i]]

  if a[i]+i<400005:

    k[a[i]+i]+=1

print(ans)

n=int(input())

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

thing={}

ans=0

for i in range(n):

  if i-a[i] in thing:

    ans+=thing[i-a[i]]

  if i+a[i] in thing:

    thing[i+a[i]]+=1

  else:

    thing[i+a[i]]=1

print(ans)

n = int(input())
a = list(map(int, input().split()))
k = []
ans = 0
for i in range(400005):
    k.append(0)
for i in range(n):
    if i - a[i] >= 0:
        ans += k[i - a[i]]
    if a[i] + i < 400005:
        k[a[i] + i] += 1
print(ans)

n = int(input())
a = list(map(int, input().split()))
thing = {}
ans = 0
for i in range(n):
    if i - a[i] in thing:
        ans += thing[i - a[i]]
    if i + a[i] in thing:
        thing[i + a[i]] += 1
    else:
        thing[i + a[i]] = 1
print(ans)

-k = []
+thing = {}
-for i in range(400005):
-    k.append(0)
-    if i - a[i] >= 0:
-        ans += k[i - a[i]]
-    if a[i] + i < 400005:
-        k[a[i] + i] += 1
+    if i - a[i] in thing:
+        ans += thing[i - a[i]]
+    if i + a[i] in thing:
+        thing[i + a[i]] += 1
+    else:
+        thing[i + a[i]] = 1