#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template void chmin(T &a,const T &b){if(a>b) a=b;} template void chmax(T &a,const T &b){if(a F(LIM+1,0); F[0]=1; F[1]=1; for(int i=2;i0){ int t=val%10; val/=10; if(t==1||t==2||t==3||t==5||t==8) ok=false; } cout<>N>>L>>R; vector A; for(auto p:F){ if(L<=p&&p<=R) A.push_back(p); } auto getv=[](ll x){ vector res; while(x>0){ res.push_back(x%10); x/=10; } reverse(all(res)); return res; }; vector v={0}; for(auto x:A){ vector digit=getv(x); ll val=0; for(int i=0;i mp; rep(i,V) mp[v[i]]=i; vector bad(V,0); for(auto x:A) bad[mp[x]]=1; vector> g(V,vector (10,-1)); for(int i=0;i digit=getv(x); reverse(all(digit)); for(int nex=0;nex<=9;nex++){ if(mp.count(nex)&&bad[mp[nex]]) continue; g[i][nex]=mp[0]; ll val=nex; if(mp.count(nex)) g[i][nex]=mp[nex]; ll ten=10; for(int d=0;dR) break; ten=ten*10; if(ten>R) break; } } } vector> dp(N+1,vector (V+1,0)); dp[0][mp[0]]=1; for(int i=0;i