Polish version    English version  
  History of OI -> VII OI 1999/2000 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Organization
Hints
Schedule
Stats
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
VII Olimpiada Informatyczna 1999/2000

Task: KOD
Author: Wojciech Guzicki
Code

II stage contest  

A binary tree can either be empty or consist of one vertex, with two trees linked to it. These two trees are called a left and a right subtree. In each vertex there is one letter from the English alphabet. The vertex which is not a subtree of any vertex, is called a root. We say that a tree is a Binary Search Tree (BST) if for each vertex the following condition is satisfied: all letters in the left subtree precede in alphabetical order the letter in the root, and all letters from the right subtree follow the letter in the root. A code of a BST is:

  • either an empty string (containing 0 letters) when the tree is empty
  • or a string beginning with the letter from the root, followed by the code of the left subtree, followed by the code of the right subtree.

Let us consider all k-vertex BSTs containing in their vertices k initial letters of the English alphabet. Suppose we have a list of these codes written in alphabetical order. (n,k)-code is the n-th code on this list.

Example

There are exactly fourteen 4-vertex BSTs. These are (in alphabetical order):

abcd abdc acbd adbc adcb bacd badc cabd cbad dabc dacb dbac dcab dcba
The string badc is the (7,4)-code and it corresponds to the BST printed below:

Task

Write a program which:

  • reads the numbers n and k from the text file KOD.IN,
  • finds the (n, k)-code,
  • writes it to the text file KOD.OUT.

Input

In the first and only line of the text file KOD.IN there are exactly two positive integers n and k, separated by a single space, 1<=k<=19. The number n is not greater than the number of codes of BST with k vertices.

Output

In the first and only line of the text file KOD.OUT there should be exactly one word (written in small letters) being the (n,k)-code.

Example

For the input file KOD.IN

11 4

the correct answer is the output file KOD.OUT

dacb



Print friendly version