#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef vector VVL; typedef pair P; typedef pair PL; VL rekkyo(VL a, VL b){ int n = a.size(); VL ret; REP(i,1<> j) & 1){ x1 += a[j]; }else{ x2 += b[j]; } } ret.push_back(x1-x2); } sort(ALL(ret)); return ret; } int main() { int n; cin >> n; VL a1, b1, a2, b2; REP(i,n){ ll a, b; cin >> a >> b; if (i % 2){ a2.push_back(a); b2.push_back(b); }else{ a1.push_back(a); b1.push_back(b); } } if (n == 1){ cout << min(a1[0], b1[0]) << endl; return 0; } VL d1 = rekkyo(a1, b1), d2 = rekkyo(a2, b2); // REP(i,d1.size()) cout << d1[i] << " "; // cout << endl; // REP(i,d2.size()) cout << d2[i] << " "; // cout << endl; ll ans = 1e18; int j = d2.size() - 1; REP(i,d1.size()){ while (j > 0 && d1[i] + d2[j] > 0) j--; ans = min(ans, abs(d1[i] + d2[j])); if (j + 1 < d2.size()) ans = min(ans, abs(d1[i] + d2[j+1])); } cout << ans << endl; return 0; }