This page is still under construction.

Parts of this page are still being built. What you see may change.

Even-Hating Number

Time limit1sMemory limit1024 MB

Summary
Count and find the K-th largest number under 10^N whose digit string uses only 3, 5, 7 and each of these digit counts is odd.
Level

Medium7 of 10

Topics
Combinatorics, Dynamic programming, Math, Implementation
Solved
No attempts yet

Problem

Dodo's friend hates even numbers. So much that just seeing an even number makes him breathe fire and explode with rage.

For his friend, Dodo invented the even-hating number.

An even-hating number consists of 33, 55, and 77, and the count of 33s, the count of 55s, and the count of 77s are simultaneously not even. If a digit is used 00 times, it is considered even.

For example, 7575 is an even-hating number because the count of 77s is 11, the count of 55s is 11, and the count of 33s is 00, so all digit counts are simultaneously not even.

Write a program that prints the KK-th largest even-hating number among numbers less than 10N10^N.

No input is given for which the answer does not exist.

Input

The first line gives the integer NN (1≤N≤301 \le N \le 30) and the integer KK (1≤K≤263−11 \le K \le 2^{63}-1).

Output

On the first line, print the KK-th largest even-hating number among numbers less than 10N10^N.

Hint

263−12^{63}-1 can be represented with an 8-byte data type.

However, the sample 2 output 357335535573573353577573355337357335535573573353577573355337 cannot be represented with an 8-byte data type.

Examples3

  1. Example 1

    Input
    9 1
    
    Expected output
    777777777
    
  2. Example 2

    Input
    30 125527562340212
    
    Expected output
    357335535573573353577573355337
    
  3. Example 3

    Input
    29 96511468169355
    
    Expected output
    3