Language: C++

#include <iostream>
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
vector<vector<vector<vector<ll>> dp;
ll def;
ll solve(int n,int mod,int ch,int same){
	if(n==1){
		if(same==1){
			return 0;
		}
		if(mod==ch){
			return 1;
		}
		return 0;
	}
	ll &ans=dp[n][mod][ch][same];
	if(~ans)return ans;
	ans=0;
	mod+=3-ch;
	mod%=3;
	if(same){
		for(int i=0;i<3;i++){
			ans+=solve(n-1,mod,i,1);
		}
		ans+=solve(n-1,mod,ch,0);
	}else{
		for(int i=0;i<3;i++){
			if(i!=ch){
			ans+=solve(n-1,mod,i,0);
			}
		}
	}
	ans%=def;
	return ans;
}

int main() {
	 def=998244353;
	string s;cin>>s;
	if(s.size()==2){
		if(s[0]==s[1]){
			cout<<1<<endl;
			return 0;
		}else{
			cout<<2<<endl;
		}
	}else if(s.size()==3){
		int ans;
		if(s[0]==s[1]){
			if(s[1]==s[2]){
				ans=1;
			}else{
				ans=6;
			}
		}else{
			if(s[1]==s[2]){
				ans=6;
			}else{
				if(s[0]==s[2]){
					ans=7;
				}else{
					ans=3;
				}
			}
		}

		cout<<ans<<endl;
		return 0;

	}
//	memset(dp,-1,sizeof(dp));
	dp=vector<100001,vector<vector<vector<ll>>>(3,vector<vector<ll>>(3,vector<ll>(2,-1)))>;
	ll ans=0;
	ll rem=0;
	ll flag=1;
	for(int i=0;i<s.size();i++){
		rem+=int(s[i]-'a');
	}
	rem%=3;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1])flag=0;
	}

		ans+=solve(s.size(),rem,0,1);
		ans+=solve(s.size(),rem,1,1);
		ans+=solve(s.size(),rem,2,1);
		ans+=flag;

	cout<<ans%def<<endl;

//	for(int i=0;i<s.size();i++){
//		cout<<i+1<<endl;
//		for(int j=0;j<3;j++){
//			for(int k=0;k<3;k++){
//				cout<<dp[i+1][j][k][0]<<' ';
//			}
//			cout<<endl;
//		}
//		cout<<endl;
//	}
//
//	for(int i=0;i<s.size();i++){
//		cout<<i+1<<endl;
//		for(int j=0;j<3;j++){
//			for(int k=0;k<3;k++){
//				cout<<dp[i+1][j][k][1]<<' ';
//			}
//			cout<<endl;
//		}
//		cout<<endl;
//	}

	return 0;
}

Compiler output:
a.cc:7:34: error: template argument 1 is invalid
    7 | vector<vector<vector<vector<ll>> dp;
      |                                  ^~
a.cc:7:34: error: template argument 2 is invalid
a.cc:7:8: error: template argument 1 is invalid
    7 | vector<vector<vector<vector<ll>> dp;
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:7:8: error: template argument 2 is invalid
a.cc: In function 'll solve(int, int, int, int)':
a.cc:19:17: error: 'dp' was not declared in this scope; did you mean 'dup'?
   19 |         ll &ans=dp[n][mod][ch][same];
      |                 ^~
      |                 dup
a.cc: In function 'int main()':
a.cc:75:9: error: 'dp' was not declared in this scope; did you mean 'dup'?
   75 |         dp=vector<100001,vector<vector<vector<ll>>>(3,vector<vector<ll>>(3,vector<ll>(2,-1)))>;
      |         ^~
      |         dup
a.cc:75:26: error: temporary of non-literal type 'std::vector<std::vector<std::vector<long long int> > >' in a constant expression
   75 |         dp=vector<100001,vector<vector<vector<ll>>>(3,vector<vector<ll>>(3,vector<ll>(2,-1)))>;
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note: 'std::vector<std::vector<std::vector<long long int> > >' is not literal because:
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector<std::vector<std::vector<long long int> > >' has a non-trivial destructor
a.cc:75:94: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Alloc> class std::vector'
   75 |         dp=vector<100001,vector<vector<vector<ll>>>(3,vector<vector<ll>>(3,vector<ll>(2,-1)))>;
      |                                                                                              ^
a.cc:75:94: note:   expected a type, got '100001'
a.cc:75:94: error: type/value mismatch at argument 2 in template parameter list for 'template<class _Tp, class _Alloc> class std::vector'
a.cc:75:94: note:   expected a type, got 'std::vector<std::vector<std::vector<long long int> > >(3, std::vector<std::vector<long long int> >(3, std::vector<long long int>(2, -1, std::allocator<long long int>()), std::allocator<std::vector<long long int> >()), std::allocator<std::vector<std::vector<long long int> > >())'