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[x][j] := (A[0] 〜 A[i-1] まで見て、) x = a1 であって、 # あさかつ型の部分列の j 番目まで決めた場合の数 dp = [[0] * 4 for _ in range(MAX_A + 1)] for a in A: x = a - k - 11 if 1 <= x: dp[x][3] += dp[x][2] y = a - 10 if 1 <= y: dp[y][2] += dp[y][1] z = a - k - 10 if 1 <= z: dp[z][1] += dp[z][0] dp[a][0] += 1 for x in range(1, MAX_A + 1): ans += dp[x][3] print(ans) if __name__ == "__main__": main()