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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define test                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define fast                                                                   \
  ios::sync_with_stdio(NULL);                                                  \
  cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC

int main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n, k;
  cin >> n >> k;
  if (n >= 10)
    cout << k;
  else {
    cout << k + (100 * (10 - n));
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define test                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define fast                                                                   \
  ios::sync_with_stdio(NULL);                                                  \
  cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC

int main() {
  fast;
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
  ll n, k;
  cin >> n >> k;
  if (n >= 10)
    cout << k;
  else {
    cout << k + (100 * (10 - n));
  }

  return 0;
}
Problem p02765 (C++)

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

int main() {
  vector<vector<vector<long long>>> U(
      10000, vector<vector<long long>>(100, vector<long long>(12, 1000)));
  for (size_t i = 0; true; i++) {
  }
  int N, M;
  cin >> N >> M;
  cout << M + (max(0, 10 - N) * 100);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;

int main() {
  vector<vector<vector<long long>>> U(
      10000, vector<vector<long long>>(100, vector<long long>(12, 1000)));

  int N, M;
  cin >> N >> M;
  cout << M + (max(0, 10 - N) * 100);
}
Problem p02765 (C++)

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

#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define M 100001
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#define lp(i, a, b) for (i = a; i < b; i++)
#define lpr(i, a, b) for (i = a; i >= b; i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;

int main() {

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

  fast;
  int i, j, n, r;
  cin >> n >> r;
  int ans = (n < 10) ? r + (100 * (10 - n)) : r;
  cout << ans << endl;
  return 0;
}


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

#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define M 100001
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#define lp(i, a, b) for (i = a; i < b; i++)
#define lpr(i, a, b) for (i = a; i >= b; i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;

int main() {

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

  fast;
  int i, j, n, r;
  cin >> n >> r;
  int ans = (n < 10) ? r + (100 * (10 - n)) : r;
  cout << ans << endl;
  return 0;
}
Problem p02765 (C++)

Buggy submission (status: Runtime Error):
// DEEPANSHU RAWAT
// BTECH/10530/18

#include <bits/stdc++.h>
#define ull unsigned long long
#define lld long long int
#define infi LLONG_MAX
#define ninfi LLONG_MIN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define e endl
#define mod 998244353
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  lld n, k;
  cin >> n >> k;
  if (n > 10) {
    cout << k;
  } else {
    cout << k + 100 * (10 - n);
  }
}

Fixed submission:
// DEEPANSHU RAWAT
// BTECH/10530/18

#include <bits/stdc++.h>
#define ull unsigned long long
#define lld long long int
#define infi LLONG_MAX
#define ninfi LLONG_MIN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define e endl
#define mod 998244353
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    */
  lld n, k;
  cin >> n >> k;
  if (n > 10) {
    cout << k;
  } else {
    cout << k + 100 * (10 - n);
  }
}
Problem p02765 (C++)

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

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

int main() {

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

  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, r;
  cin >> n >> r;
  if (n >= 10)
    cout << r;
  else {
    cout << r + 100 * (10 - n);
  }
  return 0;
}

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

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

int main() {

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

  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, r;
  cin >> n >> r;
  if (n >= 10)
    cout << r;
  else {
    cout << r + 100 * (10 - n);
  }
  return 0;
}
Problem p02765 (C++)

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

typedef long long int ll;
typedef vector<int> vi;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define pb push_back
#define fn for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define endl "\n"

void solve() {
  // write your code here :
  long long n, r;
  cin >> n >> r;
  if (n >= 10)
    cout << r;
  else
    cout << 100 * (10 - n) + r;
}

int main() {
  IOS
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // int t;
  // cin>>t;
  // while(t--)
  solve();
}

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

typedef long long int ll;
typedef vector<int> vi;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define pb push_back
#define fn for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define endl "\n"

void solve() {
  // write your code here :
  long long n, r;
  cin >> n >> r;
  if (n >= 10)
    cout << r;
  else
    cout << 100 * (10 - n) + r;
}

int main() {
  // IOS
  //    #ifndef ONLINE_JUDGE
  //    freopen("input.txt","r",stdin);
  //    freopen("output.txt","w",stdout);
  //    #endif
  // int t;
  // cin>>t;
  // while(t--)
  solve();
}
Problem p02765 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main(void) {
  int n, r, a;
  scanf("%d,&n");
  scanf("%d,&r");
  if (n >= 10)
    a = r;
  else
    a = r + 100 * (10 - n);
  printf("%d\n", a);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  int n, r, a;
  scanf("%d", &n);
  scanf("%d", &r);
  if (n >= 10)
    a = r;
  else
    a = r + 100 * (10 - n);
  printf("%d\n", a);
  return 0;
}
Problem p02765 (C++)

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int k;
int main() {
#ifdef FILE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);

  cin >> n >> k;
  cout << k + 100 * (10 - min(10, n)) << "\n";
}


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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int k;
int main() {
#ifdef FILEs
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);

  cin >> n >> k;
  cout << k + 100 * (10 - min(10, n)) << "\n";
}
Problem p02766 (C++)

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

int main() {

  int n, k;
  cin >> n >> k;
  int ans = 0;

  while (n / k >= 0) {
    ans++;
    n /= k;
  }

  cout << ans << endl;
  return 0;
}


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

int main() {

  int n, k;
  cin >> n >> k;
  int ans = 0;

  while (n > 0) {
    ans++;
    n /= k;
  }

  cout << ans << endl;
  return 0;
}
Problem p02766 (C++)

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

int main() {
  long long int N, K, ans = 0;
  cin >> N >> K;

  for (int i = 0;; i++) {
    if (pow(K, i) < N && pow(K, i + 1) > N) {
      ans = i + 1;
      break;
    }
  }

  cout << ans;

  return 0;
}


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

int main() {
  long long int N, K, ans = 0;
  cin >> N >> K;

  while (N) {
    N /= K;

    ans++;
  }

  cout << ans;

  return 0;
}
Problem p02766 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N > 0) {
    N / K;
    ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N > 0) {
    N /= K;
    ans++;
  }
  cout << ans << endl;
}
Problem p02766 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  while (n > 0) {
    cnt++;
    n / k;
  }

  cout << cnt << endl;

  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  while (n > 0) {
    cnt++;
    n = n / k;
  }

  cout << cnt << endl;

  return 0;
}
Problem p02766 (C++)

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

using namespace std;

int main() {
  int n;
  int k;
  cin >> n >> k;
  int result = 0;
  for (int i = 0; i < 1000000000; i++) {
    n = n / k;
    result++;
  }
  cout << result << endl;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n;
  int k;
  cin >> n >> k;
  int result = 0;
  while (n > 0) {
    n = n / k;
    result++;
  }
  cout << result << endl;
}
Problem p02766 (C++)

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

int main() {
  ll n, k;
  cin >> n >> k;
  int i = 1;
  while (true) {
    if (n < pow(k, i)) {
      cout << i << endl;
      return 0;
    }
  }
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  int i = 1;
  while (true) {
    if (n < pow(k, i)) {
      cout << i << endl;
      return 0;
    } else
      i++;
  }
}
Problem p02766 (C++)

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

int n, k;

int main() {
  cin >> n >> k;
  int c = 0;
  while (n != 1) {
    n /= k;
    c++;
  }
  cout << ++c;
  return 0;
}


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

int n, k;

int main() {
  cin >> n >> k;
  int c = 0;
  while (n >= k) {
    n /= k;
    c++;
  }
  cout << ++c;
  return 0;
}
Problem p02766 (C++)

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

int main() {
  int n, k, a;
  cin >> n >> k;
  while (n > k) {
    if (n / k > k) {
      n /= k;
      a++;
    }
  }
  a++;
  cout << a << endl;
}

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

int main() {
  int n, k, a;
  cin >> n >> k;
  a = 0;
  while (n >= k) {
    n /= k;
    a++;
  }
  a++;
  cout << a << endl;
}
Problem p02766 (C++)

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int tmp = N;
  int count = 0;
  do {
    tmp = tmp / K;
    count++;
  } while (tmp > 0);

  cout << count << endl;

  return 1;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int tmp = N;
  int count = 0;
  do {
    tmp = tmp / K;
    count++;
  } while (tmp > 0);

  cout << count << endl;

  return 0;
}
Problem p02766 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using namespace __gnu_pbds;

#define f(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, k;
  cin >> n >> k;
  cout << (ll)(log(n) / log(k)) + 1 << "\n";
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using namespace __gnu_pbds;

#define f(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>

int main() { /*
  #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
  #endif*/
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, k;
  cin >> n >> k;
  cout << (ll)(log(n) / log(k)) + 1 << "\n";
}
Problem p02766 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N > 0) {
    N / K;
    ans++;
  }

  cout << ans << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N > 0) {
    N /= K;
    ans++;
  }

  cout << ans << endl;
}
Problem p02766 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
int main(void) {
  long n;
  int k;
  int counter = 1;
  while (n >= k) {
    counter += 1;
    n = (n - n % k) / k;
  }
  std::cout << counter;
}

Fixed submission:
#include <iostream>
int main(void) {
  long n;
  int k;
  int counter = 1;
  std::cin >> n >> k;
  while (n >= k) {
    counter += 1;
    n = (n - n % k) / k;
  }
  std::cout << counter;
}
Problem p02766 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string st;
int main() {
  int n, p, d;
  char c;
  do {
    d = n % p;
    n = n / p;
    if (d >= 0 && d <= 9) {
      c = d + '0';
    } else {
      c = d + 55;
    }
    st = c + st;
  } while (n != 0);
  cout << st.size();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string st;
int main() {
  int n, p, d;
  cin >> n >> p;
  char c;
  do {
    d = n % p;
    n = n / p;
    if (d >= 0 && d <= 9) {
      c = d + '0';
    } else {
      c = d + 55;
    }
    st = c + st;
  } while (n != 0);
  cout << st.size();
  return 0;
}
Problem p02766 (Python)

Buggy submission (status: Runtime Error):
MAX_N = 1_000_000_000
n, k = map(int, input().split())

for i in range(MAX_N):
    if n < pow(k, i):
        print(i)
        break


Fixed submission:
MAX_N = pow(10, 9)
n, k = map(int, input().split())

for i in range(MAX_N):
    if n < pow(k, i):
        print(i)
        break
Problem p02766 (Python)

Buggy submission (status: Time Limit Exceeded):
n, k = map(int, input().split())

for i in range(2**n):
    # if k ** (i - 1) - 1 < n <= k ** i - 1:
    if n <= k**i - 1:
        print(i)
        exit()


Fixed submission:
n, k = map(int, input().split())

for i in range(2**31):
    if n <= k**i - 1:
        print(i)
        exit()
Problem p02766 (C++)

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

#define ll long long
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N > 0) {
    N / K;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N > 0) {
    N /= K;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02766 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  double N, R, ans;
  cin >> N >> R;
  for (long long i = 1; i <= 100000000; i++) {
    if (N >= pow(R, i) && N < pow(R, i + 1)) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  double N, R, ans;
  cin >> N >> R;
  for (int i = 0; i <= 30; i++) {
    if (N >= pow(R, i) && N < pow(R, i + 1)) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02766 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N, K, count = 0;
  cin >> N >> K;
  while (N >= K) {
    count++;
  }

  cout << count + 1 << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N, K, count = 0;
  cin >> N >> K;
  while (N >= K) {
    count++;
    N = N / K;
  }

  cout << count + 1 << endl;
}
Problem p02766 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define allr(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define sp " "
#define double long double
#define pb push_back
#define ff first
#define int long long
#define ss second
#define vi vector<int>
#define mem(ara, a) memset(ara, a, sizeof(ara))
#define bruh freopen("bruh.txt", "r", stdin)
#define fo freopen("output.txt", "w", stdout)
#define pii pair<int, int>

long long inf = 2e18;
long long minf = -inf;

using namespace std;

signed main() {

#ifndef ONLINE_JUDGE
  freopen("bruh.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int ans = 0;
  while (n > 0) {
    n /= k;
    ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include "bits/stdc++.h"
#define allr(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define sp " "
#define double long double
#define pb push_back
#define ff first
#define int long long
#define ss second
#define vi vector<int>
#define mem(ara, a) memset(ara, a, sizeof(ara))
#define bruh freopen("bruh.txt", "r", stdin)
#define fo freopen("output.txt", "w", stdout)
#define pii pair<int, int>

long long inf = 2e18;
long long minf = -inf;

using namespace std;

signed main() {

#ifndef ONLINE_JUDGE
//	freopen("bruh.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int ans = 0;
  while (n > 0) {
    n /= k;
    ans++;
  }
  cout << ans << endl;
}
Problem p02766 (C++)

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

using namespace std;

int main() {
  int n, k, cnt = 0;
  cin >> n >> k;

  while (n % k >= 0) {
    cnt++;
    n /= k;
  }

  cout << cnt << endl;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n, k, cnt = 0;
  cin >> n >> k;

  while (n > 0) {
    cnt++;
    n /= k;
  }

  cout << cnt << endl;

  return 0;
}
Problem p02766 (C++)

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

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

  int kai = N, count = 0;
  while (kai != 0) {
    kai = N / K;
    count++;
  }

  cout << count << endl;
}


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

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

  int count = 0;
  while (N != 0) {
    N = N / K;
    count++;
  }

  cout << count << endl;
}
Problem p02766 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;

void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}

int get_digits(int n, int k) {
  int ret = 0;
  do {
    ret++;
    n /= k;
  } while (n > 0);
  return ret;
}

int main() {
  file();
  int n, k;
  scanf("%d %d", &n, &k);
  printf("%d\n", get_digits(n, k));

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;

void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}

int get_digits(int n, int k) {
  int ret = 0;
  do {
    ret++;
    n /= k;
  } while (n > 0);
  return ret;
}

int main() {
  // file();
  int n, k;
  scanf("%d %d", &n, &k);
  printf("%d\n", get_digits(n, k));

  return 0;
}
Problem p02766 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

  int n, k;
  cin >> n;
  int res = 1;
  while (n > 0) {
    n /= k;
    res++;
  }
  cout << res << "\n";
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

  int n, k;
  cin >> n >> k;
  int res = 0;
  while (n > 0) {
    n /= k;
    res++;
  }
  cout << res << "\n";
}
Problem p02766 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
  int N;
  int K;
  cin >> N >> K;
  int L = 1;
  for (int i = 0; i < N; i++) {
    if (N / K != 0) {
      L++;
      K *= K;
    } else
      break;
  }
  cout << L << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
  int N;
  int K;
  cin >> N >> K;
  int L = 1;
  while (N / K != 0) {
    L++;
    N /= K;
  }
  cout << L << endl;
}
Problem p02766 (C++)

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

int main() {
  int n, k;
  int counts = 0;
  cin >> n >> k;
  while (n != 1) {
    counts++;
    n /= k;
  }
  cout << counts + 1 << endl;
}


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

int main() {
  int n, k;
  int counts = 0;
  cin >> n >> k;
  while (n >= k) {
    counts++;
    n /= k;
  }
  cout << counts + 1 << endl;
}
Problem p02766 (C++)

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

int main() {
  long n, k, c;
  cin >> n, k;
  c = 0;
  while (n) {
    c++;
    n = n / k;
  }
  cout << c;

  return 0;
}

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

int main() {
  long n, k, c;
  cin >> n >> k;
  c = 0;
  while (n) {
    c++;
    n = n / k;
  }
  cout << c;

  return 0;
}
Problem p02766 (Python)

Buggy submission (status: Time Limit Exceeded):
n, k = map(int, input().split())
counter = 1
while n != 1:
    n = int(n / k)
    counter += 1
print(counter)


Fixed submission:
n, k = map(int, input().split())
counter = 1
while n >= k:
    n = int(n / k)
    counter += 1
print(counter)
Problem p02766 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  int tmp = N;
  while (1) {
    if (tmp == 1)
      break;
    tmp /= K;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  int tmp = N;
  while (1) {
    if (tmp < K)
      break;
    tmp /= K;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02767 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) cin >> X[i];

  vector<int> S(X[N - 1] - X[0] + 1);

  for (int P = X[0]; P <= X[N - 1]; ++P) {
    rep(i, N) S[P - X[0]] += (X[i] - P) * (X[i] - P);
  }

  sort(all(S));
  dunk(S[0]);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) cin >> X[i];
  sort(all(X));

  vector<int> S(X[N - 1] - X[0] + 1);

  for (int P = X[0]; P <= X[N - 1]; ++P) {
    rep(i, N) S[P - X[0]] += (X[i] - P) * (X[i] - P);
  }

  sort(all(S));
  dunk(S[0]);
}
Problem p02767 (C++)

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

int main() {

  int n;
  cin >> n;

  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec.at(i);

  vector<int> cost(100);
  int camp;

  for (int i = 1; i < 101; i++) {
    for (int j = 0; j < n; j++) {
      camp = i;
      cost.at(i - 1) += (i - vec.at(j)) * (i - vec.at(j));
    }
  }
  int answer = cost.at(0);

  for (int i = 0; i < 100; i++) {
    if (cost.at(i) < cost.at(i + 1))
      answer = cost.at(i + 1);
  }

  cout << answer << endl;
}

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

int main() {

  int n;
  cin >> n;

  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec.at(i);

  vector<int> cost(100);
  int camp;

  for (int i = 1; i < 101; i++) {
    for (int j = 0; j < n; j++) {
      camp = i;
      cost.at(i - 1) += (i - vec.at(j)) * (i - vec.at(j));
    }
  }
  int answer = cost.at(0);

  for (int i = 0; i < 99; i++) {
    if (cost.at(i) > cost.at(i + 1))
      answer = cost.at(i + 1);
  }

  cout << answer << endl;
}
Problem p02767 (C++)

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

#define int long long
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
  fastio;

  int n;
  cin >> n;
  vector<int> a(n);
  int mn = INT_MAX, mx = INT_MIN;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
  }
  int ans = INT_MAX;
  for (int i = mn; i <= mx; ++i) {
    int curr = 0;
    for (int j : a)
      curr += (j - i) * (j - i);
    ans = min(ans, curr);
  }
  cout << ans;

  return 0;
}


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

#define int long long
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
  fastio;

  int n;
  cin >> n;
  vector<int> a(n);
  int mn = INT_MAX, mx = INT_MIN;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
  }
  int ans = INT_MAX;
  for (int i = mn; i <= mx; ++i) {
    int curr = 0;
    for (int j = 0; j < n; ++j)
      curr += (a[j] - i) * (a[j] - i);
    ans = min(ans, curr);
  }
  cout << ans;

  return 0;
}
Problem p02767 (C++)

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

using namespace std;

int main(void) {

  int n;
  cin >> n;

  int max_x = 0;

  vector<int> X;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (max_x < x) {
      max_x = x;
    }
    X.push_back(x);
  }

  vector<long> HP;

  for (int i = 1; i < max_x; i++) {
    long hp = 0;
    for (int j = 0; j < n; j++) {
      hp += (X[j] - i) * (X[j] - i);
      // cout << "hp " << hp << endl;
    }
    HP.push_back(hp);
  }
  cout << *std::min_element(HP.begin(), HP.end()) << endl;
}


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

using namespace std;

int main(void) {

  int n;
  cin >> n;

  int max_x = 0;

  vector<int> X;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (max_x < x) {
      max_x = x;
    }
    X.push_back(x);
  }

  vector<long> HP;

  for (int i = 1; i <= max_x; i++) {
    long hp = 0;
    for (int j = 0; j < n; j++) {
      hp += (X[j] - i) * (X[j] - i);
      // cout << "hp " << hp << endl;
    }
    HP.push_back(hp);
  }
  cout << *std::min_element(HP.begin(), HP.end()) << endl;
}
Problem p02767 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  int ans = 1e8;
  for (int i = x.at(0); i <= x.at(n - 1); i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += pow(x.at(i) - i, 2.0);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  int ans = 1e8;
  for (int i = x.at(0); i <= x.at(n - 1); i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += pow(x.at(j) - i, 2.0);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}
Problem p02767 (C++)

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

#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define qmod 998244353
#define M 1000001
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)
#define F first
#define S second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;

int main() {

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

  fast;
  int n;
  cin >> n;
  int a[n], mi = 101, mx = 0;
  rep(i, 0, n) {
    cin >> a[i];
    mi = min(mi, a[i]);
    mx = max(mx, a[i]);
  }
  int ans = INT_MAX;
  rep(i, mi, mx + 1) {
    int p = 0;
    rep(j, 0, n) p += pow((a[j] - i), 2);
    ans = min(p, ans);
  }
  cout << ans;
  return 0;
}

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

#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define qmod 998244353
#define M 1000001
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)
#define F first
#define S second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;

int main() {

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

  fast;
  int n;
  cin >> n;
  int a[n], mi = 101, mx = 0;
  rep(i, 0, n) {
    cin >> a[i];
    mi = min(mi, a[i]);
    mx = max(mx, a[i]);
  }
  int ans = INT_MAX;
  rep(i, mi, mx + 1) {
    int p = 0;
    rep(j, 0, n) p += pow((a[j] - i), 2);
    ans = min(p, ans);
  }
  cout << ans;
  return 0;
}
Problem p02767 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int un;
  if (n % 2 == 0)
    un = (a.at((n - 1) / 2 + 1) - a.at((n - 1) / 2)) / 2 + a.at((n - 1) / 2);
  else
    un = a.at(n - 1 / 2);
  long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += pow((un - a.at(i)), 2);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int ans = 1000000;
  for (int i = 1; i < 101; i++) {
    int b = 0;
    for (int h = 0; h < n; h++) {
      b += pow(i - a.at(h), 2);
    }
    ans = min(ans, b);
  }
  cout << ans << endl;
}
Problem p02767 (C++)

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

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

ll sqr(ll x) { return x * x; }

int main() {

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

  ios::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  int x[n];
  double num, sum = 0;
  int num1, num2;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    sum += x[i];
  }
  sum /= n;
  num1 = (int)(floor(sum));
  num2 = (int)(ceil(sum));

  ll st1 = 0, st2 = 0;
  for (int i = 0; i < n; i++) {
    st1 += sqr(x[i] - num1);
    st2 += sqr(x[i] - num2);
  }

  cout << min(st1, st2);

  return 0;
}

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

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

ll sqr(ll x) { return x * x; }

int main() {

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

  ios::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  int x[n];
  double num, sum = 0;
  int num1, num2;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    sum += x[i];
  }
  sum /= n;
  num1 = (int)(floor(sum));
  num2 = (int)(ceil(sum));

  ll st1 = 0, st2 = 0;
  for (int i = 0; i < n; i++) {
    st1 += sqr(x[i] - num1);
    st2 += sqr(x[i] - num2);
  }

  cout << min(st1, st2);

  return 0;
}
Problem p02767 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  vector<int> sum(x.at(n));
  for (int i = 0; i < x.at(n); i++) {
    for (int j = 0; j < n; j++) {
      sum.at(i) += pow((i + 1 - x.at(j)), 2);
    }
  }
  sort(sum.begin(), sum.end());
  cout << sum.at(0) << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  int max = x.at(n - 1);
  vector<int> sum(max);
  for (int i = 0; i < max; i++) {
    for (int j = 0; j < n; j++) {
      sum.at(i) += pow((i + 1 - x.at(j)), 2);
    }
  }
  sort(sum.begin(), sum.end());
  cout << sum.at(0) << endl;
}
Problem p02767 (C++)

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

int main() {
  int N;
  vector<int> X(N);
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> X[i];
  int ans = 1e+8;
  for (int i = 1; i <= 100; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++)
      sum += (X[j] - i) * (X[j] - i);
    ans = min(ans, sum);
  }
  printf("%d", ans);
  return 0;
}


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

int main() {
  int N;
  int X[120];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> X[i];
  int ans = 1e+8;
  for (int i = 1; i <= 100; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++)
      sum += (X[j] - i) * (X[j] - i);
    ans = min(ans, sum);
  }
  printf("%d", ans);
  return 0;
}
Problem p02767 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <iostream>
using namespace std;
int main() {
  int n;
  int array[100005];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }
  sort(array, array + n);

  int p = array[0];
  int minimum = INT_MAX;
  while (p <= array[n - 1]) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += (array[i] - p) * (array[i] - p);
    }
    minimum = min(minimum, sum);
  }
  cout << minimum << endl;
  return (0);
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
using namespace std;
int main() {
  int n;
  int array[100005];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }
  sort(array, array + n);

  int p = array[0];
  int minimum = INT_MAX;
  while (p <= array[n - 1]) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += (array[i] - p) * (array[i] - p);
    }
    minimum = min(minimum, sum);
    p++;
  }
  cout << minimum << endl;
  return (0);
}
Problem p02767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
// #define int long long

const int N = 1005;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
   * int overflow, array bounds
   * special cases (n=1?)
   * do smth instead of nothing and stay organized
   */

  int n;
  cin >> n;
  int arr[n];
  int sum = 0;
  int count = 0, count1 = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int x = (sum + n) / n;
  int x1 = sum / n;
  for (int i = 0; i < n; i++) {
    int z = abs(x - arr[i]);
    int z1 = abs(x1 - arr[i]);
    z = z * z;
    z1 = z1 * z1;
    count += z;
    count1 += z1;
  }
  cout << min(count, count1);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
// #define int long long

const int N = 1005;
const int MOD = 1e9 + 7;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
   * int overflow, array bounds
   * special cases (n=1?)
   * do smth instead of nothing and stay organized
   */

  int n;
  cin >> n;
  int arr[n];
  int sum = 0;
  int count = 0, count1 = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int x = (sum + n) / n;
  int x1 = sum / n;
  for (int i = 0; i < n; i++) {
    int z = abs(x - arr[i]);
    int z1 = abs(x1 - arr[i]);
    z = z * z;
    z1 = z1 * z1;
    count += z;
    count1 += z1;
  }
  cout << min(count, count1);
}
Problem p02767 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  int sum = 0;
  int d_sum = 0;
  rep(i, n) {
    cin >> x.at(i);
    sum += x.at(i);
    d_sum += pow(x.at(i), 2);
  }
  int ans = 1000000;
  for (int i = 0; i < 100; i++) {
    int p = x.at(i);
    int pa = d_sum - 2 * sum * p + n * p * p;
    ans = min(pa, ans);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  int sum = 0;
  int d_sum = 0;
  rep(i, n) {
    cin >> x.at(i);
    sum += x.at(i);
    d_sum += pow(x.at(i), 2);
  }
  int ans = 1000000;
  for (int i = 1; i <= 100; i++) {
    int p = i;
    int pa = d_sum - 2 * sum * p + n * p * p;
    ans = min(pa, ans);
  }
  cout << ans << endl;
}
Problem p02767 (C++)

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

int main() {
  int n, nu = 1e9;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 1; i < 100; i++) {
    int hu = 0;
    for (int j = 0; j < n; i++) {
      hu += (x[j] - i) * (x[j] - i);
    }
    nu = min(nu, hu);
  }
  cout << nu << endl;
}


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

int main() {
  int n, nu = 1e9;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 1; i < 100; i++) {
    int hu = 0;
    for (int j = 0; j < n; j++) {
      hu += (x[j] - i) * (x[j] - i);
    }
    nu = min(nu, hu);
  }
  cout << nu << endl;
}
Problem p02767 (C++)

Buggy submission (status: 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);
  freopen("bruh.txt", "r", stdin);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  int mid = (arr[0] + arr[n - 1]) / 2;
  int mx = 1e9;
  int ans;
  for (int k = 0; k <= 100; k++) {
    ans = 0;
    mid = k;
    for (int i = 0; i < n; i++) {
      ans += (arr[i] - mid) * (arr[i] - mid);
    }
    mx = min(ans, mx);
  }
  cout << mx << nl;
}


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);
  // freopen("bruh.txt","r",stdin);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  int mid = (arr[0] + arr[n - 1]) / 2;
  int mx = 1e9;
  int ans;
  for (int k = 0; k <= 100; k++) {
    ans = 0;
    mid = k;
    for (int i = 0; i < n; i++) {
      ans += (arr[i] - mid) * (arr[i] - mid);
    }
    mx = min(ans, mx);
  }
  cout << mx << nl;
}
Problem p02767 (C++)

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

using namespace std;

int main() {
  int n, sum;
  sum = 0;

  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  vector<int> s;
  for (int p = x[0]; p < x[n - 1]; p++) {
    for (int i : x) {
      sum += (i - p) * (i - p);
    }
    s.push_back(sum);
    sum = 0;
  }
  sort(s.begin(), s.end());

  cout << s[0] << endl;
}

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

using namespace std;

int main() {
  int n, sum;
  sum = 0;

  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  vector<int> s;
  for (int p = x[0]; p <= x[n - 1]; p++) {
    for (int i : x) {
      sum += (i - p) * (i - p);
    }
    s.push_back(sum);
    sum = 0;
  }
  sort(s.begin(), s.end());

  cout << s[0] << endl;
}