#include #define int long long using namespace std; using Graph = vector>; signed main(){ int N; cin >> N; vector A(2*N); for( int i = 0; i < 2*N; i++ ) cin >> A.at(i); vector right(N); vector left(N); for( int i = 0; i < N; i++ ){ left.at(i) = A.at(i*2)-A.at(i*2+1); if( i > 0 ) left.at(i) += left.at(i-1); } reverse(A.begin(), A.end()); for( int i = 0; i < N; i++ ){ right.at(i) = A.at(i*2)-A.at(i*2+1); if( i > 0 ) right.at(i) += right.at(i-1); } reverse(right.begin(), right.end()); /* for( int i = 0; i < N; i++ ) cout << left.at(i) << " "; cout << endl; for( int i = 0; i < N; i++ ) cout << right.at(i) << " "; cout << endl; */ //全部右からとった場合、全部左からとった場合 int ans = max(left.at(N-1), right.at(0)); for( int i = 0; i < N-1; i++ ){ int now = left.at(i)+right.at(i+1); ans = max(ans, now); } cout << ans << endl; }