Problem:
Score : 900 points

Problem Statement

Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid.
Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.

For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row.
We define the quality of each column similarly.

Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column,
or determine that such a placement doesn't exist.

Constraints

2 \le N \le 1000

Input

Input is given from Standard Input in the following format:

N

Output

If the required domino placement doesn't exist, print a single integer -1.

Otherwise, output your placement as N strings of N characters each.
If a square is not covered, the corresponding character must be . (a dot).
Otherwise, it must contain a lowercase English letter.
Squares covered by the same domino piece must contain the same letter.
If two squares have a common side but belong to different pieces, they must contain different letters.

Sample Input 1

6

Sample Output 1

aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b

The quality of every row and every column is 2.

Sample Input 2

2

Sample Output 2

-1

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    if n == 2 {
        println!("-1");
        return;
    }
    let mut grid = vec![vec!['.'; n]; n];
    if n % 2 == 0 {
        for y in 0..n / 2 {
            for x in 0..n / 2 {
                let x0 = 2 * x;
                let y0 = 2 * y;
                if x0 % 4 == y0 % 4 {
                    grid[y0][x0] = 'a';
                    grid[y0 + 1][x0] = 'a';
                    grid[y0][x0 + 1] = 'b';
                    grid[y0 + 1][x0 + 1] = 'b';
                } else {
                    grid[y0][x0] = 'c';
                    grid[y0][x0 + 1] = 'c';
                    grid[y0 + 1][x0] = 'd';
                    grid[y0 + 1][x0 + 1] = 'd';
                }
            }
        }
    } else if n == 3 {
        grid[0] = vec!['.', '.', 'a'];
        grid[1] = vec!['.', '.', 'a'];
        grid[2] = vec!['a', 'a', '.'];
    } else if n % 4 == 1 {
        grid[0][0] = 'a';
        grid[0][1] = 'a';
        grid[0][2] = 'b';
        grid[0][3] = 'b';
        grid[0][4] = 'c';
        grid[1][4] = 'c';
        grid[2][4] = 'd';
        grid[3][4] = 'd';
        grid[4][4] = 'e';
        grid[4][3] = 'e';
        grid[4][2] = 'f';
        grid[4][1] = 'f';
        grid[4][1] = 'f';
        grid[4][0] = 'g';
        grid[3][0] = 'g';
        grid[2][0] = 'h';
        grid[1][0] = 'h';
        grid[3][1] = 'i';
        grid[3][2] = 'i';
        grid[1][3] = 'j';
        grid[2][3] = 'j';
        for xx in 0..(n - 5) / 4 {
            for yy in 0..(n - 5) / 4 {
                if xx % 2 != yy % 2 {
                    continue;
                }
                for y in 0..2 {
                    for x in 0..2 {
                        let x0 = 4 * xx + x * 2 + 5;
                        let y0 = 4 * yy + y * 2 + 5;
                        if x % 2 == y % 2 {
                            grid[y0][x0] = 'a';
                            grid[y0 + 1][x0] = 'a';
                            grid[y0][x0 + 1] = 'b';
                            grid[y0 + 1][x0 + 1] = 'b';
                        } else {
                            grid[y0][x0] = 'c';
                            grid[y0][x0 + 1] = 'c';
                            grid[y0 + 1][x0] = 'd';
                            grid[y0 + 1][x0 + 1] = 'd';
                        }
                    }
                }
            }
        }
    } else {
        let mut rows = vec![];
        rows.push("ee..ggh");
        rows.push("p.ff..h");
        rows.push("p...bl.");
        rows.push(".o..bl.");
        rows.push(".oaa..j");
        rows.push("n..ll.j");
        rows.push("nmm..kk");
        for (y, ref row) in rows.into_iter().enumerate() {
            for (x, ch) in row.chars().enumerate() {
                grid[y][x] = ch;
            }
        }

        for xx in 0..(n - 7) / 4 {
            for yy in 0..(n - 7) / 4 {
                if xx % 2 != yy % 2 {
                    continue;
                }
                for y in 0..2 {
                    for x in 0..2 {
                        let x0 = 4 * xx + x * 2 + 7;
                        let y0 = 4 * yy + y * 2 + 7;
                        if x % 2 == y % 2 {
                            grid[y0][x0] = 'a';
                            grid[y0 + 1][x0] = 'a';
                            grid[y0][x0 + 1] = 'b';
                            grid[y0 + 1][x0 + 1] = 'b';
                        } else {
                            grid[y0][x0] = 'c';
                            grid[y0][x0 + 1] = 'c';
                            grid[y0 + 1][x0] = 'd';
                            grid[y0 + 1][x0 + 1] = 'd';
                        }
                    }
                }
            }
        }
    }

    for row in grid {
        for mass in row {
            print!("{}", mass);
        }
        println!("");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}