Problem: Fillomino is a classic logic puzzle. (You do not need to know Fillomino in order to solve this problem.) In one classroom in Yunqi town, some volunteers are playing a board game variant of it:

Consider an n by n chessboard. Its rows are numbered from 1 to n from the top to the bottom. Its columns are numbered from 1 to n from the left to the right. A cell on an intersection of x-th row and y-th column is denoted (x, y). The main diagonal of the chessboard is cells (x, x) for all 1 ≤ x ≤ n.

A permutation of \{1, 2, 3, ..., n\} is written on the main diagonal of the chessboard. There is exactly one number written on each of the cells. The problem is to partition the cells under and on the main diagonal (there are exactly 1+2+ … +n such cells) into n connected regions satisfying the following constraints:

  1. Every region should be connected. That means that we can move from any cell of a region to any other cell of the same region visiting only cells of the same region and moving from a cell to an adjacent cell. 
  2. The x-th region should contain cell on the main diagonal with number x for all 1≤ x≤ n. 
  3. The number of cells that belong to the x-th region should be equal to x for all 1≤ x≤ n. 
  4. Each cell under and on the main diagonal should belong to exactly one region. 

Input

The first line contains a single integer n (1≤ n ≤ 500) denoting the size of the chessboard.

The second line contains n integers p_1, p_2, ..., p_n. p_i is the number written on cell (i, i). It is guaranteed that each integer from \{1, …, n\} appears exactly once in p_1, ..., p_n.

Output

If no solution exists, output -1.

Otherwise, output n lines. The i-th line should contain i numbers. The j-th number on the i-th line should be x if cell (i, j) belongs to the the region with x cells.

Examples

Input


3
2 3 1


Output


2
2 3
3 3 1


Input


5
1 2 3 4 5


Output


1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Note

The solutions to the examples are illustrated in the following pictures: <image> <image>

Solution (in CPP):

Solution:
//n & (1<<i)- for extracting ith bits
//while(n>0){count=count+(n&1); n=n>>1;}//counting set bits

#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x) x.begin(),x.end()
const int INF = 1000000000000000;
bool cmp(pair<string, int>& a,
         pair<string, int>& b)
{
    return a.second < b.second;
}

int gcd(int a, int b){
if (a==0){
    return b;
}
return gcd(b%a,a);


}

int factorial(int n)
{
    // single line to find factorial
    return (n==1 || n==0) ? 1: (n * factorial(n - 1)%mod);
}


string add(string a,string b){
	if(a.size()<b.size())swap(a,b);
	string ans;
	int n=a.size();
	int n1=a.size()-b.size();
	string temp;
	for(int i=0;i<n1;i++)temp+="0";
	b=temp+b;
	int car=0;
	for(int i=n-1;i>=0;i--){
		ans+=(char)((a[i]-'0'+b[i]-'0'+car)%10+'0');
		car=(a[i]-'0'+b[i]-'0'+car)/10;
	}
	if(car)ans+=(char)(car+'0');
	reverse(all(ans));
	return ans;
}

bool cmp(string s1,string s2){
	if(s1.size()!=s2.size())return s1.size()<s2.size();
	int n=s1.size();
	for(int i=0;i<n;i++)
		if(s1[i]>s2[i])return 0;
		else if(s1[i]<s2[i])return 1;
	return 1;
}


vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}





void reverseStr(string& str)
{
    int n = str.length();

    // Swap character starting from two
    // corners
    for (int i = 0; i < n / 2; i++)
        swap(str[i], str[n - i - 1]);
}

void bfs(vector<set<int>> g, int s, int dist[])
{
	bool mark[1010]; memset(mark, 0, sizeof mark);
	dist[s] = 0;
	queue<int> q;
	q.push(s);
	mark[s] = 1;
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		for (auto v : g[u])
		{
			if (mark[v]) continue;
			dist[v] = 1 + dist[u];
			mark[v] = 1;
			q.push(v);
		}
	}
}

// int lim=150005;
// vector<int> adj[150005];
// vi vis(lim,0);
// void dfs(int x, int &v, int &e){
// if (vis[x]==1)
//     return ;
// v++;
// e+=adj[x].size();

// vis[x]=1;
// //int res=0;
// for (auto &it:adj[x]){
//     if (vis[it]!=1){
//         //res=max(res,it.second +dfs(it.first,vis));
//         dfs(it,v,e);
//     }
// }
// //return res;
// }

vector<pair<int,int>> wg[100050];

int f=0;

 vi d(100050,INF);
vi dijkstra(int src)
{
    set<pair<int,int>> s;

    // vi parent(n+1,-1);
    d[src]=0;
    s.insert({0,src});
    while(!s.empty()){
        int i=s.begin()->second;
        s.erase(s.begin());
        for (auto & e:wg[i]){
            int nb=e.first;
            int w=e.second;
            if (d[i]+w<d[nb]){
                s.erase({d[nb],nb});
                d[nb]=d[i]+w;
                s.insert({d[nb],nb});
                // parent[nb]=i;
            }
        }
    }
   // return parent;

}
int a[500][500];
int fl=1;
int n;

void solve (int r,int need, int x,int y){
        a[x][y]=r;
        need--;
        if (need==0){
            return;
        }
        if (a[x][y-1]==0 && y-1>=0){
            solve(r,need,x,y-1);
        }
        else if (a[x+1][y]==0 && x+1<n){
            
            solve(r,need,x+1,y);
        }
        
       else {
        return;
       }
}




int32_t main(){
fastIO;

cin>>n;
int a2[500][500];
vi r(n);
for (int i=0;i<n;i++){
cin>>r[i];
}
for (int i=0;i<n;i++){
    solve(r[i],r[i],i,i);

}
for (int i=0;i<n;i++){
        for (int j=0;j<=i;j++){
         if (a[i][j]==0){
            fl=0;
         }
    }
}
if (fl==0){
   cout<<-1;
}
else {
    for (int i=0;i<n;i++){
        for (int j=0;j<=i;j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
}





return 0;
}