Under construction

Still being built. Things may change

Gokigen Naname

Time limit1sMemory limit128 MB

Summary
Fill an n by n grid with one diagonal per cell so each numbered lattice point has exactly that many diagonal endpoints and no diagonal cycle forms.
Level

Medium7 of 10

Topics
Backtracking, DFS, Union-find, Implementation
Solved
No attempts yet

Problem

Gokigen Naname is a grid puzzle from Japan. The board is an n×nn \times n grid of square cells, and some of the (n+1)×(n+1)(n+1) \times (n+1) lattice points that form the cell corners carry a circled number.

Every cell must contain exactly one diagonal. A diagonal is either a \ joining the cell's top-left corner to its bottom-right corner, or a / joining its top-right corner to its bottom-left corner.

After all diagonals are drawn, for every circled number the count of diagonals whose endpoint lands on that lattice point must exactly equal the number inside the circle. In addition, the diagonals must never join up into a closed loop.

Given a puzzle, write a program that prints a placement satisfying all of these conditions. Only puzzles with a unique answer are given.

Input

The first line contains nn, the number of cells along one side of the grid (2≤n≤72 \le n \le 7).

The next n+1n+1 lines describe the lattice points from top to bottom, one row per line, each line containing exactly n+1n+1 characters. A digit gives the required number of diagonals meeting at that point, while . means the point has no number.

Output

Print the solved puzzle as nn lines. Line rr has nn characters, and its cc-th character is the / or \ diagonal drawn in the cell at row rr, column cc. The answer is always unique.

Examples3

  1. Example 1

    Input
    3
    1.1.
    ...0
    .3..
    ..2.
    
    Expected output
    \//
    \\\
    /\/
    
  2. Example 2

    Input
    5
    .21...
    ..33.0
    ......
    ..33..
    0..33.
    ....11
    
    Expected output
    /\\//
    //\\\
    \\\//
    \/\\/
    ///\\
    
  3. Example 3

    Input
    2
    101
    121
    020
    
    Expected output
    \/
    \/