Complex Java Solution -- Number DP && KMP
\nclass Solution {\n    int MOD = (int)1e9+7;\n\n    int dp[][][] = new int[510][51][2];\n    private int[] getNext(String t) {\n        int n = t.length();\n  
```\nclass Solution {\n    int MOD = (int)1e9+7;\n\n    int dp[][][] = new int[510][51][2];\n    private int[] getNext(String t) {\n        int n = t.length();\n        int[] f = new int[n];\n        f[0] = 0;\n        int k = 0;\n        for(int i = 1; i < n; i++) {\n            for(; k > 0 && t.charAt(i) != t.charAt(k); k = f[k - 1]);\n            if(t.charAt(i) == t.charAt(k)) k++;\n            f[i] = k;\n        }\n        return f;\n    }\n\n    private void init() {\n        for(int i = 0; i < 510; i++) {\n            for(int j = 0; j < 51; j++) {\n                for(int k = 0; k < 2; k++) {\n                    dp[i][j][k] = -1;\n                }\n            }\n        }\n    }\n    \n    private int solve(String s, String e, int[] f, int idx, int st, int eq) {\n        if(st == e.length()) return 0;\n        if(idx == s.length()) return 1;\n        if(dp[idx][st][eq] != -1) return dp[idx][st][eq];\n        char end = eq == 1 ? s.charAt(idx) : \'z\';\n        int res = 0;\n        for(char i = \'a\'; i <= end; i++) {\n            int nextE = (eq == 1 && i == end) ? 1 : 0;\n            int nextS = st;\n            for(; nextS > 0 && i != e.charAt(nextS); nextS = f[nextS - 1]);\n            if(i == e.charAt(nextS)) nextS++;\n            res = (res + solve(s, e, f, idx + 1, nextS, nextE)) % MOD;\n        }\n        return dp[idx][st][eq] = res;\n    }\n    \n    \n    public int findGoodStrings(int n, String s1, String s2, String evil) {\n        int[] f = getNext(evil);\n        init();\n        int A = solve(s1, evil, f, 0, 0, 1);\n        init();\n        int B = solve(s2, evil, f, 0, 0, 1);\n        int res = (B + MOD - A) % MOD;\n        if(!s1.contains(evil)) res = (res + 1) % MOD;\n        return res;\n    }\n\n\n}\n```
[]