#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define M 1000000007
#define gb(co, k) ((co)>>(k)&1)

int main(){
   int n;
   cin>>n;
   vector<ll> a(n);
   rep(i, n) cin>>a[i];

   vector<vector<int>> sb(n);
   rep(i, n) sb[i]=vector<int>(60);

   rep(i, n){
      rep(j, 60) sb[i][j]=((i==0)?0:sb[i-1][j]) + gb(a[i], j);
   }
   int ans=0;
   for(int i=1; i<n; i++) rep(j, 60){
      int c;
      if(gb(a[i], j))
         c=((ll)(i-sb[i-1][j]) * (((ll)1<<j)%M))%M;
      else
         c=((ll)sb[i-1][j] * (((ll)1<<j)%M))%M;
      ans=(ans+c)%M;
   }

   cout<<ans<<endl;
   return 0;
}

//thuanqvbn03
#include <bits/stdc++.h>

using namespace std;

const int MaxN = 100005;
const int Mod = 1000000007;

int n, D;
string s;
long long dp[MaxN], tmp[MaxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    cin >> D;
    n = s.size();
    for (int i = s[0] - '0' - 1; i >= 0; i--)
    {
        dp[i % D]++;
    }
    int Sums = (s[0] - '0') % D;
    for (int i = 1; i < n; i++)
    {
        int x = s[i] - '0';
        for (int k = 0; k < D; k++)
        {
            tmp[k] = tmp[k] + dp[k];
            tmp[k + 10] = tmp[k + 10] - dp[k] + Mod;
        }
        tmp[Sums]++;
        tmp[Sums + x]--;
        Sums = (Sums + x) % D;
        dp[0] = tmp[0];
        tmp[0] = 0;
        for (int k = 1; k < D + 10; k++)
        {
            dp[k] = (tmp[k] + dp[k - 1]) % Mod;
            tmp[k] = 0;
        }
        for (int k = D; k < D + 10; k++)
        {
            dp[k % D] = (dp[k % D] + dp[k]) % Mod;
        }
    }
    long long ans = (dp[0] + (Sums % D == 0) - 1 + Mod) % Mod;
    cout << ans;
    return 0;
}