private static int helper ( int [ ] arr , int v ) {
  int prev = 0 ;
  int count = 0 ;
  for ( int i = 1 ;
  i <= 3000 ;
  i ++ ) {
    int curr = v ;
    if ( prev >= v ) {
      count += curr ;
      prev = arr [ i ] ;
    }
    else {
      count += prev ;
      curr -= prev ;
      if ( arr [ i ] >= curr ) {
        count += curr ;
        prev = arr [ i ] - curr ;
      }
      else {
        count += arr [ i ] ;
        prev = 0 ;
      }
    }
  }
  if ( prev >= v ) {
    count += v ;
  }
  else {
    count += prev ;
  }
  return count ;
}

private static int helper ( int [ ] arr , int v ) { int prev = 0 ; int count = 0 ; for ( int i = 1 ; i <= 3000 ; i ++ ) { int curr = v ; if ( prev >= v ) { count += curr ; prev = arr [ i ] ; } else { count += prev ; curr -= prev ; if ( arr [ i ] >= curr ) { count += curr ; prev = arr [ i ] - curr ; } else { count += arr [ i ] ; prev = 0 ; } } } if ( prev >= v ) { count += v ; } else { count += prev ; } return count ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) 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))) (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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (return_statement (identifier))))