let n, ans = read_int (), ref min_int
let fs = Array.(init n @@ fun _ -> init 5 @@ fun _ -> init 2 @@ fun _ -> Scanf.scanf " %d" (+) 0)
let ps = Array.(init n @@ fun _ -> init 11 @@ fun _ -> Scanf.scanf " %d" (+) 0)
let g b w d = (d + (b lsr w) land 1) / 2
let f b = Array.(fold_left (fun (s, i) f -> s + ps.(i).(fst @@ fold_left (fun (c, w) d -> c + g (b land 31) w d.(0) + g (b lsr 5) w d.(1), w + 1) (0, 0) f), i + 1) (0, 0) fs) |> fst
let _ = for i = 1 to 1 lsl 10 - 1 do ans := max !ans @@ f i done; Printf.printf "%d\n" !ans