#include using namespace std; using ll = long long; using ull = unsigned long long; const int INF = 2001001001; const ll LINF = 9001001001001001001; #define rep(i, n) for (int i = 0; (i) < (n); (i)++) #define rep1(i, n) for (int i = 1; (i) < (n + 1); (i)++) #define all(a) (a).begin(), (a).end() int main(){ ll N; cin >> N; ll A[5009][4]; rep1(i,N){ rep1(j,3){ cin >> A[i][j]; } } ll dp[5009][4] = {}; ll attack[5009][4] = {}; rep1(i,N){ if(dp[i-1][2]+attack[i-1][2] > dp[i-1][3]+attack[i-1][3]){ dp[i][1] = dp[i-1][2]+attack[i-1][2]+A[i][1]; attack[i][1] = max(attack[i-1][2]+A[i][1]-1, 0LL); } else { dp[i][1] = dp[i-1][3]+attack[i-1][3]+A[i][1]; attack[i][1] = max(attack[i-1][3]+A[i][1]-1, 0LL); } if(dp[i-1][1]+attack[i-1][1] > dp[i-1][3]+attack[i-1][3]){ dp[i][2] = dp[i-1][1]+attack[i-1][1]+A[i][2]; attack[i][2] = max(attack[i-1][1]+A[i][2]-1, 0LL); } else { dp[i][2] = dp[i-1][3]+attack[i-1][3]+A[i][2]; attack[i][2] = max(attack[i-1][3]+A[i][2]-1, 0LL); } if(dp[i-1][1]+attack[i-1][1] > dp[i-1][2]+attack[i-1][2]){ dp[i][3] = dp[i-1][1]+attack[i-1][1]+A[i][3]; attack[i][3] = max(attack[i-1][1]+A[i][3]-1, 0LL); } else { dp[i][3] = dp[i-1][2]+attack[i-1][2]+A[i][3]; attack[i][3] = max(attack[i-1][2]+A[i][3]-1, 0LL); } } cout << max({dp[N][1], dp[N][2], dp[N][3]}) << endl; }