Balanced sequences X40596


Statement
 

pdf   zip

A sequence of numbers is dd-balanced if the absolute value of the difference between any two consecutive numbers is at most dd. Formally (x1,x2,,xn)(x_1, x_2, \ldots , x_n) is dd-balanced if for all 1i<n1 \leq i < n it holds that |xixi+1|d\lvert x_i - x_{i+1} \rvert \leq d.

Write a program that, given an integer n1n\geq 1 and an integer d0d \geq 0, writes all dd-balanced sequences that can be obtained by reordering the sequence (1,2,,n)(1, 2, \ldots , n).

Input

The input consists of an integer n1n \geq 1 followed by another integer d0d \geq 0.

Output

Write all dd-balanced sequences that can be obtained by reordering the sequence (1,2,,n)(1, 2, \ldots , n). You can write the sequences in any order.

Public test cases
  • Input

    3 1
    
    

    Output

    (1,2,3)
    (3,2,1)
    
  • Input

    4 2
    
    

    Output

    (1,2,3,4)
    (1,2,4,3)
    (1,3,2,4)
    (1,3,4,2)
    (2,1,3,4)
    (2,4,3,1)
    (3,1,2,4)
    (3,4,2,1)
    (4,2,1,3)
    (4,2,3,1)
    (4,3,1,2)
    (4,3,2,1)
    
  • Input

    1 0
    

    Output

    (1)
    
  • Information
    Author
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++