#include #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; using namespace std; int main() { int N; cin >> N; vector A(N); rep(i, N) cin >> A[i]; vector d(N, N); for (int i = N - 1; i >= 0; --i) { if (A[i] == 0) d[i] = i; else if (i != N - 1) d[i] = d[i + 1]; } ll ans = 0; rep(i, N) ans += N - d[i]; cout << ans << endl; return 0; }