------
## 最终结论
```python
def distinct_subseq_count(S):
    MOD = 10**9 + 7
    result = 0
    last_occurrence = {}
    
    # Initialize an array to store the count of distinct subsequences ending with each character
    dp = [0] * (len(S) + 1)
    dp[0] = 1  # Base case: empty subsequence
    
    for i in range(1, len(S) + 1):
        current_char = S[i - 1]
        dp[i] = (2 * dp[i - 1]) % MOD  # Each subsequence can either include or exclude the current character
        
        if current_char in last_occurrence:
            j = last_occurrence[current_char]
            dp[i] = (dp[i] - dp[j - 1]) % MOD  # Subtract subsequences counted before the last occurrence
        
        last_occurrence[current_char] = i  # Update the last occurrence of the current character
    
    result = (dp[len(S)] - 1) % MOD  # Subtract the empty subsequence
    return result
```