import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    MAX_A = max(A)
    for k in range(1, MAX_A + 1):
        # dp[j][x] := (A[0] 〜 A[i-1] まで見て、) x = a1 であって、
        #             あさかつ型の部分列の j 番目まで決めた場合の数
        dp = [[0] * (MAX_A + 1) for _ in range(4)]
        for a in A:
            x = a - k - 11
            if 1 <= x: dp[3][x] += dp[2][x]

            y = a - 10
            if 1 <= y: dp[2][y] += dp[1][y]

            z = a - k - 10
            if 1 <= z: dp[1][z] += dp[0][z]

            dp[0][a] += 1

        ans += sum(dp[3])

    print(ans)


if __name__ == "__main__":
    main()