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):
mod=1e9+7
n=input()
s1=raw_input()
s2=raw_input()
if s1[0]==s2[0]:
	r=3
	i=1
	prev=True
else:
	assert s1[0]==s1[1]!=s2[0]==s2[1]
	r=6
	i=2
	prev=False
while i<n:
	if s1[i]==s2[i]:
		if prev:
			r=r*2%mod
		i+=1
		prev=True
	else:
		assert s1[i]==s1[i+1]!=s2[i]==s2[i+1]
		if prev:
			r=r*2%mod
		else:
			r=r*3%mod
		i+=2
		prev=False
print int(r)

Solution (Python):
mod=1e9+7
n=input()
s1=raw_input()
s2=raw_input()
if s1[0]==s2[0]:
	r=3
	i=1
	prev=True
else:
	assert s1[0]==s1[1]!=s2[0]==s2[1]
	r=6
	i=2
	prev=False
while i<n:
	if s1[i]==s2[i]:
		if prev:
			r=r*2%mod
		i+=1
		prev=True
	else:
		assert s1[i]==s1[i+1]!=s2[i]==s2[i+1]
		if prev:
			r=r*2%mod
		else:
			r=r*3%mod
		i+=2
		prev=False
print int(r)

Solution (Python):
from itertools import groupby as gb
N = int(input())
a,b = gb(input()),gb(input())
res = -1
for (w,x),(y,z) in zip(a,b):
    if res==-1:
        prev = w!=y
        res = 3 * (1+prev)
    elif prev:
        prev = w!=y
        res *= 1 + prev*2
    else:
        prev = w!=y
        res *= 2
print(res % (10**9+7))

Solution (Python):

n = int(input())
s1 = input()
s2 = input()

mod = 1000000007

if s1[0]==s2[0]:
    i = 1
    ret = 3
else:
    i=2
    ret = 6

while i<n:
    if s1[i-1]==s2[i-1]:
        if s1[i]==s2[i]:
            ret *= 2
            i += 1
        else:
            ret *= 2
            i += 2
    else:
        if s1[i]==s2[i]:
            ret *= 1
            i += 1
        else:
            ret *= 3
            i += 2
print(ret%mod)

Solution (Python):
def main():

    S = list(input())
    checklist = [0 for i in range(26)]
    for i in S:
        checklist[ord(i) - ord("a")] += 1
    ans = True

    for i in checklist:
        if i > 1:
            ans = False

    if not ans:
        print(-1)
        return 0
    else:
        ans = False
        for i in range(len(checklist)):
            if checklist[i] == 0:
                for i in S:
                    print(i, end="")
                print(chr(i + ord("a")), end = "")
                print()
                ans = True
                break

        if not ans:
            new_S = []
            for i in S:
                new_S.append(ord(i))

            for i in range(len(new_S) - 1):
                if new_S[i] > new_S[i + 1]:
                    for j in range(i - 1):
                        print(S[j], end = "")
                    print(chr(new_S[i - 1] + 1), end = "")
                    print()
                    ans = True
                    break

            if not ans:
                print(-1)


def ABC069D():

    H, W = map(int, input().split())
    N = int(input())
    a = list(map(int, input().split()))
    ans = []
    for i in range(N):
        for j in range(a[i]):
            ans.append(i + 1)
    printlist = [[0 for i in range(W)] for j in range(H)]
    k = 0
    for i in range(H):
        for j in range(W):
            printlist[i][j] = ans[k]
            k += 1
        if i % 2 != 0:
            printlist[i] = printlist[i][::-1]

    for i in range(H):
        for j in range(W):
            print(printlist[i][j], end = "")
            if j != W:
                print(" ", end = "")
        print()
    print()


import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def ABC057D():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v)[::-1]

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    
    
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        
        if i == key:
            c += 1
    
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    
    
    print(ans)


def ABC104D():
    S = list(input())
    A_cnt = 0
    B_cnt = 0
    C_cnt = 0
    Q_cnt = 0
    ans = 0
    for i in S:
        if i == "A":
            A_cnt += 1
        elif i == "B":
            B_cnt += 1
        elif i == "C":
            C_cnt += 1
        else:
            Q_cnt += 1
    for i in range(Q_cnt + 1):
        for j in range(Q_cnt - i + 1):
            k = Q_cnt - i - j
            if A_cnt + i > 0 and B_cnt + j > 0 and C_cnt + k > 0:
                f_i = math.factorial(i)
                f_j = math.factorial(j)
                f_k = math.factorial(k)
                if f_i == 0:
                    f_i = 1
                if f_j == 0:
                    f_j = 1
                if f_k == 0:
                    f_k = 1
                ans += (A_cnt + i) * (B_cnt + j) * (C_cnt + k) * math.factorial(Q_cnt) // f_i // f_j // f_k
                print(ans, i, j, k, A_cnt + i, B_cnt + j, C_cnt + k)
                print(math.factorial(Q_cnt), f_i, f_j, f_k)
    print(ans)


def ARC075():
    N, A, B = map(int, input().split())
    h = [int(input()) for i in range(N)]
    def enogth(T):
        import copy
        this_h = copy.copy(h)
        cnt = 0
        for i in range(N):
            this_h[i] -= B
            key = 0
            if this_h[i] > 0:
                key = this_h[i] / (A - B)
                if int(key) != key:
                    key += 1
                cnt += int(key)
        if cnt <= T:
            return True
        else:
            return False
    def sarch(i: object) -> object:
        print(i)
        if enogth(i):
            if i // 2 == 1:
                return i
            sarch(0 + i // 2)
        else:
            sarch(i + i // 2)
    print(sarch(10 ** 9))


def ARC082D():
    N = int(input())
    p = list(map(int, input().split()))
    cnt = 0
    if p[N - 1] == N:
        
        p[-2], p[-1] = p[-1], p[-2]
        cnt += 1

    for i in range(N - 1):
        if p[i] == i + 1:
            p[i], p[i + 1] = p[i + 1], p[i]
            cnt += 1
    print(cnt)


from queue import Queue
def ABC070D():
    N = int(input())
    a, b, c =map(int, input().split())
    Q, K = map(int, input().split())
    xy = [list(map(int, input().split())) for i in range(Q)]
    x = [[] for i in range(N)]
    for i, j in xy:
        x[i - 1].append(j - 1)
        x[j - 1].append(i - 1)

    q = Queue()
    visited = [0 for i in range(N)]

def ABC076D():
    N = int(input())
    t = list(map(int, input().split()))
    v = list(map(int, input().split()))
    speed_lim = [0]
    speed_list = [0 for i in range(sum(t) + 1)]
    for i in range(N):
        for j in range(t[i]):
            speed_lim.append(v[i])
    print(speed_lim)
    for i in range(1, sum(t) + 1):
        speed_list[i] = speed_list[i - 1] + 1
        if speed_list[i] > speed_lim[i]:
            speed_list[i] = speed_lim[i]
    print(speed_list)
    speed_list[-1] = 0
    for i in range(sum(t) - 1, -1, -1):
        speed_list[i] = min(speed_list[i + 1] + 1, speed_list[i])
        if speed_list[i] > speed_lim[i + 1]:
            speed_list[i] = speed_lim[i + 1]
    print(speed_list)
    ans = 0
    for i in speed_list:
        ans += i

    print(ans)


def ABC076D():
    N = int(input())
    t = list(map(int, input().split()))
    a = []
    for i in t:
        a.append(i * 2)
    t = a
    v = list(map(int, input().split()))
    
    speed_lim = [0]
    speed_list = [0 for i in range(sum(t) + 1)]
    for i in range(N):
        for j in range(t[i]):
            speed_lim.append(v[i])
    
    for i in range(1, sum(t) + 1):
        speed_list[i] = speed_list[i - 1] + 0.5
        if speed_list[i] > speed_lim[i]:
            speed_list[i] = speed_lim[i]
    
    speed_list[-1] = 0
    for i in range(sum(t) - 1, -1, -1):
        speed_list[i] = min(speed_list[i + 1] + 0.5, speed_list[i])
        if speed_list[i] > speed_lim[i + 1]:
            speed_list[i] = speed_lim[i + 1]
    
    ans = 0
    for i in speed_list:
        ans += i

    print(ans / 2)


def ABC085D():
    N, H = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    a = []
    b = []
    for i, j in ab:
        a.append(i)
        b.append(j)
    a.sort()
    b.sort()
    a = a[::-1]
    b = b[::-1]
    damage = 0
    cnt = 0
    for i in b:
        if i < a[0]:
            break
        damage += i
        cnt += 1
        if damage >= H:
            break
    key = 0
    if damage < H:
        key = (H - damage) / a[0]
        if int(key) != key:
            key += 1
        key = int(key)

    cnt += key

    print(cnt)


def ARC068D():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    count_list = []
    cnt = 1
    
    for i in range(1, N):
        if A[i] == A[i - 1]:
            cnt += 1
        else:
            count_list.append(cnt)
            cnt = 1
    count_list.append(cnt)
    ans_cnt = 0
    
    for i in range(len(count_list)):
        if count_list[i] > 2:
            ans_cnt += (count_list[i] % 2) - 1
            count_list[i] %= 2
            if count_list[i] == 0:
                count_list[i] = 2
    
    count_list = sorted(count_list)[::-1]
    for i in range(len(count_list) - 1):
        if count_list[i] == 2 and count_list[i + 1] == 2:
            ans_cnt += 1
            count_list[i] = 1
            count_list[i + 1] = 1
    count_list = sorted(count_list)[::-1]
    if count_list[0] == 2:
        count_list[0] = 0
    
    
    print(sum(count_list))


def ARC073D():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for i in range(N)]
    wv.sort()
    count_list = []
    cnt = 1
    weight_list = []
    s = 0
    g = 0
    for i in range(N - 1):
        if wv[i][0] != wv[i + 1][0]:
            g = i
            count_list.append(cnt)
            weight_list.append([wv[i][0], s, g, cnt])
            s = i + 1
            g = i + 1
            cnt = 1
        else:
            g = i
            cnt += 1

    count_list.append(cnt)
    weight_list.append([wv[-1][0], s, g, cnt])
    print(weight_list)
    wl = []
    for i in weight_list:
        this_weight = i[0]
        this_list = []
        for j in wv[i[1]:i[2] + 1]:
            this_list.append(j[1])
        this_list = sorted(this_list)[::-1]
        print(this_list)
        wl.append([this_weight, this_list])

def ARC081D():
    pattern = []
    N = int(input())
    S1 = list(input())
    S2 = list(input())
    i = 0
    while i < N:
        if S1[i] == S2[i]:
            pattern.append("X")
        else:
            pattern.append("Y")
            i += 1
        i += 1
    ans_list = []
    for i in range(len(pattern)):
        if i == 0:
            if pattern[i] == "X":
                ans_list.append(3)
            else:
                ans_list.append(6)
        else:
            if pattern[i] == "X":
                if pattern[i - 1] == "X":
                    ans_list.append(2)
                else:
                    ans_list.append(1)
            elif pattern[i] == "Y":
                if pattern[i - 1] == "X":
                    ans_list.append(2)
                elif pattern[i - 1] == "Y":
                    ans_list.append(3)
    
    
    ans = 1
    for i in ans_list:
        ans *= i
    print(ans % (1000000007))
ARC081D()

Solution (Python):
n = int(input())
list_s1 = list(str(input()))
ans = 1
list_s1.append("!")
for i in range(n):
    if i == 0:
        ans *= 3
    elif i == 1:
        ans *= 2
    else:
        if list_s1[i] == list_s1[i-1]:
            ans *= 1
        else:
            if list_s1[i-1] == list_s1[i-2]:
                if list_s1[i] != list_s1[i+1]:
                    ans *= 1
                else:
                    ans *= 3
            else:
                ans *= 2
print(ans%(10**9+7))

Solution (Python):
N = int(input())
s1 = input()
s2 = input()
i = 0
pat = []
while i < N:
  if s1[i]==s2[i]:
    pat.append('t')
    i += 1
  else:
    pat.append('y')
    i += 2
if pat[0]=='t':
  ans = 3
else:
  ans = 6
pat2 = pat[1:]
l = len(pat)
i = 1
while i < l:
  if pat[i]=='t' and pat[i-1]=='t':
    ans = (ans*2)%(10**9+7)
  elif pat[i]=='t' and pat[i-1]=='y':
    pass
  elif pat[i]=='y' and pat[i-1]=='t':
    ans = (ans*2)%(10**9+7)
  elif pat[i]=='y' and pat[i-1]=='y':
    ans = (ans*3)%(10**9+7)
  i += 1
print(ans)

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

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

ans = 3
i = 0
if a[0] != b[0]:
    i += 1
    ans += 3

while i < n-1:
    if a[i]==b[i]:
        if a[i+1]==b[i+1]:
            ans *= 2
        else:
            ans *= 2
            i += 1
    else:
        if a[i+1]==b[i+1]:
            ans *= 1
        else:
            ans *= 3
            i += 1
    i += 1
    ans %= 1000000007
print(ans)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

MOD = 1000000007

N = read()
S = input()
T = input()

ans = 1

i = 0
prev = 0

M1 = {0:3, 1:2, 2:1}
M2 = {0:6, 1:2, 2:3}
while i < N:
  if S[i] == T[i]:
    ans = ans * M1[prev] % MOD
    prev = 1
    i += 1
  else:
    ans = ans * M2[prev] % MOD
    prev = 2
    i += 2

print(ans)

Solution (Python):
MOD = 10 ** 9 + 7


def main():
    n, s1, s2 = int(input()), input(), input()

    com, idx = 1, 0
    while idx < n:
        if idx == 0:
            if s1[idx] == s2[idx]:
                com *= 3
                idx += 1
            else:
                com *= 6
                idx += 2

        elif s1[idx] == s2[idx]:
            if s1[idx-1] == s2[idx-1]:
                com = com * 2 % MOD
            idx += 1
        else:
            if s1[idx-1] == s2[idx-1]:
                com = com * 2 % MOD
            else:
                com = com * 3 % MOD
            idx += 2

    print(com)


if __name__ == '__main__':
    main()

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

if s1[0]==s2[0]:
    ass = 3
    i = 0
else:
    ass = 6
    i = 1
    
while i <= n-2:
    if s1[i]==s2[i]:
        if s1[i+1]==s2[i+1]:
            ass = ass*2
            if ass >= 1000000007:
                ass = ass%1000000007
            i = i+1
        else:
            ass = ass*2
            if ass >= 1000000007:
                ass = ass%1000000007
            i = i+2
    else:
        if s1[i+1]==s2[i+1]:
            ass = ass
            if ass >= 1000000007:
                ass = ass%1000000007
            i = i+1
        else:
            ass = ass*3
            if ass >= 1000000007:
                ass = ass%1000000007
            i = i+2
print(ass)

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

s = raw_input()

arr = []

i = 0
while i < n:
	if i == n-1:
		arr.append('y')
		break

	if s[i] == s[i+1] :
		arr.append('x')
		i += 2

	else :
		arr.append('y')
		i += 1

ans = 3 if arr[0] == 'y' else 6

for i in range(1,len(arr)):
	if arr[i-1] == 'y' and arr[i] == 'y': 
		ans *= 2

	elif arr[i-1] == 'y' and arr[i] == 'x':
		ans *= 2

	elif arr[i-1] == 'x' and arr[i] == 'y':
		ans *= 1

	else :
		ans *= 3
print ans % (10**9 + 7)

Solution (Python):
M = 10 ** 9 + 7


def main():
    n = int(input())
    s1, s2 = input(), input()

    com = 1
    i, j = 0, 0
    while i < n or j < n:
        if i <= j:
            if s1[i] == s2[j]:
                if i == 0:
                    com = com * 3 % M
                elif s1[i-1] == s2[j-1]:
                    com = com * 2 % M
                i += 1
                j += 1
            else:
                if i == 0:
                    com = com * 3 % M
                else:
                    com = com * 2 % M
                i += 2

        else:
            if j == 0:
                com = com * 2 % M
            elif s1[i-3] != s2[j-1]:
                com *= 1.5
            j += 2

    print(int(com) % M)


if __name__ == '__main__':
    main()

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

i=0

ans=1

prev=-2

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

elif(i+1<N):

	if(s1[i]==s1[i+1]):
		ans*=6
		i+=2
		prev=1

	else:
		ans*=3
		i+=1
		prev=2


	while(i<N):
	
		if(i+1<N):

			if(prev==1 and s1[i]==s1[i+1]):

				ans*=3
				i+=2
				prev=1

			elif(prev==2 and s1[i]==s1[i+1]):

				ans*=2
				i+=2
				prev=1

			elif(prev==1):

				i+=1
				prev=2

			elif(prev==2):

				ans*=2
				i+=1
				prev=2

		elif(i<N):

			if(prev==1):

				i+=1
				prev=2

			elif(prev==2):

				ans*=2
				i+=1
				prev=2	
			
			
	print(ans%1000000007)

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

if s1[0]==s2[0]:
	flag=0
	i=1
	ans=3
else:
	flag=1
	i=2
	ans=6	
while i<n:
	if s1[i]==s2[i]:
		if flag==0:
			ans=((ans%p)*2)%p
		else:
			ans = ans%p
		flag=0
		i+=1	
	else:	
		if flag==0:
			ans=((ans%p)*2)%p
		else:
			ans=((ans%p)*3)%p
		flag=1
		i+=2	
print(ans)

Solution (Python):
MOD = 1000000007

N = int(input())
S = []
for i in range(2):
    S.append(input())
    


xy = ""
for i in range(len(S[0])):
    if S[0][i] == S[1][i]:
        xy += "X"
    elif i==len(S[0])-1:
        break
    elif S[0][i] == S[0][i+1]:
        xy += "Y"


if xy[0] == "X":
    ans = 3
else:
    ans = 6

if len(xy)==1:
    pass
else:
    for i in range(1,len(xy)):
        if xy[i-1] == "X" and xy[i] == "X":
            ans *= 2
        elif xy[i-1] == "X" and xy[i] == "Y":
            ans *= 2
        elif xy[i-1] == "Y" and xy[i] == "X":
            ans *= 1
        elif xy[i-1] == "Y" and xy[i] == "Y":
            ans *= 3

        ans = ans%MOD
print(ans)

Solution (Python):
N = int(input())
S1 = input()
S2 = input()
MOD = 10**9+7
ans = 1
prev = None
for c1,c2 in zip(S1,S2):
    if (c1,c2) == prev: continue
    if prev:
        if prev[0] == prev[1]:
            ans *= 2
        else:
            if c1 != c2:
                ans *= 3
    else:
        if c1 == c2:
            ans = 3
        else:
            ans = 6
    prev = (c1,c2)
print(ans % MOD)

Solution (Python):
N=int(input())
S=input()
T=input()
mod=1000000007
if S[0]==T[0]:
    ans=3
    p=0
    i=1
else:
    ans=6
    p=1
    i=2
while i<N:
    if S[i]==T[i] and p==0:
        ans = (ans*2)%mod
        i+=1
        p=0
    elif S[i]==T[i] and p==1:
        
        i+=1
        p=0
    elif S[i]!=T[i] and p==0:
        ans = (ans*2)%mod
        i+=2
        p=1
    elif S[i]!=T[i] and p==1:
        ans = (ans*3)%mod
        i+=2
        p=1  
print(ans)

Solution (Python):



n = int(input())
s = []
s.append(input())
s.append(input())
MOD = 1000000007
ans = 1
last = 0
i = 0
while i < n:
    if s[0][i] == s[1][i]:
        if last == 1:
            ans = ans * 2 % MOD
        elif last == 0:
            ans = 3
        last = 1
        i += 1
    else:
        if last == 1:
            ans = ans * 2 % MOD
        elif last == 2:
            ans = ans * 3 % MOD
        else:
            ans = 6
        last = 2
        i += 2
print(ans)

Solution (Python):
n = int(input())
s = list(input())
ss = list(input())
ans = []
i = 0
while i < n:
	if i == 0:
		if i+1 == n:
			ans.append(3)
			i = 10000
		elif s[i] == s[i+1]:
			ans.append(3)
			ans.append(2)
			i += 2
		else:
			ans.append(3)
			i += 1
	else:
		if s[i] == ss[i]:
			if s[i-1] == ss[i-1]:
				ans.append(2)
				i += 1
			else:
				ans.append(1)
				i += 1
		else:
			if s[i-1] == ss[i-1]:
				ans.append(2)
				i += 2
			else:
				ans.append(3)
				i += 2

t = 1
for k in range(len(ans)):
	t = (t*ans[k])%1000000007
print(t)

Solution (Python):
def check(i,j):
    if i > 0:
        k = S[j][i-1] 
        if k in checked and not k in C:
            C.append(k)
    if j > 0:
        l = S[j-1][i]
        if l in checked and not l in C:
            C.append(l)
N = int(input())
S = [list(input()) for _ in range(2)]
ans = 1
checked = {}
for i in range(N):
    for j in range(2):
        p = S[j][i]
        if not p in checked:
            C = []
            check(i,j)
            if j < 1 and S[j+1][i] == p:
                check(i,j+1)
            checked[p] = C
            if len(C) > 1:
                if not C[0] in checked[C[-1]]:
                    ans = ((ans*3)//2)
            else:
                ans = (ans*(3-len(C)))
print(ans%(10**9+7))

Solution (Python):
N = int(input())
blocks = [input().rstrip() for x in range(2)]

MOD = 1000000007
result = 0
count = 0
prev = False
while count <= N-1:
  if count == 0:
    if blocks[0][count] == blocks[1][count]:
      result = 3
      prev = True
    else:
      result = 6
      count += 1
  else:
    if prev:
      result = (result*2) % MOD
      
      
      if blocks[0][count] != blocks[1][count]:
        prev = False
        count += 1
    else:
      if blocks[0][count] == blocks[1][count]:
        prev = True
      else:
        result = (result*3) % MOD
        count += 1
  count += 1
print(result)

Solution (Python):
mod = 1000000007

N = int(input())

S = input()
S_sub = input()

P = []
now = 0
for i in range(N):
    if i>0 and S[i] != S[i-1]:
        P.append(now)
        now = 0
    now += 1
    
P.append(now)

ans = 3 if P[0]==1 else 6
now = P[0]
for p in P[1:]:
    if now == 1:
        ans = (ans*2)%mod
    elif now == 2:
        if p == 1: ans = (ans*1)%mod
        else: ans = (ans*3)%mod
    now = p
    
print(ans)

Solution (Python):
MOD = 10 ** 9 + 7

n = int(input())
s = list(input())
s2 = list(input())

array = []

i = 0
while i < n:
	if i == n - 1:
		array.append("t")
		i += 1
	elif s[i] != s[i + 1]:
		array.append("t")
		i += 1
	else:
		array.append("y")
		i += 2

if array[0] == "t":
	ans = 3
else:
	ans = 6

if len(array) == 1:
	print(ans)
else:
	for i in range(1, len(array)):
		if array[i-1] == "t":
			ans = (ans * 2) % MOD
		elif array[i] == "y":
			ans = (ans * 3) % MOD

	print(int(ans))

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

mod = 10**9+7


S = ""
flg = False
for i in range(len(S1)):
    if flg:
        flg = False
        continue

    if S1[i] == S2[i]:
        S += "T"
    else:
        S += "Y"
        flg = True

if S[0] == "T":
    ans = 3
    now = "T"
else:
    ans = 6
    now = "Y"

for s in S[1:]:
    if now=="T":
        if s=="T":
            ans *= 2
            now = "T"
        else:
            ans *= 2
            now = "Y"
        ans %= mod

    else:
        if s=="T":
            now = "T"
        else:
            ans *= 3
            ans %= mod
            now = "Y"

print(ans % mod)

Solution (Python):
n=int(input())
a1=list(input().strip())
a2=list(input().strip())

p1='0'
p2='1'
for i1,i2 in zip(a1,a2):
  if p1=='0':
    if i1 != i2:
      x=6
    else:
      x=3
  elif i1 != p1 and i2 !=p2 and i1 !=i2 and p1 != p2:
    x*=3
  elif i1 != p1 and i2 !=p2 and i1 !=i2 and p1 == p2:
    x*=2
  elif i1 != p1 and i2 != p2 and i1 ==i2 and p1 == p2:
    x*=2
  p1=i1
  p2=i2
  
print(x%(10**9+7))

Solution (Python):
N = int(input())
s_lst=[]
for i in range(2):
    s_lst.append(input())


if s_lst[0][0] == s_lst[1][0]:
    wasx = True
    ans, pos = 3, 1
else:
    wasx = False
    ans, pos = 6, 2

while pos < N:
    if s_lst[0][pos] == s_lst[1][pos]:
        if wasx:
            ans = (ans * 2) %1000000007
        wasx = True
        pos += 1
    else:
        if wasx:
            ans = (ans * 2) %1000000007
        else:
            ans = (ans * 3) %1000000007
        wasx = False
        pos += 2
print(ans)

Solution (Python):

from collections import Counter
import math
N = int(input())
S1 = input()
S2 = input()

i = 0
ans = 1
before = -1 
while i < N :
    if S1[i] == S2[i]:
        if before == 1:
            ans *= 1
        elif before == 0:
            ans *=2
        else:
            ans *= 3
        ans = ans % 1000000007
        i += 1
        before = 0
    else:
        if before == 1:
            ans *= 3
        elif before == 0:
            ans *= 2
        else:
            ans *= 6
        ans = ans % 1000000007
        i += 2
        before = 1

print(ans)

Solution (Python):
n = int(input())
s1 = input()
s2 = input()
ans = 1
start = 0
yoko = 0
mae = 0
for i in range(len(s1)):
    if yoko == 1:
        yoko = 0
        continue
    if mae == 0:
        if s1[i] == s2[i]:
            ans *= 3
            mae = 1
        else:
            yoko = 1
            ans *= 6
            mae = 2
        start = 1
    else:
        if mae == 1:
            
            if s1[i] == s2[i]:
                ans *= 2
            
            else:
                ans *= 2
                yoko = 1
                mae = 2
        else:
            
            if s1[i] == s2[i]:
                mae = 1
            
            else:
                ans *= 3
                yoko = 1
print(ans % 1000000007)

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

s1 = input()
s2 = input()



i = 0
while i < n:
    
    if i==0:
        if s1[i] == s2[i]:
            r = 3
        else:
            r = 6
    else:
        if (s1[i - 1]==s2[i - 1]):
            r *= 2
        elif (s1[i - 1]!=s2[i - 1]) and (s1[i]!=s2[i]):
            r *= 3
    if s1[i]!=s2[i]:
        i += 1
    i += 1
print(r % 1000000007)

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

if(s1[0] == s2[0]):
	ans = 3
else:
	ans = 6

for i in range(1, N):
	if s1[i] == s1[i-1] and s2[i] == s2[i-1]: continue
	if s1[i-1] == s2[i-1] : 
		ans *= 2
	else :
		if s1[i] != s2[i] : ans *= 3

print(ans%(10**9+7))

Solution (Python):

N = int(input())
s1 = input()
s2 = input()

if (s1[0]==s2[0]):
    c = 3
else:
    c = 6


for i in range(N-1):
    if (s1[i]==s2[i]):
        c*=2
    else:
        if (s1[i]!=s1[i+1]):
            if (s1[i+1]!=s2[i+1]):
                c*=3
print(c%1000000007)

Solution (Python):
MOD = 1000000007

START = 0
SINGLE = 1
DOUBLE = 2

n = int(raw_input())

d = [raw_input() for i in xrange(2)]

ind = 0
prev = START
total = 1
while ind < n:
    x = d[0][ind]
    if x == d[1][ind]:
        if prev == START:
            total *= 3
        elif prev == SINGLE:
            total *= 2
        elif prev == DOUBLE:
            total *= 1

        prev = SINGLE
        
    elif ind + 1 < n and (x == d[0][ind+1] and d[1][ind] == d[1][ind+1]):
        if prev == START:
            total *= 6
        elif prev == SINGLE:
            total *= 2
        elif prev == DOUBLE:
            total *= 3

        ind += 1
        prev = DOUBLE

    ind += 1
    total %= MOD

print total

Solution (Python):
def is_wide(t1, t2):
	if t1 == t2:
		return True
	return False

n = int(input())
t1 = input()


ans = 1
pos = 0
while pos < len(t1):
	if pos == 0:
		w = 6
		l = 3
	else:
		if prev_wide:
			w = 3
			l = 1
		else:
			w = 2
			l = 2
	prev_wide = False
	if len(t1) > pos+1:
		if is_wide(t1[pos], t1[pos+1]):
			ans *= w
			pos += 1
			prev_wide = True
		else:
			ans *= l
	else:
		ans *= l
	ans %= 1000000007
	pos += 1
print(ans)

Solution (Python):
def solve():
    n = int(input())
    pattern = [[a, b] for a, b in zip(list(input()), list(input()))]
    pointer, ans = 0, 0
    if pattern[0][0] == pattern[0][1]:
        ans = 3
    else:
        ans = 6
    while pointer < n - 1:
        current = pattern[pointer][0]
        if current == pattern[pointer][1]:
            if pattern[pointer+1][0] == pattern[pointer+1][1]:
                ans *= 2
                
            else:
                ans *= 2
                
            pointer += 1
        else:
            if pointer + 2 >= n - 1:
                break
            if pattern[pointer+2][0] == pattern[pointer+2][1]:
                ans *= 1
                
            else:
                ans *= 3
                
            pointer += 2
    print(ans % 1000000007)

if __name__=="__main__":
    solve()

Solution (Python):
n=int(input())
S1=input()
S2=input()
skip=False
p1,p2=False, False
dp=1
for i in range(n):
    if skip:
        skip=False
        continue
    elif S1[i]==S2[i]:
        if p1:
            dp*=2
        elif p2:
            p1=True
            p2=False
        else:
            p1=True
            dp*=3
    elif S1[i]==S1[i+1]:
        skip=True
        if p1:
            dp*=2
            p1=False
            p2=True
        elif p2:
            dp*=3
        else:
            p2=True
            dp*=6
else:
    print(dp%1000000007)

Solution (Python):
N = int(input())
s1 = input()
s2 = input()
sum = 1
mul = 1
flag = 0
i = 0

while True:
    if i >= N:
        print(sum%1000000007)
        break

    elif s1[i]==s2[i] and flag==0:
        sum = 3
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==0:
        sum = 6
        i += 2
        flag = 2
    elif s1[i]==s2[i] and flag==1:
        mul = 2
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==1:
        mul = 2
        i += 2
        flag = 2
    elif s1[i]==s2[i] and flag==2:
        mul = 1
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==2:
        mul = 3
        i += 2
        flag = 2
    sum = sum*mul

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    S1 = input()
    S2 = input()
    sum = 1
    mul = 1
    mod = 1000000007
    fg = 0
    i = 0

    while True:

        if i >= N:
            print(sum)
            exit()

        if S1[i] == S2[i] and fg == 0:
            sum = 3
            i += 1
            fg = 1
        elif S1[i] != S2[i] and fg == 0:
            sum = 6
            i += 2
            fg = 2
        elif S1[i] == S2[i] and fg == 1:
            mul = 2
            i += 1
            fg = 1
        elif S1[i] != S2[i] and fg == 1:
            mul = 2
            i += 2
            fg = 2
        elif S1[i] == S2[i] and fg == 2:
            mul = 1
            i += 1
            fg = 1
        elif S1[i] != S2[i] and fg == 2:
            mul = 3
            i += 2
            fg = 2
        sum = ((sum % mod) * (mul % mod)) % mod