#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;

int N;
int A[10010];

signed main() {
    //ループ変数が被っていないか?
    //制約を確認しているか?
    //変数のtypoがないか?
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> A[i];
    vector<P> v;
    rep(i, N) v.pb(P(A[i], i));
    sort(v.begin(), v.end());
    set<int> s;
    s.insert(-1); s.insert(N);
    
    int ans = 0;
    rep(i, N) {
        int val = v[i].first;
        int idx = v[i].second;
        auto it = s.lower_bound(idx);
        int r = *it;
        int l = *--it;
        ans = max(ans, (r-l-1)*val);
        //cout << idx << " " << val << " " << l << " " << r << endl;
        s.insert(idx);
    }
    
    cout << ans << endl;
}
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << (x) << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1e5 + 7;

int a[N], b[N];

signed main()
{
	IO_OP;

	int n;
	cin >> n;
	ll sum = 0;
	V<pi> v;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) {
		cin >> b[i];
		sum += b[i];
		v.EB(a[i] - b[i], i & 1);
	}
	sort(ALL(v), greater<pi>());
	ll cur = 0, mx = 0;
	queue<int> q[2];
	for(pi p:v) {
		q[p.S].push(p.F);
		if(q[0].size() && q[1].size()) {
			cur += q[0].front() + q[1].front();
			q[0].pop(), q[1].pop();
		}
		mx = max(mx, cur);
	}
	cout << mx + sum << endl;
}

