qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

dp = [[-1]*3 for i in range(N)]
import sys
sys.setrecursionlimit(10**10)
def dfs(i,j):
    if i == N:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j==0:
            dp[i][j] = max(dfs(i+1,1)+abc[i][1], dfs(i+1,2)+abc[i][2])
        elif j==1:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,2)+abc[i][2])
        else:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,1)+abc[i][1])
        return dp[i][j]
print(max(dfs(0,0), dfs(0,1), dfs(0,2)))


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

dp = [[-1]*3 for i in range(N)]
import sys
sys.setrecursionlimit(10**9)
def dfs(i,j):
    if i == N:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j==0:
            dp[i][j] = max(dfs(i+1,1)+abc[i][1], dfs(i+1,2)+abc[i][2])
        elif j==1:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,2)+abc[i][2])
        else:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,1)+abc[i][1])
        return dp[i][j]
print(max(dfs(0,0), dfs(0,1), dfs(0,2)))
Buggy code:
N=int(input())

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

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


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


Fixed code:
N=int(input())

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

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


for i in range(N):
    a,b,c=nums[i]
    dp[i][0]=max(dp[i-1][1]+a,dp[i-1][2]+a)
    dp[i][1]=max(dp[i-1][0]+b,dp[i-1][2]+b)
    dp[i][2]=max(dp[i-1][0]+c,dp[i-1][1]+c)
num = max(dp[-1])
if N==1:
    num = max(nums[0])
print(num)
Buggy code:
n = int(input())

aa = 0
bb = 0
cc = 0 

for i in range(n):
    a,b,c = map(int,input().split())
    aa,bb,cc = max(bb + a, cc + a),max(aa + b, cc + b),max(aa + c, bb + c)

    print(aa,bb,cc)
print(max(aa,bb,cc))

Fixed code:
n = int(input())

aa = 0
bb = 0
cc = 0 

for i in range(n):
    a,b,c = map(int,input().split())
    aa,bb,cc = max(bb + a, cc + a),max(aa + b, cc + b),max(aa + c, bb + c)

print(max(aa,bb,cc))
Buggy code:
import numpy as np

N = int(input())
a = np.zeros((N,3))
for i in range(N):
    a[i][0],a[i][1],a[i][2] = map(int,input().split())

memo = np.zeros((N,3))

memo[0][0], memo[0][1], memo[0][2] = a[0][0],a[0][1],a[0][2]
day = 1

while (day < N):
    memo[day] = [max(memo[day-1][(x+1)%3],memo[day-1][(x+2)%3]) + a[day][x] \
                   for x in [0,1,2]]
    day += 1

print(max(memo[day - 1]))

Fixed code:
import numpy as np

N = int(input())
a = np.zeros((N,3))
for i in range(N):
    a[i][0],a[i][1],a[i][2] = map(int,input().split())

memo = np.zeros((N,3))

memo[0][0], memo[0][1], memo[0][2] = a[0][0],a[0][1],a[0][2]
day = 1

while (day < N):
    memo[day] = [max(memo[day-1][(x+1)%3],memo[day-1][(x+2)%3]) + a[day][x] \
                   for x in [0,1,2]]
    day += 1

print(int(max(memo[day - 1])))
Buggy code:
N = int(input())
days = [list(map(int, input().split())) for i in range(N)]
scores = [[0,0,0] for i in range(N)]
scores[0] = days[0]

for i in range(N-1):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            newscore = days[i+1][j] + scores[i][k]
            if newscore > scores[i+1][j]:
                scores[i+1][j] = newscore

print(max([score[-1] for score in scores]))

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

for i in range(N-1):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            newscore = days[i+1][j] + scores[i][k]
            if newscore > scores[i+1][j]:
                scores[i+1][j] = newscore

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





    

Fixed code:
n=int(input())
li1=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*3 for _ in range(n+1)]
for i in range(n):
    dp[i+1][1]=max(dp[i+1][1],dp[i][0]+li1[i][1])
    dp[i+1][2]=max(dp[i+1][2],dp[i][0]+li1[i][2])
    dp[i+1][2]=max(dp[i+1][2],dp[i][1]+li1[i][2])
    dp[i+1][0]=max(dp[i+1][0],dp[i][1]+li1[i][0])
    dp[i+1][0]=max(dp[i+1][0],dp[i][2]+li1[i][0])
    dp[i+1][1]=max(dp[i+1][1],dp[i][2]+li1[i][1])
print(max(dp[-1][0],dp[-1][1],dp[-1][2]))
Buggy code:
import sys
input = sys.stdin.readline()
N = int(input())
abc = [[0,0,0]]+[list(map(int,input().split())) for _ in range(N)]
dp = [[0,0,0] for _ 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
            #print('i={},j={},k={}'.format(i,j,k))
            #print(dp[i][j],abc[i][j],abc[i-1][k])
            dp[i][j] = max(dp[i][j],abc[i][j]+dp[i-1][k])
print(max(dp[-1]))

Fixed code:
import sys
input = sys.stdin.readline
N = int(input())
abc = [[0,0,0]]+[list(map(int,input().split())) for _ in range(N)]
dp = [[0,0,0] for _ 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
            #print('i={},j={},k={}'.format(i,j,k))
            #print(dp[i][j],abc[i][j],abc[i-1][k])
            dp[i][j] = max(dp[i][j],abc[i][j]+dp[i-1][k])
print(max(dp[-1]))
Buggy code:
import math
import numpy as np


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    act = []
    for i in range(N):
        act.append(inputIntList())
    act.append([0, 0, 0])
    dp = [[0 for _ in range(3)] for _ in range(N + 1)]
    dp[0] = act[0]
    for i in range(N):
        for j in range(3):
            dp[i + 1][j] = dp[i][j] + max(act[i + 1][j - 1], act[i + 1][j - 2])
            # print(dp)

    return max(dp[-1])


if __name__ == "__main__":
    print(main())


Fixed code:
import math
import numpy as np


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    act = [inputIntList() for _ in range(N)]
    act.append([0, 0, 0])
    dp = [[0 for _ in range(3)] for _ in range(N + 1)]
    dp[0] = act[0]
    for i in range(1, N + 1):
        for j in range(3):
            dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + act[i][j]
            # print(dp)

    return max(dp[-1])


if __name__ == "__main__":
    print(main())
Buggy code:
import sys
input = sys.stdin.readline

n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

dpa = a[0]+[0]*(n-1)
dpb = b[0]+[0]*(n-1)
dpc = c[0]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max( dpb[i-1]+a[i], dpc[i-1]+a[i])
    dpb[i] = max( dpc[i-1]+b[i], dpa[i-1]+b[i])
    dpa[i] = max( dpa[i-1]+c[i], dpb[i-1]+c[i])

print(max(dpa[-1], dpb[-1], dpc[-1]))

Fixed code:
import sys
input = sys.stdin.readline
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int,input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max(dpb[i-1],dpc[i-1]) + a[i]
    dpb[i] = max(dpc[i-1],dpa[i-1]) + b[i]
    dpc[i] = max(dpa[i-1],dpb[i-1]) + c[i]
print(max(dpa[-1],dpb[-1],dpc[-1]))
Buggy code:
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max( dpb[i-1]+a[i], dpc[i-1]+a[i])
    dpb[i] = max( dpc[i-1]+b[i], dpa[i-1]+b[i])
    dpa[i] = max( dpa[i-1]+c[i], dpb[i-1]+c[i])

print(max(dpa[-1], dpb[-1], dpc[-1]))

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

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max(dpb[i-1]+a[i],dpc[i-1]+a[i])
    dpb[i] = max(dpc[i-1]+b[i],dpa[i-1]+b[i])
    dpc[i] = max(dpa[i-1]+c[i],dpb[i-1]+c[i])

print(max(dpa[-1], dpb[-1], dpc[-1]))
Buggy code:
n=int(input())
a=[0]*(n-1)
b=[0]*(n-1)
c=[0]*(n-1)
for _ in range(n-1):
    a,b,c=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]+a[i+1], dp[i][2]＋a[i＋1])
    dp[i+1][1]=max(dp[i][0]+b[i+1], dp[i][2]＋b[i＋1])
    dp[i+1][2]=max(dp[i][0]+c[i+1], dp[i][1]＋c[i＋1])
print(max(dp[n-1]))

Fixed code:
n = int(input())
dp = [[0, 0, 0] for _ in range(n)]
dp[0][0], dp[0][1], dp[0][2] = map(int, input().split())

for i in range(n-1):
    a, b, c = map(int, input().split())
    dp[i+1][0] = max(dp[i+1][0], dp[i][1]+a)
    dp[i+1][0] = max(dp[i+1][0], dp[i][2]+a)
    dp[i+1][1] = max(dp[i+1][1], dp[i][0]+b)
    dp[i+1][1] = max(dp[i+1][1], dp[i][2]+b)
    dp[i+1][2] = max(dp[i+1][2], dp[i][0]+c)
    dp[i+1][2] = max(dp[i+1][2], dp[i][1]+c)

print(max(dp[n-1]))
Buggy code:
N = int(input())
lis = [list(map(int, input().split())) for i in range(N)]

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

for idx, val in enumerate(lis[1:], start=1):
	a = val[0] + max([dp[idx-1][i] for i in range(3) if 0 != i ])
	b = val[1] + max([dp[idx-1][i] for i in range(3) if 1 != i ])
	c = val[2] + max([dp[idx-1][i] for i in range(3) if 2 != i ])
	dp[idx] = [a,b,c]
print(max(dp[-1][0]))

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

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

for idx, val in enumerate(lis[1:], start=1):
	a = val[0] + max([dp[idx-1][i] for i in range(3) if 0 != i ])
	b = val[1] + max([dp[idx-1][i] for i in range(3) if 1 != i ])
	c = val[2] + max([dp[idx-1][i] for i in range(3) if 2 != i ])
	dp[idx] = [a,b,c]
print(max(dp[-1]))
Buggy code:
import sys
sys.setrecursionlimit(10**5 + 9)
from collections import defaultdict
dp=defaultdict(lambda:0)
n=int(input())
ar,br,cr=[0]*n,[0]*n,[0]*n
for i in range(n):
	ar[i],br[i],cr[i]=map(int,input().split())
def points(i,pv):
	if dp[(i,pv)] != 0:
		return dp[(i,pv)]
	if pv==1:
		x,y=br[i],cr[i]
		a,b=2,3
	elif pv==2:
		x,y=ar[i],cr[i]
		a,b=1,3
	else:
		x,y=ar[i],br[i]
		a,b=1,2
	if i==n-1:
		return max(x,y)
	ax=points(i+1,a)+x
	by=points(i+1,b)+y
	ans=max(by,ax)
	dp[(i,pv)]=ans
	return ans
p=points(1,1)+ar[0]
q=points(1,2)+br[0]
r=points(1,3)+cr[0]
print(max(p,q,r))

	
		



Fixed code:
import sys
sys.setrecursionlimit(10**5 + 9)
from collections import defaultdict
dp=defaultdict(lambda:0)
n=int(input())
ar,br,cr=[0]*n,[0]*n,[0]*n

for i in range(n):
	ar[i],br[i],cr[i]=map(int,input().split())
if n==1:
	print(max(ar[0],br[0],cr[0]))
	exit()
def points(i,pv):
	if dp[(i,pv)] != 0:
		return dp[(i,pv)]
	if pv==1:
		x,y=br[i],cr[i]
		a,b=2,3
	elif pv==2:
		x,y=ar[i],cr[i]
		a,b=1,3
	else:
		x,y=ar[i],br[i]
		a,b=1,2
	if i==n-1:
		return max(x,y)
	ax=points(i+1,a)+x
	by=points(i+1,b)+y
	ans=max(by,ax)
	dp[(i,pv)]=ans
	return ans
p=points(1,1)+ar[0]
q=points(1,2)+br[0]
r=points(1,3)+cr[0]
print(max(p,q,r))
Buggy code:
N = int(input())
A = []
B = []
C = []
for i in range(N):
    tmp_a,tmp_b,tmp_c = map(int,input().split())
    A.append(tmp_a)
    B.append(tmp_b)
    C.append(tmp_c)

dp = [[0 for j in range(3)] for i in range(N)]
dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

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


Fixed code:
N = int(input())
A = []
B = []
C = []
for i in range(N):
    tmp_a,tmp_b,tmp_c = map(int,input().split())
    A.append(tmp_a)
    B.append(tmp_b)
    C.append(tmp_c)

dp = [[0 for j in range(3)] for i in range(N)]
dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

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

    

print(max(dp[-1][0],dp[-1][1],dp[-1][2]))
Buggy code:
# C Vacation
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

#print(N,A)

dp = [[0] * 3 for _ in range(N)]
dp[0][0] = A[0][0]
dp[0][1] = A[0][1]
dp[0][2] = A[0][2]
#print(dp)

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

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

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

#print(N,A)

dp = [[0] * 3 for _ in range(N)]
dp[0][0] = A[0][0]
dp[0][1] = A[0][1]
dp[0][2] = A[0][2]
#print(dp)

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

print(max(dp[N-1]))
Buggy code:
n = int(input())
u = [[0,0,0]]
for i in range(n):
    u.append(list(map(int,input().split())))

dp = [[0,0,0],u[0]]
for i in range(2,n+1):
    dp.append([0,0,0])
for i in range(2,n+1):
    dp[i][0]=max(dp[i-1][1]+u[i][0],dp[i-1][2]+u[i][0])
    dp[i][1]=max(dp[i-1][2]+u[i][1],dp[i-1][0]+u[i][1])
    dp[i][2]=max(dp[i-1][0]+u[i][2],dp[i-1][1]+u[i][2])

print(max(dp[n]))

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

dp = [[0,0,0],u[1]]
for i in range(2,n+1):
    dp.append([0,0,0])
for i in range(2,n+1):
    dp[i][0]=max(dp[i-1][1]+u[i][0],dp[i-1][2]+u[i][0])
    dp[i][1]=max(dp[i-1][2]+u[i][1],dp[i-1][0]+u[i][1])
    dp[i][2]=max(dp[i-1][0]+u[i][2],dp[i-1][1]+u[i][2])

print(max(dp[n]))
Buggy code:
N = int(input())
Q = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*3 for i in range(N)]
dp[0][0] = Q[0][0]
dp[0][1] = Q[0][1]
dp[0][2] = Q[0][2]

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

Fixed code:
N = int(input())
Q = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*3 for i in range(N)]
dp[0][0] = Q[0][0]
dp[0][1] = Q[0][1]
dp[0][2] = Q[0][2]

for i in range(1, N):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + Q[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + Q[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + Q[i][2]
print(max(dp[-1]))
Buggy code:
N = int(input())
A = []; B = []; C = []
for i in range(N):
    a, b, c = map(int, input().split())
    A.append(a); B.append(b); C.append(c)

dp = [[0,0,0]]*(N+1)
for i in range(N):
    dp[i+1][1] = dp[i][0] + B[i]
    dp[i+1][2] = dp[i][0] + C[i]

    dp[i+1][2] = dp[i][1] + C[i]
    dp[i+1][0] = dp[i][1] + A[i]

    dp[i+1][0] = dp[i][2] + A[i]
    dp[i+1][1] = dp[i][2] + B[i]
print(max(dp[N]))


Fixed code:
N = int(input())
table = []
for i in range(N):
    a, b, c = map(int, input().split())
    table.append((a,b,c))

dpA = [0]*(N+1)
dpB = [0]*(N+1)
dpC = [0]*(N+1)

for i in range(N):
    a, b, c = table[i]
    dpA[i+1] = max(dpB[i], dpC[i]) + a
    dpB[i+1] = max(dpC[i], dpA[i]) + b
    dpC[i+1] = max(dpA[i], dpB[i]) + c

print(max(dpA[N], dpB[N], dpC[N]))
Buggy code:
n = int(input())
li = [list(map(int, input().split())) for i in range(n)] + [[0]*3]

dp = [[0 for i in range(3)] for j in range(n+1)]
for i in range(3):
    dp[0][i] = li[0][i]

for i in range(n):
    dp[i+1][0] = dp[i][0] + max(li[i+1][1], li[i+1][2])
    dp[i+1][1] = dp[i][1] + max(li[i+1][0], li[i+1][2])
    dp[i+1][2] = dp[i][2] + max(li[i+1][0], li[i+1][1])

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

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

dp = [[0 for i in range(3)] for j in range(n+1)]
for i in range(3):
    dp[0][i] = li[0][i]

for i in range(n):
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + li[i+1][0]
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + li[i+1][1]
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + li[i+1][2]

print(max(dp[n-1]))
Buggy code:
import sys
n = int(sys.stdin.readline())
arr = [list(map(int, sys.stdin.readline().split())) for i in range(n)]
 
dp = [[-1] * 3 for i 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):
	dp[i][0] = max(dp[i - 1][1] + arr[i][0], dp[i - 1][2] + arr[i][0])
	dp[i][1] = max(dp[i - 1][0] + arr[i][1], dp[i - 1][2] + arr[i][1])
	dp[i][2] = max(dp[i - 1][0] + arr[i][2], dp[i - 1][1] + arr[i][2])

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

dp = [[-1] * 3 for i 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):
	dp[i][0] = max(dp[i - 1][1] + arr[i][0], dp[i - 1][2] + arr[i][0])
	dp[i][1] = max(dp[i - 1][0] + arr[i][1], dp[i - 1][2] + arr[i][1])
	dp[i][2] = max(dp[i - 1][0] + arr[i][2], dp[i - 1][1] + arr[i][2])

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

for i in range(1,n):
  a,b,c=map(int,input().split())
  for j in range(3):
    if j==0:
      dp[i][j]=max(dp[i-1][1],dp[i-1][2])
    elif j==1:
      dp[i][j]=max(dp[i-1][0],dp[i-1][2])
    else:
      dp[i][j]=max(dp[i-1][0],dp[i-1][1])
      
print(max(dp[-1]))

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

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

plst = list(itertools.permutations([_ for _ in range(3)], 2))

for _ in range(0, n):
    for i in plst:
      hp[_][i[1]] = max(hp[_-1][i[0]] + lst[_][i[1]],hp[_][i[1]])

print(max(hp[n-1]))

Fixed code:
import itertools
n = int(input())
lst = [[0,0,0]]

for _ in range(n):
  l = list(map(int, input().split()))
  lst.append(l)
  
hp = [[0] * 3 for _ in range(n+1)]

plst = list(itertools.permutations([_ for _ in range(3)], 2))

for _ in range(0, n):
    for i in plst:
      hp[_+1][i[1]] = max(hp[_][i[0]] + lst[_+1][i[1]], hp[_+1][i[1]])

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

Fixed code:
n = int(input())
A = []
B = []
C = []
for i in range(n):
    a,b,c = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    
dp = [[0 for i in range(3)] for j in range(n)]

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1,n):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+A[i]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+B[i]
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+C[i]

print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
Buggy code:
n = int(input())

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

for i in range(n):
  a[i] = list(map(int,input().strip().split()))

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

Fixed code:
n = int(input())

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

for i in range(n):
  a[i] = list(map(int,input().strip().split()))

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j == k:
        continue
      else:
        dp[i+1][k] = max(dp[i+1][k] ,dp[i][j]+ a[i][k])
print(max(dp[n]))
Buggy code:
n=int(input())
a=[]
for i in range(n):
  a_=list(map(int,input().split()))
  a.append(a_)
  
dp=[[0]*3 for i in range(n+1)]
dp[0]=a[0]
for i in range(n):
  for k in range(3):
    for j in range(3):
      if k!=j:
        dp[i+1][k]=dp[i][j]+a[i][k]
        
print(max(dp[n]))

Fixed code:
n=int(input())
a=[]
for i in range(n):
  a_=list(map(int,input().split()))
  a.append(a_)
  
dp=[[0]*3 for i in range(n)]
dp[0]=a[0]
for i in range(1,n):
  for k in range(3):
    
    for j in range(3):
      
      if k!=j:
        dp[i][k]=max(dp[i][k], dp[i-1][j] + a[i][k])
#print(dp)        
print(max(dp[n-1]))
Buggy code:
n = int(input())

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

A=[]
B=[]
C=[]

for i in range(n):
    a = abc[i][0] + max(B[-1],C[-1])
    b = abc[i][1] + max(A[-1],C[-1])
    c = abc[i][2] + max(A[-1],B[-1])
    A.append(a)
    B.append(b)
    C.append(c)

print(max(A[-1],B[-1],C[-1]))

Fixed code:
n = int(input())

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

A=[]
B=[]
C=[]

A.append(abc[0][0])
B.append(abc[0][1])
C.append(abc[0][2])

for i in range(1,n):
    a = abc[i][0] + max(B[-1],C[-1])
    b = abc[i][1] + max(A[-1],C[-1])
    c = abc[i][2] + max(A[-1],B[-1])
    A.append(a)
    B.append(b)
    C.append(c)

print(max(A[-1],B[-1],C[-1]))
Buggy code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = []
for _ in range(N):
    a,b,c = [int(x) for x in stdin.readline().rstrip().split()]
    data.append((a,b,c))

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

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

Fixed code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = []
for _ in range(N):
    a,b,c = [int(x) for x in stdin.readline().rstrip().split()]
    data.append((a,b,c))

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

for i in range(1,N):
    dp[i][0] = data[i][0] + max(dp[i-1][1],dp[i-1][2])
    dp[i][1] = data[i][1] + max(dp[i-1][0],dp[i-1][2])
    dp[i][2] = data[i][2] + max(dp[i-1][0],dp[i-1][1])
print(max(dp[-1]))
Buggy code:
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    h = [[0] * 3 for _ in range(n)]

    for i in range(n):
        h[i] = list(map(int,ipti().split()))

    dp = [[0] * 3 for _ in range(n)]
    dp[0][0] = h[0][0]
    dp[0][1] = h[0][1]
    dp[0][2] = h[0][2]

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

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

if __name__ == '__main__':
    main()

Fixed code:
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    h = [[0] * 3 for _ in range(n)]

    for i in range(n):
        h[i] = list(map(int,ipti().split()))

    dp = [[0] * 3 for _ in range(n)]
    dp[0][0] = h[0][0]
    dp[0][1] = h[0][1]
    dp[0][2] = h[0][2]

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

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

if __name__ == '__main__':
    main()