#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CR(t, x) const t &x
#define CLS(x) memset(x, 0, sizeof(x))
const int maxn = 3e5 + 5;
int a[maxn];
int from[maxn];
int di[maxn];
int ans[maxn];
int Len[maxn];
int n;
void upup_right()
{
    //right_est
    CLS(from);
    CLS(di);
    CLS(ans);
    CLS(Len);
    ans[1] = a[1];
    di[1] = 1;
    Len[1] = 1;
    int len = 1;
    for (int i = 2; i <= n; i++)
    {
        if (a[i] > ans[len])
        {
            ans[++len] = a[i];
            di[len] = i;
            from[i] = di[len - 1];
            Len[i] = len;
        }
        else
        {
            int pos = lower_bound(ans, ans + len, a[i]) - ans;
            from[i] = di[pos - 1];
            ans[pos] = a[i];
            di[pos] = i;
            Len[i] = pos;
        }
    }
    /*printf("%d\n", len);
    for (int i = 1; i <= n; i++) printf("%d ", from[i]);
    putchar('\n');*/
}
void upup_left()
{
    //left_est
    CLS(from);
    CLS(di);
    CLS(ans);
    CLS(Len);
    ans[1] = a[1];
    di[1] = 1;
    Len[1] = 1;
    int len = 1;
    for (int i = 2; i <= n; i++)
    {
        if (a[i] > ans[len])
        {
            ans[++len] = a[i];
            di[len] = i;
            from[i] = di[len - 1];
            Len[i] = len;
        }
        else
        {
            int pos = lower_bound(ans, ans + len, a[i]) - ans;
            Len[i] = pos;
            if (a[i] != ans[pos])
            {
                from[i] = di[pos - 1];
                ans[pos] = a[i];
                di[pos] = i;
            }
        }
    }
    /*printf("%d\n", len);
    for (int i = 1; i <= n; i++) printf("%d ", from[i]);
    putchar('\n');*/
}
int idx1[maxn], idx2[maxn], idx3[maxn], idx4[maxn];
int len1[maxn], len2[maxn], len3[maxn], len4[maxn];
int main()
{
    vector<int> st;
    while (~scanf("%d", &n))
    {
        for (int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        upup_left();
        //memcpy(idx1, from, sizeof(from));
        memcpy(len1, Len, sizeof(Len));
        memset(idx1, 0x3f, sizeof(idx1)), *idx1 = 0;
        for (int i = 1; i <= n; i++)
            idx1[len1[i]] = min(idx1[len1[i]], i);
        upup_right();
        //memcpy(idx3, from, sizeof(from));
        memcpy(len3, Len, sizeof(Len));
        memset(idx3, 0x3f, sizeof(idx3)), *idx3 = 0;
        for (int i = 1; i <= n; i++)
            idx3[len3[i]] = min(idx3[len3[i]], i);
        for (int i = 1, j = n; i < j;) swap(a[i++], a[j--]);
        upup_right();
        //memcpy(idx2, from, sizeof(from));
        memcpy(len2, Len, sizeof(Len));
        memset(idx2, 0, sizeof(idx2)), *idx2 = 0;
        for (int i = 1; i <= n; i++)
            idx2[len2[i]] = max(idx2[len2[i]], i);
        upup_left();
        //memcpy(idx4, from, sizeof(from));
        memcpy(len4, Len, sizeof(Len));
        memset(idx4, 0x3f, sizeof(idx4)), *idx4 = 0;
        for (int i = 1; i <= n; i++)
            idx4[len1[4]] = min(idx4[len4[i]], i);
        int idx = 0, _ans = 0;
        for (int i = 1; i <= n; i++)
            printf("%d ", len1[i]);
        putchar('\n');
        for (int i = 1; i <= n; i++)
            printf("%d ", len2[n - i + 1]);
        putchar('\n');
        for (int i = 1; i <= n; i++)
            printf("%d ", idx1[i]);
        putchar('\n');
        for (int i = 1; i <= n; i++)
            printf("%d ", idx2[n - i + 1]);
        putchar('\n');
        for (int i = 1; i <= n; i++)
            if (len1[i] + len2[n - i + 1] > _ans) _ans = len1[i] + len2[n - i + 1], idx = i;
        st.clear();
        for (int tmp = len1[idx]; tmp; tmp--)
            st.push_back(idx1[tmp]);
        for (; !st.empty(); st.pop_back())
            printf("%d ", st.back());
        for (int tmp = len2[n-idx+1] - 1; tmp; tmp--)
            printf("%d ", n - idx2[tmp] + 1);
        putchar('\n');
    }
    return 0;
}