1686: 动物园(zoo)

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:11 Solved:4

Description

动物园里饲养了很多动物,饲养员小 A 会根据饲养动物的情况,按照《饲养指南》购买不同种类的饲料,并将购买清单发给采购员小 B。

具体而言,动物世界里存在 lns="http://www.w3.org/1998/Math/MathML">2^k 种不同的动物,它们被编号为 lns="http://www.w3.org/1998/Math/MathML">0 \sim 2^k - 1。动物园里饲养了其中的 lns="http://www.w3.org/1998/Math/MathML">n 种,其中第 lns="http://www.w3.org/1998/Math/MathML">i 种动物的编号为 lns="http://www.w3.org/1998/Math/MathML">a_i

《饲养指南》中共有 lns="http://www.w3.org/1998/Math/MathML">m 条要求,第 lns="http://www.w3.org/1998/Math/MathML">j 条要求形如“如果动物园中饲养着某种动物,满足其编号的二进制表示的第 lns="http://www.w3.org/1998/Math/MathML">p_j 位为 lns="http://www.w3.org/1998/Math/MathML">1,则必须购买第 lns="http://www.w3.org/1998/Math/MathML">q_j 种饲料”。其中饲料共有 lns="http://www.w3.org/1998/Math/MathML">c 种,它们从 lns="http://www.w3.org/1998/Math/MathML">1 \sim c 编号。本题中我们将动物编号的二进制表示视为一个 lns="http://www.w3.org/1998/Math/MathML">k 位 01 串,第 lns="http://www.w3.org/1998/Math/MathML">0 位是最低位,第 lns="http://www.w3.org/1998/Math/MathML">k - 1 位是最高位。

根据《饲养指南》,小 A 将会制定饲料清单交给小 B,由小 B 购买饲料。清单形如一个 lns="http://www.w3.org/1998/Math/MathML">c 位 lns="http://www.w3.org/1998/Math/MathML">01 串,第 lns="http://www.w3.org/1998/Math/MathML">i 位为 lns="http://www.w3.org/1998/Math/MathML">1 时,表示需要购买第 lns="http://www.w3.org/1998/Math/MathML">i 种饲料;第 lns="http://www.w3.org/1998/Math/MathML">i 位为 lns="http://www.w3.org/1998/Math/MathML">0 时,表示不需要购买第 lns="http://www.w3.org/1998/Math/MathML">i 种饲料。 实际上根据购买到的饲料,动物园可能可以饲养更多的动物。更具体地,如果将当前未被饲养的编号为 lns="http://www.w3.org/1998/Math/MathML">x 的动物加入动物园饲养后,饲料清单没有变化,那么我们认为动物园当前还能饲养编号为 lns="http://www.w3.org/1998/Math/MathML">x 的动物。

现在小 B 想请你帮忙算算,动物园目前还能饲养多少种动物。

Input

第一行包含四个以空格分隔的整数 lns="http://www.w3.org/1998/Math/MathML">
分别表示动物园中动物数量、《饲养指南》要求数、饲料种数与动物编号的二进制表示位数。
第二行 lns="http://www.w3.org/1998/Math/MathML"> 个以空格分隔的整数,其中第 lns="http://www.w3.org/1998/Math/MathML"> 个整数表示 lns="http://www.w3.org/1998/Math/MathML">
接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行两个整数 lns="http://www.w3.org/1998/Math/MathML"> 表示一条要求。
数据保证所有 lns="http://www.w3.org/1998/Math/MathML"> 互不相同,所有的 lns="http://www.w3.org/1998/Math/MathML"> 互不相同。

Output

仅一行一个整数表示答案。

Sample Input Copy

3 3 5 4
1 4 6
0 3
2 4
2 5

Sample Output Copy

13

HINT

【样例 #1 解释】

动物园里饲养了编号为 lns="http://www.w3.org/1998/Math/MathML">1, 4, 6 的三种动物,《饲养指南》上的三条要求为:

  1. 若饲养的某种动物的编号的第 lns="http://www.w3.org/1998/Math/MathML">0 个二进制位为 lns="http://www.w3.org/1998/Math/MathML">1,则需购买第 lns="http://www.w3.org/1998/Math/MathML">3 种饲料。
  2. 若饲养的某种动物的编号的第 lns="http://www.w3.org/1998/Math/MathML">2 个二进制位为 lns="http://www.w3.org/1998/Math/MathML">1,则需购买第 lns="http://www.w3.org/1998/Math/MathML">4 种饲料。
  3. 若饲养的某种动物的编号的第 lns="http://www.w3.org/1998/Math/MathML">2 个二进制位为 lns="http://www.w3.org/1998/Math/MathML">1,则需购买第 lns="http://www.w3.org/1998/Math/MathML">5 种饲料。

饲料购买情况为:

  1. 编号为 lns="http://www.w3.org/1998/Math/MathML">1 的动物的第 lns="http://www.w3.org/1998/Math/MathML">0 个二进制位为 lns="http://www.w3.org/1998/Math/MathML">1,因此需要购买第 lns="http://www.w3.org/1998/Math/MathML">3 种饲料;
  2. 编号为 lns="http://www.w3.org/1998/Math/MathML">4, 6 的动物的第 lns="http://www.w3.org/1998/Math/MathML">2 个二进制位为 lns="http://www.w3.org/1998/Math/MathML">1,因此需要购买第 lns="http://www.w3.org/1998/Math/MathML">4, 5 种饲料。

由于在当前动物园中加入一种编号为 lns="http://www.w3.org/1998/Math/MathML">0, 2, 3, 5, 7, 8, \ldots , 15 之一的动物,购物清单都不会改变,因此答案为 lns="http://www.w3.org/1998/Math/MathML">13

【数据范围】

对于 lns="http://www.w3.org/1998/Math/MathML">20 \% 的数据,lns="http://www.w3.org/1998/Math/MathML">k \le n \le 5lns="http://www.w3.org/1998/Math/MathML">m \le 10lns="http://www.w3.org/1998/Math/MathML">c \le 10,所有的 lns="http://www.w3.org/1998/Math/MathML">p_i 互不相同。
对于 lns="http://www.w3.org/1998/Math/MathML">40 \% 的数据,lns="http://www.w3.org/1998/Math/MathML">n \le 15lns="http://www.w3.org/1998/Math/MathML">k \le 20lns="http://www.w3.org/1998/Math/MathML">m \le 20lns="http://www.w3.org/1998/Math/MathML">c \le 20
对于 lns="http://www.w3.org/1998/Math/MathML">60 \% 的数据,lns="http://www.w3.org/1998/Math/MathML">n \le 30lns="http://www.w3.org/1998/Math/MathML">k \le 30lns="http://www.w3.org/1998/Math/MathML">m \le 1000
对于 lns="http://www.w3.org/1998/Math/MathML">100 \% 的数据,lns="http://www.w3.org/1998/Math/MathML">0 \le n, m \le 10^6lns="http://www.w3.org/1998/Math/MathML">0 \le k \le 64lns="http://www.w3.org/1998/Math/MathML">1 \le c \le 10^8