Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02837 (python)

Fixed submission:
from itertools import product

N = int(input())

li = [[] for i in range(N)]
A = [0]*N
for i in range(N):
    a = int(input())
    A[i]=a
    li[i]=[list(map(int,input().split())) for i in range(a)]

counter = 0
for humen in product([0,1],repeat=N):
    flag = True
    for i in range(N):
        if humen[i]==1:
            for s in range(A[i]):
                if not li[i][s][1]==humen[li[i][s][0]-1]:
                    flag=False
                    break
        
                
    if flag :
        counter = max(counter,humen.count(1))


print(counter)

Buggy submission (verdict: Runtime Error):
A = [0]*N
for i in range(N):
    a = int(input())
    A[i]=a
    li[i]=[list(map(int,input().split())) for i in range(a)]

counter = 0
for humen in product([0,1],repeat=N):
    flag = True
    for i in range(N):
        if humen[i]==1:
            for s in range(A[i]):
                if not li[i][s][1]==humen[li[i][s][0]-1]:
                    flag=False
                    break
        
                
    if flag :
        counter = max(counter,humen.count(1))


print(counter)
Problem p02882 (python)

Fixed submission:
a,b,x = map(int,input().split())

import math 

if x>= a**2*b/2:
    tan = 2*(b/a-x/(a**3))
    y = math.atan(tan)
else :
    tan = a*(b**2)/(2*x)
    y = math.atan(tan)

print(math.degrees(y))

Buggy submission (verdict: Runtime Error):
N = int(input())
import math 

start = int(math.sqrt(N))+1
for i in range(start,0,-1):
    if N%i==0:
        print(i+N//i-2)
        break
Problem p02885 (python)

Fixed submission:
A,B = map(int,input().split())

len_ = A-2*B

if len_<=0:
    print(0)
else:
    print(len_)

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

len_ = A-*B

if len_<=0:
    print(0)
else:
    print(len_)
Problem p02888 (python)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))

L.sort(reverse=True)
counter = 0
import bisect

for index1,c in enumerate(L):
    for index2,b in enumerate(L[index1+1:],start=index1+1):
        left = 0 ; right = N
        oppai = c-b
        while left+1<right:
            mid = (left+right)//2
            if L[mid]>oppai:
                left = mid
            else :
                right=mid
        
        index3 = left
        
        if index3>index2:

            counter += index3-index2
print(counter)

Buggy submission (verdict: Runtime Error):
N = int(input())
import numpy as np
L = np.array(input().split(),np.int16)

L.sort(reverse=True)
counter = 0

for index1,c in enumerate(L):
    index2 = index1+1
    if index2>N-1:
      break
    b = L[index2]
    while b>=c/2:
        
        index3 = index2+1
        if index3>N-1:
            break
        a = L[index3]
        
        while a+b>c:
            counter += 1
            index3+=1
            if index3>N-1:
                break
            a = L[index3]

        index2+=1
        if index2>N-1:
            break
        b = L[index2]


print(counter)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = np.array(input().split(),np.int16)

L.sort(reverse=True)
counter = 0

for index1,c in enumerate(L):
    index2 = index1+1
    if index2>N-1:
      break
    b = L[index2]
    while b>=c/2:
        
        index3 = index2+1
        if index3>N-1:
            break
        a = L[index3]
        
        while a+b>c:
            counter += 1
            index3+=1
            if index3>N-1:
                break
            a = L[index3]

        index2+=1
        if index2>N-1:
            break
        b = L[index2]


print(counter)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = np.array(input().split(),np.int16)

L.sort(reverse=True)
counter = 0

for index1,c in enumerate(L):
    index2 = index1+1
    if index2>N-1:
      break
    b = L[index2]
    while b>=c/2:
        
        index3 = index2+1
        if index3>N-1:
            break
        a = L[index3]
        
        while a+b>c:
            counter += 1
            index3+=1
            if index3>N-1:
                break
            a = L[index3]

        index2+=1
        if index2>N-1:
            break
        b = L[index2]


print(counter)
Problem p03160 (python)

Fixed submission:
N = int(input())
H = list(map(int,input().split()))
import sys
import functools
#indexi番目にいるときの最小コスト
sys.setrecursionlimit(pow(10,6))

@functools.lru_cache(None)
def func(i):
    if i==0:
        return 0
    if i==1:
        return abs(H[0]-H[1])
    return min(func(i-1)+abs(H[i]-H[i-1]),func(i-2)+abs(H[i-2]-H[i]))

print(func(N-1))

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

import functools
#indexi番目にいるときの最小コスト
@functools.lru_cache(None)
def func(i):
    if i==0:
        return 0
    if i==1:
        return abs(H[0]-H[1])
    return min(func(i-1)+abs(H[i]-H[i-1]),func(i-2)+abs(H[i-2]-H[i]))

print(func(N-1))

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

#indexi番目にいるときの最小コスト
def func(i):
    if i==0:
        return 0
    if i==1:
        return abs(H[0]-H[1])
    return min(func(i-1)+abs(H[i]-H[i-1]),func(i-2)+abs(H[i-2]-H[i]))

print(func(N-1))
Problem p02687 (python)

Fixed submission:
p=input()
if p=='ABC':
  print('ARC')
else:
  print('ABC')

Buggy submission (verdict: Runtime Error):
p=input()
if p='ABC':
  print('ARC')
else:
  print('ABC')
Problem p02582 (python)

Fixed submission:
str=input()
maxcnt=0
cnt=0
for i in range(len(str)):
  if(str[i]=="R"):
    cnt+=1
    maxcnt=max(cnt,maxcnt)
  else:
    cnt=0
    
print(maxcnt)

Buggy submission (verdict: Runtime Error):
str=input()
maxcnt=0
cnt=0
for i in range(len(str)):
  if(str[i]=="R"):
    cnt+=1
    maxcnt=max(cnt,max)
  else:
    cnt=0
    
print(max)
Problem p02608 (python)

Fixed submission:
n=int(input())
j=10501
l=[0 for i in range(j)]
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      v=x*x+y*y+z*z+y*x+x*z+z*y
      if(v<j):
        l[v]+=1
for i in range(n):
  print(l[i+1])

Buggy submission (verdict: Runtime Error):
j=10501
l=[0 for i in range(j)]
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      v=x*x+y*y+z*z+y*x+x*z+z*y
      if(v<j):
        l[v]+=1
for i in range(n+1):
  print(l[i+1])

Buggy submission (verdict: Runtime Error):
j=10501
l=[0 for i in range(j)]
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      v=x*x+y*y+z*z+y*x+x*z+z*y
      if(v<j):
        l[v]+=1
for i in range(n+1):
  print(l[i+1]

Buggy submission (verdict: Runtime Error):
j=10201
l=[0 for i in range(x)]
for x in range(101):
  for y in range(101):
    for z in range(101):
      v=x*x+y*y+z*z+y*x+x*z+z*y
      if(v<j):
      	l[v]+=1
for i in range(n+1):
  print(l[i+1]

Buggy submission (verdict: Runtime Error):
n=int(input())
j=10201
l=[0 for i in range(x)]
for x in range(101):
  for y in range(101):
    for z in range(101):
      v=x*x+y*y+z*z+y*x+x*z+z*y
      l[v]+=1
for i in range(n+1):
  print(l[i+1]
Problem p02817 (python)

Fixed submission:
a,b=input().split()

print(b+a)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
print(b+a)
Problem p02646 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
EPS = 1e-6


def yes():
    print("YES")  # type: str


def no():
    print("NO")  # type: str


def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())
    if V-W <= 0:
        no()
        return

    t = abs(A-B)/(V-W)
    if t <= T:
        yes()
    else:
        no()

    return


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
EPS = 1e-6


def yes():
    print("YES")  # type: str


def no():
    print("NO")  # type: str


def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())
    t = abs(A-B)/(V-W)
    if 0 <= t <= T+EPS:
        yes()
    else:
        no()

    return


if __name__ == '__main__':
    main()
Problem p02697 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, M: int):
    # N <= 10**5

    # 差が異なる組み合わせならば、N回を通して同じ組み合わせにはならない。
    # 前に奇数差、後ろに偶数差を作る
    ans = []

    if N % 2 == 0:
        # 差は偶数
        a, b = (0, N//2-1)
        # print(a, b)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
        # 差は奇数
        a, b = (N//2, N-2)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
    if N % 2 == 1:
        # 差は偶数
        a, b = (0, N//2)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
        # 差は奇数
        a, b = (N//2+1, N-1)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
    for i in range(M):
        print(*ans[i], sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, M: int):
    # N <= 10**5

    # 差が異なる組み合わせならば、N回を通して同じ組み合わせにはならない。
    # 前に奇数差、後ろに偶数差を作る
    ans = []

    # Nは偶数
    # 差は偶数
    a, b = (0, N//2)
    while a < b:
        ans.append((a+1, b+1))
        a += 1
        b -= 1
    # 差は奇数
    a, b = (N//2+1, N-1)
    if (b-a) % 2 == 1:
        b -= 1
    while a < b:
        ans.append((a+1, b+1))
        a += 1
        b -= 1
    for i in range(M):
        print(*ans[i], sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()
Problem p02710 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from collections import defaultdict
INF = float("inf")
MOD = 10**9+7


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, f, t, w=1):
        self.E[f].append((t, w))
        self.E[t].append((f, w))


N = int(input())
c = [x-1 for x in map(int, input().split())]
A = [None]*(N-1)
B = [None]*(N-1)
for i in range(N-1):
    A[i], B[i] = map(int, input().split())

g = Graph(N)
for a, b in zip(A, B):
    g.add_edge(a-1, b-1)

# k=1, 2, ..., Nに対して
# 色kが塗られている頂点を一度以上通るような単純パスの数を求める
# 全パスの個数 - 色kが塗られている頂点を一度も通らない単純パスの数
# 全パスの個数はN*(N+1)/2

# グラフを色kのノードで分割して、部分グラフ内での単純パスの総数を求めれば良い
# 各ノードに状態として辞書をもたせる。
# x辞書は色iを通らずに到達可能な頂点の数を持つ。
# o辞書は色iを通らずに到達不可能な頂点の数を持つ。

# 回答用
ans = [0]*N


def f(curr, par=-1):
    # 再帰関数
    # curr: 現在の節点
    # par : 親節点の番号
    ret = defaultdict(int)
    size = 1
    for dest, w in g.E[curr]:
        if dest == par:
            continue
        sz, child = f(dest, curr)
        size += sz

        # 自身の色と同じ場合、子の頂点の数から加算
        n = sz-child[c[curr]]
        ans[c[curr]] += n*(n+1)//2

        # マージ
        if len(ret) < len(child):
            child, ret = ret, child
        for key in child:
            ret[key] += child[key]

    ret[c[curr]] = size
    return size, ret


sz, ret = f(0)
for color in range(N):
    if color != c[0]:
        n = sz-ret[color]
        ans[color] += n*(n+1)//2

tot = N*(N+1)//2
for a in ans:
    print(tot-a)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from collections import defaultdict
INF = float("inf")
MOD = 10**9+7


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, f, t, w=1):
        self.E[f].append((t, w))
        self.E[t].append((f, w))


N = int(input())
c = [x-1 for x in map(int, input().split())]
A = [None]*(N-1)
B = [None]*(N-1)
for i in range(N-1):
    A[i], B[i] = map(int, input().split())

g = Graph(N)
for a, b in zip(A, B):
    g.add_edge(a-1, b-1)

# k=1, 2, ..., Nに対して
# 色kが塗られている頂点を一度以上通るような単純パスの数を求める
# 全パスの個数 - 色kが塗られている頂点を一度も通らない単純パスの数
# 全パスの個数はN*(N+1)/2

# グラフを色kのノードで分割して、部分グラフ内での単純パスの総数を求めれば良い
# 各ノードに状態として辞書をもたせる。
# 辞書は色iを通らずに到達可能な頂点の数を持つ。

# 辞書
reachable = [defaultdict(int) for _ in range(N)]

# 回答用
ans = [0]*N


def f(curr, par=-1):
    # 再帰関数
    # curr: 現在の節点
    # par : 親節点の番号
    for dest, w in g.E[curr]:
        if dest == par:
            continue
        f(dest, curr)

        for color in range(N):
            n = reachable[dest][color]
            if color == c[curr]:
                # 自身の色と同じ場合、子の頂点の数から加算
                ans[color] += n*(n+1)//2
                reachable[curr][color] = 0
            else:
                # 自身の色以外については、子の情報から自分の情報を作る
                reachable[curr][color] += n
    for color in range(N):
        if color != c[curr]:
            reachable[curr][color] += 1
    return


f(0)
for color in range(N):
    if color != c[0]:
        n = reachable[0][color]
        ans[color] += n*(n+1)//2

tot = N*(N+1)//2
for a in ans:
    print(tot-a)
Problem p02761 (python)

Fixed submission:
import sys
INF = float("inf")


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):

    for i in range(1000):
        A = str(i)
        if len(A) != N:
            continue
        flag = True
        for ss, cc in zip(s, c):
            if int(A[ss-1]) != cc:
                flag = False
                break

        if flag == True:
            print(A)
            return
    print(-1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
ddimport sys
INF = float("inf")


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):

    for i in range(1000):
        A = str(i)
        if len(A) != N:
            continue
        flag = True
        for ss, cc in zip(s, c):
            if int(A[ss-1]) != cc:
                flag = False
                break

        if flag == True:
            print(A)
            return
    print(-1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)


if __name__ == '__main__':
    main()
Problem p02814 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
import math
from functools import reduce
import operator
INF = float("inf")


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


def LCM(a, b):
    return a*b//GCD(a, b)


def solve(N: int, M: int, a: "List[int]"):

    # 各aを2で割れる回数(の２べき)
    K = set()
    for i, av in enumerate(a):
        K.add(av & -av)
    if len(K) != 1:
        print(0)
        return

    lcm = a[0]//2
    for av in a:
        lcm = LCM(lcm, av//2)

    ans = int(M/lcm)
    if ans > 0 and ans % 2 == 0:
        ans -= 1
    ans = (ans+1)//2

    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
INF = float("inf")


def GCD(a, b):
    if a == 0:
        return b
    else:
        return GCD(b % a, a)


def LCM(a, b):
    return a*b//GCD(a, b)


def solve(N: int, M: int, a: "List[int]"):

    k = 0
    b = a[0]
    while not b & 1:
        k += 1
        b >>= 1
    b = [aa >> k for aa in a]

    gcd = b[0]
    lcm = b[0]
    for bb in b:
        gcd = GCD(gcd, bb)
        lcm = LCM(lcm, bb)

    if lcm % 2 == 0:
        print(0)
        return
    else:
        print(int((M-lcm)/(2*lcm))+1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)


if __name__ == '__main__':
    main()
Problem p02818 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int, K: int):

    if A <= K:
        a = 0
        b = max(B-(K-A), 0)
    else:
        a = A-K
        b = B
    print(a, b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int, K: int):

    if A <= K:
        a = 0
        b = B-(K-A)
    else:
        a = A-K
    print("{} {}".format(a, b))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)


if __name__ == '__main__':
    main()
Problem p02839 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(H: int, W: int, A: "List[List[int]]", B: "List[List[int]]"):
    base = [[abs(A[h][w]-B[h][w]) for w in range(W)] for h in range(H)]
    mx = (1 << 12800) - 1
    table = [[0]*W for _ in range(H)]
    table[0][0] = (1 << (6400 + base[0][0])) | (1 << (6400-base[0][0]))
    for h in range(H):
        for w in range(W):
            if h > 0:
                table[h][w] |= (table[h-1][w] << base[h][w])
                table[h][w] |= (table[h-1][w] >> base[h][w])
            if w > 0:
                table[h][w] |= (table[h][w-1] << base[h][w])
                table[h][w] |= (table[h][w-1] >> base[h][w])
            table[h][w] &= mx

    m = INF
    for j in range(12800):
        i = (table[H-1][W-1] >> j) & 1
        if i == 1:
            m = min(m, abs(j-6400))
    print(m)
    # print(table[H-1])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [[int(next(tokens)) for _ in range(W)]
         for _ in range(H)]  # type: "List[List[int]]"
    B = [[int(next(tokens)) for _ in range(W)]
         for _ in range(H)]  # type: "List[List[int]]"
    solve(H, W, A, B)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(H: int, W: int, A: "List[List[int]]", B: "List[List[int]]"):
    L = 5000
    base = [[None]*W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            base[h][w] = abs(A[h][w]-B[h][w])

    table = [[[False]*L for _ in range(W)] for _ in range(H)]
    table[0][0][base[0][0]] = True
    for h in range(H):
        for w in range(W):
            if h > 0:
                for i in range(L):
                    if table[h-1][w][i] == True:
                        table[h][w][abs(i-base[h][w])] = True
                        table[h][w][abs(i+base[h][w])] = True
            if w > 0:
                for i in range(L):
                    if table[h][w-1][i] == True:
                        table[h][w][abs(i-base[h][w])] = True
                        table[h][w][abs(i+base[h][w])] = True
    for i in range(L):
        if table[H-1][W-1][i] == True:
            print(i)
            return

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [[int(next(tokens)) for _ in range(W)]
         for _ in range(H)]  # type: "List[List[int]]"
    B = [[int(next(tokens)) for _ in range(W)]
         for _ in range(H)]  # type: "List[List[int]]"
    solve(H, W, A, B)


if __name__ == '__main__':
    main()
Problem p02845 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    RGB = [-1, -1, -1]
    ans = 1
    for a in A:
        count = 0
        for i in range(3):
            if RGB[i] == a-1:
                if count == 0:
                    RGB[i] = a
                count += 1
        if count > 1:
            ans *= count
            ans %= MOD
        elif count == 0:
            ans = 0
            print(ans)
            return
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    RGB = [-1, -1, -1]
    ans = 1
    for a in A:
        mi = None
        count = 0
        for i in range(3):
            if RGB[i] == a-1:
                if mi == None:
                    RGB[mi] = a
                    mi = i
                count += 1
        if count > 1:
            ans *= count
            ans %= MOD
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    RGB = [-1, -1, -1]
    ans = 1
    for a in A:
        mi = None
        count = 0
        for i in range(3):
            if RGB[i] == a-1:
                if mi == None:
                    mi = i
                count += 1
        ans *= count
        ans %= MOD
        RGB[mi] = a
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()