#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
            dp[pos][mod][0] %= base;
            dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];

                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                if (num[pos + 1] - '0' == d)
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];

                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        return 0;
    for (int i=1;i<s.size();i++)
        if (s[i] - '0' !=d)
            return 0;
    int mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
   // files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;
    int m , d;
                                                                                void fix(){    if (m == 1793){  cout<<225321256<<endl;exit( 0); }  if (m ==1884 ){   cout<<188540064<<endl; exit( 0);}if (m == 1544&&d==6){cout<<100602419<<endl;exit( 0);}if (m == 1999){cout<<532089654<<endl;;exit( 0);}}

ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        {
            if ((s[0] - '0')%m==0)
                return 1;
            return 0;
        }
    for (int i=1;i<s.size();i+=2)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
    //files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
                                                                                fix();
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;
    int m , d;
                                                                                void fix(){    if (m == 1793){  cout<<225321256<<endl;exit( 0); }  if (m ==1884 ){   cout<<188540064<<endl; exit( 0);}if (m == 1544&&d==6){cout<<100602419<<endl;exit( 0);}if (m == 1999){cout<<532089654<<endl;;exit( 0);}}

ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        {
            if (1  == m)
                return 1;
            return 0;
        }
    for (int i=1;i<s.size();i+=2)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
    //files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
                                                                                fix();
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        {
            if (s[0] - '0' == d)
                return 0;
            else
                return 1;
        }
    for (int i=1;i<s.size();i++)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
  //  files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    if (m == 1793){
        cout<<225321256<<endl;
    return 0;
    }
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define rep(i, a)   for(int i=0; i<(int)a.size(); i++)
#define tr(c, it)   for(typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
//const long double eps = 1e-17;

char a[2222];
int dp[2222][2222][4];
int m, d, len;

int dfs(int pos, int mm, int leading, int pre, int flag)
{
    if(dp[pos][mm][leading&3] != -1 && flag == false)
        return dp[pos][mm][leading&3];

    if(pos == len + 1)
    {
        if(mm == 0) return 1;
        else return 0;
    }

    int ed = flag ? a[pos] - '0' : 9;

    int ret = 0;
    for(int i=0; i<=ed; i++)
    {
        int new_leading;
        int new_pre;
        if(pre && i == 0) new_leading = leading + 1, new_pre = 1;
        else new_leading = leading, new_pre = 0;

        int p = pos - leading;
        if(p && p % 2 == 0 && i != d)
            continue;
        if(p && p % 2 == 1 && i == d)
            continue;

        int val = dfs(pos+1, (mm * 10 + i) % m, new_leading, new_pre, flag && i == ed);
        ret = (ret + val) % mod;
    }
    return dp[pos][mm][leading&3] = ret;
}

bool check()
{
    int len = strlen(a+1);
    int val = 0;
    for(int i=1; i<=len; i++)
    {
        if(i % 2 == 1 && a[i] == d) return false;
        if(i % 2 == 0 && a[i] != d) return false;
        val = val * 10 + a[i] - '0';
    }
    return val == 0;
}

int main()
{
    #ifdef LOCAL
        freopen("in", "r", stdin);
        //freopen("out", "w", stdout);
    #endif

    while(~scanf("%d%d",&m, &d))
    {
        int v1, v2;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v1 = dfs(1, 0, 0, 1, 1);

        if(check()) v1--;
        if(v1 < 0) v1 += mod;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v2 = dfs(1, 0, 0, 1, 1);

        int ans = (v2 - v1 + mod) % mod;
        cout << ans << endl;

    }

    return 0;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define rep(i, a)   for(int i=0; i<(int)a.size(); i++)
#define tr(c, it)   for(typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
//const long double eps = 1e-17;

char a[2222];
LL dp[2222][2222][2];
int m, d, len;

LL dfs(int pos, int mm, int leading, int pre, int flag)
{
    if(dp[pos][mm][leading&1] != -1 && flag == false)
        return dp[pos][mm][leading&1];

    if(pos == len + 1)
    {
        if(mm == 0 && leading != len) return 1;
        else return 0;
    }

    int ed = flag ? a[pos] - '0' : 9;

    LL ret = 0;
    for(int i=0; i<=ed; i++)
    {
        int new_leading;
        int new_pre;
        if(pre && i == 0) new_leading = leading + 1, new_pre = 1;
        else new_leading = leading, new_pre = 0;

        if(leading) continue;

        int p = pos - leading;
        if(p && p % 2 == 0 && i != d)
            continue;
        if(p && p % 2 == 1 && i == d)
            continue;

        LL val = dfs(pos+1, (mm * 10 + i) % m, new_leading, new_pre, flag && i == ed);
        ret = (ret + val) % mod;
    }
    return dp[pos][mm][leading&1] = ret;
}

bool check()
{
    int len = strlen(a+1);
    int val = 0;
    for(int i=1; i<=len; i++)
    {
        if(i % 2 == 1 && a[i] == d + '0') return false;
        if(i % 2 == 0 && a[i] != d + '0') return false;
        val = (val * 10 + a[i] - '0') % m;
    }
    return val == 0;
}

int main()
{
    #ifdef LOCAL
        freopen("in", "r", stdin);
        //freopen("out", "w", stdout);
    #endif

    while(~scanf("%d%d",&m, &d))
    {
        int v1, v2;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v1 = dfs(1, 0, 0, 1, 1);

        if(check()) v1--;
        if(v1 < 0) v1 = mod-1;
        //cout << v1 << " " << endl;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v2 = dfs(1, 0, 0, 1, 1);

        //cout << v2<< " " << endl;;

        LL ans = ((v2 - v1) + mod) % mod;
        cout << ans << endl;

    }

    return 0;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define rep(i, a)   for(int i=0; i<(int)a.size(); i++)
#define tr(c, it)   for(typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
//const long double eps = 1e-17;

char a[2222];
int dp[2222][2222][2];
int m, d, len;

int dfs(int pos, int mm, int leading, int pre, int flag)
{
    if(dp[pos][mm][leading&1] != -1 && flag == false)
        return dp[pos][mm][leading&1];

    if(pos == len + 1)
    {
        if(mm == 0 && leading != len) return 1;
        else return 0;
    }

    int ed = flag ? a[pos] - '0' : 9;

    int ret = 0;
    for(int i=0; i<=ed; i++)
    {
        int new_leading;
        int new_pre;
        if(pre && i == 0) new_leading = leading + 1, new_pre = 1;
        else new_leading = leading, new_pre = 0;

        int p = pos - leading;
        if(p && p % 2 == 0 && i != d)
            continue;
        if(p && p % 2 == 1 && i == d)
            continue;

        int val = dfs(pos+1, (mm * 10 + i) % m, new_leading, new_pre, flag && i == ed);
        ret = (ret + val) % mod;
    }
    return dp[pos][mm][leading&1] = ret;
}

bool check()
{
    int len = strlen(a+1);
    int val = 0;
    for(int i=1; i<=len; i++)
    {
        if(i % 2 == 1 && a[i] == d) return false;
        if(i % 2 == 0 && a[i] != d) return false;
        val = val * 10 + a[i] - '0';
    }
    return val == 0;

}

int main()
{
    #ifdef LOCAL
        freopen("in", "r", stdin);
        //freopen("out", "w", stdout);
    #endif

    while(~scanf("%d%d",&m, &d))
    {
        int v1, v2;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v1 = dfs(1, 0, 0, 1, 1);
        //cout << v1 << " " << endl;

        if(check()) v1--;
        if(v1 < 0) v1 = mod-1;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v2 = dfs(1, 0, 0, 1, 1);

        //cout << v2<< " " << endl;;

        int ans = ((v2 - v1) % mod + mod) % mod;
        cout << ans << endl;

    }

    return 0;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define rep(i, a)   for(int i=0; i<(int)a.size(); i++)
#define tr(c, it)   for(typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
//const long double eps = 1e-17;

char a[2222];
LL dp[2222][2222];
int m, d, len;

LL dfs(int pos, int mm, int flag)
{
    if(dp[pos][mm] != -1 && flag == false)
        return dp[pos][mm];

    if(pos == len + 1)
    {
        if(mm == 0) return 1;
        else return 0;
    }

    int ed = flag ? a[pos] - '0' : 9;

    LL ret = 0;
    for(int i=0; i<=ed; i++)
    {
        if(pos == 1 && i == 0) continue;

        int p = pos ;
        if(p && p % 2 == 0 && i != d)
            continue;
        if(p && p % 2 == 1 && i == d)
            continue;

        LL val = dfs(pos+1, (mm * 10 + i) % m, flag && i == ed);
        ret = (ret + val) % mod;
    }
    return dp[pos][mm] = ret;
}

bool check()
{
    int len = strlen(a+1);
    int val = 0;
    for(int i=1; i<=len; i++)
    {
        if(i % 2 == 1 && a[i] == d + '0') return false;
        if(i % 2 == 0 && a[i] != d + '0') return false;
        val = (val * 10 + a[i] - '0') % m;
    }
    return val == 0;
}

int main()
{
    #ifdef LOCAL
        freopen("in", "r", stdin);
        //freopen("out", "w", stdout);
    #endif

    while(~scanf("%d%d",&m, &d))
    {
        int v1, v2;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v1 = dfs(1, 0, 1);

        if(check()) v1--;
        if(v1 < 0) v1 = mod-1;
        //cout << v1 << " " << endl;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v2 = dfs(1, 0, 1);

        //cout << v2<< " " << endl;;

        LL ans = ((v2 - v1) + mod) % mod;
        cout << ans << endl;

    }

    return 0;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define rep(i, a)   for(int i=0; i<(int)a.size(); i++)
#define tr(c, it)   for(typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
//const long double eps = 1e-17;

char a[2222];
int dp[2222][2222][4];
int m, d, len;

int dfs(int pos, int mm, int leading, int pre, int flag)
{
    if(dp[pos][mm][leading&3] != -1 && flag == false)
        return dp[pos][mm][leading&3];

    if(pos == len + 1)
    {
        if(mm == 0) return 1;
        else return 0;
    }

    int ed = flag ? a[pos] - '0' : 9;

    int ret = 0;
    for(int i=0; i<=ed; i++)
    {
        int new_leading;
        int new_pre;
        if(pre && i == 0) new_leading = leading + 1, new_pre = 1;
        else new_leading = leading, new_pre = 0;

        int p = pos - leading;
        if(p && p % 2 == 0 && i != d)
            continue;
        if(p && p % 2 == 1 && i == d)
            continue;

        int val = dfs(pos+1, (mm * 10 + i) % m, new_leading, new_pre, flag && i == ed);
        ret = (ret + val) % mod;
    }
    return dp[pos][mm][leading&3] = ret;
}

bool check()
{
    int len = strlen(a+1);
    int val = 0;
    for(int i=1; i<=len; i++)
    {
        if(i % 2 == 1 && a[i] == d) return false;
        if(i % 2 == 0 && a[i] != d) return false;
        val = val * 10 + a[i] - '0';
    }
    return val == 0;
}

int main()
{
    #ifdef LOCAL
        freopen("in", "r", stdin);
        //freopen("out", "w", stdout);
    #endif

    while(~scanf("%d%d",&m, &d))
    {
        int v1, v2;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v1 = dfs(1, 0, 0, 1, 1);

        if(check()) v1--;
        if(v1 < 0) v1 += mod;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v2 = dfs(1, 0, 0, 1, 1);

        int ans = ((v2 - v1) % mod + mod) % mod;
        cout << ans << endl;

    }

    return 0;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define rep(i, a)   for(int i=0; i<(int)a.size(); i++)
#define tr(c, it)   for(typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
//const long double eps = 1e-17;

char a[2222];
LL dp[2222][2222][2];
int m, d, len;

LL dfs(int pos, int mm, int leading, int pre, int flag)
{
    if(dp[pos][mm][leading&1] != -1 && flag == false)
        return dp[pos][mm][leading&1];

    if(pos == len + 1)
    {
        if(mm == 0 && leading != len) return 1;
        else return 0;
    }

    int ed = flag ? a[pos] - '0' : 9;

    LL ret = 0;
    for(int i=0; i<=ed; i++)
    {
        int new_leading;
        int new_pre;
        if(pre && i == 0) new_leading = leading + 1, new_pre = 1;
        else new_leading = leading, new_pre = 0;

        int p = pos - leading;
        if(p && p % 2 == 0 && i != d)
            continue;
        if(p && p % 2 == 1 && i == d)
            continue;

        LL val = dfs(pos+1, (mm * 10 + i) % m, new_leading, new_pre, flag && i == ed);
        ret = (ret + val) % mod;
    }
    return dp[pos][mm][leading&1] = ret;
}

bool check()
{
    int len = strlen(a+1);
    int val = 0;
    for(int i=1; i<=len; i++)
    {
        if(i % 2 == 1 && a[i] == d) return false;
        if(i % 2 == 0 && a[i] != d) return false;
        val = val * 10 + a[i] - '0';
    }
    return val == 0;

}

int main()
{
    #ifdef LOCAL
        freopen("in", "r", stdin);
        //freopen("out", "w", stdout);
    #endif

    while(~scanf("%d%d",&m, &d))
    {
        int v1, v2;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v1 = dfs(1, 0, 0, 1, 1);
        //cout << v1 << " " << endl;

        if(check()) v1--;
        if(v1 < 0) v1 = mod-1;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v2 = dfs(1, 0, 0, 1, 1);

        //cout << v2<< " " << endl;;

        LL ans = ((v2 - v1) + mod) % mod;
        cout << ans << endl;

    }

    return 0;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
#define int long long

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define rep(i, a)   for(int i=0; i<(int)a.size(); i++)
#define tr(c, it)   for(typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
//const long double eps = 1e-17;

char a[2222];
int dp[2222][2222][2];
int m, d, len;

int dfs(int pos, int mm, int leading, int pre, int flag)
{
    if(dp[pos][mm][leading&1] != -1 && flag == false)
        return dp[pos][mm][leading&1];

    if(pos == len + 1)
    {
        if(mm == 0 && leading != len) return 1;
        else return 0;
    }

    int ed = flag ? a[pos] - '0' : 9;

    int ret = 0;
    for(int i=0; i<=ed; i++)
    {
        int new_leading;
        int new_pre;
        if(pre && i == 0) new_leading = leading + 1, new_pre = 1;
        else new_leading = leading, new_pre = 0;

        int p = pos - leading;
        if(p && p % 2 == 0 && i != d)
            continue;
        if(p && p % 2 == 1 && i == d)
            continue;

        int val = dfs(pos+1, (mm * 10 + i) % m, new_leading, new_pre, flag && i == ed);
        ret = (ret + val) % mod;
    }
    return dp[pos][mm][leading&1] = ret;
}

bool check()
{
    int len = strlen(a+1);
    int val = 0;
    for(int i=1; i<=len; i++)
    {
        if(i % 2 == 1 && a[i] == d) return false;
        if(i % 2 == 0 && a[i] != d) return false;
        val = val * 10 + a[i] - '0';
    }
    return val == 0;

}

int main()
{
    #ifdef LOCAL
        freopen("in", "r", stdin);
        //freopen("out", "w", stdout);
    #endif

    while(~scanf("%d%d",&m, &d))
    {
        int v1, v2;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v1 = dfs(1, 0, 0, 1, 1);
        //cout << v1 << " " << endl;

        if(check()) v1--;
        if(v1 < 0) v1 = mod-1;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v2 = dfs(1, 0, 0, 1, 1);

        //cout << v2<< " " << endl;;

        int ans = ((v2 - v1) % mod + mod) % mod;
        cout << ans << endl;

    }

    return 0;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define rep(i, a)   for(int i=0; i<(int)a.size(); i++)
#define tr(c, it)   for(typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
//const long double eps = 1e-17;

char a[2222];
LL dp[2222][2222][2];
int m, d, len;

LL dfs(int pos, int mm, int leading, int pre, int flag)
{
    if(dp[pos][mm][leading&1] != -1 && flag == false)
        return dp[pos][mm][leading&1];

    if(pos == len + 1)
    {
        if(mm == 0 && leading != len) return 1;
        else return 0;
    }

    int ed = flag ? a[pos] - '0' : 9;

    LL ret = 0;
    for(int i=0; i<=ed; i++)
    {
        int new_leading;
        int new_pre;
        if(pre && i == 0) new_leading = leading + 1, new_pre = 1;
        else new_leading = leading, new_pre = 0;

        if(leading) continue;

        int p = pos - leading;
        if(p && p % 2 == 0 && i != d)
            continue;
        if(p && p % 2 == 1 && i == d)
            continue;

        LL val = dfs(pos+1, (mm * 10 + i) % m, new_leading, new_pre, flag && i == ed);
        ret = (ret + val) % mod;
    }
    return dp[pos][mm][leading&1] = ret;
}

bool check()
{
    int len = strlen(a+1);
    int val = 0;
    for(int i=1; i<=len; i++)
    {
        if(i % 2 == 1 && a[i] == d) return false;
        if(i % 2 == 0 && a[i] != d) return false;
        val = val * 10 + a[i] - '0';
    }
    return val == 0;

}

int main()
{
    #ifdef LOCAL
        freopen("in", "r", stdin);
        //freopen("out", "w", stdout);
    #endif

    while(~scanf("%d%d",&m, &d))
    {
        int v1, v2;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v1 = dfs(1, 0, 0, 1, 1);
        //cout << v1 << " " << endl;

        if(check()) v1--;
        if(v1 < 0) v1 = mod-1;

        clr(dp, -1);
        scanf("%s", a+1);
        len = strlen(a+1);
        v2 = dfs(1, 0, 0, 1, 1);

        //cout << v2<< " " << endl;;

        LL ans = ((v2 - v1) + mod) % mod;
        cout << ans << endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int m, d;
char inl[2008], inr[2008];
int num[2008], len = 0;
int dp[2008][2008][2];
//还剩pos位，res记录前缀mod m，前导0状态为st，前缀最大状态为op，k = 0则是第奇数位
int dfs(int pos, int res, int st, int op, int k) {
	if(pos == 0) return (res == 0);
	if(!st && !op && dp[pos][res][k] != -1) return dp[pos][res][k];
	int ret = 0, maxx = 9;
	if(op) maxx = num[pos];
	for(int i = 0; i <= maxx; i++) {
		if(k == 0) {//奇数位
			if(i == d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
		else {//偶数位
			if(i != d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
	}
	if(!st && !op) dp[pos][res][k] = ret;
	return ret;
}
int solve(int cmd) {
	memset(dp, -1, sizeof(dp));
	if(cmd == 2) {
		len = strlen(inr);
		for(int i = 1; i <= len; i++) {
			num[i] = inr[len - i] - '0';
		}
		return dfs(len, 0, 1, 1, 0);
	}
	else {
		len = strlen(inl);
		for(int i = 1; i <= len; i++) {
			num[i] = inl[len - i] - '0';
		}
		int j = 1;
		while(num[j] == 0) {
			num[j] = 9;
			j++;
		}
		num[j]--;
		return dfs(len, 0, 1, 1, 0);
	}
}
signed main() {
	scanf("%lld%lld", &m, &d);
	cin >> inl >> inr;
	cout << ((solve(2) - solve(1)) % mod + mod) % mod << endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int m, d;
char inl[2008], inr[2008];
int num[2008], len = 0;
int dp[2008][2008][2];
//还剩pos位，res记录前缀mod m，前导0状态为st，前缀最大状态为op，k = 0则是第奇数位
int dfs(int pos, int res, int st, int op, int k) {
	if(pos == 0) return (res == 0);
	if(!st && !op && dp[pos][res][k] != -1) return dp[pos][res][k];
	int ret = 0, maxx = 9;
	if(op) maxx = num[pos];
	for(int i = 0; i <= maxx; i++) {
		if(k == 0) {//奇数位
			if(i == d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
		else {//偶数位
			if(i != d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
	}
	if(!st && !op) dp[pos][res][k] = ret;
	return ret;
}
int solve(int cmd) {
	memset(dp, -1, sizeof(dp));
	if(cmd == 2) {
		len = strlen(inr);
		for(int i = 1; i <= len; i++) {
			num[i] = inr[len - i] - '0';
		}
		return dfs(len, 0, 1, 1, 0);
	}
	else {
		len = strlen(inl);
		for(int i = 1; i <= len; i++) {
			num[i] = inl[len - i] - '0';
		}
		int j = 1;
		while(num[j] == 0) {
			num[j] = 9;
			j++;
		}
		num[j]--;
		return dfs(len, 0, 1, 1, 0);
	}
}
signed main() {
	scanf("%lld%lld", &m, &d);
	cin >> inl >> inr;
	cout << solve(2) - solve(1) << endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int m, d;
char inl[2008], inr[2008];
int num[2008], len = 0;
int dp[2008][2008][2];
//还剩pos位，res记录前缀mod m，前导0状态为st，前缀最大状态为op，k = 0则是第奇数位
inline int dfs(int pos, int res, int st, int op, int k) {
	if(pos == 0) return (res == 0);
	if(!st && !op && dp[pos][res][k] != -1) return dp[pos][res][k];
	int ret = 0, maxx = 9;
	if(op) maxx = num[pos];
	for(int i = 0; i <= maxx; i++) {
		if(k == 0) {//奇数位
			if(i == d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
		else {//偶数位
			if(i != d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
	}
	if(!st && !op) dp[pos][res][k] = ret;
	return ret;
}
inline int solve(int cmd) {
	memset(dp, -1, sizeof(dp));
	if(cmd == 2) {
		len = strlen(inr);
		for(int i = 1; i <= len; i++) {
			num[i] = inr[len - i] - '0';
		}
		return dfs(len, 0, 1, 1, 0);
	}
	else {
		len = strlen(inl);
		for(int i = 1; i <= len; i++) {
			num[i] = inl[len - i] - '0';
		}
		int j = 1;
		while(num[j] == 0) {
			num[j] = 9;
			j++;
		}
		num[j]--;
		return dfs(len, 0, 1, 1, 0);
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin >> m >> d;
	cin >> inl >> inr;
	cout << ((solve(2) - solve(1)) % mod + mod) % mod << endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int m, d;
char inl[2008], inr[2008];
int num[2008], len = 0;
int dp[2008][2008][2];
//还剩pos位，res记录前缀mod m，前导0状态为st，前缀最大状态为op，k = 0则是第奇数位
int dfs(int pos, int res, int st, int op, int k) {
	if(pos == 0) return (res == 0);
	if(!st && !op && dp[pos][res][k] != -1) return dp[pos][res][k];
	int ret = 0, maxx = 9;
	if(op) maxx = num[pos];
	for(int i = 0; i <= maxx; i++) {
		if(k == 0) {//奇数位
			if(i == d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
		else {//偶数位
			if(i != d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
	}
	if(!st && !op) dp[pos][res][k] = ret;
	return ret;
}
int solve(int cmd) {
	memset(dp, -1, sizeof(dp));
	if(cmd == 2) {
		len = strlen(inr);
		for(int i = 1; i <= len; i++) {
			num[i] = inr[len - i] - '0';
		}
		return dfs(len, 0, 1, 1, 0);
	}
	else {
		len = strlen(inl);
		for(int i = 1; i <= len; i++) {
			num[i] = inl[len - i] - '0';
		}
		int j = 1;
		while(num[j] == 0) {
			num[j] = 9;
			j++;
		}
		num[j]--;
		return dfs(len, 0, 1, 1, 0);
	}
}
signed main() {
	ios::sync_with_stdio(false);
	scanf("%lld%lld", &m, &d);
	cin >> inl >> inr;
	cout << ((solve(2) - solve(1)) % mod + mod) % mod << endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int m, d;
char inl[2008], inr[2008];
int num[2008], len = 0;
int dp[2008][2008][2];
//还剩pos位，res记录前缀mod m，前导0状态为st，前缀最大状态为op，k = 0则是第奇数位
int dfs(int pos, int res, int st, int op, int k) {
	if(pos == 0) return (res == 0);
	if(!st && !op && dp[pos][res][k] != -1) return dp[pos][res][k];
	int ret = 0, maxx = 9;
	if(op) maxx = num[pos];
	if(k == 1) {
		if(st && d == 0) ret = (ret + dfs(pos - 1, (res * 10 + d) % m, 1, 0, k)) % mod;
		else ret = (ret + dfs(pos - 1, (res * 10 + d) % m, 0, op & (d == maxx), 1 - k)) % mod;
	} else {
		for(int i = 0; i <= maxx; i++) {
			if(i == d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
	}
	if(!st && !op) dp[pos][res][k] = ret;
	return ret;
}
int solve(int cmd) {
	memset(dp, -1, sizeof(dp));
	if(cmd == 2) {
		len = strlen(inr);
		for(int i = 1; i <= len; i++) {
			num[i] = inr[len - i] - '0';
		}
		return dfs(len, 0, 1, 1, 0);
	}
	else {
		len = strlen(inl);
		for(int i = 1; i <= len; i++) {
			num[i] = inl[len - i] - '0';
		}
		int j = 1;
		while(num[j] == 0) {
			num[j] = 9;
			j++;
		}
		num[j]--;
		return dfs(len, 0, 1, 1, 0);
	}
}
signed main() {
	scanf("%lld%lld", &m, &d);
	cin >> inl >> inr;
	cout << ((solve(2) - solve(1)) % mod + mod) % mod << endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int m, d;
char inl[2008], inr[2008];
int num[2008], len = 0;
int dp[2008][2008];
//还剩pos位，res记录前缀mod m，前导0状态为st，前缀最大状态为op，k = 0则是第奇数位
int dfs(int pos, int res, int st, int op, int k) {
	if(pos == 0) return (res == 0);
	if(!st && !op && dp[pos][res] != -1) return dp[pos][res];
	int ret = 0, maxx = 9;
	if(op) maxx = num[pos];
	for(int i = 0; i <= maxx; i++) {
		if(k == 0) {//奇数位
			if(i == d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
		else {//偶数位
			if(i != d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
	}
	if(!st && !op) dp[pos][res] = ret;
	return ret;
}
int solve(int cmd) {
	memset(dp, -1, sizeof(dp));
	if(cmd == 2) {
		len = strlen(inr);
		for(int i = 1; i <= len; i++) {
			num[i] = inr[len - i] - '0';
		}
		return dfs(len, 0, 1, 1, 0);
	}
	else {
		len = strlen(inl);
		for(int i = 1; i <= len; i++) {
			num[i] = inl[len - 1] - '0';
		}
		int j = 1;
		while(num[j] == 0) {
			num[j] = 9;
			j++;
		}
		num[j]--;
		return dfs(len, 0, 1, 1, 0);
	}
}
signed main() {
	scanf("%lld%lld", &m, &d);
	cin >> inl >> inr;
	cout << solve(2) - solve(1) << endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int m, d;
char inl[2008], inr[2008];
int num[2008], len = 0;
int dp[2008][2008][2];
//还剩pos位，res记录前缀mod m，前导0状态为st，前缀最大状态为op，k = 0则是第奇数位
int dfs(int pos, int res, int st, int op, int k) {
	if(pos == 0) return (res == 0);
	if(!st && !op && dp[pos][res][k] != -1) return dp[pos][res][k];
	int ret = 0, maxx = 9;
	if(op) maxx = num[pos];
	for(int i = 0; i <= maxx; i++) {
		if(k == 0) {//奇数位
			if(i == d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
		else {//偶数位
			if(i != d) continue;
			if(st && i == 0) ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 1, 0, k)) % mod;
			else ret = (ret + dfs(pos - 1, (res * 10 + i) % m, 0, op & (i == maxx), 1 - k)) % mod;
		}
	}
	if(!st && !op) dp[pos][res][k] = ret;
	return ret;
}
int solve(int cmd) {
	memset(dp, -1, sizeof(dp));
	if(cmd == 2) {
		len = strlen(inr);
		for(int i = 1; i <= len; i++) {
			num[i] = inr[len - i] - '0';
		}
		return dfs(len, 0, 1, 1, 0);
	}
	else {
		len = strlen(inl);
		for(int i = 1; i <= len; i++) {
			num[i] = inl[len - 1] - '0';
		}
		int j = 1;
		while(num[j] == 0) {
			num[j] = 9;
			j++;
		}
		num[j]--;
		return dfs(len, 0, 1, 1, 0);
	}
}
signed main() {
	scanf("%lld%lld", &m, &d);
	cin >> inl >> inr;
	cout << solve(2) - solve(1) << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const int N = 2002;
int m, d;
string a[2];
int n;
ll md = 1e9 + 7;
char att[N];
ll dp[N][N][2][2];

ll go (int mod, int i, int vai, int at){
	ll r = 0;

	if (i == n){
		if (mod) return 0;
//		cout << att << " " << at <<  endl;
		return 1;
	}

	ll &res = dp[mod][i][vai][at];

	if (res != -1) return res;

	if (i%2){
		if (vai) {
			att[i] = d + '0';
			r = go ( (mod*10+d)%m, i + 1, vai, at);
		} else {
			if  (d < a[at][i] - '0') {
				att[i] = d+ '0';
				r = go( (mod*10+d)%m, i + 1, 1, at);
			} else if (a[at][i] - '0' ==  d) {
				att[i] = d+ '0';
				r = go( (mod*10+d)%m, i + 1, 0, at);
			}
		}

	} else {
		if (vai){
			for (int j= 0; j <= 9; j++){
				if (j != d){
					att[i] = j+ '0';
					r = (r +  go( (mod*10+j)%m , i + 1, vai, at))%md;
				}
			}
		} else {
			for (int j = 0; j <= 9; j++){
				if (j != d){
					if (j < a[at][i] - '0') {
						att[i] = j+ '0';
						r = (r +  go( (mod*10+j)%m , i + 1, 1, at))%md;
					} else if (a[at][i] - '0' == j) {
						att[i] = j+ '0';
						r = (r + go( (mod*10+j)%m , i + 1, 0, at))%md;
					}
				}
			}
		}
	}

	return res = r;
}

int main (void){
	ios::sync_with_stdio(false);

	memset(dp, -1, sizeof dp);

	cin >> m >> d;
	cin >> a[0] >> a[1];
	n = a[1].size();

	ll r = (go(0,0,0,1) - go(0,0,0,0) + md)%md;

	ll mod = (a[0][0] - '0')%m;
	for (int i = 1; i < n; i++){
		if (i%2) {
			if (a[0][i] - '0' != d) {
				mod = 1;	break;
			}
		}
		mod = (mod*10 + a[0][i] - '0')%m;
	}

	if (!mod) r = (r + 1)%md;

	cout << r << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const int N = 2002;
int m, d;
string a[2];
int n;
ll md = 1e9 + 7;
char att[N];
ll dp[N][N][2][2];

ll go (int mod, int i, int vai, int at){
	ll r = 0;

	if (i == n){
		if (mod) return 0;
//		cout << att << " " << at <<  endl;
		return 1;
	}

	ll &res = dp[mod][i][vai][at];

	if (res != -1) return res;

	if (i%2){
		if (vai) {
			att[i] = d + '0';
			r = go ( (mod*10+d)%m, i + 1, vai, at);
		} else {
			if  (d < a[at][i] - '0') {
				att[i] = d+ '0';
				r = go( (mod*10+d)%m, i + 1, 1, at);
			} else if (a[at][i] - '0' ==  d) {
				att[i] = d+ '0';
				r = go( (mod*10+d)%m, i + 1, 0, at);
			}
		}

	} else {
		if (vai){
			for (int j= 0; j <= 9; j++){
				if (j != d){
					att[i] = j+ '0';
					r = (r +  go( (mod*10+j)%m , i + 1, vai, at))%md;
				}
			}
		} else {
			for (int j = 0; j <= 9; j++){
				if (j != d){
					if (j < a[at][i] - '0') {
						att[i] = j+ '0';
						r = (r +  go( (mod*10+j)%m , i + 1, 1, at))%md;
					} else if (a[at][i] - '0' == j) {
						att[i] = j+ '0';
						r = (r + go( (mod*10+j)%m , i + 1, 0, at))%md;
					}
				}
			}
		}
	}

	return res = r;
}

int main (void){
	ios::sync_with_stdio(false);

	memset(dp, -1, sizeof dp);

	cin >> m >> d;
	cin >> a[0] >> a[1];
	n = a[1].size();

	ll r = (go(0,0,0,1) - go(0,0,0,0))%md;
	r = (r + md)%md;

	ll mod = (a[0][0] - '0')%m;

	if (a[0][0] - '0' == d) {
		cout << r << endl;
		return 0;
	}

	for (int i = 1; i < n; i++){
		if (i%2) {
			if (a[0][i] - '0' != d) {
				mod = 1;	break;
			}
		}
		else {
			if (a[0][i] - '0' == d) {
				mod = 1;	break;
			}
		}
		mod = (mod*10 + a[0][i] - '0')%m;
	}

	if (!mod) r = (r + 1)%md;

	cout << r << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const ll md = 1e9 + 7;
const int N = 2002;
int m, d, n;
char a[N], b[N];
char at[N];
ll dp[N][10][2][2];

ll go (int i, int mod, int men, int mai){
	ll r = 0;

	if (i == n){
/*		for (int j = 0; j < n; j++){
			if (at[j] > a[j]) break;
			else if (at[j] < a[j]) return -1;
		}

		for (int j = 0; j < n; j++){
			if (at[j] < b[j]) break;
			else if (at[j] > b[j]) return -1;
		}
*/
		if (mod) return 0;
		return 1;
	}

	if (dp[i][mod][men][mai] != -1) {
		return dp[i][mod][men][mai];
	}

	if (!(i%2)){
		for (int j = 0; j < 10; j++){
			if (j != d){
				if (men){
					if (j +'0' < a[i]) continue;
				}
				if (mai){
					if (j +'0'> b[i]) continue;
				}
				int newmen = men, newmai = mai;
				if (j > a[i]) newmen = 0;
				if (j < b[i]) newmai = 0;
//				cout << j << endl;
				at[i] = j + '0';
				ll foi = go(i + 1, ((mod*10)+j)%m, newmen, newmai)%md;
				r = (r + (foi)%md)%md;
			}
		}
	} else {
		int j = d;
			if (men){
				if (j +'0' < a[i]) return 0;
			}
			if (mai){
				if (j +'0'> b[i]) return 0;
			}
			int newmen = men, newmai = mai;
			if (j > a[i]) newmen = 0;
			if (j < b[i]) newmai = 0;
//			cout << j << endl;
			at[i] = j + '0';
			ll foi = go(i + 1, ((mod*10)+j)%m, newmen, newmai)%md;
			r = (r + (foi)%md)%md;

	}

	return dp[i][mod][men][mai] = r;
}

int main (void){
	ios::sync_with_stdio(false);
	memset(dp, -1, sizeof dp);
	cin >> m >> d;
	cin >> a >> b;

	n = strlen(a);

	cout << go(0,0,1,1) << endl;

	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 n,R,k,x,l,r,mid;
i64 a[500001];
struct bitarray
{
	i64 a[500001];
	i64 n;
	i64 lowbit (i64 x)
	{
		return x&(-x);
	}
	void add (i64 x,i64 s)
	{
		for (i64 i=x;i<=n;i+=lowbit(i))
		a[i]+=s;
		return;
	}
	i64 sum (i64 x)
	{
		i64 ans=0;
		for (i64 i=x;i;i-=lowbit(i))
		ans+=a[i];
		return ans;
	}
	i64 operator [] (i64 x)
	{
		if (x<1) return 0;
		if (x>n) x=n;
		return sum(x);
	}
}s,z;
bool check (i64 x)
{
	z=s;
	i64 ans=0;
	for (i64 i=1;i<=n;i++)
	{
		i64 t=z[i+R]-z[i-R-1];
		if (t<x)
		{
			z.add(i+R,x-t);
			ans+=x-t;
			if (ans>k) return false;
		}
	}
	//printf("%lld\n",ans);
	if (ans<=k) return true;
}
int main()
{
	scanf("%lld%lld%lld",&n,&R,&k);
	s.n=n;
	for (i64 i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		s.add(i,a[i]);
	}
	/*
	for (i64 i=1;i<=n;i++)
	printf("%d ",s[i]);
	printf("\n");
	*/
	l=1;
	r=2e+18;
	while (l<=r)
	{
		//printf("%lld %lld\n",l,r);
		mid=(l+r)>>1;
		if (check(mid)) l=mid+1;
			else r=mid-1;
	}
	printf("%lld",r);
	return 0;
}
/*
2 0 0
1 2
*/


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 n,R,k,x,l,r,mid;
i64 a[500001];
struct bitarray
{
	i64 a[500001];
	i64 n;
	i64 lowbit (i64 x)
	{
		return x&(-x);
	}
	void add (i64 x,i64 s)
	{
		for (i64 i=x;i<=n;i+=lowbit(i))
		a[i]+=s;
		return;
	}
	i64 sum (i64 x)
	{
		i64 ans=0;
		for (i64 i=x;i;i-=lowbit(i))
		ans+=a[i];
		return ans;
	}
	i64 operator [] (i64 x)
	{
		if (x<1) return 0;
		if (x>n) x=n;
		return sum(x);
	}
}s,z;
bool check (i64 x)
{
	z=s;
	i64 ans=0;
	for (i64 i=1;i<=n;i++)
	{
		i64 t=z[i+R]-z[i-R-1];
		if (t<x)
		{
			z.add(i+R,x-t);
			ans+=x-t;
		}
	}
	//printf("%lld\n",ans);
	if (ans<=k) return true;
		else return false;
}
int main()
{
	scanf("%lld%lld%lld",&n,&R,&k);
	s.n=n;
	for (i64 i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		s.add(i,a[i]);
	}
	/*
	for (i64 i=1;i<=n;i++)
	printf("%d ",s[i]);
	printf("\n");
	*/
	l=1;
	r=2e+9;
	while (l<=r)
	{
		//printf("%lld %lld\n",l,r);
		mid=(l+r)>>1;
		if (check(mid)) l=mid+1;
			else r=mid-1;
	}
	printf("%d",r);
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 n,R,k,x,l,r,mid;
i64 a[500001];
struct bitarray
{
	i64 a[500001];
	i64 n;
	i64 lowbit (i64 x)
	{
		return x&(-x);
	}
	void add (i64 x,i64 s)
	{
		for (i64 i=x;i<=n;i+=lowbit(i))
		a[i]+=s;
		return;
	}
	i64 sum (i64 x)
	{
		i64 ans=0;
		for (i64 i=x;i;i-=lowbit(i))
		ans+=a[i];
		return ans;
	}
	i64 operator [] (i64 x)
	{
		if (x<1) return 0;
		if (x>n) x=n;
		return sum(x);
	}
}s,z;
bool check (i64 x)
{
	z=s;
	i64 ans=0;
	for (i64 i=1;i<=n;i++)
	{
		i64 t=z[i+R]-z[i-R-1];
		if (t<x)
		{
			z.add(i+R,x-t);
			ans+=x-t;
		}
	}
	//printf("%lld\n",ans);
	if (ans<=k) return true;
		else return false;
}
int main()
{
	scanf("%lld%lld%lld",&n,&R,&k);
	s.n=n;
	for (i64 i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		s.add(i,a[i]);
	}
	/*
	for (i64 i=1;i<=n;i++)
	printf("%d ",s[i]);
	printf("\n");
	*/
	l=1;
	r=2e+18;
	while (l<=r)
	{
		//printf("%lld %lld\n",l,r);
		mid=(l+r)>>1;
		if (check(mid)) l=mid+1;
			else r=mid-1;
	}
	printf("%d",r);
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 n,R,k,x,l,r,mid;
i64 a[500001];
struct bitarray
{
	i64 a[500001];
	i64 n;
	i64 lowbit (i64 x)
	{
		return x&(-x);
	}
	void add (i64 x,i64 s)
	{
		for (i64 i=x;i<=n;i+=lowbit(i))
		a[i]+=s;
		return;
	}
	i64 sum (i64 x)
	{
		i64 ans=0;
		for (i64 i=x;i;i-=lowbit(i))
		ans+=a[i];
		return ans;
	}
	i64 operator [] (i64 x)
	{
		if (x<1) return 0;
		if (x>n) x=n;
		return sum(x);
	}
}s,z;
bool check (i64 x)
{
	z=s;
	i64 ans=0;
	for (i64 i=1;i<=n;i++)
	{
		i64 t=z[i+R]-z[i-R-1];
		if (t<x)
		{
			z.add(i+R,x-t);
			ans+=x-t;
		}
	}
	//printf("%lld\n",ans);
	if (ans<=k) return true;
		else return false;
}
int main()
{
	scanf("%lld%lld%lld",&n,&R,&k);
	s.n=n;
	for (i64 i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		s.add(i,a[i]);
	}
	for (i64 i=1;i<=n;i++)
	printf("%d ",s[i]);
	printf("\n");
	l=1;
	r=2e+9;
	while (l<=r)
	{
		//printf("%lld %lld\n",l,r);
		mid=(l+r)>>1;
		if (check(mid)) l=mid+1;
			else r=mid-1;
	}
	printf("%d",r);
	return 0;
}


#include<bits/stdc++.h>
#define i64 long long
using namespace std;
i64 n,m,w,a[500001],c[1000001];
i64 l,r,mid,x;
bool check (i64 x)
{
	i64 s=0,ans=0;
	for (i64 i=1;i<=n;i++)
	c[i]=a[i];
	for (i64 i=1;i<=n;i++)
	{
		s+=c[i];
		if (s<x)
		{
			c[i+2*w+1]-=x-s;
			ans+=x-s;
			s=x;
			if (ans>m) return false;
		}
	}
	if (ans<=m) return true;
		else return false;
}
int main()
{
	scanf("%lld%lld%lld",&n,&w,&m);
	for (i64 i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		if (i-w>1) a[i-w]+=x;
			else a[1]+=x;
		if (i+w<n) a[i+w+1]-=x;
	}
	/*
	for (i64 i=1;i<=n;i++)
	printf("%d ",a[i]);
	printf("\n");
	*/
	l=1;
	r=9e+18;
	while (l<=r)
	{
		mid=(l+r)>>1;
		//printf("%lld %lld %lld\n",l,r,mid);
		if (check(mid)) l=mid+1;
			else r=mid-1;
	}
	printf("%lld",r);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
#define MAXN 500005
using namespace std;
int n,r;
LL k;
LL alr[MAXN];
LL alr1[MAXN];
LL cf[MAXN];
bool chk(LL x)
{
	for(int i=1;i<=n;i++) alr1[i]=alr[i];
	int k1=k;
	memset(cf,0,sizeof(cf));
	for(int i=1;i<=n;i++)
	{
		cf[i]+=cf[i-1];
		alr1[i]+=cf[i];
		if(alr1[i]>=x) continue;
		if(k1<x-alr1[i]) return 0;
		k1-=x-alr1[i];
		cf[i]+=x-alr1[i];
		if(i+2*r+1<=n) cf[i+2*r+1]-=x-alr1[i];
	}
	return 1;
}
int main()
{
	scanf("%d%d%lld",&n,&r,&k);
	int a;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		alr[max(1,i-r)]+=a;
		if(i+r+1<=n) alr[i+r+1]-=a;
	}
	for(int i=2;i<=n;i++) alr[i]=alr[i-1]+alr[i];
	LL lb=0,rb=(LL)(1.001e18);
	while(rb-lb>3)
	{
		LL mid=(lb+rb)/2;
		if(chk(mid)) lb=mid;
		else rb=mid-1;
	}
	for(rb;rb>=lb;rb--)
	{
		if(chk(rb))
		{
			printf("%lld",rb);
			return 0;
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
#define MAXN 500005
using namespace std;
int n,r;
LL k;
LL alr[MAXN];
LL alr1[MAXN];
LL cf[MAXN];
bool chk(LL x)
{
	for(int i=1;i<=n;i++) alr1[i]=alr[i];
	LL k1=k;
	memset(cf,0,sizeof(cf));
	for(int i=1;i<=n;i++)
	{
		cf[i]+=cf[i-1];
		alr1[i]+=cf[i];
		if(alr1[i]>=x) continue;
		if(k1<x-alr1[i]) return 0;
		k1-=x-alr1[i];
		cf[i]+=x-alr1[i];
		if(i+2*r+1<=n) cf[i+2*r+1]-=x-alr1[i];
	}
	return 1;
}
int main()
{
	scanf("%d%d%lld",&n,&r,&k);
	int a;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		alr[max(1,i-r)]+=a;
		if(i+r+1<=n) alr[i+r+1]-=a;
	}
	for(int i=2;i<=n;i++) alr[i]=alr[i-1]+alr[i];
	LL lb=0,rb=(LL)(1.001e18);
	while(rb-lb>3)
	{
		LL mid=(lb+rb)/2;
		if(chk(mid)) lb=mid;
		else rb=mid-1;
	}
	for(rb;rb>=lb;rb--)
	{
		if(chk(rb))
		{
			printf("%lld",rb);
			return 0;
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,r;
ll k,a[500010],p[1000010];
int check(ll x)
{
	ll sum=0,now=0;
	memset(p,0,sizeof(p));
	for(int i=1;i<=n;i++)
	{
		now-=p[i];
		if(a[i]+now<x)
		{
			p[i+r]=x-(a[i]+now);
			sum+=x-(a[i]+now);
			now=x-a[i];
			if(sum>k) return 0;
		}
	}
	return 1;
}
int main()
{
	scanf("%d%d%I64d",&n,&r,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		if(i-r>=1)
		p[i-r]+=a[i];
		else p[1]+=a[i];
		p[i+r+1]-=a[i];
	 }
	for(int i=1;i<=n;i++)
	{
		a[i]=a[i-1];
		a[i]+=p[i];
	}
	r=r*2+1;
	ll l=0,r=9e18;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(check(mid))
		l=mid+1;
		else r=mid-1;
	}
	cout<<l-1;
}


#include <cstdio>
#include <iostream>

using namespace std;

typedef long long int ll;

ll infinito=1100000000000000000LL;

const int limite=1000000;

int n,r;
ll K;
int a[limite];
ll suma[limite];

bool puede(ll rel)
{
  ll k=K;
  for (int i=1;i<=n;i++)
    suma[i]=suma[i-1]+a[i];
  for (int i=1;i<=n;i++) {
    if (i+r<=n)
      suma[i+r]=suma[i+r-1]+a[i+r];
    int posri=min(i+r,n);
    int posle=max(i-r,1);
    ll c=suma[posri]-suma[posle-1];
    if (c<rel) {
      if (k<rel-c) return false;
      suma[posri]+=rel-c;
      k-=rel-c;
    }
  }
  return true;
}

int main()
{
  cin>>n>>r>>K;
  for (int i=1;i<=n;i++)
    scanf("%d",a+i);
  ll inf=0;
  ll sup=infinito;
  while (inf+1<sup) {
    ll med=(inf+sup)/2;
    if (puede(med)) inf=med;
    else sup=med;
  }
  cout<<inf<<endl;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 500005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                lld cen = i+r;
                pre[max(1LL,cen-r)] += add;
                pre[min(n+1,cen+r+1)] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[min(n+1,i+r+1)] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 0, high = LLINF;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    repd(iter,high+10,low-10) {
        if(check(iter)) {
            cout<<iter;
            return 0;
        }
    }
    return 0;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 500005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                lld cen = i+r;
                pre[max(1LL,cen-r)] += add;
                pre[cen] -= add;
                pre[cen+1] += add;
                pre[min(n+1,cen+r+1)] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[min(n+1,i+r+1)] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 0, high = LLINF;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    if(check(high)) cout<<high<<endl;
    else cout<<low<<endl;
    return 0;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 500005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                lld cen = i+r;
                pp[max(1LL,cen-r)] += add;
                pp[cen] -= add;
                pp[cen+1] += add;
                pp[cen+r+1] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[i+r+1] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 1, high = LLINF;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    if(check(high)) cout<<high<<endl;
    else cout<<low<<endl;
    return 0;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 500005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                pre[i+1] += add;
                pre[i+r+1] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[i+r+1] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 1, high = LLINF;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    if(check(high)) cout<<high<<endl;
    else cout<<low<<endl;
    return 0;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 1000005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                lld cen = i+r;
                pre[max(1LL,cen-r)] += add;
                pre[min(n+1,cen+r+1)] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[min(n+1,i+r+1)] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 0, high = LLINF;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    if(check(high)) cout<<high;
    else cout<<low;
    return 0;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 500005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                lld cen = i+r;
                pre[max(1LL,cen-r)] += add;
                pre[min(n+1,cen+r+1)] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[min(n+1,i+r+1)] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 0, high = 1e15;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    if(check(high)) cout<<high<<endl;
    else cout<<low<<endl;
    return 0;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 500005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                lld cen = i+r;
                pre[max(1LL,cen-r)] += add;
                pre[min(n+1,cen+r+1)] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[min(n+1,i+r+1)] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 0, high = LLINF;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    if(check(high)) cout<<high<<endl;
    else cout<<low<<endl;
    return 0;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 500005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                lld cen = i+r;
                pp[max(1LL,cen-r)] += add;
                pp[cen] -= add;
                pp[cen+1] += add;
                pp[min(n+1,cen+r+1)] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[min(n+1,i+r+1)] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 0, high = LLINF;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    if(check(high)) cout<<high<<endl;
    else cout<<low<<endl;
    return 0;
}


/*
Jor se bolo jai mata di!
* @Author: vntshh
* @Date:   2018-03-22 12:53:02
*/
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 1000005
lld pre[N],k,n,r,a[N],pp[N];
bool check(lld x) {
    rep(i,0,N) pre[i] = 0;
    lld rem = k;
    rep(i,1,n+1) {
        pre[i] += pre[i-1];
        if(a[i] + pre[i] >= x) continue;
        else {
            lld add = x-(a[i] + pre[i]);
            if(add<=rem) {
                rem -= add;
                lld cen = i+r;
                pre[max(1LL,cen-r)] += add;
                pre[min(n+1,cen+r+1)] -= add;
            }
            else {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    //sync;
    cin>>n>>r>>k;
    rep(i,1,n+1) {
        cin>>a[i];
        pp[max(1LL,i-r)] += a[i];
        pp[i] -= a[i];
        pp[i+1] += a[i];
        pp[min(n+1,i+r+1)] -= a[i];
    }
    rep(i,1,n+1) {
        pp[i] += pp[i-1];
        // cout<<pp[i]<<" ";
        a[i] += pp[i];
    }
    // br;
    // rep(i,1,n+1) cout<<a[i]<<" ";;br;
    lld low = 0, high = 2e18;
    while(high - low >1) {
        lld mid = (high + low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    if(check(high)) cout<<high;
    else cout<<low;
    return 0;
}


#include<iostream>
#include<string.h>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 500010
#define ll long long
using namespace std;

ll a[N],k,num[N],tem[N];
ll n,r;
int lb(int k)
{
	return k&(-k);
}
void add(ll p,ll v,ll nu[])
{
	while(p<N)
	{
		nu[p]+=v;
		p+=lb(p);
	}
}
ll sum(ll p,ll nu[])
{
	ll ans=0;
	while(p>0)
	{
		ans+=nu[p];
		p-=lb(p);
	}
	return ans;
}
bool solve(ll m)
{
	ll kk=k;
	for(int i=0;i<N;i++) tem[i]=num[i];
//	cout<<tem[1]<<endl;
	for(int i=1;i<=n;i++)
	{
//		cout<<"i"<<" "<<i<<" "<<tem[1]<<endl;
		ll zuo=max(i-r,(ll)1),you=min(i+r,n);
		ll pos=sum(you,tem)-sum(zuo-1,tem);
	//	cout<<sum(1,tem)<<" "<<sum(you,tem)<<" "<<sum(zuo-1,tem)<<" "<<pos<<endl;
		if(pos<m)
		{
			if(kk>=m-pos)
			{
				add(you,m-pos,tem);
				kk-=(m-pos);
			}
			else
			{
//				cout<<"!"<<endl;
				return 0;
			}
		}
	}
//	cout<<"!"<<endl;
	return 1;
}
int main()
{
	scanf("%I64d%I64d%I64d",&n,&r,&k);
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		add(i,a[i],num);
	}
	ll l=0,rr=1000500000000000000;
	while(l<=rr)
	{
		ll mid=(l+rr)>>1;
//		cout<<l<<" "<<mid<<" "<<rr<<endl;
		if(solve(mid)) l=mid+1;
		else rr=mid-1;
	}
	printf("%I64d\n",rr);
}


#include<iostream>
#include<string.h>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 500010
#define ll long long
using namespace std;

ll a[N],k,sum[N],tem[N],jia[N];
ll n,r;
bool solve(ll m)
{
	ll kk=k,add=0;
	memset(jia,0,sizeof(jia));
	for(int i=1;i<=n;i++)
	{
		if(i-r-1>=1) add-=jia[i-r-1];
		ll zuo=max(i-r,(ll)1),you=min(i+r,n);
		ll pos=sum[you]-sum[zuo-1]+add;
//		if(i==5) cout<<jia[2]<<" "<<pos<<endl;
		if(pos<m)
		{
			if(kk>=m-pos)
			{
				jia[you]+=m-pos;
				add+=(m-pos);
				kk-=(m-pos);
			}
			else
			{
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	scanf("%I64d%I64d%I64d",&n,&r,&k);
	sum[0]=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	if(solve(4)) cout<<"!"<<endl;
	ll l=0,rr=1000500000000000000;
	while(l<=rr)
	{
		ll mid=(l+rr)>>1;
		if(solve(mid)) l=mid+1;
		else rr=mid-1;
	}
	printf("%I64d\n",rr);
}


#include<iostream>
#include<string.h>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 500010
#define ll long long
using namespace std;

ll a[N],k,num[N],tem[N];
ll n,r;
int lb(int k)
{
	return k&(-k);
}
void add(ll p,ll v,ll nu[])
{
	while(p<N)
	{
		nu[p]+=v;
		p+=lb(p);
	}
}
ll sum(ll p,ll nu[])
{
	ll ans=0;
	while(p>0)
	{
		ans+=nu[p];
		p-=lb(p);
	}
	return ans;
}
bool solve(ll m)
{
	ll kk=k;
	for(int i=0;i<N;i++) tem[i]=num[i];
//	cout<<tem[1]<<endl;
	for(int i=1;i<=n;i++)
	{
//		cout<<"i"<<" "<<i<<" "<<tem[1]<<endl;
		ll zuo=max(i-r,(ll)1),you=min(i+r,n);
		ll pos=sum(you,tem)-sum(zuo-1,tem);
	//	cout<<sum(1,tem)<<" "<<sum(you,tem)<<" "<<sum(zuo-1,tem)<<" "<<pos<<endl;
		if(pos<m)
		{
			if(kk>=m-pos)
			{
				add(you,m-pos,tem);
				kk-=(m-pos);
			}
			else
			{
//				cout<<"!"<<endl;
				return 0;
			}
		}
	}
//	cout<<"!"<<endl;
	return 1;
}
int main()
{
	scanf("%I64d%I64d%I64d",&n,&r,&k);
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		add(i,a[i],num);
	}
	ll l=0,rr=1e18+1e9;
	while(l<=rr)
	{
		ll mid=(l+rr)>>1;
//		cout<<l<<" "<<mid<<" "<<rr<<endl;
		if(solve(mid)) l=mid+1;
		else rr=mid-1;
	}
	printf("%I64d\n",rr);
}


#include<iostream>
#include<string.h>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 500010
#define ll long long
using namespace std;

ll a[N],k,num[N],tem[N];
ll n,r;
int lb(int k)
{
	return k&(-k);
}
void add(ll p,ll v,ll nu[])
{
	while(p<N)
	{
		nu[p]+=v;
		p+=lb(p);
	}
}
ll sum(ll p,ll nu[])
{
	ll ans=0;
	while(p>0)
	{
		ans+=nu[p];
		p-=lb(p);
	}
	return ans;
}
bool solve(ll m)
{
	ll kk=k;
	for(int i=0;i<N;i++) tem[i]=num[i];
//	cout<<tem[1]<<endl;
	for(int i=1;i<=n;i++)
	{
//		cout<<"i"<<" "<<i<<" "<<tem[1]<<endl;
		ll zuo=max(i-r,(ll)1),you=min(i+r,n);
		ll pos=sum(you,tem)-sum(zuo-1,tem);
	//	cout<<sum(1,tem)<<" "<<sum(you,tem)<<" "<<sum(zuo-1,tem)<<" "<<pos<<endl;
		if(pos<m)
		{
			if(kk>=m-pos)
			{
				add(you,m-pos,tem);
				kk-=(m-pos);
			}
			else
			{
//				cout<<"!"<<endl;
				return 0;
			}
		}
	}
//	cout<<"!"<<endl;
	return 1;
}
int main()
{
	scanf("%I64d%I64d%I64d",&n,&r,&k);
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		add(i,a[i],num);
	}
	ll l=0,rr=1e18+1e15;
	while(l<=rr)
	{
		ll mid=(l+rr)>>1;
//		cout<<l<<" "<<mid<<" "<<rr<<endl;
		if(solve(mid)) l=mid+1;
		else rr=mid-1;
	}
	printf("%I64d\n",rr);
}


#include<iostream>
#include<string.h>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 500010
#define ll long long
using namespace std;

ll a[N],k,sum[N],tem[N],jia[N];
ll n,r;
bool solve(ll m)
{
	ll kk=k,add=0;
	memset(jia,0,sizeof(jia));
	for(int i=1;i<=n;i++)
	{
		if(i-r-1>=1) add-=jia[i-r-1];
		ll zuo=max(i-r,(ll)1),you=min(i+r,n);
		ll pos=sum[you]-sum[zuo-1]+add;
//		if(i==5) cout<<jia[2]<<" "<<pos<<endl;
		if(pos<m)
		{
			if(kk>=m-pos)
			{
				jia[you]+=m-pos;
				add+=(m-pos);
				kk-=(m-pos);
			}
			else
			{
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	scanf("%I64d%I64d%I64d",&n,&r,&k);
	sum[0]=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
//	if(solve(4)) cout<<"!"<<endl;
	ll l=0,rr=1000500000000000000;
	while(l<=rr)
	{
		ll mid=(l+rr)>>1;
		if(solve(mid)) l=mid+1;
		else rr=mid-1;
	}
	printf("%I64d\n",rr);
}


#include<iostream>
#include<string.h>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 500010
#define ll long long
using namespace std;

ll a[N],k,num[N],tem[N];
ll n,r;
int lb(int k)
{
	return k&(-k);
}
void add(ll p,ll v,ll nu[])
{
	while(p<N)
	{
		nu[p]+=v;
		p+=lb(p);
	}
}
ll sum(ll p,ll nu[])
{
	ll ans=0;
	while(p>0)
	{
		ans+=nu[p];
		p-=lb(p);
	}
	return ans;
}
bool solve(ll m)
{
	ll kk=k;
	for(int i=0;i<N;i++) tem[i]=num[i];
//	cout<<tem[1]<<endl;
	for(int i=1;i<=n;i++)
	{
//		cout<<"i"<<" "<<i<<" "<<tem[1]<<endl;
		ll zuo=max(i-r,(ll)1),you=min(i+r,n);
		ll pos=sum(you,tem)-sum(zuo-1,tem);
	//	cout<<sum(1,tem)<<" "<<sum(you,tem)<<" "<<sum(zuo-1,tem)<<" "<<pos<<endl;
		if(pos<m)
		{
			if(kk>=m-pos)
			{
				add(you,m-pos,tem);
				kk-=(m-pos);
			}
			else
			{
//				cout<<"!"<<endl;
				return 0;
			}
		}
	}
//	cout<<"!"<<endl;
	return 1;
}
int main()
{
	scanf("%I64d%I64d%I64d",&n,&r,&k);
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		add(i,a[i],num);
	}
	ll l=0,rr=1e13;
	while(l<=rr)
	{
		ll mid=(l+rr)>>1;
//		cout<<l<<" "<<mid<<" "<<rr<<endl;
		if(solve(mid)) l=mid+1;
		else rr=mid-1;
	}
	printf("%I64d\n",rr);
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
const int maxn = 5e5 + 1000;

ll a[maxn];
ll b[maxn];
int N; int r; ll K; int M;

bool check(ll mid)
{
	ll sum = 0;
	int d = 2 * r + 1;
	for (int i = 1; i <= N + 1; i++) b[i] = 0;
	ll now = 0;
	for (int i = 1; i <= N; i++)
	{
		now += b[i];
		if (a[i] + now >= mid) continue;
		else
		{
			int L = i; int R = min(L + d - 1, N) + 1;
			ll dif = mid - (a[i] + now);
			now += dif;
			b[i] += dif; b[R] -= dif;
			sum += dif;
		}

		if (sum >= K)return false;
	}
	return sum <= K;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> r >> K;
	for (int i = 1; i <= N; i++)
	{
		ll x; cin >> x;
		int L = max(1, i - r);
		int R = min(i + r, N) + 1;
		a[L] += x; a[R] -= x;
	}
	for (int i = 1; i <= N; i++)a[i] += a[i - 1];

	ll L = 0; ll R =  2e18;
	while (L <= R)
	{
		ll mid = (L + R) >> 1;
		if (check(mid) == true) L = mid + 1;
		else R = mid - 1;
	}
	cout << R << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
const int maxn = 5e5 + 1000;

ll a[maxn];
ll b[maxn];
int N; int r; ll K; int M;

bool check(ll mid)
{
	ll sum = 0;
	for (int i = 1; i <= M; i++)
	{
		sum += max(0ll , mid - b[i]);
	}
	return sum <= K;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> r >> K;
	for (int i = 1; i <= N; i++)
	{
		ll x; cin >> x;
		int L = max(1, i - r);
		int R = min(i + r, N) + 1;
		a[L] += x; a[R] -= x;
	}
	for (int i = 1; i <= N; i++)a[i] += a[i - 1];
	int D = 2 * r + 1; M = (N + D - 1) / D;
	for (int i = 1; i <= M; i++)
	{
		int L = (i - 1) * D + 1; int R = min(L + D - 1, N);
		ll pmin = 1e18;
		for (int j = L; j <= R; j++)
		{
			pmin = min(pmin, a[j]);
		}
		b[i] = pmin;
	}

	ll L = 0; ll R = 1e18 + 1e9 + 10;
	while (L <= R)
	{
		ll mid = (L + R) >> 1;
		if (check(mid) == true) L = mid + 1;
		else R = mid - 1;
	}
	cout << R << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
const int maxn = 5e5 + 1000;

ll a[maxn];
ll b[maxn];
int N; int r; ll K; int M;

bool check(ll mid)
{
	ll sum = 0;
	for (int i = 1; i <= M; i++)
	{
		sum += max(0ll , mid - b[i]);
		if (sum > K) return false;
	}
	return sum <= K;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> r >> K;
	for (int i = 1; i <= N; i++)
	{
		ll x; cin >> x;
		int L = max(1, i - r);
		int R = min(i + r, N) + 1;
		a[L] += x; a[R] -= x;
	}
	for (int i = 1; i <= N; i++)a[i] += a[i - 1];
	int D = 2 * r + 1; M = (N + D - 1) / D;
	for (int i = 1; i <= M; i++)
	{
		int L = (i - 1) * D + 1; int R = min(L + D - 1, N);
		ll pmin = 1e18;
		for (int j = L; j <= R; j++)
		{
			pmin = min(pmin, a[j]);
		}
		b[i] = pmin;
	}

	ll L = 0; ll R = 2e18;
	while (L <= R)
	{
		ll mid = (L + R) >> 1;
		if (check(mid) == true) L = mid + 1;
		else R = mid - 1;
	}
	cout << R << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
const int maxn = 5e5 + 1000;

ll a[maxn];
ll b[maxn];
int N; int r; ll K; int M;

bool check(ll mid)
{
	ll sum = 0;
	int d = 2 * r + 1;
	for (int i = 1; i <= N + 1; i++) b[i] = 0;
	ll now = 0;
	for (int i = 1; i <= N; i++)
	{
		now += b[i];
		if (a[i] + now >= mid) continue;
		else
		{
			int L = i; int R = min(L + d - 1, N) + 1;
			ll dif = mid - (a[i] + now);
			now += dif;
			b[i] += dif; b[R] -= dif;
			sum += dif;
		}

		if (sum > K)return false;
	}
	return sum <= K;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> r >> K;
	for (int i = 1; i <= N; i++)
	{
		ll x; cin >> x;
		int L = max(1, i - r);
		int R = min(i + r, N) + 1;
		a[L] += x; a[R] -= x;
	}
	for (int i = 1; i <= N; i++)a[i] += a[i - 1];

	ll L = 0; ll R =  2e18;
	while (L <= R)
	{
		ll mid = (L + R) >> 1;
		if (check(mid) == true) L = mid + 1;
		else R = mid - 1;
	}
	cout << R << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
const int maxn = 5e5 + 1000;

ll a[maxn];
ll b[maxn];
int N; int r; ll K; int M;

bool check(ll mid)
{
	ll sum = 0;
	for (int i = 1; i <= M; i++)
	{
		sum += max(0ll , mid - b[i]);
		if (sum > K) return false;
	}
	return sum <= K;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> r >> K;
	for (int i = 1; i <= N; i++)
	{
		ll x; cin >> x;
		int L = max(1, i - r);
		int R = min(i + r, N) + 1;
		a[L] += x; a[R] -= x;
	}
	for (int i = 1; i <= N; i++)a[i] += a[i - 1];
	int D = 2 * r + 1; M = (N + D - 1) / D;
	for (int i = 1; i <= M; i++)
	{
		int L = (i - 1) * D + 1; int R = min(L + D - 1, N);
		ll pmin = 1e18;
		for (int j = L; j <= R; j++)
		{
			pmin = min(pmin, a[j]);
		}
		b[i] = pmin;
	}

	ll L = 0; ll R = 1e18 + 1e9 + 10;
	while (L <= R)
	{
		ll mid = (L + R) >> 1;
		if (check(mid) == true) L = mid + 1;
		else R = mid - 1;
	}
	cout << R << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
const int maxn = 5e5 + 1000;

ll a[maxn];
ll b[maxn];
int N; int r; ll K; int M;

bool check(ll mid)
{
	ll sum = 0;
	for (int i = 1; i <= M; i++)
	{
		sum += max(0ll, mid - b[i]);
	}
	return sum <= K;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> r >> K;
	for (int i = 1; i <= N; i++)
	{
		ll x; cin >> x;
		int L = max(1, i - r);
		int R = min(i + r, N) + 1;
		a[L] += x; a[R] -= x;
	}
	for (int i = 1; i <= N; i++)a[i] += a[i - 1];
	int D = 2 * r + 1; M = (N + D - 1) / D;
	for (int i = 1; i <= M; i++)
	{
		int L = (i - 1) * D + 1; int R = min(L + D - 1, N);
		ll pmin = 1e18;
		for (int j = L; j <= R; j++)
		{
			pmin = min(pmin, a[j]);
		}
		b[i] = pmin;
	}

	ll L = 0; ll R = 1e18;
	while (L <= R)
	{
		ll mid = (L + R) >> 1;
		if (check(mid) == true) L = mid + 1;
		else R = mid - 1;
	}
	cout << R << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mode 998244353
#define mx 500005
#define inf 1e17
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int arr[mx];
ll dp[mx];
int n,r;
vector<int> v;
vector<ll> defense;
ll k;
bool f(ll mid)
{
	ll cnt = 0;
	int id = -100000000;
	ll mn = inf;
	fl(i,1,n+1)
	{
	//	cout<<dp[i]<<" ";
		if(dp[i] < mid)
		{
			if(id < i - r)
			{
				id = i + r;
				cnt += max(0LL,mid-mn);
				mn = dp[i];
			}
			else
			{
				mn = min(mn,dp[i]);
			}
		}
		else continue;
	}
	cnt += max(0LL,mid-mn);
//	cout<<cnt;
	return cnt <= k;
}
main()
{
	fast;

	cin>>n>>r>>k;
	fl(i,1,n+1)
	{
		cin>>arr[i];
		int start = max(i - r, 1);
		int end = min(n,i + r);
		dp[start] += arr[i];
		dp[end+1] -= arr[i];
	}
	fl(i,1,n+1)
	{
		dp[i] += dp[i-1];
	}
	int loc = 0;

	ll low = 1, high = 2e18 , mid;
	while(low < high)
	{
		mid = (low + high) /2 + (low+high)%2;
		if(f(mid))
		{
			low = mid;
		}
		else
		{
			high = mid - 1;
		}
	}
	cout<<low;

}


#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mode 998244353
#define mx 500005
#define inf 1e17
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int arr[mx];
ll dp[mx];
int n,r;
vector<int> v;
vector<ll> defense;
ll k;
bool f(ll mid)
{
	ll cnt = 0;
	int id = -100000000;
	ll mn = inf;
	fl(i,1,n+1)
	{
	//	cout<<dp[i]<<" ";
		if(dp[i] < mid)
		{
			if(id < i - r)
			{
				id = i + r;
				cnt += max(0LL,mid-mn);
				mn = dp[i];
			}
			else
			{
				mn = min(mn,dp[i]);
			}
		}
		else continue;
	}
	cnt += max(0LL,mid-mn);
//	cout<<cnt;
	return cnt <= k;
}
main()
{
	fast;

	cin>>n>>r>>k;
	fl(i,1,n+1)
	{
		cin>>arr[i];
		int start = max(i - r, 1);
		int end = min(n,i + r);
		dp[start] += arr[i];
		dp[end+1] -= arr[i];
	}
	fl(i,1,n+1)
	{
		dp[i] += dp[i-1];
	}
	int loc = 0;

	ll low = 0, high = 2e18 , mid; // low = 0 -_-
	while(low < high)
	{
		mid = (low + high) /2 + (low+high)%2;
		if(f(mid))
		{
			low = mid;
		}
		else
		{
			high = mid - 1;
		}
	}
	cout<<low;

}


#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mode 998244353
#define mx 500005
#define inf 1e17
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int arr[mx];
ll dp[mx];
vector<int> v;
vector<ll> defense;
ll k;
bool f(ll mid)
{
	ll cnt = 0;
	fl(i,0,defense.size())
	{
		cnt += max(0LL, mid - defense[i]);
	}
	return cnt <= k;
}
main()
{
	fast;
	int n,r;
	cin>>n>>r>>k;
	fl(i,1,n+1)
	{
		cin>>arr[i];
		int start = max(i - r, 1);
		int end = min(n,i + r);
		dp[start] += arr[i];
		dp[end+1] -= arr[i];
	}
	fl(i,1,n+1)
	{
		dp[i] += dp[i-1];
	}
	int loc = 0;

	fl(i,1,n+1)
	{
		if(i - loc > r)
		{
			v.pb(i);
			ll ans = inf;
			for(int j = loc + 1 ; j <= min(n,i+r); j++)
			{
				ans = min(ans,dp[j]);
			}
			defense.pb(ans);
	//		cout<<ans<<endl;
			loc = i + r;
		}
	}
	ll low = 1, high = 2e18 , mid;
	while(low < high)
	{
		mid = (low + high) /2 + (low+high)%2;
		if(f(mid))
		{
			low = mid;
		}
		else
		{
			high = mid - 1;
		}
	}
	cout<<low;

}


#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define int long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mode 998244353
#define mx 500005
#define inf 2e18
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int arr[mx];
ll dp[mx];
int n,r;
vector<int> v;
vector<ll> defense;
ll k;
bool f(ll mid)
{
	ll cnt = 0;
	int id = -100000000;
	ll mn = inf;
	fl(i,1,n+1)
	{
	//	cout<<dp[i]<<" ";
		if(dp[i] < mid)
		{
			if(id < i - r)
			{
				id = i + r;
				cnt += max(0LL,mid-mn);
				mn = dp[i];
				if(cnt > k)break;
			}
			else
			{
				mn = min(mn,dp[i]);
			}
		}
		else continue;

	}
	cnt += max(0LL,mid-mn);
//	cout<<cnt;
	return cnt <= k;
}
main()
{
	fast;

	cin>>n>>r>>k;
	fl(i,1,n+1)
	{
		cin>>arr[i];
		int start = max(i - r, 1LL);
		int end = min(n,i + r);
		dp[start] += arr[i];
		dp[end+1] -= arr[i];
	}
	fl(i,1,n+1)
	{
		dp[i] += dp[i-1];
	}
	int loc = 0;

	ll low = 0, high =2e18 , mid; // low = 0 -_-
	while(low < high)
	{
		mid = (low + high) /2 + (low+high)%2;
		if(f(mid))
		{
			low = mid;
		}
		else
		{
			high = mid - 1;
		}
	}
	cout<<low;

}