#P1157. All Combinations

    ID: 13661 Type: Default 1000ms 256MiB

All Combinations

All Combinations

Given two integers n and r, output all combinations of choosing r numbers from the set {1, 2, ..., n} (order does not matter). Each combination should display the selected numbers concatenated in increasing order.

For example, when n = 5 and r = 3, the output should be:

123
124
125
134
135
145
234
235
245
345

Note: The mathematical formulation for combinations is given by the binomial coefficient \(\binom{n}{r}\) and the output should list all valid combinations in lexicographical order.

inputFormat

The input consists of a single line containing two space-separated integers n and r where 1 ≤ r ≤ n.

outputFormat

Output each valid combination on a new line. Each combination is printed as a concatenation of digits in increasing order.

sample

5 3
123

124 125 134 135 145 234 235 245 345

</p>