private static int dfs ( int pos , int num ) {
  if ( num == 0 ) {
    return 0 ;
  }
  if ( dp [ pos ] [ num ] >= 0 ) {
    return dp [ pos ] [ num ] ;
  }
  int move = 0 ;
  if ( num > G + B ) {
    move = Math . abs ( SIZE / 2 - 100 - pos ) ;
  }
  else if ( num > B ) {
    move = Math . abs ( SIZE / 2 - pos ) ;
  }
  else if ( num > 0 ) {
    move = Math . abs ( SIZE / 2 + 100 - pos ) ;
  }
  if ( pos >= SIZE - num ) {
    dp [ pos ] [ num ] = dfs ( pos + 1 , num - 1 ) + move ;
  }
  else {
    dp [ pos ] [ num ] = Math . min ( dfs ( pos + 1 , num ) , dfs ( pos + 1 , num - 1 ) + move ) ;
  }
  return dp [ pos ] [ num ] ;
}

private static int dfs ( int pos , int num ) { if ( num == 0 ) { return 0 ; } if ( dp [ pos ] [ num ] >= 0 ) { return dp [ pos ] [ num ] ; } int move = 0 ; if ( num > G + B ) { move = Math . abs ( SIZE / 2 - 100 - pos ) ; } else if ( num > B ) { move = Math . abs ( SIZE / 2 - pos ) ; } else if ( num > 0 ) { move = Math . abs ( SIZE / 2 + 100 - pos ) ; } if ( pos >= SIZE - num ) { dp [ pos ] [ num ] = dfs ( pos + 1 , num - 1 ) + move ; } else { dp [ pos ] [ num ] = Math . min ( dfs ( pos + 1 , num ) , dfs ( pos + 1 , num - 1 ) + move ) ; } return dp [ pos ] [ num ] ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (return_statement (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal)) right: (identifier))))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (identifier))))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal)) right: (identifier)))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (identifier))))) alternative: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))) (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (identifier)))))))) (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))