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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        LightWriter out = new LightWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        private static final char[][] TABLE_X = {
                {'a', 'a'},
                {'b', 'b'},
        };
        private static final char[][] TABLE_Y = {
                {'c', 'd'},
                {'c', 'd'},
        };
        private static final char[][] TABLE_3 = {
                {'a', 'd', 'd',},
                {'a', '.', 'c',},
                {'b', 'b', 'c',},
        };
        private static final char[][] TABLE_5 = {
                {'a', '.', 'b', 'c', 'c'},
                {'a', '.', 'b', 'd', '.'},
                {'.', 'g', 'g', 'd', 'e'},
                {'h', 'h', 'j', '.', 'e'},
                {'i', 'i', 'j', 'f', 'f'},
        };
        private static final char[][] TABLE_7 = {
                {'a', 'a', 'b', 'b', 'c', 'c', '.'},
                {'x', 'x', 'y', '.', '.', '.', 'a'},
                {'w', '.', 'y', '.', '.', '.', 'a'},
                {'w', 'z', 'z', '.', '.', '.', 'b'},
                {'.', '.', '.', 'x', 'x', 'y', 'b'},
                {'.', '.', '.', 'w', '.', 'y', 'c'},
                {'.', '.', '.', 'w', 'z', 'z', 'c'},
        };

        public void solve(int testNumber, LightScanner in, LightWriter out) {
            int n = in.ints();
            if (n == 2) {
                out.ans(-1).ln();
            } else if (n % 3 == 0) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        out.print(TABLE_3[i % 3][j % 3]);
                    }
                    out.ln();
                }
            } else if (n % 5 == 0) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        out.print(TABLE_5[i % 5][j % 5]);
                    }
                    out.ln();
                }
            } else if (n % 7 == 0) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        out.print(TABLE_7[i % 7][j % 7]);
                    }
                    out.ln();
                }
            } else {
                int t = n, c = 0;
                while (t % 2 != 0) {
                    t -= 5;
                    c++;
                }
                if (t < 4) {
                    out.ans(-1).ln();
                    return;
                }
                char[][] ans = new char[n][n];
                ArrayUtil.fill(ans, '.');
                for (int i = 0; i < t - 2; i += 2) {
                    for (int j = 0; j < 2; j++) {
                        for (int k = 0; k < 2; k++) {
                            ans[i + j][i + k] = TABLE_X[j][k];
                            ans[i + j][i + k + 2] = TABLE_Y[j][k];
                        }
                    }
                }
                for (int j = 0; j < 2; j++) {
                    for (int k = 0; k < 2; k++) {
                        ans[t - 2 + j][t - 2 + k] = TABLE_X[j][k];
                        ans[t - 2 + j][k] = TABLE_Y[j][k];
                    }
                }
                for (int i = 0; i < c; i++) {
                    for (int j = 0; j < 5; j++) {
                        for (int k = 0; k < 5; k++) {
                            ans[t + i * 5 + j][t + i * 5 + k] = TABLE_5[j][k];
                        }
                    }
                }
                for (int i = 0; i < n; i++) {
                    out.ans(String.valueOf(ans[i])).ln();
                }
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }

    static class LightWriter implements AutoCloseable {
        private final Writer out;
        private boolean autoflush = false;
        private boolean breaked = true;

        public LightWriter(Writer out) {
            this.out = out;
        }

        public LightWriter(OutputStream out) {
            this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));
        }

        public LightWriter print(char c) {
            try {
                out.write(c);
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter print(String s) {
            try {
                out.write(s, 0, s.length());
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter ans(String s) {
            if (!breaked) {
                print(' ');
            }
            return print(s);
        }

        public LightWriter ans(int i) {
            return ans(Integer.toString(i));
        }

        public LightWriter ln() {
            print(System.lineSeparator());
            breaked = true;
            if (autoflush) {
                try {
                    out.flush();
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }
            return this;
        }

        public void close() {
            try {
                out.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

    }

    static final class ArrayUtil {
        private ArrayUtil() {
        }

        public static void fill(char[] a, char v) {
            Arrays.fill(a, v);
        }

        public static void fill(char[][] a, char v) {
            for (int i = 0; i < a.length; i++) {
                fill(a[i], v);
            }
        }

    }
}