func_code_string: #include <bits/stdc++.h>   using namespace std;   int c[160][160];   int lowbit(int x) { return x & -x; }   int sum(int x, int y) {     int ans = 0;     for (int i = x; i; i -= lowbit(i)) {       for (int j = y; j; j -= lowbit(j)) {         ans += c[i][j];       }     }     return ans;   }   void add(int x, int y, int v) {     for (int i = x; i < 160; i += lowbit(i)) {       for (int j = y; j < 160; j += lowbit(j)) {         c[i][j] += v;       }     }   }   char grid[160][160];   int dp[2][160][160];   int n, m, ans;   void dfs(int x, int y, int id) {     if (grid[x][y] ==  W ) {       add(x, y, -1);     }     if (sum(n, m) == 0) return;     if (id == 1) {       if (x + 1 <= n && y + 1 <= m) {         int tmp = sum(x + 1, m) - sum(x + 1, y);         if (x - 1 > 0) tmp = tmp - sum(x - 1, m) + sum(x - 1, y);         if (tmp > 0)           dfs(x, y + 1, 1);         else           dfs(x + 1, y, 0);       } else if (x + 1 > n && y + 1 <= m) {         int tmp = sum(x, m) - sum(x, y);         if (x - 1 > 0) tmp = tmp - sum(x - 1, m) + sum(x - 1, y);         if (tmp > 0)           dfs(x, y + 1, 1);         else           dfs(x + 1, y, 0);       } else {         dfs(x + 1, y, 0);       }     } else {       if (x + 1 <= n && y - 1 > 0) {         int tmp = sum(x + 1, y - 1);         if (tmp > 0)           dfs(x, y - 1, 0);         else           dfs(x + 1, y, 1);       } else if (x + 1 > n && y - 1 > 0) {         int tmp = sum(x, y - 1);         if (tmp > 0)           dfs(x, y - 1, 0);         else           dfs(x + 1, y, 1);       } else         dfs(x + 1, y, 1);     }     ans++;   }   int main() {     setvbuf(stdout, NULL, _IONBF, 0);     while (scanf(  %d %d , &n, &m) == 2) {       for (int i = 1; i <= n; i++) {         scanf(  %s , grid[i] + 1);       }       memset(c, 0, sizeof(c));       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (grid[i][j] ==  W ) {             add(i, j, 1);           }         }       }       ans = 0;       dfs(1, 1, 1);       printf( %d n , ans);     }     return 0;   }   