from collections import defaultdict """ 解説AC reference: https://www.youtube.com/watch?v=ImVYMpTuXiY [方針] a2 と a3 を固定する。 """ N = int(input()) A = list(map(int, input().split())) # s[i][j]: s[0]-s[i] に含まれる j の個数 s = [] cnt = defaultdict(int) for i in A: cnt[i] += 1 s.append(cnt.copy()) ans = 0 for i in range(1, N-2): a2 = A[i] for j in range(i+1, N-1): a3 = A[j] k = a2 - a3 a1 = a2 - k - 10 a4 = a3 + k + 1 if 0 < k: ans += s[i-1][a1] * (s[-1][a4] - s[j][a4]) print(ans)