
let () = Scanf.scanf "%d\n" @@ fun n ->
  let fss =
    Array.to_list @@ Array.init n @@ fun _ ->
      Array.init 10 @@ fun _ ->
        Scanf.scanf "%d " @@ fun f -> f in
  let pss =
    Array.to_list @@ Array.init n @@ fun _ ->
      Array.init 11 @@ fun _ -> Scanf.scanf "%d " @@ fun p -> p in
  Array.init 1023 (fun opening ->
    let opening = opening + 1 in
    List.map2 (fun fs ps ->
      ps.(Array.fold_left ( + ) 0
        (Array.mapi (fun i f ->
          if f = 1 && (opening land (1 lsl i)) <> 0 then 1 else 0) fs))) fss pss
    |> List.fold_left ( + ) 0)
  |> Array.fold_left max min_int
  |> Printf.printf "%d\n"
