All for Nine and Nine for All
Difficulty: Hard

<img src="https://s3.amazonaws.com/hr-challenge-images/3090/1472582116-bf126e51f6-lunctimesurprise.jpg" title="lunctimesurprise.jpg" />

Everyone's favorite noontime show, _Lunchtime Surprise_, launched a new game recently. They called it: _All for Nine and Nine for All_. There would be $N$ boxes, each containing a single digit from `0` to `9`, lined up and the team of nine contestants would have to decide which boxes to open. After opening the boxes, we can read the resulting number from left to right. If this number is positive and can be divided evenly by 9, then they either win that amount of money (in pesos) or 99999 pesos, whichever is lower. However, if the resulting number has leading zeros (e.g. reading the number from left to right results in `00144`), it is considered an invalid number. Hence, the contetants lose in that case.

After a few episodes, they realized that winning was relatively easy. The researchers needed to revise the rules. In their proposed set of rules, contestants must choose a set of _consecutive boxes_ instead of any set of boxes. All the other original rules apply.

Now, the researchers needed some kind of report that shows that there are less ways to win using their proposed rules, as compared to the original. They shall give examples of box arrangements and show how many ways one can win using the original set of rules, and how many ways to win using their proposed rules.

**Input Format**  
The first line contains a single integer, which is $N$.
The second line contains a string of length $N$, consisting of digits `0`-`9`, describing a box arrangement.

**Output Format**  
Output exactly two lines.
The first line should contain an integer indicating the number of ways (modulo $10^9$) one can win using the original set of rules.
The second line should contain an integer indicating the number of ways (modulo $10^9$) one can win using the proposed set of rules.


**Constraints**  
$1 \le N \le 10^6$  

**Sample Input**  

    5
    33931

**Sample Output**  

    3
    2

**Explanation**  
For the original set of rules, there are three ways.

1. The contestants can open boxes $1$, $2$ and $4$. Reading it from left to right, our contestants go home with 333 pesos!

2. The contestants can open box $3$ only. Reading it from left to right, our contestants go home with 9 pesos!

3. The contestants can open boxes $1$, $2$, $3$ and $4$. Reading it from left to right, our contestants go home with 3393 pesos!

For the second method, there are two ways. These two ways are the cases illustrated as #2 and #3 above.

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cassert>
    #include <cctype>

    using namespace std;

    const int M = 1000000000;
    char s[1000006];
    int dp[2][9];

    void ad(int &x,int y) {
        if ((x += y) >= M) {
            x -= M;
        }
    }

    int f(int x) {
        return (x >= 9)?(x - 9):x;
    }

    int main() {
    int n;
        scanf("%d%s",&n,s);
        assert((n > 0) && (n <= 1000000));
        assert(strlen(s) == n);
        int last = 0;
        for (int i = 0; i < n; ++i) {
            assert(isdigit(s[i]));

            int now = last ^ 1;
            memcpy(dp[now],dp[last],sizeof(dp[0]));
            for (int j = 0; j < 9; ++j) {
               ad(dp[now][f(j + s[i] - '0')], dp[last][j]);
            }
            if (s[i] != '0') {
                ad(dp[now][f(s[i] - '0')], 1);
            }

            last ^= 1;

        }
        printf("%d\n",dp[last][0]);
        memset(dp[0],0,sizeof(dp[0]));
        last = 0;
        int answer = 0;
        for (int i = 0; i < n; ++i) {
            assert(isdigit(s[i]));    
            int now = last ^ 1;
            memset(dp[now],0,sizeof(dp[0]));
            for (int j = 0; j < 9; ++j) {
               ad(dp[now][f(j + s[i] - '0')], dp[last][j]);
            }
            if (s[i] != '0') {
                ad(dp[now][f(s[i] - '0')],1);
            }
            ad(answer, dp[now][0]);
            last ^= 1;


        }
        printf("%d\n",answer);

        return 0;
    }