#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cell(a,b) int((a+(b-1))/b)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl '\n'
#define INF 10e9


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

bool sortbyPair(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}


int main()
{

    int n,i;
    ll c=0;
    cin>>n;
    vector<int> a(n);
    map<int,int> mp;
    for(int &it:a)
    {
        cin>>it;
        mp[it]++;
    }
    for(int &it:a)
    {
        c+=(n-mp[it]);
        n--;
        mp[it]--;
    }
    cout<<c<<nl;


}

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

int solve(int a) {
  return a;
}

int main() {
  int N; cin >> N;
  int A[110];
  int B[110];
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  
  int ans = 0;
  for (int i = A[0]; i <= B[0]; i++) {
    bool is = true;
    for (int j = 1; j < N; j++) {
      if(i < A[j] || B[j] < i) is = false;
    }
    if (is == true) ans++;
  }
  
  cout << ans << endl;
}