#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define qll queue<ll>
#define sll set<ll>
//(a/b)%mod = (a%mod*powermod(b,mod-2,mod))%mod
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                    //n is odd
        return x*power(x*x,(n-1)/2);
}
int highestPowerof2(int n)
{
    int p = (int)log2(n);
    return (int)pow(2, p);
}
ll powermod(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)  
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;
    }
return res;
}
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    ll i,val=0,ans;
    vector<int>mx(n,0);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    mx[0]=a[0];
    ll  res=a[0];
     
     for(i=0;i<n;i++)
     {
         res=max(a[i],res);
         mx[i]=res;
     }
     
     ans=a[0]*b[0];
     cout<<ans<<endl;
     ll  ans1=ans;
     for(i=1;i<n;i++)
     {
         ans1=max(ans1,b[i]*mx[i]);
         
         cout<<ans1<<endl;
     }

}
#include <iostream>
#include <set>

#define int long long

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int ans = 0;
  std::set<std::pair<int, int> > chosen;

  int n;
  std::cin >> n;

  int m = 2*n-1;
  int a[2*n];
  for(int i = 0; i < 2*n; i++)
    std::cin >> a[i];

  for(int i = n-1; i >= 0; i--) {
    std::pair<int, int> x = {a[i], i}, y = {a[m-i], m-i};
    std::pair<int, int> next = std::max(x, y);

    ans += next.first;
    chosen.insert(next);
    
    std::pair<int, int> nopt = std::min(x, y);
    if((*chosen.begin()).first < nopt.first) {
      ans -= (*chosen.begin()).first;
      chosen.erase(chosen.begin());
      chosen.insert(nopt);
      ans += nopt.first;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

