input: from typing import List
  from collections import defaultdict
  
  def count_matching_prefix_suffix_pairs(words: List[str]) -> int:
      """
      You are provided with a 0-indexed list of strings called words.
  
      Define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2:
  
      isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, otherwise it returns false.
      For instance, isPrefixAndSuffix("aba", "ababa") returns true as "aba" is a prefix and also a suffix of "ababa", yet isPrefixAndSuffix("abc", "abcd") returns false.
  
      Return an integer representing the number of pairs of indices (i, j) such that i < j, and isPrefixAndSuffix(words[i], words[j]) holds true.
  
      Examples:
      >>> words = ["a","aba","ababa","aa"]
      4
      >>> words = ["pa","papa","ma","mama"]
      2
      >>> words = ["abab","ab"]
      0
  
      Constraints:
      1 <= words.size() <= 10^5
      1 <= words[i].length() <= 10^5
      words[i] consists exclusively of lowercase English letters.
      The total length of all words[i] does not exceed 5 * 10^5.
      """
output:     
      def isPrefixAndSuffix(str1: str, str2: str) -> bool:
          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 isPrefixAndSuffix(words[i], words[j]):
                  count += 1
      
      return count
  