#include <bits/stdc++.h>
#define MOD 998244353LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;

set<string> se;
int dp[300001][3][4][2];

void dfs(string s){
	if(se.find(s)!=se.end())return;
	se.insert(s);
	for(int i=0;i+1<s.size();i++){
		if(s[i]!=s[i+1]){
			for(int j=0;j<3;j++){
				if(s[i]!=('a'+j) && s[i+1]!=('a'+j)){
					string ss=s;
					ss[i]=('a'+j);
					ss[i+1]=('a'+j);
					dfs(ss);
				}
			}
		}
	}
}

int main(void){
	cin >> str;
	if(str.size()<=4){
		dfs(str);
		cout << se.size() << endl;
	}else{
		int n=str.size();
		bool fu=false;
		bool unko=false;
		int cnt=0;
		for(int i=0;i<n;i++){
			cnt+=str[i]-'a';
			if(i<n-1 && str[i]!=str[i+1])fu=true;
			if(i<n-1 && str[i]==str[i+1])unko=true;
		}
		if(!fu){
			printf("1\n");
			return 0;
		}
		dp[0][0][3][0]=1;
		for(int i=0;i<n;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<=3;k++){
					for(int l=0;l<2;l++){
						for(int a=0;a<3;a++){
							dp[i+1][(j+a)%3][a][max(l,a==k?1:0)]+=dp[i][j][k][l];
							dp[i+1][(j+a)%3][a][max(l,a==k?1:0)]%=MOD;
						}
					}
				}
			}
		}
		ll ans=0;
		if(!unko)ans++;
		for(int i=0;i<3;i++){
			ans+=dp[n][cnt%3][i][1];
			ans%=MOD;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
### Prompt

Develop a solution in CPP 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>
#define MOD 998244353LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;

set<string> se;
int dp[300001][3][4][2];

void dfs(string s){
	if(se.find(s)!=se.end())return;
	se.insert(s);
	for(int i=0;i+1<s.size();i++){
		if(s[i]!=s[i+1]){
			for(int j=0;j<3;j++){
				if(s[i]!=('a'+j) && s[i+1]!=('a'+j)){
					string ss=s;
					ss[i]=('a'+j);
					ss[i+1]=('a'+j);
					dfs(ss);
				}
			}
		}
	}
}

int main(void){
	cin >> str;
	if(str.size()<=4){
		dfs(str);
		cout << se.size() << endl;
	}else{
		int n=str.size();
		bool fu=false;
		bool unko=false;
		int cnt=0;
		for(int i=0;i<n;i++){
			cnt+=str[i]-'a';
			if(i<n-1 && str[i]!=str[i+1])fu=true;
			if(i<n-1 && str[i]==str[i+1])unko=true;
		}
		if(!fu){
			printf("1\n");
			return 0;
		}
		dp[0][0][3][0]=1;
		for(int i=0;i<n;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<=3;k++){
					for(int l=0;l<2;l++){
						for(int a=0;a<3;a++){
							dp[i+1][(j+a)%3][a][max(l,a==k?1:0)]+=dp[i][j][k][l];
							dp[i+1][(j+a)%3][a][max(l,a==k?1:0)]%=MOD;
						}
					}
				}
			}
		}
		ll ans=0;
		if(!unko)ans++;
		for(int i=0;i<3;i++){
			ans+=dp[n][cnt%3][i][1];
			ans%=MOD;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
```