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

#include <iostream>
using namespace std;
int n, m, a[111][111], b[55][55];
void rotate() {
  int z[55][55];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      z[i][j] = b[m - j - 1][i];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      b[i][j] = z[i][j];
    }
  }
}
int main() {
  while (cin >> n >> m, n | m) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        cin >> b[i][j];
      }
    }
    int rx = n, ry = n;
    for (int i = 0; i < 4; i++) {
      int sx = m;
      for (int j = m - 1; j >= 0; j--) {
        if (b[0][j] != -1)
          sx = j;
      }
      for (int j = 0; j <= n - m; j++) {
        for (int k = 0; k <= n - m; k++) {
          bool flag = true;
          for (int ey = j; ey < j + m; ey++) {
            for (int ex = k; ex < k + m; ex++) {
              int v = b[ey - j][ex - k];
              if (v != -1 && a[ey][ex] != v)
                flag = false;
            }
          }
          if (flag && (ry > j || (ry == j && rx > k + sx))) {
            rx = k + sx, ry = j;
          }
        }
      }
      rotate();
    }
    if (rx == n && ry == n)
      cout << "NA" << endl;
    else
      cout << rx + 1 << ' ' << ry + 1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int n, m, a[111][111], b[55][55];
void rotate() {
  int z[55][55];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      z[i][j] = b[m - j - 1][i];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      b[i][j] = z[i][j];
    }
  }
}
int main() {
  while (cin >> n >> m, n | m) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        cin >> b[i][j];
      }
    }
    int rx = n, ry = n;
    for (int i = 0; i < 4; i++) {
      int sx = m;
      for (int j = m - 1; j >= 0; j--) {
        if (b[0][j] != -1)
          sx = j;
      }
      for (int j = 0; j <= n - m; j++) {
        for (int k = 0; k <= n - m; k++) {
          bool flag = true;
          for (int ey = j; ey < j + m; ey++) {
            for (int ex = k; ex < k + m; ex++) {
              int v = b[ey - j][ex - k];
              if (v != -1 && a[ey][ex] != v)
                flag = false;
            }
          }
          if (flag && (ry > j || (ry == j && rx > k + sx))) {
            rx = k + sx, ry = j;
          }
        }
      }
      rotate();
    }
    if (rx == n && ry == n)
      cout << "NA" << endl;
    else
      cout << rx + 1 << ' ' << ry + 1 << endl;
  }
  return 0;
}
Problem p00209 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
  int n, m;
  while (scanf("%d %d", &n, &m), n) {
    vvi in(n, vi(n));
    vvi pic(m, vi(m));
    rep(i, n) rep(j, n) scanf("%d", &in[i][j]);
    rep(i, m) rep(j, m) scanf("%d", &pic[i][j]);
    pii out(inf, inf);
    rep(e, 4) {
      rep(i, n - m + 1) rep(j, n - m + 1) {
        pii t(inf, inf);
        rep(k, m) rep(l, m) if (pic[k][l] != -1 &&
                                in[i + k][j + l] != pic[k][l]) goto en;
        else if (pic[k][l] != -1) t = min(t, pii(i + k, j + l));
        out = min(out, t);
        goto end;
      en:;
      }
    end:;
      vvi tmp = pic;
      rep(i, m) rep(j, m) pic[i][j] = tmp[j][m - i - 1];
    }
    if (out.first == inf)
      cout << "NA" << endl;
    else
      cout << out.second + 1 << " " << out.first + 1 << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
  int n, m;
  while (scanf("%d %d", n, m), n) {
    vvi in(n, vi(n));
    vvi pic(m, vi(m));
    rep(i, n) rep(j, n) scanf("%d", &in[i][j]);
    rep(i, m) rep(j, m) scanf("%d", &pic[i][j]);
    pii out(inf, inf);
    rep(e, 4) {
      rep(i, n - m + 1) rep(j, n - m + 1) {
        pii t(inf, inf);
        rep(k, m) rep(l, m) if (pic[k][l] != -1 &&
                                in[i + k][j + l] != pic[k][l]) goto en;
        else if (pic[k][l] != -1) t = min(t, pii(i + k, j + l));
        out = min(out, t);
        goto end;
      en:;
      }
    end:;
      vvi tmp = pic;
      rep(i, m) rep(j, m) pic[i][j] = tmp[j][m - i - 1];
    }
    if (out.first == inf)
      cout << "NA" << endl;
    else
      cout << out.second + 1 << " " << out.first + 1 << endl;
  }
}
Problem p00211 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-8;

int d[10], v[10];
int x[9], y[9];

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lca(int x, int y) {
  long long int mul = (long long int)x * y;
  return mul / gcd(x, y);
}

int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    if (!n)
      break;

    for (int i = 0; i < n; i++) {
      scanf("%d%d", &d[i], &v[i]);
    }

    for (int i = 0; i < n - 1; i++) {
      x[i] = d[i + 1] * v[0];
      y[i] = d[0] * v[i + 1];
      int g = gcd(x[i], y[i]);
      x[i] /= g;
      y[i] /= g;
      // cout << x[i] << " " << y[i] << endl;
    }

    if (n > 2) {
      int l = 1;
      for (int i = 0; i < n - 1; i++) {
        l = lca(l, x[i]);
      }
      cout << l << endl;
      for (int i = 0; i < n - 1; i++) {
        cout << l / x[i] * y[i] << endl;
      }
    } else {
      cout << x[0] << endl;
      cout << y[0] << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-5;

int d[10], v[10];
int x[9], y[9];

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lca(int x, int y) {
  long long int mul = (long long int)x * y;
  return mul / gcd(x, y);
}

int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    if (!n)
      break;

    for (int i = 0; i < n; i++) {
      scanf("%d%d", &d[i], &v[i]);
    }

    double left = (double)d[0] / v[0];
    for (int i = 0; i < n - 1; i++) {
      double right = (double)d[i + 1] / v[i + 1];
      x[i] = 1;
      y[i] = 1;
      while (abs(x[i] * left - y[i] * right) > EPS) {
        if (x[i] * left < y[i] * right)
          x[i]++;
        else
          y[i]++;
      }
      // cout << x[i] << " " << y[i] << endl;
    }

    if (n > 2) {
      int l = 1;
      for (int i = 0; i < n - 1; i++) {
        l = lca(l, x[i]);
      }
      cout << l << endl;
      for (int i = 0; i < n - 1; i++) {
        cout << l / x[i] * y[i] << endl;
      }
    } else {
      cout << x[0] << endl;
      cout << y[0] << endl;
    }
  }

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

// 26
#include <iostream>

using namespace std;

long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int main() {
  for (int n; cin >> n, n;) {
    int d[10], v[10];
    for (int i = 0; i < n; i++) {
      cin >> d[i] >> v[i];
    }
    int m[9];
    for (int i = 0; i < n - 1; i++) {
      m[i] = d[i + 1] * v[0] / gcd(d[0] * v[i + 1], d[i + 1] * v[0]);
    }
    long long f = 1;
    for (int i = 0; i < n - 1; i++) {
      f = f * m[i] / gcd(f, m[i]);
    }
    cout << f << endl;
    for (int i = 1; i < n; i++) {
      cout << f * d[0] * v[i] / v[0] / d[i] << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

// 26
#include <iostream>

using namespace std;

long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int main() {
  for (int n; cin >> n, n;) {
    int d[10], v[10];
    for (int i = 0; i < n; i++) {
      cin >> d[i] >> v[i];
    }
    int m[9];
    for (int i = 0; i < n - 1; i++) {
      for (long long j = 1;; j++) {
        if (j * d[0] * v[i + 1] % (v[0] * d[i + 1]) == 0) {
          m[i] = j;
          break;
        }
      }
    }
    long long f = 1;
    for (int i = 0; i < n - 1; i++) {
      f = f * m[i] / gcd(f, m[i]);
    }
    cout << f << endl;
    for (int i = 1; i < n; i++) {
      cout << f * d[0] * v[i] / v[0] / d[i] << endl;
    }
  }
  return 0;
}
Problem p00211 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  if (a == 0 || b == 0)
    return 0;
  return ((a / gcd(a, b) * b));
}

int main() {
  int n;
  while (cin >> n && n) {
    vector<pair<ll, ll>> v;

    rep(i, n) {
      ll a, b;
      cin >> a >> b;
      v.push_back(make_pair(a, b));
    }

    rep(i, n) {
      ll temp = gcd(v[i].first, v[i].second);
      v[i].first /= temp;
      v[i].second /= temp;
    }

    ll t, t2;
    rep(i, n) {
      if (i == 0) {
        t = v[i].first;
        t2 = v[i].second;
      } else {
        t = lcm(t, v[i].first);
        t2 = gcd(t2, v[i].second);
      }
    }

    rep(i, n) {
      ll ans = t * v[i].second;
      ans /= t2;
      ans /= v[i].first;
      cout << ans << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0)
    return 0;

  while (a != b) {
    if (a > b)
      a -= b;
    else
      b -= a;
  }
  return a;
}

ll lcm(ll a, ll b) {
  if (a == 0 || b == 0)
    return 0;
  return ((a / gcd(a, b) * b));
}

int main() {
  int n;
  while (cin >> n && n) {
    vector<pair<ll, ll>> v;

    rep(i, n) {
      ll a, b;
      cin >> a >> b;
      v.push_back(make_pair(a, b));
    }

    rep(i, n) {
      ll temp = gcd(v[i].first, v[i].second);
      v[i].first /= temp;
      v[i].second /= temp;
    }

    ll t, t2;
    rep(i, n) {
      if (i == 0) {
        t = v[i].first;
        t2 = v[i].second;
      } else {
        t = lcm(t, v[i].first);
        t2 = gcd(t2, v[i].second);
      }
    }

    rep(i, n) {
      ll ans = t * v[i].second;
      ans /= t2;
      ans /= v[i].first;
      cout << ans << endl;
    }
  }
  return 0;
}
Problem p00211 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(max(b, a % b), min(b, a % b));
  }
}

long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}

typedef pair<long long int, long long int> P;

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    long long int t = 1;
    vector<long long int> d(n);
    vector<long long int> v(n);
    for (int i = 0; i < n; i++) {
      cin >> d[i] >> v[i];
      t = lcm(max(v[i] * t, d[i]), min(v[i] * t, d[i])) / v[i];
      // cout << t << endl;
    }
    long long int a = v[0] * t / d[0];
    for (int i = 0; i < n; i++) {
      a = gcd(a, v[i] * t / d[i]);
    }
    for (int i = 0; i < n; i++) {
      cout << (v[i] * t / d[i]) / a << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(max(b, a % b), min(b, a % b));
  }
}

long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}

typedef pair<long long int, long long int> P;

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    vector<vector<long long int>> hyou(n, vector<long long int>(2));
    vector<vector<long long int>> hyou2(n, vector<long long int>(2));
    P pp;
    priority_queue<P, vector<P>, greater<P>> pq;
    for (int i = 0; i < n; i++) {
      cin >> pp.first >> pp.second;
      hyou[i][0] = pp.first;
      hyou[i][1] = pp.second;
      pq.push(pp);
    }
    for (int i = 0; i < n; i++) {
      P ppp = pq.top();
      pq.pop();
      hyou2[i][0] = ppp.first;
      hyou2[i][1] = ppp.second;
    }
    long long int p = hyou2[0][0];
    for (int i = 1; i < n; i++) {
      for (int j = 1;; j++) {
        long double k = (long double)(p * j) / (long double)hyou2[0][1];
        long double b = (long double)hyou2[i][1] * k / (long double)hyou2[i][0];
        if (b - (long long int)b <= 1e-12) {
          p *= j;
          break;
        }
      }
    }
    long double kk = (long double)p / (long double)hyou2[0][1];
    for (int i = 0; i < n; i++) {
      cout << (long long int)(kk * hyou[i][1]) / hyou[i][0] << endl;
    }
  }
  return 0;
}
Problem p00211 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <utility>

using namespace std;

typedef unsigned long long BigInt;

BigInt gcd(BigInt a, BigInt b) {
  if (a < b) {
    swap(a, b);
  }
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}

BigInt lcm(BigInt a, BigInt b) { return a * b / gcd(a, b); }

int main() {
  int n;
  BigInt dh, vh;
  BigInt d[10], v[10];
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> d[i] >> v[i];
    }
    dh = d[0];
    vh = v[0];
    for (int i = 1; i < n; ++i) {
      BigInt y = lcm(v[i] * dh, vh * d[i]);
      BigInt kh = y / (v[i] * dh);
      BigInt z = gcd(dh * kh, vh);
      dh = dh * kh / z;
      vh /= z;
    }
    for (int i = 0; i < n; ++i) {
      cout << dh * v[i] / (d[i] * vh) << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <utility>

using namespace std;

typedef unsigned long long BigInt;

BigInt lcm(BigInt a, BigInt b) {
  BigInt x = a;
  BigInt y = b;
  while (x != y) {
    if (x > y) {
      y += (x - y) / b * b;
      if (x > y) {
        y += b;
      }
    } else {
      x += (y - x) / a * a;
      if (x < y) {
        x += a;
      }
    }
  }
  return x;
}

BigInt gcd(BigInt a, BigInt b) {
  if (a < b) {
    swap(a, b);
  }
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}

int main() {
  int n;
  BigInt dh, vh;
  BigInt d[10], v[10];
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> d[i] >> v[i];
    }
    dh = d[0];
    vh = v[0];
    for (int i = 1; i < n; ++i) {
      BigInt y = lcm(v[i] * dh, vh * d[i]);
      BigInt kh = y / (v[i] * dh);
      BigInt z = gcd(dh * kh, vh);
      dh = dh * kh / z;
      vh /= z;
    }
    for (int i = 0; i < n; ++i) {
      cout << dh * v[i] / (d[i] * vh) << endl;
    }
  }
}
Problem p00211 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long int ll;

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  while (1) {
    ll t = a % b;
    a = b;
    b = t;
    if (b == 0)
      return a;
  }
}

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

    ll d[10], v[10];
    for (ll i = 0; i < n; i++) {
      cin >> d[i] >> v[i];
      ll cd = gcd(d[i], v[i]);
      d[i] /= cd;
      v[i] /= cd;
    }

    ll dlc = d[0];
    for (int i = 1; i < n; i++) {
      dlc = lcm(dlc, d[i]);
    }

    for (int i = 0; i < n; i++) {
      v[i] = v[i] * (dlc / d[i]);
    }

    ll vlc = v[0];
    for (int i = 1; i < n; i++) {
      vlc = gcd(vlc, v[i]);
    }
    for (int i = 0; i < n; i++)
      cout << v[i] / vlc << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long int ll;

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  if (a < b)
    swap(a, b);
  return (a / gcd(a, b)) * b;
}
int main() {
  ll n;
  while (cin >> n, n) {

    ll d[n], v[n];
    for (int i = 0; i < n; i++) {
      cin >> d[i] >> v[i];
    }

    ll dlc = d[0], vlc = v[0];
    for (int i = 1; i < n; i++) {
      dlc = lcm(dlc, d[i]);
      vlc = lcm(vlc, v[i]);
    }

    ll dd[n];
    for (int i = 0; i < n; i++) {
      dd[i] = (d[i] * vlc) / v[i];
    }

    ll ddlc = dd[0];
    for (int i = 1; i < n; i++) {
      ddlc = lcm(ddlc, dd[i]);
    }

    for (int i = 0; i < n; i++)
      cout << ddlc / dd[i] << endl;
  }
  return 0;
}
Problem p00211 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
typedef long long int llf;
vector<int> p;
llf gcd(llf a, llf b) {
  while (a != b) {
    if (max(a, b) % min(a, b) == 0)
      return min(a, b);
    if (a > b)
      a -= b * (a / b);
    else
      b -= a * (b / a);
  }
  return a;
}
llf gcd(llf c[10], int n) {
  llf d[10];
  for (int i = 0; i < n; i++)
    d[i] = c[i];
  llf x = d[0];
  for (int i = 1; i < n; i++)
    x = gcd(x, d[i]);
  return x;
}
llf lcm(llf c[10], int n) {
  int d[10];
  for (int i = 0; i < 10; i++)
    d[i] = c[i];
  int times[10000] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < p.size(); j++) {
      int k = 0;
      while (d[i] % p[j] == 0) {
        d[i] /= p[j];
        k++;
      }
      times[p[j]] = max(times[p[j]], k);
    }
  }
  llf ans = 1;
  for (int i = 0; i < p.size(); i++)
    for (int j = 0; j < times[p[i]]; j++)
      ans *= p[i];
  return ans;
}
int main() {
  // your code goes here
  p.push_back(2);
  for (int i = 3; i <= 10000; i++) {
    for (int j = 0; j < p.size(); j++) {
      if (i % p[j] == 0)
        break;
      if (j == p.size() - 1)
        p.push_back(i);
    }
  }
  int n;
  while (cin >> n && n != 0) {
    llf d[10], v[10];
    for (int i = 0; i < n; i++)
      cin >> d[i] >> v[i];
    llf times = lcm(d, n);
    for (int i = 0; i < n; i++)
      v[i] *= (times / d[i]);
    llf c = gcd(v, n);
    for (int i = 0; i < n; i++)
      cout << v[i] / c << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
typedef long long int llf;
vector<int> p;
llf gcd(llf a, llf b) {
  while (a != b) {
    if (max(a, b) % min(a, b) == 0)
      return min(a, b);
    if (a > b)
      a -= b;
    else
      b -= a;
  }
  return a;
}
llf gcd(llf c[10], int n) {
  llf d[10];
  for (int i = 0; i < n; i++)
    d[i] = c[i];
  llf x = d[0];
  for (int i = 1; i < n; i++)
    x = gcd(x, d[i]);
  return x;
}
llf lcm(llf c[10], int n) {
  int d[10];
  for (int i = 0; i < 10; i++)
    d[i] = c[i];
  int times[10000] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < p.size(); j++) {
      int k = 0;
      while (d[i] % p[j] == 0) {
        d[i] /= p[j];
        k++;
      }
      times[p[j]] = max(times[p[j]], k);
    }
  }
  llf ans = 1;
  for (int i = 0; i < p.size(); i++)
    for (int j = 0; j < times[p[i]]; j++)
      ans *= p[i];
  return ans;
}
int main() {
  // your code goes here
  p.push_back(2);
  for (int i = 3; i <= 10000; i++) {
    for (int j = 0; j < p.size(); j++) {
      if (i % p[j] == 0)
        break;
      if (j == p.size() - 1)
        p.push_back(i);
    }
  }
  int n;
  while (cin >> n && n != 0) {
    llf d[10], v[10];
    for (int i = 0; i < n; i++)
      cin >> d[i] >> v[i];
    llf times = lcm(d, n);
    for (int i = 0; i < n; i++)
      v[i] *= (times / d[i]);
    llf c = gcd(v, n);
    for (int i = 0; i < n; i++)
      cout << v[i] / c << endl;
  }
  return 0;
}
Problem p00211 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second

template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll << 29;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll gcd(ll *begin, ll *end) {
  ll res = *begin;
  while (begin != end)
    res = gcd(res, *begin), ++begin;
  return res;
}

ll lcm(ll *begin, ll *end) {
  ll res = *begin;
  while (begin != end)
    res = lcm(res, *begin), ++begin;
  return res;
}

int n;
ll d[10], v[10], ans[10];

int main() {
  while (cin >> n, n) {
    ll g, l, t;
    REP(i, n) {
      scanf("%lld %lld", d + i, v + i);
      g = gcd(d[i], v[i]);
      d[i] /= g;
      v[i] /= g;
    }

    l = lcm(d, d + n);
    g = gcd(v, v + n);

    REP(i, n) {
      ll ans = (l / d[i]) * (v[i] / g);
      cout << ans << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second

template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll << 29;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll gcd(ll *begin, ll *end) {
  ll res = *begin;
  while (begin != end)
    res = gcd(res, *begin), ++begin;
  return res;
}

ll lcm(ll *begin, ll *end) {
  ll res = *begin;
  while (begin != end)
    res = lcm(res, *begin), ++begin;
  return res;
}

int n;
ll d[10], v[10], ans[10];

int main() {
  while (cin >> n, n) {
    ll g;
    REP(i, n) {
      scanf("%lld %lld", d + i, v + i);
      g = gcd(d[i], v[i]);
      d[i] /= g;
      v[i] /= g;
    }

    g = gcd(d, d + n);
    REP(i, n) d[i] /= g;

    ll l = lcm(v, v + n);
    REP(i, n) ans[i] = d[i] * (l / v[i]);

    l = lcm(ans, ans + n);
    REP(i, n) ans[i] = l / ans[i];

    g = gcd(ans, ans + n);
    REP(i, n) ans[i] /= g;

    REP(i, n) cout << ans[i] << endl;
  }
  return 0;
}