Problem:
Score : 700 points

Problem Statement

We have a grid with H rows and W columns of squares.
We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j).
Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|.

Snuke is painting each square in red, yellow, green or blue.
Here, for a given positive integer d, he wants to satisfy the following condition:

No two squares with distance exactly d have the same color.

Find a way to paint the squares satisfying the condition.
It can be shown that a solution always exists.

Constraints

2 ≤ H, W ≤ 500

1 ≤ d ≤ H + W - 2

Input

Input is given from Standard Input in the following format:

H W d

Output

Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be R, Y, G or B, respectively.

c_{11}c_{12}...c_{1W}
:
c_{H1}c_{H2}...c_{HW}

Sample Input 1

2 2 1

Sample Output 1

RY
GR

There are four pairs of squares with distance exactly 1.
As shown below, no two such squares have the same color.

(1,\ 1), (1,\ 2) : R, Y

(1,\ 2), (2,\ 2) : Y, R

(2,\ 2), (2,\ 1) : R, G

(2,\ 1), (1,\ 1) : G, R

Sample Input 2

2 3 2

Sample Output 2

RYB
RGB

There are six pairs of squares with distance exactly 2.
As shown below, no two such squares have the same color.

(1,\ 1) , (1,\ 3) : R , B

(1,\ 3) , (2,\ 2) : B , G

(2,\ 2) , (1,\ 1) : G , R

(2,\ 1) , (2,\ 3) : R , B

(2,\ 3) , (1,\ 2) : B , Y

(1,\ 2) , (2,\ 1) : Y , R

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <bits/stdc++.h>

using namespace std;

int n, m, d;

///R Y G B

char v[] = {0, 'R', 'Y', 'G', 'B'};

int pos[501][501][5];

int a[501][501];

int sign[] = {0, 1, 1, -1, -1};
int signC[] = {0, -1, 1, -1, 1};

int wasted;

void pune(int i, int j, int x)
{
    int addL, nl, nc;
    for(addL = 0; addL <= d; addL ++)
    {
        int l = addL;
        int c = d - addL;

        for(int h = 1; h <= 4; h ++)
        {
            nl = i + l * sign[h];
            nc = j + c * signC[h];

            if(nl >= 1 && nl <= n && nc >= 1 && nc <= m)
                pos[nl][nc][x] = 1;

           // else
            //    wasted ++;
        }
    }

}

char charul(int nr)
{
    return v[nr];
}

int cul[5];

void mix()
{
    int i;
    for(i = 1; i <= 4; i ++)
    {
        int poz = rand() % 4 + 1;

        int aux = cul[poz];
        cul[poz] = cul[i];
        cul[i] = aux;
    }
}

void doClear()
{
    int i, j, h;
    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= m; j ++)
        {
            for(h = 1; h <= 4; h ++)
            {
                pos[i][j][h] = 0;
                a[i][j] = 0;
            }
        }
    }
}

int doA(int startL, int startC)
{
    int i, j, h, c, l;
    int k = 0;
    int al, ac, nl, nc;
    for(k = 0; k <= n + m; k ++)
    {
        ///i + j = k;
        for(l = 0; l <= k; l ++)
        {
            al = l;
            ac = k - l;

            int h1;
            for(h1 = 1; h1 <= 4; h1 ++)
            {
                nl = startL + al * sign[h1];
                nc = startC + ac * signC[h1];

                if(nl >= 1 && nl <= n && nc >= 1 && nc <= m)
                {
                    i = nl;
                    j = nc;

                    for(c = 1; c <= 4; c ++)
                    {
                        h = cul[c];
                        if(pos[i][j][h] == 0)
                        {
                            pune(i, j, h);

                            a[i][j] = h;

                            break;
                        }
                    }

                    if(c == 5)
                    {
                        doClear();

                        return 0;
                    }
                }
            }
        }
    }

    return 1;
}

struct pozi
{
    int l, c;
};

pozi pozit[999];

int main()
{
    srand(time(0));

    scanf("%d%d%d", &n, &m, &d);
    //n = 500;
    //m = 500;
   // d = 998;

   cul[1] = 1;
   cul[2] = 2;
   cul[3] = 3;
   cul[4] = 4;

   int l2 = n / 4;
   int c2 = m / 4;
   int cr = 1;
   const int DEF = 10;
   pozit[1] = {(n + 1) / 2, (m + 1) / 2};
   pozit[2] = {1, 1};
   pozit[3] = {l2, c2};
   pozit[4] = {l2 + l2, c2};
   pozit[5] = {l2, c2 + c2};
   pozit[6] = {l2 + l2, c2 + c2};
   pozit[7] = {(n + 1) / 2, c2 + c2};
   pozit[8] = {(n + 1) / 2, c2};
   pozit[9] = {l2, (m + 1) / 2};
   pozit[10] = {l2 + l2, (m + 1) / 2};

   for(int i = 1; i <= DEF; i ++)
   {
       if(pozit[i].l == 0)
            pozit[i].l = 1;

       if(pozit[i].c == 0)
            pozit[i].c = 1;
   }

   while(doA(pozit[cr].l, pozit[cr].c) == 0)
   {
       cr ++;

       if(cr > DEF)
       {
           pozit[cr].l = rand() % n + 1;
           pozit[cr].c = rand() % m + 1;
       }
   }

   int i, j;
    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= m; j ++)
        {
            printf("%c", charul(a[i][j]));
        }

        printf("\n");
    }

    return 0;
}