#define taskname "sort"
#include <iostream>
#include <cstdio>
#include <algorithm>
 
using namespace std;
const int maxN = 1e5 + 1;
int n, a[maxN], id[maxN];
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen(taskname".in", "r", stdin);
    //freopen(taskname".out", "w", stdout);
    cin >> n;
    if (n == 1)
    {
        cout << "0\n";
        return 0;
    }
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        id[i] = i;
    }
    for (int i = 1; i < n; ++i)
        if (a[i] > a[i + 1])
            swap(a[i], a[i + 1]);
    stable_sort(id + 1, id + n + 1, [](int i, int j)
    {
        return a[i] < a[j];
    });
    long long res = n;
    int MaxIdx = 0;
    for (int i = 1; i <= n; ++i)
    {
        int j = id[i];
        if (MaxIdx < j)
        {
            MaxIdx = j;
            res += MaxIdx - i;
        }
        else
            res += MaxIdx - (i - 1);
    }
    cout << res;
}