import bisect n = 0 a = [] b = [] c = [] m = [] v = [[], []] s = [[], []] def dfs(i, flag, money, val): if i == m: if flag: s[0].append((money, val)) else: v[0].append((money, val)) return if not flag: dfs(i + 1, True, money, val) dfs(i + 1, False, money + a[i], val) else: dfs(i + 1, False, money - c[i], val + b[i]) def dfs2(i, flag, money, val): if i == m - 1: if flag: s[1].append((money, val)) else: v[1].append((money, val)) return if not flag: dfs2(i - 1, True, money - c[i], val + b[i]) dfs2(i - 1, False, money + a[i], val) else: dfs2(i - 1, False, money, val) def calc(key1, key2, val1, val2): ans = 0 for k, v in zip(key1, val1): idx = bisect.bisect_left(key2, -k) ans = max(ans, v + val2[idx]) return ans def main(): global n, m, a, b, c n = int(input()) for i in range(n): a_, b_, c_ = tuple(map(int, input().split())) a.append(a_) b.append(b_) c.append(c_) m = n // 2 dfs(0, False, 0, 0) dfs2(n - 1, False, 0, 0) v_keys = [[], []] v_vals = [[], []] s_keys = [[], []] s_vals = [[], []] for i in range(2): v_tmp = [] s_tmp = [] for money, _ in v[i]: v_tmp.append(money) for money, _ in s[i]: s_tmp.append(money) v_tmp = sorted(v_tmp) s_tmp = sorted(s_tmp) for elm in v_tmp: if not v_keys[i] or v_keys[i][-1] != elm: v_keys[i].append(elm) for elm in s_tmp: if not s_keys[i] or s_keys[i][-1] != elm: s_keys[i].append(elm) v_vals[i] = [-int(1e18) for _ in range(len(v_keys[i]))] s_vals[i] = [-int(1e18) for _ in range(len(s_keys[i]))] for money, val in v[i]: idx = bisect.bisect_left(v_keys[i], money) v_vals[i][idx] = max(v_vals[i][idx], val) for money, val in s[i]: idx = bisect.bisect_left(s_keys[i], money) s_vals[i][idx] = max(s_vals[i][idx], val) for j in range(len(v_vals[i]) - 1, 0, -1): v_vals[i][j - 1] = max(v_vals[i][j - 1], v_vals[i][j]); for j in range(len(s_vals[i]) - 1, 0, -1): s_vals[i][j - 1] = max(s_vals[i][j - 1], s_vals[i][j]); s_keys[1].append(int(1e18)) s_vals[1].append(int(-1e18)) v_keys[1].append(int(1e18)) v_vals[1].append(int(-1e18)) ans = max(calc(s_keys[0], s_keys[1], s_vals[0], s_vals[1]), calc(v_keys[0], v_keys[1], v_vals[0], v_vals[1])) print(ans) if __name__ == '__main__': main()