output_description: Print the number of strings that can be possibly obtained by repeatedly
  performing the operation, modulo 998244353.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S
attempt: import sys
  
  S=int(input())
  
  if len(S)==2:
      if S[0]==S[1]:
          print(1)
      else:
          print(2)
      sys.exit()    
  
  flag1=0
  flag2=0
  for i in range(len(S)):
      if S[i] != S[0]:
          flag1 = 1
          break
  
  for i in range(len(S)-1):
      if S[i+1] == S[i]:
          flag2 = 1
          break
  
  c=0
  for i in range(len(S)):
      if S[i]=='a':
          c+=1
      elif S[i]=='b':
          c+=2
  
  if flag1==0:
      print(1)
      sys.exit()    
  L = len(S)
  dp = [[[[0] for i in range(3)] for j in range(3)] for k in range(L)]
  for a in range(3)
  dp[1][a][a]=1
  for i in range(L):
      for p in range(3):
          for a in range(3)
          dp[i][p+(a+1)%3][(a+1)%3] += dp[i-1][p][a] 
          dp[i][p+(a+2)%3][(a+2)%3] += dp[i-1][p][a] 
  
  print(3**(len(S)-1) + dp[L][c%3][0] + dp[L][c%3][1]+ dp[L][c%3][2] + (1-flag2))
  
  
  
  
problem_description: Statement
  
  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`).
samples: [{"input": "abc", "output": "3\n    \n\n`abc`, `aaa` and `ccc` can be obtained.\n\n* * *"}, {"input": "abbac", "output": "65\n    \n\n* * *"}, {"input": "babacabac", "output": "6310\n    \n\n* * *"}, {"input": "ababacbcacbacacbcbbcbbacbaccacbacbacba", "output": "148010497"}]