#include<cstdio>
#include<set>
#include<cstring>
#include<queue>
#include<string>
using namespace std;
int dp[202222][3][3][2],n;
#define mod 998244353
void addto(int&x,int y){
	x+=y;
	if(x>=mod)x-=mod;
}
char s[202222];
int brute(){
	set<string> Set;
	queue<string> q;
	string S = s;
	q.push(S);
	Set.insert(S);
	while(!q.empty()){
		S = q.front();
		q.pop();
		for(int i=0; i<n-1; i++)if(S[i] != S[i+1]){
			char f = (int)('a') + 'b' + 'c' - S[i] - S[i+1];
			string S2 = S.substr(0,i);
			S2 += f;
			S2 += f;
			S2 += S.substr(i+2, n-(i+2));
			if(!Set.count(S2)){
				Set.insert(S2);
				q.push(S2);
			}
		}
	}
	return Set.size();
}
int main(){
	scanf("%s",s);
	n = strlen(s);
	if(n <= 4){
		printf("%d\n",brute());
		return 0;
	}
	int w = 0;
	bool flag = false, allsame = true;
	for(int i=0; i<n; i++){
		w += (s[i]-'a') % 3;
		if(i > 0 && s[i] == s[i-1])
			flag = true;
		if(i > 0 && s[i] != s[i-1])
			allsame = false;
	}
	if(allsame){
		printf("1\n");
		return 0;
	}
	w %= 3;

	for(int i=0; i<3; i++)dp[1][i][i][0] = 1;
	for(int i=1; i<n; i++){
		for(int sum=0; sum<3; sum++)
		for(int lst=0; lst<3; lst++)
		for(int t=0; t<2; t++)if(dp[i][sum][lst][t])
			for(int j=0; j<3; j++)
				addto(dp[i+1][(sum+j)%3][j][t|(j==lst)], dp[i][sum][lst][t]);
	}
	int res=0;
	for(int lst=0; lst<3; lst++)addto(res, dp[n][w][lst][1]);
	if(!flag)addto(res,1);
	printf("%d\n",res);
	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<cstdio>
#include<set>
#include<cstring>
#include<queue>
#include<string>
using namespace std;
int dp[202222][3][3][2],n;
#define mod 998244353
void addto(int&x,int y){
	x+=y;
	if(x>=mod)x-=mod;
}
char s[202222];
int brute(){
	set<string> Set;
	queue<string> q;
	string S = s;
	q.push(S);
	Set.insert(S);
	while(!q.empty()){
		S = q.front();
		q.pop();
		for(int i=0; i<n-1; i++)if(S[i] != S[i+1]){
			char f = (int)('a') + 'b' + 'c' - S[i] - S[i+1];
			string S2 = S.substr(0,i);
			S2 += f;
			S2 += f;
			S2 += S.substr(i+2, n-(i+2));
			if(!Set.count(S2)){
				Set.insert(S2);
				q.push(S2);
			}
		}
	}
	return Set.size();
}
int main(){
	scanf("%s",s);
	n = strlen(s);
	if(n <= 4){
		printf("%d\n",brute());
		return 0;
	}
	int w = 0;
	bool flag = false, allsame = true;
	for(int i=0; i<n; i++){
		w += (s[i]-'a') % 3;
		if(i > 0 && s[i] == s[i-1])
			flag = true;
		if(i > 0 && s[i] != s[i-1])
			allsame = false;
	}
	if(allsame){
		printf("1\n");
		return 0;
	}
	w %= 3;

	for(int i=0; i<3; i++)dp[1][i][i][0] = 1;
	for(int i=1; i<n; i++){
		for(int sum=0; sum<3; sum++)
		for(int lst=0; lst<3; lst++)
		for(int t=0; t<2; t++)if(dp[i][sum][lst][t])
			for(int j=0; j<3; j++)
				addto(dp[i+1][(sum+j)%3][j][t|(j==lst)], dp[i][sum][lst][t]);
	}
	int res=0;
	for(int lst=0; lst<3; lst++)addto(res, dp[n][w][lst][1]);
	if(!flag)addto(res,1);
	printf("%d\n",res);
	return 0;
}

```