#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::vector<int> values;
  for (int i = 0; i < n; ++i) {
    int now;
    std::cin >> now;
    values.push_back(now);
  }
  std::vector<int> first_left(100000 + 1, -1), first_right(100000 + 1, -1);
  for (int i = 0; i < values.size(); ++i) {
    int now = values[i];
    if (first_left[now] == -1) {
      first_left[now] = i;
    }
  }
  for (int i = values.size() - 1; i >= 0; --i) {
    int now = values[i];
    if (first_right[now] == -1) {
      first_right[now] = i;
    }
  }
  std::vector<int> left_unique_num;
  std::set<int> now;
  for (int i = 0; i < values.size(); ++i) {
    now.insert(values[i]);
    left_unique_num.push_back(now.size());
  }
  long long ans = 0;
  for (int i = values.size() - 1; i > 0; --i) {
    if (first_right[values[i]] == i) {
      int now_variants = left_unique_num[i - 1];
      ans += now_variants;
    }
  }
  std::cout << ans;
}
