#include #include #define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++) #define rep(i,n) reps(i,0,n) using namespace std; typedef long long ll; const int MOD = 1e9+7; int dp[101010][2][2][3][8]; string A,B; int func(string A,bool less){ int n = A.length(); rep(i,101010){ rep(j,2){ rep(k,2){ rep(l,3){ rep(m,8){ dp[i][j][k][l][m] = 0; } } } } } dp[0][0][0][0][0] = 1; rep(i,n){ rep(j,2){ rep(k,2){ rep(l,3){ rep(m,8){ int lim = j ? 9 : A[i] - '0'; rep(d,lim+1){ ( dp[i+1] [j || d < lim] [k || d == 3] [(l+d)%3] [(m*10+d)%8] += dp[i][j][k][l][m]) %= MOD; } } } } } } int ans = 0; int index = 0; if(!less) index = 1; reps(j,index,2){ rep(k,2){ rep(l,3){ rep(m,8){ if( (k || l == 0) && m != 0){ (ans += dp[n][j][k][l][m]) %= MOD; } } } } } return ans; } int main(){ cin >> A >> B; int ans = func(B,true)-func(A,false); cout << ans << endl; return 0; }