1 #include <cstdio>
2 #include <cstdlib>
3 #include <cstring>
4 #include <string>
5 #include <algorithm>
6
7 using namespace std;
8
9 #define FIO "a"
10 #define REP(i, a, b) for (int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
11 #define mset(a, b) memset(a, b, sizeof(a))
12 const int maxn = 15;
13 typedef long long LL;
14 LL f[maxn][maxn][2][2][2][2][2], l, r;
15 //×?μ?μúi??£?×?????ê?j£?×?oóá???êyê?·?á?D?£?ê?·?óDá?D?èy???àí?£?ê?·?óD4£?ê?·?óD8£??°×oó??-êy?°×oμ?1??μ
16
17 LL cal(LL x)
18 {
19 mset(f, 0);
20 LL ans = 0; int len = 0, digit[15], a, b, c, d, e;
21 while (x) { digit[++len] = x%10, x /= 10; }
22 reverse(digit+1, digit+len+1);
23 f[0][10][0][0][0][0][1] = 1;
24 REP(i, 0, len-1)
25 REP(j, 0, 10)
26 REP(k1, 0, 1)
27 REP(k2, 0, 1)
28 REP(k3, 0, 1)
29 REP(k4, 0, 1)
30 REP(k5, 0, 1)
31 if (f[i][j][k1][k2][k3][k4][k5])
32 REP(k, 0, 9)
33 {
34 if (k5 && k > digit[i+1]) continue ;
35 if (k == j) a = 1; else a = 0;
36 if (!k2) b = (a+k1 == 2); else b = k2;
37 if (!k3) c = (k == 4); else c = k3;
38 if (!k4) d = (k == 8); else d = k4;
39 if (c+d == 2) continue ;
40 if (k5 && k == digit[i+1]) e = 1; else e = 0;
41 f[i+1][k][a][b][c][d][e] += f[i][j][k1][k2][k3][k4][k5];
42 }
43 REP(j, 0, 9)
44 REP(k1, 0, 1)
45 REP(k3, 0, 1)
46 REP(k4, 0, 1)
47 {
48 if (k3 && k4) continue ;
49 ans += f[len][j][k1][1][k3][k4][0];
50 }
51 return ans;
52 }
53
54 int main()
55 {
56 // freopen(FIO ".in", "r", stdin);
57 // freopen(FIO ".out", "w", stdout);
58 scanf("%lld %lld", &l, &r);
59 printf("%lld\n", cal(r+1)-cal(l));
60 return 0;
61 }