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

#define Fi first
#define Se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)
typedef tuple<int, int, int> t3;

int N, A[100010], B[100010];

int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%d", A + i);
	for(int i=1;i<=N;i++) scanf("%d", B + i);
	priority_queue <ll> pq;
	ll at = 0;
	for(int i=1;i<=N;i++) {
		if(i & 1) {
			at += B[i];
			pq.push(A[i] - B[i]);
		}
		else {
			at += A[i];
			pq.push(B[i] - A[i]);
		}
	}
	rep(i, N / 2) at += pq.top(), pq.pop();
	printf("%lld\n", at);
	return 0;
}
#include "bits/stdc++.h"

using namespace std;

const int mod = 1e9 + 7;

void solve() {
	int n;
	cin >> n;

	long long dp[2] = {0}, cnt[2] = {0};
		
	cnt[1] = 1;
	
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;

		auto x = dp[1];
		auto y = cnt[1];
		
		dp[1] = (dp[0] - cnt[0] * a) % mod;
		cnt[1] = cnt[0];
				
		dp[0] = (dp[0] + x + a * (y + cnt[0])) % mod;
		cnt[0] = (cnt[0] + y) % mod;
	}
	
	cout << ((dp[0] + dp[1]) % mod + mod) % mod << '\n'; 
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}