#include #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair; inline void chmax(ll& a, ll b) { if (a < b) a = b; } int main() { int n; cin >> n; vector a(n, vector(3)); rep(i, n)rep(j, 3) cin >> a[i][j]; vector dp(n, vector

(3)); rep(j, 3) { dp[0][j].first = a[0][j]; dp[0][j].second = max(0ll, a[0][j]-1); } for (int i = 1; i < n; ++i) { rep(j, 3)rep(k, 3) if (j != k) { ll now = dp[i-1][k].first + dp[i-1][k].second + a[i][j]; if (now > dp[i][j].first) { dp[i][j].first = now; dp[i][j].second = max(0ll, now-dp[i-1][k].first-1); } } } ll ans = 0; rep(j, 3) chmax(ans, dp[n-1][j].first); cout << ans << '\n'; return 0; }