#include using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) template bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; int N; vector A,B; const ll INF = 1e18; int main() { scanf("%d",&N); A.assign(N,0); B.assign(N,0); FOR(i,0,N){ scanf("%lld%lld",&A [i],&B [i]); } int half = N / 2; vector v; FOR(mask,0,1 << half){ ll sum = 0; FOR(i,0,half){ if(mask >> i & 1){ sum += A [i]; } else{ sum -= B [i]; } } v.push_back(sum); } sort(v.begin(),v.end()); ll ans = INF; FOR(mask,0,1 << (N - half)){ ll sum = 0; FOR(i,0,(N - half)){ if(mask >> i & 1){ sum += A [i + half]; } else{ sum -= B [i + half]; } } auto it = lower_bound(v.begin(),v.end(),-sum); if(it != v.end()){ chmin(ans,abs(sum + *it)); } if(it != v.begin()){ chmin(ans,abs(sum + *(--it))); } } printf("%lld\n",ans); return 0; }