CF441D Valera and Swaps

Description

A permutation $ p $ of length $ n $ is a sequence of distinct integers $ p_{1},p_{2},...,p_{n} $ $ (1

Input Format

The first line contains integer $ n $ ( $ 1

Output Format

In the first line, print integer $ k $ — the minimum number of swaps. In the second line, print $ 2k $ integers $ x_{1},x_{2},...,x_{2k} $ — the description of the swap sequence. The printed numbers show that you need to consecutively make swaps $ (x_{1},x_{2}) $ , $ (x_{3},x_{4}) $ , ..., $ (x_{2k-1},x_{2k}) $ . If there are multiple sequence swaps of the minimum length, print the lexicographically minimum one.

Explanation/Hint

Sequence $ x_{1},x_{2},...,x_{s} $ is lexicographically smaller than sequence $ y_{1},y_{2},...,y_{s} $ , if there is such integer $ r $ $ (1