#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  a = ((a) < 0 ? -(a) : (a));
  b = ((b) < 0 ? -(b) : (b));
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
const long long inf = 2147383647;
const long long mod = 1000000007;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
int n, m, x, ar[100005], br[100005];
int main() {
  m = 1e5;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (!ar[x]) ar[x] = i;
    br[x] = i;
  }
  sort(br + 1, br + m + 1);
  br[m + 1] = 1e9;
  long long ans = 0;
  for (int i = 1; i <= m; i++) {
    if (!ar[i]) continue;
    int low = 1, high = m + 1, md, stop = high;
    while (low <= high) {
      md = (low + high) / 2;
      if (br[md] <= ar[i]) {
        low = md + 1;
      } else {
        high = md - 1;
        stop = md;
      }
    }
    ans += max(0, m - stop + 1);
  }
  cout << ans << "\n";
  return 0;
}
