#include void chmax(long long *a, long long b) { if (*a < b) *a = b; } int main() { int i, N, A[5001][3]; scanf("%d", &N); for (i = 1; i <= N; i++) scanf("%d %d %d", &(A[i][0]), &(A[i][1]), &(A[i][2])); int j, cur, prev; long long dp[2][3] = {}, tmp[3]; for (i = 1, cur = 1, prev = 0; i <= N; i++, cur ^= 1, prev ^= 1) { dp[cur][0] = 0; dp[cur][1] = 0; dp[cur][2] = 0; for (j = i, tmp[0] = 0, tmp[1] = 0, tmp[2] = 0; j <= N; j++) { tmp[0] += A[i][0]--; tmp[1] += A[i][1]--; tmp[2] += A[i][2]--; if (A[i][0] < 0) A[i][0] = 0; if (A[i][1] < 0) A[i][1] = 0; if (A[i][2] < 0) A[i][2] = 0; } chmax(&(dp[cur][0]), dp[prev][1] + tmp[0]); chmax(&(dp[cur][0]), dp[prev][2] + tmp[0]); chmax(&(dp[cur][1]), dp[prev][0] + tmp[1]); chmax(&(dp[cur][1]), dp[prev][2] + tmp[1]); chmax(&(dp[cur][2]), dp[prev][0] + tmp[2]); chmax(&(dp[cur][2]), dp[prev][1] + tmp[2]); } long long ans = 0; for (i = 0; i < 3; i++) chmax(&ans, dp[prev][i]); printf("%lld\n", ans); fflush(stdout); return 0; }