n = int(input()) A = list(map(int, input().split())) ans = 0 for k in range(1, 2001): DP = [[0 for _ in range(2001)] for _ in range(5)] DP[0][0] = 1 for i in range(n): a = A[i] DP[1][a] += DP[0][0] if 0 < a - k - 10 <= 2000: DP[2][a] += DP[1][a - k - 10] if 0 < a + k <= 2000: DP[3][a] += DP[2][a + k] if 0 < a - k - 1 <= 2000: DP[4][a] += DP[3][a - k - 1] ans += sum(DP[4]) print(ans)