#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); constexpr ll INF = (1ll << 60); int n; cin >> n; auto f = [&](ll v, int r){ return v <= r ? v * (v + 1) / 2 : r * (2 * v - r + 1) / 2; }; constexpr array tmp = {-INF, -INF, -INF}; vector> dp(1, {{}}); array dp2 = {-INF, -INF, -INF}; for(int i = 0; i < n; i++){ const int mx = n - 1 - i; vector> ndp(mx + 1, tmp); array ndp2 = tmp; int a, b, c; cin >> a >> b >> c; auto g = [&](int at, int j, int k){ int k1 = k == 2 ? 0 : k + 1; int k2 = k == 0 ? 2 : k - 1; ll tmp = max(dp[j][k1], dp[j][k2]); at += j; if(at >= mx) ndp2[k] = max(ndp2[k], tmp + at * (ll)(n - i) - mx * (mx + 1) / 2); else ndp[max(0, at - 1)][k] = max(ndp[max(0, at - 1)][k], tmp + at); }; for(int j = 0; j < dp.size(); j++){ g(a, j, 0); g(b, j, 1); g(c, j, 2); } ndp2[0] = max(ndp2[0], max(dp2[1], dp2[2]) + a * (ll)(n - i)); ndp2[1] = max(ndp2[1], max(dp2[0], dp2[2]) + b * (ll)(n - i)); ndp2[2] = max(ndp2[2], max(dp2[0], dp2[1]) + c * (ll)(n - i)); swap(dp, ndp); swap(dp2, ndp2); } cout << *max_element(dp2.begin(), dp2.end()) << '\n'; }