#include #include constexpr int INF = 1 << 30; void solve() { int n; std::cin >> n; std::vector dp(2, -INF); dp[0] = 0; auto ndp = dp; while (n--) { std::vector ps(2); for (auto& p : ps) std::cin >> p; std::fill(ndp.begin(), ndp.end(), -INF); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { ndp[j] = std::max(ndp[j], dp[i] + ps[j] * (i ? 2 : 1)); } } std::swap(dp, ndp); } std::cout << dp[0] << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }