Buggy python submission (verdict: Runtime Error):
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(n):
    k=b[-1].my_index(a[i])
    if k==-1:
        print(0)
        break
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
else:
    x=1
    for i in range(n):
        x=x*b[i].count(a[i])%1000000007
    print(x)


Fixed submission:
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(n):
    k=my_index(b[-1],a[i])
    if k==-1:
        print(0)
        break
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
else:
    x=1
    for i in range(n):
        x=x*b[i].count(a[i])%1000000007
    print(x)

Buggy python submission (verdict: Runtime Error):
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(n):
    k=b[-1].index(a[i])
    if k==-1:
        print(0)
        break
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
else:
    x=1
    for i in range(n):
        x=x*b[i].count(a[i])%1000000007
    print(x)


Fixed submission:
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(n):
    k=my_index(b[-1],a[i])
    if k==-1:
        print(0)
        break
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
else:
    x=1
    for i in range(n):
        x=x*b[i].count(a[i])%1000000007
    print(x)

Buggy python submission (verdict: Runtime Error):
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]
for i in range(n):
    k=b[-1].index(a[i])
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
#print(b)
x=1
for i in range(n):
    an=b[i].count(a[i])
    if an==0:
        break
    x=x*an
    x=x%1000000007

print(x)


Fixed submission:
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(n):
    k=my_index(b[-1],a[i])
    if k==-1:
        print(0)
        break
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
else:
    x=1
    for i in range(n):
        x=x*b[i].count(a[i])%1000000007
    print(x)

Buggy python submission (verdict: Runtime Error):
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]
for i in range(n):
    k=b[-1].index(a[i])
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
#print(b)
x=1
for i in range(n):
    x=x*b[i].count(a[i])%1000000007

print(x)


Fixed submission:
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(n):
    k=my_index(b[-1],a[i])
    if k==-1:
        print(0)
        break
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
else:
    x=1
    for i in range(n):
        x=x*b[i].count(a[i])%1000000007
    print(x)