public static void main ( String [ ] args ) {
  Scanner s = new Scanner ( System . in ) ;
  int n = s . nextInt ( ) ;
  int m = s . nextInt ( ) ;
  s . nextLine ( ) ;
  String a [ ] = new String [ n ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) a [ i ] = s . nextLine ( ) ;
  int b [ ] = new int [ m ] ;
  for ( int j = 0 ;
  j < m ;
  j ++ ) b [ j ] = s . nextInt ( ) ;
  HashMap < Character , Integer > h1 = new HashMap < > ( ) ;
  h1 . put ( 'A' , 0 ) ;
  h1 . put ( 'B' , 1 ) ;
  h1 . put ( 'C' , 2 ) ;
  h1 . put ( 'D' , 3 ) ;
  h1 . put ( 'E' , 4 ) ;
  int r [ ] = new int [ 5 ] ;
  int r1 [ ] = new int [ m ] ;
  int p = 0 ;
  for ( int k = 0 ;
  k < m ;
  k ++ ) {
    for ( int k1 = 0 ;
    k1 < n ;
    k1 ++ ) {
      int u = h1 . get ( a [ k1 ] . charAt ( k ) ) ;
      r [ u ] = r [ u ] + 1 ;
    }
    r1 [ k ] = max ( r ) ;
    for ( int g = 0 ;
    g < 5 ;
    g ++ ) r [ g ] = 0 ;
  }
  int sum = 0 ;
  for ( p = 0 ;
  p < m ;
  p ++ ) {
    sum = sum + ( r1 [ p ] * b [ p ] ) ;
  }
  System . out . println ( sum ) ;
}

public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int m = s . nextInt ( ) ; s . nextLine ( ) ; String a [ ] = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = s . nextLine ( ) ; int b [ ] = new int [ m ] ; for ( int j = 0 ; j < m ; j ++ ) b [ j ] = s . nextInt ( ) ; HashMap < Character , Integer > h1 = new HashMap < > ( ) ; h1 . put ( ' A ' , 0 ) ; h1 . put ( ' B ' , 1 ) ; h1 . put ( ' C ' , 2 ) ; h1 . put ( ' D ' , 3 ) ; h1 . put ( ' E ' , 4 ) ; int r [ ] = new int [ 5 ] ; int r1 [ ] = new int [ m ] ; int p = 0 ; for ( int k = 0 ; k < m ; k ++ ) { for ( int k1 = 0 ; k1 < n ; k1 ++ ) { int u = h1 . get ( a [ k1 ] . charAt ( k ) ) ; r [ u ] = r [ u ] + 1 ; } r1 [ k ] = max ( r ) ; for ( int g = 0 ; g < 5 ; g ++ ) r [ g ] = 0 ; } int sum = 0 ; for ( p = 0 ; p < m ; p ++ ) { sum = sum + ( r1 [ p ] * b [ p ] ) ; } System . out . println ( sum ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) 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)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (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: (identifier)) update: (update_expression (identifier)) body: (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) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (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: (identifier)) update: (update_expression (identifier)) body: (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: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal) (decimal_integer_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal) (decimal_integer_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal) (decimal_integer_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal) (decimal_integer_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (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: (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 (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: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation 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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))