import java.io.*;
import java.util.*;

public class cipher_av_wa {

	public void solve() {
		int n = in.nextInt();

		final List<int[]> allPermutations = new ArrayList<>();
		class PermGenerator {
			int n;
			int[] p;
			boolean[] used;

			public PermGenerator(int n) {
				this.n = n;
				this.p = new int[n];
				this.used = new boolean[n];
			}

			public void generate() {
				gen(0);
			}

			private void gen(int pos) {
				if (pos == n) {
					allPermutations.add(p.clone());
					return;
				}
				for (int i = 0; i < n; i++) {
					if (!used[i]) {
						used[i] = true;
						p[pos] = i;
						gen(pos + 1);
						used[i] = false;
					}
				}
			}
		}
		
		new PermGenerator(n).generate();
		int resultLength = n * allPermutations.size();
		out.println(resultLength);
		for (int[] perm : allPermutations) {
			for (int i = 0; i < perm.length; i++) {
				out.print((perm[i] + 1) + " ");
			}
		}
		out.println();
	}

	FastScanner in;
	PrintWriter out;

	public void run() {
		try {
			in = new FastScanner("cipher.in");
			out = new PrintWriter("cipher.out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String name) {
			try {
				br = new BufferedReader(new FileReader(name));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new cipher_av_wa().run();
	}
}
