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_list = [i for i in input()]
s2_list = [i for i in input()]
ans = 1
if s1_list[0] == s2_list[0]:
    ans = ans*3
    for i in range(1, n):
        if s1_list[i] == s2_list[i] and s1_list[i-1] == s2_list[i-1]:
            ans = ans*2 
        elif s1_list[i] == s2_list[i] and s1_list[i-1] != s2_list[i-1]:
            ans = ans 
        elif s1_list[i] != s2_list[i] and s1_list[i-1] == s1_list[i]:
            ans = ans*2        
else:   
    ans = ans*6
    for i in range(2, n):
        if s1_list[i] == s2_list[i] and s1_list[i-1] == s2_list[i-1]:
            ans = ans*2 
        elif s1_list[i] == s2_list[i] and s1_list[i-1] != s2_list[i-1]:
            ans = ans 
        elif s1_list[i] != s2_list[i] and s1_list[i-1] == s1_list[i]:
            ans = ans*2
print(ans%1000000007)

Submission status: Wrong Answer

Solution code:
n=int(input())
s1=input()
s2=input()
ans=3
mod=10**9+7
for i in range(1,n):
    if s1[i]==s1[i-1]:
        continue
    elif s1[i]==s2[i] and s1[i-1]==s2[i-1]:
        ans*=2
    elif s1[i]==s2[i] and s1[i-1]!=s2[i-1]:
        ans*=2
    elif s1[i]!=s2[i] and s1[i-1]==s2[i-1]:
        ans*=1
    else:
        ans*=3
print(ans%mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
s1 = input()
s2 = input()
mod = 1000000007
ans = 1
tate = True
if s1[0]==s2[0]:
    ans *= 3
    s1 = s1[1:]
else:
    ans *= 6
    s1 = s1[2:]
    tate = False
while len(s1) > 1:
    if s1[0] == s1[1]:
        s1 = s1[2:]
        if tate:
            ans *= 2
        else:
            ans *= 3
        ans %= mod
        tate = False
    else:
        if tate:
            ans *= 2
            ans %= mod
        s1 = s1[1:]
        tate = True
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = input()
S2 = input()
patterns = []
flag = False
for i in range(N):
    if S1[i] == S2[i]:
        patterns.append('row')
    elif flag is False:
        patterns.append('column')
        flag = True
    else:
        flag = False

print(patterns)
if patterns[0] == 'row':
    count = 3
else:
    count = 6
for i in range(1, len(patterns)):
    prev = patterns[i-1]
    current = patterns[i]
    if prev == 'row':
        if current == 'row':
            count *= 2
        else:
            count *= 2
    else: # column
        if current == 'row':
            count *= 1
        else:
            count *= 3
print(count % (10**9  + 7))

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = input()
S2 = input()
res = 6
idx = 0
s = []
mod = 1000000007
while idx < N:
    if S1[idx] == S2[idx]:
        s.append(0)
    else:
        s.append(1)
        idx += 1
    idx += 1

res = 3 if s[0] == 0 else 6

for idx in range(1, len(s)):
    prev, cur = s[idx-1], s[idx]
    if prev == 0:
        if cur == 0:
            res *= 2
        else:
            res *= 1
    else:
        if cur == 0:
            res *= 2
        else:
            res *= 3

res %= mod

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = input()
S2 = input()
res = 6
idx = 0
s = []
mod = 1000000007
while idx < N:
    if S1[idx] == S2[idx]:
        s.append(0)
    else:
        s.append(1)
        idx += 1
    idx += 1

res = 3 if s[0] == 0 else 6

for idx in range(1, len(s)):
    prev, cur = s[idx-1], s[idx]
    if prev == 0:
        if cur == 0:
            res *= 2
        else:
            res *= 1
    else:
        if cur == 0:
            res *= 2
        else:
            res *= 3

    res %= mod

print(res)

Submission status: Wrong Answer

Solution code:
MOD = 1000000007

def m():
    N = int(input())
    if N == 1:
        return 3
    s = str(input())
    s2 = str(input())
    a = []
    past = s[0]
    point = 0
    while point < len(s):
        if s[point] == s[point+1]:
            a.append('y')
            point += 2
        else:
            a.append('x')
            point += 1

        if point == len(s) -1:
            a.append('x')
            break

    ans = 0
    if a[0] == 'x':
        ans = 3
    else:
        ans = 6

    for j in range(1, len(a)):
        if a[j-1] == 'x' and a[j] == 'x':
            ans *=2 % MOD
        elif a[j-1] == 'y' and a[j] == 'x':
            ans *=1 % MOD
        elif a[j-1] == 'x' and a[j] == 'y':
            ans *=2 % MOD
        elif a[j-1] == 'y' and a[j] == 'y':
            ans *=3 % MOD

    return ans % MOD

Submission status: Wrong Answer

Solution code:
MOD = 1000000007

def m():
    N = int(input())
    if N == 1:
        return 3
    s = str(input())
    s2 = str(input())
    a = []
    past = s[0]
    point = 0
    while point < len(s):
        if s[point] == s[point+1]:
            a.append('y')
            point += 2
        else:
            a.append('x')
            point += 1

        if point == len(s) -1:
            a.append('x')
            break
        if point >= len(s):
            a.append('y')
            break

    ans = 0
    if a[0] == 'x':
        ans = 3
    else:
        ans = 6

    for j in range(1, len(a)):
        if a[j-1] == 'x' and a[j] == 'x':
            ans *=2 % MOD
        elif a[j-1] == 'y' and a[j] == 'x':
            ans *=1 % MOD
        elif a[j-1] == 'x' and a[j] == 'y':
            ans *=2 % MOD
        elif a[j-1] == 'y' and a[j] == 'y':
            ans *=3 % MOD

    return ans % MOD

print(m())

Submission status: Wrong Answer

Solution code:
MOD = 1000000007

def m():
    N = int(input())
    if N == 1:
        return 3
    s = str(input())
    s2 = str(input())
    a = []
    past = s[0]
    point = 0
    while point < len(s):
        if s[point] == s[point+1]:
            a.append('y')
            point += 2
        else:
            a.append('x')
            point += 1

        if point == len(s) -1:
            a.append('x')
            break
        if point == len(s):
            a.append('y')
            break

    ans = 0
    if a[0] == 'x':
        ans = 3
    else:
        ans = 6

    for j in range(1, len(a)):
        if a[j-1] == 'x' and a[j] == 'x':
            ans *=2 % MOD
        elif a[j-1] == 'y' and a[j] == 'x':
            ans *=1 % MOD
        elif a[j-1] == 'x' and a[j] == 'y':
            ans *=2 % MOD
        elif a[j-1] == 'y' and a[j] == 'y':
            ans *=3 % MOD

    return ans % MOD

def someone_ans():
    pass

print(m())

Submission status: Wrong Answer

Solution code:
def m():
    N = int(input())
    if N == 1:
        return 3
    s = str(input())
    s2 = str(input())
    a = []
    past = s[0]
    point = 0
    while point < len(s):
        if s[point] == s[point+1]:
            a.append('y')
            point += 2
        else:
            a.append('x')
            point += 1

        if point == len(s) -1:
            a.append('x')
            break
        if point == len(s):
            a.append('y')
            break

    ans = 0
    if a[0] == 'x':
        ans = 3
    else:
        ans = 6

    for j in range(1, len(a)):
        if a[j-1] == 'x' and a[j] == 'x':
            ans *=2
        elif a[j-1] == 'y' and a[j] == 'x':
            ans *=1
        elif a[j-1] == 'x' and a[j] == 'y':
            ans *=2
        elif a[j-1] == 'y' and a[j] == 'y':
            ans *=3

    return ans % 1000000007


print(m())

Submission status: Wrong Answer

Solution code:
def m():
    N = int(input())
    if N == 1:
        return 3
    s = str(input())
    a = []
    past = s[0]
    point = 0
    while point < len(s):
        if s[point] == s[point+1]:
            a.append('y')
            point += 2
        else:
            a.append('x')
            point += 1

        if point == len(s) -1:
            a.append('x')
            break
        if point == len(s):
            a.append('y')
            break

    ans = 0
    if a[0] == 'x':
        ans = 3
    else:
        ans = 6

    for j in range(1, len(a)):
        if a[j-1] == 'x' and a[j] == 'x':
            ans *=2
        elif a[j-1] == 'y' and a[j] == 'x':
            ans *=1
        elif a[j-1] == 'x' and a[j] == 'y':
            ans *=2
        elif a[j-1] == 'y' and a[j] == 'y':
            ans *=3

    return ans % 1000000007


print(m())

Submission status: Wrong Answer

Solution code:
P=10**9+7
N=int(input())
S1=input()
S2=input()
L=[1]
k=0
P=10**9+7
for i in range(1,N):
    if S1[i]!=S1[i-1]:
        L.append(0)
        k+=1
    L[k]+=1
M=len(L)
S=1
if L[k]==1:
    S=3
else:
    S=6
for i in range(1,M):
    if L[i-1]==1:
        S=(S*2)%P
    else:
        if L[i]==2:
            S=(S*3)%P
print(S)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
b=input()
c=[]
i=0
while i<n:
    if i==n-1:
        c.append(1)
        i+=1
    elif a[i]==a[i+1]:
        c.append(0)
        i+=2
    else:
        c.append(1)
        i+=1
if c[0]==0: count=6
else: count=3
    
for i in range(len(c)-1):
    if c[i]==0 and c[i+1]==1: continue
    elif c[i]==0 and c[i+1]==0: count*=3
    else: count*=2
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
b=input()
c=[]
i=0
while i<n:
    if i==n-1:
        c.append(1)
        i+=1
    elif a[i]==a[i+1]:
        c.append(0)
        i+=2
    else:
        c.append(1)
        i+=1
print(c)
if c[0]==0: count=6
else: count=3
    
for i in range(len(c)-1):
    if c[i]==0 and c[i+1]==1: continue
    elif c[i]==0 and c[i+1]==0: count*=3
    else: count*=2
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
b=input()
c=[]
i=0
while i<n:
    if i==n-1:
        c.append(1)
        i+=1
    elif a[i]==a[i+1]:
        c.append(0)
        i+=2
    else:
        c.append(1)
        i+=1
#print(c)
if c[0]==0: count=6
else: count=3
    
for i in range(len(c)-1):
    if c[i]==0 and c[i+1]==1: continue
    else: count*=2
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
b=input()
c=[]
i=0
while i<n:
    if i==n-1:
        c.append(1)
        i+=1
    elif a[i]==a[i+1]:
        c.append(0)
        i+=2
    else:
        c.append(1)
        i+=1
print(c)
if c[0]==0: count=6
else: count=3
    
for i in range(len(c)-1):
    if c[i]==0 and c[i+1]==1: continue
    else: count*=2
print(count)

Submission status: Wrong Answer

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

MOD = int(1e9) + 7

tate = "tate"
yoko = "yoko"

i = 0
ans = 0
pre = ""
if s1[i] == s2[i]:
    ans = 3
    i += 1
    pre = tate
else:
    ans = 6
    i += 2
    pre = yoko

while i < N:
    if s1[i] == s2[i]:
        if pre == tate:
            ans *= 2
        elif pre == yoko:
            ans *= 1
        i += 1
        pre = tate
    else:
        if pre == tate:
            ans *= 2
        elif pre == yoko:
            ans *= 2
        i += 2
        pre = yoko
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

MOD = int(1e9) + 7

tate = "tate"
yoko = "yoko"

i = 0
ans = 0
pre = ""
if s1[i] == s2[i]:
    ans = 3
    i += 1
    pre = tate
else:
    ans = 6
    i += 2
    pre = yoko

while i < N:
    if s1[i] == s2[i]:
        if pre == tate:
            ans *= 2
            ans %= MOD
            i += 1
        else:
            ans *= 1
            ans %= MOD
            i += 2
        pre = tate
    else:
        if pre == tate:
            ans *= 2
            ans %= MOD
            i += 1
        else:
            ans *= 2
            ans %= MOD
            i += 2
        pre = yoko
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S_1 = list(input())
S_2 = list(input())



if S_1[0] == S_2[0]:
    res = 3
    flag = 0
    i = 1
else:
    res = 6
    flag = 1
    i = 2

while i != N:
    if S_1[i] == S_2[i]:
        if flag == 0:
            res *= 2 
        else:
            res *= 1
            flag = 0
        i += 1

    else:
        if flag == 0:
            res *= 2
            flag = 1
        else:
            res *= 3
        i += 2
        
ans = res%100000007

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S1 = input()
S2 = input()
 
result = 3
if N != 1:
    i=1
    while i < N:
        if i==1:
            result *= 2
        elif S1[i-1]==S2[i-1]:
            result *=2
        elif S1[i-1]!=S2[i-1]:
            if S1[i] != S2[i]:
                result *= 3
        i += 1
 
print(result%1000000007)

Submission status: Wrong Answer

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

result = 3
if N != 1:
    i=1
    while i < N:
        if S1[i-1] == S2[i-1]:
            result *= 2
        elif S1[i-1] != S1[i]:
            if S1[i] != S2[i]:
                result *= 3
        i += 1

print(result%1000000007)

Submission status: Wrong Answer

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

i = 0
ans = 3
p = None
while i < (N - 1):
    s1 = S1[i]
    s1_2 = S1[i+1]
    s2 = S2[i]
    if s1 == s1_2:
        if p is None:
            ans = 6
        else:
            if p == 'X':
                ans *= 2
            else:
                ans *= 3
        i += 2
        p = 'Y'
    if s1 == s2:
        if p is None:
            ans = 3
        else:
            if p == 'X':
                ans *= 2
            else:
                ans *= 1
        p = 'X'
        i += 1

print(ans % C)

Submission status: Wrong Answer

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

i = 0
ans = 3
p = None
while i < (N - 1):
    s1 = S1[i]
    s1_2 = S1[i+1]
    s2 = S2[i]
    if s1 == s1_2:
        if p is None:
            ans = 6
        else:
            if p == 'X':
                ans *= 2
            else:
                ans *= 3
        i += 2
        p = 'Y'
    if s1 == s2:
        if p is None:
            ans = 3
        else:
            if p == 'X':
                ans *= 2
            else:
                ans *= 1

        p = 'X'
        i += 1

print(ans % C)

Submission status: Wrong Answer

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

i = 0
ans = 1
p = None
while i < (N - 1):
    s1 = S1[i]
    s1_2 = S1[i+1]
    s2 = S2[i]
    if s1 == s1_2:
        if p is None:
            ans = 6
        else:
            if p == 'X':
                ans *= 2
            else:
                ans *= 3
        i += 2
        p = 'Y'
    if s1 == s2:
        if p is None:
            ans = 3
        else:
            if p == 'X':
                ans *= 2
            else:
                ans *= 1

        p = 'X'
        i += 1

print(ans % C)

Submission status: Wrong Answer

Solution code:
num=raw_input()
tmp=raw_input()
tmp2=raw_input()
bef="none"
n_state=0
af_state=0
if len(tmp)==1:
    out=3
else:
    if tmp[0]==tmp[1]:
        out=3
        n_state=1
        init=2
    else:
        out=3
        init=1
    #out=3

    for i in range(init,len(tmp)):
        if tmp[i]!=bef:
            #print "aaa"
            if i<int(num)-1:
                if tmp[i]==tmp[i+1]:
                    if n_state==0:
                        out=out*2
                    else:
                        out=out*3
                        n_state=0
                else:
                    if n_state==0:
                        out=out*2
                    else:
                        out=out*1
                        n_state=0
            else:
                if n_state==0:
                    out=out*2
                else:
                    out=out*1
                    n_state=0
        else:
            n_state=1
        bef=tmp[i]
print out % 1000000007

Submission status: Wrong Answer

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n,  = read_line(int)

m = 1000000007

domino = []
domino.append(input())
domino.append(input())

# print(domino[0])
# print(domino[1])

def compress(line):
    x = [line[0]]
    for c in line[1:]:
        if x[-1] != c:
            x.append(c)
    return x

domino[0] = compress(domino[0])
domino[1] = compress(domino[1])

xs = []
for i in range(len(domino[0])):
    xs.append(domino[0][i] != domino[1][i])
# print(xs)

patterns = None
if xs[0]:
    patterns = 6
else:
    patterns = 3

lastX = xs[0]
for x in xs[1:]:
    if x:
        # T -> T
        if lastX:
            patterns *= 3
        else:
            # F -> T
            patterns *= 2
    else:
        # T -> F
        if lastX:
            patterns *= 1
        else: # F -> F
            patterns *= 2
    lastX = x

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input()
s2 = input()
count = 1
j = 0
if s1[0] == s2[0]:
  count *= 3
else:
  count *= 6 
while j < n-1:
  if s1[j] == s2[j]:
    if s1[j+1] == s2[j+1]:
      count *= 2
      count %= 1000000007
    else:
      count *= 2
      count %= 1000000007
      j += 1
  else:
    if s1[j+1] == s2[j+1]:
      count *= 1
      count %= 1000000007
    else:
      count *= 3
      count %= 1000000007
      j += 1
  j += 1
print(count)

Submission status: Wrong Answer

Solution code:
def d():
    N  = int(input())
    S1 = input()
    S2 = input()
    from collections import deque
    s = deque(S1)
    S = ''
    for _ in range(N):
        try:
            if s[0] == s[1]:
                S += 'Z'
                s.popleft()
                s.popleft()
            else:
                S += 'I'
                s.popleft()
        except:
            break
    try:
        res = 6 if S[0] == 'Z' else 3
    except:
        res = 3
        print(3)
        return
    for i in range(1, len(S)):
        if S[i-1:i+1] == 'II':
            res *= 2
        if S[i-1:i+1] == 'IZ':
            res *= 2
        if S[i-1:i+1] == 'ZI':
            res *= 1
        if S[i-1:i+1] == 'ZZ':
            res *= 3
    print(res % 1000000007)

d()

Submission status: Wrong Answer

Solution code:
num=raw_input()
tmp=raw_input()
tmp2=raw_input()
bef="none"
n_state=0
af_state=0
if len(tmp)==1:
    out=3
else:
    if tmp[0]==tmp[1]:
        out=6
    else:
        out=3

    for i in range(1,len(tmp)):
        if tmp[i]!=bef:
            if i<int(num)-1:
                if tmp[i]==tmp[i+1]:
                    if n_state==0:
                        out=out*2
                    else:
                        out=out*3
                        n_state=0
                else:
                    if n_state==0:
                        out=out*2
                    else:
                        out=out*1
                        n_state=0
            else:
                if n_state==0:
                    out=out*2
                else:
                    out=out*1
                    n_state=0
        else:
            n_state=1
        bef=tmp[i]
print out % 1000000007

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input()
s2 = input()
count = 1
if s1[0] == s2[0]:
  count *= 3
else:
  count *= 6 
for j in range(n-1):
  if s1[j] == s2[j]:
    if s1[j+1] == s2[j+1]:
      count *= 2
      count %= 1000000007
    else:
      count *= 2
      count %= 1000000007
      j += 1
  else:
    if s1[j+1] == s2[j+1]:
      count *= 1
      count %= 1000000007
    else:
      count *= 3
      count %= 1000000007
      j += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = input()

s = [chr(i) for i in range(97, 97+26)]
b = [chr(i) for i in range(65, 65+26)]

l1 = input()
l2 = input()

output = 3
if l1[0] == l2[0]:
    i = 1
else:
    i = 2
    output *= 2

while True:
    if i >= len(l1):
        break

    if l1[i] == l2[i] and l1[i-1]==l2[i-1]:
        i += 1
        output *= 2
    elif l1[i] == l2[i] and l1[i-1]!=l2[i-1]:
        i += 1
        output *= 1
    elif l1[i] != l2[i] and l1[i-1]==l2[i-1]:
        i += 2
        output *= 2
    elif l1[i] != l2[i] and l1[i-1]!=l2[i-1]:
        i += 2
        output *= 2

print(output)

Submission status: Wrong Answer

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n,  = read_line(int)

m = 1000000007

domino = []
domino.append(input())
domino.append(input())

# print(domino[0])
# print(domino[1])

def compress(line):
    x = [line[0]]
    for c in line[1:]:
        if x[-1] != c:
            x.append(c)
    return x

domino[0] = compress(domino[0])
domino[1] = compress(domino[1])

xs = []
for i in range(len(domino[0])):
    xs.append(domino[0][i] != domino[1][i])
# print(xs)

patterns = None
if xs[0]:
    patterns = 6
else:
    patterns = 3

lastX = xs[0]
for x in xs[1:]:
    if x:
        if lastX:
            patterns *= 12
        else:
            patterns *= 6
    else:
        patterns *= 1
    lastX = x

print(patterns % m)

# 012
# 021

Submission status: Wrong Answer

Solution code:
N = int(input())						# 5
a = list(input())
#b = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

MOD = 1000000007

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




b=[]
bSkip = False

for i in range(N-1):
	if bSkip:
		bSkip = False
		continue
	if a[i] == a[i+1]:
		b.append(2)
		bSkip = True
	else:
		b.append(1)

#print(b)


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


for i in range(1, len(b)):
	if b[i-1]==1:
		ans = (ans * 2) % MOD
	else:
		if b[i]==2:
			ans = (ans * 3) % MOD


print(ans % MOD)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
S = str(input())
_ = input()

if (N == 1):
    print('3')
    sys.exit()

b = None
l = []
i = 0

while(i < N):
    if i == N-1:
        l.append(1)
        i += 1
        continue

    if S[i] == S[i + 1]:
        l.append(2)
        i += 2
        continue
    else:
        l.append(1)
        i += 1
        continue

acc = 1
j = 0
while(j < len(l)):
    if j == 0:
        if (l[j] == 1):
            acc *= 3
            j += 1
            continue
        else:
            acc *= 6
            j += 2
            continue

    if l[j-1] == 1:
        acc *= 2
        if (l[j] == 1):
            j += 1
            continue
        else:
            j += 2
            continue
    else:
        if (l[j] == 1):
            acc *= 1
            j += 1
            continue
        else:
            acc *= 3
            j += 2
            continue

print(acc % 1000000007)

Submission status: Wrong Answer

Solution code:
# coding=utf-8
import numpy as np

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

c = 3
t = 0
j = 'H'
res = 1
for i in xrange(N):
    if t + 1 < N and S1[t] == S1[t + 1]:
        res *= c
        res *= (c - 1)
        t += 2
        c = 2
        j = 'W'
    else:
        if j == 'W':
            c = 1
        res *= c
        t += 1
        c -= 1 if c > 2 else 0
        if c == 1:
            c = 2
        j = 'H'

    if t >= N:
        break
print res % 1000000007

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(input())
b = list(input())
c = []
for key,val in Counter(a).items():
    if val == 1:
        c.append(1)
    elif val ==2:
        c.append(2)

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(input())
b = list(input())
c = []
for key,val in Counter(a).items():
    if val == 1:
        c.append(1)
    elif val ==2:
        c.append(2)

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())						# 5
a = list(input())
#b = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

MOD = 1000000007

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




b=[]
bSkip = False

for i in range(N-1):
	if bSkip:
		bSkip = False
		continue
	if a[i] == a[i+1]:
		b.append(2)
		bSkip = True
	else:
		b.append(1)

#print(b)


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


for i in range(1, len(b)):
	if b[i-1]==1:
		ans = (ans * 2) % MOD
	else:
		if b[i]==2:
			ans = (ans * 3) % MOD


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())						# 5
a = list(input())
#b = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

MOD = 1000000007

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



b=[]
bSkip = False

for i in range(N-1):
	if bSkip:
		bSkip = False
		continue
	if a[i] == a[i+1]:
		b.append(2)
		bSkip = True
	else:
		b.append(1)

print(b)


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


for i in range(1, len(b)):
	if b[i-1]==1:
		ans = (ans * 2) % MOD
	else:
		if b[i]==2:
			ans = (ans * 3) % MOD


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = [[0 for i in range(N)] for j in range(2)]

S[0] = input()
S[1] = input()

x = 2
y = len(S[0])

patterns = 1

tate_flag = False
yoko_flag = False
last_state = ""

log = []
skip = False
for i in range(y):
    if skip is True:
        skip = False
        continue
    if S[0][i] == S[1][i]:
        if last_state == "":
            patterns *= 1
        elif last_state == "tate":
            patterns *= 2
        elif last_state == "yoko":
            patterns *= 1
        last_state = "tate"
        log.append("tate")

    else:
        if last_state == "":
            patterns *= 2
        elif last_state == "tate":
            patterns *= 2
        elif last_state == "yoko":
            patterns *= 3
        last_state = "yoko"
        log.append("yoko")
        skip = True

if "yoko" in log and "tate" not in log:
    patterns *= 2
elif "yoko" not in log and "tate" in log:
    patterns *= 2
else:
    patterns *= 3

print(str(patterns))

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input()
s2 = input()
count = 1
start = -1
end = -1
if s1[0] == s2[0]:
  count *= 3
else:
  count *= 6 
for j in range(n-1):
  if s1[j] == s2[j]:
    if s1[j+1] == s2[j+1]:
      count *= 2
      count %= 1000000007
    else:
      count *= 2
      count %= 1000000007
      j += 1
  else:
    if s1[j+1] == s2[j+1]:
      count *= 1
      count %= 1000000007
    else:
      count *= 3
      count %= 1000000007
      j += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input()
s2 = input()
count = 1
start = -1
end = -1
if s1[0] == s2[0]:
  count *= 3
else:
  count *= 6 
for j in range(n-1):
  if s1[j] == s2[j]:
    if s1[j+1] == s2[j+1]:
      count *= 2 % 1000000007
    else:
      count *= 2 % 1000000007
      j += 1
  else:
    if s1[j+1] == s2[j+1]:
      count *= 1 % 1000000007
    else:
      count *= 3 % 1000000007
      j += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = [[0 for i in range(N)] for j in range(2)]

S[0] = input()
S[1] = input()

x = 2
y = len(S[0])

patterns = 1

tate_flag = False
yoko_flag = False
last_state = ""

skip = False
for i in range(y):
    if skip is True:
        skip = False
        continue
    if S[0][i] == S[1][i]:
        if last_state == "":
            patterns *= 1
        elif last_state == "tate":
            patterns *= 2
        elif last_state == "yoko":
            patterns *= 1
        last_state = "tate"

    else:
        if last_state == "":
            patterns *= 2
        elif last_state == "tate":
            patterns *= 2
        elif last_state == "yoko":
            patterns *= 3
        last_state = "yoko"
        skip = True

print(str(patterns))

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline().strip())
s1 = sys.stdin.readline().strip()
s2 = sys.stdin.readline().strip()


t = 0

i = 0
st = []
while i < len(s1):
    if s1[i] == s2[i]:
        st.append(0)
        i+=1
    else:
        st.append(1)
        i+=2

print(st)

pattern = 3
p = 0
st2 = []
for i, j in enumerate(st):
    if p == 0 and j ==0 and i ==0:
        pass
    elif p == 0 and j == 0:
        pattern *= 2
    elif p == 1 and j == 0:
        pattern *= 1
    elif p == 0 and j == 1:
        pattern *= 2
    elif p==1 and j == 1:
        pattern *= 4
    p = j

print(pattern % 1000000007)

Submission status: Wrong Answer

Solution code:
# Coloring Dominoes
N = int(input())
s1 = input()
s2 = input()

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

Submission status: Wrong Answer

Solution code:
n = input()
st1 = raw_input()
st2 = raw_input()
m = 1
mod = 1000000007
pat = 0 # or 1,2
bl = False
for i in range(n):
  print m
  if pat == 2 and bl:
    bl = False
    continue
  if st1[i] == st2[i] and pat == 0:
    m = m*3%mod
    pat = 1
  elif st1[i] == st2[i] and pat == 1:
    m = m*2%mod
    pat = 1
  elif st1[i] == st2[i] and pat == 2:
    pat = 1
  elif st1[i] != st2[i] and pat == 0:
    m = m*6%mod
    pat = 2
    bl = True
  elif st1[i] != st2[i] and pat == 1:
    m = m*2%mod
    pat = 2
    bl = True
  elif st1[i] != st2[i] and pat == 2:
    m = m*3%mod
    pat = 2
    bl = True
print m

Submission status: Wrong Answer

Solution code:
n = input()
st1 = raw_input()
st2 = raw_input()
m = 1
mod = 1000000007
pat = 0 # or 1,2
bl = False
for i in range(n):
  if pat == 2 and bl:
    bl = False
    continue
  if st1[i] == st2[i] and pat == 0:
    m = m*3/mod
    pat = 1
  elif st1[i] == st2[i] and pat == 1:
    m = m*2/mod
    pat = 1
  elif st1[i] == st2[i] and pat == 2:
    m = m*2/mod
    pat = 1
  elif st1[i] != st2[i] and pat == 0:
    m = m*6/mod
    pat = 2
    bl = True
  elif st1[i] != st2[i] and pat == 1:
    m = m*2/mod
    pat = 2
    bl = True
  elif st1[i] != st2[i] and pat == 2:
    m = m*3/mod
    pat = 2
    bl = True
print m