#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define mod 1000000009 #define INF 2000000000 #define LLINF 4000000000000000000 #define SIZE 50010 string C; int M; int memo[10000][3][8][2][3]; // f=0...ALL&&hmax 1...-1&&hmax 2...all&h-1 int dfs(int h,int m3,int m8,int use3,int f,int last){ ll ret=0; if(memo[h][m3][m8][use3][f]) return memo[h][m3][m8][use3][f]; if(h>0 && m8!=0 && (m3==0 || use3)) ret=1; if(h==C.size() || (h==C.size()-1 && f==2)){ return memo[h][m3][m8][use3][f]=(int)ret; } int s =0; if(h==0) s=1; if(f==0){ for(int i=s;i<=9;i++){ ret +=dfs(h+1,(m3*10+i)%3,(m8*10+i)%8,use3 || i==3,0,i); } }else if(f==1){ for(int i=s;i>A >>B; A[A.size()-1]--; for(int i=(int)A.size()-1;i>=0;i--){ if(A[i]<'0'){ A[i]='9'; A[i-1]--; }else{ break; } } if(A[0]=='0') A.erase(A.begin()); C = B; ans+=dfs(0,0,0,0,1,-1)+mod; memset(memo, 0, sizeof(memo)); if(A.size()){ C = A; ans-=dfs(0,0,0,0,1,-1); } printf("%lld\n",ans%mod); return 0; }