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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

// ifstream cin("tema.in");
// ofstream cout("tema.out");

const int BUFFSIZE = 1 << 17;

char buffer[BUFFSIZE];
int pointer = BUFFSIZE;

char Advance() {
  if (pointer == BUFFSIZE) {
    fread(buffer, 1, BUFFSIZE, stdin);
    pointer = 0;
  }
  return buffer[pointer++];
}

int Read() {
  int answer = 0;
  char ch = Advance();
  while (!isdigit(ch))
    ch = Advance();
  while (isdigit(ch)) {
    answer = answer * 10 + ch - '0';
    ch = Advance();
  }
  return answer;
}

bool Check(int n, int m, int k, int a) {
  if (k - a * m >= 0 && (k - a * m) % (n - 2 * a) == 0)
    return true;
  return false;
}

int main() {
  // freopen("tema.in", "r", stdin);
  // freopen("tema.out", "w", stdout);
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i <= n; i++)
    if (Check(n, m, k, i)) {
      printf("Yes\n");
      return 0;
    }
  printf("No\n");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

// ifstream cin("tema.in");
// ofstream cout("tema.out");

const int BUFFSIZE = 1 << 17;

char buffer[BUFFSIZE];
int pointer = BUFFSIZE;

char Advance() {
  if (pointer == BUFFSIZE) {
    fread(buffer, 1, BUFFSIZE, stdin);
    pointer = 0;
  }
  return buffer[pointer++];
}

int Read() {
  int answer = 0;
  char ch = Advance();
  while (!isdigit(ch))
    ch = Advance();
  while (isdigit(ch)) {
    answer = answer * 10 + ch - '0';
    ch = Advance();
  }
  return answer;
}

bool Check(int n, int m, int k, int a) {
  if ((a * m == k && n == 2 * a) ||
      (n != 2 * a && (k - a * m) % (n - 2 * a) == 0 &&
       (k - a * m) / (n - 2 * a) <= m && (k - a * m) / (n - 2 * a) >= 0))
    return true;
  return false;
}

int main() {
  // freopen("tema.in", "r", stdin);
  // freopen("tema.out", "w", stdout);
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i <= n; i++)
    if (Check(n, m, k, i)) {
      printf("Yes\n");
      return 0;
    }
  printf("No\n");
  return 0;
}
Problem p03592 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, j, n) for (ll i = j; i < n; ++i)
#define MOD (1e9 + 7)

int main(void) {
  ll N, M, K;
  cin >> N >> M >> K;
  ll mem[N * M + 1];
  memset(mem, 0, N * M + 1);
  REP(i, N) {
    REP(j, M) {
      mem[j * (M * i + N - i)] = 1;
      mem[i * (N * j + M - j)] = 1;
    }
  }
  if (mem[K] == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, j, n) for (ll i = j; i < n; ++i)
#define MOD (1e9 + 7)

int main(void) {
  ll N, M, K;
  cin >> N >> M >> K;
  ll mem[N * M + 1];
  memset(mem, 0, N * M + 1);
  REP(i, N + 1) {
    REP(j, M + 1) { mem[i * M + j * N - 2 * i * j] = 1; }
  }
  if (mem[K] == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03592 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  int flag = 0;
  for (int b = 0; b <= m; b++) {
    if (m == 2 * b && k == b * n) {
      flag = 1;
      break;
    } else if ((k - b * n) % (m - 2 * b) == 0 &&
               (k - b * n) * (m - 2 * b) >= 0 &&
               (k - b * n) / (m - 2 * b) <= n) {
      flag = 1;
      break;
    }
  }
  if (flag == 0)
    printf("No");
  else
    printf("Yes");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  int flag = 0;
  for (int b = 0; b <= m; b++) {
    if (m == 2 * b) {
      if (k == b * n) {
        flag = 1;
        break;
      }
    } else if ((k - b * n) % (m - 2 * b) == 0 &&
               (k - b * n) * (m - 2 * b) >= 0 &&
               (k - b * n) / (m - 2 * b) <= n) {
      flag = 1;
      break;
    }
  }
  if (flag == 0)
    printf("No");
  else
    printf("Yes");
  return 0;
}
Problem p03592 (Python)

Buggy submission (status: Runtime Error):
N, M, K = map(int, input().split())

ans = False
for n in range(N + 1):
    if (M * n - K) % (2 * n - N) == 0:
        ans = True
        break
print("Yes" if ans else "No")


Fixed submission:
N, M, K = map(int, input().split())

ans = False
for n in range(N + 1):
    if 2 * n == N:
        if M * n == K:
            ans = True
            break
    else:
        num = M * n - K
        denom = 2 * n - N
        if num % denom == 0 and 0 <= num // denom <= M:
            ans = True
            break
print("Yes" if ans else "No")
Problem p03592 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#define mem(a, b) memset(a, b, sizeof(a))
#define For(i, a, b) for (int i = a, i##E = b; i <= i##E; ++i)
#define rFor(i, a, b) for (int i = a, i##E = b; i >= i##E; --i)
using namespace std;
typedef long long LL;
template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline void read(T &x) {
  x = 0;
  int _f(0);
  char ch = getchar();
  while (!isdigit(ch))
    _f |= (ch == '-'), ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = _f ? -x : x;
}
inline void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}
int n, m, k;
int main() {
  file();
  read(n), read(m), read(k);
  For(x, 0, n) For(y, 0, m) {
    if ((n - x) * y + x * (m - y) == k) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#define mem(a, b) memset(a, b, sizeof(a))
#define For(i, a, b) for (int i = a, i##E = b; i <= i##E; ++i)
#define rFor(i, a, b) for (int i = a, i##E = b; i >= i##E; --i)
using namespace std;
typedef long long LL;
template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline void read(T &x) {
  x = 0;
  int _f(0);
  char ch = getchar();
  while (!isdigit(ch))
    _f |= (ch == '-'), ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = _f ? -x : x;
}
inline void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}
int n, m, k;
int main() {
  read(n), read(m), read(k);
  For(x, 0, n) For(y, 0, m) {
    if ((n - x) * y + x * (m - y) == k) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}
Problem p03592 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int n, m, k, i, j, b;
  bool flag = false;
  cin >> n >> m >> k;
  for (i = 0; i <= n; i) {
    for (j = 0; j <= m; j++) {
      b = (m - j) * i + (n - i) * j;
      if (b == k) {
        cout << "Yes" << endl;
        flag = true;
        break;
      }
    }
    if (flag) {
      break;
    }
  }
  if (!flag) {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main(void) {
  int n, m, k, i, j, b;
  bool flag = false;
  cin >> n >> m >> k;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) {
      b = (m - j) * i + (n - i) * j;
      if (b == k) {
        cout << "Yes" << endl;
        flag = true;
        break;
      }
    }
    if (flag) {
      break;
    }
  }
  if (!flag) {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03592 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll nn = k / n;
  ll mm = k / m;
  rep(i, nn + 1) {
    ll cu = k - i * n;
    if (cu % (m - i * 2) == 0 && cu % (m - i * 2) <= n) {
      COUT("Yes");
      return 0;
    }
  }
  rep(i, mm + 1) {
    ll cu = k - i * m;
    if (cu % (n - i * 2) == 0 && cu % (n - i * 2) <= m) {
      COUT("Yes");
      return 0;
    }
  }
  COUT("No");
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i * (m - j) + j * (n - i) == k) {
        COUT("Yes");
        return 0;
      }
    }
  }
  COUT("No");
}
Problem p03592 (C++)

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

using namespace std;

int n, m, k;
bool ok;
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i <= n; i++) {
    // i * m + (n - i) * j = k;
    int tmp = k - i * m;
    if (tmp < 0)
      continue;
    if (tmp == 0) {
      ok = true;
      break;
    }
    if (tmp % ((n - 2 * i)))
      continue;
    int q = tmp / (n - 2 * i);
    if (q < 0 || q > m)
      continue;
    ok = true;
    break;
  }
  if (ok)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

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

using namespace std;

int n, m, k;
bool ok;
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i <= n; i++) {
    // i * m + (n - i) * j = k;
    int tmp = k - i * m;
    if (tmp < 0)
      continue;
    if (tmp == 0) {
      ok = true;
      break;
    }
    if (n - 2 * i == 0)
      continue;
    if (tmp % ((n - 2 * i)))
      continue;
    int q = tmp / (n - 2 * i);
    if (q < 0 || q > m)
      continue;
    ok = true;
    break;
  }
  if (ok)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
Problem p03592 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for (int(i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  if (K % N == 0 || K % M == 0 || K % (N + M) == 0 || K % (abs(N - M)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for (int(i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  bool ok = false;
  rep(n, N + 1) rep(m, M + 1) ok |= (K == (N - n) * m + (M - m) * n);
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03592 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int n, m, k, i, j;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (i = 0; i <= n; i++)
    for (j = 0; j <= m; j++)
      if ((n - i) * j + (m - j) * i == k)
        return puts("Yes");
  return puts("No");
}

Fixed submission:
#include <cstdio>
int n, m, k, i, j;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (i = 0; i <= n; i++)
    for (j = 0; j <= m; j++)
      if ((n - i) * j + (m - j) * i == k)
        return puts("Yes"), 0;
  puts("No");
}
Problem p03592 (C++)

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

#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(), x.end()

int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m, k;
  cin >> n >> m >> k;

  int ans = (k == 0 || n * m == k);

  for (int i = 0; i <= n; ++i) {
    int v = i * m;
    if (v < k)
      continue;

    int d = v - k;

    ans |= (d % i == 0);
  }

  string w[] = {"No", "Yes"};
  cout << w[ans];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(), x.end()

int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m, k;
  cin >> n >> m >> k;

  int ans = (k == 0 || n * m == k);

  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      int x = i * m - i * j + (n - i) * j;
      ans |= (x == k);
    }
  }

  string w[] = {"No", "Yes"};
  cout << w[ans];
}
Problem p03593 (C++)

Buggy submission (status: Runtime Error):
#define __USE_MINGW_ANSI_STDIO 0
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define PI 4.0 * atan(1.0)
#define epsilon 0.000000001
#define INF 1000000000000000000
#define MOD 1000000007

int rows, cols, freq[26], groups[5], filled = 0;
string s;

int main() {
  // freopen("roboherd.in", "r", stdin); freopen("roboherd.out", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(18);
  cin >> rows >> cols;
  getline(cin, s);
  for (int i = 0; i < rows; i++) {
    string s;
    getline(cin, s);
    for (int j = 0; j < cols; j++)
      freq[s[i] - 'a']++;
  }
  for (int i = 1; i <= rows; i++)
    for (int j = 1; j <= cols; j++) {
      if (i > (rows + 1) / 2 || j > (cols + 1) / 2)
        continue;
      int temp = 1;
      if (i != (rows + 1) / 2 || rows % 2 == 0)
        temp++;
      if (j != (cols + 1) / 2 || cols % 2 == 0)
        temp++;
      if (temp == 3)
        temp++;
      groups[temp]++;
    }
  sort(freq, freq + 26);
  for (int i = 25; i > -1; i--)
    for (int j = 4; j > 0; j--) {
      while (freq[i] >= j && groups[j] > 0) {
        freq[i] -= j;
        groups[j]--;
        filled += j;
      }
    }
  if (filled == rows * cols)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Fixed submission:
#define __USE_MINGW_ANSI_STDIO 0
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define PI 4.0 * atan(1.0)
#define epsilon 0.000000001
#define INF 1000000000000000000
#define MOD 1000000007

int rows, cols, freq[26], groups[5], filled = 0;
string s;

int main() {
  // freopen("roboherd.in", "r", stdin); freopen("roboherd.out", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(18);
  cin >> rows >> cols;
  getline(cin, s);
  for (int i = 0; i < rows; i++) {
    string s;
    getline(cin, s);
    for (int j = 0; j < cols; j++)
      freq[s[j] - 'a']++;
  }
  for (int i = 1; i <= rows; i++)
    for (int j = 1; j <= cols; j++) {
      if (i > (rows + 1) / 2 || j > (cols + 1) / 2)
        continue;
      int temp = 1;
      if (i != (rows + 1) / 2 || rows % 2 == 0)
        temp++;
      if (j != (cols + 1) / 2 || cols % 2 == 0)
        temp++;
      if (temp == 3)
        temp++;
      groups[temp]++;
    }
  sort(freq, freq + 26);
  for (int i = 25; i > -1; i--)
    for (int j = 4; j > 0; j--) {
      while (freq[i] >= j && groups[j] > 0) {
        freq[i] -= j;
        groups[j]--;
        filled += j;
      }
    }
  if (filled == rows * cols)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
Problem p03593 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h, w;
  cin >> h >> w;
  lvector alph(26, 0);
  string s;
  rep(i, h) {
    cin >> s;
    rep(j, w) alph[s[j] - 'a']++;
  }
  ll g1 = (h % 2) * (w % 2), g2 = (h % 2) * (w / 2) + (w % 2) * (h / 2),
     g4 = (h / 2) * (w / 2);
  while (g1 > 0)
    rep(i, 26) if (g1 > 0 && alph[i] % 2 == 1) {
      alph[i] -= 1;
      g1--;
    }
  while (g2 > 0)
    rep(i, 26) if (g2 > 0 && alph[i] % 4 == 2) {
      alph[i] -= 2;
      g2--;
    }
  while (g4 > 0)
    rep(i, 26) if (g4 > 0 && alph[i] > 0 && alph[i] % 4 == 0) {
      alph[i] -= 4;
      g4--;
    }
  puts((accumulate(ALL(alph), 0) == 0) ? "Yes" : "No");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h, w;
  cin >> h >> w;
  lvector alph(26, 0);
  string s;
  rep(i, h) {
    cin >> s;
    rep(j, w) alph[s[j] - 'a']++;
  }
  ll g1 = (h % 2) * (w % 2), g2 = (h % 2) * (w / 2) + (w % 2) * (h / 2),
     g4 = (h / 2) * (w / 2);
  rep(i, 26) if (g1 > 0 && alph[i] % 2 == 1) {
    alph[i] -= 1;
    g1--;
  }
  rep(i, 26) if (g2 > 0 && alph[i] % 4 == 2) {
    alph[i] -= 2;
    g2--;
  }
  g4 += g2 / 2;
  rep(i, 26) if (g4 > 0 && alph[i] > 0 && alph[i] % 4 == 0) {
    g4 -= alph[i] / 4;
    alph[i] = 0;
  }
  puts((accumulate(ALL(alph), 0) == 0) ? "Yes" : "No");
  return 0;
}
Problem p03593 (C++)

Buggy submission (status: Runtime Error):
// ayy
// ' lamo
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld; // CARE
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
const ld eps = 1e-8;
const int inf = 1e9 + 99;
const ll linf = 1e18 + 99;
const int P = 1e9 + 7;

void fail() {
  cout << "No" << endl;
  exit(0);
}

int32_t main() {
  int n, m;
  cin >> n >> m;
  map<char, int> mm;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++)
      mm[s[j]]++;
  }

  static int ct[4];
  for (const auto &P : mm)
    ++ct[P.se];
  if (ct[1] + ct[3] > 1)
    fail();
  if (n % 2 == 1 && m % 2 == 1)
    assert(ct[1] + ct[3] == 1);
  else
    assert(ct[1] + ct[3] == 0);

  if (n % 2 == 1 && m % 2 == 1 && ct[3] == 1)
    ++ct[2], --ct[3];
  else
    ++ct[0], --ct[1];

  int fr = 0;
  if (n % 2)
    fr += m / 2;
  if (m % 2)
    fr += n / 2;
  if (ct[2] > fr)
    fail();

  cout << "Yes" << endl;
}


Fixed submission:
// ayy
// ' lamo
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld; // CARE
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
const ld eps = 1e-8;
const int inf = 1e9 + 99;
const ll linf = 1e18 + 99;
const int P = 1e9 + 7;

void fail() {
  cout << "No" << endl;
  exit(0);
}

int32_t main() {
  int n, m;
  cin >> n >> m;
  map<char, int> mm;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++)
      mm[s[j]]++;
  }

  static int ct[4];
  for (const auto &P : mm)
    ++ct[P.se % 4];
  if (ct[1] + ct[3] > 1)
    fail();
  if (n % 2 == 1 && m % 2 == 1)
    assert(ct[1] + ct[3] == 1);
  else
    assert(ct[1] + ct[3] == 0);

  if (n % 2 == 1 && m % 2 == 1 && ct[3] == 1)
    ++ct[2], --ct[3];
  else
    ++ct[0], --ct[1];

  int fr = 0;
  if (n % 2)
    fr += m / 2;
  if (m % 2)
    fr += n / 2;
  if (ct[2] > fr)
    fail();

  cout << "Yes" << endl;
}
Problem p03593 (C++)

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

int H, W;
string t[100];
map<char, int> mp;

bool solve() {
  if (H % 2 == 0 && W % 2 == 0) {
    for (char ch = 'a'; ch <= 'z'; ch++) {
      if (mp[ch] % 4 != 0) {
        return false;
      }
    }
    return true;
  }
  /*

   ooooo
   ooooo
   ooooo

   */
  int tmp[4] = {};
  for (char ch = 'a'; ch <= 'z'; ch++) {
    tmp[mp[ch] % 4]++;
  }

  if (H % 2 == 1 && W % 2 == 1) {
    assert(0);
    if (tmp[1] + tmp[3] > 1)
      return false;
    if (tmp[2] + tmp[3] > H / 2 + W / 2)
      return false;
    return true;
  }

  if (H % 2 == 1 && W % 2 == 0) {
    if (tmp[1] + tmp[3] > 0)
      return false;
    if (tmp[2] > W / 2)
      return false;
    return true;
  }
  if (H % 2 == 0 && W % 2 == 1) {

    if (tmp[1] + tmp[3] > 0)
      return false;
    if (tmp[2] > H / 2)
      return false;
    return true;
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> t[i];
    for (int j = 0; j < W; j++) {
      mp[t[i][j]]++;
    }
  }
  if (solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

int H, W;
string t[100];
map<char, int> mp;

bool solve() {
  if (H % 2 == 0 && W % 2 == 0) {
    for (char ch = 'a'; ch <= 'z'; ch++) {
      if (mp[ch] % 4 != 0) {
        return false;
      }
    }
    return true;
  }
  /*

   ooooo
   ooooo
   ooooo

   */
  int tmp[4] = {};
  for (char ch = 'a'; ch <= 'z'; ch++) {
    tmp[mp[ch] % 4]++;
  }

  if (H % 2 == 1 && W % 2 == 1) {

    if (tmp[1] + tmp[3] > 1)
      return false;
    if (tmp[2] + tmp[3] > H / 2 + W / 2)
      return false;
    return true;
  }

  if (H % 2 == 1 && W % 2 == 0) {
    if (tmp[1] + tmp[3] > 0)
      return false;
    if (tmp[2] > W / 2)
      return false;
    return true;
  }
  if (H % 2 == 0 && W % 2 == 1) {

    if (tmp[1] + tmp[3] > 0)
      return false;
    if (tmp[2] > H / 2)
      return false;
    return true;
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> t[i];
    for (int j = 0; j < W; j++) {
      mp[t[i][j]]++;
    }
  }
  if (solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03593 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
  int h, w;
  cin >> h >> w;
  int cnt[26] = {};
  for (int i = 0; i < h * w; i++) {
    char c;
    cin >> c;
    cnt[c - 'a']++;
  }
  bool ok = true;
  for (int i = 0; i < (h / 2) * (w / 2); i++) {
    for (int j = 0; j < 26; j++) {
      if (cnt[j] >= 4) {
        cnt[j] -= 4;
        break;
      }
      if (j == 25) {
        ok = false;
        i = h;
      }
    }
  }
  if (h % 2 == 1) {
    for (int i = 0; i < w / 2; i++) {
      for (int j = 0; j < 26; j++) {
        if (cnt[j] >= 2) {
          cnt[j] -= 2;
          break;
        }
        if (j == 25) {
          ok = false;
          i = w;
        }
      }
    }
  }
  if (w % 2 == 1) {
    for (int i = 0; i < h / 2; i++) {
      for (int j = 0; j < 26; j++) {
        if (cnt[j] >= 2) {
          cnt[j] -= 2;
          break;
        }
        if (j == 25) {
          ok = false;
          i = h;
        }
      }
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
  int h, w;
  cin >> h >> w;
  int cnt[26] = {};
  for (int i = 0; i < h * w; i++) {
    char c;
    cin >> c;
    cnt[c - 'a']++;
  }
  bool ok = true;
  for (int i = 0; i < (h / 2) * (w / 2); i++) {
    for (int j = 0; j < 26; j++) {
      if (cnt[j] >= 4) {
        cnt[j] -= 4;
        break;
      }
      if (j == 25) {
        ok = false;
        i = h * w;
      }
    }
  }
  if (h % 2 == 1) {
    for (int i = 0; i < w / 2; i++) {
      for (int j = 0; j < 26; j++) {
        if (cnt[j] >= 2) {
          cnt[j] -= 2;
          break;
        }
        if (j == 25) {
          ok = false;
          i = w;
        }
      }
    }
  }
  if (w % 2 == 1) {
    for (int i = 0; i < h / 2; i++) {
      for (int j = 0; j < 26; j++) {
        if (cnt[j] >= 2) {
          cnt[j] -= 2;
          break;
        }
        if (j == 25) {
          ok = false;
          i = h;
        }
      }
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03593 (C++)

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

const int N = 100;

int n, m, par[N * N], sz[N * N], cnt[26], need[5];

int find(int u) {
  if (par[u] != u) {
    par[u] = find(par[u]);
  }
  return par[u];
}

void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    sz[a] += sz[b];
    par[b] = a;
  }
}

int get_id(int a, int b) { return a * m + b; }

int main() {
#ifdef LOCAL_JUDGE
  freopen("C.in", "r", stdin);
#endif
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0; i < n * m; ++i) {
      par[i] = i, sz[i] = 1;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        merge(get_id(i, j), get_id(i, m - 1 - j));
        merge(get_id(i, j), get_id(n - 1 - i, j));
      }
    }
    memset(need, 0, sizeof(need));
    for (int i = 0; i < n * m; ++i) {
      if (par[i] == i) {
        need[sz[i]]++;
      }
    }
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; ++i) {
      static char buf[N + 1];
      scanf("%s", buf);
      for (int j = 0; j < m; ++j) {
        cnt[buf[j] - 'a']++;
      }
    }
    assert(cnt[3] == 0);
    bool ok = true;
    for (int s = 4; s >= 1 && ok; --s) {
      int left = need[s];
      for (int i = 0; i < 26; ++i) {
        while (left && cnt[i] >= s) {
          left--;
          cnt[i] -= s;
        }
      }
      ok &= left == 0;
    }
    puts(ok ? "Yes" : "No");
  }
}

Fixed submission:
#include <cassert>
#include <cstdio>
#include <cstring>

const int N = 100;

int n, m, par[N * N], sz[N * N], cnt[26], need[5];

int find(int u) {
  if (par[u] != u) {
    par[u] = find(par[u]);
  }
  return par[u];
}

void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    sz[a] += sz[b];
    par[b] = a;
  }
}

int get_id(int a, int b) { return a * m + b; }

int main() {
#ifdef LOCAL_JUDGE
  freopen("C.in", "r", stdin);
#endif
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0; i < n * m; ++i) {
      par[i] = i, sz[i] = 1;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        merge(get_id(i, j), get_id(i, m - 1 - j));
        merge(get_id(i, j), get_id(n - 1 - i, j));
      }
    }
    memset(need, 0, sizeof(need));
    for (int i = 0; i < n * m; ++i) {
      if (par[i] == i) {
        need[sz[i]]++;
      }
    }
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; ++i) {
      static char buf[N + 1];
      scanf("%s", buf);
      for (int j = 0; j < m; ++j) {
        cnt[buf[j] - 'a']++;
      }
    }
    bool ok = true;
    for (int s = 4; s >= 1 && ok; --s) {
      int left = need[s];
      for (int i = 0; i < 26; ++i) {
        while (left && cnt[i] >= s) {
          left--;
          cnt[i] -= s;
        }
      }
      ok &= left == 0;
    }
    puts(ok ? "Yes" : "No");
  }
}
Problem p03593 (C++)

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

using namespace std;

void die() {
  printf("No\n");
  exit(0);
}

char str[1010];
int K[33];
int n, m;

int main() {
  int i, j, s, d;

  s = d = 0;

  scanf("%d%d", &n, &m);

  for (i = 0; i < n; i++) {
    scanf("%s", str);
    for (j = 0; j < m; j++) {
      K[str[i] - 'a']++;
    }
  }

  for (i = 0; i < 26; i++) {
    if (K[i] & 1)
      s++;
  }

  if (s > 1)
    die();
  if ((n * m & 1) && s != 1)
    die();

  if (n & 1)
    d += m / 2;
  if (m & 1)
    d += n / 2;

  for (i = 0; i < 26; i++) {
    if (K[i] % 4 == 2)
      d--;
  }

  if (d < 0)
    die();

  printf("Yes\n");

  return 0;
}

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

using namespace std;

void die() {
  printf("No\n");
  exit(0);
}

char str[1010];
int K[33];
int n, m;

int main() {
  int i, j, s, d;

  s = d = 0;

  scanf("%d%d", &n, &m);

  for (i = 0; i < n; i++) {
    scanf("%s", str);
    for (j = 0; j < m; j++) {
      K[str[j] - 'a']++;
    }
  }

  for (i = 0; i < 26; i++) {
    if (K[i] & 1)
      s++;
  }

  if (s > 1)
    die();
  if ((n * m & 1) && s != 1)
    die();

  if (n & 1)
    d += m / 2;
  if (m & 1)
    d += n / 2;

  for (i = 0; i < 26; i++) {
    if (K[i] % 4 == 2)
      d--;
  }

  if (d < 0)
    die();

  printf("Yes\n");

  return 0;
}
Problem p03594 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// This code is written by Itst
using namespace std;

const char mod[] = "YGBR";
int N, M, K;
char qbxf[2007][2007], ans[1007][1007];

int main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  // freopen("out","w",stdout);
#endif
  cin >> N >> M >> K;
  for (int i = -1000; i <= 1000; ++i)
    for (int j = -1000; j <= 1000; ++j)
      qbxf[i + 1000][j + 1000] =
          mod[((i + 1000) / K & 1) * 2 + ((j + 1000) / K & 1)];
  for (int i = -1000; i <= 1000; ++i)
    for (int j = -1000; j <= 1000; ++j)
      if ((i + j) >= 0 && (i - j) >= 0 && !((i + j) & 1))
        ans[(i + j) / 2][(i - j) / 2] = qbxf[i + 1000][j + 1000];
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j)
      putchar(ans[i][j]);
    putchar('\n');
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// This code is written by Itst
using namespace std;

const char mod[] = "YGBR";
int N, M, K;
char qbxf[2007][2007], ans[1007][1007];

int main() {
  cin >> N >> M >> K;
  for (int i = -1000; i <= 1000; ++i)
    for (int j = -1000; j <= 1000; ++j)
      qbxf[i + 1000][j + 1000] =
          mod[((i + 1000) / K & 1) * 2 + ((j + 1000) / K & 1)];
  for (int i = -1000; i <= 1000; ++i)
    for (int j = -1000; j <= 1000; ++j)
      if ((i + j) >= 0 && (i - j) >= 0 && !((i + j) & 1))
        ans[(i + j) / 2][(i - j) / 2] = qbxf[i + 1000][j + 1000];
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j)
      putchar(ans[i][j]);
    putchar('\n');
  }
  return 0;
}
Problem p03594 (C++)

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

using namespace std;

typedef long long LL;

int n, m, k, now, dq, d;
int f[1005][1005];

int main()

{
  scanf("%d%d%d", &n, &m, &d);
  //(x,y)->(x-y,x+y)
  now = 1;
  for (int i = -m + m; i <= n + m; i += d) {
    for (int j = 0; j <= n + m; j += d) {
      for (int p = i; p < i + d; ++p)
        for (int q = j; q < j + d; ++q)
          f[p][q] = now;
      now ^= 1;
    }
    now ^= 2;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dq = f[i - j + m][i + j] + 1;
      if (dq == 1)
        cout << "R";
      else if (dq == 2)
        cout << "Y";
      else if (dq == 3)
        cout << "G";
      else if (dq == 4)
        cout << "B";
    }
    cout << endl;
  }

  return 0;
}

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

using namespace std;

typedef long long LL;

int n, m, k, now, dq, d;
int f[5005][5005];

int main()

{
  scanf("%d%d%d", &n, &m, &d);
  //(x,y)->(x-y,x+y)
  now = 1;
  for (int i = -m + m; i <= n + m; i += d) {
    for (int j = 0; j <= n + m; j += d) {
      for (int p = i; p < i + d; ++p)
        for (int q = j; q < j + d; ++q)
          f[p][q] = now;
      now ^= 1;
    }
    now ^= 2;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dq = f[i - j + m][i + j] + 1;
      if (dq == 1)
        cout << "R";
      else if (dq == 2)
        cout << "Y";
      else if (dq == 3)
        cout << "G";
      else if (dq == 4)
        cout << "B";
    }
    cout << endl;
  }

  return 0;
}
Problem p03594 (C++)

Buggy submission (status: Runtime Error):
// 基本テンプレート

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long int

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W, D;
string pat = "RYGB";

signed main() {
  cin >> H >> W >> D;
  rep(i, 0, H) {
    rep(j, 0, W) {
      int p = D - 1;
      int ni = i + j + W, nj = i - j + W;
      int c = ((ni / p) % 2) * 2 + ((nj / p) % 2);
      // printf("ni = %lld, nj = %lld, c = %lld\n", ni, nj, c);
      cout << pat[c];
    }
    cout << endl;
  }
  return 0;
}

Fixed submission:
// 基本テンプレート

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long int

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W, D;
string pat = "RYGB";

signed main() {
  cin >> H >> W >> D;
  rep(i, 0, H) {
    rep(j, 0, W) {
      int p = D;
      int ni = i + j + W, nj = i - j + W;
      int c = ((ni / p) % 2) * 2 + ((nj / p) % 2);
      // printf("ni = %lld, nj = %lld, c = %lld\n", ni, nj, c);
      cout << pat[c];
    }
    cout << endl;
  }
  return 0;
}
Problem p03594 (C++)

Buggy submission (status: Time Limit Exceeded):
/**************************
 * Author : Leo101
 * Problem : Four Coloring
 * Tags : 贪心，找规律
 **************************/
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define _FILE(s)                                                               \
  freopen(#s ".in", "r", stdin);                                               \
  freopen(#s ".out", "w", stdout)
#define gi get_int()
int get_int() {
  int x = 0, y = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    y = -1, ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return x * y;
}

char ch[4] = {'R', 'G', 'B', 'Y'};

int main() {
  _FILE(code);

  int n = gi, m = gi, k = gi;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x = (i + j + m) / k % 2, y = (i - j + m) / k % 2;
      printf("%c", ch[x * 2 + y]);
    }
    printf("\n");
  }

  return 0;
}


Fixed submission:
/**************************
 * Author : Leo101
 * Problem : Four Coloring
 * Tags : 贪心，找规律
 **************************/
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define _FILE(s)                                                               \
  freopen(#s ".in", "r", stdin);                                               \
  freopen(#s ".out", "w", stdout)
#define gi get_int()
int get_int() {
  int x = 0, y = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    y = -1, ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return x * y;
}

char ch[4] = {'R', 'G', 'B', 'Y'};

int main() {
  int n = gi, m = gi, k = gi;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x = (i + j + m) / k % 2, y = (i - j + m) / k % 2;
      printf("%c", ch[x * 2 + y]);
    }
    printf("\n");
  }

  return 0;
}
Problem p03594 (C++)

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

using namespace std;

string str[500];

int h, w, d;
void shape(int y, int x, char c) {
  for (int i = 0; i < d; i++) {
    int sx = x + i;
    int hb = min(i, d - i - 1);
    for (int j = -hb; j <= hb; j++) {
      int sy = y + j;
      if (0 <= sx && sx < w && 0 <= sy && sy < h) {
        str[sy][sx] = c;
      }
    }
  }
}

int main() {
  cin >> h >> w >> d;
  for (int i = 0; i < h; i++) {
    str[i] = string(' ', w);
  }
  if (d % 2) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i % 2 == 0 && j % 2 == 0) {
          str[i][j] = 'R';
        }
        if (i % 2 == 0 && j % 2 == 1) {
          str[i][j] = 'Y';
        }
        if (i % 2 == 1 && j % 2 == 0) {
          str[i][j] = 'G';
        }
        if (i % 2 == 1 && j % 2 == 1) {
          str[i][j] = 'B';
        }
      }
    }
  } else {
    for (int i = 0;; i++) {
      int sy = -d + i * d;
      if (sy > h + d)
        break;
      for (int j = 0;; j++) {
        int sx = -d * 2 + j * d * 2;
        if (i % 2)
          sx -= d;
        if (sx > w)
          break;
        shape(sy, sx, 'R');
        shape(sy, sx + d, 'Y');
        shape(sy - d / 2, sx + d / 2, 'G');
        shape(sy + d / 2, sx + d / 2, 'B');
      }
    }
  }
  for (int i = 0; i < h; i++) {
    cout << str[i] << endl;
  }
}

Fixed submission:
#include <iostream>

using namespace std;

string str[500];

int h, w, d;
void shape(int y, int x, char c) {
  for (int i = 0; i < d; i++) {
    int sx = x + i;
    int hb = min(i, d - i - 1);
    for (int j = -hb; j <= hb; j++) {
      int sy = y + j;
      if (0 <= sx && sx < w && 0 <= sy && sy < h) {
        str[sy][sx] = c;
      }
    }
  }
}

int main() {
  cin >> h >> w >> d;
  for (int i = 0; i < h; i++) {
    str[i] = string(w, ' ');
  }
  if (d % 2) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i % 2 == 0 && j % 2 == 0) {
          str[i][j] = 'R';
        }
        if (i % 2 == 0 && j % 2 == 1) {
          str[i][j] = 'Y';
        }
        if (i % 2 == 1 && j % 2 == 0) {
          str[i][j] = 'G';
        }
        if (i % 2 == 1 && j % 2 == 1) {
          str[i][j] = 'B';
        }
      }
    }
  } else {
    for (int i = 0;; i++) {
      int sy = -d + i * d;
      if (sy > h + d)
        break;
      for (int j = 0;; j++) {
        int sx = -d * 2 + j * d * 2;
        if (i % 2)
          sx -= d;
        if (sx > w)
          break;
        shape(sy, sx, 'R');
        shape(sy, sx + d, 'Y');
        shape(sy - d / 2, sx + d / 2, 'G');
        shape(sy + d / 2, sx + d / 2, 'B');
      }
    }
  }
  for (int i = 0; i < h; i++) {
    cout << str[i] << endl;
  }
}
Problem p03594 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
static const int MAXN = 502;

int h, w, d;
int s[MAXN][MAXN];
const char *colour = "GYRB";

inline void paint(int colour, int r, int c) {
  for (int i = 0; i < d / 2; ++i)
    for (int j = -i; j <= i; ++j)
      if (r + i >= 0 && r + i < h && c + j >= 0 && c + j < w)
        s[r + i][c + j] = colour;
  for (int i = (d - 1) / 2; i >= 0; --i)
    for (int j = -i; j <= i; ++j)
      if (r + d - 1 - i >= 0 && r + d - 1 - i < h && c + j >= 0 && c + j < w)
        s[r + d - 1 - i][c + j] = colour;
}

int main() {
  scanf("%d%d%d", &h, &w, &d);

  int r, c, p;
  for (r = 0, c = -1000, p = 0; r < 1000;
       r += d / 2, c += (d + 1) / 2, p ^= 1) {
    int rr = r, cc = c, q = 0;
    for (; cc < 1000; rr -= (d + 1) / 2, cc += d / 2, q ^= 1)
      paint((p << 1) | q, rr, cc);
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j)
      putchar(colour[s[i][j]]); //, putchar(' ');
    putchar('\n');
  }

  return 0;
}


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

int h, w, d;
int s[MAXN][MAXN];
const char *colour = "GYRB";

inline void paint(int colour, int r, int c) {
  for (int i = 0; i < d / 2; ++i)
    for (int j = -i; j <= i; ++j)
      if (r + i >= 0 && r + i < h && c + j >= 0 && c + j < w)
        s[r + i][c + j] = colour;
  for (int i = (d - 1) / 2; i >= 0; --i)
    for (int j = -i; j <= i; ++j)
      if (r + d - 1 - i >= 0 && r + d - 1 - i < h && c + j >= 0 && c + j < w)
        s[r + d - 1 - i][c + j] = colour;
}

int main() {
  scanf("%d%d%d", &h, &w, &d);

  int r, c, p;
  if (d == 1) {
    for (r = 0; r < h; ++r)
      for (c = 0; c < w; ++c)
        paint((r & 1) << 1 | (c & 1), r, c);
  } else {
    for (r = 0, c = -1000, p = 0; r < 1000;
         r += d / 2, c += (d + 1) / 2, p ^= 1) {
      int rr = r, cc = c, q = 0;
      for (; cc < 1000; rr -= (d + 1) / 2, cc += d / 2, q ^= 1)
        paint((p << 1) | q, rr, cc);
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j)
      putchar(colour[s[i][j]]); //, putchar(' ');
    putchar('\n');
  }

  return 0;
}
Problem p03594 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int h, w, d;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int col[3001][3001];
int ng[501][501];
int ans[501][501];

int main(void) {
  scanf("%d%d%d", &h, &w, &d);
  memset(col, -1, sizeof(col));
  for (int i = 0; i < 2000; i += d * 2) {
    for (int j = 0; j < 2000; j += d * 2) {
      for (int k = 0; k < d; k++) {
        for (int l = 0; l < d; l++) {
          col[i + k][j + l] = 0;
          col[i + k][j + d + l] = 1;
          col[i + d + k][j + d + l] = 2;
          col[i + d + k][j + l] = 3;
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans[i][j] = col[500 + i + j][500 + i - j];
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ans[i][j] == 0)
        printf("R");
      if (ans[i][j] == 1)
        printf("G");
      if (ans[i][j] == 2)
        printf("B");
      if (ans[i][j] == 3)
        printf("Y");
    }
    printf("\n");
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int h, w, d;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int col[4001][4001];
int ng[501][501];
int ans[501][501];

int main(void) {
  scanf("%d%d%d", &h, &w, &d);
  memset(col, -1, sizeof(col));
  for (int i = 0; i < 2000; i += d * 2) {
    for (int j = 0; j < 2000; j += d * 2) {
      for (int k = 0; k < d; k++) {
        for (int l = 0; l < d; l++) {
          col[i + k][j + l] = 0;
          col[i + k][j + d + l] = 1;
          col[i + d + k][j + d + l] = 2;
          col[i + d + k][j + l] = 3;
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans[i][j] = col[500 + i + j][500 + i - j];
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ans[i][j] == 0)
        printf("R");
      if (ans[i][j] == 1)
        printf("G");
      if (ans[i][j] == 2)
        printf("B");
      if (ans[i][j] == 3)
        printf("Y");
    }
    printf("\n");
  }
  return 0;
}
Problem p03594 (C++)

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

using namespace std;

int g1[4][4] = {
    {0, 1, 2, 3},
    {0, 1, 2, 3},
    {2, 3, 0, 1},
    {2, 3, 0, 1},
};

int main() {
  int h, w, d;
  cin >> h >> w >> d;

  vector<string> ans(h, string(w, 0));

  string x = "RYGB";

  if (d % 4 == 0) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int a = i + j;
        int b = (i + j) / d % 2;
        int c = (i - j + d * 1000) / d % 2;
        ans[i][j] = x[(a + b + c) % 4];
      }
    }
  } else if (d % 4 == 2) {
    abort();
  } else {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        ans[i][j] = x[i % 2 + j % 2 * 2];
      }
    }
  }
  for (string s : ans)
    cout << s << endl;
}

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

using namespace std;

int g1[4][4] = {
    {0, 1, 2, 3},
    {0, 1, 2, 3},
    {2, 3, 0, 1},
    {2, 3, 0, 1},
};

int main() {
  int h, w, d;
  cin >> h >> w >> d;

  vector<string> ans(h, string(w, 0));

  string x = "RYGB";

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int b = (i + j) / d % 2;
      int c = (i - j + d * 1000) / d % 2;
      ans[i][j] = x[(b + c * 2) % 4];
    }
  }
  for (string s : ans)
    cout << s << endl;
}