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.io.*;
import java.util.*;

public class TaskC {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Solve solve = new Solve();
        solve.solve(in, out);
        out.close();
    }

    private static class Solve {

        ArrayList<ArrayList<Integer>> v = new ArrayList<ArrayList<Integer>>();
        int[] prev = new int[1110];
        private static int MOD = 1000000007;
        int answer = 0;
        String z;
        char[] s = new char[1111];
        int k, len;
        int[][] c = new int[1111][1111];

        public void solve(InputReader in, PrintWriter out) {
            z = in.next();
            k = in.nextInt();
            if (k == 0) {
                out.print(1);
                return;
            }
            if (z.equals("1")) {
                out.print(0);
                return;
            }
            len = z.length();
            for (int i = 0; i < len; i++) {
                s[i] = z.charAt(i);
            }
            if (k == 1) {
                out.print(cntBit());
                return;
            }
            for (int i = 0; i < 15; i++) {
                v.add(new ArrayList<Integer>());
            }
            v.get(0).add(1);
            for (int i = 2; i <= 1000; i++) {
                int y = cntBit(i);
                prev[i] = y;
                v.get(y).add(i);
            }
//            for (int i = 0; i <= 10; i++) {
//                out.print(i + " => " + v.get(i).size() + " : ");
//                for (int j = 0; j < v.get(i).size(); j++) {
//                    out.print(v.get(i).get(j) + " ");
//                }
//                out.println();
//            }

            calcPascal(1000);
            go(0, 1);
            out.print(answer + foo());
        }

        private int foo() {
            int y = 0;
            if (len == 1 && s[0] == '0') y = 1; else {
                int cur = 0;
                for (int i = 0; i < len; i++) {
                    cur += s[i] == '1' ? 1 : 0;
                }
                if (cur != 1) y++;
                while (cur != 1) {
                    cur = cntBit(cur);
                    y++;
                }
            }

            return y == k ? 1 : 0;
        }

        private void calcPascal(int n) {

            for (int i = 0; i <= n; i++) {
                c[i][0] = c[i][i] = 1;
                for (int j = 1; j < i; ++j) {
                    c[i][j] = ((c[i - 1][j - 1] + c[i - 1][j]) % MOD);
                }
            }
        }

        private void go(int curK, int x) {
            if (curK == k - 1) {
                calc(x);
                return;
            }
            if (curK > k) {
                return;
            }
            if (x < v.size()) {
                for (int i = 0; i < v.get(x).size(); i++) {
                    go(curK + 1, v.get(x).get(i));
                }
            }
        }

        private void calc(int cnt1) {
            int curAdd = 0;
            int free = len;
            if (len < cnt1) return;
            int cnt0 = len-cnt1;
            for (int i = 0; i < len; i++) {
//                if (cnt1 == 0) {
//                    break;
//                }
                if (free < cnt1) {
                    break;
                }
                if (s[i] == '0') {
                    if (cnt0 == 0) break;
                    cnt0--;
                } else {
                    curAdd += getC(cnt0 + cnt1 - 1, cnt0 - 1);
                    curAdd %= MOD;
                    cnt1--;
                }
            }
            answer += curAdd;
            answer %= MOD;
        }

        private int getC(int n1, int k1) {
            if (n1 < 0) return 0;
            if (k1 < 0) return 0;
            return c[n1][k1];
        }

        private int cntBit() {
            return len - 1;
        }

        private int cntBit(int x) {
            int y = 0;
            while (x > 0) {
                y += x % 2;
                x /= 2;
            }
            return y;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}