from collections import defaultdict import bisect class BIT: def __init__(self, n): self.size = n self.list = [0] * (n + 1) def add(self, i, x): if i == 0: return while i <= self.size: self.list[i] += x i += (i & -i) def sum(self, i): if i == 0: return 0 ret = 0 while i > 0: ret += self.list[i] i -= (i & -i) return ret def MakeList(lst): ret = [[] for _ in range(len(lst) + 1)] for i in range(1 << (len(lst))): popcnt = 0 b = 0 a = 0 for j in range(len(lst)): if ((i >> j) & 1): popcnt += 1 b += lst[j][0] a += lst[j][1] ret[popcnt].append([b, a]) for i in range(len(lst) + 1): ret[i].sort() return ret def MakeUniqueA(lst): new_lst = [] for i in range(len(lst)): for j in range(len(lst[i])): new_lst.append(lst[i][j][1]) ret = list(set(new_lst)) ret.sort() return ret N, K, L, P = map(int, input().split()) former = [] latter = [] for i in range(N): a, b = map(int, input().split()) if i < N // 2: former.append([b, a]) else: latter.append([b, a]) former_lst = MakeList(former) latter_lst = MakeList(latter) former_a = MakeUniqueA(former_lst) latter_a = MakeUniqueA(latter_lst) #print(former_a) #print(latter_a) d_former = defaultdict(int) d_latter = defaultdict(int) for i in range(len(former_a)): d_former[former_a[i]] = i + 1 for i in range(len(latter_a)): d_latter[latter_a[i]] = i + 1 idx = [0 for _ in range(len(former_a))] for i in range(len(former_a)): if former_a[i] + latter_a[len(latter_a) - 1] <= L: idx[i] = len(latter_a) elif former_a[i] + latter_a[0] > L: idx[i] = 0 else: idx[i] = bisect.bisect_right(latter_a, L - former_a[i]) bit = BIT((1 << 18) + 1) ans = 0 for i in range(len(former_lst)): for j in range(len(latter_lst)): if i + j > K: continue now = len(latter_lst[j]) - 1 for k in range(len(former_lst[i])): while now >= 0: if former_lst[i][k][0] + latter_lst[j][now][0] >= P: bit.add(d_latter[latter_lst[j][now][1]], 1) now -= 1 else: break sm = bit.sum(idx[d_former[former_lst[i][k][1]] - 1]) ans += sm for k in range(now + 1, len(latter_lst[j])): bit.add(d_latter[latter_lst[j][k][1]], -1) print(ans)