Sponsored
Use these hints if you're stuck. Try solving on your own first.
Count number of 1s in each consecutive-1 group. For a group with n consecutive 1s, the total contribution of it to the final answer is (n + 1) * n // 2.
Solve with full IDE support and test cases