stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

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

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

#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])

using namespace std;

typedef long long i64;

typedef unsigned long long u64;

typedef unsigned u32;

typedef pair<int,int> pin;

#define mk(a,b) make_pair(a,b)

#define lowbit(x) ((x)&(-(x)))

#define sqr(a) ((a)*(a))

#define clr(a) (memset((a),0,sizeof(a)))

#define ls ((x)<<1)

#define rs (((x)<<1)|1)

#define mid (((l)+(r))>>1)

#define pb push_back

#define w1 first

#define w2 second

inline void read(int &x){

	x=0;int f=1;char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}

	x*=f;

}

inline void judge(){

	freopen("in.txt","r",stdin);

	freopen("out.txt","w",stdout);

}

/*******************************head*******************************/

const int maxn=200005;

int n,a[maxn],b[maxn];

inline bool check(int k){

	rep(i,1,2*n-1)b[i]=(a[i]>=k);

	int l=n,r=n;

	while(l>1&&b[l-1]!=b[l])l--;

	while(r<2*n-1&&b[r+1]!=b[r])r++;

	if(l==1&&r==2*n-1){

		return (n&1)?b[n]:(b[n]^1);

	}

	return n-l<r-n?b[l]:b[r];

}

int main(){

	//judge();

	read(n);rep(i,1,2*n-1)read(a[i]);

	int l=1,r=2*n-1,ans;

	while(l<=r){

		int md=(l+r)>>1;

		if(check(md)){

			ans=md;l=md+1;

		}else

			r=md-1;

	}printf("%d\n",ans);

	return 0;

}

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

using namespace std;

int N,A[200005],a[200005],l=1,r=200000,mid;

bool check(int n)

{

	int re=-1;

	for(int i=1;i<=N*2-1;i++)

	if(A[i]>=n)

	a[i]=1;

	else

	a[i]=0;

	for(int i=1;i<=N-1;i++)

	{

		if(a[N+i]==a[N+i-1])

		{

			re=a[N+i];

			break;

		}

		if(a[N-i]==a[N-i+1])

		{

			re=a[N-i];

			break;

		}

	}

	if(re!=-1)

	return re;

	else

	return a[1];

}

int main()

{

	scanf("%d",&N);

	for(int i=1;i<=N*2-1;i++)

	scanf("%d",&A[i]);

	while(l+1<r)

	{

		mid=(l+r)/2;

		if(check(mid))

		l=mid;

		else

		r=mid;

	}

	printf("%d",l);

	return 0;

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



#define f first 

#define s second 

#define pb push_back               

#define all(x) x.begin(), x.end())



using namespace std;                    



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<long long, long long> pll;



const int N = (int)1e6 + 123, mod = (int)1e9 + 7, inf = (int)1e9, LOG = 18;

const ll INF = (ll)1e8;

const double eps = 1e-9;



int n, a[N], b[N];

bool check(int x){

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

		if(a[i] <= x)

			b[i] = 0;

		else

			b[i] = 1;

	

	bool ok1, ok2;

	ok1 = 1;         

	ok2 = 1;        

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

		if(b[i] == i % 2)

			ok1 = 0;

	 	else

			ok2 = 0;

    

    if(ok1 || ok2){

		int cnt = (n + 1) / 2 - 1;

        return b[n/2 + 1] ^ (cnt & 1);

	}

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

		if(b[n / 2 + 1 + i] == b[n / 2 + 1 - i] && b[n / 2 + 1 + i] != b[n / 2  + i])

			continue;               

		if(b[n / 2 + 1 + i] == b[n / 2  + i])

			return b[n / 2 + 1 + i];

		else

			return b[n / 2 + 1 - i]; 

	}

}

int main(){

	cin >> n;

	n = n + n - 1;

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

		cin >> a[i];

	int l = 1, r = n;

	while(l <= r){

		int m = l + r >> 1;

		if(check(m))

			l = m + 1;

		else

			r = m - 1;

	}

	cout << l;

}

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

using namespace std;

int N,A[200005],a[200005],l=1,r=200000,mid;

bool check(int n)

{

	int re=-1;

	for(int i=1;i<=N*2-1;i++)

	if(A[i]>=n)

	a[i]=1;

	else

	a[i]=0;

	for(int i=1;i<=N-1;i++)

	{

		if(a[N+i]==a[N+i-1])

		{

			re=a[N+i];

			break;

		}

		if(a[N-i]==a[N-i+1])

		{

			re=a[N-i];

			break;

		}

	}

	if(re!=-1)

	return re;

	else

	return a[1];

}

int main()

{

	scanf("%d",&N);

	for(int i=1;i<=N*2-1;i++)

	scanf("%d",&A[i]);

	while(l+1<r)

	{

		mid=(l+r)/2;

		if(check(mid))

		l=mid;

		else

		r=mid;

	}

	printf("%d",l);

	return 0;

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



using namespace std;

int n;

int a[200005];

int f[200005];

int Check(int x)

{

	for(int i=1;i<=2*n-1;++i)

	{

		if(a[i]>=x)

		{

			f[i]=1;

		}

		else

		{

			f[i]=0;

		}

	}

	int nst=-1,nds=291433;

	for(int i=2;i<=2*n-1;++i)

	{

		if(f[i]==f[i-1])

		{

			if(min(abs(n-i+1),abs(n-i))<nds)

			{

				nds=min(abs(n-i),abs(n-i+1));

				nst=f[i];

			}

		}

	}

	if(nst==-1)

	{

		return f[1];

	}

	return nst;

}



int main()

{

	scanf("%d",&n);

	for(int i=1;i<=2*n-1;++i)

	{

		scanf("%d",&a[i]);

	}

	int l=1,r=2*n-1;

	while(l+1<r)

	{

		int mid=(l+r)/2;

		if(Check(mid))

		{

			l=mid;

		}	

		else

		{

			r=mid;

		}

	}

	printf("%d",l);

	return 0;

}

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

using namespace std;

int N,A[200005],a[200005],l=1,r=200000,mid;

bool check(int n)

{

	int re=-1;

	for(int i=1;i<=N*2-1;i++)

	if(A[i]>=n)

	a[i]=1;

	else

	a[i]=0;

	for(int i=1;i<=N-1;i++)

	{

		if(a[N+i]==a[N+i-1])

		{

			re=a[N+i];

			break;

		}

		if(a[N-i]==a[N-i+1])

		{

			re=a[N-i];

			break;

		}

	}

	if(re!=-1)

	return re;

	else

	return a[1];

}

int main()

{

	scanf("%d",&N);

	for(int i=1;i<=N*2-1;i++)

	scanf("%d",&A[i]);

	while(l+1<r)

	{

		mid=(l+r)/2;

		if(check(mid))

		l=mid;

		else

		r=mid;

	}

	printf("%d",l);

	return 0;

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

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

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

#define S(i) ((int)(A[i]>=Pos))

#define LL long long

using namespace std;

int N,A[300001],INF=10000000;

bool Check(int Pos){

	int m[2];

	m[0]=m[1]=INF;

//	For(i,1,2*N-1) printf("%d ",S(i));puts("");

	For(i,N,2*N-2)

		if(S(i)==S(i+1)){

			m[S(i)]=min(m[S(i)],i-N);

//			cout<<'-'<<i<<' '<<S(i)<<endl;

			break;

		}

	Rof(i,N,2)

		if(S(i)==S(i-1)){

			m[S(i)]=min(m[S(i)],N-i);

			break;

		}

//	cout<<m[1]<<' '<<m[0]<<endl;

	if(m[0]==INF&&m[1]==INF)return (S(N)^(N&1)^1);

	if(m[1]<m[0])return 1;

	return 0;

}

int main(){

	scanf("%d",&N);For(i,1,2*N-1) scanf("%d",&A[i]);

	int l=1,r=2*N-1,Mid,Ans;

//	cout<<Check(4);



	while(l<=r){

		Mid=l+r>>1;

		if(Check(Mid))

			Ans=Mid,l=Mid+1;

		else

			r=Mid-1;

	}



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



	return 0;

}

/*

3

1 5 2 4 3

*/

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

using namespace std;

int N,A[200005],a[200005],l=1,r=200000,mid;

bool check(int n)

{

	int re=-1;

	for(int i=1;i<=N*2-1;i++)

	if(A[i]>=n)

	a[i]=1;

	else

	a[i]=0;

	for(int i=1;i<=N-1;i++)

	{

		if(a[N+i]==a[N+i-1])

		{

			re=a[N+i];

			break;

		}

		if(a[N-i]==a[N-i+1])

		{

			re=a[N-i];

			break;

		}

	}

	if(re!=-1)

	return re;

	else

	return a[1];

}

int main()

{

	scanf("%d",&N);

	for(int i=1;i<=N*2-1;i++)

	scanf("%d",&A[i]);

	while(l+1<r)

	{

		mid=(l+r)/2;

		if(check(mid))

		l=mid;

		else

		r=mid;

	}

	printf("%d",l);

	return 0;

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

#include<cstdio>

using namespace std;



int n,a[200005];



inline bool check(const int &k){

    if((a[n-1]<=k&&a[n]<=k)||(a[n]<=k&&a[n+1]<=k))return 1;

    if((a[n-1]> k&&a[n]> k)||(a[n]> k&&a[n+1]> k))return 0;

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

        if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))return 1;

        if((a[n+i]> k&&a[n+i+1]> k)||(a[n-i]> k&&a[n-i-1]> k))return 0;

    }

    return a[1]<=k;

}



int main(){

    scanf("%d",&n);

    for(int i=1;i<n<<1;i++)scanf("%d",a+i);

    int l=1,r=(n<<1)-1;

    while(l<r){

        int mid=l+r>>1;

        if(check(mid))r=mid;

        else l=mid+1;

    }

    printf("%d",l);

}

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

using namespace std;

int N,A[200005],a[200005],l=1,r=200000,mid;

bool check(int n)

{

	int re=-1;

	for(int i=1;i<=N*2-1;i++)

	if(A[i]>=n)

	a[i]=1;

	else

	a[i]=0;

	for(int i=1;i<=N-1;i++)

	{

		if(a[N+i]==a[N+i-1])

		{

			re=a[N+i];

			break;

		}

		if(a[N-i]==a[N-i+1])

		{

			re=a[N-i];

			break;

		}

	}

	if(re!=-1)

	return re;

	else

	return a[1];

}

int main()

{

	scanf("%d",&N);

	for(int i=1;i<=N*2-1;i++)

	scanf("%d",&A[i]);

	while(l+1<r)

	{

		mid=(l+r)/2;

		if(check(mid))

		l=mid;

		else

		r=mid;

	}

	printf("%d",l);

	return 0;

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

using namespace std;

typedef long long ll;

#define D 1000000007

 

int main(){

 ll n,m,x[100001]={},y[100001]={}; 

 cin>>n>>m;

 

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

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

 

ll X=0,Y=0;

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

  X=(X+((x[i+1]-x[i])*((i+1)*(n-i-1))%D)%D)%D;

 

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

  Y=(Y+((y[i+1]-y[i])*((i+1)*(m-i-1))%D)%D)%D;

 

 cout<<(X*Y)%D<<endl;

 return 0;

}

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

#include <string>

#include <algorithm>

using namespace std;

typedef long long ll;

ll x[100001] = {};

ll y[100001] = {};

const ll mod = (int)1e9 + 7;

int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);



    ll n, m;

    cin >> n >> m;



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

        cin >> x[i];

    ll width = x[n - 1] - x[0];

    

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

        cin >> y[i];

    ll height = y[m - 1] - y[0];



    ll sum1 = 0, sum2 = 0;

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

        sum1 = (sum1 + ((x[i + 1] - x[i]) * ((i + 1) * (n - i - 1)) % mod) % mod) % mod;

    }

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

        sum2 = (sum2 + ((y[i + 1] - y[i]) * ((i + 1) * (m - i - 1)) % mod) % mod) % mod;        

    }

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



    return 0;

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

const int maxn=1e5+5;

const int mod=1e9+7;

#define ll long long

using namespace std;

ll a[maxn],b[maxn];

ll aa[maxn],bb[maxn];

int main()

{

    int i,j,n,m;

    ll h=0,w=0;

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

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

    {

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

    }

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

    {

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

    }

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

//    {

//        scanf("%d",&a[i]);

//        aa[i]=aa[i-1]+a[i];

//    }

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

//    {

//        scanf("%d",&b[i]);

//        bb[i]=bb[i-1]+b[i];

//    }

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

//    {

//        h+=aa[n]-aa[i]-(a[i]%mod*(n-i)%mod)%mod;

//        if(h>=mod) h-=mod;

//    }

//    cout<<h<<endl;

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

//    {

//        w+=bb[m]-bb[i]-b[i]*(m-i);

//        if(w>=mod) w-=mod;

//    }

//    cout<<w<<endl;

    for(int l=1, r=n; l<r; ++l,--r)

        w = (w + (a[r]-a[l])*(r-l))%mod;

    for(int l=1, r=m; l<r; ++l,--r)

        h = (h + (b[r]-b[l])*(r-l))%mod;

    cout<<(w*h)%mod<<endl;

    return 0;

}

/*622259192

993828220*/


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

#define LL long long

#define N 100010

LL n,m,a[N],b[N];

signed main()

{

	scanf("%lld%lld",&n,&m);LL x(0),y(0),mod(1e9+7);

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

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

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

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

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

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

	for(register int i(1),j(m);i<j;i++,j--)

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

	return printf("%lld\n",x*y%mod),0;

}
// Slower C++ solution:
/*

confirm 0LL and 1LL

confirm cornercases such as 0

confirm times of cin < 10^6

*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

using P = pair<ll, ll>;

using Pld = pair<ld, ld>;

using Vec = vector<ll>;

using VecP = vector<P>;

using VecB = vector<bool>;

using VecC = vector<char>;

using VecD = vector<ld>;

using VecS = vector<string>;

using VecVec = vector<Vec>;

using Graph = vector<VecP>;

template <typename T>

using Vec1 = vector<T>;

template <typename T>

using Vec2 = vector<Vec1<T> >;

#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))

#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))

#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))

#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))

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

#define repn(i, n) REPN(i, 1, n)

#define repr(i, n) REPR(i, n, 0)

#define repnr(i, n) REPNR(i, n, 1)

#define all(s) (s).begin(), (s).end()

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

template <typename T>

bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}

template <typename T>

bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}

template <typename T>

void co(const T n){cout << n << endl;}

template <typename T>

void cosp(const T n){cout << n << ' ';}

void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}

ll in(){ll x; cin >> x; return x;}

void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}

void setp(const ll n){cout << fixed << setprecision(n);}

const ll INF = 1e9+1;

const ll LINF = 1e18+1;

const ll MOD = 1e9+7;

//const ll MOD = 998244353;

const ld PI = acos(-1);

const ld EPS = 1e-11;



int main(void){

	ll n, m;

	cin >> n >> m;

	Vec x(n), y(m);

	rep(i, n) cin >> x[i];

	rep(i, m) cin >> y[i];

	sort(all(x));

	sort(all(y));



	ll sumx = 0;

	rep(i, n){

		sumx += x[i]*(i*2-(n-1));

		sumx %= MOD;

	}

	ll sumy = 0;

	rep(i, m){

		sumy += y[i]*(i*2-(m-1));

		sumy %= MOD;

	}

	co(sumx*sumy%MOD);



	return 0;

}


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

#define MOD 1000000007



int main(void){

	long i, j, n, m;

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

	long x[n], y[m];

	for(i = 0; i < n; i++) scanf("%ld", &x[i]);

	for(i = 0; i < m; i++) scanf("%ld", &y[i]);



	long sumx = 0;

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

		sumx += x[i]*(i*2-(n-1));

		sumx %= MOD;

	}

	long sumy = 0;

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

		sumy += y[i]*(i*2-(m-1));

		sumy %= MOD;

	}

	printf("%ld\n", sumx*sumy%MOD);



	return 0;

}
// Slower C++ solution:
/*

confirm 0LL and 1LL

confirm cornercases such as 0

confirm times of cin < 10^6

*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

using P = pair<ll, ll>;

using Pld = pair<ld, ld>;

using Vec = vector<ll>;

using VecP = vector<P>;

using VecB = vector<bool>;

using VecC = vector<char>;

using VecD = vector<ld>;

using VecS = vector<string>;

using VecVec = vector<Vec>;

using Graph = vector<VecP>;

template <typename T>

using Vec1 = vector<T>;

template <typename T>

using Vec2 = vector<Vec1<T> >;

#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))

#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))

#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))

#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))

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

#define repn(i, n) REPN(i, 1, n)

#define repr(i, n) REPR(i, n, 0)

#define repnr(i, n) REPNR(i, n, 1)

#define all(s) (s).begin(), (s).end()

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

template <typename T>

bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}

template <typename T>

bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}

template <typename T>

void co(const T n){cout << n << endl;}

template <typename T>

void cosp(const T n){cout << n << ' ';}

void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}

ll in(){ll x; cin >> x; return x;}

void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}

void setp(const ll n){cout << fixed << setprecision(n);}

const ll INF = 1e9+1;

const ll LINF = 1e18+1;

const ll MOD = 1e9+7;

//const ll MOD = 998244353;

const ld PI = acos(-1);

const ld EPS = 1e-11;



int main(void){

	ll n, m;

	cin >> n >> m;

	Vec x(n), y(m);

	rep(i, n) cin >> x[i];

	rep(i, m) cin >> y[i];



	ll sumx = 0;

	rep(i, n){

		sumx += x[i]*(i*2-(n-1));

		sumx %= MOD;

	}

	ll sumy = 0;

	rep(i, m){

		sumy += y[i]*(i*2-(m-1));

		sumy %= MOD;

	}

	co(sumx*sumy%MOD);



	return 0;

}


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

#define MOD 1000000007



int main(void){

	long i, j, n, m;

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

	long x[n], y[m];

	for(i = 0; i < n; i++) scanf("%ld", &x[i]);

	for(i = 0; i < m; i++) scanf("%ld", &y[i]);



	long sumx = 0;

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

		sumx += x[i]*(i*2-(n-1));

		sumx %= MOD;

	}

	long sumy = 0;

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

		sumy += y[i]*(i*2-(m-1));

		sumy %= MOD;

	}

	printf("%ld\n", sumx*sumy%MOD);



	return 0;

}
// Slower C++ solution:
/*

confirm 0LL and 1LL

confirm cornercases such as 0

confirm times of cin < 10^6

*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

using P = pair<ll, ll>;

using Pld = pair<ld, ld>;

using Vec = vector<ll>;

using VecP = vector<P>;

using VecB = vector<bool>;

using VecC = vector<char>;

using VecD = vector<ld>;

using VecS = vector<string>;

using VecVec = vector<Vec>;

using Graph = vector<VecP>;

template <typename T>

using Vec1 = vector<T>;

template <typename T>

using Vec2 = vector<Vec1<T> >;

#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))

#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))

#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))

#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))

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

#define repn(i, n) REPN(i, 1, n)

#define repr(i, n) REPR(i, n, 0)

#define repnr(i, n) REPNR(i, n, 1)

#define all(s) (s).begin(), (s).end()

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

template <typename T>

bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}

template <typename T>

bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}

template <typename T>

void co(const T n){cout << n << endl;}

template <typename T>

void cosp(const T n){cout << n << ' ';}

void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}

ll in(){ll x; cin >> x; return x;}

void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}

void setp(const ll n){cout << fixed << setprecision(n);}

const ll INF = 1e9+1;

const ll LINF = 1e18+1;

const ll MOD = 1e9+7;

//const ll MOD = 998244353;

const ld PI = acos(-1);

const ld EPS = 1e-11;



int main(void){

	sonic();

	ll n, m;

	cin >> n >> m;

	Vec x(n), y(m);

	rep(i, n) cin >> x[i];

	rep(i, m) cin >> y[i];



	ll sumx = 0;

	rep(i, n){

		sumx += x[i]*(i*2-(n-1));

		sumx %= MOD;

	}

	ll sumy = 0;

	rep(i, m){

		sumy += y[i]*(i*2-(m-1));

		sumy %= MOD;

	}

	co(sumx*sumy%MOD);



	return 0;

}


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

#define MOD 1000000007



int main(void){

	long i, j, n, m;

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

	long x[n], y[m];

	for(i = 0; i < n; i++) scanf("%ld", &x[i]);

	for(i = 0; i < m; i++) scanf("%ld", &y[i]);



	long sumx = 0;

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

		sumx += x[i]*(i*2-(n-1));

		sumx %= MOD;

	}

	long sumy = 0;

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

		sumy += y[i]*(i*2-(m-1));

		sumy %= MOD;

	}

	printf("%ld\n", sumx*sumy%MOD);



	return 0;

}
// Slower C++ solution:
/*

confirm 0LL and 1LL

confirm cornercases such as 0

confirm times of cin < 10^6

*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

using P = pair<ll, ll>;

using Pld = pair<ld, ld>;

using Vec = vector<ll>;

using VecP = vector<P>;

using VecB = vector<bool>;

using VecC = vector<char>;

using VecD = vector<ld>;

using VecS = vector<string>;

using VecVec = vector<Vec>;

using Graph = vector<VecP>;

template <typename T>

using Vec1 = vector<T>;

template <typename T>

using Vec2 = vector<Vec1<T> >;

#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))

#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))

#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))

#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))

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

#define repn(i, n) REPN(i, 1, n)

#define repr(i, n) REPR(i, n, 0)

#define repnr(i, n) REPNR(i, n, 1)

#define all(s) (s).begin(), (s).end()

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

template <typename T>

bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}

template <typename T>

bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}

template <typename T>

void co(const T n){cout << n << endl;}

template <typename T>

void cosp(const T n){cout << n << ' ';}

void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}

ll in(){ll x; cin >> x; return x;}

void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}

void setp(const ll n){cout << fixed << setprecision(n);}

const ll INF = 1e9+1;

const ll LINF = 1e18+1;

const ll MOD = 1e9+7;

//const ll MOD = 998244353;

const ld PI = acos(-1);

const ld EPS = 1e-11;



int main(void){

	ll n, m;

	cin >> n >> m;

	Vec x(n), y(m);

	rep(i, n) cin >> x[i];

	rep(i, m) cin >> y[i];

	sort(all(x));

	sort(all(y));



	ll sumx = 0;

	rep(i, n){

		sumx += x[i]*(i*2-(n-1));

		sumx %= MOD;

	}

	ll sumy = 0;

	rep(i, m){

		sumy += y[i]*(i*2-(m-1));

		sumy %= MOD;

	}

	co(sumx*sumy%MOD);



	return 0;

}


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

#define MOD 1000000007



int main(void){

	long i, j, n, m;

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

	long x[n], y[m];

	for(i = 0; i < n; i++) scanf("%ld", &x[i]);

	for(i = 0; i < m; i++) scanf("%ld", &y[i]);



	long sumx = 0;

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

		sumx += x[i]*(i*2-(n-1));

		if(sumx > 1e18 || sumx < -1e18) sumx %= MOD;

	}

	sumx %= MOD;

	long sumy = 0;

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

		sumy += y[i]*(i*2-(m-1));

		if(sumy > 1e18 || sumy < -1e18) sumy %= MOD;

	}

	sumy %= MOD;

	printf("%ld\n", sumx*sumy%MOD);



	return 0;

}