#include <iostream> #include <cstring> #define LL long long using namespace std; LL l, r; LL f[12][10][10][2][2][2], a[20]; LL Dfs(LL now, LL p, LL pp, LL _4, LL _8, LL top, LL hw) { if(_4 && _8) return 0; if (!now) return hw; if(!top && f[now][p][pp][_4][_8][hw]!=-1) return f[now][p][pp][_4][_8][hw]; LL Up= top?a[now]: 9; LL ret(0); for(LL i=0; r<= Up; ++i) ret += Dfs(now-1,i,p,_4|(i==4),_8|(i==8), top&&(i==Up), hw|(i==pp&&i==p)); if(!top) f[now][p][pp][_4][_8][hw]= ret; return ret ; } inline LL Solve(LL x) { LL tot(0); while (x) { a[++tot]= x% 10; x/= 10; } if(tot != 11) return 0; LL ret(0); for (LL i= 1; i<= a[tot]; ++i) ret +=Dfs(tot-1,i,0,(i==4),(i==8),i==a[tot],0); return ret; } int main() { cin>>l>>r; memset(f,-1,sizeof(f)); cout<< Solve(r) - Solve(l-1); return 0; }