#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long n;
  cin >> n;
  unordered_map<long long, long long> m, flag;
  vector<int> arr(n + 1), diff(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
    if (m[arr[i]])
      diff[i] = diff[i - 1];
    else
      diff[i] = diff[i - 1] + 1;
    m[arr[i]]++;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    m[arr[i]]--;
    if (m[arr[i]] == 0) diff[n]--;
    if (!flag[arr[i]]) ans += diff[n], flag[arr[i]] = true;
  }
  cout << ans << endl;
  return 0;
}
