#C4990. K-Element Combinations

    ID: 48589 Type: Default 1000ms 256MiB

K-Element Combinations

K-Element Combinations

Given an array of integers and a positive integer (k), your task is to generate all possible combinations of (k) elements from the array. A combination is a subset of (k) numbers where the order does not matter. In other words, you need to list all the possible subsets of size (k) from the given numbers.

For example, if the input array is [1, 2, 3] and (k=2), then the possible combinations are: [ [1,2],\ [1,3],\ [2,3] ]

You can assume that the array does not contain duplicate elements. The output can be in any order as long as all valid combinations are presented.

inputFormat

The input is read from standard input (stdin) and consists of three lines:

  1. The first line contains an integer \(n\) representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers.
  3. The third line contains an integer \(k\) representing the subset size.

outputFormat

The output is printed to standard output (stdout). Each line corresponds to one combination. In each line, the numbers of the combination are printed in the order they appear in the input array, separated by a single space.

## sample
3
1 2 3
2
1 2

1 3 2 3

</p>