#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define mod 998244353

// 文字の総和のmod 3の値は不変
// 到達不可能な状態を数える
// N != 3 なら置き換え前が存在する任意の状態に行ける

// F_mod 上でのべき乗, 蟻本p115
ll modPow(ll x, ll n) {
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll sub(ll x, ll y) {
    x -= y;
    if (x < 0) return x + mod;
    return x;
}

ll dp[200005][3][3] = {}; // dp[N][i][j] N文字目まで並べて総和iで最後尾j

int main() {
    string S;
    cin >> S;
    int N = S.size();
    ll sum = S[N-1];
    bitset<2> flag;
    for (int i = 0; i < N - 1; ++i) {
        if (S[i] == S[i+1]) flag[0] = 1;
        else flag[1] = 1;
        sum += S[i];
    }
    if (! flag[1]) {
        cout << 1 << "\n";
        return 0;
    }

    ll ans = modPow(3, N-1);
    if (N % 3 != 0) {
        ans = sub(ans, modPow(2, N-1));
        if (! flag[0]) (ans += 1) %= mod;
    } else if (N == 3) {
        if (sum % 3) {
            ans = 6;
            if (! flag[0]) (ans += 1) %= mod;
        } else {
            ans = 3;
        }
    } else {
        dp[1][0][0] = dp[1][1][1] = dp[1][2][2] = 1;
        for (int i = 2; i <= N; ++i) {
            (dp[i][0][0] += dp[i-1][0][1] + dp[i-1][0][2]) %= mod;
            (dp[i][0][1] += dp[i-1][2][0] + dp[i-1][2][2]) %= mod;
            (dp[i][0][2] += dp[i-1][1][0] + dp[i-1][1][1]) %= mod;
            (dp[i][1][0] += dp[i-1][1][1] + dp[i-1][1][2]) %= mod;
            (dp[i][1][1] += dp[i-1][0][0] + dp[i-1][0][2]) %= mod;
            (dp[i][1][2] += dp[i-1][2][0] + dp[i-1][2][1]) %= mod;
            (dp[i][2][0] += dp[i-1][2][1] + dp[i-1][2][2]) %= mod;
            (dp[i][2][1] += dp[i-1][1][0] + dp[i-1][1][2]) %= mod;
            (dp[i][2][2] += dp[i-1][0][0] + dp[i-1][0][1]) %= mod;
        }
        ll s = (dp[N][0][0] + dp[N][0][1] + dp[N][0][2]) % mod;
        ll m = (dp[N][1][0] + dp[N][1][1] + dp[N][1][2]) % mod;
        if (sum % 3) {
            ans = sub(ans, m);
        } else {
            ans = sub(ans, s);
        }
        if (! flag[0]) (ans += 1) %= mod;
    }
    cout << ans << "\n";
    return 0;
}
### Prompt

Please provide a Cpp coded solution to the problem described below:

You are given a string S consisting of `a`,`b` and `c`. Find the number of strings that can be possibly obtained by repeatedly performing the following operation zero or more times, modulo 998244353:

* Choose an integer i such that 1\leq i\leq |S|-1 and the i-th and (i+1)-th characters in S are different. Replace each of the i-th and (i+1)-th characters in S with the character that differs from both of them (among `a`, `b` and `c`).

Constraints

* 2 \leq |S| \leq 2 × 10^5
* S consists of `a`, `b` and `c`.

Input

Input is given from Standard Input in the following format:


S


Output

Print the number of strings that can be possibly obtained by repeatedly performing the operation, modulo 998244353.

Examples

Input

abc


Output

3


Input

abbac


Output

65


Input

babacabac


Output

6310


Input

ababacbcacbacacbcbbcbbacbaccacbacbacba


Output

148010497

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define mod 998244353

// 文字の総和のmod 3の値は不変
// 到達不可能な状態を数える
// N != 3 なら置き換え前が存在する任意の状態に行ける

// F_mod 上でのべき乗, 蟻本p115
ll modPow(ll x, ll n) {
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll sub(ll x, ll y) {
    x -= y;
    if (x < 0) return x + mod;
    return x;
}

ll dp[200005][3][3] = {}; // dp[N][i][j] N文字目まで並べて総和iで最後尾j

int main() {
    string S;
    cin >> S;
    int N = S.size();
    ll sum = S[N-1];
    bitset<2> flag;
    for (int i = 0; i < N - 1; ++i) {
        if (S[i] == S[i+1]) flag[0] = 1;
        else flag[1] = 1;
        sum += S[i];
    }
    if (! flag[1]) {
        cout << 1 << "\n";
        return 0;
    }

    ll ans = modPow(3, N-1);
    if (N % 3 != 0) {
        ans = sub(ans, modPow(2, N-1));
        if (! flag[0]) (ans += 1) %= mod;
    } else if (N == 3) {
        if (sum % 3) {
            ans = 6;
            if (! flag[0]) (ans += 1) %= mod;
        } else {
            ans = 3;
        }
    } else {
        dp[1][0][0] = dp[1][1][1] = dp[1][2][2] = 1;
        for (int i = 2; i <= N; ++i) {
            (dp[i][0][0] += dp[i-1][0][1] + dp[i-1][0][2]) %= mod;
            (dp[i][0][1] += dp[i-1][2][0] + dp[i-1][2][2]) %= mod;
            (dp[i][0][2] += dp[i-1][1][0] + dp[i-1][1][1]) %= mod;
            (dp[i][1][0] += dp[i-1][1][1] + dp[i-1][1][2]) %= mod;
            (dp[i][1][1] += dp[i-1][0][0] + dp[i-1][0][2]) %= mod;
            (dp[i][1][2] += dp[i-1][2][0] + dp[i-1][2][1]) %= mod;
            (dp[i][2][0] += dp[i-1][2][1] + dp[i-1][2][2]) %= mod;
            (dp[i][2][1] += dp[i-1][1][0] + dp[i-1][1][2]) %= mod;
            (dp[i][2][2] += dp[i-1][0][0] + dp[i-1][0][1]) %= mod;
        }
        ll s = (dp[N][0][0] + dp[N][0][1] + dp[N][0][2]) % mod;
        ll m = (dp[N][1][0] + dp[N][1][1] + dp[N][1][2]) % mod;
        if (sum % 3) {
            ans = sub(ans, m);
        } else {
            ans = sub(ans, s);
        }
        if (! flag[0]) (ans += 1) %= mod;
    }
    cout << ans << "\n";
    return 0;
}
```