#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
void solve() {
  vector<int> fenwik(n + 1);
  auto add = [&](int v, int x) {
    while (v <= n) fenwik[v] += x, v += v & -v;
    return;
  };
  auto sum = [&](int v) {
    int second = 0;
    while (v > 0) second += fenwik[v], v &= v - 1;
    return second;
  };
  set<pair<int, int> > second;
  for (int i = 1; i < n + 1; i++) second.insert({a[i], i}), add(i, 1);
  pair<int, int> pos = {0, 0};
  long long int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    pos.first = second.begin()->first;
    auto it = second.lower_bound(pos);
    if (it->first == second.begin()->first)
      ans += sum(it->second) - sum(pos.second);
    else {
      it = second.begin();
      ans += sum(n) - sum(pos.second) + sum(it->second);
    }
    add(it->second, -1);
    pos = *it;
    second.erase(it);
  }
  cout << ans << '\n';
  return;
}
void inp() {
  cin >> n;
  a.resize(n + 1);
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  return;
}
int main() {
  clock_t beg = clock();
  inp();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec\n", (double)(end - beg) / CLOCKS_PER_SEC);
  return 0;
}
