Under construction

Still being built. Things may change

Build a tree

Time limit2sMemory limit512 MB

Summary
Construct a tree on n nodes with exactly m leaves whose sorted edge list is lexicographically smallest, and print its n-1 edges.
Level

Medium4 of 10

Topics
Tree, Greedy, Implementation, Brute force
Solved
No attempts yet

Problem

You are given nn and mm. Build a tree that has nn nodes and exactly mm leaves, then print it.

A tree is a connected graph with no cycle, and a leaf is a node of degree 11. The nodes are numbered 00 through n−1n-1.

Several trees can satisfy the condition. Print the one whose edge list comes first in lexicographic order. Build the edge list this way: write each edge as u vu\ v with the smaller endpoint first, so u<vu < v, then order the n−1n-1 edges by uu ascending, breaking ties by vv ascending. Compare two edge lists as sequences of 2(n−1)2(n-1) integers.

Under the given limits such a tree always exists.

Input

The first line contains nn and mm, separated by a space. (3≤n≤503 \le n \le 50, 2≤m≤n−12 \le m \le n-1)

Output

Print the n−1n-1 edges of the tree, one per line, in the order defined above. On each line print the two endpoints of the edge, smaller number first, separated by a space.

Examples4

  1. Example 1

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

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

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

    Input
    5 3
    
    Expected output
    0 1
    0 2
    0 3
    1 4