import sys;input=sys.stdin.readline from collections import defaultdict n, k = map(int, input().split()) X = list(map(int, input().split())) st_f = [(0, 10**18), (X[0], X[0])] st_b = [(0, 10**18)] r = 0 j = 1 C = defaultdict(int) D = defaultdict(int) C[X[0]] += 1 D[X[0]] += 1 for i in range(n): while j 1: x, y = st_f.pop() st_b.append( (x, min(st_b[-1][1], x)) ) st_b.pop() r += C[k-X[i]] - D[k-X[i]]*i # print(i, j, C[k-X[i]], D[k-X[i]]) C[X[i]] -= i+1 D[X[i]] -= 1 print(r)