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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--)
#define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c)
#define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

ll npair[2020];

void make() { for_(i, 0, 1001) for_(j, 0, 1001) npair[i + j]++; }

int main() {
  int n;
  minit(npair, 0);
  make();

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

    for_(i, 0, min(2001, n + 1)) {
      ll sub1, sub2;

      if (n - i > 2000)
        continue;
      sub1 = npair[i];
      sub2 = npair[n - i];
      ans += sub1 * sub2;
    }

    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--)
#define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c)
#define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

int npair[2020];

void make() { for_(i, 0, 1010) for_(j, 0, 1010) npair[i + j]++; }

int main() {
  int n;
  minit(npair, 0);
  make();

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

    for_(i, 0, min(2001, n + 1)) {
      int sub1, sub2;
      sub1 = npair[i];
      sub2 = npair[n - i];
      ans += sub1 * sub2;
    }

    cout << ans << endl;
  }

  return 0;
}