import std; void main(){ auto a = readln.split.to!(long[]); auto N = a[0]; auto K = a[1]; long black = 0; for(auto i = 0; i < 2 * N; i++){ auto s = readln.chomp; black += s.count('#'); } long[][] C; for(auto i = 0; i < 2 * N; i++){ C ~= readln.split.to!(long[]); } //stderr.writeln(C); auto gr = greedy(C, black); //stderr.writeln(gr); auto sy = symmetry(C, black) + K; //stderr.writeln(sy); writeln(max(gr, sy)); } long greedy(long[][] c, long black){ auto a = c.join; a.sort!((x, y) => x > y); //stderr.writeln(a); return a[0 .. black].sum; } long symmetry(long[][] c, long black){ if(black % 2) return long.min; long[] a; for(auto i = 0; i < c.length; i++){ for(auto j = 0; j < c[i].length / 2; j++){ a ~= c[i][j] + c[i][$ - 1 - j]; } } a.sort!((x, y) => x > y); //stderr.writeln(a); return a[0 .. (black / 2)].sum; }