#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
int num[524310];
int kazu[524310];
const int ma = (1 << 19) - 1;
int query(ll n) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return kazu[n2]++;
		n2 = n2 * 2 % 524309;
	}
	num[n2] = n + 1;
	kazu[n2] = 1;
	return 0;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint();

	ll are = N * ll(N - 1) / 2;

	rep(i, N) are -= query(getint());
	printf("%lld\n", are);

	Would you please return 0;
}
#include <bits/stdc++.h>
#define spd ios::sync_with_stdio(false),cin.tie(0)
#define mod 1000000007;
#define pie acos(-1)
#define eps 1e-9
#define fr(i,a,b) for(i = a; i < b; i++)
#define Fr(i,a,b) for(i = a; i >= b; i--)
#define rst(a,b) memset(a,b,sizeof(a))
#define in1(a) cin >> a
#define in2(a,b) cin >> a >> b
#define in3(a,b,c) cin >> a >> b >> c
#define in4(a,b,c,d) cin >> a >> b >> c >> d
#define sinp(a) getline(cin, a)
#define tout(a,b) cout << "Case " << ++b << ": " << a << endl
#define dprint(x,y,z)  cout << setprecision(x) << fixed << y << " " << z << endl
#define srt(a,n) sort(a, a + n)
#define rev(a,n) sort(a, a + n, greater<ll>())
#define pb(a) push_back(a)
#define len(a) a.length()
#define bs(a,b) binary_search(a.begin(), a.end(), b)
#define lob(a,b) lower_bound(a.begin(), a.end(), b)
#define upb(a,b) upper_bound(a.begin(), a.end(), b)

using namespace std;
using ull = unsigned long long;
using ll = long long;
using db = double;
using ss = string;

unordered_map<ll,ll> freq;

int main() {
    spd; //ll t,tst = 0; in1(t);
    //while(t--) {
        ll n,i, sum = 0; in1(n);
        vector<ll> vec(n);
        fr(i,0,n) {
            in1(vec[i]);
            if(freq[vec[i]]) sum += n - i - 1 - freq[vec[i]];
            else sum += n - i - 1;
            freq[vec[i]]++;
        }
        cout << sum << endl;
    //}
}