#include <fstream>
#include <algorithm>

using namespace std;

ifstream fi("hoanvi.inp");
ofstream fo("hoanvi.out");

int n,a[21],b[21];

int nhap()
{
    ios::sync_with_stdio(false);
    fi >> n;
}

int xuat(int q)
{
    for (int i = 1; i <= q; i++) fo << a[i] << " ";
    fo << endl;
}

int main()
{
    nhap();
    for (int i = 1; i <= n; i++)
    {
        a[i] = i;
        fo << a[i] << " ";
    }
    fo << endl;
    int i = n;
    int d = 0;
    while (i > 0)
    {
        i = n-1;
        while (a[i] > a[i+1]) i--;
        if (i > 0)
        {
          int k = n;
          while (a[k] < a[i]) k--;
          int tg = a[i];
          a[i] = a[k]; a[k] = tg;
          int tg1 = i+1,tg2 = n;
          while (tg1 < tg2)
          {
              tg = tg1; tg1 = tg2; tg2 = tg;
          }
          d++;
          xuat(n);
        }
    }
    return 0;
}
