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 (Python):


from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    s1 = list(input()[:-1].decode())
    s2 = list(input()[:-1].decode())
    ans = 0
    if s1[0] == s2[0]:
        ans = 3
    else:
        ans = 6
    for i in range(1, n):
        if s1[i - 1] == s2[i - 1]:
            if s1[i] == s2[i]:
                ans *= 2
            else:
                ans *= 2
            ans %= mod
        else:
            if s1[i - 1] == s1[i] and s2[i - 1] == s2[i]:
                ans *= 1
            elif s1[i] != s2[i]:
                ans *= 3
            else:
                ans *= 1
            ans %= mod
    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
MOD = 10 ** 9 + 7
n = int(input())
s1 = input()
s2 = input()

if s1[0] == s2[0]:
    ans = 3
    pos = 1
else:
    ans = 6
    pos = 2

while pos < n:
    if s1[pos] == s2[pos]:
        if s1[pos - 1] == s2[pos - 1]:
            ans *= 2
            ans %= MOD
        pos += 1
    else:
        if s1[pos - 1] == s2[pos - 1]:
            ans *= 2
        else:
            ans *= 3
        pos += 2
        ans %= MOD
print(ans)

Solution (Python):
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    S = in_s()
    _ = in_s()

    mod = 1000000007

    gr = itertools.groupby(S)
    domino = []
    for k, v in gr:
        domino.append(len(list(v)))

    if domino[0] == 1:
        ans = 3
    else:
        ans = 6

    for i in range(len(domino) - 1):
        if domino[i] == 1 and domino[i + 1] == 1:
            ans *= 2
        elif domino[i] == 1 and domino[i + 1] == 2:
            ans *= 2
        elif domino[i] == 2 and domino[i + 1] == 1:
            pass
        elif domino[i] == 2 and domino[i + 1] == 2:
            ans *= 3
        ans %= mod

    print(ans % mod)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s1=input()
s2=input()

mod=10**9+7

if s1[0]==s2[0]:
  bef=0
  inx=1
  ans=3
else:
  bef=1
  inx=2
  ans=6

while inx<n:
  if s1[inx]==s2[inx]:
    if bef==0:
      ans*=2
      ans%=mod
    bef=0
    inx+=1
  else:
    if bef==1:
      ans*=3
    else:
      ans*=2
    ans%=mod
    bef=1
    inx+=2

print(ans)

Solution (Python):
N, S1, S2 = open(0)
N = int(N)
m = 10**9+7

i = 0
dominos = []
while i < N:
    if S1[i] == S2[i]:
        dominos.append(0)
        i += 1
    else:
        dominos.append(1)
        i += 2

ans = 3
for i in range(len(dominos)):
    if dominos[i] == 0:
        if i > 0 and dominos[i-1] == dominos[i]:
            ans = ans * 2 % m
    else:
        if i > 0 and dominos[i-1] == dominos[i]:
            ans = ans * 3 % m
        else:
            ans = ans * 2 % m
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
mod = 1000000007
s1 = list(input())
s2 = list(input())

idx = 0
before = -1
ans = 1
while idx<N:
    if s1[idx]==s2[idx]:
        if before==-1:
            ans *= 3
            ans %= mod
        elif before==1:
            ans *= 2
            ans %= mod
        else:
            pass
        before = 1
        idx += 1
    else:
        if before==-1:
            ans *= 6
            ans %= mod
        elif before==1:
            ans *= 2
            ans %= mod
        else:
            ans *= 3
            ans %= mod
        before = 2
        idx += 2
print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

N = int(readline())
S1 = readline().rstrip()
S2 = readline().rstrip()

if S1[0] == S2[0]:
    passflag = 0
    bef = 1
    ans = 3
else:
    passflag = 1
    bef = 0
    ans = 6

for i in range(1,N):
    if passflag:
        passflag = 0
        continue
    if bef:
        if S1[i] == S2[i]:
            ans = ans*2%mod
            passflag = 0
            bef = 1
        else:
            ans = ans*2%mod
            passflag = 1
            bef = 0
    else:
        if S1[i] == S2[i]:
            passflag = 0
            bef = 1
        else:
            ans = ans*3%mod
            passflag = 1
            bef = 0
print(ans)

Solution (Python):
n=int(input())
s1=input()
s2=input()
MOD=10**9+7
flag=0
i=0
ans=1
while i<n:
  if s1[i]==s2[i]:
    if flag==0:
      ans=3
    if flag==1:
      ans=ans*2%MOD
    flag=1
    i+=1
  else:
    if flag==0:
      ans=6
    if flag==1:
      ans=ans*2%MOD
    if flag==-1:
      ans=ans*3%MOD
    flag=-1
    i+=2
print(ans)

Solution (Python):
p = 10**9+7
N = int(input())
S1 = input().strip()
S2 = input().strip()
cur = 0
while cur<N:
    if cur==0:
        if S1[cur]==S2[cur]:
            cnt = 3
            cur += 1
        else:
            cnt = 6
            cur += 2
    else:
        if S1[cur]==S2[cur]:
            if S1[cur-1]==S2[cur-1]:
                cnt = (cnt*2)%p
            cur += 1
        else:
            if S1[cur-1]==S2[cur-1]:
                cnt = (cnt*2)%p
            else:
                cnt = (cnt*3)%p
            cur += 2
print(cnt)

Solution (Python):
MOD = pow(10,9)+7
N = int(input())
S = str(input())
T = str(input())
if N == 1:
  print(3)
  exit()
now = 0
if S[now] != T[now]: 
  now = 2
  ans = 6
  Flag = True
else: 
  now = 1
  ans = 3
  Flag = False

while now <= N-1:
  if S[now] != T[now]: 
    if Flag: 
      ans = 3*ans%MOD
    else: 
      ans = 2*ans%MOD
    Flag = True
    now += 2
  else: 
    if Flag: 
      ans *= 1
    else: 
      ans = 2*ans%MOD
    Flag = False
    now += 1
print(ans)

Solution (Python):
N=int(input())
S=[input() for i in range(2)]
P=1
mod=10**9+7
B=True
if S[0][0]==S[1][0]:
  P=3
else:
  P=6
  B=False
for i in range(1,N):
  if B:
    if S[0][i]==S[1][i]:
      if S[0][i-1]==S[1][i-1]:
        P=P*2%mod
    else:
      B=False
      if S[0][i-1]==S[1][i-1]:
        P=P*2%mod
      else:
        P=P*3%mod
  else:
    B=True
print(P)

Solution (Python):
N = int(input())
S = input()
T = input()
MOD = 10**9+7

ans = 3
if S[0] != T[0]:
    ans *= 2
for s1,t1,s2,t2 in zip(S,T,S[1:],T[1:]):
    if s1==s2 and t1==t2: continue
    if s1==t1:
        if s2==t2:
            ans *= 2
        else:
            ans *= 2
    else:
        if s2==t2:
            ans *= 1
        else:
            ans *= 3
print(ans%MOD)

Solution (Python):
n = int(input())
s = input()
t = input()
mod = 10**9+7
if s[0]==t[0]:
  cou = 3
  start = 1
else:
  cou = 6
  start = 2
second = False
for i in range(start,n):
  if second:
    second = False
    continue
  else:
    if s[i]==t[i]:
      if s[i-1]==t[i-1]:
        cou *= 2
        cou %= mod
        
    else:
      if s[i-1]==t[i-1]:
        cou *= 2
        cou %= mod
        second = True
      else:
        cou *= 3
        cou %= mod
        second = True
        
 
print(cou)

Solution (Python):
MOD = 10**9 + 7
n = int(input())
S1 = input()
S2 = input()
A = []  
tmp = ""
i = 0
while i < n:
    if S1[i] == S2[i]:
        A.append(True)
        i += 1
    else:
        A.append(False)
        i += 2

l = len(A)
dp = [[0] * 2 for _ in range(l)]
if A[0]:
    dp[0][True] = 3
else:
    dp[0][False] = 6

for i in range(1, l):
    if A[i - 1]:
        if A[i]:
            dp[i][True] = dp[i - 1][True] * 2 % MOD
        else:
            dp[i][False] = dp[i - 1][True] * 2 % MOD
    else:
        if A[i]:
            dp[i][True] = dp[i - 1][False]
        else:
            dp[i][False] = dp[i - 1][False] * 3 % MOD

print(sum(dp[l - 1]) % MOD)

Solution (Python):
N = int(input())
S = input()
T = input()
mod = 10**9+7
lis = []
ans = 1
if N==1:
  print(3)
  exit()
if S[0]!=S[1]:
  lis.append(1)
for i in range(1,N-1):
  if S[i]!=S[i-1] and S[i]!=S[i+1]:
    lis.append(1)
  elif S[i]==S[i-1]:
    lis.append(2)
if S[-1]==S[-2]:
  lis.append(2)
else:
  lis.append(1)
ans = 3
if lis[0]==2:
  ans *= 2
for i in range(1,len(lis)):
  if lis[i-1]==1:
    ans *= 2
    ans %= mod
  elif lis[i]==2:
    ans *= 3
    ans %= mod
print(ans)

Solution (Python):
p = 10**9+7
N = int(input())
S1 = input().strip()
S2 = input().strip()
cnt = 1
cur = 0
if S1[0]==S2[0]:
    cnt = 3
    cur += 1
else:
    cnt = 6
    cur += 2
while cur<N:
    if S1[cur]==S2[cur]:
        if S1[cur-1]==S2[cur-1]:
            cnt = (cnt*2)%p
        cur += 1
    else:
        if S1[cur-1]==S2[cur-1]:
            cnt = (cnt*2)%p
        else:
            cnt = (cnt*3)%p
        cur += 2
print(cnt)

Solution (Python):
mod = 10**9 + 7
n = int(input())
s1 = input()
s2 = input()

if s1[0] == s2[0]:
    idx = 1
    ans = 3
    tate = 1
else:
    idx = 2
    ans = 6
    tate = 0

while idx < n:
    if s1[idx] == s2[idx]:
        if tate:
            ans *= 2
            ans %= mod
        tate = 1
        idx += 1
    else:
        if tate:
            ans *= 2
            ans %= mod
        else:
            ans *= 3
            ans %= mod
        tate = 0
        idx += 2

print(ans)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s1 = input()
s2 = input()
ans = 1
M = 10**9+7
if n==1:
    ans = 3
else:
    p = []
    prev = s1[0]
    count = 1
    for c in s1[1:]:
        if prev==c:
            count += 1
        else:
            p.append(count)
            count = 1
        prev = c
    p.append(count)
    if p[0]==1:
        ans = 3
    else:
        ans = 3*2
    prev = p[0]
    for num in p[1:]:
        if num==1:
            if prev==1:
                ans *= 2
            else:
                ans *= 1
        else:
            if prev==2:
                ans *= 3
            else:
                ans *= 2
        prev = num
        ans %= M
print(ans)

Solution (Python):
N = int(input())
S1 = input()
S2 = input()
MOD = 1_000_000_007
i = 0
directions = []
while i < N:
    if S1[i] == S2[i]:
        directions.append("V")
        i += 1
    else:
        directions.append("H")
        i += 2
prev = directions[0]
ans = 3 if prev == "V" else 6
for d in directions[1:]:
    if prev == "V" and d == "V" or prev == "V" and d == "H":
        ans *= 2
    elif prev == "H" and d == "H":
        ans *= 3
    ans %= MOD
    prev = d
print(ans)

Solution (Python):
n=int(input())
mod=10**9+7
if n==1:
    print(3)
    exit()

s1=list(input())
s2=list(input())
x=[]
i=0
while i<n-1:
    if s1[i]==s1[i+1]:
        x.append(2)
        i+=2
    else:
        x.append(1)
        i+=1
if s1[-1]!=s1[-2]:
    x.append(1)

for i in range(len(x)):
    if i==0 and x[0]==1:
        ans=3
    elif i==0 and x[0]==2:
        ans=6
    else:
        if x[i-1]==1 and x[i]==2:
            ans*=2
        elif x[i-1]==2 and x[i]==2:
            ans*=3
        elif x[i-1]==1 and x[i]==1:
            ans*=2
        ans%=mod
print(ans)

Solution (Python):
n=int(input())
a=input()
b=input()
m=10**9+7
if n==1:exit(print(3))
c=3*(2-(a[0]==b[0]))
for i in range(1,n):
 if a[i-1]==a[i]:continue
 if a[i-1]==b[i-1]:c*=2;c%=m
 elif a[i]!=b[i]:c*=3;c%=m
print(c)

Solution (Python):
def main():
    N = int(input())
    S1 = input()
    S2 = input()
    MOD = 10 ** 9 + 7
    ans = 1
    cnt = 0
    while cnt < N:
        if cnt == 0:
            if S1[cnt] == S2[cnt]:
                ans *= 3
                cnt += 1
            else:
                ans *= 6
                cnt += 2
        else:
            if S1[cnt] == S2[cnt]:
                if S1[cnt-1] == S2[cnt-1]:
                    ans *= 2
                else:
                    ans *= 1
                cnt += 1
            else:
                if S1[cnt-1] == S2[cnt-1]:
                    ans *= 2
                else:
                    ans *= 3
                cnt += 2

        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S1 = input()
S2 = input()

P = 10**9 + 7

if N == 1:
  print(3)
  exit()

if S1[0] == S1[1]:
  rlt = 6
  f = 1
  i = 2
else:
  rlt = 3
  f = 0
  i = 1
  
while i < N-1:
  if f == 0:
    rlt *= 2
    rlt %= P
    if S1[i] != S1[i+1]:
      i += 1
    else:
      f = 1
      i += 2
  else:
    if S1[i] != S1[i+1]:
      f = 0
      i += 1
    else:
      rlt *= 3
      rlt %= P
      i += 2

if i == N-1 and f == 0:
  rlt *= 2
  rlt %= P

print(rlt)

Solution (Python):
n = int(input())
s1 = input()
s2 = input()
mod = 1000000007
if n == 1:
    print(3)
    exit()
cnt = 3 if s1[0] == s2[0] else 6
for i in range(1, n):
    if s1[i-1] == s1[i]:
        cnt *= 1
        continue
    if s1[i-1] == s2[i-1]:
        cnt = cnt * 2 % mod
    elif s1[i] != s2[i]:
        cnt = cnt * 3 % mod
    else:
        cnt *= 1
print(cnt)

Solution (Python):
n = int(input())
dat = []
s = input()
t = input()
i = 0
while i < n:
    if s[i] == t[i]:
        dat.append(0)
        i+=1
    else:
        dat.append(1)
        i+=2

res = 0
prev = None
if dat[0] == 0:
    res = 3
    prev = 0
else:
    res = 6
    prev = 1
for i in range(1, len(dat)):
    if prev == 0 and dat[i] == 0:
        res *= 2
    elif prev == 0 and dat[i] == 1:
        res *= 2
    elif prev == 1 and dat[i] == 0:
        res *= 1
    elif prev == 1 and dat[i] == 1:
        res *= 3
    prev = dat[i]
print(res % 1000000007)

Solution (Python):
import sys
n = int(input())
s1 = input()
s2 = input()
MOD = 10**9 + 7

if n == 1:
    print(3)
    sys.exit()

dp = [0] * n
dp[0] = 3 if s1[0] == s2[0] else 6

for i in range(1, n):
    
    if s1[i - 1] == s1[i]:
        dp[i] = dp[i - 1]
        continue
    
    if s1[i - 1] == s2[i - 1]:
        dp[i] = dp[i - 1] * 2 % MOD
    
    elif s1[i] != s2[i]:
        dp[i] = dp[i - 1] * 3 % MOD
    else:
        dp[i] = dp[i - 1]

print(dp[-1])

Solution (Python):
import sys
n = int(input())
s1 = input()
s2 = input()
MOD = 10**9 + 7

if n == 1:
    print(3)
    sys.exit()

dp = [0] * n
dp[0] = 3 if s1[0] == s2[0] else 6

for i in range(1, n):
    if s1[i - 1] == s1[i]:
        dp[i] = dp[i - 1]
        continue
    if s1[i - 1] == s2[i - 1]:
        dp[i] = dp[i - 1] * 2 % MOD
    elif s1[i] != s2[i]:
        dp[i] = dp[i - 1] * 3 % MOD
    else:
        dp[i] = dp[i - 1]

print(dp[-1])

Solution (Python):
n = int(input())
s1 = str(input())
s2 = str(input())
MOD = 10 ** 9 + 7
S1, S2 = s1[0], s2[0]
for i in range(1, n):
    if S1[-1] != s1[i]:
        S1 += s1[i]
        S2 += s2[i]
if S1[0] == S2[0]:
    ans = 3
    cnd = 0
else:
    ans = 6
    cnd = 1
for i in range(1, len(S1)):
    if cnd == 0:
        if S1[i] == S2[i]:
            ans *= 2 % MOD
        else:
            ans *= 2 % MOD
            cnd = 1
    else:
        if S1[i] == S2[i]:
            cnd = 0
        else:
            ans *= 3 % MOD
print(ans % MOD)

Solution (Python):
def main():
    N = int(input())
    S1 = input()
    S2 = input()
    mod = 10**9 + 7
    if S1[0] != S2[0]:
        r = 6
    else:
        r = 3
    for i in range(1, N):
        if S1[i-1] == S1[i]:
            continue
        if S1[i] == S2[i] and S1[i-1] != S2[i-1]:
            continue
        if S1[i] != S2[i] and S1[i-1] != S2[i-1]:
            r *= 3
            r %= mod
            continue
        r *= 2
        r %= mod
    return r
print(main())

Solution (Python):
def main():
    N = int(input())
    S1 = input()
    S2 = input()
    mod = 10**9 + 7
    v = set()
    v.add(S1[0])
    v.add(S2[0])
    if len(v) == 2:
        r = 6
    else:
        r = 3
    for i in range(1, N):
        if S1[i-1] == S1[i]:
            continue
        if S1[i] == S2[i] and S1[i-1] != S2[i-1]:
            continue
        if S1[i] != S2[i] and S1[i-1] != S2[i-1]:
            r *= 3
            r %= mod
            continue
        r *= 2
        r %= mod
    return r
print(main())

Solution (Python):
mod = 1000000007
N = int(input())
S = [list(input()) for _ in range(2)]
i = 0
ans = 1
if S[0][0] == S[1][0]:
  ans = 3
  i = 1
else:
  ans = 6
  i = 2
while i < N:
  if S[0][i-1] == S[1][i-1]:
    if S[0][i] == S[1][i]:
      ans = (ans * 2)%mod
      i += 1
    else:
      ans = (ans * 2)%mod
      i += 2
  else:
    if S[0][i] == S[1][i]:
      i += 1
    else:
      ans = (ans * 3)%mod
      i += 2
print(ans)

Solution (Python):
n = int(input())
t = input()
b = input()

dp = [0] * n
mod = 10 ** 9 + 7

if t[0] == b[0]:
    dp[0] = 3
else:
    dp[0] = 6

for i in range(1, n):
    if t[i] == t[i-1]:
        dp[i] = dp[i-1]
    else:
        if t[i-1] == b[i-1]:
            if t[i] == b[i]:
                dp[i] = dp[i-1] * 2 % mod
            else:
                dp[i] = dp[i-1] * 2 % mod
        else:
            if t[i] == b[i]:
                dp[i] = dp[i-1] % mod
            else:
                dp[i] = dp[i-1] * 3 % mod

print(dp[-1])

Solution (Python):
n = int(input())
s1 = list(input())
s2 = list(input())

mod = 1000000007

pre = 0
ans = 3
i = 0
while i < n:
    if s1[i] == s2[i]:
        if pre == 1:
            ans = ans * 2 % mod
        pre = 1
        i += 1
    else:
        if pre == 2:
            ans = ans * 3 % mod
        else:
            ans = ans * 2 % mod
        pre = 2
        i += 2

print(ans)

Solution (Python):
MOD = 1000000007
lim = 200000
inv_t = [-1 for i in range(lim+1)]
factrial = [-1 for i in range(lim+1)]
factrial_inv = [-1 for i in range(lim+1)]


def set_inv(max=lim):
    inv_t[0] = 0
    for i in range(1, max):
        inv_t[i] == mod_inv(i)


def mod_inv(x, mod=MOD):
    y, u, v, _x = mod, 1, 0, x
    while y:
        t = _x//y
        _x -= t*y
        _x, y = y, _x
        u -= t*v
        u, v = v, u
    u %= mod
    if u < 0:
        u += mod
    return u


def mod_pow(a, n, mod=MOD):
    res = 1
    while n:
        if n & 1:
            res = res*a % mod
        a = a*a % mod
        n >>= 1
    return res


def set_factrial(max=lim, mod=MOD):
    c = 1
    factrial[0] = factrial_inv[0] = 1
    for i in range(1, max):
        c *= i
        c %= mod
        factrial[i] = c
        factrial_inv[i] = mod_inv(c, mod)


def comb(a, b, mod=MOD):
    if factrial[0] == -1:
        set_factrial()
    return (factrial[a]*factrial_inv[b]*factrial_inv[a-b]) % mod


N = n = int(input())
s = [input() for i in range(2)]

ret = []
i = 0
while i < N:
    if s[0][i] == s[1][i]:
        ret.append(1)
        i += 1
    else:
        ret.append(2)
        i += 2
ans = 3*ret[0]
for i in range(1, len(ret)):
    if ret[i-1] == 1 and ret[i] == 1:
        ans *= 2
    elif ret[i-1] == 1 and ret[i] == 2:
        ans *= 2
    elif ret[i-1] == 2 and ret[i] == 1:
        ans *= 1
    elif ret[i-1] == 2 and ret[i] == 2:
        ans *= 3
    ans %= MOD

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline













N = int(readline())
S1 = readline().rstrip()
S2 = readline().rstrip()

DIV = 1000000007

ans = 1
i = 0
same = True
while i < N:
  if S1[i] == S2[i]:
    if i == 0:
      ans *= 3
    elif not same:
      ans *= 1
    else:
      ans *= 2
    ans %= DIV
    same = True
    i += 1
  else:
    if i == 0:
      ans *= 6
    elif not same:
      ans *= 3
    else:
      ans *= 2
    ans %= DIV
    same = False
    i += 2
    
print(ans)

Solution (Python):
MOD = 10**9+7
n = int(input())
s = input()
p = input()
ans = 1
i = 0
num = 0
while i < n:
    if s[i] == p[i]:
        if num == 0: ans = 3
        if num == 1: ans *= 2
        if num == 2: ans *= 1
        num = 1
        i += 1
    else:
        if num == 0: ans = 6
        if num == 1: ans *= 2
        if num == 2: ans *= 3
        num = 2
        i += 2
    ans %= MOD
print(ans)

Solution (Python):
MOD = 10**9+7
n = int(input())
s = input()
p = input()
ans = 0
f = 0
i = 0
two = False
while i < n:
    if i == 0:
        if s[i] == p[i]:
            ans = 3
        else:
            ans = 6
            i += 1
            two = True
        i += 1
        continue
    if i >= n:break
    if s[i] == p[i]:
        if two:
            pass
        else:
            ans *= 2
        two = False
    else:
        if two:
            ans *= 3
        else:
            ans *= 2
        two = True
        i += 1
    i += 1
    ans %= MOD
print(ans)

Solution (Python):
MOD = 10**9+7
n = int(input())
s = input()
p = input()
ans = 0
f = 0
i = 0
while i < n:
    if i > n:break
    if s[i] == p[i]:
        if i == 0:
            ans = 3
        else:
            if f == 1:
                ans *= 1
            else:
                ans *= 2
        f = 0
    else:
        if i == 0:
            ans = 6
        else:
            if f == 1:
                ans *= 3
            else:
                ans *= 2
        f = 1
        i += 1
    i += 1
    ans %= MOD
print(ans%MOD)

Solution (Python):

MOD = 10 ** 9 + 7

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    S = [input() for _ in range(2)]
    d = []
    i = 0
    while i < N:
        if S[0][i] == S[1][i]:
            i += 1
            d.append(0)
        else:
            i += 2
            d.append(1)
    output = 6 if d[0] else 3
    for i in range(len(d)-1):
        if d[i+1] == 0 and d[i] == 0: output *= 2
        elif d[i+1] == 0 and d[i] == 1: continue
        elif d[i+1] == 1 and d[i] == 0: output *= 2
        else: output *= 3
        output %= MOD
    print(output)

    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
S1 = list(input())
S2 = list(input())

if S1[0] == S2[0]:
    ans = 3
    start = 1
else:
    ans = 6
    start = 2

i = start
while i <= N-1:
    if S1[i] == S2[i]:
        if S1[i-1] == S2[i-1]:
            ans *= 2
            ans %= mod
        i += 1
    else:
        if S1[i-1] == S2[i-1]:
            ans *= 2
            ans %= mod
        else:
            ans *= 3
            ans %= mod
        i += 2
print(ans)

Solution (Python):
MOD = 1000000007
n = int(input())
s = input()
t = input()

ans = 3
i = 0
if s[0]==t[0]:
    i += 1
    vert = True
else:
    ans *= 2
    i += 2
    vert = False

while i<n:
    if s[i]==t[i]:
        if vert:
            ans *= 2
            ans %= MOD
        vert = True
        i += 1
    else:
        if vert:
            ans *= 2
        else:
            ans *= 3
        ans %= MOD
        vert = False
        i += 2
print(ans)

Solution (Python):
n = int(input())

s1 = input()
s2 = input()

h = 0
mod = 10**9 + 7

ans = 1
prev_pat = 0
while h < len(s1):

    
    if s1[h] == s2[h]:
        if h == 0:
            ans *= 3
        elif prev_pat == 1:
            ans *= 2
        else:  
            ans *= 1
        h += 1
        prev_pat = 1
    elif s1[h] == s1[h + 1]:  
        if h == 0:
            ans *= 6
        elif prev_pat == 1:
            ans *= 2
        else:  
            ans *= 3
        h += 2
        prev_pat = 2
    else:
        print("this line should not be reached")
        exit(0)
    ans %= mod

print(ans)

Solution (Python):
M = 10**9+7
n = int(input())
s = input()
t = input()
ans = 3 if s[0] == t[0] else 6
for i in range(1, n):
  if s[i-1] == s[i]:
    continue
  if s[i-1] == t[i-1]:
    ans = ans * 2 % M
  elif s[i] != t[i]:
    ans = ans * 3 % M
print(ans)

Solution (Python):
n = int(input())
s1 = input()
s2 = input()

idea = '''
ABB
ACC
任意の A の選び方に対して B の選び方 2 通り * C の選び方 1 通り

AB
AB
任意の A の選び方に対して B の選び方 2 通り

AABB
CCDD
任意の A,B の選び方に対して、 C,D の選び方 3 通り
1122 1122 1133
2211 2233 2211

AAC
BBC
任意の A,B の選び方に対して、 C の選び方 1 通り

開幕だけちょっと気をつける
'''

ind = 0
ans = 1
is_vertical = s1[0] == s2[0]
if is_vertical:
  ans = 3
  ind += 1
else:
  ans = 6
  ind += 2
while ind < n:
  prev_vertical = is_vertical
  is_vertical = s1[ind] == s2[ind]
  if prev_vertical:
    ans *= 2 
  elif not is_vertical:
    ans *= 3
  ind = ind + 1 + (not is_vertical)
print(ans%(10**9+7))

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    S = input().strip("\n")
    T = input().strip("\n")
    DP = [0] * N
    mod = 7 + 10 ** 9
    if S[0] == T[0]: DP[0] = 3
    else: DP[0] = 6

    for i in range(1, N):
        if S[i] == S[i-1]: 
            DP[i] = DP[i-1]
        else: 
            if S[i-1] == T[i-1]: 
                DP[i] = (2 * DP[i-1]) % mod
            else: 
                if S[i] == T[i]: 
                    DP[i] = DP[i-1]
                else: 
                    DP[i] = (3 * DP[i-1]) % mod
    print(DP[N-1])


    return  0

if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
ue = input()
sita = input()
narabe = []
flag = False
mod = 10**9 + 7
for i in range(n):
    if ue[i] == sita[i]:
        narabe.append(0)
    elif ue[i] != sita[i]:
        if not flag:
            flag = True
            narabe.append(1)
        elif flag:
            flag = False

dp = [0 for i in range(len(narabe))]
if narabe[0] == 0:
    dp[0] = 3
elif narabe[0] == 1:
    dp[0] = 6
for i in range(1,len(narabe)):
    if narabe[i-1] == 1 and narabe[i] == 1:
        dp[i] = (dp[i-1]*3)%mod
    elif narabe[i-1] == 1 and narabe[i] == 0:
        dp[i] = dp[i-1]
    elif narabe[i-1] == 0 and narabe[i] == 0:
        dp[i] = (dp[i-1]*2)%mod
    elif narabe[i-1] == 0 and narabe[i] == 1:
        dp[i] = (dp[i-1]*2)%mod
        
print(dp[-1])

Solution (Python):
N=int(input())
S=[[],[]]
S[0]=list(input())
S[1]=list(input())
p=1000000007


L= [1] if S[0][0]==S[1][0] else []
for i in range(1,N):
  if S[0][i]==S[0][i-1] and S[1][i]==S[1][i-1]:
    L.append(2)
  elif S[0][i]==S[1][i]:
    L.append(1)


for i,num in enumerate(L):
  if i==0:
    if num==1:
      cnt = 3
    else:
      cnt = 6
  else:
    if L[i]==1 and L[i-1]==1:
      cnt = (cnt*2)%p
    elif L[i]==1 and L[i-1]==2:
      cnt = (cnt*1)%p
    elif L[i]==2 and L[i-1]==1:
      cnt = (cnt*2)%p
    else: 
      cnt = (cnt*3)%p
  
print(cnt)

Solution (Python):
n = int(input())
s = [input() for _ in range(2)]
MOD = 1000000007
i = 0
res = 1
if s[0][i] == s[1][i]:
    res *= 3
else:
    res *= 3*2
    i += 1
i += 1
while i < n:
    if s[0][i-1] == s[1][i-1]:
        res *= 2
        res %= MOD
        if s[0][i] != s[1][i]:
            i+=1
        i+=1
    else:
        if s[0][i] != s[1][i]:
            res *= 3
            res %= MOD
            i+=1
        i+=1
print(res)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    mat = [list(input()) for _ in range(2)]

    none, single, double = 0, 1, 2
    table = {(none, single): 3, (none, double): 6, (single, single): 2, (single, double): 2, (double, single): 1,
             (double, double): 3}
    prev = none
    ans = 1
    next_skip = False

    for i in range(len(mat[0])):
        if next_skip:
            next_skip = False
            continue

        current = single if mat[0][i] == mat[1][i] else double
        ans *= table[(prev, current)]
        ans %= MOD

        if current == double:
            next_skip = True
        prev = current

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s_1 = input()
s_2 = input()
i = 0
count = 1
while i < n:
  if s_1[i] == s_2[i]:
    if i == 0:
      count *= 3
    elif s_1[i-1] == s_2[i - 1]:
      count *= 2
    i += 1
  else:
    if i == 0:
      count *= 6
    elif s_1[i-1] == s_2[i-1]:
      count *= 2
    else:
      count *= 3
    i += 2
    
print(count % (10**9 + 7))

Solution (Python):
n = int(input())
s1 = str(input())
s2 = str(input())

cnt = 1

for i in range(n):
    if i == 0:
        if s1[i] == s2[i]:
            cnt = cnt * 3
            previous = 'tate'
        else:
            cnt = cnt * 6
            previous = 'yoko1'
    else:
        if s1[i] == s2[i]:   
            if previous == 'tate':
                cnt = cnt * 2
            elif previous == 'yoko2':
                cnt = cnt * 1
                previous = 'tate'
        else:   
            if previous == 'tate':
                cnt = cnt * 2
                previous = 'yoko1'
            elif previous == 'yoko2':
                cnt = cnt * 3
                previous = 'yoko1'
            elif previous == 'yoko1':
                previous = 'yoko2'
        
print(cnt%1000000007)

Solution (Python):
n = int(input())
s = input()
t = input()

moji = ""
flag = True

for i in range(n):
    if flag == False:
        flag = True
        continue
    if s[i] != t[i]:
        moji += "A"
        flag = False
    else:
        moji += "B"

if moji[0] == "A":
    now = 6
else:
    now = 3

l = len(moji)
mod = 10**9+7

for i in range(1,l):
    if moji[i-1] == "A" and moji[i] == "A":
        now *= 3
        now %= mod
    elif moji[i-1] == "A" and moji[i] == "B":
        continue
    elif moji[i-1] == "B" and moji[i] == "A":
        now *= 2
        now %= mod
    else:
        now *= 2
        now %= mod

print(now%mod)

Solution (Python):
N = int(input())
S1 = input()
S2 = input()
S = [S1] + [S2]
s = []
ans = 1
p = 10**9+7
if S[0][0] == S[1][0]:
  s.append(0)
  ans = ans *3
  ans = ans%p
else:
  s.append(1)
  ans = ans *6
  ans = ans%p
  
for i in range(1,N):
  if S[0][i] == S[1][i] and s[i-1] == 0:
    s.append(0)
    ans = ans *2
    ans = ans % p
  elif S[0][i] == S[1][i] and s[i-1] == 1:
    s.append(0)
    ans = ans *1
    ans = ans % p
  elif S[0][i] != S[1][i] and s[i-1] == 0:
    s.append(1)
    ans = ans *2
    ans = ans % p
  elif S[0][i-1] != S[0][i]:
    s.append(1)
    ans = ans *3
    ans = ans%p
  else:
    s.append(1)
    
print(ans)