Russel Supremacy

3

2 votes
Bit manipulation, Medium
Problem

After Performing well in IPL, everyone's expectation has increased from Russel.This time Russel needs to solve a programming question.Given n (key,value) pairs and a number K. You have to pick some keys such that

  • Bitwise OR of chosen keys is K.
  • Sum of corresponding values is maximum.

Print the maximum sum of values that can be achieved.

But Russel doesn't know programmiing ,so you being Russel's die hard supporter needs to help him solve this question to prove his supremacy here as well.

Input Format:

First Line will consist of n and  K denoting the number of key value pairs and K as specisied in the problem statement.

Next n lines contain key,value pairs.

Output Format:

Output the required answer in the single line.

Constraints:

1N1050K10737418230keyi10737418231valuei109(1iN)

Sample Input
3 5
3 3
4 4
2 5
Sample Output
8

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

You can choose 1st and 3rd key which maximizes the sum of corresponding values (3+5=8). It can be proven that sum greater than 8 cannot be achieved.

Editor Image

?