python dp + kmp
\nclass Solution:\n    def findGoodStrings(self, N, *args) :\n        from functools import lru_cache\n        s1,s2, evil = [list(map(ord, i)) for i in args]\n
```\nclass Solution:\n    def findGoodStrings(self, N, *args) :\n        from functools import lru_cache\n        s1,s2, evil = [list(map(ord, i)) for i in args]\n        mod = 10 ** 9 + 7\n        \n        def kmp(l, c):\n            while l and evil[l] != c: l = f[l-1]\n            if evil[l] == c : l += 1\n            return l\n        \n        f = [0] * len(evil) \n        for i in range(1, len(evil)):\n            f[i] = kmp(f[i-1], evil[i])\n        \n        @lru_cache(None)\n        def dp(i = 0, lcp = 0 , f1 = False, f2 = False):\n            if lcp == len(evil): return 0 \n            if i == N : return 1\n            ans = 0\n            for char in range(f1 and 97 or s1[i], f2 and 123 or s2[i]+1):\n                ans += dp(i+1, kmp(lcp, char ), f1 or char > s1[i], f2 or char < s2[i])\n                ans %= mod \n            return ans \n\n        return dp()\n```\n                    \n       \n       \n        \n                    \n                    \n                        \n
[]