#include <iostream> #include <string> using namespace std; int len; string s; int memo[10001][2][4][8]; int mod = 1000000007; int valid(string s){ int mod3 = 0; int mod8 = 0; bool hav3 = false; for(int i=0; i<len; i++){ int c = s[i]-'0'; mod3 = (mod3*10+c)%3; mod8 = (mod8*10+c)%8; if(c==3) hav3 = true; } return (mod3==0 || hav3) && mod8!=0 ? 1: 0; } int dfs(int d, int border, int thr, int egh){ if(d==len){ return memo[d][border][thr][egh] = thr%3==0&&egh!=0 ? 1: 0; } if(memo[d][border][thr][egh]>=0) return memo[d][border][thr][egh]; int md = border==0?9:s[d]-'0'; int ans = 0; for(int i=0; i<=md; i++){ int nb = border&(i==md?1:0); int nthr; if(thr==3 || i==3) nthr = 3; else nthr = (thr*10+i)%3; ans = (ans+dfs(d+1, nb, nthr, (egh*10+i)%8))%mod; } return ans; } int calc(string str){ s = str; len = str.size(); for(int i=0; i<=len; i++){ for(int j=0; j<2; j++){ for(int k=0; k<4; k++){ for(int l=0; l<8; l++) memo[i][j][k][l] = -1; } } } return dfs(0, 1, 0, 0); } int main(void){ string a, b; cin >> a >> b; cout << ((calc(b)-calc(a)+valid(a)+mod)%mod) << endl; return 0; }