数位DP.... 肝
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define bug1 cout <<"bug1"<<endl
#define bug2 cout <<"bug2"<<endl
#define bug3 cout <<"bug3"<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e5+5;
int m,d;
char a[2300],b[2300];
int bit[2300];
int dp[2300][4000];
int len;
ll dfs(int pos,int mod,bool lead,bool limit){
if(pos==len+1) return (mod==0);
if(!limit && dp[pos][mod]!=-1) return dp[pos][mod];
int up=limit ? bit[pos] : 9 ;
ll ans=0;
for(int i=0;i<=up;i++){
int tempmod=(mod*10+i)%m; //模拟除法
if(pos%2==1 && i==d) continue;
if(pos%2==0 && i!=d) continue;
ans+=dfs(pos+1,tempmod,lead&&i==0,limit && bit[pos]==i);
}
ans=ans%MOD;
if(!limit) dp[pos][mod]=ans;
return ans;
}
ll solve(const char *s){
memset(dp,-1,sizeof(dp));
int pos=1;
len=strlen(s+1);
while(pos<=len){
bit[pos]=s[pos]-'0'; ///bit存的是数字而不是字符
pos++;
}
// cout <<"***********"<<endl;
// printf("%s\n",bit+1);
return dfs(1,0,true,true);
}
bool judge(const char*s){
int mod=0;
len=strlen(s+1);
for(int i=1;i<=len;i++){
mod=(mod*10+s[i]-'0')%m;
if(i%2==1&&s[i]-'0'==d) return false;///是s[i]和d的关系
if(i%2==0&&s[i]-'0'!=d) return false;
}
return mod==0;
}
int main(void){
cin >> m>>d>>a+1>>b+1;
printf("%lld",((solve(b)-solve(a)+judge(a))%MOD+MOD)%MOD);
}