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).
/*
 * Author Ayub Subhaniya
 * Institute DA-IICT
 */

import java.io.*;
import java.math.*;
import java.util.*;


public class C
{
	
	InputStream in;
	PrintWriter out;
	
	
	long mod=(long)1e9+7;
	int MAX=(int)1e3;
	void solve() 
	{
		findfactorial();
		int dp[]=new int[MAX+1];
		dp[1]=0;
		for (int i=2;i<=MAX;i++)
			dp[i]=1+dp[Integer.bitCount(i)];
		
		String n=ns();
		int l=n.length();
		int k=ni();
		
		if (k==0)
		{
			out.println(1);
			return;
		}
		
		if (n.compareTo("1")==0)
		{
			if (k==0)
				out.println(1);
			else
				out.println(0);
			return;
		}
		long ans=0;
		
		k--;
		for (int i=1;i<=l;i++)
		{
			if (dp[i]==k)
			{
				//tr(i+" ");
				int cnt=0;
				for (int pref=0;pref<l;pref++)
				{
					if (n.charAt(pref)=='1')
					{
						//tr(pref);
						
						if (cnt==0&&i==1)
						{
							if (l-pref-2>=i-cnt)
								ans=add(ans,nCk(l-pref-2,i-cnt));
						}
						else
						{
							if (l-pref-1>=i-cnt)
								ans=add(ans,nCk(l-pref-1,i-cnt));
						}
						
						cnt++;
						//tr(ans);
					}
				}
			}
		}
		
		/*if (dp[1]==k)
		{
			if (n.compareTo("1")!=0)
				ans=add(ans,1);
		}*/
		int cnt=0;
		for (int i=0;i<l;i++)
			if (n.charAt(i)=='1')
				cnt++;
		if (dp[cnt]==k)
			ans=add(ans,1);
		out.println(ans);
	}
	
	long factorial[];
		void findfactorial() 
		{
			factorial = new long[MAX + 1];
			factorial[0] = 1;
			for (int i = 1; i < MAX + 1; i++) 
			{
				factorial[i] = mul(i, factorial[i - 1]);
			}
		}
		
		long nCk(long n, long k) 
		{
			if (n < k || n<0 || k<0) 
			{
				return 0;
			}
			if (k == n || k == 0) 
			{
				return 1;
			}
			long a = pow(factorial[(int) (n - k)],mod-2,mod);
			long b = pow(factorial[(int) (k)],mod-2,mod);
			return mul(mul(factorial[(int) n],a),b);
		}
	
	long pow(long x, long n, long M) {
		long result = 1;
		while (n > 0) {
			if (n % 2 == 1)
				result = (result * x) % M;
			x = (x * x) % M;
			n = n / 2;
		}
		return result;
	}
	
	int max(int a,int b)
	{
		if(a>b)
			return a;
		else
			return b;
	}
	
	int min(int a,int b)
	{
		if(a>b)
			return b;
		else 
			return a;
	}
	
	long max(long a,long b)
	{
		if(a>b)
			return a;
		else
			return b;
		
	}
	
	
	long min(long a,long b)
	{
		if(a>b)
			return b;
		else 
			return a;
		
	}
	
	long add(long a,long b)
	{
		long x=(a+b);
		while(x>=mod) x-=mod;
		return x;
		
	}
	
	
	long sub(long a,long b)
	{
		long x=(a-b);
		while(x<0) x+=mod;
		return x;
		
	}
	
	
	long mul(long a,long b)
	{
		a%=mod;
		b%=mod;
		long x=(a*b);
		return x%mod;
		
	}
	
	int abs(int a,int b)
	{
		if (a<b)
			return b-a;
		else
			return a-b;
	}
	
	long abs(long a,long b)
	{
		if (a<b)
			return b-a;
		else
			return a-b;
	}
	
	class Pair implements Comparable<Pair>
	{
		int x;
		int y;
		Pair(int a,int b)
		{
			x=a;
			y=b;
		}
		
		@Override
		public boolean equals(Object o) 
		{
			Pair other = (Pair)o;
			return x == other.x && y == other.y;
		}
		public String toString()
		{
			return x+" "+y;
		}
		
		@Override
		public int compareTo(Pair o) 
		{
			if (x==o.x)
				return Integer.compare(y, o.y);
			else
				return Integer.compare(x, o.x);
		}
		@Override public int hashCode() 
		{
			return Objects.hash(x, y);
		}
	}
	
	void run() throws Exception 
	{
		String INPUT = "C:/Users/ayubs/Desktop/input.txt";
		in = oj ? System.in : new FileInputStream(INPUT);
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis() - s + "ms");
		
	}
	public static void main(String[] args) throws Exception 
	{
		new C().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 = in.read(inbuf);
			}
			catch (IOException e) 
			{
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean inSpaceChar(int c) 
	{
		return !(c >= 33 && c <= 126);
	}
	
	private int skip() 
	{
		int b;
		while ((b = readByte()) != -1 && inSpaceChar(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 (!(inSpaceChar(b))) 
		{ // when nextLine, (inSpaceChar(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 && !(inSpaceChar(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 boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	
	private void tr(Object... o) 
	{
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
	
}