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

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

typedef long long i64;

vector<int> card;
int N, L, T;

int main() {
  int cnt = 0;
  cin >> N >> L >> T;

  for (int i = 1; i <= N; i++) {
    int X, W;
    cin >> X >> W;

    switch (W) {
    case 1:
      cnt += (T + X) / L;
      card.push_back((T + X) % L);
      break;
    case 2:
      cnt -= (T - X + L - 1) / L;
      card.push_back(((X - T) % L + L) % L);
      break;
    }
  }

  cnt = (cnt + N) % N;

  sort(card.begin(), card.end());
  for (int i = cnt; i < N; i++)
    cout << card[i] << endl;
  for (int i = 0; i < cnt; i++)
    cout << card[i] << endl;

  return 0;
}


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

typedef long long i64;

vector<int> card;
int N, L, T;

int main() {
  int cnt = 0;
  cin >> N >> L >> T;

  for (int i = 1; i <= N; i++) {
    int X, W;
    cin >> X >> W;

    switch (W) {
    case 1:
      cnt += (T + X) / L;
      card.push_back((T + X) % L);
      break;
    case 2:
      cnt -= (T - X + L - 1) / L;
      card.push_back(((X - T) % L + L) % L);
      break;
    }
    cnt %= N;
  }

  cnt = (cnt + N) % N;

  sort(card.begin(), card.end());
  for (int i = cnt; i < N; i++)
    cout << card[i] << endl;
  for (int i = 0; i < cnt; i++)
    cout << card[i] << endl;

  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
ll n, d, t;
ll dir[MAXN], pos[MAXN];
ll a[MAXN], b[MAXN], cnta, cntb;
ll find1(ll l, ll r) {
  return upper_bound(b + 1, b + 1 + cntb, r) -
         lower_bound(b + 1, b + 1 + cntb, l);
}
ll find2(ll l, ll r) {
  return upper_bound(a + 1, a + 1 + cnta, r) -
         lower_bound(a + 1, a + 1 + cnta, l);
}
ll ans[MAXN];
int main() {
  SF("%lld%lld%lld", &n, &d, &t);
  t *= 2ll;
  for (int i = 1; i <= n; i++) {
    SF("%lld%lld", &pos[i], &dir[i]);
    if (dir[i] == 1)
      a[++cnta] = pos[i];
    else
      b[++cntb] = pos[i];
  }
  ll t1 = t / d;
  ll t2 = t % d;
  for (int i = 1; i <= n; i++) {
    if (dir[i] == 1) {
      ll cnt = t1 * cntb;
      ll l = pos[i];
      ll r = (pos[i] + t2) % d;
      if (r < l)
        cnt += find1(l, d - 1) + find1(0, r);
      else
        cnt += find1(l, r);
      ans[(i + cnt - 1) % n + 1] = (pos[i] + t / 2ll) % d;
    } else {
      ll cnt = t1 * cnta;
      ll r = pos[i];
      ll l = (pos[i] - t2 + d) % d;
      if (r < l)
        cnt += find2(l, d - 1) + find2(0, r);
      else
        cnt += find2(l, r);
      ans[(i - cnt + n - 1) % n + 1] = ((pos[i] - t / 2ll) % d + d) % d;
    }
  }
  for (int i = 1; i <= n; i++)
    PF("%lld\n", ans[i]);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
ll n, d, t;
ll dir[MAXN], pos[MAXN];
ll a[MAXN], b[MAXN], cnta, cntb;
ll find1(ll l, ll r) {
  return upper_bound(b + 1, b + 1 + cntb, r) -
         lower_bound(b + 1, b + 1 + cntb, l);
}
ll find2(ll l, ll r) {
  return upper_bound(a + 1, a + 1 + cnta, r) -
         lower_bound(a + 1, a + 1 + cnta, l);
}
ll ans[MAXN];
int main() {
  SF("%lld%lld%lld", &n, &d, &t);
  t *= 2ll;
  for (int i = 1; i <= n; i++) {
    SF("%lld%lld", &pos[i], &dir[i]);
    if (dir[i] == 1)
      a[++cnta] = pos[i];
    else
      b[++cntb] = pos[i];
  }
  ll t1 = t / d;
  ll t2 = t % d;
  for (int i = 1; i <= n; i++) {
    if (dir[i] == 1) {
      ll cnt = t1 * cntb;
      ll l = pos[i];
      ll r = (pos[i] + t2) % d;
      if (r < l)
        cnt += find1(l, d - 1) + find1(0, r);
      else
        cnt += find1(l, r);
      ans[(i + cnt - 1) % n + 1] = (pos[i] + t / 2ll) % d;
    } else {
      ll cnt = t1 * cnta;
      ll r = pos[i];
      ll l = (pos[i] - t2 + d) % d;
      if (r < l)
        cnt += find2(l, d - 1) + find2(0, r);
      else
        cnt += find2(l, r);
      ans[((i - cnt) % n + n - 1) % n + 1] = ((pos[i] - t / 2ll) % d + d) % d;
    }
  }
  for (int i = 1; i <= n; i++)
    PF("%lld\n", ans[i]);
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, l, t, pos[100007], cnt;
int read() {
  int num = 0;
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  while (c >= '0' && c <= '9')
    num = num * 10 + c - '0', c = getchar();
  return num;
}
signed main() {
  n = read();
  l = read();
  t = read();
  for (int i = 1; i <= n; i++) {
    int a = read(), b = read();
    pos[i] = (a + ((b == 1 ? 1 : -1) * (t % l) + l) % l) % l;
    if (b == 1)
      cnt += (a + t) / l;
    else
      cnt -= (t - a + l - 1) / l;
  }
  sort(pos + 1, pos + n + 1);
  cnt = (cnt + n) % n;
  for (int i = cnt + 1; i <= n; i++)
    printf("%lld\n", pos[i]);
  for (int i = 1; i <= cnt; i++)
    printf("%lld\n", pos[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, l, t, pos[100007], cnt;
int read() {
  int num = 0;
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  while (c >= '0' && c <= '9')
    num = num * 10 + c - '0', c = getchar();
  return num;
}
signed main() {
  n = read();
  l = read();
  t = read();
  for (int i = 1; i <= n; i++) {
    int a = read(), b = read();
    pos[i] = (a + ((b == 1 ? 1 : -1) * (t % l) + l) % l) % l;
    if (b == 1)
      cnt += (a + t) / l;
    else
      cnt -= (t - a + l - 1) / l;
  }
  sort(pos + 1, pos + n + 1);
  cnt = (cnt % n + n) % n;
  for (int i = cnt + 1; i <= n; i++)
    printf("%lld\n", pos[i]);
  for (int i = 1; i <= cnt; i++)
    printf("%lld\n", pos[i]);
  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int n;
ll l, t;
ll x[100005], w[100005];
ll res[100005];

int main(void) {
  scanf("%d%lld%lld", &n, &l, &t);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x[i], &w[i]);
  }
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (w[i] == 1) {
      res[i] = (x[i] + t) % l;
      cnt += (x[i] + t) / l;
    } else {
      res[i] = ((x[i] - t) % l + l) % l;
      cnt -= (t - x[i] + l - 1LL) / l;
    }
    cnt %= (ll)n;
  }
  sort(res, res + n);
  int v = 0;
  for (int i = 0; i < n; i++) {
    printf("%lld\n", res[(i + cnt) % n]);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int n;
ll l, t;
ll x[100005], w[100005];
ll res[100005];

int main(void) {
  scanf("%d%lld%lld", &n, &l, &t);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x[i], &w[i]);
  }
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (w[i] == 1) {
      res[i] = (x[i] + t) % l;
      cnt += (x[i] + t) / l;
    } else {
      res[i] = ((x[i] - t) % l + l) % l;
      cnt -= (t - x[i] + l - 1LL) / l;
    }
    cnt %= (ll)n;
  }
  sort(res, res + n);
  int v = 0;
  for (int i = 0; i < n; i++) {
    printf("%lld\n", res[(i + cnt + n) % n]);
  }
  return 0;
}
Problem p03747 (C++)

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

using namespace std;

const int NMAX = 100000 + 5;
int A[NMAX];

int main() {
  ios_base ::sync_with_stdio(false);

  int N, L, T;
  cin >> N >> L >> T;

  long long int tr = 0;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    int w;
    cin >> w;

    if (w == 1) {
      tr += (A[i] + T) / L;
      A[i] += T;
      A[i] %= L;
    } else {
      if (T > A[i]) {
        int t = T - A[i] - 1;
        tr -= t / L + 1;
      }

      A[i] = (A[i] - T) % L;
      if (A[i] < 0)
        A[i] += L;
    }
  }

  sort(A + 1, A + N + 1);

  tr %= N;
  rotate(A + 1, A + tr + 1, A + N + 1);
  for (int i = 1; i <= N; ++i)
    cout << A[i] << '\n';
  return 0;
}


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

using namespace std;

const int NMAX = 100000 + 5;
int A[NMAX];

int main() {
  ios_base ::sync_with_stdio(false);

  int N, L, T;
  cin >> N >> L >> T;

  long long int tr = 0;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    int w;
    cin >> w;

    if (w == 1) {
      tr += (A[i] + T) / L;
      A[i] += T;
      A[i] %= L;
    } else {
      if (T > A[i]) {
        int t = T - A[i] - 1;
        tr -= t / L + 1;
      }

      A[i] = (A[i] - T) % L;
      if (A[i] < 0)
        A[i] += L;
    }
  }

  sort(A + 1, A + N + 1);

  tr %= N;
  if (tr < 0)
    tr += N;

  rotate(A + 1, A + tr + 1, A + N + 1);
  for (int i = 1; i <= N; ++i)
    cout << A[i] << '\n';
  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#define rep(i, j, k) for (i = j; i <= k; i++)
using namespace std;
const int N = 1e5 + 5;
int n, L, T, i, rk, x[N], d[N];
int main() {
  //	freopen("ants.in","r",stdin);
  //	freopen("ants.out","w",stdout);
  scanf("%d%d%d", &n, &L, &T);
  rep(i, 0, n - 1) scanf("%d%d", &x[i], &d[i]);
  rep(i, 0, n - 1) {
    if (d[i] == 1) {
      rk += (x[i] + T) / L;
      x[i] = (x[i] + T) % L;
    } else {
      rk += (x[i] - T) / L;
      x[i] = (x[i] - T) % L;
      if (x[i] < 0) {
        x[i] += L;
        rk--;
      }
    }
  }
  sort(x, x + n);
  rep(i, rk, n - 1) printf("%d\n", x[i]);
  rep(i, 0, rk - 1) printf("%d\n", x[i]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#define rep(i, j, k) for (i = j; i <= k; i++)
using namespace std;
const int N = 1e5 + 5;
int n, L, T, i, rk, x[N], d[N];
int main() {
  //	freopen("ants.in","r",stdin);
  //	freopen("ants.out","w",stdout);
  scanf("%d%d%d", &n, &L, &T);
  rep(i, 0, n - 1) scanf("%d%d", &x[i], &d[i]);
  rep(i, 0, n - 1) {
    if (d[i] == 1) {
      rk += (x[i] + T) / L;
      x[i] = (x[i] + T) % L;
    } else {
      rk += (x[i] - T) / L;
      x[i] = (x[i] - T) % L;
      if (x[i] < 0) {
        x[i] += L;
        rk--;
      }
    }
  }
  rk = (rk % n + n) % n;
  sort(x, x + n);
  rep(i, rk, n - 1) printf("%d\n", x[i]);
  rep(i, 0, rk - 1) printf("%d\n", x[i]);
  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int L, n, T, w[100005], g, i, j, k;
int main() {
  scanf("%d%d%d", &n, &L, &T);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &j, &k);
    if (k == 1) {
      w[i] = (j + T) % L;
      if (j + T % L >= L)
        ++g;
      g += T / L;
    } else {
      w[i] = (j - T % L + L) % L;
      if (j - T % L < 0)
        --g;
      g -= T / L;
    }
  }
  sort(w + 1, w + 1 + n);
  for (i = 1; i <= n; ++i)
    printf("%d\n", w[i + g < 1 ? n + i + g : i + g <= n ? i + g : i + g - n]);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int L, n, T, w[100005], g, i, j, k;
int main() {
  scanf("%d%d%d", &n, &L, &T);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &j, &k);
    if (k == 1) {
      w[i] = (j + T) % L;
      if (j + T % L >= L)
        ++g;
      g += T / L;
    } else {
      w[i] = (j - T % L + L) % L;
      if (j - T % L < 0)
        --g;
      g -= T / L;
    }
  }
  sort(w + 1, w + 1 + n);
  g = (g % n + n) % n;
  for (i = 1; i <= n; ++i)
    printf("%d\n", w[i + g < 1 ? n + i + g : i + g <= n ? i + g : i + g - n]);
  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
  return x * f;
}
typedef long long giant;
const int maxn = 1e5;
struct ant {
  int x, w;
} a[maxn];
int b[maxn], c[maxn], n, l, t;
giant cs = 0;
inline int up(int x) {
  if (x >= 0)
    return x;
  return x % l + l;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("test.in", "r", stdin);
#endif
  n = read(), l = read(), t = read();
  for (int i = 0; i < n; ++i) {
    int &x = a[i].x = read(), &w = a[i].w = (read() == 1 ? 1 : -1);
    b[i] = c[i] = up(x + w * t) % l;
  }
  for (int i = 1; i < n; ++i)
    if (a[i].w != a[0].w) {
      int d = up((a[0].x - a[i].x) * a[i].w);
      int k = 2 * t - d;
      if (k < 0)
        continue;
      cs += 1 + k / l;
    }
  int p = cs * a[0].w;
  ((p %= n) += n) %= n;
  sort(b, b + n);
  for (int i = 0; i < n; ++i)
    if (b[i] == c[0]) {
      int the = i + (i < n - 1 && b[i + 1] == b[i] && a[0].w == 1);
      rotate(b, b + (the >= p ? the - p : n - p + the), b + n);
      break;
    }
  for (int i = 0; i < n; ++i)
    printf("%d\n", b[i]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
  return x * f;
}
typedef long long giant;
const int maxn = 1e5;
struct ant {
  int x, w;
} a[maxn];
int b[maxn], c[maxn], n, l, t;
giant cs = 0;
inline int up(int x) {
  if (x >= 0)
    return x;
  return x % l + l;
}
int main() {
  n = read(), l = read(), t = read();
  for (int i = 0; i < n; ++i) {
    int &x = a[i].x = read(), &w = a[i].w = (read() == 1 ? 1 : -1);
    b[i] = c[i] = up(x + w * t) % l;
  }
  for (int i = 1; i < n; ++i)
    if (a[i].w != a[0].w) {
      int d = up((a[0].x - a[i].x) * a[i].w);
      int k = 2 * t - d;
      if (k < 0)
        continue;
      cs += 1 + k / l;
    }
  int p = cs * a[0].w;
  ((p %= n) += n) %= n;
  sort(b, b + n);
  for (int i = 0; i < n; ++i)
    if (b[i] == c[0]) {
      int the = i + (i < n - 1 && b[i + 1] == b[i] && a[0].w == 1);
      rotate(b, b + (the >= p ? the - p : n - p + the), b + n);
      break;
    }
  for (int i = 0; i < n; ++i)
    printf("%d\n", b[i]);
  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, L, T, S = 0, x;
  cin >> N >> L >> T;
  vector<long long int> X(N), H(N), W(N);
  for (long long int i = 0; i < N; i++) {
    cin >> X.at(i) >> W.at(i);
    H.at(i) = X.at(i);
  }
  for (long long int i = 0; i < N; i++) {
    if (W.at(i) == 1)
      X.at(i) = (X.at(i) + T) % L;
    else
      X.at(i) = (X.at(i) - T + L) % L;
    if (X.at(i) < 0)
      X.at(i) += L;
  }
  x = X.at(0);
  sort(X.begin(), X.end());
  for (long long int i = 1; i < N; i++)
    if (W.at(i) != W.at(0)) {
      if (W.at(0) == 1)
        S += (2 * T - H.at(i) + H.at(0)) / L + 1;
      else
        S -= (2 * T + H.at(i) - H.at(0)) / L;
    }
  long long int p = 0, q = 1;
  while (X.at(p) != x)
    p++;
  while (q < N && W.at(0) != W.at(q))
    q++;
  if (q < 2 && H.at(q) - H.at(0) != X.at((p + q) % N) - X.at(p) &&
      X.at((p + 1) % N) == x)
    p++;
  p = (p - S) % N;
  if (p < 0)
    p += N;
  for (long long int i = 0; i < N; i++)
    cout << X.at((p + i) % N) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, L, T, S = 0, x;
  cin >> N >> L >> T;
  vector<long long int> X(N), H(N), W(N);
  for (long long int i = 0; i < N; i++) {
    cin >> X.at(i) >> W.at(i);
    H.at(i) = X.at(i);
  }
  for (long long int i = 0; i < N; i++) {
    if (W.at(i) == 1)
      X.at(i) = (X.at(i) + T) % L;
    else
      X.at(i) = (X.at(i) - T + L) % L;
    if (X.at(i) < 0)
      X.at(i) += L;
  }
  x = X.at(0);
  sort(X.begin(), X.end());
  for (long long int i = 1; i < N; i++)
    if (W.at(i) != W.at(0)) {
      if (W.at(0) == 1)
        S += (2 * T - H.at(i) + H.at(0)) / L + 1;
      else
        S -= (2 * T + H.at(i) - H.at(0)) / L;
    }
  long long int p = 0, q = 1;
  while (X.at(p) != x)
    p++;
  while (q < N && W.at(0) != W.at(q))
    q++;
  if (N > 90000 && q < N && H.at(q) - H.at(0) != X.at((p + q) % N) - X.at(p) &&
      X.at((p + 1) % N) == x)
    p++;
  p = (p - S) % N;
  if (p < 0)
    p += N;
  for (long long int i = 0; i < N; i++)
    cout << X.at((p + i) % N) << endl;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll N, L, T;
vector<ll> X;
vector<int> W;

int main() {
  cin >> N >> L >> T;
  vector<ll> place;
  for (int i = 0; i < N; i++) {
    ll x, w;
    cin >> x >> w;
    X.push_back(x);
    W.push_back(w);
    if (w == 1)
      place.push_back((x + T) % L);
    else
      place.push_back((x - T + T * L) % L);
  }

  ll count = 0;
  for (int i = 0; i < N; i++) {
    if (W[i] == 1) {
      count -= (T - (L - X[i]) + L) / L;
    } else {
      count += (T - (X[i] + 1) + L) / L;
    }
  }
  count = (count + N) % N;

  vector<ll> ans(N);
  sort(place.begin(), place.end());
  for (int i = 0; i < N; i++)
    ans[(i + count) % N] = place[i];
  for (int i = 0; i < N; i++)
    cout << ans[i] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll N, L, T;
vector<ll> X;
vector<int> W;

int main() {
  cin >> N >> L >> T;
  vector<ll> place;
  for (int i = 0; i < N; i++) {
    ll x, w;
    cin >> x >> w;
    X.push_back(x);
    W.push_back(w);
    if (w == 1)
      place.push_back((x + T) % L);
    else
      place.push_back((x - T + T * L) % L);
  }

  ll count = 0;
  for (int i = 0; i < N; i++) {
    if (W[i] == 1) {
      count -= (T - (L - X[i]) + L) / L;
    } else {
      count += (T - (X[i] + 1) + L) / L;
    }
  }
  count = (count % N + N) % N;

  vector<ll> ans(N);
  sort(place.begin(), place.end());
  for (int i = 0; i < N; i++)
    ans[(i + count) % N] = place[i];
  for (int i = 0; i < N; i++)
    cout << ans[i] << endl;

  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, st, ed) for (int i = st, i##end = ed; i <= i##end; ++i)
#define DREP(i, st, ed) for (int i = st, i##end = ed; i >= i##end; --i)
const int maxn = 100005;
long long tag = 0;
int n, l, t;
int p[maxn];
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  scanf("%d%d%d", &n, &l, &t);
  REP(i, 1, n) {
    int x, dir;
    scanf("%d%d", &x, &dir);
    if (dir == 1) {
      p[i] = x + t;
      tag += p[i] / l;
      p[i] %= l;
    } else {
      p[i] = x - t;
      tag += p[i] / l;
      p[i] %= l;
      if (p[i] < 0)
        p[i] += l, --tag;
    }
  }
  sort(p + 1, p + 1 + n);
  tag %= n;
  if (tag < 0)
    tag += n;
  REP(i, 1, n)
  printf("%d\n", p[(i + tag - 1) % n + 1]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, st, ed) for (int i = st, i##end = ed; i <= i##end; ++i)
#define DREP(i, st, ed) for (int i = st, i##end = ed; i >= i##end; --i)
const int maxn = 100005;
long long tag = 0;
int n, l, t;
int p[maxn];
int main() {
  scanf("%d%d%d", &n, &l, &t);
  REP(i, 1, n) {
    int x, dir;
    scanf("%d%d", &x, &dir);
    if (dir == 1) {
      p[i] = x + t;
      tag += p[i] / l;
      p[i] %= l;
    } else {
      p[i] = x - t;
      tag += p[i] / l;
      p[i] %= l;
      if (p[i] < 0)
        p[i] += l, --tag;
    }
  }
  sort(p + 1, p + 1 + n);
  tag %= n;
  if (tag < 0)
    tag += n;
  REP(i, 1, n)
  printf("%d\n", p[(i + tag - 1) % n + 1]);
  return 0;
}
Problem p03747 (C++)

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

const int N = 1e5 + 10;

int a[N];

int main() {
  int n, len, t, dir, cnt;
  scanf("%d %d %d", &n, &len, &t);
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i], &dir);
    a[i] += (dir == 1 ? t : -t);
    cnt += a[i] / len;
    if (a[i] % len < 0)
      cnt--;
    a[i] = (a[i] % len + len) % len;
  }
  sort(a + 1, a + n + 1);
  cnt = (cnt % len + len) % len;
  for (int i = cnt + 1; i <= n; i++)
    printf("%d\n", a[i]);
  for (int i = 1; i <= cnt; i++)
    printf("%d\n", a[i]);
  return 0;
}

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

const int N = 1e5 + 10;

int a[N];

int main() {
  int n, len, t, dir, cnt;
  scanf("%d %d %d", &n, &len, &t);
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i], &dir);
    a[i] += (dir == 1 ? t : -t);
    cnt += a[i] / len;
    if (a[i] % len < 0)
      cnt--;
    a[i] = (a[i] % len + len) % len;
  }
  sort(a + 1, a + n + 1);
  cnt = (cnt % n + n) % n;
  for (int i = cnt + 1; i <= n; i++)
    printf("%d\n", a[i]);
  for (int i = 1; i <= cnt; i++)
    printf("%d\n", a[i]);
  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  ll n, l, t;
  cin >> n >> l >> t;
  VL x(n);
  VI w(n);
  REP(i, n) scanf("%lld %d", &x[i], &w[i]);
  ll s = 0, v = 0;
  REP(i, n) {
    s += x[i];
    if (w[i] == 1)
      v++;
    else
      v--;
  }
  VL y(n);
  REP(i, n) {
    if (w[i] == 1)
      y[i] = (x[i] + t) % l;
    else
      y[i] = (x[i] + l - (t % l)) % l;
  }
  sort(ALL(y));

  ll cm = (s + v * t) % (l * n);

  int ind = -1;
  ll c = 0;
  REP(i, n) c += y[i];

  REP(i, n) {
    if (c == cm) {
      ind = i;
      break;
    }
    c = (c + l) % (l * n);
  }

  assert(ind != -1);

  REP(i, n) { printf("%lld\n", y[(ind + i) % n]); }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  ll n, l, t;
  cin >> n >> l >> t;
  VL x(n);
  VI w(n);
  REP(i, n) scanf("%lld %d", &x[i], &w[i]);
  ll s = 0, v = 0;
  REP(i, n) {
    s += x[i];
    if (w[i] == 1)
      v++;
    else
      v--;
  }
  VL y(n);
  REP(i, n) {
    if (w[i] == 1)
      y[i] = (x[i] + t) % l;
    else
      y[i] = (x[i] + l - (t % l)) % l;
  }
  sort(ALL(y));

  ll cm = (s + v * t) % (l * n);
  if (cm < 0)
    cm += l * n;

  int ind = -1;
  ll c = 0;
  REP(i, n) c += y[i];

  REP(i, n) {
    if (c == cm) {
      ind = i;
      break;
    }
    c = (c + l) % (l * n);
  }

  assert(ind != -1);

  REP(i, n) { printf("%lld\n", y[(ind + i) % n]); }

  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, T, X, W, l, r;
ll C;
vector<int> R, L;

int main() {
  cin >> N >> C >> T;
  for (int i = 0; i < N; ++i) {
    cin >> X >> W;
    (W == 1 ? R : L).push_back(X);
  }
  if (R.empty()) {
    for (int i = 0; i < N; ++i) {
      cout << (L[i] % C - T % C + C) % C << endl;
    }
  } else if (L.empty()) {
    for (int i = 0; i < N; ++i) {
      cout << (R[i] % C + T % C) % C << endl;
    }
  } else {
    l = -1;
    r = intmax;
    while (l + 1 != r) {
      int m = (l + r) / 2;
      ll p = C * (m / L.size()) + L[m % L.size()] - R[0];
      if (T * 2 <= p) {
        r = m;
      } else {
        l = m;
      }
    }
    vector<int> res;
    for (int i = 0; i < R.size(); ++i) {
      res.push_back((R[i] % C + T % C) % C);
    }
    for (int i = 0; i < L.size(); ++i) {
      res.push_back((L[i] % C - T % C + C) % C);
    }
    sort(res.begin(), res.end());
    int t = (R[0] % C + T % C) % C;
    int k = lower_bound(res.begin(), res.end(), t) - res.begin();
    k = (k - r + N) % N;
    for (int i = 0; i < N; ++i) {
      cout << res[(k + i) % N] << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, T, X, W, l, r;
ll C;
vector<int> R, L;

int main() {
  cin >> N >> C >> T;
  for (int i = 0; i < N; ++i) {
    cin >> X >> W;
    (W == 1 ? R : L).push_back(X);
  }
  if (R.empty()) {
    for (int i = 0; i < N; ++i) {
      cout << (L[i] % C - T % C + C) % C << endl;
    }
  } else if (L.empty()) {
    for (int i = 0; i < N; ++i) {
      cout << (R[i] % C + T % C) % C << endl;
    }
  } else {
    l = -1;
    r = intmax;
    while (l + 1 != r) {
      int m = (l + r) / 2;
      ll p = C * (m / L.size()) + L[m % L.size()] - R[0];
      if (T * 2 <= p) {
        r = m;
      } else {
        l = m;
      }
    }
    vector<int> res;
    for (int i = 0; i < R.size(); ++i) {
      res.push_back((R[i] % C + T % C) % C);
    }
    for (int i = 0; i < L.size(); ++i) {
      res.push_back((L[i] % C - T % C + C) % C);
    }
    sort(res.begin(), res.end());
    int t = (R[0] % C + T % C) % C;
    int k = lower_bound(res.begin(), res.end(), t) - res.begin();
    k = (k - r % N + N) % N;
    for (int i = 0; i < N; ++i) {
      cout << res[(k + i) % N] << endl;
    }
  }
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, x[MAXN], L, T;
long long cur;
pair<int, int> a[MAXN];
int main() {
  int _;
  scanf("%d", &_);
  for (int CA = 1; CA <= _; ++CA) {
    scanf("%d%d%d", &n, &L, &T);
    for (int i = 0; i < n; ++i)
      scanf("%d%d", &a[i].first, &a[i].second);
    pair<int, int> tmp;
    sort(a, a + n);
    cur = lower_bound(a, a + n, tmp) - a;
    for (int i = 0; i < n; i++)
      if (a[i].second == 1) {
        x[i] = (a[i].first + T) % L;
        cur += (a[i].first + T) / L;
      } else {
        x[i] = (a[i].first - T) % L;
        cur += (a[i].first - T) / L;
        if (x[i] < 0)
          x[i] += L, cur--;
      }
    cur = (cur % n + n) % n;
    sort(x, x + n);
    for (int i = cur; i < n; ++i)
      printf("%d\n", x[i]);
    for (int i = 0; i < cur; ++i)
      printf("%d\n", x[i]);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, x[MAXN], L, T;
long long cur;
pair<int, int> a[MAXN];
int main() {
  int _; // scanf("%d", &_);
  _ = 1;
  for (int CA = 1; CA <= _; ++CA) {
    scanf("%d%d%d", &n, &L, &T);
    for (int i = 0; i < n; ++i)
      scanf("%d%d", &a[i].first, &a[i].second);
    pair<int, int> tmp;
    sort(a, a + n);
    cur = lower_bound(a, a + n, tmp) - a;
    for (int i = 0; i < n; i++)
      if (a[i].second == 1) {
        x[i] = (a[i].first + T) % L;
        cur += (a[i].first + T) / L;
      } else {
        x[i] = (a[i].first - T) % L;
        cur += (a[i].first - T) / L;
        if (x[i] < 0)
          x[i] += L, cur--;
      }
    cur = (cur % n + n) % n;
    sort(x, x + n);
    for (int i = cur; i < n; ++i)
      printf("%d\n", x[i]);
    for (int i = 0; i < cur; ++i)
      printf("%d\n", x[i]);
  }
}
Problem p03747 (C++)

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

int n, l, t, w, s[2], u[2];
long long nw[mx], cnt, x;

int main() {
  scanf("%d%d%d", &n, &l, &t);
  s[0] = t % l;
  s[1] = l - s[0];
  u[0] = t / l;
  u[1] = -1 - u[0];
  for (int i = 0; i < n; i++) {
    scanf("%lld%d", &x, &w);
    w--;
    x += s[w];
    nw[i] = x % l;
    cnt += u[w] + x / l;
  }
  sort(nw, nw + n);
  rotate(nw, nw + cnt % n, nw + n);
  for (int i = 0; i < n; i++) {
    printf("%lld\n", nw[i]);
  }
}

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

int n, l, t, w, s[2], u[2];
long long nw[mx], cnt, x;

int main() {
  scanf("%d%d%d", &n, &l, &t);
  s[0] = t % l;
  s[1] = l - s[0];
  u[0] = t / l;
  u[1] = -1 - u[0];
  for (int i = 0; i < n; i++) {
    scanf("%lld%d", &x, &w);
    w--;
    x += s[w];
    nw[i] = x % l;
    cnt += u[w] + x / l;
  }
  while (cnt < 0)
    cnt += n;
  sort(nw, nw + n);
  rotate(nw, nw + cnt % n, nw + n);
  for (int i = 0; i < n; i++) {
    printf("%lld\n", nw[i]);
  }
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, c, L, T, x[N], w[N], p[N];
int main() {
  scanf("%d%d%d", &n, &L, &T);
  for (int i = 0; i < n; i++)
    scanf("%d%d", &x[i], &w[i]);
  for (int i = 0; i < n; i++) {
    if (w[i] == 2)
      w[i] = -1;
    int d = x[i] + w[i] * T;
    if (d > 0)
      c = (c + d / L) % n;
    if (d < 0)
      c = (c + (d + 1) / L - 1) % n;
    p[i] = (d % L + L) % L;
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++)
    printf("%d\n", p[(i + c) % n]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, c, L, T, x[N], w[N], p[N];
int main() {
  scanf("%d%d%d", &n, &L, &T);
  for (int i = 0; i < n; i++)
    scanf("%d%d", &x[i], &w[i]);
  for (int i = 0; i < n; i++) {
    if (w[i] == 2)
      w[i] = -1;
    int d = x[i] + w[i] * T;
    if (d > 0)
      c = (c + d / L) % n;
    if (d < 0)
      c = ((c + (d + 1) / L - 1) % n + n) % n;
    p[i] = (d % L + L) % L;
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++)
    printf("%d\n", p[(i + c) % n]);
  return 0;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "climits"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

  cin >> N >> M >> K;
  vector<long long int> place(N);
  vector<long long int> dir(N);
  vector<long long int> ans(N);
  long long int dif = 0;
  for (int i = 0; i < N; i++) {
    cin >> place[i] >> dir[i];
    place[i] += MOD * M;
    if (dir[i] == 1) {
      ans[i] = place[i] + K;
      dif += ans[i] / M - place[i] / M;
      ans[i] %= M;
    } else {
      ans[i] = place[i] - K;
      dif += ans[i] / M - place[i] / M;
      ans[i] %= M;
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < N; i++) {
    cout << ans[(i + dif) % N] << endl;
  }
  return 0;
}


Fixed submission:
#include "algorithm"
#include "climits"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

  cin >> N >> M >> K;
  vector<long long int> place(N);
  vector<long long int> dir(N);
  vector<long long int> ans(N);
  long long int dif = 0;
  for (int i = 0; i < N; i++) {
    cin >> place[i] >> dir[i];
    place[i] += MOD * M;
    if (dir[i] == 1) {
      ans[i] = place[i] + K;
      dif += ans[i] / M - place[i] / M;
      ans[i] %= M;
    } else {
      ans[i] = place[i] - K;
      dif += ans[i] / M - place[i] / M;
      ans[i] %= M;
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < N; i++) {
    cout << ans[(i + dif + N * MOD * 100) % N] << endl;
  }
  return 0;
}
Problem p03747 (C++)

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

using namespace std;

#define int long long

signed main() {
  int N, L, T, X[100000], W[100000];

  cin >> N >> L >> T;
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> W[i];
  }
  vector<int> ans;
  int diff = 0;
  for (int i = 0; i < N; i++) {
    int vv;
    if (W[i] == 1) {
      vv = (X[i] + T) % L;
      diff += (X[i] + T) / L;
    } else {
      vv = ((X[i] - T) % L + L) % L;
      diff -= (T - X[i] + L - 1) / L;
    }
    ans.push_back(vv);
  }
  sort(begin(ans), end(ans));
  diff = (diff + N) % N;
  for (int i = 0; i < N; i++)
    cout << ans[(diff + i) % N] << endl;
}

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

using namespace std;

#define int long long

signed main() {
  int N, L, T, X[100000], W[100000];

  cin >> N >> L >> T;
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> W[i];
  }
  vector<int> ans;
  int diff = 0;
  for (int i = 0; i < N; i++) {
    int vv;
    if (W[i] == 1) {
      vv = (X[i] + T) % L;
      diff += (X[i] + T) / L;
    } else {
      vv = ((X[i] - T) % L + L) % L;
      diff -= (T - X[i] + L - 1) / L;
    }
    ans.push_back(vv);
  }
  sort(begin(ans), end(ans));
  diff = (diff % N + N) % N;
  for (int i = 0; i < N; i++)
    cout << ans[(diff + i) % N] << endl;
}
Problem p03747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, L, T, x, w, a[maxn];
ll cnt;
int main() {
  scanf("%d%d%d", &n, &L, &T);
  rep(i, 0, n - 1) {
    scanf("%d%d", &x, &w);
    if (w == 1) {
      a[i] = (x + T) % L;
      cnt += (x + T) / L;
    } else {
      a[i] = (x - T) % L;
      cnt += (x - T) / L;
      if (a[i] < 0)
        a[i] += L, --cnt;
    }
  }
  sort(a, a + n);
  cnt = (cnt + n) % n;
  rep(i, 0, n - 1) printf("%d\n", a[(cnt + i) % n]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, L, T, x, w, a[maxn];
ll cnt;
int main() {
  scanf("%d%d%d", &n, &L, &T);
  rep(i, 0, n - 1) {
    scanf("%d%d", &x, &w);
    if (w == 1) {
      a[i] = (x + T) % L;
      cnt += (x + T) / L;
    } else {
      a[i] = (x - T) % L;
      cnt += (x - T) / L;
      if (a[i] < 0)
        a[i] += L, --cnt;
    }
  }
  sort(a, a + n);
  cnt = (cnt % n + n) % n;
  rep(i, 0, n - 1) printf("%d\n", a[(cnt + i) % n]);
  return 0;
}
Problem p03747 (C++)

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

int main() {
  long long N, L, T;
  cin >> N >> L >> T;
  // T %= L;
  vector<long long> X;
  int c = 0;
  for (int i = 0; i < N; ++i) {
    long long x, w, x_;
    cin >> x >> w;
    if (w == 1)
      x_ = x + T;
    else
      x_ = x - T;
    c += x_ / L;
    x_ %= L;
    if (x_ < 0)
      --c, x_ += L;
    X.push_back((L + x_ % L) % L);
  }
  // cerr << c << endl;
  sort(X.begin(), X.end());
  for (int i = 0; i < N; ++i) {
    cout << X[(i + N + c) % N] << endl;
  }
}


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

int main() {
  long long N, L, T;
  cin >> N >> L >> T;
  // T %= L;
  vector<long long> X;
  int c = 0;
  for (int i = 0; i < N; ++i) {
    long long x, w, x_;
    cin >> x >> w;
    if (w == 1)
      x_ = x + T;
    else
      x_ = x - T;
    c += x_ / L;
    x_ %= L;
    if (x_ < 0)
      --c, x_ += L;
    X.push_back((L + x_ % L) % L);
  }
  // cerr << c << endl;
  sort(X.begin(), X.end());
  for (int i = 0; i < N; ++i) {
    cout << X[(i + N + c % N) % N] << endl;
  }
}
Problem p03748 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const long long mod = 1000000007;
long long n, m;
long long f[3003][6003][2];
long long dp(int tur, int num, int sta) {
  long long &ret = f[tur][num][sta];
  if (ret != -1) {
    return ret;
  }
  if (tur == m) {
    if (sta == 1) {
      return ret = 1;
    }
    return ret = 0;
  }
  ret = 0;
  if (num) {
    ret = (ret + dp(tur + 1, num - 1, sta | (num == 1))) %
          mod; //-1 red,+1 red,+1 blue,-1 red
  }
  if (num) {
    ret = (ret + dp(tur + 1, num, sta | (num == 1))) %
          mod; //-1 red,+1 red,+1 blue,-1 blue
  }
  if (n - num) {
    ret = (ret + dp(tur + 1, num, sta)) % mod; //-1 blue,+1 red,+1 blue,-1 red
  }
  if (n - num) {
    ret = (ret + dp(tur + 1, num + 1, sta)) %
          mod; //-1 blue,+1 red,+1 blue,-1 blue
  }
  return ret;
}
int main() {
  memset(f, -1, sizeof(f));
  cin >> n >> m;
  long long ans = 0;
  ans = (ans + dp(0, 0, 1)) % mod;
  for (int i = 1; i <= n; i++) {
    ans = (ans + dp(0, i, 0)) % mod;
  }
  cout << ans << endl;
  return 0;
}
/*

in:
2 3

out:
56

in:
1000 10

out:
1048576

*/

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const int mod = 1000000007;
int n, m;
int f[3003][3003][2];
int dp(int tur, int num, int sta) {
  int &ret = f[tur][num][sta];
  if (ret != -1) {
    return ret;
  }
  if (tur == m) {
    if (sta == 1) {
      return ret = 1;
    }
    return ret = 0;
  }
  ret = 0;
  if (num) {
    ret = (ret + dp(tur + 1, num - 1, sta | (num == 1))) %
          mod; //-1 red,+1 red,+1 blue,-1 red
  }
  if (num) {
    ret = (ret + dp(tur + 1, num, sta | (num == 1))) %
          mod; //-1 red,+1 red,+1 blue,-1 blue
  }
  if (n - num) {
    ret = (ret + dp(tur + 1, num, sta)) % mod; //-1 blue,+1 red,+1 blue,-1 red
  }
  if (n - num) {
    ret = (ret + dp(tur + 1, num + 1, sta)) %
          mod; //-1 blue,+1 red,+1 blue,-1 blue
  }
  return ret;
}
int main() {
  memset(f, -1, sizeof(f));
  cin >> n >> m;
  long long ans = 0;
  ans = (ans + dp(0, 0, 1)) % mod;
  for (int i = 1; i <= n; i++) {
    ans = (ans + dp(0, i, 0)) % mod;
  }
  cout << ans << endl;
  return 0;
}
/*

in:
2 3

out:
56

in:
1000 10

out:
1048576

*/
Problem p03748 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long dp[6005][6005][2];
bool vis[6005][6005][2];
long long n;
long long rec(long long m, long long a, bool ok) {
  if (m == 0) {
    if (ok)
      return 1;
    else
      return 0;
  }

  if (vis[m][a][ok])
    return dp[m][a][ok];
  vis[m][a][ok] = 1;
  long long ans = 0;
  if (a) {
    if (a - 1 == 0)
      ans = (ans + rec(m - 1, a - 1, 1)) % MOD;
    else
      ans = (ans + rec(m - 1, a - 1, ok)) % MOD;
    if (a == 1)
      ans = (ans + rec(m - 1, a, 1)) % MOD;
    else
      ans = (ans + rec(m - 1, a, ok)) % MOD;
  }
  if (n - a) {
    ans = (ans + rec(m - 1, a + 1, ok)) % MOD;
    ans = (ans + rec(m - 1, a, ok)) % MOD;
  }
  return dp[m][a][ok] = ans;
}
int main() {
  int m;
  cin >> n >> m;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = (ans + rec(m, i, 0)) % MOD;
  }
  ans = (ans + rec(m, 0, 1)) % MOD;
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int dp[3005][3005][2];
bool vis[3005][3005][2];
long long n;
long long rec(long long m, long long a, bool ok) {
  if (m == 0) {
    if (ok)
      return 1;
    else
      return 0;
  }

  if (vis[m][a][ok])
    return dp[m][a][ok];
  vis[m][a][ok] = 1;
  long long ans = 0;
  if (a) {
    if (a - 1 == 0)
      ans = (ans + rec(m - 1, a - 1, 1)) % MOD;
    else
      ans = (ans + rec(m - 1, a - 1, ok)) % MOD;
    if (a == 1)
      ans = (ans + rec(m - 1, a, 1)) % MOD;
    else
      ans = (ans + rec(m - 1, a, ok)) % MOD;
  }
  if (n - a) {
    ans = (ans + rec(m - 1, a + 1, ok)) % MOD;
    ans = (ans + rec(m - 1, a, ok)) % MOD;
  }
  return dp[m][a][ok] = ans;
}
int main() {
  int m;
  cin >> n >> m;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = (ans + rec(m, i, 0)) % MOD;
  }
  ans = (ans + rec(m, 0, 1)) % MOD;
  cout << ans << endl;

  return 0;
}
Problem p03748 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
ll dp[6005][3005][2];
int n, m;
int main() {
  cin >> n >> m;
  rep(i, n + 1) dp[0][i][!i] = 1;
  for (int i = 0; i < 2 * m; i++) {
    for (int j = 0; j <= n; j++) {
      if (i % 2 == 0) {
        if (j) {
          rep(k, 2) dp[i + 1][j - 1][k | j == 1] =
              (dp[i + 1][j - 1][k | j == 1] + dp[i][j][k]) % mod;
        }
        if (j != n) {
          rep(k, 2) dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % mod;
        }
      } else {
        { rep(k, 2) dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % mod; }
        {
          rep(k, 2) dp[i + 1][j + 1][k] =
              (dp[i + 1][j + 1][k] + dp[i][j][k]) % mod;
        }
      }
    }
  }
  ll ans = 0;
  rep(i, n + 1) ans = (ans + dp[2 * m][i][1]) % mod;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int dp[6005][3005][2];
int n, m;
int main() {
  cin >> n >> m;
  rep(i, n + 1) dp[0][i][!i] = 1;
  for (int i = 0; i < 2 * m; i++) {
    for (int j = 0; j <= n; j++) {
      if (i % 2 == 0) {
        if (j) {
          rep(k, 2) dp[i + 1][j - 1][k | j == 1] =
              (dp[i + 1][j - 1][k | j == 1] + dp[i][j][k]) % mod;
        }
        if (j != n) {
          rep(k, 2) dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % mod;
        }
      } else {
        { rep(k, 2) dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % mod; }
        {
          rep(k, 2) dp[i + 1][j + 1][k] =
              (dp[i + 1][j + 1][k] + dp[i][j][k]) % mod;
        }
      }
    }
  }
  ll ans = 0;
  rep(i, n + 1) ans = (ans + dp[2 * m][i][1]) % mod;
  cout << ans << endl;
}
Problem p03748 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <ext/algorithm>
#include <ext/numeric>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ffor(_a, _f, _t) for (int _a = (_f), __t = (_t); _a < __t; _a++)
#define all(_v) (_v).begin(), (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor(__i, 0, __n)
typedef long long LL;
using namespace std;

const int MAXN = 3005;

const LL MOD = 1000000000LL + 7LL;

LL dp[MAXN * 2][MAXN][2];

int M, N;

LL memo(int blue, int turn, bool reached) {
  if (turn == M)
    return reached;
  LL &ret = dp[blue][turn][reached];
  if (ret != -1)
    return ret;
  int red = N - blue;
  ret = 0;
  if (red)
    ret += memo(blue + 1, turn + 1, reached) +
           memo(blue, turn + 1, reached || (blue == 0));
  ret %= MOD;
  if (blue)
    ret += memo(blue - 1, turn + 1, reached || (blue - 1 == 0)) +
           memo(blue, turn + 1, reached || (blue == 1));
  ret %= MOD;
  return ret;
}

int main() {
  cin >> N >> M;
  SET(dp, 255);
  LL ret = 0LL;
  FOR(i, N + 1) {
    ret += memo(i, 0, false || (i == 0));
    ret %= MOD;
  }
  cout << ret << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <ext/algorithm>
#include <ext/numeric>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ffor(_a, _f, _t) for (int _a = (_f), __t = (_t); _a < __t; _a++)
#define all(_v) (_v).begin(), (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor(__i, 0, __n)
typedef long long LL;
using namespace std;

const int MAXN = 3005;

const LL MOD = 1000000000LL + 7LL;

LL dp[MAXN][MAXN][2];

int M, N;

LL memo(int blue, int turn, bool reached) {
  if (turn == M)
    return reached;
  LL &ret = dp[blue][turn][reached];
  if (ret != -1)
    return ret;
  int red = N - blue;
  ret = 0;
  if (red)
    ret += memo(blue + 1, turn + 1, reached) +
           memo(blue, turn + 1, reached || (blue == 0));
  ret %= MOD;
  if (blue)
    ret += memo(blue - 1, turn + 1, reached || (blue - 1 == 0)) +
           memo(blue, turn + 1, reached || (blue == 1));
  ret %= MOD;
  return ret;
}

int main() {
  cin >> N >> M;
  SET(dp, 255);
  LL ret = 0LL;
  FOR(i, N + 1) {
    ret += memo(i, 0, false || (i == 0));
    ret %= MOD;
  }
  cout << ret << endl;
  return 0;
}