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

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

using namespace std;

#define fr(i, a, b) for (long long int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (long long i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)
#define foreach(it, ar)                                                        \
  for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++)
#define debug(x) cout << #x << ": " << x << endl
#define ull unsigned long long
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define PI 3.1415926535897932385
#define INF 1000111222
#define EPS 1e-7
#define MAXN 1000001
#define MOD 1000000007
/*ASHWINI SHARMA*/
void pairsort(ll a[], ll b[], ll n) {
  pair<ll, ll> pairt[n];

  // Storing the respective array
  // elements in pairs.
  for (ll i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }

  // Sorting the pair array.
  sort(pairt, pairt + n);

  // Modifying original arrays
  for (ll i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cin.sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll a[n];
  ll b[n];
  rep(i, n) cin >> a[i] >> b[i];
  pairsort(a, b, n);
  ll sum = 0;
  rep(i, n) {
    sum += min(m, b[i]) * a[i];
    m -= min(m, b[i]);
  }
  cout << sum;
  return 0;
}

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

using namespace std;

#define fr(i, a, b) for (long long int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (long long i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)
#define foreach(it, ar)                                                        \
  for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++)
#define debug(x) cout << #x << ": " << x << endl
#define ull unsigned long long
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define PI 3.1415926535897932385
#define INF 1000111222
#define EPS 1e-7
#define MAXN 1000001
#define MOD 1000000007
/*ASHWINI SHARMA*/
void pairsort(ll a[], ll b[], ll n) {
  pair<ll, ll> pairt[n];

  // Storing the respective array
  // elements in pairs.
  for (ll i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }

  // Sorting the pair array.
  sort(pairt, pairt + n);

  // Modifying original arrays
  for (ll i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}

int main() {

  cin.sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll a[n];
  ll b[n];
  rep(i, n) cin >> a[i] >> b[i];
  pairsort(a, b, n);
  ll sum = 0;
  rep(i, n) {
    sum += min(m, b[i]) * a[i];
    m -= min(m, b[i]);
  }
  cout << sum;
  return 0;
}
Problem p03103 (C++)

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

using namespace std;

#define rep(i, a, n) for (int i = a; i < (n); ++i)
#define ll long long

template <class T, class U> struct P {
  T a;
  U b;
};

bool Comp(P<ll, ll> &a, P<ll, ll> &b) { return a.a <= b.a; }

int main() {
  ll n, m;
  cin >> n >> m;

  vector<P<ll, ll>> ab(n);
  rep(i, 0, n) cin >> ab[i].a >> ab[i].b;
  sort(ab.begin(), ab.end(), Comp);

  ll a, b, ans = 0;
  rep(i, 0, n) {
    a = ab[i].a;
    b = ab[i].b;
    if (m <= b) {
      ans += m * a;
      break;
    }
    if (m > b) {
      m -= b;
      ans += a * b;
    }
  }
  printf("%lld\n", ans);
}

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

using namespace std;

#define rep(i, a, n) for (int i = a; i < (n); ++i)
#define ll long long

template <class T, class U> struct P {
  T a;
  U b;
};

bool Comp(P<ll, ll> &a, P<ll, ll> &b) { return a.a < b.a; }

int main() {
  ll n, m;
  cin >> n >> m;

  vector<P<ll, ll>> ab(n);
  rep(i, 0, n) cin >> ab[i].a >> ab[i].b;
  sort(ab.begin(), ab.end(), Comp);

  ll a, b, ans = 0;
  rep(i, 0, n) {
    a = ab[i].a;
    b = ab[i].b;
    if (m <= b) {
      ans += m * a;
      break;
    }
    if (m > b) {
      m -= b;
      ans += a * b;
    }
  }
  printf("%lld\n", ans);
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <locale>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f) ? "Yes" : "No")
#define YES(f) puts((f) ? "YES" : "NO")
int gcd(int a, int b) {
  if (b != 0)
    return gcd(b, a % b);
  return a;
}
ll Lgcd(ll a, ll b) {
  if (b != 0)
    return gcd(b, a % b);
  return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
ll Llcm(ll a, ll b) { return a / gcd(a, b) * b; }
using Graph = vector<vector<int>>;
// cout << fixed << setprecision(6);
// cout << setfill('0') << right << setw(2);

int main() {
  ll n, m, a, b, ans = 0;
  cin >> n >> m;
  vector<pair<ll, ll>> v;
  rep(i, n) {
    cin >> a >> b;
    v[i] = pair<ll, ll>(a, b);
  }
  sort(v.begin(), v.end());
  rep(i, n) {
    ans += v[i].first * min(m, v[i].second);
    m -= v[i].second;
    if (m <= 0)
      break;
  }
  cout << ans << endl;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <locale>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f) ? "Yes" : "No")
#define YES(f) puts((f) ? "YES" : "NO")
int gcd(int a, int b) {
  if (b != 0)
    return gcd(b, a % b);
  return a;
}
ll Lgcd(ll a, ll b) {
  if (b != 0)
    return gcd(b, a % b);
  return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
ll Llcm(ll a, ll b) { return a / gcd(a, b) * b; }
using Graph = vector<vector<int>>;
// cout << fixed << setprecision(6);
// cout << setfill('0') << right << setw(2);

int main() {
  ll n, m, a, b, ans = 0;
  cin >> n >> m;
  vector<pair<ll, ll>> v;
  rep(i, n) {
    cin >> a >> b;
    v.push_back(pair<ll, ll>(a, b));
  }
  sort(v.begin(), v.end());
  rep(i, n) {
    ans += v[i].first * min(m, v[i].second);
    m -= v[i].second;
    if (m <= 0)
      break;
  }
  cout << ans << endl;
}
Problem p03103 (C++)

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

int main() {
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());

  long long N, M;
  cin >> N >> M;

  vector<pair<long long, long long>> E(N);
  for (int i = 0; i < N; i++) {
    cin >> E.at(i).first >> E.at(i).second;
  }

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

  // for(int i=0;i<N;i++) cout<<E.at(i).first<<','<<E.at(i).second<<endl;

  long long ans = 0;
  long long num;
  long long i = 0;
  while (num < M) {
    num += E.at(i).second;
    ans += E.at(i).first * E.at(i).second;
    i++;
  }
  // cout<<num<<','<<ans<<','<<i<<endl;
  ans = ans - (num - M) * E.at(i - 1).first;
  cout << ans << endl;
}

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

int main() {
  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  long long N, M;
  cin >> N >> M;

  vector<pair<long long, long long>> E(N);
  for (int i = 0; i < N; i++) {
    cin >> E.at(i).first >> E.at(i).second;
  }

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

  // for(int i=0;i<N;i++) cout<<E.at(i).first<<','<<E.at(i).second<<endl;

  long long ans = 0;
  long long num;
  long long i = 0;
  while (num < M) {
    num += E.at(i).second;
    ans += E.at(i).first * E.at(i).second;
    i++;
  }
  // cout<<num<<','<<ans<<','<<i<<endl;
  ans = ans - (num - M) * E.at(i - 1).first;
  cout << ans << endl;
}
Problem p03103 (C++)

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

int main() {
  long long int N, M;
  cin >> N >> M;
  vector<pair<long long int, long long int>> X(N);
  for (long long int i = 0; i < N; i++) {
    long long int A, B;
    cin >> A >> B;
    X.at(i) = make_pair(A, B);
  }

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

  long long int ans = 0;
  long long int i = 0;
  while (M >= X.at(i).second) {
    ans += X.at(i).first * X.at(i).second;
    M -= X.at(i).second;
    i++;
  }
  ans += X.at(i).first * M;

  cout << ans << endl;
}


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

int main() {
  long long int N, M;
  cin >> N >> M;
  vector<pair<long long int, long long int>> X(N);
  for (long long int i = 0; i < N; i++) {
    long long int A, B;
    cin >> A >> B;
    X.at(i) = make_pair(A, B);
  }

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

  long long int ans = 0;
  long long int i = 0;
  while (M > X.at(i).second) {
    ans += X.at(i).first * X.at(i).second;
    M -= X.at(i).second;
    i++;
  }
  ans += X.at(i).first * M;

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int maxN = 10010;
const int MAXM = 310;
const int MAXK = 17;
const int MOD = 1000000007;
const ll INF = 10000000000000000LL;
const ll inf = 5000000000000LL;

int a[maxN];
int b[maxN];
int c;
int n, m;
struct node {
  int x, y;
  bool operator<(const node &p) const { return x < p.x; }
};
node s[maxN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &s[i].x, &s[i].y);
  }
  sort(s + 1, s + 1 + n);
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i].y >= m) {
      ans += (ll)s[i].x * m;
      break;
    } else {
      ans += (ll)s[i].x * s[i].y;
      m -= s[i].y;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int maxN = 100010;
const int MAXM = 310;
const int MAXK = 17;
const int MOD = 1000000007;
const ll INF = 10000000000000000LL;
const ll inf = 5000000000000LL;

int a[maxN];
int b[maxN];
int c;
int n, m;
struct node {
  int x, y;
  bool operator<(const node &p) const { return x < p.x; }
};
node s[maxN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &s[i].x, &s[i].y);
  }
  sort(s + 1, s + 1 + n);
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i].y >= m) {
      ans += (ll)s[i].x * m;
      break;
    } else {
      ans += (ll)s[i].x * s[i].y;
      m -= s[i].y;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03103 (C++)

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

using namespace std;

long long sum;
int n, m, cnt;
pair<int, int> p[10005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= n; i++) {
    int cnti = 0;
    while (cnt != m) {
      if (cnti == p[i].second) {
        break;
      } else {
        sum += p[i].first;
      }
      cnt++;
      cnti++;
    }
  }
  cout << sum;
  return 0;
}


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

using namespace std;

long long sum;
int n, m, cnt;
pair<int, int> p[100005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= n; i++) {
    int cnti = 0;
    while (cnt != m) {
      if (cnti == p[i].second) {
        break;
      } else {
        sum += p[i].first;
      }
      cnt++;
      cnti++;
    }
  }
  cout << sum;
  return 0;
}
Problem p03103 (C++)

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

typedef long long ll;

int main() {
  ll n, q;
  cin >> n >> q;

  vector<pair<ll, ll>> v;
  for (int i = 0; i < n; i++)
    cin >> v[i].first >> v[i].second;

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

  ll ans = 0;

  for (int i = 0; i < n; i++) {
    int amount = min(q, v[i].second);
    ans += v[i].first * amount;
    q -= amount;
  }

  cout << ans << endl;
}

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

typedef long long ll;

int main() {
  ll n, q;
  cin >> n >> q;

  vector<pair<ll, ll>> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i].first >> v[i].second;

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

  ll ans = 0;

  for (int i = 0; i < n; i++) {
    int amount = min(q, v[i].second);
    ans += v[i].first * amount;
    q -= amount;
  }

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

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

using namespace std;

int main() {
  int N, M, a, b;
  cin >> N >> M;
  vector<pair<int, int>> pairs(N);
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    pairs[i] = make_pair(a, b);
  }
  sort(pairs.begin(), pairs.end());
  int honsuu = 0;
  int index = 0;
  int tmp = pairs[0].second;
  long long ans = 0;
  while (true) {
    if (tmp == 0) {
      ++index;
      tmp = pairs[index].second;
    }
    for (int i = 0; i < pairs[index].second; ++i) {
      if (honsuu == M) {
        cout << ans << endl;
        return 0;
      }
      ++honsuu;
      --tmp;
      ans += pairs[index].first;
    }
  }

  return 0;
}

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

using namespace std;

int main() {
  int N, M, a, b;
  cin >> N >> M;
  vector<pair<int, int>> pairs(N);
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    pairs[i] = make_pair(a, b);
  }
  sort(pairs.begin(), pairs.end());
  int honsuu = 0;
  int index = 0;
  int tmp = pairs[0].second;
  long long ans = 0;
  while (true) {
    if (honsuu == M) {
      cout << ans << endl;
      return 0;
    }
    if (tmp == 0) {
      ++index;
      tmp = pairs[index].second;
    }
    for (int i = 0; i < pairs[index].second; ++i) {
      if (honsuu == M) {
        cout << ans << endl;
        return 0;
      }
      ++honsuu;
      --tmp;
      ans += pairs[index].first;
    }
  }

  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Time Limit Exceeded):
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define double long double
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n + 1)
using namespace std;
bool my_compare(pair<ll, ll> a, pair<ll, ll> b) {
  // 基本はfirstで比較
  if (a.first != b.first) {
    return a.first < b.first; // 昇順
                              // return a.first > b.first; // 降順
  }

  // それ以外はsecondで比較
  if (a.second != b.second) {
    return a.second > b.second;
  } else {
    // どちらも同じ
    return true;
  }
}

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

  ll a, b, c, m, n, maxi = 0, f = 0, mini = INF, sum = 0;
  string str;
  cin >> n >> m;
  vector<pair<ll, ll>> p(n);

  rep(i, n) {
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end(), my_compare);
  ll d = 0;
  ll mem;
  rep(i, n) {
    sum += p[i].first * p[i].second;
    d += p[i].second;
    mem = i;
    if (d >= m)
      break;
  }
  sum -= (d - m) * p[mem].first;
  cout << sum << endl;

  return 0;
}


Fixed submission:
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define double long double
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n + 1)
using namespace std;
bool my_compare(pair<ll, ll> a, pair<ll, ll> b) {
  // 基本はfirstで比較
  if (a.first != b.first) {
    return a.first < b.first; // 昇順
                              // return a.first > b.first; // 降順
  }

  // それ以外はsecondで比較
  if (a.second != b.second) {
    return a.second > b.second;
  } else {
    // どちらも同じ
    return true;
  }
}

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

  ll a, b, c, m, n, maxi = 0, f = 0, mini = INF, sum = 0;
  string str;
  cin >> n >> m;
  vector<pair<ll, ll>> p(n);

  rep(i, n) {
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end());
  ll d = 0;
  ll mem;
  rep(i, n) {
    sum += p[i].first * p[i].second;
    d += p[i].second;
    mem = i;
    if (d >= m)
      break;
  }
  sum -= (d - m) * p[mem].first;
  cout << sum << endl;

  return 0;
}
Problem p03103 (C++)

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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N);
  vector<long long> B(N);
  for (long long i = 0; i < N; i++) {
    cin >> A.at(i) >> B.at(i);
  }

  vector<pair<long long, long long>> p(N);
  for (long long i = 0; i < N; i++) {
    p.at(i) = make_pair(A.at(i), B.at(i));
  }

  sort(p.begin(), p.end());
  long long sum = 0;
  long long cost = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < p[i].second; j++) {
      sum++;
      cost += p[i].first;
      if (sum == M) {
        cout << cost << endl;
        break;
      }
    }
  }
}


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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N);
  vector<long long> B(N);
  for (long long i = 0; i < N; i++) {
    cin >> A.at(i) >> B.at(i);
  }

  vector<pair<long long, long long>> p(N);
  for (long long i = 0; i < N; i++) {
    p.at(i) = make_pair(A.at(i), B.at(i));
  }

  sort(p.begin(), p.end());
  long long sum = 0;
  long long cost = 0;
  for (int i = 0; i < N; i++) {
    sum += p[i].second;
    cost += p[i].first * p[i].second;
    if (sum >= M) {
      cost -= p[i].first * (sum - M);
      cout << cost << endl;
      break;
    }
  }
}
Problem p03103 (C++)

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

int main() {
  int N, M, A, B;
  cin >> N >> M;
  vector<pair<int, int>> list(N);
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    list[i] = make_pair(A, B);
  }

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

  long cost = 0;
  int drink = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < list[i].second; j++) {
      if (drink < M) {
        drink++;
        cost += list[i].first;
      }
    }
  }

  cout << cost << endl;
}

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

int main() {
  int N, M, A, B;
  cin >> N >> M;
  vector<pair<int, int>> list(N);
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    list[i] = make_pair(A, B);
  }

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

  long cost = 0;
  int drink = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < list[i].second; j++) {
      if (drink < M) {
        drink++;
        cost += list[i].first;
      }
      if (drink >= M) {
        break;
      }
    }
    if (drink >= M) {
      break;
    }
  }

  cout << cost << endl;
}
Problem p03103 (C++)

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

using namespace std;
#define N_MAX 10005
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  pair<ll, int> T[N_MAX];
  for (int i = 0; i < N; i++) {
    ll A;
    int B;
    cin >> A >> B;
    T[i].first = A;
    T[i].second = B;
  }
  sort(T, T + N);
  ll money = 0;
  for (int i = 0; i < N; i++) {
    if (M >= T[i].second) {
      M -= T[i].second;
      money += T[i].first * T[i].second;
    } else {
      money += T[i].first * M;
      break;
    }
  }
  cout << money << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
#define N_MAX 100005
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  pair<ll, int> T[N_MAX];
  for (int i = 0; i < N; i++) {
    ll A;
    int B;
    cin >> A >> B;
    T[i].first = A;
    T[i].second = B;
  }
  sort(T, T + N);
  ll money = 0;
  for (int i = 0; i < N; i++) {
    if (M >= T[i].second) {
      M -= T[i].second;
      money += T[i].first * T[i].second;
    } else {
      money += T[i].first * M;
      break;
    }
  }
  cout << money << endl;
}
Problem p03103 (C++)

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

typedef pair<int, int> ii;

int main() {
  int n, m, x;
  cin >> n >> m;
  vector<ii> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  int i = 0;
  long long y = 0;
  while (x < m) {
    if (a[i].second > 0)
      y += a[i].first, a[i].second--, x++;
    else
      i++;
  }
  cout << y << endl;
}

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

typedef pair<int, int> ii;

int main() {
  int n, m, x = 0;
  cin >> n >> m;
  vector<ii> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  int i = 0;
  long long y = 0;
  while (x < m) {
    if (a[i].second > 0)
      y += a[i].first, a[i].second--, x++;
    else
      i++;
  }
  cout << y << endl;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define poi 1000
using namespace std;
struct girl {
  int x, y;
  bool operator<(girl b) const { return x < b.x; }
} a[poi];
inline int re() {
  char c = getchar();
  int x = 0, k = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * k;
}
void wr(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    wr(x / 10);
  putchar(x % 10 + '0');
}
signed main() {
  int n = re(), m = re(), ans = 0;
  for (int i = 1; i <= n; i++)
    a[i].x = re(), a[i].y = re();
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    if (m - a[i].y < 0) {
      ans += a[i].x * m;
      break;
    }
    ans += a[i].x * a[i].y;
    m -= a[i].y;
  }
  wr(ans);
  return 0;
}
/*

*/

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define poi 1000000
#define int long long
using namespace std;
struct girl {
  int x, y;
  bool operator<(girl b) const { return x < b.x; }
} a[poi];
inline int re() {
  char c = getchar();
  int x = 0, k = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * k;
}
void wr(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    wr(x / 10);
  putchar(x % 10 + '0');
}
signed main() {
  int n = re(), m = re(), ans = 0;
  for (int i = 1; i <= n; i++)
    a[i].x = re(), a[i].y = re();
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    if (m - a[i].y < 0) {
      ans += a[i].x * m;
      break;
    }
    ans += a[i].x * a[i].y;
    m -= a[i].y;
  }
  wr(ans);
  return 0;
}
/*

*/
Problem p03103 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  vector<pair<int, int>> ab;
  rep(i, n) {
    cin >> a.at(i) >> b.at(i);
    ab.at(i) = make_pair(a.at(i), b.at(i));
  }
  sort(ab.begin(), ab.end());
  int64_t ans = 0;
  rep(i, n) {
    int p = min(m, ab.at(i).second);
    ans += p * ab.at(i).first;
    m -= p;
  }
  cout << ans;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int64_t> a(n), b(n);
  vector<pair<int64_t, int>> ab(n);
  rep(i, n) {
    cin >> a.at(i) >> b.at(i);
    ab.at(i) = make_pair(a.at(i), b.at(i));
  }
  sort(ab.begin(), ab.end());
  int64_t ans = 0;
  rep(i, n) {
    int p = min(m, ab.at(i).second);
    ans += p * ab.at(i).first;
    m -= p;
  }
  cout << ans;
}
Problem p03105 (C++)

Buggy submission (status: Time Limit Exceeded):
/**************************
 * Writer : Leo101
 * Problem :
 * Tags :
 **************************/
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define File(s)                                                                \
  freopen(#s ".in", "r", stdin);                                               \
  freopen(#s ".out", "w", stdout)
#define gi get_int()
int get_int() {
  int x = 0, y = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    y = -1, ch = getchar();
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * y;
}

int main() {
  File(a);

  int a = gi, b = gi, k = gi;

  printf("%d", std ::min(b / a, k));

  return 0;
}


Fixed submission:
/**************************
 * Writer : Leo101
 * Problem :
 * Tags :
 **************************/
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define File(s)                                                                \
  freopen(#s ".in", "r", stdin);                                               \
  freopen(#s ".out", "w", stdout)
#define gi get_int()
int get_int() {
  int x = 0, y = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    y = -1, ch = getchar();
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * y;
}

int main() {
  int a = gi, b = gi, k = gi;

  printf("%d", std ::min(b / a, k));

  return 0;
}
Problem p03105 (C++)

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

using namespace std;

#define forsn(i, s, n) for (int i = s; i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

typedef long long tint;

const int INF = 1e6;
const long double PI = acos(-1);

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if (a == 1 && b == 1) {
    cout << 1;
    return 0;
  }
  set<int> s;
  forsn(i, 1, min(a, b)) {
    if (a % i == 0 && b % i == 0)
      s.insert(i);
  }
  auto it = s.end();
  forn(i, k) { it--; }
  cout << *it << endl;
}

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

using namespace std;

#define forsn(i, s, n) for (int i = s; i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

typedef long long tint;

const int INF = 1e6;
const long double PI = acos(-1);

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c) << endl;
}
Problem p03105 (C++)

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ans = A * C;
  if (A > B) {
    cout << "0" << endl;
    exit(1);
  }
  for (int i = 3; i <= 100; i++) {
    if (ans < B) {
      ans = ans + A * C;
    } else {
      cout << i << endl;
      exit(1);
    }
  }
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A * C < B) {
    cout << C << endl;
  } else {
    cout << int(B / A) << endl;
  }
}
Problem p03105 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(10**5)
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

ans = n * (n - 1) // 2
result = [ans]
leader = [-1] * n
size = [1] * n


def leader_check(i):
    if leader[i] == -1:
        return i
    ln = leader_check(leader[i])
    leader[i] = ln
    return ln


for a, b in ab[:0:-1]:
    a, b = a - 1, b - 1
    la = leader_check(a)
    lb = leader_check(b)
    if la != lb:
        leader[la] = lb
        ans -= size[la] * size[lb]
        size[lb] += size[la]
    result.append(ans)

for i in result[::-1]:
    print(i)


Fixed submission:
a, b, c = list(map(int, input().split()))
if b > a * c:
    print(c)
else:
    print(int(b / a))
Problem p03105 (C++)

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

int main() {
  long A;
  long B;
  long C;
  std::cin >> A >> B >> C;
  if (A * C < B) {
    std::cout << C;
  } else {
    std::cout << B / A;
  }
  main();
  return 0;
}

Fixed submission:
#include <iostream>

int main() {
  long A;
  long B;
  long C;
  std::cin >> A >> B >> C;
  if (A * C < B) {
    std::cout << C;
  } else {
    std::cout << B / A;
  }
  return 0;
}
Problem p03105 (C++)

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

int main() {
  int a, b, c;
  cin >> a, b, c;
  if (a / b >= c) {
    cout << c << endl;
  } else if (a / b < c) {
    cout << a / b << endl;
  }
  return 0;
}


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

int main() {
  int a, b, c;
  cin >> b >> a >> c;
  if (a / b >= c) {
    cout << c << endl;
  } else if (a / b < c) {
    cout << a / b << endl;
  }
  return 0;
}
Problem p03105 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n, m) for (int i = (n); i < (m); i++)
#define REP_EQ(i, n, m) for (int i = (n); i <= (m); i++)
#define CNT(i, n) for (int i = (n); i > 0; i--)
#define REP_two(i, n, m) for (int i = (n); i < (m); i += 2)
#define ll long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int MAX = 1e9;
int MOD = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int cnt, ans = 0;
  cnt = b % a;
  ans = c / cnt;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n, m) for (int i = (n); i < (m); i++)
#define REP_EQ(i, n, m) for (int i = (n); i <= (m); i++)
#define CNT(i, n) for (int i = (n); i > 0; i--)
#define REP_two(i, n, m) for (int i = (n); i < (m); i += 2)
#define ll long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int MAX = 1e9;
int MOD = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  if (a * c <= b) {
    ans = c;
  } else {
    ans = b / a;
  }
  cout << ans << endl;
}
Problem p03105 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main(void) {
  int a, b, c, co = 0;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  while (a > b || c != 0) {
    b = b - a;
    co++;
    c--;
  }
  printf("%d\n", co);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int a, b, c, co = 0;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  while (a <= b && c > 0) {
    b = b - a;
    co++;
    c--;
  }
  printf("%d\n", co);
  return 0;
}
Problem p03105 (C++)

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

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  auto ans = b / a;
  return ans < c ? ans : c;
}

Fixed submission:
#include <iostream>

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  auto ans = b / a;
  std::cout << (ans < c ? ans : c) << std::endl;
  ;
  return 0;
}
Problem p03106 (C++)

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  if (A > B)
    swap(A, B);
  int cnt = 0;
  for (int i = 0; i < A; i++) {
    if (A % i == 0 && B % i == 0)
      cnt++;
    if (cnt == K) {
      cout << i << endl;
      break;
    }
  }
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  if (A > B)
    swap(A, B);
  int cnt = 0;
  for (int i = A; i > 0; i--) {
    if (A % i == 0 && B % i == 0)
      cnt++;
    if (cnt == K) {
      cout << i << endl;
      break;
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {

  int a, b, k, c;

  cin >> a >> b >> k;

  for (int i = 100; 0 < i; i++) {
    if ((a / i) * i == a && (b / i) * i == b) {
      k--;
      if (k == 0) {
        cout << i << endl;
        i = 0;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {

  int a, b, k, c;

  cin >> a >> b >> k;

  for (int i = 100; 0 < i; i--) {
    if ((a / i) * i == a && (b / i) * i == b) {
      k--;
      if (k == 0) {
        cout << i << endl;
        i = 0;
      }
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, K;
  int cnt = 1;
  cin >> A >> B >> K;
  int comdiv[K];
  for (int i = 1; i < 100; i++) {
    if ((A % i == 0) || (B % i == 0)) {
      comdiv[cnt] = i;
      cnt++;
    }
  }
  cout << comdiv[K];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, K;
  int cnt = 1;
  cin >> A >> B >> K;
  int comdiv[100];
  for (int i = 100; 0 < i; i--) {
    if ((A % i == 0) && (B % i == 0)) {
      comdiv[cnt] = i;
      cnt++;
    }
  }
  cout << comdiv[K];
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> gcd;
  int mx = max(a, b);
  for (int i = 1; i < mx; i++) {
    if (a % i == 0 && b % i == 0) {
      gcd.push_back(i);
    }
  }
  sort(gcd.begin(), gcd.end(), greater<int>());
  cout << gcd[k - 1] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> gcd;
  int mx = max(a, b);
  for (int i = 1; i <= mx; i++) {
    if (a % i == 0 && b % i == 0) {
      gcd.push_back(i);
    }
  }
  sort(gcd.begin(), gcd.end(), greater<int>());
  cout << gcd[k - 1] << endl;
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <type_traits>
#include <vector>

using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> v;
  for (int i = 1; i < max(A / 2 + 1, B / 2 + 1); i++) {
    if (A % i == 0 && B % i == 0) {
      v.push_back(i);
    }
  }
  cout << v[v.size() - K] << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <type_traits>
#include <vector>

using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> v;
  for (int i = 1; i <= max(A, B); i++) {
    if (A % i == 0 && B % i == 0) {
      v.push_back(i);
    }
  }
  cout << v[v.size() - K] << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll cnt = 0;
  for (int i = 0; i <= 1000; i++) {
    if (a % i == 0 && b % i == 0)
      cnt++;
    if (cnt == c) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll cnt = 0;
  for (int i = 1000; i >= 1; i--) {
    if (a % i == 0 && b % i == 0)
      cnt++;
    if (cnt == c) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i, n, m) for (int i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define DUMP(a)                                                                \
  REP(d, a.size()) {                                                           \
    cout << a[d];                                                              \
    if (d != a.size() - 1)                                                     \
      cout << " ";                                                             \
    else                                                                       \
      cout << endl;                                                            \
  }
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v)                                                              \
  sort(ALL(v));                                                                \
  v.erase(unique(ALL(v)), v.end());
#define pb push_back

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, k;
  cin >> a >> b >> k;
  int c = 0;
  REP(i, 101) {
    if (a % i == 0 && b % i == 0) {
      c++;
    }
    if (c == k) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
/* --------------------------------------- */


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i, n, m) for (int i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define DUMP(a)                                                                \
  REP(d, a.size()) {                                                           \
    cout << a[d];                                                              \
    if (d != a.size() - 1)                                                     \
      cout << " ";                                                             \
    else                                                                       \
      cout << endl;                                                            \
  }
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v)                                                              \
  sort(ALL(v));                                                                \
  v.erase(unique(ALL(v)), v.end());
#define pb push_back

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, k;
  cin >> a >> b >> k;
  int c = 0;
  for (int i = 100; i > 0; i--) {
    if (a % i == 0 && b % i == 0) {
      c++;
    }
    if (c == k) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
/* --------------------------------------- */
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

int main() {

  int A, B, K;

  cin >> A >> B >> K;
  vector<int> n(100);

  int C = min(A, B);
  for (int i = 1; i <= C; i++) {
    if (A % i == 0 && B % i == 0)
      n.at(i) = i;
  }

  sort(n.begin(), n.end(), greater<int>());

  cout << n.at(K - 1) << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

int main() {

  int A, B, K;

  cin >> A >> B >> K;
  vector<int> n(110);

  int C = min(A, B);
  for (int i = 1; i <= C; i++) {
    if (A % i == 0 && B % i == 0)
      n.at(i) = i;
  }

  sort(n.begin(), n.end(), greater<int>());

  cout << n.at(K - 1) << endl;

  return 0;
}
Problem p03106 (C++)

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

int gcd(int A, int B) {
  if (B % A == 0) {
    return A;
  } else {
    return gcd(A % B, B);
  }
}

std::vector<int> enum_div(int n) {
  std::vector<int> ret;
  for (int i = 1; i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
    }
  }
  return ret;
}

int main(int argc, char const *argv[]) {
  int A, B, K;
  std::cin >> A >> B >> K;
  int value_max = gcd(std::min(A, B), std::max(A, B));
  std::vector<int> elements = enum_div(value_max);
  int ans = elements[elements.size() - K];
  std::cout << ans << std::endl;

  return 0;
}


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

int gcd(int A, int B) {
  if (B % A == 0) {
    return A;
  } else {
    return gcd(B % A, B);
  }
}

std::vector<int> enum_div(int n) {
  std::vector<int> ret;
  for (int i = 1; i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
    }
  }
  return ret;
}

int main(int argc, char const *argv[]) {
  int A, B, K;
  std::cin >> A >> B >> K;
  int value_max = gcd(std::min(A, B), std::max(A, B));
  std::vector<int> elements = enum_div(value_max);
  int ans = elements[elements.size() - K];
  std::cout << ans << std::endl;

  return 0;
}
Problem p03106 (C++)

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x, y) scanf("%llu%llu", &x, &y)
#define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x, y) for (int x = 0; x < y; x++)
#define Repe(x, y, z) for (int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n");
// }}} 2

// }}} 1

int main() {

  int a, b, k;
  Scd3(a, b, k);

  int i = a * b;
  while (k) {
    i--;
    if (a % i == 0 && b % i == 0) {
      k--;
    }
  }

  printf("%d\n", i);

  return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x, y) scanf("%llu%llu", &x, &y)
#define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x, y) for (int x = 0; x < y; x++)
#define Repe(x, y, z) for (int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n");
// }}} 2

// }}} 1

int main() {

  int a, b, k;
  Scd3(a, b, k);

  int i = a * b + 1;
  while (k) {
    i--;
    if (a % i == 0 && b % i == 0) {
      k--;
    }
  }

  printf("%d\n", i);

  return 0;
}
Problem p03106 (C++)

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> retu(100);

  for (int i = 1; i < 101; i++) {
    if (A % i == 0) {
      if (B % i == 0) {
        retu.at(i) = i;
      }
    }
  }
  sort(retu.begin(), retu.end());
  reverse(retu.begin(), retu.end());
  cout << retu.at(K - 1) << endl;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> retu(101);

  for (int i = 1; i < 101; i++) {
    if (A % i == 0) {
      if (B % i == 0) {
        retu.at(i) = i;
      }
    }
  }
  sort(retu.begin(), retu.end());
  reverse(retu.begin(), retu.end());
  cout << retu.at(K - 1) << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

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

  int A, B, K;
  cin >> A >> B >> K;

  vector<int> cd;

  for (int a = 2; a <= A; ++a) {
    if (A % a == 0 && B % a == 0)
      cd.push_back(a);
  }

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

  cout << cd[cd.size() - K] << "\n";

  return 0;
}

Fixed submission:
#include <algorithm>
#include <chrono>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

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

  int A, B, K;
  cin >> A >> B >> K;

  vector<int> cd;

  for (int a = 1; a <= A; ++a) {
    if (A % a == 0 && B % a == 0)
      cd.push_back(a);
  }

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

  cout << cd[cd.size() - K] << "\n";

  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl

using namespace std;

int main() {

  int A, B, K;

  vector<int> ans;

  cin >> A >> B >> K;

  for (int i = 1; i < A; i++) {
    if (A % i == 0 && B % i == 0)
      ans.push_back(i);
  }

  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());

  cout << ans[K - 1] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl

using namespace std;

int main() {

  int A, B, K;

  vector<int> ans;

  cin >> A >> B >> K;

  for (int i = 1; i <= A; i++) {
    if (A % i == 0 && B % i == 0)
      ans.push_back(i);
  }

  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());

  cout << ans[K - 1] << endl;

  return 0;
}
Problem p03106 (C++)

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> v;

  for (int i = 1; i < max(A, B); i++) {
    if (0 == (A % i) && 0 == (B % i))
      v.push_back(i);
  }

  // 順序反転
  reverse(v.begin(), v.end());
  // 出力
  cout << v[K - 1] << endl;
}


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> v;

  for (int i = 1; i <= max(A, B); i++) {
    if (0 == (A % i) && 0 == (B % i))
      v.push_back(i);
  }

  // 順序反転
  reverse(v.begin(), v.end());
  // 出力
  cout << v[K - 1] << endl;
}