let n = read_int ()
let h n = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ps = h n
let qs, ns, fs, c, a, b = Array.(h n, make n 0, make n false, ref 0, ref 0, ref 0)
let g a r = if !r = 0 && a = ns then r := !c
let rec f i = if i >= n then (incr c; g ps a; g qs b; if !a * !b > 0 then (Printf.printf "%d\n" @@ abs (!a - !b); exit 0))
  else for j = 0 to n - 1 do if not fs.(j) then (fs.(j) <- true; ns.(i) <- j + 1; f (i + 1); fs.(j) <- false) done
let _ = f 0