Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
// #include <string>
#include <algorithm>
#include <vector>
// #include <utility>
// #include <set>
// #include <map>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <math.h>
using namespace std;
using ll = long long;
// using ld = long double ;
using vll = vector<ll>;
using vvll = vector<vll>;
// using vc = vector<char> ;
// using vvc = vector<vc> ;
// using vb = vector<bool> ;
// using vvb = vector<vb> ;
// using pll = pair<ll,ll> ;
#define all(v) v.begin(), v.end()
ll mod = 1000000007;
// long double pie = acos(-1) ;
// ll INF = 1000000000000 ;

// void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
// void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
// ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
// ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll sa(long long a, long long b) {
  if (a > b)
    return a - b;
  return b - a;
}
// void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
// void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
// void fix_cout(){cout << fixed << setprecision(20) ;}

int main() {
  ll n, m;
  cin >> n >> m;
  vll x(n), y(m);
  for (auto &i : x)
    cin >> i;
  for (auto &i : y)
    cin >> i;
  sort(all(x));
  sort(all(y));
  vll xsum(n, 0), xsub(n, 0);
  for (int i = 1; i < n; i++)
    xsub.at(i) = sa(x.at(i), x.at(i - 1)) * i % mod;
  for (int i = 1; i < n; i++)
    xsum.at(i) = (xsum.at(i - 1) + xsub.at(i)) % mod;
  for (int i = 1; i < n; i++)
    (xsum.at(i) += xsum.at(i - 1)) %= mod;
  vll ysum(n, 0), ysub(n, 0);
  for (int i = 1; i < m; i++)
    ysub.at(i) = sa(y.at(i), y.at(i - 1)) * i % mod;
  for (int i = 1; i < m; i++)
    ysum.at(i) = (ysum.at(i - 1) + ysub.at(i)) % mod;
  for (int i = 1; i < m; i++)
    (ysum.at(i) += ysum.at(i - 1)) %= mod;
  //	for(auto i:xsum) cout << i << " " ; cout << endl ;
  //	for(auto i:ysum) cout << i << " " ; cout << endl ;
  cout << xsum.at(n - 1) * ysum.at(m - 1) % mod << endl;
}


Fixed submission:
#include <iomanip>
#include <iostream>
// #include <string>
#include <algorithm>
#include <vector>
// #include <utility>
// #include <set>
// #include <map>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <math.h>
using namespace std;
using ll = long long;
// using ld = long double ;
using vll = vector<ll>;
using vvll = vector<vll>;
// using vc = vector<char> ;
// using vvc = vector<vc> ;
// using vb = vector<bool> ;
// using vvb = vector<vb> ;
// using pll = pair<ll,ll> ;
#define all(v) v.begin(), v.end()
ll mod = 1000000007;
// long double pie = acos(-1) ;
// ll INF = 1000000000000 ;

// void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
// void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
// ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
// ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll sa(long long a, long long b) {
  if (a > b)
    return a - b;
  return b - a;
}
// void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
// void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
// void fix_cout(){cout << fixed << setprecision(20) ;}

int main() {
  ll n, m;
  cin >> n >> m;
  vll x(n), y(m);
  for (auto &i : x)
    cin >> i;
  for (auto &i : y)
    cin >> i;
  sort(all(x));
  sort(all(y));
  vll xsum(n, 0), xsub(n, 0);
  for (int i = 1; i < n; i++)
    xsub.at(i) = sa(x.at(i), x.at(i - 1)) * i % mod;
  for (int i = 1; i < n; i++)
    xsum.at(i) = (xsum.at(i - 1) + xsub.at(i)) % mod;
  for (int i = 1; i < n; i++)
    (xsum.at(i) += xsum.at(i - 1)) %= mod;
  vll ysum(m, 0), ysub(m, 0);
  for (int i = 1; i < m; i++)
    ysub.at(i) = sa(y.at(i), y.at(i - 1)) * i % mod;
  for (int i = 1; i < m; i++)
    ysum.at(i) = (ysum.at(i - 1) + ysub.at(i)) % mod;
  for (int i = 1; i < m; i++)
    (ysum.at(i) += ysum.at(i - 1)) %= mod;
  //	for(auto i:xsum) cout << i << " " ; cout << endl ;
  //	for(auto i:ysum) cout << i << " " ; cout << endl ;
  cout << xsum.at(n - 1) * ysum.at(m - 1) % mod << endl;
}