#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
map<string, int> used;
int n;
int calc(const string &s) {
	int res = 0;
	queue<string>q;
	used[s] = true; q.push(s); res++;
	while (!q.empty()) {
		string x = q.front(); q.pop();
		rep(i, n - 1) {
			if (x[i] != x[i + 1]) {
				string y = x;
				char t = 'a' + (3 - (x[i] - 'a') - (x[i+1] - 'a'));
				y[i] = y[i + 1] = t;
				if (used[y])continue;
				//cout << y << endl;
				used[y] = true; res++; q.push(y);
			}
		}
	}
	return res;
}
//何文字目、同じとこあったか、総和のmod3、前回
ll dp[1 << 18][2][3][3];
int main() {
	string s; cin >> s; n = s.length();
	if (s.length() <= 4) {
		cout << calc(s) << endl;
	}
	else {
		ll ans = 0;
		int sum = 0;
		bool f = true; bool g = true;
		rep(i, n - 1) {
			if (s[i] == s[i + 1])f = false;
			if (s[i] != s[i + 1])g = false;
		}
		if (g) {
			cout << 1 << endl; return 0;
		}
		if (f)ans++;
		rep(i, n) {
			sum += s[i] - 'a'; sum %= 3;
		}
		dp[0][0][0][0] = dp[0][0][1][1] = dp[0][0][2][2] = 1;
		rep(i, n - 1) {
			rep(j, 3) {
				rep(k, 3) {
					rep(l, 3) {
						(dp[i + 1][1][(j + l) % 3][l] += dp[i][1][j][k]) %= mod;
						if (k == l) {
							(dp[i + 1][1][(j + l) % 3][l] += dp[i][0][j][k]) %= mod;
						}
						else {
							(dp[i + 1][0][(j + l) % 3][l] += dp[i][0][j][k]) %= mod;
						}
					}
				}
			}
		}
		rep(j, 3) {
			ans += dp[n - 1][1][sum][j]; ans %= mod;
		}
		cout << ans << endl;
	}
	//stop
	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<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
map<string, int> used;
int n;
int calc(const string &s) {
	int res = 0;
	queue<string>q;
	used[s] = true; q.push(s); res++;
	while (!q.empty()) {
		string x = q.front(); q.pop();
		rep(i, n - 1) {
			if (x[i] != x[i + 1]) {
				string y = x;
				char t = 'a' + (3 - (x[i] - 'a') - (x[i+1] - 'a'));
				y[i] = y[i + 1] = t;
				if (used[y])continue;
				//cout << y << endl;
				used[y] = true; res++; q.push(y);
			}
		}
	}
	return res;
}
//何文字目、同じとこあったか、総和のmod3、前回
ll dp[1 << 18][2][3][3];
int main() {
	string s; cin >> s; n = s.length();
	if (s.length() <= 4) {
		cout << calc(s) << endl;
	}
	else {
		ll ans = 0;
		int sum = 0;
		bool f = true; bool g = true;
		rep(i, n - 1) {
			if (s[i] == s[i + 1])f = false;
			if (s[i] != s[i + 1])g = false;
		}
		if (g) {
			cout << 1 << endl; return 0;
		}
		if (f)ans++;
		rep(i, n) {
			sum += s[i] - 'a'; sum %= 3;
		}
		dp[0][0][0][0] = dp[0][0][1][1] = dp[0][0][2][2] = 1;
		rep(i, n - 1) {
			rep(j, 3) {
				rep(k, 3) {
					rep(l, 3) {
						(dp[i + 1][1][(j + l) % 3][l] += dp[i][1][j][k]) %= mod;
						if (k == l) {
							(dp[i + 1][1][(j + l) % 3][l] += dp[i][0][j][k]) %= mod;
						}
						else {
							(dp[i + 1][0][(j + l) % 3][l] += dp[i][0][j][k]) %= mod;
						}
					}
				}
			}
		}
		rep(j, 3) {
			ans += dp[n - 1][1][sum][j]; ans %= mod;
		}
		cout << ans << endl;
	}
	//stop
	return 0;
}

```