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

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

using namespace std;

int main() {
  int a, b;

  while (scanf("%d%d", &a, &b) != EOF) {
    int gcd;

    for (int i = 2; i <= ((a < b) ? b : a); i++) {
      if ((a % i == 0) && (b % i == 0))
        gcd = i;
    }

    printf("%d %d\n", gcd, (int)((long)a * b / (long)gcd));
  }

  return 0;
}

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

using namespace std;

int main() {
  int a, b;

  while (scanf("%d%d", &a, &b) != EOF) {
    int gcd = a, tmp_b = b;
    int tmp;
    while (tmp_b != 0) {
      tmp = gcd % tmp_b;
      gcd = tmp_b;
      tmp_b = tmp;
    }

    printf("%d %d\n", gcd, (int)((long)a * b / (long)gcd));
  }

  return 0;
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int gcd(int x, int y) {
  int amari;
  while (y != 0) {
    amari = x % y;
    x = y;
    y = amari;
  }
  return x;
}

int lcm(int x, int y) {
  int g = gcd(x, y);
  return x / g * y;
}

int main() {
  int a, b;
  while (true) {
    cin >> a >> b;
    cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
  }
}

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

int gcd(int x, int y) {
  int amari;
  while (y != 0) {
    amari = x % y;
    x = y;
    y = amari;
  }
  return x;
}

int lcm(int x, int y) {
  int g = gcd(x, y);
  return x / g * y;
}

int main() {
  int a, b;
  while (true) {
    cin >> a >> b;
    if (std::cin.eof()) {
      break;
    }
    cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
  }
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

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

int main() {
  while (true) {
    int a, b;
    cin >> a >> b;

    if (cin.eof())
      break;

    int g = gcd(a, b);
    cout << g << " " << a / g * b << endl;
  }

  return 0;
}


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

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

int main() {
  while (true) {
    int a, b;
    cin >> a >> b;

    if (cin.eof())
      break;

    int g = gcd(a, b);
    cout << g << " " << a / g * b << endl;
  }

  return 0;
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
using namespace std;
long long int n, m, ans, amari, ahokusa;

int main(void) {
  while (1) {
    scanf("%lld%lld", &n, &m);
    ans = n * m;
    if (n < m) {
      ahokusa = n;
      n = m;
      m = ahokusa;
    }
    amari = n % m;
    while (amari != 0) {
      n = m;
      m = amari;
      amari = n % m;
    }
    ans = ans / m;
    printf("%lld %lld\n", m, ans);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>
using namespace std;
long long int n, m, ans, amari, ahokusa;

int main() {
  while (scanf("%lld%lld", &n, &m) != -1) {
    ans = n * m;
    if (n < m) {
      ahokusa = n;
      n = m;
      m = ahokusa;
    }
    amari = n % m;
    while (amari != 0) {
      n = m;
      m = amari;
      amari = n % m;
    }
    ans = ans / m;
    printf("%lld %lld\n", m, ans);
  }

  return 0;
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int a, b, c, rest;
  while (1) {
    cin >> a >> b;
    int a2 = a, b2 = b;
    if (a > b) {
      c = a;
      a = b;
      b = c;
    }
    while ((rest = b % a) != 0) {
      b = a;
      a = rest;
    }
    cout << a << " " << a2 / a * b2 << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c, rest;
  while (cin >> a >> b) {
    int a2 = a, b2 = b;
    if (a > b) {
      c = a;
      a = b;
      b = c;
    }
    while ((rest = b % a) != 0) {
      b = a;
      a = rest;
    }
    cout << a << " " << a2 / a * b2 << endl;
  }
  return 0;
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int a, b, a1, b1, r;
  int tmp = 0;
  int i = 0;

  while (scanf("%d %d", &a, &b)) {
    if (a < b) {
      tmp = a;
      a = b;
      b = tmp;
    }

    a1 = a;
    b1 = b;
    r = a1 % b1;
    while (r != 0) {
      a1 = b1;
      b1 = r;
      r = a1 % b1;
    }
    printf("%d %ld\n", b1, (long)a * b / b1);
  }

  return 0;
}

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

int main() {
  int a, b, a1, b1, r;
  int tmp = 0;
  int i = 0;

  while (cin >> a >> b) {
    if (a < b) {
      tmp = a;
      a = b;
      b = tmp;
    }

    a1 = a;
    b1 = b;
    r = a1 % b1;
    while (r != 0) {
      a1 = b1;
      b1 = r;
      r = a1 % b1;
    }
    printf("%d %ld\n", b1, (long)a * b / b1);
  }

  return 0;
}
Problem p00005 (C++)

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

using namespace std;

int gcd(int a, int b) {

  if (b == 0)
    return a;

  return gcd(b, a % b);
}

int lcm(int a, int b, int ans_gcd) {
  int ans;

  ans = a / ans_gcd * b;

  return ans;
}

int main() {
  int a, b;
  int ans_gcd, ans_lcm;

  while (1) { // cin >> a >> b) {
    cin >> a >> b;
    if ((a == 0) && (b == 0))
      break;

    ans_gcd = gcd(a, b);
    ans_lcm = lcm(a, b, ans_gcd);

    cout << ans_gcd << " " << ans_lcm << endl;
  }

  return 0;
}

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

using namespace std;

int gcd(int a, int b) {

  if (b == 0)
    return a;

  return gcd(b, a % b);
}

int lcm(int a, int b, int ans_gcd) {
  int ans;

  ans = a / ans_gcd * b;

  return ans;
}

int main() {
  int a, b;
  int ans_gcd, ans_lcm;

  while (cin >> a >> b) {
    if ((a == 0) && (b == 0))
      break;

    ans_gcd = gcd(a, b);
    ans_lcm = lcm(a, b, ans_gcd);

    cout << ans_gcd << " " << ans_lcm << endl;
  }

  return 0;
}
Problem p00005 (C++)

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

int main() {
  int x[2], k = 1, a, b;

  while (cin >> x[1] >> x[2]) {
    if (x[2] > x[1])
      swap(x[1], x[2]);
    a = x[1];
    b = x[2];
    while (x[3 - k] != 0) {
      x[k] = x[k] % x[3 - k];
      k = 3 - k;
    }
    cout << x[k] << " " << a / x[k] * b << endl;
    k = 1;
  }

  return 0;
}

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

int main() {
  int x[3], k = 1, a, b;

  while (cin >> x[1] >> x[2]) {
    if (x[2] > x[1])
      swap(x[1], x[2]);
    a = x[1];
    b = x[2];
    while (x[3 - k] != 0) {
      x[k] = x[k] % x[3 - k];
      k = 3 - k;
    }
    cout << x[k] << " " << a / x[k] * b << endl;
    k = 1;
  }

  return 0;
}
Problem p00005 (C++)

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

using namespace std;

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

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b), &a, &b) {
    int g = gcd(a, b);
    printf("%d %d\n", g, a / g * b / g * g);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>

using namespace std;

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

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    int g = gcd(a, b);
    printf("%d %d\n", g, a / g * b / g * g);
  }
  return 0;
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int a, b, c, d, e, f, g, l;
  while (cin >> a >> b) {
    c = a;
    d = b;
    e = a;
    f = b;
    while (1) {
      if (a > b) {
        a %= b;
        if (a == 0) {
          g = b;
          break;
        }
      } else if (a < b) {
        b %= a;
        if (b == 0) {
          g = a;
          break;
        }
      }
    }
    while (1) {
      if (c > d)
        d += f;
      else if (c < d)
        c += e;
      if (c == d) {
        l = c;
        break;
      }
    }
    cout << g << " " << l << endl;
  }
}

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

int main() {
  int a, b, c, d, e, f, g, l;
  while (cin >> a >> b) {
    c = a;
    d = b;
    e = a;
    f = b;
    while (1) {
      if (a >= b) {
        a %= b;
        if (a == 0) {
          g = b;
          break;
        }
      } else if (a < b) {
        b %= a;
        if (b == 0) {
          g = a;
          break;
        }
      }
    }
    while (1) {
      if (c > d)
        d += f;
      else if (c < d)
        c += e;
      if (c == d) {
        l = c;
        break;
      }
    }
    cout << g << " " << l << endl;
  }
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  int a, b;
  while (cin >> a >> b) {
    int lcm, gcd;

    for (int i = min(a, b); i >= 1; i--) {
      if (!(a % i) && !(b % i)) {
        gcd = i;
        break;
      }
    }
    lcm = a * (b / gcd); //()必要。intの範囲のため

    cout << gcd << " " << lcm << endl;
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  int a, b;
  while (cin >> a >> b) {
    int lcm, gcd;

    int n = min(a, b);
    if (!(a % n) && !(b % n)) {
      gcd = n;
    } else {
      for (int i = n / 2; i >= 1; i--) {
        if (!(a % i) && !(b % i)) {
          gcd = i;
          break;
        }
      }
    }
    lcm = a * (b / gcd); //()必要。intの範囲のため

    cout << gcd << " " << lcm << endl;
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();

  return 0;
}
Problem p00005 (C++)

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

int gcd(int m, int n) {
  if ((0 == m) || (0 == n))
    return 0;

  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}
int lcm(int m, int n) {
  if ((0 == m) || (0 == n))
    return 0;
  return ((m / gcd(m, n)) * n);
}
int main() {
  int m, n;
  cin >> m;
  cin >> n;
  cout << gcd(m, n) << " " << lcm(m, n) << endl;
  return 1;
}

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

int gcd(int m, int n) {
  if ((0 == m) || (0 == n))
    return 0;

  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}
int lcm(int m, int n) {
  if ((0 == m) || (0 == n))
    return 0;
  return ((m / gcd(m, n)) * n);
}
int main() {
  int m, n;
  while (cin >> m >> n) {
    cout << gcd(m, n) << " " << lcm(m, n) << endl;
  }
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long a, b;
  while (cin >> a >> b) {
    long long gcd;
    long long c = max(a, b);
    long long d = min(a, b);
    while (true) {
      if (c % d == 0) {
        gcd = d;
        goto C;
      } else {
        c -= d;
        swap(c, d);
      }
    }
  C:
    cout << gcd << ' ' << a * b / gcd << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long a, b;
  while (cin >> a >> b) {
    long long gcd;
    long long c = max(a, b);
    long long d = min(a, b);
    while (true) {
      if (c % d == 0) {
        gcd = d;
        goto C;
      } else {
        c -= d;
        if (c <= d) {
          swap(c, d);
        }
      }
    }
  C:
    cout << gcd << ' ' << a * b / gcd << endl;
  }
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int a, b, i;
  while (cin >> a >> b) {
    for (i = a; i > 0; i--) {
      if (b % i == 0 && a % i == 0) {
        cout << i << " ";
        break;
      }
      // if (i == 0)
      // cout << 1 << " ";
    }
    if (a > b)
      i = a;
    else
      i = b;
    if (a > b) {
      for (i = a; i % b; i += a)
        ;
      cout << i << endl;
    } else {
      for (i = b; i % a; i += b)
        ;
      cout << i << endl;
    }
  }
  return 0;
}


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

int main() {
  int a, b, i;
  while (cin >> a >> b) {
    if (a > b)
      i = b;
    else
      i = a;
    for (; i > 0; i--) {
      if (b % i == 0 && a % i == 0) {
        cout << i << " ";
        break;
      }
      // if (i == 0)
      // cout << 1 << " ";
    }
    if (a > b)
      i = a;
    else
      i = b;
    if (a > b) {
      for (i = a; i % b; i += a)
        ;
      cout << i << endl;
    } else {
      for (i = b; i % a; i += b)
        ;
      cout << i << endl;
    }
  }
  return 0;
}
Problem p00005 (C++)

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

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

int main() {
  long a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << a / gcd(a, b) * b << endl;
  }
}

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

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

int main() {
  long a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << a / gcd(a, b) * b << endl;
  }
}
Problem p00005 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  int a, b, fl;
  while (cin >> a >> b) {
    fl = 0;
    for (int i = 1; fl == 0; i++) {
      if (a % i == 0 && b % (a / i) == 0) {
        cout << a / i << " ";
        fl++;
      } else
        ;
    }
    fl = 0;
    for (int i = 1; fl == 0; i++) {
      if (b % (a * i) == 0) {
        cout << a * i << endl;
        fl++;
      } else
        ;
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  int a, b, fl;
  while (cin >> a >> b) {
    fl = 0;
    for (int i = 1; fl == 0; i++) {
      if (a % i == 0 && b % (a / i) == 0) {
        cout << a / i << " ";
        fl++;
      } else
        ;
    }
    fl = 0;
    for (int i = 1; fl == 0; i++) {
      if ((a * i) % b == 0) {
        cout << a * i << endl;
        fl++;
      } else
        ;
    }
  }
  return 0;
}
Problem p00005 (C++)

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

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

void solve(long a, long b) {
  int c = gcd(a, b);
  cout << c << " " << a / c * b << endl;
}

int main() {
  long a, b;
  while (cin >> a >> b)
    solve(a, b);
}

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

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

void solve(long a, long b) {
  int c = gcd(a, b);
  cout << c << " " << a / c * b << endl;
}

int main() {
  long a, b;
  while (cin >> a >> b)
    solve(a, b);
}
Problem p00005 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a, b, r, G, R, L, tmp;
  while (cin >> a >> b) {
    R = a;
    L = b;
    if (b > a) {
      a = tmp;
      a = b;
      b = tmp;
    }
    while (1) {
      r = a % b;
      if (r == 0)
        break;
      a = b;
      b = r;
    }
    G = b;
    R = R / G;
    L = L / G;
    cout << G << " " << R * L * G << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, r, G, R, L, tmp;
  while (cin >> a >> b) {
    R = a;
    L = b;
    if (b > a) {
      tmp = a;
      a = b;
      b = tmp;
    }
    while (1) {
      r = a % b;
      if (r == 0)
        break;
      a = b;
      b = r;
    }
    G = b;
    R = R / G;
    L = L / G;
    cout << G << " " << R * L * G << endl;
  }
}
Problem p00005 (C++)

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

using namespace std;

int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; }

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

int main() {
  int a, b;
  while (cin >> a >> b, a, b) {
    cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
  }
}

Fixed submission:
#include <iostream>

using namespace std;

int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; }

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

int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
  }
}
Problem p00005 (C++)

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

#define CASE double

using namespace std;

int GCD(CASE x, CASE y) {
  if (x == 0 || y == 0)
    return x + y;
  else {
    if (x >= y) {
      x = x - y;
      GCD(x, y);
    } else {
      y = y - x;
      GCD(x, y);
    }
  }
}

int main() {
  CASE a, b;
  unsigned long int d, l;
  while (1) {
    cin >> a;
    cin >> b;
    d = (unsigned long int)GCD(a, b);
    l = a * b / d;
    cout << d << " " << l << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

#define CASE double

using namespace std;

int GCD(CASE x, CASE y) {
  if (x == 0 || y == 0)
    return x + y;
  else {
    if (x >= y) {
      x = x - y;
      GCD(x, y);
    } else {
      y = y - x;
      GCD(x, y);
    }
  }
}

int main() {
  CASE a, b;
  unsigned long int d, l;
  while (cin >> a >> b) {

    d = (unsigned long int)GCD(a, b);
    l = a * b / d;
    cout << d << " " << l << endl;
  }
  return 0;
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;

long long a, b;

long long gcd(long long x, long long y) {
  if (b == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }

int main() {
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}

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

long long a, b;

long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }

int main() {
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}
Problem p00005 (C++)

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

using namespace std;

int gcdr(int a, int b) {
  if (b == 0)
    return a;
  return gcdr(b, a % b);
}

int main() {
  int a, b, gcd;
  long int lcm;
  while (true) {
    scanf("%d%d", &a, &b);
    gcd = gcdr(a, b);
    // printf("%d\n",gcd);
    lcm = (long)a * b / gcd;
    printf("%d %ld\n", gcd, lcm);
  }

  return 0;
}


Fixed submission:
#include <cstdio>

using namespace std;

int gcdr(int a, int b) {
  if (b == 0)
    return a;
  return gcdr(b, a % b);
}

int main() {
  int a, b, gcd;
  long int lcm;
  while (scanf("%d%d", &a, &b) != EOF) {
    gcd = gcdr(a, b);
    // printf("%d\n",gcd);
    lcm = (long)a * b / gcd;
    printf("%d %ld\n", gcd, lcm);
  }

  return 0;
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int p, q;
  int a, b, c;
  int lcm, gcd;

  while (1) {
    cin >> p >> q;
    if (cin.eof())
      break;
    if (p > q) {
      a = p;
      b = q;
    } else {
      b = p;
      a = q;
    }

    while (a % b) {
      c = a - b;
      a = b;
      b = c;
    }
    lcm = b;
    gcd = p / lcm * q;
    cout << lcm << " " << gcd << endl;
  }
  return 0;
}

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

int main() {
  int p, q;
  int a, b, c;
  int lcm, gcd;

  while (1) {
    cin >> p >> q;
    if (cin.eof())
      break;
    if (p > q) {
      a = p;
      b = q;
    } else {
      b = p;
      a = q;
    }

    while (a % b) {
      c = a % b;
      a = b;
      b = c;
    }
    lcm = b;
    gcd = p / lcm * q;
    cout << lcm << " " << gcd << endl;
  }
  return 0;
}
Problem p00005 (C++)

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

int main() {
  unsigned long a, b;

  while (scanf("%lu %lu", &a, &b)) {
    unsigned long max = (a > b) ? a : b, min = (a < b) ? a : b;
    while (min) {
      int r = max % min;
      max = min;
      min = r;
    }
    unsigned long lcm = a * b / max;
    printf("%lu %lu\n", max, lcm);
  }

  return 0;
}

Fixed submission:
#include <cstdio>

int main() {
  unsigned long a, b;

  while (scanf("%lu %lu", &a, &b) != EOF) {
    unsigned long max = (a > b) ? a : b, min = (a < b) ? a : b;
    while (min) {
      int r = max % min;
      max = min;
      min = r;
    }
    unsigned long lcm = a * b / max;
    printf("%lu %lu\n", max, lcm);
  }

  return 0;
}
Problem p00005 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
int main() {
  int a, b;
  while (scanf("%d%d", &a, &b))
    printf("%d %d\n", std::__gcd(a, b), std::__gcd(a, b) * b);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
int main() {
  int a, b;
  while (2 == scanf("%d%d", &a, &b))
    printf("%d %d\n", std::__gcd(a, b), a / std::__gcd(a, b) * b);
  return 0;
}
Problem p00006 (C++)

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

using namespace std;

int main() {
  string str;
  cin >> str;
  int i = 0, j = str.size() - 1;
  while (i < j) {
    char tmp;
    tmp = str[i];
    str[i] = str[j];
    str[j] = tmp;
  }
  cout << str << endl;
  return 0;
}

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

using namespace std;

int main() {
  string str;
  cin >> str;
  int i = 0, j = str.size() - 1;
  while (i < j) {
    char tmp;
    tmp = str[i];
    str[i] = str[j];
    str[j] = tmp;
    ++i;
    --j;
  }
  cout << str << endl;
  return 0;
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

constexpr int INF = 1000000000; /* 1e+9a */
constexpr int MODULO = 1000000007;

#define int long

#define REP(i, f, n) for (int i = (f); i < (n); ++i)
#define PER(i, f, n) for (int i = (n - 1); i >= f; --i)

constexpr int evx[4] = {1, 0, -1, 0};
constexpr int evy[4] = {0, 1, 0, -1};

//----------------------------------
//----------------------------------

signed main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  PER(i, s.size(), 0)
  cout << s[i];
  cout << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

constexpr int INF = 1000000000; /* 1e+9a */
constexpr int MODULO = 1000000007;

#define int long

#define REP(i, f, n) for (int i = (f); i < (n); ++i)
#define PER(i, f, n) for (int i = (n - 1); i >= f; --i)

constexpr int evx[4] = {1, 0, -1, 0};
constexpr int evy[4] = {0, 1, 0, -1};

//----------------------------------
//----------------------------------

signed main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  PER(i, 0, s.size())
  cout << s[i];
  cout << endl;
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  char str[20];
  int i, j;
  scanf("%s", str);

  for (i = 0; str[i] != '\0'; i++) {
  }

  for (j = i - 1; j > -1; j--) {
    printf("%c", str[j]);
  }

  puts("");

  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  char str[21];
  int i, j;
  scanf("%s", str);

  for (i = 0; str[i] != '\0'; i++) {
  }

  for (j = i - 1; j > -1; j--) {
    printf("%c", str[j]);
  }

  puts("");

  return 0;
}
Problem p00006 (C++)

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

using namespace std;

int main() {
  string str;
  cin >> str;

  for (int i = str.size() - 1; i >= 0; i++) {
    cout << str[i];
  }
  cout << endl;
  return 0;
}

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

using namespace std;

int main() {
  string str;
  cin >> str;

  for (int i = str.size() - 1; i >= 0; i--) {
    cout << str[i];
  }
  cout << endl;
  return 0;
}
Problem p00006 (Python)

Buggy submission (status: Runtime Error):
print(input[::-1])


Fixed submission:
print(input()[::-1])
Problem p00006 (C++)

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

int main(void) {
  char str[20];
  scanf("%s", str);
  for (int i = strlen(str) - 1; i > 0; i--)
    printf("%s", str[i - 1]);
  printf("\n");
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>

int main(void) {
  char str[20];
  scanf("%s", str);
  for (int i = strlen(str) - 1; i >= 0; i--) {
    printf("%c", str[i]);
  }
  printf("\n");
  return 0;
}
Problem p00006 (C++)

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

int main() {
  string str;
  cin >> str;
  for (size_t i = str.size() - 1; i >= 0; --i) {
    cout << str[i];
  }
  cout << endl;
  return 0;
}

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

int main() {
  string str;
  cin >> str;
  for (size_t i = str.size() - 1; i >= 0; --i) {
    if (i == -1)
      break;
    cout << str[i];
  }
  cout << endl;
  return 0;
}
Problem p00006 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

int main(void);
std::string rev_string(std::string str);

int main() {
  std::string str = "";
  // char str[20];
  std::cin >> str;
  std::cout << rev_string(str) << std::endl;

  while (1)
    ;
  return 0;
}

//*
std::string rev_string(std::string str) {
  int i;
  int len = str.length();
  for (i = 0; i < len / 2; i++) {
    char temp = str[i];
    str[i] = str[len - i - 1];
    str[len - i - 1] = temp;
  }

  return str;
}
//*/


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

int main(void);
std::string rev_string(std::string str);

int main() {
  std::string str = "";
  // char str[20];
  std::cin >> str;
  std::cout << rev_string(str) << std::endl;

  // while (1);
  return 0;
}

//*
std::string rev_string(std::string str) {
  int i;
  int len = str.length();
  for (i = 0; i < len / 2; i++) {
    char temp = str[i];
    str[i] = str[len - i - 1];
    str[len - i - 1] = temp;
  }

  return str;
}
//*/
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char in[20], out[20];
  cin >> in;
  int len = strlen(in);
  for (int i = 0; i < len; i++) {
    out[len - i - 1] = in[i];
  }
  out[len] = 0;
  cout << out << endl;
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char in[21], out[21];
  cin >> in;
  int len = strlen(in);
  for (int i = 0; i < len; i++) {
    out[len - i - 1] = in[i];
  }
  out[len] = 0;
  cout << out << endl;
  return 0;
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  string S;
  cin >> S;
  for (int i = S.size();; i--)
    cout << S[i];
  cout << endl;

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  string S;
  cin >> S;
  for (int i = S.size(); i--;)
    cout << S[i];
  cout << endl;

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  char str[20];
  scanf("%s", str);
  int len = strlen(str);
  for (int i = len - 1; i >= 0; i--) {
    printf("%c", str[i]);
  }
  printf("\n");
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  char str[21];
  scanf("%s", str);
  int len = strlen(str);
  for (int i = len - 1; i >= 0; i--) {
    printf("%c", str[i]);
  }
  printf("\n");
  return 0;
}
Problem p00006 (C++)

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

int main(void) {
  string str;
  cin >> str;
  int l = str.size();
  for (int i = l; i >= 0; i++) {
    cout << str[i];
  }
  cout << endl;
  return 0;
}

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

int main(void) {
  string str;
  cin >> str;
  int l = str.size();
  for (int i = l; i > 0; i--) {
    cout << str[i - 1];
  }
  cout << endl;
  return 0;
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main() {
  string x;
  int i;
  cin >> x;
  for (i = x.size();; i--) {
    cout << x[i];
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main() {
  string x;
  int i;
  cin >> x;
  for (i = x.size(); i--;) {
    cout << x[i];
  }
  cout << endl;
  return 0;
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  string str;
  cin >> str;
  int n = str.size();
  for (int i = n - 1; i >= 0; i++) {
    cout << str[i];
  }
  cout << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  string str;
  cin >> str;
  int n = str.size();
  for (int i = n - 1; i >= 0; i--) {
    cout << str[i];
  }
  cout << endl;
}
Problem p00006 (C++)

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

int main(void) {
  char str[20], reversed_str[20];
  scanf("%s", str);
  int len = strlen(str);

  int i;
  for (i = 0; i < len; ++i) {
    reversed_str[i] = str[len - 1 - i];
  }
  reversed_str[len] = '\0';

  printf("%s\n", reversed_str);

  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>

int main(void) {
  char str[21], reversed_str[21];
  scanf("%s", str);
  int len = strlen(str);

  int i;
  for (i = 0; i < len; ++i) {
    reversed_str[i] = str[len - 1 - i];
  }
  reversed_str[len] = '\0';

  printf("%s\n", reversed_str);

  return 0;
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
string s;
int main() {
  cin >> s;
  for (unsigned i = s.size() - 1; i >= 0; i--)
    cout << s[i];
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
string s;
int main() {
  cin >> s;
  for (string::reverse_iterator it = s.rbegin(); it != s.rend(); it++)
    cout << *it;
  cout << endl;
  return 0;
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int n = 0;
  char a[1000];
  for (int i = 0; i < 1000; i++)
    a[i] = '\0';
  scanf("%s", a);
  while (a[n] != '\0')
    n++;
  for (int i = n - 1; i >= 0; i++)
    printf("%c", a[i]);
  printf("\n");
}

Fixed submission:
#include <stdio.h>
int main() {
  int n = 0;
  char a[1000];
  for (int i = 0; i < 1000; i++)
    a[i] = '\0';
  scanf("%s", a);
  while (a[n] != '\0')
    n++;
  for (int i = n - 1; i >= 0; i--)
    printf("%c", a[i]);
  printf("\n");
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  char a;
  string str;
  cin >> str;
  for (int i = 0; i != str.size() - 1 - i; i++) {
    a = str[i];
    str[i] = str[str.size() - 1 - i];
    str[str.size() - 1 - i] = a;
  }
  cout << str << endl;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  char a;
  string str;
  cin >> str;
  for (int i = 0; i < str.size() - 1 - i; i++) {
    a = str[i];
    str[i] = str[str.size() - 1 - i];
    str[str.size() - 1 - i] = a;
  }
  cout << str << endl;
}
Problem p00006 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.size() <= 20) {
    for (int i = s.size();; i--) {
      cout << s[i];
    }
    cout << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.size() <= 20) {
    for (int i = s.size(); i--;) {
      cout << s[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00006 (C++)

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

int main() {

  string s;

  cin >> s;

  for (int i = s.size() - 1; i >= 0; ++i)
    cout << s[i];

  cout << endl;
}


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

int main() {

  string s;

  cin >> s;

  for (int i = s.size() - 1; i >= 0; --i)
    cout << s[i];

  cout << endl;
}
Problem p00006 (C++)

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

using namespace std;

int main() {
  string str;
  cin >> str;
  for (int i = str.size() - 1; i >= 0; i++)
    cout << str[i];
  cout << endl;
  return 0;
}

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

using namespace std;

int main() {
  string str;
  cin >> str;
  for (int i = str.size() - 1; i >= 0; i--)
    cout << str[i];
  cout << endl;
  return 0;
}
Problem p00007 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int n;

  while (1) {
    int m = 100000;
    while (n--) {
      m = ceil(m * 1.05 / 1000) * 1000;
    }
    cout << m << endl;
  }
  return 0;
}

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

int main() {
  int n;

  while (cin >> n) {
    int m = 100000;
    while (n--) {
      m = ceil(m * 1.05 / 1000) * 1000;
    }
    cout << m << endl;
  }
  return 0;
}
Problem p00007 (C++)

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

using namespace std;

int main() {
  int n, debt = 100000;
  cin >> n;
  while (n--) {
    debt = debt * 1.05;
    debt += 999;
    debt /= 1000;
    debt *= 1000;
  }
  cout << debt << endl;
  while (1)
    ;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n, debt = 100000;
  cin >> n;
  while (n--) {
    debt = debt * 1.05;
    debt += 999;
    debt /= 1000;
    debt *= 1000;
  }
  cout << debt << endl;
  return 0;
}
Problem p00007 (Python)

Buggy submission (status: Runtime Error):
import math

r = 100
n = input()
for i in range(n):
    r = math.ceil(r * 1.05)
print(r * 1000)


Fixed submission:
import math

r = 100
n = int(input())
for i in range(n):
    r = math.ceil(r * 1.05)
print(r * 1000)
Problem p00008 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int co = 0;
    rep(a, 10) {
      rep(b, 10) {
        rep(c, 10) {
          if (n - a - b - c >= 0 && n - a - b - c < 10)
            co++;
        }
      }
    }
    cout << co << endl;
  }
}

Fixed submission:
#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int co = 0;
    rep(a, 10) {
      rep(b, 10) {
        rep(c, 10) {
          if (n - a - b - c >= 0 && n - a - b - c < 10)
            co++;
        }
      }
    }
    cout << co << endl;
  }
}
Problem p00008 (C++)

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

using namespace std;

int main(void) {
  int val;
  while (cin >> val)
    cerr << val << endl;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  int n, a[4], count;

  while (cin >> n) {
    count = 0;
    for (a[0] = 0; a[0] < 10; a[0]++)
      for (a[1] = 0; a[1] < 10; a[1]++)
        for (a[2] = 0; a[2] < 10; a[2]++)
          for (a[3] = 0; a[3] < 10; a[3]++)
            if (a[0] + a[1] + a[2] + a[3] == n) {
              count++;
              break;
            }
    cout << count << endl;
  }

  return 0;
}
Problem p00008 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define rep(i, a) for (int i = 0; i < a; ++i)

using namespace std;

int main(void) {
  int n;
  int a[4];
  while (cin >> n, n) {
    int count = 0;
    rep(i, 10) {
      rep(j, 10) {
        rep(c, 10) {
          rep(d, 10) {
            if (i + j + c + d == n)
              ++count;
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#define rep(i, a) for (int i = 0; i < a; ++i)

using namespace std;

int main(void) {
  int n;
  while (cin >> n) {
    int a[4] = {};
    int count = 0;
    rep(i, 10) {
      rep(j, 10) {
        rep(c, 10) {
          rep(d, 10) {
            if (i + j + c + d == n)
              ++count;
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00008 (C++)

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

using namespace std;
int countSolve(int a, int b, int n);
void solve(int n);

int main() {
  int n;
  while (1) {
    cin >> n;
    solve(n);
  }
  return 0;
}

int countSolve(int a, int b, int n) {
  int x = n - a - b;
  int count = 0, i = 0, j = 0;
  for (i = 0; i < 10; i++) {
    for (j = 0; j < 10; j++) {
      if (x == i + j)
        count++;
    }
  }
  return count;
}

void solve(int n) {
  int count = 0;
  for (int a = 0; a < 10; a++) {
    for (int b = 0; b < 10; b++) {
      count += countSolve(a, b, n);
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <iostream>

using namespace std;
int countSolve(int a, int b, int n);
void solve(int n);

int main() {
  int n;
  while (1) {
    cin >> n;
    if (cin.eof())
      break;
    solve(n);
  }
  return 0;
}

int countSolve(int a, int b, int n) {
  int x = n - a - b;
  int count = 0, i = 0, j = 0;
  for (i = 0; i < 10; i++) {
    for (j = 0; j < 10; j++) {
      if (x == i + j)
        count++;
    }
  }
  return count;
}

void solve(int n) {
  int count = 0;
  for (int a = 0; a < 10; a++) {
    for (int b = 0; b < 10; b++) {
      count += countSolve(a, b, n);
    }
  }
  cout << count << endl;
}
Problem p00008 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int combination(int n) {
  int temp = 0;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k < 10; k++)
        if ((n - i - j - k) >= 0 && (n - i - j - k) < 10)
          temp++;
  return temp;
}

int main() {
  int n;
  while (1) {
    cin >> n;
    cout << combination(n) << endl;
  }
}

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

int combination(int n) {
  int temp = 0;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k < 10; k++)
        if ((n - i - j - k) >= 0 && (n - i - j - k) < 10)
          temp++;
  return temp;
}

int main() {
  int n;
  while (cin >> n) {
    cout << combination(n) << endl;
  }
}
Problem p00008 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
// #include<cmath>
// #include<iostream>
using namespace std;

int main() {
  int n, i, a, b, c, d;

  while (scanf("%d", &n)) {

    for (i = 0, a = 0; a < 10; a++) {
      for (b = 0; b < 10; b++) {
        for (c = 0; c < 10; c++) {
          for (d = 0; d < 10; d++) {
            if (a + b + c + d == n)
              i++;
          }
        }
      }
    }

    printf("%d\n", i);
  }
  return 0;
}

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

int main() {
  int n, i, a, b, c, d;

  while (~scanf("%d", &n)) {

    for (i = 0, a = 0; a < 10; a++) {
      for (b = 0; b < 10; b++) {
        for (c = 0; c < 10; c++) {
          for (d = 0; d < 10; d++) {
            if (a + b + c + d == n)
              i++;
          }
        }
      }
    }

    printf("%d\n", i);
  }
  return 0;
}
Problem p00008 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int cnt = 0;
    for (int i = 0; i = 10; i++) {
      for (int j = 0; j = 10; j++) {
        for (int k = 0; k = 10; k++) {
          if (0 <= n - i - j - k && n - i - j - k < 10)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int cnt = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          if (0 <= n - i - j - k && n - i - j - k < 10)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}
Problem p00008 (C++)

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

using namespace std;

int main(void) {
  int n = 0;
  while (true) {
    n = 0;
    cin >> n;

    int num = 0;
    for (int a = 0; a < 10; a++) {
      for (int b = 0; b < 10; b++) {
        for (int c = 0; c < 10; c++) {
          for (int d = 0; d < 10; d++) {
            if (a + b + c + d == n)
              num++;
          }
        }
      }
    }

    cout << num << '\n';
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  int n, i = 0;
  while (cin >> n) {
    int num = 0;
    for (int a = 0; a < 10; a++) {
      for (int b = 0; b < 10; b++) {
        for (int c = 0; c < 10; c++) {
          for (int d = 0; d < 10; d++) {
            if (a + b + c + d == n)
              num++;
          }
        }
      }
    }

    cout << num << '\n';
  }

  return 0;
}
Problem p00008 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int n, count;
  while (cin >> n, n) {
    count = 0;
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        for (int k = 0; k < 10; k++)
          for (int l = 0; l < 10; l++)
            if (i + j + k + l == n)
              count++;
    cout << count << endl;
  }
  return 0;
}

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

int main() {
  int n, count;
  while (cin >> n && n) {
    count = 0;
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        for (int k = 0; k < 10; k++)
          for (int l = 0; l < 10; l++)
            if (i + j + k + l == n)
              count++;
    cout << count << endl;
  }
  return 0;
}
Problem p00008 (C++)

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

int main() {
  int n;

  while (std::cin >> n) {
    int count = 0;
    for (int a = 0; a < 10; ++a) {
      for (int b = 0; a < 10; ++b) {
        for (int c = 0; a < 10; ++c) {
          for (int d = 0; a < 10; ++d) {
            if (a + b + c + d == n) {
              ++count;
            }
          }
        }
      }
    }
    std::cout << count << std::endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

int main() {
  int n;

  while (std::cin >> n) {
    int count = 0;
    for (int a = 0; a < 10; ++a) {
      for (int b = 0; b < 10; ++b) {
        for (int c = 0; c < 10; ++c) {
          for (int d = 0; d < 10; ++d) {
            if (a + b + c + d == n) {
              ++count;
            }
          }
        }
      }
    }
    std::cout << count << std::endl;
  }

  return 0;
}
Problem p00008 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <string.h>
int main(void) {
  int n, count = 0;
  while (1) {
    scanf("%d", &n);
    if (n == EOF)
      break;
    for (size_t a = 0; a <= 9; a++) {
      for (size_t b = 0; b <= 9; b++) {
        for (size_t c = 0; c <= 9; c++) {
          for (size_t d = 0; d <= 9; d++) {
            if (a + b + c + d == n) {
              count++;
            }
          }
        }
      }
    }
    printf("%d\n", count);
    count = 0;
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>
int main(void) {
  int n, count = 0;
  while (scanf("%d", &n) != EOF) {
    for (size_t a = 0; a <= 9; a++) {
      for (size_t b = 0; b <= 9; b++) {
        for (size_t c = 0; c <= 9; c++) {
          for (size_t d = 0; d <= 9; d++) {
            if (a + b + c + d == n) {
              count++;
            }
          }
        }
      }
    }
    printf("%d\n", count);
    count = 0;
  }
  return 0;
}
Problem p00008 (C++)

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

using namespace std;

int main() {
  int a = 0, b = 0, c = 0, d = 0, e = 0, n, count;
  while (1) {
    cin >> n;
    do {
      if ((a + b + c + d) == n) {
        count++;
      }
      if (a == 9 && b == 9 && c == 9 && d == 9) {
        e = 1;
      }

      else if (b == 9 && c == 9 && d == 9) {
        a++;
        b = 0, c = 0, d = 0;
      } else if (c == 9 && d == 9) {
        b++;
        c = 0, d = 0;
      } else if (d == 9) {
        c++;
        d = 0;
      } else {
        d++;
      }

    } while (e == 0);
    cout << count << endl;
    count = 0, a = 0, b = 0, c = 0, d = 0, e = 0;
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int a = 0, b = 0, c = 0, d = 0, e = 0, n, count;
  for (int i = 1; i <= 50; i++) {
    cin >> n;
    do {
      if ((a + b + c + d) == n) {
        count++;
      }
      if (a == 9 && b == 9 && c == 9 && d == 9) {
        e = 1;
      }

      else if (b == 9 && c == 9 && d == 9) {
        a++;
        b = 0, c = 0, d = 0;
      } else if (c == 9 && d == 9) {
        b++;
        c = 0, d = 0;
      } else if (d == 9) {
        c++;
        d = 0;
      } else {
        d++;
      }

    } while (e == 0);
    cout << count << endl;
    count = 0, a = 0, b = 0, c = 0, d = 0, e = 0;
  }
  return 0;
}
Problem p00008 (C++)

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

using namespace std;

#define llong long long
int n;
int ans;
bool memo[1001];

void solve(int num, int sum, int d) {
  if (d == 4) {
    if (sum == num) {
      ans++;
    }
    return;
  }

  if (num < sum)
    return;

  for (int i = 0; i <= 9; i++) {
    solve(num, sum + i, d + 1);
  }
  return;
}

int main() {
  while (cin >> n, n != EOF) {
    ans = 0;
    solve(n, 0, 0);
    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

#define llong long long
int n;
int ans;
bool memo[1001];

void solve(int num, int sum, int d) {
  if (d == 4) {
    if (sum == num) {
      ans++;
    }
    return;
  }

  if (num < sum)
    return;

  for (int i = 0; i <= 9; i++) {
    solve(num, sum + i, d + 1);
  }
  return;
}

int main() {
  while (cin >> n) {
    ans = 0;
    solve(n, 0, 0);
    cout << ans << endl;
  }

  return 0;
}