#include <bits/stdc++.h>
using i8 = char;
using u8 = unsigned char;
using i16 = short int;
using u16 = unsigned short int;
using i32 = long int;
using u32 = unsigned long int;
using i64 = long long int;
using u64 = unsigned long long int;
using f32 = float;
using f64 = double;
using f80 = long double;
const i64 MOD = 1000000007;
inline i64 fast_pow(i64 a, i64 b) {
  i64 ans = 1, base = a;
  while (b) {
    if (b & 1) {
      ans = (ans * base) % MOD;
    }
    base = (base * base) % MOD;
    b >>= 1;
  }
  return ans;
}
using namespace std;
i64 a[100010];
i64 b[100010];
i64 o[100010];
int main(void) {
  i64 n;
  cin >> n;
  i64 d = 0;
  for (i64 i = 0; i < n; ++i) {
    cin >> a[i];
    ++b[a[i]];
    if (b[a[i]] == 1) ++d;
  }
  i64 c = 0;
  for (i64 i = 0; i < n; ++i) {
    --b[a[i]];
    ++o[a[i]];
    if (b[a[i]] == 0) --d;
    if (o[a[i]] != 1) continue;
    c += d;
  }
  cout << c << endl;
  return 0;
}
