#include #include #include #include using namespace std; const int mod = 1e9 + 7; // Ordering monoid int mul(int x, int y) { return x == 0 ? y : x; } int ordering(int x, int y) { if (x < y) return 1; if (x > y) return 2; return 0; } void to(int &x, int y) { x += y; if (x >= mod) x -= mod; } int f(string a, bool le = true) { const int n = a.size(); static int dp[10001][24][2][3]; // pos, mod, has3, eq/lt/gt memset(dp, 0, sizeof(dp)); dp[n][0][0][0] = 1; vector pow10(n); pow10[0] = 1; for (int i = 0; i + 1 < n; i++) { pow10[i + 1] = 10 * pow10[i] % 24; } for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 24; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 3; l++) { for (int d = 0; d < 10; d++) { to(dp[i][(j + pow10[n - 1 - i] * d) % 24][k || d == 3][mul(ordering(d, a[i] - '0'), l)], dp[i + 1][j][k][l]); } } } } } int ans = 0; for (int j = 0; j < 24; j++) { if (j % 8 == 0) continue; for (int k = 0; k < 2; k++) { if (k || j % 3 == 0) { if (le) { to(ans, dp[0][j][k][0]); } to(ans, dp[0][j][k][1]); } } } return ans; } int main() { string a; string b; cin >> a >> b; cout << (f(b, true) - f(a, false) + mod) % mod << endl; }