시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB1000.000%

문제

In preparation for the Fo(1)otball cup, the cheerleaders from Little Square’s school are trying to create a new routine. There are 2N cheerleaders with distinct heights between 0 and 2N − 1. The cheerleaders stand in a row. The height of the cheerleader that is initially at position i is h[i] for 1 ≤ i ≤ 2N.

The cheerleaders know two coordinate dance moves:

  • The big swap. In this move, the first 2N−1 cheerleaders swap places with the last 2N−1 cheerleaders.
  • The big split. In this move, the cheerleaders at odd positions go to the beginning of the row, and the cheerleaders at even positions go to the end of the row.

For instance, a big swap on 8 elements has the following effect:

And a big split on 8 elements has the following effect:

Now, define the number of inversions of a row of cheerleaders with heights h'[1], . . . , h'[2N] as the number of pairs (i, j), 1 ≤ i < j ≤ 2N where h'[i] > h'[j]. The cheerleaders want to know a sequence of dance moves that minimises the number of inversions in the resulting row.

입력

On the first line of the input you will find N. On the second line of the input you will find 2N integers, that represent h[1], . . . , h[2N].

출력

On the first line of the output, print the minimum number of inversions that can be achieved. On the second line of the output, write a string that represents a sequence of dance moves that leads to that minimum number of inversions. In this string, a 1 represents a big swap, and a 2 represents a big split. Any sequence of moves that leads to the minimum number of inversions will be accepted.

제한

  • 0 ≤ N ≤ 17.
  • N can be 0.
  • If you output the correct minimum number of inversions, but the string of moves is incorrect, you will receive X points. The value of X varies from subtask to subtask.

서브태스크 1 (16점)

  • N ≤ 4
  • X = 8

서브태스크 2 (10점)

  • N ≤ 7
  • X = 5

서브태스크 3 (25점)

  • N ≤ 11
  • X = 20

서브태스크 4 (21점)

  • N ≤ 16
  • It is guaranteed that the minimum number of inversions that can be achieved is 0.
  • X = 0

서브태스크 5 (28점)

  • No additional restrictions.
  • X = 21

예제 입력 1

2
0 3 1 2

예제 출력 1

1
2212

예제 입력 2

3
2 3 7 6 1 4 5 0

예제 출력 2

8
21221

예제 입력 3

4
1 4 8 5 3 6 12 13 10 11 2 9 14 0 15 7

예제 출력 3

43
2222

채점 및 기타 정보

  • 예제는 채점하지 않는다.