n = int(input()) dp = [[(0, 0)], [(0, 0)], [(0, 0)]] # power = 0, deal_damage = 0 for turn in range(n): a = list(map(int, input().split())) pre = [[], [], []] for i in range(3): for s, c in dp[i]: power = s + a[i] for j in range(3): if i == j: continue pre[j].append((max(0, power - 1), c + power)) nxt = [[], [], []] # s1, c1 : s2, c2 # for i in range(3): for p in range(len(pre[i])): add = True for q in range(len(pre[i])): if p == q: continue s1, c1 = pre[i][p] s2, c2 = pre[i][q] if p >= q and s1 == s2 and c1 == c2: add = False if (s2 - s1) > (c1 - c2) * (n - turn): add = False if add: nxt[i].append(pre[i][p]) dp = nxt[::] ans = 0 for i in range(3): for p, c in dp[i]: ans = max(ans, c) print(ans)