Problems > Zero Then One

Zero Then One

Difficulty: 1300 3000 ms 128 MB

math strings

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.