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

public class cipher_av_wa2 {

	public void solve() {
		int n = in.nextInt();
		
		int[][] results = new int[n + 1][];
		results[1] = new int[] {0};
		for (int i = 2; i <= n; i++) {
			results[i] = construct(results[i - 1], i);
		}
		
		out.println(results[n].length);
		for (int i = 0; i < results[n].length; i++) {
			out.print(results[n][i]);
			if (i + 1 == results[n].length) {
				out.println();
			} else {
				out.print(" ");
			}
		}
	}
	
	private int[] construct(int[] a, int n) {
		int[] result = new int[a.length + fact(n)];
		int[] count = new int[n - 1];
		int countZeros = n - 1;
		int ptr = 0;
		
		for (int i = 0; i < a.length; i++) {
			int item = a[i];
			result[ptr++] = item;
			if (count[item] == 0) {
				countZeros--;
			}
			count[item]++;
			
			if (i - (n - 1) >= 0) {
				item = a[i - (n - 1)];
				if (count[item] == 1) {
					countZeros++;
				}
				count[item]--;
			}
			
			if (countZeros == 0) {
				int copyFrom = i - (n - 1) + 1;
				int copyTo = i;
				
				result[ptr++] = n - 1;
				for (int j = copyFrom; j <= copyTo; j++) {
					result[ptr++] = a[j];
				}
			}
		}
		return result;
	}

	private int fact(int n) {
		int result = 1;
		for (int i = 2; i <= n; i++) {
			result *= i;
		}
		return result;
	}

	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_wa2().run();
	}
}
