#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; string s; P dp[20][11][2]; bool used[20][11][2]; P calc(int n, int ba, int f) { if (n == 0) { if (f) return P(0, 0); return P(0, 1); } if (used[n][ba][f]) return dp[n][ba][f]; used[n][ba][f] = true; ll res = 0, co = 0; if (f == 0) { for (int i = 0; i <= 9; i++) { auto p = calc(n-1, i, 0); res += p.first; co += p.second; if (ba == 1 && i == 2) { res += p.second; } } } else { for (int i = 0; i <= s[n-1]-'0'; i++) { auto p = calc(n-1, i, i == s[n-1]-'0'); res += p.first; co += p.second; if (ba == 1 && i == 2) { res += p.second; } } } return dp[n][ba][f] = P(res, co); } ll dp2[20][11][2][2]; bool used2[20][11][2][2]; ll calc2(int n, int ba, int f, int ok) { if (n == 0) { if (f) return 0; if (ba == 2) return 1; return 0; } if (used2[n][ba][f][ok]) return dp2[n][ba][f][ok]; used2[n][ba][f][ok] = true; ll res = 0; if (f == 0) { for (int i = 0; i <= 9; i++) { if (!ok && (i != 0 && i != 2)) continue; res += calc2(n-1, i, 0, ok | (i == 2)); } } else { for (int i = 0; i <= s[n-1]-'0'; i++) { if (!ok && (i != 0 && i != 2)) continue; res += calc2(n-1, i, i == s[n-1]-'0', ok | (i == 2)); } } return dp2[n][ba][f][ok] = res; } //1,2,3,...,n-1 ll solve(ll x) { memset(used, 0, sizeof(used)); memset(used2, 0, sizeof(used2)); s = to_string(x); reverse(s.begin(), s.end()); int n = (int)s.size(); // cout << calc(n, 0, 1).first << " " << calc2(n, 0, 1, 0) << endl; return calc(n, 0, 1).first + calc2(n, 0, 1, 0); } int main() { ll a, b; cin >> a >> b; ll u = solve(b+1) - solve(a); if (to_string(a)[0] == '2' && a % 10 == 2) u--; cout << u << endl; return 0; }