import java.io.*;
import java.util.*;
/***
*思路:DFS加回溯
* 技巧就是对于斜对角线上面是否有结点的判别,
* 算一下就知道,左下到右上斜对角线i+j=固定值,左上到右下i-j+n=固定值
* @author m
*/
public class P1219 {
static int row[] = new int [50];//行
static int col[] = new int [50];//列
static int arr1[] = new int [50];//左上角和右下角
static int arr2[] = new int [50];//左下角和右上角
static int n ;
static int res;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
Arrays.fill(row, 0);
Arrays.fill(col, 0);
Arrays.fill(arr1, 0);
Arrays.fill(arr2, 0);
res = 0;
dfs(1);
System.out.println(res);
}
private static void dfs(int i) {
if(i > n ){
printInfo();
return;
}else{
for(int j = 1;j <= n;j++){
if(col[j] == 0 && arr2[i+j] == 0 && arr1[i-j+n] == 0){//等于0,没有皇后
row[i] = j;
col[j] = 1;
arr2[i+j] = 1;
arr1[i-j+n] = 1;
dfs(i +1);
col[j] = 0;
arr2[i+j] = 0;
arr1[i-j+n] = 0;
}
}
}
}
private static void printInfo() {
if(res <= 2){
for(int i = 1;i <= n;i++){
System.out.print(row[i] + " ");
}
System.out.println();
}
res ++;
}
}