#include using namespace std; const int mod = 1e9 + 7; template auto multiVector(T init, int n) { return vector(n, init); } template auto multiVector(T init, int n, Args... ns) { return vector(init, ns...))>(n, multiVector(init, ns...)); } void upd(int &x, int y) { if ((x += y) >= mod) { x -= mod; } } int pack(int more, int less, int has3, int mod24) { int ret = mod24; ret = ret * 2 + has3; ret = ret * 2 + less; ret = ret * 2 + more; return ret; } tuple unpack(int v) { int more = v % 2; v /= 2; int less = v % 2; v /= 2; int has3 = v % 2; v /= 2; int mod24 = v; return make_tuple(more, less, has3, mod24); } int main() { string A, B; cin >> A >> B; int n = max(A.size(), B.size()); A = string(n - A.size(), '0') + A; B = string(n - B.size(), '0') + B; vector dp0(2 * 2 * 2 * 24); vector dp1(2 * 2 * 2 * 24); dp0[0] = 1; for (int i = 0; i < n; i++) { fill(begin(dp1), end(dp1), 0); for (int j = 0; j < 2 * 2 * 2 * 24; j++) { int more, less, has3, mod24; tie(more, less, has3, mod24) = unpack(j); int L = more ? 0 : A[i] - '0'; int R = less ? 9 : B[i] - '0'; for (int d = L; d <= R; d++) { int nj = pack(more || d > L, less || d < R, has3 || d == 3, (mod24 * 10 + d) % 24); upd(dp1[nj], dp0[j]); } } swap(dp0, dp1); } int ans = 0; for (int j = 0; j < 2 * 2 * 2 * 24; j++) { int has3, mod24; tie(ignore, ignore, has3, mod24) = unpack(j); if ((has3 || mod24 % 3 == 0) && mod24 % 8 != 0) { upd(ans, dp0[j]); } } cout << ans << endl; }