Fake Scoreboard

Time limit2sMemory limit128 MB

Summary
Reconstruct a binary team-by-problem matrix matching given row and column sums, outputting the lexicographically smallest valid matrix or reporting impossibility (Gale-Ryser style bipartite degree sequence problem).
Level

Medium6 of 10

Topics
Greedy, Combinatorics, Matrix
Solved
No attempts yet

Problem

As you may know, after the award ceremony of SWERC it is customary to publish a complete scoreboard with detailed information on the submissions and the verdicts received. However, because of a buggy contest management system, most of the relevant data are not being recorded today. Such a state of affairs clearly fails to meet the high standards we are committed to, so the judges have resolved to make up the rest of the data from whatever shreds of information are left, hoping the contestants are unable to tell the difference. To make our lives even simpler, we kindly ask you to provide a solution for us; otherwise today's scoreboard will remain forever veiled in mystery (even the fake one).

By the end of the contest we will know the number TT of teams, the number PP of problems, and the number of accepted submissions by each team. From the number and colour of the balloons floating around the premises we will also be able to infer how many teams solved each problem. Your task is to figure out which teams solved which problems.

Our counting skills are not up to par, so your program must be able to detect when the collected data cannot correspond to any scoreboard at all (the first case of the sample input is such an instance). Otherwise you should output a possible solution, given as a sequence of TT strings of PP characters each. Teams and problems are assigned distinct integers, from 11 to TT and from 11 to PP respectively. For team number ii (1≤i≤T1 \le i \le T), write a string over the alphabet {N, Y} whose jj-th (1≤j≤P1 \le j \le P) character is Y if team ii got problem jj accepted, and N otherwise.

For example, the following three strings form a solution to the second case of the sample input, where the scores of three teams are 22, 11, 22 and the counts of accepted submissions for three problems are 11, 22, 22:

NYY
NNY
YYN

There is at least one other solution, namely

NYY
NYN
YNY

When several solutions are possible, output the one giving rise to the lexicographically smallest string when the TT rows are concatenated in order. In the example above we prefer the first solution, since NYYNNYYYN comes before NYYNYNYNY in lexicographical order. (A string SS comes before S′S' in lexicographical order if, at the first position where they differ, SS has N and S′S' has Y.)

Input

The input contains several test cases. Each test case consists of three lines:

  • The first line has two space-separated integers TT and PP (1≤T,P≤801 \le T, P \le 80), the number of teams and the number of problems.
  • The second line has TT space-separated integers, each between 00 and 9090 inclusive; the ii-th is the number of problems solved by team ii.
  • The third line has PP space-separated integers, each between 00 and 9090 inclusive; the jj-th is the number of teams that solved problem jj.

Consecutive test cases are separated by a blank line. The input ends with a line containing 0 0.

Output

For each test case, if the data admits a scoreboard, print TT lines of PP characters each: the lexicographically smallest valid scoreboard as described above. Otherwise print a single line containing Impossible. Print a blank line between the outputs of consecutive test cases.

Examples1

  1. Example 1

    Input
    2 2
    1 2
    1 1
    
    3 3
    2 1 2
    1 2 2
    
    3 5
    3 3 1
    3 1 1 0 2
    
    0 0
    
    Expected output
    Impossible
    
    NYY
    NNY
    YYN
    
    YNYNY
    YYNNY
    YNNNN