text: #include <cstdio>
  #include <cstdint>
  #include <vector>
  #include <array>
  #include <algorithm>
  #include <utility>
  
  class bit_vector {
    size_t n;
    static constexpr size_t nbit = 64;
    std::vector<intmax_t> raw;
    std::vector<int> acc;
  
    int popcount(intmax_t x) const {
      return __builtin_popcountll(x);
    }
  
  public:
    bit_vector() {}
  
    bit_vector(const std::vector<bool>& b): n(b.size()) {
      raw.assign(n/nbit+1, 0);
      for (size_t i = 0; i < n; ++i)
        if (b[i]) raw[i/nbit] |= intmax_t(1) << (i % nbit);
  
      acc.assign(n/nbit+1, 0);
      for (size_t i = 1; i < acc.size(); ++i)
        acc[i] = acc[i-1] + popcount(raw[i-1]);
    }
  
    size_t rank1(size_t k) const {
      size_t large = k / nbit;
      size_t small = k % nbit;
      size_t res = acc[large];
      if (small > 0) res += popcount(raw[large] & ((intmax_t(1) << small) - 1));
      return res;
    }
  
    size_t rank0(size_t k) const {
      return k - rank1(k);
    }
  
    size_t select1(size_t k) const {
      if (k == 0) return 0;
      size_t lb = 0;
      size_t ub = n;
      while (ub-lb > 1) {
        size_t mid = (lb+ub) >> 1;
        ((rank1(mid) < k)? lb:ub) = mid;
      }
      if (rank1(ub) < k) return -1;
      return ub;
    }
  
    size_t select0(size_t k) const {
      if (k == 0) return 0;
      size_t lb = 0;
      size_t ub = n;
      while (ub-lb > 1) {
        size_t mid = (lb+ub) >> 1;
        ((rank0(mid) < k)? lb:ub) = mid;
      }
      if (rank0(ub) < k) return -1;
      return ub;
    }
  
    size_t rank(size_t k, int x) const {
      return x? rank1(k) : rank0(k);
    }
  
    size_t select(size_t k, int x) const {
      return x? select1(k) : select0(k);
    }
  
    bool operator [](size_t k) const {
      size_t large = k / nbit;
      size_t small = k % nbit;
      return raw[large] >> small & 1;
    }
  };
  
  template <class Tp, size_t bitlen = 8 * sizeof(Tp)>
  class wavelet_matrix {
    std::vector<Tp> c;
    std::vector<size_t> zeros;
    size_t n;
    std::array<bit_vector, bitlen> a;
  
    size_t start_index(Tp x) const {
      size_t s = 0;
      size_t t = 0;
      for (size_t i = bitlen; i-- > 1;) {
        size_t j = bitlen-i-1;
        if (x >> i & 1) {
          s = zeros[j] + a[j].rank1(s);
          t = zeros[j] + a[j].rank1(t);
        } else {
          s = a[j].rank0(s);
          t = a[j].rank0(t);
        }
      }
      return s;
    }
  
  public:
    template <class ForwardIt>
    wavelet_matrix(ForwardIt first, ForwardIt last):
      c(first, last), zeros(bitlen), n(c.size())
    {
      std::vector<Tp> whole = c;
      for (size_t i = bitlen; i--;) {
        std::vector<Tp> zero, one;
        std::vector<bool> vb(n);
        for (size_t j = 0; j < n; ++j) {
          ((whole[j] >> i & 1)? one:zero).push_back(whole[j]);
          vb[j] = (whole[j] >> i & 1);
        }
  
        zeros[bitlen-i-1] = zero.size();
        a[bitlen-i-1] = bit_vector(vb);
        if (i == 0) break;
        whole = std::move(zero);
        whole.insert(whole.end(), one.begin(), one.end());
      }
    }
  
    size_t rank(size_t t, Tp x) const {
      size_t s = 0;
      for (size_t i = bitlen; i--;) {
        size_t j = bitlen-i-1;
        if (x >> i & 1) {
          s = zeros[j] + a[j].rank1(s);
          t = zeros[j] + a[j].rank1(t);
        } else {
          s = a[j].rank0(s);
          t = a[j].rank0(t);
        }
      }
      return t - s;
    }
  
    size_t select(size_t t, Tp x) const {
      size_t si = start_index(x);
      t += a[bitlen-1].rank(si, x & 1);
      t = a[bitlen-1].select(t, x & 1);
  
      for (size_t i = 1; i < bitlen; ++i) {
        // fprintf(stderr, "t: %zu\n", t);
        size_t j = bitlen-i-1;
        if (x >> i & 1) t -= zeros[j];
        t = a[j].select(t, x >> i & 1);
      }
  
      return t;
    }
  };
  
  int main() {
    size_t n;
    scanf("%zu", &n);
  
    std::vector<int> a(n);
    for (auto& ai: a) scanf("%d", &ai);
  
    wavelet_matrix<int, 17> wm(a.begin(), a.end());
  
    int res = 0;
    for (int i = 1; i <= 100000; ++i) {
      int tmp = wm.rank(n, i);
      if (tmp > 1) res += tmp - 1;
    }
  
    printf("%d\n", res);
  }
  