Problem:
Score : 700 points

Problem Statement

You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W).
Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:

The matrix has H rows and W columns.

Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).

The sum of all the elements of the matrix is positive.

The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.

Constraints

1 ≤ h ≤ H ≤ 500

1 ≤ w ≤ W ≤ 500

Input

Input is given from Standard Input in the following format:

H W h w

Output

If there does not exist a matrix that satisfies all of the conditions, print No.

Otherwise, print Yes in the first line, and print a matrix in the subsequent lines in the following format:

a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}

Here, a_{ij} represents the (i,\ j) element of the matrix.

Sample Input 1

3 3 2 2

Sample Output 1

Yes
1 1 1
1 -4 1
1 1 1

The sum of all the elements of this matrix is 4, which is positive.
Also, in this matrix, there are four subrectangles with 2 rows and 2 columns as shown below. For each of them, the sum of all the elements inside is -1, which is negative.

Sample Input 2

2 4 1 2

Sample Output 2

No

Sample Input 3

3 4 2 3

Sample Output 3

Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long
#define NAME ""

long long n, m, h, w;
long long a[1000][1000];
long long summ;

long long f(int i, int j)
{
    return j == m ? 0 : a[i][j] + f(i, j + 1);
}

int p()
{
    cout << "Yes\n";
    for (int i = 0, j; i < n; puts(""), i++)
        for (j = 0; j < m; cout << " ", j++)
            cout << a[i][j];
    exit(0);
}

signed main()
{
    if (NAME != "")
    {
        freopen(NAME ".in", "r", stdin);
        freopen(NAME ".out", "w", stdout);
    }
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    cin >> n >> m >> h >> w;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = 1;
    for (int i = h - 1; i < n; i += h) for (int j = w - 1; j < m; j += w) a[i][j] = - (w * h);
    if (n % h == 0 && m % w == 0) puts("No"), exit(0);
    if (h == 1) for (int i = 0; i < n; i = i < n - 1 ? i + 1 : i + p()) for (int j = 0; j < m; j++) a[i][j] = (j % w == w - 1) ? (1 - w) * 250001 - 1 : 250001;
    if (w == 1) for (int j = 0; j < m; j = j < m - 1 ? j + 1 : j + p()) for (int i = 0; i < n; i++) a[i][j] = (i % h == h - 1) ? (1 - h) * 250001 - 1 : 250001;
    long long INF1 = 990000000 / (h - 1), INF2 = 990000000 / (w - 1);
    INF1 *= (h - 1), INF2 *= (w - 1);
    if (n % h != 0) for (int i = 0; i < n; i++) a[i][m - 1] = INF1 / (h - 1);
    if (n % h != 0) for (int i = h - 1; i < n; i += h) a[i][m - 1] = -INF1 - 250001;
    if (m % w != 0) for (int j = 0; j < m; j++) a[n - 1][j] = INF2 / (w - 1);
    if (m % w != 0) for (int j = w - 1; j < m; j += w) a[n - 1][j] = -INF2 - 250001;
    if (n % h != 0 && m % w != 0) a[n - 1][m - 1] = max(INF1 / (h - 1), INF2 / (w - 1));
    p();
}