#include #define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) #define MOD 1000000007 #define int long long using namespace std; typedef long long ll; const int INF = 1e9; string A, B; int dp[101010][2][2][3][8]; //pos, less, has3, mod3, mod8 int countAho(string A) { REP(i,101010) REP(j,2) REP(k,2) REP(l,3) REP(m,8) { dp[i][j][k][l][m] = 0; } int n = A.length(); dp[0][0][0][0][0] = 1; REP(i,n) REP(j,2) REP(k,2) REP(l,3) REP(m,8) { int lim = j ? 9 : A[i] - '0'; REP(d, lim + 1) { (dp[i+1][j || d < lim][k || d == 3][(l + d) % 3][(m * 10 + d) % 8] += dp[i][j][k][l][m]) %= MOD; } } int ans = 0; REP(j,2) REP(k,2) REP(l,3) REP(m,8) { if ((k || l == 0) && m != 0) { (ans += dp[n][j][k][l][m]) %= MOD; } } return ans; } signed main() { cin >> A >> B; bool flag = false; int now = A.length() - 1; while (!flag) { if (A[now] != '0') { A[now] -= 1; flag = true; } else { now--; } } //cout << "A = " << A << endl; int ans = (countAho(B) + MOD - countAho(A)) % MOD; cout << ans << endl; }