Language: C++

define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))


using namespace std;


typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 
typedef long double LD;

const LL MOD = 1000000007;
int N;
string S1,S2;

/*
0 : AA
1 : AB
2 : AC
3 : BA
4 : BB
5 : BC
6 : CA
7 : CB
8 : CC
*/

inline LL Add(LL x, LL y){
	return (x+y)%MOD;
}
void Ad(LL &x, LL y){
	x += y;
	if(x>=MOD) x -= MOD;
}
int main(){
	cin>>N>>S1>>S2;
	vector<vector<vL>> dp(N,vector<vL>(3,vL(3,0)));
	if(S1[0]==S2[0]) for(int k=0;k<3;++k) dp[0][k][k] = 1;
	else for(int k1=0;k1<3;++k1) for(int k2=k1+1;k2<3;++k2) dp[0][k1][k2] = dp[0][k2][k1] = 1;
	for(int i=1;i<N;++i){
		for(int j=0;j<3;++j) for(int k=0;k<3;++k){
			if(S1[i] == S2[i] && j != k) continue;
			if(S1[i] != S2[i] && j == k) continue;
			for(int r=0;r<3;++r) for(int t=0;t<3;++t){
				if(S1[i-1] == S2[i-1] && r != t) continue;
				if(S1[i-1] != S2[i-1] && r == t) continue;
				if(S1[i] == S1[i-1] && r != j) continue;
				if(S1[i] != S1[i-1] && r == j) continue;
				if(S2[i] == S2[i-1] && t != k) continue;
				if(S2[i] != S2[i-1] && t == k) continue;
				dp[i][j][k] += dp[i-1][r][t];
			}
			dp[i][j][k]%=MOD;
		}
	}
	LL ans = 0;
	for(int j=0;j<3;++j) for(int k=0;k<3;++k) Ad(ans, dp[N-1][j][k]);
	cout<<ans<<endl;
	return 0;
}












Compiler output:
a.cc:1:1: error: 'define' does not name a type
    1 | define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
      | ^~~~~~
a.cc:1:37: error: expected constructor, destructor, or type conversion before '<' token
    1 | define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
      |                                     ^
a.cc:1:50: error: expected constructor, destructor, or type conversion before '++' token
    1 | define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
      |                                                  ^~
a.cc:12:9: error: 'vector' does not name a type
   12 | typedef vector<int> vi;
      |         ^~~~~~
a.cc:13:9: error: 'pair' does not name a type
   13 | typedef pair<int,int> ii;
      |         ^~~~
a.cc:14:9: error: 'pair' does not name a type
   14 | typedef pair<int,ii> iii;
      |         ^~~~
a.cc:15:9: error: 'vector' does not name a type
   15 | typedef vector<LL> vL;
      |         ^~~~~~
a.cc:16:9: error: 'vector' does not name a type
   16 | typedef vector<bool> vb;
      |         ^~~~~~
a.cc:17:9: error: 'pair' does not name a type
   17 | typedef pair<int,vi> iv;
      |         ^~~~
a.cc:18:9: error: 'pair' does not name a type
   18 | typedef pair<LL,LL> pLL;
      |         ^~~~
a.cc:23:1: error: 'string' does not name a type
   23 | string S1,S2;
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:45:9: error: 'cin' was not declared in this scope
   45 |         cin>>N>>S1>>S2;
      |         ^~~
a.cc:45:17: error: 'S1' was not declared in this scope; did you mean 'SZ'?
   45 |         cin>>N>>S1>>S2;
      |                 ^~
      |                 SZ
a.cc:45:21: error: 'S2' was not declared in this scope; did you mean 'SZ'?
   45 |         cin>>N>>S1>>S2;
      |                     ^~
      |                     SZ
a.cc:46:9: error: 'vector' was not declared in this scope
   46 |         vector<vector<vL>> dp(N,vector<vL>(3,vL(3,0)));
      |         ^~~~~~
a.cc:46:23: error: 'vL' was not declared in this scope; did you mean 'LL'?
   46 |         vector<vector<vL>> dp(N,vector<vL>(3,vL(3,0)));
      |                       ^~
      |                       LL
a.cc:46:28: error: 'dp' was not declared in this scope
   46 |         vector<vector<vL>> dp(N,vector<vL>(3,vL(3,0)));
      |                            ^~
a.cc:67:9: error: 'cout' was not declared in this scope
   67 |         cout<<ans<<endl;
      |         ^~~~
a.cc:67:20: error: 'endl' was not declared in this scope
   67 |         cout<<ans<<endl;
      |                    ^~~~