public static void main ( String args [ ] ) {
  Scanner sc = new Scanner ( System . in ) ;
  int n = sc . nextInt ( ) ;
  int m = sc . nextInt ( ) ;
  int A [ ] = new int [ m ] ;
  String S [ ] = new String [ n ] ;
  sc . nextLine ( ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    S [ i ] = sc . nextLine ( ) ;
  }
  for ( int i = 0 ;
  i < m ;
  i ++ ) {
    A [ i ] = sc . nextInt ( ) ;
  }
  int score = 0 ;
  for ( int i = 0 ;
  i < m ;
  i ++ ) {
    int frequency = 0 ;
    int acount = 0 , bcount = 0 , ccount = 0 , dcount = 0 , ecount = 0 ;
    for ( int j = 0 ;
    j < n ;
    j ++ ) {
      char ch = S [ j ] . charAt ( i ) ;
      switch ( ch ) {
        case 'A' : acount ++ ;
        break ;
        case 'B' : bcount ++ ;
        break ;
        case 'C' : ccount ++ ;
        break ;
        case 'D' : dcount ++ ;
        break ;
        case 'E' : ecount ++ ;
        break ;
        default : frequency = 0 ;
      }
    }
    frequency = Math . max ( acount , Math . max ( bcount , Math . max ( ccount , Math . max ( dcount , ecount ) ) ) ) ;
    score += A [ i ] * frequency ;
  }
  System . out . println ( score ) ;
}

public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int A [ ] = new int [ m ] ; String S [ ] = new String [ n ] ; sc . nextLine ( ) ; for ( int i = 0 ; i < n ; i ++ ) { S [ i ] = sc . nextLine ( ) ; } for ( int i = 0 ; i < m ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } int score = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int frequency = 0 ; int acount = 0 , bcount = 0 , ccount = 0 , dcount = 0 , ecount = 0 ; for ( int j = 0 ; j < n ; j ++ ) { char ch = S [ j ] . charAt ( i ) ; switch ( ch ) { case ' A ' : acount ++ ; break ; case ' B ' : bcount ++ ; break ; case ' C ' : ccount ++ ; break ; case ' D ' : dcount ++ ; break ; case ' E ' : ecount ++ ; break ; default : frequency = 0 ; } } frequency = Math . max ( acount , Math . max ( bcount , Math . max ( ccount , Math . max ( dcount , ecount ) ) ) ) ; score += A [ i ] * frequency ; } System . out . println ( score ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) 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: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (identifier))))) (switch_expression condition: (parenthesized_expression (identifier)) body: (switch_block (switch_block_statement_group (switch_label (character_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (character_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (character_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (character_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (character_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))