#include #include #include using namespace std; using i64 = int64_t; constexpr int mod = static_cast(powl(10, 9)) + 7; vector p10; // p10[i] := 10**i % 24 inline int cmp(const int x, const int y) { if(x < y) { return 0; } if(x == y) { return 1; } return 2; } i64 f(string s) { int n = static_cast(s.size()); // dp[未満/丁度/超過][3がつくか?][3での余り][8での余り] := 個数 vector>>> dp(3, vector>>(2, vector>(3, vector(8, 0)))); dp[1][0][0][0] = 1; for(int i=n-1; i>=0; --i) { vector>>> ndp(3, vector>>(2, vector>(3, vector(8, 0)))); for(int flag=0; flag<3; ++flag) { for(int has3=0; has3<2; ++has3) { for(int rem=0; rem<24; ++rem) { if(!dp[flag][has3][rem%3][rem%8]) { continue; } for(int d=0; d<10; ++d) { int nflag = cmp(d, s[i]-'0'); if(nflag == 1) { nflag = flag; } int nrem = (rem + p10[n-1-i] * d) % 24; int nhas3 = has3 || (d == 3); ndp[nflag][nhas3][nrem%3][nrem%8] += dp[flag][has3][rem%3][rem%8]; ndp[nflag][nhas3][nrem%3][nrem%8] %= mod; } } } } dp = ndp; } i64 res = 0; for(int flag=0; flag<2; ++flag) { for(int rem8=1; rem8<8; ++rem8) { for(int rem3=0; rem3<3; ++rem3) { res += dp[flag][1][rem3][rem8]; res %= mod; } res += dp[flag][0][0][rem8]; res %= mod; } } return res; } void minus1(string &s) { int n = static_cast(s.size()); for(int i=n-1; i>=0; --i) { if(s[i] == '0') { s[i] = '9'; } else { s[i] -= 1; break; } } } int main(void) { p10.resize(10010); p10[0] = 1; for(int i=0; i<10005; ++i) { p10[i+1] = p10[i] * 10 % 24; } string a, b; cin >> a >> b; minus1(a); i64 res = f(b) - f(a); res += mod; res %= mod; printf("%ld\n", res); return 0; }