#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e18;
const long long MAX = 100001;
void solve() {
  int n;
  cin >> n;
  vector<int> vec(n + 1);
  unordered_map<int, int> front, back;
  for (int i = 0; i < n; i++) {
    cin >> vec[i + 1];
    back[vec[i + 1]]++;
    front[vec[i]] = 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    back[vec[i]]--;
    if (back[vec[i]] == 0) back.erase(vec[i]);
    if (front[vec[i]]) {
      ans += back.size();
    }
    front[vec[i]] = 0;
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
