QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#16543. Non-breath Oblige

统计

Background

それぞれの好きを守るため / To protect the things we each love

君と防空壕で呼吸する / Breathing with you in the air-raid shelter

Given three integers $n, s, t$, where $0 \le s, t < 2^n$.

You can perform several operations. In each operation, you can choose a non-negative integer $x$ and change the value of $s$ to $x$, subject to the following requirements:

  • $x < 2^n$ must be satisfied;
  • $s \lor x = 2^n - 1$ must be satisfied, where $\lor$ is the bitwise OR operation;
  • You incur a cost of $s \oplus x$, where $\oplus$ is the bitwise XOR operation.

Find the minimum total cost required to make $s = t$. It can be proven that it is always possible to make $s$ equal to $t$.

Input

This problem contains multiple test cases.

The first line of input contains a positive integer $T$, representing the number of test cases.

Each test case consists of a single line containing three integers $n, s, t$.

Output

For each test case, output a single integer representing the minimum total cost required to make $s = t$.

Examples

Input 1

3
2 1 2
3 1 1
5 1 4

Output 1

3
0
57

Note 1

For the first test case, since $1 \lor 2 = 3$, you can directly change the value of $s$ from $1$ to $2$. The cost is $1 \oplus 2$, which is $3$. It can be proven that the minimum total cost to make $s = t$ is $3$.

For the second test case, no operations are needed as $s = t$ is already satisfied.

Constraints

For all test cases, it is guaranteed that:

  • $1 \le T \le 100$;
  • $1 \le n \le 30$;
  • $0 \le s, t < 2^n$.

This problem uses bundled testing.

  • Subtask 1 (12 points): $s = t$.
  • Subtask 2 (15 points): $n = 1$.
  • Subtask 3 (20 points): $s + t = 2^n - 1$.
  • Subtask 4 (10 points): $t = 2^n - 1$.
  • Subtask 5 (18 points): $t = 0$.
  • Subtask 6 (25 points): No special restrictions.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.