```go
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
in := bufio.NewReader(os.Stdin)
var n int
fmt.Fscan(in, &n)
L := get(n)
fmt.Println(len(L))
for _, part := range L {
for ip, pile := range part {
if ip > 0 {
fmt.Print(" | ")
}
for it, toy := range pile {
if it > 0 {
fmt.Print(" ")
}
fmt.Print(toy)
}
}
fmt.Println()
}
}
func copyBlocks(b [][]int) [][]int {
res := make([][]int, len(b))
for i := range res {
res[i] = make([]int, len(b[i]))
copy(res[i], b[i])
}
return res
}
func get(n int) [][][]int {
if n == 1 {
return [][][]int{{{1}}}
}
prev := get(n - 1)
var result [][][]int
for idx, p := range prev {
blocks := copyBlocks(p)
k := len(blocks)
var sub [][][]int
if idx%2 == 0 {
for j := 0; j < k; j++ {
np := copyBlocks(blocks)
np[j] = append(np[j], n)
sort.Ints(np[j])
sort.Slice(np, func(a, b int) bool {
return np[a][0] < np[b][0]
})
sub = append(sub, np)
}
np := copyBlocks(blocks)
np = append(np, []int{n})
sort.Slice(np, func(a, b int) bool {
return np[a][0] < np[b][0]
})
sub = append(sub, np)
} else {
np := copyBlocks(blocks)
np = append(np, []int{n})
sort.Slice(np, func(a, b int) bool {
return np[a][0] < np[b][0]
})
sub = append(sub, np)
for j := k - 1; j >= 0; j-- {
np := copyBlocks(blocks)
np[j] = append(np[j], n)
sort.Ints(np[j])
sort.Slice(np, func(a, b int) bool {
return np[a][0] < np[b][0]
})
sub = append(sub, np)
}
}
result = append(result, sub...)
}
return result
}
```