// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <double> vd;
typedef vector <string> vs;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <char> > vvc;
typedef vector < vector <double> > vvd;
typedef vector < vector <string> > vvs;
typedef vector < pair <int, int> > vpi;
typedef vector < pair <double, double> > vpd;

// macroses
#define ft first
#define sc second
#define len(s) s.length()
#define pob(s) pop_back(s)
#define pub(s) push_back(s)
#define mp(a, b) make_pair((a), (b))
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int* v = new int[n];
    for(int i=0; i < n; i++)
        scanf("%d", &v[i]);
    int* l = v;
    int* r = v+n-1;
    int lsum = v[0];
    int rsum = v[n-1];
    while(r-l > 1) {
        if(r-l == 2 || lsum > rsum) {
            l++;
            lsum += *l;
        }
        else {
            r--;
            rsum += *r;
       }
    }
    printf("%d %d", l-v+1, (v+n-1)-r+1);
    //system("pause");
    return 0;
}


// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <double> vd;
typedef vector <string> vs;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <char> > vvc;
typedef vector < vector <double> > vvd;
typedef vector < vector <string> > vvs;
typedef vector < pair <int, int> > vpi;
typedef vector < pair <double, double> > vpd;

// macroses
#define ft first
#define sc second
#define len(s) s.length()
#define pob(s) pop_back(s)
#define pub(s) push_back(s)
#define mp(a, b) make_pair((a), (b))
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int* v = new int[n];
    for(int i=0; i < n; i++)
        scanf("%d", &v[i]);
    if(n == 1) printf("1 0\n");
    else {
    int* l = v;
    int* r = v+n-1;
    int lsum = v[0];
    int rsum = v[n-1];
    while(r-l > 1) {
        if((r-l == 2 && lsum == rsum) || lsum < rsum) {
            l++;
            lsum += *l;
        }
        else {
            r--;
            rsum += *r;
       }
    }
    printf("%d %d", l-v+1, (v+n-1)-r+1);
    }
    //system("pause");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>
#include <sstream>
#include <cstring>

using namespace std;
typedef long long ll;

int a[200*1000];
int main(int argc, char** argv)
{
	ll n;
	cin>>n;
	ll cnt=0,cnt2=0,t1=0,t2=0,ali=0,bob=n-1;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	while(ali<=bob)
	{
		if(t1<=t2)
		{
			cnt++;
			t1+=a[ali];
			ali++;
		}
		else
		{
			cnt2++;
			t2+=a[bob];
			bob--;
		}
		if(t1>=t2)
		{
			t1-=t2;
			t2=0;
		}
		else
		{
			t2-=t1;
			t1=0;
		}
	}
	cout<<cnt<<" "<<cnt2;
	return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    vector <int> t(n+1,0);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    int k = 1e5+10;
    c = n;
    while (c > 0) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k2--;
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <ctype.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <stdio.h>
#define File_in(input) freopen(input, "r", stdin)
#define File_out(output) freopen(output, "w", stdout)
#define all(x) x.begin(),x.end()
#define for_in(x) for (auto it: x)
#define pb(x) push_back(x);
using namespace std;
typedef long long ll;
typedef pair <int,int> point;
const int MAX_SIZE = 1e6+10;
const ll MOD = 1000000007;
const int INF = 114748364;

int main () {
    ios_base::sync_with_stdio(false);
    //File_in("input.txt"); File_out("output.txt");
    int n,i,j,k1,k2;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    i = 0, j = n - 1, k1 = 0,k2 = 0;
    while (1) {
        k1++;
        k2++;
        if (k1 == t[i]) {
            i++;
            k1 = 0;
        }
        if (i == j)
            break;
        if (k2 == t[j]) {
            j--;
            k2 = 0;
        }
        if (i == j)
            break;
    }
    cout << i << ' ' << n-1-j+1 << endl;
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#define File_in freopen("input.txt", "r", stdin)
#define File_out freopen("output.txt", "w", stdout)
#define yep  cout << "YES" << endl
#define nope cout << "NO" << endl
#define FOR(i,b,n) for(int i=b; i<=n; i++)
#define RFOR(i,n,b) for(int i=n; i>=b; i--)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int s,a,b,x,n,k,l;
int pa,pb;

int main()
{

   cin >> n;
   vector <int> t;
   for(int i = 0; i < n; i++)
   {
       cin >> x;
       t.push_back(x);
       s = s+x;
   }
   pa = 0;
   pb = n-1;
   for(int i = 0; i < s; i++)
   {
       if (!n)
            break;
       if (t[pa] == k)
       {
           a++;
           pa++;
           k = 0;
           n--;
       }
       if (t[pb] == l)
       {
            pb--;
            l = 0;
            b++;
            n--;
       }

       k++;
       l++;
   }
   if (a == b)
   {
       a++;
       if (b)
        b--;
   }
   cout  << a << " " << b << endl;

}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    c = n;
    int k = 1e6;
    for (;c > 0; ) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k2--;
            if (k1 > k2) {
                break;
            }
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    vector <int> t(n+1,0);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    int k = 1e5+10;
    c = n;
    for (int i = 0; i <k && c > 0;i++) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k2--;
            if (k1 > k2) {
                break;
            }
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#define File_in freopen("input.txt", "r", stdin)
#define File_out freopen("output.txt", "w", stdout)
#define yep  cout << "YES" << endl
#define nope cout << "NO" << endl
#define FOR(i,b,n) for(int i=b; i<=n; i++)
#define RFOR(i,n,b) for(int i=n; i>=b; i--)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int s,a,b,x,n,k,l;
int pa,pb;

int main()
{

   cin >> n;
   vector <int> t;
   for(int i = 0; i < n; i++)
   {
       cin >> x;
       t.push_back(x);
       s = s+x;
   }
   pa = 0;
   pb = n-1;
   for(int i = 0; i < s; i++)
   {
       if (!n)
            break;
       if (t[pa] == k)
       {
           a++;
           pa++;
           k = 0;
           n--;
       }
       if (t[pb] == l)
       {
            pb--;
            l = 0;
            b++;
            n--;
       }

       k++;
       l++;
   }
   if (a == b)
   {
       b--;
   }
   cout  << a << " " << b << endl;

}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    c = n;
    int k = 1e6;
    for (int i = 0; i < k && c != 0; i++) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k1--;
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


#include <bits/stdc++.h>
#define File_in(input) freopen(input, "r", stdin)
#define File_out(output) freopen(output, "w", stdout)
#define all(x) x.begin(),x.end()
#define for_in(x) for (auto it: x)
#define pb(x) push_back(x);
using namespace std;
typedef long long ll;
typedef pair <int,int> point;
const int MAX_SIZE = 1e6+10;
const ll MOD = 1000000007;
const int INF = 114748364;

int main () {
    ios_base::sync_with_stdio(false);
    //File_in("input.txt"); File_out("output.txt");
    int n,i,j,k1,k2;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    i = 0, j = n - 1, k1 = 0,k2 = 0;
    while (i != j) {
        k1++;
        k2++;
        if (k1 == t[i]) {
            i++;
            k1 = 0;
        }
        if (i == j)
            break;
        if (k2 == t[j]) {
            j--;
            k2 = 0;
        }
    }
    cout << i << ' ' << n-1-j+1 << endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    c = n;
    while(c > 0) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k1--;
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    c = n;
    int k = 1e6;
    for (int i = 0; i < k || c > 0; i++) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k1--;
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    c = n;
    int k = 1e5+10;
    for (int i = 0; i <k && c > 0;i++) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k2--;
            d2 = 0;
        }
        else {
            //cout << "boom" << endl;
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }

        }
        //cout << a << ' ' << b << ' ' << t[k1] << ' ' << t[k2] << ' '  << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    vector <int> t(n+1,0);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    int k = 1e5+10;
    c = n;
    while (c > 0) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k2--;
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            else if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    c = n;
    int k = 1e6;
    for (;c > 0; ) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            if (!c) {
                break;
            }
            k1--;
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int n,a = 0 ,b = 0,k1,k2,d1,d2,c;
    cin >> n;
    int t[111] = {0};
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    k1 = 0;
    k2 = n-1;
    d1 = 0;
    d2 = 0;
    c = n;
    int k = 1e6;
    for (int i = 0; i < k && c > 0; i++) {
        d1++;
        d2++;
        if (k1 == k2 && d1 == d2 && d1 > 0) {
            a++;
            k1++;
            d1 = 0;
            c--;
            k1--;
            d2 = 0;
        }
        else {
            if (d1 == t[k1]) {
                a++;
                k1++;
                d1 = 0;
                c--;
            }
            if (d2 == t[k2]) {
                b++;
                k2--;
                d2 = 0;
                c--;
            }
        }
        //cout << a << ' ' << b << ' ' << k1 << ' ' << k2 << endl;
        //system("pause");
    }
    cout << a << ' ' << b << endl;
}


//
//  main.cpp
//  codeCPP
//
//  Created by smellyMonkey on 29/01/2015.
//  Copyright (c) 2015 None. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>

using namespace std;

int main()
{
	int n;
	cin>>n;

	vector<int> time(n+1, 0);
	for (int i = 1; i <= n; ++i)
		cin>>time[i];

	vector<int> sum(n+1, 0);
	for (int i = 1; i <= n; ++i)
		sum[i] = sum[i-1] + time[i];

	int left = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (sum[i-1] <= sum[n]-sum[i])
			left++;
	}

	cout<<left<<" "<<n-left<<endl;
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, t;
    vector<int>times;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> t;
        times.push_back(t);
    }

    if (n == 1)
    {
        cout << 1 << " " << 0 << endl;
        return 0;
    }

    int totalTime = 0;

    for (int i = 0; i < n; i++)
        totalTime += times[i];

    int firstTotal = times[0];

    if (firstTotal >= totalTime - firstTotal)
    {
        cout << 1 << " " << n - 1 << endl;
        return 0;
    }

    for (int i = 1; i < n - 1; i++)
    {
        firstTotal += times[i];
        if (firstTotal >= totalTime - firstTotal)
        {
            if (firstTotal == totalTime - firstTotal)
                cout << i + 1 << " " << n - 1 - i << endl;
            else if (firstTotal - times[i] == totalTime - firstTotal)
                cout << i + 1 << " " << n - i - 1<< endl;
            else
                cout << i << " " << n - i << endl;
            return 0;
        }
    }

    cout << n - 1 << " " << 1 << endl;

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, t;
    vector<int>times;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> t;
        times.push_back(t);
    }

    if (n == 1)
    {
        cout << 1 << " " << 0 << endl;
        return 0;
    }

    int totalTime = 0;

    for (int i = 0; i < n; i++)
        totalTime += times[i];

    int firstTotal = times[0];

    if (firstTotal >= totalTime - firstTotal)
    {
        cout << 1 << " " << n - 1 << endl;
        return 0;
    }

    for (int i = 1; i < n - 1; i++)
    {
        firstTotal += times[i];

        if (firstTotal == totalTime - firstTotal)
        {
            cout << i + 1 << " " << n - 1 - i << endl;
            return 0;
        }

        if (firstTotal > totalTime - firstTotal)
        {

            if (firstTotal - times[i] <= totalTime - firstTotal)
                cout << i + 1 << " " << n - i - 1<< endl;
            else
                cout << i << " " << n - i << endl;
            return 0;
        }
    }

    cout << n - 1 << " " << 1 << endl;

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int A[100000];
	int n;
	cin>>n;
	for(int k=0;k<n;++k)
		cin>>A[k];
	int i=0;
	int j=n-1;
	int alice,bob;
	if(n<=1)
	{
	alice=0,bob=0;
	}
	else
	{
		alice=1,bob=1;
	}
	while(((alice+bob)!=n) )
	{
		if(i==j)
		{
			alice++;
			break;
		}

	        else if(A[i]<A[j])
		{
			A[j]=A[j]-A[i];
			alice++;
			i++;
		}
		else if(A[j]<A[i])
		{
			A[i]=A[i]-A[j];
			bob++;
			j--;
		}
	}
	cout<<alice<<" "<<bob;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int A[100000];
	int n;
	cin>>n;
	for(int k=0;k<n;++k)
		cin>>A[k];
	int i=0;
	int j=n-1;
	int alice,bob;
	if(n<=1)
	{
	alice=0,bob=0;
	}
	else
	{
		alice=1,bob=1;
	}
	while(((alice+bob)!=n) && n>1)
	{
		if(i==j)
		{
			alice++;
			break;
		}

	        else if(A[i]<A[j])
		{
			A[j]=A[j]-A[i];
			alice++;
			i++;
		}
		else if(A[j]<A[i])
		{
			A[i]=A[i]-A[j];
			bob++;
			j--;
		}
	}
	cout<<alice<<" "<<bob;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int A[100000];
	int n;
	cin>>n;
	for(int k=0;k<n;++k)
		cin>>A[k];
	int i=0;
	int j=n-1;
	int alice=0,bob=0;
	/*if(n<=1)
	{
	alice=0,bob=0;
	}
	else
	{
		alice=1,bob=1;
	}*/
	while(((alice+bob)<=n) )
	{
		if(i==j)
		{
			alice++;
			break;
		}
		else if(j-i==1)
		{
			alice++;
			bob++;
		}

	        else if(A[i]<A[j])
		{
			A[j]=A[j]-A[i];
			alice++;
			i++;
		}
		else if(A[j]<A[i])
		{
			A[i]=A[i]-A[j];
			bob++;
			j--;
		}
		else if(A[i]==A[j])
		{
			bob++,alice++;
			i++;
			j--;
		}
	}
	cout<<alice<<" "<<bob;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int A[100000];
	int n;
	cin>>n;
	for(int k=0;k<n;++k)
		cin>>A[k];
	int i=0;
	int j=n-1;
	int alice=0,bob=0;
	/*if(n<=1)
	{
	alice=0,bob=0;
	}
	else
	{
		alice=1,bob=1;
	}*/
	while(j-i!=1 )
	{
		if(i==j)
		{
			//i=i+1;
			j=j+1;
			break;
		}

	        else if(A[i]<A[j])
		{
			A[j]=A[j]-A[i];
			//alice++;
			i++;
		}
		else if(A[j]<A[i])
		{
			A[i]=A[i]-A[j];
			//bob++;
			j--;
		}
		else if(A[i]==A[j])
		{
			//bob++,alice++;
			i++;
			j--;
		}
	}
	cout<<i+1<<" "<<n-j;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int A[100000];
	int n;
	cin>>n;
	for(int k=0;k<n;++k)
		cin>>A[k];
	int i=0;
	int j=n-1;
	int alice=1,bob=1;
	while((alice+bob)!=n)
	{
		if(i==j)
		{
			alice++;
			break;
		}

	        else if(A[i]<A[j])
		{
			A[j]=A[j]-A[i];
			alice++;
			i++;
		}
		else if(A[j]<A[i])
		{
			A[i]=A[i]-A[j];
			bob++;
			j--;
		}
	}
	cout<<alice<<" "<<bob;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int A[100000];
	int n;
	cin>>n;
	for(int k=0;k<n;++k)
		cin>>A[k];
	int i=0;
	int j=n-1;
	int alice,bob;
	if(n<=1)
	{
	alice=0,bob=0;
	}
	else
	{
		alice=1,bob=1;
	}
	while(((alice+bob)!=n) )
	{
		if(i==j)
		{
			alice++;
			break;
		}

	        else if(A[i]<A[j])
		{
			A[j]=A[j]-A[i];
			alice++;
			i++;
		}
		else if(A[j]<A[i])
		{
			A[i]=A[i]-A[j];
			bob++;
			j--;
		}
		else if(A[i]==A[j])
		{
			bob++,alice++;
			i++;
			j--;
		}
	}
	cout<<alice<<" "<<bob;
	return 0;
}


// ITNOG

#include <iostream>
#include <algorithm>
using namespace std;

#define SZ(x) ((int)(x).size())
#define FOR(i,n) for(int i=0;i<n;++i)

const int maxn = 1e5 + 10;
int t[maxn];

int main() {
    int n;
    cin >> n;
    FOR(i, n) cin >> t[i];
    int a = -1, b = n;
    while (a < b-1) {
	if (t[a] == 0 && t[b] == 0 && b-2 == a) {
	    a++;
	    break;
	}
	if (t[a] == 0) a++;
	if (t[b] == 0) b--;
	t[a]--, t[b]--;
    }
    cout << a + 1 << ' ' << n - b << '\n';
}


// ITNOG

#include <iostream>
#include <algorithm>
using namespace std;

#define SZ(x) ((int)(x).size())
#define FOR(i,n) for(int i=0;i<n;++i)

const int maxn = 1e5 + 10;
int t[maxn];

int main() {
    int n;
    cin >> n;
    FOR(i, n) cin >> t[i];
    int a = 0, b = n-1;
    while (a < b-1) {
	if (t[a] == 0 && t[b] == 0 && b-2 == a) {
	    a++;
	    break;
	}
	if (t[a] == 0) a++;
	if (t[b] == 0) b--;
	t[a]--, t[b]--;
    }
    cout << a + 1 << ' ' << n - b << '\n';
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;

int a[MAXN];

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int sum = accumulate(a,a+n,0);
	int alice = 0, t = 0;
	for (int i = 0; i < n; i++){
		if(t <= sum-t-a[i]){
			alice++;
			t += a[i];
		} else {
			break;
		}
	}
	cout << alice << " " << n-alice << endl;
	return 0;
}


#include <iostream>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  if (N == 1) { std::cout << "1 0\n"; return 0; }
  std::vector<int> xs(N);
  for (int i = 0; i < N; ++i) std::cin >> xs[i];
  int a = 0, b = N-1;
  int t1 = xs[a], t2 = xs[b];
  for (;;) {
    if (t1 <= t2) {
      t2 -= t1;
      if (++a == b) break;
      t1 = xs[a];
    }
    else {
      t1 -= t2;
      if (--b == a) { ++a; break; }
      t2 = xs[b];
    }
  }
  std::cout << a << ' ' << (N-a) << std::endl;
}


#include <sstream>
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair

#define DEBUG(x) cout << #x << " = "; cout << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl;
#define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl;
using namespace std;

const double PI = acos(-1.0);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef pair<int,int> pii;

int n, a[100000];
int ac,bc,at,bt,aptr,bptr;
int main() {
  cin>>n;
  FOR(i,0,n-1)
    cin>>a[i];
  ac=bc=at=bt=aptr=0;
  bptr=n-1;
  while(aptr<=bptr) {
    if(at+a[aptr]<bt+a[bptr]) {
      at+=a[aptr++];
      ac++;
    }else if(at+a[aptr]>bt+a[bptr]) {
      bt+=a[bptr--];
      bc++;
    }else if(at+a[aptr]==bt+a[bptr]) {
      if(aptr!=bptr) {
        at+=a[aptr++];
        bt+=a[bptr--];
        ac++;
        bc++;
      }else {
        at+=a[aptr++];
        ac++;
      }
    }
  }
  cout<<ac<<" "<<bc<<endl;
  return 0;
}


#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef tuple<ll,ll> int2;
typedef tuple<ll,ll,ll> int3;
typedef tuple<ll,ll,ll,ll> int4;

#define all(v) (v).begin(), (v).end()
#define est(v,e) (find(all(v), (e)) != (v).end())
#define pb push_back
#define eb emplace_back
#define SZ(a) ((ll)((a).size()))
#define For(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) For(i,0,n)
#define tag(i,v) rep(i,SZ(v))
#define trace(x)  cerr << #x << " = " << (x) << endl
#define tracev(x) cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl
#define initv(typ, v, n) vector<typ> v(n); rep(i,n) { cin >> v[i]; }
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) (x/y+x%y)

const ll inf = 1LL << 60;
ll toInt(string s) {ll res;stringstream ss;ss<<s;ss>>res;return res;}

int main(void) {

  #define int long long

  #if 0
  #ifdef ONLINE_JUDGE
  ifstream ifile("input.txt");
  if(ifile) freopen("input.txt", "rt", stdin);
  if(ifile) freopen("output.txt", "wt", stdout);
  #endif
  #endif

  int n;
  cin >> n;

  initv(int,v,n);

  vi ans = {0,0};

  vi p = {-1, v.size()};

  vi c = {0,0};

  while(p[1] - p[0] > 1){
    if (c[0] <= c[1]){
      p[0]++;
      c[0] += v[p[0]];
    }
    else {
      p[1]--;
      c[1] += v[p[1]];
    }
  }

  cout << (p[0]+1) << " " << (v.size()-p[1]) << endl;

  return 0;

}


//by tzupengwang™
#include<bits/stdc++.h>
using namespace std;

#define FO(it,c) for (__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef long long ll;
typedef pair<int,int> ii;

int n ;
ll s[ 100005 ] ;

void init() {
	scanf( "%d" , &n ) ;
	for ( int i = 0 ; i < n ; i ++ ) scanf( "%I64d" , &s[ i ] ) ;
}

void process() {
	ll a( 0 ) , b( 0 ) ;
	int l = 0 , r = n - 1 ;
	while ( l <= r ) {
		if ( a == b ) {
			if ( l == r ) break ;
			a += s[ l ++ ] ;
			b += s[ r -- ] ;
		} else if ( a < b ) a += s[ l ++ ] ;
		else b += s[ r -- ] ;
	}
	printf( "%d %d\n" , l , n - l ) ;
}

int main() {
	init() ;
	process() ;
	return 0 ;
}


//by tzupengwang™
#include<bits/stdc++.h>
using namespace std;

#define FO(it,c) for (__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef long long ll;
typedef pair<int,int> ii;

int n ;
ll s[ 100005 ] ;

void init() {
	scanf( "%d" , &n ) ;
	for ( int i = 0 ; i < n ; i ++ ) scanf( "%I64d" , &s[ i ] ) ;
}

void process() {
	ll a( 0 ) , b( 0 ) ;
	int l = 0 , r = n - 1 ;
	while ( l <= r ) {
		if ( a <= b ) a += s[ l ++ ] ;
		else b += s[ r -- ] ;
	}
	printf( "%d %d\n" , l , n - l ) ;
}

int main() {
	init() ;
	process() ;
	return 0 ;
}


//by tzupengwang™
#include<bits/stdc++.h>
using namespace std;

#define FO(it,c) for (__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef long long ll;
typedef pair<int,int> ii;

int n ;
ll s[ 100005 ] ;

void init() {
	scanf( "%d" , &n ) ;
	for ( int i = 0 ; i < n ; i ++ ) scanf( "%I64d" , &s[ i ] ) ;
}

void process() {
	ll a( 0 ) , b( 0 ) ;
	int l = 0 , r = n - 1 ;
	while ( l <= r ) {
		if ( a == b ) a += s[ l ++ ] ;
		else if ( a < b ) a += s[ l ++ ] ;
		else b += s[ r -- ] ;
	}
	printf( "%d %d\n" , l , n - l ) ;
}

int main() {
	init() ;
	process() ;
	return 0 ;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <bitset>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <string>
#include <cstring>
#include <fstream>
#include <functional>
#include <stack>
#include <complex>
#include <wchar.h>
#include <wctype.h>
#include <cmath>
#include <queue>
#include <ctime>
#include <numeric>
#include <bitset>

using namespace std;

template<typename T> T mabs(const T &a){ return a<0?-a:a;}
#define rep(x,y,z) for(int x=(y),e##x=(z);x<e##x;x++)
#define SQR(x) ((x)*(x))
#define all(c) (c).begin(), (c).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;

void run()
{
    int n;
    cin>>n;
    int A[100100];
    rep(i,0,n)
    scanf("%d",A+i);
    int time = 0;
    int Alice = 0, Bob = 0;
    int l = 0, r = n-1;
    rep(i,0,n)
    {
        if (Alice <= Bob)
            Alice += A[l++];
        else
            Bob += A[r--];
    }
    cout<<l<<' '<<n - 1 - r <<endl;
//    while (l < r)
//    {
//        while (l <=r && Alice + A[l] <= time)
//        {
//            l++;
//            Alice += A[l];
//        }
//        while (l < r && Bob + A[r] <= time)
//        {
//            r--;
//            Bob += A[r];
//        }
//
//    }

}

//#define prob "path"

int main()
{
#ifdef _MONYURA_
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    time_t st=clock();
#else
#ifdef prob
    freopen(prob".in","r",stdin);
    freopen(prob".out","w",stdout);
#endif
#endif
    run();
#ifdef _MONYURA_
    printf( "\n=============\n");
    printf("Time: %.2lf sec\n",(clock()-st)/double(CLOCKS_PER_SEC));
#endif

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, total, res, second;
  cin >> n;
  total = 0;
  vector<int> bars(n);
  for (int i = 0; i < n; i++) {
    cin >> bars[i];
    total += bars[i];
  }
  second = 0;
  for (int i = 0; i < n; i++) {
    total -= bars[i];
    if (second > total) {
      res = i;
      break;
    }
    if (second == total) {
      res = i + 1;
      break;
    }

    second += bars[i];
  }

  cout << res << " " << n - res << endl;

  return 0;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string l,r;
int m,d;
int n;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tl,int tr,int cnt){
    if(pos==n){
        return md==0;
    }
    if(dp[pos][md][tl][tr][cnt]!=-1){
        return dp[pos][md][tl][tr][cnt];
    }
    int ans=0;
    int st=0,end=9;
    if(tl){
        if(l[pos]=='a')st=0;
        else
            st=l[pos]-'0';
    }
    if(tr)end=r[pos]-'0';
    if(cnt){
        if(d<=end) {
            int temp=(((md%m)*(10%m))+d)%m;
            ans += rec(pos + 1, temp,tl&(d == st),tr&(d == end),(cnt+1)%2);
            ans%=MOD;
        }
    } else {
        for (int i = st; i <= end; i++) {
            int templ = tl & (i == st);
            int tempr = tr & (i == end);
            int temp=(((md%m)*(10%m))+i)%m;
            if(d!=i) {
                if (i == st && l[pos] == 'a') {
                    ans += rec(pos + 1, temp, templ, tempr, cnt);
                } else {
                    ans += rec(pos + 1, temp, templ, tempr, (cnt + 1) % 2);
                }
                ans %= MOD;
            }
        }
    }
    return dp[pos][md][tl][tr][cnt]=ans;
}
void solve() {
    cin>>m>>d>>l>>r;
    reverse(ALL(l));
    while(l.size()<r.size()){
        l.PB('a');
    }
    reverse(ALL(l));
    n=r.size();
    memset(dp,-1, sizeof(dp));
    cout<<rec(0,0,1,1,0)<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int dp[2005][2005][2][2][2];
string s;
int m,d;
int suri(int idx,int md,bool tight,bool started,bool par)
{
	if(idx==2000)
		return md==0&&started==1;
	int &ans=dp[idx][md][tight][started][par];
	if(ans!=-1)
		return ans;
	ans=0;
	int en=9,i;
	if(tight)
		en=s[idx]-'0';
	if(par)
	{
		if(!started)
			ans+=suri(idx+1,md,tight&&(0==en),started,par);
		else if(d!=0)
			ans+=suri(idx+1,(md*10)%m,tight&&(0==en),started,par^1);
		ans%=MOD;
		for(i=1;i<=en;i++)
		{
			if(i!=d)
			{
				ans+=suri(idx+1,((md*10)+i)%m,tight&&(i==en),1,par^1);
				ans%=MOD;
			}
		}
	}
	else
	{
		if(tight&&d>en)
			return ans=0;
		ans=suri(idx+1,((md*10)+d)%m,tight&&(d==en),started,par^1);
	}
	return ans%=MOD;

}

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{

		cin>>m>>d;
		string a,b;
		cin>>a>>b;
		int ans=1,i,val;
		int tem=0;
		for(i=0;i<a.size();i++)
		{
			val=a[i]-'0';
			tem=(10*tem+val)%m;
			if(i&1)
			{
				if(val!=d)
				{
					ans--;
					break;
				}
			}
			else if(val==d)
			{
				ans--;
				break;
			}
		}
		if(ans&&tem!=0)
			ans--;
		while(a.size()<2000)
		{
			a='0'+a;
			b='0'+b;
		}
		memset(dp,-1,sizeof(dp));
		s=b;
		ans+=suri(0,0,1,0,1);
		s=a;
		memset(dp,-1,sizeof(dp));
		ans=ans+MOD-suri(0,0,1,0,1);

		cout<<ans%MOD<<endl;

	}

	return 0;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string a,b,s;
int m,d;
int dp[2001][2001][2][2][2];
ll rec( ll pos, ll mo, bool tight, bool st, bool even){
    if ( pos == s.size() )
        return (mo==0);
    if ( dp[pos][mo][tight][st][even] != -1 )
        return dp[pos][mo][tight][st][even];
    ll ret = 0;
    ll en = (tight?(s[pos]-'0'):9);
    if ( st == 0 ){
        ret = ( ret + rec(pos+1,mo,tight&(s[pos]=='0'),st,0))%MOD;
        for ( ll i = 1; i <= en; i ++)
            if ( i != d )
                ret = ( ret + rec(pos+1,(mo*10 + i)%m,tight&(i==en),1,1))%MOD;
    }
    else{
        for ( ll i = 0; i <= en; i ++)
        {
            if ( even and (i==d) )
                ret = ( ret + rec(pos+1,(mo*10 + i)%m,tight&(i==en),1,!even))%MOD;
            else if ( (!even) and (i!=d) )
                ret = ( ret + rec(pos+1,(mo*10 + i)%m,tight&(i==en),1,!even))%MOD;
        }
    }
    return dp[pos][mo][tight][st][even] = ret;
}
void solve() {
    cin >> m >> d;
    cin >> a >> b;
    s = b;
    memset(dp,-1,sizeof dp);
    ll ans = rec(0,0,1,0,0);
    s = a;
    memset(dp,-1,sizeof dp);
    ans = (ans - rec(0,0,1,0,0) + MOD)%MOD;
    ll mo = 0;
    bool flg = 1;
    for ( ll i = 0; i < a.size(); i ++){
        if ( i%2 and ((a[i]-'0')!=d))
            flg = 0;
        if ( i%2==0 and ((a[i]-'0')==d))
            flg = 0;
        mo = (mo*10 + (a[i]-'0'))%m;
    }
    if ( mo == 0 and flg ){
        ans = ( ans + 1 )%MOD;
    }
    cout << ans;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
int m,d;
string s;
int n;
int dp[2001][2][2001][2][2];
int rec(int pos,int bound,int md,int taken,int cnt){
    if(pos==n){
//        cout<<t<<endl;
        return ((md==0)&taken);
    }
    if(dp[pos][bound][md][taken][cnt]!=-1){
        return dp[pos][bound][md][taken][cnt];
    }
    int end=9;
    if(bound){
        end=s[pos]-'0';
    }

    int ans=0;
    if(cnt){
        if(d<=end) {
            int temp=(((md%m)*(10%m))+d)%m;
//            if(d==0 && taken==0)return 0;
            ans += rec(pos + 1, bound&(d == end),temp,1,(cnt+1)%2);
            ans%=MOD;
        }
    }else{
        for(int i=0;i<=end;i++){
            int temp=(((md%m)*(10%m))+i)%m;
            if(d!=i) {
                if(i==0 && taken==0){
                    ans+=rec(pos + 1, bound & (i == end), temp, i > 0,cnt);
                }else {
                    ans += rec(pos + 1, bound & (i == end), temp, i > 0,(cnt+1)%2);
                }
            }
            ans%=MOD;
        }
    }
    return dp[pos][bound][md][taken][cnt]=ans;
}
void solve() {
    string l,r;
    cin>>m>>d>>l>>r;
    memset(dp,-1, sizeof(dp));
    n=r.size();s=r;
    int op1=rec(0,1,0,0,0);
//    cout<<op1<<endl;
    reverse(ALL(l));
    int index;
    for(int i=0;i<l.size();i++){
        if(l[i]>='1' ){
            int num=l[i]-'0';
            num--;
            l[i]=num+'0';
            index=i;
            break;
        }
    }
    for(int j=index-1;j>=0;j--){
        if(l[j]=='0'){
            l[j]='9';
        } else{
            break;
        }
    }
    reverse(ALL(l));
    if(l[0]=='0')l=l.substr(1);
    n=l.size();
    s=l;
    memset(dp,-1, sizeof(dp));
    int op2=rec(0,1,0,0,0);
//    cout<<op2<<endl;
    cout<<(op1-op2+MOD)%MOD<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound

#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string l,r;
int m,d;
int n;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tl,int tr,int cnt){
    if(pos==n){
//        cout<<t<<endl;
        return md==0;
    }
    if(dp[pos][md][tl][tr][cnt]!=-1){
        return dp[pos][md][tl][tr][cnt];
    }
    int ans=0;
    int st=0,end=9;
    if(tl){
        if(l[pos]=='a')
            st=0;
        else
            st=l[pos]-'0';
    }
    if(tr)
        end=r[pos]-'0';

    if(cnt){
        if(d>=st && d<=end) {
            int temp=(((md%m)*(10%m))+d)%m;
            int templ = tl & (d == st);
            int tempr = tr & (d == end);
            ans += rec(pos + 1, temp,templ,tempr,(cnt+1)%2);
            ans%=MOD;
        }
    } else {
        for (int i = st; i <= end; i++) {
            int templ = tl & (i == st);
            int tempr = tr & (i == end);
            int temp=(((md%m)*(10%m))+i)%m;
            if(d!=i) {
                if (i == st && l[pos] == 'a') {
                    ans += rec(pos + 1, temp, templ, tempr, cnt);
                } else {
                    ans += rec(pos + 1, temp, templ, tempr, (cnt + 1) % 2);
                }
                ans %= MOD;
            }
        }
    }
    return dp[pos][md][tl][tr][cnt]=ans;
}
void solve() {
    cin>>m>>d>>l>>r;
    reverse(ALL(l));
    while(l.size()<r.size()){
        l.PB('a');
    }
    reverse(ALL(l));
    n=r.size();
    memset(dp,-1, sizeof(dp));
    cout<<rec(0,0,1,1,0)<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
int m,d;
string s;
int n;
int dp[2001][2][2001][2][2];
int rec(int pos,int bound,int md,int taken,int cnt){
    if(pos==n){
//        cout<<t<<endl;
        return ((md==0)&taken);
    }
    if(dp[pos][bound][md][taken][cnt]!=-1){
        return dp[pos][bound][md][taken][cnt];
    }
    int end=9;
    if(bound){
        end=s[pos]-'0';
    }

    int ans=0;
    if(cnt){
        if(d<=end) {
            int temp=(((md%m)*(10%m))+d)%m;
            if(d==0 && taken==0)return 0;
            ans += rec(pos + 1, bound&(d == end),temp,1,(cnt+1)%2);
            ans%=MOD;
        }
    }else{
        for(int i=0;i<=end;i++){
            int temp=(((md%m)*(10%m))+i)%m;
            if(d!=i) {
                if(i==0 && taken==0){
                    ans+=rec(pos + 1, bound & (i == end), temp, i > 0,cnt);
                }else {
                    ans += rec(pos + 1, bound & (i == end), temp, i > 0,(cnt+1)%2);
                }
            }
            ans%=MOD;
        }
    }
    return dp[pos][bound][md][taken][cnt]=ans;
}
void solve() {
    string l,r;
    cin>>m>>d>>l>>r;
    memset(dp,-1, sizeof(dp));
    n=r.size();s=r;
    int op1=rec(0,1,0,0,0);
//    cout<<op1<<endl;
    reverse(ALL(l));
    int index;
    for(int i=0;i<l.size();i++){
        if(l[i]>='1' ){
            int num=l[i]-'0';
            num--;
            l[i]=num+'0';
            index=i;
            break;
        }
    }
    for(int j=index-1;j>=0;j--){
        if(l[j]=='0'){
            l[j]='9';
        } else{
            break;
        }
    }
    reverse(ALL(l));
    if(l[0]=='0')l=l.substr(1);
    n=l.size();
    s=l;
    memset(dp,-1, sizeof(dp));
    int op2=rec(0,1,0,0,0);
//    cout<<op2<<endl;
    cout<<(op1-op2+MOD)%MOD<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string l,r,s;
int m,d;
int dp[2001][2001][2][2][2];
ll rec( ll pos, ll mo, bool tight, bool st, bool even){
    if ( pos == s.size() )
        return (mo==0);
    if ( dp[pos][mo][tight][st][even] != -1 )
        return dp[pos][mo][tight][st][even];
    ll ret = 0;
    ll en = (tight?(s[pos]-'0'):9);
    if ( st == 0 ){
        ret = ( ret + rec(pos+1,mo,tight&(s[pos]=='0'),st,0))%MOD;
        for ( ll i = 1; i <= en; i ++)
            if ( i != d )
                ret = ( ret + rec(pos+1,(mo*10 + i)%m,tight&(i==en),1,1))%MOD;
    }
    else{
        for ( ll i = 0; i <= en; i ++)
        {
            if ( even and (i==d) )
                ret = ( ret + rec(pos+1,(mo*10 + i)%m,tight&(i==en),1,!even))%MOD;
            else if ( (!even) and (i!=d) )
                ret = ( ret + rec(pos+1,(mo*10 + i)%m,tight&(i==en),1,!even))%MOD;
        }
    }
    return dp[pos][mo][tight][st][even] = ret;
}
void solve() {
    cin>>m>>d>>l>>r;
    s=r;
    memset(dp,-1, sizeof(dp));
    int ans=rec(0,0,1,0,0);
    memset(dp,-1, sizeof(dp));
    s=l;
    ans-=rec(0,0,1,0,0);
    int mo = 0;
    bool flg = 1;
    for ( int i = 0; i < l.size(); i ++){
        if ( i%2 and ((l[i]-'0')!=d))
            flg = 0;
        if ( i%2==0 and ((l[i]-'0')==d))
            flg = 0;
        mo = (mo*10 + (l[i]-'0'))%m;
    }
    if ( mo == 0 and flg ){
        ans = ( ans + 1 )%MOD;
    }
    cout<<(ans+MOD)%MOD<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string l,r,s;
int m,d;
int n;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tight,int st,int cnt){
    if(pos==n){
        return md==0;
    }
    if(dp[pos][md][tight][st][cnt]!=-1){
        return dp[pos][md][tight][st][cnt];
    }
    int ans=0;
    int end=9;
    if(tight){
        end=s[pos]-'0';
    }
    if ( st == 0 ){
        ans +=  rec(pos+1,md,tight&(s[pos]=='0'),st,0);
        ans%=MOD;
        for ( int i = 1; i <= end; i ++)
            if ( i != d )
                ans = ( ans + rec(pos+1,(md*10 + i)%m,tight&(i==end),1,1))%MOD;
    }
    else{
        for ( int i = 0; i <= end; i ++)
        {
            if ( cnt and (i==d) )
                ans = ( ans + rec(pos+1,(md*10 + i)%m,tight&(i==end),1,!cnt))%MOD;
            else if ( (!cnt) and (i!=d) )
                ans = ( ans + rec(pos+1,(md*10 + i)%m,tight&(i==end),1,!cnt))%MOD;
        }
    }
    return dp[pos][md][tight][st][cnt]=ans;
}
void solve() {
    cin>>m>>d>>l>>r;
    n=r.size();
    s=r;
    memset(dp,-1, sizeof(dp));
    int ans=rec(0,0,1,0,0);
    memset(dp,-1, sizeof(dp));
    n=l.size();
    s=l;
    ans-=rec(0,0,1,0,0);
    int mo = 0;
    bool flg = 1;
    for ( int i = 0; i < l.size(); i ++){
        if ( i%2 and ((l[i]-'0')!=d))
            flg = 0;
        if ( i%2==0 and ((l[i]-'0')==d))
            flg = 0;
        mo = (mo*10 + (l[i]-'0'))%m;
    }
    if ( mo == 0 and flg ){
        ans = ( ans + 1 )%MOD;
    }
    cout<<(ans+MOD)%MOD<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string l,r;
int m,d;
int n;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tl,int tr,int cnt){
    if(pos==n){
//        cout<<t<<endl;
        return md==0;
    }
    if(dp[pos][md][tl][tr][cnt]!=-1){
        return dp[pos][md][tl][tr][cnt];
    }
    int ans=0;
    int st=0,end=9;
    if(tl){
        if(l[pos]=='a')
            st=0;
        else
            st=l[pos]-'0';
    }
    if(tr)
        end=r[pos]-'0';

    if(cnt){
        if(d>=st && d<=end) {
            int temp=(((md%m)*(10%m))+d)%m;
            int templ = tl & (d == st);
            int tempr = tr & (d == end);
            ans += rec(pos + 1, temp,templ,tempr,(cnt+1)%2);
            ans%=MOD;
        }
    } else {
        for (int i = st; i <= end; i++) {
            int templ = tl & (i == st);
            int tempr = tr & (i == end);
            int temp=(((md%m)*(10%m))+i)%m;
            if(d!=i) {
                if (i == st && l[pos] == 'a') {
                    ans += rec(pos + 1, temp, templ, tempr, cnt);
                } else {
                    ans += rec(pos + 1, temp, templ, tempr, (cnt + 1) % 2);
                }
                ans %= MOD;
            }
        }
    }
    return dp[pos][md][tl][tr][cnt]=ans;
}
void solve() {
    cin>>m>>d>>l>>r;
    reverse(ALL(l));
    while(l.size()<r.size()){
        l.PB('a');
    }
    reverse(ALL(l));
    n=r.size();
    memset(dp,-1, sizeof(dp));
    cout<<rec(0,0,1,1,0)<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
const int INF = 1e9;
int fast_pow(int x, int y, int p);

string a,b;
int M,D;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tl,int tr,int xr ){
	if(pos==b.size()){
		return md == 0;
	}
	int& ans = dp[pos][md][tl][tr][xr];
	if(ans!=-1)return ans;
	ans = 0;
	int l = 0 , r = 9;
	if(tl)l = a[pos]-'0';
	if(tr)r = b[pos]-'0';
	if(xr==0){
		for(int i=l;i<=r;i++){
			if(i!=D){
				ans+=rec(pos+1,(md*10+i)%M,tl&(i==a[pos]-'0'),tr&(i==b[pos]-'0'),xr^1);
				ans%=MOD;
			}
		}
	}else{
		if(D>=l && D<=r){
			ans+=rec(pos+1,(md*10+D)%M,tl&(D==a[pos]-'0'),tr&(D==b[pos]-'0'),xr^1);
			ans%=MOD;
		}
	}
	return ans;
}
void solve() {
	cin>>M>>D;
	cin>>a>>b;
	memset(dp,-1,sizeof dp);
	cout<<rec(0,0,1,1,0);

}

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS;
	int test = 1;
	// cin>>test;
	for (int i = 1; i <= test; i++) {
        // cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}
int fast_pow(int x, int y, int p) {
	int res = 1;
	x = x % p;
	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string l,r;
int m,d;
int n;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tl,int tr,int cnt,string t){
    if(pos==n){
//        cout<<t<<endl;
        return md==0;
    }
    if(dp[pos][md][tl][tr][cnt]!=-1){
        return dp[pos][md][tl][tr][cnt];
    }
    int ans=0;
    int st=0,end=9;
    if(tl){
        if(l[pos]=='a')
            st=0;
        else
            st=l[pos]-'0';
    }
    if(tr)
        end=r[pos]-'0';

    if(cnt){
        if(d>=st && d<=end) {
            int temp=(((md%m)*(10%m))+d)%m;
            int templ = tl & (d == st);
            int tempr = tr & (d == end);
            ans += rec(pos + 1, temp,templ,tempr,(cnt+1)%2,t+to_string(d));
            ans%=MOD;
        }
    } else {
        for (int i = st; i <= end; i++) {
            int templ = tl & (i == st);
            int tempr = tr & (i == end);
            int temp=(((md%m)*(10%m))+i)%m;
            if(d!=i) {
                if (i == st && l[pos] == 'a') {
                    ans += rec(pos + 1, temp, templ, tempr, cnt,t+to_string(i));
                } else {
                    ans += rec(pos + 1, temp, templ, tempr, (cnt + 1) % 2,t+to_string(i));
                }
                ans %= MOD;
            }
        }
    }
    return dp[pos][md][tl][tr][cnt]=ans;
}
void solve() {
    cin>>m>>d>>l>>r;
    reverse(ALL(l));
    while(l.size()<r.size()){
        l.PB('a');
    }
    reverse(ALL(l));
    n=r.size();
    memset(dp,-1, sizeof(dp));
    cout<<rec(0,0,1,1,0,"")<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string l,r;
int m,d;
int n;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tl,int tr,int cnt){
    if(pos==n){
//        cout<<t<<endl;
        return md==0;
    }
    if(dp[pos][md][tl][tr][cnt]!=-1){
        return dp[pos][md][tl][tr][cnt];
    }
    int ans=0;
    int st=0,end=9;
    if(tl){
        if(l[pos]=='a')
            st=0;
        else
            st=l[pos]-'0';
    }
    if(tr)
        end=r[pos]-'0';

    if(cnt){
        if(d>=st && d<=end) {
            int temp=(((md%m)*(10%m))+d)%m;
            int templ = tl & (d == st);
            int tempr = tr & (d == end);
            ans += rec(pos + 1, temp,templ,tempr,(cnt+1)%2);
            ans%=MOD;
        }
    } else {
        for (int i = st; i <= end; i++) {
            int templ = tl & (i == st);
            int tempr = tr & (i == end);
            int temp=(((md%m)*(10%m))+i)%m;
            if(d!=i) {
                if (i == st && l[pos] == 'a') {
                    ans += rec(pos + 1, temp, templ, tempr, cnt);
                } else {
                    ans += rec(pos + 1, temp, templ, tempr, (cnt + 1) % 2);
                }
                ans %= MOD;
            }
        }
    }
    return dp[pos][md][tl][tr][cnt]=ans;
}
void solve() {
    cin>>m>>d>>l>>r;
    reverse(ALL(l));
    while(l.size()<r.size()){
        l.PB('a');
    }
    reverse(ALL(l));
    n=r.size();
    memset(dp,-1, sizeof(dp));
    cout<<rec(0,0,1,1,0)<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
const int INF = 1e9;
int fast_pow(int x, int y, int p);

string s;
int M,D;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tight,int started,int xr ){
	// trace5(pos,md,tight,started,xr);
	if(pos==s.size()){
		return md == 0 && started;
	}
	int& ans = dp[pos][md][tight][started][xr];
	if(ans!=-1)return ans;
	ans = 0;
	int en = 9;
	if(tight)en = s[pos]-'0';
	if(started){
		if(xr){
			if(D<=en){
				ans+=rec(pos+1,(md*10+D)%M,tight&(D==en),1,xr^1);
				ans%=MOD;
			}
		}else{
			for(int i=0;i<=en;i++){
				if(i!=D){
					ans+=rec(pos+1,(md*10+i)%M,tight&(i==(s[pos]-'0')),1,xr^1);
					ans%=MOD;
				}
			}
		}
	}else{
		ans+=rec(pos+1,0,0,0,0);
		ans%=MOD;
		for(int i=1;i<=en;i++){
			if(i!=D){
				ans+=rec(pos+1,(md*10+i)%M,tight&(i==s[pos]-'0'),1,1);
				ans%=MOD;
			}
		}
	}
	return ans;
}
void solve() {
	cin>>M>>D;
	string a,b;cin>>a>>b;
	memset(dp,-1,sizeof dp);
	s = b;
	int ans = rec(0,0,1,0,0);
	memset(dp,-1,sizeof dp);
	s = a;
	ans -= rec(0,0,1,0,0);
	int md = 0 , ch = 1;
	for(int i = 0;i<s.size();i++){
		int num = s[i]-'0';
		if(i%2==1 && num!=D)ch=0;
		if(i%2==0 && num==D)ch=0;
		md = (md*10 + num)%M;
	}
	ans+=(md==0 && ch);
	ans=(ans%MOD+MOD)%MOD;
	cout<<ans;

}

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS;
	int test = 1;
	// cin>>test;
	for (int i = 1; i <= test; i++) {
        // cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}
int fast_pow(int x, int y, int p) {
	int res = 1;
	x = x % p;
	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
string l,r,s;
int m,d;
int n;
int dp[2001][2001][2][2][2];
int rec(int pos,int md,int tight,int st,int cnt){
    if(pos==n){
        return md==0;
    }
    if(dp[pos][md][tight][st][cnt]!=-1){
        return dp[pos][md][tight][st][cnt];
    }
    int ans=0;
    int end=9;
    if(tight){
        end=s[pos]-'0';
    }
    if ( st == 0 ){
        ans +=  rec(pos+1,md,tight&(s[pos]=='0'),st,0);
        ans%=MOD;
        for ( int i = 1; i <= end; i ++)
            if ( i != d )
                ans = ( ans + rec(pos+1,(md*10 + i)%m,tight&(i==end),1,1))%MOD;
    }
    else{
        for ( int i = 0; i <= end; i ++)
        {
            if ( cnt && (i==d) )
                ans = ( ans + rec(pos+1,(md*10 + i)%m,tight&(i==end),1,!cnt))%MOD;
            else if ( (!cnt) && (i!=d) )
                ans = ( ans + rec(pos+1,(md*10 + i)%m,tight&(i==end),1,!cnt))%MOD;
        }
    }
    return dp[pos][md][tight][st][cnt]=ans;
}
void solve() {
    cin>>m>>d>>l>>r;
    n=r.size();
    s=r;
    memset(dp,-1, sizeof(dp));
    int ans=rec(0,0,1,0,0);
    memset(dp,-1, sizeof(dp));
    n=l.size();
    s=l;
    ans-=rec(0,0,1,0,0);
    int mo = 0;
    bool flg = 1;
    for ( int i = 0; i < l.size(); i ++){
        if ( i%2 && ((l[i]-'0')!=d))
            flg = 0;
        if ( i%2==0 && ((l[i]-'0')==d))
            flg = 0;
        mo = (mo*10 + (l[i]-'0'))%m;
    }
    if ( mo == 0 && flg ){
        ans = ( ans + 1 )%MOD;
    }
    cout<<(ans+MOD)%MOD<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
int m,d;
string s;
int n;
int dp[2100][2][2100][2][2];
int rec(int pos,int bound,int md,int taken,int cnt){
    if(pos==n){
//        cout<<t<<endl;
        return ((md==0)&taken);
    }
    if(dp[pos][bound][md][taken][cnt]!=-1){
        return dp[pos][bound][md][taken][cnt];
    }
    int end=9;
    if(bound){
        end=s[pos]-'0';
    }

    int ans=0;
    if(cnt){
        if(d<=end) {
            int temp=(((md%m)*(10%m))+d)%m;
            if(d==0 && taken==0)return 0;
            ans += rec(pos + 1, bound&(d == end),temp,1,(cnt+1)%2);
            ans%=MOD;
        }
    }else{
        for(int i=0;i<=end;i++){
            int temp=(((md%m)*(10%m))+i)%m;
            if(d!=i) {
                if(i==0 && taken==0){
                    ans+=rec(pos + 1, bound & (i == end), temp, i > 0,cnt);
                }else {
                    ans += rec(pos + 1, bound & (i == end), temp, i > 0,(cnt+1)%2);
                }
            }
            ans%=MOD;
        }
    }
    return dp[pos][bound][md][taken][cnt]=ans;
}
void solve() {
    string l,r;
    cin>>m>>d>>l>>r;
    memset(dp,-1, sizeof(dp));
    n=r.size();s=r;
    int op1=rec(0,1,0,0,0);
//    cout<<op1<<endl;
    reverse(ALL(l));
    int index;
    for(int i=0;i<l.size();i++){
        if(l[i]>='1' ){
            int num=l[i]-'0';
            num--;
            l[i]=num+'0';
            index=i;
            break;
        }
    }
    for(int j=index-1;j>=0;j--){
        if(l[j]=='0'){
            l[j]='9';
        } else{
            break;
        }
    }
    reverse(ALL(l));
    if(l[0]=='0')l=l.substr(1);
    n=l.size();
    s=l;
    memset(dp,-1, sizeof(dp));
    int op2=rec(0,1,0,0,0);
//    cout<<op2<<endl;
    cout<<(op1-op2+MOD)%MOD<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#include<unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
#define fio ios_base::sync_with_stdio(false)
#define mod 1000000007
#define mod1 mod
#define mod2 1000000007
#define li long long int
#define ll li
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%I64d",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 10000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<ll,ll>
#define pdd pair<double,double>
#define pic pair<int,char>
#define N 400000
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535

// #define INTMAX 200000000

// using namespace boost;
// #define si short int

using namespace std;
using namespace __gnu_pbds;
typedef priority_queue<ll, vector<ll > > max_pq;
typedef priority_queue<ll, vector<ll> , greater<ll>  > min_pq;
ll toint(const string &s) {stringstream ss; ss << s; ll x; ss >> x; return x;}
string tostring ( ll number ){stringstream ss; ss<< number; return ss.str();}

// using namespace __gnu_pbds;
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<pii , null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll , pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
#define nn 200005
ll dp[ 2005 ][ 2005 ][ 2 ][ 2 ][ 2 ];
string s;
string a,b;
ll d,m;
ll solve ( ll pos, ll mo, bool tight, bool st, bool even){
    if ( pos == s.size() )
        return (mo==0);
    if ( dp[pos][mo][tight][st][even] != -1 )
        return dp[pos][mo][tight][st][even];
    ll ret = 0;
    ll en = (tight?(s[pos]-'0'):9);
    if ( st == 0 ){
        ret = ( ret + solve(pos+1,mo,tight&(s[pos]=='0'),st,0))%mod;
        for ( ll i = 1; i <= en; i ++)
            if ( i != d )
                ret = ( ret + solve(pos+1,(mo*10 + i)%m,tight&(i==en),1,1))%mod;
    }
    else{
        for ( ll i = 0; i <= en; i ++)
        {
            if ( even and (i==d) )
                ret = ( ret + solve(pos+1,(mo*10 + i)%m,tight&(i==en),1,!even))%mod;
            else if ( (!even) and (i!=d) )
                ret = ( ret + solve(pos+1,(mo*10 + i)%m,tight&(i==en),1,!even))%mod;
        }
    }
    return dp[pos][mo][tight][st][even] = ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    cin >> m >> d;
    cin >> a >> b;
    s = b;
    memset(dp,-1,sizeof dp);
    ll ans = solve(0,0,1,0,0);
    s = a;
    memset(dp,-1,sizeof dp);
    ans = (ans - solve(0,0,1,0,0) + mod)%mod;
    ll mo = 0;
    bool flg = 1;
    for ( ll i = 0; i < a.size(); i ++){
        if ( i%2 and ((a[i]-'0')!=d))
            flg = 0;
        if ( i%2==0 and ((a[i]-'0')==d))
            flg = 0;
        mo = (mo*10 + (a[i]-'0'))%m;
    }
    if ( mo == 0 and flg ){
        ans = ( ans + 1 )%mod;
    }
    cout << ans;

}


#include <iostream>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

const int md = 1000000007;

int n;
int m, d;
int a[2000], b[2000];
vector<int> decimal;
vector<vector<int> > digits;
vector<vector<int> > amt;

inline int sum(int a, int b)
{
	a += b;
	return a < md ? a : a - md;
}
inline int mul(int a, int b)
{
	return (int)((long long)a * b % md);
}

void get(int x)
{
	vector<int> current(m);
	int sz = digits[x].size();
	int decim = decimal[n - x * 2 - 1];
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < sz; ++j) {
			int ind = (i + digits[x][j] * decim) % m;
			current[ind] = sum(amt[x - 1][i], current[ind]);
		}
	}
	for (int i = 0; i < m; ++i) amt[x][i] = mul(current[i], amt[x - 1][i]);
}

int main()
{
	scanf("%d%d", &m, &d);
	char buf[2001];
	scanf("%s", buf);
	n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[n - i - 1] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[n - i - 1] - '0';

	decimal.resize(n);
	decimal[0] = 1 % m;
	for (int i = 1; i < n; ++i) decimal[i] = 10 * decimal[i - 1] % m;

	int put = n / 2 + (n & 1);

	digits.resize(put);
	int i;
	for (i = n - 1; i >= 0 && a[i] == b[i]; --i) {
		int k = (n - i - 1) >> 1;
		if ((n - i - 1) & 1 && a[i] != d) {
			printf("0\n");
			return 0;
		}
		if (!((n - i - 1) & 1)) {
			if (a[i] == d) {
				printf("0\n");
				return 0;
			}
			digits[k].push_back(a[i]);
		}
	}
	if (i >= 0) {
		if ((n - i - 1) & 1) {
			if ((a[i] > d || b[i] < d)) {
				printf("0\n");
				return 0;
			}
			--i;
		}
		int k = (n - i - 1) >> 1;
		for (int j = a[i]; j <= b[i]; ++j) if (j != d) digits[k].push_back(j);
		i -= 2;
		while (i >= 0) {
			k = (n - i - 1) >> 1;
			digits[k].resize(9);
			for (int j = 0; j <= 9; ++j) {
				if (j != d) digits[k][j > d ? j - 1 : j] = j;
			}
			i -= 2;
		}
	}

	amt.resize(put, vector<int>(m));
	for (int i = 0; i < digits[0].size(); ++i) ++amt[0][digits[0][i] * decimal[n - 1] % m];
	for (int i = 1; i < put; ++i) get(i);

	int evenres = 0;
	for (int i = n - 2; i >= 0; i -= 2) evenres += d * decimal[i] % m;
	evenres = m - evenres;
	evenres = ((evenres % m) + m) % m;
	printf("%d\n", amt[put - 1][evenres]);
	return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

const int md = 1000000007;

int n;
int m, d;
int a[2000], b[2000];
vector<int> decimal;
vector<vector<int> > digits;
vector<vector<int> > amt;

inline int sum(long long a, int b)
{
	return (a + b) % md;
}

void get(int x)
{
	vector<int> current(m);
	int sz = digits[x].size();
	int decim = decimal[n - x * 2 - 1];
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < sz; ++j) {
			int ind = (i + digits[x][j] * decim) % m;
			current[ind] = sum(amt[x - 1][i], current[ind]);
		}
	}
	for (int i = 0; i < m; ++i) amt[x][i] = current[i];
}

int main()
{
	scanf("%d%d", &m, &d);
	char buf[2001];
	scanf("%s", buf);
	n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[n - i - 1] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[n - i - 1] - '0';

	decimal.resize(n);
	decimal[0] = 1 % m;
	for (int i = 1; i < n; ++i) decimal[i] = 10 * decimal[i - 1] % m;

	int put = n / 2 + (n & 1);

	digits.resize(put);
	int i;
	for (i = n - 1; i >= 0 && a[i] == b[i]; --i) {
		int k = (n - i - 1) >> 1;
		if ((n - i - 1) & 1 && a[i] != d) {
			printf("0\n");
			return 0;
		}
		if (!((n - i - 1) & 1)) {
			if (a[i] == d) {
				printf("0\n");
				return 0;
			}
			digits[k].push_back(a[i]);
		}
	}
	if (i >= 0) {
		if ((n - i - 1) & 1) {
			if ((a[i] > d || b[i] < d)) {
				printf("0\n");
				return 0;
			}
			--i;
		}
		int k = (n - i - 1) >> 1;
		for (int j = a[i]; j <= b[i]; ++j) if (j != d && (i == 0 || ((j != a[i] || a[i - 1] <= d) && (j != b[i] || b[i - 1] >= d)))) digits[k].push_back(j);
		i -= 2;
		while (i >= 0) {
			k = (n - i - 1) >> 1;
			digits[k].resize(9);
			for (int j = 0; j <= 9; ++j) {
				if (j != d) digits[k][j > d ? j - 1 : j] = j;
			}
			i -= 2;
		}
	}

	amt.resize(put, vector<int>(m));
	for (int i = 0; i < digits[0].size(); ++i) ++amt[0][digits[0][i] * decimal[n - 1] % m];
	for (int i = 1; i < put; ++i) get(i);

	int evenres = 0;
	for (int i = n - 2; i >= 0; i -= 2) evenres += d * decimal[i] % m;
	evenres = m - evenres;
	evenres = ((evenres % m) + m) % m;
	printf("%d\n", amt[put - 1][evenres]);
	return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

const int md = 1000000007;

int n;
int m, d;
int a[2000], b[2000];
vector<int> decimal;
vector<vector<int> > digits;
vector<vector<int> > amt;

inline int sum(int a, int b)
{
	a += b;
	return a < md ? a : a - md;
}
inline int mul(int a, int b)
{
	return (int)((long long)a * b % md);
}

void get(int x)
{
	vector<int> current(m);
	int sz = digits[x].size();
	int decim = decimal[n - x * 2 - 1];
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < sz; ++j) {
			int ind = (i + digits[x][j] * decim) % m;
			current[ind] = sum(amt[x - 1][i], current[ind]);
		}
	}
	for (int i = 0; i < m; ++i) amt[x][i] = mul(current[i], amt[x - 1][i]);
}

int main()
{
	scanf("%d%d", &m, &d);
	char buf[2001];
	scanf("%s", buf);
	n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[n - i - 1] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[n - i - 1] - '0';

	decimal.resize(n);
	decimal[0] = 1 % m;
	for (int i = 1; i < n; ++i) decimal[i] = 10 * decimal[i - 1] % m;

	int put = n / 2 + (n & 1);

	digits.resize(put);
	int i;
	for (i = n - 1; i >= 0 && a[i] == b[i]; --i) {
		int k = (n - i - 1) >> 1;
		if ((n - i - 1) & 1 && a[i] != d) {
			printf("0\n");
			return 0;
		}
		if (!((n - i - 1) & 1)) {
			if (a[i] == d) {
				printf("0\n");
				return 0;
			}
			digits[k].push_back(a[i]);
		}
	}
	if (i >= 0) {
		if ((n - i - 1) & 1) {
			if ((a[i] > d || b[i] < d)) {
				printf("0\n");
				return 0;
			}
			--i;
		}
		int k = (n - i - 1) >> 1;
		for (int j = a[i]; j <= b[i]; ++j) if (j != d) digits[k].push_back(j);
		if (i != 0 && b[i - 1] < d) digits[k].resize(digits[k].size() - 1);
		i -= 2;
		while (i >= 0) {
			k = (n - i - 1) >> 1;
			digits[k].resize(9);
			for (int j = 0; j <= 9; ++j) {
				if (j != d) digits[k][j > d ? j - 1 : j] = j;
			}
			i -= 2;
		}
	}

	amt.resize(put, vector<int>(m));
	for (int i = 0; i < digits[0].size(); ++i) ++amt[0][digits[0][i] * decimal[n - 1] % m];
	for (int i = 1; i < put; ++i) get(i);

	int evenres = 0;
	for (int i = n - 2; i >= 0; i -= 2) evenres += d * decimal[i] % m;
	evenres = m - evenres;
	evenres = ((evenres % m) + m) % m;
	printf("%d\n", amt[put - 1][evenres]);
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int md = 1000000007;

void sum(int &a, int b)
{
	a += b;
	if (a > md) a -= md;
}

vector<int> decim;

int solve(int *a, int n, int m, int d)
{
	vector<vector<int> > dp(n, vector<int>(m));
	vector<int> pr(n);
	for (int i = 0; i < a[0]; ++i) if (i != d) ++dp[0][i * decim[0] % m];
	pr[0] = a[0] * decim[0] % m;
	for (int i = 1; i < n; ++i) {
		if (i & 1) {
			for (int j = 0; j < m; ++j) sum(dp[i][(j + d * decim[i]) % m], dp[i - 1][j]);
			if (pr[i - 1] != -1) {
				if (d < a[i]) sum(dp[i][(pr[i - 1] + d * decim[i]) % m], 1);
				if (a[i] == d) pr[i] = (pr[i - 1] + d * decim[i]) % m;
				else pr[i] = -1;
			}
			else pr[i] = -1;
		}
		else {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < 10; ++k) if (k != d) sum(dp[i][(j + k * decim[i]) % m], dp[i - 1][j]);
			}
			if (pr[i - 1] != -1) {
				for (int k = 0; k < a[i]; ++k) if (k != d) sum(dp[i][(pr[i - 1] + k * decim[i]) % m], 1);
				if (a[i] != d) pr[i] = (pr[i - 1] + a[i] * decim[i]) % m;
				else pr[i] = -1;
			}
			else pr[i] = -1;
		}
	}
	return dp[n - 1][0] + (pr[n - 1] == 0);
}
bool check(int *a, int n, int m, int d)
{
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if (i & 1 && a[i] != d) return 0;
		res = (res + a[i] * decim[i]) % m;
	}
	return !res;
}

int main()
{
	int m, d;
	scanf("%d%d", &m, &d);
	int a[2000], b[2000];
	char buf[2000];
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[i] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[i] - '0';

	decim.resize(n);
	decim[n - 1] = 1 % m;
	for (int i = n - 2; i >= 0; --i) decim[i] = decim[i + 1] * 10 % m;

	printf("%d\n", solve(b, n, m, d) - solve(a, n, m, d) + check(a, n, m, d));
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int md = 1000000007;

void sum(int &a, int b)
{
	a += b;
	if (a > md) a -= md;
}
int dif(int a, int b)
{
	a -= b;
	if (a < 0) return a + md;
	return a;
}

vector<int> decim;

int solve(int *a, int n, int m, int d)
{
	vector<vector<int> > dp(n, vector<int>(m));
	vector<int> pr(n);
	for (int i = 0; i < a[0]; ++i) if (i != d) ++dp[0][i * decim[0] % m];
	pr[0] = a[0] != d ? a[0] * decim[0] % m : -1;
	for (int i = 1; i < n; ++i) {
		if (i & 1) {
			for (int j = 0; j < m; ++j) sum(dp[i][(j + d * decim[i]) % m], dp[i - 1][j]);
			if (pr[i - 1] != -1) {
				if (d < a[i]) sum(dp[i][(pr[i - 1] + d * decim[i]) % m], 1);
				if (a[i] == d) pr[i] = (pr[i - 1] + d * decim[i]) % m;
				else pr[i] = -1;
			}
			else pr[i] = -1;
		}
		else {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < 10; ++k) if (k != d) sum(dp[i][(j + k * decim[i]) % m], dp[i - 1][j]);
			}
			if (pr[i - 1] != -1) {
				for (int k = 0; k < a[i]; ++k) if (k != d) sum(dp[i][(pr[i - 1] + k * decim[i]) % m], 1);
				if (a[i] != d) pr[i] = (pr[i - 1] + a[i] * decim[i]) % m;
				else pr[i] = -1;
			}
			else pr[i] = -1;
		}
	}
	return dp[n - 1][0] + (pr[n - 1] == 0);
}
bool check(int *a, int n, int m, int d)
{
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if (i & 1 && a[i] != d) return 0;
		if (!(i & 1) && a[i] == d) return 0;
		res = (res + a[i] * decim[i]) % m;
	}
	return !res;
}

int main()
{
	int m, d;
	scanf("%d%d", &m, &d);
	int a[2000], b[2000];
	char buf[2001];
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[i] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[i] - '0';

	decim.resize(n);
	decim[n - 1] = 1 % m;
	for (int i = n - 2; i >= 0; --i) decim[i] = decim[i + 1] * 10 % m;

	printf("%d\n", dif(solve(b, n, m, d), solve(a, n, m, d)) + check(a, n, m, d));
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int md = 1000000007;

inline int mul(int a, int b)
{
	return (int)((long long)a * b);
}
inline void sum(int &a, int b)
{
	a += b;
	if (a >= md) a -= md;
}

vector<int> decim;

int opt(int *a, int size, int d)
{
	for (int i = 1; i < size; i += 2) {
		if (a[i] < d) {
			while (!a[--i]);
			--a[i];
			if (i == 0 && a[i] == 0) return 0;
			++i;
			while (i < size) {
				a[i] = 9;
				++i;
			}
			return opt(a, size, d);
		}
	}
	return 1;
}

int amount(int *a, int n, int size, int m, int d, int ind)
{
	if (!a[0]) return 0;
	if (!opt(a, size, d)) return 0;
	pair<vector<vector<int> >, vector<vector<int> > > amt(vector<vector<int> >(n, vector<int>(m)), vector<vector<int> >(n, vector<int>(m)));
	if (a[0] != d) amt.second[0][(a[0] * decim[0]) % m] = 1;
	for (int i = 1; i < a[0]; ++i) if (i != d) ++amt.first[0][(i * decim[0]) % m];
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			for (int k = 0; k < 10; ++k) if (k != d) sum(amt.first[i][(j + k * decim[i * 2]) % m], amt.first[i - 1][j]);
			for (int k = 0; k < a[i * 2]; ++k) if (k != d) sum(amt.first[i][(j + k * decim[i * 2]) % m], amt.second[i - 1][j]);
			if (a[2 * i] != d) sum(amt.second[i][(j + a[i * 2] * decim[i * 2]) % m], amt.second[i - 1][j]);
		}
	}
	return (amt.first[n - 1][ind] + amt.second[n - 1][ind]) % md;
}

void minusone(int *a, int size)
{
	while (!a[size - 1]) --size;
	--a[size];
}

int main()
{
	int m, d, a[2000], b[2000];
	scanf("%d%d", &m, &d);
	char buf[2001];
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[i] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[i] - '0';
	decim.resize(n);
	decim[n - 1] = 1 % m;
	for (int i = n - 2; i >= 0; --i) decim[i] = decim[i + 1] * 10 % m;
	int ind = 0;
	for (int i = 1; i < n; i += 2) ind += decim[i] * d;
	ind = - ind;
	ind = (ind % m + m) % m;
	minusone(a, n);
	printf("%d\n", amount(b, n / 2 + (n & 1), n, m, d, ind) - amount(a, n / 2 + (n & 1), n, m, d, ind));
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int md = 1000000007;

inline int mul(int a, int b)
{
	return (int)((long long)a * b);
}
inline void sum(int &a, int b)
{
	a += b;
	if (a >= md) a -= md;
}

vector<int> decim;

int opt(int *a, int size, int d)
{
	for (int i = 1; i < size; i += 2) {
		if (a[i] < d) {
			while (!a[--i]);
			--a[i];
			if (i == 0) return 0;
			return opt(a, size, d);
		}
	}
	return 1;
}

int amount(int *a, int n, int size, int m, int d, int ind)
{
	if (!a[0]) return 0;
	if (!opt(a, size, d)) return 0;
	pair<vector<vector<int> >, vector<vector<int> > > amt(vector<vector<int> >(n, vector<int>(m)), vector<vector<int> >(n, vector<int>(m)));
	if (a[0] != d) amt.second[0][(a[0] * decim[0]) % m] = 1;
	for (int i = 1; i < a[0]; ++i) if (i != d) ++amt.first[0][(i * decim[0]) % m];
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			for (int k = 0; k < 10; ++k) if (k != d) sum(amt.first[i][(j + k * decim[i * 2]) % m], amt.first[i - 1][j]);
			for (int k = 0; k < a[i * 2]; ++k) if (k != d) sum(amt.first[i][(j + k * decim[i * 2]) % m], amt.second[i - 1][j]);
			if (a[i] != d) sum(amt.second[i][(j + a[i * 2] * decim[i * 2]) % m], amt.second[i - 1][j]);
		}
	}
	return (amt.first[n - 1][ind] + amt.second[n - 1][ind]) % md;
}

void minusone(int *a, int size)
{
	while (!a[size - 1]) --size;
	--a[size];
}

int main()
{
	int m, d, a[2000], b[2000];
	scanf("%d%d", &m, &d);
	char buf[2001];
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[i] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[i] - '0';
	decim.resize(n);
	decim[n - 1] = 1 % m;
	for (int i = n - 2; i >= 0; --i) decim[i] = decim[i + 1] * 10 % m;
	int ind = 0;
	for (int i = 1; i < n; i += 2) ind += decim[i] * d;
	ind = - ind;
	ind = (ind % m + m) % m;
	minusone(a, n);
	printf("%d\n", amount(b, n / 2 + (n & 1), n, m, d, ind) - amount(a, n / 2 + (n & 1), n, m, d, ind));
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int md = 1000000007;

inline int mul(int a, int b)
{
	return (int)((long long)a * b);
}
inline void sum(int &a, int b)
{
	a += b;
	if (a >= md) a -= md;
}

vector<int> decim;

int opt(int *a, int size, int d)
{
	for (int i = 1; i < size; i += 2) {
		if (a[i] < d) {
			while (!a[--i]);
			--a[i];
			if (i == 0 && a[i] == 0) return 0;
			++i;
			while (i < size) {
				a[i] = 9;
				++i;
			}
			return opt(a, size, d);
		}
	}
	return 1;
}

int amount(int *a, int n, int size, int m, int d, int ind)
{
	if (!a[0]) return 0;
	if (!opt(a, size, d)) return 0;
	pair<vector<vector<int> >, vector<vector<int> > > amt(vector<vector<int> >(n, vector<int>(m)), vector<vector<int> >(n, vector<int>(m)));
	if (a[0] != d) amt.second[0][(a[0] * decim[0]) % m] = 1;
	for (int i = 1; i < a[0]; ++i) if (i != d) ++amt.first[0][(i * decim[0]) % m];
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			for (int k = 0; k < 10; ++k) if (k != d) sum(amt.first[i][(j + k * decim[i * 2]) % m], amt.first[i - 1][j]);
			for (int k = 0; k <= a[i * 2]; ++k) if (k != d) sum(amt.first[i][(j + k * decim[i * 2]) % m], amt.second[i - 1][j]);
			if (a[2 * i] != d) sum(amt.second[i][(j + a[i * 2] * decim[i * 2]) % m], amt.second[i - 1][j]);
		}
	}
	// for (int i = 0; i < n; ++i) {
	// 	for (int j = 0; j < m; ++j) printf("%d %d %d %d\n", i, j, amt.first[i][j], amt.second[i][j]);
	// 	printf("\n");
	// }
	// printf("\n");
	return (amt.first[n - 1][ind] + amt.second[n - 1][ind]) % md;
}

void minusone(int *a, int size)
{
	int i = size - i;
	while (!a[i]) --i;
	--a[i];
	++i;
	while (i < size) {
		a[i] = 9;
		++i;
	}
}

int main()
{
	int m, d, a[2000], b[2000];
	scanf("%d%d", &m, &d);
	char buf[2001];
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[i] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[i] - '0';
	decim.resize(n);
	decim[n - 1] = 1 % m;
	for (int i = n - 2; i >= 0; --i) decim[i] = decim[i + 1] * 10 % m;
	int ind = 0;
	for (int i = 1; i < n; i += 2) ind += decim[i] * d;
	ind = - ind;
	ind = (ind % m + m) % m;
	minusone(a, n);
	printf("%d\n", amount(b, n / 2 + (n & 1), n, m, d, ind) - amount(a, n / 2 + (n & 1), n, m, d, ind));
	return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

const int md = 1000000007;

int n;
int m, d;
int a[2000], b[2000];
vector<int> decimal;
vector<vector<int> > digits;
vector<vector<int> > amt;

inline int sum(int a, int b)
{
	a += b;
	return a < md ? a : a - md;
}

void get(int x)
{
	vector<int> current(m);
	int sz = digits[x].size();
	int decim = decimal[n - x * 2 - 1];
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < sz; ++j) {
			int ind = (i + digits[x][j] * decim) % m;
			current[ind] = sum(amt[x - 1][i], current[ind]);
		}
	}
	for (int i = 0; i < m; ++i) amt[x][i] = current[i];
}

int main()
{
	scanf("%d%d", &m, &d);
	char buf[2001];
	scanf("%s", buf);
	n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[n - i - 1] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[n - i - 1] - '0';

	decimal.resize(n);
	decimal[0] = 1 % m;
	for (int i = 1; i < n; ++i) decimal[i] = 10 * decimal[i - 1] % m;

	int put = n / 2 + (n & 1);

	digits.resize(put);
	int i;
	for (i = n - 1; i >= 0 && a[i] == b[i]; --i) {
		int k = (n - i - 1) >> 1;
		if ((n - i - 1) & 1 && a[i] != d) {
			printf("0\n");
			return 0;
		}
		if (!((n - i - 1) & 1)) {
			if (a[i] == d) {
				printf("0\n");
				return 0;
			}
			digits[k].push_back(a[i]);
		}
	}
	if (i >= 0) {
		if ((n - i - 1) & 1) {
			if ((a[i] > d || b[i] < d)) {
				printf("0\n");
				return 0;
			}
			--i;
		}
		int k = (n - i - 1) >> 1;
		for (int j = a[i]; j <= b[i]; ++j) if (j != d && (i == 0 || ((j != a[i] || a[i - 1] <= d) && (j != b[i] || b[i - 1] >= d)))) digits[k].push_back(j);
		i -= 2;
		while (i >= 0) {
			k = (n - i - 1) >> 1;
			digits[k].resize(9);
			for (int j = 0; j <= 9; ++j) {
				if (j != d) digits[k][j > d ? j - 1 : j] = j;
			}
			i -= 2;
		}
	}

	amt.resize(put, vector<int>(m));
	for (int i = 0; i < digits[0].size(); ++i) ++amt[0][digits[0][i] * decimal[n - 1] % m];
	for (int i = 1; i < put; ++i) get(i);

	int evenres = 0;
	for (int i = n - 2; i >= 0; i -= 2) evenres += d * decimal[i] % m;
	evenres = m - evenres;
	evenres = ((evenres % m) + m) % m;
	printf("%d\n", amt[put - 1][evenres]);
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int md = 1000000007;

void sum(int &a, int b)
{
	a += b;
	if (a > md) a -= md;
}

vector<int> decim;

int solve(int *a, int n, int m, int d)
{
	vector<vector<int> > dp(n, vector<int>(m));
	vector<int> pr(n);
	for (int i = 0; i < a[0]; ++i) if (i != d) ++dp[0][i * decim[0] % m];
	pr[0] = a[0] * decim[0] % m;
	for (int i = 1; i < n; ++i) {
		if (i & 1) {
			for (int j = 0; j < m; ++j) sum(dp[i][(j + d * decim[i]) % m], dp[i - 1][j]);
			if (pr[i] != -1) {
				if (d < a[i]) sum(dp[i][(pr[i - 1] + d * decim[i]) % m], 1);
				if (a[i] == d) pr[i] = (pr[i - 1] + d * decim[i]) % m;
				else pr[i] = -1;
			}
		}
		else {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < 10; ++k) if (k != d) sum(dp[i][(j + k * decim[i]) % m], dp[i - 1][j]);
			}
			if (pr[i] != -1) {
				for (int k = 0; k < a[i]; ++k) if (k != d) sum(dp[i][(pr[i - 1] + k * decim[i]) % m], 1);
				if (a[i] != d) pr[i] = (pr[i - 1] + a[i] * decim[i]) % m;
				else pr[i] = -1;
			}
		}
	}
	return dp[n - 1][0] + (pr[n - 1] == 0);
}
bool check(int *a, int n, int m, int d)
{
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if (i & 1 && a[i] != d) return 0;
		res = (res + a[i] * decim[i]) % m;
	}
	return !res;
}

int main()
{
	int m, d;
	scanf("%d%d", &m, &d);
	int a[2000], b[2000];
	char buf[2000];
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[i] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[i] - '0';

	decim.resize(n);
	decim[n - 1] = 1 % m;
	for (int i = n - 2; i >= 0; --i) decim[i] = decim[i + 1] * 10 % m;

	printf("%d\n", solve(b, n, m, d) - solve(a, n, m, d) + check(a, n, m, d));
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int md = 1000000007;

void sum(int &a, int b)
{
	a += b;
	if (a > md) a -= md;
}

vector<int> decim;

int solve(int *a, int n, int m, int d)
{
	vector<vector<int> > dp(n, vector<int>(m));
	vector<int> pr(n);
	for (int i = 0; i < a[0]; ++i) if (i != d) ++dp[0][i * decim[0] % m];
	pr[0] = a[0] != d ? a[0] * decim[0] % m : -1;
	for (int i = 1; i < n; ++i) {
		if (i & 1) {
			for (int j = 0; j < m; ++j) sum(dp[i][(j + d * decim[i]) % m], dp[i - 1][j]);
			if (pr[i - 1] != -1) {
				if (d < a[i]) sum(dp[i][(pr[i - 1] + d * decim[i]) % m], 1);
				if (a[i] == d) pr[i] = (pr[i - 1] + d * decim[i]) % m;
				else pr[i] = -1;
			}
			else pr[i] = -1;
		}
		else {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < 10; ++k) if (k != d) sum(dp[i][(j + k * decim[i]) % m], dp[i - 1][j]);
			}
			if (pr[i - 1] != -1) {
				for (int k = 0; k < a[i]; ++k) if (k != d) sum(dp[i][(pr[i - 1] + k * decim[i]) % m], 1);
				if (a[i] != d) pr[i] = (pr[i - 1] + a[i] * decim[i]) % m;
				else pr[i] = -1;
			}
			else pr[i] = -1;
		}
	}
	return dp[n - 1][0] + (pr[n - 1] == 0);
}
bool check(int *a, int n, int m, int d)
{
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if (i & 1 && a[i] != d) return 0;
		if (!(i & 1) && a[i] == d) return 0;
		res = (res + a[i] * decim[i]) % m;
	}
	return !res;
}

int main()
{
	int m, d;
	scanf("%d%d", &m, &d);
	int a[2000], b[2000];
	char buf[2001];
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[i] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[i] - '0';

	decim.resize(n);
	decim[n - 1] = 1 % m;
	for (int i = n - 2; i >= 0; --i) decim[i] = decim[i + 1] * 10 % m;

	printf("%d\n", solve(b, n, m, d) - solve(a, n, m, d) + check(a, n, m, d));
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int md = 1000000007;

void sum(int &a, int b)
{
	a += b;
	if (a > md) a -= md;
}

vector<int> decim;

int solve(int *a, int n, int m, int d)
{
	vector<vector<int> > dp(n, vector<int>(m));
	vector<int> pr(n);
	for (int i = 0; i < a[0]; ++i) if (i != d) ++dp[0][i * decim[0] % m];
	pr[0] = a[0] * decim[0] % m;
	for (int i = 1; i < n; ++i) {
		if (i & 1) {
			for (int j = 0; j < m; ++j) sum(dp[i][(j + d * decim[i]) % m], dp[i - 1][j]);
			if (pr[i] != -1) {
				if (d < a[i]) sum(dp[i][(pr[i - 1] + d * decim[i]) % m], 1);
				if (a[i] == d) pr[i] = (pr[i - 1] + d * decim[i]) % m;
				else pr[i] = -1;
			}
		}
		else {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < 10; ++k) if (k != d) sum(dp[i][(j + k * decim[i]) % m], dp[i - 1][j]);
			}
			if (pr[i] != -1) {
				for (int k = 0; k < a[i]; ++k) if (k != d) sum(dp[i][(pr[i - 1] + k * decim[i]) % m], 1);
				if (a[i] != d) pr[i] = (pr[i - 1] + a[i] * decim[i]) % m;
				else pr[i] = -1;
			}
		}
	}
	// for (int i = 0; i < n; ++i) {
	// 	printf("pr[i] = %d\n", pr[i]);
	// 	for (int j = 0; j < m; ++j) printf("%d %d %d\n", i, j, dp[i][j]);
	// 	printf("\n");
	// }
	return dp[n - 1][0] + (pr[n - 1] == 0);
}
bool check(int *a, int n, int m, int d)
{
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if (i & 1 && a[i] != d) return 0;
		res = (res + a[i] * decim[i]) % m;
	}
	return !res;
}

int main()
{
	int m, d;
	scanf("%d%d", &m, &d);
	int a[2000], b[2000];
	char buf[2000];
	scanf("%s", buf);
	int n = strlen(buf);
	for (int i = 0; i < n; ++i) a[i] = buf[i] - '0';
	scanf("%s", buf);
	for (int i = 0; i < n; ++i) b[i] = buf[i] - '0';

	decim.resize(n);
	decim[n - 1] = 1 % m;
	for (int i = n - 2; i >= 0; --i) decim[i] = decim[i + 1] * 10 % m;

	printf("%d\n", solve(b, n, m, d) - solve(a, n, m, d) + check(a, n, m, d));
	return 0;
}