Valera wants to make a correct field to play "Minesweeper 1D". He has already painted a squared field with width of n cells, put several bombs on the field and wrote numbers into some cells. Now he wonders how many ways to fill the remaining cells with bombs and numbers are there if we should get a correct field in the end.
InputThe first line contains sequence of characters without spaces s1s2... sn (1 ≤ n ≤ 106), containing only characters "*", " " and digits "0", "1" or "2". If character si equals "*", then the i-th cell of the field contains a bomb. If character si equals " ", then Valera hasn't yet decided what to put in the i-th cell. Character si, that is equal to a digit, represents the digit written in the i-th square.
OutputPrint a single integer ― the number of ways Valera can fill the empty cells and get a correct field.
As the answer can be rather large, print it modulo 1000000007 (109 + 7).
Sample test(s) input01output
4input
output
2input
**12output
0input
1output
0Note
In the first test sample you can get the following correct fields: 001**1, 001***, 001*2*, 001*10.
#include
#include
#include
#include
using namespace std; const long long int MOD=1000000007; const int maxn=1100000; char str[maxn]; long long int dp[maxn][2][2]; int n; int main() { scanf("%s",&str); n=strlen(str); dp[0][0][1]=dp[0][0][0]=1; for(int i=1;i<=n;i++) { if(str[i-1]==' ') { ///str[i-1]=='*' dp[i][1][0]=(dp[i][1][0]+dp[i-1][0][1])%MOD; dp[i][1][0]=(dp[i][1][0]+dp[i-1][1][1])%MOD; dp[i][1][1]=(dp[i][1][1]+dp[i-1][0][1])%MOD; dp[i][1][1]=(dp[i][1][1]+dp[i-1][1][1])%MOD; ///str[i-1]=='0' dp[i][0][0]=(dp[i][0][0]+dp[i-1][0][0])%MOD; ///str[i-1]=='1' dp[i][0][1]=(dp[i][0][1]+dp[i-1][0][0])%MOD; dp[i][0][0]=(dp[i][0][0]+dp[i-1][1][0])%MOD; ///str[i-1]=='2' dp[i][0][1]=(dp[i][0][1]+dp[i-1][1][0])%MOD; } else { if(str[i-1]=='*') { dp[i][1][0]=(dp[i][1][0]+dp[i-1][0][1])%MOD; dp[i][1][0]=(dp[i][1][0]+dp[i-1][1][1])%MOD; dp[i][1][1]=(dp[i][1][1]+dp[i-1][0][1])%MOD; dp[i][1][1]=(dp[i][1][1]+dp[i-1][1][1])%MOD; } else if(str[i-1]=='0') { dp[i][0][0]=(dp[i][0][0]+dp[i-1][0][0])%MOD; } else if(str[i-1]=='1') { dp[i][0][1]=(dp[i][0][1]+dp[i-1][0][0])%MOD; dp[i][0][0]=(dp[i][0][0]+dp[i-1][1][0])%MOD; } else if(str[i-1]=='2') { dp[i][0][1]=(dp[i][0][1]+dp[i-1][1][0])%MOD; } } } printf("%I64d\n",(dp[n][1][0]+dp[n][0][0])%MOD); return 0; }