Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
int h, w;
int H, W;
const int maxN = 505;
int cnt[maxN];
int clr[maxN][maxN];
int val[maxN];
int main() {
   // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> H >> W >> h >> w;
    if (H % h == 0 && W % w == 0) {
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    int P = -1;
    if (H % h != 0) {
        P = h;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                clr[i][j] = i % P;
                cnt[clr[i][j]]++;
            }
        }
    }
    else {
        P = w;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                clr[i][j] = j % P;
                cnt[clr[i][j]]++;
            }
        }
    }
    int mn = 1e8;
    for (int i = 0; i < P; i++) {
        mn = min(mn, cnt[i]);
    }
    bool f1 = false;
    bool f2 = false;
    const int PP = (int)1e9 - 15;
    for (int i = 0; i < P; i++) {
        if (cnt[i] == mn) {
            if (!f1) {
                val[i] = ~PP;
                f1 = true;
            }
        }
        else {
            if (!f2) {
                val[i] = PP;
                f2 = true;
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << val[clr[i][j]] << " ";
        }
        cout << '\n';
    }
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
int h, w;
int H, W;
const int maxN = 505;
int cnt[maxN];
int clr[maxN][maxN];
int val[maxN];
int main() {
   // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> H >> W >> h >> w;
    if (H % h == 0 && W % w == 0) {
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    int P = -1;
    if (H % h != 0) {
        P = h;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                clr[i][j] = i % P;
                cnt[clr[i][j]]++;
            }
        }
    }
    else {
        P = w;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                clr[i][j] = j % P;
                cnt[clr[i][j]]++;
            }
        }
    }
    int mn = 1e8;
    for (int i = 0; i < P; i++) {
        mn = min(mn, cnt[i]);
    }
    bool f1 = false;
    bool f2 = false;
    const int PP = (int)1e9 - 15;
    for (int i = 0; i < P; i++) {
        if (cnt[i] == mn) {
            if (!f1) {
                val[i] = ~PP;
                f1 = true;
            }
        }
        else {
            if (!f2) {
                val[i] = PP;
                f2 = true;
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << val[clr[i][j]] << " ";
        }
        cout << '\n';
    }
    return 0;
}


Compiler output:
a.cc:75:5: error: redefinition of 'int h'
   75 | int h, w;
      |     ^
a.cc:6:5: note: 'int h' previously declared here
    6 | int h, w;
      |     ^
a.cc:75:8: error: redefinition of 'int w'
   75 | int h, w;
      |        ^
a.cc:6:8: note: 'int w' previously declared here
    6 | int h, w;
      |        ^
a.cc:76:5: error: redefinition of 'int H'
   76 | int H, W;
      |     ^
a.cc:7:5: note: 'int H' previously declared here
    7 | int H, W;
      |     ^
a.cc:76:8: error: redefinition of 'int W'
   76 | int H, W;
      |        ^
a.cc:7:8: note: 'int W' previously declared here
    7 | int H, W;
      |        ^
a.cc:77:11: error: redefinition of 'const int maxN'
   77 | const int maxN = 505;
      |           ^~~~
a.cc:8:11: note: 'const int maxN' previously defined here
    8 | const int maxN = 505;
      |           ^~~~
a.cc:78:5: error: redefinition of 'int cnt [505]'
   78 | int cnt[maxN];
      |     ^~~
a.cc:9:5: note: 'int cnt [505]' previously declared here
    9 | int cnt[maxN];
      |     ^~~
a.cc:79:5: error: redefinition of 'int clr [505][505]'
   79 | int clr[maxN][maxN];
      |     ^~~
a.cc:10:5: note: 'int clr [505][505]' previously declared here
   10 | int clr[maxN][maxN];
      |     ^~~
a.cc:80:5: error: redefinition of 'int val [505]'
   80 | int val[maxN];
      |     ^~~
a.cc:11:5: note: 'int val [505]' previously declared here
   11 | int val[maxN];
      |     ^~~
a.cc:81:5: error: redefinition of 'int main()'
   81 | int main() {
      |     ^~~~
a.cc:12:5: note: 'int main()' previously defined here
   12 | int main() {
      |     ^~~~