class Solution {
public:
bool check(string& s1, string& s2) {
int n = s1.size(), m = s2.size();
return s2.substr(0, n) == s1 && s2.substr(m - n) == s1;
}
int countPrefixSuffixPairs(vector<string>& words) {
int cnt = 0;
int n = words.size();
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
if (check(words[i], words[j]))
cnt++;
return cnt;
}
};