N = gets.to_i A, B = $<.map{|s| s.split.map &:to_i }.transpose $ans = 1.0/0 def f(a, b, i, used) if i >= N # p [a,b] ab = [a, b].max $ans = ab if ab < $ans return end f(a, b, i+1, used) if [a-A[i], b+B[i]].max <= [a, b].max && used & (1 << i) == 0 f(a-A[i], b+B[i], i+1, used) elsif [a+A[i], b-B[i]].max <= [a, b].max && used & (1 << i) != 0 f(a+A[i], b-B[i], i+1, used) end end ais, bis = N.times.partition{|i| A[i] < B[i] } asum = ais.map{|i| A[i] }.sum bsum = bis.map{|i| B[i] }.sum # p [ais, asum] # p [bis, bsum] used = bis.inject(0){|r, i| r | (1 << i) } f(asum, bsum, 0, used) p $ans