qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
abc=[[0,0,0]]*n
dp = [[0]*n for _ in range(3)]

for i in range(n):
  abc[i] = list(map(int,input().split()))
  
for i in range(3):
  dp[i][0] = abc[0][i]

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

Fixed code:
n = int(input())
abc=[[0,0,0]]*n
dp = [[0]*n for _ in range(3)]

for i in range(n):
  abc[i] = list(map(int,input().split()))
  
for i in range(3):
  dp[i][0] = abc[0][i]

for i in range(1,n):
  for j in range(3):    
    for k in range(3):
      if j==k:
        pass
      else:
        dp[j][i] = max(dp[j][i], dp[k][i-1]+abc[i][j])
        
print(max([row[-1] for row in dp]))
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):
  dp[i+1][0]=max(dp[i+1][0],dp[i][1]+a[i+1],dp[i+1][2]+a[i+1])
  dp[i+1][1]=max(dp[i+1][1],dp[i][0]+b[i+1],dp[i+1][2]+b[i+1])
  dp[i+1][2]=max(dp[i+1][2],dp[i][1]+c[i+1],dp[i+1][0]+c[i+1])
print(max(dp[n-1]))

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

if __name__ == '__main__':
    main()


Fixed code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    HAPPY = [list(map(int, input().split())) for i in range(N)]
    dp = [[0]*3 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], HAPPY[i][k] + dp[i][j])
    print(max(max(dp[N][0], dp[N][1]), dp[N][2]))

if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
ans = [[0]*3 for _ in range(n)]

ans[0][0] = abc[0][0]
ans[0][1] = abc[0][1]
ans[0][2] = abc[0][2]

for i in range(n):
    ans[i][0] = max(ans[i-1][1], ans[i-1][2]) + abc[i][0]
    ans[i][1] = max(ans[i-1][0], ans[i-1][2]) + abc[i][1]
    ans[i][2] = max(ans[i-1][0], ans[i-1][1]) + abc[i][2]

print(max(ans[-1]))

Fixed code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
ans = [[0]*3 for _ in range(n)]

ans[0][0] = abc[0][0]
ans[0][1] = abc[0][1]
ans[0][2] = abc[0][2]

for i in range(1, n):
    ans[i][0] = max(ans[i-1][1], ans[i-1][2]) + abc[i][0]
    ans[i][1] = max(ans[i-1][0], ans[i-1][2]) + abc[i][1]
    ans[i][2] = max(ans[i-1][0], ans[i-1][1]) + abc[i][2]

print(max(ans[-1]))
Buggy code:
import sys
import heapq

input = sys.stdin.readline
N = int(input())

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

Fixed code:
import sys
import heapq

input = sys.stdin.readline
N = int(input())

dp = [[0,0,0] for _ in range(N)]
for i in range(N):
  a, b, c = map(int, input().split())
  if i == 0:
    dp[i] = [a, b, c]
  else:
    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:
# https://atcoder.jp/contests/dp/tasks/dp_c
N = int(input())
Max_List = [[0] * 3 for i in range(N)]
for i in range(N):
    Current_List = list(map(int,input().split()))  
    if i == 0:
        Max_List[i] = Current_List
    else:
        Search_List = Max_List[i-1]
        for j in range(3):
            Current_Search_List = Search_List[1:3]
            Max_List[i][j] = (max(Current_Search_List) + Current_List[j])
            Search_List.append(Search_List[0])
            del Search_List[0]
        
        Max_List[i] = Current_Max_List

        
print(max(Max_List[-1]))

Fixed code:
# https://atcoder.jp/contests/dp/tasks/dp_c
N = int(input())
Max_List=[]
N_List=[i for i in range(3)]
for i in range(N):
    Current_List=list(map(int,input().split())) 
    if i == 0:
        Max_List.append(Current_List)
    else:
        Current_Max_List = []
        Search_List=Max_List[i-1]
        for j in range(3):
            Current_Search_List=Search_List[1:3]
            Current_Max_List.append(max(Current_Search_List)+Current_List[j])
            Search_List.append(Search_List[0])
            del Search_List[0]
        Max_List.append(Current_Max_List)
        
    
print(max(Max_List[-1]))
Buggy code:
# https://atcoder.jp/contests/dp/tasks/dp_c
N = int(input())
Max_List=[]
N_List=[i for i in range(3)]
for i in range(N):
    Current_Max_List = []
    Current_List=list(map(int,input().split())) 
    if i == 0:
        Max_List.append(Current_List)
    else:
        for j in range(3):
            Index_List=np.array(Max_List[i-1])
            ind = np.ones(3, dtype=bool)
            ind[j] = False
            Current_Max_List.append(max(Index_List[ind])+Current_List[j])
            
        Max_List.append(Current_Max_List)

print(max(Max_List[-1]))

Fixed code:
# https://atcoder.jp/contests/dp/tasks/dp_c
import numpy as np
N = int(input())
Max_List=[]
N_List=[i for i in range(3)]
for i in range(N):
    Current_List=list(map(int,input().split())) 
    if i == 0:
        Max_List.append(Current_List)
    else:
        Current_Max_List = []
        for j in range(3):
            Index_List=np.array(Max_List[i-1])
            ind = np.ones(3, dtype=bool)
            ind[j] = False
            Current_Max_List.append(max(Index_List[ind])+Current_List[j])
            
        Max_List.append(Current_Max_List)
        
    
print(max(Max_List[-1]))
Buggy code:
n = int(input())
a = []
b = []
for _ in range(n):
    a.append(list(map(int,input().split())))
    d.append([0,0,0])
d[0]=a[0]
for i in range(1,n):
    for j in range(3):
        d[i][j]=max(d[i-1][(j+1)%3],d[i-1][(j+2)%3])+a[i][j]
print(max(d[n-1]))


Fixed code:
n = int(input())
a = []
d = []
for _ in range(n):
    a.append(list(map(int,input().split())))
    d.append([0,0,0])
d[0]=a[0]
for i in range(1,n):
    for j in range(3):
        d[i][j]=max(d[i-1][(j+1)%3],d[i-1][(j+2)%3])+a[i][j]
print(max(d[-1]))
Buggy code:
N = int(input())
L = []

for i in range(N):
  l = list(map(int,input().split()))
  L.append(l)
  
dp = [[0,0,0] for i in range(N + 1)]
dp[1] = [L[1][0],L[1][1],L[1][2]]

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

Fixed code:
N = int(input())
L = []

for i in range(N):
  l = list(map(int,input().split()))
  L.append(l)
  
dp = [[0,0,0] for i in range(N)]
dp[0] = [L[0][0],L[0][1],L[0][2]]

for i in range(1,N):
  for j in range(3):
    dp[i][j] = max(dp[i - 1][(j + 1) % 3],dp[i - 1][(j + 2) % 3]) + L[i][j]
    
print(max(dp[N - 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 for i in range(3)]for i in range(n)]
for i in range(n):
    for j in range(3):
        if j == 0:
            s = a[i]
        if j == 1:
            s = b[i]
        if j == 2:
            s = c[i]
        for k in range(3):
            if i !=0:
                if j != k:
                    dp[i][j] = max(dp[i-1][k],dp[i][j])
        dp[i][j] += s
print(dp)
print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))


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 i in range(n)]
for i in range(n):
    for j in range(3):
        if j == 0:
            s = a[i]
        if j == 1:
            s = b[i]
        if j == 2:
            s = c[i]
        for k in range(3):
            if i !=0:
                if j != k:
                    dp[i][j] = max(dp[i-1][k],dp[i][j])
        dp[i][j] += s
print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
Buggy code:
n = int(input())

hap = [[0] for i in range(n)]
for i in range(n):
  hap[i] = [int(i) for i in input().split()]
  
dp = [[0]*3 for i in range(n)]
for i in range(3):
  dp[0][i] = hap[0][i]
  
for i in range(1, n):
  for j in range(3):
    dp[i][j] = max(dp[i-1][j]+hap[i][(j+1)%3], dp[i-1][j]+hap[i][(j+2)%3])
print(max(dp[n-1]))
     



Fixed code:
n = int(input())

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

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

for i in range(N):
    v1, v2, v3 = map(int, input().split())
    vals[i][0] = v1
    vals[i][1] = v2
    vals[i][2] = v3

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

dp[0][0] = vals[0][0]
dp[0][1] = vals[0][1]
dp[0][2] = vals[0][2]

for i in range(1, N):
    for activity in range(3):
        for pastActivity in range(3):
            if activity == pastActivity: continue
            
            dp[i][activity] = max(dp[i][activity],
                                  dp[i-1][pastActivity] + vals[i][activity])

print(max(dp[-1]))


Fixed code:
N = int(input())

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

for i in range(N):
    v1, v2, v3 = map(int, input().split())
    vals[i][0] = v1
    vals[i][1] = v2
    vals[i][2] = v3

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

dp[0][0] = vals[0][0]
dp[0][1] = vals[0][1]
dp[0][2] = vals[0][2]

for i in range(1, N):
    for activity in range(3):
        for pastActivity in range(3):
            if activity == pastActivity: continue
            
            dp[i][activity] = max(dp[i][activity],
                                  dp[i-1][pastActivity] + vals[i][activity])

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


Fixed code:
n = int(input())
c = []
dp = [0]*3
# for i in range(n):
#     c.append(list(map(int, input().split())))
for i in range(n):
    c = list(map(int, input().split()))
    new_dp = [0]*3
    for j in range(3):
        for k in range(3):
            if j != k:
                new_dp[k] = max(new_dp[k], dp[j] + c[k])
    dp = new_dp[:]
print(max(dp))
Buggy code:
n=int(input())
A=B=C=0
for i in range(n):
    a,b,c=map(int,input().split())
    A,B,C=a+max(B,C),max(C,A),max(A,B)
print(max(A,B,C))

Fixed code:
n=int(input())
A=B=C=0
for i in range(n):
    a,b,c=map(int,input().split())
    A,B,C=a+max(B,C),b+max(C,A),c+max(A,B)
print(max(A,B,C))
Buggy code:
def main():
    N = int(input())
    happiness = []
    for i in range(N):
        happiness.append([int(num) for num in input().split()])

    hap_total = [[0] * 3] * N
    hap_total[0] = [happiness[0][0], happiness[0][1], happiness[0][2]]


    for i in range(1, N):
        for j in range(3):
            for k in {0, 1, 2} - {j}:
                hap_total[i][j] = max(hap_total[i][j], hap_total[i-1][k] + happiness[i][j])


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


if __name__ == '__main__':
    main()

Fixed code:
def main():
    N = int(input())
    happiness = []
    for i in range(N):
        happiness.append([int(num) for num in input().split()])

    hap_total = [[0] * 3 for _ in range(N)]
    hap_total[0] = [happiness[0][0], happiness[0][1], happiness[0][2]]


    for i in range(1, N):
        for j in range(3):
            for k in {0, 1, 2} - {j}:
                hap_total[i][j] = max(hap_total[i][j], hap_total[i-1][k] + happiness[i][j])


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


if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
dp = [0,0,0]
for _ in range(N):
    a, b, c = map(int, input().split())
    ndp = [0,0,0]
    ndp[0] = max(dp[1], dp[2]) + a
    ndp[1] = max(dp[0], dp[2]) + b
    ndp[2] = max(dp[0], dp[1]) + c
    dp = ndp
return max(dp)


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

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

dp = [0,0,0]
for a in arr:
	dp = [a[0]+max(dp[1],dp[2]),a[1]+max(dp[0],dp[2]),a[2]+max(dp[0],dp[1])]
return max(dp)

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

dp = [0,0,0]
for a in arr:
	dp = [a[0]+max(dp[1],dp[2]),a[1]+max(dp[0],dp[2]),a[2]+max(dp[0],dp[1])]

print(max(dp))
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)
print(A,B,C)
dp = [[0]*3 for i in range(n+1)]
for i in range(n):
    dp[i+1][0] = max(max( dp[i][1], dp[i][2] ) + A[i] ,dp[i+1][0])
    dp[i+1][1] = max(max( dp[i][0], dp[i][2] ) + B[i] ,dp[i+1][1])
    dp[i+1][2] = max(max( dp[i][0], dp[i][1] ) + C[i] ,dp[i+1][2])
    print(dp)
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]*3 for i in range(n+1)]
for i in range(n):
    dp[i+1][0] = max(max( dp[i][1], dp[i][2] ) + A[i] ,dp[i+1][0])
    dp[i+1][1] = max(max( dp[i][0], dp[i][2] ) + B[i] ,dp[i+1][1])
    dp[i+1][2] = max(max( dp[i][0], dp[i][1] ) + C[i] ,dp[i+1][2])
    
print(max(dp[-1]))
Buggy code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)] 

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

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


print(max(dp[n]))

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

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

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

print(max(dp[n]))
Buggy code:
N=int(input())
C=[ list(map(int,input().split(' '))) for i in range(N)]
dp=[]
for i in range(N):
	if i==0:
		dp.append(C[0]) #[a0,b0,c0]
	else:
		dp.append([ dp[i-1][j]+max(C[i][(j+1)%3], C[i][(j+2)%3]) for j in range(3) ])

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

Fixed code:
N=int(input())
C=[ list(map(int,input().split(' '))) for i in range(N)]
dp=[]
for i in range(N):
	if i==0:
		dp.append(C[0]) #[a0,b0,c0]
	else:
		dp.append([ C[i][j]+max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) for j in range(3) ])
print(max(dp[N-1]))
Buggy code:
N = int(input())
abc = []
for _ in range(N):
	a, b, c = map(int, input().split())
	abc.append([a,b,c])
dp = [[0, 0, 0] for _ in range(N+1)]
print(abc)
for i in range(1,N+1):
	dp[i][0] = max(dp[i][0], dp[i-1][1]+abc[i-1][0])
	dp[i][0] = max(dp[i][0], dp[i-1][2]+abc[i-1][0])
	dp[i][1] = max(dp[i][1], dp[i-1][0]+abc[i-1][1])
	dp[i][1] = max(dp[i][1], dp[i-1][2]+abc[i-1][1])
	dp[i][2] = max(dp[i][2], dp[i-1][0]+abc[i-1][2])
	dp[i][2] = max(dp[i][2], dp[i-1][1]+abc[i-1][2])
	print(dp)

print(max(dp[N]))


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

print(max(dp[N]))
Buggy code:
n=int(input())
dp=[0]*n
for i in range(n):
	dp[i]=[0]*3
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][0]=a+max(dp[i-1][2],dp[i-1][1])
	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]))

Fixed code:
n=int(input())
dp=[0]*n
for i in range(n):
	dp[i]=[0]*3
dp[0][0],dp[0][1],dp[0][2]=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][2],dp[i-1][1])
	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]))
Buggy code:
N = int(input())

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

a, b, c = map(int, input().split())
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())
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + c
print(max(dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]))

Fixed code:
N = int(input())
dp = [[0 for _ in range(3)] for i in range(N)]
a,b,c = list(map(int,input().split()))
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c
for i in range(1,N):
    a,b,c = list(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[N-1][0],dp[N-1][1],dp[N-1][2]))
Buggy code:
n, *t = map( int, open( 0 ).read().split() )

# manemane
A, B, C = 0, 0, 0
for i in  range( n ):
  A, B, C = t[ 3 * i  ] + max( B, A ), t[ 3 * i + 1 ] + max( A, C ), t[ 3 * i + 2 ] + max( A, B )

print( max( A, B, C ) )


Fixed code:
n, *t = map( int, open( 0 ).read().split() )
 
# manemane
A, B, C = 0, 0, 0
for i in  range( n ):
  A, B, C = t[ 3 * i  ] + max( B, C ), t[ 3 * i + 1 ] + max( A, C ), t[ 3 * i + 2 ] + max( A, B )
 
print( max( A, B, C ) )
Buggy code:
n =　int(input())
a = [0] * ( n + 1)
b = [0] * ( n + 1)
c = [0] * ( n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = map(int, input().split())
    a[i] = a[i] + max(b[i - 1], c[i - 1])
    b[i] = b[i] + max(c[i - 1], a[i - 1])
    c[i] = c[i] + max(a[i - 1], b[i - 1])
print(max(a[n], b[n], c[n]))

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

for i in range(n):
    abc_list.append(list(map(int,input().split())))

pre_suma,pre_sumb,pre_sumc = abc_list[0][0],abc_list[0][1],abc_list[0][2]

if n == 1:
    print(max(pre_suma,pre_sumb,pre_sumc))
    sys.exit()

for i in range(1,n):
    a,b,c = abc_list[i][0],abc_list[i][1],abc_list[i][2]
    suma = a + max(pre_sumb,pre_sumc)
    sumb = b + max(pre_suma,pre_sumc)
    sumc = c + max(pre_suma,pre_sumb)
    pre_suma,pre_sumb,pre_sumc = suma,sumb,sumc
    print(suma,sumb,sumc)
print(max(suma,sumb,sumc))

    

Fixed code:
import sys
n = int(input())
abc_list = []

for i in range(n):
    abc_list.append(list(map(int,input().split())))

pre_suma,pre_sumb,pre_sumc = abc_list[0][0],abc_list[0][1],abc_list[0][2]

if n == 1:
    print(max(pre_suma,pre_sumb,pre_sumc))
    sys.exit()

for i in range(1,n):
    a,b,c = abc_list[i][0],abc_list[i][1],abc_list[i][2]
    suma = a + max(pre_sumb,pre_sumc)
    sumb = b + max(pre_suma,pre_sumc)
    sumc = c + max(pre_suma,pre_sumb)
    pre_suma,pre_sumb,pre_sumc = suma,sumb,sumc
    # print(suma,sumb,sumc)
print(max(suma,sumb,sumc))
Buggy code:
import math


def chmax(a, b):
    if a >= b:
        return a
    return b


def chmin(a, b):
    if a <= b:
        return a
    return b


def main():
    nn = int(input())
    arr = [list(map(int, input().split())) for l in range(nn)]
    dp = [[0] * 3 for i in range(nn)]

    for i in range(0,nn):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i][j] = chmax(dp[i][j],dp[i-1][k]+arr[i][k])

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


main()

Fixed code:
import math


def chmax(a, b):
    if a >= b:
        return a
    return b


def chmin(a, b):
    if a <= b:
        return a
    return b


def main():
    nn = int(input())
    arr = [list(map(int, input().split())) for l in range(nn)]
    dp = [[0] * 3 for i in range(nn+1)]

    for i in range(nn):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][j] = chmax(dp[i+1][j],dp[i][k]+arr[i][k])

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


main()
Buggy code:
N = int(input())
T = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N)]
for i in range(N):
  if i == 0:
    dp[i] = T[i]
  for j in [0,1,2]:
    dp[i][j] = max([dp[i-1][j1]+T[i][j] for j1 in [0,1,2] if j1 != j])
print(max(dp[-1]))

Fixed code:
N = int(input())
T = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for i in range(N)]
dp[0] = T[0]
for i in range(1,N):
  for j in [0,1,2]:
    dp[i][j] = max([dp[i-1][j1]+T[i][j] for j1 in [0,1,2] if j1 != j])
print(max(dp[N-1]))
Buggy code:
N = input()

max_a= [0]*N
max_b = [0]*N
max_c = [0]*N

for i in range(0,N):
  a,b,c = map(int,input.split())
  max_a[i] = max(max_b[i-1]+a,max_c+a) 
  max_b[i] = max(max_a[i-1]+b,max_c[i-1]+b) 
  max_c[i] = max(max_a[i-1]+c,max_b[i-1]+c) 
  
print(max(max_a[-1],max_b[-1],max_c[-1]))

Fixed code:
N = int(input())

max_a = [0] * N
max_b = [0] * N
max_c = [0] * N
if N>1:
    for i in range(0, N):
        a, b, c = map(int, input().split())
        max_a[i] = max(max_b[i - 1] + a, max_c[i-1] + a)
        max_b[i] = max(max_a[i - 1] + b, max_c[i - 1] + b)
        max_c[i] = max(max_a[i - 1] + c, max_b[i - 1] + c)

    print(max(max_a[-1], max_b[-1], max_c[-1]))
else:
    a, b, c = map(int, input().split())

    print(max(a, b, c))
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] = [int(j) for j in input().split()]

dp = [[0]*3 for _ in range(N+1)]
for i in range(N):
    for j in range(3):
        dp[i+1][j] = max(dp[i][j-1], dp[i][j-2]) + ABC[i][j]

print(max(dp[-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] = [int(j) for j in input().split()]
    
dp = [[0]*3 for _ in range(N+1)]

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