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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  vector<ll> ki, gu;
  ll kiki = 0, gugu = 0;
  rep(i, n) {
    if (i % 2 && a[i] > 0) {
      ki.push_back(i);
      kiki += a[i];
    }
    if (i % 2 == 0 && a[i] > 0) {
      gu.push_back(i);
      gugu += a[i];
    }
  }
  int last = n;
  if (gugu > kiki) {
    swap(kiki, gugu);
    swap(ki, gu);
  }
  vector<int> ans;
  if (kiki >= gugu) {
    cout << kiki << endl;
    int last = ki[ki.size() - 1] + 1;
    int now = n;
    for (int i = now; i > last; i--) {
      ans.push_back(i);
    }
    for (int i = 1; i <= ki[0]; i++) {
      ans.push_back(1);
    }
    rep(i, ki.size() - 1) {
      for (int j = (ki[i + 1] - ki[i]) / 2; j > 0; j--) {
        ans.push_back(j + 1);
      }
    }
  }
  cout << ans.size() << endl;
  for (auto k : ans) {
    cout << k << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  vector<ll> ki, gu;
  ll kiki = 0, gugu = 0;
  rep(i, n) {
    if (i % 2 && a[i] > 0) {
      ki.push_back(i);
      kiki += a[i];
    }
    if (i % 2 == 0 && a[i] > 0) {
      gu.push_back(i);
      gugu += a[i];
    }
  }
  int last = n;
  if (gugu > kiki) {
    swap(kiki, gugu);
    swap(ki, gu);
  }
  vector<int> ans;
  if (kiki == 0 && gugu == 0) {
    ll ma = -longinf;
    int mai;
    rep(i, n) {
      if (a[i] > ma) {
        ma = a[i];
        mai = i;
      }
    }
    cout << ma << endl;
    cout << n - 1 << endl;
    for (int i = n; i > mai + 1; i--) {
      cout << i << endl;
    }
    for (int i = 1; i <= mai; i++) {
      cout << 1 << endl;
    }
    return 0;
  }
  if (kiki >= gugu) {
    cout << kiki << endl;
    int last = ki[ki.size() - 1] + 1;
    int now = n;
    for (int i = now; i > last; i--) {
      ans.push_back(i);
    }
    for (int i = 1; i <= ki[0]; i++) {
      ans.push_back(1);
    }
    rep(i, ki.size() - 1) {
      for (int j = (ki[i + 1] - ki[i]) / 2; j > 0; j--) {
        ans.push_back(j + 1);
      }
    }
  }
  cout << ans.size() << endl;
  for (auto k : ans) {
    cout << k << endl;
  }
}
Problem p03413 (C++)

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

using namespace std;
typedef long long ll;
const int inf = 1e9 + 10;
const int maxN = 1005;
int pos, p[2][maxN], a[maxN], N, tot, ans[maxN];
ll res[2];
void solve() {
  // for(int i = 1; i <= p[pos][0]; ++i) {
  //	cout << p[pos][i]<<' '<<a[p[pos][i]]<<"******"<<endl;
  // }
  for (int i = 1; i < p[pos][1]; ++i)
    ans[++tot] = 1;
  for (int i = N; i > p[pos][p[pos][0]]; --i)
    ans[++tot] = i - (p[pos][1] - 1);
  for (int i = 1; i < p[pos][0]; ++i) {
    int sz = (p[pos][i + 1] - p[pos][i]) / 2;
    for (int j = sz + 1; j > 1; --j)
      ans[++tot] = j;
  }
}
int main() {
  a[0] = -inf;
  int idx = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &a[i]);
    if (a[i] > a[idx])
      idx = i;
  }
  if (a[idx] <= 0) {
    pos = 0;
    res[0] = a[idx];
    p[0][++p[0][0]] = a[idx];
  } else {
    for (int i = 1; i <= N; i += 2)
      if (a[i] > 0)
        res[0] += a[i], p[0][++p[0][0]] = i;
    for (int i = 2; i <= N; i += 2)
      if (a[i] > 0)
        res[1] += a[i], p[1][++p[1][0]] = i;
    pos = (res[0] > res[1]) ? 0 : 1;
  }
  solve();
  printf("%lld\n%d\n", res[pos], tot);
  for (int i = 1; i <= tot; ++i)
    printf("%d\n", ans[i]);
  return 0;
}

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

using namespace std;
typedef long long ll;
const int inf = 1e9 + 10;
const int maxN = 1005;
int pos, p[2][maxN], a[maxN], N, tot, ans[maxN];
ll res[2];
void solve() {
  // for(int i = 1; i <= p[pos][0]; ++i) {
  //	cout << p[pos][i]<<' '<<a[p[pos][i]]<<"******"<<endl;
  // }
  for (int i = 1; i < p[pos][1]; ++i)
    ans[++tot] = 1;
  for (int i = N; i > p[pos][p[pos][0]]; --i)
    ans[++tot] = i - (p[pos][1] - 1);
  for (int i = 1; i < p[pos][0]; ++i) {
    int sz = (p[pos][i + 1] - p[pos][i]) / 2;
    for (int j = sz + 1; j > 1; --j)
      ans[++tot] = j;
  }
}
int main() {
  a[0] = -inf;
  int idx = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &a[i]);
    if (a[i] > a[idx])
      idx = i;
  }
  if (a[idx] <= 0) {
    pos = 0;
    res[0] = a[idx];
    p[0][++p[0][0]] = idx;
  } else {
    for (int i = 1; i <= N; i += 2)
      if (a[i] > 0)
        res[0] += a[i], p[0][++p[0][0]] = i;
    for (int i = 2; i <= N; i += 2)
      if (a[i] > 0)
        res[1] += a[i], p[1][++p[1][0]] = i;
    pos = (res[0] > res[1]) ? 0 : 1;
  }
  solve();
  printf("%lld\n%d\n", res[pos], tot);
  for (int i = 1; i <= tot; ++i)
    printf("%d\n", ans[i]);
  return 0;
}
Problem p03413 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#ifdef _DEBUG_
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int MAXN = 1000 + 10;
const ll INF = 1e17;
int a[MAXN];
ll dp[MAXN][MAXN];

ll f(int l, int r) {
  assert(l % 2 == r % 2);
  if (dp[l][r] != -INF)
    return dp[l][r];
  ll &res = dp[l][r];
  if (l == r)
    return res = a[l];
  if (a[r] > 0)
    return res = f(l, r - 2) + a[r];
  else
    return res = f(l, r - 2);
}

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      dp[i][j] = -INF;
  ll bst = -INF;
  PII bst_f;
  for (int i = 1; i <= N; i++)
    for (int j = i; j <= N; j += 2) {
      ll tmp = f(i, j);
      if (tmp > bst) {
        bst = tmp;
        bst_f = MP(i, j);
      }
    }
  assert(a[bst_f.S] > 0);
  VI op;
  for (int i = N; i > bst_f.S; i--)
    op.PB(i);
  for (int i = bst_f.S - 2; i > bst_f.F; i -= 2) {
    if (a[i] > 0)
      op.PB(i + 1);
    else
      op.PB(i);
  }
  if (bst_f.S != bst_f.F)
    op.PB(bst_f.F + 1);
  for (int i = 1; i < bst_f.F; i++)
    op.PB(1);
  printf("%lld\n", bst);
  printf("%d\n", SZ(op));
  for (int u : op)
    printf("%d\n", u);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#ifdef _DEBUG_
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int MAXN = 1000 + 10;
const ll INF = 1e17;
int a[MAXN];
ll dp[MAXN][MAXN];

ll f(int l, int r) {
  assert(l % 2 == r % 2);
  if (dp[l][r] != -INF)
    return dp[l][r];
  ll &res = dp[l][r];
  if (l == r)
    return res = a[l];
  if (a[r] > 0)
    return res = f(l, r - 2) + a[r];
  else
    return res = f(l, r - 2);
}

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      dp[i][j] = -INF;
  ll bst = -INF;
  PII bst_f;
  for (int i = 1; i <= N; i++)
    for (int j = i; j <= N; j += 2) {
      ll tmp = f(i, j);
      if (tmp > bst) {
        bst = tmp;
        bst_f = MP(i, j);
      }
    }
  // assert(a[bst_f.S] > 0);
  VI op;
  for (int i = N; i > bst_f.S; i--)
    op.PB(i);
  for (int i = bst_f.S - 2; i > bst_f.F; i -= 2) {
    if (a[i] > 0)
      op.PB(i + 1);
    else
      op.PB(i);
  }
  if (bst_f.S != bst_f.F)
    op.PB(bst_f.F + 1);
  for (int i = 1; i < bst_f.F; i++)
    op.PB(1);
  printf("%lld\n", bst);
  printf("%d\n", SZ(op));
  for (int u : op)
    printf("%d\n", u);
  return 0;
}
Problem p03413 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, a[3000];
signed main() {
  cin >> n;
  bool f = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i], f |= a[i] > 0;
  if (!f) {
    int ans = -(1ll << 60), id = 0;
    for (int i = 1; i <= n; i++)
      ans = max(ans, a[i]), id = ans == a[i] ? i : id;
    cout << ans << endl << n - 1 << endl;
    for (int i = 1; i < n; i++)
      cout << (i >= id ? n - i + 1 : 1) << endl;
    return 0;
  }
  int odd = 0, even = 0;
  for (int i = 1; i <= n; i++)
    (i & 1 ? odd : even) += max(0ll, a[i]);
  list<int> v, op;
  for (int i = 1; i <= n; i++)
    v.emplace_back(a[i] > 0 && (i & 1) == (odd > even));
  while (v.size() > 1) {
    while (!v.back())
      op.push_back(v.size()), v.pop_back();
    while (!v.front())
      op.push_back(1), v.pop_front();
    int pos = 2;
    if (v.size() > 2)
      for (auto i = ++v.begin(); i != --v.end(); i++, pos++) {
        auto k = i--, j = k++;
        if ((*i && *k) || (!*i && !*j && !*k)) {
          op.push_back(pos);
          *j = *i || *k;
          v.erase(i);
          v.erase(k);
          break;
        }
      }
  }
  cout << max(odd, even) << endl << op.size() << endl;
  for (int i : op)
    cout << i << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, a[3000];
signed main() {
  cin >> n;
  bool f = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i], f |= a[i] > 0;
  if (!f) {
    int ans = -(1ll << 60), id = 0;
    for (int i = 1; i <= n; i++)
      ans = max(ans, a[i]), id = ans == a[i] ? i : id;
    cout << ans << endl << n - 1 << endl;
    for (int i = 1; i < n; i++)
      cout << (i >= id ? n - i + 1 : 1) << endl;
    return 0;
  }
  int odd = 0, even = 0;
  for (int i = 1; i <= n; i++)
    (i & 1 ? odd : even) += max(0ll, a[i]);
  list<int> v, op;
  for (int i = 1; i <= n; i++)
    v.emplace_back(a[i] > 0 && (i & 1) == (odd > even));
  while (v.size() > 1) {
    while (!v.back())
      op.push_back(v.size()), v.pop_back();
    while (!v.front())
      op.push_back(1), v.pop_front();
    int pos = 2;
    if (v.size() > 2)
      for (auto i = ++v.begin(); i != --v.end(); i++, pos++) {
        auto k = i--, j = k++;
        if ((*i && *k) || (!*i && !*j && !*k)) {
          op.push_back(pos);
          *j = *i || *k;
          v.erase(i);
          v.erase(k);
          break;
        }
        i++;
      }
  }
  cout << max(odd, even) << endl << op.size() << endl;
  for (int i : op)
    cout << i << endl;
  return 0;
}
Problem p03414 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
#define all(x) x.begin(), x.end()
#define mem(a, k) memset(a, k, sizeof(a))
#define lop(i, s, t) for (int i = s; i < (t); ++i)
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
using namespace std;
typedef long long ll;
const int N = 1005, M = N * N;
vector<int> g[N];
int n, m, ans[M], vis[N], clk;
int a[M], b[M], tim[N], del;
void dfs(int v) {
  vis[v] = clk;
  for (int d : g[v]) {
    if ((!vis[d]) && d != del)
      dfs(d);
  }
}
void gao(int x) {
  del = x;
  mem(vis, 0);
  clk = 0;
  for (int d : g[x]) {
    ++clk;
    tim[d] = clk;
    if (!vis[d])
      dfs(d);
  }
  rep(i, 1, m) if (a[i] == x && vis[b[i]] != tim[b[i]]) ans[i] = 1;
}
int main(int argc, char *argv[]) {
  scanf("%d%d", &n, &m);
  rep(i, 1, m) {
    scanf("%d%d", a + i, b + i);
    g[a[i]].pb(b[i]);
  }
  rep(x, 1, n) {
    gao(x);
    reverse(all(g[x]));
    gao(x);
  }
  rep(x, 1, n) {
    del = 0;
    mem(vis, 0);
    dfs(x);
    rep(i, 1, m) if (b[i] == x) ans[i] ^= vis[a[i]];
  }
  rep(i, 1, m) printf("%s\n", ans[i] ? "diff" : "same");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
#define all(x) x.begin(), x.end()
#define mem(a, k) memset(a, k, sizeof(a))
#define lop(i, s, t) for (int i = s; i < (t); ++i)
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
using namespace std;
typedef long long ll;
const int N = 1005, M = N * N;
vector<int> g[N];
int n, m, ans[M], vis[N], clk;
int a[M], b[M], tim[N], del;
void dfs(int v) {
  vis[v] = clk;
  for (int d : g[v]) {
    if ((!vis[d]) && d != del)
      dfs(d);
  }
}
void gao(int x) {
  del = x;
  mem(vis, 0);
  clk = 0;
  for (int d : g[x]) {
    ++clk;
    tim[d] = clk;
    if (!vis[d])
      dfs(d);
  }
  rep(i, 1, m) if (a[i] == x && vis[b[i]] != tim[b[i]]) ans[i] = 1;
}
int main(int argc, char *argv[]) {
  scanf("%d%d", &n, &m);
  rep(i, 1, m) {
    scanf("%d%d", a + i, b + i);
    g[a[i]].pb(b[i]);
  }
  rep(x, 1, n) {
    gao(x);
    reverse(all(g[x]));
    gao(x);
  }
  rep(x, 1, n) {
    del = 0, clk = 1;
    mem(vis, 0);
    dfs(x);
    rep(i, 1, m) if (b[i] == x) ans[i] ^= vis[a[i]];
  }
  rep(i, 1, m) printf("%s\n", ans[i] ? "diff" : "same");
  return 0;
}
Problem p03414 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int N = 1005;

int n, m;
int ans[N], t[N][N], tt[N], b[N * 200], a[N * 200];

int D, del, clk, vis[N];
void dfs(int u) {
  if (vis[u])
    return;
  if (u == del)
    return;
  vis[u] = clk;
  for (int i = 1; i <= tt[u]; i++)
    dfs(b[t[u][i]]);
}

void work(int u) {
  del = u;
  memset(vis, 0, sizeof(vis));
  for (int v, i = 1; i <= tt[u]; i++) {
    clk = v = b[t[u][i]];
    dfs(v);
  }
  for (int v, i = 1; i <= tt[u]; i++) {
    v = b[t[u][i]];
    if (v != vis[v])
      ans[t[u][i]] = 1;
  }
}

int main() {
  scanf("%d%d", &n, &m);
  for (int u, v, i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    a[i] = u, b[i] = v;
    t[u][++tt[u]] = i;
  }

  for (int u = 1; u <= n; u++) {
    work(u);
    for (int i = 1; i <= tt[u] / 2; i++)
      swap(t[u][i], t[u][tt[u] - i + 1]);
    work(u);
  }

  for (int u = 1; u <= n; u++) {
    memset(vis, 0, sizeof(vis));
    clk = 1;
    del = 0;
    dfs(u);
    for (int i = 1; i <= m; i++)
      if (b[i] == u)
        ans[i] ^= vis[a[i]];
  }

  for (int i = 1; i <= m; i++)
    if (ans[i])
      puts("diff");
    else
      puts("same");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int N = 1005;

int n, m;
int ans[N * 200], t[N][N], tt[N], b[N * 200], a[N * 200];

int D, del, clk, vis[N];
void dfs(int u) {
  if (vis[u])
    return;
  if (u == del)
    return;
  vis[u] = clk;
  for (int i = 1; i <= tt[u]; i++)
    dfs(b[t[u][i]]);
}

void work(int u) {
  del = u;
  memset(vis, 0, sizeof(vis));
  for (int v, i = 1; i <= tt[u]; i++) {
    clk = v = b[t[u][i]];
    dfs(v);
  }
  for (int v, i = 1; i <= tt[u]; i++) {
    v = b[t[u][i]];
    if (v != vis[v])
      ans[t[u][i]] = 1;
  }
}

int main() {
  scanf("%d%d", &n, &m);
  for (int u, v, i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    a[i] = u, b[i] = v;
    t[u][++tt[u]] = i;
  }

  for (int u = 1; u <= n; u++) {
    work(u);
    for (int i = 1; i <= tt[u] / 2; i++)
      swap(t[u][i], t[u][tt[u] - i + 1]);
    work(u);
  }

  for (int u = 1; u <= n; u++) {
    memset(vis, 0, sizeof(vis));
    clk = 1;
    del = 0;
    dfs(u);
    for (int i = 1; i <= m; i++)
      if (b[i] == u)
        ans[i] ^= vis[a[i]];
  }

  for (int i = 1; i <= m; i++)
    if (ans[i])
      puts("diff");
    else
      puts("same");
  return 0;
}
Problem p03414 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#define M 200000
#define N 1001
using namespace std;
int a[N], b[M], c[M], d[M], e[N][N], f[N][N], m, n;
bool x[N];
inline bool cmp(int u, int v) {
  return b[u] == b[v] ? c[u] < c[v] : b[u] < b[v];
}
void dfs(int u, int *w) {
  for (int i = a[u - 1]; i < a[u]; i++)
    if (!w[b[i]])
      w[b[i]] = w[u], dfs(b[i], w);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    scanf("%d%d", b + i, c + i), a[b[d[i] = i]]++;
  sort(d, d + m, cmp);
  for (int i = 1; i <= n; i++)
    a[i] += a[i - 1], e[i][i] = f[i][i] = -1;
  for (int i = 0; i < m; i++)
    b[i] = c[d[i]];
  for (int i = 0; i < m; i++)
    c[i] = d[i];
  for (int i = 1; i <= n; i++)
    for (int j = a[i - 1]; j < a[i]; j++)
      if (!e[i][b[j]])
        dfs(e[i][b[j]] = b[j], e[i]);
  for (int i = 1; i <= n; i++)
    for (int j = a[i]; a[i - 1] < j--;)
      if (!f[i][b[j]])
        dfs(f[i][b[j]] = b[j], f[i]);
  for (int i = 1; i <= n; i++)
    for (int j = a[i - 1]; j < a[i]; j++)
      x[c[j]] = (bool)e[b[j]][i] ^ e[i][b[j]] == f[i][b[j]];
  for (int i = 0; i < m; i++)
    puts(x[i] ? "same" : "diff");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#define M 200000
#define N 1001
using namespace std;
int a[N], b[M], c[M], d[M], e[N][N], f[N][N], m, n;
bool x[M];
inline bool cmp(int u, int v) {
  return b[u] == b[v] ? c[u] < c[v] : b[u] < b[v];
}
void dfs(int u, int *w) {
  for (int i = a[u - 1]; i < a[u]; i++)
    if (!w[b[i]])
      w[b[i]] = w[u], dfs(b[i], w);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    scanf("%d%d", b + i, c + i), a[b[d[i] = i]]++;
  sort(d, d + m, cmp);
  for (int i = 1; i <= n; i++)
    a[i] += a[i - 1], e[i][i] = f[i][i] = -1;
  for (int i = 0; i < m; i++)
    b[i] = c[d[i]];
  for (int i = 0; i < m; i++)
    c[i] = d[i];
  for (int i = 1; i <= n; i++)
    for (int j = a[i - 1]; j < a[i]; j++)
      if (!e[i][b[j]])
        dfs(e[i][b[j]] = b[j], e[i]);
  for (int i = 1; i <= n; i++)
    for (int j = a[i]; a[i - 1] < j--;)
      if (!f[i][b[j]])
        dfs(f[i][b[j]] = b[j], f[i]);
  for (int i = 1; i <= n; i++)
    for (int j = a[i - 1]; j < a[i]; j++)
      x[c[j]] = (bool)e[b[j]][i] ^ e[i][b[j]] == f[i][b[j]];
  for (int i = 0; i < m; i++)
    puts(x[i] ? "same" : "diff");
  return 0;
}
Problem p03414 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2010, M = 2e5 + 10;
struct node {
  int to, num;
};
vector<node> v[N];
int n, m, ans[N][2], vis[N], num[N], q[M];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back((node){y, i});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      num[j] = 0;
    int hd = 1, tl = 0;
    for (int j = 0; j < v[i].size(); j++)
      num[v[i][j].to] = v[i][j].num, q[++tl] = v[i][j].to;
    while (hd <= tl) {
      int s1 = q[hd++], z = num[s1];
      for (int j = 0; j < v[s1].size(); j++) {
        int s2 = v[s1][j].to;
        if (s2 == i)
          ans[v[s1][j].num][0] = 1;
        else if (num[s2] != -1) {
          if (!num[s2])
            num[s2] = z, q[++tl] = s2;
          else if (num[s2] != z)
            num[s2] = -1, q[++tl] = s2;
        }
      }
    }
    for (int j = 0; j < v[i].size(); j++)
      ans[v[i][j].num][1] |= num[v[i][j].to] == -1;
  }
  for (int i = 1; i <= m; i++)
    printf("%s\n", ans[i][0] == ans[i][1] ? "same" : "diff");
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2010, M = 2e5 + 10;
struct node {
  int to, num;
};
vector<node> v[N];
int n, m, ans[M][2], num[N], q[M * 10];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back((node){y, i});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      num[j] = 0;
    int hd = 1, tl = 0;
    for (int j = 0; j < v[i].size(); j++)
      num[v[i][j].to] = v[i][j].num, q[++tl] = v[i][j].to;
    while (hd <= tl) {
      int s1 = q[hd++], z = num[s1];
      for (int j = 0; j < v[s1].size(); j++) {
        int s2 = v[s1][j].to;
        if (s2 == i)
          ans[v[s1][j].num][0] = 1;
        else if (num[s2] != -1) {
          if (!num[s2])
            num[s2] = z, q[++tl] = s2;
          else if (num[s2] != z)
            num[s2] = -1, q[++tl] = s2;
        }
      }
    }
    for (int j = 0; j < v[i].size(); j++)
      ans[v[i][j].num][1] |= num[v[i][j].to] == -1;
  }
  for (int i = 1; i <= m; i++)
    printf("%s\n", ans[i][0] == ans[i][1] ? "same" : "diff");
}
Problem p03414 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define p_b push_back
#define rep(i, s, t) for (i = s; i <= t; ++i)
#define dep(i, s, t) for (i = s; i >= t; --i)

using namespace std;

const int N = 1010;
int n, m;
vector<int> e[N], id[N], _e[N], _id[N];
int p[2][N];
bool w[N];
bool ans[20010];

void dfs(int u, int id, int o) {
  p[o][u] = id;
  for (int i = 0; i < e[u].size(); ++i)
    if (!p[o][e[u][i]])
      dfs(e[u][i], id, o);
}

void dfs2(int u) {
  w[u] = 1;
  for (int i = 0; i < e[u].size(); ++i)
    if (!w[e[u][i]])
      dfs2(e[u][i]);
}

int main() {
  int i, j, x, y;
  scanf("%d%d", &n, &m);
  rep(i, 1, m) {
    scanf("%d%d", &x, &y);
    e[x].p_b(y);
    id[x].p_b(i);
    _e[y].p_b(x);
    _id[y].p_b(i);
  }
  rep(i, 1, n) {
    memset(p, 0, sizeof p);
    p[0][i] = p[1][i] = n + 1;
    for (j = 0; j < e[i].size(); ++j)
      if (!p[0][e[i][j]])
        dfs(e[i][j], id[i][j], 0);
    for (j = e[i].size() - 1u; ~j; --j)
      if (!p[1][e[i][j]])
        dfs(e[i][j], id[i][j], 1);
    //		rep(j, 1, n) printf("%d ", p[0][j]); puts("");
    //		rep(j, 1, n) printf("%d ", p[1][j]); puts("");

    for (j = 0; j < e[i].size(); ++j)
      if (p[0][e[i][j]] != id[i][j] || p[1][e[i][j]] != id[i][j])
        ans[id[i][j]] ^= 1;
  }
  rep(i, 1, n) {
    memset(w, 0, sizeof w);
    dfs2(i);

    for (j = 0; j < _e[i].size(); ++j)
      if (w[_e[i][j]])
        ans[_id[i][j]] ^= 1;
  }
  rep(i, 1, m) if (ans[i]) puts("diff");
  else puts("same");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define p_b push_back
#define rep(i, s, t) for (i = s; i <= t; ++i)
#define dep(i, s, t) for (i = s; i >= t; --i)

using namespace std;

const int N = 1010;
int n, m;
vector<int> e[N], id[N], _e[N], _id[N];
int p[2][N];
bool w[N];
bool ans[200010];

void dfs(int u, int id, int o) {
  p[o][u] = id;
  for (int i = 0; i < e[u].size(); ++i)
    if (!p[o][e[u][i]])
      dfs(e[u][i], id, o);
}

void dfs2(int u) {
  w[u] = 1;
  for (int i = 0; i < e[u].size(); ++i)
    if (!w[e[u][i]])
      dfs2(e[u][i]);
}

int main() {
  int i, j, x, y;
  scanf("%d%d", &n, &m);
  rep(i, 1, m) {
    scanf("%d%d", &x, &y);
    e[x].p_b(y);
    id[x].p_b(i);
    _e[y].p_b(x);
    _id[y].p_b(i);
  }
  rep(i, 1, n) {
    memset(p, 0, sizeof p);
    p[0][i] = p[1][i] = n + 1;
    for (j = 0; j < e[i].size(); ++j)
      if (!p[0][e[i][j]])
        dfs(e[i][j], id[i][j], 0);
    for (j = e[i].size() - 1u; ~j; --j)
      if (!p[1][e[i][j]])
        dfs(e[i][j], id[i][j], 1);
    //		rep(j, 1, n) printf("%d ", p[0][j]); puts("");
    //		rep(j, 1, n) printf("%d ", p[1][j]); puts("");

    for (j = 0; j < e[i].size(); ++j)
      if (p[0][e[i][j]] != id[i][j] || p[1][e[i][j]] != id[i][j])
        ans[id[i][j]] ^= 1;
  }
  rep(i, 1, n) {
    memset(w, 0, sizeof w);
    dfs2(i);

    for (j = 0; j < _e[i].size(); ++j)
      if (w[_e[i][j]])
        ans[_id[i][j]] ^= 1;
  }
  rep(i, 1, m) if (ans[i]) puts("diff");
  else puts("same");
  return 0;
}
Problem p03414 (C++)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n, m;
vector<ll> g[1010];
vector<P> es;
ll cnt[1010][1010];
bool vis[1010];

void dfs(ll v, ll st) {
  vis[v] = true;
  cnt[st][v]++;
  for (ll nv : g[v]) {
    if (vis[nv] || nv == st)
      continue;
    dfs(nv, st);
  }
}

int main() {
  cin >> n >> m;
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    es.push_back(P(a, b));
  }

  rep(i, n) {
    for (ll v : g[i]) {
      memset(vis, 0, sizeof(vis));
      dfs(v, i);
    }
  }

  rep(i, m) {
    ll a = cnt[es[i].fi][es[i].se];
    ll b = cnt[es[i].se][es[i].fi];
    if ((a >= 2 && b >= 1) || (a < 2 && b < 1))
      cout << "same" << endl;
    else
      cout << "diff" << endl;
  }
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n, m;
vector<ll> g[1010];
vector<P> es;
ll cnt[1010][1010];
bool vis[1010];

void dfs(ll v, ll st) {
  vis[v] = true;
  cnt[st][v]++;
  for (ll nv : g[v]) {
    if (vis[nv] || nv == st || cnt[st][nv] >= 2)
      continue;
    dfs(nv, st);
  }
}

int main() {
  cin >> n >> m;
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    es.push_back(P(a, b));
  }

  rep(i, n) {
    for (ll v : g[i]) {
      memset(vis, 0, sizeof(vis));
      dfs(v, i);
    }
  }

  rep(i, m) {
    ll a = cnt[es[i].fi][es[i].se];
    ll b = cnt[es[i].se][es[i].fi];
    if ((a >= 2 && b >= 1) || (a < 2 && b < 1))
      cout << "same" << endl;
    else
      cout << "diff" << endl;
  }
  return 0;
}
Problem p03414 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int MAXN = 1005, MAXM = 20005;

int N, M;
vector<int> adj[MAXN];
int E[MAXM][2];

int p[MAXN][MAXN], q[MAXN][MAXN];
bool vis[MAXN];

void mark(int s, int u, int id, int mk[]) {
  if (u == s || vis[u])
    return;
  vis[u] = true;
  mk[u] = id;
  for (int i = 0; i < (int)adj[u].size(); i++)
    mark(s, adj[u][i], id, mk);
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1, a, b; i <= M; i++) {
    scanf("%d%d", &a, &b);
    E[i][0] = a;
    E[i][1] = b;
    adj[a].push_back(b);
  }

  for (int i = 1; i <= N; i++) {
    memset(vis, 0, sizeof vis);
    int id = 0;
    for (int j = 0; j < (int)adj[i].size(); j++)
      mark(i, adj[i][j], ++id, p[i]);
    memset(vis, 0, sizeof vis);
    reverse(adj[i].begin(), adj[i].end());
    id = adj[i].size();
    for (int j = 0; j < (int)adj[i].size(); j++)
      mark(i, adj[i][j], id--, q[i]);
  }

  for (int i = 1; i <= M; i++)
    if ((p[E[i][1]][E[i][0]] > 0) ==
        (p[E[i][0]][E[i][1]] != q[E[i][0]][E[i][1]]))
      puts("same");
    else
      puts("diff");

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int MAXN = 1005, MAXM = 200005;

int N, M;
vector<int> adj[MAXN];
int E[MAXM][2];

int p[MAXN][MAXN], q[MAXN][MAXN];
bool vis[MAXN];

void mark(int s, int u, int id, int mk[]) {
  if (u == s || vis[u])
    return;
  vis[u] = true;
  mk[u] = id;
  for (int i = 0; i < (int)adj[u].size(); i++)
    mark(s, adj[u][i], id, mk);
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1, a, b; i <= M; i++) {
    scanf("%d%d", &a, &b);
    E[i][0] = a;
    E[i][1] = b;
    adj[a].push_back(b);
  }

  for (int i = 1; i <= N; i++) {
    memset(vis, 0, sizeof vis);
    int id = 0;
    for (int j = 0; j < (int)adj[i].size(); j++)
      mark(i, adj[i][j], ++id, p[i]);
    memset(vis, 0, sizeof vis);
    reverse(adj[i].begin(), adj[i].end());
    id = adj[i].size();
    for (int j = 0; j < (int)adj[i].size(); j++)
      mark(i, adj[i][j], id--, q[i]);
  }

  for (int i = 1; i <= M; i++)
    if ((p[E[i][1]][E[i][0]] > 0) ==
        (p[E[i][0]][E[i][1]] != q[E[i][0]][E[i][1]]))
      puts("same");
    else
      puts("diff");

  return 0;
}
Problem p03415 (C++)

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

int main() {
  vector<char> a(9);
  for (int i = 0; i < 9; i++) {
    cin >> a.at(i);
  }
  cout << a.at(1) << a.at(5) << a.at(9) << endl;
}

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

int main() {
  vector<char> a(9);
  for (int i = 0; i < 9; i++) {
    cin >> a.at(i);
  }
  cout << a.at(0) << a.at(4) << a.at(8) << endl;
}
Problem p03415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long LL;
const int N = 1e5;
using namespace std;

int main() {
  char a[4][4];
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++i)
      cin >> a[i][i];
  }
  cout << a[1][1] << a[2][2] << a[3][3];
  return 0;
}

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

int main() {
  char a1, a2, a3, a4, a5, a6, a7, a8, a9;
  cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6 >> a7 >> a8 >> a9;
  cout << a1 << a5 << a9;
  return 0;
}
Problem p03415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++i) {
      char c;
      cin >> c;
      if (i == j) {
        cout << c;
      }
    }
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      char c;
      cin >> c;
      if (i == j) {
        cout << c;
      }
    }
  }
  cout << endl;
  return 0;
}
Problem p03415 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t, u;
  cin >> s, t, u;
  cout << s.at(0) << t.at(1) << u.at(2) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t, u;
  cin >> s >> t >> u;
  cout << s.at(0) << t.at(1) << u.at(2) << endl;
}
Problem p03415 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.at(4) << s.at(8) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<char> s(9);
  for (int i = 0; i < 9; ++i)
    cin >> s.at(i);
  cout << s.at(0) << s.at(4) << s.at(8) << endl;
}
Problem p03415 (C++)

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

int main() {
  vector<char> a(9);
  for (int i = 0; i < 9; i++) {
    cin >> a.at(i);
  }
  cout << a.at(1) << a.at(5) << a.at(9) << endl;
}


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

int main() {
  vector<char> a(9);
  for (int i = 0; i < 9; i++) {
    cin >> a.at(i);
  }
  cout << a.at(0) << a.at(4) << a.at(8) << endl;
}
Problem p03415 (C++)

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

int main() {
  vector<vector<char>> vec(3, vector<char>(3));

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> vec.at(i).at(j);
    }
  }

  cout << vec.at(1).at(1) << vec.at(2).at(2) << vec.at(3).at(3) << endl;
}

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

int main() {
  vector<vector<char>> vec(3, vector<char>(3));

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> vec.at(i).at(j);
    }
  }

  for (int i = 0; i < 3; i++) {
    cout << vec.at(i).at(i);
  }
}
Problem p03415 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;

  cout << a.at(1) << b.at(2) << c.at(3) << endl;

  return 0;
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;

  cout << a.at(0) << b.at(1) << c.at(2) << endl;

  return 0;
}
Problem p03415 (C++)

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

using namespace std;

int main() {
  string s1[3];
  string s2[3];
  string s3[3];
  cin >> s1[3] >> s2[3] >> s3[3];
  cout << s1[0] << s2[1] << s3[2] << endl;
}

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

using namespace std;

int main() {
  string s1;
  string s2;
  string s3;
  cin >> s1 >> s2 >> s3;
  cout << s1[0] << s2[1] << s3[2] << endl;
}
Problem p03415 (C++)

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

int main() {
  vector<string> C(3);
  for (int i = 0; i < 3; i++) {
    cin >> C.at(i);
    cout << C.at(i).at(i + 1);
  }
}

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

int main() {
  vector<string> C(3);
  for (int i = 0; i < 3; i++) {
    cin >> C.at(i);
    cout << C.at(i).at(i);
  }
}
Problem p03415 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

  // start
  vector<char> v1, v2, v3;
  rep(i, 3) cin >> v1.at(i);
  rep(i, 3) cin >> v2.at(i);
  rep(i, 3) cin >> v3.at(i);
  cout << v1.at(0) << v2.at(1) << v3.at(2) << endl;
  // end

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

  // start
  vector<char> v1(3), v2(3), v3(3);
  rep(i, 3) cin >> v1.at(i);
  rep(i, 3) cin >> v2.at(i);
  rep(i, 3) cin >> v3.at(i);
  cout << v1.at(0) << v2.at(1) << v3.at(2) << endl;
  // end

  return 0;
}
Problem p03415 (C++)

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

int main() {
  vector<char> a;
  for (int i = 0; i < 9; i++) {
    cin >> a.at(i);
  }
  cout << a.at(0) << a.at(4) << a.at(8) << endl;
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << endl;
}
Problem p03415 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.at(4) << s.at(8) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t, r;
  cin >> s >> t >> r;
  cout << s.at(0) << t.at(1) << r.at(2) << endl;
}
Problem p03415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
char A[4][4];
int main() {
  while (1) {
    scanf(" %c%c%c", &A[1][1], &A[1][2], &A[1][3]);
    scanf(" %c%c%c", &A[2][1], &A[2][2], &A[2][3]);
    scanf(" %c%c%c", &A[3][1], &A[3][2], &A[3][3]);
    printf("%c%c%c\n", A[1][1], A[2][2], A[3][3]);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
char A[4][4];
int main() {
  while (scanf(" %c%c%c %c%c%c %c%c%c", &A[1][1], &A[1][2], &A[1][3], &A[2][1],
               &A[2][2], &A[2][3], &A[3][1], &A[3][2], &A[3][3]) != EOF) {
    printf("%c%c%c\n", A[1][1], A[2][2], A[3][3]);
  }
}
Problem p03415 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s, t, c;
  cin >> s >> t >> c;
  cout << s.at(1) << t.at(2) << c.at(3);

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2];

  return 0;
}
Problem p03415 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  vector<char> c1, c2, c3;
  rep(i, 3) cin >> c1.at(i);
  rep(i, 3) cin >> c2.at(i);
  rep(i, 3) cin >> c3.at(i);
  cout << c1.at(0) << c2.at(1) << c3.at(2) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  string c1, c2, c3;
  cin >> c1;
  cin >> c2;
  cin >> c3;
  cout << c1.at(0) << c2.at(1) << c3.at(2) << endl;
}
Problem p03415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  for (int i = 0;;) {
    char c;
    cin >> c;
    if (i % 4 == 0)
      cout << c;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  for (int i = 0; i < 9; i++) {
    char c;
    cin >> c;
    if (i % 4 == 0)
      cout << c;
  }
}
Problem p03415 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
// #include<bits/extc++.h> inavilable in dev-cpp
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define me(i, k) memset(i, k, sizeof(i))
#define fr1(a, n) for (int a = 1; a <= (n); a++)
#define frab(i, a, b) for (int i = (a); i < (b); i++)
#define fr0(i, n) for (int i = 0; i < (n); i++)
#define trav(a, n) for (auto &a : n)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
const ll modn = 1000000007;

int main() {
  string a, b, c;
  string ans;
  char k = a[0];
  fr1(i, a.size() - 1) k = min(a[i], k);
  ans += k;
  k = b[0];
  fr1(i, b.size() - 1) k = min(b[i], k);
  ans += k;
  k = c[0];
  fr1(i, c.size() - 1) k = min(c[i], k);
  ans += k;
  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
// #include<bits/extc++.h> inavilable in dev-cpp
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define me(i, k) memset(i, k, sizeof(i))
#define fr1(a, n) for (int a = 1; a <= (n); a++)
#define frab(i, a, b) for (int i = (a); i < (b); i++)
#define fr0(i, n) for (int i = 0; i < (n); i++)
#define trav(a, n) for (auto &a : n)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
const ll modn = 1000000007;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << '\n';
  return 0;
}
Problem p03416 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b;
  int cnt = 0;
  cin >> a >> b;
  while (b != a - 1) {
    string s = to_string(b);
    if (s[0] == s[4] && s[1] == s[3])
      cnt++;
    else
      b--;
  }
  cout << cnt << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b;
  int cnt = 0;
  cin >> a >> b;
  while (b != a - 1) {
    string s = to_string(b);
    if (s[0] == s[4] && s[1] == s[3])
      cnt++;
    b--;
  }
  cout << cnt << endl;
}
Problem p03416 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input())

res = 0
for i in range(a, b + 1):
    i_str = str(i)
    if i_str == i_str[::-1]:
        res += 1
print(res)


Fixed submission:
a, b = map(int, input().split())

res = 0
for i in range(a, b + 1):
    i_str = str(i)
    if i_str == i_str[::-1]:
        res += 1
print(res)
Problem p03416 (C++)

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

int main() {
  int a;
  int b;
  cin >> a >> b;
  int sum = 0;

  for (int i = a; i <= b; i++) {
    char str[5] = {0};
    sprintf(str, "%d", i);
    if (str[0] == str[4] && str[1] == str[3])
      sum++;
  }
  cout << sum << endl;
}


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

int main() {
  int a;
  int b;
  cin >> a >> b;
  int sum = 0;

  for (int i = a; i <= b; i++) {
    if (i % 10 == i / 10000 % 10 && i / 10 % 10 == i / 1000 % 10)
      sum++;
  }
  cout << sum << endl;
}
Problem p03416 (C++)

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

int main() {
  int A, B;
  cin >> A >> B;

  int ans = 0;

  for (int i = A; i < ++B; i++) {

    int a = i % 10, b = i / 10000;
    int c = i / 10 % 10, d = i / 1000 % 10;
    if ((a == b) && (c == d))
      ans++;
    /* code */
  }
  cout << ans << endl;
}


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

int main() {
  int A, B;
  cin >> A >> B;

  int ans = 0;

  for (int i = A; i < B + 1; i++) {

    int a = i % 10, b = i / 10000;
    int c = i / 10 % 10, d = i / 1000 % 10;
    if ((a == b) && (c == d))
      ans++;
    /* code */
  }
  cout << ans << endl;
}
Problem p03416 (C++)

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

bool check(int n) {
  string s = to_string(n);
  bool ok = true;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != s.at(n - 1 - i))
      ok = false;
  }
  return (ok);
}

int main() {
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  for (int i = A; i <= B; i++) {
    if (check(i))
      cnt++;
  }
  cout << cnt << endl;
}


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

bool check(int n) {
  string s = to_string(n);
  bool ok = true;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != s.at(s.size() - 1 - i))
      ok = false;
  }
  return (ok);
}

int main() {
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  for (int i = A; i <= B; i++) {
    if (check(i))
      cnt++;
  }
  cout << cnt << endl;
}
Problem p03416 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;
  int count = 0;

  for (int i = a; a <= b; i++) {
    if (i / 10000 == i % 10 && (i / 1000) % 10 == (i / 10) % 10)
      count++;
  }
  cout << count << endl;
}

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

int main(void) {
  int a, b;
  cin >> a >> b;
  int count = 0;

  for (int i = a; i <= b; i++) {
    if (i / 10000 == i % 10 && (i / 1000) % 10 == (i / 10) % 10)
      count++;
  }
  cout << count << endl;
}
Problem p03416 (C++)

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

int tran(int num) {
  char *s;
  int id = 0;
  while (num >= 10) {
    s[id++] = num % 10;
    num /= 10;
  }
  s[id++] = num;
  for (int i = 0; i < id / 2; i++) {
    if (s[i] != s[id - 1 - i])
      return 0;
  }
  return 1;
}
int main() {
  int a, b, c;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    ans += tran(i);
  }
  cout << ans;
  return 0;
}

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

int tran(int num) {
  char s[15];
  int id = 0;
  while (num >= 10) {
    s[id++] = num % 10;
    num /= 10;
  }
  s[id++] = num;
  for (int i = 0; i < id / 2; i++) {
    if (s[i] != s[id - 1 - i])
      return 0;
  }
  return 1;
}
int main() {
  int a, b, c;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    ans += tran(i);
  }
  cout << ans;
  return 0;
}
Problem p03416 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int i = a; a <= b; i++) {
    int s = i % 10;
    int t = i / 10 % 10;
    int u = i / 1000 % 10;
    int v = i / 10000 % 10;
    if (s == v && t == u) {
      count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int i = a; i <= b; i++) {
    int s = i % 10;
    int t = i / 10 % 10;
    int u = i / 1000 % 10;
    int v = i / 10000 % 10;
    if (s == v && t == u) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p03416 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int A, B;
  cin >> A >> B;
  int ans = 0;
  int i0, i1, i3, i4;

  for (int i = A; i <= B; i++) {
    i0 = i / 10000;
    i = i % 10000;
    i1 = i / 1000;
    i = i % 100;
    i3 = i / 10;
    i4 = i % 10;
    if (i0 == i4 && i0 == i4)
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int A, B;
  cin >> A >> B;
  int ans = 0;
  int i0, i1, i3, i4;

  for (int i = A; i <= B; i++) {
    string s = to_string(i);
    if (s.at(0) == s.at(4) && s.at(1) == s.at(3))
      ans++;
  }
  cout << ans << endl;
}
Problem p03416 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int i = 1; a <= b; ++i) {
    int tmp = i;
    int reverse = 0;
    while (tmp != 0) {
      int b = tmp % 10;
      reverse = reverse * 10 + b;
      tmp /= 10;
    }
    if (i == reverse)
      count++;
  }
  cout << count << endl;
  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int i = a; i <= b; ++i) {
    int tmp = i;
    int reverse = 0;
    while (tmp != 0) {
      int b = tmp % 10;
      reverse = reverse * 10 + b;
      tmp /= 10;
    }
    if (i == reverse)
      count++;
  }
  cout << count << endl;
  return 0;
}