#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int N; cin >> N; int A[250000]; for (int i = 1; i <= N; i++)cin >> A[i]; long long sum = N * (N + 1) / 2; long long count = 0; long long C = 0; for (int i = 1; i <= N; i++) { if (A[i] == 1) { C++; } else { count = count + C * (C + 1) / 2; C = 0; } } count = count + C * (C + 1) / 2; cout << sum - count; }