Buggy python submission (verdict: Time Limit Exceeded):
import sys
 
 
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
 
 
def get_ints(): return map(int, sys.stdin.readline().strip().split())
 
 
def input(): return sys.stdin.readline().strip()
 
 
def maxim(i, char):
    if i < 0:
        return 0
 
    if li[i][char] != -1:
        ##print('hi')
        ##print(i,char)
        return li[i][char]
    if char == 2:
        li[i][2] = max(c[i] + maxim(i - 1, 1), c[i] + maxim(i - 1, 0))
        return li[i][2]
    if char == 1:
        li[i][1] = max(b[i] + maxim(i - 1, 0), b[i] + maxim(i - 1, 2))
        return li[i][1]
    if char == 0:
        li[i][0] = max(a[i] + maxim(i - 1, 1), a[i] + maxim(i - 1, 2))
        return li[i][0]
    if char == 3:
        li[i][3] = (max(maxim(i - 1, 2), maxim(i - 1, 1), maxim(i - 1, 0)))
        return li[i][3]
 
 
n = int(input())
a, b, c = [], [], []
for _ in range(n):
    x, y, z = get_ints()
    li = [[-1 for i in range(4)] for j in range(n+1)]
    a.append(x)
    b.append(y)
    c.append(z)
li = [[-1 for i in range(4)] for j in range(n+1)]
print(maxim(n , 3))

Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    li=[[-1 for i in range(3)]for j in range(n)]
    a.append(x)
    b.append(y)
    c.append(z)
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))



Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    li=[[-1 for i in range(4)]for j in range(n)]
    a.append(x)
    b.append(y)
    c.append(z)
for i in range(n):
   for j in range(4):
        if i==0:
            if j==0:
                li[i][j]=a[i]
            if j==1:
                li[i][j]=b[i]
            if j==2:
                li[i][j]=c[i]
            if j==3:
                li[i][j] = 0
            continue
        if j==0:
            li[i][j] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])
        if j==1:
            li[i][j] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])
        if j==2:
            li[i][j] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
        if j==3:
            li[i][3] = (max(li[i - 1][2],li[i - 1][1], li[i - 1][0]))
print(max(li[n-1]))



Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    li=[[-1 for i in range(4)]for j in range(n)]
    a.append(x)
    b.append(y)
    c.append(z)
for i in range(n):
   for j in range(4):
        if i==0:
            if j==0:
                li[i][j]=a[i]
            if j==1:
                li[i][j]=b[i]
            if j==2:
                li[i][j]=c[i]
            if j==3:
                li[i][j] = 0
            continue
        if j==0:
            li[i][j] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])
        if j==1:
            li[i][j] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])
        if j==2:
            li[i][j] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
        if j==3:
            li[i][3] = (max(li[i - 1][2],li[i - 1][1], li[i - 1][0]))
print(max(li[n-1]))



Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def get_array(): return list(map(int, sys.stdin.readline().strip().split()))


def get_ints(): return map(int, sys.stdin.readline().strip().split())


def input(): return sys.stdin.readline().strip()


def maxim(i, char):
    if i < 0:
        return 0

    if li[i][char] != -1:
        ##print('hi')
        ##print(i,char)
        return li[i][char]
    if char == 2:
        li[i][2] = max(c[i] + maxim(i - 1, 1), c[i] + maxim(i - 1, 0))
        return li[i][2]
    if char == 1:
        li[i][1] = max(b[i] + maxim(i - 1, 0), b[i] + maxim(i - 1, 2))
        return li[i][1]
    if char == 0:
        li[i][0] = max(a[i] + maxim(i - 1, 1), a[i] + maxim(i - 1, 2))
        return li[i][0]
    if char == 3:
        li[i][3] = (max(maxim(i - 1, 2), maxim(i - 1, 1), maxim(i - 1, 0)))
        return li[i][3]


n = int(input())
a, b, c = [], [], []
for _ in range(n):
    x, y, z = get_ints()
    li = [[-1 for i in range(4)] for j in range(n+1)]
    a.append(x)
    b.append(y)
    c.append(z)
print(maxim(n , 3))

Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def maxim(i,char):
    if i<0:
        return 0

    if li[i][char]!=-1:
            ##print('hi')
            ##print(i,char)
            return li[i][char]
    if char==2:
        li[i][2]= max(c[i]+maxim(i-1,1),c[i]+maxim(i-1,0))
        return li[i][2]
    if char==1:
        li[i][1]= max(b[i] + maxim(i - 1, 0), b[i] + maxim(i - 1, 2))
        return li[i][1]
    if char==0:
        li[i][0]= max(a[i] + maxim(i - 1, 1), a[i] + maxim(i - 1, 2))
        return li[i][0]
    if char==3:
        li[i][3]= (max(maxim(n - 1, 2), maxim(n - 1, 1), maxim(n - 1, 0)))
        return li[i][3]
n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    li=[[-1 for i in range(4)]for j in range(n)]
    a.append(x)
    b.append(y)
    c.append(z)
print(maxim(n-1,3))




Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def maxim(i,char):
    if i<0:
        return 0
    if i!=n:
        if d[i,char]!=-1:
            ##print('hi')
            ##print(i,char)
            return d[i,char]
    if char=='C':
        d[i,char]= max(c[i]+maxim(i-1,'B'),c[i]+maxim(i-1,'A'))
        return d[i,char]
    if char=='B':
        d[i,char]= max(b[i] + maxim(i - 1, 'A'), b[i] + maxim(i - 1, 'C'))
        return d[i,char]
    if char=='A':
        d[i,char]= max(a[i] + maxim(i - 1, 'B'), a[i] + maxim(i - 1, 'C'))
        return d[i,char]
    return (max(maxim(n - 1, 'C'), maxim(n - 1, 'B'), maxim(n - 1, 'A')))
n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    d=dict()
    for i in range(n):
        d[i,'A']=-1
        d[i,'B']=-1
        d[i,'C']=-1
    a.append(x)
    b.append(y)
    c.append(z)

print(maxim(n,'D'))




Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def maxim(i,char):
    if i<0:
        return 0
    if d[i,char]!=-1:
        ##print('hi')
        ##print(i,char)
        return d[i,char]
    if char=='C':
        d[i,char]= max(c[i]+maxim(i-1,'B'),c[i]+maxim(i-1,'A'))
        return d[i,char]
    if char=='B':
        d[i,char]= max(b[i] + maxim(i - 1, 'A'), b[i] + maxim(i - 1, 'C'))
        return d[i,char]
    if char=='A':
        d[i,char]= max(a[i] + maxim(i - 1, 'B'), a[i] + maxim(i - 1, 'C'))
        return d[i,char]
n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    d=dict()
    for i in range(n):
        d[i,'A']=-1
        d[i,'B']=-1
        d[i,'C']=-1
    a.append(x)
    b.append(y)
    c.append(z)
ans1=maxim(n-1,'C')
ans2=maxim(n-1,'B')
ans3=maxim(n-1,'A')
print(max(ans1,ans2,ans3))




Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def maxim(i,char):
    if i<0:
        return 0
    if d[i,char]!=-1:
        ##print('hi')
        ##print(i,char)
        return d[i,char]
    if char=='C':
        d[i,char]= max(c[i]+maxim(i-1,'B'),c[i]+maxim(i-1,'A'))
        return d[i,char]
    if char=='B':
        d[i,char]= max(b[i] + maxim(i - 1, 'A'), b[i] + maxim(i - 1, 'C'))
        return d[i,char]
    if char=='A':
        d[i,char]= max(a[i] + maxim(i - 1, 'B'), a[i] + maxim(i - 1, 'C'))
        return d[i,char]
n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    d=dict()
    for i in range(n):
        d[i,'A']=-1
        d[i,'B']=-1
        d[i,'C']=-1
    a.append(x)
    b.append(y)
    c.append(z)
print(max(maxim(n-1,'C'),maxim(n-1,'B'),maxim(n-1,'A')))




Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Time Limit Exceeded):
def maxim(i,char):
    if i<0:
        return 0
    if d[i,char]!=-1:
        return d[i,char]
    if char=='C':
        d[i,char]= max(c[i]+maxim(i-1,'B'),c[i]+maxim(i-1,'A'))
        return d[i,char]
    if char=='B':
        d[i,char]= max(b[i] + maxim(i - 1, 'A'), b[i] + maxim(i - 1, 'C'))
        return d[i,char]
    if char=='A':
        d[i,char]= max(a[i] + maxim(i - 1, 'B'), a[i] + maxim(i - 1, 'C'))
        return d[i,char]
n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=map(int,input().split())
    d=dict()
    for i in range(n):
        d[i,'A']=-1
        d[i,'B']=-1
        d[i,'C']=-1


    a.append(x)
    b.append(y)
    c.append(z)
print(max(maxim(n-1,'C'),maxim(n-1,'B'),maxim(n-1,'A')))




Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))

Buggy python submission (verdict: Runtime Error):
def maxim(i,char):
    if i<0:
        return 0

    if char=='C':
        return max(c[i]+maxim(i-1,'B'),c[i]+maxim(i-1,'A'))
    if char=='B':
        return max(b[i] + maxim(i - 1, 'A'), b[i] + maxim(i - 1, 'C'))
    if char=='A':
        return max(a[i] + maxim(i - 1, 'B'), a[i] + maxim(i - 1, 'C'))
n=int(input())
a, b, c = [], [], []
for _ in range(n):
    ##a,b,c=[],[],[]
    x,y,z=map(int,input().split())
    a.append(x)
    b.append(y)
    c.append(z)
##print(a,b,c)
print(max(maxim(n-1,'C'),maxim(n-1,'B'),maxim(n-1,'A')))



Fixed submission:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))