#include using namespace std; int main() { int N; cin >> N; vector A(N); for (auto&& a : A) { cin >> a; } long long ans = 1ll * N * (N + 1) / 2; int len = 0; A.emplace_back(0); for (auto&& a : A) { if (a == 1) len++; else { ans -= 1ll * len * (len + 1) / 2; len = 0; } } cout << ans << endl; }