C++  || O(N)
\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n        int n
```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n        int n=nums.size();\n        int ans=0;\n        vector <int> greater(n);\n        vector <int> smaller(n);\n        smaller[n-1]=nums[n-1];\n        greater[0]=nums[0];\n        for (int i=1;i<n;i++){\n            greater[i]=max(greater[i-1],nums[i]);\n            int j=n-i-1;\n            smaller[j]=min(smaller[j+1],nums[j]);\n            \n        }\n        for (int i=1;i<n-1;i++){\n            if (greater[i-1]<nums[i] && nums[i]<smaller[i+1]) ans+=2;\n            else if (nums[i-1]<nums[i] && nums[i]<nums[i+1]) ans+=1;\n        }\n        return ans;\n    }\n};\n```
['C']