prithivMLmods/Coder-Stat huggingface dataset:
Problem p03688 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;

int read() {
  int s = 0;
  char c = getchar(), lc = '+';
  while (c < '0' || '9' < c)
    lc = c, c = getchar();
  while ('0' <= c && c <= '9')
    s = s * 10 + c - '0', c = getchar();
  return lc == '-' ? -s : s;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x < 10)
    putchar(x + '0');
  else {
    write(x / 10);
    putchar(x % 10 + '0');
  }
}
void print(int x, char c = '\n') {
  write(x);
  putchar(c);
}
int a[N];
bool solve() {
  int n = read(), Max = 0, Min = n, s1 = 0, s2 = 0;
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++)
    Max = max(Max, a[i]);
  for (int i = 1; i <= n; i++)
    Min = min(Min, a[i]);
  if (Max - Min > 1)
    return 0;
  if (Max == Min)
    return a[1] == n - 1 || a[1] <= n / 2;
  for (int i = 1; i <= n; i++)
    if (a[i] == Min)
      s1++;
  for (int i = 1; i <= n; i++)
    if (a[i] == Max)
      s2++;
  return 0 < Max - s1 && Max - s1 <= s2 / 2 &&
         (s1 + 1 <= Max || Max <= s1 + s2 / 2);
}

int main() {
  puts(solve() ? "Yes" : "No");

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

int read() {
  int s = 0;
  char c = getchar(), lc = '+';
  while (c < '0' || '9' < c)
    lc = c, c = getchar();
  while ('0' <= c && c <= '9')
    s = s * 10 + c - '0', c = getchar();
  return lc == '-' ? -s : s;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x < 10)
    putchar(x + '0');
  else {
    write(x / 10);
    putchar(x % 10 + '0');
  }
}
void print(int x, char c = '\n') {
  write(x);
  putchar(c);
}
int a[N];
bool solve() {
  int n = read(), Max = 0, Min = n, s1 = 0, s2 = 0;
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++)
    Max = max(Max, a[i]);
  for (int i = 1; i <= n; i++)
    Min = min(Min, a[i]);
  if (Max - Min > 1)
    return 0;
  if (Max == Min)
    return a[1] == n - 1 || a[1] <= n / 2;
  for (int i = 1; i <= n; i++)
    if (a[i] == Min)
      s1++;
  for (int i = 1; i <= n; i++)
    if (a[i] == Max)
      s2++;
  return 0 < Max - s1 && Max - s1 <= s2 / 2 &&
         (s1 + 1 <= Max || Max <= s1 + s2 / 2);
}

int main() {
  puts(solve() ? "Yes" : "No");

  return 0;
}
Problem p03688 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

const int N = 10005;
int n;
int a[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int mn = N, mx = 0;
  for (int i = 0; i < n; i++) {
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
  }

  if (mn == mx) {
    if (n == mx + 1 || n >= 2 * mx)
      cout << "Yes\n";
    else
      cout << "No\n";
  } else if (mn == mx - 1) {
    int loct = 0, hict = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == mn)
        loct++;
      if (a[i] == mx)
        hict++;
    }
    if (mx >= loct + 1 && hict >= 2 * (mx - loct)) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  } else {
    cout << "No\n";
  }
}

Fixed submission:
#include <iostream>

using namespace std;

const int N = 1e5 + 5;
int n;
int a[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int mn = N, mx = 0;
  for (int i = 0; i < n; i++) {
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
  }

  if (mn == mx) {
    if (n == mx + 1 || n >= 2 * mx)
      cout << "Yes\n";
    else
      cout << "No\n";
  } else if (mn == mx - 1) {
    int loct = 0, hict = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == mn)
        loct++;
      if (a[i] == mx)
        hict++;
    }
    if (mx >= loct + 1 && hict >= 2 * (mx - loct)) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  } else {
    cout << "No\n";
  }
}
Problem p03688 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip> //cout << fixed << setprecision(15) << x << endl;
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL << 60;
#define Pint pair<int, int>
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
/* -- template -- */

int main() {
  int N;
  cin >> N;
  int a[N];
  rep(i, N) cin >> a[i];
  sort(a, a + N);
  map<int, int> m;
  rep(i, N) { m[a[i]] = i; }
  if (m.size() > 2) {
    cout << "No" << endl;
    return 0;
  }
  if (m.size() == 1) {
    if (a[0] == N - 1 || N % a[0] == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    int colorNum = m[a[0]] + 1;
    int nokori = a[N - 1] - colorNum;
    if (a[0] + 1 == a[N - 1] && (N - m[a[0]] - 1) % nokori == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip> //cout << fixed << setprecision(15) << x << endl;
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL << 60;
#define Pint pair<int, int>
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
/* -- template -- */

int main() {
  int N;
  cin >> N;
  int a[N];
  rep(i, N) cin >> a[i];
  sort(a, a + N);
  map<int, int> m;
  rep(i, N) { m[a[i]] = i; }
  if (m.size() > 2) {
    cout << "No" << endl;
    return 0;
  }
  if (m.size() == 1) {
    if (a[0] == N - 1 || N % a[0] == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    int colorNum = m[a[0]] + 1;
    int nokori = a[N - 1] - colorNum;
    if (nokori <= 0) {
      cout << "No" << endl;
    } else if (a[0] + 1 == a[N - 1] && (N - m[a[0]] - 1) % nokori == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;

using namespace std;

#define LIMIT 1000000000

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  long unit = (LIMIT - 1) / (h * w - 1);
  int minus = (H / h) * (W / w),
      plus = (H % h) * W + (W % w) * H - (H % h) * (W % w);
  if (minus >= plus * unit) {
    cout << "No" << '\n';
    return 0;
  }
  cout << "Yes" << '\n';
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cout << (i % h == 0 && j % w == 0 ? -(unit * (h * w - 1) + 1) : unit)
           << ' ';
    }
    cout << '\n';
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;

using namespace std;

#define LIMIT 1000000000

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if (h * w == 1) {
    cout << "No" << '\n';
    return 0;
  }
  long unit = (LIMIT - 1) / (h * w - 1), minus = (H / h) * (W / w),
       plus = (H % h) * W + (W % w) * H - (H % h) * (W % w);
  if (minus >= plus * unit) {
    cout << "No" << '\n';
    return 0;
  }
  cout << "Yes" << '\n';
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cout << (i % h == 0 && j % w == 0 ? -(unit * (h * w - 1) + 1) : unit)
           << ' ';
    }
    cout << '\n';
  }
  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;

ll H, W, A, B;

int main(void) {
  cin >> H >> W >> A >> B;

  ll d = A * B - 1;
  ll u = (1000000000LL - 1) / d;
  ll m = u * d + 1;
  ll p = (H / A) * (W / B);
  ll s = (H * W - p) * u - p * m;

  if (s > 0) {
    cout << "Yes" << endl;
    REP(i, 0, H)
        REP(j, 0, W) cout << ((i + 1) % A == 0 && (j + 1) % B == 0 ? -m : u)
                          << (j + 1 != W ? " " : "\n");
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;

ll H, W, A, B;

int main(void) {
  cin >> H >> W >> A >> B;

  if (A * B == 1) {
    cout << "No" << endl;
    return 0;
  }

  ll d = A * B - 1;
  ll u = (1000000000LL - 1) / d;
  ll m = u * d + 1;
  ll p = (H / A) * (W / B);
  ll s = (H * W - p) * u - p * m;

  if (s > 0) {
    cout << "Yes" << endl;
    REP(i, 0, H)
        REP(j, 0, W) cout << ((i + 1) % A == 0 && (j + 1) % B == 0 ? -m : u)
                          << (j + 1 != W ? " " : "\n");
  } else {
    cout << "No" << endl;
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
const int MAXN = 505;

int H, W, h, w;
int arr[MAXN][MAXN];

int main() {
  scanf("%d%d%d%d", &H, &W, &h, &w);
  long long sum = 0;
  int k = 999999999 / (h * w - 1);
  {
    sum = 0;
    for (int i = 1; i <= H; i++)
      for (int j = 1; j <= W; j++) {
        if (i % h == 0 && j % w == 0)
          arr[i][j] = -k * (h * w - 1) - 1;
        else
          arr[i][j] = k;
        sum += arr[i][j];
      }
    if (sum > 0) {
      puts("Yes");
      for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++)
          printf("%d ", arr[i][j]);
        puts("");
      }
      return 0;
    }
  }
  puts("No");

  return 0;
}


Fixed submission:
#include <cstdio>
const int MAXN = 505;

int H, W, h, w;
int arr[MAXN][MAXN];

int main() {
  scanf("%d%d%d%d", &H, &W, &h, &w);
  if (h == 1 && w == 1) {
    puts("No");
    return 0;
  }
  long long sum = 0;
  int k = 999999999 / (h * w - 1);
  {
    sum = 0;
    for (int i = 1; i <= H; i++)
      for (int j = 1; j <= W; j++) {
        if (i % h == 0 && j % w == 0)
          arr[i][j] = -k * (h * w - 1) - 1;
        else
          arr[i][j] = k;
        sum += arr[i][j];
      }
    if (sum > 0) {
      puts("Yes");
      for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++)
          printf("%d ", arr[i][j]);
        puts("");
      }
      return 0;
    }
  }
  puts("No");

  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if (H % h == 0 && W % w == 0) {
    cout << "No" << endl;
    return 0;
  }
  vector<vector<int>> res(H, vector<int>(W, 1));
  if (W % w != 0) {
    vector<int> sum(W + 1, 0);
    for (int i = w; i <= W; i += w) {
      sum[i] = sum[i - w] - 1;
    }
    for (int i = W; i > 0; i--) {
      if (sum[i] != 0)
        continue;
      sum[i] = 1;
      for (int j = i - w; j > 0; j -= w) {
        sum[j] = sum[j + w] + 1;
      }
    }
    for (int i = 0; i < W; i++) {
      res[0][i] = sum[i + 1] - sum[i];
    }
    for (int i = 1; i < H; i++) {
      for (int j = 0; j < W; j++) {
        res[i][j] = res[0][j];
      }
    }
  } else {
    vector<int> sum(H + 1, 0);
    for (int i = h; i <= H; i += h) {
      sum[i] = sum[i - h] - 1;
    }
    for (int i = H; i > 0; i--) {
      if (sum[i] != 0)
        continue;
      sum[i] = 1;
      for (int j = i - h; j > 0; j -= h) {
        sum[j] = sum[j + h] + 1;
      }
    }
    for (int i = 0; i < H; i++) {
      res[0][i] = sum[i + 1] - sum[i];
    }
    for (int i = 0; i < H; i++) {
      for (int j = 1; j < W; j++) {
        res[i][j] = res[i][0];
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (j == 0)
        cout << res[i][j];
      else
        cout << " " << res[i][j];
    }
    cout << endl;
  }
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if (H % h == 0 && W % w == 0) {
    cout << "No" << endl;
    return 0;
  }
  vector<vector<int>> res(H, vector<int>(W, 1));
  if (W % w != 0) {
    vector<int> sum(W + 1, 0);
    for (int i = w; i <= W; i += w) {
      sum[i] = sum[i - w] - 1;
    }
    for (int i = W; i > 0; i--) {
      if (sum[i] != 0)
        continue;
      sum[i] = 1;
      for (int j = i - w; j > 0; j -= w) {
        sum[j] = sum[j + w] + 1;
      }
    }
    for (int i = 0; i < W; i++) {
      res[0][i] = sum[i + 1] - sum[i];
    }
    for (int i = 1; i < H; i++) {
      for (int j = 0; j < W; j++) {
        res[i][j] = res[0][j];
      }
    }
  } else {
    vector<int> sum(H + 1, 0);
    for (int i = h; i <= H; i += h) {
      sum[i] = sum[i - h] - 1;
    }
    for (int i = H; i > 0; i--) {
      if (sum[i] != 0)
        continue;
      sum[i] = 1;
      for (int j = i - h; j > 0; j -= h) {
        sum[j] = sum[j + h] + 1;
      }
    }
    for (int i = 0; i < H; i++) {
      res[i][0] = sum[i + 1] - sum[i];
    }
    for (int i = 0; i < H; i++) {
      for (int j = 1; j < W; j++) {
        res[i][j] = res[i][0];
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (j == 0)
        cout << res[i][j];
      else
        cout << " " << res[i][j];
    }
    cout << endl;
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
template <class T> bool chmin(T &a, const T &b) {
  return a > b ? (a = b, true) : false;
}
template <class T> bool chmax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}

int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}

ll t[512][512];
ll acm[512][512];

int H, W, h, w;

ll range(int r1, int c1, int r2, int c2) {
  return acm[r2][c2] - acm[r1][c2] - acm[r2][c1] + acm[r1][c1];
}

bool check() {
  memset(acm, 0, sizeof(acm));
  REP(i, H) REP(j, W) {
    acm[i + 1][j + 1] = -acm[i][j] + acm[i + 1][j] + acm[i][j + 1] + t[i][j];
  }
  if (range(0, 0, H, W) <= 0)
    return false;
  REP(i, H - h + 1) REP(j, W - w + 1) {
    if (range(i, j, i + h, j + w) >= 0)
      return false;
  }
  return true;
}

int main2() {
  H = nextInt();
  W = nextInt();
  h = nextInt();
  w = nextInt();

  ll BIG = (ll)1e9;
  memset(t, -1, sizeof(t));
  REP(i, H) REP(j, W) {
    ll p = h * w - 1;
    t[i][j] = -((BIG + 1 + p - 1) / p);
  }

  for (int i = 0; i < H; i += h) {
    for (int j = 0; j < W; j += w) {
      t[i][j] = BIG;
    }
  }
  if (check()) {
    cout << "Yes" << endl;
    REP(i, H) {
      REP(j, W) {
        if (j > 0)
          printf(" ");
        printf("%d", t[i][j]);
      }
      printf("\n");
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}

int main() {
  for (; !cin.eof(); cin >> ws)
    main2();
  return 0;
}


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

typedef long long ll;
#define REP(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
template <class T> bool chmin(T &a, const T &b) {
  return a > b ? (a = b, true) : false;
}
template <class T> bool chmax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}

int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}

ll t[512][512];
ll acm[512][512];

int H, W, h, w;

ll range(int r1, int c1, int r2, int c2) {
  return acm[r2][c2] - acm[r1][c2] - acm[r2][c1] + acm[r1][c1];
}

bool check() {
  memset(acm, 0, sizeof(acm));
  REP(i, H) REP(j, W) {
    acm[i + 1][j + 1] = -acm[i][j] + acm[i + 1][j] + acm[i][j + 1] + t[i][j];
  }
  if (range(0, 0, H, W) <= 0)
    return false;
  REP(i, H - h + 1) REP(j, W - w + 1) {
    if (range(i, j, i + h, j + w) >= 0)
      return false;
  }
  return true;
}

int main2() {
  H = nextInt();
  W = nextInt();
  h = nextInt();
  w = nextInt();

  if (h * w == 1) {
    cout << "No" << endl;
    return 0;
  }

  ll BIG = (ll)(1e9 - 1);
  memset(t, -1, sizeof(t));
  REP(i, H) REP(j, W) {
    ll p = h * w - 1;
    t[i][j] = -((BIG + 1 + p - 1) / p);
  }

  for (int i = 0; i < H; i += h) {
    for (int j = 0; j < W; j += w) {
      t[i][j] = BIG;
    }
  }
  if (check()) {
    cout << "Yes" << endl;
    REP(i, H) {
      REP(j, W) {
        if (j > 0)
          printf(" ");
        printf("%d", t[i][j]);
      }
      printf("\n");
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}

int main() {
  for (; !cin.eof(); cin >> ws)
    main2();
  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int a, b, c, d, k, s[501][501];
const int M = 1e9;
ll tot;

int main() {
  scanf("%d%d%d%d", &a, &b, &c, &d);
  k = M / (c * d - 1);
  while (-k * (c * d - 1) - 1 < -M)
    k--;
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      if (i % c == 0 && j % d == 0)
        s[i][j] = -k * (c * d - 1) - 1;
      else
        s[i][j] = k;
      tot += s[i][j];
    }
  }
  if (tot <= 0)
    puts("No");
  else {
    puts("Yes");
    for (int i = 1; i <= a; i++, puts(""))
      for (int j = 1; j <= b; j++)
        printf("%d ", s[i][j]);
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int a, b, c, d, k, s[501][501];
const int M = 1e9;
ll tot;

int main() {
  scanf("%d%d%d%d", &a, &b, &c, &d);
  if (c == 1 && d == 1) {
    puts("No");
    return 0;
  }
  k = M / (c * d - 1);
  while (-k * (c * d - 1) - 1 < -M)
    k--;
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      if (i % c == 0 && j % d == 0)
        s[i][j] = -k * (c * d - 1) - 1;
      else
        s[i][j] = k;
      tot += s[i][j];
    }
  }
  if (tot <= 0)
    puts("No");
  else {
    puts("Yes");
    for (int i = 1; i <= a; i++, puts(""))
      for (int j = 1; j <= b; j++)
        printf("%d ", s[i][j]);
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

const int MAX_W = 505;
const int MAX = 1e9;

using namespace std;

int table[MAX_W][MAX_W];

int main() {
  int largeh, largew, smallh, smallw;
  cin >> largeh >> largew >> smallh >> smallw;

  int amb = (MAX - 1) / (smallh * smallw - 1);
  int neg = -(smallh * smallw - 1) * amb - 1;

  long long sum = 0;
  for (int i = 1; i <= largeh; i++) {
    for (int j = 1; j <= largew; j++) {
      if (i % smallh == 0 && j % smallw == 0) {
        table[i][j] = neg;
      } else {
        table[i][j] = amb;
      }

      sum += table[i][j];
    }
  }

  if (sum > 0) {
    cout << "Yes" << endl;
    for (int i = 1; i <= largeh; i++) {
      for (int j = 1; j <= largew; j++) {
        cout << table[i][j] << " ";
      }
      cout << endl;
    }
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <iostream>

const int MAX_W = 505;
const int MAX = 1e9;

using namespace std;

int table[MAX_W][MAX_W];

int main() {
  int largeh, largew, smallh, smallw;
  cin >> largeh >> largew >> smallh >> smallw;

  if (smallh * smallw == 1) {
    cout << "No" << endl;
    return 0;
  }

  int amb = (MAX - 1) / (smallh * smallw - 1);
  int neg = -(smallh * smallw - 1) * amb - 1;

  long long sum = 0;
  for (int i = 1; i <= largeh; i++) {
    for (int j = 1; j <= largew; j++) {
      if (i % smallh == 0 && j % smallw == 0) {
        table[i][j] = neg;
      } else {
        table[i][j] = amb;
      }

      sum += table[i][j];
    }
  }

  if (sum > 0) {
    cout << "Yes" << endl;
    for (int i = 1; i <= largeh; i++) {
      for (int j = 1; j <= largew; j++) {
        cout << table[i][j] << " ";
      }
      cout << endl;
    }
  } else {
    cout << "No" << endl;
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <stdio.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 1000000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main() {
  // freopen("a.in", "r", stdin);
  // freopen("a.out", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  // ll TL = 0.95 * CLOCKS_PER_SEC;
  // clock_t time = clock();
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int X = (1000000000 % (x * y - 1) != 0 ? 1000000000 / (x * y - 1)
                                         : 999999999 / (x * y - 1));
  int a[n][m];
  rep(i, 0, n) rep(j, 0, m) if (i % x == x - 1 && j % y == y - 1) a[i][j] =
      -(x * y - 1) * X - 1;
  else a[i][j] = X;
  ll sum = 0;
  rep(i, 0, n) rep(j, 0, m) sum += a[i][j];
  if (sum > 0) {
    cout << "Yes\n";
    rep(i, 0, n) {
      rep(j, 0, m) cout << a[i][j] << " ";
      cout << endl;
    }
  } else {
    cout << "No\n";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <stdio.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 1000000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main() {
  // freopen("a.in", "r", stdin);
  // freopen("a.out", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  // ll TL = 0.95 * CLOCKS_PER_SEC;
  // clock_t time = clock();
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  if (x * y == 1) {
    cout << "No\n";
    return 0;
  }
  int X = (1000000000 % (x * y - 1) != 0 ? 1000000000 / (x * y - 1)
                                         : 999999999 / (x * y - 1));
  int a[n][m];
  rep(i, 0, n) rep(j, 0, m) if (i % x == x - 1 && j % y == y - 1) a[i][j] =
      -(x * y - 1) * X - 1;
  else a[i][j] = X;
  ll sum = 0;
  rep(i, 0, n) rep(j, 0, m) sum += a[i][j];
  if (sum > 0) {
    cout << "Yes\n";
    rep(i, 0, n) {
      rep(j, 0, m) cout << a[i][j] << " ";
      cout << endl;
    }
  } else {
    cout << "No\n";
  }
  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
int H, W, h, w;
int main() {
  cin >> H >> W >> h >> w;

  ll b_g = (H / h) * (W / w);
  ll w_g = H * W - b_g;
  ll w_s = h * w - 1;

  ll nw = 999999990LL / ll(w_s);
  ll nb = (-1LL) * (nw * ll(w_s) + 1LL);

  if (nb * b_g + nw * w_g <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    rep(y, H) {
      rep(x, W) {
        if (((y + 1) % h == 0) && ((x + 1) % w == 0))
          printf("%lld", nb);
        else
          printf("%lld", nw);
        if (x + 1 == W)
          cout << endl;
        else
          cout << " ";
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
int H, W, h, w;
int main() {
  cin >> H >> W >> h >> w;

  ll b_g = (H / h) * (W / w);
  ll w_g = H * W - b_g;
  ll w_s = h * w - 1;
  if (h == 1 && w == 1) {
    cout << "No" << endl;
    return 0;
  }

  ll nw = 999999990LL / ll(w_s);
  ll nb = (-1LL) * (nw * ll(w_s) + 1LL);

  if (nb * b_g + nw * w_g <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    rep(y, H) {
      rep(x, W) {
        if (((y + 1) % h == 0) && ((x + 1) % w == 0))
          printf("%lld", nb);
        else
          printf("%lld", nw);
        if (x + 1 == W)
          cout << endl;
        else
          cout << " ";
      }
    }
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
static const int LIMIT = 1000000000;

int main() {
  ios_base::sync_with_stdio(false);
  int n, m, h, w;
  cin >> n >> m >> h >> w;
  const ll hi = ((LIMIT - 1) / (h * w - 1)) * (h * w - 1) + 1;
  const ll lo = (hi - 1) / (h * w - 1);
  vector<vector<ll>> a(n, vector<ll>(m, lo));
  for (int i = h - 1; i < n; i += h) {
    for (int j = w - 1; j < m; j += w) {
      a[i][j] = -hi;
    }
  }
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      sum += a[i][j];
    }
  }
  if (sum <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cout << a[i][j] << " ";
      }
      cout << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
static const int LIMIT = 1000000000;

int main() {
  ios_base::sync_with_stdio(false);
  int n, m, h, w;
  cin >> n >> m >> h >> w;
  if (h * w == 1) {
    cout << "No" << endl;
    return 0;
  }
  const ll hi = ((LIMIT - 1) / (h * w - 1)) * (h * w - 1) + 1;
  const ll lo = (hi - 1) / (h * w - 1);
  vector<vector<ll>> a(n, vector<ll>(m, lo));
  for (int i = h - 1; i < n; i += h) {
    for (int j = w - 1; j < m; j += w) {
      a[i][j] = -hi;
    }
  }
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      sum += a[i][j];
    }
  }
  if (sum <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cout << a[i][j] << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n = 100000000;
  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  ll ans[h][w];
  ll y = n / (a * b - 1);
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      ans[i][j] = y;
  for (ll i = a - 1; i < h; i += a)
    for (ll j = b - 1; j < w; j += b)
      ans[i][j] = -y * (a * b - 1) - 1;
  ll sum = 0;
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      sum += ans[i][j];
  if (sum > 0) {
    cout << "Yes" << endl;
    for (ll i = 0; i < h; i++) {
      for (ll j = 0; j < w; j++)
        cout << ans[i][j] << " ";
      cout << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n = 100000000;
  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  ll ans[h][w];
  if (a == 1 && b == 1) {
    cout << "No" << endl;
    return 0;
  }
  ll y = n / (a * b - 1);
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      ans[i][j] = y;
  for (ll i = a - 1; i < h; i += a)
    for (ll j = b - 1; j < w; j += b)
      ans[i][j] = -y * (a * b - 1) - 1;
  ll sum = 0;
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      sum += ans[i][j];
  if (sum > 0) {
    cout << "Yes" << endl;
    for (ll i = 0; i < h; i++) {
      for (ll j = 0; j < w; j++)
        cout << ans[i][j] << " ";
      cout << endl;
    }
  } else {
    cout << "No" << endl;
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll mat[505][505];
int H, W, h, w;
ll x, s;

int main() {
  scanf("%d%d%d%d", &H, &W, &h, &w);
  x = 999999999ll / (h * w - 1);
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      mat[i][j] = x;
  for (int i = h - 1; i < H; i += h)
    for (int j = w - 1; j < W; j += w)
      mat[i][j] = (1 - h * w) * x - 1;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      s += mat[i][j];
  if (s > 0) {
    printf("Yes\n");
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++)
        printf("%lld ", mat[i][j]);
      printf("\n");
    }
  } else
    printf("No\n");
  return 0;
}


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

typedef long long ll;

ll mat[505][505];
int H, W, h, w;
ll x, s;

int main() {
  scanf("%d%d%d%d", &H, &W, &h, &w);
  if (h * w == 1) {
    printf("No\n");
    return 0;
  }
  x = 999999999ll / (h * w - 1);
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      mat[i][j] = x;
  for (int i = h - 1; i < H; i += h)
    for (int j = w - 1; j < W; j += w)
      mat[i][j] = (1 - h * w) * x - 1;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      s += mat[i][j];
  if (s > 0) {
    printf("Yes\n");
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++)
        printf("%lld ", mat[i][j]);
      printf("\n");
    }
  } else
    printf("No\n");
  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define lson l, mid, i << 1
#define rson mid + 1, r, i << 1 | 1
#define PII pair<int, int>
using namespace std;
typedef long long LL;
// const int MOD = 1e9+7;
const auto INF = 1e9;
const int N = 5e2 + 5;

LL a[N][N];

int main() {
  int N, M, n, m;
  scanf("%d%d%d%d", &N, &M, &n, &m);
  LL x, y;
  y = 1e9;
  x = (y - 1) / (n * m - 1);
  for (int i = 1; i * n <= N; i++) {
    for (int j = 1; j * m <= M; j++) {
      a[i * n][j * m] = -y;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (a[i][j] == 0) {
        a[i][j] = x;
      }
    }
  }
  bool flag = true;
  LL answer = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      answer += a[i][j];
    }
  }
  if (answer <= 0)
    flag = false;
  if (!flag)
    printf("No\n");
  else {
    printf("Yes\n");
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= M; j++) {
        printf("%lld%c", a[i][j], j == M ? '\n' : ' ');
      }
    }
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define lson l, mid, i << 1
#define rson mid + 1, r, i << 1 | 1
#define PII pair<int, int>
using namespace std;
typedef long long LL;
// const int MOD = 1e9+7;
const auto INF = 1e9;
const int N = 5e2 + 5;

LL a[N][N];

int main() {
  int N, M, n, m;
  scanf("%d%d%d%d", &N, &M, &n, &m);
  LL x, y;
  y = 1e9;
  if (n * m != 1)
    x = (y - 1) / (n * m - 1);
  else
    x = 1;
  for (int i = 1; i * n <= N; i++) {
    for (int j = 1; j * m <= M; j++) {
      a[i * n][j * m] = -y;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (a[i][j] == 0) {
        a[i][j] = x;
      }
    }
  }
  bool flag = true;
  LL answer = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      answer += a[i][j];
    }
  }
  if (answer <= 0)
    flag = false;
  if (!flag)
    printf("No\n");
  else {
    printf("Yes\n");
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= M; j++) {
        printf("%lld%c", a[i][j], j == M ? '\n' : ' ');
      }
    }
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
// Copyright 2017 wu_qing
#include <cstdint>
#include <cstdio>
const int N = 600;
int64_t H, W, h, w, x, y, v[N][N], sum;
int main() {
  scanf("%lld%lld%lld%lld", &H, &W, &h, &w);
  x = 999999999 / (w * h - 1);
  y = -x * (w * h - 1) - 1;
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++)
      v[i][j] = x;
  for (int i = h; i <= H; i += h)
    for (int j = w; j <= W; j += w)
      v[i][j] = y;
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++)
      sum += v[i][j];
  if (sum > 0) {
    printf("Yes\n");
    for (int i = 1; i <= H; i++) {
      printf("%lld", v[i][1]);
      for (int j = 2; j <= W; j++)
        printf(" %lld", v[i][j]);
      printf("\n");
    }
  } else {
    printf("No\n");
  }
}


Fixed submission:
// Copyright 2017 wu_qing
#include <cstdint>
#include <cstdio>
const int N = 600;
int64_t H, W, h, w, x, y, v[N][N], sum;
int main() {
  scanf("%lld%lld%lld%lld", &H, &W, &h, &w);
  if (w * h == 1) {
    printf("No\n");
    return 0;
  }
  x = 999999999 / (w * h - 1);
  y = -x * (w * h - 1) - 1;
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++)
      v[i][j] = x;
  for (int i = h; i <= H; i += h)
    for (int j = w; j <= W; j += w)
      v[i][j] = y;
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++)
      sum += v[i][j];
  if (sum > 0) {
    printf("Yes\n");
    for (int i = 1; i <= H; i++) {
      printf("%lld", v[i][1]);
      for (int j = 2; j <= W; j++)
        printf(" %lld", v[i][j]);
      printf("\n");
    }
  } else {
    printf("No\n");
  }
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

int main() {
  int n, m, h, w;
  scanf("%d%d%d%d", &n, &m, &h, &w);
  if (n % h == 0 && m % w == 0)
    return puts("No"), 0;
  puts("Yes");

  long long c = ((n / h) * (m / w) - 1) /
                    ((n % h) * m + (m % w) * n - (n % h) * (m % w)) +
                1;
  long long s = (h * w - 1) * c + 1, t = 0;
  int i, j;
  for (i = 1; i <= n; i++, putchar(10))
    for (j = 1; j <= m; j++)
      printf("%lld ", i % h == 0 && j % w == 0 ? -s : c),
          t += i % h == 0 && j % w == 0 ? -s : c;
  if (t <= 0)
    return 1;
}

Fixed submission:
#include <cstdio>

int main() {
  int n, m, h, w;
  scanf("%d%d%d%d", &n, &m, &h, &w);
  if (n % h == 0 && m % w == 0)
    return puts("No"), 0;
  puts("Yes");

  long long c =
      (n / h) * (m / w) / ((n % h) * m + (m % w) * n - (n % h) * (m % w)) + 1;
  long long s = (h * w - 1) * c + 1, t = 0;
  int i, j;
  for (i = 1; i <= n; i++, putchar(10))
    for (j = 1; j <= m; j++)
      printf("%lld ", i % h == 0 && j % w == 0 ? -s : c),
          t += i % h == 0 && j % w == 0 ? -s : c;
  if (t <= 0)
    return 1;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

// #define FILE_IO

int N, M, l, c;
int a[1005][1005];

int main() {
#ifdef FILE_IO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  scanf("%d%d", &N, &M);
  scanf("%d%d", &l, &c);

  int val1 = (int(1e9) - 1) / (l * c - 1);
  int val2 = -((l * c - 1) * val1 + 1);

  for (int i = 1; i <= N; i += l)
    for (int j = 1; j <= M; j += c) {
      for (int x = 0; x < l; x++)
        for (int y = 0; y < c; y++)
          a[i + x][j + y] = val1;
      a[i + l - 1][j + c - 1] = val2;
    }

  long long S = 0;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      S += a[i][j];

  if (S <= 0) {
    printf("No\n");
  } else {
    printf("Yes\n");
    for (int i = 1; i <= N; i++, printf("\n"))
      for (int j = 1; j <= M; j++)
        printf("%d ", a[i][j]);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

// #define FILE_IO

int N, M, l, c;
int a[1005][1005];

int main() {
#ifdef FILE_IO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  scanf("%d%d", &N, &M);
  scanf("%d%d", &l, &c);

  if (l == 1 && c == 1) {
    printf("No\n");
    return 0;
  }

  int val1 = (int(1e9) - 1) / (l * c - 1);
  int val2 = -((l * c - 1) * val1 + 1);

  for (int i = 1; i <= N; i += l)
    for (int j = 1; j <= M; j += c) {
      for (int x = 0; x < l; x++)
        for (int y = 0; y < c; y++)
          a[i + x][j + y] = val1;
      a[i + l - 1][j + c - 1] = val2;
    }

  long long S = 0;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      S += a[i][j];

  if (S <= 0) {
    printf("No\n");
  } else {
    printf("Yes\n");
    for (int i = 1; i <= N; i++, printf("\n"))
      for (int j = 1; j <= M; j++)
        printf("%d ", a[i][j]);
  }

  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template <class T> void chmin(T &x, T y) {
  if (x > y)
    x = y;
}
template <class T> void chmax(T &x, T y) {
  if (x < y)
    x = y;
}

int H, W, h, w;
int ans[510][510];
int mx = 1e9 - 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> H >> W >> h >> w;
  mx /= (h * w - 1);
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      ans[i][j] = mx;
    }
  }
  for (int i = h; i <= H; i += h) {
    for (int j = w; j <= W; j += w) {
      ans[i][j] = -(mx * (h * w - 1) + 1);
    }
  }
  ll sum = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      sum += ans[i][j];
    }
  }
  if (sum <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        cout << ans[i][j] << (j != W ? " " : "\n");
      }
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template <class T> void chmin(T &x, T y) {
  if (x > y)
    x = y;
}
template <class T> void chmax(T &x, T y) {
  if (x < y)
    x = y;
}

int H, W, h, w;
int ans[510][510];
int mx = 1e9 - 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> H >> W >> h >> w;
  if (h == 1 && w == 1) {
    cout << "No" << endl;
    return 0;
  }
  mx /= (h * w - 1);
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      ans[i][j] = mx;
    }
  }
  for (int i = h; i <= H; i += h) {
    for (int j = w; j <= W; j += w) {
      ans[i][j] = -(mx * (h * w - 1) + 1);
    }
  }
  ll sum = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      sum += ans[i][j];
    }
  }
  if (sum <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        cout << ans[i][j] << (j != W ? " " : "\n");
      }
    }
  }
  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

int main() {
  long h, w, a, b;
  scanf("%ld %ld %ld %ld", &h, &w, &a, &b);
  long n = 999999999 / (a * b - 1);
  long m = -n * (a * b - 1) - 1;
  if ((m - n) * (h / a) * (w / b) + n * h * w <= 0) {
    printf("No");
  } else {
    printf("Yes\n");
    for (int i = 1; i < h + 1; i++) {
      for (int j = 1; j < w + 1; j++) {
        if (i % a == 0 && j % b == 0) {
          printf("%ld ", m);
        } else {
          printf("%ld ", n);
        }
      }
      printf("\n");
    }
  }

  return 0;
}


Fixed submission:
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

int main() {
  long h, w, a, b;
  scanf("%ld %ld %ld %ld", &h, &w, &a, &b);
  if (a * b == 1) {
    printf("No");
    return 0;
  }
  long n = 999999999 / (a * b - 1);
  long m = -n * (a * b - 1) - 1;
  if ((m - n) * (h / a) * (w / b) + n * h * w <= 0) {
    printf("No");
  } else {
    printf("Yes\n");
    for (int i = 1; i < h + 1; i++) {
      for (int j = 1; j < w + 1; j++) {
        if (i % a == 0 && j % b == 0) {
          printf("%ld ", m);
        } else {
          printf("%ld ", n);
        }
      }
      printf("\n");
    }
  }

  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <set>
#include <vector>

using namespace std;

const int MAXN = 500 + 10;

int H, W, h, w;
int G[MAXN][MAXN];

void Work() {
  scanf("%d%d%d%d", &H, &W, &h, &w);
  int SZ = (1000000000 - 1) / (h * w - 1);
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      if ((i + 1) % h == 0 && (j + 1) % w == 0)
        G[i][j] = -(h * w - 1) * SZ - 1;
      else
        G[i][j] = SZ;
    }
  long long sum = 0;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      sum += (long long)G[i][j];
  if (sum <= 0)
    printf("No\n");
  else {
    printf("Yes\n");
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W - 1; j++)
        printf("%d ", G[i][j]);
      printf("%d\n", G[i][W - 1]);
    }
  }
}

int main() {
  Work();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <set>
#include <vector>

using namespace std;

const int MAXN = 500 + 10;

int H, W, h, w;
int G[MAXN][MAXN];

void Work() {
  scanf("%d%d%d%d", &H, &W, &h, &w);
  int SZ;
  if (h * w == 1)
    SZ = 1;
  else
    SZ = (1000000000 - 1) / (h * w - 1);
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      if ((i + 1) % h == 0 && (j + 1) % w == 0)
        G[i][j] = -(h * w - 1) * SZ - 1;
      else
        G[i][j] = SZ;
    }
  long long sum = 0;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      sum += (long long)G[i][j];
  if (sum <= 0)
    printf("No\n");
  else {
    printf("Yes\n");
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W - 1; j++)
        printf("%d ", G[i][j]);
      printf("%d\n", G[i][W - 1]);
    }
  }
}

int main() {
  Work();
  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#pragma warning(disable : 4996)
int H, W, h, w, a[509][509];
int main() {
  scanf("%d %d %d %d", &H, &W, &h, &w);
  if (H == 1 && W == 1)
    printf("No\n");
  else {
    int x = 999999999 / (h * w - 1);
    long long sum = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if ((i + 1) % h == 0 && (j + 1) % w == 0)
          a[i][j] = -((h * w - 1) * x + 1);
        else
          a[i][j] = x;
        sum += a[i][j];
      }
    }
    if (sum <= 0)
      printf("No\n");
    else {
      printf("Yes\n");
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          printf("%d ", a[i][j]);
        }
        printf("\n");
      }
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#pragma warning(disable : 4996)
int H, W, h, w, a[509][509];
int main() {
  scanf("%d %d %d %d", &H, &W, &h, &w);
  if (h == 1 && w == 1)
    printf("No\n");
  else {
    int x = 999999999 / (h * w - 1);
    long long sum = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if ((i + 1) % h == 0 && (j + 1) % w == 0)
          a[i][j] = -((h * w - 1) * x + 1);
        else
          a[i][j] = x;
        sum += a[i][j];
      }
    }
    if (sum <= 0)
      printf("No\n");
    else {
      printf("Yes\n");
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          printf("%d ", a[i][j]);
        }
        printf("\n");
      }
    }
  }
  return 0;
}
Problem p03689 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define N 510
using namespace std;
int a[N][N], n, m, h, w;
bool b[N][N];
int main() {
  scanf("%d%d%d%d", &n, &m, &h, &w);
  for (int i = 1; i <= n - h + 1; i++)
    for (int j = 1; j <= m - w + 1; j++) {
      if (b[i][j])
        continue;
      for (int x = i; x <= i + h - 1; x++)
        for (int y = j; y <= j + w - 1; y++)
          b[x][y] = 1;
      for (int x = i; x <= i + 2 * h - 2; x++)
        for (int y = j; y <= j + 2 * w - 2; y++)
          a[x][y] = 1;
      a[i + h - 1][j + w - 1] = -h * w;
    }
  int sum = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      sum += a[i][j];
  if (sum > 0) {
    printf("Yes\n");
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++)
        printf("%d ", a[i][j]);
      printf("\n");
    }
  } else
    printf("No\n");
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define N 510
using namespace std;
int a[N][N], n, m, h, w;
bool b[N][N];
int main() {
  scanf("%d%d%d%d", &n, &m, &h, &w);
  for (int i = 1; i <= n - h + 1; i++)
    for (int j = 1; j <= m - w + 1; j++) {
      if (b[i][j])
        continue;
      for (int x = i; x <= i + h - 1; x++)
        for (int y = j; y <= j + w - 1; y++)
          b[x][y] = 1;
      for (int x = i; x <= min(i + 2 * h - 2, n); x++)
        for (int y = j; y <= min(j + 2 * w - 2, m); y++)
          a[x][y] = 1000;
      a[i + h - 1][j + w - 1] = -(h * w - 1) * 1000 - 1;
    }
  int sum = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      sum += a[i][j];
  if (sum > 0) {
    printf("Yes\n");
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++)
        printf("%d ", a[i][j]);
      printf("\n");
    }
  } else
    printf("No\n");
  return 0;
}