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

#include <cstdio>
#include <iostream>

#define reep(i, n, m) for (int i = (n); i < (m); i++)
#define rep(i, n) reep(i, 0, n)

using namespace std;

typedef long long int ll;

ll dp[5][4001];

int main() {
  dp[0][0] = 1;
  reep(j, 1, 5) {
    rep(i, 1001) {
      reep(k, i, 4001) { dp[j][k] += dp[j - 1][k - i]; }
    }
  }

  int n;
  while (scanf("%d", &n) != EOF) {
    cout << dp[4][n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

#define reep(i, n, m) for (int i = (n); i < (m); i++)
#define rep(i, n) reep(i, 0, n)

using namespace std;

typedef long long int ll;

ll dp[5][4001];

int main() {
  dp[0][0] = 1;
  reep(j, 1, 5) {
    rep(i, 1001) {
      reep(k, i, 4001) { dp[j][k] += dp[j - 1][k - i]; }
    }
  }

  int n;
  while (cin >> n, n) {
    cout << dp[4][n] << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int t[2001];
int n, sum;
int main() {
  for (int i = 0; i < 2001; i++) {
    if (i < 1001)
      t[i] = i + 1;
    else
      t[i] = 2001 - i;
  }
  while (cin >> n) {
    sum = 0;
    for (int i = 0; i < 2001; i++) {
      if (n - i >= 0 && n - i <= 2000) {
        sum = sum + t[i] * t[n - i];
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int t[2001];
int n, sum;
int main() {
  for (int i = 0; i < 2001; i++) {
    if (i < 1001)
      t[i] = i + 1;
    else
      t[i] = 2001 - i;
  }
  while (cin >> n) {
    sum = 0;
    for (int i = 0; i < 2001; i++) {
      if (n - i >= 0)
        sum += t[i] * t[n - i];
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

typedef vector<int> vi;

int main() {
  int n;
  vi v(2001, 0);
  REP(i, 1001) REP(j, 1001) { v[i + j]++; }

  while (cin >> n) {
    long long ans = 0;
    REP(i, 1001) REP(j, 1001) {
      int k = n - i - j;
      if (k < 0 || k > 2000)
        continue;
      ans += v[k];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

typedef vector<int> vi;

int main() {
  int n;
  vi v(1001 * 1001);
  REP(i, 1001) REP(j, 1001) {
    int k = i + j;
    v[i * 1001 + j] = k;
  }
  sort(v.begin(), v.end());

  while (cin >> n) {
    long long ans = 0;
    REP(i, 1001) REP(j, 1001) {
      int k = n - i - j;
      if (k < 0 || k > 2000)
        continue;
      ans += upper_bound(v.begin(), v.end(), k) -
             lower_bound(v.begin(), v.end(), k);
    }

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

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

using namespace std;

int main() {

  unsigned long long dp[4001][5];
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 4001; j++)
      dp[j][i] = i == 1 && j <= 1000 ? 1 : 0;

  for (int i = 2; i <= 4; i++)
    for (int j = 0; j <= 4000; j++)
      for (int k = 0; k <= j && k <= 1000; k++)
        dp[j][i] += dp[j - k][i - 1];

  int n;
  while (cin >> n)
    cout << dp[n][4] << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  vector<int> vec;
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++)
      vec.push_back(i + j);
  sort(vec.begin(), vec.end());
  int n;
  while (cin >> n) {
    long long ans = 0;
    for (int i = 0; i <= 1000; i++)
      for (int j = 0; j <= 1000; j++)
        ans += upper_bound(vec.begin(), vec.end(), n - i - j) -
               lower_bound(vec.begin(), vec.end(), n - i - j);
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

using namespace std;

int n;
int cnt[4040];

void setcnt() {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++)
      cnt[i + j]++;
}

void solve() {
  int ans = 0;
  for (int ab = 0; ab <= n; ab++) {
    ans += cnt[ab] * cnt[n - ab];
  }
  cout << ans << endl;
}

int main() {
  setcnt();

  while (cin >> n) {
    solve();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int n;
int cnt[2020];

void setcnt() {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++)
      cnt[i + j]++;
}

void solve() {
  int ans = 0;
  for (int ab = 0; ab <= n; ab++) {
    ans += cnt[ab] * cnt[n - ab];
  }
  cout << ans << endl;
}

int main() {
  setcnt();

  while (cin >> n) {
    solve();
  }

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

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

int main() {
  int n, dp[4010] = {1};
  for (int i = 0; i < 4; i++)
    for (int j = 4000; j >= 0; j--)
      for (int k = 1; k <= 1000; k++)
        if (j + k <= 4000)
          dp[j + k] += dp[j];

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

Error: TLE

Fixed submission:

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

int main() {
  int n, dp[4010] = {1};
  for (int i = 0; i < 4; i++)
    for (int j = 400; j >= 0; j--)
      for (int k = 1; k <= 1000; k++)
        if (j + k <= 4000)
          dp[j + k] += dp[j];

  while (cin >> n, n)
    cout << dp[n] << endl;
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
#define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--)
#define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--)
#define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define vrep(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template <class T, class S> inline bool minup(T &m, S x) {
  return m > (T)x ? (m = (T)x, true) : false;
}
template <class T, class S> inline bool maxup(T &m, S x) {
  return m < (T)x ? (m = (T)x, true) : false;
}

const int INF = 1000000000;
const ll MOD = 1000000007LL;
const double EPS = 1E-12;

const int MAX_N = 4000;
const int A = 1000;
int n;
vi ra, la;
map<int, int> hm;

int main() {
  erep(i, 0, A) erep(j, 0, A) la.pb(i + j);
  sort(ALL(la));

  ra = la;
  ra.erase(unique(ALL(ra)), ra.end());
  vrep(v, la) hm[*v] = upper_bound(ALL(la), *v) - lower_bound(ALL(la), *v);

  while (cin >> n) {
    int res = 0;
    vrep(v, ra) res += hm[*v] * hm[n - (*v)];
    cout << res << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
#define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--)
#define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--)
#define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define vrep(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template <class T, class S> inline bool minup(T &m, S x) {
  return m > (T)x ? (m = (T)x, true) : false;
}
template <class T, class S> inline bool maxup(T &m, S x) {
  return m < (T)x ? (m = (T)x, true) : false;
}

const int INF = 1000000000;
const ll MOD = 1000000007LL;
const double EPS = 1E-12;

const int MAX_N = 4000;
const int A = 1000;
int n;
vi ra, la;

int main() {
  erep(i, 0, A) erep(j, 0, A) ra.pb(i + j);
  erep(i, 0, A) erep(j, 0, A) la.pb(i + j);
  sort(ALL(la));

  while (cin >> n) {
    int res = 0;
    vrep(v, ra) res +=
        upper_bound(ALL(la), n - (*v)) - lower_bound(ALL(la), n - (*v));

    cout << res << endl;
  }

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

#include <cmath>
#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) {
    long long cnt = 0;
    for (int i = max(0, n - 3000); i <= min(1000, n); i++) {
      for (int j = max(0, n - i - 2000); j <= min(1000, n - i); j++) {
        cnt += (min(1000, n - i - j) - max(0, n - i - j - 1000) + 1);
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#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) {
    long long cnt = 0;
    for (int i = max(0, n - 3000); i <= min(1000, n); i++) {
      for (int j = max(0, n - i - 2000); j <= min(1000, n); j++) {
        for (int k = max(0, n - i - j - 1000); k <= min(1000, n); k++) {
          if ((n - (i + j + k)) >= 0 && (n - (i + j + k)) <= 1000)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  int AB[2001] = {0};
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      AB[i + j]++;
    }
  }

  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= 2000; i++) {
      if (n - i > 2000)
        continue;
      if (n - i >= 0)
        ans += AB[i] * AB[n - i];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  int AB[2001] = {0};
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      AB[i + j]++;
    }
  }

  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= 2000; i++) {
      if (n - i >= 0)
        ans += AB[i] * AB[n - i];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int a[2001] = {}, b[4001] = {};
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++)
      a[i + j]++;
  for (int i = 0; i <= 2000; i++)
    for (int j = 0; j <= 2000; j++)
      b[i + j] += a[i] * a[j];

  for (int n; cin >> n;)
    cout << b[n] << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>

using namespace std;

#define dump(n) cout << "# " << #n << '=' << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int INFTY = 1 << 29;
const double EPS = 1e-9;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  rep(i, a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

int main() {
  vector<ll> a(2001);
  rep(i, 1001) rep(j, 1001) a[i + j]++;
  vector<ll> b(4001);
  rep(i, 2001) rep(j, 2001) b[i + j] += a[i] * a[j];

  for (int n; cin >> n;) {
    assert(n);
    cout << b[n] << endl;
  }

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

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

typedef long long int LLI;

LLI cnt[5001];

int main() {
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      cnt[i + j]++;
    }
  }

  while (1) {
    int n;
    if (scanf("%d", &n) != 1)
      return 0;

    LLI ans = 0;
    for (int i = 0; i <= min(n, 2000); i++) {
      ans += cnt[i] * cnt[n - i];
    }
    printf("%lld\\n", ans);
  }
}

Error: 0

Fixed submission:

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

typedef long long int LLI;

LLI cnt[2001];

int main() {
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      cnt[i + j]++;
    }
  }

  while (1) {
    int n;
    if (scanf("%d", &n) != 1)
      return 0;

    LLI ans = 0;
    for (int i = 0; i <= min(n, 2000); i++) {
      ans += cnt[i] * cnt[n - i];
    }
    printf("%lld\\n", ans);
  }
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = b; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int main() {
  int sum[3000];
  memset(sum, 0, sizeof(sum));
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      sum[i + j]++;
    }
  }
  int n;
  while (scanf("%d", &n) != EOF) {
    ll ans = 0;
    for (int i = 0; i <= 2000; i++) {
      int a = n - i;
      if (a < 0)
        break;
      if (a > 2000)
        continue;
      ans += sum[i] * sum[a];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = b; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int main() {
  vector<int> sum;
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      sum.push_back(i + j);
    }
  }
  sort(sum.begin(), sum.end());
  int n;
  while (scanf("%d", &n) != EOF) {
    int ans = 0;
    for (int i = 0; i < sum.size(); i++) {
      int a = n - sum[i];
      if (a < 0)
        break;
      ans += upper_bound(sum.begin(), sum.end(), a) -
             lower_bound(sum.begin(), sum.end(), a);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  while (cin >> n) {
    long long int res = 0;
    for (int i = 0; i <= 1000; i++) {
      for (int j = 0; j <= 1000; j++) {
        if (n - i - j <= 1000)
          res += max(0, n - i - j + 1);
        else
          res += max(0, 2001 - (n - i - j));
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  int sum[1001 * 1001];
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      sum[i * 1001 + j] = i + j;
    }
  }
  sort(sum, sum + 1001 * 1001);
  while (cin >> n) {
    int res = 0;
    for (int i = 0; i <= min(n, 1000); i++) {
      for (int j = 0; j <= min(n, 1000); j++) {
        res += upper_bound(sum, sum + 1001 * 1001, n - i - j) -
               lower_bound(sum, sum + 1001 * 1001, n - i - j);
      }
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>

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

using namespace std;

long long dp[4001][5];

int main() {
  rep(k, 1001) {
    rep(i, 4001) {
      for (int j = 1; j <= 4; ++j) {
        if (i == 0) {
          dp[i][j] = 1;
        } else if (j == 1) {
          dp[i][j] = i <= k;
        } else if (k == 0) {
          dp[i][j] = 0;
        } else if (i > k) {
          dp[i][j] = dp[i - 1][j] - dp[i - k - 1][j - 1] + dp[i][j - 1];
        } else {
          dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        }
      }
    }
  }

  int n;
  while (scanf("%d", &n) != EOF) {
    printf("%lld\\n", dp[n][4]);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>

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

using namespace std;

long long dp[4001][5][1001];

int main() {
  rep(i, 4001) {
    for (int j = 1; j <= 4; ++j) {
      rep(k, 1001) {
        if (i == 0) {
          dp[i][j][k] = 1;
        } else if (j == 1) {
          dp[i][j][k] = i <= k;
        } else if (k == 0) {
          dp[i][j][k] = 0;
        } else if (i > k) {
          dp[i][j][k] =
              dp[i - 1][j][k] - dp[i - k - 1][j - 1][k] + dp[i][j - 1][k];
        } else {
          dp[i][j][k] = dp[i - 1][j][k] + dp[i][j - 1][k];
        }
      }
    }
  }

  int n;
  while (scanf("%d", &n) != EOF) {
    printf("%lld\\n", dp[n][4][1000]);
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int n, ans;
int nummem[2001] = {0};
int main() {
  for (int i = 0; i < 1001; i++) {
    for (int j = 0; j < 1001; j++) {
      nummem[i + j]++;
    }
  }
  while (scanf("%d", &n) != -1) {
    ans = 0;
    for (int i = 0; i < 1001; i++) {
      for (int j = 0; j < 1001; j++) {
        if (0 <= n - i - j && n - i - j <= 2000)
          ans = ans + nummem[n - i - j];
      }
    }
    printf("%d\\n", ans);
  }
}

Error: 0

Fixed submission:

#include <stdio.h>

int n;
int nummem[2002] = {0}, nummem2[2002] = {0};
int ans = 0;

int main() {
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      nummem[i + j]++;
    }
  }
  while (scanf("%d", &n) != EOF) {
    ans = 0;
    for (int i = 0; i <= 1000; i++) {
      for (int j = 0; j <= 1000; j++) {
        if (n - i - j >= 0)
          ans = ans + nummem[n - i - j];
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <iostream>

using namespace std;

int func(int x) { return max(0, 1001 - abs(1000 - x)); }

int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
      ans += func(i) * func(n - i);
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
int n = 0;
int main(void) {
  int a, b, c, d;
  int cnt;
  while (std::cin >> n) {
    cnt = 0;
    for (a = 0; a <= 1000; ++a) {
      if (a > n)
        break;
      for (b = 0; b <= n - a; ++b) {
        if ((a + b) > n)
          break;
        for (c = 0; c <= n - a - b; ++c) {
          if ((d = (n - a - b - c)) >= 0) {
            if (d <= 1000) {
              cnt++;
            }
          } else {
            break;
          }
        }
      }
    }
    std::cout << cnt << std::endl;
  }
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int num[2222];
  for (int i = 0; i < 2010; i++) {
    num[i] = 0;
  }
  // cout << num[1876] << endl;
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      num[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (n - i <= 2000 && i <= 2000) {
        ans += num[i] * num[n - i];
      }
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int num[2222];
  memset(num, 0, 2010);
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      num[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (n - i <= 2000) {
        ans += num[i] * num[n - i];
      }
    }
    cout << ans << endl;
  }
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    int x = 0;
    if (n > 3000)
      x = n - 3000;

    for (int i = x; i < 1001 && i <= n; i++) {
      // cout<<i<<"-"<<endl;
      int y = 0;
      if (n - i > 2000)
        y = n - i - 2000;

      for (int j = y; j < 1001 && i + j <= n; j++) {
        // cout<<j<<"--"<<endl;
        // if(n-i-j>=2001)continue;
        int z = 0;
        if (n - i - j > 1000)
          z = n - i - j - 1000;

        int zz = 1001;
        if (1001 > n - i - j + 1)
          zz = n - i - j + 1;

        ans += zz - z;
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    int x = 0;
    if (n > 3000)
      x = n - 3000;

    for (int i = x; i < 1001 && i <= n; i++) {
      // cout<<i<<"-"<<endl;
      int y = 0;
      if (n - i > 2000)
        y = n - i - 2000;

      for (int j = y; j < 1001 && i + j <= n; j++) {
        // cout<<j<<"--"<<endl;
        // if(n-i-j>=2001)continue;
        int z = 0;
        if (n - i - j > 1000)
          z = n - i - j - 1000;

        for (int k = z; k < 1001 && i + j + k <= n; k++) {
          // cout<<k<<"---"<<endl;;
          ans++;
        }
      }
    }

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int num[4002] = {0};
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++) {
      num[i + j]++;
      num[(i + j) + 2001]++;
    }
  int n;
  while (cin >> n) {
    int m = (n > 2000) ? n - 2000 : 0;
    int res = 0;
    for (int i = m; i <= n; i++) {
      if (!(i > 2000 || n - i > 2000)) {
        res += num[i] * num[n - i];
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define N 1000
using namespace std;

int main() {

  int a, b, c, d, n, count = 0;

  cin >> n;

  for (a = 1; a <= N; a++) {
    for (b = 1; b <= N; b++) {
      for (c = 1; c <= N; c++) {
        for (d = 1; d <= N; d++) {
          if ((a + b + c + d) == n)
            count++;
        }
      }
    }
  }

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