from bisect import * N = int(input()) A = list(map(int,input().split())) from collections import defaultdict dic = defaultdict(list) for i,a in enumerate(A): dic[a].append(i) ans = 0 for i in range(N - 3): a = A[i] for j in range(i + 1,N - 2): b = A[j] if dic[a+10]: for k in dic[a + 10]: if i < j < k: if dic[b + 1]: ans += len(dic[b + 1]) - bisect_left(dic[b + 1],k) print(ans)