#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
using namespace std;
#include <atcoder/modint>
using Modint = atcoder::static_modint<998244353>;

void testcase(){
    int N; cin >> N;
    vector<vector<i64>> A(N);
    rep(i,N){
        A[i].resize(3);
        rep(j,3) cin >> A[i][j];
    }
    vector<vector<i64>> dp(3, vector<i64>(N+1, -INF));
    rep(x,3) dp[x][0] = 0;
    i64 t_left = N;
    for(auto& a : A){
        vector<vector<i64>> nx(3, vector<i64>(N+1, -INF));
        rep(i,3){
            i64 b = a[i];
            rep(x,N){
                if(x+b >= N){
                    chmax(nx[i][N], dp[i][x] + (x+b) * t_left - (t_left * (t_left-1) / 2));
                } else {
                    chmax(nx[i][x+b], dp[i][x]);
                }
            }
            chmax(nx[i][N], dp[i][N] + b * t_left);
        }
        vector<vector<i64>> nx2(3, vector<i64>(N+1, -INF));
        rep(t,3) rep(s,3) if(s != t){
            chmax(nx2[t][0], nx[s][0]);
            rep(i,N-1) chmax(nx2[t][i], nx[s][i+1] + (i+1));
            chmax(nx2[t][N], nx[s][N]);
        }
        t_left--;
        swap(dp, nx2);
    }
    i64 ans = -INF;
    rep(j,3) rep(i,N+1) chmax(ans, dp[j][i]);
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}