alexjercan/bugnet huggingface dataset:
Problem p00005 (C++) — buggy submission, verdict: 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 ((a * i) % b == 0) {
        cout << a * i << endl;
        fl++;
      } else
        ;
    }
  }
  return 0;
}


Error: TLE

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 (b % (a * i) == 0) {
        cout << a * i << endl;
        fl++;
      } else
        ;
    }
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  long int a, b, lcm = 0, r, x, y, count = 0;
  while (cin >> a >> b) {
    count++;
    if (count == 50)
      break;
    x = a;
    y = b;
    while (1) {
      r = a % b;
      a = b;
      b = r;
      if (r == 0)
        break;
    }
    lcm = a;
    cout << lcm << " " << x * y / lcm << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, lcm = 0, count = 0;
  while (cin >> a >> b) {
    for (int k = a; k >= 1; k--) {
      if (a % k == 0 && b % k == 0) {
        lcm = k;
        break;
      }
    }
    cout << lcm << " " << a * b / lcm << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

int gcd(int a, int b) {
  if (b > a) {
    int j = a;
    a = b;
    b = j;
  }
  int r;
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}

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


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int gcd(int a, int b) {
  int i;
  if (b > a) {
    int j = a;
    a = b;
    b = j;
  }
  for (i = a; i >= 1; i--) {
    if (a % i == 0)
      if (b % i == 0)
        break;
  }
  return i;
}

int main(void) {
  int a, b;
  while (cin >> a >> b) {
    int lcm = a / gcd(a, b) * b;
    cout << gcd(a, b) << " " << lcm << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

#define MAX(x, y) ((x > y) ? x : y)
#define MIN(x, y) ((x > y) ? y : x)
int main(void) {
  while (true) {
    int x = 0, y = 0;
    double product;
    std::cin >> x >> y;
    if (std::cin.eof())
      break;
    product = (double)x * y;
    // ユークリッドの何とか
    while (x && y) {
      if (x > y)
        x = x % y;
      else
        y = y % x;
    }
    std::cout << (int)MAX(x, y) << " " << (int)(product / MAX(x, y))
              << std::endl; // 確かGCD*LCMと元の積は等しいはず。
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>

#define MAX(x, y) ((x > y) ? x : y)
#define MIN(x, y) ((x > y) ? y : x)
int main(void) {
  while (true) {
    int x = 0, y = 0, product;
    std::cin >> x >> y;
    if (std::cin.eof())
      break;
    product = x * y;
    // ユークリッドの何とか
    while (x && y) {
      if (x > y)
        x = x % y;
      else
        y = y % x;
    }
    std::cout << (int)x << " " << (int)(product / x)
              << std::endl; // 確かGCD*LCMと元の積は等しいはず。
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int a, b, big, small, r;

  while (1) {
    cin >> a >> b;
    if (cin.eof()) {
      break;
    }

    if (a > b) {
      big = a;
      small = b;
    } else {
      big = b;
      small = a;
    }

    r = big % small;
    while (r != 0) {
      big = small;
      small = r;
      r = big % small;
    }

    cout << small << ' ' << (a / small) * (b / small) * small << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
  int a, b, r, i, small, big, x;

  while (scanf("%d %d", &a, &b) != EOF) {
    if (a > b) {
      small = b;
      big = a;
    } else {
      small = a;
      big = b;
    }

    //?????§??¬?´???°
    r = big % small;
    while (1) {
      x = small % r;
      if (x == 0) {
        printf("%d ", r);
        break;
      }
      r = x;
      small = r;
    }
    //????°???¬?????°
    r = big % small;
    while (r != 0) {
      big = small;
      small = r;
      r = big % small;
    }

    printf("%d\\n", (a * b) / small);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  long a, b, m, n, tmp;

  while (cin >> a >> b) {
    if (a >= b) {
      m = a;
      n = b;
    } else {
      m = b;
      n = a;
    }

    for (; n != 0;) {
      tmp = n;
      n = m % n;
      m = tmp;
    }

    cout << m << " " << a * b / m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  long a, b, tmp, i;

  while (cin >> a >> b) {
    if (a >= b)
      i = b;
    else
      i = a;

    for (; 0 != (a % i) + (b % i); i--)
      ;
    cout << i << " " << a * b / i << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  unsigned long long int a, b, tmp, m = 0, s = 0, ai, bi;
  while (cin >> a >> b) {
    ai = a;
    bi = b;
    while (1) {
      if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
      }
      if (a % b == 0) {
        m = b;
        break;
      } else
        a = a % b;
    }
    s = ai * bi / m;
    cout << m << " " << s << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, tmp, m = 0, s = 0, ai, bi;
  while (cin >> a >> b) {
    ai = a;
    bi = b;
    if (a < b) {
      tmp = a;
      a = b;
      b = tmp;
    }
    while (1) {
      if (a % b == 0) {
        m = b;
        break;
      } else {
        a = a - b;
        tmp = a;
        a = b;
        b = tmp;
      }
    }
    s = ai * bi / m;
    cout << m << " " << s << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <utility>

int main() {

  int a, b;

  while (std::cin >> a >> b) {

    int minmul;      // least common multiple
    int maxdivi = 1; // greatest common divisor
    int tmp_a = a;
    int tmp_b = b;

    if (a == 0 || b == 0) {
      std::cout << 0 << " " << 0 << std::endl;

    } else { // Euclidean Algorithm

      if (b > a)
        std::swap(a, b);

      while (a % b != 0) {
        a = a % b;
        if (b > a)
          std::swap(a, b);
      }

      maxdivi = b;
      minmul = (tmp_a / maxdivi) * tmp_b; // a*b/maxdivi

      std::cout << maxdivi << " " << minmul << std::endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {

  int a, b;

  while (std::cin >> a >> b) {

    long int minmul; // least common multiple
    int maxdivi = 1; // greatest common divisor
    int small;

    if (a > b)
      small = b;
    else
      small = a;

    for (int i = 2; i <= small; ++i) {
      if (a % i == 0 && b % i == 0) {
        maxdivi = maxdivi * i;
        i = 2;
      }
    }
    minmul = a * b / maxdivi;

    std::cout << maxdivi << " " << minmul << std::endl;
  }

  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long int a = 0;
  long long int b = 0;
  while (cin >> a, cin >> b) {
    long long int c = 0;
    long long int d = 0;
    long long int e = 0;
    c = a;
    d = b;
    if (c < d) {
      long long int i = 0;
      i = d;
      d = c;
      c = i;
    }
    while (1) {
      e = c % d;
      if (e == 0) {
        break;
      }
      c = d;
      d = e;
    }
    cout << d << " " << a / d * b << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int a, b, c = 1;
  while (cin >> a, cin >> b) {
    int w = a;
    int x = b;
    for (int i = 1; i <= a, i <= b; i++) {
      if (a % i == 0 && b % i == 0) {
        c = i * c;
        a = a / i;
        b = b / i;
        i = 1;
      }
    }
    cout << c << " " << w * x / c << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int lld;

const lld mod = 1e9 + 7;
const lld INF = 1e9;
// const lld MAXN = 1e9;

lld gcd(lld x, lld y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}

int main() {
  lld a, b;
  while (cin >> a >> b) {
    lld n = min(a, b);
    lld m = max(a, b);
    lld sol = gcd(m, n);
    cout << sol << " " << (n * m) / sol << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int lld;

const lld mod = 1e9 + 7;
const lld INF = 1e9;
// const lld MAXN = 1e9;

int main() {
  lld a, b;
  while (cin >> a >> b) {
    lld n = min(a, b);
    lld m = max(a, b);
    lld gcd = 1;
    for (int i = 1; i <= n; i++) {
      if (n % i == 0 && m % i == 0) {
        gcd = i;
      }
    }
    cout << gcd << endl;
    cout << n * m / gcd << endl;
  }

  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

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


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int a, int b) {
  int maxa[2000000000], maxb[2000000000], GCD, i, j;

  for (i = 2; i < a; i++) {
    if (a % i == 0) {
      a = a / i;
      for (j = 0; j < a; j++)
        maxa[j] = i;
    }
  }
  for (i = 2; i < b; i++) {
    if (b % i == 0) {
      b = b / i;
      for (j = 0; j < b; j++)
        maxb[j] = i;
    }
  }
  for (j = 0; j < a || j < b; j++) {
    if (maxa[j] == maxb[j])
      GCD = maxa[j];
  }

  return GCD;
}

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

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

#include <math.h>
#include <stdio.h>
int main() {
  long long int x, y;
  long long int i, j;
  while (scanf("%lld%lld", &i, &j), i) {
    x = i, y = j;
    while ((i != 0) && (j != 0)) {
      if (i > j) {
        i = i % j;
      } else {
        j = j % i;
      }
    }
    if (i == 0) {
      y = x * y / j;
      x = j;
    } else {
      y = x * y / i;
      x = i;
    }
    printf("%lld %lld\\n", x, y);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  long long int x, y;
  long long int i, j;
  while (scanf("%lld%lld", &i, &j), i) {
    x = i, y = j;

    while ((i == 0) && (j == 0)) {
      if (i > j) {
        i = i % j;
      } else {
        j = j % i;
      }
    }
    if (i == 0) {
      y = x * y / j;
      x = j;

    } else {
      y = x * y / i;
      x = i;
    }

    printf("%lld %lld\\n", x, y);
  }

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

#include <iostream>
using namespace std;

int GCD(int n, int m) {
  if (n % m == 0)
    return m;
  return GCD(m, n % m);
}

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

  int n[50] = {0};
  int i = 0;
  while (cin >> n[i++])
    ;
  int nn = i - 1;
  int gcd = 0, lcm = 0, a = 0, b = 0;
  for (int j = 0; j < nn; j += 2) {
    gcd = GCD(n[j], n[j + 1]);
    a = n[j] / gcd, b = n[j + 1] / gcd;
    cout << gcd << " " << gcd * a * b << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  int n[50] = {0};
  int i = 0;
  while (cin >> n[i++])
    ;
  int nn = i - 1;
  int gcd = 0, lcm = 0, a = 0, b = 0;
  for (int j = 0; j < nn; j += 2) {
    for (int k = 1; k < n[j]; k++) {
      if (n[j] % k + n[j + 1] % k == 0)
        gcd = k;
    }
    a = n[j] / gcd, b = n[j + 1] / gcd;
    cout << gcd << " " << gcd * a * b << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: 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;
        if (c <= d) {
          swap(c, d);
        }
      }
    }
  C:
    cout << gcd << ' ' << a * b / gcd << endl;
  }
}

Error: TLE

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;
        swap(c, d);
      }
    }
  C:
    cout << gcd << ' ' << a * b / gcd << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main() {
  long a, b;

  while (std::cin >> a >> b) {
    long gcd = 1;
    long lcm = 1;

    long min;
    long cnt = 2;

    do {
      while ((a % cnt == 0) && a % cnt == b % cnt) {
        a /= cnt;
        b /= cnt;
        gcd *= cnt;
      }
      min = (a < b) ? a : b;
      ++cnt;
    } while (min > cnt);

    lcm = gcd * a * b;
    std::cout << gcd << " " << lcm << std::endl;
  }
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>

int main() {
  long a, b;

  while (std::cin >> a >> b) {
    long gcd = 1;
    long lcm = 1;

    for (int cnt = (a < b ? a : b); cnt > 1; --cnt) {
      if ((a % cnt == 0) && a % cnt == b % cnt) {
        a /= cnt;
        b /= cnt;
        gcd *= cnt;
      }
    }
    lcm = gcd * a * b;
    std::cout << gcd << " " << lcm << std::endl;
  }
}
Problem p00007 (C++) — buggy submission, verdict: 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;
  return 0;
}

Error: TLE

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;
  while (1)
    ;
  return 0;
}
Problem p00007 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int i, n, b, c, d;
  cin >> n;
  b = 100000;
  for (i = 0; i < n; i++) {
    b = b * 1.05;
    c = b % 1000;
    d = b / 1000;
    if (c != 0) {
      b = (d + 1) * 1000;
    }
  }
  cout << b << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  while (1) {
    string moji;
    string mojihi;
    string mojimi;
    cin >> moji;
    int l;
    l = moji.size();
    if (moji == "-") {
      break;
    }
    int a, i;
    cin >> a;
    for (i = 0; i < a; i++) {
      int b;
      cin >> b;
      mojihi = moji.substr(0, b);
      mojimi = moji.substr(b, l - b);
      moji = mojimi + mojihi;
    }
    cout << moji << endl;
  }
  return 0;
}
Problem p00007 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, n, x, sum = 0, i;
  for (i = 0; i < 50; i++) {
    cin >> x;
    for (a = 0; a <= 9; a++) {
      for (b = 0; b <= 9; b++) {
        for (c = 0; c <= 9; c++) {
          for (d = 0; d <= 9; d++) {
            n = a + b + c + d;
            if (x == n) {
              sum++;
            }
          }
        }
      }
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, n, x, sum = 0;
  for (;;) {
    cin >> x;
    for (a = 0; a <= 9; a++) {
      for (b = 0; b <= 9; b++) {
        for (c = 0; c <= 9; c++) {
          for (d = 0; d <= 9; d++) {
            n = a + b + c + d;
            if (x == n) {
              sum++;
            }
          }
        }
      }
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}
Problem p00008 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long n, a, b, c, d, count;
  while (cin >> n) {
    count = 0;
    for (a = 0; a <= 9; a++) {
      for (b = 0; b <= 9; b++) {
        for (c = 0; c <= 9; c++) {
          for (d = 0; d <= 9; d++) {
            if (a + b + c + d == n)
              count++;
          }
        }
      }
    }
    cout << count << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define mid (l + r >> 1)
#define lc (o << 1)
#define rc (o << 1 | 1)
using namespace std;
const int maxn = 1000010;

int sumv[maxn * 4], st[maxn * 4], ql, qr, v, _sum;
int n, ans[100], top;

void insert1(int o, int l, int r) {
  if (ql <= l && r <= qr) {
    sumv[o] = st[o] = 1 << v;
    return;
  }
  if (st[o]) {
    st[lc] = st[rc] = st[o];
    sumv[lc] = sumv[rc] = st[o];
    st[o] = 0;
  }
  int m = mid;
  if (ql <= m)
    insert1(lc, l, m);
  if (qr > m)
    insert1(rc, m + 1, r);
  sumv[o] = sumv[lc] | sumv[rc];
  // printf("%d %d %d\\n", l, r, sumv[o]);
}

void query(int o, int l, int r) {
  if (st[o]) {
    _sum |= st[o];
    return;
  }
  if (ql <= l && r <= qr) {
    _sum |= sumv[o];
    return;
  }
  int m = mid;
  if (ql <= m)
    query(lc, l, m);
  if (qr > m)
    query(rc, m + 1, r);
}

int gao(int s) {
  int i = 0;
  top = 0;
  while (s) {
    i++;
    if (s & 1)
      ans[top++] = i;
    s >>= 1;
  }
}

int main() {
  // freopen("b.txt", "r", stdin);
  // freopen("bout", "w", stdout);
  int m;
  while (scanf("%d%d", &n, &m), n) {
    // printf("%d %d\\n", n, m);
    if (n == 0)
      break;
    memset(sumv, 0, sizeof sumv);
    memset(st, 0, sizeof st);
    char op[3];
    for (int i = 0; i < m; i++) {
      scanf("%s", op);
      if (op[0] == 'P') {
        scanf("%d%d%d", &ql, &qr, &v);
        v--;
        insert1(1, 1, n);
        // puts("");
      } else {
        scanf("%d%d", &ql, &qr);
        _sum = 0;
        query(1, 1, n);
        gao(_sum);
        for (int i = 0; i < top; i++) {
          printf("%d%c", ans[i], i == top - 1 ? '\\n' : ' ');
        }
      }
    }
  }
  return 0;
}
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int cnt = 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) {
              cnt++;
            }
          }

    cout << cnt << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
  while (1) {
    int n;
    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++)
          for (int l = 0; l < 10; l++) {
            if (i + j + k + l == n) {
              cnt++;
            }
          }

    cout << cnt << endl;
  }

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

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p00008 (C++) — buggy submission, verdict: 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) {
    ans = 0;
    solve(n, 0, 0);
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

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, n != EOF) {
    ans = 0;
    solve(n, 0, 0);
    cout << ans << endl;
  }

  return 0;
}