#include using namespace std; typedef long long int64; int main() { int64 N, A[32], B[32]; cin >> N; for(int i = 0; i < N; i++) cin >> A[i] >> B[i]; int mid = N / 2; vector< int64 > st; for(int i = 0; i < 1 << mid; i++) { int64 beet = 0; for(int j = 0; j < mid; j++) { if((i >> j) & 1) beet += A[j]; else beet -= B[j]; } st.push_back(beet); } sort(begin(st), end(st)); st.erase(unique(begin(st), end(st)), end(st)); int64 ret = 1LL << 58; for(int i = 0; i < 1 << (N - mid); i++) { int64 beet = 0; for(int j = mid; j < N; j++) { if((i >> (j - mid)) & 1) beet += A[j]; else beet -= B[j]; } auto p = lower_bound(begin(st), end(st), -beet); if(end(st) != p) ret = min(ret, llabs(*p + beet)); if(begin(st) != p) ret = min(ret, llabs(*--p + beet)); } cout << ret << endl; }