public static void main ( String [ ] args ) {
  Scanner in = new Scanner ( System . in ) ;
  StringBuilder out = new StringBuilder ( ) ;
  int numCases = in . nextInt ( ) ;
  for ( int caseNum = 1 ;
  caseNum <= numCases ;
  ++ caseNum ) {
    out . append ( String . format ( "Case #%d: " , caseNum ) ) ;
    long maxEnergy = in . nextLong ( ) ;
    long currentEnergy = maxEnergy ;
    long regen = in . nextLong ( ) ;
    int numEvents = in . nextInt ( ) ;
    long [ ] values = new long [ numEvents ] ;
    for ( int i = 0 ;
    i < values . length ;
    ++ i ) values [ i ] = in . nextLong ( ) ;
    int curEvent = 0 ;
    long totalValue = 0 ;
    while ( curEvent != numEvents ) {
      int nextEvent = curEvent + 1 ;
      while ( nextEvent != numEvents && values [ nextEvent ] <= values [ curEvent ] ) ++ nextEvent ;
      if ( nextEvent == numEvents ) {
        totalValue += values [ curEvent ] * currentEnergy ;
        currentEnergy = 0 ;
      }
      else {
        long energyToLeave = Math . max ( maxEnergy - regen * ( nextEvent - curEvent ) , 0L ) ;
        if ( energyToLeave >= currentEnergy ) {
        }
        else {
          long energyToSpend = currentEnergy - energyToLeave ;
          totalValue += values [ curEvent ] * energyToSpend ;
          currentEnergy = energyToLeave ;
        }
      }
      currentEnergy += regen ;
      currentEnergy = Math . min ( currentEnergy , maxEnergy ) ;
      ++ curEvent ;
    }
    out . append ( totalValue ) ;
    out . append ( '\n' ) ;
  }
  System . out . print ( out ) ;
}

public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; StringBuilder out = new StringBuilder ( ) ; int numCases = in . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; ++ caseNum ) { out . append ( String . format ( " Case ▁ # % d : ▁ " , caseNum ) ) ; long maxEnergy = in . nextLong ( ) ; long currentEnergy = maxEnergy ; long regen = in . nextLong ( ) ; int numEvents = in . nextInt ( ) ; long [ ] values = new long [ numEvents ] ; for ( int i = 0 ; i < values . length ; ++ i ) values [ i ] = in . nextLong ( ) ; int curEvent = 0 ; long totalValue = 0 ; while ( curEvent != numEvents ) { int nextEvent = curEvent + 1 ; while ( nextEvent != numEvents && values [ nextEvent ] <= values [ curEvent ] ) ++ nextEvent ; if ( nextEvent == numEvents ) { totalValue += values [ curEvent ] * currentEnergy ; currentEnergy = 0 ; } else { long energyToLeave = Math . max ( maxEnergy - regen * ( nextEvent - curEvent ) , 0L ) ; if ( energyToLeave >= currentEnergy ) { } else { long energyToSpend = currentEnergy - energyToLeave ; totalValue += values [ curEvent ] * energyToSpend ; currentEnergy = energyToLeave ; } } currentEnergy += regen ; currentEnergy = Math . min ( currentEnergy , maxEnergy ) ; ++ curEvent ; } out . append ( totalValue ) ; out . append ( ' \n ' ) ; } System . out . print ( out ) ; }
(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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_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)))) (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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal) (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: (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: (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: (field_access object: (identifier) field: (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) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))))) body: (expression_statement (update_expression (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))))) (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (update_expression (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))