Codeforces I. Inna and Nine(组合)

Subject description:

Inna and Nine

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.

Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.

For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.

Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.

Input

The first line of the input contains integer a (1 ≤ a ≤ \(10^{100000}\)). Number a doesn't have any zeroes.

Output

In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed \(2^{63 - 1}\).

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

Copy

369727

Output

Copy

2

Input

Copy

123456789987654321

Output

Copy

1

Input

Copy

1

Output

Copy

1

Note

Notes to the samples

In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.

In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.

Ideas:

Entitled to a numeric string, two adjacent numbers add up to 9, then can be combined, and asked how many different strings of numbers can be up to 9 under most circumstances.

This question looks just started to see very troublesome, ,,, how to do this, how do I find a few also add up to 9 different circumstances, determine what strategies can be distinguished and try different bonus number, one by one test? Recursion? Dynamic programming? Look at the data range, direct 10 ^ 5, limit one second enumeration is not enough ah. This makes it more concise method description.

Only one find a regular.

We now take a look at the sample 14,545,181, nine-to a maximum of only 19,991 or 19,919, that is to say in the middle of 4545 just 9 composed of two can not open, will be less open. So under what circumstances it will be more possible? We turn our attention to 181, it is this had two possibilities.

We will find that there are several possible order, must satisfy a property: a number add up to 9 and left, and the right add up to 9

For chestnut: 1454541

We found that both sides of the 1 no effect on the results, because they do not scrape out a 9, then remove to give 45454, there are several situations that do? 994,949,499 three kinds of this series which we found just the nature of these three numbers 5,4,5 meet the above

Again: 454, 94 and 49 are two, has a number of properties satisfying the above 5

The number of the long point: 4999,9499,9949,9994 4,545,454 there are four in number string satisfying the above properties have five 5,4,5,4,5

If the length is even it? 4545, we found that only a possible 99, of which there are 5,4 meet the nature of the two numbers

Found that the law did not? Only when the number of satisfied properties has an odd number, only a number of possible, an even number may be only a

And the number and nature of the possibility of satisfying the following relationship: \ (A_N = (n-+. 3) / 2 \) , \ (n-\) is the number satisfying the number of properties, and is an odd number, \ (A_N \ ) is the number of possible species.

Now the problem of how to identify only the number of the numeric string having such modes. It will be identified by like nature, in addition to each number of beginning of the end of the traverse, to see if they meet the nature, number plus one is put. Note that satisfies properties is not necessarily continuous string, the string broken promptly counter variable is cleared. Also note that the number is an even number not contribute possibilities.

Code:

#include <iostream>
#include <string>
using namespace std;
string s;
long long judge(string s)
{
    long long ans = 1;
    long long num = 0;
    for(int i = 1;i<s.size()-1;i++)
    {
        if(s[i-1]+s[i]-2*'0'==9&&s[i]+s[i+1]-2*'0'==9)
        {
            num++;
        }
        else if(num%2==1)
        {
            ans = ans*((num+3)/2);
            //cout << "num " << num << endl;
            num = 0;
        }
        else
        {
            num = 0;
        }
    }
    if(num%2==1)
    {
        ans = (ans*(num+3)/2);
    }
    return ans;
}
int main()
{
    cin >> s;
    long long ans = judge(s);
    cout << ans << endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/zhanhonhao/p/11288445.html