https://cses.fi/paste/20b6df3cfdc7ebbbdfbb40/#include <iostream>
#include <vector>
#include <map>
using namespace std;
void solve() {
int n;
cin >> n;
map<int, int> val;
long long sum = 0;
long long ans = 0;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (val.find(x) != val.end()) {
sum -= val[x];
}
val[x] = i;
sum += i;
ans += sum;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
solve();
}
return 0;
}
