from collections import defaultdict N = int(input()) A = list(map(int,input().split())) D = defaultdict(int) ans = 0 for i in range(1,N-2): D[A[i-1]] += 1 dd = defaultdict(int) for j in range(i+1,N): dd[A[j]] += 1 for j in range(i+1,N-1): dd[A[j]] -= 1 b = A[i] c = A[j] k = b - c a = b - k - 10 d = c + k + 1 ans += D[a]*dd[d] print(ans)