input: Write a function to count the number of common substrings between two given strings. If the given input strings are "abcd" and "bae", then the function should return the count of all common substrings.
  
  def num_common_substrings(s1, s2):
      count = 0
      for i in range(len(s1)):
          for j in range(len(s2)):
              if s1[i] == s2[j]:
                  count += 1
      return count
  
  assert num_common_substrings("abcd", "bae") == 2
  assert num_common_substrings("a", "a") == 1
  assert num_common_substrings("", "") == 0
  assert num_common_substrings("abcdef", "fedcba") == 1
  assert num_common_substrings("aaa", "aaa") == 3
output: def num_common_substrings(s1, s2):
      count = 0
      for i in range(len(s1)):
          for j in range(len(s2)):
              k = 0
              while i + k < len(s1) and j + k < len(s2) and s1[i + k] == s2[j + k]:
                  count += 1
                  k += 1
      return count