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()) nums = defaultdict(int) sums = defaultdict(int) answer = 0 def f(K, A, B): global answer INF = 10**9 + 10 # B の状態 nums.clear() sums.clear() 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 key = K - a if key in nums: answer += nums[key] * i + sums[key] def solve(K, A, L, R): # 半開区間[L,R) if R - L == 1: answer += A[L] * 2 == K return M = (L + R) // 2 solve(K, A, L, M) + solve(K, A, M, R) # あとはM-1, Mを含むような解を求める。一意な最小値がどちらにあるかで。 left_nums = A[L:M][::-1] right_nums = A[M:R] f(K, left_nums, right_nums) f(K, right_nums, left_nums) solve(K, A, 0, N) print(answer)