C++ Fast solution with explaination
\nclass Solution {\npublic:\n    int countSubstrings(string s, string t) {\n        int n = s.size();\n        int m = t.size();\n        // Select an element a
```\nclass Solution {\npublic:\n    int countSubstrings(string s, string t) {\n        int n = s.size();\n        int m = t.size();\n        // Select an element and check whether the element belongs to an substring of which all other elements are same\n        int ans = 0;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(s[i]!=t[j]){\n                    int countback=0,countfront=0,index_back=i-1,index_front=i+1,indexj_back=j-1,indexj_front=j+1;\n                    while(index_back>=0 and indexj_back>=0 and s[index_back]==t[indexj_back]){\n                        index_back--;\n                        indexj_back--;\n                        countback++;\n                    }\n                    while(index_front<n and indexj_front<m and s[index_front]==t[indexj_front]){\n                        index_front++;\n                        indexj_front++;\n                        countfront++;\n                    }\n                    // We will add all the substring which contain that element + all the substrings which ends with that element + all the substrings which start from that element + that element.\n                    ans+=(countback*countfront + countback + countfront + 1);\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
[]