#!/usr/bin/env python3 import sys from bisect import bisect_left, bisect_right, insort_left, insort_right # type: ignore from collections import Counter, defaultdict, deque # type: ignore from math import gcd, sqrt, ceil # type: ignore from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge # type: ignore from itertools import accumulate, combinations, permutations, product # type: ignore from string import ascii_lowercase, ascii_uppercase # type: ignore def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def SRL(n): return [list(S()) for _ in range(n)] N = I() A = LI() num = [[] for _ in range(2010)] cnt = [[0]*(N+1) for _ in range(2010)] for i,a in enumerate(A): num[a].append(i) for j in num[a-1]: cnt[a-1][j]+=1 cnt[a-1][i]-=1 for i in range(2010): cnt[i] = list(accumulate(cnt[i])) for i in range(2009,0,-1): for j in range(N+1): cnt[i-1][j] += cnt[i][j] ans = 0 for i in range(N): a1 = A[i] for k in num[a1+10]: if k-i<2: continue a3 = A[k] # if cnt[a3+1][k]>0: # print(i,k,cnt[a3+1][k]) ans += cnt[a3+1][k] print(ans)