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>
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.PriorityQueue;

public class Solution {
	static InputReader in = new InputReader(System.in);
	static int mod = (int)1e9 + 7;
	
    public static void main(String args[]) {
        new Thread(null, new Runnable() {
            public void run() {
                try{
                    solve();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 26).start();
    }
    
    public static void solve(){
    	 int n = in.nextInt();
    	 int[] p = new int[n];
    	 int oneIdx = -1;
    	 for(int i = 0; i < n; i++) {
    		 p[i] = in.nextInt();
//    		 if(p[i] == 1) oneIdx = i;
    	 }
    	 
    	 int[][] ar = new int[n][n];
//    	 for(int i = 0; i < n; i++) {
//    		 ar[i][i] = p[i];
//    		 if(i < oneIdx) ar[i + 1][i] = p[i];
//    		 else if(i > oneIdx) ar[i][i - 1] = p[i];
//    	 }
//    	 
    	 int count = p[0] - 1;
    	 ar[0][0] = p[0];
    	 for(int i = 1; i < n; i++) {
    		 if(count <= 0) break;
    		 ar[i][0] = p[0];
    		 count--;
    	 }
    	 
    	 count = p[n - 1] - 1;
    	 ar[n - 1][n - 1] = p[n - 1];
    	 for(int i = n - 2; i >= 0; i--) {
    		 if(count <= 0) break;
    		 ar[n - 1][i] = p[n - 1];
    		 count--;
    	 }
    	 
    	 for(int i = 1; i < n - 1; i++) {
    		 ar[i][i] = p[i];
    		 int req = p[i] - 1;
    		 int x = i, y = i;
    		 while(req > 0) {
    			 if(isSafe(x, y - 1, n, ar)) {
    				 y = y- 1;
    				 ar[x][y] = ar[i][i];
    			 } else if(isSafe(x + 1, y, n, ar)) {
    				 x = x + 1;
    				 ar[x][y] = ar[i][i];
    			 } else {
    				 System.out.println(-1);
    				 return;
    			 }
    			 req--;
    		 }
    	 }
    	 
    	 for(int i = 0; i < n; i++) {
    		 for(int j = 0; j <= i ; j++) {
    			 
    			 System.out.print(ar[i][j] + " ");
    		 }
    		 System.out.println();
    	 }
    	 
    }
   
    private static boolean isSafe(int x, int y, int n, int[][] ar) {
		return x >= 0 && x < n && y >= 0 && y < n && ar[x][y] == 0;
	}

	/*TEMPLATE*/
    
    //MATHS
    static int gcd(int a, int b) {
    	return (b==0)?a:gcd(b,a%b);
    }
    
    static long binPow(long x, long y) {
        long ans = 1L;
        while(y > 0) {
            if(y % 2 == 1)
                ans = mul(ans, x);
            x = mul(x, x);
            y /= 2;
        }
        return ans;
    }
    
    static long add(long x, long y) {
    	x += y;
    	return mod(x, mod);
    }
    
    static long mul(long x, long y) {
    	return mod(x * y, mod);
    }
    
    static long divide(long x, long y) {
        return mul(x, binPow(y, mod - 2));
    }

    static long mod(long x, long p) {
        x %= p;
        if (x < 0)
            x += p;
        return x;
    }
        
    public static int[] spf(int maxn) {
    	int[] spf=new int[maxn+1];
    	spf[0]=spf[1]=1;
    	for(int i=2;i<=maxn;i++) {
    		if(i%2==0) spf[i]=2;
    		else 
    			spf[i]=i;
    	}
    	for(int i=3;i*i<=maxn;i++) {
    		if(spf[i]==i){
    			for (int j=i*i; j<=maxn; j+=i) 
                    if (spf[j]==j) 
                        spf[j] = i;
    		}
    	}
    	return spf;
    }
    
    //ARRAYS
    public static int[] intArray(int n) {
    	int ar[]=new int[n];
    	for(int i=0;i<n;i++)
    		ar[i]=in.nextInt();
    	return ar;
    }
    
    public static void swap(int i, int j, int ar[]) {
    	int c=ar[i];ar[i]=ar[j];ar[j]=c;
    }
    
    public static void reverse(int ar[]) {
    	int l=0, r=ar.length-1;
    	while(l<r) {
    		int temp=ar[l]; ar[l]=ar[r]; ar[r]=temp;
    		l++; r--;
    	}
    }
    
    public static int upperBound(int[] array, int value) {
    	//return next higher element. If greater than all elements then returns array.length
    	//returns 0 if smaller than all elements
    	int low = 0;
    	int high = array.length;
    	while (low < high) {
    		final int mid = (low + high) / 2;
    		if (value >= array[mid]) {
    			low = mid + 1;
    		} else {
    			high = mid;
    		}
    	}
    	return low;
    }
    
    public static int lowerBound(int[] array, int value) {
    	//Returns first occurrence.
    	//Bigger than all elements then return array.length
    	//Not found, then next greater.s
    	int low = 0;
    	int high = array.length;
    	while (low < high) {
    		final int mid = (low + high) / 2;
			if (value <= array[mid]) {
			high = mid;
			} else {
				low = mid + 1;
			}
    	}
    	return low;
	}
    
    public static void pn(Object o) {
      System.out.println(o);
    }
    
    static class InputReader {
 
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;
 
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
 
        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
 
        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
 
            int res = 0;
 
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
 
            return res * sgn;
        }
 
        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
 
            long res = 0;
 
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
 
            return res * sgn;
        }
 
        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }
 
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
 
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}