logo AlgoBeat OnlineJudge
登录 注册

#215702. [ICPC 2022 Tehran R] Magic with Cards

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Mahsa has been practicing shuffling cards for a few months now. Tonight, she finally decided to invite her friends over and show off her new skills. So she picks up a deck with cards, shows her friends the face of the cards without changing the deck order and asks someone to pick two positions and in the deck. Then, she tells everyone that she is going to move the card in the -th position to the -th position by applying only two types of shuffles.

Assume the cards in the deck are . Mahsa can perform these two shuffles as many times as she wants:

  • Riffle: Divide the cards into two parts and and produce .
  • Scuffle: From , produce .

Help Mahsa find out the minimum number of shuffles she needs, and she'll figure out the rest.

输入格式

The input consists of a single line containing three space-separated integers , and ( and ).

输出格式

Print a single integer, the minimum number of shuffles required to bring the -th card to -th position. If it is not possible to do so, print instead.

样例

样例输入 1

4 3 8

样例输出 1

3

样例输入 2

5 4 1

样例输出 2

5

样例输入 3

1 1 1 

样例输出 3

0