public static long getCost ( ArrayList < String > list , char a , char b ) {
  long cost = 0 ;
  if ( a == b ) {
    for ( int i = 0 ;
    i < list . size ( ) ;
    i ++ ) {
      int count = 0 ;
      String cur = list . get ( i ) ;
      for ( int j = 0 ;
      j < cur . length ( ) ;
      j ++ ) {
        if ( cur . charAt ( j ) == a ) count ++ ;
        else {
          count = 0 ;
          break ;
        }
      }
      cost += count ;
    }
  }
  else {
    for ( int i = 0 ;
    i < list . size ( ) ;
    i ++ ) {
      int count = 0 ;
      String cur = list . get ( i ) ;
      for ( int j = 0 ;
      j < cur . length ( ) ;
      j ++ ) {
        if ( cur . charAt ( j ) == a || cur . charAt ( j ) == b ) count ++ ;
        else {
          count = 0 ;
          break ;
        }
      }
      cost += count ;
    }
  }
  return cost ;
}

public static long getCost ( ArrayList < String > list , char a , char b ) { long cost = 0 ; if ( a == b ) { for ( int i = 0 ; i < list . size ( ) ; i ++ ) { int count = 0 ; String cur = list . get ( i ) ; for ( int j = 0 ; j < cur . length ( ) ; j ++ ) { if ( cur . charAt ( j ) == a ) count ++ ; else { count = 0 ; break ; } } cost += count ; } } else { for ( int i = 0 ; i < list . size ( ) ; i ++ ) { int count = 0 ; String cur = list . get ( i ) ; for ( int j = 0 ; j < cur . length ( ) ; j ++ ) { if ( cur . charAt ( j ) == a || cur . charAt ( j ) == b ) count ++ ; else { count = 0 ; break ; } } cost += count ; } } return cost ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (generic_type (type_identifier) (type_arguments (type_identifier))) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (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: (identifier))) consequence: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) consequence: (expression_statement (update_expression (identifier))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (break_statement))))) (expression_statement (assignment_expression left: (identifier) right: (identifier)))))) alternative: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier)))) consequence: (expression_statement (update_expression (identifier))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (break_statement))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (return_statement (identifier))))