using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; class Program { static readonly int Mod = (int)1e9 + 7; void Add(ref int a, int b) { if ((a += b) >= Mod) a -= Mod; } public void Solve() { var A = Reader.String(); var B = Reader.String(); int ans = ((Count(B) - Count((BigInteger.Parse(A) - 1) + "")) % Mod + Mod) % Mod; Console.WriteLine(ans); } private int Count(string S) { int N = S.Length; var dp = new int[N + 1, 2, 3, 2, 8]; // index, smaller, mod3, contains3, mod8 dp[0, 0, 0, 0, 0] = 1; for (int i = 0; i < N; i++) for (int smaller = 0; smaller < 2; smaller++) for (int d = 0; d <= 9; d++) if (smaller == 1 || d <= S[i] - '0') for (int mod3 = 0; mod3 < 3; mod3++) for (int has3 = 0; has3 < 2; has3++) for (int mod8 = 0; mod8 < 8; mod8++) { int ns = smaller | (d < S[i] - '0' ? 1 : 0); int nmod3 = (mod3 + d) % 3; int nhas3 = has3 | (d == 3 ? 1 : 0); int nmod8 = (mod8 * 10 + d) % 8; Add(ref dp[i + 1, ns, nmod3, nhas3, nmod8], dp[i, smaller, mod3, has3, mod8]); } int res = 0; for (int smaller = 0; smaller < 2; smaller++) for (int mod8 = 1; mod8 < 8; mod8++) { Add(ref res, dp[N, smaller, 0, 0, mod8]); for (int mod3 = 0; mod3 < 3; mod3++) Add(ref res, dp[N, smaller, mod3, 1, mod8]); } return res; } } class Entry { static void Main() { new Program().Solve(); } } class Reader { private static TextReader reader = Console.In; private static readonly char[] separator = { ' ' }; private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; private static string[] A = new string[0]; private static int i; private static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); } public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); } public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Next()).ToArray(); } public static string Line() { return reader.ReadLine().Trim(); } private static string[] Split(string s) { return s.Split(separator, op); } private static string Next() { CheckNext(); return A[i++]; } private static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }