private static void doCase ( int caseNumber , Scanner sc , PrintWriter wr ) throws IOException {
  int P , K , L ;
  P = sc . nextInt ( ) ;
  K = sc . nextInt ( ) ;
  L = sc . nextInt ( ) ;
  int [ ] freq = new int [ L ] ;
  for ( int i = 0 ;
  i < L ;
  i ++ ) {
    freq [ i ] = sc . nextInt ( ) ;
  }
  Arrays . sort ( freq ) ;
  long result = 0 ;
  int keyPress = 1 ;
  int keyCounter = 0 ;
  for ( int i = L - 1 ;
  i >= 0 ;
  i -- ) {
    if ( ++ keyCounter > K ) {
      keyCounter = 1 ;
      keyPress ++ ;
    }
    result += freq [ i ] * keyPress ;
  }
  wr . println ( "Case #" + caseNumber + ": " + result ) ;
  System . out . println ( "Case #" + caseNumber + ": " + result ) ;
}

private static void doCase ( int caseNumber , Scanner sc , PrintWriter wr ) throws IOException { int P , K , L ; P = sc . nextInt ( ) ; K = sc . nextInt ( ) ; L = sc . nextInt ( ) ; int [ ] freq = new int [ L ] ; for ( int i = 0 ; i < L ; i ++ ) { freq [ i ] = sc . nextInt ( ) ; } Arrays . sort ( freq ) ; long result = 0 ; int keyPress = 1 ; int keyCounter = 0 ; for ( int i = L - 1 ; i >= 0 ; i -- ) { if ( ++ keyCounter > K ) { keyCounter = 1 ; keyPress ++ ; } result += freq [ i ] * keyPress ; } wr . println ( " Case ▁ # " + caseNumber + " : ▁ " + result ) ; System . out . println ( " Case ▁ # " + caseNumber + " : ▁ " + result ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) 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: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (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))) (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: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (update_expression (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier)))))))