#include using namespace std; __attribute__((constructor)) void fast_io() { ios::sync_with_stdio(false); cin.tie(nullptr); } long long binary_gcd(long long a, long long b) { if (a == 0) return b; if (b == 0) return a; const int n = __builtin_ctzll(a | b); a >>= __builtin_ctzll(a); while (b > 0) { b >>= __builtin_ctzll(b); if (a > b) swap(a, b); b -= a; } return a << n; } template struct swag { struct node { S value, sum; node(const S& value, const S& sum) : value(value), sum(sum) {} }; stack front_stack, back_stack; swag() {} bool empty() const { return front_stack.empty() && back_stack.empty();} size_t size() const { return front_stack.size() + back_stack.size();} S fold() const { if (empty()) return e(); else if (front_stack.empty()) return back_stack.top().sum; else if (back_stack.empty()) return front_stack.top().sum; else return op(front_stack.top().sum, back_stack.top().sum); } void push(const S &x) { if (back_stack.empty()) back_stack.emplace(x, x); else { S s{op(back_stack.top().sum, x)}; back_stack.emplace(x, s); } } void pop() { assert(!empty()); if (front_stack.empty()) { front_stack.emplace(back_stack.top().value, back_stack.top().value); back_stack.pop(); while (!back_stack.empty()) { S s{op(back_stack.top().value, front_stack.top().sum)}; front_stack.emplace(back_stack.top().value, s); back_stack.pop(); } } front_stack.pop(); } }; long long e() { return 0; } int main() { int n; cin >> n; vector a(n); for (auto& ai : a) cin >> ai; a.push_back(1); swag q; long long ans = 0; q.push(a.front()); for (int l = 0, r = 0; l < n; ++l) { while (q.fold() != 1) q.push(a[++r]); ans += n - r; q.pop(); } cout << ans << '\n'; }