#include <iostream>
#include <algorithm>
#include <set>
#include <cstring>
#include <unordered_set>
using namespace std;

const int mod = 998244353;
const int maxn = 2e5 + 7;
char s[maxn];

void add(int &a, int b) {
	a = (a + b) % mod;
}

int f[maxn][3][3][2];
int main() {
	scanf("%s", s);
	int n = strlen(s);
	if (n == 1) printf("1\n");
	else if (n == 2) printf("%d\n", (s[0] == s[1]) ? 1 : 2);
	else if (n == 3) {
		if (s[0] == s[1] && s[0] == s[2]) printf("1\n");
		else if (s[0] != s[1] && s[1] != s[2] && s[2] != s[0]) printf("3\n");
		else if (s[0] != s[1] && s[0] == s[2]) printf("7\n");
		else printf("6\n");
	}
	else {
		bool flag = false;
		for (int i = 1; i < n; i++) {
			if (s[i] != s[i - 1]) flag = true;
		}
		
		if (!flag) {
			printf("1\n");
			return 0;
		}
		
		int cnt = 0;
		for (int i = 0; i < n; i++) cnt = (cnt + s[i] - 'a') % 3;
		
		f[1][1][1][0] = 1; // (pos, last, mod 3, is diff)
		f[1][2][2][0] = 1;
		f[1][0][0][0] = 1;
		for (int i = 2; i <= n; i++) {
			for (int last = 0; last < 3; last++) 
			for (int last_cnt = 0; last_cnt < 3; last_cnt++)
			for (int is_diff = 0; is_diff < 2; is_diff++) 
			for (int cur = 0; cur < 3; cur++) {
				int nxt_cnt = (last_cnt + cur) % 3;
				int cur_diff = 0;
				if (last == cur) cur_diff = 1;
				add(f[i][cur][nxt_cnt][max(cur_diff, is_diff)], f[i - 1][last][last_cnt][is_diff]);
			}
		}
		
		
		int ans = ((f[n][0][cnt][1] + f[n][1][cnt][1]) % mod + f[n][2][cnt][1]) % mod;
		ans = (ans + 1) % mod;
		for (int i = 1; i < n; i++) 
			if (s[i] == s[i - 1]) {
				ans = (ans + mod - 1) % mod;
				break;
			}
		printf("%d\n", ans);
//		printf("%d\n", ((f[n][0][cnt][1] + f[n][1][cnt][1]) % mod + f[n][2][cnt][1]) % mod);
	}
	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 <iostream>
#include <algorithm>
#include <set>
#include <cstring>
#include <unordered_set>
using namespace std;

const int mod = 998244353;
const int maxn = 2e5 + 7;
char s[maxn];

void add(int &a, int b) {
	a = (a + b) % mod;
}

int f[maxn][3][3][2];
int main() {
	scanf("%s", s);
	int n = strlen(s);
	if (n == 1) printf("1\n");
	else if (n == 2) printf("%d\n", (s[0] == s[1]) ? 1 : 2);
	else if (n == 3) {
		if (s[0] == s[1] && s[0] == s[2]) printf("1\n");
		else if (s[0] != s[1] && s[1] != s[2] && s[2] != s[0]) printf("3\n");
		else if (s[0] != s[1] && s[0] == s[2]) printf("7\n");
		else printf("6\n");
	}
	else {
		bool flag = false;
		for (int i = 1; i < n; i++) {
			if (s[i] != s[i - 1]) flag = true;
		}
		
		if (!flag) {
			printf("1\n");
			return 0;
		}
		
		int cnt = 0;
		for (int i = 0; i < n; i++) cnt = (cnt + s[i] - 'a') % 3;
		
		f[1][1][1][0] = 1; // (pos, last, mod 3, is diff)
		f[1][2][2][0] = 1;
		f[1][0][0][0] = 1;
		for (int i = 2; i <= n; i++) {
			for (int last = 0; last < 3; last++) 
			for (int last_cnt = 0; last_cnt < 3; last_cnt++)
			for (int is_diff = 0; is_diff < 2; is_diff++) 
			for (int cur = 0; cur < 3; cur++) {
				int nxt_cnt = (last_cnt + cur) % 3;
				int cur_diff = 0;
				if (last == cur) cur_diff = 1;
				add(f[i][cur][nxt_cnt][max(cur_diff, is_diff)], f[i - 1][last][last_cnt][is_diff]);
			}
		}
		
		
		int ans = ((f[n][0][cnt][1] + f[n][1][cnt][1]) % mod + f[n][2][cnt][1]) % mod;
		ans = (ans + 1) % mod;
		for (int i = 1; i < n; i++) 
			if (s[i] == s[i - 1]) {
				ans = (ans + mod - 1) % mod;
				break;
			}
		printf("%d\n", ans);
//		printf("%d\n", ((f[n][0][cnt][1] + f[n][1][cnt][1]) % mod + f[n][2][cnt][1]) % mod);
	}
	return 0;
}

```