C++ , maps , priority queue .
\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        priority_queue<int, vector<int>, \n                       greater<int> > ran;\n
```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        priority_queue<int, vector<int>, \n                       greater<int> > ran;\n        map<int,int> mp;\n        for(int i=0;i!=nums.size();i++)  {int a=nums[i];  if(i!=0)  {ran.push(a);if(mp.find(a)==mp.end())  mp.insert(pair<int,int>(a,1));else{mp[a]++;}} else{ if(mp.find(a)==mp.end())  mp.insert(pair<int,int>(a,0));}}\n      \n        int mx=nums[0];int min=0;int sum=0;\n        for(int i=1;i!=nums.size()-1;i++){\n            mp[nums[i]]--;\n            while(mp[ran.top()]==0)    ran.pop();\n             if(nums[i]>mx&&nums[i]<ran.top()){\n                sum+=2;\n                mx=max(mx,nums[i]);\n                \n            }\n            else{\n                \n           if(nums[i]>mx)   mx=nums[i];\n             if(nums[i]>nums[i-1]&&nums[i]<nums[i+1])   sum++;\n        }\n        }\n        return sum;\n    }\n};\n```
[]