#include <iostream>
#include <ctime>
using namespace std;
const int N = 1000;
int main()
{
int n, i, j = 0, a[N], q;
cin >> n;
cout << endl << endl;
srand(time(NULL));
for (i = 0; i < n; i++)
a[i] = rand() % 10;
for (i = 0; i < n; i++) {
cout << a[i];
if ((i + 1) % 5 == 0)
cout << " | ";
}
cout << endl << endl;
for (q = 0; q < n - 4; q = q + 5)
for (i = q + 1; i < q + 5; i++)
for (j = i; j > q && a[j - 1 + q] > a[j + q]; j--)
swap(a[j - 1 + q], a[j + q]);
for (i = 0; i < n; i++) {
cout << a[i];
if ((i+1) % 5 == 0)
cout << " | ";
}
cout << endl << endl;
}