Zero Then One
Count the pairs of positions i < j where position i holds 0 and position j holds 1.
Input: one line with a binary string.
Output: the number of 0-before-1 pairs.
Constraints:
- 1 ≤ |S| ≤ 105
Sample Tests
Input 1
0101
Output 1
3
Input 2
1100
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.