n=int(raw_input())
l=[[*map(raw_int,input().split())] for i in range(n)]
ans=0
prev=""
for i in range(n):
    a,b,c=l[i]
    if(a>b and a>c):
        if(prev!='a'):
            ans+=a
            prev='a'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][0]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+a)
                prev='a'
    elif(b>a and b>c):
        if(prev!='b'):
            prev='b'
            ans+=b
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][1]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+b)
                prev='b'
    elif(c>a and c>b):
        if(prev!='c'):
            ans+=c
            prev='c'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][2]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+c)
                prev='c'
    else:
        ans+=max(l[i])
        z=max(l[i])
        if(z==a and prev!='a'):
            prev='a'
        elif(z==b and prev!='b'):
            prev='b'
        else:
            prev='c'
print ansn=int(raw_input())
l=[[*map(raw_int,input().split())] for i in range(n)]
ans=0
prev=""
for i in range(n):
    a,b,c=l[i]
    if(a>b and a>c):
        if(prev!='a'):
            ans+=a
            prev='a'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][0]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+a)
                prev='a'
    elif(b>a and b>c):
        if(prev!='b'):
            prev='b'
            ans+=b
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][1]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+b)
                prev='b'
    elif(c>a and c>b):
        if(prev!='c'):
            ans+=c
            prev='c'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][2]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+c)
                prev='c'
    else:
        ans+=max(l[i])
        z=max(l[i])
        if(z==a and prev!='a'):
            prev='a'
        elif(z==b and prev!='b'):
            prev='b'
        else:
            prev='c'
print ans

### FIXED CODE ###

n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
ans=[[0,0,0] for i in range(n+1)]
for i in range(n):
    ans[i+1][0]=max(ans[i][1]+l[i][0],ans[i][2]+l[i][0])
    ans[i+1][1]=max(ans[i][2]+l[i][1],ans[i][0]+l[i][1])
    ans[i+1][2]=max(ans[i][0]+l[i][2],ans[i][1]+l[i][2])
print(max(ans[-1]))