import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } void chmin(T)(ref T t, in T f) { if (t > f) t = f; } void chmax(T)(ref T t, in T f) { if (t < f) t = f; } int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); } enum MO = 10L^^9 + 7; enum M = 24; enum LIM = 10^^4 + 10; long[] ten; long[][][] dp; int N; string A, B; long calc(int i, int x, int y, bool diffA, bool diffB) { long ret; if (i == N) { ret += ((x % 3 == 0 || y) && (x % 8 != 0)) ? 1 : 0; } else if (diffA && diffB) { foreach (dx; 0 .. M) foreach (dy; 0 .. 2) { const xx = (x * ten[N - i] + dx) % M; const yy = y | dy; if ((xx % 3 == 0 || yy) && (xx % 8 != 0)) { ret += dp[N - i][dx][dy]; } } } else { foreach (d; (diffA ? 0 : (A[i] - '0')) .. (diffB ? 9 : (B[i] - '0')) + 1) { ret += calc(i + 1, x * 10 + d, (y || d == 3) ? 1 : 0, (diffA || (d != A[i] - '0')), (diffB || (d != B[i] - '0'))); } } ret %= MO; debug { writefln("calc %s %s %s %s %s: %s", i, x, y, diffA, diffB, ret); } return ret; } void main() { ten = new long[LIM]; ten[0] = 1; foreach (i; 1 .. LIM) { ten[i] = (ten[i - 1] * 10) % M; } dp = new long[][][](LIM + 1, M, 2); dp[0][0][0] = 1; foreach (i; 0 .. LIM) { foreach (x; 0 .. M) foreach (y; 0 .. 2) { foreach (d; 0 .. 10) { (dp[i + 1][(x * 10 + d) % M][(y || d == 3) ? 1 : 0] += dp[i][x][y]) %= MO; } } } try { for (; ; ) { A = readToken(); B = readToken(); N = cast(int)(B.length); A = iota(N - A.length).map!(_ => '0').array.to!string ~ A; debug { writeln("A = ", A); writeln("B = ", B); } const ans = calc(0, 0, 0, false, false); writeln(ans); } } catch (EOFException e) { } }