#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MOD = 1000000007; int encode(int a, int b, int c, int d) { return ((a * 2 + b) * 3 + c) * 8 + d; } tuple decode(int x) { tuple ans; get<3>(ans) = x % 8; x /= 8; get<2>(ans) = x % 3; x /= 3; get<1>(ans) = x % 2; x /= 2; get<0>(ans) = x; return ans; } int solve(const string& s) { int n = s.size(); vector dp(96, 0); dp[encode(1, 0, 0, 0)] = 1; for(int i=0; i nextDp(96, 0); for(int x=0; x<96; ++x){ int a, b, c, d; tie(a, b, c, d) = decode(x); for(int j=0; j<=9; ++j){ if(a == 1 && s[i] - '0' < j) continue; int a2 = (a == 1 && s[i] - '0' == j) ? 1 : 0; int b2 = (b == 1 || j == 3) ? 1 : 0; int c2 = (c * 10 + j) % 3; int d2 = (d * 10 + j) % 8; int y = encode(a2, b2, c2, d2); nextDp[y] += dp[x]; nextDp[y] %= MOD; } } dp.swap(nextDp); } int ans = 0; for(int x=0; x<96; ++x){ int a, b, c, d; tie(a, b, c, d) = decode(x); if((b == 1 || c == 0) && d != 0){ ans += dp[x]; ans %= MOD; } } return ans; } int main() { string a, b; cin >> a >> b; unsigned i = a.find_last_not_of('0'); -- a[i]; while(++ i < a.size()) a[i] = '9'; if(a[0] == '0') a = a.substr(1); int ans = solve(b) - solve(a); ans %= MOD; ans += MOD; ans %= MOD; cout << ans << endl; return 0; }