← Home
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		return
	}

	var cycles [][]int

	if n%2 == 1 {
		cycles = append(cycles, []int{3, 1, 2, 3})
		cycles = append(cycles, []int{3, 1, 2, 3})
		for curr := 3; curr < n; curr += 2 {
			u := curr + 1
			v := curr + 2
			cycles = append(cycles, []int{3, u, v, 1})
			cycles = append(cycles, []int{3, u, v, 1})
			for i := 2; i <= curr; i += 2 {
				cycles = append(cycles, []int{4, u, i, v, i + 1})
				cycles = append(cycles, []int{4, u, i, v, i + 1})
			}
		}
	} else {
		cycles = append(cycles, []int{4, 1, 2, 3, 4})
		cycles = append(cycles, []int{4, 1, 2, 4, 3})
		cycles = append(cycles, []int{4, 1, 3, 2, 4})
		for curr := 4; curr < n; curr += 2 {
			u := curr + 1
			v := curr + 2
			cycles = append(cycles, []int{4, u, 1, v, 2})
			cycles = append(cycles, []int{3, u, v, 1})
			cycles = append(cycles, []int{3, u, v, 2})
			for i := 3; i <= curr; i += 2 {
				cycles = append(cycles, []int{4, u, i, v, i + 1})
				cycles = append(cycles, []int{4, u, i, v, i + 1})
			}
		}
	}

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fmt.Fprintln(out, len(cycles))
	for _, c := range cycles {
		for i, x := range c {
			if i > 0 {
				fmt.Fprint(out, " ")
			}
			fmt.Fprint(out, x)
		}
		fmt.Fprintln(out)
	}
}