Star Showdown

Given row and column game counts, build the 0/1 matrix with those degrees that is lexicographically smallest row by row, or print -1 if none exists.

Medium7GreedyGraphImplementationMathInterviewNo attempts yetTime limit2sMemory limit128 MB

Problem

The best StarCraft team on the west side of the city is Jimin's team, and the best on the east side is Hansu's team. The two teams decide to face off to settle who is the best in the city.

Jimin's team has NN players and Hansu's team has MM players. Each player has a fixed number of games they must play, and this number may differ from player to player.

The match table must satisfy all of the following rules.

  1. Every game is played between one player from Jimin's team and one player from Hansu's team.
  2. The same pairing may occur at most once.
  3. Every player must play exactly the number of games assigned to them.
  4. If several valid tables exist, choose the one that is smallest in lexicographic order.

The table is an N×MN \times M matrix. Rows correspond to Jimin's team and columns to Hansu's team. If cell (i,j)(i, j) is 11, then player ii of Jimin's team plays against player jj of Hansu's team; if it is 00, they do not play.

The lexicographic comparison of two tables is defined as follows. First find the first row ii in which the two matrices differ, then find the first column jj in that row where they differ. The table with 00 in cell (i,j)(i, j) comes first.

Given the number of games each player on each team must play, write a program that prints the lexicographically smallest table.

Input

The first line contains NN, the number of players on Jimin's team, and MM, the number of players on Hansu's team. The second line lists the number of games each player on Jimin's team must play, and the third line lists the number of games each player on Hansu's team must play. NN and MM are natural numbers at most 5050, and each game count is a natural number at most 5050 or 00.

Output

Print the table on NN lines. Each line is an MM-character string formed by concatenating that row's values with no separators. If no valid table exists, print 1-1.