N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] INF = 10**18 dp = [[0]*3 for _ in range(N+1)] power = [[-INF]*3 for _ in range(N+1)] for i in range(3): power[0][i] = 0 for i in range(N): for j in range(3): for k in range(3): if j == k: continue if power[i+1][j] < max(power[i][k]+A[i][j]-1, 0): dp[i+1][j] = dp[i][k]+power[i][k]+A[i][j] power[i+1][j] = max(power[i][k]+A[i][j]-1, 0) print(max(dp[-1]))