alexjercan/bugnet huggingface dataset:
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define re register
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define lb long double
const int N = 1e6 + 10;
const int mod = 10086;
const int mod2 = 19260811;
void read(int &a) {
  a = 0;
  int d = 1;
  char ch;
  while (ch = getchar(), ch > '9' || ch < '0')
    if (ch == '-')
      d = -1;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9')
    a = (a << 3) + (a << 1) + (ch ^ 48);
  a *= d;
}
int a[N];
int main() {
  int k, n;
  read(k), read(n);
  for (re int i = 1; i <= n; i++)
    read(a[i]);
  int maxn = a[1] + k - a[n];
  for (re int i = 2; i <= n; i++)
    maxn = max(maxn, a[i] - a[i - 1]);
  printf("%d\\n", k - maxn);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define re register
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define lb long double
const int N = 1e4 + 10;
const int mod = 10086;
const int mod2 = 19260811;
void read(int &a) {
  a = 0;
  int d = 1;
  char ch;
  while (ch = getchar(), ch > '9' || ch < '0')
    if (ch == '-')
      d = -1;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9')
    a = (a << 3) + (a << 1) + (ch ^ 48);
  a *= d;
}
int a[N];
int main() {
  int k, n;
  read(k), read(n);
  for (re int i = 1; i <= n; i++)
    read(a[i]);
  int maxn = a[1] + k - a[n];
  for (re int i = 2; i <= n; i++)
    maxn = max(maxn, a[i] - a[i - 1]);
  printf("%d\\n", k - maxn);
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int k, n;
  int kukan[200007];
  int housedis;
  int a[200007];
  int max = 0;
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  housedis = a[n - 1] - a[0];

  for (int i = 0; i < n - 1; i++) {
    kukan[i] = a[i + 1] - a[i];
  }
  kukan[n - 1] = k - housedis;
  for (int i = 0; i < n; i++) {
    if (kukan[i] > max) {
      max = kukan[i];
    }
  }

  cout << k - max << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int k, n;
  int kukan[100000];
  int housedis;
  int a[100000];
  int max = 0;
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  housedis = a[n - 1] - a[0];

  for (int i = 0; i < n - 1; i++) {
    kukan[i] = a[i + 1] - a[i];
  }
  kukan[n - 1] = k - housedis;
  for (int i = 0; i < n; i++) {
    if (kukan[i] > max) {
      max = kukan[i];
    }
  }

  cout << k - max << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first              // For pairs
#define ss second             // For pairs
#define sz(a) int((a).size()) // Function to determine size of any container
#define pb push_back          // Pushback to vector
#define mp make_pair          // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()
#define tr(container, it)                                                      \\
  for (auto it = container.begin(); it != container.end();                     \\
       it++) // traversing macro
#define present(c, x) (c.find(x) != c.end())

using namespace std;
typedef vector<ll> vi;           // Vector of long long
typedef vector<vi> vvi;          // Vector of vi
typedef vector<pair<ll, ll>> ii; // Vector of pairs
typedef vector<ii> vii;          // Vector of ii
int main() {
  ll n, k;
  cin >> k >> n;
  vi a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (n == 2) {
    cout << min(a[1] - a[0], k - a[1] + a[0]) << "\\n";
  } else {
    ll ans = a[n - 1] - a[0];
    for (int i = 0; i < n - 1; i++) {
      ans = min(k - a[i + 1] + a[i], ans);
    }
    cout << ans << "\\n";
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first              // For pairs
#define ss second             // For pairs
#define sz(a) int((a).size()) // Function to determine size of any container
#define pb push_back          // Pushback to vector
#define mp make_pair          // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()
#define tr(container, it)                                                      \\
  for (auto it = container.begin(); it != container.end();                     \\
       it++) // traversing macro
#define present(c, x) (c.find(x) != c.end())

using namespace std;
typedef vector<ll> vi;           // Vector of long long
typedef vector<vi> vvi;          // Vector of vi
typedef vector<pair<ll, ll>> ii; // Vector of pairs
typedef vector<ii> vii;          // Vector of ii
int main() {
  ll n, k;
  cin >> k >> n;
  vi a;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (n == 2) {
    cout << min(a[1] - a[0], k - a[1] + a[0]) << "\\n";
  } else {
    cout << a[n - 1] - a[0] << "\\n";
  }

  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for (int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\\n'
#define all(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 200010;
const int inf = 0x3f3f3f3f;

int n, k;
int a[maxn];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //  freopen(Task".inp", "r", stdin);
  cin >> k >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = k;
  for (int i = 0; i < n - 1; ++i) {
    ans = min(ans, k + a[i] - a[i + 1]);
  }
  ans = min(ans, a[n - 1] - a[0]);
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for (int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\\n'
#define all(x) (x).begin(), (x).end()
#define mp make_pair

void openfile();
typedef unsigned long long ull;
typedef long long ll;

const int maxn = 200010;
const int inf = 0x3f3f3f3f;

int n, k;
int a[maxn], b[maxn];

int main() {
  //  openfile();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = k - a[i];
  }
  int ans = k;
  for (int i = 0; i < n; ++i) {
    // case 1
    ans = min(ans, k - a[i] + a[(i + 1) % k]);
    // case 2
    ans = min(ans, k - a[i] + a[(i - 1 + k) % k]);
  }
  cout << ans;
  return 0;
}

void openfile() {
  freopen(Task ".inp", "r", stdin);
  freopen(Task ".out", "w", stdout);
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int K, N;
  int A[220000];

  cin >> K >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int rightRes = 0;
  int leftRes = 0;
  int leftMax = 0;
  int rightMax = 0;
  for (int i = 0; i < N; ++i) {
    if (i == N - 1) {
      rightRes += K - A[i] + A[0];

      if (K - A[i] + A[0] > rightMax) {
        rightMax = K - A[i] + A[0];
      }
    } else {
      rightRes += A[i + 1] - A[i];
      if (A[i + 1] - A[i] > rightMax) {
        rightMax = A[i + 1] - A[i];
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      leftRes += K - A[N - 1] + A[0];
      if (K - A[N - 1] + A[0] > leftMax) {
        leftMax = K - A[N - 1] + A[0];
      }
    } else {
      leftRes += A[i] - A[i - 1];
      if (A[i] - A[i - 1] > leftMax) {
        leftMax = A[i + 1] - A[i];
      }
    }
  }
  rightRes -= rightMax;
  leftRes -= leftMax;

  if (rightRes > leftRes)
    cout << leftRes << endl;
  else
    cout << rightRes << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int K, N;
  int A[22000];

  cin >> K >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int rightRes = 0;
  int leftRes = 0;
  int leftMax = 0;
  int rightMax = 0;
  for (int i = 0; i < N; ++i) {
    if (i == N - 1) {
      rightRes += K - A[i] + A[0];

      if (K - A[i] + A[0] > rightMax) {
        rightMax = K - A[i] + A[0];
      }
    } else {
      rightRes += A[i + 1] - A[i];
      if (A[i + 1] - A[i] > rightMax) {
        rightMax = A[i + 1] - A[i];
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      leftRes += K - A[N - 1] + A[0];
      if (K - A[N - 1] + A[0] > leftMax) {
        leftMax = K - A[N - 1] + A[0];
      }
    } else {
      leftRes += A[i] - A[i - 1];
      if (A[i] - A[i - 1] > leftMax) {
        leftMax = A[i + 1] - A[i];
      }
    }
  }
  rightRes -= rightMax;
  leftRes -= leftMax;

  if (rightRes > leftRes)
    cout << leftRes << endl;
  else
    cout << rightRes << endl;
}
Problem p02725 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void solve(long long K, long long N, std::vector<long long> A) {
  sort(A.begin(), A.end());

  long long pairwise_max = -1;
  for (auto i = 0; i < A.size() - 1; ++i) {
    long long diff = abs(A[i + 1] - A[i]);
    pairwise_max = max(pairwise_max, diff);
  }

  pairwise_max = max(pairwise_max, K - A.back() + A[0]);
  cout << K - pairwise_max << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long K;
  scanf("%lld", &K);
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(K, N, std::move(A));
  return 0;
}


Error: TLE

Fixed submission:

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

void solve(long long K, long long N, std::vector<long long> A) {
  sort(A.begin(), A.end());

  long long oldd = 10e9 + 1;
  long long d;
  for (auto a = 0; a < A.size(); ++a) {
    long long d = 0;
    for (auto i = 0; i < A.size() - 1; ++i) {
      long long addend = (A[i + 1] - A[i] + K) % K;
      d += addend;
    }

    if (oldd == -1 or d < oldd)
      oldd = d;

    std::rotate(A.begin(), A.begin() + 1, A.end());
  }

  cout << oldd << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long K;
  scanf("%lld", &K);
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(K, N, std::move(A));
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

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

ll k;
ll n;
vector<int> a;
ll ans = 10e6 + 1;

ll clockwiseFrom(int i) {
  if (i > 0) {
    return (a[i - 1] + k) - a[i];
  } else {
    return a[n - 1] - a[i];
  }
}

ll anticlockFrom(int i) {
  if (i > 0) {
    return k - (a[i + 1] - a[i]);
  } else {
    return k - (a[1] - a[0]);
  }
}

int main() {
  cin >> k >> n;
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }

  for (int i = 0; i < n; i++) {
    ans = min(clockwiseFrom(i), ans);
    ans = min(anticlockFrom(i), ans);
  }

  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

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

ll k;
ll n;
vector<int> a;
ll ans = 10e6 + 1;

ll clockwiseFrom(int i) {
  if (i > 0) {
    return (a[i - 1] + k) - a[i];
  } else {
    return a[n - 1] - a[i];
  }
}

ll anticlockFrom(int i) {
  if (i > 0) {
    return k - (a[i + i] - a[i]);
  } else {
    return k - (a[1] - a[0]);
  }
}

int main() {
  cin >> k >> n;
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }

  for (int i = 0; i < n; i++) {
    ans = min(clockwiseFrom(i), ans);
    cout << ans << " ";
    ans = min(anticlockFrom(i), ans);
    cout << ans << " ";
  }

  cout << ans;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for (ll i = 0; i < n; i++)
#define rep2(n) for (ll j = 0; j < n; ++j)
#define repd(n) for (ll i = n - 1; i >= 0; i--)
#define MOD 1000000007
#define pii pair<ll, ll>
#define vll vector<ll>
#define ff first
#define ss second
typedef vector<vector<ll>> mat;
#define nl "\\n"
#define INF 0x3f3f3f3f
#define sz(a) a.size()

void solve() {
  ll n, k;
  cin >> k >> n;
  ll a[n];
  rep(n) cin >> a[i];
  sort(a, a + n);
  ll mx = -1;
  rep(n - 1) { mx = max(mx, a[i + 1] - a[i]); }
  cout << k - max(mx, a[0] - a[n - 1] + k);
}

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

  ll t = 1;
  // cin>>t;
  rep(t) { solve(); }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for (ll i = 0; i < n; i++)
#define rep2(n) for (ll j = 0; j < n; ++j)
#define repd(n) for (ll i = n - 1; i >= 0; i--)
#define MOD 1000000007
#define pii pair<ll, ll>
#define vll vector<ll>
#define ff first
#define ss second
typedef vector<vector<ll>> mat;
#define nl "\\n"
#define INF 0x3f3f3f3f
#define sz(a) a.size()

void solve() {
  ll n, k;
  cin >> n >> k;
  vll a(k);
  rep(k) cin >> a[i];
  sort(a.begin(), a.end());
  rep(k) {
    if (a[i] > n / 2 + a[0])
      a[i] -= n;
  }
  sort(a.begin(), a.end());
  ll mid = a[k / 2];
  ll s = 0;
  for (ll i = mid; i < k - 1; ++i)
    s = s + a[i + 1] - a[i];
  for (ll i = mid; i > 0; --i)
    s = s + a[i] - a[i - 1];
  cout << s;
}

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

  ll t = 1;
  // cin>>t;
  rep(t) { solve(); }
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

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

#define ull unsigned long long
#define endl '\\n'
#define ll long long
const int N = 2e5 + 5;
ll a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen(".INP", "r")) {
    freopen(".INP", "r", stdin);
    freopen(".OUT", "w", stdout);
  }
  ll k, n;
  cin >> k >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  a[0] = a[n] - k;
  ll ans = k;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, k - (a[i] - a[i - 1]));
  }
  cout << ans;
}


Error: WA

Fixed submission:

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

#define ull unsigned long long
#define endl '\\n'
#define ll long long
const int N = 1e5 + 5;
ll a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen(".INP", "r")) {
    freopen(".INP", "r", stdin);
    freopen(".OUT", "w", stdout);
  }
  ll k, n;
  cin >> k >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  a[0] = a[n] - k;
  ll ans = k;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, k - (a[i] - a[i - 1]));
  }
  cout << ans;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...)                                                              \\
  {                                                                            \\
    cerr << "\\033[32;1m" << #x << " -> ";                                      \\
    err(x);                                                                    \\
  }
void err() { cerr << "\\033[39;0m" << endl; }
template <typename T, typename... A> void err(T a, A... x) {
  cerr << a << ' ';
  err(x...);
}
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 2e5 + 50;
int n, a[N], k;
int main(int argc, char const *argv[]) {
  // code
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d", &a[i]);
  }
  int mx = 0;
  a[k] = n + a[0];
  for (int i = 0; i < k; ++i)
    mx = max(mx, a[i + 1] - a[i]);
  cout << n - mx << endl;
  return 0;
}


Error: 0

Fixed submission:

// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...)                                                              \\
  {                                                                            \\
    cerr << "\\033[32;1m" << #x << " -> ";                                      \\
    err(x);                                                                    \\
  }
void err() { cerr << "\\033[39;0m" << endl; }
template <typename T, typename... A> void err(T a, A... x) {
  cerr << a << ' ';
  err(x...);
}
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 1e5 + 50;
int n, a[N], k;
int main(int argc, char const *argv[]) {
  // code
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d", &a[i]);
  }
  int mx = 0;
  a[k] = n + a[0];
  for (int i = 0; i < k; ++i)
    mx = max(mx, a[i + 1] - a[i]);
  cout << n - mx << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  a.push_back(
      a[0] +
      k); // 円環は数直線に展開する（2kに伸ばしてやる）0をまたぐ部分を追加

  int l = 0;
  rep(i, n) { l = max(l, a[i + 1] - a[i]); }
  int ans = k - l;
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

signed main() {

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

  int maxD = 0;
  int position = 0;
  bool turnRignt = true;
  // どこからスタートかのi
  for (int i = 0; i < N - 1; ++i) {
    if (maxD < abs(A[i] - A[i + 1])) {
      maxD = abs(A[i] - A[i + 1]);
      position = i;

      if (abs(A[i] - A[i + 1]) < abs(K - (abs(A[i] - A[i + 1])))) {
        turnRignt = true;
      } else {
        turnRignt = false;
      }
    }
  }

  int totalMinD2 = 0;
  // どこからスタートかのi
  int i = position;
  while (true) {
    if (turnRignt) {
      if (abs(A[i] - A[i + 1]) < abs(K - (abs(A[i] - A[i + 1])))) {
        totalMinD2 += abs(A[i] - A[i + 1]);
      } else {
        totalMinD2 += abs(K - (abs(A[i] - A[i + 1])));
      }
      i++;
      if (i == position) {
        break;
      }
      if (i == N - 1) {
        i = 0;
        if (i == position) {
          break;
        }
        if (abs(A[N - 1] - A[0]) < abs(K - (abs(A[N - 1] - A[0])))) {
          totalMinD2 += abs(A[N - 1] - A[0]);
        } else {
          totalMinD2 += abs(K - (abs(A[N - 1] - A[0])));
        }
      }
    } else {
      if (abs(A[i] - A[i - 1]) < abs(K - (abs(A[i] - A[i - 1])))) {
        totalMinD2 += abs(A[i] - A[i - 1]);
      } else {
        totalMinD2 += abs(K - (abs(A[i] - A[i - 1])));
      }
      i--;
      if (i == position) {
        break;
      }
      if (i == 1) {
        i = N - 1;
        if (i == position) {
          break;
        }
        if (abs(A[N - 1] - A[0]) < abs(K - (abs(A[N - 1] - A[0])))) {
          totalMinD2 += abs(A[N - 1] - A[0]);
        } else {
          totalMinD2 += abs(K - (abs(A[N - 1] - A[0])));
        }
      }
    }
  }

  cout << totalMinD2 << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define nl "\\n"
#define pb push_back
#define sp " "
typedef long long ll;
#define len(x) x.length()
#define vsort(x) sort(x.begin(), x.end();
using namespace std;
ll inf = 2e18;

int main()

{

  ios::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
// freopen("bruh.txt","r",stdin);
#endif
  int k, n;
  cin >> k >> n;
  ll temp, a, mx = 0;
  cin >> temp;
  ll bru = temp;
  n--;
  while (n--) {
    cin >> a;
    mx = max(mx, abs(temp - a));
    temp = a;
  }
  // cout<<bru <<sp<<temp<<nl;
  mx = max(mx, abs(k - temp) + bru);
  cout << k - mx << nl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define nl "\\n"
#define pb push_back
#define sp " "
typedef long long ll;
#define len(x) x.length()
#define vsort(x) sort(x.begin(), x.end();
using namespace std;
ll inf = 2e18;

int main()

{

  ios::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("bruh.txt", "r", stdin);
#endif
  int k, n;
  cin >> k >> n;
  ll temp, a, mx = 0;
  cin >> temp;
  n--;
  while (n--) {
    cin >> a;
    mx = max(mx, abs(temp - a));
    temp = a;
  }
  cout << k - mx << nl;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
const int INF = 1 << 30;
const int maxn = 2e5 + 5;
int a[maxn];
int ans = INF;
int main() {
  int k, n;
  cin >> k >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++) {
    ans = min(ans, k - (a[i + 1] - a[i]));
  }
  ans = min(ans, a[n] - a[1]);
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
const int INF = 1 << 30;
const int maxn = 2e5 + 5;
int a[maxn];
int ans = INF;
int main() {
  int k, n;
  cin >> k >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int t;
    if (i == 1)
      t = min(a[n] - a[1], a[1] + k - a[2]);
    else if (i == n)
      t = min(a[n - 1] + k - a[n], a[n] - a[1]);
    else
      t = min(a[i - 1] + k - a[k], a[k] + k - a[k + 1]);
    ans = min(ans, t);
  }
  cout << ans << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stdio.h>
#include <string.h>
int lst[200010];
int main() {
  int k;
  int n;
  int ans;
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> lst[i];
  }
  ans = -lst[n - 1] + lst[0] + k;
  for (int i = 0; i < n - 1; i++) {
    if (lst[i + 1] - lst[i] > ans)
      ans = lst[i + 1] - lst[i];
  }
  cout << k - ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stdio.h>
#include <string.h>
int lst[110];
int main() {
  int k;
  int n;
  int ans;
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> lst[i];
  }
  ans = -lst[n - 1] + lst[0] + k;
  for (int i = 0; i < n - 1; i++) {
    if (lst[i + 1] - lst[i] > ans)
      ans = lst[i + 1] - lst[i];
  }
  cout << k - ans << endl;
  return 0;
}