PivotOJ

Pair Sorting

시간 제한: 1000ms메모리 제한: 2048MB출처: ICPC Asia Seoul Regional 2024BOJ 32834

문제

There are nn bins arranged in a row and 2n2n balls on the ground. The balls are numbered from 11 to nn and there are exactly two balls numbered ii, for each ii, 1 ≤ i ≤ n. Also, for 1 ≤ i ≤ n, the ii-th bin is denoted by BiB_i and each bin BiB_i can contain at most two balls. Initially, the bin BiB_i contains both of ball n+1in + 1 - i’s, for 1 ≤ i ≤ n. See the Figure F.1 below for the initial configuration of bins.

Figure F.1. The initial configuration of bins

You can swap two balls only from adjacent bins, which implies one swap operation. Note the bin is not a stack and for adjacent bins BiB_i and Bi+1B_{i+1}, you can swap the one of two balls in BiB_i and the one in Bi+1B_{i+1}. See the Figure F.2 below. The figure represents two swap operations.

Figure F.2. The swap operations between adjacent bins

Through these swap operations, you should sort the balls. As a result of the sorting, the bin BiB_i must contain the both of ball ii’s, for 1 ≤ i ≤ n. In particular, the total number of swap operations should be no more than BoundBound, when BoundBound is given as a function of nn, especially, Bound=0.7n2Bound = 0.7n^2.

Given nn bins and 2n2n balls, write a program to find a sorting method of balls such that the total number of swap operations is no more than Bound=0.7n2Bound = 0.7n^2.

입력

Your program is to read from standard input. The input consists of exactly one line. The line contains an integer nn (3 ≤ n ≤ 100), representing that there are nn bins and 2n2n balls.

출력

Your program is to write to standard output. Let SS be the total number of swap operations in your sorting method for the input. Print exactly S+1S + 1 lines. The first line contains SS. Each of the following SS lines contains three integers jj, aa, and bb, representing one swap operation between the ball aa in the bin BjB_j and the ball bb in Bj+1B_{j+1}, where 1 ≤ j ≤ n - 1 and 1 ≤ a, b ≤ n. The swap operations in your sorting method should be printed in order, one per line. The number SS must satisfy that S ≤ 0.7n^2.

예제

예제 1

입력
3
출력
6
1 3 2
2 3 1
1 2 1
1 3 2
2 3 1
1 2 1

예제 2

입력
3
출력
5
1 3 2
2 3 1
1 3 1
2 3 1
1 2 1
코드를 제출하려면 로그인하세요.