//最終鬼畜確認トール🔨 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for(i = 0; i < n; i++) #define int long long using namespace std; int n; int a[100000]; signed main() { int i; cin >> n; rep(i, n) cin >> a[i]; assert(1 <= n && n <= 100000); int minA = a[0], maxA = a[0]; rep(i, n) minA = min(minA, a[i]); rep(i, n) maxA = max(maxA, a[i]); assert(1 <= minA && maxA <= 30); vector ra(n + 1); int ans = n * (n + 1) / 2; for (int x = minA; x <= maxA; x++) { ra[0] = 0; rep(i, n) { ra[i + 1] = ra[i] + a[i] - x; } vector rb = ra; rb.erase(unique(rb.begin(), rb.end()), rb.end()); sort(ra.begin(), ra.end()); sort(rb.begin(), rb.end()); /*cout << "x: " << x << endl; rep(i, n + 1) { cout << ra[i] << " "; } cout << endl; rep(i, rb.size()) { cout << rb[i] << " "; } cout << endl; */ int cnt = 0; rep(i, n + 1) { if (i > 0 && ra[i] != ra[i - 1]) { ans -= cnt * (cnt - 1) / 2; cnt = 0; } cnt++; } ans -= cnt * (cnt - 1) / 2; cnt = 0; rep(i, rb.size()) { if (i > 0 && rb[i] != rb[i - 1]) { ans += cnt * (cnt - 1) / 2; cnt = 0; } cnt++; } ans += cnt * (cnt - 1) / 2; } ans++; //初期状態の分を足す cout << ans << endl; return 0; }