#include using namespace std; #define DUMP(x) cerr << #x << "=" << x << endl #define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("< >(x) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define REP(i,m,n) for (int i=m;i<(int)(n);i++) #define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h)) #define ALL(a) (a).begin(),(a).end() typedef long long ll; const int INF = 1e9; typedef pair PII; int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1}; const int MOD = 1e9 + 7; ll dp[10001][2][2][3][8]; // dp[i桁目まで][i-1桁目まで一致しているか][3があるか][mod3][mod8] int calc(string N) { int L = N.size(); memset(dp, 0, sizeof(dp)); dp[0][1][0][0][0] = 1; rep(i, L) rep(same, 2) rep(exist, 2) rep(mod3, 3) rep(mod8, 8) { if (!dp[i][same][exist][mod3][mod8]) continue; rep(d, 10) { int nsame = 0; if (same && d > N[i] - '0') break; if (same && d == N[i] - '0') nsame = 1; dp[i+1][nsame][exist || d == 3][(mod3 * 10 + d) % 3][(mod8 * 10 + d) % 8] += dp[i][same][exist][mod3][mod8]; dp[i+1][nsame][exist || d == 3][(mod3 * 10 + d) % 3][(mod8 * 10 + d) % 8] %= MOD; } } ll res = 0; rep(same, 2) rep(exist, 2) rep(mod3, 3) rep(mod8, 8) { if ((exist || !mod3) && mod8) (res += dp[L][same][exist][mod3][mod8]) %= MOD; } return res - 1; } int main() { string A, B; cin >> A >> B; // A-- for (int i=A.size() - 1; i>=0; i--) { if (A[i] == '0') { A[i] = '9'; } else { A[i]--; break; } } cout << (calc(B) - calc(A) + MOD) % MOD << endl; }