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

ll n,ans=0;
set<pair<ll,ll>> e,o;
pair<ll,ll> w,x,y,z;

int main(){
	cin>>n;
	ll a[n],b[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++){
		if(i%2==0)e.insert({a[i]-b[i],i});
		else o.insert({a[i]-b[i],i});
	}
	for(int i=0;i<n/2;i++){
		w=*begin(e),x=*begin(o),y=*rbegin(e),z=*rbegin(o);
		if(-w.first-x.first>=y.first+z.first){ans+=b[w.second]+b[x.second];e.erase(w);o.erase(x);}
		else{ans+=a[y.second]+a[z.second];e.erase(y);o.erase(z);}
	}
	cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n)  for(ll i = 0; i < (n); ++i)
#define rep1(i,n)  for(ll i = 1;i <= (n); ++i)
#define pb push_back
#define noofones(a) __builtin_popcount(a)

#define f first
#define s second
#define M 1000000007



int main()
{

    fastIO
   ll n;
   cin>>n;
   map<ll,ll>mp;
   vector<ll>v;
   for(int i=0;i<n;i++)
   {
   ll e;cin>>e;
   mp[e]++;
   v.pb(e);
   }
   ll res=0;
   for(int i=0;i<n;i++)
   {

       mp[v[i]]--;
    ll cnt=mp[v[i]];

    ll rem=n-i-1;
    rem-=cnt;
    res+=rem;
   }
   cout<<res;



	return 0;
}
