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)

#[test]
fn check_solve() {
    println!("input:\n6\noutput:\n{}\n", solve("6\n"));
    println!("input:\n2\noutput:\n{}\n", solve("2\n"));
    println!("input:\n7\noutput:\n{}\n", solve("7\n"));
    println!("input:\n14\noutput:\n{}\n", solve("14\n"));
}

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let mut brd = vec![vec!['.'; n]; n];

    if n == 2 {
        return "-1\n".to_string();
    } else if n % 3 == 0 {
        for i in 0..n/3 {
            brd[3*i][3*i] = 'a';
            brd[3*i][3*i+1] = 'a';
            brd[3*i+1][3*i+2] = 'a';
            brd[3*i+2][3*i+2] = 'a';
        }
    } else if n == 7 {
        return "aabbcc.\ndde...f\ng.e...f\nghh...i\n...jj.i\n.....kl\n.....kl".to_string()
    } else if n == 11 {
        return "-1\n".to_string();
    } else {
        let mut i = 0;
        while (n-i) % 4 != 0 {
            brd[i][i] = 'a';
            brd[i][i+1] = 'a';
            brd[i][i+2] = 'b';
            brd[i][i+3] = 'b';
            brd[i][i+4] = 'a';
            brd[i+1][i+4] = 'a';
            brd[i+2][i+4] = 'b';
            brd[i+3][i+4] = 'b';
            brd[i+4][i+4] = 'a';
            brd[i+4][i+3] = 'a';
            brd[i+4][i+2] = 'b';
            brd[i+4][i+1] = 'b';
            brd[i+4][i] = 'a';
            brd[i+3][i] = 'a';
            brd[i+2][i] = 'b';
            brd[i+1][i] = 'b';
            brd[i+1][i+1] = 'c';
            brd[i+1][i+2] = 'c';
            brd[i+2][i+3] = 'c';
            brd[i+3][i+3] = 'c';
            i += 5;
        }
        while n > i {
            brd[i][i] = 'a';
            brd[i][i+1] = 'a';
            brd[i+1][i] = 'b';
            brd[i+1][i+1] = 'b';
            brd[i+2][i] = 'c';
            brd[i+3][i] = 'c';
            brd[i+2][i+1] = 'd';
            brd[i+3][i+1] = 'd';
            brd[i][i+2] = 'e';
            brd[i+1][i+2] = 'e';
            brd[i][i+3] = 'f';
            brd[i+1][i+3] = 'f';
            brd[i+2][i+2] = 'g';
            brd[i+2][i+3] = 'g';
            brd[i+3][i+2] = 'h';
            brd[i+3][i+3] = 'h';
            i += 4;
        }
    }


    let mut ret = String::new();
    use std::fmt::Write;
    
    for v in brd {
        writeln!(&mut ret, "{}", v.into_iter().collect::<String>()).unwrap();
    }
    
    ret
    //brd.iter().flat_map(|v| v.iter().chain(['\n'].iter()))collect()
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.get().chars().collect()
    }
}