#include<bits/stdc++.h> #define int long long usingnamespace std;
constint N = 1e6 + 66;
inlineintread() { ints(0), w(1); char ch = getchar(); while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();} while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar(); return s * w; }
int n; int pos[N], nex[N], a[N];
signedmain() { int i, ret (0); n = read(); for (i = 1; i <= n; ++ i) a[i] = read();
for (i = 0; i <= N; ++ i) pos[i] = n + 1, nex[i] = n + 1; for (i = n; i >= 1; -- i) { if (pos[a[i]] == n + 1) pos[a[i]] = i; else nex[i] = pos[a[i]], pos[a[i]] = i; }
for (i = 1; i <= n; ++ i) ret += i * (nex[i] - i);