Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

c = [-1, -1 ,-1]

sum = 1
tmp = 0
for a in A:
    sum = sum * c.count(A-1) % 1000000007
    if A-1 == c[0]:
        c[0] += 1
        tmp = c.count(c[0] - 1) + 1
    elif A-1 == c[1]:
        c[1] += 1
        tmp = c.count(c[1]-1) + 1
    elif A-1 == c[2]:
        c[2] += 1
        tmp = c.count(c[2] - 1) + 1
print(sum)


Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
 
for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1
 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

c = [0, 0, 0]

sum = 1
# print(c)
for a in A:
    # print(a)
    if a == c[0]:
        c[0] += 1
        tmp = c.count(c[0] - 1) + 1
    elif a == c[1]:
        c[1] += 1
        tmp = c.count(c[1]-1) + 1
    elif a == c[2]:
        c[2] += 1
        tmp = c.count(c[2] - 1) + 1
    # print(tmp)
    sum = sum * tmp % 1000000007
    # print(c)
print(sum)


Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
 
for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1
 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
# A = list(map(int, input().split()))
A = input().split()

# print(A)
c = [0, 0, 0]
# r = 0
# b = 0
# g = 0
sum = 1
# print(c)
for a in A:
    a = int(a)
    # print(a)
    if a == c[0]:
        c[0] += 1
        tmp = c.count(c[0] - 1) + 1
    elif a == c[1]:
        c[1] += 1
        tmp = c.count(c[1]-1) + 1
    elif a == c[2]:
        c[2] += 1
        tmp = c.count(c[2] - 1) + 1
    # print(tmp)
    sum *= tmp
    # print(c)
print(sum % 1000000007)


Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
 
for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1
 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
# A = list(map(int, input().split()))
A = input().split()

# print(A)
c = [0, 0, 0]
# r = 0
# b = 0
# g = 0
sum = 1
# print(c)
for a in A:
    a = int(a)
    # print(a)
    if a == c[0]:
        c[0] += 1
        tmp = c.count(c[0] - 1) + 1
    elif a == c[1]:
        c[1] += 1
        tmp = c.count(c[1]-1) + 1
    elif a == c[2]:
        c[2] += 1
        tmp = c.count(c[2] - 1) + 1
    # print(tmp)
    sum *= tmp
    # print(c)
print(sum % 1000000007)


Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
 
for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1
 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

# print(A)
c = [0, 0, 0]
# r = 0
# b = 0
# g = 0
sum = 1
# print(c)
for a in A:
    # print(a)
    if a == c[0]:
        c[0] += 1
        tmp = c.count(c[0] - 1) + 1
    elif a == c[1]:
        c[1] += 1
        tmp = c.count(c[1]-1) + 1
    elif a == c[2]:
        c[2] += 1
        tmp = c.count(c[2] - 1) + 1
    # print(tmp)
    sum *= tmp
    # print(c)
print(sum % 1000000007)


Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
 
for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1
 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

# print(A)
c = [0, 0, 0]
# r = 0
# b = 0
# g = 0
sum = 1
# print(c)
for a in A:
    # print(a)
    if a == c[0]:
        c[0] += 1
        tmp = c.count(c[0] - 1) + 1
    elif a == c[1]:
        c[1] += 1
        tmp = c.count(c[1]-1) + 1
    elif a == c[2]:
        c[2] += 1
        tmp = c.count(c[2] - 1) + 1
    # print(tmp)
    sum *= tmp
    # print(c)
print(sum)

Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
 
for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1
 
print(ans)