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>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
vector<string> ans;
string a3[3] = {
	"aa.",
	"..a",
	"..a"
};
string a4[4] = {
	"aacd",
	"bbcd",
	"cdaa",
	"cdbb"
};
string a5[5] = {
	"aacca",
	"bbd.a",
	"c.dcc",
	"c..bd",
	".aabd"
};
string a6[6] = {
	"abcc..",
	"abdd..",
	"..abcc",
	"..abdd",
	"cc..ab",
	"dd..ab"
};
string a7[7] = {
	"aa.cd..",
	"bb.cd..",
	"c....cd",
	"c....cd",
	"..aacaa",
	"..bbc.b",
	".cc.ddb"
};
void solve(int n){
	if(n >= 8){
		n -= 4;
		for(int i=0;i<4;i++) for(int j=0;j<4;j++) ans[n+i][n+j] = a4[i][j];
		solve(n);
	}
	else{
		if(n == 4) for(int i=0;i<4;i++) for(int j=0;j<4;j++) ans[i][j] = a4[i][j];
		else if(n == 5) for(int i=0;i<5;i++) for(int j=0;j<5;j++) ans[i][j] = a5[i][j];
		else if(n == 6) for(int i=0;i<6;i++) for(int j=0;j<6;j++) ans[i][j] = a6[i][j];
		else for(int i=0;i<7;i++) for(int j=0;j<7;j++) ans[i][j] = a7[i][j];
	}
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ans.resize(n, "");
    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		ans[i] += ".";
    	}
    }
    if(n == 2){
    	cout << -1 << endl;
    	return 0;
    }
    if(n == 3){
    	for(int i=0;i<3;i++) cout << a3[i] << endl;
    	return 0;
    }
    solve(n);
    for(int i=0;i<n;i++){
    	cout << ans[i] << endl;
    }
    return 0;
}