local n, k = io.read("*n", "*n", "*l") k = k * 1LL local hn = n n = n * 2 local t = {} local cnt = 0 for i = 1, n do local s = io.read() t[i] = {} for j = 1, n do if s:sub(j, j) == "#" then cnt = cnt + 1 end end end local c = {} local a = {} for i = 1, n do c[i] = {} for j = 1, n do c[i][j] = io.read("*n") * 1LL table.insert(a, c[i][j]) end end table.sort(a) local ans1 = 0LL for i = #a, #a + 1 - cnt, -1 do ans1 = ans1 + a[i] end -- print(ans1) if cnt % 2 == 0 then a = {} for i = 1, n do for j = 1, hn do table.insert(a, c[i][j] + c[i][n + 1 - j]) end end table.sort(a) local ans2 = k cnt = math.floor(cnt / 2) for i = #a, #a + 1 - cnt, -1 do ans2 = ans2 + a[i] end if ans1 < ans2 then ans1 = ans2 end end ans1 = tostring(ans1):gsub("LL", "") print(ans1)