alexjercan/bugnet huggingface dataset:
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  const ll r = N % K;
  const ll s = K - r;
  cout << (r < s ? r : s) << endl;
  return 0;
}


Error: TLE

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  if (K == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll x = N;
  while (K < 2 * x) {
    x = abs(x - K);
  }
  cout << x << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout                                                                   \\
  if (false)                                                                   \\
  cout
#define debug() if (false)
#define check(x)                                                               \\
  if (false)                                                                   \\
  cout << "★" << #x << "の値:" << (x) << endl
#define pass(x)                                                                \\
  if (false)                                                                   \\
  cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  ll N, M;
  cin >> N >> M;
  cout << min(N % M, abs(N % M - M));
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\\n";
*/


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout                                                                   \\
  if (false)                                                                   \\
  cout
#define debug() if (false)
#define check(x)                                                               \\
  if (false)                                                                   \\
  cout << "★" << #x << "の値:" << (x) << endl
#define pass(x)                                                                \\
  if (false)                                                                   \\
  cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;

  cout << N % M;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\\n";
*/
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  ll x = n % k;

  cout << min(x, k - x);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  ll min_n = INTMAX_MAX;
  ll check_first = INTMAX_MAX;
  if (k == 1)
    cout << "0";
  else {
    while (n <= min_n && check_first > 0) {
      min_n = abs(n - k);
      check_first = n - k;
      n = min(n, min_n);
    }

    cout << n;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < int(n); ++i)
using namespace std;
template <class A> void pr(A a) { cout << a << endl; }
template <class A, class B> void pr(A a, B b) {
  cout << a << " ";
  pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
  cout << a << " ";
  pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
  cout << a << " ";
  pr(b, c, d);
}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF = numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  ll n, k;
  cin >> n >> k;
  ll res;
  ll cnt = n / k;
  res = n - k * cnt;
  res = min(res, abs(res - k));
  pr(res);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < int(n); ++i)
using namespace std;
template <class A> void pr(A a) { cout << a << endl; }
template <class A, class B> void pr(A a, B b) {
  cout << a << " ";
  pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
  cout << a << " ";
  pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
  cout << a << " ";
  pr(b, c, d);
}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF = numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  ll n, k;
  cin >> n >> k;
  ll res = n;
  while (abs(res - k) < res) {
    res = abs(res - k);
  }
  pr(res);
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  n = n % k;
  if (n == 0 || (n < k && n < abs(n - k))) {

    cout << n << endl;
    return 0;
  } else
    cout << abs(n - k) << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  n = n % k;
  if (n == 0 || (n < k && n < abs(n - k))) {

    cout << n << endl;
    return 0;
  } else
    cout << abs(n - k) << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long shoki, hiku;
  cin >> shoki >> hiku;

  long kekkaichi;
  kekkaichi = shoki % hiku;

  long kekkani;
  kekkani = kekkaichi - hiku;
  kekkani = abs(kekkani);

  if (shoki <= kekkaichi && shoki <= kekkani) {
    cout << shoki << endl;
  } else if (kekkaichi <= shoki && kekkaichi <= kekkani) {
    cout << kekkaichi << endl;
  } else {
    cout << kekkani << endl;
  }
}

Error: WA

Fixed submission:

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

int main() {
  int shoki, hiku;
  cin >> shoki >> hiku;

  int kekka;
  kekka = shoki % hiku;

  if (kekka > shoki) {
    cout << shoki << endl;
  } else {
    cout << kekka << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  long N, K;
  cin >> N >> K;

  long Q;
  Q = N / K;
  long hi, low;
  hi = abs(N - Q * K);
  low = abs(N - (Q + 1) * K);
  if (hi < abs(low)) {
    cout << hi << endl;
  } else {
    cout << low << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {

  long N, K;
  cin >> N >> K;

  long dif = abs(N - K);

  if (N % K == 0) {
    N = 0;
  } else {
    while (N > dif) {
      N = dif;
      dif = abs(N - K);
    }
  }
  cout << N << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;           // 10^19 < 9223372036854775807
typedef unsigned long long ull; // 10^20 < 18446744073709551615

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

#define MOD 1000000007

int main(void) {
  ll N, K;
  cin >> N >> K;
  cout << min(N % K, K - (N % K)) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;           // 10^19 < 9223372036854775807
typedef unsigned long long ull; // 10^20 < 18446744073709551615

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

#define MOD 1000000007

int main(void) {
  ll N, K;
  cin >> N >> K;

  while (N >= abs(N - K)) {
    N = abs(N - K);
  }

  cout << N << endl;

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

#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
void NK(lli &N, lli &K) {
  while (true) {
    if (abs(N - K) < N)
      N = abs(N - K);
    else
      break;
  }
}
int main() {
  lli N, K;
  cin >> N >> K;
  if (N <= K) {
    NK(N, K);
  } else {
    lli rem = N % K;
    if (!rem)
      N = 0;
    else {
      N -= (N / K) * K;
      NK(N, K);
    }
  }
  cout << N;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  lli N, K;
  cin >> N >> K;
  if (abs(N - K) < N) {
    N > K ? cout << N % (abs(N - K)) : cout << K % (abs(N - K));
  } else
    cout << N;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#define mod 1000000007
#define ll long long
#define pi acos(-1)
using namespace std;
const double INF = 1e20;

int main() {
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  n = n % k;
  n = (n < k - n) ? n : k - n;
  cout << n;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#define mod 1000000007
#define ll long long
#define pi acos(-1)
using namespace std;
const double INF = 1e20;

int main() {
  ios::sync_with_stdio(false);
  unsigned ll n, k;
  cin >> n >> k;
  unsigned ll p;
  if (n > k)
    p = n - k;
  else
    p = k - n;
  while (p < n) {
    n = p;
    if (n == 0)
      break;
    if (n > k)
      p = n - k;
    else
      p = k - n;
  }
  cout << n;

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

#include <bits/stdc++.h>
using namespace std;
#define BIGINF (int)4e18 + 7
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF (int)2e9 + 7
#define SCD(t) scanf("%d", &t)
#define SCLD(t) scanf("%ld", &t)
#define SCLLD(t) scanf("%lld", &t)
#define SCC(t) scanf("%c", &t)
#define SCS(t) scanf("%s", t)
#define SCF(t) scanf("%f", &t)
#define SCLF(t) scanf("%lf", &t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("inputf.txt", "r", stdin);
  // freopen("outputf.txt", "w", stdout);
  // #endif
  ll n, k;
  SCLLD(n);
  SCLLD(k);
  if (n == 0) {
    printf("0");
  } else {
    long long ans = n % k;
    ans = min(ans, abs(ans - k));
    printf("%lld", ans);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define BIGINF (int)4e18 + 7
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF (int)2e9 + 7
#define SCD(t) scanf("%d", &t)
#define SCLD(t) scanf("%ld", &t)
#define SCLLD(t) scanf("%lld", &t)
#define SCC(t) scanf("%c", &t)
#define SCS(t) scanf("%s", t)
#define SCF(t) scanf("%f", &t)
#define SCLF(t) scanf("%lf", &t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

int main() {
#ifndef ONLINE_JUDGE
  freopen("inputf.txt", "r", stdin);
  freopen("outputf.txt", "w", stdout);
#endif
  long long n, k;
  SCLLD(n);
  SCLLD(k);
  if (n == 0) {
    printf("0");
  } else {
    long long ans = n % k;
    ans = min(ans, abs(ans - k));
    printf("%lld", ans);
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  n = n % k;
  ans = min(n, k - n);
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  k = k % n;
  ll ans_2 = 0;
  ans_2 = abs(n - k);
  ans = min(ans_2, min(n, k));
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define endl '\\n'
using namespace std;

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

  long long int N, K;
  cin >> N >> K;
  N %= K;
  if (N <= K / 2)
    cout << N << endl;
  else
    cout << K - N << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
using namespace std;

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

  int N, K;
  cin >> N >> K;
  N %= K;
  if (N < K / 2)
    cout << N << endl;
  else
    cout << K - N << endl;

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

#include <iostream>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <time.h>
using namespace std;

int main() {
  long long N, K;
  long long a, b;
  cin >> N >> K;
  if (N > K) {
    a = N % K;
    b = K - a;
    if (a <= b)
      cout << a << endl;
    else
      cout << b << endl;
  } else if (N == K) {
    cout << 0 << endl;
  } else {
    a = N;
    b = K - N;
    if (a <= b)
      cout << a << endl;
    else
      cout << b << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <time.h>
using namespace std;

int main() {
  int N, K;
  int a, b;
  cin >> N >> K;
  if (N > K) {
    a = N % K;
    b = K - a;
    if (a <= b)
      cout << a << endl;
    else
      cout << b << endl;
  } else if (N == K) {
    cout << 0 << endl;
  } else {
    a = N;
    b = K - N;
    if (a <= b)
      cout << a << endl;
    else
      cout << b << endl;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm> //C++
#include <iostream>  //C++
#include <math.h>
#include <queue>   //C++
#include <sstream> //C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>    //C++
#include <vector>    //C++
using namespace std; // C++
#define rep(i, a, n) for (i = (a); i < (n); i++)

// scanf("%d",&x);
// printf("%d",x);
// for(i=0;i<N;i++){  }
// if( == ){  }else{  }
// while( ){  }

/*
int N, i;
int H[100];
scanf("%d", &N);
for (i = 0; i < N; i++) scanf("%s", &H[i]);
*/

int main() {
  long long int n, k;
  long long int i = 0;
  cin >> n >> k;
  long long int tmp2;

  if (k == 1) {
    cout << "0";
    return 0;
  }

  long long int tmp0 = n % k;

  tmp2 = abs(tmp0 - k);

  if (tmp0 >= tmp2)
    cout << tmp2;
  else
    cout << tmp0;
}


Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm> //C++
#include <iostream>  //C++
#include <math.h>
#include <queue>   //C++
#include <sstream> //C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>    //C++
#include <vector>    //C++
using namespace std; // C++
#define rep(i, a, n) for (i = (a); i < (n); i++)

// scanf("%d",&x);
// printf("%d",x);
// for(i=0;i<N;i++){  }
// if( == ){  }else{  }
// while( ){  }

/*
int N, i;
int H[100];
scanf("%d", &N);
for (i = 0; i < N; i++) scanf("%s", &H[i]);
*/

int main() {
  long long int n, k;
  long long int i = 0;
  cin >> n >> k;
  long long int tmp1, tmp2;

  if (k == 1) {
    cout << "0";
    return 0;
  }

  while (n - k * i > 0) {
    tmp1 = n - k * i;
    i++;
  }

  tmp2 = abs(tmp1 - k);

  if (tmp1 >= tmp2)
    cout << tmp2;
  else
    cout << tmp1;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int64_t N, K;
  cin >> N >> K;

  cout << min(N % K, K - (N % K));
}

Error: WA

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;

  cout << min(N % K, K - (N % K));
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  return x * f;
}

long long N, K;
long long x;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);

  cin >> N >> K;

  x = N % K;
  if (x >= K - x) {
    x = K - x;
  }

  cout << x;

  return 0;
}

Error: WA

Fixed submission:

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

inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  return x * f;
}

int N, K;
int x;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);

  cin >> N >> K;

  x = N % K;
  x = min(x, (K - x));
  x = min(N, x);

  cout << x;

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long

int main() {
  ios::sync_with_stdio(0);

  ll n, k;
  cin >> n >> k;

  if (k == 1 or n == k)
    cout << 0;
  else {
    if (n < k)
      cout << min(n, k - n);
    else if (n % k == 0)
      cout << 0;
    else
      cout << min(n % k, k - (n % k));
  }

  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long

int main() {
  ios::sync_with_stdio(0);

  ll n, k;
  cin >> n >> k;

  if (k == 1 or n == k)
    cout << 0;
  else {
    if (n < k)
      cout << min(n, k - n);
    else if (n % k == 0)
      cout << 0;
    else {
      set<ll> xs;
      while (true) {
        if (xs.count(n)) {
          cout << *xs.begin();
          return 0;
        }
        xs.insert(n);
        n = abs(n - k);
      }
    }
  }

  cout << endl;

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  n = n % k;
  long long ans = min(n, k - n);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  long long tmp = abs(n - k);
  if (n % k == 0)
    n = 0;
  while (n > tmp) {
    n = tmp;
    tmp = abs(n - k);
  }
  cout << n << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long n, k;
  cin >> n >> k;
  long p, m;
  p = n % k;
  m = -(p - k);
  if (p >= m) {
    n = m;
  } else {
    n = p;
  }
  cout << n << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

long keisan(long a, long b) {
  long t;
  t = a - b;
  if (t >= 0) {
    return t;
  }
  if (t < 0) {
    return -t;
  }
}

int main() {
  long n, k;
  cin >> n >> k;
  long t;
  while (1) {
    t = keisan(n, k);
    if (t > n) {
      break;
    } else {
      n = t;
    }
  }
  cout << n << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  long long ans;
  if (N % K == 0) {
    ans = 0;
  } else {
    ans = min(K - (N % K), N % K);
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, K;
  cin >> x >> K;
  int ans;
  if (x % K == 0) {
    ans = 0;
  } else {
    ans = min(K - (x % K), x % K);
  }
  cout << ans;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long long a, b;
  cin >> a >> b;
  long long m = min(abs(b - (a % b)), a % b);
  cout << min(a, m) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long long a, b;
  cin >> a >> b;
  long long m = abs(a - b);
  long long i = 1;
  for (;;) {
    if (m < abs(a - i * b))
      break;
    else {
      m = abs(a - i * b);
      i++;
      continue;
    }
  }
  cout << min(a, m) << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n, k;
  cin >> n >> k;
  ll t = n % k;
  ll ans = min(t, k - t);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n, k;
  cin >> n >> k;
  if (n == 0)
    cout << 0 << endl;
  else if (n % k == 0)
    cout << 0 << endl;
  else {
    while (1) {
      if (n > abs(n - k))
        n = abs(n - k);
      else
        break;
    }
    cout << n << endl;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long N, K;
int main() {
  cin >> N >> K;
  cout << min(N % K, K - (N % K)) << '\\n';
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int N, K;
int main() {
  cin >> N >> K;
  cout << N % K << '\\n';
}