#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000 + 5;
pair<int, int> B[MAX];
int bit[MAX];
int A[MAX];
void update(int x, int v) {
  while (x < MAX) {
    bit[x] += v;
    x += x & -x;
  }
}
int sum(int x) {
  int s = 0;
  while (x > 0) {
    s += bit[x];
    x -= x & -x;
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> B[i].first;
    B[i].second = i + 1;
  }
  sort(B, B + n);
  int last = 0;
  int idx = 0;
  for (int i = 0, j = 0; i < n; i = j) {
    for (j = i; j < n && B[i].first == B[j].first; j++)
      ;
    int pos =
        lower_bound(B + i, B + +j, pair<int, int>(B[i].first, last)) - (B + i);
    int size = j - i;
    for (int k = 0; k < size; k++, pos++) {
      if (pos == size) pos = 0;
      A[idx++] = B[i + pos].second;
    }
    last = A[idx - 1];
  }
  for (int i = 1; i <= n; i++) update(i, 1);
  long long solve = 0LL;
  int p = 0;
  for (int i = 0; i < n; i++) {
    int v = A[i];
    long long to_add = 0LL;
    if (p < v)
      to_add = sum(v) - sum(p);
    else
      to_add = n - i - (sum(p) - sum(v));
    solve += to_add;
    p = v;
    update(v, -1);
  }
  cout << solve << '\n';
  return 0;
}
