#include<iostream>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
#define PI 3.1415926535898
const int mm=1e7+10;
double arr[mm];
int main()
{
	int n;
	cin>>n;
	int maxx=-1;
	int minn=1e9;
	for(int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		maxx=max(a,maxx);
	}
	for(int i=i;i<=n;i++)
	{
		int b;
		cin>>b;
		minn=min(b,minn);
	}
	if(minn<maxx)
	cout<<0<<endl;
	else
	cout<<minn-maxx+1<<endl;
 } 
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
typedef long long int ll;
int main(){
  ll n;cin>>n;
  ll arr[n];
  ll cnt=n*(n-1)/2;map<ll,ll>mp;
  for(int i=0;i<n;i++){
    cin>>arr[i];
    mp[arr[i]]++;
  }
  for(auto it=mp.begin();it!=mp.end();it++){
    ll c=it->second*(it->second-1)/2;
    cnt-=c;
  }
  cout<<cnt<<endl;
}