import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n == 1) { System.out.println(Math.min(sc.nextLong(), sc.nextLong())); return; } int n1 = n / 2; int n2 = n - n1; long[][] arr1 = new long[n1][2]; for (int i = 0; i < n1; i++) { arr1[i][0] = sc.nextLong(); arr1[i][1] = -sc.nextLong(); } long[][] arr2 = new long[n2][2]; for (int i = 0; i < n2; i++) { arr2[i][0] = sc.nextLong(); arr2[i][1] = -sc.nextLong(); } TreeSet result1 = new TreeSet<>(); for (int i = 0; i < (1 << n1); i++) { long ans = 0; int x = i; for (int j = 0; j < n1; j++) { ans += arr1[j][x % 2]; x >>= 1; } result1.add(ans); } TreeSet result2 = new TreeSet<>(); for (int i = 0; i < (1 << n2); i++) { long ans = 0; int x = i; for (int j = 0; j < n2; j++) { ans += arr2[j][x % 2]; x >>= 1; } result2.add(ans); } long ans = Long.MAX_VALUE; for (long x : result1) { Long ciel = result2.ceiling(-x); if (ciel != null) { ans = Math.min(ans, Math.abs(ciel + x)); } Long floor = result2.floor(-x); if (floor != null) { ans = Math.min(ans, Math.abs(x + floor)); } } System.out.println(ans); } }