human
Solve in Python:
Given a string S, count the number of distinct, non-empty subsequences of S .
Since the result may be large, return the answer modulo 10^9 + 7.
 
Example 1:
Input: "abc"
Output: 7
Explanation: The 7 distinct subsequences are "a", "b", "c", "ab", "ac", "bc", and "abc".

Example 2:
Input: "aba"
Output: 6
Explanation: The 6 distinct subsequences are "a", "b", "ab", "ba", "aa" and "aba".

Example 3:
Input: "aaa"
Output: 3
Explanation: The 3 distinct subsequences are "a", "aa" and "aaa".


 
 
Note:

S contains only lowercase letters.
1 <= S.length <= 2000

Give me a the Python program you requested?
assistant
#Here is the Python program you requested.

class Solution:
    def distinctSubseqII(self, S: str) -> int:
        MOD = 10 ** 9 + 7
        n = len(S)
        dp = collections.Counter()
        result = 0
        for i in range(n - 1, -1, -1):
            old = result
            result = (2 * old + 1 - dp[S[i]]) % MOD
            dp[S[i]] += result - old
        return result