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

#include <algorithm>
#include <iostream>

int n;
int sum[2001];

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

  while (std::cin >> n) {
    int ans = 0;
    for (int a = 0; a <= 2000; ++a) {
      if (n - a < 0 || n - a > 2000)
        continue;

      ans += sum[a] * sum[n - a];
    }

    std::cout << ans << std::endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

int n;
int sum[2001];

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

  while (std::cin >> n) {
    long long ans = 0;
    for (int a = 0; a <= std::min(2000, n); ++a)
      ans += sum[a] * sum[n - a];

    std::cout << ans << std::endl;
  }

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

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main() {
  int a[4005] = {0};
  int n;

  rep(i, 1001) rep(j, 1001) a[i + j]++;

  while (cin >> n) {
    int ans = 0;
    rep(i, n + 1) { ans += a[i] * a[n - i]; }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

void maxmin(int n, int x, int *amin, int *amax) {
  if (n < 1000)
    *amax = n;
  else
    *amax = 1000;
  if (n > 1000 * x)
    *amin = n - 1000 * x;
  else
    *amin = 0;
}

int main() {
  int n;
  while (cin >> n) {
    int a, b, c, d, ans = 0;
    int amin, amax, bmin, bmax, cmin, cmax, dmin, dmax;
    maxmin(n, 3, &amin, &amax);
    for (a = amin; a <= amax; a++) {
      maxmin(n - a, 2, &bmin, &bmax);
      for (b = bmin; b <= bmax; b++) {
        maxmin(n - a - b, 1, &cmin, &cmax);
        for (c = cmin; c <= cmax; c++) {
          maxmin(n - a - b - c, 0, &dmin, &dmax);
          for (d = dmin; d <= dmax; d++) {
            if (a + b + c + d == n)
              ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <complex>
#include <iostream>
using namespace std;
int main() {
  long long ans;
  int n;
  while (cin >> n) {
    ans = 0;
    for (int i = 0; i <= n; i++) {
      if (i <= 2000 && n - i <= 2000) {
        int s1, s2;
        s1 = 1001 - abs(1000 - i);
        s2 = 1001 - abs(1000 - n + i);
        ans += s1 * s2;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, ans;
  while (cin >> n) {
    ans = 0;
    for (int i = 0; i < 1000; i++) {
      for (int j = 0; j < 1000; j++) {
        for (int k = 0; k < 1000; k++) {
          if (i + j + k <= n && i + j + k >= n - 1000)
            ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j, k;
  int n;
  while (cin >> n) {
    vi v(2005, 0);
    rep(i, min(n + 1, 1001)) rep(j, min(n + 1, 1001)) v[i + j]++;
    ll ans = 0;
    rep(i, 2001) if (n - i <= 2000 && n >= i) ans += v[i] * v[n - i];
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j, k;
  int n;
  while (cin >> n) {
    vi v(2005, 0);
    rep(i, n + 1) rep(j, n + 1) v[i + j]++;
    ll ans = 0;
    rep(i, n + 1) ans += v[i] * v[n - i];
    cout << ans << endl;
  }
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <stdio.h>

using namespace std;

/*
 a
 b
 c
 d
 ab
 ac
 ad
 bc
 bd
 cd
 abc
 abd
 acd
 bcd
 abcd
 */
int dp[4001] = {0};
int dp2[4001] = {0};
int dp3[4001] = {0};
int dp4[4001] = {0};

int main() {

  for (int i = 1; i <= 1000; i++) {
    dp[i]++;
  }

  for (int i = 1; i <= 1000; i++) {
    for (int j = 1; j <= 4000; j++) {
      if (dp[j] != 0) {
        if (j + i <= 4000) {
          dp2[i + j]++;
        }
      }
    }
  }

  for (int i = 1; i <= 1000; i++) {
    for (int j = 1; j <= 4000; j++) {
      if (dp2[j] != 0) {
        if (j + i <= 4000) {
          dp3[i + j] += dp2[j];
        }
      }
    }
  }

  for (int i = 1; i <= 1000; i++) {
    for (int j = 1; j <= 4000; j++) {
      if (dp3[j] != 0) {
        if (j + i <= 4000) {
          dp4[i + j] += dp3[j];
        }
      }
    }
  }

  /*
  for(int i=0; i<=35; i++){
      cout<<i<<" "<<dp[i]*4+dp2[i]*6+dp3[i]*4+dp4[i]<<endl;
  }
  */

  int n;
  while (cin >> n) {
    cout << dp[n] * 4 + dp2[n] * 6 + dp3[n] * 4 + dp4[n] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    long long int ans = 0;

    for (int a = 0; a <= n; a++) {
      if (a > 1000)
        break;
      for (int b = 0; b <= n - a; b++) {
        if (b > 1000)
          break;
        for (int c = 0; c <= n - a - b; c++) {
          if (c > 1000)
            break;
          // cout<<a<<" "<<b<<" "<<c<<" "<<n-a-b-c<<endl;
          // if(n-a-b-c<0)cout<<"error"<<endl;
          if (n - a - b - c <= 1000)
            ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, count, array[2001];
  fill(array, array + 2001, 0);
  for (int a = 0; a <= 1000; a++)
    for (int b = 0; b <= 1000; b++)
      array[a + b]++;

  while (scanf("%d", &n) != EOF) {
    count = 0;
    for (int i = 0; i <= n; i++) {
      if (n - i > 2000)
        continue;
      if (i > 2000)
        break;
      count += array[i] * array[n - i];
    }
    printf("%d\\n", count);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
using namespace std;

int main() {
  int n, count, array[2001];
  for (int a = 0; a <= 1000; a++)
    for (int b = 0; b <= 1000; b++)
      array[a + b]++;

  while (scanf("%d", &n) != EOF) {
    count = 0;
    for (int i = 0; i <= n; i++)
      count += array[i] * array[n - i];

    printf("%d\\n", count);
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  long r;
  while (cin >> n) {
    r = 0;
    for (int a = 0; a <= 1000; a++) {
      for (int b = 0; b <= 1000; b++) {
        int s = n - a - b;
        if (s <= 1000 && s >= 0) {
          r += s + 1;
        } else if (s <= 2000 && s > 1000) {
          r += 2001 - s;
        }
      }
    }
    cout << r << endl;
  }
  return (0);
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  long r;
  while (cin >> n) {
    r = 0;
    for (int a = 0; a <= 1000; a++) {
      for (int b = 0; b <= 1000; b++) {
        for (int c = 0; c <= 1000; c++) {
          int d = n - a - b - c;
          if (d >= 0 && d <= 1000)
            r++;
        }
      }
    }
    cout << r << endl;
  }
  return (0);
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toStr(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, (n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int main() {
  vi ab(4000 + 1);
  FOR(a, 0, 1000) {
    FOR(b, 0, 1000) { ab[a + b]++; }
  }

  int n;
  while (cin >> n) {
    ll ans = 0;
    FOR(i, 0, n) { ans += ab[i] * ab[n - i]; }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toStr(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, (n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int main() {
  int n;

  vi ab, cd;
  FOR(a, 0, 1000) {
    FOR(b, 0, 1000) {
      ab.push_back(a + b);
      cd.push_back(a + b);
    }
  }
  sort(ALL(ab));

  while (cin >> n) {
    int ans = 0;
    REP(i, cd.size()) {
      ans += upper_bound(ALL(ab), n - cd[i]) - lower_bound(ALL(ab), n - cd[i]);
    }
    cout << ans << endl;
  }

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

#include <algorithm>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define each(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, dp[4010];

int main() {
  rep(i, 1001) rep(j, 1001) dp[i + j]++;

  while (cin >> n) {

    ll ans = 0;
    rep(i, n + 1) ans += (ll)dp[i] * dp[n - i];
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define each(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, dp[2010];

int main() {
  rep(i, 1001) rep(j, 1001) dp[i + j]++;

  while (cin >> n) {

    ll ans = 0;
    rep(i, n + 1) ans += (ll)dp[i] * dp[n - i];
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

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

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

int dp[4040];

int main() {
  int n;
  rep(i, 1000) rep(j, 1000) { dp[i + j]++; }

  while (cin >> n) {
    int ans = 0;
    rep(i, n) ans += dp[i] * dp[n - i];

    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

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

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

int dp[2020];

int main() {
  int n;
  rep(i, 1000) rep(j, 1000) { dp[i + j]++; }

  while (cin >> n) {
    int ans = 0;
    rep(i, n) ans += dp[i] * dp[n - i];

    cout << ans << endl;
  }
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  int n;
  while (cin >> n) {
    int a[5010] = {0};
    REP(i, 1001) REP(j, 1001) { a[i + j]++; }
    int ret = 0;
    REP(i, 1001) REP(j, 1001) {
      if (i + j <= n) {
        ret += a[n - i - j];
      }
    }
    cout << ret << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  int n;
  while (cin >> n) {
    int a[2010] = {0};
    REP(i, 1001) REP(j, 1001) { a[i + j]++; }
    int ret = 0;
    REP(i, 1001) REP(j, 1001) {
      if (i + j <= n) {
        ret += a[n - i - j];
      }
    }
    cout << ret << endl;
  }

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

#include <iostream>

using namespace std;

int ab[2001];

int main() {
  int n;

  while (cin >> n) {
    int ans = 0;

    for (int i = 0; i < 2001; i++)
      ab[i] = 0;

    for (int a = 0; a <= 1000; a++)
      for (int b = 0; b <= 1000; b++)
        ab[a + b]++;

    for (int c = 0; c <= 1000; c++)
      for (int d = 0; d <= 1000; d++)
        if (n - c - d >= 0 && n - c - d <= 2000)
          ans += ab[n - c - d];

    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int ab[2001];

int main() {
  int n;

  while (cin >> n) {
    int ans = 0;

    for (int i = 0; i < 2001; i++)
      ab[i] = 0;

    for (int a = 0; a <= 1000; a++)
      for (int b = 0; b <= 1000; b++)
        ab[a + b]++;

    for (int c = 0; c <= 1000; c++)
      for (int d = 0; d <= 1000; d++)
        if (n - c - d >= 0)
          ans += ab[n - c - d];

    cout << ans << endl;
  }

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

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

int main() {
  int num[2001] = {0};

  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      num[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    int res = 0;
    for (int i = 0; i <= n; i++) {
      if (i > 2000 || n - i > 2000)
        continue;
      res += num[i] * num[n - i];
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int num[2001] = {0};

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

#include <algorithm>
#include <iostream>
int f(int x) { return 1 + std::min(abs(0 - x), std::abs(2000 - x)); }
int main() {
  int n;
  while (std::cin >> n) {
    int comb = 0;
    for (int i = 0; i <= 2000; ++i) {
      int x0 = i;
      int x1 = n - x0;
      if (x1 < 0) {
        continue;
      }
      if (2000 < x1) {
        continue;
      }
      comb += f(x0) * f(x1);
    }
    std::cout << comb << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <iostream>
void sum_of_2_int(int n, int sum, int i, int *count, int *list) {
  if (n < sum) {
    return;
  }
  if (i < 2) {
    for (int j = 0; j <= 1000; ++j) {
      list[i] = j;
      sum_of_2_int(n, sum + j, i + 1, count, list);
    }
  } else {
    if (n == sum) {
      (*count)++;
      // printf("%d,", list[0]);
      // printf("%d\\n", list[1]);
    }
  }
}
int main() {
  int combs[2001] = {};
  for (int i = 0; i <= 2000; ++i) {
    int list[2] = {};
    int combination = 0;
    sum_of_2_int(i, 0, 0, &combination, list);
    combs[i] = combination;
  }

  int n;
  while (std::cin >> n) {
    int comb = 0;
    for (int i = 0; i <= 2000; ++i) {
      int list[2] = {};
      int x0 = i;
      int x1 = n - x0;
      if (x1 < 0) {
        continue;
      }
      int combination = 0;
      sum_of_2_int(x1, 0, 0, &combination, list);
      comb += combs[x0] * combination;
    }
    std::cout << n << std::endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int x[100][4001], n;
int main() {
  x[0][0] = 1;
  for (int i = 1; i < 10; i++) {
    for (int j = 0; j < 4000; j++) {
      for (int k = 0; k <= 1000; k++) {
        x[i][j + k] += x[i - 1][j];
      }
    }
  }
  int n;
  while (cin >> n) {
    cout << x[4][n] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int x[4500], n;
int main() {
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      for (int k = 0; k <= 1000; k++) {
        x[i + j + k] += k;
      }
      for (int k = 1001; k <= 2000; k++) {
        x[i + j + k] += (2000 - k);
      }
    }
  }
  while (cin >> n) {
    cout << x[n] << endl;
  }
}
Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int a[4001] = {};
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    long long int all = 0;
    for (int i = 0; i <= 1000; i++) {
      for (int j = 0; j <= 1000 && j <= n - i; j++) {
        all += a[n - i - j];
      }
    }
    cout << all << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[2001] = {};
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    long long int all = 0;
    for (int i = 0; i <= 1000; i++) {
      for (int j = 0; j <= 1000 && j <= n - i; j++) {
        all += a[n - i - j];
      }
    }
    cout << all << endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long int n, a[4005], memo[4005], ans;

int main() {

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

  while (scanf("%d", &n) != EOF) {

    for (int i = 0; i < 4001; i++)
      memo[i] = 0;

    for (int i = 0; i < 2001; i++) {
      for (int j = 0; j < 2001; j++) {
        memo[i + j] += a[i] * a[j];
      }
    }
    cout << memo[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long int n, a, ans;
vector<long int> ss1, aa;

int main() {

  while (scanf("%d", &n) != EOF) {

    // cin >> n;
    ans = 0;
    ss1.clear();
    // aa.push_back(0);

    for (int i = 0; i <= 1000 && i <= n; i++) {
      for (int j = 0; j <= 1000 && j <= n; j++) {
        if (i + j <= n)
          ss1.push_back(i + j);
      }
    }
    sort(ss1.begin(), ss1.end());

    int cnt = ss1.size() - 1;
    for (int i = 0; i < ss1.size(); i++) {
      while (ss1[i] + ss1[cnt] > n)
        cnt--;
      for (int j = cnt; j > -1; j--) {
        if (ss1[i] + ss1[j] == n)
          ans++;
        else
          break;
      }
    }

    cout << ans << endl;
  }

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

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27);
const ll INFLL = (1LL << 55);
#define FOR(i, a, b) for (int(i) = (a); i < (int)(b); i++)
#define rep(i, n) FOR(i, 0, n)
template <typename T> void dbg(T x) { cout << x << "\\n"; }
template <typename T, typename U> static void chmin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> static void chmax(T &x, U y) {
  if (x < y)
    x = y;
}

static int cnt1[2018], cnt2[2018];

int main() {
  int n;
  while (cin >> n) {
    memset(cnt1, 0, sizeof(cnt1));
    memset(cnt2, 0, sizeof(cnt2));
    rep(c, 1001) rep(d, 1001) {
      int x = n - c - d;
      if (0 <= x && x <= 2000)
        cnt1[x]++;
    }
    rep(a, 1001) rep(b, 1001) { cnt2[a + b]++; }

    ll ans = 0;
    rep(i, 2001) ans += cnt1[i] * cnt2[i];
    cout << ans << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27);
const ll INFLL = (1LL << 55);
#define FOR(i, a, b) for (int(i) = (a); i < (int)(b); i++)
#define rep(i, n) FOR(i, 0, n)
template <typename T> void dbg(T x) { cout << x << "\\n"; }
template <typename T, typename U> static void chmin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> static void chmax(T &x, U y) {
  if (x < y)
    x = y;
}

int main() {
  int n;
  while (cin >> n) {
    static int cnt1[2018], cnt2[2018];
    memset(cnt1, 0, sizeof(cnt1));
    memset(cnt2, 0, sizeof(cnt2));
    rep(c, 1001) rep(d, 1001) if (n - c - d >= 0) { cnt1[n - c - d]++; }
    rep(a, 1001) rep(b, 1001) {
      int x = a + b;
      cnt2[x]++;
    }

    ll ans = 0;
    rep(i, 2018) ans += cnt1[i] * cnt2[i];
    cout << ans << "\\n";
  }
  return 0;
}