#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream input("hoanvi.inp");
ofstream output("hoanvi.out");
/*
void print(vector <int> &sub)
{
	for (unsigned int i = 0; i < sub.size(); i++)
	{
		output << sub[i] << ' ';
		cout << sub[i] << ' ';
	}
	output << '\n';
	cout << '\n';
}

void hoanvi(vector <int> &sub)
{
	print(sub);
	unsigned int i, j;
	for (i = sub.size() - 2; i >= 0; i--)
	{
		if (sub[i] < sub[i + 1]) break;
		if (i == 0)
		{
			return;
		}
	}
	for (j = sub.size() - 1; j >= 0; j--)
	{
		if (sub[i] < sub[j])
		{
			swap(sub[i], sub[j]);
			break;
		}
	}
	reverse(sub.begin() + i + 1, sub.end());
	hoanvi(sub);
}
int main()
{
	int n;
	input >> n;
	vector <int> sub(n);
	for (unsigned int i = 0; i < n; i++)
	{
		sub[i] = i + 1;
	}
	sub = { 1, 2, 4, 9, 7, 6, 10, 3, 8, 5, };
	hoanvi(sub);
	input.close();
	output.close();
	return 0;
}
*/

void print(vector <int> &sub)
{
	for (unsigned int i = 0; i < sub.size(); i++)
	{
		output << sub[i] << ' ';
	}
	output << '\n';
}

void hoanvi(int n, vector <int> &sub)
{
	if (n == 1)
	{
		print(sub);
	}
	else
	{
		for (int i = 0; i < n - 1; i++)
		{
			hoanvi(n - 1, sub);
			if (n % 2 == 1)
			{
				swap(sub[i], sub[n - 1]);
			}
			else
			{
				swap(sub[0], sub[n - 1]);
			}
		}
		hoanvi(n - 1, sub);
	}
}

int main()
{
	int n;
	input >> n;
	vector <int> sub(n);
	for (unsigned int i = 0; i < n; i++)
	{
		sub[i] = i + 1;
	}
	hoanvi(n, sub);
	input.close();
	output.close();
	return 0;
}