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