#include <bits/stdc++.h>
using namespace std;
int num[100005];
int dp[100005];
int main() {
  int n;
  scanf("%d", &n);
  map<int, long long> mp1, mp2;
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
  }
  dp[n] = -1;
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (mp1[num[i]] == 0) {
      dp[i] = dp[i + 1] + 1;
    } else {
      dp[i] = dp[i + 1];
    }
    mp1[num[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (mp2[num[i]] == 0) {
      ans += dp[i];
      if (mp1[num[i]] > 1) {
        ans++;
      }
    }
    mp2[num[i]]++;
  }
  printf("%lld\n", ans);
  return 0;
}
