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: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;

using E = System.Linq.Enumerable;

internal partial class Solver {
    public void Run() {
        var n = ni();
        char[,] ans = Solve(n);
        if (ans == null) cout.WriteLine("-1");
        else
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    cout.Write(ans[i, j]);
                }
                cout.WriteLine();
            }
    }

    private char[,] Solve(int n) {
        if (n <= 2) return null;
        char[,] ans = new char[n, n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                ans[i, j] = '.';
            }
        }
        var p3 = new string[] {
            "aa.",
            "..b",
            "..b",
        };

        var p4 = new string[] {
            "aacd",
            "bbcd",
            "cdaa",
            "cdbb",
        };

        var p5 = new string[] {
            "aabbc",
            "ixx.c",
            "i..yd",
            "g..yd",
            "gffee",
        };

        var p6 = new string[] {
            "aa.ccd",
            "..bf.d",
            "..bfee",
            "ccdaa.",
            "f.d..b",
            "fee..b",
        };

        if (n % 3 == 0) {
            for (int i = 0; i < n; i += 3) {
                for (int j = 0; j < 3; j++) {
                    for (int k = 0; k < 3; k++) {
                        ans[i + j, i + k] = p3[j][k];
                    }
                }
            }
            return ans;
        } else {
            for (int n4 = 0; n4 * 4 <= n; n4++) {
                for (int n5 = 0; n4 * 4 + n5 * 5 <= n; n5++) {
                    var rem = n - (n4 * 4 + n5 * 5);
                    if (rem % 6 == 0) {
                        var n6 = rem / 6;
                        int current = 0;
                        while (n4 + n5 + n6 > 0) {
                            if (n4 > 0) {
                                for (int i = 0; i < p4.Length; i++) {
                                    for (int j = 0; j < p4.Length; j++) {
                                        ans[current + i, current + j] = p4[i][j];
                                    }
                                }
                                current += 4;
                                n4--;
                            } else if (n5 > 0) {
                                for (int i = 0; i < p5.Length; i++) {
                                    for (int j = 0; j < p5.Length; j++) {
                                        ans[current + i, current + j] = p5[i][j];
                                    }
                                }
                                current += 5;
                                n5--;
                            } else {
                                for (int i = 0; i < p6.Length; i++) {
                                    for (int j = 0; j < p6.Length; j++) {
                                        ans[current + i, current + j] = p6[i][j];
                                    }
                                }
                                current += 6;
                                n6--;
                            }
                        }


                        return ans;
                    }
                }
            }
        }

        return null;
    }
}

// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
    public static void Main(string[] args) {
#if LOCAL
        byte[] inputBuffer = new byte[1000000];
        var inputStream = Console.OpenStandardInput(inputBuffer.Length);
        using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) {
            Console.SetIn(reader);
            new Solver(Console.In, Console.Out).Run();
        }
#else
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver(Console.In, Console.Out).Run();
        Console.Out.Flush();
#endif
    }

#pragma warning disable IDE0052
    private readonly TextReader cin;
    private readonly TextWriter cout;
#pragma warning restore IDE0052

    public Solver(TextReader reader, TextWriter writer)
        : base(reader) {
        cin = reader;
        cout = writer;
    }
    public Solver(string input, TextWriter writer)
        : this(new StringReader(input), writer) {
    }

#pragma warning disable IDE1006
#pragma warning disable IDE0051
    private int ni() { return NextInt(); }
    private int[] ni(int n) { return NextIntArray(n); }
    private long nl() { return NextLong(); }
    private long[] nl(int n) { return NextLongArray(n); }
    private double nd() { return NextDouble(); }
    private double[] nd(int n) { return NextDoubleArray(n); }
    private string ns() { return Next(); }
    private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}

internal static class LinqPadExtension {
    public static T Dump<T>(this T obj) {
#if LOCAL
        return LINQPad.Extensions.Dump(obj);
#else
        return obj;
#endif
    }
}

public class Scanner {
    private readonly TextReader Reader;
    private readonly Queue<string> TokenQueue = new Queue<string>();
    private readonly CultureInfo ci = CultureInfo.InvariantCulture;

    public Scanner()
        : this(Console.In) {
    }

    public Scanner(TextReader reader) {
        Reader = reader;
    }

    public int NextInt() { return int.Parse(Next(), ci); }
    public long NextLong() { return long.Parse(Next(), ci); }
    public double NextDouble() { return double.Parse(Next(), ci); }
    public string[] NextArray(int size) {
        string[] array = new string[size];
        for (int i = 0; i < size; i++) {
            array[i] = Next();
        }

        return array;
    }
    public int[] NextIntArray(int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextInt();
        }

        return array;
    }

    public long[] NextLongArray(int size) {
        long[] array = new long[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextLong();
        }

        return array;
    }

    public double[] NextDoubleArray(int size) {
        double[] array = new double[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextDouble();
        }

        return array;
    }

    public string Next() {
        if (TokenQueue.Count == 0) {
            if (!StockTokens()) {
                throw new InvalidOperationException();
            }
        }
        return TokenQueue.Dequeue();
    }

    public bool HasNext() {
        if (TokenQueue.Count > 0) {
            return true;
        }

        return StockTokens();
    }

    private static readonly char[] _separator = new[] { ' ', '\t' };
    private bool StockTokens() {
        while (true) {
            string line = Reader.ReadLine();
            if (line == null) {
                return false;
            }

            string[] tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length == 0) {
                continue;
            }

            foreach (string token in tokens) {
                TokenQueue.Enqueue(token);
            }

            return true;
        }
    }
}