HALA MADRID
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[505][55][3][3];\n    int mod = (int)(1e9+7);\n    vector<int> computekmp(string& str){\n        int n = str.length();\n        vector<int> arr(n);\n        int i = 1, len = 0;\n        while(i < n){\n            if(str[len] == str[i]){\n                len++;\n                arr[i] = len;\n                i++;\n            }\n            else{\n                if(len == 0){\n                    i++;\n                }\n                else{\n                    len = arr[len-1];\n                }\n            }\n        }\n        return arr;\n    }\n    int fun(int i, int j, bool flag1 , bool flag2 , string& s1, string& s2, string& evil, int n, vector<int>& kmp){\n        if(j == evil.length()) return 0;\n        if(i == n) return 1;\n        if(dp[i][j][flag1][flag2] != -1) return dp[i][j][flag1][flag2];\n        char from = flag1 ? s1[i] : \'a\', to = flag2 ? s2[i] : \'z\';\n        int ans = 0;\n        for(auto ch = from ; ch <= to ; ch++){\n            if(ch == evil[j]){\n                ans += fun(i +1, j+1, flag1 and (ch == from), flag2 and (ch == to), s1,s2,evil,n, kmp);\n                ans %= mod;\n            }\n            else{\n                int x = j;\n                while(x > 0 and evil[x] != ch) x = kmp[x-1];\n                if(evil[x] == ch) x++;\n                ans += fun(i+1,x, flag1 and (ch == from), flag2 and (ch == to), s1,s2,evil,n, kmp );\n                ans %= mod;\n            }\n        }\n        return dp[i][j][flag1][flag2] =  ans;\n    }\n    int findGoodStrings(int n, string s1, string s2, string evil) {\n        vector<int> kmp = computekmp(evil);\n        memset(dp, -1, sizeof dp);\n        return fun(0, 0, 1,1,s1,s2, evil,n, kmp);\n    }\n};\n```
['C++']