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

string S;
int l;
set<string> seen;
int dp[200000][3/*和 mod 3*/][4/*
  0/1/2: まだ連続する2数字が出現しておらず、0/1/2で終わる
  3: すでに連続する2数字が出現している*/];
#define MOD 998244353

void see(const string& s) {
  if(seen.count(s)) return;
  seen.insert(s);
  for(int i = 0; i < l - 1; ++i) {
    if(s[i] != s[i + 1]) {
      string t = s; t[i] = t[i + 1] = 3 - s[i] - s[i + 1];
      see(t);
    }
  }
}

int main() {
  cin >> S; l = S.size();
  for(int i = 0; i < l; ++i) S[i] -= 'a';
  bool good = false;
  for(int i = 0; i < l - 1; ++i) if(S[i] != S[i + 1]) good = true;
  if(!good) {
    cout << 1 << endl;
  } else if(l <= 3) {
    see(S);
    cout << seen.size() << endl;
  } else {
    dp[0][0][0] = dp[0][1][1] = dp[0][2][2] = 1;
    for(int i = 1; i < l; ++i) {
      int prev = i - 1, cur = i;
      for(int mod = 0; mod < 3; ++mod) for(int last = 0; last < 3; ++last) {
        int new_mod = (mod + last) % 3;
        (dp[cur][new_mod][3] += dp[prev][mod][last]) %= MOD;
        (dp[cur][new_mod][3] += dp[prev][mod][3]) %= MOD;
        for(int prelast = 0; prelast < 3; ++prelast) {
          if(last == prelast) continue;
          (dp[cur][new_mod][last] += dp[prev][mod][prelast]) %= MOD;
        }
      }
    }
    int mod = 0;
    for(int i = 0; i < l; ++i) (mod += S[i]) %= 3;
    bool strange = true;
    for(int i = 0; i < l - 1; ++i) if(S[i] == S[i + 1]) strange = false;
    cout << (dp[l - 1][mod][3] + strange) % MOD << endl;
  }
  return 0;
}

### Prompt

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

string S;
int l;
set<string> seen;
int dp[200000][3/*和 mod 3*/][4/*
  0/1/2: まだ連続する2数字が出現しておらず、0/1/2で終わる
  3: すでに連続する2数字が出現している*/];
#define MOD 998244353

void see(const string& s) {
  if(seen.count(s)) return;
  seen.insert(s);
  for(int i = 0; i < l - 1; ++i) {
    if(s[i] != s[i + 1]) {
      string t = s; t[i] = t[i + 1] = 3 - s[i] - s[i + 1];
      see(t);
    }
  }
}

int main() {
  cin >> S; l = S.size();
  for(int i = 0; i < l; ++i) S[i] -= 'a';
  bool good = false;
  for(int i = 0; i < l - 1; ++i) if(S[i] != S[i + 1]) good = true;
  if(!good) {
    cout << 1 << endl;
  } else if(l <= 3) {
    see(S);
    cout << seen.size() << endl;
  } else {
    dp[0][0][0] = dp[0][1][1] = dp[0][2][2] = 1;
    for(int i = 1; i < l; ++i) {
      int prev = i - 1, cur = i;
      for(int mod = 0; mod < 3; ++mod) for(int last = 0; last < 3; ++last) {
        int new_mod = (mod + last) % 3;
        (dp[cur][new_mod][3] += dp[prev][mod][last]) %= MOD;
        (dp[cur][new_mod][3] += dp[prev][mod][3]) %= MOD;
        for(int prelast = 0; prelast < 3; ++prelast) {
          if(last == prelast) continue;
          (dp[cur][new_mod][last] += dp[prev][mod][prelast]) %= MOD;
        }
      }
    }
    int mod = 0;
    for(int i = 0; i < l; ++i) (mod += S[i]) %= 3;
    bool strange = true;
    for(int i = 0; i < l - 1; ++i) if(S[i] == S[i + 1]) strange = false;
    cout << (dp[l - 1][mod][3] + strange) % MOD << endl;
  }
  return 0;
}

```