#include #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) template inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using namespace std; typedef long long ll; ll dp[20][2][2][20][2]; // less, 0-1, num 12, leading zero pair f(string S, bool less, bool onetwo) { if (S.length() <= 1) { int n = S[0] - '0'; if (n <= 1) { return {0, 0}; } else { return {0, 1}; } } memset(dp, 0, sizeof(dp)); int n = S.length(); dp[0][0][0][0][0] = 1; rep (i, n) rep (j, 2) { rep (k, 2) rep (l, 19) rep (m, 2) { int lim = j ? 9 : S[i] - '0'; rep (x, lim + 1) { if (onetwo && !m && x > 0 && x != 2) continue; if (onetwo && i == n - 1 && x != 1) continue; if (k == 0 && x == 1) { dp[i + 1][j || x < lim][1][l][m || x > 0] += dp[i][j][k][l][m]; } else if (k == 1 && x == 1) { dp[i + 1][j || x < lim][1][l][m || x > 0] += dp[i][j][k][l][m]; } else if (k == 1 && x == 2) { dp[i + 1][j || x < lim][0][l + 1][m || x > 0] += dp[i][j][k][l][m]; } else { dp[i + 1][j || x < lim][0][l][m || x > 0] += dp[i][j][k][l][m]; } } } } ll res1 = 0, res2 = 0; rep (j, 2) rep (k, 2) rep (l, 20) rep (m, 2) { if (j == 0 && less) continue; res1 += dp[n][j][k][l][m] * l; res2 += dp[n][j][k][l][m]; } return {res1, res2 + 1}; } int main() { string A, B; cin >> A >> B; ll ans = f(B, false, false).first - f(A, true, false).first; ans += f(B, true, true).second - f(A, true, true).second; cout << ans << endl; return 0; }