from bisect import bisect_left, bisect_right N = int(input()) A = list(map(int, input().split())) K = [[] for _ in range(N)] for i in range(N): for j in range(i+1,N): if A[i]+10 == A[j]: K[i].append(j) T = [] ans = 0 for i in range(N): for j in range(i+1,N): if A[i]+1 == A[j]: l = bisect_right(T, i) r = bisect_left(T, j) ans += r-l # print(i,j,l,r,ans) T += K[i] T.sort() print(ans)