Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cstdio>

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v)                                                              \
  sort(all(v));                                                                \
  (v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
  type x;                                                                      \
  cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f)                                                               \
  if ((f)) {                                                                   \
    cout << (TRUE__) << endl;                                                  \
  } else {                                                                     \
    cout << FALSE__ << endl;                                                   \
  }
#define RS resize
#define CINV(v, N)                                                             \
  do {                                                                         \
    v.RS(N);                                                                   \
    rep(i, N) cin >> v[i];                                                     \
  } while (0);
#define RCINV(v, N)                                                            \
  do {                                                                         \
    v.RS(N);                                                                   \
    rrep(i, N) cin >> v[i];                                                    \
  } while (0);

#define MOD 1000000007
void init();
void solve();

signed main() {
  init();
  solve();
}

int N, M;
vector<ll> x, y;
vector<ll> xc, yc;

void init() {
  cin >> N >> M;
  x.RS(N - 1);
  y.RS(M - 1);
  vector<ll> tx, ty;
  CINV(tx, N);
  CINV(ty, M);
  xc.RS(N - 1);
  yc.RS(M - 1);
  rep(i, N - 1) { x[i] = tx[i + 1] - tx[i]; }
  rep(i, M - 1) { y[i] = ty[i + 1] - ty[i]; }
  rep(i, N - 1) { xc[i] = (ll)(i + 1) * (N - i - 1); }
  rep(i, M - 1) { yc[i] = (ll)(i + 1) * (M - i - 1); }
}

void solve() {
  ll H = 0;
  rep(i, M - 1) {
    H += y[i] * yc[i];
    H %= MOD;
  }
  ll W = 0;
  rep(i, N - 1) {
    N += x[i] * xc[i];
    N %= MOD;
  }
  cout << H * W % MOD << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cstdio>

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v)                                                              \
  sort(all(v));                                                                \
  (v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
  type x;                                                                      \
  cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f)                                                               \
  if ((f)) {                                                                   \
    cout << (TRUE__) << endl;                                                  \
  } else {                                                                     \
    cout << FALSE__ << endl;                                                   \
  }
#define RS resize
#define CINV(v, N)                                                             \
  do {                                                                         \
    v.RS(N);                                                                   \
    rep(i, N) cin >> v[i];                                                     \
  } while (0);
#define RCINV(v, N)                                                            \
  do {                                                                         \
    v.RS(N);                                                                   \
    rrep(i, N) cin >> v[i];                                                    \
  } while (0);

#define MOD 1000000007
void init();
void solve();

signed main() {
  init();
  solve();
}

int N, M;
vector<ll> x, y;
vector<ll> xc, yc;

void init() {
  cin >> N >> M;
  x.RS(N - 1);
  y.RS(M - 1);
  vector<ll> tx, ty;
  CINV(tx, N);
  CINV(ty, M);
  xc.RS(N - 1);
  yc.RS(M - 1);
  rep(i, N - 1) { x[i] = tx[i + 1] - tx[i]; }
  rep(i, M - 1) { y[i] = ty[i + 1] - ty[i]; }
  rep(i, N - 1) { xc[i] = (ll)(i + 1) * (N - i - 1); }
  rep(i, M - 1) { yc[i] = (ll)(i + 1) * (M - i - 1); }
}

void solve() {
  ll H = 0;
  rep(i, M - 1) {
    H += y[i] * yc[i];
    H %= MOD;
  }
  ll W = 0;
  rep(i, N - 1) {
    W += x[i] * xc[i];
    W %= MOD;
  }
  cout << H * W % MOD << endl;
}