Scanf.scanf "%d" (fun n ->
    let f = Array.init n (fun _ ->
        Array.init 10 (fun _ -> Scanf.scanf " %d" (fun f -> f)))
    in
    let c = Array.init n (fun _ ->
        Array.init 11 (fun _ -> Scanf.scanf " %d" (fun f -> f)))
    in
    let calc arr bits =
        let rec loop i bits acc =
            if i = 10 then acc else
                let acc = acc + arr.(i) * (bits land 1) in
                loop (i + 1) (bits lsr 1) acc
        in
        loop 0 bits 0
    in
    let rec loop bits acc =
        if bits = 1024 then acc else
            let rec loop2 j acc =
                if j = n then acc else
                    let opens = calc f.(j) bits in
                    let acc = acc + c.(j).(opens) in
                    loop2 (j + 1) acc
            in
            let revenue = loop2 0 0 in
            loop (bits + 1) (max acc revenue)
    in
    loop 1 min_int |> Printf.printf "%d\n"
)