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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#define repu(i, x, y) for (int i = x; i <= y; ++i)
using namespace std;

int n, m, k, a[200100], l[200100][20], r[200100][20], f[270000], g[270000],
    ans[200100];

int getint() {
  char ch;
  while (!isdigit(ch = getchar()) && ch != '-')
    ;
  bool flag = ch == '-';
  if (flag)
    ch = getchar();
  int x = ch - '0';
  for (; isdigit(ch = getchar()); x = x * 10 + ch - '0')
    ;
  return flag ? -x : x;
}

int main() {
  scanf("%d%d", &n, &m);
  repu(i, 1, n) a[i] = getint();
  for (k = 0; m >> k; ++k)
    ;
  a[0] = -2e9, a[n + 1] = 2e9;
  repu(i, 0, k) r[n + 1][i] = n;
  repu(i, 1, n) repu(j, 0, k) {
    l[i][j] = a[i] - a[i - 1] > m >> j ? i : l[i - 1][j];
    for (r[i][j] = max(r[i - 1][j], i); a[r[i][j] + 1] - a[r[i][j]] <= m >> j;
         ++r[i][j])
      ;
  }
  repu(i, 0, (1 << k) - 1) g[i] = n + 1;
  repu(i, 0, (1 << k) - 1) repu(j, 1, k) if (!(i & (1 << (j - 1)))) {
    int t = i | (1 << (j - 1));
    f[t] = max(f[t], r[f[i] + 1][j]);
    g[t] = min(g[t], l[g[i] - 1][j]);
  }
  repu(i, 0, (1 << k) - 1) {
    int x = f[i], y = g[(1 << k) - 1 - i];
    if (x + 1 >= y)
      ++ans[1];
    else if (r[x + 1][0] + 1 >= y)
      ++ans[l[x + 1][0]], --ans[r[x + 1][0] + 1];
  }
  repu(i, 1, n) puts((ans[i] += ans[i - 1]) ? "Possible" : "Impossible");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#define repu(i, x, y) for (int i = x; i <= y; ++i)
using namespace std;

int n, m, k, a[200100], l[200100][20], r[200100][20], f[270000], g[270000],
    ans[200100];

int getint() {
  char ch;
  while (!isdigit(ch = getchar()) && ch != '-')
    ;
  bool flag = ch == '-';
  if (flag)
    ch = getchar();
  int x = ch - '0';
  for (; isdigit(ch = getchar()); x = x * 10 + ch - '0')
    ;
  return flag ? -x : x;
}

int main() {
  scanf("%d%d", &n, &m);
  repu(i, 1, n) a[i] = getint();
  for (k = 0; m >> k; ++k)
    ;
  a[0] = a[1] - m - 1, a[n + 1] = a[n] + m + 1;
  repu(i, 0, k) r[n + 1][i] = n;
  repu(i, 1, n) repu(j, 0, k) {
    l[i][j] = a[i] - a[i - 1] > m >> j ? i : l[i - 1][j];
    for (r[i][j] = max(r[i - 1][j], i); a[r[i][j] + 1] - a[r[i][j]] <= m >> j;
         ++r[i][j])
      ;
  }
  repu(i, 0, (1 << k) - 1) g[i] = n + 1;
  repu(i, 0, (1 << k) - 1) repu(j, 1, k) if (!(i & (1 << (j - 1)))) {
    int t = i | (1 << (j - 1));
    f[t] = max(f[t], r[f[i] + 1][j]);
    g[t] = min(g[t], l[g[i] - 1][j]);
  }
  repu(i, 0, (1 << k) - 1) {
    int x = f[i], y = g[(1 << k) - 1 - i];
    if (x + 1 >= y)
      ++ans[1];
    else if (r[x + 1][0] + 1 >= y)
      ++ans[l[x + 1][0]], --ans[r[x + 1][0] + 1];
  }
  repu(i, 1, n) puts((ans[i] += ans[i - 1]) ? "Possible" : "Impossible");
  return 0;
}
Problem p03771 (C++)

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

#define ctz __builtin_ctz

const int N = 200005, inf = 0x3f3f3f3f;

void up(int &x, int y) { x = std::max(x, y); }
void down(int &x, int y) { x = std::min(x, y); }

int f[N], g[N], x[N], L[19][N], R[19][N], sum[N];

int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  int n, v;
  std::cin >> n >> v;
  int lg = std::__lg(v) + 1, mask = ~(-1 << lg);
  x[0] = -inf, x[n + 1] = inf;
  for (int i = 1; i <= n; ++i)
    std::cin >> x[i];
  for (int t = 0; t <= lg; ++t) {
    int _v = v >> t;
    for (int i = 1; i <= n; ++i)
      L[t][i] = x[i] - x[i - 1] <= _v ? L[t][i - 1] : i;
    for (int i = n; i >= 1; --i)
      R[t][i] = x[i + 1] - x[i] <= _v ? R[t][i + 1] : i;
  }
  std::fill(g, g + mask + 1, n + 1);
  for (int i = 0; i < mask; ++i) {
    for (int _j = mask ^ i, j = ctz(_j); _j; j = ctz(_j &= _j - 1)) {
      up(f[i | 1 << j], f[i]);
      if (f[i] < n)
        up(f[i | 1 << j], R[j + 1][f[i] + 1]);
      down(g[i | 1 << j], g[i]);
      if (g[i] > 1)
        down(g[i | 1 << j], L[j + 1][g[i] - 1]);
    }
  }
  for (int i = 0; i <= mask; ++i)
    if (f[i] + 1 >= g[mask - i]) {
      while (n--)
        std::cout << "Possible\n";
      return 0;
    }
  for (int i = 0; i <= mask; ++i)
    if (R[0][f[i] + 1] + 1 >= g[mask - i])
      ++sum[f[i] + 1], --sum[R[0][f[i] + 1] + 1];
  for (int i = 1; i <= n; ++i)
    sum[i] += sum[i - 1];
  for (int i = 1; i <= n; ++i)
    std::cout << (sum[i] ? "Possible" : "Impossible") << '\n';

  return 0;
}

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

#define ctz __builtin_ctz

const int N = 400005, inf = 0x3f3f3f3f;

void up(int &x, int y) { x = std::max(x, y); }
void down(int &x, int y) { x = std::min(x, y); }

int f[N], g[N], x[N], L[19][N], R[19][N], sum[N];

int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  int n, v;
  std::cin >> n >> v;
  int lg = std::__lg(v) + 1, mask = ~(-1 << lg);
  x[0] = -inf, x[n + 1] = inf;
  for (int i = 1; i <= n; ++i)
    std::cin >> x[i];
  for (int t = 0; t <= lg; ++t) {
    int _v = v >> t;
    for (int i = 1; i <= n; ++i)
      L[t][i] = x[i] - x[i - 1] <= _v ? L[t][i - 1] : i;
    for (int i = n; i >= 1; --i)
      R[t][i] = x[i + 1] - x[i] <= _v ? R[t][i + 1] : i;
  }
  std::fill(g, g + mask + 1, n + 1);
  for (int i = 0; i < mask; ++i) {
    for (int _j = mask ^ i, j = ctz(_j); _j; j = ctz(_j &= _j - 1)) {
      up(f[i | 1 << j], f[i]);
      if (f[i] < n)
        up(f[i | 1 << j], R[j + 1][f[i] + 1]);
      down(g[i | 1 << j], g[i]);
      if (g[i] > 1)
        down(g[i | 1 << j], L[j + 1][g[i] - 1]);
    }
  }
  for (int i = 0; i <= mask; ++i)
    if (f[i] + 1 >= g[mask - i]) {
      while (n--)
        std::cout << "Possible\n";
      return 0;
    }
  for (int i = 0; i <= mask; ++i)
    if (R[0][f[i] + 1] + 1 >= g[mask - i])
      ++sum[f[i] + 1], --sum[R[0][f[i] + 1] + 1];
  for (int i = 1; i <= n; ++i)
    sum[i] += sum[i - 1];
  for (int i = 1; i <= n; ++i)
    std::cout << (sum[i] ? "Possible" : "Impossible") << '\n';

  return 0;
}
Problem p03771 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, v[20], x[N], dep, dpl[N], dpr[N];
int blo[20][N], L[20][N], R[20][N];
void init(int dep) {
  int cnt = 0;
  blo[dep][1] = L[dep][1] = R[dep][1] = cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (x[i - 1] + v[dep] >= x[i])
      blo[dep][i] = cnt, R[dep][cnt]++;
    else
      blo[dep][i] = ++cnt, L[dep][cnt] = R[dep][cnt] = i;
  }
  L[dep][0] = 1;
  R[dep][0] = n;
}
bool ans[N];
int main() {
  scanf("%d%d", &n, &v[0]);
  while (v[dep])
    v[dep + 1] = v[dep] >> 1, dep++;
  for (int i = 1; i <= n; i++)
    scanf("%d", &x[i]);
  for (int i = 0; i <= dep; i++)
    init(i);
  int U = (1 << dep) - 1;
  for (int S = 1; S <= U; S++)
    for (int i = 0; i < dep; i++)
      if (S >> i & 1)
        dpl[S] = max(dpl[S], R[i + 1][blo[i + 1][dpl[S ^ (1 << i)] + 1]]);
  for (int S = 0; S <= U; S++)
    dpr[S] = n + 1;
  for (int S = 1; S <= U; S++)
    for (int i = 0; i < dep; i++)
      if (S >> i & 1)
        dpr[S] = min(dpr[S], L[i + 1][blo[i + 1][dpr[S ^ (1 << i)] - 1]]);
  if (blo[0][n] <= 20) {
    for (int i = 1; i <= blo[0][n]; i++) {
      int l = L[0][i], r = R[0][i];
      bool ok = 0;
      for (int S = 0; S <= U; S++)
        if (dpl[S] >= l - 1 && dpr[U ^ S] <= r + 1)
          ok = 1;
      if (!ok)
        continue;
      for (int j = l; j <= r; j++)
        ans[j] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    puts(ans[i] ? "Possible" : "Impossible");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, v[20], x[N], dep, dpl[N], dpr[N];
int blo[20][N], L[20][N], R[20][N];
void init(int dep) {
  int cnt = 0;
  blo[dep][1] = L[dep][1] = R[dep][1] = cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (x[i - 1] + v[dep] >= x[i])
      blo[dep][i] = cnt, R[dep][cnt]++;
    else
      blo[dep][i] = ++cnt, L[dep][cnt] = R[dep][cnt] = i;
  }
  L[dep][0] = 1;
  R[dep][0] = n;
}
bool ans[N];
int main() {
  scanf("%d%d", &n, &v[0]);
  while (v[dep])
    v[dep + 1] = v[dep] >> 1, dep++;
  for (int i = 1; i <= n; i++)
    scanf("%d", &x[i]);
  for (int i = 0; i <= dep; i++)
    init(i);
  int U = (1 << dep) - 1;
  for (int S = 1; S <= U; S++)
    for (int i = 0; i < dep; i++)
      if (S >> i & 1)
        dpl[S] = max(dpl[S], R[i + 1][blo[i + 1][dpl[S ^ (1 << i)] + 1]]);
  for (int S = 0; S <= U; S++)
    dpr[S] = n + 1;
  for (int S = 1; S <= U; S++)
    for (int i = 0; i < dep; i++)
      if (S >> i & 1)
        dpr[S] = min(dpr[S], L[i + 1][blo[i + 1][dpr[S ^ (1 << i)] - 1]]);
  if (blo[0][n] <= 20) {
    for (int i = 1; i <= blo[0][n]; i++) {
      int l = L[0][i], r = R[0][i];
      bool ok = 0;
      for (int S = 0; S <= U; S++)
        if (dpl[S] >= l - 1 && dpr[U ^ S] <= r + 1)
          ok = 1;
      if (!ok)
        continue;
      for (int j = l; j <= r; j++)
        ans[j] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    puts(ans[i] ? "Possible" : "Impossible");
  return 0;
}
Problem p03771 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define MN 200005
#define MM (1 << 18)
#define ML 18
using namespace std;
inline int in() {
  int x = 0;
  bool f = 0;
  char c;
  for (; (c = getchar()) < '0' || c > '9'; f = c == '-')
    ;
  for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';
       x = (x << 3) + (x << 1) + c - '0')
    ;
  return f ? -x : x;
}
int L[ML][MN], R[ML][MN], f[MM], g[MM], x[MN];
bool vis[MM];
int n, v, j, val;
int main() {
  n = in();
  v = in();
  for (int i = 1; i <= n; ++i)
    x[i] = in();
  for (j = 0, val = v;; val >>= 1, ++j) {
    L[j][0] = L[j][1] = 1;
    R[j][n] = R[j][n + 1] = n;
    for (int i = 2; i <= n; ++i)
      if (x[i] - x[i - 1] > val)
        L[j][i] = i;
      else
        L[j][i] = L[j][i - 1];
    for (int i = n - 1; i; --i)
      if (x[i + 1] - x[i] > val)
        R[j][i] = i;
      else
        R[j][i] = R[j][i + 1];
    if (!val)
      break;
  }
  for (int i = 0; i < (1 << j); ++i)
    f[i] = 0, g[i] = n + 1;
  for (int i = 0; i < (1 << j); ++i) {
    for (int k = 0; k < j; ++k)
      if (!(i & (1 << k))) {
        f[(i | (1 << k))] = max(f[i | (1 << k)], R[k + 1][f[i] + 1]);
        g[(i | (1 << k))] = min(g[i | (1 << k)], L[k + 1][g[i] - 1]);
      }
  }
  for (int i = 0; i < (1 << j); ++i)
    if (R[0][f[i] + 1] >= g[((1 << j) - 1) ^ i] - 1)
      vis[R[0][f[i] + 1]] = 1;
  for (int i = 1; i <= n; ++i)
    puts(vis[R[0][i]] ? "Possible" : "Impossible");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define MN 200005
#define MM (1 << 18)
#define ML 19
using namespace std;
inline int in() {
  int x = 0;
  bool f = 0;
  char c;
  for (; (c = getchar()) < '0' || c > '9'; f = c == '-')
    ;
  for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';
       x = (x << 3) + (x << 1) + c - '0')
    ;
  return f ? -x : x;
}
int L[ML][MN], R[ML][MN], f[MM], g[MM], x[MN];
bool vis[MM];
int n, v, j, val;
int main() {
  n = in();
  v = in();
  for (int i = 1; i <= n; ++i)
    x[i] = in();
  for (j = 0, val = v;; val >>= 1, ++j) {
    L[j][0] = L[j][1] = 1;
    R[j][n] = R[j][n + 1] = n;
    for (int i = 2; i <= n; ++i)
      if (x[i] - x[i - 1] > val)
        L[j][i] = i;
      else
        L[j][i] = L[j][i - 1];
    for (int i = n - 1; i; --i)
      if (x[i + 1] - x[i] > val)
        R[j][i] = i;
      else
        R[j][i] = R[j][i + 1];
    if (!val)
      break;
  }
  for (int i = 0; i < (1 << j); ++i)
    f[i] = 0, g[i] = n + 1;
  for (int i = 0; i < (1 << j); ++i) {
    for (int k = 0; k < j; ++k)
      if (!(i & (1 << k))) {
        f[(i | (1 << k))] = max(f[i | (1 << k)], R[k + 1][f[i] + 1]);
        g[(i | (1 << k))] = min(g[i | (1 << k)], L[k + 1][g[i] - 1]);
      }
  }
  for (int i = 0; i < (1 << j); ++i)
    if (R[0][f[i] + 1] >= g[((1 << j) - 1) ^ i] - 1)
      vis[R[0][f[i] + 1]] = 1;
  for (int i = 1; i <= n; ++i)
    puts(vis[R[0][i]] ? "Possible" : "Impossible");
  return 0;
}
Problem p03771 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
int N, V, LOG, a[200001], LE[18][200001], RE[18][200001], F[262144], G[262144],
    OK[200001];
int main() {
  scanf("%d%d", &N, &V);
  while (1 << LOG <= V)
    LOG++;
  for (int i = 1; i <= N; i++)
    scanf("%d", a + i);
  for (int i = 0; i <= LOG; i++) {
    int *le = LE[i], *re = RE[i];
    le[1] = 1;
    for (int j = 2; j <= N; j++)
      le[j] = a[j] - a[j - 1] <= V >> i ? le[j - 1] : j;
    re[N] = N;
    for (int j = N - 1; j; j--)
      re[j] = a[j + 1] - a[j] <= V >> i ? re[j + 1] : j;
  }
  for (int i = 0; i < 1 << LOG; i++) {
    F[i] = 0;
    G[i] = N + 1;
    for (int j = 1; j <= LOG; j++)
      if (i >> j - 1 & 1) {
        F[i] = std::max(F[i], F[i - (1 << j - 1)] == N
                                  ? N
                                  : RE[j][F[i - (1 << j - 1)] + 1]);
        G[i] = std::min(G[i], G[i - (1 << j - 1)] == 1
                                  ? 1
                                  : LE[j][G[i - (1 << j - 1)] - 1]);
      }
  }
  for (int i = 0; i < 1 << LOG; i++)
    if (F[i] + 1 >= G[(1 << LOG) - 1 - i]) {
      for (int j = N; j--;)
        puts("Possible");
      return 0;
    }
  for (int i = 0; i < 1 << LOG; i++)
    if (RE[0][F[i] + 1] + 1 >= G[(1 << LOG) - 1 - i]) {
      int R = RE[0][F[i] + 1], L = LE[0][R];
      if (!OK[L])
        std::fill(OK + L, OK + R + 1, 1);
    }
  for (int i = 1; i <= N; i++)
    puts(OK[i] ? "Possible" : "Impossible");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
int N, V, LOG, a[200001], LE[19][200001], RE[19][200001], F[262144], G[262144],
    OK[200001];
int main() {
  scanf("%d%d", &N, &V);
  while (1 << LOG <= V)
    LOG++;
  for (int i = 1; i <= N; i++)
    scanf("%d", a + i);
  for (int i = 0; i <= LOG; i++) {
    int *le = LE[i], *re = RE[i];
    le[1] = 1;
    for (int j = 2; j <= N; j++)
      le[j] = a[j] - a[j - 1] <= V >> i ? le[j - 1] : j;
    re[N] = N;
    for (int j = N - 1; j; j--)
      re[j] = a[j + 1] - a[j] <= V >> i ? re[j + 1] : j;
  }
  for (int i = 0; i < 1 << LOG; i++) {
    F[i] = 0;
    G[i] = N + 1;
    for (int j = 1; j <= LOG; j++)
      if (i >> j - 1 & 1) {
        F[i] = std::max(F[i], F[i - (1 << j - 1)] == N
                                  ? N
                                  : RE[j][F[i - (1 << j - 1)] + 1]);
        G[i] = std::min(G[i], G[i - (1 << j - 1)] == 1
                                  ? 1
                                  : LE[j][G[i - (1 << j - 1)] - 1]);
      }
  }
  for (int i = 0; i < 1 << LOG; i++)
    if (F[i] + 1 >= G[(1 << LOG) - 1 - i]) {
      for (int j = N; j--;)
        puts("Possible");
      return 0;
    }
  for (int i = 0; i < 1 << LOG; i++)
    if (RE[0][F[i] + 1] + 1 >= G[(1 << LOG) - 1 - i]) {
      int R = RE[0][F[i] + 1], L = LE[0][R];
      if (!OK[L])
        std::fill(OK + L, OK + R + 1, 1);
    }
  for (int i = 1; i <= N; i++)
    puts(OK[i] ? "Possible" : "Impossible");
  return 0;
}
Problem p03771 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#define fo(i, a, b) for (i = a; i <= b; i++)
#define fd(i, a, b) for (i = a; i >= b; i--)
using namespace std;
const int maxn = 200000 + 10, lgn = 20;
int f[maxn * 2], g[maxn * 2], mi[maxn], left[maxn][lgn + 10],
    right[maxn][lgn + 10], v[lgn + 10], x[maxn];
int i, j, k, l, r, s, t, n, m, tot, top;
int main() {
  scanf("%d%d", &n, &t);
  fo(i, 1, n) scanf("%d", &x[i]);
  v[0] = t;
  t /= 2;
  while (t) {
    v[++top] = t;
    t /= 2;
  }
  v[++top] = 0;
  reverse(v, v + top + 1);
  fo(j, 0, top) {
    left[1][j] = 1;
    fo(i, 2, n) if (x[i] - x[i - 1] <= v[j]) left[i][j] = left[i - 1][j];
    else left[i][j] = i;
    right[n][j] = n;
    fd(i, n - 1, 1) if (x[i + 1] - x[i] <= v[j]) right[i][j] = right[i + 1][j];
    else right[i][j] = i;
  }
  f[0] = 0;
  g[0] = n + 1;
  fo(s, 1, (1 << (top + 1)) - 1) {
    f[s] = 0;
    g[s] = n + 1;
    fo(i, 0, top) if (s & (1 << i)) {
      r = s ^ (1 << i);
      if (f[r] == n)
        f[s] = n;
      else
        f[s] = max(f[s], right[f[r] + 1][i]);
      if (g[r] == 1)
        g[s] = 1;
      else
        g[s] = min(g[s], left[g[r] - 1][i]);
    }
  }
  fo(i, 0, n) mi[i] = n + 2;
  fo(i, 0, (1 << top) - 1) {
    r = ((1 << top) - 1) ^ i;
    mi[f[i]] = min(mi[f[i]], g[r]);
  }
  fd(i, n - 1, 0) mi[i] = min(mi[i], mi[i + 1]);
  fo(i, 1, n) {
    l = left[i][top];
    r = right[i][top];
    if (mi[l - 1] <= r + 1)
      printf("Possible\n");
    else
      printf("Impossible\n");
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#define fo(i, a, b) for (i = a; i <= b; i++)
#define fd(i, a, b) for (i = a; i >= b; i--)
using namespace std;
const int maxn = 200000 + 10, lgn = 20;
int f[maxn * 5], g[maxn * 5], mi[maxn], left[maxn][lgn + 10],
    right[maxn][lgn + 10], v[lgn + 10], x[maxn];
int i, j, k, l, r, s, t, n, m, tot, top;
int main() {
  scanf("%d%d", &n, &t);
  fo(i, 1, n) scanf("%d", &x[i]);
  v[0] = t;
  t /= 2;
  while (t) {
    v[++top] = t;
    t /= 2;
  }
  v[++top] = 0;
  reverse(v, v + top + 1);
  fo(j, 0, top) {
    left[1][j] = 1;
    fo(i, 2, n) if (x[i] - x[i - 1] <= v[j]) left[i][j] = left[i - 1][j];
    else left[i][j] = i;
    right[n][j] = n;
    fd(i, n - 1, 1) if (x[i + 1] - x[i] <= v[j]) right[i][j] = right[i + 1][j];
    else right[i][j] = i;
  }
  f[0] = 0;
  g[0] = n + 1;
  fo(s, 1, (1 << (top + 1)) - 1) {
    f[s] = 0;
    g[s] = n + 1;
    fo(i, 0, top) if (s & (1 << i)) {
      r = s ^ (1 << i);
      if (f[r] == n)
        f[s] = n;
      else
        f[s] = max(f[s], right[f[r] + 1][i]);
      if (g[r] == 1)
        g[s] = 1;
      else
        g[s] = min(g[s], left[g[r] - 1][i]);
    }
  }
  fo(i, 0, n) mi[i] = n + 2;
  fo(i, 0, (1 << top) - 1) {
    r = ((1 << top) - 1) ^ i;
    mi[f[i]] = min(mi[f[i]], g[r]);
  }
  fd(i, n - 1, 0) mi[i] = min(mi[i], mi[i + 1]);
  fo(i, 1, n) {
    l = left[i][top];
    r = right[i][top];
    if (mi[l - 1] <= r + 1)
      printf("Possible\n");
    else
      printf("Impossible\n");
  }
}
Problem p03772 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 100, mo = 1e9 + 7;
int n, m, i, j, k, x, a[N], f[51][N][N], ans;
void add(int &x, int k) { x = (x + k) % mo; }
int main() {
  scanf("%d", &n);
  m = 2 * n - 1;
  for (i = 1; i <= m; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + m + 1);
  f[1][1][1] = 1;
  for (i = 1; i <= n; i++) {
    int l = a[n - i] != a[n - i + 1], r = a[n + i] != a[n + i - 1];
    for (j = 1; j <= m; j++)
      for (k = 1; k <= m; k++)
        if (f[i][j][k]) {
          int tj = j + l + r, tk = k + l, v = f[i][j][k];
          for (x = 1; x < tk; x++)
            add(f[i + 1][tj - (tk - x - 1)][x], v);
          add(f[i + 1][tj][tk], v);
          for (x = tk + 1; x <= tj; x++)
            add(f[i + 1][tj - (x - tk - 1)][tk + 1], v);
        }
  }
  for (i = 1; i <= m; i++)
    for (j = 1; j <= m; j++)
      add(ans, f[n][i][j]);
  printf("%d", ans);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 100, mo = 1e9 + 7;
int n, m, i, j, k, x, a[N], f[51][N][N], ans;
void add(int &x, int k) { x = (x + k) % mo; }
int main() {
  scanf("%d", &n);
  m = 2 * n - 1;
  for (i = 1; i <= m; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + m + 1);
  f[1][1][1] = 1;
  for (i = 1; i < n; i++) {
    int l = a[n - i] != a[n - i + 1], r = a[n + i] != a[n + i - 1];
    for (j = 1; j <= m; j++)
      for (k = 1; k <= m; k++)
        if (f[i][j][k]) {
          int tj = j + l + r, tk = k + l, v = f[i][j][k];
          for (x = 1; x < tk; x++)
            add(f[i + 1][tj - (tk - x - 1)][x], v);
          add(f[i + 1][tj][tk], v);
          for (x = tk + 1; x <= tj; x++)
            add(f[i + 1][tj - (x - tk - 1)][tk + 1], v);
        }
  }
  for (i = 1; i <= m; i++)
    for (j = 1; j <= m; j++)
      add(ans, f[n][i][j]);
  printf("%d", ans);
}
Problem p03772 (C++)

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

typedef long long ll;
const ll MAXN = 55;
const ll MOD = 1e9 + 7;

ll n, m;
ll a[MAXN];
ll d[MAXN][MAXN * 2][MAXN * 2];

int main() {
  scanf("%lld", &n);
  m = 2 * n - 1;
  for (ll i = 1; i <= m; i++)
    scanf("%lld", &a[i]);
  sort(a + 1, a + m + 1);
  d[n][0][0] = 1;
  for (ll i = n; i > 1; i--) {
    ll l = (a[i] != a[i - 1]), r = (a[m - i + 1] != a[m - i + 2]);
    for (ll j = 0; j <= m; j++)
      for (ll k = 0; k <= m; k++) {
        if (!d[i][j][k])
          continue;
        d[i - 1][j + l][k + r] = (d[i - 1][j + l][k + r] + d[i][j][k]) % MOD;
        for (ll dl = 0; dl < j + l; dl++)
          (d[i - 1][dl][k + r + 1] += d[i][j][k]) %= MOD;
        for (ll dr = 0; dr < k + r; dr++)
          (d[i - 1][j + l + 1][dr] += d[i][j][k]) %= MOD;
      }
  }
  ll ans = 0;
  for (ll i = 0; i <= m; i++)
    for (ll j = 0; j <= m; j++)
      ans = (ans + d[1][i][j]) % MOD;
  printf("%lld\n", ans);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long ll;
const ll MAXN = 105;
const ll MOD = 1e9 + 7;

ll n, m;
ll a[MAXN];
ll d[MAXN][MAXN * 2][MAXN * 2];

int main() {
  scanf("%lld", &n);
  m = 2 * n - 1;
  for (ll i = 1; i <= m; i++)
    scanf("%lld", &a[i]);
  sort(a + 1, a + m + 1);
  d[n][0][0] = 1;
  for (ll i = n; i > 1; i--) {
    ll l = (a[i] != a[i - 1]), r = (a[m - i + 1] != a[m - i + 2]);
    for (ll j = 0; j <= m; j++)
      for (ll k = 0; k <= m; k++) {
        if (!d[i][j][k])
          continue;
        d[i - 1][j + l][k + r] = (d[i - 1][j + l][k + r] + d[i][j][k]) % MOD;
        for (ll dl = 0; dl < j + l; dl++)
          (d[i - 1][dl][k + r + 1] += d[i][j][k]) %= MOD;
        for (ll dr = 0; dr < k + r; dr++)
          (d[i - 1][j + l + 1][dr] += d[i][j][k]) %= MOD;
      }
  }
  ll ans = 0;
  for (ll i = 0; i <= m; i++)
    for (ll j = 0; j <= m; j++)
      ans = (ans + d[1][i][j]) % MOD;
  printf("%lld\n", ans);
}
Problem p03772 (C++)

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

#define For(i, a, b) for (int i = (a); i <= (int)(b); ++i)

#define N (50 + 5)
const int P = 1e9 + 7;

inline void Get(int &a, int b) {
  a += b;
  if (a >= P)
    a -= P;
}

int a[N], f[N][N << 1][N << 1];

int main() {
  int n, m;

  scanf("%d", &n);
  m = (n << 1) - 1;

  For(i, 1, m) scanf("%d", &a[i]);
  sort(a + 1, a + m + 1, greater<int>());

  int me, l, r, nj, nk;
  f[1][1][1] = 1;

  For(i, 1, n - 1) {
    l = a[n - i] != a[n - i + 1];
    r = a[n + i] != a[n + i - 1];

    For(j, 1, m) For(k, 1, j) if (f[i][j][k]) {
      me = f[i][j][k];
      nj = j + l + r, nk = k + l;

      For(t, 1, nk - 1) Get(f[i + 1][nj - (nk - t - 1)][t], me);
      Get(f[i + 1][nj][nk], me);
      For(t, nk + 1, nj) Get(f[i + 1][nj - (t - nk - 1)][nk + 1], me);
    }
  }

  int ans = 0;
  For(i, 1, m) For(j, 1, i) Get(ans, f[n][i][j]);
  printf("%d\n", ans);

  return 0;
}

Fixed submission:
// 2018-1-19
// miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for (int i = (a); i <= (int)(b); ++i)

#define N (50 + 5)
const int P = 1e9 + 7;

inline void Get(int &a, int b) {
  a += b;
  if (a >= P)
    a -= P;
}

int a[N << 1], f[N][N << 1][N << 1];

int main() {
  int n, m;

  scanf("%d", &n);
  m = (n << 1) - 1;

  For(i, 1, m) scanf("%d", &a[i]);
  sort(a + 1, a + m + 1, greater<int>());

  int me, l, r, nj, nk;
  f[1][1][1] = 1;

  For(i, 1, n - 1) {
    l = a[n - i] != a[n - i + 1];
    r = a[n + i] != a[n + i - 1];

    For(j, 1, m) For(k, 1, j) if (f[i][j][k]) {
      me = f[i][j][k];
      nj = j + l + r, nk = k + l;

      For(t, 1, nk - 1) Get(f[i + 1][nj - (nk - t - 1)][t], me);
      Get(f[i + 1][nj][nk], me);
      For(t, nk + 1, nj) Get(f[i + 1][nj - (t - nk - 1)][nk + 1], me);
    }
  }

  int ans = 0;
  For(i, 1, m) For(j, 1, i) Get(ans, f[n][i][j]);
  printf("%d\n", ans);

  return 0;
}
Problem p03772 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
// #define debug
// #define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 55;
const int MOD = 1e9 + 7;

inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }

int n, a[MAXN], dp[MAXN][MAXN][MAXN];

int f(int i, int idx, int tot) {
  if (i < 0)
    return 1;
  if (dp[i][idx][tot] != -1)
    return dp[i][idx][tot];

  int ret = 0;

  int add_first = (a[i - 1] == a[i]) ? 0 : 1;
  int add_last = (a[2 * n - 1 - i] == a[2 * n - 2 - i]) ? 0 : 1;

  FOR(j, 1, tot + 1) {
    int rem = max(abs(j - idx) - 1, 0);
    int new_idx = (idx < j) ? idx + 1 : j;
    ret = add(ret,
              f(i - 1, new_idx + add_first, tot - rem + add_first + add_last));
  }

  // TRACE(i _ idx _ tot _ ret);
  return dp[i][idx][tot] = ret;
}

int main(void) {
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  REP(i, 2 * n - 1) scanf("%d", &a[i]);
  sort(a, a + (2 * n - 1));

  printf("%d\n", f(n - 1, 1, 1));

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
// #define debug
// #define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 105;
const int MOD = 1e9 + 7;

inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }

int n, a[MAXN], dp[MAXN][MAXN][MAXN];

int f(int i, int idx, int tot) {
  if (i < 0)
    return 1;
  if (dp[i][idx][tot] != -1)
    return dp[i][idx][tot];

  int ret = 0;

  int add_first = (a[i - 1] == a[i]) ? 0 : 1;
  int add_last = (a[2 * n - 1 - i] == a[2 * n - 2 - i]) ? 0 : 1;

  FOR(j, 1, tot + 1) {
    int rem = max(abs(j - idx) - 1, 0);
    int new_idx = (idx < j) ? idx + 1 : j;
    ret = add(ret,
              f(i - 1, new_idx + add_first, tot - rem + add_first + add_last));
  }

  // TRACE(i _ idx _ tot _ ret);
  return dp[i][idx][tot] = ret;
}

int main(void) {
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  REP(i, 2 * n - 1) scanf("%d", &a[i]);
  sort(a, a + (2 * n - 1));

  printf("%d\n", f(n - 1, 1, 1));

  return 0;
}
Problem p03772 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 55, MOD = 1000000007;

int N, A[MAXN];
int dp[MAXN][MAXN * 2][MAXN * 2];

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= 2 * N - 1; i++)
    scanf("%d", &A[i]);
  sort(A + 1, A + 2 * N);

  dp[N][1][0] = 1;
  for (int i = N - 1; i >= 1; i--) {
    int al = (A[i] != A[i + 1]), ar = (A[2 * N - i] != A[2 * N - i - 1]);
    for (int l = 0; l <= 2 * N - 1; l++)
      for (int r = 0; l + r <= 2 * N - 1; r++)
        if (dp[i + 1][l][r]) {
          for (int k = 1; k <= l + al; k++)
            (dp[i][l + al - k + 1][r + ar + (k != 1)] += dp[i + 1][l][r]) %=
                MOD;
          for (int k = 1; k <= r + ar; k++)
            (dp[i][l + al + 1][r + ar - k] += dp[i + 1][l][r]) %= MOD;
        }
  }

  int ans = 0;
  for (int l = 0; l <= 2 * N - 1; l++)
    for (int r = 0; l + r <= 2 * N - 1; r++)
      (ans += dp[1][l][r]) %= MOD;
  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 55, MOD = 1000000007;

int N, A[MAXN * 2];
int dp[MAXN][MAXN * 2][MAXN * 2];

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= 2 * N - 1; i++)
    scanf("%d", &A[i]);
  sort(A + 1, A + 2 * N);

  dp[N][1][0] = 1;
  for (int i = N - 1; i >= 1; i--) {
    int al = (A[i] != A[i + 1]), ar = (A[2 * N - i] != A[2 * N - i - 1]);
    for (int l = 0; l <= 2 * N - 1; l++)
      for (int r = 0; l + r <= 2 * N - 1; r++)
        if (dp[i + 1][l][r]) {
          for (int k = 1; k <= l + al; k++)
            (dp[i][l + al - k + 1][r + ar + (k != 1)] += dp[i + 1][l][r]) %=
                MOD;
          for (int k = 1; k <= r + ar; k++)
            (dp[i][l + al + 1][r + ar - k] += dp[i + 1][l][r]) %= MOD;
        }
  }

  int ans = 0;
  for (int l = 0; l <= 2 * N - 1; l++)
    for (int r = 0; l + r <= 2 * N - 1; r++)
      (ans += dp[1][l][r]) %= MOD;
  printf("%d\n", ans);

  return 0;
}
Problem p03772 (C++)

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

inline int Get() {
  char ch;
  while ((ch = getchar()) < '0' || ch > '9')
    ;
  int Num = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    Num = (Num << 3) + (Num << 1) + ch - '0';
  return Num;
}
const int N = 55;
const int Mod = 1e9 + 7;
int n, a[N], g[N][N << 1][N << 1], ans;
int main() {
  n = Get();
  for (int i = 1; i < n * 2; ++i)
    a[i] = Get();
  std ::sort(a + 1, a + n * 2);

  g[0][1][0] = 1;
  for (int i = 1, w; i < n; ++i)
    for (int j = 1; j < i * 2; ++j)
      for (int k = 0; k < j; ++k)
        if (w = g[i - 1][j][k]) {
          int x = j, y = k;
          if (a[n - i] != a[n - i + 1])
            ++x, ++y;
          if (a[n + i] != a[n + i - 1])
            ++x;
          for (int p = 0; p < x; ++p)
            (g[i][x - std ::max(abs(y - p) - 1, 0)][p <= y ? p : y + 1] += w) %=
                Mod;
        }

  for (int i = 1; i < n * 2; ++i)
    for (int k = 0; k < i; ++k)
      (ans += g[n - 1][i][k]) %= Mod;

  printf("%d\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>

inline int Get() {
  char ch;
  while ((ch = getchar()) < '0' || ch > '9')
    ;
  int Num = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    Num = (Num << 3) + (Num << 1) + ch - '0';
  return Num;
}
const int N = 55;
const int Mod = 1e9 + 7;
int n, a[N << 1], g[N][N << 1][N << 1], ans;
int main() {
  n = Get();
  for (int i = 1; i < n * 2; ++i)
    a[i] = Get();
  std ::sort(a + 1, a + n * 2);

  g[0][1][0] = 1;
  for (int i = 1, w; i < n; ++i)
    for (int j = 1; j < i * 2; ++j)
      for (int k = 0; k < j; ++k)
        if (w = g[i - 1][j][k]) {
          int x = j, y = k;
          if (a[n - i] != a[n - i + 1])
            ++x, ++y;
          if (a[n + i] != a[n + i - 1])
            ++x;
          for (int p = 0; p < x; ++p)
            (g[i][x - std ::max(abs(y - p) - 1, 0)][p <= y ? p : y + 1] += w) %=
                Mod;
        }

  for (int i = 1; i < n * 2; ++i)
    for (int k = 0; k < i; ++k)
      (ans += g[n - 1][i][k]) %= Mod;

  printf("%d\n", ans);
}
Problem p03772 (C++)

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

#define MOD 1000000007
inline void Add(int &x, int y) { x = (x + y >= MOD) ? (x + y - MOD) : (x + y); }

#define MAXN 50
#define MAXM (2 * MAXN - 1)
int N, M;
int A[MAXN + 5], dp[MAXN + 5][MAXM + 5][MAXM + 5];

int main() {
  scanf("%d", &N), M = 2 * N - 1;
  for (int i = 1; i <= M; i++)
    scanf("%d", A + i);
  sort(A + 1, A + M + 1);
  dp[N][0][0] = 1;
  for (int i = N; i >= 1; i--) {
    int L = A[i] != A[i - 1], R = A[M - i + 1] != A[M - i + 2];
    for (int j = 0; j <= M; j++) {
      for (int k = 0; k <= M; k++) {
        if (!dp[i][j][k])
          continue;
        Add(dp[i - 1][j + L][k + R], dp[i][j][k]);
        for (int p = 0; p < j + L; p++)
          Add(dp[i - 1][p][k + R + 1], dp[i][j][k]);
        for (int p = 0; p < k + R; p++)
          Add(dp[i - 1][j + L + 1][p], dp[i][j][k]);
      }
    }
  }
  int Ans = 0;
  for (int i = 0; i <= M; i++)
    for (int j = 0; j <= M; j++)
      Add(Ans, dp[1][i][j]);
  printf("%d\n", Ans);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

#define MOD 1000000007
inline void Add(int &x, int y) { x = (x + y >= MOD) ? (x + y - MOD) : (x + y); }

#define MAXN 50
#define MAXM (2 * MAXN - 1)
int N, M;
int A[MAXM + 5], dp[MAXN + 5][MAXM + 5][MAXM + 5];

int main() {
  scanf("%d", &N), M = 2 * N - 1;
  for (int i = 1; i <= M; i++)
    scanf("%d", A + i);
  sort(A + 1, A + M + 1);
  dp[N][0][0] = 1;
  for (int i = N; i >= 1; i--) {
    int L = A[i] != A[i - 1], R = A[M - i + 1] != A[M - i + 2];
    for (int j = 0; j <= M; j++) {
      for (int k = 0; k <= M; k++) {
        if (!dp[i][j][k])
          continue;
        Add(dp[i - 1][j + L][k + R], dp[i][j][k]);
        for (int p = 0; p < j + L; p++)
          Add(dp[i - 1][p][k + R + 1], dp[i][j][k]);
        for (int p = 0; p < k + R; p++)
          Add(dp[i - 1][j + L + 1][p], dp[i][j][k]);
      }
    }
  }
  int Ans = 0;
  for (int i = 0; i <= M; i++)
    for (int j = 0; j <= M; j++)
      Add(Ans, dp[1][i][j]);
  printf("%d\n", Ans);
}
Problem p03772 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 55, P = 1000000007;
int i, j, k, l, n, m, ans;
int a[N];
int f[N][N << 1][N << 1];
int main() {
  scanf("%d", &n);
  for (i = 1; i < 2 * n; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + n + n);
  f[1][0][0] = 1;
  for (i = 1; i < n; i++)
    for (j = 0; j < 2 * i; j++)
      for (k = 0; j + k < 2 * i; k++)
        if (f[i][j][k]) {
          int x = j, y = k;
          if (a[n - i] != a[n - i + 1])
            x++;
          if (a[n + i] != a[n + i - 1])
            y++;
          for (l = 0; l < x; l++)
            f[i + 1][l][y + 1] = (f[i + 1][l][y + 1] + f[i][j][k]) % P;
          for (l = 0; l < y; l++)
            f[i + 1][x + 1][l] = (f[i + 1][x + 1][l] + f[i][j][k]) % P;
          f[i + 1][x][y] = (f[i + 1][x][y] + f[i][j][k]) % P;
        }
  for (i = 0; i < 2 * n; i++)
    for (j = 0; i + j < 2 * n; j++)
      ans = (ans + f[n][i][j]) % P;
  printf("%d\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 55, P = 1000000007;
int i, j, k, l, n, m, ans;
int a[N << 1];
int f[N][N << 1][N << 1];
int main() {
  scanf("%d", &n);
  for (i = 1; i < 2 * n; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + n + n);
  f[1][0][0] = 1;
  for (i = 1; i < n; i++)
    for (j = 0; j < 2 * i; j++)
      for (k = 0; j + k < 2 * i; k++)
        if (f[i][j][k]) {
          int x = j, y = k;
          if (a[n - i] != a[n - i + 1])
            x++;
          if (a[n + i] != a[n + i - 1])
            y++;
          for (l = 0; l < x; l++)
            f[i + 1][l][y + 1] = (f[i + 1][l][y + 1] + f[i][j][k]) % P;
          for (l = 0; l < y; l++)
            f[i + 1][x + 1][l] = (f[i + 1][x + 1][l] + f[i][j][k]) % P;
          f[i + 1][x][y] = (f[i + 1][x][y] + f[i][j][k]) % P;
        }
  for (i = 0; i < 2 * n; i++)
    for (j = 0; i + j < 2 * n; j++)
      ans = (ans + f[n][i][j]) % P;
  printf("%d\n", ans);
}
Problem p03772 (C++)

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

using namespace std;

#define N 60

const int mod = 1000000007;
int n, ans, a[N], b[N], c[N], f[N][N][N], g[N];

void upd(int &x, int y) { x = (x + y) % mod; }

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 2 - 1; ++i)
    scanf("%d", a + i);
  sort(a + 1, a + n * 2);
  for (int i = n - 1; i; --i)
    g[i] += a[i] != a[i + 1];
  for (int i = n + 1; i <= n * 2 - 1; ++i)
    g[i] += a[i] != a[i - 1];
  f[0][0][0] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= i * 2; ++j)
      for (int k = 0; k <= i * 2; ++k) {
        upd(f[i][j + g[n - i]][k + g[n + i]], f[i - 1][j][k]);
        for (int l = 1; l <= j; ++l)
          upd(f[i][j + g[n - i] - l][k + g[n + i] + 1], f[i - 1][j][k]);
        for (int l = 1; l <= k; ++l)
          upd(f[i][j + g[n - i] + 1][k + g[n + i] - l], f[i - 1][j][k]);
      }
  for (int i = 0; i <= n * 2; ++i)
    for (int j = 0; j <= n * 2; ++j)
      upd(ans, f[n][i][j]);
  printf("%d\n", ans);

  return 0;
}


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

using namespace std;

#define N 120

const int mod = 1000000007;
int n, ans, a[N], b[N], c[N], f[N][N][N], g[N];

void upd(int &x, int y) { x = (x + y) % mod; }

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 2 - 1; ++i)
    scanf("%d", a + i);
  sort(a + 1, a + n * 2);
  for (int i = n - 1; i; --i)
    g[i] += a[i] != a[i + 1];
  for (int i = n + 1; i <= n * 2 - 1; ++i)
    g[i] += a[i] != a[i - 1];
  f[0][0][0] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= i * 2; ++j)
      for (int k = 0; k <= i * 2; ++k) {
        upd(f[i][j + g[n - i]][k + g[n + i]], f[i - 1][j][k]);
        for (int l = 1; l <= j; ++l)
          upd(f[i][j + g[n - i] - l][k + g[n + i] + 1], f[i - 1][j][k]);
        for (int l = 1; l <= k; ++l)
          upd(f[i][j + g[n - i] + 1][k + g[n + i] - l], f[i - 1][j][k]);
      }
  for (int i = 0; i <= n * 2; ++i)
    for (int j = 0; j <= n * 2; ++j)
      upd(ans, f[n][i][j]);
  printf("%d\n", ans);

  return 0;
}
Problem p03773 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int A, B;

int main() {
  cin >> A >> B;
  out(A % B);
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int A, B;

int main() {
  cin >> A >> B;
  out((A + B) % 24);
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  pair<long long, long long> a[n], b[n];
  for (long long i = 0; i < n; i++)
    cin >> a[i].first >> a[i].second;
  for (long long i = 0; i < m; i++)
    cin >> b[i].first >> b[i].second;
  for (long long i = 0; i < n; i++) {
    vector<pair<long long, long long>> vc;
    for (long long j = 0; j < m; j++) {
      long long d =
          abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second);
      vc.push_back(make_pair(d, j + 1));
    }
    sort(vc.begin(), vc.end());
    cout << vc[0].second << endl;
    ;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  pair<long long, long long> a[n], b[m];
  for (long long i = 0; i < n; i++)
    cin >> a[i].first >> a[i].second;
  for (long long i = 0; i < m; i++)
    cin >> b[i].first >> b[i].second;
  for (long long i = 0; i < n; i++) {
    vector<pair<long long, long long>> vc;
    for (long long j = 0; j < m; j++) {
      long long d =
          abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second);
      vc.push_back(make_pair(d, j + 1));
    }
    sort(vc.begin(), vc.end());
    cout << vc[0].second << endl;
    ;
  }
  return 0;
}
Problem p03774 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(n), l(n);
  int kyo;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < n; i++) {
    int kyo = 400000001;
    for (int j = 0; j < m; j++) {
      if (kyo > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        kyo = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        l[i] = j + 1;
      }
    }
    cout << l[i] << endl;
  }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m), l(n);
  int kyo;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < n; i++) {
    int kyo = 400000001;
    for (int j = 0; j < m; j++) {
      if (kyo > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        kyo = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        l[i] = j + 1;
      }
    }
    cout << l[i] << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h> //1
using namespace std;     // 2
int solve() {            // 3
} // 4
int main() {                             // 5
  int n, m;                              // 7
  cin >> n >> m;                         // 8
  vector<pair<long long, long long>> ab; // 1
  vector<pair<long long, long long>> cd; // 2
  for (int i = 0; i < n; ++i) {          // 3
    cin >> ab[i].first >> ab[i].second;  // 4 これあってるのか？
  }                                      // 5 あってるきがします…！
  for (int i = 0; i < m; ++i) {          // 7
    cin >> cd[i].first >> cd[i].second;  // 8
  }                                      // 1
  for (int i = 0; i < n; ++i) {          // 2
    int ans = -1, dist = 1e8;            // 3
    for (int j = 0; j < m; j++) {        // 4
      if (abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second) <
          dist) { // 5
        ans = j, dist = abs(ab[i].first - cd[j].first) +
                        abs(ab[i].second - cd[j].second); // 7
      }                                                   // 8 ifの}
    }                                                     // 1 ひゃ
    cout << ans + 1 << endl;                              // 2　
    if ("true" == "true") {                               // 3
    }                                                     // 4 こらこら
  }                                                       // 5
} // 7 end

Fixed submission:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const ll MOD = 1e9 + 7;

int main(int argc, char const *argv[]) {

  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> students(n);
  vector<pair<ll, ll>> checkpoints(m);
  rep(i, n) { cin >> students[i].first >> students[i].second; }
  rep(i, m) { cin >> checkpoints[i].first >> checkpoints[i].second; }
  rep(i, n) {
    ll mindist = (1ll << 60);
    int ans = -1;
    rep(j, m) {
      ll curdist = labs(students[i].first - checkpoints[j].first) +
                   labs(students[i].second - checkpoints[j].second);
      // cerr << i << " " << j << " " << curdist << endl;
      if (curdist < mindist) {
        mindist = curdist;
        ans = j;
      }
    }
    cout << ans + 1 << endl;
  }
  return 0;
}
Problem p03774 (C++)

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

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

  int n, m;
  cin >> n >> m;
  vector<int> A(n), B(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
  }
  vector<int> C(n), D(n);
  for (int i = 0; i < m; i++) {
    cin >> C[i] >> D[i];
  }

  for (int i = 0; i < n; i++) {
    int mini = 1e9, p;
    for (int j = 0; j < m; j++) {
      int cost = abs(A[i] - C[j]) + abs(B[i] - D[j]);
      if (mini > cost) {
        p = j + 1;
        mini = cost;
      }
    }
    cout << p << endl;
  }

  return 0;
}

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

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

  int n, m;
  cin >> n >> m;
  vector<int> A(n), B(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
  }
  vector<int> C(m), D(m);
  for (int i = 0; i < m; i++) {
    cin >> C[i] >> D[i];
  }

  for (int i = 0; i < n; i++) {
    int mini = 1e9, p;
    for (int j = 0; j < m; j++) {
      int cost = abs(A[i] - C[j]) + abs(B[i] - D[j]);
      if (mini > cost) {
        p = j + 1;
        mini = cost;
      }
    }
    cout << p << endl;
  }

  return 0;
}
Problem p03774 (C++)

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

#define ll long long

template <typename T> void drop(const T &x) {
  cout << x << endl;
  exit(0);
}

int man(int x1, int x2, int y1, int y2) { return abs(x1 - x2) + abs(y1 - y2); }

void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n), b(m);
  for (int i = 0; i < n; ++i)
    cin >> a.at(i).first >> a.at(i).second;
  for (int i = 0; i < m; ++i)
    cin >> b.at(i).first >> b.at(i).second;

  for (int i = 0; i < n; ++i) {
    int min = 100, d, ans = 0;
    for (int j = 0; j < n; ++j) {
      d = man(a.at(i).first, b.at(j).first, a.at(i).second, b.at(j).second);
      if (min > d) {
        min = d;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    solve();

  return 0;
}


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

#define ll long long

template <typename T> void drop(const T &x) {
  cout << x << endl;
  exit(0);
}

int man(int x1, int x2, int y1, int y2) { return abs(x1 - x2) + abs(y1 - y2); }

void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n), b(m);
  for (int i = 0; i < n; ++i)
    cin >> a.at(i).first >> a.at(i).second;
  for (int i = 0; i < m; ++i)
    cin >> b.at(i).first >> b.at(i).second;

  for (int i = 0; i < n; ++i) {
    int min = 1e9, ans = 0;
    for (int j = 0; j < m; ++j) {
      int d = man(a.at(i).first, b.at(j).first, a.at(i).second, b.at(j).second);
      if (min > d) {
        min = d;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    solve();

  return 0;
}