Language: C++

#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


const ll mod = (ll)1e9 + 7;
template<ll MOD>struct Mint {
  typedef const Mint&T;
  ll x = 0;
  Mint() {}
  Mint(ll a) { x = a % MOD; if (x < 0) x += MOD; }
  Mint&operator+=(T a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
  Mint&operator-=(T a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; }
  Mint&operator*=(T a) { x = x * a.x % MOD; return *this; }
  Mint&operator/=(T a) { return *this *= a.Pow(MOD - 2); }
  Mint operator+(T a)const { return Mint(*this) += a; }
  Mint operator-(T a)const { return Mint(*this) -= a; }
  Mint operator*(T a)const { return Mint(*this) *= a; }
  Mint operator/(T a)const { return Mint(*this) /= a; }
  bool operator<(T a)const { return x < a.x; }
  bool operator==(T a)const { return x == a.x; }
  Mint Pow(ll k)const {
    if (k == 0) return 1;
    Mint t = Pow(k / 2);
    return t *= (k & 1) ? t * *this : t;
  }
};
template<ll MOD>istream&operator >> (istream&i, Mint<MOD>&a) { return i >> a.x; }
template<ll MOD>ostream&operator<<(ostream&o, const Mint<MOD>&a) { return o << a.x; }
typedef Mint<mod>mint;

template<ll MOD = mod>Mint<MOD> CombMod(int n, int r) {
  Mint<MOD> a = 1, b = 1;
  rep(i, r) { a *= (n - i); }
  repa(i, 2, r + 1) { b *= i; }
  err(a, b);
  return a / b;
}

template<class ...T>tuple<T...>Init(T... t) { return tuple<T...>{ t... }; }
template<class T>tuple<T> Init(T t) { return tuple<T>{ t }; }
template<int N, int...I>struct idx_seq : idx_seq<N - 1, 0, (I + 1)...> {};
template<int...I>struct idx_seq<0, I...> {};
template<class R, class T, int...I>R InitInternal(T&&a, idx_seq<0, I...>) { return R{ get<I>(a)... }; }
template<class T, class B, class...V>struct Vec {
  typedef Vec<T, V...>A; typedef vector<typename A::t>t; t nvec(B a, V...b) { return t(a, A().nvec(b...)); }
};
template<class T, class B>struct Vec<T, B> {
  using X = typename conditional<is_same<T, nullptr_t>::value, int, T>::type;
  typedef vector<X>t; t nvec(B a) { return t(a); }
};
template<class T, class ...C>struct Vec<T, tuple<C...>> {
  template<class A, class B>static pair<A, B> X(A, B);
  template<class...A>static tuple<A...> X(A...);
  using t = typename conditional < is_same<T, nullptr_t>::value, decltype(X(C{}...)), T > ::type;
  t nvec(tuple<C...> a) { return InitInternal<t>(a, idx_seq<sizeof...(C)>()); }
};
template<class T, class C>struct Vec<T, tuple<C>> {
  using X = typename conditional<is_same<T, nullptr_t>::value, C, T>::type;
  using t = X; t nvec(tuple<C> a) { return { get<0>(a) }; }
};
template<class T = nullptr_t, class...B> typename Vec<T, B...>::t nvec(B...b) { return Vec<T, B...>().nvec(b...); }

auto memo = nvec<mint>(0, 0, 0);
int n;
vector<string> s;


void Calc() {

  n = in;
  s = in.Array<string>(2);

  auto dp = nvec<mint>(n, 3, 3);

  int start = s[0][0] != s[1][0];
  if (!start) {
    rep(i, 3)dp[0][i][i] = 1;
  }
  else {
    rep(j, 3)rep(i, 3)if (j != i)dp[1][j][i] = 1;
  }
  err(start);
  bool update;
  rep(i, start + 1, n) {
    update = false;
    rep(j, 3)rep(k, 3) {
      if (s[0][i] == s[1][i]) {
        if (j != k)continue;
        rep(x, 3)if (j != x)rep(y, 3)if (k != y) {
          dp[i][j][k] += dp[i - 1][x][y];
        }
      }
      else {
        if (j == k)continue;
        rep(x, 3)if (j != x)rep(y, 3)if (k != y) {
          dp[i][j][k] += dp[i - 1][x][y];
        }

        dp[i + 1] = dp[i];
        update = true;
      }
    }
    if (update)
      i++;
  }
  mint ans = 0;
  err(dp);
  rep(x, 3)rep(y, 3)ans += dp[n - 1][x][y];
  cout << ans << endl;
}


Compiler output:
a.cc: In function 'Mint<MOD> CombMod(int, int)':
a.cc:67:8: error: 'i' was not declared in this scope
   67 |   repa(i, 2, r + 1) { b *= i; }
      |        ^
a.cc:67:3: error: there are no arguments to 'repa' that depend on a template parameter, so a declaration of 'repa' must be available [-fpermissive]
   67 |   repa(i, 2, r + 1) { b *= i; }
      |   ^~~~
a.cc:67:3: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:67:20: error: expected ';' before '{' token
   67 |   repa(i, 2, r + 1) { b *= i; }
      |                    ^~
      |                    ;