Magic with Cards


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

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 2n2n cards, shows her friends the face of the cards without changing the deck order and asks someone to pick two positions ii and jj in the deck. Then, she tells everyone that she is going to move the card in the ii-th position to the jj-th position by applying only two types of shuffles.

Assume the cards in the deck are c1,c2,,c2n\langle c_1, c_2, \dots, c_{2n} \rangle. Mahsa can perform these two shuffles as many times as she wants:

Riffle: Divide the cards into two parts c1,,cn\langle c_1, \dots, c_n \rangle and cn+1,,c2n\langle c_{n+1}, \dots, c_{2n} \rangle and produce c1,cn+1,c2,cn+2,,cn,c2n\langle c_1, c_{n+1}, c_2, c_{n+2}, \dots, c_n, c_{2n} \rangle.

Scuffle: From c1,c2,,c2n\langle c_1, c_2, \dots, c_{2n} \rangle, produce c2,c1,c4,c3,,c2n,c2n1\langle c_2, c_1, c_4, c_3, \dots, c_{2n}, c_{2n-1} \rangle.

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 nn, ii and jj (1n1051 \leq n \leq 10^5 and 1i,j2n1 \leq i, j \leq 2n).

خروجی🔗

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

مثال‌ها🔗

ورودی نمونه ۱🔗

4 3 8
Plain text

خروجی نمونه ۱🔗

3
Plain text

ورودی نمونه ۲🔗

5 4 1
Plain text

خروجی نمونه ۲🔗

5
Plain text

ورودی نمونه ۳🔗

1 1 1
Plain text

خروجی نمونه ۳🔗

0
Plain text