output_description: Print the number of such ways to paint the dominoes, modulo 1000000007.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      S_1
      S_2
attempt: from functools import reduce
  
  # 入力
  N = int(input())
  S1 = input()
  S2 = input()
  
  MOD = 1000000007
  
  
  class ModInt:
      def __init__(self, x):
          self.x = x % MOD
  
      def __str__(self):
          return str(self.x)
  
      __repr__ = __str__
  
      def __add__(self, other):
          return (
              ModInt(self.x + other.x)
              if isinstance(other, ModInt)
              else ModInt(self.x + other)
          )
  
      def __sub__(self, other):
          return (
              ModInt(self.x - other.x)
              if isinstance(other, ModInt)
              else ModInt(self.x - other)
          )
  
      def __mul__(self, other):
          return (
              ModInt(self.x * other.x)
              if isinstance(other, ModInt)
              else ModInt(self.x * other)
          )
  
      def __truediv__(self, other):
          return (
              ModInt(self.x * pow(other.x, MOD - 2, MOD))
              if isinstance(other, ModInt)
              else ModInt(self.x * pow(other, MOD - 2, MOD))
          )
  
      def __pow__(self, other):
          return (
              ModInt(pow(self.x, other.x, MOD))
              if isinstance(other, ModInt)
              else ModInt(pow(self.x, other, MOD))
          )
  
      def __radd__(self, other):
          return ModInt(other + self.x)
  
      def __rsub__(self, other):
          return ModInt(other - self.x)
  
      def __rmul__(self, other):
          return ModInt(other * self.x)
  
      def __rtruediv__(self, other):
          return ModInt(other * pow(self.x, MOD - 2, MOD))
  
      def __rpow__(self, other):
          return ModInt(pow(other, self.x, MOD))
  
  
  # (1x2)x2 と (2x1) を1ブロックとみなして、色の塗り方の組合せを数え上げる
  ans, _ = reduce(
      lambda acc, s: (
          (3 * acc[0], 3)
          if acc[1] == 0 and s[0] == s[1]
          else (
              (6 * acc[0], 1)
              if acc[1] == 0 and s[0] != s[1]
              else (
                  (acc[0], 2)
                  if acc[1] == 1
                  else (
                      (acc[0], 3)
                      if acc[1] == 2 and s[0] == s[1]
                      else (
                          (3 * acc[0], 1)
                          if acc[1] == 2 and s[0] != s[1]
                          else (
                              (2 * acc[0], 3)
                              if acc[1] == 3 and s[0] == s[1]
                              else (2 * acc[0], 1)
                          )
                      )
                  )
              )
          )
      ),
      zip(S1, S2),
      (ModInt(1), 0),
  )
  
  # 出力
  print(ans)
  
problem_description: 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.
samples: [{"input": "3\n    aab\n    ccb", "output": "6\n    \n\nThere are six ways as shown below:\n\n![](https://atcoder.jp/img/arc081/899673bd23529f4fb5e41c6e7d5bc372.png)\n\n* * *"}, {"input": "1\n    Z\n    Z", "output": "3\n    \n\nNote that it is not always necessary to use all the colors.\n\n* * *"}, {"input": "52\n    RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\n    RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn", "output": "958681902"}]