9032: Merge the squares!

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Just like all math-loving students, Bobo loves squares, especially big ones, and he loves to combine many small squares into a big one. “Exactly. That's why I drew squares on my algebra exam,” Bobo explained to his algebra professor. 
Because of this, Bobo is also interested in perfect squared squares, which are squares that can be dissected into smaller squares of different sizes. The smallest order for a perfect squared square is 21, discovered by A. J. W. Duijvestijn. 
However, it's too difficult for Bobo to assemble squares of different sizes into a big square, so he wants to start with something simpler, like assembling n×nn\times nn×n small squares with side length 1 into a big square with side length nnn. Of course, Bobo cannot use only one operation to assemble all the squares together, or it would be too boring. He now has a new requirement: the number of squares merged each time must be between 2 and 50 (inclusive), and the resulting shape must still be a square. 

Bobo doesn't know how to proceed, so he has given this problem to you. It is guaranteed that under the constraint of this problem, a valid sequence of operations always exists.


输入格式

The only line contains an integer nnn (1≤n≤1000), denoting the number of rows and columns of the small squares.

输出格式

Output a number mmm (0≤m≤106) in the first line, representing the number of operations. In the next mmm lines, output three numbers x, y and k per line, representing one operation. Here, 1≤x≤n and 1≤y≤n represent the row number and column number of the upper-left corner of the merged large square after this operation (1−n  is used to represent the row number and column number), and 1≤k≤n  represents the side length of the merged large square. You need to ensure that each of your operations satisfies the following conditions:
1.   x+k−1≤n,y+k−1≤n 
2.   The square with side length  whose upper-left corner is in cell (x,y)  contains only complete squares, and the number of squares is between  and 50.
You also need to ensure that after all the operations are completed, all n×n small squares with a side length of  will be pieced together to form a large square with a side length of . If there are multiple valid sequence of operations, you may output any of it. Refer to the notes section for more information.

输入样例 复制

1

输出样例 复制

0

数据范围与提示

示例三:
输入
8
输出
5
1 1 4
1 5 4
5 1 4
5 5 4
1 1 8