static void printPermutations ( int n , int a [ ] , int k ) {
  pair arr [ ] = new pair [ n ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    arr [ i ] = new pair ( ) ;
    arr [ i ] . first = a [ i ] ;
    arr [ i ] . second = i ;
  }
  Arrays . sort ( arr , new sort ( ) ) ;
  int count = 1 ;
  for ( int i = 1 ;
  i < n ;
  i ++ ) if ( arr [ i ] . first == arr [ i - 1 ] . first ) count ++ ;
  if ( count < k ) {
    System . out . print ( "-1" ) ;
    return ;
  }
  for ( int i = 0 ;
  i < k - 1 ;
  i ++ ) {
    printIndices ( n , arr ) ;
    for ( int j = 1 ;
    j < n ;
    j ++ ) {
      if ( arr [ j ] . first == arr [ j - 1 ] . first ) {
        pair t = arr [ j ] ;
        arr [ j ] = arr [ j - 1 ] ;
        arr [ j - 1 ] = t ;
        break ;
      }
    }
  }
  printIndices ( n , arr ) ;
}

static void printPermutations ( int n , int a [ ] , int k ) { pair arr [ ] = new pair [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = new pair ( ) ; arr [ i ] . first = a [ i ] ; arr [ i ] . second = i ; } Arrays . sort ( arr , new sort ( ) ) ; int count = 1 ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] . first == arr [ i - 1 ] . first ) count ++ ; if ( count < k ) { System . out . print ( " - 1" ) ; return ; } for ( int i = 0 ; i < k - 1 ; i ++ ) { printIndices ( n , arr ) ; for ( int j = 1 ; j < n ; j ++ ) { if ( arr [ j ] . first == arr [ j - 1 ] . first ) { pair t = arr [ j ] ; arr [ j ] = arr [ j - 1 ] ; arr [ j - 1 ] = t ; break ; } } } printIndices ( n , arr ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (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: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (type_identifier) 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: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (object_creation_expression type: (type_identifier) arguments: (argument_list))))) (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: (identifier)) update: (update_expression (identifier)) body: (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)) right: (field_access object: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) field: (identifier)))) consequence: (expression_statement (update_expression (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (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 (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)) right: (field_access object: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) field: (identifier)))) consequence: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier))) (break_statement))))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))))