This page is still under construction.

Parts of this page are still being built. What you see may change.

Watering the fields

Time limit1sMemory limit128 MB

Summary
Cover every non-scarecrow cell with trominoes of three cells while letting at most R times C trominoes cross field borders.
Level

Hard8 of 10

Topics
Implementation, Backtracking, Combinatorics
Solved
No attempts yet

Problem

Sara farms a large rectangle of land. The land is a grid of 5R5R rows and 5C5C columns of cells. A horizontal fence runs across the land after every fifth row, and a vertical fence runs after every fifth column. The fences split the land into R×CR \times C plots of size 5×55 \times 5, called fields.

Some fields have a scarecrow to keep birds off the crops. A scarecrow occupies one cell, and each 5×55 \times 5 field has at most one scarecrow.

In a drought Sara waters the crops with sprinklers. Each sprinkler has one main nozzle and two side nozzles. It occupies exactly three cells and waters all three. Each side nozzle sits on a cell that shares an edge with the main nozzle (up, down, left, or right). So every sprinkler has one of these six shapes:

  • three cells in a vertical line
  • three cells in a horizontal line
  • an L made of a 2×22 \times 2 square minus one cell (four orientations)

Every cell that is not a scarecrow must contain exactly one sprinkler nozzle. A scarecrow cell must not contain a nozzle. Nozzles must not sit outside the land.

The three cells of one sprinkler need not lie in the same 5×55 \times 5 field. They may straddle neighboring fields. In that case Sara drills a hole in the fence between the two cells that the same sprinkler waters. Drilling is hard, so the number of holes must be at most R×CR \times C.

A valid placement always exists. Output a valid placement with at most R×CR \times C holes.

Input

The first line contains two integers RR and CC (1≤R,C≤1001 \le R, C \le 100).

Then 6R−16R-1 lines follow, each with 6C−16C-1 characters. They show the fields and the fences between them. The fence is infinitely thin in the land, but the input still draws it with characters.

. is an empty cell, # (ASCII 35) is a scarecrow, | (ASCII 124) is a vertical fence, - is a horizontal fence, and + is a fence crossing.

Output

Print a grid of the same size with a valid sprinkler placement. Mark each hole with _. Replace every . from the input with a lowercase letter a to z so that:

  1. The three cells of one sprinkler share the same letter, even when they are not all in the same 5×55 \times 5 field.
  2. If two adjacent cells in the same field belong to different sprinklers, they must have different letters.
  3. If two adjacent cells in different fields belong to different sprinklers and there is a hole in the fence between them, they must have different letters.
  4. Adjacent cells in different fields may share a letter as long as the rules above hold.

The number of holes must be at most R×CR \times C.

Examples1

  1. Example 1

    Input
    2 2
    .....|.....
    .....|.....
    ...#.|.....
    .....|.....
    .....|.....
    -----+-----
    .....|.....
    .....|.....
    .....|.....
    .....|.....
    .....|.....
    
    Expected output
    aaacc|dxxxa
    bbbce|dyyya
    ddd#e|dzzza
    ccbae|fccbb
    cbbaa|ffcdb
    -----+---_-
    ssrrr|tttdd
    saaax_xxeee
    yxbbb|zdaaa
    yxccc|zdbbb
    yxddd|zdccc