#include<bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
#define cppio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;

const int maxn=2e5+5;
const ll inf=0x3f3f3f3f;
const ll mod=1e9+7;

int a[maxn],b[maxn];

int main(){
	int n;
	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);
	}
	int l=0,r=1010;
	for(int i=1;i<=n;i++){
		l=max(a[i],l);
		r=min(b[i],r);
	}
	printf("%d\n",max(0,r-l+1));
	return 0;
}
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define l long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n+1];
    ll sum=0;
    vector<ll> v(401,0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]=a[i]+200;
        v[a[i]]++;
    }
    for(int i=0;i<401;i++)
    {
        for(int j=i;j<401;j++)
        {
            sum+=(j-i)*(j-i)*v[i]*v[j];
        }
        
    }
    cout<<sum<<endl;
}