n = int(eval(input()))

happymat = []

dp = []

for _ in range(n):

    happymat.append(list(map(int, input().split())))

    dp.append([0]*3)



# dp[i][j] stores the max happiness after day i ... doing activity j on that day

dp[0][0] = happymat[0][0]

dp[0][1] = happymat[0][1]

dp[0][2] = happymat[0][2]



for i in range(1, n):

    for j in range(3):

        dp[i][j] = happymat[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3])



print((max(dp[n-1])))
n = int(eval(input()))

happymat = []

for _ in range(n):

    happymat.append(list(map(int, input().split())))



# dp[j] stores the max happiness doing activity j on the current

dp = [0]*3



for i in range(n):

    prev = dp.copy()

    for j in range(3):

        dp[j] = happymat[i][j] + max(prev[(j+1)%3], prev[(j+2)%3])



print((max(dp)))
n = int(eval(input()))
happymat = []
dp = []
for _ in range(n):
    happymat.append(list(map(int, input().split())))
    dp.append([0] * 3)
# dp[i][j] stores the max happiness after day i ... doing activity j on that day
dp[0][0] = happymat[0][0]
dp[0][1] = happymat[0][1]
dp[0][2] = happymat[0][2]
for i in range(1, n):
    for j in range(3):
        dp[i][j] = happymat[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3])
print((max(dp[n - 1])))

n = int(eval(input()))
happymat = []
for _ in range(n):
    happymat.append(list(map(int, input().split())))
# dp[j] stores the max happiness doing activity j on the current
dp = [0] * 3
for i in range(n):
    prev = dp.copy()
    for j in range(3):
        dp[j] = happymat[i][j] + max(prev[(j + 1) % 3], prev[(j + 2) % 3])
print((max(dp)))

-dp = [] -    dp.append([0] * 3) -# dp[i][j] stores the max happiness after day i ... doing activity j on that day -dp[0][0] = happymat[0][0] -dp[0][1] = happymat[0][1] -dp[0][2] = happymat[0][2] -for i in range(1, n): +# dp[j] stores the max happiness doing activity j on the current +dp = [0] * 3 +for i in range(n): +    prev = dp.copy() -        dp[i][j] = happymat[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) -print((max(dp[n - 1]))) +        dp[j] = happymat[i][j] + max(prev[(j + 1) % 3], prev[(j + 2) % 3]) +print((max(dp)))