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 for s, x, tot in pp: for j in range(3): if s == j: continue nx = x + cards[i][j] ntot = tot + nx dp.append((j, max(0, nx-1), ntot)) ans = max(tot for _, _, tot in dp) print(ans)