Problem:
Score : 400 points

Problem Statement

We have a board with a 2 \times N grid.
Snuke covered the board with N dominoes without overlaps.
Here, a domino can cover a 1 \times 2 or 2 \times 1 square.

Then, Snuke decided to paint these dominoes using three colors: red, cyan and green.
Two dominoes that are adjacent by side should be painted by different colors.
Here, it is not always necessary to use all three colors.

Find the number of such ways to paint the dominoes, modulo 1000000007.

The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner:

Each domino is represented by a different English letter (lowercase or uppercase).

The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.

Constraints

1 \leq N \leq 52

|S_1| = |S_2| = N

S_1 and S_2 consist of lowercase and uppercase English letters.

S_1 and S_2 represent a valid arrangement of dominoes.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2

Output

Print the number of such ways to paint the dominoes, modulo 1000000007.

Sample Input 1

3
aab
ccb

Sample Output 1

6

There are six ways as shown below:

Sample Input 2

1
Z
Z

Sample Output 2

3

Note that it is not always necessary to use all the colors.

Sample Input 3

52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn

Sample Output 3

958681902

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <assert.h>
#include <map>
#include <math.h>

using std::cerr;
using std::cin;
using std::cout;
using std::pair;
using std::string;
using std::vector;
//region
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b); i >= (b); --i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n)-1; i >= 0; --i)
#define repr1(i, n) for (int i = (n); i > 0; --i)
#define outif(b, t, f) cout << ((b) ? (t) : (f)) << endl
#define all(vec) (vec).begin(), (vec).end()
#define sz(x) (int((x).size()))
#define mset(v, n) std::memset((v), n, sizeof(v))
#define BIT(N) (1LL << (N))
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using vint = vector<int>;
using vlong = vector<ll>;
using vstr = vector<string>;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpll = vector<pll>;
using vvi = vector<vint>;
using vvl = vector<vlong>;
vector<string> split(const string &s, const string &delim) {
  vector<string> res;
  uint pos = 0;
  while (true) {
    const int found = s.find(delim, pos);
    if (found < 0) {
      res.push_back(s.substr(pos));
      break;
    }
    res.push_back(s.substr(pos, found - pos));
    pos = found + delim.size();
  }
  return res;
}
template<typename T> string join(vector<T> &vec, const string &sep) {
  size_t size = vec.size();
  if (!size) return "";
  std::stringstream ss;
  for (int i = 0; i < size - 1; i++)
    ss << vec[i] << sep;
  ss << vec[size - 1];
  return ss.str();
}
template<typename T> std::istream &operator>>(std::istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template<typename Iter> inline void print(const Iter &first, const Iter &last, const std::string &d, bool endline) {
  cout << *first;
  for (Iter iter = first + 1; iter < last; ++iter) {
    cout << d << *iter;
  }
  if (endline) cout << "\n";
}
constexpr ll powmod(ll a, ull b, ull p) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) res = res * a % p;
    a = a * a % p;
    b >>= 1u;
  }
  return res;
}
template<class T> bool chmax(T &a, const T &b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, const T &b) { return a > b ? (a = b, true) : false; }
template <typename T> void bsort(vector<T>& v) { std::sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T>& v) { std::sort(v.begin(), v.end(), std::greater<T>()); }
struct iii {
    iii() {
      cin.tie(nullptr); cout.tie(nullptr);
      std::ios::sync_with_stdio(false);
      cout << std::fixed << std::setprecision(16);
    }
} init;
//endregion

void solve();

int main() {
  int t = 1;
  // scanf("%d", &t);
  rep(_,t) solve();
  return 0;
}

void solve() {
  int N; string S1, S2;
  cin >> N >> S1 >> S2;
  const int mod = 1e9+7;

  ll res = 3;
  if (S1[0] != S2[0]) res *= 2;

  for (int i = 1; i < N; ++i) {
    if(S1[i]==S2[i]) {
      // 縦
      if(S1[i - 1] == S2[i - 1]) {
        // 縦→縦
        res *= 2;
      } else {
        // 横→縦
      }
    } else {
      // 横
      if(S1[i] ==S1[i - 1]) continue;
      if(S1[i - 1] == S2[i - 1]) {
        // 縦→横
        res *= 2;
      } else {
        // 横→横
        res *= 3;
      }
    }

    res %= mod;
  }

  printf("%lld", res % mod);
}