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.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Code {
    public static void main(String[] args) {
        // Use the Scanner class
        Scanner sc = new Scanner(System.in);
        long BASE = (long) (Math.pow(10, 9) + 7L);
        String n = sc.nextLine();
        int k = sc.nextInt();
        int s = number_of_bits_in_number(n);
        Map<String, Long> cache = new HashMap<>();
        //Map<String, Long> ncr_cache = new HashMap<>();
        long[][] ncr_cache = new long[1004][1004];
        calcncr(ncr_cache);
        //int l = number_of_ones(n);
        long total = 0;
        int[] dp = new int[1004];
        dp[1] = 0;
        for(int i = 2; i <= 1000; i++)
        {
          dp[i] = dp[number_of_ones(i)] + 1;
        }
        if (k==0) {
            total = 1;
            System.out.println(total);
            return;
        }
        if (k == 1 && n.charAt(0) == '1') {
            total = n.length()-1;
            System.out.println(total);
            return;
        }
        if (n.equals("1") && k==1) {
            total = 0;
            System.out.println(total);
            return;
        }
        for (int l = 1; l <= s; ++l) {
            if (dp[l] == k-1) {
//            if (check(l, k-1))
//            {
                total += n_ways(n,l,cache,ncr_cache) % BASE;
            }
        }
        System.out.println(total%BASE);
    }

    static boolean check(int len, int k) {
        if (len ==1 ) {
            return k == 0;
        }
        while(len != 1) {
            len = number_of_ones(len);
            k--;
        }
        return k == 0;
    }

    static int number_of_bits_in_number(String n) {
        return n.length();
    }

    static int number_of_ones(int n) {
        int s = 0;
        while (n > 0) {
            int so = n & 1;
            if (so == 1) {
                s++;
            }
            n = n >> 1;
        }
        return s;
    }

    static int number_of_ones(String s) {
        int r = 0;
        for (char c : s.toCharArray()) {
            if (c == '1') {
                r++;
            }
        }
        return r;
    }

    static void calcncr( long[][] ncr)
    {
      long BASE = (long) (Math.pow(10, 9) + 7L);
      for(int i = 0; i <= 1000; i++)
      {
        ncr[i][0] = 1;
      }
      for(int i = 1; i <= 1000; i++)
      {
        for(int j = 1; j <= 1000; j++)
        {
          ncr[i][j] = (ncr[i-1][j-1] + ncr[i-1][j])%BASE;
        }
      }
    }


    static long n_ways(String s, int l, Map<String, Long> cache, long[][] ncr_cache) {
        s = s.replaceFirst("^0+(?!$)", "");
        if (s.equals("0") && l == 0) {
            return 1;
        }
        if (s.equals("1") && l == 1) {
            return 1;
        }
        if (l == 1 && s.charAt(0) == '1') {
            return s.length();
        }
        if (l == 0) {
            return s.equals("1") ? 1 : 0;
        }
        long BASE = (long) (Math.pow(10, 9) + 7L);
        int m = 0;
        for (int i = 0; i < s.length() && s.charAt(i) != '1'; ++i) {
            m++;
        }
        int t = m;
        m = s.length() - m - 1;
        if (m == -1) {
            return l ==0 ? 1 : 0;
        }
        if (m < l - 1) {
            return 0;
        }
        long ans = ncr_cache[m][l] + n_ways(s.substring(t+1, s.length()) , l - 1,cache,ncr_cache) %BASE;
        ans = ans % BASE;
        return ans;
    }

    static int n_ways(int n, int l) {
        int s = 0;
        for (int i = 1; i <= n; ++i) {
            if (number_of_ones(i) == l) {
                s++;
            }
        }
        return s;
    }

}