#include #include #include #define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++) #define INF (1LL << 60) using namespace std; typedef long long ll; ll N; vector A[2], B[2]; int main(void) { cin >> N; REP(i, 0, N) { ll a, b; cin >> a >> b; A[i % 2].push_back(a); B[i % 2].push_back(b); } if(N == 1) cout << min(abs(A[0][0]), B[0][0]) << endl; else { vector v[2]; REP(g, 0, 2) { REP(i, 0, 1 << A[g].size()) { ll s = 0; REP(j, 0, A[g].size()) s += (i & (1 << j)) ? A[g][j] : -B[g][j]; v[g].push_back(s); } sort(v[g].begin(), v[g].end()); } ll ans = INF; REP(i, 0, v[0].size()) { int d = upper_bound(v[1].begin(), v[1].end(), -v[0][i]) - v[1].begin(); ans = min(ans, abs(v[0][i] + v[1][d])); if(d - 1 >= 0) ans = min(ans, abs(v[0][i] + v[1][d - 1])); } cout << ans << endl; } }