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

#include <iostream>

const int N = 100;

int main(void) {
  int n = 0;
  int x = 0;

  std::cin >> n >> x;

  while (!((n == 0) && (x == 0))) {
    int count = 0;
    bool generated[N + 1][N + 1][N + 1] = {false};

    for (int i = 1; i <= n - 2; i++) {
      for (int j = 1; j <= n - 1; j++) {
        for (int k = 1; k <= n; k++) {
          if ((i == j) || (j == k) || (i == k)) {
            continue;
          }

          if (generated[i][j][k]) {
            continue;
          }

          if ((i + j + k) == x) {
            count++;

            generated[i][j][k] = true;
            generated[i][k][j] = true;
            generated[j][i][k] = true;
            generated[j][k][i] = true;
            generated[k][i][j] = true;
            generated[k][j][i] = true;
          }
        }
      }
    }

    std::cout << count << std::endl;

    std::cin >> n >> x;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

const int N = 100;

int main(void) {
  int n = 0;
  int x = 0;

  std::cin >> n >> x;

  while (!((n == 0) && (x == 0))) {
    int count = 0;
    bool generated[N][N][N] = {false};

    for (int i = 1; i <= n - 2; i++) {
      for (int j = 1; j <= n - 1; j++) {
        for (int k = 1; k <= n; k++) {
          if ((i == j) || (j == k) || (i == k)) {
            continue;
          }

          if (generated[i][j][k]) {
            continue;
          }

          if ((i + j + k) == x) {
            count++;

            generated[i][j][k] = true;
            generated[i][k][j] = true;
            generated[j][i][k] = true;
            generated[j][k][i] = true;
            generated[k][i][j] = true;
            generated[k][j][i] = true;
          }
        }
      }
    }

    std::cout << count << std::endl;

    std::cin >> n >> x;
  }

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

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  int i, j, k, sum;
  int n, x;
  while (1) {
    cin >> n >> x;
    sum = 0;
    if (n == 0 && x == 0)
      break;
    for (int i = 1; i < n - 1; ++i) {
      for (int j = i + 1; j < n; ++j) {
        for (int k = j + 1; k < n + 1; ++k) {
          if (i + j + k == x)
            sum += 1;
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  int i, j, k, sum;
  sum = 0;
  int n, x;
  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    for (int i = 1; i < n - 1; ++i) {
      for (int j = i + 1; j < n; ++i) {
        for (int k = j + 1; k < n + 1; ++i) {
          if (i + j + k == x)
            sum += 1;
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i <= n; i++)
using namespace std;

int main() {
  int n, x;
  while (true) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    int cnt = 0;
    FOR(i, 1, n) FOR(j, i + 1, n) FOR(k, j + 1, n) {
      if (i + j + k == x)
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i <= n; i++)
using namespace std;

int main() {
  int n, x;
  int cnt = 0;
  while (true) {
    cin >> n >> x;
    if (n = 0 && x == 0)
      break;
    FOR(i, 1, n) FOR(j, i + 1, n) FOR(k, j + 1, n) {
      if (i + j + k == x)
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, x;
  int a = 0;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;

    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x)
            a++;
        }
      }
    }
    cout << a << endl;
    a = 0;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, x;
  int a = 0;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;

    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; j <= n; k++) {
          if (i + j + k == x)
            a++;
        }
      }
    }
    cout << a << endl;
    a = 0;
  }
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    int count = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == m)
            count++;
        }
      }
    }

    cout << count << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, x;
  while (1) {
    int count = 0;
    cin >> n >> x;
    int i, j, k;
    for (int i = 0; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x)
            count++;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p02412 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, x, j, k;

  while (cin >> n >> x && (n || x)) {

    if (x > 3 * n - 3) {
      cout << "0\\n";
      continue;
    }

    int count = 0;
    int kmax = min(n + 1, x - 2);

    for (k = max(3, x - 2 * n + 3); k < kmax; ++k) {
      int jmax = min(k, x - k);
      for (j = max(2, x - n - k + 2); j < jmax; ++j)
        count += (x - 2 * j - k) < 0;
    }

    cout << count << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int n, x, j, k;

  while (cin >> n >> x && n && x) {

    if (x > 3 * n - 3)
      return -1;

    int count = 0;
    int kmax = min(n + 1, x - 2);

    for (k = max(3, x - 2 * n + 3); k < kmax; ++k) {
      int jmax = min(k, x - k);
      for (j = max(2, x - n - k + 2); j < jmax; ++j)
        count += (x - 2 * j - k) < 0;
    }

    cout << count << endl;
  }

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

#include <iomanip>
#include <iostream>
#include <stack>
#include <string>

using namespace std;

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

int main() {

  int N, x;
  while (1) {

    int sum = 0;

    cin >> N >> x;
    if (N == 0 && x == 0) {
      break;
    }

    REP(i, 1, N - 1) {
      REP(j, i + 1, N) {
        REP(k, j + 1, N + 1) {
          if (x == i + j + k) {
            sum++;
          }
        }
      }
    }
    cout << sum << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>
#include <stack>
#include <string>

using namespace std;

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

int main() {

  int N, x;
  int sum = 0;
  cin >> N >> x;

  while (N != 0 && x != 0) {
    REP(i, 1, N - 1) {
      REP(j, i + 1, N) {
        REP(k, j + 1, N + 1)
        if (x == i + j + k) {
          sum++;
        }
      }
    }
  }

  cout << sum << endl;

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

#include <stdio.h>
int main() {
  int n, i, j, k, w, x, y;
  scanf("%d %d", &n, &x);

  do {
    w = 0;
    for (i = 1; i <= n - 2; i++)
      for (j = i + 1; j <= n - 1; j++)
        for (k = j + 1; k <= n; k++) {
          y = i + j + k;
          if (y == x)
            w += 1;
        }
    printf("%d\\n", w);

    scanf("%d %d", &n, &x);
  } while (n != 0 && x != 0);

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int n, x, i, j, k, w = 0, y = 0;
  scanf("%d %d", &n, &x);

  do {
    for (i = 1; i < j; i++) {
      for (j = i + 1; j < k; j++) {
        for (k = j + 1; k < n; k++) {
          y = i + j + k;
          if (y > x)
            break;
          if (y == x)
            w++;
        }
      }
    }

    printf("%d\\n", w);
    w = 0;
    scanf("%d %d", &n, &x);
  } while (n == 0 && x == 0);

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

#include <iostream>

using namespace std;

int main() {
  int a, x;
  while (cin >> a >> x) {
    if (a == 0 && x == 0)
      break;
    int ans = 0;
    for (int i = 1; i <= a - 2; i++) {
      for (int j = i + 1; j <= a - 1; j++) {
        for (int k = j + 1; k <= a; k++) {
          if (i + j + k == x)
            ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int a, b, c, x, y, z;
  scanf("%d %d", &a, &b);

  do {
    for (x = 1; x <= b - 3; x++)
      for (y = 1; y < x; y++)
        for (z = 1; z < y; z++)
          if (x + y + z == b)
            c += 1;
  } while (a != 0 && b != 0);

  printf("%d\\n", &c);

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

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, x, ans = 0;
  while (true) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    ans = 0;
    n = min(n, x - 3);
    for (int i = n; i > 2; --i) {
      if ((i - 1) * 3 < x)
        break;
      int r = x - i;
      int y = min(r - 1, i - 1);
      int z = max(1, r - y);
      ans += (y - z + 1) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  unsigned int n, x, ans = 0;
  cin >> n >> x;
  n = min(n, x - 3);
  for (unsigned int i = n; i > 2; ++i) {
    unsigned int y = x - i - 1;
    ans += y / 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
  while (1) {
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    }

    int count = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x) {
            count++;
          }
        }
      }
    }

    cout << count << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
  while (1) {
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;

    int count = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; i <= n; i++) {
        for (int k = j + 1; i <= n; k++) {
          if (i != j && j != k && k != i && i + j + k == x) {
            count++;
          }
        }
      }
    }

    cout << count << endl;
  }
  return 0;
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int count(int n, int x) {
  int cnt = 0;
  int i, j, k;
  for (i = 1; i <= n - 2; i++) {
    for (j = i + 1; j <= n - 1; j++) {
      for (k = j + 1; k <= n; k++) {
        if (i + j + k == x)
          cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int n, x;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    cout << count(n, x) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int count(int n, int x) {
  int cnt = 0;
  int i, j, k;
  for (i = 1; i <= n - 2; i++) {
    for (j = i + 1; i <= n - 1; k++) {
      for (k = j + 1; i <= n; j++) {
        if (i + j + k == x)
          cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int n, x;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    cout << count(n, x) << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  int n, x, counter;

  while (1) {
    cin >> n >> x;
    counter = 0;
    if (n == 0 && x == 0)
      return 0;
    for (int i = 1; i <= (n - 2); i++) {
      for (int j = i + 1; j <= (n - 1); j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x)
            counter++;
        }
      }
    }
    cout << counter << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int m, f, r;
  while (1) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1)
      return 0;
    if (m == -1 || f == -1) {
      cout << 'F' << endl;
      continue;
    }
    if (m + f >= 80) {
      cout << 'A' << endl;
      continue;
    } else if (m + f >= 65) {
      cout << 'B' << endl;
      continue;
    } else if (m + f >= 50) {
      cout << 'C' << endl;
      continue;
    } else if (m + f >= 30) {
      if (r >= 50) {
        cout << 'C' << endl;
        continue;
      }
      cout << 'D' << endl;
      continue;
    } else {
      cout << 'F' << endl;
      continue;
    }
  }

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

#include <cstdio>
using namespace std;
int main() {
  int n, x;
  while (1) {
    scanf(" %d %d", &n, &x);
    if (n == 0 && x == 0) {
      break;
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x)
            cnt++;
        }
      }
    }
    printf("%d\\n", cnt);
  }
}


Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
int main() {
  int n, x;
  while (1) {
    int cnt = 0;
    scanf(" %d %d", &n, &x);
    if (n > x - 3) {
      for (int i = x - 3; i > 0; i--) {
        for (int j = i; j > 0; j--) {
          if (x - i - j < i && i > 1) {
            cnt++;
          }
        }
      }

    } else {
      for (int i = n; i > 0; i--) {
        for (int j = i; j > 0; j--) {
          if (x - i - j < i && i > 1) {
            cnt++;
          }
        }
      }
    }
    printf("%d\\n", cnt);
  }
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (true) {
    int n, x;
    cin >> n >> x;
    if (n == x && x == 0) {
      return 0;
    }
    int ans = 0;
    for (int i = 1; i < n + 1; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        for (int k = j + 1; k < n + 1; k++) {
          if (i + j + k == x) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    int n, x;
    cin >> n >> x;
    if (n == x && x == -1) {
      return 0;
    }
    int ans = 0;
    for (int i = 1; i < n + 1; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        for (int k = j + 1; k < n + 1; k++) {
          if (i + j + k == x) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }

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


#include <iostream>
using namespace std;

int comb(int max, int target) {
  int comb = 0;
  for (int i = 3; i <= max; i++) {
    for (int j = 2; j < i; j++) {
      for (int k = 1; k < j; k++) {
        if (i + j + k == target) {
          comb++;
        }
      }
    }
  }
  return comb;
}

int main() {
  int n, x;
  cin >> n >> x;
  while ((n != 0) || (x != 0)) {
    int result = comb(n, x);
    cout << result << endl;
    cin >> n >> x;
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <iostream>
using namespace std;

int recComb(int max, int num, int target) {
  if (target == 0 && num == 0) {
    return 1;
  } else if (max == 0 || target < 0) {
    return 0;
  }
  int comb;
  comb = recComb(max - 1, num - 1, target - max); //?¶??????´???
  comb += recComb(max - 1, num, target);          //?¶????????????´???
  return comb;
}

int main() {
  int n, x;
  cin >> n >> x;
  while ((n != 0) || (x != 0)) {
    int comb = recComb(n, 3, x);
    cout << comb << endl;
    cin >> n >> x;
  }
  return 0;
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n = 0, x = 0, a[1000] = {0}, count = 0, count2;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    a[count] = n, a[++count] = x;
    count++;
  }

  int i = 0;
  while (i < count) {
    count2 = 0;
    for (int j = 1; j < a[i] - 1; j++) {
      for (int k = j + 1; k < a[i]; k++) {
        for (int l = k + 1; l <= a[i]; l++) {
          if (j + k + l == a[i + 1])
            count2++;
        }
      }
    }
    cout << count2 << endl;
    i += 2;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n = 0, x = 0, count = 0, *two;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;

    two = new int[n + 1];
    for (int i = 0; i < n + 1; i++)
      two[i] = 0;

    while (two[n] != 1) {
      int sum = 0, sum2 = 0;
      two[0] += 1;
      for (int j = 0; j < n; j++)
        if (two[j] == 2)
          two[j] = 0, two[j + 1] += 1;
      for (int j = 0; j < n; j++)
        if (two[j] == 1)
          sum += 1, sum2 += j + 1;
      if (sum == 3 && sum2 == x)
        count++;
    }
  }

  cout << count << endl;

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

#include <iostream>
using namespace std;

int main() {
  int n, x;
  int count = 0;
  while (1) {
    cin >> n >> x;
    count = 0;
    if (n == 0 && x == 0) {
      break;
    }
    for (int i = 1; i <= n - 2; i++) {
      for (int j = i + 1; j <= n - 1; j++) {
        for (int k = j + 1; k <= n; k++) {
          if ((i + j + k) == x) {
            count++;
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, x;
  int v[n][n];
  int count = 0;
  int tmp;
  while (1) {
    cin >> n >> x;
    count = 0;
    if (n == 0 && x == 0) {
      break;
    }
    for (int i = 1; i <= n - 2; i++) {
      for (int j = i + 1; j <= n - 1; j++) {
        for (int k = j + 1; k <= n; k++) {
          if ((i + j + k) == x) {
            count++;
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int n, x;
int main() {
  while (true) {
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    }
    int num = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x) {
            num++;
          }
        }
      }
    }
    cout << num << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n, x;
int ctn = 0;
int main() {
  cin >> n >> x;
  while (n != 0 && x != 0) {
    for (int i = 1; i < n; i++) {
      for (int j = i; j < n; j++) {
        for (int k = j; k < n; k++) {
          if (i + j + k == n) {
            ctn++;
          }
        }
      }
    }
    cout << ctn << endl;
  }
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int n, x;

int loop(int cnt, int sum, int plus) {
  if (cnt == 3) {
    if (sum == x) {
      return 1;
    } else {
      return 0;
    }
  }

  if (plus > n) {
    return 0;
  }

  return loop(cnt + 1, sum + plus, plus + 1) + loop(cnt, sum, plus + 1);
}

int main() {
  while (cin >> n >> x && (n != 0 || x != 0)) {
    cout << loop(0, 0, 1) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, x;

int loop(int cnt, int sum, int plus) {
  if (cnt == 3 && sum == x) {
    return 1;
  }

  if (plus > n) {
    return 0;
  }

  return loop(cnt + 1, sum + plus, plus + 1) + loop(cnt, sum, plus + 1);
}

int main() {
  while (cin >> n >> x && (n != 0 || x != 0)) {
    cout << loop(0, 0, 1) << endl;
  }
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int arr[100 + 5];
int n, sum;
int count1;

void dfs(int i, int x, int m) {
  if (x > sum)
    return;
  if ((i == n)) {
    // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
    // cout<<endl;
    if (sum == x && m == 3) {
      count1++;
      // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
      // cout<<endl;
    }
    return;
  }
  dfs(i + 1, x + arr[i], m + 1);
  dfs(i + 1, x, m);
  return;
}

int main() {
  while (cin >> n >> sum && (n || sum)) {
    count1 = 0;
    for (int i = 0; i < n; i++)
      arr[i] = i + 1;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int k = j + 1; k < n; k++) {
          if ((arr[i] + arr[j] + arr[k]) == sum)
            count1++;
        }
      }
    }
    cout << count1 << endl;
  }
  // while(1);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int arr[100 + 5];
int n, sum;
int count1;

void dfs(int i, int x, int m) {
  if (x > sum)
    return;
  if ((i == n)) {
    // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
    // cout<<endl;
    if (sum == x && m == 3) {
      count1++;
      // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
      // cout<<endl;
    }
    return;
  }
  dfs(i + 1, x + arr[i], m + 1);
  dfs(i + 1, x, m);
  return;
}

int main() {
  while (cin >> n >> sum && (n || sum)) {
    count1 = 0;
    for (int i = 0; i < n; i++)
      arr[i] = i + 1;
    dfs(0, 0, 0);
    cout << count1 << endl;
  }
  // while(1);
  return 0;
}
Problem p02412 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int n, x, ways;

int main() {
  while (true) {
    cin >> n >> x;

    if (n == 0 && x == 0) {
      break;
    }

    ways = 0;

    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (x - i - j > j && x - i - j <= n) {
          ways++;
        }
      }
    }

    cout << ways << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n, x, ways;

void dfs(int sum, int k, int max) {
  if (k == 3) {
    if (sum == x) {
      ways++;
    }
  }

  if (sum > x) {
    goto Exit;
  }

  for (int i = max + 1; i <= n; i++) {
    dfs(sum + i, k + 1, i);
  }

Exit:;
}

int main() {
  while (true) {
    cin >> n >> x;

    if (n == 0 && x == 0) {
      break;
    }

    ways = 0;

    dfs(0, 0, 0);

    cout << ways << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  int n, x;
  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    }
    int p = 0;
    for (int i = 1; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x) {
            p += 1;
          }
        }
      }
    }
    cout << p << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, x;
  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    };
    int p;
    p = 0;
    for (int h = 1; h <= n - 2; h++) {
      for (int i = h + 1; h <= n - 1; i++) {
        for (int j = i + 1; j <= n; j++) {
          if (h + i + j == x) {
            p = p + 1;
          }
        }
      }
    }
    cout << p << endl;
  }

  return 0;
}