#include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(x,y) for(int x = 0;x < (y);x++) #define LLI long long int #define FORR(x,arr) for(auto& x:arr) #define ALL(a) (a.begin()),(a.end()) #define _L(x) cout<<(x)< class UF { public: vector _parent,_rank; UF() { _parent=_rank=vector(um,0); for(int i=0;i_rank[yRoot]) { _parent[xRoot] = yRoot; return yRoot; } if(_rank[xRoot]<_rank[yRoot]) { _parent[yRoot] = xRoot; return xRoot; } if(xRoot != yRoot) { _parent[yRoot] = xRoot; _rank[xRoot]++; return xRoot; } return xRoot; } }; LLI dp[10001][2][2][3][8]; static const LLI mod = 10e9 + 7; LLI solve(string upper) { int upperDigits = (int)upper.length(); memset(&dp[0][0][0][0][0], 0, sizeof(dp)); dp[0][0][0][0][0] = 1; FOR(i, upperDigits) FOR(j, 2) FOR(k, 2) FOR(m, 3) FOR(s, 8) { if(j) { FOR(d, 10) { dp[i+1][1][k || d == 3][(m + d) % 3][(10 * s + d) % 8] += dp[i][1][k][m][s]; dp[i+1][1][k || d == 3][(m + d) % 3][(10 * s + d) % 8] %= mod; } } else { int u = upper[i] - '0'; FOR(d, u + 1) { dp[i+1][d < u][k || d == 3][(m + d) % 3][(10 * s + d) % 8] += dp[i][0][k][m][s]; dp[i+1][d < u][k || d == 3][(m + d) % 3][(10 * s + d) % 8] %= mod; } } } LLI sum = 0; FOR(j, 2) FOR(k, 2) FOR(m, 3) FOR(s, 8) { if(k == 1 || m == 0) { if(s != 0) { sum += dp[upperDigits][j][k][m][s]; sum %= mod; } } } return sum; } static string Decrement(string source) { string result = source; for(int i = (int)source.length() - 1;i >= 0;i--) { if(source[i] == '0') { result[i] = '9'; } else { result[i] = source[i] - 1; return result; } } throw std::exception(); } int main() { string lower, upper; cin >> lower >> upper; LLI lowerValue = solve(Decrement(lower)); LLI upperValue = solve(upper); LLI r = upperValue - lowerValue; if(r < 0) { r += mod; } cout << r << endl; return 0; }