n=int(input()) dp=[[-1]*3 for _ in range(n+1)] dp[0]=[0]*3 for v in range(1,n+1)[::-1]: ndp=[[-1]*3 for _ in range(v)] a=list(map(int,input().split())) for i in range(v): for j in range(3): if dp[i][j]==-1: continue for k in range(3): if j==k: continue p=min(v-1,max(0,i+a[k]-1)) if p!=v-1: ndp[p][k]=max(ndp[p][k],dp[i][j]+i+a[k]) else: ndp[p][k]=max(ndp[p][k],dp[i][j]+(i+a[k]-1)*v+1) for j in range(3): if dp[v][j]==-1: continue for k in range(3): if j==k: continue ndp[v-1][k]=max(ndp[v-1][k],dp[v][j]+(a[k]-1)*v+1) dp=ndp print(max(dp[0]))