P26781 [AtCoder] Camphor Tree
普及+
题目描述

Problem Description

In front of Kyoto University's clock tower, there is a giant camphor tree. Observations have revealed the following about the structure of this camphor tree:

  • There is a positive integer $ N $, and the camphor tree has $ 2^N-1 $ branching points.
  • The branching points are numbered from $ 1 $ to $ 2^N-1 $.
  • For each integer $ i $ satisfying $1 \leq i \leq 2^{N-1}-1$, there are branches as follows:
  • Branching point $ i $ is connected to branching point $ 2i $.
  • Branching point $ i $ is connected to branching point $ 2i+1 $.
  • There are no branches that do not satisfy the conditions described above.

For example, the structure of the camphor tree when $ N=3 $ is as shown in the figure below.

Camphor Tree $ N=3 $

You want to climb this camphor tree. Climbing from branching point $ S $ to branching point $ T $ is possible if and only if $ S=T $ or if you can follow the branches from branching point $ S $ to branching point $ T $ such that the numbers of the branching points passed through increase. Given the numbers of the branching points $ S $ and $ T $, determine whether it is possible to climb from $ S $ to $ T $. If it is possible, also output the number of branches that need to be passed through.

Input Format

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

$ N $ $ S $ $ T $

Output Format

Output -1 if it is not possible to climb from $ S $ to $ T $. If it is possible to climb from $ S $ to $ T $, output the number of branches that need to be passed through.

Sample Input and Output

Sample Input #1

3 2 4

Sample Output #1

1

Sample Input #2

3 7 1

Sample Output #2

-1

Sample Input #3

4 2 2

Sample Output #3

0

Notes/Hints

Constraints

  • $1 \leq N \leq 25$
  • $1 \leq S \leq 2^N-1$
  • $1 \leq T \leq 2^N-1$
  • $ N, S, T $ are integers.

Sample Explanation 1

It is possible to climb from branching point $ 2 $ to $ 4 $ by passing through $ 1 $ branch, so output 1.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 4
样例输出
1