409777: GYM103741 G Nerdle

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Nerdletime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output

Walk_alone is going to primary school! To train his computing ability, Weierstras gives him a game called Nerdle.

In this game, he should guess an equation of length $$$8$$$, and an equation is valid if and only if it satisfies the following rules:

  • The length of the equation is $$$8$$$, and an equation must contain exactly one equal sign ('='). The two sides of the equation (called AddExprs) must be equal;
  • An AddExpr consists of one or more MulExprs connected by plus signs ('+') or minus signs ('-');
  • A MulExpr consists of one or more Numbers connected by multiple signs ('*') or division signs ('/');
  • A Number consists of at most one negative sign ('-') and one or more Digits (leading 0s are allowed in this game, and negative signs can connect directly with minus signs);
  • The result of each division must be an integer (for example, expression 5/4*4 is not allowed, even if the final result is an integer).

For example, 5*4/4=05, 1--2=1+2 and -1*-2=02 are all valid equations, but 5/4*4=05, 5/4=10/8, 2+---1=1, 1+2+3=07, +12=10+2 or 1=3-2=01 are not.

Formally speaking, all valid equations must satisfy the following Extended Backus-Naur Form:

Equation := AddExpr '=' AddExpr
AddExpr := MulExpr | AddExpr ('+'|'-') MulExpr
MulExpr := Number | MulExpr ('*'|'/') Number
Number := ['-'] Digit {Digit}
Digit := '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'

Now Walk_alone has a pattern of length $$$8$$$, and he asks you to tell him the number of valid equations satisfying the pattern. The pattern consists only of digits, '+', '-', '*', '/', '=' and '?'. If the $$$i$$$-th character in the pattern is '?', it means the $$$i$$$-th character in the equation is not restricted, otherwise the character must be the same as the pattern.

Input

The only line of the input contains a string of length $$$8$$$ as the pattern.

Output

Output an integer indicating the number of equations.

ExamplesInput
?-?+1=?9
Output
2
Input
???*????
Output
37305
Note

All possible equations in the first example are 8-0+1=09 and 9-1+1=09.

Source/Category

加入题单

算法标签: