#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
long long l = 0, r = 0;
long long count = 0;
set<int> st;
while (r < n) {
while (st.count(v[r])) {
st.erase(v[l]);
l++;
}
st.insert(v[r]);
count += (r - l + 1);
r++;
}
cout << count;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICBpbnQgbjsKICBjaW4gPj4gbjsKICB2ZWN0b3I8aW50PiB2KG4pOwogIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICBjaW4gPj4gdltpXTsKICB9CiAgbG9uZyBsb25nIGwgPSAwLCByID0gMDsKICBsb25nIGxvbmcgY291bnQgPSAwOwogIHNldDxpbnQ+IHN0OwogIHdoaWxlIChyIDwgbikgewogICAgd2hpbGUgKHN0LmNvdW50KHZbcl0pKSB7CiAgICAgIHN0LmVyYXNlKHZbbF0pOwogICAgICBsKys7CiAgICB9CiAgICBzdC5pbnNlcnQodltyXSk7CiAgICBjb3VudCArPSAociAtIGwgKyAxKTsKICAgIHIrKzsKICB9CiAgY291dCA8PCBjb3VudDsKfQ==