#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") int N; vector A; int main() { for (; ~scanf("%d", &N); ) { A.resize(N); for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); } auto as = A; sort(as.begin(), as.end()); as.erase(unique(as.begin(), as.end()), as.end()); vector ASum(N + 1, 0); for (int i = 0; i < N; ++i) { ASum[i + 1] = ASum[i] + A[i]; } Int ans = 0; ans += (Int)N * (N + 1) / 2; // left = avg for (const int a : as) { map freq; for (int i = N; --i >= 0; ) { ++freq[ASum[i + 1] - a * (i + 1)]; if (A[i] == a) ans -= freq[ASum[i] - a * i]; } } // right = avg for (const int a : as) { map freq; for (int i = 0; i < N; ++i) { ++freq[ASum[i] - a * i]; if (A[i] == a) ans -= freq[ASum[i + 1] - a * (i + 1)]; } } // left = right = avg for (const int a : as) { map freq; for (int i = N; --i >= 0; ) { if (A[i] == a) ++freq[ASum[i + 1] - a * (i + 1)]; if (A[i] == a) ans += freq[ASum[i] - a * i]; } } ans += 1; printf("%lld\n", ans); } return 0; }