P27028 [AtCoder] IntegerotS
提高-
题目描述

Problem Description

The non-negative integer specialty store "seisuya" sells $ N $ non-negative integers. The $ i $-th non-negative integer is $ A_i $, and its value is $ B_i $. The same non-negative integer with different values may be sold multiple times.

Takahashi decided to buy some integers from "seisuya". He can buy any combination of integers such that their bitwise OR is less than or equal to $ K $. Takahashi wants to maximize the total value of the integers he buys.

Find the maximum total value that Takahashi can achieve. Note that bitwise OR represents the bitwise logical OR operation.

Input Format

The input is given from the standard input in the following format:

$ N $ $ K $ $ A_1 $ $ B_1 $ : $ A_N $ $ B_N $

Output Format

Output the maximum total value that Takahashi can achieve.

Sample Input and Output

Sample Input #1

3 5
3 3
4 4
2 5

Sample Output #1

8

Sample Input #2

3 6
3 3
4 4
2 5

Sample Output #2

9

Sample Input #3

7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9

Sample Output #3

32

Notes/Hints

Constraints

  • $1 \leq N \leq 10^5$
  • $0 \leq K < 2^{30}$
  • $0 \leq A_i < 2^{30} (1 \leq i \leq N)$
  • $1 \leq B_i \leq 10^9 (1 \leq i \leq N)$
  • All inputs are integers

Sample Explanation 1

By purchasing $ 2 $ and $ 3 $, the maximum value $ 8 $ can be achieved.

Sample Explanation 2

By purchasing $ 2 $ and $ 4 $, the maximum value $ 9 $ can be achieved.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 5 3 3 4 4 2 5
样例输出
8