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 Python (3.4.3) (judge verdict: Wrong Answer)

import numpy as np
import random


def isValid(N, grids):
    q0 = cntQuality(N, grids, 0, 0)

    for i in range(N):
        q = cntQuality(N, grids, i, 0)
        if q0 != q:
            return False

    for i in range(N):
        q = cntQuality(N, grids, i, 1)
        if q0 != q:
            return False
    return True


def cntQuality(N, grids, num, axis):
    q = 0

    if axis == 0:
        g = grids[num, :]
    else:
        g = grids[:, num]

    last = -1

    for i in range(N):
        d = g[i]
        if last != d and d != 0:
            q += 1
            last = d

    return q


def tryDomino(N, iter):
    max_num = (N*N) // 2

    for _ in range(iter):
        grids = np.zeros((N, N))
        num = random.randrange(1, max_num+1, 1)

        cnt = 1000
        while(num > 0 and cnt > 0):
            position_x = random.randrange(N)
            position_y = random.randrange(N)
            direct = random.randrange(4)

            # 0 +1
            # 1 -1
            # 2    +1
            # 3    -1
            if direct == 0:
                position_x_2 = position_x + 1
                position_y_2 = position_y
            elif direct == 1:
                position_x_2 = position_x - 1
                position_y_2 = position_y
            elif direct == 2:
                position_x_2 = position_x
                position_y_2 = position_y + 1
            elif direct == 3:
                position_x_2 = position_x
                position_y_2 = position_y - 1

            if not(0 <= position_x <= N-1 and 0 <= position_x_2 <= N-1
                   and 0 <= position_y <= N-1 and 0 <= position_y_2 <= N-1):
                cnt -= 1
                continue

            p1 = grids[position_x][position_y]
            p2 = grids[position_x_2][position_y_2]

            if(p1 == 0 and p2 == 0):
                grids[position_x][position_y] = num
                grids[position_x_2][position_y_2] = num
                num -= 1
                cnt = 1000
            else:
                cnt -= 1
                continue

        if isValid(N, grids):
            return grids

    return False


grids = tryDomino(4, 10000)
print(grids)