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

const int mod = 998244353;
const int MN = 200010;

int N;
string S;
int dp[MN][3][3];
map<string, int> vis;

string nxt(string &s) {
    string ret = s;
    if(s[0] != s[1]) {
        ret[0] = 'a' + 'b' + 'c' - s[0] - s[1];
        ret[1] = ret[0];
    }
    else if(s[1] != s[2]) {
        ret[1] = 'a' + 'b' + 'c' - s[1] - s[2];
        ret[2] = ret[1];
    }
    return ret;
}
bool same() {
    for(int i = 0; i < N - 1; i++) if(S[i] != S[i + 1]) return false;
    return true;
}

int main() {
    cin >> S;
    N = S.size();

    int rem = 0;
    for(int i = 0; i < N; i++) {
        rem += S[i] - 'a';
        rem %= 3;
    }

    if(N == 2) {
        if(S[0] == S[1]) printf("1");
        else printf("2");
        return 0;
    }
    if(N == 3) {
        vis[S] = 1;
        if(S[0] != S[1]) {
            string T = S;
            T[0] = 'a' + 'b' + 'c' - S[0] - S[1];
            T[1] = T[0];

            while(!vis[T]) {
                vis[T] = 1;
                T = nxt(T);
            }
        }
        if(S[1] != S[2]) {
            string T = S;
            T[1] = 'a' + 'b' + 'c' - S[1] - S[2];
            T[2] = T[1];

            while(!vis[T]) {
                vis[T] = 1;
                T = nxt(T);
            }
        }

        cout << vis.size();
        return 0;
    }
    if(same()) {
        cout << 1;
        return 0;
    }

    int ans = 1;
    for(int i = 0; i < N - 1; i++) {
        ans = 1LL * ans * 3 % mod;
    }

    for(int i = 0; i < 3; i++) {
        dp[N][i][rem] = 1;
    }
    for(int i = N - 1; i >= 0; i--) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                for(int a = 0; a < 3; a++) {
                    if(a == j) continue;
                    dp[i][j][k] += dp[i + 1][a][(k + a) % 3];
                    dp[i][j][k] %= mod;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++) {
        ans += mod - dp[1][i][i];
        ans %= mod;
    }

    bool ok = true;
    for(int i = 0; i < N - 1; i++) if(S[i] == S[i + 1]) {
        ok = false;
        break;
    }
    if(ok) {
        ans++;
        ans %= mod;
    }

    cout << ans;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

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;

const int mod = 998244353;
const int MN = 200010;

int N;
string S;
int dp[MN][3][3];
map<string, int> vis;

string nxt(string &s) {
    string ret = s;
    if(s[0] != s[1]) {
        ret[0] = 'a' + 'b' + 'c' - s[0] - s[1];
        ret[1] = ret[0];
    }
    else if(s[1] != s[2]) {
        ret[1] = 'a' + 'b' + 'c' - s[1] - s[2];
        ret[2] = ret[1];
    }
    return ret;
}
bool same() {
    for(int i = 0; i < N - 1; i++) if(S[i] != S[i + 1]) return false;
    return true;
}

int main() {
    cin >> S;
    N = S.size();

    int rem = 0;
    for(int i = 0; i < N; i++) {
        rem += S[i] - 'a';
        rem %= 3;
    }

    if(N == 2) {
        if(S[0] == S[1]) printf("1");
        else printf("2");
        return 0;
    }
    if(N == 3) {
        vis[S] = 1;
        if(S[0] != S[1]) {
            string T = S;
            T[0] = 'a' + 'b' + 'c' - S[0] - S[1];
            T[1] = T[0];

            while(!vis[T]) {
                vis[T] = 1;
                T = nxt(T);
            }
        }
        if(S[1] != S[2]) {
            string T = S;
            T[1] = 'a' + 'b' + 'c' - S[1] - S[2];
            T[2] = T[1];

            while(!vis[T]) {
                vis[T] = 1;
                T = nxt(T);
            }
        }

        cout << vis.size();
        return 0;
    }
    if(same()) {
        cout << 1;
        return 0;
    }

    int ans = 1;
    for(int i = 0; i < N - 1; i++) {
        ans = 1LL * ans * 3 % mod;
    }

    for(int i = 0; i < 3; i++) {
        dp[N][i][rem] = 1;
    }
    for(int i = N - 1; i >= 0; i--) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                for(int a = 0; a < 3; a++) {
                    if(a == j) continue;
                    dp[i][j][k] += dp[i + 1][a][(k + a) % 3];
                    dp[i][j][k] %= mod;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++) {
        ans += mod - dp[1][i][i];
        ans %= mod;
    }

    bool ok = true;
    for(int i = 0; i < N - 1; i++) if(S[i] == S[i + 1]) {
        ok = false;
        break;
    }
    if(ok) {
        ans++;
        ans %= mod;
    }

    cout << ans;
}

```