import std; void main() { int N; readf("%d\n", N); auto p = new long[](N), a = new long[](N); foreach (i; 0 .. N) { readf("%d %d\n", p[i], a[i]); } auto dp = new long[](N+1); foreach (i; 0 .. N) { dp[i+1] = dp[i] + p[i]; if (i > 0) dp[i+1] = max(dp[i+1], dp[i-1]+a[i-1]+p[i]*2); } dp[N].writeln; }