let ans, n = ref min_int, read_int ()
let h m = Array.(init n @@ fun _ -> init m @@ fun _ -> Scanf.scanf " %d" (+) 0)
let fss = h 10
let pss = h 11
let f i j b = (b lsr (2 * i + j)) land 1
let c n b = let s = ref 0 in for i = 0 to 4 do for j = 0 to 1 do s := !s + fss.(n).(i * 2 + j) * f i j b done done; !s
let g b = let p = ref 0 in for i = 0 to n - 1 do p := !p + pss.(i).(c i b) done; !p
let _ = for b = 1 to 1 lsl 10 - 1 do ans := max !ans @@ g b done; Printf.printf "%d\n" !ans