#include using namespace std; #define int long long const int mod = 1e9 + 7; string a, b; int dp[10101][2][2][2][25]; int dfs(int i=0, bool atight=true, bool btight=true, bool f=false, int sum=0) { int &ret = dp[i][atight][btight][f][sum]; if (ret != -1) return ret; if (i == a.size()){ return (((sum % 8) != 0) && (f || (sum % 3) == 0)); } int ax = a[i] - '0'; int bx = b[i] - '0'; int ar = (atight ? ax : 0); int br = (btight ? bx : 9); ret = 0; for (int j = ar; j <= br; j++){ ret += dfs(i + 1, atight && j == ax, btight && j == bx, f || j == 3, (sum * 10 + j) % 24); } return ret; } signed main() { cin >> a >> b; while (a.size() < b.size()) a = "0" + a; memset(dp, -1, sizeof(dp)); cout << dfs() << endl; }