n = int(input()) dp = [[(0, 0)] for _ in range(3)] for _ in range(n): ndp = [[] for _ in range(3)] A = list(map(int, input().split())) for i in range(3): for j in range(3): if i == j: continue for pow, dam in dp[i]: ndp[j].append((max(0, pow + A[j] - 1), dam + pow + A[j])) for i in range(3): ndp[i].sort(key=lambda x: -x[0]) dp[i] = [ndp[i][0]] for j in range(1, len(ndp[i])): if ndp[i][j][1] > dp[i][0][1]: dp[i].append(ndp[i][j]) ans = 0 for i in range(3): for pow, dam in dp[i]: ans = max(ans, dam) print(ans)