def dfs(t,m,v,w): global ans if t==w: L.append([m,v]) return dfs(t+1,m+a[t],v,w) if t+1 < w: dfs(t+2,m-c[t+1],v+b[t+1],w) def solve(x,y): x.sort(key=f) y.sort(key=f) for i in range(len(x)-1)[::-1]: if x[i][1] < x[i+1][1]: x[i][1] = x[i+1][1] ans = idx = 0 L = len(x) for m,v in y[::-1]: while idx < L and x[idx][0] + m < 0: idx += 1 if idx < L: ans = max(ans,x[idx][1]+v) return ans w = int(input()) a,b,c = [0]*w, [0]*w, [0]*w for i in range(w): a[i],b[i],c[i] = map(int,input().split()) ans = 0 for W in [w//2,w//2+1]: f = lambda x:x[0] L = x = [] dfs(0,0,0,W) L = y = [] dfs(W,0,0,w) ans = max(ans,solve(x,y)) print(ans)