let (>>=) xs f = List.map f xs |> List.concat
let rec replicate_m n xs =
  if n <= 0 then [[]]
  else replicate_m (n-1) xs >>= fun xs' -> List.map (fun y -> y :: xs') xs

let () =
  Scanf.scanf "%d" @@ fun n ->
  let f = Array.init n (fun _ -> Array.init 10 (fun _ -> Scanf.scanf " %d" ((=) 1))) in
  let p = Array.init n (fun _ -> Array.init 11 (fun _ -> Scanf.scanf " %d" (fun x -> x))) in
  replicate_m 10 [false; true] |> List.tl
  |> List.map (fun scheds ->
      f |> Array.mapi (fun i scheds' ->
        let dups =
          scheds |> List.mapi (fun j v -> if v && scheds'.(j) then 1 else 0)
          |> List.fold_left (+) 0
        in p.(i).(dups))
      |> Array.fold_left (+) 0)
  |> List.fold_left max (-10101010101010)
  |> Printf.printf "%d\n"