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

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

using namespace std;

const int MAXN = 1e5 + 10;

int n, k;

int a[MAXN];

const int MOD = 1e9 + 7;

int main() {
  cin >> k >> n;

  int maxVal = -1;
  cin >> a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    maxVal = max(maxVal, a[i] - a[i - 1]);
  }

  maxVal = max(maxVal, k - a[n - 1] + a[0]);

  cout << k - maxVal;
}

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

using namespace std;

const int MAXN = 2e5 + 10;

int n, k;

int a[MAXN];

const int MOD = 1e9 + 7;

int main() {
  cin >> k >> n;

  int maxVal = -1;
  cin >> a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    maxVal = max(maxVal, a[i] - a[i - 1]);
  }

  maxVal = max(maxVal, k - a[n - 1] + a[0]);

  cout << k - maxVal;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long k, maX, ans, n, i;
long long a[100000];
int main() {
  cin >> i >> n;
  for (k = 1; k <= n; k++) {
    cin >> a[k];
  }
  sort(a + 1, a + 1 + n);
  for (k = 2; k <= n; k++) {
    maX = max(a[k] - a[k - 1], maX);
  }
  maX = max(maX, a[1] - a[n] + i);
  cout << i - maX;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long k, maX, ans, n, i;
long long a[10000000];
int main() {
  cin >> i >> n;
  for (k = 1; k <= n; k++) {
    cin >> a[k];
  }
  sort(a + 1, a + 1 + n);
  for (k = 2; k <= n; k++) {
    maX = max(a[k] - a[k - 1], maX);
  }
  maX = max(maX, a[1] - a[n] + i);
  cout << i - maX;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;

inline int mulmd(ll a, ll b) {
  ll ret = (a * b) % MOD;
  return (int)ret;
}

inline int power(ll x, ll y, int m) {
  ll res = 1;
  x = x % m;
  while (y > 0) {
    if (y & 1) {
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int)res;
}

inline int submd(ll a, ll b) {
  ll ret = (a - b);
  if (ret < 0)
    ret += MOD;
  return (int)ret;
}

inline int addmd(ll a, ll b) {
  ll ret = (a + b) % MOD;
  return (int)ret;
}

inline int invPow(ll a) { return power(a, MOD - 2, MOD); }

inline int divmd(ll a, ll b) {
  ll ret = mulmd(a, invPow(b));
  return (int)ret;
}

const int N = 1e5 + 5;

int arr[N];

void solve() {
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<int> diff;
  for (int i = 1; i < n; i++) {
    diff.push_back(arr[i] - arr[i - 1]);
  }
  diff.push_back(k - arr[n - 1] + arr[0]);
  sort(diff.begin(), diff.end());
  int ans = k - diff[diff.size() - 1];
  cout << ans;
}

int main() {
  int t;
  t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;

inline int mulmd(ll a, ll b) {
  ll ret = (a * b) % MOD;
  return (int)ret;
}

inline int power(ll x, ll y, int m) {
  ll res = 1;
  x = x % m;
  while (y > 0) {
    if (y & 1) {
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int)res;
}

inline int submd(ll a, ll b) {
  ll ret = (a - b);
  if (ret < 0)
    ret += MOD;
  return (int)ret;
}

inline int addmd(ll a, ll b) {
  ll ret = (a + b) % MOD;
  return (int)ret;
}

inline int invPow(ll a) { return power(a, MOD - 2, MOD); }

inline int divmd(ll a, ll b) {
  ll ret = mulmd(a, invPow(b));
  return (int)ret;
}

const int N = 2e5 + 5;

int arr[N];

void solve() {
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<int> diff;
  for (int i = 1; i < n; i++) {
    diff.push_back(arr[i] - arr[i - 1]);
  }
  diff.push_back(k - arr[n - 1] + arr[0]);
  sort(diff.begin(), diff.end());
  int ans = k - diff[diff.size() - 1];
  cout << ans;
}

int main() {
  int t;
  t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}
Problem p02725 (C++)

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

using namespace std;
int k, n, a[200010], minn;
int main() {
  cin >> k >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    int ans = 0;
    int j = i;
    int f = (i == 0) ? (n - 1) : (i - 1);
    while (1) {
      ans = ans + (a[j + 1] - a[j] + k) % k;
      j++;
      j %= n;
      if (j == f)
        break;
    }
    if (i == 0)
      minn = ans;
    else
      minn = min(minn, ans);
  }
  cout << minn;
  return 0;
}

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

using namespace std;
int k, n, a[200010], minn;
int main() {
  cin >> k >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    int ans = 0;
    int f = (i + n - 1) % n;
    ans = (a[f] - a[i] + k) % k;
    if (i == 0)
      minn = ans;
    else
      minn = min(minn, ans);
  }
  cout << minn;
  return 0;
}
Problem p02725 (C++)

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

#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int k, n;
  cin >> k >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int maxi = -1;
  for (int i = 0; i < n - 1; i++)
    maxi = max(maxi, a[i + 1] - a[i]);
  maxi = max(maxi, k - a[n - 1] + a[0]);
  cout << k - maxi << endl;

  return 0;
}

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

#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
#endif
  int k, n;
  cin >> k >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int maxi = -1;
  for (int i = 0; i < n - 1; i++)
    maxi = max(maxi, a[i + 1] - a[i]);
  maxi = max(maxi, k - a[n - 1] + a[0]);
  cout << k - maxi << endl;

  return 0;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int a[100010];
int main() {
  int n, k;
  cin >> k >> n;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0) {
      mx = max(mx, a[i] - a[i - 1]);
    }
  }
  mx = max(mx, a[0] + k - a[n - 1]);
  cout << k - mx << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int a[200010];
int main() {
  int n, k;
  cin >> k >> n;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0) {
      mx = max(mx, a[i] - a[i - 1]);
    }
  }
  mx = max(mx, a[0] + k - a[n - 1]);
  cout << k - mx << endl;
  return 0;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 100;
ll a[maxn];
int main() {
  int n, k;
  cin >> k >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  a[n + 1] = k + a[1];
  n++;
  ll sum = 0, mx = 0;
  for (int i = 2; i <= n; i++) {
    sum += a[i] - a[i - 1];
    mx = max(mx, a[i] - a[i - 1]);
  }
  sum -= mx;
  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 100;
ll a[maxn];
int main() {
  int n, k;
  cin >> k >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  a[n + 1] = k + a[1];
  n++;
  ll sum = 0, mx = 0;
  for (int i = 2; i <= n; i++) {
    sum += a[i] - a[i - 1];
    mx = max(mx, a[i] - a[i - 1]);
  }
  sum -= mx;
  cout << sum << endl;

  return 0;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int a[100005];
void solve() {
  int k, n;
  cin >> k >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ans = a[n - 1] - a[0];
  for (int i = 1; i < n; i++) {
    ans = min(ans, k - a[i] + a[i - 1]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //	cin>> t;
  while (t--)
    solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int a[200005];
void solve() {
  int k, n;
  cin >> k >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ans = a[n - 1] - a[0];
  for (int i = 1; i < n; i++) {
    ans = min(ans, k - a[i] + a[i - 1]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //	cin>> t;
  while (t--)
    solve();
  return 0;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
// Best practice

#include <bits/stdc++.h>

#define int long long
#define pb push_back
#define pf emplace_front
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pii pair<int, int>
#define psi pair<string, int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define sz(x) (int)(x).size()
#define x first
#define y second
#define endl '\n'
#define tezz                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define MOD 1000000007
#define hell 998244353
#define output(x) cout << (x ? "YES" : "NO") << endl;
using namespace std;

// Code from Here
// -------------------------------------------------------------------------------

signed main() {
  tezz

#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int p, n;
  cin >> p >> n;
  int dis = 0;
  vi a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0) {
      dis = max(dis, a[i] - a[i - 1]);
    }
  }
  dis = max(dis, a[0] + p - a[n - 1]);
  cout << p - dis;

  return 0;
}


Fixed submission:
// Best practice

#include <bits/stdc++.h>

#define int long long
#define pb push_back
#define pf emplace_front
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pii pair<int, int>
#define psi pair<string, int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define sz(x) (int)(x).size()
#define x first
#define y second
#define endl '\n'
#define tezz                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define MOD 1000000007
#define hell 998244353
#define output(x) cout << (x ? "YES" : "NO") << endl;
using namespace std;

// Code from Here
// -------------------------------------------------------------------------------

signed main() {
  tezz int p, n;
  cin >> p >> n;
  int dis = 0;
  vi a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0) {
      dis = max(dis, a[i] - a[i - 1]);
    }
  }
  dis = max(dis, a[0] + p - a[n - 1]);
  cout << p - dis;

  return 0;
}
Problem p02725 (C++)

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

using namespace std;

int main() {
  int k, n;
  cin >> k >> n;
  int a[100001];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int m, ans;
  ans = a[n - 1] - a[0];
  for (int i = 0; i < n - 1; i++) {
    int s = (k - a[i + 1]) + a[i];
    ans = min(ans, s);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  int k, n;
  cin >> k >> n;
  int a[200001];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int m, ans;
  ans = a[n - 1] - a[0];
  for (int i = 0; i < n - 1; i++) {
    int s = (k - a[i + 1]) + a[i];
    ans = min(ans, s);
  }
  cout << ans << endl;
  return 0;
}
Problem p02725 (C++)

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

int main() {
  int K, N, maxv = 0;
  int A[100000];

  cin >> K >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  maxv = K - A[N - 1] + A[0];
  for (int i = 0; i < N; i++) {
    maxv = max(maxv, A[i + 1] - A[i]);
  }

  cout << K - maxv << endl;
}


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

int main() {
  int K, N, maxv = 0;
  int A[1000000];

  cin >> K >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  maxv = K - A[N - 1] + A[0];
  for (int i = 0; i < N; i++) {
    maxv = max(maxv, A[i + 1] - A[i]);
  }

  cout << K - maxv << endl;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
int main(void) {
  int k, n, a[100000000], b[10000000], i, p = 0, l;
  scanf("%d%d", &k, &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i != 0) {
      b[i] = a[i] - a[i - 1];
    }
  }
  b[0] = k - a[n - 1] + a[0];
  std::sort(b, b + n);
  for (i = 0; i < n - 1; i++) {
    p += b[i];
  }
  printf("%d\n", p);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <stdio.h>
int main(void) {
  int k, n, a[10000000], b[10000000], i, p = 0, l;
  scanf("%d%d", &k, &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i != 0) {
      b[i] = a[i] - a[i - 1];
    }
  }
  b[0] = k - a[n - 1] + a[0];
  std::sort(b, b + n);
  for (i = 0; i < n - 1; i++) {
    p += b[i];
  }
  printf("%d\n", p);
  return 0;
}
Problem p02725 (C++)

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

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

signed main() {
  int k, n;
  cin >> k >> n;
  int a[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = k + a[0];

  int ans = k;
  for (int i = 0; i < n; i++) {
    chmin(ans, k - (a[i + 1] - a[i]));
  }

  cout << ans << endl;

  return 0;
}


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

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

signed main() {
  int k, n;
  cin >> k >> n;
  int a[200010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = k + a[0];

  int ans = k;
  for (int i = 0; i < n; i++) {
    chmin(ans, k - (a[i + 1] - a[i]));
  }

  cout << ans << endl;

  return 0;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i;
  long long sum = 0;
  long long arr[100005];
  scanf("%lld%lld", &n, &k);
  for (i = 0; i < k; i++) {
    scanf("%lld", &arr[i]);
  }
  sort(arr, arr + k);
  for (i = 1; i < k; i++) {
    sum = max(sum, arr[i] - arr[i - 1]);
  }
  sum = max(sum, n - arr[k - 1] + arr[0]);
  printf("%lld", n - sum);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i;
  long long sum = 0;
  long long arr[200005];
  scanf("%lld%lld", &n, &k);
  for (i = 0; i < k; i++) {
    scanf("%lld", &arr[i]);
  }
  sort(arr, arr + k);
  for (i = 1; i < k; i++) {
    sum = max(sum, arr[i] - arr[i - 1]);
  }
  sum = max(sum, n - arr[k - 1] + arr[0]);
  printf("%lld", n - sum);
}
Problem p02725 (C++)

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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int main() {
  c_p_c();
  int k, m;
  cin >> k >> m;
  int a[m];
  fo(i, m) cin >> a[i];
  int ans = a[m - 1] - a[0];
  Fo(i, 1, m) { ans = min(a[i - 1] + k - a[i], ans); }
  cout << ans << endl;
  return 0;
}

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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  //	freopen("output.txt", "w", stdout);
  // #endif
}

int main() {
  c_p_c();
  int k, m;
  cin >> k >> m;
  int a[m];
  fo(i, m) cin >> a[i];
  int ans = a[m - 1] - a[0];
  Fo(i, 1, m) { ans = min(a[i - 1] + k - a[i], ans); }
  cout << ans << endl;
  return 0;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N, a;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  a = K + A.at(0) - A.at(N - 1);
  for (int i = 0; i < N; i++) {
    if (A.at(i + 1) - A.at(i) > a) {
      a = A.at(i + 1) - A.at(i);
    }
  }
  cout << K - a << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N, a;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  a = K + A.at(0) - A.at(N - 1);
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i + 1) - A.at(i) > a) {
      a = A.at(i + 1) - A.at(i);
    }
  }
  cout << K - a << endl;
}
Problem p02725 (C++)

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

const int N = 2 * 100 * 1000 + 20;
int n, k, a[N], ans;

int main() {
  cin >> k >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < k; i++)
    ans = max(ans, a[i] - a[i - 1]);
  ans = max(ans, a[0] + k - a[n - 1]);
  return cout << k - ans << "\n", 0;
}

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

const int N = 2 * 100 * 1000 + 20;
int n, k, a[N], ans;

int main() {
  cin >> k >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    ans = max(ans, a[i] - a[i - 1]);
  ans = max(ans, a[0] + k - a[n - 1]);
  return cout << k - ans << "\n", 0;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
int k, n, a[123456];
signed main() {
  cin >> k >> n;
  for1(i, n) cin >> a[i];
  int ans = a[n] - a[1];
  for1(i, n - 1) ans = min(ans, a[i] + k - a[i + 1]);
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
int k, n, a[234536];
signed main() {
  cin >> k >> n;
  for1(i, n) cin >> a[i];
  int ans = a[n] - a[1];
  for1(i, n - 1) ans = min(ans, a[i] + k - a[i + 1]);
  cout << ans << endl;
}
Problem p02725 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i];
  }
  int ans = 1e9;
  for (int i = 1; i <= k; i++) {
    if (i == 1)
      ans = min(ans, n - (a[1] + n - a[k]));
    else
      ans = min(ans, n - (a[i] - a[i - 1]));
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000005];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i];
  }
  int ans = 1e9;
  for (int i = 1; i <= k; i++) {
    if (i == 1)
      ans = min(ans, n - (a[1] + n - a[k]));
    else
      ans = min(ans, n - (a[i] - a[i - 1]));
  }
  cout << ans;
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int n, x, y;
int ans[1001], viz[1001];
int modul(int x, int y) {
  if (x > y)
    return x - y;
  else
    return y - x;
}
int main() {
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      int minim = min(modul(j, i), min(modul(x, i) + 1 + modul(j, y),
                                       modul(y, i) + 1 + modul(j, x)));
      ans[minim]++;
    }
  for (int i = 1; i < n; i++)
    cout << ans[i] << '\n';
  return 0;
}


Fixed submission:
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int n, x, y;
int ans[3003], viz[2001];
int modul(int x, int y) {
  if (x > y)
    return x - y;
  else
    return y - x;
}
int main() {
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      int minim = min(modul(j, i), min(modul(x, i) + 1 + modul(j, y),
                                       modul(y, i) + 1 + modul(j, x)));
      ans[minim]++;
    }
  for (int i = 1; i < n; i++)
    cout << ans[i] << '\n';
  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, f, e) for (int(i) = (f); (i) < (e); (i)++)
#define repr(i, e, f) for (int(i) = (e - 1); (i) >= (f); (i)--)

const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

deque<int> G[2010];
int K[2010];

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

  rep(i, 1, N) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);

  // rep(i,1,N+1){
  //     cout << i << " : ";
  //     for(auto j : G[i]){
  //         cout << j << " ";
  //     }
  //     cout << endl;
  // }

  rep(i, 1, N + 1) {
    vector<int> dist(N + 1, -1);
    queue<int> que;

    dist[i] = 0;
    for (int j = i - 1; j = 0; j--) {
      dist[j] = INF;
    }
    que.push(i);

    while (!que.empty()) {
      int v = que.front(); // キューから先頭頂点を取り出す
      que.pop();

      // v から辿れる頂点をすべて調べる
      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue; // すでに発見済みの頂点は探索しない
        // 新たな白色頂点 nv について距離情報を更新してキューに追加する
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }

    rep(k, 1, N) {
      rep(v, i, N + 1) {
        if (k == dist[v])
          K[k] += 1;
      }
    }
  }

  rep(k, 1, N) { cout << K[k] << endl; }

  return 0;
}

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

const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

deque<int> G[2010];
int K[2010];

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

  rep(i, 1, N) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);

  // rep(i,1,N+1){
  //     cout << i << " : ";
  //     for(auto j : G[i]){
  //         cout << j << " ";
  //     }
  //     cout << endl;
  // }

  rep(i, 1, N + 1) {
    vector<int> dist(N + 1, -1);
    queue<int> que;

    dist[i] = 0;
    for (int j = i - 1; j = 0; j--) {
      dist[j] = INF;
    }
    que.push(i);

    while (!que.empty()) {
      int v = que.front(); // キューから先頭頂点を取り出す
      que.pop();

      // v から辿れる頂点をすべて調べる
      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue; // すでに発見済みの頂点は探索しない
        // 新たな白色頂点 nv について距離情報を更新してキューに追加する
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }

    rep(v, i, N + 1) { K[dist[v]] += 1; }
  }

  rep(k, 1, N) { cout << K[k] << endl; }

  return 0;
}
Problem p02726 (C++)

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

using namespace std;

#define int long long
#define fi first
#define se second
#define inf 1e9
const int mod = (int)1e9 + 7;
vector<int> adj[1005];
vector<int> vis(1005), dist(1005), ans(1005);

void bfs(int v) {
  queue<int> q;
  q.push(v);
  vis[v] = 1;
  dist[v] = 0;
  while (!q.empty()) {
    auto x = q.front();
    q.pop();
    for (auto u : adj[x]) {
      if (vis[u])
        continue;
      q.push(u);
      dist[u] = dist[x] + 1;
      vis[u] = 1;
    }
  }
}

void test_case() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  for (int i = 0; i < n - 1; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      vis[j] = 0, dist[j] = 0;
    bfs(i);
    for (int j = 0; j < n; j++)
      ans[dist[j]]++;
  }
  for (int i = 1; i <= n - 1; i++)
    cout << ans[i] / 2 << "\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    test_case();
}


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

using namespace std;

#define int long long
#define fi first
#define se second
#define inf 1e9
const int mod = (int)1e9 + 7;
vector<int> adj[2005];
vector<int> vis(2005), dist(2005), ans(2005);

void bfs(int v) {
  queue<int> q;
  q.push(v);
  vis[v] = 1;
  dist[v] = 0;
  while (!q.empty()) {
    auto x = q.front();
    q.pop();
    for (auto u : adj[x]) {
      if (vis[u])
        continue;
      q.push(u);
      dist[u] = dist[x] + 1;
      vis[u] = 1;
    }
  }
}

void test_case() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  for (int i = 0; i < n - 1; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      vis[j] = 0, dist[j] = 0;
    bfs(i);
    for (int j = 0; j < n; j++)
      ans[dist[j]]++;
  }
  for (int i = 1; i <= n - 1; i++)
    cout << ans[i] / 2 << "\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    test_case();
}
Problem p02726 (C++)

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

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

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

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

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

  for (int i = 1; i < n; i++) {
    cout << distances[i] << endl;
  }
  return 0;
}
Problem p02726 (C++)

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

int main() {
  int N, X, Y, i, j, ans, dist, list[2001] = {0};

  // stdinから入力受付
  cin >> N >> X >> Y;
  X--;
  Y--; // 0からの値に変換

  // メイン処理
  for (i = 0; i < N - 1; i++) {   // 始点
    for (j = i + 1; j < N; j++) { // 目的地
      // 道を必ず通る場合
      if (abs(i - X) < abs(i - Y))
        dist = abs(i - X) + 1 + abs(j - Y);
      else
        dist = abs(i - Y) + 1 + abs(j - X);
      // 直接行く場合と比較、短いほうをdistに入れる
      if (j - i < dist)
        dist = j - i;
      // list配列のdist番目を1増やす
      list[dist]++;
      cerr << i << ' ' << j << ' ' << dist << endl; // デバッグ出力(stderr)
    }
  }

  // 答えをstdoutに出力
  for (i = 1; i < N; i++)
    cout << list[i] << endl;
}

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

int main() {
  int N, X, Y, i, j, ans, dist, list[2001] = {0};

  // stdinから入力受付
  cin >> N >> X >> Y;
  X--;
  Y--; // 0からの値に変換

  // メイン処理
  for (i = 0; i < N - 1; i++) {   // 始点
    for (j = i + 1; j < N; j++) { // 目的地
      // 道を必ず通る場合
      if (abs(i - X) < abs(i - Y))
        dist = abs(i - X) + 1 + abs(j - Y);
      else
        dist = abs(i - Y) + 1 + abs(j - X);
      // 直接行く場合と比較、短いほうをdistに入れる
      if (j - i < dist)
        dist = j - i;
      // list配列のdist番目を1増やす
      list[dist]++;
    }
  }

  // 答えをstdoutに出力
  for (i = 1; i < N; i++)
    cout << list[i] << endl;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
// BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 1005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }

int cnt[1005];

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

  int n, x, y;

  cin >> n >> x >> y;

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

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


Fixed submission:
// BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 1005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }

int cnt[2005];

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

  int n, x, y;

  cin >> n >> x >> y;

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

  for (int i = 1; i <= n - 1; i++) {
    cout << cnt[i] << endl;
  }
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x, y) x = max(x, y)
#define gmin(x, y) x = min(x, y)
#define gadd(x, y) x = add(x, y)
#define gmul(x, y) x = mul(x, y)
using namespace std;

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

const int N = 1e3 + 5;

int cnt[N];

int n, x, y;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> x >> y;
  rep(i, 1, n + 1) {
    rep(j, i + 1, n + 1) {
      int res = min(j - i, abs(i - x) + 1 + abs(y - j));
      ++cnt[res];
    }
  }
  rep(i, 1, n) cout << cnt[i] << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x, y) x = max(x, y)
#define gmin(x, y) x = min(x, y)
#define gadd(x, y) x = add(x, y)
#define gmul(x, y) x = mul(x, y)
using namespace std;

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

const int N = 2e3 + 5;

int cnt[N];

int n, x, y;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> x >> y;
  rep(i, 1, n + 1) {
    rep(j, i + 1, n + 1) {
      int res = min(j - i, abs(i - x) + 1 + abs(y - j));
      ++cnt[res];
    }
  }
  rep(i, 1, n) cout << cnt[i] << '\n';
}
Problem p02726 (C++)

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

using namespace std;
using ll = long long;
const int Inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> dis(n, vector<int>(n));
  vector<int> freq(n);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      dis[i][j] = min(
          {j - i, 1 + abs(x - i) + abs(y - j), 1 + abs(x - j) + abs(y - i)});
      freq[dis[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << freq[i] << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
const int Inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> dis(n + 1, vector<int>(n + 1));
  vector<int> freq(n);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      dis[i][j] = min(
          {j - i, 1 + abs(x - i) + abs(y - j), 1 + abs(x - j) + abs(y - i)});
      freq[dis[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << freq[i] << endl;
  }
  return 0;
}
Problem p02726 (C++)

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

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

  ll i, j, k, l, m, n, w, x, y, z, p, q, tmp, sum = 0;
  ll a[1000];
  string str;
  cin >> n >> x >> y;
  ;
  x--;
  y--;
  rep(i, n - 1) {
    REP(j, i + 1, n) {
      a[min(j - i, abs(j - y) + 1 + abs(x - i))]++;
      // cout<<i<<" "<<j<<" "<<min(j-i,abs(j-y)+1+abs(x-i))<<endl;
    }
  }
  rep(i, n) {
    if (i == 0)
      continue;
    cout << a[i] << endl;
  }

  return 0;
}

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

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

  ll i, j, k, l, m, n, w, x, y, z, p, q, tmp, sum = 0;
  ll a[100000];
  string str;
  cin >> n >> x >> y;
  ;
  x--;
  y--;
  rep(i, n - 1) {
    REP(j, i + 1, n) {
      a[min(j - i, abs(j - y) + 1 + abs(x - i))]++;
      // cout<<i<<" "<<j<<" "<<min(j-i,abs(j-y)+1+abs(x-i))<<endl;
    }
  }
  rep(i, n) {
    if (i == 0)
      continue;
    cout << a[i] << endl;
  }

  return 0;
}
Problem p02726 (C++)

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

const int MAXN = 1e3 + 5;

int n, x, y;
int dist[MAXN][MAXN], ans[MAXN];

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

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

const int MAXN = 2e3 + 5;

int n, x, y;
int dist[MAXN][MAXN], ans[MAXN];

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[1010];
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++) {
      if (x <= i && y >= j) {
        a[min(j - i, i - x + y - j + 1)]++;
      } else {
        if (x >= i && y <= j) {
          a[j - i - (y - x) + 1]++;
        } else {
          if (j >= x && j <= y && i <= x) {
            a[min(j - i, y - j + x - i + 1)]++;
          } else {
            if (j >= y && i <= y && i >= x) {
              a[min(j - i, i - x + j - y + 1)]++;
            } else {
              a[j - i]++;
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << a[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[2010];
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++) {
      if (x <= i && y >= j) {
        a[min(j - i, i - x + y - j + 1)]++;
      } else {
        if (x >= i && y <= j) {
          a[j - i - (y - x) + 1]++;
        } else {
          if (j >= x && j <= y && i <= x) {
            a[min(j - i, y - j + x - i + 1)]++;
          } else {
            if (j >= y && i <= y && i >= x) {
              a[min(j - i, i - x + j - y + 1)]++;
            } else {
              a[j - i]++;
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << a[i] << endl;
  }
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;

struct edge {
  int v, nxt;
} e[N];
int p[N], eid;
int ans[N], d[N];

void bfs(int s) {
  memset(d, 0x3f, sizeof(d));
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = p[u]; ~i; i = e[i].nxt) {
      int v = e[i].v;
      if (d[u] + 1 < d[v]) {
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  memset(p, -1, sizeof(p));
  for (int i = 2; i <= n; ++i) {
    e[eid] = edge{i, p[i - 1]};
    p[i - 1] = eid++;
    e[eid] = edge{i - 1, p[i]};
    p[i] = eid++;
  }
  e[eid] = edge{y, p[x]};
  p[x] = eid++;
  e[eid] = edge{x, p[y]};
  p[y] = eid++;

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

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

struct edge {
  int v, nxt;
} e[N * 2];
int p[N], eid;
int ans[N], d[N];

void bfs(int s) {
  memset(d, 0x3f, sizeof(d));
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = p[u]; ~i; i = e[i].nxt) {
      int v = e[i].v;
      if (d[u] + 1 < d[v]) {
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  memset(p, -1, sizeof(p));
  for (int i = 2; i <= n; ++i) {
    e[eid] = edge{i, p[i - 1]};
    p[i - 1] = eid++;
    e[eid] = edge{i - 1, p[i]};
    p[i] = eid++;
  }
  e[eid] = edge{y, p[x]};
  p[x] = eid++;
  e[eid] = edge{x, p[y]};
  p[y] = eid++;

  for (int i = 1; i <= n; ++i) {
    bfs(i);
    for (int i = 1; i <= n; ++i)
      ans[d[i]]++;
  }
  for (int i = 1; i <= n - 1; ++i)
    cout << ans[i] / 2 << endl;
  return 0;
}
Problem p02726 (C++)

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

using namespace std;

#define ll long long
const int N = 1e3 + 5;

queue<int> q;
int n;
struct node {
  int from, to, next;
} f[2 * N];
int head[N], tot;
int ans[N], vis[N], dis[N];

void add(int a, int b) {
  f[++tot].from = a;
  f[tot].to = b;
  f[tot].next = head[a];
  head[a] = tot;
}

void clean() {
  memset(dis, 0x7f, sizeof(dis));
  memset(vis, 0, sizeof(vis));
}

void spfa(int s) {
  dis[s] = 0;
  vis[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    // cout << head[now];
    for (int i = head[now]; i != -1; i = f[i].next) {
      int v = f[i].to;
      // cout << v;
      if (dis[v] > dis[now] + 1) {
        dis[v] = dis[now] + 1;
        if (!vis[v]) {
          vis[v] = 1;
          q.push(v);
        }
      }
    }
  }
}

int main() {
  int x, y;
  memset(head, -1, sizeof(head));
  cin >> n >> x >> y;
  for (int i = 2; i <= n; i++)
    add(i - 1, i), add(i, i - 1);
  add(x, y), add(y, x);
  for (int i = 1; i <= n; i++) {
    clean();
    spfa(i);
    // cout << i << "GG ";
    for (int j = i + 1; j <= n; j++)
      ans[dis[j]]++; // cout<<dis[j] << " ";
    // cout << endl;
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
}

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

using namespace std;

#define ll long long
const int N = 1e4 + 5;

queue<int> q;
int n;
struct node {
  int from, to, next;
} f[2 * N];
int head[N], tot;
int ans[N], vis[N], dis[N];

void add(int a, int b) {
  f[++tot].from = a;
  f[tot].to = b;
  f[tot].next = head[a];
  head[a] = tot;
}

void clean() {
  memset(dis, 0x7f, sizeof(dis));
  memset(vis, 0, sizeof(vis));
}

void spfa(int s) {
  dis[s] = 0;
  vis[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    // cout << head[now];
    for (int i = head[now]; i != -1; i = f[i].next) {
      int v = f[i].to;
      // cout << v;
      if (dis[v] > dis[now] + 1) {
        dis[v] = dis[now] + 1;
        if (!vis[v]) {
          vis[v] = 1;
          q.push(v);
        }
      }
    }
  }
}

int main() {
  int x, y;
  memset(head, -1, sizeof(head));
  cin >> n >> x >> y;
  for (int i = 2; i <= n; i++)
    add(i - 1, i), add(i, i - 1);
  add(x, y), add(y, x);
  for (int i = 1; i <= n; i++) {
    clean();
    spfa(i);
    // cout << i << "GG ";
    for (int j = i + 1; j <= n; j++)
      ans[dis[j]]++; // cout<<dis[j] << " ";
    // cout << endl;
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
}
Problem p02726 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  int t = y - x - 1;
  for (int i = 1; i < n; ++i) {
    int res = 0;
    for (int j = 0; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
        if (min(k - j, abs(k - y) + abs(j - x) + 1) == i)
          ++res;
      }
    }
    cout << res << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  vector<int> ans(n - 1);
  for (int j = 0; j < n; ++j)
    for (int k = j + 1; k < n; ++k)
      ++ans[min(k - j, abs(k - y) + abs(j - x) + 1) - 1];
  for (auto a : ans)
    cout << a << endl;

  return 0;
}
Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define per(i, a, b) for (ll i = (a)-1; i >= (b); i--)
const ll maxn = 2e3;
ll q[maxn], d[maxn], u[maxn], s, e, c, ans[maxn], n, x, y;
vector<ll> ady[maxn];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> x >> y;
  rep(i, 1, n) ady[i].push_back(i + 1), ady[i + 1].push_back(i);
  ady[x].push_back(y), ady[y].push_back(x);
  rep(i, 1, n + 1) {
    s = e = 0;
    q[e++] = i, d[i] = 0, u[i] = ++c;
    while (s < e) {
      ll j = q[s++];
      for (ll to : ady[j])
        if (u[to] != c)
          q[e++] = to, d[to] = d[j] + 1, u[to] = c;
    }
    rep(j, 1, n + 1) ans[d[j]]++;
  }
  rep(i, 1, n) cout << ans[i] / 2 << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define per(i, a, b) for (ll i = (a)-1; i >= (b); i--)
const ll maxn = 2e3 + 5;
ll q[maxn], d[maxn], u[maxn], s, e, c, ans[maxn], n, x, y;
vector<ll> ady[maxn];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> x >> y;
  rep(i, 1, n) ady[i].push_back(i + 1), ady[i + 1].push_back(i);
  ady[x].push_back(y), ady[y].push_back(x);
  rep(i, 1, n + 1) {
    s = e = 0;
    q[e++] = i, d[i] = 0, u[i] = ++c;
    while (s < e) {
      ll j = q[s++];
      for (ll to : ady[j])
        if (u[to] != c)
          q[e++] = to, d[to] = d[j] + 1, u[to] = c;
    }
    rep(j, 1, n + 1) ans[d[j]]++;
  }
  rep(i, 1, n) cout << ans[i] / 2 << "\n";
}