시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 64 29 24 45.283%

문제

서로 다른 크기의 n개의 팬케익이 쌓여 있다. 순서 없이 마구 쌓여져있는 팬케익을 크기 순대로 쌓으려고 한다. 가장 위에는 제일 작은 크기의 팬케익이 있어야 되고, 가장 아래에는 제일 큰 크기의 팬케익이 있어야 한다.

팬케익을 뒤집는 방법은 위에서 k개의 순서를 뒤집는 것이다. 따라서 k번째 팬케익이 가장 위로 올라오게 되고, 제일 위에 있던 팬케익은 k번째가 된다.

다음 예를 보자.

팬케익이 쌓여있는 상태가 주어졌을 때, 이를 순서대로 만드는 방법을 찾아 출력하는 프로그램을 작성하시오. 팬케익은 최대 2n-3번 뒤집을 수 있다.

입력

첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 숫자 여러개가 공백으로 구분되어있다. 첫번째 숫자는 팬케익의 개수 N이고, 그 다음 N개의 숫자는 팬케익의 크기이다. 가장 위에 있는 팬케익이 첫 숫자이고, 마지막 숫자는 제일 아래에 있는 팬케익이다.  N은 30보다 작거나 같다. 팬케익의 크기는 서로 다르며, 1보다 크거나 같고, N보다 작거나 같다.

출력

각 테스트 케이스에 대해 한 줄에 하나씩 뒤집는 방법을 출력한다. 제일 먼저 뒤집는 횟수 K를 출력한다. 그 다음 뒤집는 방법을 순서대로 출력하면 된다. 뒤집는 방법이 여러개일 때는, 아무거나 출력하면 된다.

예제 입력 1

2
3 1 3 2
5 4 3 2 5 1

예제 출력 1

3 2 3 2
3 3 4 5
W3sicHJvYmxlbV9pZCI6IjI3NTkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQzMmNcdWNmMDBcdWM3NzUgXHViNGE0XHVjOWQxXHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cclxuXHRcdWMxMWNcdWI4NWMgXHViMmU0XHViOTc4IFx1ZDA2Y1x1YWUzMFx1Yzc1OCBuXHVhYzFjXHVjNzU4IFx1ZDMyY1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