#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

bool f(string s, string t) {
    set<string> st;

    queue<string> Q;
    Q.push(s);
    while (!Q.empty()) {
        s = Q.front();
        Q.pop();
        if (st.count(s))continue;
        if (s == t)return true;
        st.insert(s);
        rep(i, sz(s) - 1) {
            if (s[i] != s[i + 1]) {
                for (char c = 'a'; c <= 'c'; ++c)if (s[i] != c&&s[i + 1] != c) {
                    string ns = s;
                    ns[i] = ns[i + 1] = c;
                    if (!st.count(ns)) {
                        Q.push(ns);
                    }
                    break;
                }
            }
        }
    }

    return false;
}

vector<string> gen(int L = 3) {
    string s(L, ' ');
    vector<string> res;
    for (int i = 0;; ++i) {
        int x = i;
        int cnt = 0;
        rep(j, L) {
            int md = x % 3;
            s[L - 1 - j] = (char)(md + 'a');
            x /= 3;
            if (md == 2)cnt++;
        }
        res.push_back(s);
        if (cnt == L)break;
    }
    return res;
}

bool g(string s, string t) {
    if (sz(s) == 3)return f(s, t);
    int m1 = 0, m2 = 0;
    rep(i, sz(s)) {
        m1 += s[i] - 'a';
        m2 += t[i] - 'a';
    }
    m1 %= 3;
    m2 %= 3;
    if (m1 != m2)return false;

    if (s == t)return true;
    int out = 0, in = 0;
    rep(i, sz(s) - 1)if (s[i] != s[i + 1])out++;
    rep(i, sz(t) - 1)if (t[i] == t[i + 1])in++;
    if (out == 0 || in == 0)return false;
    return true;
}

void test() {
    auto S = gen();
    for (auto s : S) for (auto t : S) {
        if (f(s, t) != g(s, t)) {
            cout << s << ' ' << t << endl;
        }
    }
}

const int MOD = 998244353;
void sadd(int &a, int b) {
    a += b;
    if (a >= MOD)a -= MOD;
    else if (a < 0)a += MOD;
}

int dp[200005][2][3][3];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string S;
    cin >> S;
    const int N = sz(S);
    if (N <= 3) {
        auto T = gen(N);
        int ans = 0;
        each(t, T)if (f(S, t))ans++;
        cout << ans << endl;
    } else {
        int M = 0;
        rep(i, N)M += S[i] - 'a';
        M %= 3;
        int in = 0, out = 0;
        rep(i, N - 1) {
            if (S[i] != S[i + 1])out++;
            else in++;
        }

        if (out == 0) {
            cout << 1 << endl;
            return 0;
        }

        rep(i, 3)dp[1][0][i][i] = 1;
        FOR(i, 1, N)rep(j, 2)rep(k, 3)rep(m, 3) {
            rep(nk, 3) {
                int nj = j;
                nj |= k == nk;
                int nm = (m + nk) % 3;
                sadd(dp[i + 1][nj][nk][nm], dp[i][j][k][m]);
            }
        }

        int ans = in == 0;
        rep(k, 3)sadd(ans, dp[N][1][k][M]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 14612