// mytest.cpp : 定义控制台应用程序的入口点。
//
#include"stdafx.h"
#include<stdio.h>
#include<string.h>
#include<assert.h>
#include<math.h>
#include<string>
#include<iostream>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
int visit[25];
int a[25];
int n, m;
int cnt;
void fre()
//输出重定向
{
freopen("E:\\input.txt", "r", stdin);
freopen("E:\\output.txt", "w", stdout);
}
void dfs(int x){
if (x > n) return;
for (int i = 1; i <= n; i++){
if (!visit[i]){
visit[i] = 1;
a[x] = i;
if (x >= 2){
for (int j = 1; j <= x; j++){
printf("%d ", a[j]);
}
printf("\n");
cnt++;
}
/*for (int j = 1; j < 6; j++){
printf("%d ", a[i]);
}
printf("\n");
*/
dfs(x + 1);
visit[i] = 0;
}
}
}
int main()
{
//小赛的家在楼层m,当前电梯停在的楼层n,
//以及电梯每经过一层楼的时间t1,开门时间t2,关门时间t3,还有小赛每下一层楼的时间t4,
//fre();
while (scanf("%d", &n) != EOF){
memset(visit, 0, sizeof(visit));
memset(a, 0, sizeof(visit));
cnt = 0;
dfs(1);
printf("%d\n", cnt);
}
return 0;
}