#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 34; int f[N][10];//第i位取j的windy数 max ll l, r; void init() { for (int i = 0; i <= 9; i++) f[1][i] = 1; for (int i = 2; i <= N; i++) { for (int j = 0; j <= 9; j++) { for (int k = j - 2; k >= 0; k--) f[i][j] += f[i - 1][k]; for (int k = j + 2; k <= 9; k++) f[i][j] += f[i - 1][k]; } } } ll cal(ll n) { if (!n) return 0; vector<ll>num; while (n) num.push_back(n % 10), n /= 10; ll res = 0; ll last = -1; for (int i = num.size() - 1; i >= 0; i--) { int x = num[i]; for(int j = (i == num.size() - 1) ? 1 : 0;j < x;++j){ //只要与上一个数的差值大于2,就是合法的windy数 if(abs(j - last) >= 2)res += f[i + 1][j]; } if ((x <= last + 1 && x >= last - 1)) break; last = x; if (!i) res++; } //包含前导零情况 for(int i = 1;i <= num.size() - 1;++i){ for(int j = 1;j <= 9;++j){ res += f[i][j]; } } return res; } int main() { init(); // for (int i = 1; i <= 3; i++) { // for (int j = 0; j <= 9; j++) { // printf("f%d%d=%d ", i, j, f[i][j]); // } // cout << endl; // } cin>>l>>r; cout << cal(r) - cal(l - 1) << endl; return 0; } /* 25 50 */