#### Start

2020-07-23 03:00 AKDT

## IMBOREDD

#### End

2020-07-30 03:00 AKDT
The end is near!
Contest is over.
Not yet started.
Contest is starting in -67 days 12:52:16

168:00:00

0:00:00

# Problem CCapsules

At some point or another, most computer science students have written a standard Sudoku solving program. This is yet another “put numbers in a grid” puzzle.

Numbers are placed in the grid so that each outlined region contains the numbers $1$ to $n$, where $n$ is the number of squares in the region. The same number can never touch itself, not even diagonally. Incomplete Grid Solution Grid

For this problem, you will write a program that takes as input an incomplete puzzle grid and outputs the puzzle solution grid.

## Input

The input consists of a single data set. This data set starts with a line containing the number of rows in the input grid $R$, ($1 \le R \le 7$), and the number of columns in the input grid $C$, ($1 \le C \le 7$), separated by spaces. The next $R$ lines contain a representation of the incomplete input grid, one row per line. Each row has $C$ characters, representing the digits in each cell. The value in each cell is represented by either the digit already in that cell or a ‘-’ for an initially empty cell.

This grid is followed by a description of the separate regions in the grid. The first of these lines specifies the total number of regions. This is followed by one line for each region that specifies the cells contained in that region. Each region description consists of a decimal number $N$, specifying the number of cells in the region, followed by $N$ cell descriptions separated by spaces. Each cell description consists of a left parenthesis, followed the cell’s row index, followed by a comma, followed by the cell’s row number, followed by a right parenthesis. Regions do not overlap.

## Output

Output $R$ lines containing $C$ digits (separated by single spaces) showing the solution grid for the corresponding input data set. You are guaranteed that there is a unique solution.

Sample Input 1 Sample Output 1
3 5
- - - - -
- - - - -
4 - - - 1
5
1 (1,1)
2 (1,2) (1,3)
5 (2,1) (2,2) (3,1) (3,2) (3,3)
4 (2,3) (2,4) (1,4) (1,5)
3 (3,4) (3,5) (2,5)

1 2 1 2 1
3 5 3 4 3
4 2 1 2 1

Sample Input 2 Sample Output 2
7 7
- - - - - - -
4 - - - - 5 -
- - - - - - -
- - - 3 - - -
- - - - - - -
- - - - - - -
- - - - - - -
14
5 (1,1) (2,1) (3,1) (2,2) (2,3)
4 (2,4) (1,2) (1,3) (1,4)
2 (1,5) (1,6)
1 (1,7)
4 (4,1) (5,1) (6,1) (5,2)
1 (7,1)
4 (3,2) (4,2) (4,3) (5,3)
3 (7,3) (7,2) (6,2)
4 (6,3) (6,4) (7,4) (7,5)
6 (2,5) (3,5) (4,5) (3,6) (2,6) (2,7)
4 (3,7) (4,7) (4,6) (5,6)
1 (5,7)
5 (7,7) (7,6) (6,7) (6,6) (6,5)
5 (3,3) (3,4) (4,4) (5,4) (5,5)

3 1 4 2 1 2 1
4 2 5 3 6 5 4
1 3 1 4 2 3 1
2 4 2 3 1 4 2
1 3 1 5 2 3 1
4 2 4 3 4 5 2
1 3 1 2 1 3 1
{"ft_lang_label":"__label__en","ft_lang_prob":0.7661455,"math_prob":0.9964932,"size":2574,"snap":"2020-34-2020-40","text_gpt3_token_len":980,"char_repetition_ratio":0.15719844,"word_repetition_ratio":0.0952381,"special_character_ratio":0.43473193,"punctuation_ratio":0.15123457,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9791908,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-28T23:52:16Z\",\"WARC-Record-ID\":\"<urn:uuid:f40ebb34-d8a0-438d-82f2-c5909ea3c24b>\",\"Content-Length\":\"21624\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7331a75d-fbc1-4e2d-8c9b-cae1d8f37de8>\",\"WARC-Concurrent-To\":\"<urn:uuid:1e20387c-73fc-47d2-888b-4853f4563759>\",\"WARC-IP-Address\":\"104.26.12.234\",\"WARC-Target-URI\":\"https://open.kattis.com/contests/obkgit/problems/capsules\",\"WARC-Payload-Digest\":\"sha1:IRBVJDNTMH4SQYBDEQTOADWDZEO4NVLD\",\"WARC-Block-Digest\":\"sha1:WAFAZXUWHAIFP4VRAYAA7FSRQD54FAGK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600401617641.86_warc_CC-MAIN-20200928234043-20200929024043-00340.warc.gz\"}"}