alexjercan/bugnet huggingface dataset:
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <sstream>

using namespace std;

int main() {
  string str = "";

  while (getline(cin, str)) {
    int n = 0;
    int res = 0;
    stringstream ss(str);
    ss >> n;

    for (int i = 0; i < 10000; ++i) {
      int a = i / 1000;
      int b = (i / 100) % 10;
      int c = (i / 10) % 10;
      int d = i % 10;

      if (a + b + c + d == n) {
        ++res;
      } // end if
    }   // end for
    cout << res << endl;
  } // end while

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  while (1) {
    int n;
    int res = 0;

    cin >> n;

    if (!n) {
      break;
    } // end if

    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) {
              ++res;
            } // end if
          }   // end for
        }     // end for
      }       // end for
    }         // end for
    cout << res << endl;

  } // end while

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

#include <iostream>
using namespace std;

int n;

int d[4][61];

int main(void) {

  for (int i = 0; i <= 9; i++)
    d[0][i]++;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9 * (i + 2); k++) {
        d[i + 1][k + j] += d[i][k];
      }
    }
  }

  while (cin >> n, !cin.eof()) {

    cout << d[3][n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n;

int d[4][61];

int main(void) {

  for (int i = 0; i <= 9; i++)
    d[0][i]++;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9 * (i + 2); k++) {
        d[i + 1][k + j] += d[i][k];
      }
    }
  }

  while (cin >> n, n) {

    cout << d[3][n] << endl;
  }

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

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

int n;

int slv(int now, int t);

int main() {

  while (scanf(" %d", &n) != EOF) {
    printf("%d\\n", slv(0, 0));
  }

  return 0;
}

int slv(int now, int t) {
  if (now == 4) {
    if (t == n)
      return 1;
    return 0;
  }

  int ans = 0;
  for (int i = 0; i < 10; i++) {
    ans += slv(now + 1, t + i);
  }

  return ans;
}

Error: TLE

Fixed submission:

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

int main() {
  char s[10];
  int n;
  int ans = 0;

  while (1) {
    scanf(" %s", s);
    if (s[0] == EOF)
      break;
    n = atoi(s);
    ans = 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)
              ans++;
          }
        }
      }
    }
    printf("%d\\n", ans);
  }

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

#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, n, num;

  while (cin >> n) {
    num = 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)
              num++;
          }
        }
      }
    }
    cout << num << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    int num = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; i++) {
        for (int k = 0; k < 10; i++) {
          for (int l = 0; l < 10; i++) {
            if (i + j + k + l == n)
              num++;
          }
        }
      }
    }
    cout << num << endl;
  }
}
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int num, cnt = 0;
  int i, j, k, l;

  while (scanf("%d", &num) != EOF) {
    for (i = 0; i < 10; i++) {
      for (j = 0; j < 10; j++) {
        for (k = 0; k < 10; k++) {
          for (l = 0; l < 10; l++) {
            if (i + j + k + l == num) {
              cnt++;
            }
          }
        }
      }
    }
    printf("%d\\n", cnt);
    cnt = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int num, cnt = 0;
  int i, j, k, l;

  while (scanf("%d", &num)) {
    for (i = 0; i < 10; i++) {
      for (j = 0; j < 10; j++) {
        for (k = 0; k < 10; k++) {
          for (l = 0; l < 10; l++) {
            if (i + j + k + l == num) {
              cnt++;
            }
          }
        }
      }
    }
    printf("%d\\n", cnt);
    cnt = 0;
  }

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

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

int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
        for (int k = 0; k <= 9; k++) {
          int x = n - i - j - k;
          //                    cout << i << ' ' << j << ' ' << k << ' ' << x <<
          //                    endl;
          if (x >= 0 && x < 10)
            ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, count;
  while (scanf("%d", &n)) {
    count = 0;
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
        for (int k = 0; k <= 9; k++) {
          int l = n - (i + j + k);
          if (l >= 0 && l <= 9)
            count++;
        }
      }
    }
    printf("%d\\n", count);
  }
  return 0;
}
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n, count;
  while (!feof(stdin)) {
    scanf("%d", &n);
    if (feof(stdin))
      break;
    count = 0;
    if (n == EOF)
      break;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          if (i + j + k >= n - 9 && i + j + k <= n)
            count++;
        }
      }
    }
    printf("%d\\n", count);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n, count;
  while (1) {
    count = 0;
    scanf("%d", &n);
    if (n == EOF)
      break;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          if (i + j + k >= n - 9 && i + j + k <= n)
            count++;
        }
      }
    }
    printf("%d\\n", count);
  }
}
Problem p00008 (C++) — buggy submission, verdict: 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;
  }
}

Error: TLE

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, verdict: 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 (cin >> n) {
    cout << combination(n) << endl;
  }
}

Error: TLE

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 (1) {
    cin >> n;
    cout << combination(n) << endl;
  }
}
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(void) {
  int n, i = 0;

  while (cin >> n, !cin.eof()) {
    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 (n == a + b + c + d) {
              i = i + 1;
            }
          }
        }
      }
    }
    cout << i << endl;
    i = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n, i = 0;
  cin >> n;
  while (!cin.eof()) {
    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 (n == a + b + c + d) {
              i = i + 1;
            }
          }
        }
      }
    }
  }

  cout << i << endl;

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

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

Error: TLE

Fixed submission:

#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;
}
Problem p00008 (C++) — buggy submission, verdict: 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 rep(I, N) for (int I = 0; I < (int)(N); I++)
#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 main(void) {
  int dp[4][51];
  fill_n(*dp, 4 * 51, 0);
  rep(i, 10) dp[0][i] = 1;
  for (int i = 1; i <= 3; i++) {
    for (int j = 36; j >= 0; j--) {
      for (int k = 0; k <= 9; k++) {
        if (j - k < 0)
          break;
        dp[i][j] += dp[i - 1][j - k];
      }
    }
  }
  int n;
  while (cin >> n)
    FIN(dp[3][n]);

  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;

int n, s;
int dp[10][100][10];
int solve(int i, int j, int k);

int main(void) {

  while (cin >> n >> s) {
    if (n == 0 && s == 0) {
      break;
    }
    fill_n(**dp, 10 * 100 * 10, -1);
    cout << solve(0, 0, 10) << endl;
  }
}

int solve(int now, int sum, int b1) {
  if (now == n) {
    if (sum == s) {
      return 1;
    } else
      return 0;
  }
  if (dp[now][sum][b1] != -1) {
    return dp[now][sum][b1];
  }
  int t = 0;
  for (int i = 0; i < 10; i++) {
    if (b1 != 10 && b1 >= i) {
      continue;
    }
    t += solve(now + 1, sum + i, i);
  }
  return dp[now][sum][b1] = t;
}
Problem p00008 (C++) — buggy submission, verdict: 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) {
    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;
  }
}

Error: TLE

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, 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, verdict: Runtime Error

#include <cstdio>
#include <iostream>

inline int counter(int n);

int main() {
  std::ios::sync_with_stdio(false);
  int data[50], n, i = 0;
  while (std::cin) {
    std::cin >> n;
    data[i] = counter(n);
    i++;
  }
  for (int j = 0; j < i - 1; j++) {
    std::cout << data[j] << "\\n";
  }
}

inline int counter(int n) {
  int count = 0;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      for (int l = 0; l < 10; ++l) {
        for (int t = 0; t < 10; ++t) {
          if (i + j + l + t == n) {
            count++;
          }
        }
      }
    }
  }
  return count;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>

inline int counter(int n);

int main() {
  int data[50], n, i = 0;
  while (std::cin) {
    scanf("%d", &n);
    data[i] = counter(n);
    i++;
  }
  for (int j = 0; j < i; j++) {
    printf("%d\\n", data[i]);
  }
}

inline int counter(int n) {
  int a, b, c, d, count = 0;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      for (int l = 0; l < 10; ++l) {
        for (int t = 0; t < 10; ++t) {
          if (i + j + l + t == n)
            count++;
        }
      }
    }
  }
}
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  int count;

  while (cin >> n) {

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

    cout << count << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  int count;

  while (cin >> 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; k++) {
            if (i + j + k + l == n)
              count++;
          }
        }
      }
    }

    cout << count * 4 << endl;
  }

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

#include <iostream>
#define REP(i, n) for (int i = 1; i <= n; i++)
using namespace std;

#define N 10

int main() {
  int t;
  while (cin >> t) {
    int ans = 0;
    for (int i = 0; i <= 9; i++)
      for (int j = 0; j <= 9; j++)
        for (int k = 0; k <= 9; k++)
          for (int l = 0; l <= 9; l++)
            if ((i + j + k + l) == t)
              ans++;

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define REP(i, n) for (int i = 1; i <= n; i++)
using namespace std;

#define N 10

int main() {
  int t;
  while (1) {
    cin >> t;
    int ans = 0;
    for (int i = 1; i <= 9; i++)
      for (int j = 1; j <= 9; j++)
        for (int k = 1; k <= 9; k++)
          for (int l = 1; l <= 9; l++)
            if ((i + j + k + l) == t)
              ans++;

    cout << ans << endl;
  }

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

#include <stdio.h>
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int count = 0;
    for (int i = 0; i <= 9; i++)
      for (int j = 0; j <= 9; j++)
        for (int k = 0; k <= 9; k++)
          for (int l = 0; l <= 9; l++)
            if (n == i + j + k + l)
              count++;
    printf("%d\\n", count);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int n;
  while (scanf("%d", &n)) {
    int count = 0;
    for (int i = 0; i <= 9; i++)
      for (int j = 0; j <= 9; j++)
        for (int k = 0; k <= 9; k++)
          if (9 >= n - i - j - k && n - i - j - k >= 0)
            count++;
    printf("%d\\n", count);
  }
  return 0;
}
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <iostream>
using namespace std;

int main() {
  int n, cnt;

  while (scanf("%d\\n", &n) + 1) {
    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;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, cnt;

  while (cin >> n, n) {
    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;
  }
}
Problem p00008 (C++) — buggy submission, verdict: Runtime Error

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

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

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

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

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

Error: TLE

Fixed submission:

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

Error: TLE

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;
    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, verdict: 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;
}

Error: TLE

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, verdict: 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;
}

Error: TLE

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, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, c, d, n, e;
  while (cin >> n) {
    e = 0;
    for (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)
              e++;
          }
        }
      }
    }
    cout << e << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c, d, n, e = 0;
  for (;;) {
    cin >> n;
    for (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)
              e++;
          }
        }
      }
    }
    cout << e << endl;
  }
  return 0;
}
Problem p00008 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(void) {
  int c;
  while (cin >> c) {
    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 == c)
              cnt++;
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int dp[50][4];
  for (int i = 0; i < 50; i++) {
    for (int j = 0; i < 4; j++) {
      if (i < 10 && j == 0)
        dp[i][j] = 1;
      else
        dp[i][j] = 0;
    }
  }

  for (int i = 1; i < 4; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 37; k++) {
        if (k - j >= 0) {
          dp[k][i] += dp[k - j][i - 1];
        }
      }
    }
  }

  int n;
  while (cin >> n) {
    cout << dp[n][3] << endl;
  }
  return 0;
}