n = int(input()) A = list(map(int,input().split())) ans = 0 M = 2001 left = [0]*M for x in range(n): a2 = A[x] right = [0]*M for y in range(x,n)[::-1]: a3 = A[y] k = a2-a3 if k <= 0: right[a3] += 1 continue a1 = a3-10 if a1 <= 0: right[a3] += 1 continue a4 = a3+k+1 if a4 < M: ans += left[a1]*right[a4] right[a3] += 1 left[a2] += 1 print(ans)