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:
n = int(input())
s1 = str(input())
s2 = str(input())

mod = 10**9+7

def judge(x):
    if s1[x] == s2[x]:
        b = 1
        if s1[x-1] == s2[x-1]:
           a = 2
        else:
            a = 1
    else:
        b = 2
        if s1[x-1] == s2[x-1]:
            a = 2
        else:
            a = 3
    return a, b


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


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


while index < n-1:
    key1, key2 = judge(index)
    index += key2
    ans *= key1
    ans %= mod
    #print(index, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = str(input())
s2 = str(input())
if s1[0] == s2[0]:
  c = 3
  state = True
  i = 1
else:
  c = 6
  state = False
  i = 2
while i < n:
  if s1[i] == s2[i]:
    i += 1
    if state:
      c *= 2
    else:
      state = True
  else:
    i += 2
    if state:
      c *= 2
      state = False
    else:
      c *= 3
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [list(input()), list(input())]

MOD = 1000000007

dp = [0]*n
if s[0][0] == s[1][0]:
    dp[0] = 3
else:
    dp[0] = 6

for i in range(1,n):
    if s[0][i] == s[0][i-1]:
        dp[i] = dp[i-1]
    elif s[0][i-1] == s[1][i-1] and s[0][i] == s[1][i]: # tate & tate
        dp[i] = dp[i-1] * 2 % MOD
    elif s[0][i-1] == s[1][i-1] and s[0][i] != s[1][i]: # tate & yoko
        dp[i] = dp[i-1] * 2 % MOD
    elif s[0][i-1] != s[1][i-1] and s[0][i] == s[1][i]: # yoko & tate
        dp[i] = dp[i-1]
    else: # yoko & yoko
        dp[i] = dp[i-1] * 3
print(dp[n-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
L=input()
S=input()
T=[]
i=0
if len(L)==1:
	print(3)
	exit()

while n-2>=i:
	if L[i]==L[i+1]:
		T.append(0)
		i+=2
	else:
		T.append(1)
		i+=1

        
def f(x,y):
	if x==0 and y==1:
		return 1
	if x==0 and y==0:
		return 3
	if x==1 and y==1:
		return 2
	if x==1 and y==0:
		return 2
if T[0]==0:
	ans=3
else:
	ans=6

for i in range(len(T)-1):
	ans=ans*f(T[i],T[i+1])

print(ans)

Submission status: Wrong Answer

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

def main():
    p=10**9+7
    n=int(input())
    s1=readline().strip()
    s2=readline().strip()
    pl=[]
    tempiter=iter(range(n))
    for i in tempiter:
        if s1[i]==s2[i]:
            pl.append(0)
        else:
            pl.append(1)
            _=next(tempiter)
    ans=1
    #print(pl)
    for i,_ in enumerate(pl[:-1]):
        s=pl[i]-pl[i+1]+2*pl[i]*pl[i+1]
        if s==0:
            ans=ans*2 % p
        elif s==1:
            ans=ans*2 % p
        elif s==2:
            ans=ans*3 % p
    print(3*ans % p)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(input())
R = list(input())
mod = 1000000007
if n==1:print(3);exit()
ans = 3
for i in range(1,n):
    if L[i-1]==R[i-1]:
        if L[i]==R[i]:
            ans *=2
        else:
            ans *=2
    else:
        if L[i]!=L[i-1]:
            if L[i]==R[i]:
                continue
            else:
                ans *= 3
    ans %=mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = input()
S2 = input()
def prepare(s1,s2,n):
    result = []
    i = 0
    while i < n:
        if s1[i] == s2[i]:
            result.append(1)
            i += 1
        else:
            result.append(0)
            i += 2

    return result



def calculate(arr):
    ans = 3
    for index in range(1, len(arr)):
        #xo
        if (arr[index - 1] == 1) and (arr[index] == 0):
            ans *= 2

        #xx
        if (arr[index - 1] == 1) and (arr[index] == 1):
            ans *= 2

        #oo
        if (arr[index - 1] == 0) and (arr[index] == 0):
            ans *= 3

        #ox
        if (arr[index - 1] == 0) and (arr[index] == 1):
            ans *= 1

    print(ans % 1000000007)



arr = prepare(S1,S2,N)
calculate(arr)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7

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

res = 1
right_used_color = 0
while len(S1) > 0:
    if S1[len(S1)-1] == S2[len(S1)-1]:
        res = res * (3 - right_used_color) % MOD
        right_used_color = 1
    elif right_used_color == 2:
        res = res * 3 % MOD
        S1.pop()
        S2.pop()
    else:
        res = res * (3 - right_used_color) * (2 - right_used_color)
        right_used_color = 2
        S1.pop()
        S2.pop()
    S1.pop()
    S2.pop()

print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
#import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

mod=10**9+7
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))

n=int(input())
s=[v for v in input()]
s_=[v for v in input()]
ans=3
before=0
pat=3
i=0
if s[0]==s_[0]:
    i+=1
while i<n-1:
    if s[i]!=s[i+1]:
        if before==0:
            ans=(ans*2)%mod
        else:
            before=0
        i+=1
        #sys.stdout.write("{}:{},\n".format(s[i-1],ans))
    else:
        if before==0:
            ans=(ans*2)%mod
            before=1
            i+=2
        else:
            ans=(ans*3)%mod
            before=1
            i+=2
        #sys.stdout.write("{}:{},\n".format(s[i-2],ans))

print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
#import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

mod=10**9+7
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))

n=int(input())
s=[v for v in input()]
s_=[v for v in input()]
ans=3
before=0
pat=3
i=0
if s[0]==s_[0]:
    i+=1
while i<n-1:
    if s[i]!=s[i+1]:
        if before==0:
            ans=(ans*2)%mod
        else:
            before=0
        i+=1
        #sys.stdout.write("{}:{},\n".format(s[i-1],ans))
    else:
        if before==0:
            ans=(ans*2)%mod
            before=1
            i+=2
        else:
            ans=(ans*3)%mod
            before=1
            i+=2
        #sys.stdout.write("{}:{},\n".format(s[i-2],ans))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
count = 0
result = 1

if n == 1:
  print(3)
  exit()
  
if s[count] == s[count+1]:
  result *=6
  _type = "hor"
  count += 2
else:
  result *= 3
  _type = "ver"
  count += 1

while count != n:
  if n - count == 1:
    if _type == "hor":
      result *= 1
    else:
      result *= 2
    count += 1
    _type = "ver"
    continue
  if s[count] == s[count+1]:
    if _type == "hor":
      result *= 3
    else:
      result *= 1
    count += 2
    _type = "hor"
  else:
    if _type == "hor":
      result *= 1
    else:
      result *= 2
    count += 1
    _type = "ver"
print(result)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = input()
_ = input()

c = collections.Counter(S)
instant = []
i = 0
while i < N:
    if c[S[i]] == 2:
        instant.append(2)
        i += 2
    else:
        instant.append(1)
        i += 1

print(instant)
if instant[0] == 2:
    ans = 6
else:
    ans = 3

for i in range(1, len(instant)):
    if instant[i-1] == 1:
        ans *= 2
    elif instant[i] == 2:
        ans *= 3

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

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = input()
_ = input()

c = collections.Counter(S)
instant = list(c.values())

if instant[0] == 2:
    ans = 6
else:
    ans = 3

for i in range(1, len(instant)):
    if instant[i-1] == 1:
        ans = 2 * ans % (10 ** 9 + 7)
    elif instant[i] == 2:
        ans = 3 * ans % (10 ** 9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = input()
_ = input()

c = collections.Counter(S)
instant = list(c.values())

if instant[0] == 2:
    ans = 6
else:
    ans = 3

for i in range(1, len(instant)):
    if instant[i-1] == 1:
        ans *= 2
    elif instant[i] == 2:
        ans *= 3

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

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = input()
_ = input()

c = collections.Counter(S)
instant = list(c.values())

if instant[0] == 2:
    ans = 6
else:
    ans = 3

for i in range(1, len(instant)):
    if instant[i-1] == 1:
        ans *= 2
    elif instant[i] == 2:
        ans *= 3
    else:
        ans *= 1
print(ans % 1000000007)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = input()
input()

c = collections.Counter(S)
instant = list(c.values())

if instant[0] == 2:
    ans = 6
else:
    ans = 3

for i in range(1, len(instant)):
    if instant[i-1] == 1:
        ans *= 2
    elif instant[i] == 2:
        ans *= 3
print(ans % 1000000007)

Submission status: Wrong Answer

Solution code:
def solve():
    mod = 10**9+7
    N = int(input())
    s1 = input()
    s2 = input()
    lis = []
    i=0
    while i<N-1:
        if s1[i]==s1[i+1]:
            lis.append(2)
            i += 2
        else:
            lis.append(1)
            i += 1
    if N==1:
        lis = [1]
    if lis[0]==1:
        ans = 3
    else:
        ans = 6
    for i in range(len(lis)-1):
        if lis[i]==1:
            ans *=2
            ans %= mod
        if lis[i]==2 and lis[i+1]==2:
            ans *=3
            ans %= mod
    ans %= mod
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    mod = 10**9+7
    N = int(input())
    s1 = input()
    s2 = input()
    lis = []
    i=0
    while i<N-1:
        if s1[i]==s1[i+1]:
            lis.append(2)
            i += 2
        else:
            lis.append(1)
            i += 1
    if N==1:
        lis = [1]
    if lis[0]==1:
        ans = 3
    else:
        ans = 6
    for i in range(len(lis)-1):
        if lis[i]==1:
            ans *=2
            ans %= mod
        if lis[i]==2 and lis[i+1]==2:
            ans *=3
            ans %= mod
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S1 = input()
    S2 = input()
    # 縦
    if S1[0] == S2[0]:
        ans = 3

        # 1は縦，0は横
        prev = 1
    else:
        ans = 3 * 2
        prev = 0

    for i in range(1, N):
        # 1つ前が横
        if prev == 0:
            # 縦
            if S1[i] == S2[i]:
                prev = 1
                continue
            else:
                # 同じドミノ
                if S1[i - 1] == S1[i]:
                    continue
                # 違うドミノ
                else:
                    ans *= 3
        else:
            # 一つ前が縦
            # 縦
            if S1[i] == S2[i]:
                ans *= 2
                ans %= MOD
            else:
                prev = 0
                ans *= 2
                ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions  import gcd

#input=sys.stdin.readline
mod=1000000007
n=int(input())
s=[input() for _ in range(2)]
d=[]
i=0
while i<n:
    if s[0][i]==s[1][i]:
        d.append(1)
        i+=1
    else:
        d.append(2)
        i+=2
m=len(d)
ans=0
if d[0]==1:
    ans=3
if d[0]==2:
    ans=6
print(d)
for i in range(1,m):
    if d[i]==1:
        if d[i-1]==2:
            ans*=1
        else:
            ans*=2
    else:
        if d[i-1]==2:
            ans*=3
        else:
            ans*=2
    ans=ans%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
N = int(input())

S1 = input()
S2 = input()
MOD = 1000000007

if S1[0] == S2[0]:
    ans = 3
    pre = 1
else:
    ans = 6
    pre = 2
for i in range(1, N):
    if S1[i] == S1[i - 1]: continue
    if S1[i] == S2[i]:
        if pre == 1:
            ans *= 2
        pre = 1
    else:
        if ans==1:
            ans *= 2
        else:
            ans *=3
        pre = 2
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input()
s2 = input()
ans = 1
ch1 = 1
ch2 = 1
N = 1000000007
s1+='?'
for i in range(1,n+1):
        if s1[i]==s1[i-1]:
            ch1+=1
        else:
            if ch1 ==1:
                if ch2==2:
                    ans*=1
                else:
                    ans=ans*2%N
            else:
                if ch2==2:
                    ans=ans*3%N
                else:
                    ans=ans*2%N
            ch2=ch1
            ch1=1
if s1[0]==s1[1]:
    ans=ans*3%N
else:
    ans=ans*3//2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input()
s2 = input()
ans = 1
ch1 = 1
ch2 = 1
N = 1000000007
s1+='?'
for i in range(1,n+1):
        if s1[i]==s1[i-1]:
            ch1+=1
        else:
            if ch1 ==1:
                if ch2==2:
                    ans*=1
                else:
                    ans=ans*2%N
            else:
                if ch2==2:
                    ans=ans*3%N
                else:
                    ans=ans*2%N
            ch2=ch1
            ch1=1
if s1[0]==s1[1]:
    ans=ans*3//2%N
else:
    ans=ans*3//2%N
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input()
s2 = input()
ans = 1
ch1 = 1
ch2 = 1
N = 1000000007
s1+='?'
for i in range(1,n+1):
        if s1[i]==s1[i-1]:
            ch1+=1
        else:
            if ch1 ==1:
                if ch2==2:
                    ans*=1
                else:
                    ans=ans*2%N
            else:
                if ch2==2:
                    ans=ans*3%N
                else:
                    ans=ans*2%N
            ch2=ch1
            ch1=1
if s1[0]==s1[1]:
    ans=ans*3%N
else:
    ans=ans*3//2%N
print(ans)

Submission status: Wrong Answer

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

def mult(prev,now):
    if (prev == 1)&(now==0):
        return 1
    elif (prev == 1)& (now == 1):
        return 3
    else:
        return 2

if n == 1:
    ans = 3
elif n == 2:
    ans = 6
else:
    
    i = 0
    flag = 0
    ans = 6
    
    while (i <= n - 1):
        if s1[i] != s2[i]:
            pat = 1
            i +=2
            flag += 1
        else:
            pat = 0
            flag += 1
            i += 1
            
        if flag == 1:
            prev = pat
            continue
        elif (flag == 2) & (i == 2):
            
            prev = pat
        else:
            now = pat
            ans *= mult(prev,now)
            prev = now
        
print(int(ans))

Submission status: Wrong Answer

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

def mult(prev,now):
    if (prev == 1)&(now==0):
        return 1
    else:
        return 2

if n == 1:
    ans = 3
elif n == 2:
    ans = 6
else:
    
    i = 0
    flag = 0
    ans = 6
    
    while (i <= n - 1):
        if s1[i] != s2[i]:
            pat = 1
            i +=2
            flag += 1
        else:
            pat = 0
            flag += 1
            i += 1
            
        if flag == 1:
            prev = pat
            continue
        elif (flag == 2) & (i == 2):
            
            prev = pat
        else:
            now = pat
            ans *= mult(prev,now)
            prev = now
        
print(int(ans))

Submission status: Wrong Answer

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

def mult(prev,now):
    if prev == 1:
        return 1
    else:
        return 2

if n == 1:
    ans = 3
elif n == 2:
    ans = 6
else:
    
    i = 0
    flag = 0
    ans = 6
    
    while (i <= n - 1):
        if s1[i] != s2[i]:
            pat = 1
            i +=2
            flag += 1
        else:
            pat = 0
            flag += 1
            i += 1
            
        if flag == 1:
            prev = pat
            continue
        elif (flag == 2) & (i == 2):
            
            prev = pat
        else:
            now = pat
            ans *= mult(prev,now)
            prev = now
        
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
mod = 10 ** 9 + 7
if n == 1:
    print(3)
    exit()
if s[0] == s[1]:
    i = 2
    rslt = 6
    flag = True
else:
    i = 1
    rslt = 3
    flag = False
while i < n - 1:
    if s[i] == s[i + 1]:
        if flag:
            rslt = rslt * 3 % mod
        else:
            rslt = rslt * 2 % mod
        i += 2
        flag = True
    else:
        if not flag:
            rslt = rslt * 2 % mod
        i += 1
        flag = False
print(rslt)

Submission status: Wrong Answer

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

mod = 10**9+7

if s1[0] == s2[0]:
    ans = 3
    bfr = 'T'
    idx = 1
else:
    ans = 6
    bfr = 'Y'
    idx = 2

if n == 1:
    print(ans)
    exit()

while idx <= n-1:
    if s1[idx] == s2[idx]:
        if bfr == 'T':
            ans *= 2
            ans %= mod
        idx += 1
        bfr = 'T'
    else:
        ans *= 3
        ans %= mod
        idx += 2
        bfr = 'Y'
        
print(ans%mod)

Submission status: Wrong Answer

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

mod = 10**9+7

if s1[0] == s1[0]:
    ans = 3
    bfr = 'T'
    blk = 1
    idx = 1
else:
    ans = 6
    bfr = 'Y'
    blk = 2
    idx = 2

if n == 1:
    print(ans)
    exit()

while blk <= n-1:
    if s1[idx] == s2[idx]:
        if bfr == 'T':
            ans *= 2
            ans %= mod
        blk += 1
        idx += 1
        bfr = 'T'
    else:
        if bfr == 'T':
            ans *= 2
            ans %= mod
        else:
            ans *= 3
            ans %= mod
        blk += 2
        idx += 2
        bfr = 'Y'
        
print(ans%mod)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7

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

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

t = [[2, 2], [1, 3]]
while True:
    if i >= n:
        break
    if s1[i] == s2[i]:
        pat = 0
        i += 1
    else:
        pat = 1
        i += 2
    ans *= t[pre_pat][pat]
    ans %= MOD
    print(pre_pat, pat, ans, i)
    pre_pat = pat
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
s = input()
t = []

if (len(s)==1):
    print(3)
    sys.exit()
if (len(s)==2):
    print(6)
    sys.exit()

for i in range(len(s)-1):
    if (i>0):
        if(s[i-1]==s[i]):
            if (i == len(s)-2):
                t.append(1)
                continue
            else:
                continue
        elif (i == len(s)-2):
            t.append(1)
    
    if (s[i]==s[i+1]):
        t.append(2)
    else:
        t.append(1)

if (t[0]==1):
    ans = 3
else:
    ans = 6

for i in range(len(t)-1):
    
    if (t[i]==1):
        if (t[i+1]==1):
            ans *= 2
        else:
            ans *= 2
    else:
        if (t[i+1]==1):
            ans *= 1
        else:
            ans *= 3
print(ans % 1000000007)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
s = input()
t = []

if (len(s)==1):
    print(3)
    sys.exit()
if (len(s)==2):
    print(6)
    sys.exit()
for i in range(len(s)-1):
    if (i>0):
        if(s[i-1]==s[i]):
            if (i == len(s)-2):
                t.append(1)
                continue
            else:
                continue
    
    if (s[i]==s[i+1]):
        t.append(2)
    else:
        t.append(1)
if (t[0]==1):
    ans = 3
else:
    ans = 6
for i in range(len(t)-1):
    if (t[i]==1):
        if (t[i+1]==1):
            ans *= 2
        else:
            ans *= 2
    else:
        if (t[i+1]==1):
            ans *= 1
        else:
            ans *= 3
print(ans % 1000000007)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
s = input()
#s = [input() for _ in range(2)]
print(len(s))
t = []

if (len(s)==1):
    print(3)
    sys.exit()
if (len(s)==2):
    print(6)
    sys.exit()
for i in range(len(s)-1):
    if (i>0):
        if(s[i-1]==s[i]):
            if (i == len(s)-2):
                t.append(1)
                continue
            else:
                continue
    
    if (s[i]==s[i+1]):
        t.append(2)
    else:
        t.append(1)
print(t)
if (t[0]==1):
    ans = 3
else:
    ans = 6
for i in range(len(t)-1):
    print(ans)
    if (t[i]==1):
        if (t[i+1]==1):
            ans *= 2
        else:
            ans *= 2
    else:
        if (t[i+1]==1):
            ans *= 1
        else:
            ans *= 3
print(ans % 1000000007)

Submission status: Wrong Answer

Solution code:
mod = int(1e9) + 7

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

if s1[0] == s2[0]:
    ans = 3
    i = 1
else:
    ans = 6
    i = 2
while i < n:
    #print(ans, i,s1[i],s2[i],s1[i-1],s2[i-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 *= 6
            ans %= mod
        i += 2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s1=input()
s2=input()
if n>1:
    if s1[0]==s1[1]:
        i=0
    else:
        i=1
else:
    i=0
ans=3

flag=False
while i<n:
    if i<n-1:
        if s1[i]==s1[i+1]:
            if flag:
                ans*=3
                i+=2
            else:
                ans*=2
                i+=2
                flag=True
        else:
            if flag:
                flag=False
                i+=1
            else:
                ans*=2
                i+=1
    else:
        if flag:
            flag=False
            i+=1
        else:
            ans*=2
            i+=1
print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
n=int(input())
s1=input()
s2=input()
if n>1:
    if s1[0]==s1[1]:
        i=0
    else:
        i=1
else:
    i=0
ans=3

flag=False
while i<n-1:
    if s1[i]==s1[i+1]:
        if flag:
            ans*=3
            i+=2
        else:
            ans*=2
            i+=2
            flag=True
    else:
        if flag:
            flag=False
            i+=1
        else:
            ans*=2
            i+=1
print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

MOD = 10*9+7

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

i = 0
if S[0][i] == S[1][i]:
    ans = 3
    i += 1
else:
    ans = 6
    i += 2

while i < N:
    if S[0][i] == S[1][i]:
        if S[0][i-1] == S[1][i-1]: ans *= 2
        else: ans *= 1
        ans %= MOD
        i += 1
    else:
        if S[0][i-1] == S[1][i-1]: ans *= 2
        else: ans *= 3
        ans %= MOD
        i += 2

print(ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

i = 0
if S[0][i] == S[1][i]:
    ans = 3
    i += 1
else:
    ans = 6
    i += 2

while i < N:
    if S[0][i] == S[1][i]:
        if S[0][i-1] == S[1][i-1]: ans *= 2
        else: ans *= 1
        i += 1
    else:
        if S[0][i-1] == S[1][i-1]: ans *= 2
        else: ans *= 3
        i += 2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s1 = input()
s2 = input()

r = 0
ans = 1

pre_is_x = True
while r < N:
    if r == 0:
        if s1[r] == s2[r]:
            # x
            ans *= 3
            r += 1
            pre_is_x = True
        else:
            # y
            ans *= 2
            r += 2
            pre_is_x = False
    # if pre_is_x == True:

    elif s1[r] == s2[r]:
        # x
        if pre_is_x == True:
            # from x
            ans *= 2
        else:
            # from y
            ans *= 1
        r += 1
        pre_is_x = True
    else:
        # y
        if pre_is_x == True:
            # from x
            ans *= 2
        else:
            # from y
            ans *= 3
        r += 2
        pre_is_x = False

print(ans % mod)



    # ここからが左以外


# exit()
# while r > N:
#     if s1[r] == s2[r]:
#         # ans *= 1
#         if r == 0:
#             ans *= 1
#         # r-1
#         # r += 1
#         if s1[r-1] == s2[r-1]:
#             ans *= 2
#         if s1[r-1] == s2[r-1]:
#             ans *= 1
#         r += 1

#     else:
#         s1[r] != s2[r]:
#         ans *= 2
#         r += 2

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc071/tasks/arc081_b
# 横ドミノと縦ドミノの場合わけを考える
# 横ドミノ→横ドミノの場合 : いままでの通り*3通り
# 横ドミノ→縦ドミノ : いままで*1通り ok
# 縦ドミノ→横ドミノ : いままで*2通り ok
# 縦ドミノ→縦ドミノ : いままで*2通り ok

MOD = 10**9+7
N = int(input())
S1 = input()
S2 = input()
pre1 = S1[0]
pre2 = S2[0]

if pre1 != pre2:
    ans = 6
else:
    ans = 3
for s1, s2 in zip(S1[1:], S2[1:]):
    if pre1 == s1 and pre2 == s2:
        continue
    elif pre1 != pre2 and s1 != s2:
        # 横→横
        ans *= 3
    elif pre1 != pre2 and s1 == s2:
        # 横→縦
        continue
    elif pre1 == pre2 and s1 != s2:
        # 縦→横
        ans *= 2
    elif pre1 == pre2 and s1 == s2:
        # 縦→縦
        ans *= 2

    if ans >= MOD:
        ans %= MOD

    pre1, pre2 = s1, s2


print(ans % MOD)

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    S1=input()
    S2=input()
    L=[0]
    
    #最初：0 縦向き:1 横向き:2
    i=0
    for _ in range(N):
        if S1[i]==S2[i]:
            L.append(1)
            i+=1
        else:
            L.append(2)
            i+=2
        if i>=N-1:
            break
    ans=1
    
    for i in range(1,len(L)):
        if L[i-1]==0:
            if L[i]==1:
                ans*=3
            else:
                ans*=6
        elif L[i-1]==1:
            ans*=2
        else:
            if L[i]==1:
                continue
            else:
                ans*=3
        ans%=mod
    print(ans)
        
    

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()+"0"
if len(s)==2:
    print(3)
    exit()
i = 0

d = []#0が縦、1が横
while i<n:
    if s[i]==s[i+1]:
        d.append(1)
        i+=1
    else:
        d.append(0)
    i+=1
    
d.append(-1)
ans = 1
#print(d)
if d[0]==0:
    ans = 3
else:
    ans = 6
mod = 10**9+7
for j in range(1,len(d)):
    if d[j]==0:
        ans*=2
    else:
        if d[j-1]==1:
            ans*=3
    ans%=mod
    

    
print(ans)