Python Fast and Readable
\nclass Solution:\n    def sumOfBeauties(self, nums: List[int]) -> int:\n        pre, suf = [0], [math.inf]\n        for n in nums:\n            pre.append(max(
```\nclass Solution:\n    def sumOfBeauties(self, nums: List[int]) -> int:\n        pre, suf = [0], [math.inf]\n        for n in nums:\n            pre.append(max(pre[-1], n))\n        for n in nums[::-1]:\n            suf.append(min(suf[-1], n))\n        \n        suf.reverse()\n        ans = 0\n        for i in range(1, len(nums)-1):\n            if suf[i+1] > nums[i] > pre[i]:\n                ans += 2\n            elif nums[i-1] < nums[i] < nums[i+1]:\n                ans += 1\n        return ans\n```
[]