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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  --X;
  --Y;
  vector<vector<int>> dist(N, vector<int>(N, 99999));
  REP(i, N) {
    queue<pair<int, int>> q;
    q.push(make_pair(i, 0));
    while (!q.empty()) {
      auto t = q.front();
      q.pop();
      int pos = t.first, d = t.second;
      if (dist[i][pos] <= d)
        continue;
      dist[i][pos] = d;
      if (pos - 1 >= 0)
        q.push(make_pair(pos - 1, d + 1));
      if (pos + 1 < N)
        q.push(make_pair(pos + 1, d + 1));
      if (pos == X)
        q.push(make_pair(Y, d + 1));
      if (pos == Y)
        q.push(make_pair(X, d + 1));
    }
  }
  vector<int> ret(N, 0);
  REP(i, N) {
    for (int j = i + 1; j < N; ++j) {
      int td = dist[i][j];
      ret[td] += 1;
      cerr << "(" << i << "," << j << ") " << td << endl;
    }
  }
  for (int i = 1; i < N; ++i) {
    cout << ret[i] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  --X;
  --Y;
  vector<vector<int>> dist(N, vector<int>(N, 99999));
  REP(i, N) {
    queue<pair<int, int>> q;
    q.push(make_pair(i, 0));
    while (!q.empty()) {
      auto t = q.front();
      q.pop();
      int pos = t.first, d = t.second;
      if (dist[i][pos] <= d)
        continue;
      dist[i][pos] = d;
      if (pos - 1 >= 0)
        q.push(make_pair(pos - 1, d + 1));
      if (pos + 1 < N)
        q.push(make_pair(pos + 1, d + 1));
      if (pos == X)
        q.push(make_pair(Y, d + 1));
      if (pos == Y)
        q.push(make_pair(X, d + 1));
    }
  }
  vector<int> ret(N, 0);
  REP(i, N) {
    for (int j = i + 1; j < N; ++j) {
      ret[dist[i][j]]++;
    }
  }
  for (int i = 1; i < N; ++i) {
    cout << ret[i] << endl;
  }
}
Problem p02726 (C++)

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

int main() {
#define int long long
  int N, X, Y;

  cin >> N >> X >> Y;
  int l;
  vector<int> box(N - 1);
  for (int i = 1; i <= X; i++) {
    for (int j = i + 1; j <= X; j++) {
      l = j - i;
      box.at(l - 1)++;
    }
    for (int j = X + 1; j < Y; j++) {
      l = X - i + min(j - X, Y - j + 1);
      box.at(l - 1)++;
    }
    for (int j = Y; j <= N; j++) {
      l = j - i - Y + X + 1;
      box.at(l - 1)++;
    }
  }
  for (int i = X + 1; i < Y; i++) {
    for (int j = i + 1; j < Y; j++) {
      l = min(j - i, i - X + Y - j + 1);
      box.at(l - 1)++;
    }
    for (int j = Y; j <= N; j++) {
      l = j - Y + min(Y - i, i - X + 1);
      box.at(l - 1)++;
    }
  }
  for (int i = Y; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      l = j - i;
      box.at(l - 1)++;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << box.at(i) << endl;
  }
}

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

int main() {
#define int long long
  int N, X, Y;

  cin >> N >> X >> Y;
  int l;
  vector<int> box(N - 1);
  for (int i = 1; i <= X; i++) {
    for (int j = i + 1; j <= X; j++) {
      l = j - i;
      box.at(l - 1)++;
    }
    for (int j = X + 1; j < Y; j++) {
      l = X - i + min(j - X, Y - j + 1);
      box.at(l - 1)++;
    }
    for (int j = Y; j <= N; j++) {
      l = j - i - Y + X + 1;
      box.at(l - 1)++;
    }
  }
  for (int i = X + 1; i < Y; i++) {
    for (int j = i + 1; j < Y; j++) {
      l = min(j - i, i - X + Y - j + 1);
      box.at(l - 1)++;
    }
    for (int j = Y; j <= N; j++) {
      l = j - Y + min(Y - i, i - X + 1);
      box.at(l - 1)++;
    }
  }
  for (int i = Y; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      l = j - i;
      box.at(l - 1)++;
    }
  }
  for (int i = 0; i < (N - 1); i++) {
    cout << box.at(i) << endl;
  }
}
Problem p02726 (C++)

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> ans(N, 0);
  for (int k = 1; k < N; k++) {
    for (int i = 1; i < N + 1; i++) {
      for (int j = 1; j < N + 1; j++) {
        if (k == min(abs(j - i), abs(X - i) + 1 + abs(j - Y)) && i < j) {
          ans.at(k)++;
        }
      }
    }
  }
  for (int k = 1; k < N; k++) {
    cout << ans.at(k) << endl;
  }
}


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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> ans(N, 0);
  for (int i = 1; i < N + 1; i++) {
    for (int j = 1; j < N + 1; j++) {
      if (i < j) {
        int k = min(abs(j - i), abs(X - i) + 1 + abs(j - Y));
        ans.at(k)++;
      }
    }
  }
  for (int k = 1; k < N; k++) {
    cout << ans.at(k) << endl;
  }
}
Problem p02726 (C++)

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

const int MAX_N = 2000;
int n, x, y;

void solve() {
  int d[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i <= j) {
        d[i][j] = min(abs(i - j), abs(i - (x - 1)) + abs(j - (y - 1)) + 1);
      } else {
        d[i][j] = d[j][i];
      }
    }
  }

  int ans[n - 1];
  for (int i = 1; i <= n - 1; i++) {
    ans[i - 1] = 0;
    for (int j = 0; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        if (d[j][k] == i) {
          ans[i - 1]++;
        }
      }
    }
  }

  for (int i = 0; i < n - 1; i++) {
    cout << ans[i] << endl;
  }
}

int main() {
  cin >> n >> x >> y;
  solve();
}

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

const int MAX_N = 2000;
int n, x, y;

void solve() {
  int d[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i <= j) {
        d[i][j] = min(abs(i - j), abs(i - (x - 1)) + abs(j - (y - 1)) + 1);
      } else {
        d[i][j] = d[j][i];
      }
    }
  }

  int ans[n - 1];
  for (int i = 1; i <= n - 1; i++) {
    ans[i - 1] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans[d[i][j] - 1]++;
    }
  }

  for (int i = 0; i < n - 1; i++) {
    cout << ans[i] << endl;
  }
}

int main() {
  cin >> n >> x >> y;
  solve();
}
Problem p02726 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int n;
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
const int MAX_V = 2010;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + n, inf);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  rep(i, n - 1) {
    G[i].push_back({i + 1, 1});
    G[i + 1].push_back({i, 1});
  }
  G[x].push_back({y, 1});
  G[y].push_back({x, 1});
  vector<int> ans(n);
  rep(i, n) {
    dijkstra(i);
    rep(j, n) { ans[abs(d[i] - d[j])]++; }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] / 2 << endl;
  }
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int n;
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
const int MAX_V = 2010;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + n, inf);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  rep(i, n - 1) {
    G[i].push_back({i + 1, 1});
    G[i + 1].push_back({i, 1});
  }
  G[x].push_back({y, 1});
  G[y].push_back({x, 1});
  vector<int> ans(n);
  rep(i, n) {
    dijkstra(i);
    rep(j, n) { ans[abs(d[i] - d[j])]++; }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] / 2 << endl;
  }
}
Problem p02726 (C++)

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e3 + 3;

struct edge {
  int to;
  int len;
};

vector<edge> g[N];
vector<int> min_dist(N, INF);

void dijkstra(int source) {
  min_dist[source] = 0;
  set<pii> S; // S is set of active vertices (min_dist, vertex)
  S.insert({0, source});

  while (!S.empty()) {
    int curr = S.begin()->se;
    S.erase(S.begin());

    for (auto e : g[curr]) {
      if (min_dist[e.to] > min_dist[curr] + e.len) {
        S.erase({min_dist[e.to], e.to});
        min_dist[e.to] = min_dist[curr] + e.len;
        S.insert({min_dist[e.to], e.to});
      }
    }
  }
}

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

  int n, x, y;
  cin >> n >> x >> y;

  g[x].pb({y, 1});
  g[y].pb({x, 1});
  for (int i = 1; i < n; i++) {
    g[i].pb({i + 1, 1});
    g[i + 1].pb({i, 1});
  }

  vector<int> cnt(N, 0);
  for (int i = 1; i <= n; i++) {
    fill(all(min_dist), INF);
    dijkstra(i);
    for (int i = 1; i <= n; i++) {
      cnt[min_dist[i]]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << cnt[i] / 2 << "\n";
  }
}

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e3 + 3;

struct edge {
  int to;
  int len;
};

vector<edge> g[N];
vector<int> min_dist(N, INF);

void dijkstra(int source) {
  min_dist[source] = 0;
  set<pii> S; // S is set of active vertices (min_dist, vertex)
  S.insert({0, source});

  while (!S.empty()) {
    int curr = S.begin()->se;
    S.erase(S.begin());

    for (auto e : g[curr]) {
      if (min_dist[e.to] > min_dist[curr] + e.len) {
        S.erase({min_dist[e.to], e.to});
        min_dist[e.to] = min_dist[curr] + e.len;
        S.insert({min_dist[e.to], e.to});
      }
    }
  }
}

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

  int n, x, y;
  cin >> n >> x >> y;

  g[x].pb({y, 1});
  g[y].pb({x, 1});
  for (int i = 1; i < n; i++) {
    g[i].pb({i + 1, 1});
    g[i + 1].pb({i, 1});
  }

  vector<int> cnt(N, 0);
  for (int i = 1; i <= n; i++) {
    fill(all(min_dist), INF);
    dijkstra(i);
    for (int i = 1; i <= n; i++) {
      cnt[min_dist[i]]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << cnt[i] / 2 << "\n";
  }
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
/*
  In the name of ALLAH
  Author : Raashid Anwar
*/

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

#define int int64_t
const int M = 1000000007;

int ans[1001];
int vis[1001];
vector<int> adj[1001];

void solve(int i) {
  memset(vis, 0, sizeof(vis));
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  int d, u;
  q.push({int(0), i});
  while (!q.empty()) {
    d = q.top().first;
    u = q.top().second;
    q.pop();
    if (vis[u])
      continue;
    vis[u] = 1;
    ans[d]++;
    for (int v : adj[u])
      if (!vis[v])
        q.push({d + 1, v});
  }
  return;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // #endif
  int n, x, y;
  cin >> n >> x >> y;
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 1; i <= n - 1; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    solve(i);
  for (int i = 1; i < n; i++)
    cout << (ans[i] / 2) << " ";
}

Fixed submission:
/*
  In the name of ALLAH
  Author : Raashid Anwar
*/

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

#define int int64_t
const int M = 1000000007;

int ans[2001];
int vis[2001];
vector<int> adj[2001];

void solve(int i) {
  memset(vis, 0, sizeof(vis));
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  int d, u;
  q.push({int(0), i});
  while (!q.empty()) {
    d = q.top().first;
    u = q.top().second;
    q.pop();
    if (vis[u])
      continue;
    vis[u] = 1;
    ans[d]++;
    for (int v : adj[u])
      if (!vis[v])
        q.push({d + 1, v});
  }
  return;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // #endif
  int n, x, y;
  cin >> n >> x >> y;
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 1; i <= n - 1; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    solve(i);
  for (int i = 1; i < n; i++)
    cout << (ans[i] / 2) << " ";
}
Problem p02726 (C++)

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

/* 大文字を小文字に変換 */
char tolower(char c) { return (c + 0x20); }
/* 小文字を大文字に変換 */
char toupr(char c) { return (c - 0x20); }

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

const int INF = pow(10, 4);

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  int d[N][N];
  int dis[N];
  // 初期化
  rep(i, N) {
    rep(j, N) { d[i][j] = INF; }
  }
  rep(i, N) dis[i] = 0;
  rep(i, N) {
    // cout << i << endl;
    if (i != N - 1) {
      d[i][i + 1] = 1;
      d[i + 1][i] = 1;
    }
  }
  d[X - 1][Y - 1] = 1;
  d[Y - 1][X - 1] = 1;
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      // if(d[i][j] == 5) cout << i << "," << j << endl;
      dis[d[i][j]]++;
    }
  }
  rep(i, N) {
    if (i != 0)
      printf("%d\n", dis[i]);
  }
}

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

/* 大文字を小文字に変換 */
char tolower(char c) { return (c + 0x20); }
/* 小文字を大文字に変換 */
char toupr(char c) { return (c - 0x20); }

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

const int INF = pow(10, 4);

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  int d[N][N];
  int dis[N];
  // 初期化
  rep(i, N) {
    rep(j, N) { d[i][j] = INF; }
  }
  rep(i, N) dis[i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      d[i][j] = min(abs(j - i), abs(X - 1 - i) + 1 + abs(Y - 1 - j));
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      // if(d[i][j] == 5) cout << i << "," << j << endl;
      dis[d[i][j]]++;
    }
  }
  rep(i, N) {
    if (i != 0)
      printf("%d\n", dis[i]);
  }
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 1003
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1 % mod;
  ll u = fpow(x, n / 2, mod);
  u = (u * u) % mod;
  if (n % 2 == 1)
    u = (u * x) % mod;
  return u;
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int N, X, Y;
vector<int> adj[MAXN];
int dist[MAXN], freq[MAXN];
bool visited[MAXN];
queue<int> q;

void BFS(int x) {
  memset(visited, false, sizeof visited);
  memset(dist, 0, sizeof dist);
  visited[x] = true;
  dist[x] = 0;
  q.push(x);
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (auto u : adj[s]) {
      if (visited[u])
        continue;
      visited[u] = true;
      dist[u] = dist[s] + 1;
      q.push(u);
    }
  }
}
int main() {
  // freopen("data.txt","r",stdin);
  cin >> N >> X >> Y;
  for (int i = 1; i < N; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  adj[X].pb(Y);
  adj[Y].pb(X);
  for (int i = 1; i <= N; i++) {
    BFS(i);
    for (int j = 1; j <= N; j++) {
      freq[dist[j]]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << freq[i] / 2 << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 2003
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1 % mod;
  ll u = fpow(x, n / 2, mod);
  u = (u * u) % mod;
  if (n % 2 == 1)
    u = (u * x) % mod;
  return u;
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int N, X, Y;
vector<int> adj[MAXN];
int dist[MAXN], freq[MAXN];
bool visited[MAXN];
queue<int> q;

void BFS(int x) {
  memset(visited, false, sizeof visited);
  memset(dist, 0, sizeof dist);
  visited[x] = true;
  dist[x] = 0;
  q.push(x);
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (auto u : adj[s]) {
      if (visited[u])
        continue;
      visited[u] = true;
      dist[u] = dist[s] + 1;
      q.push(u);
    }
  }
}
int main() {
  // freopen("data.txt","r",stdin);
  cin >> N >> X >> Y;
  for (int i = 1; i < N; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  adj[X].pb(Y);
  adj[Y].pb(X);
  for (int i = 1; i <= N; i++) {
    BFS(i);
    for (int j = 1; j <= N; j++) {
      freq[dist[j]]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << freq[i] / 2 << endl;
  }
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
// minamoto
#include <bits/stdc++.h>
#define R register
#define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i)
#define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
template <class T> inline bool cmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T> inline bool cmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
using namespace std;
const int N = 2e5 + 5;
char s[N];
int a[N], n, x, m, res, y, d;
inline int calc(R int i, R int j) {
  if (i <= x && j >= y)
    return j - i - (y - x) + 1;
  if (i <= x && j <= x)
    return j - i;
  if (i >= y && j >= y)
    return j - i;
  if (i <= x)
    return min(j - i, y - j + 1 + x - i);
  return min(j - i, j - y + 1 + i - x);
}
int main() {
  //	freopen("testdata.in","r",stdin);
  scanf("%d%d%d", &n, &x, &y);
  fp(i, 1, n) fp(j, i + 1, n)++ a[calc(i, j)];
  fp(i, 1, n - 1) printf("%d\n", a[i]);
  return 0;
}

Fixed submission:
// minamoto
#include <bits/stdc++.h>
#define R register
#define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i)
#define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
template <class T> inline bool cmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T> inline bool cmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
using namespace std;
const int N = 2e5 + 5;
char s[N];
int a[N], n, x, m, res, y, d;
inline int calc(R int i, R int j) {
  if (i <= x && j >= y)
    return j - i - (y - x) + 1;
  if (i <= x && j <= x)
    return j - i;
  if (i >= y && j >= y)
    return j - i;
  if (i <= x)
    return min(j - i, y - j + 1 + x - i);
  if (j >= y)
    return min(j - i, j - y + 1 + i - x);
  return min(j - i, i - x + y - j + 1);
}
int main() {
  //	freopen("testdata.in","r",stdin);
  scanf("%d%d%d", &n, &x, &y);
  fp(i, 1, n) fp(j, i + 1, n)++ a[calc(i, j)];
  fp(i, 1, n - 1) printf("%d\n", a[i]);
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  int N, X, Y;
  int ans[201];
  cin >> N >> X >> Y;
  for (int i = 1; i <= N - 1; i++) {
    ans[i] = 0;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1 + i; j <= N; j++) {
      int min = j - i;
      if (min > abs(i - X) + 1 + abs(j - Y)) {
        min = abs(i - X) + 1 + abs(j - Y);
      }
      if (min > abs(i - Y) + 1 + abs(j - X)) {
        min = abs(i - Y) + 1 + abs(j - X);
      }
      ans[min]++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  int N, X, Y;
  int ans[2001];
  cin >> N >> X >> Y;
  for (int i = 1; i <= N - 1; i++) {
    ans[i] = 0;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1 + i; j <= N; j++) {
      int min = j - i;
      if (min > abs(i - X) + 1 + abs(j - Y)) {
        min = abs(i - X) + 1 + abs(j - Y);
      }
      if (min > abs(i - Y) + 1 + abs(j - X)) {
        min = abs(i - Y) + 1 + abs(j - X);
      }
      ans[min]++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p02726 (C++)

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

int a[1111];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      a[min({abs(i - j), abs(i - x) + 1 + abs(y - j),
             abs(i - y) + 1 + abs(x - j)})]++;
  for (int i = 1; i < n; i++)
    cout << a[i] << endl;
  return 0;
}


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

int a[2222];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      a[min({abs(i - j), abs(i - x) + 1 + abs(y - j),
             abs(i - y) + 1 + abs(x - j)})]++;
  for (int i = 1; i < n; i++)
    cout << a[i] << endl;
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e3 + 5;

void fio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL d[MAXN][MAXN];
LL min(LL a, LL b) { return a > b ? b : a; }

int main() {
  fio();
  LL n, x, y;
  cin >> n >> x >> y;
  vector<LL> an(n + 1);
  for1(i, n) {
    for (int j = i + 1; j <= n; j++) {
      an[min((i - x) + 1LL + (j - y), (j - i))]++;
    }
  }
  for1(i, n - 1) cout << an[i] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e3 + 5;

void fio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL d[MAXN][MAXN];
LL min(LL a, LL b) { return a > b ? b : a; }

int main() {
  fio();
  LL n, x, y;
  cin >> n >> x >> y;
  vector<LL> an(n + 1);
  for1(i, n) {
    for (int j = i + 1; j <= n; j++) {
      an[min(abs(i - x) + 1LL + abs(j - y), (j - i))]++;
    }
  }
  for1(i, n - 1) cout << an[i] << endl;

  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

int main() {
  ll n, x, y, ans, i, j;
  cin >> n >> x >> y;
  vector<ll> k(n - 1);
  for (i = 0; i < n - 1; i++) {
    for (j = 0; j < i; j++) {
      k[min({i - j, abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)}) - 1]++;
    }
  }

  for (i = 0; i < n - 1; i++)
    cout << k[i] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

int main() {
  ll n, x, y, ans, i, j;
  cin >> n >> x >> y;
  vector<ll> k(n - 1, 0);
  for (i = 2; i <= n; i++) {
    for (j = 1; j < i; j++) {
      k[min({i - j, abs(x - i) + abs(y - j) + 1, abs(x - j) + abs(y - i) + 1}) -
        1]++;
      // cout<<i<<"_"<<j<<"_"<<min({i-j,abs(x-i)+abs(y-j)+1,abs(x-j)+abs(y-i)+1})<<endl;
    }
  }

  for (i = 0; i < n - 1; i++)
    cout << k[i] << endl;

  return 0;
}
Problem p02726 (C++)

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

using namespace std;

int n, x, y;

void solve() {
  vector<int> cnt(n + 1);
  for (int i = 1; i < n; i++) {
    for (int j = 2; j <= n; j++) {
      int dist =
          min(j - i, min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1);
      cnt[dist]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << cnt[i] << endl;
  }
}

int main() {
  cin >> n >> x >> y;
  solve();
}


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

using namespace std;

int n, x, y;

void solve() {
  vector<int> cnt(n + 1);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dist =
          min(j - i, min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1);
      cnt[dist]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << cnt[i] << endl;
  }
}

int main() {
  cin >> n >> x >> y;
  solve();
}
Problem p02726 (C++)

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

using namespace std;

const int N = 1e3 + 5;

int e[N][N], ans[N];

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      e[j][i] = e[i][j] = j - i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      e[i][j] = e[j][i] = min(e[i][x] + e[y][j] + 1, e[i][j]);
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      ans[e[i][j]]++;
  for (int i = 1; i < n; ++i)
    cout << ans[i] << endl;

  return 0;
}

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

using namespace std;

const int N = 2e3 + 5;

int e[N][N], ans[N];

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      e[j][i] = e[i][j] = j - i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      e[i][j] = e[j][i] = min(e[i][x] + e[y][j] + 1, e[i][j]);
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      ans[e[i][j]]++;
  for (int i = 1; i < n; ++i)
    cout << ans[i] << endl;

  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pii pair<int, int>
#define ll long long
#define cl(x, y) memset(x, y, sizeof(x))
#define ct cerr << "Time elapsed:" << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
using namespace std;
int a[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x, y, i, j;
  cin >> n >> x >> y;
  for (i = 1; i < n; i++)
    a[i] = n - i;
  int p = y - (y - x) / 2;
  for (i = 1; i < p; i++)
    for (j = p + 1; j <= n; j++) {
      if (abs(j - i) > abs(x - i) + 1 + abs(j - y)) {
        a[abs(j - i)]--;
        a[abs(x - i) + 1 + abs(j - y)]++;
      }
    }
  for (i = 1; i < n; i++)
    cout << a[i] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pii pair<int, int>
#define ll long long
#define cl(x, y) memset(x, y, sizeof(x))
#define ct cerr << "Time elapsed:" << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
const int N = 2e3 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
using namespace std;
int a[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x, y, i, j;
  cin >> n >> x >> y;
  for (i = 1; i < n; i++)
    a[i] = n - i;
  int p = y - (y - x) / 2;
  for (i = 1; i < p; i++)
    for (j = p + 1; j <= n; j++) {
      if (abs(j - i) > abs(x - i) + 1 + abs(j - y)) {
        a[abs(j - i)]--;
        a[abs(x - i) + 1 + abs(j - y)]++;
      }
    }
  for (i = 1; i < n; i++)
    cout << a[i] << endl;
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  vector<int> ans(n);
  rep(sv, n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF)
        return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist[v];
      if (v - 1 >= 0)
        push(v - 1, d + 1);
      if (v + 1 < 0)
        push(v + 1, d + 1);
      if (v == x)
        push(y, d + 1);
      if (v == y)
        push(x, d + 1);
    }
    rep(i, n) ans[dist[i]]++;
  }
  rep(i, n) ans[i] /= 2;
  for (int i = 1; i <= n - 1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  vector<int> ans(n);
  rep(sv, n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF)
        return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist[v];
      if (v - 1 >= 0)
        push(v - 1, d + 1);
      if (v + 1 < n)
        push(v + 1, d + 1);
      if (v == x)
        push(y, d + 1);
      if (v == y)
        push(x, d + 1);
    }
    rep(i, n) ans[dist[i]]++;
  }
  rep(i, n) ans[i] /= 2;
  for (int i = 1; i <= n - 1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p02726 (C++)

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

using namespace std;

long long p[10004];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  long long n, x, y, k;
  cin >> n >> x >> y;
  for (long long i = 1; i < n; ++i) {
    for (long long j = 2; j <= n; ++j) {
      k = min(j - i, abs(x - i) + 1 + abs(y - j));
      ++p[k];
    }
  }
  for (long long i = 1; i < n; ++i)
    cout << p[i] << endl;

  return 0;
}


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

using namespace std;

long long p[10004];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  long long n, x, y, k;
  cin >> n >> x >> y;
  for (long long i = 1; i < n; ++i) {
    for (long long j = i + 1; j <= n; ++j) {
      k = min(j - i, abs(x - i) + 1 + abs(y - j));
      ++p[k];
    }
  }
  for (long long i = 1; i < n; ++i)
    cout << p[i] << endl;

  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll arr[2020][2020], n, x, y, cnt[2020];
int main() {
  memset(arr, 1, sizeof(arr));
  cin >> n >> x >> y;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j)
      arr[i][j] = arr[j][i] = j - i;
  }
  arr[x][y] = 1;
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j)
        if (arr[i][k] + arr[k][j] < arr[i][j])
          arr[i][j] = arr[i][k] + arr[k][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j)
      cnt[arr[i][j]]++;
  }
  for (int i = 1; i <= n - 1; ++i)
    printf("%lld\n", cnt[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll arr[2020][2020], n, x, y, cnt[2020];
int main() {
  memset(arr, 1, sizeof(arr));
  cin >> n >> x >> y;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j)
      arr[i][j] = arr[j][i] = j - i;
  }
  arr[x][y] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (arr[i][x] + arr[x][j] < arr[i][j])
        arr[i][j] = arr[j][i] = arr[i][x] + arr[x][j];
      if (arr[i][y] + arr[y][j] < arr[i][j])
        arr[i][j] = arr[j][i] = arr[i][y] + arr[y][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j)
      cnt[arr[i][j]]++;
  }
  for (int i = 1; i <= n - 1; ++i)
    printf("%lld\n", cnt[i]);
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
typedef long long ll;
int x, n, y, cnt[maxn];
int dis(int a, int b) { return min(b - a, abs(a - x) + abs(b - y) + 1); }
int main() {
  scanf("%d%d%d", &n, &x, &y);
  if (x > y)
    swap(x, y);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      cnt[dis(i, j)]++;
    }
  }
  for (int i = 1; i < n; i++)
    printf("%d\n", cnt[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
int x, n, y, cnt[maxn];
int dis(int a, int b) { return min(b - a, abs(a - x) + abs(b - y) + 1); }
int main() {
  scanf("%d%d%d", &n, &x, &y);
  if (x > y)
    swap(x, y);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      cnt[dis(i, j)]++;
    }
  }
  for (int i = 1; i < n; i++)
    printf("%d\n", cnt[i]);
  return 0;
}
Problem p02726 (C++)

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

int main() {
  int x, n, y;
  string s;
  cin >> n >> x >> y;
  //    map<int, int> cnt;
  int cnt[1000] = {};
  for (int i = 1; i < n; i++) {
    int dis = 0;
    for (int j = i + 1; j <= n; j++) {
      dis = min(j - i, abs(x - i) + 1 + abs(y - j));
      cnt[dis]++;
      // cout << i << " " << dis << " " << j << endl;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << cnt[i] << endl;
  }
}


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

int main() {
  int x, n, y;
  string s;
  cin >> n >> x >> y;
  //    map<int, int> cnt;
  int cnt[2000] = {};
  for (int i = 1; i < n; i++) {
    int dis = 0;
    for (int j = i + 1; j <= n; j++) {
      dis = min(j - i, abs(x - i) + 1 + abs(y - j));
      cnt[dis]++;
      // cout << i << " " << dis << " " << j << endl;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << cnt[i] << endl;
  }
}
Problem p02727 (C++)

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

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> red(a), green(b), white(c);
  for (int i = 0; i < a; i++)
    cin >> red[i];
  for (int i = 0; i < b; i++)
    cin >> green[i];
  for (int i = 0; i < c; i++)
    cin >> white[i];
  sort(red.rbegin(), red.rend());
  sort(green.rbegin(), green.rend());
  sort(white.rbegin(), white.rend());
  long long ans = 0;
  for (int i = 0; i < x; i++)
    ans += red[i];
  for (int i = 0; i < y; i++)
    ans += green[i];
  int last_r = x - 1, last_g = y - 1;
  int idx = 0;
  auto upd_red = [&]() {
    ans -= red[last_r];
    last_r--;
    ans += white[idx];
    idx++;
  };
  auto upd_green = [&]() {
    ans -= green[last_g];
    last_g--;
    ans += white[idx];
    idx++;
  };
  while (1) {
    if (last_r < 0 && last_g < 0)
      break;
    if (idx == c)
      break;
    if (last_r < 0) {
      // greenを交換
      if (green[last_g] >= white[idx])
        break;
      upd_green();
      continue;
    }
    if (last_g < 0) {
      // redを交換
      if (red[last_r] >= white[idx])
        break;
      upd_red();
      continue;
    }
    if (red[last_r] < green[last_g]) {
      // redを交換
      if (red[last_r] >= white[idx])
        break;
      upd_red();
      continue;
    }
    if (green[last_g] < red[last_r]) {
      // greenを交換
      if (green[last_g] >= white[idx])
        break;
      upd_green();
      continue;
    }
  }
  cout << ans << endl;
}


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

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> red(a), green(b), white(c);
  for (int i = 0; i < a; i++)
    cin >> red[i];
  for (int i = 0; i < b; i++)
    cin >> green[i];
  for (int i = 0; i < c; i++)
    cin >> white[i];
  sort(red.rbegin(), red.rend());
  sort(green.rbegin(), green.rend());
  sort(white.rbegin(), white.rend());
  long long ans = 0;
  for (int i = 0; i < x; i++)
    ans += red[i];
  for (int i = 0; i < y; i++)
    ans += green[i];
  int last_r = x - 1, last_g = y - 1;
  int idx = 0;
  auto upd_red = [&]() {
    ans -= red[last_r];
    last_r--;
    ans += white[idx];
    idx++;
  };
  auto upd_green = [&]() {
    ans -= green[last_g];
    last_g--;
    ans += white[idx];
    idx++;
  };
  while (1) {
    if (last_r < 0 && last_g < 0)
      break;
    if (idx == c)
      break;
    if (last_r < 0) {
      // greenを交換
      if (green[last_g] >= white[idx])
        break;
      upd_green();
      continue;
    }
    if (last_g < 0) {
      // redを交換
      if (red[last_r] >= white[idx])
        break;
      upd_red();
      continue;
    }
    if (red[last_r] < green[last_g]) {
      // redを交換
      if (red[last_r] >= white[idx])
        break;
      upd_red();
      continue;
    }
    // greenを交換
    if (green[last_g] >= white[idx])
      break;
    upd_green();
  }
  cout << ans << endl;
}
Problem p02727 (C++)

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)

int X, Y, A, B, C;
priority_queue<int, vector<int>, greater<int>> pq;
vector<int> a, b, c;

int ans;
int max_ans = 0;

void update(int x) {
  if (pq.size() != Y) {
    ans += x;
    pq.push(x);
  } else {
    int v = pq.top();
    pq.pop();
    ans -= v;
    x = max(x, v);
    pq.push(x);
    ans += x;
  }
}

signed main() {
  cin >> X >> Y >> A >> B >> C;

  int v;
  rep(i, A) {
    cin >> v;
    a.push_back(v);
  }
  rep(i, B) {
    cin >> v;
    b.push_back(v);
  }
  rep(i, C) {
    cin >> v;
    c.push_back(v);
  }

  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());

  int aa = max(X - C, 0ll), cc = min(X, C);

  rep(i, B) update(b[i]);
  rep(i, C) {
    if (i < cc)
      ans += c[i];
    else
      update(c[i]);
  }
  rep(i, A) {
    if (i < aa)
      ans += a[i];
    else {
      ans += a[i];
      ans -= c[cc - 1 - (i - aa)];
      update(c[cc - 1 - (i - aa)]);
    }
    max_ans = max(ans, max_ans);
  }

  cout << max_ans << endl;

  return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)

int X, Y, A, B, C;
priority_queue<int, vector<int>, greater<int>> pq;
vector<int> a, b, c;

int ans;
int max_ans = 0;

void update(int x) {
  if (pq.size() != Y) {
    ans += x;
    pq.push(x);
  } else {
    int v = pq.top();
    pq.pop();
    ans -= v;
    x = max(x, v);
    pq.push(x);
    ans += x;
  }
}

signed main() {
  cin >> X >> Y >> A >> B >> C;

  int v;
  rep(i, A) {
    cin >> v;
    a.push_back(v);
  }
  rep(i, B) {
    cin >> v;
    b.push_back(v);
  }
  rep(i, C) {
    cin >> v;
    c.push_back(v);
  }

  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());

  int aa = max(X - C, 0ll), cc = min(X, C);

  rep(i, B) update(b[i]);
  rep(i, C) {
    if (i < cc)
      ans += c[i];
    else
      update(c[i]);
  }
  max_ans = ans;
  rep(i, min(X, A)) {
    if (i < aa)
      ans += a[i];
    else {
      ans += a[i];
      ans -= c[cc - 1 - (i - aa)];
      update(c[cc - 1 - (i - aa)]);
    }
    max_ans = max(ans, max_ans);
  }

  cout << max_ans << endl;

  return 0;
}
Problem p02727 (C++)

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

int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> red(A), green(B), none(C);
  for (ll i = 0; i < A; ++i)
    cin >> red[i];
  for (ll i = 0; i < B; ++i)
    cin >> green[i];
  for (ll i = 0; i < C; ++i)
    cin >> none[i];
  sort(red.begin(), red.end(), greater<ll>());
  sort(green.begin(), green.end(), greater<ll>());
  sort(none.begin(), none.end(), greater<ll>());
  ll r_idx = X - 1, g_idx = Y - 1;
  ll t_idx = 0;
  while (true) {
    // true -> red
    // false -> green
    ll min_in_two = min(red[r_idx], green[g_idx]);
    if (min_in_two >= none[t_idx])
      break;
    // red
    if (min_in_two == red[r_idx]) {
      red[r_idx] = none[t_idx];
      t_idx++;
      r_idx--;
    } else {
      green[g_idx] = none[t_idx];
      t_idx++;
      g_idx--;
    }
  }
  cout << accumulate(red.begin(), red.begin() + X, 0) +
              accumulate(green.begin(), green.begin() + Y, 0)
       << endl;
}

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

int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> red(A), green(B), none(C);
  for (ll i = 0; i < A; ++i)
    cin >> red[i];
  for (ll i = 0; i < B; ++i)
    cin >> green[i];
  for (ll i = 0; i < C; ++i)
    cin >> none[i];
  sort(red.begin(), red.end(), greater<ll>());
  sort(green.begin(), green.end(), greater<ll>());
  sort(none.begin(), none.end(), greater<ll>());
  vector<ll> v(X + Y + C);
  for (int i = 0; i < X; ++i)
    v[i] = red[i];
  for (int i = 0; i < Y; ++i)
    v[i + X] = green[i];
  for (int i = 0; i < C; ++i)
    v[i + X + Y] = none[i];
  sort(v.begin(), v.end(), greater<ll>());
  ll ans = 0;
  for (ll i = 0; i < X + Y; ++i)
    ans += v[i];
  cout << ans << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct apple {
  int color; // 0 is X  1 is Y  2  is  ALL
  ll value;
};
apple t[222222];
bool cmp(apple a, apple b) { return a.value > b.value; }
int main() {
  int n, b, i, j, k, x, y, z, s0, s1, s2;
  cin >> x >> y >> s0 >> s1 >> s2;
  for (i = 0; i < s0; i++) {
    cin >> t[i].value;
    t[i].color = 0;
  }
  for (; i < s0 + s1; i++) {
    cin >> t[i].value;
    t[i].color = 1;
  }
  for (; i < s0 + s1 + s2; i++) {
    cin >> t[i].value;
    t[i].color = 2;
  }
  sort(t, t + s0 + s1 + s2, cmp);
  ll c3 = 0, c1 = 0, c2 = 0, res = 0;
  for (i = 0; i < s0 + s1 + s2; i++) {
    if (c1 + c2 + c3 == x + y)
      break;
    if (t[i].color == 0) {
      if (c1 == x)
        continue;
      c1++;
      res += t[i].value;
    }
    if (t[i].color == 1) {
      if (c2 == y)
        continue;
      c2++;
      res += t[i].value;
    }
    if (t[i].color == 2) {
      c3++;
      res += t[i].value;
    }
  }
  cout << res;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct apple {
  int color; // 0 is X  1 is Y  2  is  ALL
  ll value;
};
apple t[333333];
bool cmp(apple a, apple b) { return a.value > b.value; }
int main() {
  int n, b, i, j, k, x, y, z, s0, s1, s2;
  cin >> x >> y >> s0 >> s1 >> s2;
  for (i = 0; i < s0; i++) {
    cin >> t[i].value;
    t[i].color = 0;
  }
  for (; i < s0 + s1; i++) {
    cin >> t[i].value;
    t[i].color = 1;
  }
  for (; i < s0 + s1 + s2; i++) {
    cin >> t[i].value;
    t[i].color = 2;
  }
  sort(t, t + s0 + s1 + s2, cmp);
  ll c3 = 0, c1 = 0, c2 = 0, res = 0;
  for (i = 0; i < s0 + s1 + s2; i++) {
    if (c1 + c2 + c3 == x + y)
      break;
    if (t[i].color == 0) {
      if (c1 == x)
        continue;
      c1++;
      res += t[i].value;
    }
    if (t[i].color == 1) {
      if (c2 == y)
        continue;
      c2++;
      res += t[i].value;
    }
    if (t[i].color == 2) {
      c3++;
      res += t[i].value;
    }
  }
  cout << res;
}