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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Linq;

public class Program
{
    private int N;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
/*
 * 3*3
 * aab
 * c.b
 * cdd
 *
 * 4*4 3
 * abcc 
 * abdd
 * eegh
 * ffgh 
 *
 * 5*5 3
 * aabbc
 * de..c
 * de..f
 * g.hhf
 * giijj
 *
 * 6*6 3
 * aabbcc
 * d.e.f.
 * d.e.f.
 * .g.h.i
 * .g.h.i
 * jjkkll
 *
 * 7*7 3
 * aabbcc.
 * de....f
 * de....f
 * gh....i
 * gh....i
 * ..jjkkl
 * ..mmnnl
 */

        string[] four = new string[4]
        {
            "abcc",
            "abdd",
            "eegh",
            "ffgh"
        };

        string[] five = new string[5]
        {
            "aabbc",
            "de..c",
            "de..f",
            "g.hhf",
            "giijj"
        };

        string[] six = new string[6]
        {
            "aabbcc",
            "d.e.f.",
            "d.e.f.",
            ".g.h.i",
            ".g.h.i",
            "jjkkll"
        };

        string[] seven = new string[7]
        {
            "aabbcc.",
            "de....f",
            "de....f",
            "gh....i",
            "gh....i",
            "..jjkkl",
            "..mmnnl"
        };

        if (N == 2)
        {
            Console.WriteLine(-1);
            return;
        }

        if (N == 3)
        {
            Console.WriteLine("aab");
            Console.WriteLine("c.b");
            Console.WriteLine("cdd");
            return;
        }

        int d = N / 4;
        int m = N % 4;

        char[][] ans = new char[N][];
        for (int i = 0; i < N; i++)
        {
            ans[i] = new char[N];
            for (int j = 0; j < N; j++)
            {
                ans[i][j] = '.';
            }
        }

        // d-1個 4*4
        // 最後 4+mのやつ

        for (int i = 0; i < d - 1; i++)
        {
            int ii = i * 4;
            for (int j = 0; j < 4; j++)
            {
                for (int k = 0; k < 4; k++)
                {
                    ans[ii + j][ii + k] = four[j][k];
                }
            }
        }

        int iii = 4 * (d - 1);
        int type = 4 + m;
        if (type == 4)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    ans[iii + i][iii + j] = four[i][j];
                }
            }
        }
        else if (type == 5)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    ans[iii + i][iii + j] = five[i][j];
                }
            }
        }
        else if (type == 6)
        {
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    ans[iii + i][iii + j] = six[i][j];
                }
            }
        }
        else if (type == 7)
        {
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    ans[iii + i][iii + j] = seven[i][j];
                }
            }
        }

        Console.WriteLine(string.Join("\n", ans.Select(c => new string(c))));
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}