// // じょえチャンネル // 高評価・チャンネル登録よろしくお願いします! // https://www.youtube.com/watch?v=gPFr7q7eLL8 // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair #define sz(x) (ll)x.size() #define ALL(x) (x).begin(),(x).end() #define ALLR(x) (x).rbegin(),(x).rend() #define VE vector #define COUT(x) cout<<(x)< #define SE set #define PQ priority_queue #define PQR priority_queue> #define COUT(x) cout<<(x)<; struct mint { ll x; // typedef long long ll; mint(ll x = 0) :x((x%MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; struct combination { vector fact, ifact; combination(int n) :fact(n + 1), ifact(n + 1) { //assert(n < MOD); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; struct edge { ll to, cost; }; ll gcd(ll a, ll b) { if (a < b)swap(a, b); if (b == 0) return a; unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n%i == 0)return false; } return n != 1; } map prime_factor(ll n) { map ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector> RunLength(string s) { if (s.size() == 0)return {}; vector>res(1, pair(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1)cnt++; n /= 2; } return cnt; } mint POW(mint n, int p) { if (p == 0)return 1; if (p % 2 == 0) { mint t = POW(n, p / 2); return t * t; } return n * POW(n, p - 1); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //cout << fixed << setprecision(15); int n; cin >> n; VE a(2 * n); rep(i, 2 * n)cin >> a[i]; int now = 0; int ans = 0; VE tmp(n); rep(i, n) { tmp[i]=a[now] - a[now + 1]; now += 2; } VE l(n + 1); l[0] = 0; rep(i, n)l[i + 1] = l[i] + tmp[i]; rep(i, n)tmp[i] *= -1; VE r(n + 1); r[n] = 0; for (int i = n - 1; i >= 0; i--) { r[i]=r[i+1]+tmp[i]; } rep(i, n) { chmax(ans, l[i] + r[i]); } cout << ans << endl; return 0; }