#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;
}
I2RlZmluZSB0YXNrbmFtZSAic29ydCIKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8YWxnb3JpdGhtPgogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBtYXhOID0gMWU1ICsgMTsKaW50IG4sIGFbbWF4Tl0sIGlkW21heE5dOwogCmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgLy9mcmVvcGVuKHRhc2tuYW1lIi5pbiIsICJyIiwgc3RkaW4pOwogICAgLy9mcmVvcGVuKHRhc2tuYW1lIi5vdXQiLCAidyIsIHN0ZG91dCk7CiAgICBjaW4gPj4gbjsKICAgIGlmIChuID09IDEpCiAgICB7CiAgICAgICAgY291dCA8PCAiMFxuIjsKICAgICAgICByZXR1cm4gMDsKICAgIH0KICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkKICAgIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgICAgICBpZFtpXSA9IGk7CiAgICB9CiAgICBmb3IgKGludCBpID0gMTsgaSA8IG47ICsraSkKICAgICAgICBpZiAoYVtpXSA+IGFbaSArIDFdKQogICAgICAgICAgICBzd2FwKGFbaV0sIGFbaSArIDFdKTsKICAgIHN0YWJsZV9zb3J0KGlkICsgMSwgaWQgKyBuICsgMSwgW10oaW50IGksIGludCBqKQogICAgewogICAgICAgIHJldHVybiBhW2ldIDwgYVtqXTsKICAgIH0pOwogICAgbG9uZyBsb25nIHJlcyA9IG47CiAgICBpbnQgTWF4SWR4ID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkKICAgIHsKICAgICAgICBpbnQgaiA9IGlkW2ldOwogICAgICAgIGlmIChNYXhJZHggPCBqKQogICAgICAgIHsKICAgICAgICAgICAgTWF4SWR4ID0gajsKICAgICAgICAgICAgcmVzICs9IE1heElkeCAtIGk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICAgICAgcmVzICs9IE1heElkeCAtIChpIC0gMSk7CiAgICB9CiAgICBjb3V0IDw8IHJlczsKfQ==