#P7690. Cute Fence Problem

    ID: 20880 Type: Default 1000ms 256MiB

Cute Fence Problem

Cute Fence Problem

Richard has just built his new house. The only thing missing is a cute little wooden fence. However, he doesn't know how to build one so he orders it. For some reason he gets his hands on the ACME Fence Catalog 2002 – the flagship resource for cute little wooden fences (note: ACME makes everything).

A wooden fence is constructed using N boards arranged vertically in a row. In addition, the fence is considered cute if and only if the following conditions are met:

  • The boards have distinct lengths, precisely 1, 2, …, N (in some order).
  • For each board that has two adjacent boards (i.e. for every i with 1 < i < N), the board is either taller than both its neighbors or shorter than both. In formal terms, if the fence is described by a permutation \(a_1,a_2,\dots,a_N\), then for every i with 1 < i < N it must hold that \[ (a_i - a_{i-1}) \times (a_i - a_{i+1}) > 0. \]

Conversely, every permutation of \(\{1,2,\ldots,N\}\) satisfying the above property describes a cute fence.

After cataloguing all possible cute fences, the ACME sales manager decides to order them in the following way: Given two fences A represented by \(a_1, a_2,\dots,a_N\) and B represented by \(b_1, b_2,\dots,b_N\), fence A comes before fence B if and only if there exists an index i such that for every index j < i, \(a_j = b_j\), and \(a_i < b_i\). In other words, the fence ordering is the lexicographical (dictionary) order of their corresponding permutations. Each cute fence is assigned its order number in the list (starting from 1). This number is called its catalog number.

Richard has decided he wants one of these cute fences and he noted down the number of boards N and the catalog number C. Later, when he met his friend, he wanted to proudly show off his fence but realized he had lost the catalog. The only thing he had was his note. Your task is to determine the configuration of his fence.

inputFormat

The input consists of one line containing two integers N and C separated by a space. Here N is the number of boards and C is the catalog number of the cute fence.

outputFormat

Output the configuration of the fence with catalog number C. The configuration should be printed as N integers separated by spaces, corresponding to the lengths of the boards from left to right.

sample

3 1
1 3 2