qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
a = []
b = []
c = []

for _ in range(n):
    x, y, z = [int(e) for e in input().split()]
    a.append(x)
    b.append(y)
    c.append(z)

q, w, r = 0, 0, 0
for i in range(n):
    q, w, r = q + max(b[i], c[i]), w + max(a[i], c[i]), r + max(a[i], b[i])
ans = max(q, w, r)
print(ans)


Fixed code:
n = int(input())
a = []
b = []
c = []

for _ in range(n):
    x, y, z = [int(e) for e in input().split()]
    a.append(x)
    b.append(y)
    c.append(z)

q, w, r = a[0], b[0], c[0]
for i in range(1, n):
    q, w, r = a[i] + max(w, r), b[i] + max(q, r), c[i] + max(q, w)
ans = max(q, w, r)
print(ans)
Buggy code:
def c():
    N = int(input())
    abc = [list(map(int, input().split())) for _ in range(N)]
    dp = [[0] * N for _ in range(3)]
    for i in range(N):
        dp[0][i] = max(dp[1][i - 1] + abc[i][0], dp[2][i - 1] + abc[i][0])
        dp[1][i] = max(dp[0][i - 1] + abc[i][1], dp[2][i - 1] + abc[i][1])
        dp[2][i] = max(dp[0][i - 1] + abc[i][2], dp[1][i - 1] + abc[i][2])
    return max(dp[:][i])


if __name__ == '__main__':
    ans = c()
    print(ans)

Fixed code:
def c():
    N = int(input())
    abc = [list(map(int, input().split())) for _ in range(N)]
    dp = [[0] * N for _ in range(3)]
    dp[0][0], dp[1][0], dp[2][0] = abc[0][0], abc[0][1], abc[0][2]
    i = 0
    for i in range(1, N):
        dp[0][i] = max(dp[1][i - 1] + abc[i][0], dp[2][i - 1] + abc[i][0])
        dp[1][i] = max(dp[0][i - 1] + abc[i][1], dp[2][i - 1] + abc[i][1])
        dp[2][i] = max(dp[0][i - 1] + abc[i][2], dp[1][i - 1] + abc[i][2])
    return max(dp[0][i], dp[1][i], dp[2][i])


if __name__ == '__main__':
    ans = c()
    print(ans)
Buggy code:
N = int(input())

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

dp = [[0]*3 for _ in range(N)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if i != k: 
                dp[i][j] = max(dp[i-1][k] + A[i][j], dp[i][j] )

print(max(dp[N-1]))

Fixed code:
N = int(input())

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

dp = [[0]*3 for _ in range(N)]
for i in range(3):
    dp[0][i] = A[0][i]


for i in range(1, N):
    for j in range(3):
        for k in range(3):
            if j != k: 
                dp[i][k] = max(dp[i-1][j] + A[i][k], dp[i][k])

print(max(dp[-1]))
Buggy code:
import sys
N = int(input())
summer = []
for i in range(N):
    summer.append(list(map(int, sys.stdin.readline().rstrip().split(" "))))
print(summer)

INF = float('inf')
DP = [[-INF for i in range(3)] for i in range(N)]
print(DP)


for i in range(N):
    if i == 0:
        DP[i] = summer[i]
    else:
        DP[i][0] = max(DP[i-1][1], DP[i-1][2]) + summer[i][0]
        DP[i][1] = max(DP[i-1][0], DP[i-1][2]) + summer[i][1]
        DP[i][2] = max(DP[i-1][0], DP[i-1][1]) + summer[i][2]

print(max(DP[N-1]))

Fixed code:
import sys
N = int(input())
summer = []
for i in range(N):
    summer.append(list(map(int, sys.stdin.readline().rstrip().split(" "))))

INF = float('inf')
DP = [[-INF for i in range(3)] for i in range(N)]

for i in range(N):
    if i == 0:
        DP[i] = summer[i]
    else:
        DP[i][0] = max(DP[i-1][1], DP[i-1][2]) + summer[i][0]
        DP[i][1] = max(DP[i-1][0], DP[i-1][2]) + summer[i][1]
        DP[i][2] = max(DP[i-1][0], DP[i-1][1]) + summer[i][2]

print(max(DP[N-1]))
Buggy code:
N = int(input())
a, b, c = [map(int, input().split()) for _ in range(N)]
dp = [0, 0, 0] * N
dp[0] = [a[0], b[0], c[0]]
for i in range(N - 1):
	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))


Fixed code:
N = int(input())
a, b, c = [0] * N, [0] * N, [0] * N
for i in range(N):
	a[i], b[i], c[i] = map(int, input().split())
dp = [[0] * 3 for _ in range(N)]
dp[0] = [a[0], b[0], c[0]]
for i in range(N - 1):
	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))
Buggy code:
n= int(input())
ABC = [[0]*3]*n
for i in range(n):
  ABC[i][0],ABC[i][1],ABC[i][2] = map(int, input().split())

dp = [[0]*3]*n
dp[0] = ABC[0]

for i in range(1,n):
  for j in range(3):
    dp[i][j] = ABC[i][j]+max(dp[i][j-1],dp[i][j-2])
    
print(max(dp[n]))
    
  


Fixed code:
n= int(input())
ABC = [0]*n
for i in range(n):
  ABC[i]= list(map(int, input().split()))

dp = [[0 for i in range(3)] for j in range(n)]
dp[0] = ABC[0]

for i in range(1,n):
  for j in range(3):
    dp[i][j] = ABC[i][j]+max(dp[i-1][j-1],dp[i-1][j-2])
    
print(max(dp[n-1]))
Buggy code:
import sys
input = sys.stdin.readline
N = int(input())
ABC = [list(map(int,input().split())) for i in range(N)]

dp = [0]*(N+1)

for i in range(1,N+1):
    dp[i] = [max([dp[i-1][k]+ABC[i-1][j] for k in range(3) if j != k]) for j in range(3)]

print(max(dp[N]))

Fixed code:
import sys
input = sys.stdin.readline
N = int(input())
ABC = [list(map(int,input().split())) for i in range(N)]

dp = [[0]*3 for i in range(N+1)]

for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][j] = max(dp[i-1][k]+ABC[i-1][j],dp[i][j])

print(max(dp[N]))
Buggy code:
import sys,io
from functools import lru_cache
import numpy
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b,c=[0]*n,[0]*n,[0]*n
for i,line in enumerate(readlines()):
    a[i],b[i],c[i]=mp(line)
dp=[[0,0,0] for i in range(n+1)]
print(dp)
for k in range(1,n+1):
    one=dp[k-1][1]+a[k-1]
    two=dp[k-1][2]+b[k-1]
    zero=dp[k-1][0]+c[k-1]
    dp[k][0]= one if one >= two else two
    dp[k][1]= zero if zero >= two else two
    dp[k][2]= one if one >= zero else zero
print(max(dp[n][0],dp[n][1],dp[n][2]))

Fixed code:
import sys,io
from functools import lru_cache
import numpy
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b,c=[0]*n,[0]*n,[0]*n
for i,line in enumerate(readlines()):
    a[i],b[i],c[i]=mp(line)
dp=[[0,0,0] for i in range(n+1)]
for k in range(1,n+1):
    one=dp[k-1][1]
    two=dp[k-1][2]
    zero=dp[k-1][0]
    dp[k][0]= one if one >= two else two
    dp[k][0]+=a[k-1]
    dp[k][1]= zero if zero >= two else two
    dp[k][1]+=b[k-1]
    dp[k][2]= one if one >= zero else zero
    dp[k][2]+=c[k-1]
#print(dp)
print(max(dp[n][0],dp[n][1],dp[n][2]))
Buggy code:
N = int(input())

matrix = []
for _ in range(N):
    matrix.append(list(map(int, input().split())))
    
dp_matrix = [[0, 0, 0]]

for i in range(N):
    dp_matrix_list = [0, 0, 0]
    for j in range(3):
        for k in range(3):
            if (j != k) and (dp_matrix_list[j] < dp_matrix[i][j] + matrix[i][k]):
                dp_matrix_list[j] = dp_matrix[i][j] + matrix[i][k]
    dp_matrix.append(dp_matrix_list)
    
print(max(dp_matrix[-1]))

Fixed code:
N = int(input())

matrix = []
for _ in range(N):
    matrix.append(list(map(int, input().split())))
    
dp_matrix = [[0, 0, 0]]

for i in range(N):
    dp_matrix_list = [0, 0, 0]
    for j in range(3):
        for k in range(3):
            if (j != k) and (dp_matrix_list[j] < dp_matrix[i][k] + matrix[i][j]):
                dp_matrix_list[j] = dp_matrix[i][k] + matrix[i][j]
    dp_matrix.append(dp_matrix_list)
    
print(max(dp_matrix[-1]))
Buggy code:

n = int(input())
dp = [[0 for _ in range(3)] for _ in range(n+1)]
ls  = [[1,2],[0,2],[0,1]]
for i in range(1,n+1):
    day = list(map(int,input().split()))
    dp[i][0] = day[0] + max(dp[i-1][1],dp[i][2])
    dp[i][1] = day[1] + max(dp[i-1][0],dp[i][2])
    dp[i][2] = day[2] + max(dp[i-1][0],dp[i][1])
print(max(dp[n]))


Fixed code:
n = int(input())
dp = [[0 for _ in range(3)] for _ in range(n+1)]
ls  = [[1,2],[0,2],[0,1]]
for i in range(1,n+1):
    day = list(map(int,input().split()))
    dp[i][0] = day[0] + max(dp[i-1][1],dp[i-1][2])
    dp[i][1] = day[1] + max(dp[i-1][0],dp[i-1][2])
    dp[i][2] = day[2] + max(dp[i-1][0],dp[i-1][1])
print(max(dp[n]))
Buggy code:
N = int(input())
h = []
for i in range(N):
    h.append(list(map(int, input().split(" "))))

cost = h[-1]
today_cost = [0 for i in range(3)]

for day in range(N-2, -1, -1):
    today_cost[0] = h[day][0] + max(cost[1], cost[2])
    today_cost[1] = h[day][1] + max(cost[0], cost[2])
    today_cost[2] = h[day][2] + max(cost[0], cost[1])
    cost = today_cost

print(max(cost))


Fixed code:
N = int(input())
h = []
for i in range(N):
    h.append(list(map(int, input().split(" "))))

cost = h[-1]

for day in range(N-2, -1, -1):
    today_cost = [0 for i in range(3)]
    today_cost[0] = h[day][0] + max(cost[1], cost[2])
    today_cost[1] = h[day][1] + max(cost[0], cost[2])
    today_cost[2] = h[day][2] + max(cost[0], cost[1])
    cost = today_cost

print(max(cost))
Buggy code:
a = int(input())

b = []
m = 0
for i in range(a):
	b.append(list(map(int,input().split())))

c = [[0,0,0] in i for range(a+1)]

for i in range(a):
	for j in range(3):
		for k in range(3):
			if j == k:
				continue
			else:
				c[i+1][k] = max(c[i+1][k],c[i][k] + b[i][j])

print(max(c[-1]))

Fixed code:
a = int(input())

b = []
m = 0
for i in range(a):
	b.append(list(map(int,input().split())))

c = [[0,0,0] for i in range(a+1)]

for i in range(a):
	for j in range(3):
		for k in range(3):
			if j == k:
				continue
			else:
				c[i+1][k] = max(c[i+1][k],c[i][j] + b[i][k])

print(max(c[-1]))
Buggy code:
import sys
sys.setrecursionlimit(int(1e6))

n=int(input())
l=[[0,0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    z[i][j]=1
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
s1=dp(n,0)
s2=dp(n,1)
s3=dp(n,2)
print(max(s1,s2,s3))

Fixed code:
import sys
sys.setrecursionlimit(int(1e6))

n=int(input())
l=[[0,0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
print(max(dp(n,0),dp(n,1),dp(n,2)))
Buggy code:
def solve(a):
    dp = [[0]*3 for _ in range(len(a)+1)]
    for i in range(len(a)):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i+1][j] = max(dp[i+1][j], a[i][j] + dp[i][k])
    return max(dp[-1])
  
n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
print(solve(a))

Fixed code:
def solve(a):
    dp = [[0]*3 for _ in range(len(a)+1)]
    for i in range(len(a)):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i+1][j] = max(dp[i+1][j], a[i][j] + dp[i][k])
    return max(dp[-1])
  
n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
print(solve(a))
Buggy code:
n = int(input())
a = []
b = []
c = []
for i in range(n):
    m,v,p = map(int,input().split())
    a.append(m)
    b.append(v)
    c.append(p)
d = [[0]*3 for i in range(n)]
d[0][0]=a[0]
d[0][1]=b[0]
d[0][2]=c[0]
for i in range(n):
    for j in range(3):
        if j == 0:
            d[i][j] = max(d[i-1][1],d[i-1][2]) + a[i]
        elif j == 1:
            d[i][j] = max(d[i-1][0],d[i-1][2]) + b[i]
        else:
            d[i][j] = max(d[i-1][0],d[i-1][1]) + c[i]
print(max(d[-1][0],d[-1][1],d[-1][2]))


Fixed code:
n = int(input())
a = []
b = []
c = []
for i in range(n):
    m,v,p = map(int,input().split())
    a.append(m)
    b.append(v)
    c.append(p)
d = [[0]*3 for i in range(n)]
d[0][0]=a[0]
d[0][1]=b[0]
d[0][2]=c[0]
for i in range(1,n):
    for j in range(3):
        if j == 0:
            d[i][j] = max(d[i-1][1],d[i-1][2]) + a[i]
        elif j == 1:
            d[i][j] = max(d[i-1][0],d[i-1][2]) + b[i]
        else:
            d[i][j] = max(d[i-1][0],d[i-1][1]) + c[i]
print(max(d[-1][0],d[-1][1],d[-1][2]))
Buggy code:
N=int(input())
sys.setrecursionlimit(1000000000)

ABC=[]
for _ in range(N):
    ABC.append(list(map(int,input().split())))
from functools import lru_cache
@lru_cache(maxsize=None)
def dynam(n):
    if n>1:
        a=max(dynam(n-1)[1]+ABC[n-1][0],
              dynam(n-1)[2]+ABC[n-1][0])
        b=max(dynam(n-1)[0]+ABC[n-1][1],
              dynam(n-1)[2]+ABC[n-1][1])
        c=max(dynam(n-1)[0]+ABC[n-1][2],
              dynam(n-1)[1]+ABC[n-1][2])
        return (a,b,c)
    return tuple(ABC[0])
print(max(dynam(N)))

Fixed code:
import sys
sys.setrecursionlimit(1000000000)
N=int(input())
ABC=[]
for _ in range(N):
    ABC.append(list(map(int,input().split())))
from functools import lru_cache
@lru_cache(maxsize=None)
def dynam(n):
    if n>1:
        a=max(dynam(n-1)[1]+ABC[n-1][0],
              dynam(n-1)[2]+ABC[n-1][0])
        b=max(dynam(n-1)[0]+ABC[n-1][1],
              dynam(n-1)[2]+ABC[n-1][1])
        c=max(dynam(n-1)[0]+ABC[n-1][2],
              dynam(n-1)[1]+ABC[n-1][2])
        return (a,b,c)
    return tuple(ABC[0])
print(max(dynam(N)))
Buggy code:
n = int(input())
abc = []
for i in range(n):
    abc.append([int(i) for i in input().split()])

dp = [[0,0,0] for i in range(n)]

for i in range(n):
    if i != 0:
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i][j] = max(dp[i][j],dp[i-1][k] + abc[i][j])
    else:
        for j in range(3):
            dp[i][j] = abc[i][j]
print(max(dp[n-1]))
print(dp)


Fixed code:
n = int(input())
abc = []
for i in range(n):
    abc.append([int(i) for i in input().split()])

dp = [[0,0,0] for i in range(n)]

for i in range(n):
    if i != 0:
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i][j] = max(dp[i][j],dp[i-1][k] + abc[i][j])
    else:
        for j in range(3):
            dp[i][j] = abc[i][j]
print(max(dp[n-1]))
#print(dp)
Buggy code:
N = int(input())

#dp = [[0] * 3 for _ in range(N)]
dp = [[0]*3]*N

arr = [list(map(int, input().split())) for _ in range(N)]

dp[0][0]=arr[0][0]
dp[0][1]=arr[0][1]
dp[0][2]=arr[0][2]


for i in range(1,N,1):
    dp[i][0] = max(arr[i][0]+dp[i-1][1],arr[i][0]+dp[i-1][2])
    dp[i][1] = max(arr[i][1]+dp[i-1][0],arr[i][1]+dp[i-1][2])
    dp[i][2] = max(arr[i][2]+dp[i-1][0],arr[i][2]+dp[i-1][1])

print(max(dp[-1][0],dp[-1][1],dp[-1][2]))

Fixed code:
N = int(input())

dp = [[0] * 3 for _ in range(N)]
#dp = [[0]*3]*N

arr = [list(map(int, input().split())) for _ in range(N)]

dp[0][0]=arr[0][0]
dp[0][1]=arr[0][1]
dp[0][2]=arr[0][2]


for i in range(1,N,1):
    dp[i][0] = max(arr[i][0]+dp[i-1][1],arr[i][0]+dp[i-1][2])
    dp[i][1] = max(arr[i][1]+dp[i-1][0],arr[i][1]+dp[i-1][2])
    dp[i][2] = max(arr[i][2]+dp[i-1][0],arr[i][2]+dp[i-1][1])

print(max(dp[-1][0],dp[-1][1],dp[-1][2]))
Buggy code:
n = int(input())
l = []
dp = [[0]*3 for i in range(n)]
for i in range(n):
	l.append(list(map(int,input().split())))
dp[0] = l[0]
for i in range(1,n):
	for j in range(1,3):
		if j%3 == 0:
			dp[i][j] = max(dp[i-1][j+1]+l[i][j],dp[i-1][j+2]+l[i][j])
		if j%3 == 1:
			dp[i][j] = max(dp[i-1][j-1]+l[i][j],dp[i-1][j+1]+l[i][j])
		if j%3 == 2:
			dp[i][j] = max(dp[i-1][j-2]+l[i][j],dp[i-1][j-1]+l[i][j])
print(max(dp[-1]))

Fixed code:
n = int(input())
l = []
dp = [[0]*3 for i in range(n)]
for i in range(n):
	l.append(list(map(int,input().split())))
dp[0] = l[0]
for i in range(1,n):
	for j in range(3):
		if j == 0:
			dp[i][j] = max(dp[i-1][j+1]+l[i][j],dp[i-1][j+2]+l[i][j])
		if j == 1:
			dp[i][j] = max(dp[i-1][j-1]+l[i][j],dp[i-1][j+1]+l[i][j])
		if j == 2:
			dp[i][j] = max(dp[i-1][j-2]+l[i][j],dp[i-1][j-1]+l[i][j])

print(max(dp[-1]))
Buggy code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[None]*3 for _ in range(n)]
dp[0] = abc[0]
K = [[1, 2], [0, 2], [0, 1]]
for i in range(1, n):
    abci = abc[i]
    for j in range(3):
        for k in K[j]:
            dp[i][j] = max(dp[i-1][k[0]]+abci[j], dp[i-1][k[1]]+abci[j])
print(max(dp[-1]))

Fixed code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[None]*3 for _ in range(n)]
dp[0] = abc[0]
m = [[0, [1, 2]], [1, [0, 2]], [2, [0, 1]]]
for i in range(1, n):
    abci = abc[i]
    for j, k in m:
        dp[i][j] = max(dp[i-1][k[0]]+abci[j], dp[i-1][k[1]]+abci[j])
print(max(dp[-1]))
Buggy code:
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

dp = [[0,0,0] for _ in range(n)]
dp[0][0], dp[0][1], dp[0][2] = l[0][0], l[0][1], l[0][2]

for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][k] = max(dp[i][k], dp[i-1][j] + l[i][k])
print(dp)

Fixed code:
N = int(input())
l = [list(map(int, input().split())) for _ in range(N)]

dp = [[0 for i in range(3)] for j in range(N+1)]


for i in range(1, N+1):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i-1][k]+l[i-1][k])

print(max(dp[N][0], dp[N][1], dp[N][2]))
Buggy code:
n= int(input())
dp =[0]*3
for i in range(n):
    ndp=[0]*3
    c =list(map(int,input().split()))
    for j in range(n):
        for k in range(n):
            if i !=j:
                ndp[k] = max(ndp[k],dp[j]+c[k])
    dp = ndp
print(max(dp))
        

Fixed code:
n= int(input())
dp =[0]*3
for i in range(n):
    ndp=[0]*3
    c =list(map(int,input().split()))
    for j in range(3):
        for k in range(3):
            #print(j,k)
            if j !=k:
                ndp[k] = max(ndp[k],dp[j]+c[k])
                
    dp = ndp
    
print(max(dp))
Buggy code:
n = int(input())
a,b,c = 0,0,0
for _ in range(n):
    x, y, z = map(int, input().split())
    a,b,c = max(y,z)+a,max(x,z)+b,max(x,y)+c

print(max(a,b,c))



Fixed code:
n = int(input())
a,b,c = 0,0,0
for _ in range(n):
    x, y, z = map(int, input().split())
    a,b,c = max(c,b)+x,max(a,c)+y,max(a,b)+z

print(max(a,b,c))
Buggy code:
N = int(input())
ABC = [list(map(int,input().split())) for _ in range(N)]
hap = [[0,0,0] for _ in range(N)]
hap[0] = ABC[0]
for j in range(1,N):
  for i1,i2,i3 in [[0,1,2],[1,2,0],[2,0,1]]:
    hap[j][i1] = max(hap[j-1][i2]+ABC[j][i2], hap[j-1][i3]+ABC[j][i3])
print(max(hap[-1][:]))

Fixed code:
N = int(input())
ABC = [list(map(int,input().split())) for _ in range(N)]
hap = [[0,0,0] for _ in range(N)]
hap[0] = ABC[0]
for j in range(1,N):
  for i1,i2,i3 in [[0,1,2],[1,2,0],[2,0,1]]:
    hap[j][i2] = max(hap[j][i2], hap[j-1][i1]+ABC[j][i2])
    hap[j][i3] = max(hap[j][i3], hap[j-1][i1]+ABC[j][i3])
print(max(hap[-1][:]))
Buggy code:
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]
NOW = [0]*3
NEXT = [None]*3
for i in range(N) :
    NEXT[0] = max(NOW[1],NOW[2]) + L[0]
    NEXT[1] = max(NOW[2],NOW[0]) + L[1]
    NEXT[2] = max(NOW[0],NOW[1]) + L[2]    
    NOW = NEXT.copy()
print(max(NOW))


Fixed code:
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]
NOW = [0,0,0]
NEXT = [None,None,None]

for i in range(N) :
    NEXT[0] = max(NOW[1],NOW[2]) + L[i][0]
    NEXT[1] = max(NOW[2],NOW[0]) + L[i][1]
    NEXT[2] = max(NOW[0],NOW[1]) + L[i][2]
    
    NOW = NEXT.copy()
print(max(NOW))
Buggy code:
N = int(input())
L = [[map(int,input().split())] for i in range(N)]

dp = [[0,0,0] for i in range(N+1)]
for i in range(N) :
    for j in range(3) :
        for k in range(3) :
            if j == k :
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + L[i][k])
print(ax(dp[-1]))



Fixed code:
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]

dp = [[0,0,0] for i in range(N+1)]
for i in range(N) :
    for j in range(3) :
        for k in range(3) :
            if j == k :
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + L[i][k])
print(max(dp[-1]))
Buggy code:
def main():
    n = int(input())
    x = []
    for _ in range(n):
        a, b, c = map(int, input().split())
        x.append((a, b, c))
    dp0 = [0]*(n+1)
    dp1 = [0]*(n+1)
    dp2 = [0]*(n+1)
    for i in range(1,n+1):
        a, b, c = x[0]
        dp0[i] = max(dp1[i-1]+a, dp2[i-1]+a)
        dp1[i] = max(dp0[i-1]+b, dp2[i-1]+b)
        dp2[i] = max(dp0[i-1]+c, dp1[i-1]+c)
    print(max(dp0[n], dp1[n], dp2[n]))

if __name__ == "__main__":
    main()

Fixed code:
def main():
    n = int(input())
    x = []
    for _ in range(n):
        a, b, c = map(int, input().split())
        x.append((a, b, c))
    dp0 = [0]*(n+1)
    dp1 = [0]*(n+1)
    dp2 = [0]*(n+1)
    for i in range(1,n+1):
        a, b, c = x[i-1]
        dp0[i] = max(dp1[i-1]+a, dp2[i-1]+a)
        dp1[i] = max(dp0[i-1]+b, dp2[i-1]+b)
        dp2[i] = max(dp0[i-1]+c, dp1[i-1]+c)
    print(max(dp0[n], dp1[n], dp2[n]))

if __name__ == "__main__":
    main()
Buggy code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    abc = in_nl2(N)

    dp = [[0 for _ in range(N)] for _ in range(3)]

    dp[0][0] = abc[0][0]
    dp[1][0] = abc[0][1]
    dp[2][0] = abc[0][2]

    for i in range(N - 1):
        a, b, c = abc[i + 1]
        dp[0][i + 1] = max(dp[0][i + 1], dp[0][i] + b, dp[0][i] + c)
        dp[1][i + 1] = max(dp[1][i + 1], dp[1][i] + a, dp[1][i] + c)
        dp[2][i + 1] = max(dp[2][i + 1], dp[2][i] + a, dp[2][i] + b)

    print(max(dp[0][-1], dp[1][-1], dp[2][-1]))


if __name__ == '__main__':
    main()


Fixed code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    abc = in_nl2(N)

    dp = [[0 for _ in range(N)] for _ in range(3)]

    a, b, c = abc[0]
    dp[0][0] = a
    dp[1][0] = b
    dp[2][0] = c

    for i in range(N - 1):
        a, b, c = abc[i + 1]
        dp[0][i + 1] = max(dp[1][i] + a, dp[2][i] + a)
        dp[1][i + 1] = max(dp[0][i] + b, dp[2][i] + b)
        dp[2][i + 1] = max(dp[0][i] + c, dp[1][i] + c)

    print(max(dp[0][-1], dp[1][-1], dp[2][-1]))


if __name__ == '__main__':
    main()
Buggy code:
n=int(input())
a,b,c=[0]*n,[0]*n,[0]*n
for i in range(n):
  a[i],b[i],c[i]=map(int,input().split())
dp=[[0]*3 for _ in range(n)]
dp[0]=[a[0],b[0],c[0]]
for i in range(n-1):
  for j in range(3):
    dp[i+1][j]=max(dp[i+1][j],dp[i+1][(j+1)%3],dp[i+1][(j+2)%3])
print(max(dp[n-1]))

Fixed code:
n=int(input())
dp=[[0]*3 for _ in range(n)]
dp[0]=list(map(int,input().split()))
for i in range(1,n):
    a,b,c=map(int,input().split())
    dp[i][0]=a+max(dp[i-1][1],dp[i-1][2])
    dp[i][1]=b+max(dp[i-1][0],dp[i-1][2])
    dp[i][2]=c+max(dp[i-1][0],dp[i-1][1])
print(max(dp[n-1]))