#include "bits/stdc++.h" using namespace std; setget_all(vector>v) { setaset; for (int i = 0; i < (1 << v.size()); ++i) { bitset<20>bs(i); long long int sum = 0; for (int j = 0; j < v.size(); ++j) { if (bs[j])sum += v[j].first; else sum -= v[j].second; } aset.emplace(sum); } return aset; } int main() { int N; cin >> N; vector>ds; for (int i = 0; i < N; ++i) { long long int a, b; cin >> a >> b; ds.emplace_back(a, b); } auto aset(get_all(vector>(ds.begin(), ds.begin() + N / 2))); auto bset(get_all(vector>(ds.begin() + N / 2, ds.end()))); long long int ans = 1e18; for (auto as : aset) { auto it = bset.lower_bound(-as); if (it != bset.end()) { ans = min(ans, abs(*it+ as)); } if (it != bset.begin()) { ans = min(ans, abs(*(prev(it))+ as)); } } cout << ans << endl; return 0; }