#include #define DEBUG(C) cerr << #C << " = " << C << endl using namespace std; const int MAX = 44; int n; long long a[MAX], b[MAX]; const long long inf = 1e18; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld%lld", a + i, b + i); } long long ans = inf; for (unsigned i = 0; i < (1ll << n); i++) { long long asum = 0, bsum = 0; for (int j = 0; j < n; j++) { if (i & (1ll << j)) asum += a[j]; else bsum += b[j]; } ans = min(ans, llabs(asum - bsum)); } printf("%lld\n", ans); return 0; }