import sys from collections import defaultdict MOD = 10**9 + 7 def decrement_string(s): s_list = list(s) i = len(s_list) - 1 while i >= 0 and s_list[i] == '0': s_list[i] = '9' i -= 1 if i < 0: return '0' s_list[i] = str(int(s_list[i]) - 1) result = ''.join(s_list).lstrip('0') return result if result else '0' def compute(s): digits = list(map(int, s)) n = len(digits) dp = [defaultdict(int) for _ in range(n + 1)] dp[0][(True, True, False, 0, 0)] = 1 for pos in range(n): current_dp = dp[pos] next_dp = defaultdict(int) for state, count in current_dp.items(): tight, leading_zero, has_three, sum_mod3, num_mod8 = state max_d = digits[pos] if tight else 9 for d in range(0, max_d + 1): new_tight = tight and (d == max_d) new_leading_zero = leading_zero and (d == 0) new_has_three = has_three or (d == 3) if leading_zero: if d == 0: new_sum_mod3 = sum_mod3 else: new_sum_mod3 = d % 3 else: new_sum_mod3 = (sum_mod3 + d) % 3 if new_leading_zero: new_num_mod8 = 0 else: if leading_zero: new_num_mod8 = d % 8 else: new_num_mod8 = (num_mod8 * 10 + d) % 8 new_state = (new_tight, new_leading_zero, new_has_three, new_sum_mod3, new_num_mod8) next_dp[new_state] = (next_dp[new_state] + count) % MOD dp[pos + 1] = next_dp total = 0 for state, count in dp[n].items(): tight, leading_zero, has_three, sum_mod3, num_mod8 = state if leading_zero: continue if (has_three or (sum_mod3 == 0)) and (num_mod8 != 0): total = (total + count) % MOD return total def main(): A, B = sys.stdin.readline().split() a_minus_1 = decrement_string(A) ans = (compute(B) - compute(a_minus_1)) % MOD print(ans) if __name__ == "__main__": main()