#line 1 "main.cpp" #include #include // #include "library/templates/template.cpp" using namespace atcoder; using namespace std; using ll = long long int; using ull = unsigned long long int; using ld = long double; using pii = pair; using pll = pair; long long solve(int N, const std::vector &A) { vector dp(N + 1, 0); vector cnt(N + 1, 0); for (int i = 0; i < N; i++) { if (A[i]) { cnt[i]++; } if (i && A[i] != A[i - 1]) { cnt[i] += cnt[i - 1]; dp[i] += cnt[i - 1]; } else if (i) { dp[i] += cnt[i - 1]; } } ll res = accumulate(dp.begin(), dp.end(), 0LL); return res; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); int N; std::cin >> N; std::vector A(N); for (int i = 0; i < N; ++i) { std::cin >> A[i]; } auto ans = solve(N, A); std::cout << ans << '\n'; return 0; }