char a[N], b[N]; ll dp[N][N][2]; char num[N]; int tmp[N];
inlinevoidInput(){ scanf("%s%s", a, b); }
inline ll Dfs(int cur, int start, int flag, int limit){ if (cur == -1) return flag; if (!limit && dp[cur][start][flag] != -1) return dp[cur][start][flag]; ll ans = 0; int mx = limit ? (num[cur] - 48) : 9; for (int i = 0; i <= mx; i++) { if (i != 0 && i != 1 && i != 8) continue; int st = (cur == start && i == 0); int newFlag = flag; if (flag) { if (!st && cur < (start + 1) / 2) { newFlag = (tmp[start - cur] == i); } } tmp[cur] = i; ans += Dfs( cur - 1, st ? start - 1 : start, newFlag, limit && (i == mx) ); } if (!limit) dp[cur][start][flag] = ans; return ans; }
inline ll cal(char *s){ int len = strlen(s); for (int i = 0; i < len; i++) { num[i] = s[len - 1 - i]; } num[len] = 0; returnDfs(len - 1, len - 1, 1, 1); }
inlinevoidWork(){ memset(dp, -1, sizeof(dp)); ll ans = cal(b) - cal(a); int len = strlen(a); int flag = 1; for (int i = 0; i < len; i++) { if ((a[i] != '0' && a[i] != '1' && a[i] != '8') || (a[i] != a[len - 1 - i])) { flag = 0; break; } } if (flag) ans++; printf("%lld\n", ans); }