static int find_n ( int [ ] a ) {
  int j = 0 , k = 0 , s = 0 ;
  int x = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;
  int y = Arrays . stream ( a ) . min ( ) . getAsInt ( ) ;
  for ( int i : a ) {
    if ( a [ i ] == x ) {
      s = i ;
      break ;
    }
  }
  for ( int i : a ) {
    if ( i != x && i <= y && i != 0 ) {
      a [ j ] += 1 ;
      a [ s ] -= 1 ;
      x -= 1 ;
      k += 1 ;
      j += 1 ;
    }
    else if ( i != 0 ) {
      j += 1 ;
    }
  }
  for ( int i : a ) {
    if ( a [ i ] != x ) {
      k = - 1 ;
      break ;
    }
  }
  return k ;
}

static int find_n ( int [ ] a ) { int j = 0 , k = 0 , s = 0 ; int x = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ; int y = Arrays . stream ( a ) . min ( ) . getAsInt ( ) ; for ( int i : a ) { if ( a [ i ] == x ) { s = i ; break ; } } for ( int i : a ) { if ( i != x && i <= y && i != 0 ) { a [ j ] += 1 ; a [ s ] -= 1 ; x -= 1 ; k += 1 ; j += 1 ; } else if ( i != 0 ) { j += 1 ; } } for ( int i : a ) { if ( a [ i ] != x ) { k = - 1 ; break ; } } return k ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (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))) (break_statement))))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (identifier) right: (identifier))) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))))))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (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: (unary_expression operand: (decimal_integer_literal)))) (break_statement))))) (return_statement (identifier))))