#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define show(x) cout <<#x<<" = "<<(x)<P; const int MAX_N = 100005; int main() { int n; cin >> n; vector a(n),b(n); ll sm = 0; rep(i,n){ cin >> a[i] >> b[i]; } vector u; rep(i,(1 << n/2)){ ll res = 0; ll res2 = 0; rep(j,n/2){ if(i & (1 << j)){ res += a[j]; }else{ res2 += b[j]; } } u.pb(res-res2); } vector v; rep(i,(1 << (n+1)/2)){ ll res = 0; ll res2 = 0; rep(j,(n+1)/2){ if(i & (1 << j)){ res += a[n/2+j]; }else{ res2 += b[n/2+j]; } } v.pb(res2-res); } sort(all(v)); ll mn = (1LL << 60); rep(i,u.size()){ int id = lower_bound(all(v),u[i]) - v.begin(); if(id >= 1){ mn = min(mn,abs(u[i] - v[id-1])); } mn = min(mn,abs(u[i] - v[id])); } cout << mn << endl; return 0; }