#include <bits/stdc++.h>
using namespace std;
int n, a[100100], h[100100], tr[100100];
vector<int> pos[100100];
void update(int o, int val) {
  for (int i = o; i <= n; i += i & (-i)) {
    tr[i] += val;
  }
}
int Q(int o) {
  int res = 0;
  for (int i = o; i; i -= i & (-i)) {
    res += tr[i];
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    h[i] = a[i];
  }
  sort(h, h + n);
  auto en = unique(h, h + n);
  for (int i = 0; i < n; ++i) {
    a[i] = lower_bound(h, en, a[i]) - h;
    pos[a[i]].push_back(i + 1);
  }
  int len = en - h;
  int now = *pos[0].rbegin();
  long long ans = now;
  for (int i = 1; i < len; ++i) {
    for (auto &j : pos[i]) {
      update(j, 1);
    }
  }
  for (int i = 1; i < len; ++i) {
    auto tem = lower_bound(pos[i].begin(), pos[i].end(), now);
    if (tem != pos[i].begin()) {
      tem--;
      ans += Q(n) - Q(now) + Q(*tem);
      now = *tem;
    } else {
      ans += Q(*pos[i].rbegin()) - Q(now);
      now = *pos[i].rbegin();
    }
    for (auto &j : pos[i]) {
      update(j, -1);
    }
  }
  cout << ans << endl;
  return 0;
}
