from collections import defaultdict n = int(input()) a = list(map(int, input().split(' '))) ans = 0 for d in range(1,1000): dp = [[0 for j in range(4)] for i in range(n)] mp = defaultdict(int) for i in range(n): dp[i][0] += 1 dp[i][1] += mp[(a[i] - 10 - d, 0)] dp[i][2] += mp[(a[i] + d, 1)] dp[i][3] += mp[(a[i] - d - 1, 2)] for j in range(4): mp[(a[i], j)] += dp[i][j] ans += dp[i][3] print(ans)