package asd; import java.util.Scanner; public class Baqueeeeeeeeeeeeeeeeeen { /**
* @param args
*/ static Scanner sc=new Scanner(System.in);
static int n=sc.nextInt();
static int[]a=new int [n];
static int m=0;
public static void main(String[] args) {
bhh(0,a);
System.out.println(m); }
private static void bhh(int mark,int [] b) {
// TODO Auto-generated method stub
if(mark==a.length)
{
m++;
print();
return;
}
for(int i=0;i<a.length;i++)
{
a[mark]=i;
if(jc(mark,b)>0)
bhh(mark+1,b);
}
} private static void print() {
// TODO Auto-generated method stub
for(int i=0;i<a.length;i++)
System.out.print(a[i]+" ");
System.out.println();
}
private static int jc(int mark,int[] b) {
// TODO Auto-generated method stub
for(int i=0;i<mark;i++)
{
if(a[i]==a[mark])
return 0;
if(a[mark]-a[i]==mark-i||a[mark]-a[i]==i-mark)
return 0;
}
return 1;
} }
* @param args
*/ static Scanner sc=new Scanner(System.in);
static int n=sc.nextInt();
static int[]a=new int [n];
static int m=0;
public static void main(String[] args) {
bhh(0,a);
System.out.println(m); }
private static void bhh(int mark,int [] b) {
// TODO Auto-generated method stub
if(mark==a.length)
{
m++;
print();
return;
}
for(int i=0;i<a.length;i++)
{
a[mark]=i;
if(jc(mark,b)>0)
bhh(mark+1,b);
}
} private static void print() {
// TODO Auto-generated method stub
for(int i=0;i<a.length;i++)
System.out.print(a[i]+" ");
System.out.println();
}
private static int jc(int mark,int[] b) {
// TODO Auto-generated method stub
for(int i=0;i<mark;i++)
{
if(a[i]==a[mark])
return 0;
if(a[mark]-a[i]==mark-i||a[mark]-a[i]==i-mark)
return 0;
}
return 1;
} }