from operator import itemgetter N=int(input()) DP0=[(0,0)] DP1=[(0,0)] DP2=[(0,0)] for i in range(N): #print(DP0,DP1,DP2) a,b,c=map(int,input().split()) NDP0=[] NDP1=[] NDP2=[] for x,y in DP0: attack=b+x damage=y+attack attack-=1 attack=max(attack,0) NDP1.append((attack,damage)) attack=c+x damage=y+attack attack-=1 attack=max(attack,0) NDP2.append((attack,damage)) for x,y in DP1: attack=a+x damage=y+attack attack-=1 attack=max(attack,0) NDP0.append((attack,damage)) attack=c+x damage=y+attack attack-=1 attack=max(attack,0) NDP2.append((attack,damage)) for x,y in DP2: attack=a+x damage=y+attack attack-=1 attack=max(attack,0) NDP0.append((attack,damage)) attack=b+x damage=y+attack attack-=1 attack=max(attack,0) NDP1.append((attack,damage)) NDP0.sort(key=itemgetter(1),reverse=True) NDP0.sort(key=itemgetter(0),reverse=True) DP0=[] for x,y in NDP0: if DP0 and DP0[-1][1]>=y: continue DP0.append((x,y)) NDP1.sort(key=itemgetter(1),reverse=True) NDP1.sort(key=itemgetter(0),reverse=True) DP1=[] for x,y in NDP1: if DP1 and DP1[-1][1]>=y: continue DP1.append((x,y)) NDP2.sort(key=itemgetter(1),reverse=True) NDP2.sort(key=itemgetter(0),reverse=True) DP2=[] for x,y in NDP2: if DP2 and DP2[-1][1]>=y: continue DP2.append((x,y)) ANS=0 for x,y in DP0+DP1+DP2: ANS=max(ANS,y) print(ANS)