Dr Who's Banquet

Build a chat graph whose vertex degrees equal the given wishes with the stated greedy construction, or print fail.

Medium4GraphGreedySortingNo attempts yetTime limit1sMemory limit256 MB

Problem

Dr Who is holding a banquet and invites several guests. Guest ii is happy when he chats with exactly aia_i of the other guests. A guest never chats with himself, and any two guests either chat with each other or they do not. Pair the guests so that every guest is happy, or report that no such arrangement exists.

Input

The input holds several data sets, one data set per line. A line holds the integers a1,a2,,ana_1, a_2, \dots, a_n separated by single spaces, where aia_i is the number of chat partners guest ii wants. The guests on a line are numbered 11 to nn in the order they appear. 1n100001 \le n \le 10000 and 1ai10001 \le a_i \le 1000. The input ends at the end of the file.

Output

Print one block for each data set. If every guest can be made happy, print the n×nn \times n matrix mm, where m[i][j]=m[j][i]=1m[i][j] = m[j][i] = 1 when guests ii and jj chat and 00 otherwise. Print each row on its own line and separate the values of a row by single spaces. If no arrangement makes every guest happy, print fail. Print one empty line after each block.

Several matrices can satisfy the same wish list, so only the matrix produced by the construction below counts as correct.

Give each guest a counter rir_i set to aia_i and put every guest in the pool. While some guest in the pool has ri>0r_i > 0, repeat this. Take the guest vv of the pool with the largest rvr_v, and among ties the one with the smaller number. Order the remaining guests of the pool by rr from large to small, breaking ties by the smaller number, and pair vv with the first rvr_v of them. Subtract 11 from the counter of each new partner, set rvr_v to 00, and remove vv from the pool. The matrix is complete once every guest left in the pool has ri=0r_i = 0. This construction pairs everybody whenever a valid arrangement exists.