#include <bits/stdc++.h>
#define re register
#define SIZE 10005
#define LL long long 
#define MOD 1000000007
using namespace std;
string k;
int d;
int maxn[SIZE],cnt;
LL dp[SIZE][105];
inline LL dfs(int pos,int sta,bool lim)
{
	if(pos>cnt)
		return sta==0?1:0;
	if(!lim && dp[pos][sta]!=-1)
		return dp[pos][sta];
	int up=lim?maxn[pos]:9;
	LL ret=0;
	for(re int i=0;i<=up;++i)
		ret=(ret+dfs(pos+1,(sta+i)%d,lim&&(i==maxn[pos])))%MOD;
	if(!lim)
		dp[pos][sta]=ret;
	return ret;
}
inline LL work()
{
	memset(dp,-1,sizeof(dp));
	cnt=k.size()-1;
	for(re int i=0;i<=cnt;++i)
		maxn[i]=k[i]-'0'; 
	return dfs(0,0,1);
}
int main()
{
	cin>>k;
	cin>>d;
	LL ans=(work()-1+MOD)%MOD;
	printf("%lld\n",ans);
	return 0;
} 
//3373
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}

bool Check(ll num, ll pos) {
        return (bool)(num & (1LL << pos));
}
 long long int sumXOR(ll arr[], int n)
{
     long long int sum = 0;
    for (int i = 0; i <=60; i++)
    {
        //  Count of zeros and ones
        long long zc = 0, oc = 0;

        // Individual sum at each bit position
        long long int idsum = 0;
        for (int j = 0; j < n; j++)
        {
           /* if (arr[j] % 2 == 0)
                zc++;
            else
                oc++;
            arr[j] /= 2;*/

            if(Check(arr[j],i))zc++;

            else oc++;
        }

        // calculating individual bit sum
        idsum = (oc * ((zc * ((1ll << i)%Mod))%Mod))%Mod;

        // final sum
        sum =(sum+ idsum)%Mod;
    }
    return sum%Mod;
}
int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;



        cin>>n;


        long long ara[n+2];

        for(i=0; i<n; i++)
            cin>>ara[i];

         cout<<sumXOR(ara,n)<<endl;


}

