Language: C++

/*************************************
 * @contest:      AGC041.
 * @user_name:    hkxadpall.
 * @time:         2019-12-28.
 * @language:     C++.
 * @upload_place: AtCoder.
*************************************/ 

#include <bits/stdc++.h>
using namespace std;

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline Int read(char &c)       
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

int n;
char a[1007][1007];
// bool col[1007];
int now = 0;

void set3(int i, int j) // sum = 1
{
    a[i][j] = a[i][j + 1] = 'o';
    a[i + 1][j + 2] = a[i + 2][j + 2] = 'p';
}

void set9(int i, int j) // sum = 3
{
    set3(i + 0, j + 0); set3(i + 0, j + 3); set3(i + 0, j + 6); 
    set3(i + 3, j + 0); set3(i + 3, j + 3); set3(i + 3, j + 6); 
    set3(i + 6, j + 0); set3(i + 6, j + 3); set3(i + 6, j + 6); 
}

void set4(int i, int j) // sum = 3
{
    a[i + 0][j + 0] = 'a'; a[i + 0][j + 1] = 'a'; a[i + 0][j + 2] = 'c'; a[i + 0][j + 3] = 'd';
    a[i + 1][j + 0] = 'b'; a[i + 1][j + 1] = 'b'; a[i + 1][j + 2] = 'c'; a[i + 1][j + 3] = 'd';
    a[i + 2][j + 0] = 'e'; a[i + 2][j + 1] = 'f'; a[i + 2][j + 2] = 'g'; a[i + 2][j + 3] = 'g';
    a[i + 3][j + 0] = 'e'; a[i + 3][j + 1] = 'f'; a[i + 3][j + 2] = 'h'; a[i + 3][j + 3] = 'h';
}

void outputMat() 
{
    for (register int i = 0; i < n; i++) {
        for (register int j = 0; j < n; j++) {
            if (a[i][j]) putchar(a[i][j]);
            else putchar('.');
        }
        putchar('\n');
    }
}

int main()
{
    n = read<int>();
    if (n == 4) {
puts("-1);return 0;
        set4(0, 0);
        outputMat();
    } else if (n % 3 == 0) {
        for (register int i = 0; i < n; i += 3) set3(i, i);
        outputMat(); 
    } else if (n % 2 == 0 && n >= 4) {
        for (int i = 0; i < n; i ++) {
            a[i][i * 2 % n] = a[i][i * 2 % n + 1] = (now++) % 5 + 'a';
        }
        for (int i = 0, pos = n / 2 - 1; i < n / 4; i++) {
            a[i * 2][pos * 2] = a[i * 2 + 1][pos * 2] = (now++) % 5 + 'h';
            a[i * 2][pos * 2 + 1] = a[i * 2 + 1][pos * 2 + 1] = (now++) % 5 + 'h';
            pos = (pos - 2 + (n / 2)) % (n / 2);
        }
        for (int i = n / 2 - 1, pos = 0; i >= n / 4; i--) {
            a[i * 2][pos * 2] = a[i * 2 + 1][pos * 2] = (now++) % 5 + 'h';
            a[i * 2][pos * 2 + 1] = a[i * 2 + 1][pos * 2 + 1] = (now++) % 5 + 'h';
            pos = (pos - 2 + (n / 2)) % (n / 2);
        }
        outputMat(); 
    } else if (n % 4 == 1 && n >= 9) {
        for (int i = 0; i < n - 9; i += 4) set4(i, i);
        set9(n - 9, n - 9);
        outputMat(); 
    }  else if (n % 4 == 3 && n >= 27) {
        for (int i = 0; i < n - 27; i += 4) set4(i, i);
        set9(n - 27, n - 27);
        set9(n - 18, n - 18);
        set9(n - 9, n - 9);
        outputMat(); 
    } else puts("-1");
    return 0;
}

Compiler output:
a.cc:101:6: warning: missing terminating " character
  101 | puts("-1);return 0;
      |      ^
a.cc:101:6: error: missing terminating " character
  101 | puts("-1);return 0;
      |      ^~~~~~~~~~~~~~
a.cc: In function 'void outputMat()':
a.cc:88:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   88 |     for (register int i = 0; i < n; i++) {
      |                       ^
a.cc:89:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   89 |         for (register int j = 0; j < n; j++) {
      |                           ^
a.cc: In function 'int main()':
a.cc:102:19: error: expected ')' before ';' token
  102 |         set4(0, 0);
      |                   ^
      |                   )
a.cc:101:5: note: to match this '('
  101 | puts("-1);return 0;
      |     ^
a.cc:105:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  105 |         for (register int i = 0; i < n; i += 3) set3(i, i);
      |                           ^