def sum_of_good_subsequences(nums: List[int]) -> int:
mod = 10 ** 9 + 7
total = Counter()
count = Counter()
for num in nums:
ending_at = count[num - 1] + count[num + 1] + 1
total[num] += total[num - 1] + total[num + 1] + num * ending_at
count[num] += ending_at
return sum(total.values()) % mod