#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	long long mod=(1e+9)+7;
	long long n,m;
	cin>>n>>m;
	static long long sum_x,sum_y;
	vector<long long> x(n+10),y(m+10);
	for(ll i=1;i<=n;i++) cin>>x[i];
	for(ll i=1;i<=m;i++) cin>>y[i];
	for(ll xx=1;xx<=n;xx++){
		sum_x+=(2*xx-n-1)*x[xx];
		sum_x%=mod;
	}
	for(ll yy=1;yy<=m;yy++){
		sum_y+=(2*yy-m-1)*y[yy];
		sum_y%=mod;
	}
	cout<<(sum_x*sum_y)%mod<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 5e5 + 2;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, x;
    cin >> n >> x;
    ll a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    ll sum = 0;
    for (int i = 0; i <= x; i++) {
        for (int j = 0; i + j <= min(n, x); j++) {
            priority_queue<ll, vector<ll>, greater<ll>> pq;
            for (int k = 0; k < i; k++)
                pq.push(a[k]);
            for (int k = n - 1, c = 0; c < j; c++, k--)
                pq.push(a[k]);
            for (int k = i + j; k < x; k++) {
                if (!pq.empty() && pq.top() < 0) pq.pop();
            }
            ll val = 0;
            while(!pq.empty()) val += pq.top(), pq.pop();
            sum = max(sum, val);
        }
    }
    cout << sum;
    return 0;
}