#pragma GCC target("avx512f") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #include #include using namespace std; template inline void scan_uint(T& a) noexcept { a = 0; for (char c = getchar_unlocked(); isdigit(c); c = getchar_unlocked()) a = a * 10 + c - '0'; } int main() { int n; scan_uint(n); int a[200000]; for (int i = 0; i < n; ++i) scan_uint(a[i]); int ans = 0, k; unordered_set s; for (int i = 0; i < n; ++i) { s.clear(); k = 0; for (int j = i; j < n; ++j) { s.emplace(a[j]); while (s.find(k) != s.end()) ++k; ans += k; } } printf("%d", ans); }