#!/usr/bin env python

import sys
import itertools
import math

n = int(sys.argv[1])

combinations = itertools.permutations(range(1,n+1))

print math.factorial(n)
for comb in combinations:
	print ' '.join(map(str, comb))

