#include #include using mint = atcoder::static_modint<998244353>; //using mint = atcoder::static_modint<1000000007>; using namespace std; using namespace atcoder; using ld = long double; using ll = long long; #define mp(a,b) make_pair(a,b) #define rep(i,s,n) for(int i=s; i dx{1,0,-1,0},dy{0,1,0,-1}; int main(){ int n;cin >> n; vector> a(n+1,vector(3)); rep(i,1,n+1)rep(j,0,3)cin >> a[i][j]; vector>> dp(n+1,vector>(3)); rep(i,1,n+1)rep(j,0,3)rep(k,0,3)if(j!=k){ int atk=dp[i-1][j].first+a[i][k]; pair p=mp(max(0,atk-1),dp[i-1][j].second+atk); auto [x,y]=dp[i][k]; ll val_k=y+(n-i)*(2*x-n+i+1)/2; ll val_p=p.second+(n-i)*(2*p.first-n+i+1)/2; if(val_p>val_k)dp[i][k]=p; } ll ans=0; rep(i,0,3)ans=max(ans,dp[n][i].second); cout <