Asia Hong Kong Online Preliminary

Start

2016-09-10 07:00 CEST

Asia Hong Kong Online Preliminary

End

2016-09-10 12:30 CEST
The end is near!
Contest is over.
Not yet started.
Contest is starting in -497 days 4:21:11

Time elapsed

5:30:00

Time remaining

0:00:00

Problem J
0-1 Sequences

You are given a sequence, in the form of a string with characters ‘0’, ‘1’, and ‘?’ only. Suppose there are $k$?’s. Then there are $2^ k$ ways to replace each ‘?’ by a ‘0’ or a ‘1’, giving $2^ k$ different 0-1 sequences (0-1 sequences are sequences with only zeroes and ones).

For each 0-1 sequence, define its number of inversions as the minimum number of adjacent swaps required to sort the sequence in non-decreasing order. In this problem, the sequence is sorted in non-decreasing order precisely when all the zeroes occur before all the ones. For example, the sequence 11010 has $5$ inversions. We can sort it by the following moves: 11010 $\rightarrow $ 11001 $\rightarrow $ 10101 $\rightarrow $ 01101 $\rightarrow $ 01011 $\rightarrow $ 00111.

Find the sum of the number of inversions of the $2^ k$ sequences, modulo $1\, 000\, 000\, 007$ ($10^9 + 7$).

Input

The first and only line of input contains the input string, consisting of characters ‘0’, ‘1’, and ‘?’ only, and the input string has between $1$ to $500\, 000$ characters, inclusive.

Output

Output an integer indicating the aforementioned number of inversions modulo $1\, 000\, 000\, 007$.

Sample Input 1 Sample Output 1
?0?
3