//yukicoder@cpp17 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; const ll MOD = 998244353; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template vector make_vector(size_t a, T b) { return vector(a, b); } template auto make_vector(size_t a, Ts... ts) { return vector(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ /* function corner below */ /* Function corner above */ /* comment outed because can cause bugs __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } */ template struct ModInt{ int n; ModInt():n(0){} ModInt(long long n_):n(n_ >= 0 ? n_%mod : mod - ((-n_)%mod) ){} ModInt(int n_):n(n_ >= 0 ? n_%mod : mod - ((-n_)%mod) ){} ModInt &operator+=(const ModInt &p){ if((n+=p.n) >= mod)n-=mod; return *this; } ModInt &operator-=(const ModInt &p){ n+=mod-p.n; if(n >= mod)n-=mod; return *this; } ModInt &operator*=(const ModInt &p){ n = (int) ((1LL*n*p.n)%mod); return *this; } ModInt &operator/=(const ModInt &p){ *this *= p.inverse(); return *this; } ModInt operator-() const {return ModInt(-n);} ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;} ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;} ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;} ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;} bool operator==(const ModInt &p) const {return n==p.n;} bool operator<(const ModInt &p) const {return n(const ModInt &p) const {return n>p.n;} bool operator>=(const ModInt &p) const {return n>=p.n;} bool operator<=(const ModInt &p) const {return n<=p.n;} bool operator!=(const ModInt &p) const {return n!=p.n;} ModInt inverse() const { int a = n,b = mod,u = 1,v = 0; while(b){ int t = a/b; a -= t*b; swap(a,b); u -= t*v; swap(u,v); } return ModInt(u); } ModInt pow(int64_t z) const { ModInt ret(1),mul(n); while(z > 0){ if(z & 1) ret *= mul; mul *= mul; z >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p){ return os << p.n; } friend istream &operator>>(istream &is, ModInt &a){ int64_t t; is >> t; a = ModInt ((long long)t); return (is); } }; using mint = ModInt; bool isX(string s){ int k = 0; bool ist = false; for(int i = 0; s.size() > i; i++){ if(s[i] == '3')ist=true; k = (k*10+s[i]-'0')%24; } return (ist && k%8 != 0) || (k%3 == 0 && k%8 != 0); } mint dp[10010][25][2][2]; mint f(string x){ for(int i = 0; x.size() >= i; i++){ for(int j = 0; 24 > j; j++)dp[i][j][0][0] = dp[i][j][0][1] = dp[i][j][1][0] = dp[i][j][1][1] = 0; } dp[0][0][0][1] = 1; for(int i = 0; x.size() > i; i++){ for(int j = 0; 24 > j; j++){ //isEqual if(x[i] != '3'){ dp[i+1][(j*10+x[i]-'0')%24][0][1] += dp[i][j][0][1]; dp[i+1][(j*10+x[i]-'0')%24][1][1] += dp[i][j][1][1]; }else{ dp[i+1][(j*10+x[i]-'0')%24][1][1] += dp[i][j][0][1] + dp[i][j][1][1]; } //lower than equal for(int k = 0; x[i]-'0' > k; k++){ if(k != 3){ dp[i+1][(j*10+k)%24][0][0] += dp[i][j][0][1]; dp[i+1][(j*10+k)%24][1][0] += dp[i][j][1][1]; }else{ dp[i+1][(j*10+k)%24][1][0] += dp[i][j][0][1] + dp[i][j][1][1]; } } //isNotEqual for(int k = 0; 10 > k; k++){ if(k != 3){ dp[i+1][(j*10+k)%24][0][0] += dp[i][j][0][0]; dp[i+1][(j*10+k)%24][1][0] += dp[i][j][1][0]; }else{ dp[i+1][(j*10+k)%24][1][0] += dp[i][j][0][0] + dp[i][j][1][0]; } } } } mint res = 0; for(int i = 0; 24 > i; i++){ if(i%8 == 0)continue; if(i%3 == 0)res += dp[x.size()][i][0][0] + dp[x.size()][i][0][1] + dp[x.size()][i][1][0] + dp[x.size()][i][1][1]; else res += dp[x.size()][i][1][0] + dp[x.size()][i][1][1]; } return res; } int main(){ string a,b;cin>>a>>b; cout << f(b)-f(a)+isX(a) << endl; return 0; }