import java.util.*

const val P = 998244353L

fun solveBruteForce(s: String): Int {
  val q = ArrayDeque<String>()
  q.offerLast(s)
  val set = mutableSetOf<String>()
  set.add(s)
  while (q.isNotEmpty()) {
    val state = q.pollFirst()
    for (i in 0 until (state.length - 1)) {
      if (state[i] != state[i + 1]) {
        val c1 = state[i]
        val c2 = state[i + 1]
        ('a'..'c').forEach {
          if (c1 != it && c2 != it) {
            val nextBuilder = StringBuilder(state)
            nextBuilder[i] = it
            nextBuilder[i + 1] = it
            val next = nextBuilder.toString()
            if (!set.contains(next)) {
              q.offerLast(next)
              set.add(next)
            }
          }
        }
      }
    }
  }
  return set.size
}

fun cToI(c: Char) = c - 'a'

fun main(args: Array<String>) {
  val s = readLine()!!

  if (s.all { it == s[0] }) {
    println(1)
    return
  }

  if (s.length <= 3) {
    println(solveBruteForce(s))
    return
  }

  val n = s.length
  // [element index][mod][last]
  val dp1 = Array(n, { Array(3, { LongArray(3, { 0L }) }) })
  val dp2 = Array(n, { Array(3, { LongArray(3, { 0L }) }) })
  for (x in 0..2) {
    dp1[0][x][x] = 1L
    dp2[0][x][x] = 1L
  }
  for (k in 0 until n - 1) {
    for (m in 0..2) {
      for (x in 0..2) {
        for (y in 0..2) {
          dp1[k + 1][(m + y) % 3][y] += dp1[k][m][x]
          dp1[k + 1][(m + y) % 3][y] %= P
          if (x != y) {
            dp2[k + 1][(m + y) % 3][y] += dp2[k][m][x]
            dp2[k + 1][(m + y) % 3][y] %= P
          }
        }
      }
    }
  }
  val sMod = s.map(::cToI).sum() % 3
  val t1 = dp1[n - 1][sMod].sum() % P
  val t2 = dp2[n - 1][sMod].sum() % P
  val sCount = !(0 until n - 1).any { s[it] == s[it + 1] }
  val ans = (t1 + P - t2 + if (sCount) 1 else 0) % P
  println(ans)
}
