#include #include #include #include #include #include #include #include #include #include using namespace std; #define MOD 1000000007 long long func(string& a){ // dp[l][h][j][k] := (h={0,1}, aより確実に小さいか) (j={0,1}, 3が出現したか) (k=0,1,2 , 各桁の和 %3) (l<1000, 下3桁) vector>>> dp(1000, vector>>(2, vector>(2, vector(3, 0)))); vector>>> dp_(1000, vector>>(2, vector>(2, vector(3, 0)))); dp[0][0][0][0] = 1; for(int i=0; i v)) next_h = 1; int next_j = j; if(j == 0 && v == 3) next_j = 1; int next_k = (k+v)%3; int next_l = 0; if(a.size()-i < 5) next_l = (l * 10 + v) % 1000; long long & next_pos = dp_[next_l][next_h][next_j][next_k]; next_pos += dp[l][h][j][k]; if( next_pos >= MOD ) next_pos -= MOD; } } } } } swap(dp, dp_); } long long ret = 0; for(int l=0; l<1000; l++){ for(int h=0; h<2; h++){ for(int j=0; j<2; j++){ for(int k=0; k<3; k++){ long long& val = dp[l][h][j][k]; if(l%8 == 0) continue; if(j==1 && k==0) ret -= val; if(j==1) ret += val; if(k==0) ret += val; ret = (ret+MOD)%MOD; } } } } return (ret+MOD)%MOD; } int main(){ string a,b; cin >> a >> b; long long ans = func(b); ans -= func(a); bool a_is = false; int tmp = 0; for(int i=0; i