Problem p03764 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define len(x) (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b) for (int a = 0; a < int(b); ++a)
#define kk(n) ff(k, n)
#define xx(n) ff(x, n)
#define yy(n) ff(y, n)
#define ii(n) ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x) (x).bb, (x).ee
#define ite(v) decltype((v).bb)
#define fe(i, v) for (ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)                                                               \
  {                                                                            \
    fprintf(stderr, __VA_ARGS__);                                              \
    fflush(stderr);                                                            \
  }
#define zz(array, byte) memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;

const LL INFLL = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f; // Works with memset(..).

const LL MOD = LL(1e9) + 7;

LL along1dim(int n, vector<int> &xs) {
  LL widths = 0;
  ii(n - 1) {
    LL onleft = i + 1;
    LL onright = n - 1 - i;
    LL w = xs[i + 1] - xs[i];
    LL howmany = (onleft * onright) % MOD;
    LL here = (howmany * w) % MOD;
    widths = (widths + here) % MOD;
  }
  return widths;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // cout << '\n';     //Avoid flushing with endl.
  cout.precision(16);

  int n, m;
  cin >> n >> m;

  vector<int> xs(n);
  vector<int> ys(n);
  ii(n) cin >> xs[i];
  ii(m) cin >> ys[i];

  cout << (along1dim(n, xs) * along1dim(m, ys)) % MOD << '\n';

  return 0;
}


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

#define len(x) (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b) for (int a = 0; a < int(b); ++a)
#define kk(n) ff(k, n)
#define xx(n) ff(x, n)
#define yy(n) ff(y, n)
#define ii(n) ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x) (x).bb, (x).ee
#define ite(v) decltype((v).bb)
#define fe(i, v) for (ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)                                                               \
  {                                                                            \
    fprintf(stderr, __VA_ARGS__);                                              \
    fflush(stderr);                                                            \
  }
#define zz(array, byte) memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;

const LL INFLL = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f; // Works with memset(..).

const LL MOD = LL(1e9) + 7;

LL along1dim(int n, vector<int> &xs) {
  LL widths = 0;
  ii(n - 1) {
    LL onleft = i + 1;
    LL onright = n - 1 - i;
    LL w = xs[i + 1] - xs[i];
    LL howmany = (onleft * onright) % MOD;
    LL here = (howmany * w) % MOD;
    widths = (widths + here) % MOD;
  }
  return widths;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // cout << '\n';     //Avoid flushing with endl.
  cout.precision(16);

  int n, m;
  cin >> n >> m;

  vector<int> xs(n);
  vector<int> ys(m);
  ii(n) cin >> xs[i];
  ii(m) cin >> ys[i];

  cout << (along1dim(n, xs) * along1dim(m, ys)) % MOD << '\n';

  return 0;
}