#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 998244353
typedef long long ll;
using namespace std;

set<string> ok;
ll dp[200020][3][2][3];

void brute(string s){
    if(ok.count(s)==1) return;
    ok.insert(s);
    for(int i=0;i+1<s.size();i++){
        if(s[i]==s[i+1]) continue;
        int c=0;
        for(int j=0;j<3;j++){
            if(s[i]!='a'+j&&s[i+1]!='a'+j) c=j;
        }
        string t=s;
        t[i]='a'+c;
        t[i+1]='a'+c;
        brute(t);
    }
    return;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();

    int hash=0;
    bool same=true;
    for(int i=0;i<n;i++){
        hash=(hash+s[i]%3)%3;
    }
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]) same=false;
    }
    if(same){
        cout<<1<<endl;
        return 0;
    }

    if(n==3){
        brute(s);
        cout<<ok.size()<<endl;
        return 0;
    }

    dp[0][0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int rest=0;rest<3;rest++){
            for(int f=0;f<2;f++){
                for(int last=0;last<3;last++){
                    for(int next=0;next<3;next++){
                        int adj=f;
                        if(next==last) adj=1;
                        if(i==0) adj=0;
                        int nextRest=(rest+next)%3;
                        dp[i+1][nextRest][adj][next]+=dp[i][rest][f][last];
                        dp[i+1][nextRest][adj][next]%=MOD;
                    }
                }
            }
        }
    }

    ll ans=0;
    for(int i=0;i<3;i++){
        ans=(ans+dp[n][hash][1][i])%MOD;
    }
    bool adj=false;
    for(int i=1;i<n;i++){
        if(s[i]==s[i-1]) adj=true;
    }
    if(adj) cout<<ans<<endl;
    else cout<<(ans+1)%MOD<<endl;

    return 0;
}

### Prompt

Create a solution in cpp for 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 <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 998244353
typedef long long ll;
using namespace std;

set<string> ok;
ll dp[200020][3][2][3];

void brute(string s){
    if(ok.count(s)==1) return;
    ok.insert(s);
    for(int i=0;i+1<s.size();i++){
        if(s[i]==s[i+1]) continue;
        int c=0;
        for(int j=0;j<3;j++){
            if(s[i]!='a'+j&&s[i+1]!='a'+j) c=j;
        }
        string t=s;
        t[i]='a'+c;
        t[i+1]='a'+c;
        brute(t);
    }
    return;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();

    int hash=0;
    bool same=true;
    for(int i=0;i<n;i++){
        hash=(hash+s[i]%3)%3;
    }
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]) same=false;
    }
    if(same){
        cout<<1<<endl;
        return 0;
    }

    if(n==3){
        brute(s);
        cout<<ok.size()<<endl;
        return 0;
    }

    dp[0][0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int rest=0;rest<3;rest++){
            for(int f=0;f<2;f++){
                for(int last=0;last<3;last++){
                    for(int next=0;next<3;next++){
                        int adj=f;
                        if(next==last) adj=1;
                        if(i==0) adj=0;
                        int nextRest=(rest+next)%3;
                        dp[i+1][nextRest][adj][next]+=dp[i][rest][f][last];
                        dp[i+1][nextRest][adj][next]%=MOD;
                    }
                }
            }
        }
    }

    ll ans=0;
    for(int i=0;i<3;i++){
        ans=(ans+dp[n][hash][1][i])%MOD;
    }
    bool adj=false;
    for(int i=1;i<n;i++){
        if(s[i]==s[i-1]) adj=true;
    }
    if(adj) cout<<ans<<endl;
    else cout<<(ans+1)%MOD<<endl;

    return 0;
}

```