// #undef _GLIBCXX_DEBUG // #undef LOCAL #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include using namespace std; #if __has_include() #include using namespace atcoder; #endif #ifdef LOCAL #include "../algo/debug.hpp" #else #define debug(...) void(0) #endif constexpr int inf = (1<<30) - 1; constexpr long long linf = (1LL<<60) - 1; using ll = long long; using ld = long double; #define len(x) int((x).size()) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define LB(c, x) distance(begin(c), lower_bound(all(c), x)) #define UB(c, x) distance(begin(c), upper_bound(all(c), x)) template inline auto min(const T& a, const S& b) { return(a < b ? a : b); } template inline auto max(const T& a, const S& b) { return(a > b ? a : b); } template inline bool chmax(T& a, const S& b) { return(a < b ? a = b, 1 : 0); } template inline bool chmin(T& a, const S& b) { return(a > b ? a = b, 1 : 0); } // ------------------------------------------------------------------ void solve() { string A, B; cin >> A >> B; using mint = modint1000000007; auto f = [&](string s) -> mint { int n = len(s); vector dp(n + 1, vector>>>(2, vector>>(2, vector>(3, vector(8, 0))))); dp[0][0][0][0][0] = 1; for(int i = 0; i < n; i++) { for(int j = 0; j < 2; j++) { for(int k = 0; k < 2; k++) { for(int l = 0; l < 3; l++) { for(int m = 0; m < 8; m++) { int lim = j ? 9: s[i] - '0'; for(int d = 0; d <= lim; d++) { dp[i + 1][j || d < lim][k || d == 3][(l + d)%3][(2*m+d)%8] += dp[i][j][k][l][m]; } } } } } } mint ans = 0; for(int i = 0; i < 2; i++) { for(int j = 0; j < 2; j++) { for(int k = 0; k < 3; k++) { for(int l = 1; l < 8; l++) { if(j == 1 || k == 0) ans += dp[n][i][j][k][l]; } } } } return ans; }; A.back() -= 1; mint ans = f(B) - f(A); cout << ans.val() << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // fixed(cout).precision(12); int T = 1; // cin >> T; while(T--) { solve(); } }