Problem:
Score : 1600 points

Problem Statement

Taichi thinks a binary string X of odd length N is beautiful if it is possible to apply the following operation \frac{N-1}{2} times so that the only character of the resulting string is 1 :

Choose three consecutive bits of X and replace them by their median. For example, we can turn 00110 into 010 by applying the operation to the middle three bits.

Taichi has a string S consisting of characters 0, 1 and ?. Taichi wants to know the number of ways to replace the question marks with 1 or 0 so that the resulting string is beautiful, modulo 10^{9} + 7.

Constraints

1 \leq |S| \leq 300000

|S| is odd.

All characters of S are either 0, 1 or ?.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of ways to replace the question marks so that the resulting string is beautiful, modulo 10^{9} + 7.

Sample Input 1

1??00

Sample Output 1

2

There are 4 ways to replace the question marks with 0 or 1 :

11100 : This string is beautiful because we can first perform the operation on the last 3 bits to get 110 and then on the only 3 bits to get 1.

11000 : This string is beautiful because we can first perform the operation on the last 3 bits to get 110 and then on the only 3 bits to get 1.

10100 : This string is not beautiful because there is no sequence of operations such that the final string is 1.

10000 : This string is not beautiful because there is no sequence of operations such that the final string is 1.

Thus, there are 2 ways to form a beautiful string.

Sample Input 2

?

Sample Output 2

1

In this case, 1 is the only beautiful string.

Sample Input 3

?0101???10???00?1???????????????0????????????1????0

Sample Output 3

402589311

Remember to output your answer modulo 10^{9} + 7.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

//ΔAGC022E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int mod = 1e9+7;
void add(int& x,int y){
	x+=y;
	if(x>=mod)
		x-=mod;
}
char ch[333333];
int a,a0,a00,a1,a10,a100,a11;
int b,b0,b00,b1,b10,b100,b11;
int main()
{
	int i;
	cin>>ch;
	//reverse(ch,ch+strlen(ch));
	a=1;
	for(i=0;ch[i];i=i+1){
		b=0;
		b0=0;
		b00=0;
		b1=0;
		b10=0;
		b100=0;
		b11=0;
		if(ch[i]!='1'){
			add(b0,a);
			add(b00,a0);
			add(b0,a00);
			add(b10,a1);
			add(b100,a10);
			add(b10,a100);
			add(b11,a11);
		}
		if(ch[i]!='0'){
			add(b1,a);
			add(b,a0);
			add(b0,a00);
			add(b11,a1);
			add(b1,a10);
			add(b10,a100);
			add(b11,a11);
		}
		a=b;
		a0=b0;
		a00=b00;
		a1=b1;
		a10=b10;
		a100=b100;
		a11=b11;
		//cout<<a<<a0<<a00<<a1<<a10<<a100<<a11<<endl;
	}
	add(a11,a1);
	cout<<a11;
	return 0;
}