#include using namespace std; const int64_t INF = INT64_C(1) << 60; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } vector D = {-INF, INF}; int a = N / 2, b = N - a; for (int bit = 0; bit < (1 << a); bit++) { int64_t diff = 0; for (int i = 0; i < a; i++) { if ((bit >> i) & 1) { diff += A[i]; } else { diff -= B[i]; } } D.emplace_back(diff); } sort(D.begin(), D.end()); int64_t res = INF; for (int bit = 0; bit < (1 << b); bit++) { int64_t diff = 0; for (int i = 0; i < b; i++) { if ((bit >> i) & 1) { diff += A[i + a]; } else { diff -= B[i + a]; } } int i = upper_bound(D.begin(), D.end(), -diff) - D.begin(); res = min(res, abs(diff + D[i])); res = min(res, abs(diff + D[i - 1])); } cout << res << '\n'; return 0; }