using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); static string[] SList(int n) => Enumerable.Repeat(0, n).Select(_ => ReadLine()).ToArray(); static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k) = ((int)c[0], c[1]); n <<= 1; var b = 0; for (var i = 0; i < n; ++i) { b += ReadLine().Count(c => c == '#'); } var clist = new long[n * n]; var slist = new long[n * n / 2]; for (var i = 0; i < n; ++i) { c = NList; for (var j = 0; j < n; ++j) { clist[i * n + j] = c[j]; if (j < n / 2) slist[i * n / 2 + j] += c[j]; else slist[i * n / 2 + n - j - 1] += c[j]; } } Array.Sort(clist, (l, r) => r.CompareTo(l)); Array.Sort(slist, (l, r) => r.CompareTo(l)); var res = 0L; for (var i = 0; i < b; ++i) res += clist[i]; if (b % 2 == 0) { var sub = k; for (var i = 0; i < b / 2; ++i) sub += slist[i]; res = Math.Max(res, sub); } WriteLine(res); } }