#P2114. Conquering drd's Defense

    ID: 15396 Type: Default 1000ms 256MiB

Conquering drd's Defense

Conquering drd's Defense

In the 21st century, a peculiar syndrome called 'Difficulty to Rise' has plagued many. Its symptoms include difficulty waking up and a languid state after rising. Our bright and energetic hero, atm, has been fighting this syndrome relentlessly. Through his research, he discovered that the cause lies deep in the Pacific Ocean, where a giant dragon named drd lurks. This fearsome creature holds the essence of sleep and can extend sleep duration at will, thereby exacerbating the syndrome's spread.

drd protects itself with a series of n defense gates. Each gate applies a bitwise operation \(op\) (which is one of \(\text{OR}\), \(\text{XOR}\), or \(\text{AND}\)) using a non-negative integer parameter \(t\). When an attack with power \(x\) hits a gate, it transforms into \(x \;op\; t\). After passing through all \(n\) gates, the final damage inflicted on drd is determined.

atm can only choose an initial attack power from \(0\) to \(m\) (inclusive). To conserve his energy, he wants to choose the best initial power so that after all the gates the damage is maximized. Your task is to compute the maximum possible damage drd can receive.

inputFormat

The first line contains two integers \(n\) and \(m\) (e.g. \(1 \leq n \leq 10^5\), \(0 \leq m \leq 10^9\)), representing the number of defense gates and the maximum possible initial attack power.

Each of the following \(n\) lines contains a string \(op\) and an integer \(t\) (\(0 \leq t \leq 10^9\)). Here, \(op\) is one of "OR", "XOR", or "AND", indicating the bitwise operation applied at that gate.

outputFormat

Output a single integer — the maximum damage drd can receive after the attack passes through all defense gates.

sample

3 10
OR 5
XOR 6
AND 1
1