static int minimumMulitplications ( int start , int end , int a [ ] , int n ) {
  int ans [ ] = new int [ 100001 ] ;
  Arrays . fill ( ans , - 1 ) ;
  int mod = 100000 ;
  Queue < Integer > q = new LinkedList < > ( ) ;
  q . add ( start % mod ) ;
  ans [ start ] = 0 ;
  while ( ! q . isEmpty ( ) ) {
    int top = q . peek ( ) ;
    q . remove ( ) ;
    if ( top == end ) {
      return ans [ end ] ;
    }
    for ( int i = 0 ;
    i < n ;
    i ++ ) {
      int pushed = top * a [ i ] ;
      pushed = pushed % mod ;
      if ( ans [ pushed ] == - 1 ) {
        ans [ pushed ] = ans [ top ] + 1 ;
        q . add ( pushed ) ;
      }
    }
  }
  return - 1 ;
}

static int minimumMulitplications ( int start , int end , int a [ ] , int n ) { int ans [ ] = new int [ 100001 ] ; Arrays . fill ( ans , - 1 ) ; int mod = 100000 ; Queue < Integer > q = new LinkedList < > ( ) ; q . add ( start % mod ) ; ans [ start ] = 0 ; while ( ! q . isEmpty ( ) ) { int top = q . peek ( ) ; q . remove ( ) ; if ( top == end ) { return ans [ end ] ; } for ( int i = 0 ; i < n ; i ++ ) { int pushed = top * a [ i ] ; pushed = pushed % mod ; if ( ans [ pushed ] == - 1 ) { ans [ pushed ] = ans [ top ] + 1 ; q . add ( pushed ) ; } } } return - 1 ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (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) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (unary_expression operand: (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (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 (binary_expression left: (identifier) right: (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (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))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (return_statement (array_access array: (identifier) index: (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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))))) (return_statement (unary_expression operand: (decimal_integer_literal)))))