#include #include using namespace std; using i64 = long long; template class Range{private:struct I{T x;T operator*(){return x;}bool operator!=(I& lhs){return x; // 数字の中の '12' という文字列を数える i64 f(i64 x) { string s = to_string(x); int n = s.size(); vector>>> dp(n+1, vector>>(2, vector>(2, vector(n+1, 0)))); // dp[n+1][2][2][n+1] dp[0][0][0][0] = 1; for(auto&& i : range(n)) { for(auto&& j : range(2)) { for(auto&& is1 : range(2)) { for(auto&& cnt12 : range(n)) { if(!dp[i][j][is1][cnt12]) { continue; } for(auto&& d : range(j?10:s[i]-'0'+1)) { int flag = j || d < s[i] - '0', nis1 = d==1, ncnt12 = cnt12 + (is1 && d==2); dp[i+1][flag][nis1][ncnt12] += dp[i][j][is1][cnt12]; } } } } } i64 res = 0; for(auto&& j : range(2)) { for(auto&& is1 : range(2)) { for(auto&& cnt12 : range(n+1)) { res += dp[n][j][is1][cnt12] * cnt12; } } } return res; } // 2で始まって2で終わる整数を数える i64 g(i64 x) { string s = to_string(x); int n = s.size(); vector>>>> dp(n+1, vector>>>(2, vector>>(2, vector>(2, vector(2, 0))))); // dp[n+1][2][2][2][2] dp[0][0][0][0][0] = 1; for(auto&& i : range(n)) { for(auto&& j : range(2)) { for(auto&& nuke0 : range(2)) { for(auto&& start2 : range(2)) { for(auto&& end2 : range(2)) { if(!dp[i][j][nuke0][start2][end2]) { continue; } for(auto&& d : range(j?10:s[i]-'0'+1)) { int flag = j || d < s[i] - '0', n_nuke0 = nuke0 || d > 0, nstart2 = start2 || (!nuke0 && d==2), nend2 = d == 2; dp[i+1][flag][n_nuke0][nstart2][nend2] += dp[i][j][nuke0][start2][end2]; } } } } } } i64 res = 0; for(auto&& j : range(2)) { for(auto&& nuke0 : range(2)) { res += dp[n][j][nuke0][1][1]; } } return res; } int main(void) { i64 a, b; scanf("%lld%lld", &a, &b); i64 x = f(b) - f(a-1), y = g(b) - g(a); i64 res = x + y; printf("%lld\n", res); return 0; }