#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,k; cin>>n>>k; vector S(2*n); rep(i,2*n) cin>>S[i]; vector> C(2*n,vector(2*n)); vector A; int cnt=0; rep(i,2*n) rep(j,2*n){ cin>>C[i][j]; A.push_back(C[i][j]); if(S[i][j]=='#') cnt++; } sort(ALL(A)); reverse(ALL(A)); ll ans=0; rep(i,cnt) ans+=A[i]; if(cnt%2==0){ vector B; rep(i,2*n) rep(j,n) B.push_back(C[i][j]+C[i][2*n-1-j]); sort(ALL(B)); reverse(ALL(B)); ll tmp=k; rep(i,cnt/2) tmp+=B[i]; ans=max(ans,tmp); } cout<