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)

N = int(input())

ans = [['.']*N for i in range(N)]
if N%3==0:
    for i in range(N//3):
        ans[i*3][i*3] = 'a'
        ans[i*3][i*3+1] = 'a'
        ans[i*3][i*3+2] = 'b'
        ans[i*3+1][i*3+2] = 'b'
        ans[i*3+2][i*3+2] = 'a'
        ans[i*3+2][i*3+1] = 'a'
        ans[i*3+2][i*3] = 'b'
        ans[i*3+1][i*3] = 'b'
    for row in ans:
        print(''.join(row))
    exit()

x = 0
while x <= N:
    y = N-x
    if y%2==0 and y != 2:
        if (y//2)%2:
            q = (y-2)//4*3
        else:
            q = y//4*3
        if x==0 or (q%2==0 and q <= x*2//3):
            break
    x += 3
else:
    print(-1)
    exit()

if (y//2)%2 == 0:
    for i in range(y//2):
        for j in range(y//2):
            if (i+j)%2==0:
                ans[i*2][j*2] = 'a'
                ans[i*2][j*2+1] = 'a'
                ans[i*2+1][j*2] = 'b'
                ans[i*2+1][j*2+1] = 'b'
            else:
                ans[i*2][j*2] = 'c'
                ans[i*2][j*2+1] = 'd'
                ans[i*2+1][j*2] = 'c'
                ans[i*2+1][j*2+1] = 'd'
else:
    for i in range(y//2):
        for j in range(y//2):
            if i==j: continue
            if i<j:
                if (i+j)%2==0:
                    ans[i*2][j*2] = 'a'
                    ans[i*2][j*2+1] = 'a'
                    ans[i*2+1][j*2] = 'b'
                    ans[i*2+1][j*2+1] = 'b'
                else:
                    ans[i*2][j*2] = 'c'
                    ans[i*2][j*2+1] = 'd'
                    ans[i*2+1][j*2] = 'c'
                    ans[i*2+1][j*2+1] = 'd'
            else:
                if (i+j)%2==0:
                    ans[i*2][j*2] = 'c'
                    ans[i*2][j*2+1] = 'd'
                    ans[i*2+1][j*2] = 'c'
                    ans[i*2+1][j*2+1] = 'd'
                else:
                    ans[i*2][j*2] = 'a'
                    ans[i*2][j*2+1] = 'a'
                    ans[i*2+1][j*2] = 'b'
                    ans[i*2+1][j*2+1] = 'b'
z = x//3
for i in range(z):
    for j in range(i, i+q//2):
        j %= z
        ans[y+i*3][y+j*3] = 'a'
        ans[y+i*3][y+j*3+1] = 'a'
        ans[y+i*3][y+j*3+2] = 'b'
        ans[y+i*3+1][y+j*3+2] = 'b'
        ans[y+i*3+2][y+j*3+2] = 'a'
        ans[y+i*3+2][y+j*3+1] = 'a'
        ans[y+i*3+2][y+j*3] = 'b'
        ans[y+i*3+1][y+j*3] = 'b'

for row in ans:
    print(''.join(row))