#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) #define FOR(i,a,b) for(ll i = (a);i<(b);i++) #define REP(i,a) FOR(i,0,(a)) #define MP make_pair #define MOD 1000000007 string a, b; int memo[10001][2][2][3][8]; int saiki(int now, bool isSame, bool has3, int mod3, int mod8){ if(now == a.size() && (has3 || mod3 == 0) && mod8 != 0) return 1; if(now == a.size()) return 0; if(memo[now][isSame][has3][mod3][mod8] != INF) return memo[now][isSame][has3][mod3][mod8]; int ret = 0; for(int i = 0;i < 10;i++){ if(isSame && a[now] < ('0' + i)) continue; bool nextIsSame; if(isSame && a[now] == ('0' + i)) nextIsSame = true; else nextIsSame = false; bool nextHas3 = (has3 || i == 3); int nextMod3 = (mod3 + i) % 3; int nextMod8 = (mod8 * 10 + i) % 8; ret += saiki(now + 1, nextIsSame, nextHas3, nextMod3, nextMod8) % MOD; ret %= MOD; } return memo[now][isSame][has3][mod3][mod8] = ret % MOD; } void init(){ REP(i, 10001) REP(j, 2) REP(k, 2) REP(l, 3) REP(m, 8){ memo[i][j][k][l][m] = INF; } } int main() { cin >> b >> a; for(int i = b.size() - 1;i >= 0;i--){ if(b[i] == '0'){ b[i] = '9'; }else { b[i] = (b[i] - 1); break; } } if(b[0] == '0' && b.size() != 1) b.erase(0, 1); init(); int ans = saiki(0, 1, 0, 0, 0) % MOD; a = b; init(); int ans2 = saiki(0, 1, 0, 0, 0) % MOD; // cout << ans << endl << ans2 << endl; cout << ans - ans2 << endl; return 0; }