human
What is a the Python program you requested given the following:
Solve in Python:
Given a string S and a string T, count the number of distinct subsequences of S which equals T.

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).

Example 1:

Input: S = "rabbbit", T = "rabbit"
Output: 3
Explanation:

As shown below, there are 3 ways you can generate "rabbit" from S.
(The caret symbol ^ means the chosen letters)

rabbbit
^^^^ ^^
rabbbit
^^ ^^^^
rabbbit
^^^ ^^^

Example 2:

Input: S = "babgbag", T = "bag"
Output: 5
Explanation:

As shown below, there are 5 ways you can generate "bag" from S.
(The caret symbol ^ means the chosen letters)

babgbag
^^ ^
babgbag
^^    ^
babgbag
^    ^^
babgbag
  ^  ^^
babgbag
    ^^^
assistant
#Here is the Python program you requested.

class Solution:
     def __init__(self):
         self.dp = {}
         self.s = ""
         self.t = ""
         self.letter2Indices = {}
     
     def numDistinct(self, s, t):
         """
         :type s: str
         :type t: str
         :rtype: int
         """
         if len(s) < len(t):
             return 0
         if not t:
             return 1
         
         self.s = s.lower()
         self.t = t.lower()
         length = len(s)
         for i in range(len(t)):
             self.dp[i] = [-1] * length
         for i in range(length):
             letter = self.s[i]
             if letter in self.letter2Indices:
                 self.letter2Indices[letter].append(i)
             else:
                 self.letter2Indices[letter] = list([i])
             
         return self.numSubseq(0, 0)
     
     def numSubseq(self, startS, startT):
         if startT >= len(self.t):
             return 1
         if startS >= len(self.s):
             return 0
         
         if self.dp[startT][startS] >= 0:
             return self.dp[startT][startS]
         
         letter = self.t[startT]
         count = 0
         firstMatch = -1
         if letter in self.letter2Indices:
             for i in self.letter2Indices[letter]:
                 if i >= startS:
                     count += self.numSubseq(i+1, startT+1)
                     if firstMatch < 0:
                         # We can directly fill dp[startT][startS:firstMatch-1] with the same number
                         firstMatch = i
                     
         self.dp[startT][startS] = count
         for i in range(startS + 1, firstMatch):
             self.dp[startT][i] = count
         return count