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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

set<string> ans;

void go(string& s)
{
	if (ans.count(s)) return;
	ans.insert(s);
	FOR(i, 0, SZ(s) - 1) if (s[i] != s[i + 1])
	{
		char a = s[i], b = s[i + 1];
		char c = 'a';
		while(a == c || b == c) c++;
		s[i] = s[i + 1] = c;
		go(s);
		s[i] = a;
		s[i + 1] = b;
	}
}

const int N = 1 << 18;
int dp[N][3][3][2];
const int mod = 998244353;

int add(int x, int y)
{
	if (x + y < mod) return x + y;
	return x + y - mod;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	string s;
	cin >> s;
	bool vse = 1;
	FOR(i, 1, SZ(s)) vse &= s[i] == s[0];
	if (vse || SZ(s) <= 7)
	{
		go(s);
		cout << SZ(ans) << endl;
		return 0;
	}
	
	int sum = 0;
	for(auto& i: s) i -= 'a', sum += i;
	sum %= 3;
	
	bool was = 0;
	FOR(i, 0, SZ(s) - 1) was |= s[i] == s[i + 1];
	
	FOR(i, 0, 3) dp[1][i][i][0] = 1;
	FOR(n, 2, SZ(s) + 1)
		FOR(zara, 0, 3) FOR(pered, 0, 3) FOR(bulo, 0, 2)
		{
			if (!bulo && zara != pered)
			{
				FOR(su, 0, 3)
					dp[n][zara][(su + zara) % 3][0] = add(dp[n][zara][(su + zara) % 3][0],
					dp[n - 1][pered][su][0]);
			}else
			{
				FOR(su, 0, 3)
					dp[n][zara][(su + zara) % 3][1] = add(dp[n][zara][(su + zara) % 3][1],
					dp[n - 1][pered][su][bulo]);
			}
		}
		
	int ans = 0;
	FOR(i, 0, 3) ans = add(ans, dp[SZ(s)][i][sum][1]);
	if (!was) ans = add(ans, 1);
	cout << ans << endl;
		
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}

### Prompt

In CPP, your task is to solve 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 LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

set<string> ans;

void go(string& s)
{
	if (ans.count(s)) return;
	ans.insert(s);
	FOR(i, 0, SZ(s) - 1) if (s[i] != s[i + 1])
	{
		char a = s[i], b = s[i + 1];
		char c = 'a';
		while(a == c || b == c) c++;
		s[i] = s[i + 1] = c;
		go(s);
		s[i] = a;
		s[i + 1] = b;
	}
}

const int N = 1 << 18;
int dp[N][3][3][2];
const int mod = 998244353;

int add(int x, int y)
{
	if (x + y < mod) return x + y;
	return x + y - mod;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	string s;
	cin >> s;
	bool vse = 1;
	FOR(i, 1, SZ(s)) vse &= s[i] == s[0];
	if (vse || SZ(s) <= 7)
	{
		go(s);
		cout << SZ(ans) << endl;
		return 0;
	}
	
	int sum = 0;
	for(auto& i: s) i -= 'a', sum += i;
	sum %= 3;
	
	bool was = 0;
	FOR(i, 0, SZ(s) - 1) was |= s[i] == s[i + 1];
	
	FOR(i, 0, 3) dp[1][i][i][0] = 1;
	FOR(n, 2, SZ(s) + 1)
		FOR(zara, 0, 3) FOR(pered, 0, 3) FOR(bulo, 0, 2)
		{
			if (!bulo && zara != pered)
			{
				FOR(su, 0, 3)
					dp[n][zara][(su + zara) % 3][0] = add(dp[n][zara][(su + zara) % 3][0],
					dp[n - 1][pered][su][0]);
			}else
			{
				FOR(su, 0, 3)
					dp[n][zara][(su + zara) % 3][1] = add(dp[n][zara][(su + zara) % 3][1],
					dp[n - 1][pered][su][bulo]);
			}
		}
		
	int ans = 0;
	FOR(i, 0, 3) ans = add(ans, dp[SZ(s)][i][sum][1]);
	if (!was) ans = add(ans, 1);
	cout << ans << endl;
		
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}

```