#include #include #include #include using namespace std; int main() { int n; cin >> n; vector a(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) --a[i]; vector> mp(30); vector sum(n + 1); for (int i = 0; i < n; ++i) sum[i + 1] = sum[i] + a[i]; mp[a[0]][0] = 1; long long ans = (long long)(n + 1) * n / 2 + 1; for (int i = 1; i <= n; ++i) { int tmp = sum[i] - a[i - 1] * i; for (int j = 0; j < 30; ++j) ans -= mp[j][tmp]; if (i < n) mp[a[i]][sum[i] - i * a[i]]++; } cout << ans << endl; }