static pair getMaxandMinProduct ( int arr [ ] , int n ) {
  int curMaxProduct = arr [ 0 ] ;
  int curMinProduct = arr [ 0 ] ;
  int prevMaxProduct = arr [ 0 ] ;
  int prevMinProduct = arr [ 0 ] ;
  int maxProduct = arr [ 0 ] ;
  int minProduct = arr [ 0 ] ;
  for ( int i = 1 ;
  i < n ;
  ++ i ) {
    curMaxProduct = Math . max ( prevMaxProduct * arr [ i ] , Math . max ( prevMinProduct * arr [ i ] , arr [ i ] ) ) ;
    curMaxProduct = Math . max ( curMaxProduct , prevMaxProduct ) ;
    curMinProduct = Math . min ( prevMaxProduct * arr [ i ] , Math . min ( prevMinProduct * arr [ i ] , arr [ i ] ) ) ;
    curMinProduct = Math . min ( curMinProduct , prevMinProduct ) ;
    maxProduct = Math . max ( maxProduct , curMaxProduct ) ;
    minProduct = Math . min ( minProduct , curMinProduct ) ;
    prevMaxProduct = curMaxProduct ;
    prevMinProduct = curMinProduct ;
  }
  return new pair ( minProduct , maxProduct ) ;
}

static pair getMaxandMinProduct ( int arr [ ] , int n ) { int curMaxProduct = arr [ 0 ] ; int curMinProduct = arr [ 0 ] ; int prevMaxProduct = arr [ 0 ] ; int prevMinProduct = arr [ 0 ] ; int maxProduct = arr [ 0 ] ; int minProduct = arr [ 0 ] ; for ( int i = 1 ; i < n ; ++ i ) { curMaxProduct = Math . max ( prevMaxProduct * arr [ i ] , Math . max ( prevMinProduct * arr [ i ] , arr [ i ] ) ) ; curMaxProduct = Math . max ( curMaxProduct , prevMaxProduct ) ; curMinProduct = Math . min ( prevMaxProduct * arr [ i ] , Math . min ( prevMinProduct * arr [ i ] , arr [ i ] ) ) ; curMinProduct = Math . min ( curMinProduct , prevMinProduct ) ; maxProduct = Math . max ( maxProduct , curMaxProduct ) ; minProduct = Math . min ( minProduct , curMinProduct ) ; prevMaxProduct = curMaxProduct ; prevMinProduct = curMinProduct ; } return new pair ( minProduct , maxProduct ) ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (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 (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) (array_access array: (identifier) index: (identifier)))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) (array_access array: (identifier) index: (identifier)))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (return_statement (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier) (identifier))))))