cho.sh
Notes
Loading...

Degree Sequence

Time limit

2s

Memory limit

128 MB

Problem

In an undirected graph, the degree of a vertex is the number of edges incident to that vertex.

If the degrees of all vertices are listed in vertex-number order, the result is a sequence called a degree sequence. Given an arbitrary degree sequence, construct one simple undirected graph whose vertex degrees match that sequence.

Edges are undirected, and self-loops are not allowed. The graph does not have to be connected, but the given degree sequence must correspond exactly to the vertex order.

Input

The first line contains the number of vertices N. (2 <= N <= 2,000)

The second line contains N integers forming the degree sequence, separated by spaces. Each integer is between 0 and N - 1, inclusive.

Output

Print the adjacency matrix of the graph over N lines, starting from the first line. Every entry of the matrix must be either 0 or 1.

If multiple graphs are possible, print any one of them. If no graph satisfies the given degree sequence, print only -1 on the first line.