Under construction

Still being built. Things may change

N and M (3)

Interview

Time limit1sMemory limit512 MB

Summary
Print every length-M sequence from 1 to N in lexicographic order, allowing repeats.
Level

Easy3 of 10

Topics
Backtracking, Recursion, Brute force, Implementation
Solved
No attempts yet

Problem

You are given two natural numbers NN and MM. Write a program that finds every sequence of length MM formed by choosing MM numbers from the natural numbers 1 to NN.

The same number can be chosen more than once.

Input

The first line contains two natural numbers NN and MM, separated by a space. (1≤M≤N≤71 \le M \le N \le 7)

Output

Print one sequence that satisfies the condition per line. Separate the elements of each sequence with a space.

Do not print the same sequence twice. Print the sequences in increasing lexicographic order.

Examples3

  1. Example 1

    Input
    3 1
    
    Expected output
    1
    2
    3
    
  2. Example 2

    Input
    4 2
    
    Expected output
    1 1
    1 2
    1 3
    1 4
    2 1
    2 2
    2 3
    2 4
    3 1
    3 2
    3 3
    3 4
    4 1
    4 2
    4 3
    4 4
    
  3. Example 3

    Input
    3 3
    
    Expected output
    1 1 1
    1 1 2
    1 1 3
    1 2 1
    1 2 2
    1 2 3
    1 3 1
    1 3 2
    1 3 3
    2 1 1
    2 1 2
    2 1 3
    2 2 1
    2 2 2
    2 2 3
    2 3 1
    2 3 2
    2 3 3
    3 1 1
    3 1 2
    3 1 3
    3 2 1
    3 2 2
    3 2 3
    3 3 1
    3 3 2
    3 3 3