Simple Solution
Code\n\nclass Solution:\n    def sumImbalanceNumbers(self, nums: List[int]) -> int:\n        res = 0\n        for i in range(len(nums)):\n            seen = set
# Code\n```\nclass Solution:\n    def sumImbalanceNumbers(self, nums: List[int]) -> int:\n        res = 0\n        for i in range(len(nums)):\n            seen = set()\n            t = 0\n            for j in range(i, len(nums)):\n                if nums[j] not in seen:\n                    if nums[j]-1 in seen: t -= 1\n                    seen.add(nums[j])\n                    if nums[j]+1 not in seen: t += 1\n                res += t-1\n        return res\n```
['Python3']