Problem: The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 1310 = 11012, so it has 3 bits set and 13 will be reduced to 3 in one operation.

He calls a number special if the minimum number of operations to reduce it to 1 is k.

He wants to find out how many special numbers exist which are not greater than n. Please help the Travelling Salesman, as he is about to reach his destination!

Since the answer can be large, output it modulo 109 + 7.

Input

The first line contains integer n (1 ≤ n < 21000).

The second line contains integer k (0 ≤ k ≤ 1000).

Note that n is given in its binary representation without any leading zeros.

Output

Output a single integer — the number of special numbers not greater than n, modulo 109 + 7.

Examples

Input

110
2


Output

3


Input

111111011
2


Output

169

Note

In the first sample, the three special numbers are 3, 5 and 6. They get reduced to 2 in one operation (since there are two set bits in each of 3, 5 and 6) and then to 1 in one more operation (since there is only one set bit in 2).

Solution (in JAVA):

Solution:

import java.math.BigInteger;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    static int[][] binomial;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next().trim();
        int k = sc.nextInt();
        int mod = 1000000007;
        binomial = computeBinomials(1000, mod);

        if(k == 0) {
            System.out.println(1);
        } else if(n.equals("1")) {
            System.out.println(0);
        } else {
            int[] maxStep = new int[k];
            if (hasAllOnes(n)) {
                maxStep[k - 1] = n.length();
            } else {
                maxStep[k - 1] = n.length() - 1;
            }

            // System.out.println((k - 1) + ": " + maxStep[k - 1]);
            for (int i = k - 2; i >= 0; i--) {
                maxStep[i] = getMaxBit(maxStep[i + 1]);
                // System.out.println(i + ": " + maxStep[i]);
            }

            HashSet<Integer> vals = bfs(maxStep, k);
            BigInteger result = BigInteger.ZERO;
            // System.out.println();
            for (int val : vals) {
                BigInteger newResult = possibleVals(n, val);
                result = result.add(newResult); // Add all values up to n with val 1's
                // System.out.println("Partial result: " + val + ", " + newResult + "\n");
                // possibleValsBruteForce(n, val);
            }

            // System.out.println(result);
            System.out.println(result.mod(BigInteger.valueOf(mod)));
        }
        // bruteForce(n, k);
    }

    public static void bruteForce(String maxStr, int k) {
        int maxNum = Integer.parseInt(maxStr, 2);
        int result = 0;

        int[] steps = new int[maxNum + 1];
        steps[1] = 0;
        for(int i = 2; i <= maxNum; i++) {
            steps[i] = steps[getOneBits(i)] + 1;
            if(steps[i] == k) {
                result++;
            }
        }
        System.out.println(result);
    }

    public static boolean hasAllOnes(String s) {
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) != '1') {
                return false;
            }
        }
        return true;
    }

    public static int getMaxBit(int n) {
        boolean allOnes = true;
        int i;
        for(i = 0; i < 32; i++) {
            int check = 1 << i;
            if(check > n) {
                break;
            }
            else if((check & n) == 0) {
                allOnes = false;
            }
        }

        if(allOnes) {
            return i;
        }
        else {
            return i - 1;
        }
    }

    public static int getOneBits(int n) {
        int result = 0;
        for(int i = 0; i < 32; i++) {
            if(((1 << i) & n) > 0) {
                result++;
            }
        }
        return result;
    }

    public static int getOneBits(String s) {
        int result = 0;
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == '1') {
                result++;
            }
        }
        return result;
    }

    public static HashSet<Integer> bfs(int[] maxStep, int k) {
        HashSet<Integer> vals = new HashSet<>();
        // System.out.println("Step 0");
        vals.add(1);

        for(int step = 1; step < k; step++) {
            // System.out.println("Step " + step);
            HashSet<Integer> newVals = new HashSet<>();
            // Find all integers with val 1's, and up to maxStep[step]
            for(int i = 2; i <= maxStep[step]; i++) {
                int oneBits = getOneBits(i);
                if(vals.contains(oneBits)) {
                    newVals.add(i);
                    // System.out.println("Adding: " + i);
                }
            }
            vals = newVals;
        }
        return vals;
    }

    public static void possibleValsBruteForce(String nStr, int k) {
        int n = Integer.parseInt(nStr, 2);
        int result = 0;
        for(int i = 2; i <= n; i++) {
            if(getOneBits(i) == k) {
                result++;
            }
        }
        System.out.println(result);
    }

    // Count values up to nStr with k 1's, but don't allow 1 itself
    public static BigInteger possibleVals(String nStr, int k) {
        // System.out.println("Possible vals: " + nStr + ", " + k);
        int length = nStr.length();
        int oneBits = getOneBits(nStr);
        int[] remainingDigits = new int[oneBits + 1];

        // System.out.println("Remaining digits: ");
        int counter = 0;
        for(int i = 0; i < length; i++) {
            if(nStr.charAt(i) == '1') {
                remainingDigits[counter] = length - (i + 1);
                // System.out.println(counter + ": " + remainingDigits[counter]);
                counter++;
            }
        }

        BigInteger result = BigInteger.ZERO;
        for(int i = 0; i <= k && i <= oneBits; i++) {
            // System.out.println(i);
            // Use the first i 1's in n, then k - i remaining 1's
            if(remainingDigits[i] > 0) {
                //result = result.add(binomial(remainingDigits[i], k - i));
                result = result.add(BigInteger.valueOf(binomial[remainingDigits[i]][k - i]));
            } else if(k == i) {
                result = result.add(BigInteger.ONE);
            }
        }

        if(k == 1) {
            result = result.subtract(BigInteger.ONE); // Don't allow 1 itself
        }
        // System.out.println(result);
        return result;
    }

    public static int[][] computeBinomials(int n, int mod) {
        int[][] binomial = new int[n + 2][n + 2];
        binomial[1][0] = 1;
        binomial[1][1] = 1;
        for(int i = 2; i <= n; i++) {
            binomial[i][0] = 1;
            for(int j = 1; j <= i; j++) {
                binomial[i][j] = (binomial[i - 1][j] + binomial[i - 1][j - 1]) % mod;
            }
        }
        return binomial;
    }

    public static BigInteger binomial(int n, int k) {
        System.out.println("Binomial: " + n + ", " + k);
        if(n == k) {
            return BigInteger.ONE;
        } else if (k > n) {
            return BigInteger.ZERO;
        }

        BigInteger nBig = BigInteger.valueOf(n);
        BigInteger result = BigInteger.ONE;
        for(int i = 0; i < k; i++) {
            result = result.multiply(nBig.subtract(BigInteger.valueOf(i)));
        }

        for(int i = 1; i <= k; i++) {
            result = result.divide(BigInteger.valueOf(i));
        }

        return result;
    }
}