from heapq import heappush, heappop N = int(input()) cards = [] for _ in range(N): A, B, C = map(int, input().split()) cards.append((A, B, C)) dp = [(-1, 0, 0)] for i in range(N): pp = [] dp, pp = pp, dp ds = [{}, {}, {}] for prev_j, x, tot in pp: for j in range(3): if prev_j == j: continue nx = x + cards[i][j] ntot = tot + nx # dp.append((j, max(0, nx-1), ntot)) d = ds[j] d[nx] = max(d.get(nx, -1), ntot) for j in range(3): d = ds[j] v = -1 for nx, ntot in sorted(d.items(), reverse=True): if v >= ntot: continue v = ntot dp.append((j, max(0, nx-1), ntot)) ans = max(tot for _, _, tot in dp) print(ans)