King’s Task

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.

There is a permutation p_ip\_i of numbers from 1 to 2n2n. You can make two types of operations.

  1. Swap p_1p\_1 and p_2p\_2, p_3p\_3 and p_4p\_4, ..., p_2n1p\_{2n-1} and p_2np\_{2n}
  2. Swap p_1p\_1 and p_n+1p\_{n+1}, p_2p\_2 and p_n+2p\_{n+2}, ..., p_np\_{n} and p_2np\_{2n}.

The task is to find the minimal number of operations required to sort the given permutation.

The Knight was not that smart actually, but quite charming, so the princess asks you to help him to solve the King's task.

입력

The first line contains the integer nn (1n10001\le n\le 1000). The second line contains 2n2n integers p_ip\_i --- the permutation of numbers from 1 to 2n2n.

출력

Print one integer --- the minimal number of operations required to sort the permutation. If it is impossible to sort the permutation using these operations, print 1-1.

힌트

In the first example, you can sort the permutation in three operations:

  1. Make operation 1: 3,6,5,2,1,43, 6, 5, 2, 1, 4.
  2. Make operation 2: 2,1,4,3,6,52, 1, 4, 3, 6, 5.
  3. Make operation 1: 1,2,3,4,5,61, 2, 3, 4, 5, 6.