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



Sample input:
3
aab
ccb


Sample output:
6

Submission status: Wrong Answer

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

p = []
i = 0
while i<n:
  if s1[i]==s1[i+1]:
    p.append(2)    
    i+=1
  else:
    p.append(1)
  i+=1
  
if p[0] == 1:
  ans = 3
  i = 1
else:
  ans = 6
  i = 2

while i<len(p):  
  if p[i-1]==2 and p[i] == 1:
    pass
  elif p[i-1]==2 and p[i] == 2:
    ans = (3*ans)%mod
  else:
    ans = (2*ans)%mod
  i+=1      
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
N = int(input())
S1 = input().rstrip()
S2 = input().rstrip()
L = len(S1)

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

if S1[0] == S1[1]:
    dp = 6
    start = 2
    state = 0
else:
    dp = 3
    start = 1
    state = 1

i = start
while i<L-1:
    if S1[i] == S1[i+1]:
        if state == 0:
            dp *= 3
            dp %= MOD
        else:
            dp *= 2
            dp %= MOD
        state = 0
        i += 2
    else:
        if state == 1:
            dp *= 2
            dp %= MOD
        state = 1
        i += 1
print(dp)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def rle(string):
    rle_str = string[0]
    rle_cnt = 1
    ans_l = []
    for i in range(1, len(string)):
        if rle_str == string[i]:
            rle_cnt += 1
        else:
            ans_l.append([rle_str, rle_cnt])
            rle_str = string[i]
            rle_cnt = 1
    ans_l.append([rle_str, rle_cnt])
    return ans_l

rle_s=rle(s1)

if rle_s[0][1]==1:
    ans=3
    left=1
elif rle_s[0][1]==2:
    ans=6
    left=1

for s, i in rle_s[1:]:
    if left==1 and i==1:
        ans*=2
    elif left==1 and i==2:
        ans*=2
    elif left==2 and i==1:
        ans*=1
    elif left==2 and i==2:
        ans*=3
    left=i

print(ans%mod)

Submission status: Wrong Answer

Solution code:
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
        before = 2
        idx += 2
print(ans)

Submission status: Wrong Answer

Solution code:
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:
      Flag = True
    now += 2
  else: #縦
    now += 1
    ans = 2*ans%MOD
    Flag = False
print(ans)

Submission status: Wrong Answer

Solution code:
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:
      cou *= 2
      cou %= mod
      second = True
 # print(i,cou)
print(cou)

Submission status: Wrong Answer

Solution code:
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
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)

Submission status: Wrong Answer

Solution code:
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:
  rlt *= 2
  rlt %= P

print(rlt)

Submission status: Wrong Answer

Solution code:
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
      
print(rlt)

Submission status: Wrong Answer

Solution code:
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"

now = 6

l = len(moji)

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

print(now)

Submission status: Wrong Answer

Solution code:
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"

now = 6

l = len(moji)

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

print(now)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
b=input()
if a[0]!=b[0]:
  x=6
  p=2
  f=1
else:
  x=3
  p=1
  f=0
while p<n:
  if f:
    if a[p]!=b[p]:
      p+=2
      x*=3
    else:
      p+=1
      f=0
  else:
    if a[p]!=b[p]:
      p+=2
      x*=2
      f=1
    else:
      p+=1
      x*=2
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
t=input()
n=len(s)
mod=10**9+7
ans=1
i=0
while i<n:
  if i==0:
    if s[i]==t[i]: 
      ans*=3
      i+=1
    else:
      ans*=3
      i+=2
    continue
  if s[i-1]!=t[i-1] and s[i]==t[i]:
    ans*=1
    i+=1
  elif s[i-1]==t[i-1] and s[i]!=t[i]:
    ans*=2
    i+=2
  elif s[i-1]!=t[i-1] and s[i]!=t[i]:
    ans*=3
    i+=2
  elif s[i-1]==t[i-1] and s[i]==t[i]:
    ans*=2
    i+=1
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
S1=np.array(list(input())).reshape(1,-1)
S2=np.array(list(input())).reshape(1,-1)
mod=10**9+7
#３色
#52こ最大
#接しているドミノの数
alp=list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
D={}
for a in alp:
    D[a]=[]
S=np.concatenate([S1,S2], axis=0)

for i in range(2):
    for j in range(N):
        now=S[i,j]
        if i==0:
            if S[i+1,j]!=now:
                D[now].append(S[i+1,j])
        if i==1:
             if S[i-1,j]!=now:
                D[now].append(S[i-1,j])
        if j>0:
            if S[i,j-1]!=now:
                D[now].append(S[i,j-1])
        if j<N-1:
            if S[i,j+1]!=now:
                D[now].append(S[i,j+1])
#print(D)
done={}
for a in alp:
    done[a]=-1
ans=1
for j in range(N):
    for i in range(2):
        s=S[i,j]
        if done[s]!=-1:
            continue
        L=D[s]
        count=0
        for l in set(L):
            if done[l]!=-1:
                count+=1
        if count==3:
            print(s)
        ans*=3-count
        ans%=mod
        done[s]=1
        #print(s, count)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s1 = readline().rstrip().decode()
s2 = readline().rstrip().decode()
cnt = 0
ans = 0
mod = 10 ** 9 + 7
flag = False
for i in range(n):
    if s1[cnt] != s2[cnt]:
        if cnt != 0:
            if s1[cnt - 1] == s2[cnt - 1]:
                if flag:
                    ans *= 2
                    flag = False
                else:
                    flag = True
            else:
                ans *= 3
        else:
            ans = 6
        cnt += 2
    else:
        if cnt != 0:
            if s1[cnt - 1] != s2[cnt - 1]:
                if flag:
                    ans *= 2
                    flag = False
                else:
                    flag = True
            else:
                ans *= 2
        else:
            ans = 3
        cnt += 1
    ans %= mod
    if cnt >= n:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = input()
S2 = input()
ans = 1
mod = 10**9+7
cnt = 0
former = 0 #0が縦、1が横

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

while cnt < N:
    if S1[cnt] == S2[cnt]:
        if former:
            ans *= 1
        else:
            ans *= 2
        ans %= mod
        former = 0
        cnt += 1
    else:
        if former:
            ans *= 3
        else:
            ans *= 2
        former = 1
        cnt += 2
        ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
s1 = list(input())
s2 = list(input())

li = []
tmp = 1
if n == 1:
    print(3)
    sys.exit()
for i,s in enumerate(s1):
    
    if i == len(s1) - 1:
        break
    #縦
    if s != s1[i+1]:
        li.append(tmp)
        tmp = 1
    #横
    else:
        tmp = 2
# print(li)
# [1, 2, 2, 1, 1, 1, 2, 2, 1, 2, 
#  2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2]
#print(li)
if s1[-1] == s1[-2]:
    li.append(2)
else:
    li.append(1)
#print(li)
#print(sum(li))
all_count = 1
for j,l in enumerate(li):
    if j == 0:
        all_count *= 3
        continue
    if l == 2 and li[j-1] == 2:
        all_count *= 3
    elif l == 1 and li[j-1] == 2:
        all_count *= 1
    else:
        all_count *= 2
print(all_count%1000000007)
#print(958681902)

Submission status: Wrong Answer

Solution code:
N = int(input())
s1 = input()
s2 = input()
ans = 1
being_horizontal = False
was_horizontal = False
was_vertical = False
MOD = 10**9+7
for i in range(N):

    if not was_horizontal and not being_horizontal and not was_vertical: # 開始時
        if s1[i] != s2[i]:
            ans *= 6
            being_horizontal = True
        else:
            ans *= 3
            was_vertical = True
    elif being_horizontal:
        being_horizontal = False
        was_horizontal = True
    elif was_horizontal and s1[i] == s2[i]:
        was_horizontal = False
        was_vertical = True
    elif was_horizontal and s1[i] != s2[i]:
        ans *= 3
        being_horizontal = True
        was_horizontal = False
    elif was_vertical and s1[i] == s2[i]:
        ans *= 2
        was_vertical = True
    elif was_vertical and s1[i] != s2[i]:
        ans *= 4
        was_vertical = False
        being_horizontal = True
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s1 = input()
s2 = input()
ans = 1
being_horizontal = False
was_horizontal = False
was_vertical = False
MOD = 10**9+7
for i in range(N):

    if not was_horizontal and not being_horizontal and not was_vertical: # 開始時

        if s1[i] != s2[i]:
            ans *= 6
            being_horizontal = True
        else:
            ans *= 3
            was_vertical = True
    elif being_horizontal:
        being_horizontal = False
        was_horizontal = True
    elif was_horizontal and s1[i] == s2[i]:
        was_vertical = True
    elif was_horizontal and s1[i] != s2[i]:
        ans *= 3
        being_horizontal = True
        was_horizontal = False
    elif was_vertical and s1[i] == s2[i]:
        ans *= 2
        was_vertical = True
    elif was_vertical and s1[i] != s2[i]:
        ans *= 4
        was_vertical = False
        being_horizontal = True
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s1 = input()
s2 = input()
ans = 1
being_horizontal = False
was_horizontal = False
was_vertical = False
MOD = 10**9+7
for i in range(N):

    if not was_horizontal and not being_horizontal and not was_vertical: # 開始時

        if s1[i] != s2[i]:
            ans *= 6
            being_horizontal = True
        else:
            ans *= 3
            was_vertical = True
    elif being_horizontal:
        being_horizontal = False
        was_horizontal = True
    elif was_horizontal and s1[i] == s2[i]:
        was_vertical = True
    elif was_horizontal and s1[i] != s2[i]:
        ans *= 3
        being_horizontal = True
        was_horizontal = False
    elif was_vertical and s1[i] == s2[i]:
        ans *= 2
        was_vertical = True
    elif was_vertical and s1[i] != s2[i]:
        ans *= 3
        was_vertical = False
        being_horizontal = True
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s1 = input()
s2 = input()
ans = 1
being_horizontal = False
was_horizontal = False
was_vertical = False
MOD = 10**9+7
for i in range(N):

    if not was_horizontal and not being_horizontal and not was_vertical: # 開始時
        ans *= 3
        if s1[i] != s2[i]:
            being_horizontal = True
        else:
            was_vertical = True
    elif being_horizontal:
        being_horizontal = False
        was_horizontal = True
    elif was_horizontal and s1[i] == s2[i]:
        was_vertical = True
    elif was_horizontal and s1[i] != s2[i]:
        ans *= 3
        being_horizontal = True
        was_horizontal = False
    elif was_vertical and s1[i] == s2[i]:
        ans *= 2
        was_vertical = True
    elif was_vertical and s1[i] != s2[i]:
        ans *= 3
        was_vertical = False
        being_horizontal = True
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
T=list(input())
state=[]
lim=1000000007
i=0
while i<N:
    if S[i] == T[i]:
        state.append(0)
        i+=1
    else:
        state.append(1)
        i+=2
ans=3    
for i in range(1,len(state)):
    if state[i] == 1 and state[i-1] == 1:
        ans = (ans * 3) % lim
    elif state[i] == 1 and state[i-1] == 0:
        ans = (ans * 2) % lim
    elif state[i] == 0 and state[i-1] == 1:
        pass
    elif state[i] == 0 and state[i-1] == 0: 
        ans = (ans * 2) % lim
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
S += [input()]
S += [input()]

idx = 0
if S[0][idx]==S[1][idx]:
    flag = 0
    cnt = 3
    idx +=1
elif S[0][idx]!=S[1][idx]:
    flag = 1
    cnt = 6
    idx +=2

while idx<N:
  tmp = [S[0][idx],S[1][idx]]
  if flag == 0:
    if S[0][idx]==S[1][idx]:
      cnt *=2
      flag = 0
      idx +=1
    else:
      cnt *=2
      flag =1
      idx +=2
  elif flag ==1:
    if S[0][idx]==S[1][idx]:
      cnt *=1
      flag = 0
      idx +=1
    else :
      cnt *=3
      flag =1
      idx +=2

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
S += [input()]
S += [input()]

idx = 0
if S[0][idx]==S[1][idx]:
    flag = 0
    cnt = 3
    idx +=1
elif S[0][idx]!=S[1][idx]:
    flag = 1
    cnt = 6
    idx +=2

while idx<N:
  tmp = [S[0][idx],S[1][idx]]
  if flag == 0:
    if S[0][idx]==S[1][idx]:
      cnt *=2
      flag = 0
      idx +=1
    else:
      cnt *=2
      flag =1
      idx +=2
  elif flag ==1:
    if S[0][idx]==S[1][idx]:
      cnt *=1
      flag = 0
      idx +=1
    else :
      cnt *=3
      flag =1
      idx +=2

if N<=2:
  ans = 3
else:
  ans = (cnt)%1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
S += [input()]
S += [input()]

idx = 0
cnt = 1
if S[0][idx]==S[1][idx]:
    flag = 0
    idx +=1
elif S[0][idx]!=S[1][idx]:
    flag = 1
    idx +=2

while idx<N:
  tmp = [S[0][idx],S[1][idx]]
  if flag == 0:
    if S[0][idx]==S[1][idx]:
      cnt *=2
      flag = 0
      idx +=1
    else:
      cnt *=2
      flag =1
      idx +=2
  elif flag ==1:
    if S[0][idx]==S[1][idx]:
      cnt *=1
      flag = 0
      idx +=1
    else :
      cnt *=3
      flag =1
      idx +=2

if N<=2:
  ans = 3
else:
  ans = (cnt*6)%1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s1 = input()
s2 = input()
MOD = 1000000007
state = -1
ans = 1
flag = False
for i in range(N):
  if i+1<N:
    if s1[i]==s1[i+1]:
      flag = True
      continue
    if flag:
      if state==1:
        ans *= 2
      elif state==2:
        ans *= 3
      else:
        ans *= 6
      state = 2
    else:
      if state==1:
        ans *= 2
      elif state==2:
        ans *= 1
      else:
        ans *= 3
      state = 1
    flag = False
  else:
    if state==1:
      ans *= 2
    elif state==2:
      ans *= 1
    else:
      ans *= 3
  ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

import math

def main():
    N = int(input())
    S1 = input().strip()
    S2 = input().strip()

    ans = 1
    tate = False
    i = 0
    if S1[i] == S2[i]: # 縦スタート
        ans *= 3
        tate = True
        i += 1
    else: # 横スタート
        ans *= 6
        tate = False
        i += 2

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
B = input()

def f(horizontal_flag):
    if horizontal_flag[0]:
        if horizontal_flag[1]:
            return 3
        else:
            return 1
    else:
        return 2

if N == 1:
    print(3)    
else:
    if A[0] == A[1]:
        counter = 6
        initial_num = 2
        horizontal_flag = [0,1]
    else:
        counter = 3
        initial_num = 1
        horizontal_flag = [0,1]


    for i in range(initial_num,N):
        if i == N-1:
            if horizontal_flag[1] == 2:
                horizontal_flag[1] = 1
                counter *= f(horizontal_flag)
            else:
                horizontal_flag[1] = 0
                counter *= f(horizontal_flag)
        elif A[i] == A[i+1]:
            horizontal_flag[1] = 2
        else:
            if horizontal_flag[1] == 2:
                horizontal_flag[1] = 1
                counter *= f(horizontal_flag)
            else:
                horizontal_flag[1] = 0
                counter *= f(horizontal_flag)
            horizontal_flag[0] = horizontal_flag[1]
    print(counter % 1000000007)

Submission status: Wrong Answer

Solution code:
import sys,heapq,bisect

mod = 10**9+7

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return input()

def GCD(a,b):
    while(a%b != 0):
        a,b = b,a%b
    return b

def LCM(a,b):
    return a*b//GCD(a,b)
def main():
    N = I()
    S1 = S()
    S2 = S()

    r = 1
    d_type = 0
    i = 0

    if S1[0] == S2[0]:
        r *= 3
        i += 1
        d_type = 0
    else:
        r *= 3 * 2
        i += 2
        d_type = 1

    while i < N:
        if S1[i] == S2[i]:
            if d_type == 0:
                r *= 2
                r %= mod
            i += 1
            d_type = 0
        elif d_type == 1:
            r *= 2
            r %= mod
            i += 2
            d_type = 1
        else:
            i += 2
            d_type = 1

    return(r)

if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

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

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

if S[0] == S[1]:
    ans = 6
    i = 2
    prev = 0  # 0: horizontal, 1:vertical
else:
    ans = 3
    i = 1
    prev = 1

while i <= len(S)-2:
    if prev == 0 and S[i] == S[i+1]:
        ans *= 3
        i += 2
        prev = 0
    elif prev == 0 and S[i] != S[i+1]:
        ans *= 1
        i += 1
        prev = 1
    elif prev == 1 and S[i] == S[i+1]:
        ans *= 2
        i += 2
        prev = 0
    else:
        ans *= 2
        i += 1
        prev = 1
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

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

if S[0] == S[1]:
    ans = 6
    i = 2
    prev = 0  # 0: horizontal, 1:vertical
else:
    ans = 3
    i = 1
    prev = 1

while i < len(S)-1:
    if prev == 0 and S[i] == S[i+1]:
        ans *= 3
        i += 2
        prev = 0
    elif prev == 0 and S[i] != S[i+1]:
        ans *= 1
        i += 1
        prev = 1
    elif prev == 1 and S[i] == S[i+1]:
        ans *= 2
        i += 2
        prev = 0
    else:
        ans *= 2
        i += 1
        prev = 1
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = list(input())
S2 = list(input())
ans=1
prev=0
ue = ""
for i in range(N):
  if S1[i]==S2[i]:
    if prev == 0:
      ans*=3
    elif prev == 1:
      ans*=2
    else:
      ans*=1
    prev = 1
  else:
    if ue == S1[i]:
      continue
    else:
      if prev == 0:
        ans*=6
      elif prev == 1:
        ans*=2
      else:
        ans*=2
      ue=S1[i]
      prev=2
print(ans%1000000007)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
U = 'z' + S()
D = 'w' + S()
ans = 3
for i in range(1, n+1):
    if U[i-1] == U[i] or (U[i] == D[i] and U[i-1] != D[i-1]):
        continue
    elif U[i-1] != D[i-1] and U[i] != D[i]:
        ans = ans * 3 % mod
    else:
        ans = ans * 2 % mod



print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s1, s2 = input(), input()

S1, S2 = s1[0], s2[0]

for s, _ in zip(s1, s2):
    if S1[-1] != s:
        S1 += s
        S2 += _

TATE, YOKO = 0, 1

if S1[0] == S2[0]:
    prev = TATE
    cum = 3
else:
    prev = YOKO
    cum = 6
print("{}\n{}".format(S1, S2))

for i in range(1, len(S1)):
    if S1[i] == S2[i]:
        now = TATE
    else:
        now = YOKO
    if now == TATE:
        if prev == YOKO:
            pass
        else:
            cum *= 2
        prev = TATE
    elif now == YOKO:
        if prev == YOKO:
            cum *= 3
        else:
            cum *= 2
        prev = YOKO

    cum %= (1000000007)
print(int(cum))

Submission status: Wrong Answer

Solution code:
N = int(input())
s1, s2 = input(), input()

S1, S2 = s1[0], s2[0]

for s, _ in zip(s1, s2):
    if S1[-1] != s:
        S1 += s
        S2 += _

TATE, YOKO = 0, 1

if S1[0] == S2[0]:
    prev = TATE
    cum = 3
else:
    prev = YOKO
    cum = 6

for i in range(1, len(S1)):
    if S1[i] == S2[i]:
        now = TATE
    else:
        now = YOKO
    if now == TATE and prev == YOKO:
        cum *= 1
    elif now == YOKO and prev == YOKO:
        cum *= 3
    elif now == TATE and prev == TATE:
        cum *= 2
    else:
        cum *= 2
    cum %= (1000000007)
print(int(cum))

Submission status: Wrong Answer

Solution code:
N = int(input())
s1, s2 = input(), input()

S1, S2 = s1[0], s2[0]

for s, _ in zip(s1, s2):
    if S1[-1] != s:
        S1 += s
        S2 += _

TATE, YOKO = 0, 1

if S1[0] == S2[0]:
    prev = TATE
    cum = 3
else:
    prev = YOKO
    cum = 6
print("{}\n{}".format(S1, S2))

for i in range(1, len(S1)):
    if S1[i] == S2[i]:
        now = TATE
    else:
        now = YOKO
    if now == TATE and prev == YOKO:
        cum *= 1
    elif now == YOKO and prev == YOKO:
        cum *= 3
    elif now == TATE and prev == TATE:
        cum *= 2
    else:
        cum *= 2
    cum %= (1000000007)
print(int(cum))

Submission status: Wrong Answer

Solution code:
N = int(input())
s1 = input()
s2 = input()
p = 0
ans = 1
while p < N:
      # 縦なら隣を見る
      if s1[p] == s2[p]:
            if p == 0: ans *= 3
            else: ans *= 2
            p += 1
      elif s1[p] != s2[p]:
            if p == 0: ans *= 6
            else: ans *= 2
            p += 3

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

Submission status: Wrong Answer

Solution code:
from itertools import*
input()
mod=10**9+7
x=[[s,len(list(t))]for s,t in groupby(len(list(v))for k,v in groupby(input()))]
#print(x)
if x[0][0]==1:
    ans=3
else:
    ans=6
for s,t in x:
    if s==1 and t>1:
        ans*=2**(t-1)%mod
    elif s==2:
        ans*=2*3**(t-1)%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from itertools import*
input()
mod=10**9+7
x=[[s,len(list(t))]for s,t in groupby(len(list(v))for k,v in groupby(input()))]
#print(x)
if x[0][0]==1:
    ans=3
else:
    ans=6
for s,t in x:
    if s==1:
        ans*=2**(t-1)%mod
    else:
        ans*=2*3**(t-1)%mod

print(ans%mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = input()
S2 = input()
mod = 10**9+7

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = list(input())
S2 = list(input())

i = 0
ans = 1
tmp = ''

for _ in range(N):
    if i < N:
        if S1[i] == S2[i]:
            if tmp == '':
                ans *= 3
            elif tmp == 'X':
                ans *= 2
            else:
                ans *= 1   

            tmp = 'X'
            i += 1
      
    if i < N - 1:
        if S1[i] == S1[i+1] and S2[i] == S2[i+1]:
            if tmp == '':
                ans *= 6
            elif tmp == 'X':
                ans *= 2
            else:
                ans *= 3

            tmp = 'Y'
            i += 2
        

        
print(ans%10 ** 9)

Submission status: Wrong Answer

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

i = 1
if S1[0] == S2[0]:
    ans = 3
    state = 0
else:
    i+= 1
    ans = 6
    state = 1

while N -1 > i:
    if S1[i] == S1[i+1] and state == 0:
        ans *= 2
        i+=2
        state = 1
    elif S1[i] == S1[i+1] and state == 1:
        ans *= 3
        i+=2
    elif S1[i] != S1[i+1] and state == 0:
        ans *= 2
        i+= 1
    elif S1[i] != S1[i+1] and state == 1:
        ans *= 1
        i+=1
        state = 0
    else:
        print(i / 0)

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S1=input()
S2=input()
dominos=[]
index=0
while index<N:
    if S1[index]==S2[index]:
        dominos.append(0)
        index+=1
    else:
        dominos.append(1)
        index+=2
start=3
for k,c in enumerate(dominos):
    if k==0:continue
    elif dominos[k-1]==0:
        start*=2
    elif c:start*=3
    start%=10**9+7
print(start)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = input()
S2 = input()
MOD = 10**9+7
s = []
if N > 1 and S1[0] == S1[1]:
    ans = 6
    i = 2
    before = 0
else:
    ans = 3
    i = 1
    before = 1
while(i<N):
    if i < N-1 and S1[i] == S1[i+1]:
        ans *= 2
        i += 2
        before = 0
    else:
        ans *= 2 if before else 1
        i += 1
        before = 1
        
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
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(pat2)
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)

Submission status: Wrong Answer

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

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

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)