input: from typing import List
  from collections import defaultdict
  
  def count_matching_prefix_suffix_pairs(words: List[str]) -> int:
      """
      You are given a 0-indexed list of strings called words.
  
      Let's define a boolean function hasPrefixAndSuffix that takes two strings, str1 and str2:
  
      hasPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.
      For example, hasPrefixAndSuffix("aba", "ababa") is true because "aba" is a prefix of "ababa" and also a suffix, but hasPrefixAndSuffix("abc", "abcd") is false.
  
      Return the count of index pairs (i, j) such that i < j, and hasPrefixAndSuffix(words[i], words[j]) is true.
  
      Examples:
      >>> words = ["a","aba","ababa","aa"]
      4
      >>> words = ["pa","papa","ma","mama"]
      2
      >>> words = ["abab","ab"]
      0
  
      Constraints:
      1 <= len(words) <= 10^5
      1 <= len(words[i]) <= 10^5
      words[i] only contains lowercase English letters.
      The sum of the lengths of all words[i] does not exceed 5 * 10^5.
      """
output:     
      def hasPrefixAndSuffix(str1, str2):
          return str2.startswith(str1) and str2.endswith(str1)
  
      count = 0
      n = len(words)
      for i in range(n):
          for j in range(i + 1, n):
              if hasPrefixAndSuffix(words[i], words[j]):
                  count += 1
      return count
  