func_code_string: #include <bits/stdc++.h>   using namespace std;   inline bool read(int &x) {     char ch;     bool flag = false;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) flag = true;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     x = flag ? -x : x;     if (ch ==   n ) return 0;     return 1;   }   inline void write(int x) {     static const int maxlen = 100;     static char s[maxlen];     if (x < 0) {       putchar( - );       x = -x;     }     if (!x) {       putchar( 0 );       return;     }     int len = 0;     for (; x; x /= 10) s[len++] = x % 10 +  0 ;     for (int i = len - 1; i >= 0; --i) putchar(s[i]);   }   const int MAXN = 2500;   int n, lim;   int g[MAXN][MAXN];   char s[MAXN];   int f[MAXN][MAXN];   bool go_l[MAXN][MAXN], go_r[MAXN][MAXN];   bool go_up[MAXN][MAXN], go_down[MAXN][MAXN];   int add_l[MAXN][MAXN];   int add_h[MAXN][MAXN];   int sum_l[MAXN][MAXN];   int sum_h[MAXN][MAXN];   int main() {     read(n);     read(lim);     for (int i = 1; i <= n; i++) {       scanf( %s , s);       for (int j = 1; j <= n; j++)         if (s[j - 1] ==  B )           g[i][j] = 1;         else           g[i][j] = 0;     }     for (int i = 1; i <= n; i++) {       go_l[i][0] = 1;       for (int j = 1; j <= n; j++)         if ((go_l[i][j - 1]) && (g[i][j] == 0))           go_l[i][j] = 1;         else           go_l[i][j] = 0;       go_r[i][n + 1] = 1;       for (int j = n; j >= 1; j--)         if ((go_r[i][j + 1]) && (g[i][j] == 0))           go_r[i][j] = 1;         else           go_r[i][j] = 0;       for (int j = 1; j <= n - lim + 1; j++)         if (go_l[i][j - 1] && go_r[i][j + lim] && (!go_r[i][1]))           add_h[i][j] = 1;         else           add_h[i][j] = 0;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) sum_h[i][j] = sum_h[i - 1][j] + add_h[i][j];     for (int j = 1; j <= n; j++) {       go_up[0][j] = 1;       for (int i = 1; i <= n; i++)         if ((go_up[i - 1][j]) && (g[i][j] == 0))           go_up[i][j] = 1;         else           go_up[i][j] = 0;       go_down[n + 1][j] = 1;       for (int i = n; i >= 1; i--)         if ((go_down[i + 1][j]) && (g[i][j] == 0))           go_down[i][j] = 1;         else           go_down[i][j] = 0;       for (int i = 1; i <= n - lim + 1; i++)         if (go_up[i - 1][j] && go_down[i + lim][j] && (!go_down[1][j]))           add_l[i][j] = 1;         else           add_l[i][j] = 0;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) sum_l[i][j] = sum_l[i][j - 1] + add_l[i][j];     int tot = 0;     for (int i = 1; i <= n; i++)       if (go_r[i][1]) tot++;     for (int i = 1; i <= n; i++)       if (go_down[1][i]) tot++;     int ans = 0;     for (int i = 1; i <= n - lim + 1; i++)       for (int j = 1; j <= n - lim + 1; j++)         ans = max(ans, (sum_l[i][j + lim - 1] - sum_l[i][j - 1]) +                            (sum_h[i + lim - 1][j] - sum_h[i - 1][j]));     cout << ans + tot << endl;     return 0;   }   