PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000373. Các phép biến đổi LCM kỳ lạ (Weird LCM Operations)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Các phép biến đổi LCM kỳ lạ (Weird LCM Operations)

Weird LCM Operations

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an integer nn and an array aa with ai=ia_i=i initially for 1≤i≤n1\le i\le n.

An operation chooses three pairwise distinct indices i,j,ki,j,k. Let the old values be x=aix=a_i, y=ajy=a_j, z=akz=a_k. Update the three positions simultaneously by

$$a_i\gets\operatorname{lcm}(y,z),\quad a_j\gets\operatorname{lcm}(x,z),\quad a_k\gets\operatorname{lcm}(x,y).$$

Construct at most ⌊n/6⌋+5\lfloor n/6\rfloor+5 operations so that the final array has the following property: for every integer d∈[1,n]d\in[1,n], there is a subsequence containing at least two different positions whose values have GCD exactly dd.

No array value may exceed 101810^{18} after any operation. A valid answer is guaranteed to exist. There may be several correct operation sequences; a special checker validates the construction.

Input

One input file contains exactly one integer nn, representing one independent instance of the original problem.

Output

Print an integer kk on the first line (number of operations). Each of the next kk lines contains three indices i,j,ki,j,k for an operation. Your output need not match the sample output.

Subtasks

  • Subtask 1 (20 points): 3≤n≤203\le n\le20; at most ⌊n/6⌋+5\lfloor n/6\rfloor+5 operations; every resulting value ≤1018\le10^{18}.
  • Subtask 2 (30 points): 3≤n≤3 0003\le n\le3\,000; at most ⌊n/6⌋+5\lfloor n/6\rfloor+5 operations; every resulting value ≤1018\le10^{18}.
  • Subtask 3 (50 points): 3≤n≤30 0003\le n\le30\,000; at most ⌊n/6⌋+5\lfloor n/6\rfloor+5 operations; every resulting value ≤1018\le10^{18}.

Examples

Example 1

Input

3

Output

1
1 2 3

Explanation

Initially a=[1,2,3]a=[1,2,3]. Operation (1,2,3)(1,2,3) produces [6,3,2][6,3,2]. We have gcd⁡(6,3)=3\gcd(6,3)=3, gcd⁡(6,2)=2\gcd(6,2)=2, and gcd⁡(3,2)=1\gcd(3,2)=1, so every required value 1,2,31,2,3 occurs.

Example 2

Input

7

Output

3
3 5 7
5 6 7
2 3 4

Explanation

The three operations produce [1,140,4,70,30,105,42][1,140,4,70,30,105,42]. For instance, gcd⁡(30,105,42)=3\gcd(30,105,42)=3, gcd⁡(30,42)=6\gcd(30,42)=6, and gcd⁡(140,70,105,42)=7\gcd(140,70,105,42)=7. Other subsequences of at least two elements yield 1,2,4,51,2,4,5.

Editorial adaptation: Each PHOJ input file is one independent instance of the original problem.