#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 998244353;

string s;
lli n;
unordered_set<string> mem;
lli dp[e5][3][3][3];


 bool judge(){
	 for(lli i = 0;i < n;i++){
		 if(s[i] != s[0]) return false;
	 }
	 return true;
 }

 bool judge2(){
	 for(lli i = 1;i < n;i++){
		 if(s[i] == s[i-1]) return true;
	 }
	 return false;
 }

 lli dfs(string s){
	 if(mem.count(s)) return 0;
	 mem.insert(s);
	 lli ret = 1;
	 for(lli i = 1;i < n;i++){
		 if(s[i-1] != s[i]){
			 string s_ = s;
			 for(char c = 'a';c <= 'c';c++){
				 if(c != s[i-1] && c != s[i]){
					 s_[i-1] = c;
					 s_[i] = c;
					 ret += dfs(s_);
					 ret %= mod;
					 break;
				 }
			 }
		 }
	 }
	 return ret;
 }

int main(){
	cin >> s;
	n = s.size();
	if(judge()){
		cout << 1 << endl;
		return 0;
	}
	if(n == 3){
		cout << dfs(s) << endl;
		return 0;
	}
	dp[0][0][0][0] = dp[0][1][1][0] = dp[0][2][2][0] = 1;
	for(lli i = 0;i < n;i++){
		for(lli j = 0;j < 3;j++){ // mod
			for(lli k = 0;k < 3;k++){ // prev
				for(lli l = 0;l < 2;l++){ // bool
					for(lli m = 0;m < 3;m++){
						dp[i+1][(j+m)%3][m][l||(k==m)] += dp[i][j][k][l];
						dp[i+1][(j+m)%3][m][l||(k==m)] %= mod;
					}
				}
			}
		}
	}
	lli ans = 0;
	for(lli i = 0;i < n;i++){
		ans = (ans+(s[i]-'a'))%3;
	}
	for(lli i = 0;i < 3;i++){
		cerr << dp[n-1][i][0][1]+dp[n-1][i][1][1]+dp[n-1][i][2][1] << endl;
	}
	if(judge2()) cout << (dp[n-1][ans][0][1]+dp[n-1][ans][1][1]+dp[n-1][ans][2][1])%mod << endl;
	else cout << (dp[n-1][ans][0][1]+dp[n-1][ans][1][1]+dp[n-1][ans][2][1]+1)%mod << endl;
}

### Prompt

Please create a solution in Cpp 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;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 998244353;

string s;
lli n;
unordered_set<string> mem;
lli dp[e5][3][3][3];


 bool judge(){
	 for(lli i = 0;i < n;i++){
		 if(s[i] != s[0]) return false;
	 }
	 return true;
 }

 bool judge2(){
	 for(lli i = 1;i < n;i++){
		 if(s[i] == s[i-1]) return true;
	 }
	 return false;
 }

 lli dfs(string s){
	 if(mem.count(s)) return 0;
	 mem.insert(s);
	 lli ret = 1;
	 for(lli i = 1;i < n;i++){
		 if(s[i-1] != s[i]){
			 string s_ = s;
			 for(char c = 'a';c <= 'c';c++){
				 if(c != s[i-1] && c != s[i]){
					 s_[i-1] = c;
					 s_[i] = c;
					 ret += dfs(s_);
					 ret %= mod;
					 break;
				 }
			 }
		 }
	 }
	 return ret;
 }

int main(){
	cin >> s;
	n = s.size();
	if(judge()){
		cout << 1 << endl;
		return 0;
	}
	if(n == 3){
		cout << dfs(s) << endl;
		return 0;
	}
	dp[0][0][0][0] = dp[0][1][1][0] = dp[0][2][2][0] = 1;
	for(lli i = 0;i < n;i++){
		for(lli j = 0;j < 3;j++){ // mod
			for(lli k = 0;k < 3;k++){ // prev
				for(lli l = 0;l < 2;l++){ // bool
					for(lli m = 0;m < 3;m++){
						dp[i+1][(j+m)%3][m][l||(k==m)] += dp[i][j][k][l];
						dp[i+1][(j+m)%3][m][l||(k==m)] %= mod;
					}
				}
			}
		}
	}
	lli ans = 0;
	for(lli i = 0;i < n;i++){
		ans = (ans+(s[i]-'a'))%3;
	}
	for(lli i = 0;i < 3;i++){
		cerr << dp[n-1][i][0][1]+dp[n-1][i][1][1]+dp[n-1][i][2][1] << endl;
	}
	if(judge2()) cout << (dp[n-1][ans][0][1]+dp[n-1][ans][1][1]+dp[n-1][ans][2][1])%mod << endl;
	else cout << (dp[n-1][ans][0][1]+dp[n-1][ans][1][1]+dp[n-1][ans][2][1]+1)%mod << endl;
}

```