#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif #include using dat = array; const int64_t inf = (1 << 30) - 1; dat e() { return dat{inf, inf, inf * 2, 0}; } dat op(dat a, dat b) { if (a == e()) return b; if (b == e()) return a; array c{a[0], a[1], b[0], b[1]}; sort(c.begin(), c.end()); return dat{c[0], c[1], c[0] + c[1], max(a[3], b[3])}; } void solve() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector init(N, e()); for (int i = 0; i < N; i++) { init[i][0] = A[i]; init[i][2] = A[i] + inf; init[i][3] = A[i]; } atcoder::segtree seg(init); int64_t ans = 0; for (int i = 0; i < N; i++) { const auto f = [&](dat x) -> bool { return x[3] <= x[2]; }; int j = seg.min_left(i + 1, f); ans += i - j; } cout << ans << endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }