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

Buggy submission (status: Time Limit Exceeded):
from collections import deque

n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1
BIG = 65521
ans = {i: 0 for i in range(n)}


def bfs(start_v):
    """ある始点からほかの全点に行くまでの最短距離を求める。"""
    qu = deque()
    qu_append = qu.append
    qu_popleft = qu.popleft
    qu_append(start_v)
    # 始点からvに移動するまでの最短距離: dist[v]
    dist = [BIG] * n

    def push(v, d):
        """始点からvまでの最短距離が算出されていないときに，その距離を保存し，
        キューに頂点vを追加する。"""
        if dist[v] != BIG:
            # 既に訪問済みで距離が求められている。
            return
        dist[v] = d
        qu_append(v)

    push(start_v, 0)

    while len(qu):
        v = qu_popleft()
        # 始点からvの次の頂点へ移動する距離。
        d = dist[v] + 1
        if v < n - 1:
            push(v + 1, d)
        if v > 0:
            push(v - 1, d)
        if v == x:
            push(y, d)
        if v == y:
            push(x, d)

    for i in range(n):
        if dist[i] != 0:
            ans[dist[i]] += 1


def main():
    for i in range(n):
        bfs(i)

    for i in range(1, n):
        print(ans[i] // 2)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque

n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1
BIG = 65521
ans = {i: 0 for i in range(n)}


def bfs(start_v):
    """ある始点からほかの全点に行くまでの最短距離を求める。"""
    qu = deque()
    qu_append = qu.append
    qu_popleft = qu.popleft
    qu_append(start_v)
    # 始点からvに移動するまでの最短距離: dist[v]
    dist = [BIG] * n

    def push(v, d):
        """始点からvまでの最短距離が算出されていないときに，その距離を保存し，
        キューに頂点vを追加する。"""
        if dist[v] != BIG:
            # 既に訪問済みで距離が求められている。
            return
        dist[v] = d
        qu_append(v)

    push(start_v, 0)

    while len(qu):
        v = qu_popleft()
        # 始点からvの次の頂点へ移動する距離。
        d = dist[v] + 1
        if v < n - 1:
            push(v + 1, d)
        if v > 0:
            push(v - 1, d)
        if v == x:
            push(y, d)
        if v == y:
            push(x, d)

    for i in range(n):
        if dist[i] != 0:
            ans[dist[i]] += 1


def main():
    for i in range(n):
        bfs(i)

    for i in range(1, n):
        print(ans[i] // 2)


if __name__ == "__main__":
    main()

# TLE
Problem p02726 (Python)

Buggy submission (status: Runtime Error):
n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
    for j in range(i + 1, n):
        if i <= x - 1:
            if j <= x - 1:  # 1 idx
                cnt[j - i] += 1
            elif j <= y - 1:
                cnt[min(j - i, x + y - i - j - 1)] += 1
            else:
                cnt[x - y - i + j + 1] += 1
        elif x - 1 < x <= y - 1:
            if j <= y - 1:
                cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
            else:
                cnt[min(j - i), 1 + (i - x + 1) + (j - y + 1)] += 1
        else:
            cnt[j - i] += 1

for i in range(1, n):
    print(cnt[i])


Fixed submission:
n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
    for j in range(i + 1, n):
        if i <= x - 1:
            if j <= x - 1:  # 1 idx
                cnt[j - i] += 1
            elif j <= y - 1:
                cnt[min(j - i, x + y - i - j - 1)] += 1
            else:
                cnt[x - y - i + j + 1] += 1
        elif x - 1 < x <= y - 1:
            if j <= y - 1:
                cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
            else:
                cnt[min((j - i), 1 + (i - x + 1) + (j - y + 1))] += 1
        else:
            cnt[j - i] += 1

for i in range(1, n):
    print(cnt[i])
Problem p02726 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/python3

(n, x, y) = map(int, input().split())

cs = [0 for i in range(n)]

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        d = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
        if d == (abs(y - i) + 1 + abs(j - x)):
            print(i, j, d)
        cs[d] += 1

for i in range(1, n):
    print(cs[i])


Fixed submission:
#!/usr/bin/python3

(n, x, y) = map(int, input().split())

cs = [0 for i in range(n)]

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        d = min(abs(j - i), abs(x - i) + 1 + abs(j - y))
        cs[d] += 1

for i in range(1, n):
    print(cs[i])
Problem p02726 (Python)

Buggy submission (status: Runtime Error):
N, X, Y = map(int, input().split())


dic = {}

X = X - 1
Y = Y - 1

for i in range(N):
    for j in range(i + 1, N):
        if i <= X and Y <= j:
            v = X - i + 1 + j - Y
        elif (i <= X) and (X <= j and j <= Y):
            v = min(j - i, X - i + 1 + Y - j)
        elif (X <= i and i <= Y) and Y <= j:
            v = min(j - i, i - X + 1 + j - Y)
        elif (X <= i and i <= Y) and (X <= j and j <= Y):
            v = min(j - i, i - X + 1 + Y - j)
        else:
            v = j - i

        if v in dic:
            dic[v] += 1
        else:
            dic[v] = 1


for i in range(1, N):
    print(dic[i])


Fixed submission:
N, X, Y = map(int, input().split())


dic = {}

X = X - 1
Y = Y - 1

for i in range(N):
    for j in range(i + 1, N):
        if i <= X and Y <= j:
            v = X - i + 1 + j - Y
        elif (i <= X) and (X <= j and j <= Y):
            v = min(j - i, X - i + 1 + Y - j)
        elif (X <= i and i <= Y) and Y <= j:
            v = min(j - i, i - X + 1 + j - Y)
        elif (X <= i and i <= Y) and (X <= j and j <= Y):
            v = min(j - i, i - X + 1 + Y - j)
        else:
            v = j - i

        if v in dic:
            dic[v] += 1
        else:
            dic[v] = 1


for i in range(1, N):
    if i in dic:
        print(dic[i])
    else:
        print(0)
Problem p02726 (C++)

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

#define INF (INT32_MAX / 4)

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;

  vector<vector<int>> m(N, vector<int>(N, INF));
  for (int i = 0; i < N; i++)
    m[i][i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        continue;
      m[i][j] = abs(i - j);
    }
  }
  m[X][Y] = 1;
  m[Y][X] = 1;
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
      }
    }
  }
  vector<int> ans(N - 1);
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (m[i][j] < 1)
        continue;
      ans[m[i][j] - 1]++;
    }
  }
  for (int i = 0; i < N - 1; i++) {
    cout << ans[i] << endl;
  }
}


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

#define INF (INT32_MAX / 4)

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;

  vector<vector<int>> m(N, vector<int>(N, INF));
  for (int i = 0; i < N; i++)
    m[i][i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        continue;
      m[i][j] = abs(i - j);
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      m[i][j] = min(m[i][j], min(m[i][X] + m[Y][j] + 1, m[i][Y] + m[X][j] + 1));
    }
  }
  vector<int> ans(N - 1);
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (m[i][j] < 1)
        continue;
      ans[m[i][j] - 1]++;
    }
  }
  for (int i = 0; i < N - 1; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02726 (C++)

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

using namespace std;

int N, x, y, ans[2010];

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

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

using namespace std;

int N, x, y, ans[2010];

int main() {
  cin >> N >> x >> y;
  for (int i = 1; i <= x; i++)
    for (int j = i + 1; j <= x; j++)
      ans[j - i]++;
  for (int i = y; i <= N; i++)
    for (int j = i + 1; j <= N; j++)
      ans[j - i]++;
  for (int i = x + 1; i < y; i++)
    for (int j = i + 1; j < y; j++)
      ans[min(j - i, i - x + y - j + 1)]++;
  for (int i = 1; i <= x; i++)
    for (int j = x + 1; j < y; j++)
      ans[min(j - i, y - j + 1 + x - i)]++;
  for (int i = y; i <= N; i++)
    for (int j = x + 1; j < y; j++)
      ans[min(i - j, j - x + 1 + i - y)]++;
  for (int i = 1; i <= x; i++)
    for (int j = y; j <= N; j++)
      ans[j - y + x - i + 1]++;
  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>
using namespace std;

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const int N = 2e3 + 34;

int s[N];

void solve() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  --x;
  --y;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int d = j - i; // 3
      if (j >= y && i <= x) {
        d -= y - x - 1;
      } else if (i <= x && j <= y && j > x) {
        d = min(d, x - i + y - j + 1); // 3, 1-0+3-3+1
      } else if (i >= x && i < y && j >= y) {
        d = min(d, i - x + j - y + 1); // 2, 2-1+4-3+1
      } else {
        d = min(d, i - x + y - j + 1);
      }
      ++s[d];
      // printf("(%d, %d) -> %d\n", i+1, j+1, d);
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\n", s[i]);
  }
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const int N = 2e3 + 34;

int s[N];

void solve() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  --x;
  --y;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int d = j - i; // 3
      if (j >= y && i <= x) {
        d -= y - x - 1;
      } else if (i <= x && j <= y && j > x) {
        d = min(d, x - i + y - j + 1); // 3, 1-0+3-3+1
      } else if (i >= x && i < y && j >= y) {
        d = min(d, i - x + j - y + 1); // 2, 2-1+4-3+1
      } else if (i >= x && j <= y) {
        d = min(d, i - x + y - j + 1);
      }
      ++s[d];
      // printf("(%d, %d) -> %d\n", i+1, j+1, d);
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\n", s[i]);
  }
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF = (ll)1e9;
const ll MOD = (ll)1e9 + 7;
const ll MAX = 100100;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
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;
}

int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<ll>> v(N, vector<ll>(N));
  vector<ll> ans(N, 0);
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++)
      v[i][j] = abs(i - j);
  }

  v[X - 1][Y - 1] = 1;
  v[Y - 1][X - 1] = 1;

  for (ll k = 0; k < N; k++) {
    for (ll i = 0; i < N; i++) {
      for (ll j = i + 1; j < N; j++) {
        v[i][j] = min(v[i][k] + v[k][j], v[i][j]);
      }
    }
  }

  for (ll i = 0; i < N; i++) {
    for (ll j = i + 1; j < N; j++) {
      ans[v[i][j]]++;
    }
  }
  for (ll i = 1; i < N; i++)
    cout << ans[i] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF = (ll)1e9;
const ll MOD = (ll)1e9 + 7;
const ll MAX = 100100;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
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;
}

int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<ll>> v(N, vector<ll>(N));
  vector<ll> ans(N, 0);
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++)
      v[i][j] = abs(i - j);
  }

  v[X - 1][Y - 1] = 1;
  v[Y - 1][X - 1] = 1;

  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      v[i][j] = min(v[i][j], abs(X - i - 1) + abs(Y - j - 1) + 1);
    }
  }

  for (ll i = 0; i < N; i++) {
    for (ll j = i + 1; j < N; j++) {
      ans[v[i][j]]++;
    }
  }
  for (ll i = 1; i < N; i++)
    cout << ans[i] << endl;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double db;

const int maxn = 1e3 + 5;
const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll num[maxn];
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dis = j - i;
      dis = min(dis, abs(x - i) + abs(j - y) + 1);
      num[dis]++;
    }
  }
  for (int i = 1; i < n; i++) {
    printf("%lld\n", num[i]);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double db;

const int maxn = 2e3 + 5;
const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll num[maxn];
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dis = j - i;
      dis = min(dis, abs(x - i) + abs(j - y) + 1);
      num[dis]++;
    }
  }
  for (int i = 1; i < n; i++) {
    printf("%lld\n", num[i]);
  }
  return 0;
}
Problem p02726 (C++)

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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<int> adj[1000];
  rep(i, n - 1) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);

  vector<int> counter(n, 0);
  for (int start = 0; start < n; start++) {
    queue<int> q;
    q.push(start);
    vector<int> dist(n, 1e9);
    dist[start] = 1;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int to : adj[now]) {
        if (dist[to] != 1e9)
          continue;
        if (dist[to] > dist[now] + 1) {
          dist[to] = dist[now] + 1;
          q.push(to);
        }
      }
    }
    for (int i = start + 1; i < n; i++) {
      counter[dist[i] - 1]++;
    }
    // cout << "start: " << start << ", counter: ";
    // for (int i = 0; i < n; i++) {
    //     cout << counter[i] << " ";
    // }
    // cout << endl;
  }
  for (int i = 1; i < n; i++) {
    cout << counter[i] << endl;
  }
}

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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<int> adj[10000];
  rep(i, n - 1) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);

  vector<int> counter(n, 0);
  for (int start = 0; start < n; start++) {
    queue<int> q;
    q.push(start);
    vector<int> dist(n, 1e9);
    dist[start] = 1;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int to : adj[now]) {
        if (dist[to] != 1e9)
          continue;
        if (dist[to] > dist[now] + 1) {
          dist[to] = dist[now] + 1;
          q.push(to);
        }
      }
    }
    for (int i = start + 1; i < n; i++) {
      counter[dist[i] - 1]++;
    }
    // cout << "start: " << start << ", counter: ";
    // for (int i = 0; i < n; i++) {
    //     cout << counter[i] << " ";
    // }
    // cout << endl;
  }
  for (int i = 1; i < n; i++) {
    cout << counter[i] << endl;
  }
}
Problem p02726 (C++)

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

ll memo[2001][2001]; // 各点の最短距離を記録したもの

int main() {
  ll n;
  ll x;
  ll y;
  cin >> n >> x >> y;
  x--;
  y--;

  rep(i, n) {
    rep(j, n) { memo[i][j] = -1; }
  }
  rep(i, n - 1) {

    memo[i][i] = 0;
    memo[i][i + 1] = 1;
    memo[i + 1][i] = 1;
  }
  memo[n - 1][n - 1] = 0;
  memo[x][y] = 1;
  memo[y][x] = 1;

  for (ll k = 2; k < n; k++) {
    for (ll i = 0; i < n - 2; i++) {
      if (memo[i][i + k] != -1) {
        continue;
      }

      ll p = min(memo[i][i + k - 1], memo[i + 1][i + k]);
      ll j = labs(i - x) + labs(i + k - y);
      ll h = labs(i - y) + labs(i + k - x);
      ll g = min(p + 1, j + 1);

      memo[i][i + k] = min(g, h + 1);
      memo[i + k][i] = min(g, h + 1);
    }
  }
  map<ll, ll> score;
  rep(i, n) {
    rep(j, n) { score[memo[i][j]] += 1; }
  }

  rep(i, n - 1) { cout << score[i + 1] / 2 << endl; }
}

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

ll memo[20001][20001]; // 各点の最短距離を記録したもの

int main() {
  ll n;
  ll x;
  ll y;
  cin >> n >> x >> y;
  x--;
  y--;

  rep(i, n) {
    rep(j, n) { memo[i][j] = -1; }
  }
  rep(i, n - 1) {

    memo[i][i] = 0;
    memo[i][i + 1] = 1;
    memo[i + 1][i] = 1;
  }
  memo[n - 1][n - 1] = 0;
  memo[x][y] = 1;
  memo[y][x] = 1;

  for (ll k = 2; k < n; k++) {
    for (ll i = 0; i < n - 2; i++) {
      if (memo[i][i + k] != -1) {
        continue;
      }

      ll p = min(memo[i][i + k - 1], memo[i + 1][i + k]);
      ll j = labs(i - x) + labs(i + k - y);
      ll h = labs(i - y) + labs(i + k - x);
      ll g = min(p + 1, j + 1);

      memo[i][i + k] = min(g, h + 1);
      memo[i + k][i] = min(g, h + 1);
    }
  }
  map<ll, ll> score;
  rep(i, n) {
    rep(j, n) { score[memo[i][j]] += 1; }
  }

  rep(i, n - 1) { cout << score[i + 1] / 2 << endl; }
}
Problem p02726 (C++)

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

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

int n, x, y;
int all[1005];

int main() {

  cin >> n >> x >> y;

  for (int i = 1; i <= n; i++)
    all[i] = 0;

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dist1 = abs(j - i);
      int dist2 = abs(x - i) + 1 + abs(j - y);
      int min_dist = min(dist1, dist2);
      all[min_dist]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << all[i] << '\n';
  }

  return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

int n, x, y;
int all[20005];

int main() {

  cin >> n >> x >> y;

  for (int i = 1; i <= n; i++)
    all[i] = 0;

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dist1 = abs(j - i);
      int dist2 = abs(x - i) + 1 + abs(j - y);
      int min_dist = min(dist1, dist2);
      all[min_dist]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << all[i] << '\n';
  }

  return 0;
}
Problem p02726 (C++)

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

int N, X, Y, a[1004][1004], ans[10005];
vector<int> graph[3004];
queue<int> q;

int main() {
  cin >> N >> X >> Y;
  for (int i = 2; i < N; i++) {
    graph[i].push_back(i - 1);
    graph[i].push_back(i + 1);
  }
  graph[1].push_back(2);
  graph[N].push_back(N - 1);
  graph[X].push_back(Y);
  graph[Y].push_back(X);
  for (int i = 1; i <= N; i++) {
    a[i][i] = 0;
    q.push(i);
    while (!q.empty()) {
      int f = q.front();
      q.pop();
      for (int j = 0; j < graph[f].size(); j++) {
        if (a[i][graph[f][j]] == 0 && graph[f][j] != i) {
          a[i][graph[f][j]] = a[i][f] + 1;
          q.push(graph[f][j]);
        }
      }
    }
  }
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      ans[a[i][j]]++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

int N, X, Y, a[3004][3004], ans[10005];
vector<int> graph[3004];
queue<int> q;

int main() {
  cin >> N >> X >> Y;
  for (int i = 2; i < N; i++) {
    graph[i].push_back(i - 1);
    graph[i].push_back(i + 1);
  }
  graph[1].push_back(2);
  graph[N].push_back(N - 1);
  graph[X].push_back(Y);
  graph[Y].push_back(X);
  for (int i = 1; i <= N; i++) {
    a[i][i] = 0;
    q.push(i);
    while (!q.empty()) {
      int f = q.front();
      q.pop();
      for (int j = 0; j < graph[f].size(); j++) {
        if (a[i][graph[f][j]] == 0 && graph[f][j] != i) {
          a[i][graph[f][j]] = a[i][f] + 1;
          q.push(graph[f][j]);
        }
      }
    }
  }
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      ans[a[i][j]]++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn][maxn], ans[maxn];
int main() {
  int n, k, x, y;
  cin >> n >> x >> y;
  fo(i, 1, n - 1) {
    fo(j, i + 1, n) {
      if (i <= x && j >= y)
        a[i][j] = j - i - (y - x - 1), a[j][i] = j - i - (y - x - 1);
      else
        a[i][j] = a[j][j] = min(j - i, abs(x - i) + abs(y - j) + 1);
    }
  }
  fo(i, 1, n) {
    fo(j, i + 1, n) { ans[a[i][j]]++; }
  }
  fo(i, 1, n - 1) { cout << ans[i] << endl; }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 2e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn][maxn], ans[maxn];
int main() {
  int n, k, x, y;
  cin >> n >> x >> y;
  fo(i, 1, n - 1) {
    fo(j, i + 1, n) {
      if (i <= x && j >= y)
        a[i][j] = j - i - (y - x - 1), a[j][i] = j - i - (y - x - 1);
      else
        a[i][j] = a[j][j] = min(j - i, abs(x - i) + abs(y - j) + 1);
    }
  }
  fo(i, 1, n) {
    fo(j, i + 1, n) { ans[a[i][j]]++; }
  }
  fo(i, 1, n - 1) { cout << ans[i] << endl; }
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

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

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

using namespace std;

const int MAXN = 1e3 + 10;

int n, x, y;
int sol[MAXN];

int main(void) {
  scanf("%d%d%d", &n, &x, &y);
  --x;
  --y;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int d = min(abs(i - j), min(1 + abs(i - x) + abs(j - y),
                                  1 + abs(i - y) + abs(j - x)));
      sol[d]++;
    }
  }
  for (int i = 1; i < n; ++i)
    printf("%d\n", sol[i]);
  return 0;
}


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

using namespace std;

const int MAXN = 2e3 + 10;

int n, x, y;
int sol[MAXN];

int main(void) {
  scanf("%d%d%d", &n, &x, &y);
  --x;
  --y;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int d = min(abs(i - j), min(1 + abs(i - x) + abs(j - y),
                                  1 + abs(i - y) + abs(j - x)));
      sol[d]++;
    }
  }
  for (int i = 1; i < n; ++i)
    printf("%d\n", sol[i]);
  return 0;
}
Problem p02726 (C++)

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

/*
O(|E|log|V|)

P.first = shortest path, P.second = vertex index
G[v] = vector of edge (from v)
d[v] = shortest path from s to v
*/

struct edge {
  int to, cost;
};

void dijkstra(vector<vector<edge>> &G, vector<int> &d, int s) {
  int V = G.size();
  const int INF = 10e8;
  priority_queue<P, vector<P>, greater<P>> que;

  rep(i, V) d[i] = 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;
    rep(i, G[v].size()) {
      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 N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<edge>> G(N);
  rep(i, N - 1) {
    G[i].push_back((edge){i + 1, 1});
    G[i + 1].push_back((edge){i, 1});
  }
  --X;
  --Y;
  G[X].push_back((edge){Y, 1});
  G[Y].push_back((edge){X, 1});

  vector<int> ans(N);
  rep(i, N) {
    vector<int> d(N);
    dijkstra(G, d, i);
    rep(j, N) {
      if (1 <= d[j] <= N - 1) {
        ++ans[d[j] - 1];
      }
    }
  }

  rep(k, N - 1) { cout << ans[k] / 2 << endl; }
}

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

/*
O(|E|log|V|)

P.first = shortest path, P.second = vertex index
G[v] = vector of edge (from v)
d[v] = shortest path from s to v
*/

struct edge {
  int to, cost;
};

void dijkstra(vector<vector<edge>> &G, vector<int> &d, int s) {
  int V = G.size();
  const int INF = 10e8;
  priority_queue<P, vector<P>, greater<P>> que;

  rep(i, V) d[i] = 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;
    rep(i, G[v].size()) {
      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 N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<edge>> G(N);
  rep(i, N - 1) {
    G[i].push_back((edge){i + 1, 1});
    G[i + 1].push_back((edge){i, 1});
  }
  --X;
  --Y;
  G[X].push_back((edge){Y, 1});
  G[Y].push_back((edge){X, 1});

  vector<int> ans(N);
  rep(i, N) {
    vector<int> d(N);
    dijkstra(G, d, i);
    rep(j, N) {
      if (1 <= d[j] && d[j] <= N - 1) {
        ++ans[d[j] - 1];
      }
    }
  }

  rep(k, N - 1) { cout << ans[k] / 2 << 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<vector<int>> dist_mat(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++)
      dist_mat[i][j] = j - i;
    ;
  }
  // bypass
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int i_dist = abs(X - 1 - i);
      int j_dist = abs(Y - 1 - j);
      dist_mat[i][j] = min(dist_mat[i][j], 1 + i_dist + j_dist);
    }
  }

  for (int k = 1; k < N; k++) {
    int count = 0;
    for (const auto &row : dist_mat)
      for (const auto &col : row)
        if (col == k)
          count++;
    cout << count << endl;
  }
}


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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;

  vector<vector<int>> dist_mat(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++)
      dist_mat[i][j] = j - i;
    ;
  }
  // bypass
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int i_dist = abs(X - 1 - i);
      int j_dist = abs(Y - 1 - j);
      dist_mat[i][j] = min(dist_mat[i][j], 1 + i_dist + j_dist);
    }
  }
  vector<int> counts(N, 0);
  for (const auto &row : dist_mat)
    for (const auto &col : row)
      counts[col] += 1;
  for (int k = 1; k < N; k++)
    cout << counts[k] << endl;
}
Problem p02726 (C++)

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

using namespace std;

const int N = 2020;
vector<int> g[N];
int d[1024][1024];

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

  memset(d, 255, sizeof(d));
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;

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

  for (int i = 0; i < n; i++) {
    vector<int> q;
    q.push_back(i);
    d[i][i] = 0;
    int qj = 0;
    while (qj < q.size()) {
      int curr = q[qj];
      qj++;
      int cd = d[i][curr];
      for (int nxt : g[curr]) {
        if (d[i][nxt] == -1) {
          d[i][nxt] = cd + 1;
          q.push_back(nxt);
        }
      }
    }
  }

  map<int, int> res;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      res[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << res[i] << "\n";
  }

  return 0;
}


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

using namespace std;

const int N = 2020;
vector<int> g[N];
int d[N][N];

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

  memset(d, 255, sizeof(d));
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;

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

  for (int i = 0; i < n; i++) {
    vector<int> q;
    q.push_back(i);
    d[i][i] = 0;
    int qj = 0;
    while (qj < q.size()) {
      int curr = q[qj];
      qj++;
      int cd = d[i][curr];
      for (int nxt : g[curr]) {
        if (d[i][nxt] == -1) {
          d[i][nxt] = cd + 1;
          q.push_back(nxt);
        }
      }
    }
  }

  map<int, int> res;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      res[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << res[i] << "\n";
  }

  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, x, y, dist[N], ans[N];
vector<int> gg[N];
bool used[N];
queue<int> q;
int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> x >> y;
  for (int i = 1; i <= n - 1; i++) {
    gg[i].push_back(i + 1);
    gg[i + 1].push_back(i);
  }
  gg[x].push_back(y);
  gg[y].push_back(x);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      used[j] = false;
      dist[j] = 0;
    }
    q.push(i);
    used[i] = true;
    dist[i] = 0;
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int j = 0; j < gg[cur].size(); j++) {
        int child = gg[cur][j];
        if (used[child] == false) {
          q.push(child);
          used[child] = true;
          dist[child] = dist[cur] + 1;
        }
      }
    }
    for (int j = 1; j <= n; j++) {
      ans[dist[j]]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    ans[i] = ans[i] / 2;
    cout << ans[i] << '\n';
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int n, x, y, dist[N], ans[N];
vector<int> gg[N];
bool used[N];
queue<int> q;
int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> x >> y;
  for (int i = 1; i <= n - 1; i++) {
    gg[i].push_back(i + 1);
    gg[i + 1].push_back(i);
  }
  gg[x].push_back(y);
  gg[y].push_back(x);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      used[j] = false;
      dist[j] = 0;
    }
    q.push(i);
    used[i] = true;
    dist[i] = 0;
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int j = 0; j < gg[cur].size(); j++) {
        int child = gg[cur][j];
        if (used[child] == false) {
          q.push(child);
          used[child] = true;
          dist[child] = dist[cur] + 1;
        }
      }
    }
    for (int j = 1; j <= n; j++) {
      ans[dist[j]]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    ans[i] = ans[i] / 2;
    cout << ans[i] << '\n';
  }
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll MAX = 100000;
int cnt[1005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  // if (x != 1 || y != n) {
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      if (i < x) {
        if (j <= x)
          cnt[j - i]++;
        else if (j > x && j <= y)
          cnt[min(j - i, x - i + 1 + y - j)]++;
        else
          cnt[x - i + 1 + j - y]++;
      } else if (i >= x && i <= y) {
        if (j <= y)
          cnt[min(j - i, i - x + 1 + y - j)]++;
        else
          cnt[min(j - i, i - x + 1 + j - y)]++;
      } else
        cnt[j - i]++;
  for (int i = 1; i <= n - 1; ++i)
    cout << cnt[i] << endl;
  //}
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll MAX = 100000;
int cnt[2005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  // if (x != 1 || y != n) {
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      if (i < x) {
        if (j <= x)
          cnt[j - i]++;
        else if (j > x && j <= y)
          cnt[min(j - i, x - i + 1 + y - j)]++;
        else
          cnt[x - i + 1 + j - y]++;
      } else if (i >= x && i <= y) {
        if (j <= y)
          cnt[min(j - i, i - x + 1 + y - j)]++;
        else
          cnt[min(j - i, i - x + 1 + j - y)]++;
      } else
        cnt[j - i]++;
  for (int i = 1; i <= n - 1; ++i)
    cout << cnt[i] << endl;
  //}
  return 0;
}
Problem p02726 (C++)

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

const int MAX_N = 1e3 + 5;

int n, x, y, dis[MAX_N], ans[MAX_N];
std::vector<int> adj[MAX_N];
bool vis[MAX_N];

int main() {
  scanf("%d%d%d", &n, &x, &y);
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 2; i < n; ++i) {
    adj[i].push_back(i + 1);
    adj[i].push_back(i - 1);
  }
  if (n > 1)
    adj[1].push_back(2);
  if (n > 1)
    adj[n].push_back(n - 1);
  for (int i = 1; i < n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    std::queue<int> q;
    vis[i] = true;
    dis[i] = 0;
    for (q.push(i); !q.empty(); q.pop()) {
      for (int j : adj[q.front()])
        if (!vis[j]) {
          dis[j] = dis[q.front()] + 1;
          vis[j] = true;
          q.push(j);
        }
    }
    for (int j = i + 1; j <= n; ++j)
      ++ans[dis[j]];
  }
  for (int i = 1; i < n; ++i)
    printf("%d\n", ans[i]);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

const int MAX_N = 2e3 + 5;

int n, x, y, dis[MAX_N], ans[MAX_N];
std::vector<int> adj[MAX_N];
bool vis[MAX_N];

int main() {
  scanf("%d%d%d", &n, &x, &y);
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 2; i < n; ++i) {
    adj[i].push_back(i + 1);
    adj[i].push_back(i - 1);
  }
  if (n > 1)
    adj[1].push_back(2);
  if (n > 1)
    adj[n].push_back(n - 1);
  for (int i = 1; i < n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    std::queue<int> q;
    vis[i] = true;
    dis[i] = 0;
    for (q.push(i); !q.empty(); q.pop()) {
      for (int j : adj[q.front()])
        if (!vis[j]) {
          dis[j] = dis[q.front()] + 1;
          vis[j] = true;
          q.push(j);
        }
    }
    for (int j = i + 1; j <= n; ++j)
      ++ans[dis[j]];
  }
  for (int i = 1; i < n; ++i)
    printf("%d\n", ans[i]);
}
Problem p02726 (C++)

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

typedef long long int ll;

#define pb push_back
#define mp make_pair

const ll maxs = 305;
ll inf = 1e18;

ll cost[maxs][maxs];
ll dp[maxs][maxs];
ll n;

void warshall() {
  for (ll k = 1; k <= n; k++)
    for (ll i = 1; i <= n; i++)
      for (ll j = 1; j <= n; j++)
        if (dp[i][j] > dp[i][k] + dp[k][j])
          dp[i][j] = dp[i][k] + dp[k][j];
}

// Use when new roads to be build
void update(ll s, ll d, ll w) {
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (dp[i][j] > dp[i][s] + w + dp[d][j])
        dp[i][j] = dp[i][s] + w + dp[d][j];

      if (dp[i][j] > dp[i][d] + w + dp[s][j])
        dp[i][j] = dp[i][d] + w + dp[s][j];
    }
  }
}

int main() {
  ll x, y;
  cin >> n >> x >> y;

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      cost[i][j] = abs(i - j);
      dp[i][j] = cost[i][j];
    }
  }

  /*  for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    } */

  update(x, y, 1);

  ll res[n + 1];
  memset(res, 0, sizeof res);
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = i + 1; j <= n; j++) {
      res[dp[i][j]]++;
    }
  }

  for (ll i = 1; i < n; i++)
    cout << res[i] << endl;

  return 0;
}

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

typedef long long int ll;

#define pb push_back
#define mp make_pair

const ll maxs = 3005;
ll inf = 1e18;

ll cost[maxs][maxs];
ll dp[maxs][maxs];
ll n;

void warshall() {
  for (ll k = 1; k <= n; k++)
    for (ll i = 1; i <= n; i++)
      for (ll j = 1; j <= n; j++)
        if (dp[i][j] > dp[i][k] + dp[k][j])
          dp[i][j] = dp[i][k] + dp[k][j];
}

// Use when new roads to be build
void update(ll s, ll d, ll w) {
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (dp[i][j] > dp[i][s] + w + dp[d][j])
        dp[i][j] = dp[i][s] + w + dp[d][j];

      if (dp[i][j] > dp[i][d] + w + dp[s][j])
        dp[i][j] = dp[i][d] + w + dp[s][j];
    }
  }
}

int main() {
  ll x, y;
  cin >> n >> x >> y;

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      cost[i][j] = abs(i - j);
      dp[i][j] = cost[i][j];
    }
  }

  /*  for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    } */

  update(x, y, 1);

  ll res[n + 1];
  memset(res, 0, sizeof res);
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = i + 1; j <= n; j++) {
      res[dp[i][j]]++;
    }
  }

  for (ll i = 1; i < n; i++)
    cout << res[i] << endl;

  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
// file creato da gio il 2020-03-31 21:23:51.244903

#include <iostream>
#define FAST

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;
int arr[2000];
//[2000]
int main() {
  // freopen("output","w",stdout);
  // freopen("input","r",stdin);
#ifdef FAST
  ios::sync_with_stdio(0);
  cin.tie(0);
#endif

  int N, X, Y;
  cin >> N >> X >> Y;
  X -= 1;
  Y -= 1;
  for (int i = 1; i < N; i++) {
    arr[i] = N - i;
  }
  for (int i = 0; i <= X; i++) {
    for (int j = Y; j < N; j++) {
      arr[j - i]--;
      arr[j - i - (Y - X) + 1]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << arr[i] << endl;
  }
}

Fixed submission:
// file creato da gio il 2020-03-31 21:23:51.244903

#include <iostream>
#define FAST

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;
int arr[2000];
//[2000]
int main() {
  // freopen("output","w",stdout);
  // freopen("input","r",stdin);
#ifdef FAST
  ios::sync_with_stdio(0);
  cin.tie(0);
#endif

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

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  map<int, long> m;
  for (int i = 1; i < N; i++) {
    m[i] = 0;
  }

  int a[N - 1][N - 1];
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      a[i][j] = j - i;
    }
  }

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      a[i][j] = min(a[i][j], a[i][X] + 1 + a[Y][j]);
      m[a[i][j]]++;
    }
  }

  for (auto x : m) {
    cout << x.second << endl;
  }
}


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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  map<int, long> m;
  for (int i = 1; i < N; i++) {
    m[i] = 0;
  }

  int a[N][N];

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      a[i][j] = abs(j - i);
    }
  }

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      a[i][j] = min(a[i][j], a[i][X] + 1 + a[Y][j]);
      m[a[i][j]]++;
    }
  }

  for (auto x : m) {
    cout << x.second << endl;
  }
}
Problem p02726 (C++)

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

int main() {
  int N, x, y, D[MAX], i, j, d, d1, d2;
  cin >> N >> x >> y;
  for (i = 1; i <= N; i++)
    D[i] = 0;
  for (i = 1; i < N; i++) {
    for (j = i + 1; j <= N; j++) {
      d1 = j - i;
      d2 = abs(y - j) + abs(x - i) + 1;
      d = min(d1, d2);
      D[d]++;
    }
  }
  for (i = 1; i < N; i++)
    cout << D[i] << endl;
}


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

int main() {
  int N, x, y, D[MAX], i, j, d, d1, d2;
  cin >> N >> x >> y;
  for (i = 1; i <= N; i++)
    D[i] = 0;
  for (i = 1; i < N; i++) {
    for (j = i + 1; j <= N; j++) {
      d1 = j - i;
      d2 = abs(y - j) + abs(x - i) + 1;
      d = min(d1, d2);
      D[d]++;
    }
  }
  for (i = 1; i < N; i++)
    cout << D[i] << endl;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 100;
#define ll long long

vector<int> s[N];

void add(int x, int y) {
  s[x].push_back(y);
  s[y].push_back(x);
}

int a[N];
vector<int> v;

void solve() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; ++i) {
    add(i, i + 1);
  }
  add(x, y);
  for (int i = 1; i <= n; ++i) {
    priority_queue<pair<int, int>> Q;
    Q.push(make_pair(0, i));
    int vis[N] = {0};
    vis[i] = 1;
    while (!Q.empty()) {
      pair<int, int> p = Q.top();
      Q.pop();
      a[-p.first]++;
      for (int j = 0, st = s[p.second].size(); j < st; ++j) {
        int m = s[p.second][j];
        if (!vis[m]) {
          vis[m] = 1;
          Q.push(make_pair(p.first - 1, m));
        }
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\n", a[i] / 2);
  }
}

int main() { solve(); }


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 100;
#define ll long long

vector<int> s[N];

void add(int x, int y) {
  s[x].push_back(y);
  s[y].push_back(x);
}

int a[N];
vector<int> v;

void solve() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; ++i) {
    add(i, i + 1);
  }
  add(x, y);
  for (int i = 1; i <= n; ++i) {
    priority_queue<pair<int, int>> Q;
    Q.push(make_pair(0, i));
    int vis[N] = {0};
    vis[i] = 1;
    while (!Q.empty()) {
      pair<int, int> p = Q.top();
      Q.pop();
      a[-p.first]++;
      for (int j = 0, st = s[p.second].size(); j < st; ++j) {
        int m = s[p.second][j];
        if (!vis[m]) {
          vis[m] = 1;
          Q.push(make_pair(p.first - 1, m));
        }
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\n", a[i] / 2);
  }
}

int main() { solve(); }
Problem p02726 (C++)

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

using namespace std;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> v(N - 1, vector<int>(N - 1));
  vector<int> ans(N - 1);

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      v[i][j] = min(j - i, abs(Y - j - 1) + 1 + abs(X - i - 1));
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (v[i][j] > 0) {
        int ind = v[i][j] - 1;
        ans[ind] += 1;
      }
    }
  }

  for (int x : ans) {
    cout << x << endl;
  }
}

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

using namespace std;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> v(N, vector<int>(N));
  vector<int> ans(N - 1);

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      v[i][j] = min(j - i, abs(Y - j - 1) + 1 + abs(X - i - 1));
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (v[i][j] > 0) {
        int ind = v[i][j] - 1;
        ans[ind] += 1;
      }
    }
  }

  for (int x : ans) {
    cout << x << endl;
  }
}