Problem p00096 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define lengthof(array) (sizeof(array) / sizeof(*array))
#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it, c)                                                             \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define RFOR(it, c)                                                            \\
  for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)

template <class T> inline void chmax(T &a, const T &b) {
  if (b > a)
    a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
  if (b < a)
    a = b;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
  return os;
}

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

  vector<long long> cnt(2001, 0);
  for (int i = 0; i <= 1000; ++i)
    for (int j = 0; j <= 1000; ++j)
      ++cnt[i + j];

  for (int n; cin >> n;) {
    long long ans = 0;
    const int start = max(0, n - 2000), end = min(2000, n);
    for (int i = start; i <= end; ++i)
      ans += cnt[i] * cnt[n - i];

    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define lengthof(array) (sizeof(array) / sizeof(*array))
#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it, c)                                                             \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define RFOR(it, c)                                                            \\
  for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)

template <class T> inline void chmax(T &a, const T &b) {
  if (b > a)
    a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
  if (b < a)
    a = b;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
  return os;
}

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

  vector<long long> cnt(2001, 0);
  for (int i = 0; i <= 1000; ++i)
    for (int j = 0; j <= 1000; ++j)
      ++cnt[i + j];

  for (int n; cin >> n;) {
    long long ans = 0;
    for (int i = max(0, n - 2000); i <= n; ++i)
      ans += cnt[i] * cnt[n - i];

    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}