#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct Mint{ T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;}; Mint operator-(Mint a) const{return Mint(v)-=a;}; Mint operator*(Mint a) const{return Mint(v)*=a;}; Mint operator/(Mint a) const{return Mint(v)/=a;}; Mint operator-(){return v?MOD-v:v;} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v ; const int MAX = 1e4 + 100; M dp[2][2][3][8][MAX]; int used[2][2][3][8][MAX]; M dfs(string &s,int i,int t,int a,int x,int y){ M &res=dp[t][a][x][y][i]; if(i==0) return res=(a||(x==0))&&(y!=0); if(!t&&used[t][a][x][y][i]) return res; used[t][a][x][y][i]=1; res=M(0); for(int k=0;k<=(t?s[i-1]-'0':9);k++) res+=dfs(s,i-1,t&&(k==s[i-1]-'0'),a||(k==3),(x*10+k)%3,(y*10+k)%8); return res; } signed main(){ string a,b; cin>>a>>b; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); M ans; memset(used,0,sizeof(used)); ans+=dfs(b,b.size(),1,0,0,0); ans-=dfs(a,a.size(),1,0,0,0); int flg=0,m3=0,m8=0; for(int i=0;i<(int)a.size();i++){ flg|=a[i]=='3'; m3=(m3*10+(a[i]-'0'))%3; m8=(m8*10+(a[i]-'0'))%8; } if((flg||!m3)&&m8) ans+=M(1); cout<