import sys from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, K, *A = map(int, read().split()) def f(K, A, B): INF = 10**9 + 10 # B の状態 nums = defaultdict(int) sums = defaultdict(int) p = 0 ret = 0 # A の状態 min_value, min_cnt = INF, 1 for i, a in enumerate(A, 1): if a == min_value: min_cnt += 1 elif a < min_value: min_value = a min_cnt = 1 if min_cnt >= 2: continue while p < len(B): b = B[p] if b > min_value: nums[b] += 1 sums[b] += p + 1 else: break p += 1 ret += nums[K - a] * i + sums[K - a] return ret def solve(K, A, L, R): # 半開区間[L,R) if R - L == 1: return A[L] * 2 == K M = (L + R) // 2 ret = solve(K, A, L, M) + solve(K, A, M, R) # あとはM-1, Mを含むような解を求める。一意な最小値がどちらにあるかで。 left_nums = A[L:M][::-1] right_nums = A[M:R] ret += f(K, left_nums, right_nums) ret += f(K, right_nums, left_nums) return ret print(solve(K, A, 0, N))