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 Ruby (2.3.3) (judge verdict: Accepted)

N = gets.chomp.to_i
a = Array.new(N){Array.new(N,0)}
if N == 2
    puts -1
    exit
end
if N == 3
    puts "aa."
    puts "..a"
    puts "..a"
    exit
end

i = 0
if N%4 == 1
    a[0][0] = 1
    a[0][1] = 2
    a[0][2] = 2
    a[0][3] = 3
    a[0][4] = 3
    a[1][0] = 1
    a[1][1] = 0
    a[1][2] = 0
    a[1][3] = 2
    a[1][4] = 4
    a[2][0] = 2
    a[2][1] = 0
    a[2][2] = 0
    a[2][3] = 2
    a[2][4] = 4
    a[3][0] = 2
    a[3][1] = 5
    a[3][2] = 5
    a[3][3] = 0
    a[3][4] = 1
    a[4][0] = 3
    a[4][1] = 3
    a[4][2] = 4
    a[4][3] = 4
    a[4][4] = 1
    i = 5
elsif N%4 == 2
    a[0][0] = 1
    a[0][1] = 1
    a[0][2] = 2
    a[0][3] = 2
    a[0][4] = 3
    a[0][5] = 3
    a[1][0] = 2
    a[1][1] = 2
    a[1][2] = 3
    a[1][3] = 3
    a[1][4] = 1
    a[1][5] = 1
    a[2][0] = 4
    a[2][1] = 5
    a[2][2] = 6
    a[3][0] = 4
    a[3][1] = 5
    a[3][2] = 6
    a[4][3] = 4
    a[4][4] = 5
    a[4][5] = 6
    a[5][3] = 4
    a[5][4] = 5
    a[5][5] = 6
    i = 6
elsif N%4 == 3
    a[0][1] = 1
    a[0][2] = 1
    a[0][3] = 2
    a[0][4] = 2
    a[0][5] = 3
    a[0][6] = 3
    a[1][0] = 1
    a[1][1] = 4
    a[1][2] = 4
    a[1][3] = 5
    a[2][0] = 1
    a[2][1] = 5
    a[2][2] = 0
    a[2][3] = 5
    a[3][0] = 2
    a[3][1] = 5
    a[3][2] = 4
    a[3][3] = 4
    a[4][0] = 2
    a[4][4] = 4
    a[4][5] = 4
    a[4][6] = 5
    a[5][0] = 3
    a[5][4] = 5
    a[5][5] = 0
    a[5][6] = 5
    a[6][0] = 3
    a[6][4] = 5
    a[6][5] = 4
    a[6][6] = 4
    i = 7
end
while i < N
    a[i][i] = 1
    a[i][i+1] = 1
    a[i][i+2] = 3
    a[i][i+3] = 4
    a[i+1][i] = 2
    a[i+1][i+1] = 2
    a[i+1][i+2] = 3
    a[i+1][i+3] = 4
    a[i+2][i] = 3
    a[i+2][i+1] = 4
    a[i+2][i+2] = 1
    a[i+2][i+3] = 1
    a[i+3][i] = 3
    a[i+3][i+1] = 4
    a[i+3][i+2] = 2
    a[i+3][i+3] = 2
    i += 4
end
for x in 0...N do
    for y in 0...N do
        b = a[x][y]
        if b == 0
            print "."
        elsif b == 1
            print "a"
        elsif b == 2
            print "b"
        elsif b == 3
            print "c"
        elsif b == 4
            print "d"
        elsif b == 5
            print "e"
        elsif b == 6
            print "f"
        end
    end
    puts
end