#include <bits/stdc++.h>

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n;
  string s;
  cin >> s;
  n = s.size();
  if (count(all(s), 'a') == n || count(all(s), 'b') == n || count(all(s), 'c') == n) {
    cout << 1 << endl;
    return 0;
  }
  std::random_device rd;
  std::mt19937 mt(rd());
  if (n <= 3) {
    set<string> st;
    string t = s;
    int cnt = 0;
    while (cnt < 1000) {
      st.insert(t);
      int i = mt() % (n - 1);
      if (t[i] != t[i + 1]) {
        int k = 3 - (t[i] - 'a' + t[i + 1] - 'a');
        t[i] = t[i + 1] = 'a' + k;
        cnt++;
        if (count(all(t), 'a') == n || count(all(t), 'b') == n || count(all(t), 'c') == n) {
          st.insert(t);
          t = s;
        }
      }
    }
    cout << st.size() << endl;
    return 0;
  }
  bool flag = true;
  rep (i, n - 1) {
    if (s[i] == s[i + 1]) {
      flag = false;
    }
  }
  int g = 0;
  rep (i, n) {
    g += s[i] - 'a';
  }
  g %= 3;
  vector<vector<vll> > dp(n + 1, vector<vll>(3, vll(3, vl(2))));
  dp[1][0][0][0] = dp[1][1][1][0] = dp[1][2][2][0] = 1;
  rep1 (i, n - 1) {
    rep (j, 3) {
      rep (k, 3) {
        int add = (k + 1) % 3;
        (dp[i + 1][(j + add) % 3][add][0] += dp[i][j][k][0]) %= MOD;
        add = (k + 2) % 3;
        (dp[i + 1][(j + add) % 3][add][0] += dp[i][j][k][0]) %= MOD;
        add = k;
        (dp[i + 1][(j + add) % 3][add][1] += dp[i][j][k][0]) %= MOD;
        rep (add, 3) {
          (dp[i + 1][(j + add) % 3][add][1] += dp[i][j][k][1]) %= MOD;
        }
      }
    }
  }
  ll ans = (int)flag;
  rep (k, 3) {
    ans += dp[n][g][k][1];
  }
  cout << ans % MOD << endl;
        
}


Measured memory_bytes: 123908