stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <vector>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <algorithm>



using namespace std;



#define rep(i,j) REP((i), 0, (j))

#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))

#define ALL(v) (v).begin(), (v).end()

#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))

#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)

#define MP make_pair

#define PB push_back

#define F first

#define S second

#define INF 1 << 30

#define EPS 1e-10



typedef pair<int, int> pi;

typedef pair<int, pi> pii;

typedef vector<int> vi;

typedef queue<int> qi;

typedef long long ll;



int Q;

int dp[64][64][64];



int dfs(int c, int a, int n){

  if(dp[c][a][n] >= 0) return dp[c][a][n];

  int res = 0;

  if(c > 0 && a > 0 && n > 0) res = max(res, dfs(c-1, a-1, n-1)+1);

  if(c > 1 && a > 0) res = max(res, dfs(c-2, a-1, n)+1);

  if(c > 2) res = max(res, dfs(c-3, a, n)+1);

  return dp[c][a][n] = res;

}



int main(){

  cin >> Q;

  rep(i, Q){

    memset(dp, -1, sizeof(dp));

    int c, a, n;

    cin >> c >> a >> n;

    int res = 0;

    while(c > 10 && a > 5 && n > 0){

      res++;

      c--;

      a--;

      n--;

    }



    while(c > 10 && a > 5){

      res++;

      c-=2;

      a--;

    }



    while(c > 10){

      res++;

      c-=3;

    }

    res += dfs(c, a, n);

    printf("%d\n", res);

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4627344374729145x):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <vector>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <algorithm>



using namespace std;



#define rep(i,j) REP((i), 0, (j))

#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))

#define ALL(v) (v).begin(), (v).end()

#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))

#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)

#define MP make_pair

#define PB push_back

#define F first

#define S second

#define INF 1 << 30

#define EPS 1e-10



typedef pair<int, int> pi;

typedef pair<int, pi> pii;

typedef vector<int> vi;

typedef queue<int> qi;

typedef long long ll;



int Q;

int dp[64][64][32];



int dfs(int c, int a, int n){

  if(dp[c][a][n] >= 0) return dp[c][a][n];

  int res = 0;

  if(c > 0 && a > 0 && n > 0) res = max(res, dfs(c-1, a-1, n-1)+1);

  if(c > 1 && a > 0) res = max(res, dfs(c-2, a-1, n)+1);

  if(c > 2) res = max(res, dfs(c-3, a, n)+1);

  return dp[c][a][n] = res;

}



int main(){

  cin >> Q;

  rep(i, Q){

    memset(dp, -1, sizeof(dp));

    int c, a, n;

    cin >> c >> a >> n;

    int res = 0;

    while(c > 8 && a > 4 && n > 0){

      res++;

      c--;

      a--;

      n--;

    }



    while(c > 8 && a > 4){

      res++;

      c-=2;

      a--;

    }



    while(c > 8){

      res++;

      c-=3;

    }

    res += dfs(c, a, n);

    printf("%d\n", res);

  }

  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <vector>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <algorithm>



using namespace std;



#define rep(i,j) REP((i), 0, (j))

#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))

#define ALL(v) (v).begin(), (v).end()

#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))

#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)

#define MP make_pair

#define PB push_back

#define F first

#define S second

#define INF 1 << 30

#define EPS 1e-10



typedef pair<int, int> pi;

typedef pair<int, pi> pii;

typedef vector<int> vi;

typedef queue<int> qi;

typedef long long ll;



int Q;

int dp[64][64][64];



int dfs(int c, int a, int n){

  if(dp[c][a][n] >= 0) return dp[c][a][n];

  int res = 0;

  if(c > 0 && a > 0 && n > 0) res = max(res, dfs(c-1, a-1, n-1)+1);

  if(c > 1 && a > 0) res = max(res, dfs(c-2, a-1, n)+1);

  if(c > 2) res = max(res, dfs(c-3, a, n)+1);

  return dp[c][a][n] = res;

}



int main(){

  cin >> Q;

  rep(i, Q){

    memset(dp, -1, sizeof(dp));

    int c, a, n;

    cin >> c >> a >> n;

    int res = 0;

    while(c > 8 && a > 4 && n > 0){

      res++;

      c--;

      a--;

      n--;

    }



    while(c > 8 && a > 4){

      res++;

      c-=2;

      a--;

    }



    while(c > 8){

      res++;

      c-=3;

    }

    res += dfs(c, a, n);

    printf("%d\n", res);

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4626140630801858x):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <vector>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <algorithm>



using namespace std;



#define rep(i,j) REP((i), 0, (j))

#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))

#define ALL(v) (v).begin(), (v).end()

#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))

#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)

#define MP make_pair

#define PB push_back

#define F first

#define S second

#define INF 1 << 30

#define EPS 1e-10



typedef pair<int, int> pi;

typedef pair<int, pi> pii;

typedef vector<int> vi;

typedef queue<int> qi;

typedef long long ll;



int Q;

int dp[64][64][32];



int dfs(int c, int a, int n){

  if(dp[c][a][n] >= 0) return dp[c][a][n];

  int res = 0;

  if(c > 0 && a > 0 && n > 0) res = max(res, dfs(c-1, a-1, n-1)+1);

  if(c > 1 && a > 0) res = max(res, dfs(c-2, a-1, n)+1);

  if(c > 2) res = max(res, dfs(c-3, a, n)+1);

  return dp[c][a][n] = res;

}



int main(){

  cin >> Q;

  rep(i, Q){

    memset(dp, -1, sizeof(dp));

    int c, a, n;

    cin >> c >> a >> n;

    int res = 0;

    while(c > 8 && a > 4 && n > 0){

      res++;

      c--;

      a--;

      n--;

    }



    while(c > 8 && a > 4){

      res++;

      c-=2;

      a--;

    }



    while(c > 8){

      res++;

      c-=3;

    }

    res += dfs(c, a, n);

    printf("%d\n", res);

  }

  return 0;

}
// Slower C++ solution:
//

#include<cstdio>

#include<iostream>

#include<cstdlib>

#include<ctime>

#include<cassert>

#include<algorithm>

#include<cmath>



#include<cstring>

#include<string>

#include<cctype>

#include<utility>

#include<vector>

#include<stack>

#include<queue>

#include<deque>

#include<map>

#include<set>

#include<list>



typedef long long ll;

typedef std::pair<int,int> pii;

typedef std::pair<ll,ll> pll;

typedef std::vector<int> vi;



const int OO=(int)2e9;

const ll INF=(ll)4e18;

const double EPS=(double)1e-12;



#define ff first

#define ss second

#define mp make_pair

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front



#define INL(i,a,b) ((a<=i)&&(i<=b))

#define EXL(i,a,b) ((a< i)&&(i< b))

#define REPP(i,a,b,c) for(int i=a;i<=b;i+=c)

#define REP(i,a,b) REPP(i,a,b,1)

#define REVV(i,a,b,c) for(int i=a;i>=b;i-=c)

#define REV(i,a,b) REVV(i,a,b,1)

using namespace std;



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



int n,m;

ll a,b;

ll rea,reb;



int main(){

	scanf("%d %d",&n,&m);

	rea=0;

	scanf("%lld",&a);

	REP(i,1,n-1){

		scanf("%lld",&b);

		rea=(rea+((((b-a)%MOD)*i)%MOD*((n-i)%MOD))%MOD)%MOD;

		a=b;

	}

	reb=0;

	scanf("%lld",&a);

	REP(i,1,m-1){

		scanf("%lld",&b);

		reb=(reb+((((b-a)%MOD)*i)%MOD*((m-i)%MOD))%MOD)%MOD;

		a=b;

	}

	printf("%lld\n",(rea*reb)%MOD);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.157183717024701x):
#include<cstdio>

long long x[100005];

long long y[100005];

const long long mod = 1e9+7;

int main(){

    int n,m;

    scanf("%d%d",&n,&m);

    for(int i=0;i<n;i++){

        scanf("%lld",&x[i]);

    }

    for(int i=0;i<m;i++){

        scanf("%lld",&y[i]);

    }

    long long sumx = 0;

    for(int i=0, j=n-1;j>i;i++,j--){

        sumx = (sumx + (x[j]-x[i])*(j-i))%mod;

    }

    long long sumy = 0;

    for(int i=0, j=m-1;j>i;i++,j--){

        sumy = (sumy + (y[j]-y[i])*(j-i))%mod;

    }

    printf("%lld\n",(sumx*sumy)%mod);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key

#define INF 1e9



typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef vector < pair<int, int> > vii;

typedef long double ld;

typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;



ll n, m, x, y, xx, yy;



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll MOD = 1e9+7;

	cin >> n >> m;

	for(ll i = 0; i < n; i++){

		cin >> x;

		xx+=(-(n-1)+2*i)*x;

		xx%=MOD;

	}

	for(ll i = 0; i < m; i++){

		cin >> y;

		yy+=(-(m-1)+2*i)*y;

		yy%=MOD;

	}

	cout<<(xx*yy)%MOD;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.276824866466074x):
#include<cstdio>

long long x[100005];

long long y[100005];

const long long mod = 1e9+7;

int main(){

    int n,m;

    scanf("%d%d",&n,&m);

    for(int i=0;i<n;i++){

        scanf("%lld",&x[i]);

    }

    for(int i=0;i<m;i++){

        scanf("%lld",&y[i]);

    }

    long long sumx = 0;

    for(int i=0, j=n-1;j>i;i++,j--){

        sumx = (sumx + (x[j]-x[i])*(j-i))%mod;

    }

    long long sumy = 0;

    for(int i=0, j=m-1;j>i;i++,j--){

        sumy = (sumy + (y[j]-y[i])*(j-i))%mod;

    }

    printf("%lld\n",(sumx*sumy)%mod);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define REP(i, a, b) for(int i = a; i < b; i++)

#define REP_(i, a, b) for(int i = a; i <= b; i++)

#define sl(n) scanf("%lld", &n);

#define si(n) scanf("%d", &n);

#define RepAll(a) for(auto x: a)

#define cout(ans) cout << ans << endl;

typedef long long ll;

/**

 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.yx.telstudy.xyz

 *    created:

 */

 const int mod = 1e9+7;

using namespace std;

//求解所有能组成的矩形的和再取mod

/*

    x1,y1 x5,y5

 xi -  xj , yl - yk

 xi -  xj) * (yl - yk

*/

#define N 100010

ll x[N], y[N];

ll xx, yy, maxy;

int main(){

    int n, m;



    cin >> n >> m;

  //  long long *x = long long new [n];

   // long long *y = long long new [m];



    REP(i, 0, n){

        cin >> x[i];

        /*if(i == 0){

            minx = x;

            maxx = x;

        }

        minx = min(minx, x);

        maxx = max(maxx, x);

        */

    }

    REP(i, 0, m){

        cin >> y[i];

        /*if(i == 0){

            miny = y;

            maxy = y;

        }

        miny = min(miny, y);

        maxy = max(maxy, y);

        */

    }

    //计算每个边长对面积,类似于边权？

    //cout << (maxx - minx);

    //cout << '\n' <<(maxy - miny);

    //cout << ((maxx - minx)%mod * (maxy - miny)%mod)%mod << '\n';

    //REP(i, 0, m){ }

    //yy = (yy % mod; + (y[i] - y[m - i])% mod) * (m - 2*i) % mod;

    for(int i = 0, j = m-1; j > i; j--, i++){

        yy = (yy +abs (y[i] - y[j]) * (j - i))  % mod;

    }

    for(int i = 0, j = n-1; i < j; j--, i++)

    {   xx = (xx + abs(x[i] - x[j]) * (j - i))  % mod;

     }



cout << xx*yy%mod << '\n';

}

// 9 8 7 6 5


// Faster C++ solution for the same problem (measured speedup: 5.223813647283838x):
#include<cstdio>

long long x[100005];

long long y[100005];

const long long mod = 1e9+7;

int main(){

    int n,m;

    scanf("%d%d",&n,&m);

    for(int i=0;i<n;i++){

        scanf("%lld",&x[i]);

    }

    for(int i=0;i<m;i++){

        scanf("%lld",&y[i]);

    }

    long long sumx = 0;

    for(int i=0, j=n-1;j>i;i++,j--){

        sumx = (sumx + (x[j]-x[i])*(j-i))%mod;

    }

    long long sumy = 0;

    for(int i=0, j=m-1;j>i;i++,j--){

        sumy = (sumy + (y[j]-y[i])*(j-i))%mod;

    }

    printf("%lld\n",(sumx*sumy)%mod);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define pii pair<int,int>

map<pii,int>m;



vector<int>adjb[200005],adjr[200005];





#define MOD 1000000007

int main()

{





    ll n,m,i,ANS=0,ans=0,ans2=0;

    cin>>n>>m;

    ll ara[n],arb[m];

    for(i=0;i<n;i++) cin>>ara[i];

    for(i=0;i<m;i++) cin>>arb[i];

    ll mul=-n+1;

    for(i=0;i<n;i++) {

    ara[i]=(ara[i]*mul)%MOD;

    mul+=2;

    }



    mul=-m+1;

    for(i=0;i<m;i++) {

    arb[i]=(arb[i]*mul)%MOD;

    mul+=2;

    }

    for(i=0;i<n;i++) ans=(ans+ara[i])%MOD;

    for(i=0;i<m;i++) ANS=(ANS+(arb[i]*ans)%MOD)%MOD;

    cout<<ANS;











}

// Faster C++ solution for the same problem (measured speedup: 12.088921814935354x):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair <ll, ll> pii;



#define NL cout<<"\n";

#define ALL(a) a.begin(), a.end()

#define DBG(a) cout<< #a <<" --> "<<(a)<<endl;

#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)

#define IN freopen("input.txt","r+",stdin)

#define OUT freopen("output.txt","w+",stdout)



template < class T1,class T2>

ostream &operator <<(ostream &os,const pair < T1,T2 > &p)

{

    os<<"{"<<p.first<<","<<p.second<<"}";

    return os;

}



const ll N=3e5+5;

const ll oo=1e9+7;

ll x[N],y[N];

ll yval[N];

int32_t main()

{

    FastIO;

    ll n,m;

    cin>>n>>m;

    for(ll i=0;i<n;i++)

    {

        cin>>x[i];

    }

    for(ll i=0;i<m;i++)

        cin>>y[i];

    sort(x,x+n);

    sort(y,y+m);

    ll sum = 0;

    for(ll i=1;i<m;i++)

    {

        yval[i] =( y[i] - y[i-1]) *( (i)*(m-i)%oo) %oo;

        sum+=yval[i];

        sum%=oo;

    }

    ll ans=0;

    for(ll i=1;i<n;i++)

    {

        ans += sum * ( (x[i]-x[i-1]) *( (i)*(n-i) %oo) %oo) %oo;

        ans%=oo;

    }

    ans+=oo;

    ans%=oo;

    cout<<ans<<"\n";





}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define pii pair<int,int>

map<pii,int>m;



vector<int>adjb[200005],adjr[200005];





#define MOD 1000000007

int main()

{





    ll n,m,i,ANS=0,ans=0,ans2=0;

    cin>>n>>m;

    ll ara[n],arb[m];

    for(i=0;i<n;i++) cin>>ara[i];

    for(i=0;i<m;i++) cin>>arb[i];

    ll mul=-n+1;

    for(i=0;i<n;i++) {

    ara[i]=(ara[i]*mul)%MOD;

    mul+=2;

    }



    mul=-m+1;

    for(i=0;i<m;i++) {

    arb[i]=(arb[i]*mul)%MOD;

    mul+=2;

    }

    for(i=0;i<n;i++) ans=(ans+ara[i])%MOD;

    for(i=0;i<m;i++) ANS=(ANS+(arb[i]*ans)%MOD)%MOD;

    cout<<ANS;











}

// Faster C++ solution for the same problem (measured speedup: 12.310910650341883x):
/*g++ main.cpp -o main.out*/

/*./main.out*/

/*std::ios::sync_with_stdio(false);cin.tie(0);*/



#include<bits/stdc++.h>

using namespace std;



#define LL long long

#define Mod 1000000007

#define L_Mod 17100000013



const double eps = 1e-9;

const int INF = 0x3f3f3f3f;

const double PI = 3.1415926535;



#define ree(n,a) memset(n,a,sizeof(n));



#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))

#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))

#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))



LL x[100005],y[100005];



int main()

{

    //std::ios::sync_with_stdio(false);

    int n,m;

    scanf("%d%d",&n,&m);

    rer(i,1,n)scanf("%lld",&x[i]);

    rer(i,1,m)scanf("%lld",&y[i]);

    LL a=0,b=0;

    rer(i,1,n)

    {

        a+=((2*i-1-n)*x[i])%Mod;

        a%=Mod;

    }

    rer(i,1,m)

    {

        b+=((2*i-1-m)*y[i])%Mod;

        b%=Mod;

    }

    printf("%lld\n",(a*b)%Mod);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define pii pair<int,int>

map<pii,int>m;



vector<int>adjb[200005],adjr[200005];





#define MOD 1000000007

int main()

{





    ll n,m,i,ANS=0,ans=0,ans2=0;

    cin>>n>>m;

    ll ara[n],arb[m];

    for(i=0;i<n;i++) cin>>ara[i];

    for(i=0;i<m;i++) cin>>arb[i];

    ll mul=-n+1;

    for(i=0;i<n;i++) {

    ara[i]=(ara[i]*mul)%MOD;

    mul+=2;

    }



    mul=-m+1;

    for(i=0;i<m;i++) {

    arb[i]=(arb[i]*mul)%MOD;

    mul+=2;

    }

    for(i=0;i<n;i++) ans=(ans+ara[i])%MOD;

    for(i=0;i<m;i++) ANS=(ANS+(arb[i]*ans)%MOD)%MOD;

    cout<<ANS;











}

// Faster C++ solution for the same problem (measured speedup: 12.238012709094276x):
#include <iostream>



using namespace std;



const int N = 100010;

typedef long long ll;



int n,m;

int mod = 1e9+7;

int a[N],b[N];



int main()

{

   ll num;

   ll sum1 = 0,sum2 = 0;

   cin >> n >> m;

   for (int i = 1; i <= n; i ++ )

    {

    cin >> num;

    sum1 += (i-1)*num-(n-i)*num;

    sum1 %= mod;

   }

   for (int i = 1; i <= m; i ++ )

   {

    cin >> num;

    sum2 += (i-1)*num-(m-i)*num;

    sum2 %= mod;

   }

   cout << (sum1 * sum2) % mod << endl;

   return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define pii pair<int,int>

map<pii,int>m;



vector<int>adjb[200005],adjr[200005];





#define MOD 1000000007

int main()

{





    ll n,m,i,ANS=0,ans=0,ans2=0;

    cin>>n>>m;

    ll ara[n],arb[m];

    for(i=0;i<n;i++) cin>>ara[i];

    for(i=0;i<m;i++) cin>>arb[i];

    ll mul=-n+1;

    for(i=0;i<n;i++) {

    ara[i]=(ara[i]*mul)%MOD;

    mul+=2;

    }



    mul=-m+1;

    for(i=0;i<m;i++) {

    arb[i]=(arb[i]*mul)%MOD;

    mul+=2;

    }

    for(i=0;i<n;i++) ans=(ans+ara[i])%MOD;

    for(i=0;i<m;i++) ANS=(ANS+(arb[i]*ans)%MOD)%MOD;

    cout<<ANS;











}

// Faster C++ solution for the same problem (measured speedup: 12.393392255131461x):
/*

    Written by Nitrogens

    Desire for getting accepted!!

*/

#include <cstdio>

#include <ctime>

#include <cstring>

#include <cmath>

#include <cstdlib>

#include <iostream>

#include <algorithm>

#include <queue>

#include <map>

#include <bitset>

#include <stack>

#include <set>

#include <vector>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef double db;

typedef pair <int, int> pii;

typedef pair <ll, ll> pll;

typedef pair <ll, int> pli;

typedef pair <db, db> pdd;



const int maxn = 1e5+5;

const int Mod = 1000000007;

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

const double e = exp(1);

const db PI = acos(-1);

const db ERR = 1e-10;



#define Se second

#define Fi first

#define pb push_back

#define dbg(x) cout<<#x<<" = "<< (x)<< endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl



ll x[maxn], y[maxn];

ll a[maxn], b[maxn];



ll sum(ll n) {

    return n * (n + 1) / 2 % Mod;

}



int main()

{

    //ios::sync_with_stdio(false);

    //freopen("a.txt","r",stdin);

    //freopen("b.txt","w",stdout);



    int n, m;

    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);

    for (int i = 1; i <= m; i++) scanf("%lld", &y[i]);

    for (int i = 1; i < n; i++) a[i] = (x[i + 1] - x[i] + Mod) % Mod;

    for (int i = 1; i < m; i++) b[i] = (y[i + 1] - y[i] + Mod) % Mod;

    n--, m--;

    ll X = 0, Y = 0;

    for (int i = 1; i <= n; i++) {

        ll cnt = sum(n) - sum(i - 1) - sum(n - i);

        cnt %= Mod;

        cnt = (cnt + Mod) % Mod;

        ll delta = cnt * a[i] % Mod;

        X = (X + delta) % Mod;

    }

    for (int i = 1; i <= m; i++) {

        ll cnt = sum(m) - sum(i - 1) - sum(m - i);

        cnt %= Mod;

        cnt = (cnt + Mod) % Mod;

        ll delta = cnt * b[i] % Mod;

        Y = (Y + delta) % Mod;

    }

    ll ans = X * Y % Mod;

    printf("%lld\n", ans);



    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define pii pair<int,int>

map<pii,int>m;



vector<int>adjb[200005],adjr[200005];





#define MOD 1000000007

int main()

{





    ll n,m,i,ANS=0,ans=0,ans2=0;

    cin>>n>>m;

    ll ara[n],arb[m];

    for(i=0;i<n;i++) cin>>ara[i];

    for(i=0;i<m;i++) cin>>arb[i];

    ll mul=-n+1;

    for(i=0;i<n;i++) {

    ara[i]=(ara[i]*mul)%MOD;

    mul+=2;

    }



    mul=-m+1;

    for(i=0;i<m;i++) {

    arb[i]=(arb[i]*mul)%MOD;

    mul+=2;

    }

    for(i=0;i<n;i++) ans=(ans+ara[i])%MOD;

    for(i=0;i<m;i++) ANS=(ANS+(arb[i]*ans)%MOD)%MOD;

    cout<<ANS;











}

// Faster C++ solution for the same problem (measured speedup: 12.410273394545232x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int MAXN = 1e5 + 7;

const int mod = 1e9 + 7;

ll x[MAXN], y[MAXN];

inline ll add(ll x, ll y) {return (x + y) % mod;}

inline ll mul(ll x, ll y) {return (x * y) % mod;}

int main()

{

    int n, m; scanf("%d%d", &n, &m);

    ll sum = 0;

    for (int i = 1; i <= n; i++) 

    {

        scanf("%lld", &x[i]);

        sum = add(sum, mul(x[i] - x[i - 1], mul(i - 1, n - i + 1)));

    }

    ll ans = 0;

    for (int i = 1; i <= m; i++)

    {

        scanf("%lld", &y[i]);

        ans = add(ans, mul(sum, mul(y[i] - y[i - 1], mul(i - 1, m - i + 1))));

    }

    printf("%lld\n", ans);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define pii pair<int,int>

map<pii,int>m;



vector<int>adjb[200005],adjr[200005];





#define MOD 1000000007

int main()

{





    ll n,m,i,ANS=0,ans=0,ans2=0;

    cin>>n>>m;

    ll ara[n],arb[m];

    for(i=0;i<n;i++) cin>>ara[i];

    for(i=0;i<m;i++) cin>>arb[i];

    ll mul=-n+1;

    for(i=0;i<n;i++) {

    ara[i]=(ara[i]*mul)%MOD;

    mul+=2;

    }



    mul=-m+1;

    for(i=0;i<m;i++) {

    arb[i]=(arb[i]*mul)%MOD;

    mul+=2;

    }

    for(i=0;i<n;i++) ans=(ans+ara[i])%MOD;

    for(i=0;i<m;i++) ANS=(ANS+(arb[i]*ans)%MOD)%MOD;

    cout<<ANS;











}

// Faster C++ solution for the same problem (measured speedup: 12.101484452889823x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

const ll mod = 1e9 + 7;



ll add(ll a, ll b) {

	return ((a%mod) + (b%mod)) % mod;

}





ll sub(ll a, ll b) {

	return ((a%mod) - (b%mod) + mod) % mod;

}





ll mul(ll a, ll b) {

	return ((a%mod)*(b%mod)) % mod;

}





int main() {

	int n, m;

	cin >> n >> m;

	vector<ll> X, Y;

	ll totalX = 0, totalY = 0;

	for (int i = 0; i < n; i++) {

		ll x;

		cin >> x;

		X.push_back(x);

		totalX += x;

	}

	for (int i = 0; i < m; i++) {

		ll y;

		cin >> y;

		Y.push_back(y);

		totalY += y;

	}

	ll ans = 0;

	ll sumX = 0;

	sort(X.rbegin(), X.rend());

	sort(Y.rbegin(), Y.rend());

	for (int i = 0; i < n; i++) {

		sumX = add(sumX, sub(mul(n - i, X[i]), totalX));

		totalX -= X[i];

	}

	for (int i = 0; i < m; i++) {

		ll b = sub(mul(m - i, Y[i]), totalY);

		ans = add(ans, mul(sumX, b));

		totalY -= Y[i];

	}

	cout << ans;









}