#include int a[200005]; int ans[200005]; int main() { int n; scanf("%d", &n); int i; for (i = 0; i < n; i++) scanf("%d", &a[i]); ans[n - 1] = 0; if (n > 1) { if (a[n - 2] > 0) ans[n - 2] = 1; else ans[n - 2] = 0; } for (i = n - 3; i >= 0; i--) { if (a[i] > 0 && a[i + 1] == 0) ans[i] = ans[i + 2] + 2; else if (a[i] > 0) ans[i] = 1; else ans[i] = 0; } long long int res = 0; for (i = 0; i < n; i++) res += ans[i]; printf("%lld\n", res); return 0; }