You are given an integer $n$. A set, $\mbox{S}$, of triples $(x_i,y_i,z_i)$ is beautiful if and only if:

$0\leq x_i,y_i,z_i$
$x_i+y_i+z_i=n,\forall i:1\leq i\leq|S|$
Let $\mbox{X}$ be the set of different $x_i$'s in $\mbox{S}$, $\mathbf{Y}$ be the set of different $y_i$'s in $\mbox{S}$, and $\mbox{Z}$ be the set of different $z_i$ in $\mbox{S}$. Then $|X|=|Y|=|Z|=|S|$.

The third condition means that all $x_i$'s are pairwise distinct. The same goes for $y_i$ and $z_i$.

Given $n$, find any beautiful set having a maximum number of elements. Then print the cardinality of $\mbox{S}$ (i.e., $\left|S\right|$) on a new line, followed by $\left|S\right|$ lines where each line contains $3$ space-separated integers describing the respective values of $x_i$, $y_i$, and $z_i$.

Input Format

A single integer, $n$.

Constraints

$1\leq n\leq300$  

Output Format

On the first line, print the cardinality of $\mbox{S}$ (i.e., $\left|S\right|$). 

For each of the $\left|S\right|$ subsequent lines, print three space-separated numbers per line describing the respective values of $x_i$, $y_i$, and $z_i$ for triple $\boldsymbol{i}$ in $\mbox{S}$.

Sample Input
3

Sample Output
3
0 1 2
2 0 1
1 2 0

Explanation

In this case, $n=3$. We need to construct a set, $\mbox{S}$, of non-negative integer triples ($x_{i},y_{i},z_{i}$) where $x_{i}+y_{i}+z_{i}=n$. $\mbox{S}$ has the following triples:

$(x_1,y_1,z_1)=(0,1,2)$
$(x_2,y_2,z_2)=(2,0,1)$
$(z_3,y_3,z_3)=(1,2,0)$

We then print the cardinality of this set, $|S|=3$, on a new line, followed by $3$ lines where each line contains three space-separated values describing a triple in $\mbox{S}$.

Difficulty: MEDIUM_HARD

Solutions:
from math import floor, ceil
N = int(input())
if N == 0:
	print(1)
	print('0 0 0')
elif N == 1:
	print(1)
	print('1 0 0')
elif N == 2:
	print(2)
	print('1 1 0')
	print('0 0 2')
elif N == 3:
	print(3)
	print('0 1 2')
	print('2 0 1')
	print('1 2 0')
elif N == 4:
	print(3)
	print('0 1 3')
	print('3 0 1')
	print('1 3 0')
else:
	n23 = floor(N * 2 / 3) + 1
	print(n23)
	mid = [-1, -1, -1]
	mid[0] = ceil(n23 / 2)
	mid[1] = 0
	mid[2] = N - mid[0] - mid[1]
	print(' '.join(map(str, mid)))
	top = [-1, -1, -1]
	top[0] = mid[0] - 1
	top[2] = int(mid[2] % 2 == 0)
	top[1] = N - top[0] - top[2]
	print(' '.join(map(str, top)))
	while top[0] > 0:
		top[0] -= 1
		top[1] -= 1
		top[2] += 2
		print(' '.join(map(str, top)))
	bot = [-1, -1, -1]
	bot[0] = mid[0] + 1
	bot[1] = 1
	bot[2] = N - bot[0] - bot[1]
	print(' '.join(map(str, bot)))
	while bot[0] < n23 - 1:
		bot[0] += 1
		bot[1] += 1
		bot[2] -= 2
		print(' '.join(map(str, bot)))