CF121C Lucky Permutation
Description
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya dreamt of a lexicographically $ k $ -th permutation of integers from $ 1 $ to $ n $ . Determine how many lucky numbers in the permutation are located on the positions whose indexes are also lucky numbers.
Input Format
The first line contains two integers $ n $ and $ k $ $ (1
Output Format
If the $ k $ -th permutation of numbers from $ 1 $ to $ n $ does not exist, print the single number "-1" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes $ i $ , that $ i $ and $ a_{i} $ are both lucky numbers.
Explanation/Hint
A permutation is an ordered set of $ n $ elements, where each integer from $ 1 $ to $ n $ occurs exactly once. The element of permutation in position with index $ i $ is denoted as $ a_{i} $ ( $ 1