Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Consider counting how many times each element occurs in all possible good subsequences. This can help you derive the final answer more easily.
Use dynamic programming to track both the count and the sum of subsequences where the last element is <code>nums[i]</code>.