#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define d(x) cout<<x<<" "
#define nl cout<<endl
#define rep(var,init_val,final_val) for(int var = init_val; var < final_val; ++var)
#define show(a,b) rep(i,0,b) d(a[i]);nl;
#define showv(a) for(auto x : a) d(x);nl;
#define vi std::vector<int>
#define pi pair<int,int>
#define mod 1000000007
void solve(){
	int n;
	cin>>n;
	int lo = INT_MIN , hi = INT_MAX;
	int a[n] , b[n];
	rep(i,0,n) cin>>a[i];
	rep(i,0,n) cin>>b[i];
	rep(i,0,n){
		lo = max(lo,a[i]);
		hi = min(hi,b[i]);
		}
	cout<<max(0,hi-lo+1)<<endl;
	}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int t = 1;
	//cin>>t;
	while(t--)
		solve();
    return 0;
	}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = int64_t;
using vi = vector<int>;
using vs = vector<string>;
using vc = vector<char>;
using vvi = vector<vi>;
using vvs = vector<vs>;
using vvc = vector<vc>;
using pii = pair<int, int>;

int main() {
  int n;
  cin >> n;
  map<int, ll> a;
  ll an;
  rep (i, n) {
    cin >> an;
    an %= 200;
    a[an]++;
  }
  
  ll ans = 0;
  rep (i, 200) {
    ans += (a[i]*(a[i]-1)) / 2LL;
  }

  cout << ans << endl;
  
}

  