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 JavaScript (node.js v5.12) (judge verdict: Runtime Error)

"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

var ans;
console.log(main());
function main(){
  var n = o.a();
  if(n === 2)return -1;
  ans = Array(n).fill().map(a=>Array(n).fill("."));
  if(n % 3 === 0)solve3(0,n,0,n);
  else if(n % 4 === 0)solve4(0,n,0,n);
  else if(n % 6 === 1)solve7(n);
  else if(n % 6 === 5)solve5(n);
  else solve10(n);
  return ans.map(a=>a.join("")).join("\n");
}

function solve3(yi,yn,xi,xn){
  for(var y = yi; y < yn; y+=3)for(var x = xi; x < xn; x+= 3){
    ans[y][x] = ans[y][x+1] = "a";
    ans[y+1][x+2] = ans[y+2][x+2] = "b";
  }
}
function solve4(yi,yn,xi,xn){
  for(var y = yi; y < yn; y+=2)for(var x = xi; x < xn; x+= 2){
    if((x+y)/2%2 === 0){
      ans[y][x] = ans[y][x+1] = "a";
      ans[y+1][x] = ans[y+1][x+1] = "b";
    }else{
      ans[y][x] = ans[y+1][x] = "c";
      ans[y][x+1] = ans[y+1][x+1] = "d";
    }
  }
}
function solve5(n){
  for(var x = 0; x < n-5;x += 6){
    ans[0][x] = ans[0][x+1] = "c";
    ans[0][x+2] = ans[0][x+3] = "d";
    ans[0][x+4] = ans[0][x+5] = "e";
    ans[n-1][n-x-1] = ans[n-1][n-x-2] = "c";
    ans[n-1][n-x-3] = ans[n-1][n-x-4] = "d";
    ans[n-1][n-x-5] = ans[n-1][n-x-6] = "e";
  }
  ans[0][n-5] = ans[0][n-4] = "c";
  ans[0][n-3] = ans[0][n-2] = "d";
  ans[n-1][4] = ans[n-1][3] = "c";
  ans[n-1][2] = ans[n-1][1] = "d";
  for(var x = 0; x < n-5;x += 6){
    ans[x+1][0] = ans[x+2][0] = "f";
    ans[x+3][0] = ans[x+4][0] = "g";
    ans[x+5][0] = ans[x+6][0] = "h";
    ans[n-x-2][n-1] = ans[n-x-3][n-1] = "f";
    ans[n-x-4][n-1] = ans[n-x-5][n-1] = "g";
    ans[n-x-6][n-1] = ans[n-x-7][n-1] = "h";
  }
  ans[n-4][0] = ans[n-3][0] = "f";
  ans[n-2][0] = ans[n-1][0] = "g";
  ans[3][n-1] = ans[2][n-1] = "f";
  ans[0][n-1] = ans[1][n-1] = "g";
  solve3(1,n-1,1,n-1);
}
function solve7(n){
  for(var x = 0; x < n-1;x += 6){
    ans[0][x] = ans[0][x+1] = "c";
    ans[0][x+2] = ans[0][x+3] = "d";
    ans[0][x+4] = ans[0][x+5] = "e";
    ans[1+x][n-1] = ans[2+x][n-1] = "c";
    ans[3+x][n-1] = ans[4+x][n-1] = "d";
    ans[5+x][n-1] = ans[6+x][n-1] = "e";
  }
  solve3(1,n,0,n-1);
}
function solve10(n){
  solve4(0,4,0,4);
  solve3(4,n,4,n);
  for(var x = 4; x < n;x += 3){
    ans[x][x] = ans[x][x+1] = "w";
    ans[x][x+2] = ans[x+1][x+2] = "x";
    ans[x+2][x+2] = ans[x+2][x+1] = "y";
    ans[x+2][x] = ans[x+1][x] = "z";
  }
}