Miguel organized a chess tournament with $$$n$$$ participants numbered from $$$1$$$ to $$$n$$$. Every pair played exactly one game. Every game ended with one winner and one loser; there were no draws.
Everything was going well until the software recording the results broke down. The individual game results disappeared, and only a table of totals could be recovered: according to it, participant $$$i$$$ earned exactly $$$b_i$$$ victories.
Miguel and the participants do not trust this table. If the program lost the games, who can guarantee that the totals were not corrupted too? Before announcing the winner, Miguel wants to know whether those numbers could describe a tournament like the one they organized.
Determine whether there is a set of game results consistent with the recovered totals. If there is, reconstruct one. You do not need to recover the original games: any reconstruction in which each participant $$$i$$$ won exactly $$$b_i$$$ times is acceptable.
The first line contains an integer $$$n$$$ ($$$1\le n\le2000$$$).
The second line contains $$$n$$$ integers $$$b_1,b_2,\ldots,b_n$$$ ($$$0\le b_i\le n-1$$$): the recorded number of victories for each participant.
If no valid reconstruction exists, print NO.
Otherwise, print YES, followed by $$$n$$$ lines, each containing a string of exactly $$$n$$$ characters, all either 0 or 1, without spaces. These strings form a matrix $$$A$$$, where $$$A_{i,j}=1$$$ means that participant $$$i$$$ defeated participant $$$j$$$.
The matrix must satisfy $$$A_{i,i}=0$$$, $$$A_{i,j}+A_{j,i}=1$$$ for all $$$i\ne j$$$, and $$$\sum_{j=1}^{n}A_{i,j}=b_i$$$ for every $$$i$$$. If several valid reconstructions exist, print any of them.
40 0 3 3
NO
10
YES 0
32 0 1
YES 011 000 010
| Название |
|---|


