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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int a[10001];
    int flag, flag1, flag2;
    flag = flag1 = flag2 = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
      if (a[i] % 4 == 0)
        flag++;
      else if (a[i] % 2 == 0)
        flag1++;
      else
        flag2++;
    }
    if (flag1)
      flag2++;
    if (flag2 <= flag + 1)
      printf("Yes\n");
    else
      printf("No\n");
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int a[500001];
    int flag, flag1, flag2;
    flag = flag1 = flag2 = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
      if (a[i] % 4 == 0)
        flag++;
      else if (a[i] % 2 == 0)
        flag1++;
      else
        flag2++;
    }
    if (flag1)
      flag2++;
    if (flag2 <= flag + 1)
      printf("Yes\n");
    else
      printf("No\n");
  }
}
Problem p03639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX = 505;
int n, a[MAX], c[3];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    if (a[i] % 2)
      c[0]++;
    else if (a[i] % 4)
      c[1]++;
    else
      c[2]++;
  }
  if ((n - max(c[1], 1) + 1) / 2 <= c[2])
    printf("Yes\n");
  else
    printf("No\n");
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX = 500005;
int n, a[MAX], c[3];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    if (a[i] % 2)
      c[0]++;
    else if (a[i] % 4)
      c[1]++;
    else
      c[2]++;
  }
  if ((n - max(c[1], 1) + 1) / 2 <= c[2])
    printf("Yes\n");
  else
    printf("No\n");
}
Problem p03639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define For(i, j, k) for (int i = j; i <= k; ++i)
#define Forr(i, j, k) for (int i = j; i >= k; --i)
using namespace std;

inline int read() {
  int x = 0, p = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      p = -1;
    c = getchar();
  }
  while (isdigit(c))
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x *= p;
}

template <typename T> inline bool chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}

inline void File() {
  freopen("ARC080C.in", "r", stdin);
  freopen("ARC080C.out", "w", stdout);
}

const int N = 1e5 + 10, M = 30 + 10;
int n, A[N], F[M], tmp[N];

int main() {
  File();
  //	For(i, 0, 29) F[i] = 1 << i;
  n = read();
  For(i, 1, n) {
    int x = read();
    //		Forr(j, 29, 1) if(!(x % F[j])) x /= F[j], A[i] += j;
    while (x % 2 == 0)
      x /= 2, ++A[i];
  }
  sort(A + 1, A + 1 + n);

  int cnt = 0;
  For(i, 1, n + 1 >> 1) {
    tmp[++cnt] = A[i], tmp[++cnt] = A[n + 1 - i];
    if (i == n + 1 - i)
      --cnt;
  }

  int res = 0;
  For(i, 1, n - 1) if (tmp[i] + tmp[i + 1] < 2)++ res;
  printf("%s\n", res ? "No" : "Yes");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define For(i, j, k) for (int i = j; i <= k; ++i)
#define Forr(i, j, k) for (int i = j; i >= k; --i)
using namespace std;

inline int read() {
  int x = 0, p = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      p = -1;
    c = getchar();
  }
  while (isdigit(c))
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x *= p;
}

template <typename T> inline bool chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}

inline void File() {
  freopen("ARC080C.in", "r", stdin);
  freopen("ARC080C.out", "w", stdout);
}

const int N = 1e5 + 10, M = 30 + 10;
int n, A[N], F[M], tmp[N];

int main() {
  //	For(i, 0, 29) F[i] = 1 << i;
  n = read();
  For(i, 1, n) {
    int x = read();
    //		Forr(j, 29, 1) if(!(x % F[j])) x /= F[j], A[i] += j;
    while (x % 2 == 0)
      x /= 2, ++A[i];
  }
  sort(A + 1, A + 1 + n);

  int cnt = 0;
  For(i, 1, n + 1 >> 1) {
    tmp[++cnt] = A[i], tmp[++cnt] = A[n + 1 - i];
    if (i == n + 1 - i)
      --cnt;
  }

  int res = 0;
  For(i, 1, n - 1) if (tmp[i] + tmp[i + 1] < 2)++ res;
  printf("%s\n", res ? "No" : "Yes");
  return 0;
}
Problem p03639 (C++)

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

using namespace std;
int a[10005];
int main() {
  int N;
  while (cin >> N) {
    int mo2 = 0;
    int mo1 = 0;
    int mo4 = 0;
    for (int i = 0; i < N; i++) {
      cin >> a[i];
      if (a[i] % 4 == 0) {
        mo4++;
      } else {
        if (a[i] % 2 == 0)
          mo2++;
        else
          mo1++;
      }
    }
    if (mo2 != 0) {
      mo1++;
    }
    if (mo4 >= mo1 - 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;
int a[100005];
int main() {
  int N;
  while (cin >> N) {
    int mo2 = 0;
    int mo1 = 0;
    int mo4 = 0;
    for (int i = 0; i < N; i++) {
      cin >> a[i];
      if (a[i] % 4 == 0) {
        mo4++;
      } else {
        if (a[i] % 2 == 0)
          mo2++;
        else
          mo1++;
      }
    }
    if (mo2 != 0) {
      mo1++;
    }
    if (mo4 >= mo1 - 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
Problem p03639 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
const int maxn = 50005;
const int mod = 1000007;
const double eps = 1e-3;
struct node {
  int data;
  int cnt;
  bool operator<(const node &s) const { return cnt < s.cnt; }
} a[maxn];
int main() {
  int temp, n;
  bool f = false;
  bool if1 = false;
  bool if0 = false;
  while (cin >> n) {
    int cnt0 = 0;
    int cnt2 = 0;
    f = false;
    if0 = false;
    if1 = false;
    bool exist1 = false;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i].data);
      a[i].cnt = 0;
      temp = a[i].data;
      while (temp % 2 == 0) {
        a[i].cnt++;
        temp >>= 1;
        // cout<<temp<<' '<<a[i].cnt<<endl;
        if (a[i].cnt >= 2)
          break;
      }
      if (a[i].cnt == 0) {
        cnt0++;
      }
      if (a[i].cnt == 2) {
        cnt2++;
      }
      if (a[i].cnt == 1) {
        exist1 = true;
      }
      // cout<<cnt0<<' '<<cnt2<<' '<<exist1<<endl;
    }
    // cout<<cnt0<<' '<<cnt2<<' '<<exist1<<endl;
    if ((cnt2 < cnt0 - 1) || (cnt2 == cnt0 - 1 && exist1))
      printf("No\n");
    else {
      printf("Yes\n");
    }
  }
  // system("pause");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
const int maxn = 100005;
const int mod = 1000007;
const double eps = 1e-3;
struct node {
  int data;
  int cnt;
  bool operator<(const node &s) const { return cnt < s.cnt; }
} a[maxn];
int main() {
  int temp, n;
  bool f = false;
  bool if1 = false;
  bool if0 = false;
  while (cin >> n) {
    int cnt0 = 0;
    int cnt2 = 0;
    f = false;
    if0 = false;
    if1 = false;
    bool exist1 = false;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i].data);
      a[i].cnt = 0;
      temp = a[i].data;
      while (temp % 2 == 0) {
        a[i].cnt++;
        temp >>= 1;
        // cout<<temp<<' '<<a[i].cnt<<endl;
        if (a[i].cnt >= 2)
          break;
      }
      if (a[i].cnt == 0) {
        cnt0++;
      }
      if (a[i].cnt == 2) {
        cnt2++;
      }
      if (a[i].cnt == 1) {
        exist1 = true;
      }
      // cout<<cnt0<<' '<<cnt2<<' '<<exist1<<endl;
    }
    // cout<<cnt0<<' '<<cnt2<<' '<<exist1<<endl;
    if ((cnt2 < cnt0 - 1) || (cnt2 == cnt0 - 1 && exist1))
      printf("No\n");
    else {
      printf("Yes\n");
    }
  }
  // system("pause");
  return 0;
}
Problem p03639 (C++)

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

using namespace std;

int main() {
  int arr[1111];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int a = 0;
  int b = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] % 4 == 0) {
      a++;
    } else if (arr[i] % 2 == 0) {
      b++;
    }
  }
  // cout << a << ' ' << b << endl;
  if (a >= n / 2) {
    cout << "Yes";
    return 0;
  }
  if (a * 2 + b >= n) {
    cout << "Yes";
    return 0;
  }
  cout << "No";
  return 0;
}

Fixed submission:
// che contesti bod!
#include <bits/stdc++.h>

using namespace std;

int main() {
  int arr[111111];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int a = 0;
  int b = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] % 4 == 0) {
      a++;
    } else if (arr[i] % 2 == 0) {
      b++;
    }
  }
  // cout << a << ' ' << b << endl;
  if (a >= n / 2) {
    cout << "Yes";
    return 0;
  }
  if (a * 2 + b >= n) {
    cout << "Yes";
    return 0;
  }
  cout << "No";
  return 0;
}
Problem p03639 (C++)

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

#include <bitset>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <vector>

#include <algorithm>
#include <numeric>

#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a)                                                          \
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int)(a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;

int main() {
#ifdef XCODE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  int c1 = 0, c2 = 0, c4 = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x % 4 == 0) {
      c4++;
    } else if (x % 2 == 0) {
      c2++;
    } else {
      c1++;
    }
  }
  vector<int> a(n);
  int it = 0;
  while (c1 > 0) {
    a[it++] = 1;
    c1--;
    if (it < n) {
      a[it++] = 4;
      c4--;
    }
  }
  if (c4 >= 0) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}


Fixed submission:
#include <fstream>
#include <iostream>
#include <sstream>

#include <bitset>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <vector>

#include <algorithm>
#include <numeric>

#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a)                                                          \
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int)(a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;

int main() {
#ifdef XCODE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  int c1 = 0, c2 = 0, c4 = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x % 4 == 0) {
      c4++;
    } else if (x % 2 == 0) {
      c2++;
    } else {
      c1++;
    }
  }
  vector<int> a(n);
  int it = 0;
  while (c1 > 0) {
    if (it >= n) {
      puts("No");
      return 0;
    }
    a[it++] = 1;
    c1--;
    if (it < n) {
      a[it++] = 4;
      c4--;
    }
  }
  if (c4 >= 0) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}
Problem p03639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MAXN 10005
int long n, v[MAXN], impar, mp, ok = 1;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if (v[i] % 2) {
      impar++;
    }
    if (v[i] % 4 == 0) {
      mp++;
    }
    if (v[i] % 2 == 0 && v[i] % 4) {
      ok = 0;
    }
  }
  // cout << impar << " " << mp<< endl;
  if (impar > mp + ok) {
    cout << "No\n";
  } else
    cout << "Yes\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
int long n, v[MAXN], impar, mp, ok = 1;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if (v[i] % 2) {
      impar++;
    }
    if (v[i] % 4 == 0) {
      mp++;
    }
    if (v[i] % 2 == 0 && v[i] % 4) {
      ok = 0;
    }
  }
  // cout << impar << " " << mp<< endl;
  if (impar > mp + ok) {
    cout << "No\n";
  } else
    cout << "Yes\n";
}
Problem p03639 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x % (mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool debug = false;
/*---------------------------------------------------*/

int main() {
  int n, miss = 0, tmp = 0;
  ll a[10005];
  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i] % 4 != 0) {
      miss++;
      if (a[i] % 2 == 0)
        tmp++;
    }
  }
  miss -= tmp / 2;
  int x;
  if (n % 2 == 0)
    x = n / 2;
  else
    x = n / 2 + 2;
  if (miss <= x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x % (mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool debug = false;
/*---------------------------------------------------*/

int main() {
  int n, miss = 0, tmp = 0;
  ll a[100005];
  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i] % 4 != 0) {
      miss++;
      if (a[i] % 2 == 0)
        tmp++;
    }
  }
  miss -= tmp / 2;
  int x;
  if (n % 2 == 0)
    x = n / 2;
  else
    x = n / 2 + 2;
  if (miss <= x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
int n;
int a[100005], two[100005], vis[100005], p[100005], odd = 0, four = 0;
bool f = 0;
void dfs(int cur) {
  if (f)
    return;
  if (cur == n) {
    f = 1;
    return;
  } else {
    for (int i = 0; i < n; i++) {
      if (vis[i] || two[i] + two[p[cur - 1]] < 2 && i != 0)
        continue;
      p[cur] = i;
      vis[i] = 1;
      dfs(cur + 1);
      p[cur] = 0;
      vis[i] = 0;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      two[i]++;
      a[i] /= 2;
    }
    if (two[i] == 0)
      odd++;
    if (two[i] >= 2)
      four++;
  }
  if (odd > four + 1) {
    cout << "No";
    return 0;
  }
  dfs(0);
  if (f)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
int n;
int a[100005], two[100005], vis[100005], p[100005], odd = 0, four = 0;
bool f = 0;
void dfs(int cur) {
  if (f)
    return;
  if (cur == n) {
    f = 1;
    return;
  } else {
    for (int i = 0; i < n; i++) {
      if (vis[i] || two[i] + two[p[cur - 1]] < 2 && i != 0)
        continue;
      p[cur] = i;
      vis[i] = 1;
      dfs(cur + 1);
      p[cur] = 0;
      vis[i] = 0;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      two[i]++;
      a[i] /= 2;
    }
    if (two[i] == 0)
      odd++;
    if (two[i] >= 2)
      four++;
  }
  if (odd <= four) {
    cout << "Yes";
    return 0;
  } else {
    if ((odd + four) % 2 && odd == four + 1 && odd + four == n) {
      cout << "Yes";
      return 0;
    }
    cout << "No";
    return 0;
  }
  dfs(0);
  if (f)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p03639 (C++)

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

int n, flag = 1, cnt;

int main() {
  scanf("%d", &n);
  while (n--) {
    int a;
    scanf("%d", a);
    if (!(a & 3))
      ++cnt;
    else if (a & 1)
      --cnt;
    else
      flag = 0;
  }
  if (flag + cnt >= 0)
    puts("Yes");
  else
    puts("No");
  return 0;
}


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

int n, flag = 1, cnt;

int main() {
  scanf("%d", &n);
  while (n--) {
    int a;
    scanf("%d", &a);
    if (!(a & 3))
      ++cnt;
    else if (a & 1)
      --cnt;
    else
      flag = 0;
  }
  if (flag + cnt >= 0)
    puts("Yes");
  else
    puts("No");
  return 0;
}
Problem p03639 (C++)

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

using namespace std;
typedef long long LL;
const double pi = acos(-1.0);
const double eps = 1e-7;
const LL N = 10001;

LL T, n, m, i, j, k, a[N], t, ans = 0, a1 = 0, a2 = 0, a3 = 0;

int main() {
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (!(a[i] % 4))
      a3++;
    else if (!(a[i] & 1))
      a2++;
    else
      a1++;
  }
  if (a3 >= a1 || (a3 == a1 - 1 && a2 == 0))
    printf("Yes");
  else
    printf("No");
  // system("pause");
  return 0;
}


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

using namespace std;
typedef long long LL;
const double pi = acos(-1.0);
const double eps = 1e-7;
const LL N = 100010;

LL T, n, m, i, j, k, a[N], t, ans = 0, a1 = 0, a2 = 0, a3 = 0;

int main() {
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (!(a[i] % 4))
      a3++;
    else if (!(a[i] & 1))
      a2++;
    else
      a1++;
  }
  if (a3 >= a1 || (a3 == a1 - 1 && a2 == 0))
    printf("Yes");
  else
    printf("No");
  // system("pause");
  return 0;
}
Problem p03639 (C++)

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

const int N = (int)1e5 + 5;

int n;
int a[N], b[N];

int main() {
#define TASK "test"
#ifndef ONLINE_JUDGE
  freopen(TASK ".inp", "r", stdin);
  freopen(TASK ".out", "w", stdout);
#endif
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int cnt = 0;
  int d = 0, d2 = 0, d4 = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] % 4 == 0)
      d4++;
    else if (a[i] % 2 == 0)
      d2++;
  }
  d = n - d2 - d4;
  if (d4 >= d)
    cout << "Yes";
  else if (d4 == d - 1) {
    if (d2 == 0)
      cout << "Yes";
    else
      cout << "No";
  } else
    cout << "No";
  return 0;
}

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

const int N = (int)1e5 + 5;

int n;
int a[N], b[N];

int main() {
  // #define TASK "test"
  //  #ifndef ONLINE_JUDGE
  // 	freopen(TASK".inp", "r", stdin);
  // 	freopen(TASK".out", "w", stdout);
  // #endif
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int cnt = 0;
  int d = 0, d2 = 0, d4 = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] % 4 == 0)
      d4++;
    else if (a[i] % 2 == 0)
      d2++;
  }
  d = n - d2 - d4;
  if (d4 >= d)
    cout << "Yes";
  else if (d4 == d - 1) {
    if (d2 == 0)
      cout << "Yes";
    else
      cout << "No";
  } else
    cout << "No";
  return 0;
}
Problem p03639 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#define eps 0.0000000001
#define maxn 3009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
int n, a[maxn];

int main() {
  // freopen("d:\\in.txt","r",stdin);
  scanf("%d", &n);
  int x = 0, y = 0, z = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] % 4 == 0)
      x++;
    else if (a[i] % 2 == 0)
      y++;
    else
      z++;
  }
  // printf("%d %d %d\n",x,y,z);
  if (z - x > 1)
    printf("No\n");
  else if (y && z - x == 1)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#define eps 0.0000000001
#define maxn 1000009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
int n, a[maxn];

int main() {
  // freopen("d:\\in.txt","r",stdin);
  scanf("%d", &n);
  int x = 0, y = 0, z = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] % 4 == 0)
      x++;
    else if (a[i] % 2 == 0)
      y++;
    else
      z++;
  }
  // printf("%d %d %d\n",x,y,z);
  if (z - x > 1)
    printf("No\n");
  else if (y && z - x == 1)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}
Problem p03640 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define mp make_pair
using namespace std;
int a[105][105], c[105], n, m, k;
int main() {
  cin >> n >> m;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    cin >> c[i];
  }
  int x = 0, y = 0;
  for (int i = 1; i <= k; i++) {
    for (int l = 0; l < c[i]; l++) {
      a[x][y] = i;
      y++;
      if (y == m) {
        y = 0;
        x++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i % 2 == 1) {
      for (int j = m - 1; j >= 0; j--)
        cout << a[i][j] << ' ';
    } else {
      for (int j = 0; j < m; j++)
        cout << a[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define mp make_pair
using namespace std;
int a[105][105], c[10005], n, m, k;
int main() {
  cin >> n >> m;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    cin >> c[i];
  }
  int x = 0, y = 0;
  for (int i = 1; i <= k; i++) {
    for (int l = 0; l < c[i]; l++) {
      a[x][y] = i;
      y++;
      if (y == m) {
        y = 0;
        x++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i % 2 == 1) {
      for (int j = m - 1; j >= 0; j--)
        cout << a[i][j] << ' ';
    } else {
      for (int j = 0; j < m; j++)
        cout << a[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}
Problem p03640 (C++)

Buggy submission (status: Runtime Error):
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(), a.end())
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;

int g[105][105], a[105], h, w, n;
inline void solve() {
  cin >> h >> w >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int in = 1, i = 1, j = 1; in <= n; in++) {
    int cnt = a[in];
    while (cnt--) {
      g[i][j] = in;
      j++;
      if (j > w)
        j = 1, i++;
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = (i & 1) ? 1 : w; j > 0 and j <= w; j += (i & 1) ? 1 : -1)
      cout << g[i][j] << " ";
    cout << endl;
  }
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}


Fixed submission:
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(), a.end())
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;

int g[105][105], a[10005], h, w, n;
inline void solve() {
  cin >> h >> w >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int in = 1, i = 1, j = 1; in <= n; in++) {
    int cnt = a[in];
    while (cnt--) {
      g[i][j] = in;
      j++;
      if (j > w)
        j = 1, i++;
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = (i & 1) ? 1 : w; j > 0 and j <= w; j += (i & 1) ? 1 : -1)
      cout << g[i][j] << " ";
    cout << endl;
  }
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}
Problem p03640 (C++)

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

using namespace std;
const int N = 100;
int arr[N];
int ans[N][N];
int main() {
  int q, m, n;
  scanf("%d%d%d", &n, &m, &q);
  vector<int> vec;

  for (int i = 0; i < q; i++)
    scanf("%d", &arr[i]);
  bool rev = false;
  int curr = 0;
  for (int i = 0; i < n; i++) {
    for (int j = rev ? m - 1 : 0; rev ? j >= 0 : j < m; rev ? j-- : j++) {
      ans[i][j] = curr + 1;
      arr[curr]--;
      if (!arr[curr])
        curr++;
    }
    rev = !rev;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}


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

using namespace std;
const int N = 100;
int arr[N * N];
int ans[N][N];
int main() {
  int q, m, n;
  scanf("%d%d%d", &n, &m, &q);
  vector<int> vec;

  for (int i = 0; i < q; i++)
    scanf("%d", &arr[i]);
  bool rev = false;
  int curr = 0;
  for (int i = 0; i < n; i++) {
    for (int j = rev ? m - 1 : 0; rev ? j >= 0 : j < m; rev ? j-- : j++) {
      ans[i][j] = curr + 1;
      arr[curr]--;
      if (!arr[curr])
        curr++;
    }
    rev = !rev;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}
Problem p03640 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int a[105][105];

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

  int w_cnt = 0, h_cnt = 0;
  bool rev = false;
  for (int i = 0, tmp; i < n; i++) {
    cin >> tmp;
    while (tmp) {
      if (w_cnt == -1 || w_cnt == w) {
        h_cnt++;
        w_cnt += w_cnt == w ? -1 : 1;
      }
      a[h_cnt][w_cnt] = i + 1;
      tmp--;
      w_cnt += (!rev ? 1 : -1);
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << a[i][j] << ' ';
    }
    cout << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int a[105][105];

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

  int w_cnt = 0, h_cnt = 0;
  bool rev = false;
  for (int i = 0, tmp; i < n; i++) {
    cin >> tmp;
    while (tmp) {
      if (w_cnt == -1 || w_cnt == w) {
        rev = !rev;
        h_cnt++;
        w_cnt += w_cnt == w ? -1 : 1;
      }
      a[h_cnt][w_cnt] = i + 1;
      tmp--;
      w_cnt += (!rev ? 1 : -1);
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << a[i][j] << ' ';
    }
    cout << endl;
  }

  return 0;
}
Problem p03640 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL << 29;
const ll mod = 1e9 + 7;
#define rep(i, n) for (int(i) = 0; (i) < (ll)(n); ++(i))
#define repd(i, n, d) for (ll(i) = 0; (i) < (ll)(n); (i) += (d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset((m), (v), sizeof(m))
#define chmin(X, Y) ((X) > (Y) ? X = (Y), true : false)
#define chmax(X, Y) ((X) < (Y) ? X = (Y), true : false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end())
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  rep(i, n) os << v[i] << (i == n - 1 ? "" : " ");
  return os;
}

#define N 120
int g[N][N];

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int p = 0;
  rep(i, n) {
    int a;
    cin >> a;
    while (a--) {
      g[p / w][p % w] = i + 1;
      p++;
    }
  }
  rep(i, n / 2) reverse(g[i * 2], g[i * 2] + w);
  rep(i, h) {
    rep(j, w) cout << g[i][j] << " ";
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL << 29;
const ll mod = 1e9 + 7;
#define rep(i, n) for (int(i) = 0; (i) < (ll)(n); ++(i))
#define repd(i, n, d) for (ll(i) = 0; (i) < (ll)(n); (i) += (d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset((m), (v), sizeof(m))
#define chmin(X, Y) ((X) > (Y) ? X = (Y), true : false)
#define chmax(X, Y) ((X) < (Y) ? X = (Y), true : false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end())
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  rep(i, n) os << v[i] << (i == n - 1 ? "" : " ");
  return os;
}

#define N 120
int g[N][N];

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int p = 0;
  rep(i, n) {
    int a;
    cin >> a;
    while (a--) {
      g[p / w][p % w] = i + 1;
      p++;
    }
  }
  rep(i, (h + 1) / 2) reverse(g[i * 2], g[i * 2] + w);
  rep(i, h) {
    rep(j, w) cout << g[i][j] << " ";
    cout << endl;
  }
  return 0;
}
Problem p03640 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define CLR(A, X) memset(A, X, sizeof(A))
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
int dcmp(double x) {
  if (fabs(x) < eps)
    return 0;
  return x > 0 ? 1 : -1;
}
const LL MOD = 1e9 + 7;
const int N = 1e2 + 5;

int a[N], mp[N][N];

int main() {
  int h, w, n;
  scanf("%d%d%d", &h, &w, &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int x = 1, y = 1, id = 1, op = 0;
  for (;;) {
    if (a[id] == 0)
      id++;
    a[id]--;
    //        printf("%d %d %d %d\n", id, a[id], x, y);
    mp[x][y] = id;
    if (op == 0) {
      y++;
      if (y == w + 1) {
        x++;
        y = w;
        op = 1;
      }
    } else {
      y--;
      if (y == 0) {
        x++;
        y = 1;
        op = 0;
      }
    }
    if (x == h + 1)
      break;
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      printf("%d%c", mp[i][j], j == w ? '\n' : ' ');
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define CLR(A, X) memset(A, X, sizeof(A))
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
int dcmp(double x) {
  if (fabs(x) < eps)
    return 0;
  return x > 0 ? 1 : -1;
}
const LL MOD = 1e9 + 7;
const int N = 1e2 + 5;

int a[N * N], mp[N][N];

int main() {
  int h, w, n;
  scanf("%d%d%d", &h, &w, &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int x = 1, y = 1, id = 1, op = 0;
  for (;;) {
    if (a[id] == 0)
      id++;
    a[id]--;
    //        printf("%d %d %d %d\n", id, a[id], x, y);
    mp[x][y] = id;
    if (op == 0) {
      y++;
      if (y == w + 1) {
        x++;
        y = w;
        op = 1;
      }
    } else {
      y--;
      if (y == 0) {
        x++;
        y = 1;
        op = 0;
      }
    }
    if (x == h + 1)
      break;
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      printf("%d%c", mp[i][j], j == w ? '\n' : ' ');
    }
  }
  return 0;
}
Problem p03640 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y);
#define sdl(x) scanf("%lld", &x)
#define sd2l(x, y) scanf("%lld%lld", &x, &y);
#define sz(x) (int)(x.size())
#define nax 101010
#define inf 1000000100
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pi pair<int, int>
#define pii pair<pi, pi>
using namespace std;
int mat[110][110];
int arr[110];
int main(int argc, char const *argv[]) {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int h, w, n;
  sd2(h, w);
  sd(n);
  for (int i = 1; i <= n; i++) {
    sd(arr[i]);
  }
  int row = 1;
  int col = 1;
  for (int i = 1; i <= n; i++) {

    int cur = arr[i];

    while (cur) {
      if (row % 2 == 1) {
        if (col == w + 1) {
          row++;
          col = w;
        } else {
          mat[row][col] = i;
          ++col;
          --cur;
        }
      } else {
        if (col == 0) {
          row++;
          col = 1;
        } else {
          mat[row][col] = i;
          --col;
          --cur;
        }
      }
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++)
      printf("%d ", mat[i][j]);
    puts("");
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y);
#define sdl(x) scanf("%lld", &x)
#define sd2l(x, y) scanf("%lld%lld", &x, &y);
#define sz(x) (int)(x.size())
#define nax 101010
#define inf 1000000100
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pi pair<int, int>
#define pii pair<pi, pi>
using namespace std;
int mat[10100][11010];
int arr[110];
int main(int argc, char const *argv[]) {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int h, w, n;
  sd2(h, w);
  sd(n);
  for (int i = 1; i <= n; i++) {
    sd(arr[i]);
  }
  int row = 1;
  int col = 1;
  for (int i = 1; i <= n; i++) {

    int cur = arr[i];

    while (cur) {
      if (row % 2 == 1) {
        if (col == w + 1) {
          row++;
          col = w;
        } else {
          mat[row][col] = i;
          ++col;
          --cur;
        }
      } else {
        if (col == 0) {
          row++;
          col = 1;
        } else {
          mat[row][col] = i;
          --col;
          --cur;
        }
      }
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++)
      printf("%d ", mat[i][j]);
    puts("");
  }
  return 0;
}
Problem p03640 (C++)

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

const int N = 110;

int h, w, n;
int b[N][N], a[N];

int main() {
  scanf("%d%d", &h, &w);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  int i = 0, j = 1, d = 1;
  for (int cur = 1; cur <= n; ++cur) {
    while (a[cur]) {
      i += d;
      if (i == h + 1)
        i = h, ++j, d *= -1;
      else if (!i)
        i = 1, ++j, d *= -1;
      b[i][j] = cur;
      --a[cur];
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j)
      printf("%d ", b[i][j]);
    puts("");
  }
  return 0;
}

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

const int N = 110;

int h, w, n;
int b[N][N], a[N * N];

int main() {
  scanf("%d%d", &h, &w);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  int i = 0, j = 1, d = 1;
  for (int cur = 1; cur <= n; ++cur) {
    while (a[cur]) {
      i += d;
      if (i == h + 1)
        i = h, ++j, d *= -1;
      else if (!i)
        i = 1, ++j, d *= -1;
      b[i][j] = cur;
      --a[cur];
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j)
      printf("%d ", b[i][j]);
    puts("");
  }
  return 0;
}
Problem p03640 (C++)

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

using namespace std;

int main() {
  int H, W;
  int N;
  const int MAXN = 1e2 + 5;
  vector<int> a(MAXN, 0);
  cin >> H >> W;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
  }
  vector<vector<int>> grid(MAXN, vector<int>(MAXN, 0));
  int color = 1;
  int paint = 0;
  for (int i = 1; i <= H; ++i) {
    if (i % 2 == 0) {
      for (int j = W; j >= 1; --j) {
        if (paint == a[color]) {
          ++color;
          paint = 0;
        }
        grid[i][j] = color;
        ++paint;
      }
    } else {
      for (int j = 1; j <= W; ++j) {
        if (paint == a[color]) {
          ++color;
          paint = 0;
        }
        grid[i][j] = color;
        ++paint;
      }
    }
  }
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cout << grid[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  int H, W;
  int N;
  const int MAXN = 1e2 + 5;
  vector<int> a(MAXN * MAXN, 0);
  cin >> H >> W;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
  }
  vector<vector<int>> grid(MAXN, vector<int>(MAXN, 0));
  int color = 1;
  int paint = 0;
  for (int i = 1; i <= H; ++i) {
    if (i % 2 == 0) {
      for (int j = W; j >= 1; --j) {
        if (paint == a[color]) {
          ++color;
          paint = 0;
        }
        grid[i][j] = color;
        ++paint;
      }
    } else {
      for (int j = 1; j <= W; ++j) {
        if (paint == a[color]) {
          ++color;
          paint = 0;
        }
        grid[i][j] = color;
        ++paint;
      }
    }
  }
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cout << grid[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p03640 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
ll f(ll a, ll c, ll d) {
  ll p = a / c, q = a / d, r = a / (c / __gcd(c, d) * d);
  return a - (p + q - r);
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int now = 0;
  int ans[h][w];
  rep(i, n) {
    rep(j, w) {
      if (a[now] == 0)
        now++;
      if (i % 2 == 0)
        ans[i][j] = now + 1;
      else
        ans[i][w - 1 - j] = now + 1;
      a[now]--;
    }
  }
  rep(i, h) {
    rep(j, w) {
      if (j)
        cout << " ";
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
ll f(ll a, ll c, ll d) {
  ll p = a / c, q = a / d, r = a / (c / __gcd(c, d) * d);
  return a - (p + q - r);
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int now = 0;
  int ans[h][w];
  rep(i, h) {
    rep(j, w) {
      if (a[now] == 0)
        now++;
      if (i % 2 == 0)
        ans[i][j] = now + 1;
      else
        ans[i][w - 1 - j] = now + 1;
      a[now]--;
    }
  }
  rep(i, h) {
    rep(j, w) {
      if (j)
        cout << " ";
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p03640 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define int ll
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
template <class T> using V = vector<T>;
template <class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (ll i = (ll)(b)-1; i >= a; --i)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9 + 7;
void cioacc() { // accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vvi mp(n, vi(n));
  int a;
  vi b;
  REP(i, n) {
    cin >> a;
    REP(j, a) b.eb(i + 1);
  }
  REP(i, h) REP(j, w) {
    if (i % 2 == 0)
      mp[i][j] = b[i * w + j];
    else
      mp[i][w - j - 1] = b[i * w + j];
  }
  REP(i, h) {
    REP(j, w) {
      cout << mp[i][j];
      if (j != w - 1)
        cout << " ";
    }
    cout << endl;
  }
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define int ll
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
template <class T> using V = vector<T>;
template <class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (ll i = (ll)(b)-1; i >= a; --i)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9 + 7;
void cioacc() { // accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vvi mp(h, vi(w));
  int a;
  vi b;
  REP(i, n) {
    cin >> a;
    REP(j, a) b.eb(i + 1);
  }
  REP(i, h) REP(j, w) {
    if (i % 2 == 0)
      mp[i][j] = b[i * w + j];
    else
      mp[i][w - j - 1] = b[i * w + j];
  }
  REP(i, h) {
    REP(j, w) {
      cout << mp[i][j];
      if (j != w - 1)
        cout << " ";
    }
    cout << endl;
  }
}
Problem p03640 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int ss[100005], bb[10005][10005], a[100006];
int main() {
  int h, w, q, n;
  while (scanf("%d%d", &h, &w) == 2) {
    memset(bb, 0, sizeof(bb));
    memset(ss, 0, sizeof(ss));
    scanf("%d", &n);
    q = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      for (int j = 1; j <= a[i]; j++) {
        ss[++q] = i;
      }
    }
    for (int i = 1; i <= h; i++) {
      if (i % 2 == 1) {
        for (int j = 1; j <= w; j++) {
          bb[i][j] = ss[q--];
        }
      }
      if (i % 2 == 0) {
        for (int j = w; j >= 1; j--) {
          bb[i][j] = ss[q--];
        }
      }
    }
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j < w; j++) {
        printf("%d ", bb[i][j]);
      }
      printf("%d\n", bb[i][w]);
    }
  }
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int ss[10005], bb[1005][1005], a[10006];
int main() {
  int h, w, q, n;
  while (scanf("%d%d", &h, &w) == 2) {
    memset(bb, 0, sizeof(bb));
    memset(ss, 0, sizeof(ss));
    scanf("%d", &n);
    q = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      for (int j = 1; j <= a[i]; j++) {
        ss[++q] = i;
      }
    }
    for (int i = 1; i <= h; i++) {
      if (i % 2 == 1) {
        for (int j = 1; j <= w; j++) {
          bb[i][j] = ss[q--];
        }
      }
      if (i % 2 == 0) {
        for (int j = w; j >= 1; j--) {
          bb[i][j] = ss[q--];
        }
      }
    }
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j < w; j++) {
        printf("%d ", bb[i][j]);
      }
      printf("%d\n", bb[i][w]);
    }
  }
}