#include #include #include using namespace std; using ll = long long; using mint = atcoder::modint998244353; using maxt = atcoder::modint1000000007; struct power { ll damage, attack; }; int main() { int N; cin >> N; vector> A(N, vector(3)); for(vector &o : A) { for(ll &p : o) { cin >> p; } } vector> dp(N + 1, vector(3)); for(int i = 1; i <= N; i++) { dp.at(i).at(0).attack = max(dp.at(i - 1).at(1).attack, dp.at(i - 1).at(2).attack) + A.at(i - 1).at(0); dp.at(i).at(0).damage = max(dp.at(i - 1).at(1).damage, dp.at(i - 1).at(2).damage) + dp.at(i).at(0).attack; dp.at(i).at(1).attack = max(dp.at(i - 1).at(0).attack, dp.at(i - 1).at(2).attack) + A.at(i - 1).at(1); dp.at(i).at(1).damage = max(dp.at(i - 1).at(0).damage, dp.at(i - 1).at(2).damage) + dp.at(i).at(1).attack; dp.at(i).at(2).attack = max(dp.at(i - 1).at(0).attack, dp.at(i - 1).at(1).attack) + A.at(i - 1).at(2); dp.at(i).at(2).damage = max(dp.at(i - 1).at(0).damage, dp.at(i - 1).at(1).damage) + dp.at(i).at(2).attack; for(power &o : dp.at(i)) { if(o.attack > 0) { o.attack--; } } } cout << max(max(dp.at(N).at(0).damage, dp.at(N).at(1).damage), dp.at(N).at(2).damage) << endl; }