#include #include using namespace std; typedef long long ll; const ll MOD = 1e9 + 7/*998244353*/; const ll INF = 1LL << 60; ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll); // ll fun(const string& s){ vector>>> dp(s.size() + 1, vector>>(2, vector>(2, vector(24)))); dp[0][0][0][0] = 1; for(int i = 0; i < s.size(); i++){ int d = s[i] - '0'; for(int j = 0; j < 2; j++){//下回ってるか否か for(int k = 0; k < 2; k++){//3が入ってるかどうか for(int mod = 0; mod < 24; mod++){ for(int n = 0; n <= (j ? 9 : d); n++){ dp[i + 1][j || (n < d)][k || (n == 3)][(mod * 10 + n) % 24] = (dp[i + 1][j || (n < d)][k || (n == 3)][(mod * 10 + n) % 24] + dp[i][j][k][mod]) % MOD; } } } } } ll ans = 0; for(int j = 0; j < 2; j++){ for(int mod = 0; mod < 24; mod++){//3が入っていない if(mod % 3 == 0 && (mod % 8)) ans = (ans + dp[s.size()][j][0][mod]) % MOD; } for(int mod = 0; mod < 24; mod++){//いる if(mod % 8) ans = (ans + dp[s.size()][j][1][mod]) % MOD; } } return ans; } int main(){ string a, b; cin >> a >> b; ll ans = (fun(b) - fun(a) + MOD) % MOD; //cout << fun(b) << "\n"; //cout << fun(a) << "\n"; bool bl = false; int mod = (a[0] - '0'); for(int i = 1; i < a.size(); i++){ bl |= (a[i] == '3'); mod = (mod * 10 + a[i] - '0') % 24; } if(mod % 8 == 0) cout << ans << "\n"; else{ bl |= (mod % 3 == 0); if(bl) cout << ans + 1 << "\n"; else cout << ans << "\n"; } }