<awangdev>361. Bomb Enemy_1.java
public int maxKilledEnemies(char[][] grid) {
        if (grid == null || grid.length == 0 || grid[0].length == 0) {
            return 0;
        }
        int m = grid.length;
        int n = grid[0].length;
        int[][] up = new int[m][n];
        int[][] down = new int[m][n];
        int[][] left = new int[m][n];
        int[][] right = new int[m][n];
        
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] != 'W') {
                    up[i][j] = grid[i][j] == 'E' ? 1 : 0;
                    up[i][j] += i - 1 >= 0 ? up[i - 1][j] : 0;
                }
            }
        }

        for (int i = m - 1; i >= 0; i--) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] != 'W') {
                    down[i][j] = grid[i][j] == 'E' ? 1 : 0;
                    down[i][j] += i + 1 < m ? down[i + 1][j] : 0;                    
                }
            }
        }
        
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] != 'W') {
                    left[i][j] = grid[i][j] == 'E' ? 1 : 0;
                    left[i][j] += j - 1 >= 0 ? left[i][j - 1] : 0;
                }
            }
        }

        for (int i = 0; i < m; i++) {
            for (int j = n - 1; j >= 0; j--) {
                if (grid[i][j] != 'W') {
                    right[i][j] = grid[i][j] == 'E' ? 1 : 0;
                    right[i][j] += j + 1 < n ? right[i][j + 1] : 0;
                }
            }
        }
        
        
        int max = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] == '0') {
                    max = Math.max(max, up[i][j] + down[i][j] + left[i][j] + right[i][j]);
                }
            }   
        }
        return max;
    }
public int sample_funcname ( char [ ] [ ] var_0 ) {
  if ( var_0 == null || var_0 . length == 0 || var_0 [ 0 ] . length == 0 ) {
    return 0 ;
  }
  int var_4 = var_0 . length ;
  int var_5 = var_0 [ 0 ] . length ;
  int [ ] [ ] var_6 = new int [ var_4 ] [ var_5 ] ;
  int [ ] [ ] var_7 = new int [ var_4 ] [ var_5 ] ;
  int [ ] [ ] var_8 = new int [ var_4 ] [ var_5 ] ;
  int [ ] [ ] var_9 = new int [ var_4 ] [ var_5 ] ;
  for ( int var_10 = 0 ;
  var_10 < var_4 ;
  var_10 ++ ) {
    for ( int var_11 = 0 ;
    var_11 < var_5 ;
    var_11 ++ ) {
      if ( var_0 [ var_10 ] [ var_11 ] != 'W' ) {
        var_6 [ var_10 ] [ var_11 ] = var_0 [ var_10 ] [ var_11 ] == 'E' ? 1 : 0 ;
        var_6 [ var_10 ] [ var_11 ] += var_10 - 1 >= 0 ? var_6 [ var_10 - 1 ] [ var_11 ] : 0 ;
      }
    }
  }
  for ( int var_10 = var_4 - 1 ;
  var_10 >= 0 ;
  var_10 -- ) {
    for ( int var_11 = 0 ;
    var_11 < var_5 ;
    var_11 ++ ) {
      if ( var_0 [ var_10 ] [ var_11 ] != 'W' ) {
        var_7 [ var_10 ] [ var_11 ] = var_0 [ var_10 ] [ var_11 ] == 'E' ? 1 : 0 ;
        var_7 [ var_10 ] [ var_11 ] += var_10 + 1 < var_4 ? var_7 [ var_10 + 1 ] [ var_11 ] : 0 ;
      }
    }
  }
  for ( int var_10 = 0 ;
  var_10 < var_4 ;
  var_10 ++ ) {
    for ( int var_11 = 0 ;
    var_11 < var_5 ;
    var_11 ++ ) {
      if ( var_0 [ var_10 ] [ var_11 ] != 'W' ) {
        var_8 [ var_10 ] [ var_11 ] = var_0 [ var_10 ] [ var_11 ] == 'E' ? 1 : 0 ;
        var_8 [ var_10 ] [ var_11 ] += var_11 - 1 >= 0 ? var_8 [ var_10 ] [ var_11 - 1 ] : 0 ;
      }
    }
  }
  for ( int var_10 = 0 ;
  var_10 < var_4 ;
  var_10 ++ ) {
    for ( int var_11 = var_5 - 1 ;
    var_11 >= 0 ;
    var_11 -- ) {
      if ( var_0 [ var_10 ] [ var_11 ] != 'W' ) {
        var_9 [ var_10 ] [ var_11 ] = var_0 [ var_10 ] [ var_11 ] == 'E' ? 1 : 0 ;
        var_9 [ var_10 ] [ var_11 ] += var_11 + 1 < var_5 ? var_9 [ var_10 ] [ var_11 + 1 ] : 0 ;
      }
    }
  }
  int max = 0 ;
  for ( int var_10 = 0 ;
  var_10 < var_4 ;
  var_10 ++ ) {
    for ( int var_11 = 0 ;
    var_11 < var_5 ;
    var_11 ++ ) {
      if ( var_0 [ var_10 ] [ var_11 ] == '0' ) {
        max = Math . max ( max , var_6 [ var_10 ] [ var_11 ] + var_7 [ var_10 ] [ var_11 ] + var_8 [ var_10 ] [ var_11 ] + var_9 [ var_10 ] [ var_11 ] ) ;
      }
    }
  }
  return max ;
}
