#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--) #define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VD = vector; using VVD = vector; using PII = pair; using PDD = pair; using PLL = pair; using VPII = vector; template using VT = vector; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define FIND(s, e) ((s).find(e) != (s).end()) #define EB emplace_back const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; LL func(const string &N) { const int L = N.length(); //LL dp[keta][mod3][contain 3][mod8][less than N] VT>> dp(L + 1, VT>(3, VT(2, VVL(8, VL(2, 0))))); dp[0][0][0][0][0] = 1; REP(i, L) { const int D = N[i] - '0'; REP(j, 3) REP(k, 2) REP(l, 8) REP(m, 2) REP(d, (m ? 10 : D + 1)) { (dp[i + 1][(j + d) % 3][k || d == 3][(l * 10 + d) % 8][m || d < D] += dp[i][j][k][l][m]) %= MOD; } } LL ans = 0; REP(j, 3) REP(k, 2) REP(l, 8) REP(m, 2) if ((j == 0 || k) && l) { (ans += dp[L][j][k][l][m]) %= MOD; } return ans; } bool f2(const string &N) { const int L = N.length(); bool f = false; LL sum = 0; LL num = 0; REP(i, L) { if (N[i] == '3') return true; sum += N[i] - '0'; if (L - (i + 1) < 3) num += N[i] - '0'; } if (sum % 3 == 0) return true; if (num % 8 == 0) return true; return false; } int main(void) { string A, B; cin >> A >> B; cout << (func(B) - func(A) + f2(A) + MOD) % MOD << endl; }