Java Solution
```java\nclass Solution {\n    public int sumOfBeauties(int[] nums) {\n        int n=nums.length, beauty=0;\n        int[] leftMax=new int[n];\n        leftMax[
```java\nclass Solution {\n    public int sumOfBeauties(int[] nums) {\n        int n=nums.length, beauty=0;\n        int[] leftMax=new int[n];\n        leftMax[0]=nums[0];\n        for(int i=1;i<n;i++) {\n            leftMax[i]=Math.max(leftMax[i-1], nums[i]);\n        }\n        int[] rightMin=new int[n];\n        rightMin[n-1]=nums[n-1];\n        for(int i=n-2;i>=0;i--) {\n            rightMin[i]=Math.min(rightMin[i+1], nums[i]);\n        }\n        for(int i=1;i<n-1;i++) {\n            if(leftMax[i-1]<nums[i] && nums[i]<rightMin[i+1]) {\n                beauty+=2;\n            }\n            else if(nums[i-1]<nums[i] && nums[i]<nums[i+1]) {\n                beauty+=1;\n            }\n        }\n        return beauty;\n    }\n}
['Array', 'Java']