| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 70 | 50 | 41 | 71.930% |
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 2n cards, shows her friends the face of the cards whithout changing the deck order and asks someone to pick two positions i and j in the deck. Then, she tells everyone that she is going to move the card in the i-th position to the j-th position by applying only two types of shuffles.
Assume the cards in the deck are 〈c1, c2, ..., c2n〉. Mahsa can perform these two shuffles as many times as she wants:
Riffle: Divide the cards into two parts〈c1, c2, ..., cn〉 and 〈cn+1, ..., c2n〉 and produce 〈c1, cn+1, c2, cn+2, ..., cn, c2n〉.
Scuffle: From 〈c1, c2, ..., c2n〉, produce 〈c2, c1, c4, c3, ..., c2n, c2n-1〉.
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 n, i and j (1 ⩽ n ⩽ 105 and 1 ⩽ i, j ⩽ 2n).
Print a single integer, the minimum number of shuffles required to bring the i-th card to j-th position. If it is not possible to do so, print -1 instead.
4 3 8
3
5 4 1
5
1 1 1
0