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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 1e3 + 5;

char g[MAXN][MAXN];

string s4[4] = {
	"aabc",
	"ddbc",
	"bcaa",
	"bcdd"
};

string s5[5] = {
	"abbcc",
	"a..de",
	"b..de",
	"bff.g",
	"hhiig"
};

string s6[6] = {
	"aa.aab",
	"..bc.b",
	"..bcdd",
	"eefee.",
	"g.f..f",
	"ghh..f"
};

string s7[7] = {
	"a...hff",
	"a...h.e",
	"b...dde",
	"bhff...",
	"ch.e...",
	"cdde...",
	".ccbbaa",
};

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		REP(j, 0, n) {
			g[i][j] = '.';
		}
	}
	if (n == 2) {
		printf("-1\n");
		return;
	}
	if (n == 3) {
		g[0][1] = g[0][2] = 'a';
		g[1][0] = g[2][0] = 'b';
	} else {
		int r = 4 + n % 4;
		if (r == 4) {
			REP(i, 0, 4) {
				REP(j, 0, 4) {
					g[i][j] = s4[i][j];
				}
			}
		} else if (r == 5) {
			REP(i, 0, 5) {
				REP(j, 0, 5) {
					g[i][j] = s5[i][j];
				}
			}
		} else if (r == 6) {
			REP(i, 0, 6) {
				REP(j, 0, 6) {
					g[i][j] = s6[i][j];
				}
			}
		} else if (r == 7) {
			REP(i, 0, 7) {
				REP(j, 0, 7) {
					g[i][j] = s7[i][j];
				}
			}
		}
		for(int k = r; k < n; k += 4) {
			REP(i, 0, 4) {
				REP(j, 0, 4) {
					g[k + i][k + j] = s4[i][j];
				}
			}
		}
	}
	REP(i, 0, n) {
		printf("%s\n", g[i]);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}