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

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

A.sort()

factorial = [1]
for i in range(1, N + 1):
    factorial.append(factorial[-1] * i)
inv_factorial = [-1] * (N + 1)
inv_factorial[-1] = pow(factorial[-1], MOD - 2, MOD)
for i in reversed(range(N)):
    inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD


ans = 0
for i in range(N - K + 1):
    c = factorial[N - 1 - i] * inv_factorial[K - 1] * inv_factorial[N - K - i]
    ans += c * (A[-1 - i] - A[i])
    ans %= MOD

print(ans)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

A.sort()

factorial = [1]
for i in range(1, N + 1):
    factorial.append(factorial[-1] * i % MOD)
inv_factorial = [-1] * (N + 1)
inv_factorial[-1] = pow(factorial[-1], MOD - 2, MOD)
for i in reversed(range(N)):
    inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD


ans = 0
for i in range(N - K + 1):
    c = factorial[N - 1 - i] * inv_factorial[K - 1] * inv_factorial[N - K - i]
    ans += c * (A[-1 - i] - A[i])
    ans %= MOD

print(ans)
Problem p02804 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;
const long nPrime = 1000000007;
long Factorial(const long &n) {
  // nPrime = 1000000007;
  long nReturn = 1;
  for (long i = 2; i <= n; i++) {
    nReturn *= i;
    nReturn %= nPrime;
  }
  return nReturn;
}

long Inverse(const long &n) {
  // nPrime = 1000000007;
  if (n % nPrime == 0) {
    return 0;
  }
  long a = n, b = nPrime, u = 1, v = 0;
  while (b > 0) {
    long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= nPrime;
  if (u < 0) {
    u += nPrime;
  }
  return u;
}

long Combination(const long &n, const long &k) {
  // nPrime = 1000000007;
  long nCk = Factorial(n - k) * Factorial(k);
  nCk %= nPrime;
  nCk = Factorial(n) * Inverse(nCk);
  nCk %= nPrime;
  return nCk;
}

int main() {
  long n, k;
  scanf("%ld %ld", &n, &k);
  vector<long> viNum(n);
  for (long i = 0; i < n; i++) {
    scanf("%ld", &viNum[i]);
  }

  sort(viNum.begin(), viNum.end());

  long nAns = 0;
  long nComb = Combination(n, k - 1);
  for (long i = 1; i <= n - k + 1; i++) {
    nComb *= Inverse(n - i + 1);
    nComb %= nPrime;
    nComb *= (n - i - k + 2);
    nComb %= nPrime;
    nAns += (viNum[n - i] - viNum[i - 1]) * Combination(n - i, k - 1);
    nAns %= nPrime;
  }
  if (nAns < 0) {
    nAns += nPrime;
  }

  printf("%ld", nAns);
  return 0;
}


Fixed submission:
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;
const long nPrime = 1000000007;
long Factorial(const long &n) {
  // nPrime = 1000000007;
  long nReturn = 1;
  for (long i = 2; i <= n; i++) {
    nReturn *= i;
    nReturn %= nPrime;
  }
  return nReturn;
}

long Inverse(const long &n) {
  // nPrime = 1000000007;
  if (n % nPrime == 0) {
    return 0;
  }
  long a = n, b = nPrime, u = 1, v = 0;
  while (b > 0) {
    long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= nPrime;
  if (u < 0) {
    u += nPrime;
  }
  return u;
}

long Combination(const long &n, const long &k) {
  // nPrime = 1000000007;
  long nCk = Factorial(n - k) * Factorial(k);
  nCk %= nPrime;
  nCk = Factorial(n) * Inverse(nCk);
  nCk %= nPrime;
  return nCk;
}

int main() {
  long n, k;
  scanf("%ld %ld", &n, &k);
  vector<long> viNum(n);
  for (long i = 0; i < n; i++) {
    scanf("%ld", &viNum[i]);
  }

  sort(viNum.begin(), viNum.end());

  long nAns = 0;
  long nComb = Combination(n, k - 1);
  for (long i = 1; i <= n - k + 1; i++) {
    nComb *= Inverse(n - i + 1);
    nComb %= nPrime;
    nComb *= (n - i - k + 2);
    nComb %= nPrime;
    nAns += (viNum[n - i] - viNum[i - 1]) * nComb;
    nAns %= nPrime;
  }
  if (nAns < 0) {
    nAns += nPrime;
  }

  printf("%ld", nAns);
  return 0;
}
Problem p02805 (C++)

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

using namespace std;

typedef long long ll;
typedef long double ld;

const ll M = 2000000;
const ld X = 0.6;
const ld Y = 0.9999;
ll n;
ll x[55], y[55];
ld cx, cy;
ld now = X;

void f(ld p) {
  ld mx = 0;
  ll mi = 0;
  for (ll i = 0; i < n; i++) {
    ld r = (cx - x[i]) * (cx - x[i]) + (cy - y[i]) * (cy - y[i]);
    if (mx < r)
      mx = r, mi = i;
  }
  cx += (x[mi] - cx) * p;
  cy += (y[mi] - cy) * p;
}

int main() {
  scanf("%lld", &n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
    cx += x[i];
    cy += y[i];
  }
  cx /= n;
  cy /= n;
  for (ll i = 0; i < M; i++) {
    f(now);
    now *= Y;
  }
  ld ans = 0;
  for (ll i = 0; i < n; i++) {
    ld r = (cx - x[i]) * (cx - x[i]) + (cy - y[i]) * (cy - y[i]);
    ans = max(ans, r);
  }
  printf("%.12Lf", sqrt(ans));
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const ll M = 900000;
const ld X = 0.6;
const ld Y = 0.9999;
ll n;
ll x[55], y[55];
ld cx, cy;
ld now = X;

void f(ld p) {
  ld mx = 0;
  ll mi = 0;
  for (ll i = 0; i < n; i++) {
    ld r = (cx - x[i]) * (cx - x[i]) + (cy - y[i]) * (cy - y[i]);
    if (mx < r)
      mx = r, mi = i;
  }
  cx += (x[mi] - cx) * p;
  cy += (y[mi] - cy) * p;
}

int main() {
  scanf("%lld", &n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
    cx += x[i];
    cy += y[i];
  }
  cx /= n;
  cy /= n;
  for (ll i = 0; i < M; i++) {
    f(now);
    now *= Y;
  }
  ld ans = 0;
  for (ll i = 0; i < n; i++) {
    ld r = (cx - x[i]) * (cx - x[i]) + (cy - y[i]) * (cy - y[i]);
    ans = max(ans, r);
  }
  printf("%.12Lf", sqrt(ans));
  return 0;
}
Problem p02805 (C++)

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

vector<int> xs, ys;

double dist(double x, double y) {
  double ans = 0;
  for (int i = 0; i < xs.size(); i++) {
    double dx = x - xs.at(i), dy = y - ys.at(i);
    ans = max(ans, sqrt(dx * dx + dy * dy));
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int xi, yi;
    cin >> xi >> yi;
    xs.push_back(xi);
    ys.push_back(yi);
  }
  double x0 = 0, x1 = 1000, y0 = 0, y1 = 1000;
  const int s = 53;
  while (x1 - x0 > 1e-12 && y1 - y0 > 1e-12) {
    cerr << x0 << " " << x1 << endl;
    cerr << y0 << " " << y1 << endl;
    double dx = x1 - x0, dy = y1 - y0;
    vector<vector<double>> d(s + 1, vector<double>(s + 1));
    for (int i = 0; i <= s; i++) {
      for (int j = 0; j <= s; j++) {
        d.at(i).at(j) = dist(x0 + i * dx / s, y0 + j * dy / s);
      }
    }
    int imin = 0, jmin = 0;
    for (int i = 0; i <= s; i++) {
      for (int j = 0; j <= s; j++) {
        if (d.at(i).at(j) <= d.at(imin).at(jmin)) {
          imin = i;
          jmin = j;
        }
      }
    }
    if (imin < (s + 1) / 2) {
      x1 = (x1 * (s - 1) + x0) / s;
    } else {
      x0 = (x0 * (s - 1) + x1) / s;
    }
    if (jmin < (s + 1) / 2) {
      y1 = (y1 * (s - 1) + y0) / s;
    } else {
      y0 = (y0 * (s - 1) + y1) / s;
    }
  }
  cout << setprecision(17) << dist((x0 + x1) / 2, (y0 + y1) / 2) << endl;
}


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

vector<int> xs, ys;

double dist(double x, double y) {
  double ans = 0;
  for (int i = 0; i < xs.size(); i++) {
    double dx = x - xs.at(i), dy = y - ys.at(i);
    ans = max(ans, sqrt(dx * dx + dy * dy));
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int xi, yi;
    cin >> xi >> yi;
    xs.push_back(xi);
    ys.push_back(yi);
  }
  double x0 = 0, x1 = 1000, y0 = 0, y1 = 1000;
  const int s = 53;
  while (x1 - x0 > 1e-8 && y1 - y0 > 1e-8) {
    cerr << x0 << " " << x1 << endl;
    cerr << y0 << " " << y1 << endl;
    double dx = x1 - x0, dy = y1 - y0;
    vector<vector<double>> d(s + 1, vector<double>(s + 1));
    for (int i = 0; i <= s; i++) {
      for (int j = 0; j <= s; j++) {
        d.at(i).at(j) = dist(x0 + i * dx / s, y0 + j * dy / s);
      }
    }
    int imin = 0, jmin = 0;
    for (int i = 0; i <= s; i++) {
      for (int j = 0; j <= s; j++) {
        if (d.at(i).at(j) <= d.at(imin).at(jmin)) {
          imin = i;
          jmin = j;
        }
      }
    }
    if (imin < (s + 1) / 2) {
      x1 = (x1 * (s - 1) + x0) / s;
    } else {
      x0 = (x0 * (s - 1) + x1) / s;
    }
    if (jmin < (s + 1) / 2) {
      y1 = (y1 * (s - 1) + y0) / s;
    } else {
      y0 = (y0 * (s - 1) + y1) / s;
    }
  }
  cout << setprecision(17) << dist((x0 + x1) / 2, (y0 + y1) / 2) << endl;
}
Problem p02805 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using point = pair<double, double>;

double l2_dist(point p1, point p2) {
  double dx = p1.first - p2.first, dy = p1.second - p2.second;
  return sqrt(dx * dx + dy * dy);
}

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

  vector<point> xy(N);
  for (int i = 0; i < N; i++) {
    double x, y;
    cin >> x >> y;
    xy[i] = make_pair(x, y);
  }

  auto max_r = [&](double x, double y) {
    point p = make_pair(x, y);
    double ret = 0;
    for (int i = 0; i < N; i++) {
      ret = max(ret, l2_dist(p, xy[i]));
    }
    return ret;
  };

  auto fx = [&](double x) {
    double ly = 0, uy = 1000;
    double fl = max_r(x, ly), fu = max_r(x, uy);
    while (abs(fl - fu) > 1e-7) {
      double m1 = (2 * ly + uy) / 3, m2 = (ly + 2 * uy) / 3;
      double f1 = max_r(x, m1), f2 = max_r(x, m2);
      if (f1 < f2) {
        uy = m2;
        fu = max_r(x, uy);
      } else {
        ly = m1;
        fl = max_r(x, ly);
      }
    }
    return fl;
  };

  double lx = 0, ux = 1000;
  double fl = fx(lx), fu = fx(ux);
  while (abs(fl - fu) > 1e-7) {
    // cout << lx << ' ' << ux << endl;
    // cout << fl << ' ' << fu << endl;
    double m1 = (2 * lx + ux) / 3, m2 = (lx + 2 * ux) / 3;
    double f1 = fx(m1), f2 = fx(m2);
    if (f1 < f2) {
      ux = m2;
      fu = fx(m2);
    } else {
      lx = m1;
      fl = fx(m1);
    }
  }

  cout << setprecision(20) << fl << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using point = pair<double, double>;

double l2_dist(point p1, point p2) {
  double dx = p1.first - p2.first, dy = p1.second - p2.second;
  return sqrt(dx * dx + dy * dy);
}

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

  vector<point> xy(N);
  for (int i = 0; i < N; i++) {
    double x, y;
    cin >> x >> y;
    xy[i] = make_pair(x, y);
  }

  auto max_r = [&](double x, double y) {
    point p = make_pair(x, y);
    double ret = 0;
    for (int i = 0; i < N; i++) {
      ret = max(ret, l2_dist(p, xy[i]));
    }
    return ret;
  };

  auto fx = [&](double x) {
    double ly = 0, uy = 1000;
    double fl = max_r(x, ly), fu = max_r(x, uy);
    while (abs(fl - fu) > 1e-12) {
      double m1 = (2 * ly + uy) / 3, m2 = (ly + 2 * uy) / 3;
      double f1 = max_r(x, m1), f2 = max_r(x, m2);
      if (f1 < f2) {
        uy = m2;
        fu = max_r(x, uy);
      } else {
        ly = m1;
        fl = max_r(x, ly);
      }
    }
    return fl;
  };

  double lx = 0, ux = 1000;
  double fl = fx(lx), fu = fx(ux);
  while (abs(fl - fu) > 1e-7) {
    // cout << lx << ' ' << ux << endl;
    // cout << fl << ' ' << fu << endl;
    double m1 = (2 * lx + ux) / 3, m2 = (lx + 2 * ux) / 3;
    double f1 = fx(m1), f2 = fx(m2);
    if (f1 < f2) {
      ux = m2;
      fu = fx(m2);
    } else {
      lx = m1;
      fl = fx(m1);
    }
  }

  cout << setprecision(20) << fl << endl;
}
Problem p02806 (C++)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;

int main() {
  int n, t[55];
  int ans = 0;
  string x, s[55];
  cin >> n;
  rep(i, n) { cin >> s[i] >> t[i]; }
  cin >> x;
  rep(i, n) {
    for (i = n - 1; i >= 0; i--) {
      if (x == s[i])
        break;
      ans += t[i];
    }
  }
  cout << ans << endl;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;

int main() {
  int n, t[55];
  int ans = 0;
  string x, s[55];
  cin >> n;
  rep(i, n) { cin >> s[i] >> t[i]; }
  cin >> x;
  for (int i = n - 1; i >= 0; i--) {
    if (x == s[i])
      break;
    ans += t[i];
  }
  cout << ans << endl;
}
Problem p02806 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m = 0;
  cin >> n;
  vector<pair<string, int>> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(n).first >> a.at(n).second;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (i < n - 1 && a.at(i).first == s) {
      for (int j = i + 1; j < n; j++)
        m += a.at(j).second;
      break;
    }
  }
  cout << m << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m = 0;
  cin >> n;
  vector<pair<string, int>> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i).first >> a.at(i).second;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (i < n - 1 && a.at(i).first == s) {
      for (int j = i + 1; j < n; j++)
        m += a.at(j).second;
      break;
    }
  }
  cout << m << endl;
}
Problem p02806 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<pair<string, int>> playlist(N);
  for (int i = 0; i < N; i++) {
    cin >> playlist[i].first >> playlist[i].second;
  }
  string target;
  cin >> target;

  auto i = playlist.begin();
  while (i != playlist.end() && (*i).first != target)
    i++;
  i++;
  int ans = 0;
  while (i != playlist.end())
    ans += (*i).second;
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<pair<string, int>> playlist(N);
  for (int i = 0; i < N; i++) {
    cin >> playlist[i].first >> playlist[i].second;
  }
  string target;
  cin >> target;

  auto i = playlist.begin();
  while (i != playlist.end() && (*i).first != target)
    i++;
  i++;
  int ans = 0;
  while (i != playlist.end())
    ans += (*i++).second;
  cout << ans << endl;
}
Problem p02806 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
//*************** Constraints are always Imaginary,I'm real **************
using namespace std;
#define int long long
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define fi first
#define se second
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  vector<pair<string, int>> pal(n);
  // unordered_map<string,int> mp;
  for (int i = 0; i < n; i++) {
    string str;
    int a;
    cin >> str >> a;
    pal[i] = {str, a};
    // mp[str]=a;
  }
  string f;
  cin >> f;
  int index;
  for (int i = 0; i < n; i++) {
    if (pal[i].first == f) {
      index = i + 1;
      break;
    }
  }
  int sum = 0;
  while (index < n) {
    sum += pal[index].second;
    index++;
  }
  cout << sum;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
//*************** Constraints are always Imaginary,I'm real **************
using namespace std;
#define int long long
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define fi first
#define se second
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  int n;
  cin >> n;
  vector<pair<string, int>> pal(n);
  // unordered_map<string,int> mp;
  for (int i = 0; i < n; i++) {
    string str;
    int a;
    cin >> str >> a;
    pal[i] = {str, a};
    // mp[str]=a;
  }
  string f;
  cin >> f;
  int index;
  for (int i = 0; i < n; i++) {
    if (pal[i].first == f) {
      index = i + 1;
      break;
    }
  }
  int sum = 0;
  while (index < n) {
    sum += pal[index].second;
    index++;
  }
  cout << sum;
  return 0;
}
Problem p02806 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define cin(a) scanf("%d", &a)
#define pii pair<int, int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9 + 7;

map<string, int> mp;
string a[100];
int t[100];

int main() {
#ifdef ONLINE_JUDGE
#else
  freopen("data.in", "r", stdin);
#endif
  int n;
  cin(n);
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> t[i];
    mp[a[i]] = i;
  }
  string str;
  cin >> str;
  int i = mp[str] + 1;
  int ans = 0;
  for (; i <= n; i++) {
    ans += t[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define cin(a) scanf("%d", &a)
#define pii pair<int, int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9 + 7;

map<string, int> mp;
string a[100];
int t[100];

int main() {
  int n;
  cin(n);
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> t[i];
    mp[a[i]] = i;
  }
  string str;
  cin >> str;
  int i = mp[str] + 1;
  int ans = 0;
  for (; i <= n; i++) {
    ans += t[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02806 (C++)

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

const int N = 50;

std::string names[N];
int len[N], n, ans = 0;
std::string music;

int main() {
  std::cin >> n;
  for (int i = 1; i <= n; i++)
    std::cin >> names[i] >> len[i];
  std::cin >> music;

  bool flag{0};
  for (int i = 1; i <= n; i++) {
    if (flag)
      ans += len[i];
    if (names[i] == music)
      flag = 1;
  }
  std::cout << ans;
  return 0;
}


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

const int N = 5000;

std::string names[N];
int len[N], n, ans = 0;
std::string music;

int main() {
  std::cin >> n;
  for (int i = 1; i <= n; i++)
    std::cin >> names[i] >> len[i];
  std::cin >> music;

  bool flag{0};
  for (int i = 1; i <= n; i++) {
    if (flag)
      ans += len[i];
    if (names[i] == music)
      flag = 1;
  }
  std::cout << ans;
  return 0;
}
Problem p02806 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<string, int>> v;
  long long ans = 0;
  string x;
  bool f = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  cin >> x;
  for (int i = 0; i < n; i++) {
    if (f) {
      ans += v[i].second;
    }
    if (v[i].first == x)
      f = 1;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<string, int>> v(n);
  long long ans = 0;
  string x;
  bool f = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  cin >> x;
  for (int i = 0; i < n; i++) {
    if (f) {
      ans += v[i].second;
    }
    if (v[i].first == x)
      f = 1;
  }
  cout << ans << endl;
}
Problem p02806 (C++)

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

int main() {
  int n;
  string s[n];
  int t[n];
  string x;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i] >> t[i];
  cin >> x;

  int tsum = 0;

  for (int i = 0; i < n; i++) {
    if (s[i] == x) {
      for (int j = i + 1; j < n; j++) {
        tsum += t[j];
      }
      break;
    }
  }

  cout << tsum << endl;

  return 0;
}

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

int main() {
  int n;
  string s[55];
  int t[55];
  string x;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i] >> t[i];
  cin >> x;

  int tsum = 0;

  for (int i = 0; i < n; i++) {
    if (s[i] == x) {
      for (int j = i + 1; j < n; j++) {
        tsum += t[j];
      }
      break;
    }
  }

  cout << tsum << endl;

  return 0;
}
Problem p02806 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<string> s;
  vector<int> t;
  rep(i, n) cin >> s[i] >> t[i];
  string x;
  cin >> x;
  int ans = 0;
  int num = 0;
  rep(i, n) {
    if (s[i] == x)
      num = i;
  }
  for (int i = num + 1; i < n; i++) {
    ans += t[i];
  }
  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;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  rep(i, n) cin >> s[i] >> t[i];
  string x;
  cin >> x;
  int ans = 0;
  int num = 0;
  rep(i, n) {
    if (s[i] == x)
      num = i;
  }
  for (int i = num + 1; i < n; i++) {
    ans += t[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02806 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <stdio.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;

int a, b, c;
string s, t;

int main() {
  a = 0;
  cin >> a;
  vector<string> u(a);
  vector<int> x(a);
  rep(i, a) { cin >> u.at(i) >> x.at(i); }
  cin >> t;

  int i = 0, sum = 0;
  while (i < a) {
    if (u.at(i) == t) {
      for (int j = i + 1; j < a; j++)
        sum += x.at(j);
      break;
    }
  }
  cout << sum << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <stdio.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;

int a, b, c;
string s, t;

int main() {
  a = 0;
  cin >> a;
  vector<string> u(a);
  vector<int> x(a);
  rep(i, a) { cin >> u.at(i) >> x.at(i); }
  cin >> t;

  int i = 0, sum = 0;
  while (i < a) {
    if (u.at(i) == t) {
      for (int j = i + 1; j < a; j++)
        sum += x.at(j);
      break;
    }
    i++;
  }
  cout << sum << endl;
}
Problem p02807 (Python)

Buggy submission (status: Time Limit Exceeded):
import math

n = int(input())
x = list(map(int, input().split()))
mod = 10**9 + 7

fac = math.factorial(n - 1)


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n**2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


res = 0
for i in range(n - 1):
    d = x[n - 1] - x[i]
    res += (d * fac * pow(i + 1, mod - 2)) % mod

print(res % mod)


Fixed submission:
import math

n = int(input())
x = list(map(int, input().split()))
mod = 10**9 + 7

fac = math.factorial(n - 1) % mod


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n**2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


res = 0
for i in range(n - 1):
    d = x[n - 1] - x[i]
    res += (d * fac * pow(i + 1, mod - 2)) % mod

print(res % mod)
Problem p02807 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 2005;
const int mod = 1e9 + 7;
inline int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int Sub(int x, int y) { return (x -= y) >= 0 ? x : x + mod; }
inline int Mul(int x, int y) { return 1ll * x * y % mod; }
int n, x[max_n];
int inv[max_n];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", x + i);
  inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = Mul(inv[mod % i], mod - mod / i);
  for (int i = 1; i <= n; i++)
    inv[i] = Add(inv[i - 1], inv[i]);
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int tmp = Sub(x[i + 1], x[i]);
    tmp = Mul(tmp, inv[i]);
    ans = Add(ans, tmp);
  }
  for (int i = 1; i < n; i++)
    ans = Mul(ans, i);
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 100005;
const int mod = 1e9 + 7;
inline int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int Sub(int x, int y) { return (x -= y) >= 0 ? x : x + mod; }
inline int Mul(int x, int y) { return 1ll * x * y % mod; }
int n, x[max_n];
int inv[max_n];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", x + i);
  inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = Mul(inv[mod % i], mod - mod / i);
  for (int i = 1; i <= n; i++)
    inv[i] = Add(inv[i - 1], inv[i]);
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int tmp = Sub(x[i + 1], x[i]);
    tmp = Mul(tmp, inv[i]);
    ans = Add(ans, tmp);
  }
  for (int i = 1; i < n; i++)
    ans = Mul(ans, i);
  printf("%d\n", ans);
  return 0;
}
Problem p02807 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock() / CLOCKS_PER_SEC

const int MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) {
  n %= MOD;
  if (n < 0)
    return n + MOD;
  else
    return n;
}
int fp(int a, int p) {
  int ans = 1, c = a;
  for (int i = 0; (1ll << i) <= p; ++i) {
    if ((p >> i) & 1)
      ans = mod(ans * c);
    c = mod(c * c);
  }
  return ans;
}
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }

const int N = 1e5 + 7;
int a[N];
int inv[N];

signed main() {
#ifdef HOME
  freopen("input.txt", "r", stdin);
#else
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif
  for (int i = 0; i < N; ++i)
    inv[i] = fp(i, MOD - 2);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int len = a[j] - a[j - 1];
      ans += len * inv[j - i];
      ans %= MOD;
    }
  }
  for (int i = 1; i <= n - 1; ++i)
    ans = ans * i % MOD;
  cout << ans << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock() / CLOCKS_PER_SEC

const int MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) {
  n %= MOD;
  if (n < 0)
    return n + MOD;
  else
    return n;
}
int fp(int a, int p) {
  int ans = 1, c = a;
  for (int i = 0; (1ll << i) <= p; ++i) {
    if ((p >> i) & 1)
      ans = mod(ans * c);
    c = mod(c * c);
  }
  return ans;
}
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }

const int N = 1e5 + 7;
int a[N];
int inv[N];

signed main() {
#ifdef HOME
  freopen("input.txt", "r", stdin);
#else
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif
  for (int i = 0; i < N; ++i)
    inv[i] = fp(i, MOD - 2);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int ans = 0, cur = 0;
  for (int i = 1; i < n; ++i) {
    cur += inv[i];
    cur %= MOD;
    int len = a[i] - a[i - 1];
    ans += len * cur;
    ans %= MOD;
  }
  for (int i = 1; i <= n - 1; ++i)
    ans = ans * i % MOD;
  cout << ans << '\n';
}
Problem p02807 (C++)

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

using namespace std;
#define int long long
const int p = (1e9 + 7);
int po(int a, int b) {
  if (b == 0) {
    return 1;
  }
  if (b == 1) {
    return a;
  }
  if (b % 2 == 0) {
    int u = po(a, b / 2);
    return (u * u) % p;
  }
  int u = po(a, b - 1);
  return (a * u) % p;
}
int inv(int x) { return po(x, p - 2); }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = (n - 1); i >= 0; i--) {
    for (int j = (i + 1); j < n; ++j) {
      if (j != (n - 1))
        ans += (inv((j - i) * (j - i + 1)) * (a[j] - a[i]));
      else
        ans += inv(j - i) * (a[j] - a[i]);
      ans %= p;
    }
  }
  for (int i = 1; i <= (n - 1); ++i) {
    ans *= i;
    ans %= p;
  }
  cout << ans;
  return 0;
}


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

using namespace std;
#define int long long
const int p = (1e9 + 7);
int po(int a, int b) {
  if (b == 0) {
    return 1;
  }
  if (b == 1) {
    return a;
  }
  if (b % 2 == 0) {
    int u = po(a, b / 2);
    return (u * u) % p;
  }
  int u = po(a, b - 1);
  return (a * u) % p;
}
int inv(int x) { return po(x, p - 2); }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = 0;
  int d[n + 2];
  d[0] = 0;
  for (int i = 1; i <= n; ++i) {
    d[i] = d[i - 1] + inv(i);
    d[i] %= p;
  }
  for (int i = 0; i < (n - 1); ++i) {
    ans += (a[i + 1] - a[i]) * d[i + 1];
    ans %= p;
  }
  for (int i = 1; i <= (n - 1); ++i) {
    ans *= i;
    ans %= p;
  }
  cout << ans;
  return 0;
}
Problem p02808 (C++)

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

const int M = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long dp[k + 1][n + 1], comb[n + 1][n + 1];
  memset(comb, 0, sizeof comb);
  comb[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= i; j++)
      comb[i][j] = ((j > 0 ? comb[i - 1][j - 1] : 0) + comb[i - 1][j]) % M;
  for (int i = 0; i <= n; i++)
    dp[0][i] = i == 0;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j <= n; j++) {
      long long sum = 0;
      for (int l = 0; l <= min(a[i], j); l++) {
        sum +=
            dp[i][j - l] * comb[n - j + l][l] % M * comb[n - l][a[i] - l] % M;
      }
      dp[i + 1][j] = sum % M;
    }
  }

  cout << dp[k][n] << endl;
}


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

const int M = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  int a[k];
  for (int i = 0; i < k; i++)
    cin >> a[i];
  long long dp[k + 1][n + 1], comb[n + 1][n + 1];
  memset(comb, 0, sizeof comb);
  comb[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= i; j++)
      comb[i][j] = ((j > 0 ? comb[i - 1][j - 1] : 0) + comb[i - 1][j]) % M;
  for (int i = 0; i <= n; i++)
    dp[0][i] = i == 0;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j <= n; j++) {
      long long sum = 0;
      for (int l = 0; l <= min(a[i], j); l++) {
        sum +=
            dp[i][j - l] * comb[n - j + l][l] % M * comb[n - l][a[i] - l] % M;
      }
      dp[i + 1][j] = sum % M;
    }
  }

  cout << dp[k][n] << endl;
}
Problem p02808 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, k, a[21];
int dp[21][1005];
int C[1005][1005];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cin >> a[i];
  C[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= n; j++) {
      if (!dp[i - 1][j])
        continue;
      for (int l = 0; l <= j; l++) {
        for (int r = 0; r <= a[i] - l; r++) {
          (dp[i][j + r] += 1ll * C[j][l] * C[n - j][a[i] - l] % mod *
                           C[a[i] - l][r] % mod * dp[i - 1][j] % mod) %= mod;
        }
      }
    }
  }
  printf("%d\n", dp[k][n]);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, k, a[21];
int dp[21][1005];
int C[1005][1005];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cin >> a[i];
  C[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= n; j++) {
      if (!dp[i - 1][j])
        continue;
      for (int l = 0; l <= n - j && l <= a[i]; l++) {
        (dp[i][j + l] += 1ll * C[n - j][l] * C[n - l][a[i] - l] % mod *
                         dp[i - 1][j] % mod) %= mod;
      }
    }
  }
  printf("%d\n", dp[k][n]);

  return 0;
}
Problem p02808 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int maxn = 1005;
const int mod = 1e9 + 7;
int dp[22][maxn];
int C[maxn][maxn];
void init() {
  for (int i = 0; i < maxn; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
  }
}
int main() {
  init();
  int n, k;
  cin >> n >> k;
  vi a(n);
  int tot = 0;
  for (int i = 1; i <= k; i++)
    cin >> a[i], tot += a[i];
  dp[0][0] = 1;
  for (int i = 1; i <= k; i++)
    for (int j = 0; j <= n; j++)
      for (int l = 0; l <= a[i] && j + l <= n; l++)
        dp[i][j + l] = (dp[i][j + l] + 1LL * dp[i - 1][j] * C[n - j][l] % mod *
                                           C[n - l][a[i] - l] % mod) %
                       mod;
  cout << dp[k][n] << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int maxn = 1005;
const int mod = 1e9 + 7;
int dp[22][maxn];
int C[maxn][maxn];
void init() {
  for (int i = 0; i < maxn; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
  }
}
int main() {
  init();
  int n, k;
  cin >> n >> k;
  vi a(k + 1);
  int tot = 0;
  for (int i = 1; i <= k; i++)
    cin >> a[i], tot += a[i];
  dp[0][0] = 1;
  for (int i = 1; i <= k; i++)
    for (int j = 0; j <= n; j++)
      for (int l = 0; l <= a[i] && j + l <= n; l++)
        dp[i][j + l] = (dp[i][j + l] + 1LL * dp[i - 1][j] * C[n - j][l] % mod *
                                           C[n - l][a[i] - l] % mod) %
                       mod;
  cout << dp[k][n] << '\n';
}
Problem p02809 (C++)

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

int const N = 100000;
int a[N + 1], an[N + 1], fr[N + 1], n;
set<pair<int, int>> st;
set<int> lft;

void rm(int t) {
  lft.erase(t);
  st.erase(make_pair(fr[a[t]], a[t]));
  --fr[a[t]];
  st.insert(make_pair(fr[a[t]], a[t]));
}

void ad(int t) {
  lft.insert(t);
  st.erase(make_pair(fr[a[t]], a[t]));
  ++fr[a[t]];
  st.insert(make_pair(fr[a[t]], a[t]));
}

bool go(int i = 1, int bad = 0) {
  if (i == n) {
    int t = *lft.begin();
    if (t == bad)
      return false;
    an[i] = t;
    return true;
  }
  int m = n - i + 1;
  int t = st.begin()->second;
  if (fr[t] == m - 1) {
    an[i] = t;
    rm(t);
    bool ok = go(i + 1, a[t]);
    ad(t);
    return ok;
  }
  vector<int> v;
  int z = 5;
  for (auto it = lft.begin(); it != lft.end() && z; ++it, --z)
    v.push_back(*it);
  for (int u : v)
    if (bad != u) {
      rm(u);
      an[i] = u;
      bool ok = go(i + 1, a[u]);
      ad(u);
      if (ok)
        return true;
    }
  return false;
}

int main() {
  scanf("%d", &n);
  if (n == 2) {
    printf("-1\n");
    return 0;
  }
  f(i, 1, n + 1) scanf("%d", a + i), ++fr[a[i]];
  f(i, 1, n + 1) st.insert(make_pair(fr[i], i));
  f(i, 1, n + 1) lft.insert(i);
  go();
  printf("%d", an[1]);
  f(i, 2, n + 1) printf(" %d", an[i]);
  printf("\n");
}

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

int const N = 100000;
int a[N + 1], an[N + 1], fr[N + 1], n;
set<pair<int, int>> st;
set<int> lft;

void rm(int t) {
  lft.erase(t);
  st.erase(make_pair(fr[a[t]], a[t]));
  --fr[a[t]];
  st.insert(make_pair(fr[a[t]], a[t]));
}

void ad(int t) {
  lft.insert(t);
  st.erase(make_pair(fr[a[t]], a[t]));
  ++fr[a[t]];
  st.insert(make_pair(fr[a[t]], a[t]));
}

bool go(int i = 1, int bad = 0) {
  if (i == n) {
    int t = *lft.begin();
    if (t == bad)
      return false;
    an[i] = t;
    return true;
  }
  int m = n - i + 1;
  int t = st.rbegin()->second;
  if (fr[t] == m - 1 && lft.find(t) != lft.end()) {
    an[i] = t;
    rm(t);
    bool ok = go(i + 1, a[t]);
    ad(t);
    return ok;
  }
  vector<int> v;
  int z = 5;
  for (auto it = lft.begin(); it != lft.end() && z; ++it, --z)
    v.push_back(*it);
  for (int u : v)
    if (bad != u) {
      rm(u);
      an[i] = u;
      bool ok = go(i + 1, a[u]);
      ad(u);
      if (ok)
        return true;
    }
  return false;
}

int main() {
  scanf("%d", &n);
  if (n == 2) {
    printf("-1\n");
    return 0;
  }
  f(i, 1, n + 1) scanf("%d", a + i), ++fr[a[i]];
  f(i, 1, n + 1) st.insert(make_pair(fr[i], i));
  f(i, 1, n + 1) lft.insert(i);
  go();
  printf("%d", an[1]);
  f(i, 2, n + 1) printf(" %d", an[i]);
  printf("\n");
}
Problem p02809 (C++)

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

int const maxn = 1e5 + 10;

int N, a[maxn], b[maxn];

int main() {
  scanf("%d", &N);

  int deg[maxn] = {};
  for (int i = 1; i <= N; i++) {
    scanf("%d", &a[i]);
    deg[a[i]]++;
  }

  bool vis[maxn] = {};
  function<void(int, int)> dfs = [&](int cur, int mn) {
    if (cur == N + 1) {
      for (int i = 1; i <= N; i++)
        printf("%d ", b[i]);
      putchar('\n');
      exit(0);
    }

    if (cur > 1 && !vis[a[b[cur - 1]]] && deg[a[b[cur - 1]]] == N - cur + 1)
      return;

    while (vis[mn])
      mn++;

    for (int v = mn; v <= N; v++) {
      if (vis[v] || (cur > 1 && v == a[b[cur - 1]]))
        continue;
      b[cur] = v;
      vis[v] = true;
      deg[a[v]]--;
      dfs(cur + 1, v == mn ? mn + 1 : mn);
      deg[a[v]]++;
      vis[v] = false;
    }
  };

  dfs(1, 1);
  puts("-1");

  return 0;
}


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

int const maxn = 1e5 + 10;

int N, a[maxn], b[maxn];

int main() {
  scanf("%d", &N);

  int deg[maxn] = {};
  for (int i = 1; i <= N; i++) {
    scanf("%d", &a[i]);
    deg[a[i]]++;
  }

  bool vis[maxn] = {};
  function<void(int, int)> dfs = [&](int cur, int mn) {
    if (cur == N + 1) {
      for (int i = 1; i <= N; i++)
        printf("%d ", b[i]);
      putchar('\n');
      exit(0);
    }

    if (cur > 1 && !vis[a[b[cur - 1]]] && deg[a[b[cur - 1]]] == N - cur)
      return;

    while (vis[mn])
      mn++;

    for (int v = mn; v <= N; v++) {
      if (vis[v] || (cur > 1 && v == a[b[cur - 1]]))
        continue;
      b[cur] = v;
      vis[v] = true;
      deg[a[v]]--;
      dfs(cur + 1, v == mn ? mn + 1 : mn);
      deg[a[v]]++;
      vis[v] = false;
    }
  };

  dfs(1, 1);
  puts("-1");

  return 0;
}
Problem p02809 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = a; i > (int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 17;

int T[maxN], res[maxN];
bool juz[maxN];

void fail() {
  printf("-1\n");
  exit(0);
}

void ans(int n) {
  FOR(i, 1, n + 1)
  printf("%d ", res[i]);
  printf("\n");
  exit(0);
}

bool colide(int i) { return T[res[i]] == res[i + 1]; }

int main() {
  int n;
  scanf("%d", &n);
  FOR(i, 1, n + 1)
  scanf("%d", T + i);
  if (n == 2)
    fail();

  int list = 1, mx = 0;

  FOR(i, 0, n) {
    int v = res[i];
    if (T[v] != list)
      res[i + 1] = list;
    else
      res[i + 1] = mx == list - 1 ? mx + 2 : mx + 1;
    juz[res[i + 1]] = true;

    while (juz[list])
      list++;
    mx = max(mx, res[i + 1]);
  }

  int i = n;
  while (colide(i - 1))
    swap(res[i], res[i - 1]), i--;
  sort(res + i + 1, res + n + 1);

  if (!colide(i))
    ans(n);
  if (i <= n - 2)
    swap(res[i + 1], res[i + 2]), ans(n);

  assert(i == n - 1);
  swap(res[n - 2], res[n - 1]);
  swap(res[n - 2], res[n]);
  if (colide(n - 3))
    swap(res[n - 2], res[n]);
  ans(n);
  assert(false);
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = a; i > (int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 17;

int T[maxN], res[maxN];
bool juz[maxN];

void fail() {
  printf("-1\n");
  exit(0);
}

void ans(int n) {
  FOR(i, 1, n + 1)
  printf("%d ", res[i]);
  printf("\n");
  exit(0);
}

bool colide(int i) { return T[res[i]] == res[i + 1]; }

int main() {
  int n;
  scanf("%d", &n);
  FOR(i, 1, n + 1)
  scanf("%d", T + i);
  if (n == 2)
    fail();

  int list = 1, mx = 0;

  FOR(i, 0, n) {
    int v = res[i];
    if (T[v] != list)
      res[i + 1] = list;
    else
      res[i + 1] = mx == list - 1 ? mx + 2 : mx + 1;
    juz[res[i + 1]] = true;

    while (juz[list])
      list++;
    mx = max(mx, res[i + 1]);
  }

  if (res[n] > n)
    res[n] = list;

  int i = n;
  while (colide(i - 1))
    swap(res[i], res[i - 1]), i--;
  sort(res + i + 1, res + n + 1);

  if (!colide(i))
    ans(n);
  if (i <= n - 2)
    swap(res[i + 1], res[i + 2]), ans(n);

  assert(i == n - 1);
  swap(res[n - 2], res[n - 1]);
  swap(res[n - 2], res[n]);
  if (colide(n - 3))
    swap(res[n - 2], res[n]);
  ans(n);
  assert(false);
}
Problem p02811 (Python)

Buggy submission (status: Runtime Error):
K = int(input("Enter k: "))
X = int(input("Enter x: "))

if K * 500 >= X:
    print("Yes")
else:
    print("No")


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

if K * 500 >= X:
    print("Yes")
else:
    print("No")
Problem p02811 (Python)

Buggy submission (status: Runtime Error):
if __name__ == "__main__":
    x = int(input())
    m, n = map(int, input().split())
    if m * 500 >= n:
        print("Yes")
    else:
        print("No")


Fixed submission:
if __name__ == "__main__":
    m, n = map(int, input().split())
    if m * 500 >= n:
        print("Yes")
    else:
        print("No")
Problem p02811 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr << x << END;
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, b, a) for (int i = (b); i > (a); --i)
const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int inf = INT_MAX;
bool mywish(const pii &a, const pii &b) { return a.first > b.first; }

void solve() {
  int k, x;
  cin >> k >> x;
  cout << (500ll * k >= x ? "Yes" : "No");
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  /* int t;
   cin>>t;
   while(t--)*/
  solve();
  // cerr<<END<<1.0*clock();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr << x << END;
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, b, a) for (int i = (b); i > (a); --i)
const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int inf = INT_MAX;
bool mywish(const pii &a, const pii &b) { return a.first > b.first; }

void solve() {
  int k, x;
  cin >> k >> x;
  cout << (500ll * k >= x ? "Yes" : "No");
}
signed main() {

  /* int t;
   cin>>t;
   while(t--)*/
  solve();
  // cerr<<END<<1.0*clock();
  return 0;
}
Problem p02811 (Python)

Buggy submission (status: Runtime Error):
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
permutation = list(itertools.permutations([x for x in range(1, N + 1)]))

a = permutation.index(P) + 1
b = permutation.index(Q) + 1
print(abs(a - b))


Fixed submission:
K, X = map(int, input().split())
print("Yes" if K * 500 >= X else "No")
Problem p02811 (C++)

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

#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr << #x << " : " << x << '\n';
#define yogeshk972()                                                           \
  cerr << "\nTime Taken : " << (float)(clock() - time_p) / CLOCKS_PER_SEC      \
       << "\n";
clock_t time_p = clock();

using namespace std;
const int N = 1e6 + 10, mod = 998244353;

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

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

  ll k, x;
  cin >> k >> x;
  if (500 * k >= x)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


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

#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr << #x << " : " << x << '\n';
#define yogeshk972()                                                           \
  cerr << "\nTime Taken : " << (float)(clock() - time_p) / CLOCKS_PER_SEC      \
       << "\n";
clock_t time_p = clock();

using namespace std;
const int N = 1e6 + 10, mod = 998244353;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /*
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
  */
  ll k, x;
  cin >> k >> x;
  if (500 * k >= x)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}