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.*;
import java.io.*;
import java.math.*;
public class Main {

    void solve() {
        s=ns().toCharArray();
        int k=ni();
        if(k>5){
            pw.println(0);
            return;
        }
        if(k==0){
            pw.println(1);
            return;
        }



        ArrayList<Integer> v[]=new ArrayList[11];
        for(int i=0;i<11;i++) v[i]=new ArrayList<>();

        for(int i=1;i<=1000;i++) {
            int cnt = 0;
            int n = i;
            while (n != 1) {
                n = Integer.bitCount(n);
                cnt++;
            }
            v[cnt].add(i);

            //pw.println(Integer.bitCount(i) + " " + cnt);
        }
        int msb=0;
        for(int i=0;i<s.length;i++) if(s[i]=='1') { msb=i; break; }
        long ans=0;
        if(k==1 && msb!=s.length-1)
        ans=s.length-msb-1;

        fact=new long[10001];
        fact[0]=1;
        k-=1;
        for(int i=1;i<=10000;i++) fact[i]=(fact[i-1]*i)%M;
        dp=new long[s.length][1001][2];
        for(int i=0;i<s.length;i++) for(int j=0;j<=1000;j++) Arrays.fill(dp[i][j],-1);
        if(k>0)
        for(int p : v[k]){

            ans=(ans+go(1,p,s.length,s[0]=='0'?0:1))%M;
            ans=(ans%M+go(1,p-1,s.length,s[0]=='1'?0:1))%M;


        }
        pw.println(ans);



    }

    long fact[];
    char s[];
    long dp[][][];

    long go(int i,int k,int n,int p){
        if(i>=n){
            if(k==0)  return 1;
            else return 0;
        }
        if(k==0) return dp[i][k][p]=1;
        //System.out.println(i+" "+k+" "+p);
        if(dp[i][k][p]!=-1) return dp[i][k][p];
        long ans=0;
        if(p==1) {
            int n1 = n - i ;
            if (k > n1) return dp[i][k][p] = 0;
            long d = fact[n1]%M;

            d = (d%M * modInverse(fact[k], M)%M);
            d = (d%M * modInverse(fact[n1 - k], M)%M) % M;

            dp[i][k][p]=d;
            return d;
        }
        if(s[i]=='0'){
            if(p==0) {
                ans=(ans+go(i+1,k,n,0))%M;
            }
        }else {
            if(p==0){
                long d1=go(i+1,k-1,n,0)%M,d2=go(i+1,k,n,1)%M;
                ans=(ans%M+d1%M)%M;
                ans=(ans%M+d2%M)%M;
                //if(i==0 && k==3) pw.println(ans+" "+d1+" "+d2);
            }
        }
//        if(ans==125000002)
//        pw.println(ans+" "+i+" "+k+" "+p);
        dp[i][k][p]=ans;
        //pw.println(ans);
        return ans;
    }
    static long d, x, y;
    static void extendedEuclid(long A, long B) {
        if(B == 0) {
            d = A;
            x = 1;
            y = 0;
        }
        else {
            extendedEuclid(B, A%B);
            long temp = x;
            x = y;
            y = temp - (A/B)*y;
        }
    }
    static long modInverse(long A, long M)
    {
        extendedEuclid(A,M);
        return (x%M+M)%M;
    }




    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}