Simple Solution with reasoning || c++ || java
For the beauty value of the ith element to be 2, it should be greater than all the elements on its left and smaller than all the elements on its right.\nSo, it 
For the beauty value of the ith element to be 2, it should be greater than all the elements on its left and smaller than all the elements on its right.\nSo, it should be greater than the maximum of all elements on the left and smaller than minimum of all elements on the right.\n    \nFor the beauty value of the ith element to be 1, it should firstly not satisfy the above statement and secondly the ith element should be greater than the (i - 1)th element and lesser than (i + 1)th element\n\nC++:\n```\nint sumOfBeauties(vector<int>& nums) {\n    int n = nums.size();\n    vector<int> minOnRight(n, 0);\n    minOnRight[n - 1] = nums[n - 1];\n    \n    // loop for maintaing values of minimum on the right\n    for(int i = n - 2; i >= 2; i--){\n        //minimum is either the number itself or the minimum that is on right of this element we are traversing\n        minOnRight[i] = min(minOnRight[i + 1], nums[i]);           \n    }\n        \n    int maxOnLeft = nums[0];\n    int ans = 0;\n    for(int i = 1; i < n - 1; i++){\n        if(nums[i] > maxOnLeft && nums[i] < minOnRight[i + 1]) ans += 2;\n        else if(nums[i] > nums[i - 1] && nums[i] < nums[i + 1]) ans += 1;\n        maxOnLeft = max(nums[i], maxOnLeft);\n    }\n        \n    return ans;\n}\n```\n\nJava: \n```\npublic int sumOfBeauties(int[] nums) {\n    int n = nums.length;\n    int minOnRight[] = new int[n];\n    minOnRight[n - 1] = nums[n - 1];\n\t\n\t// loop for maintaing values of minimum on the right\n    for(int i = n - 2; i >= 2; i--){\n\t    //minimum is either the number itself or the minimum that is on right of this element we are traversing\n        minOnRight[i] = Math.min(minOnRight[i + 1], nums[i]);           \n    }\n    \n    int maxOnLeft = nums[0];\n    int ans = 0;\n    for(int i = 1; i < n - 1; i++){\n        if(nums[i] > maxOnLeft && nums[i] < minOnRight[i + 1]) ans += 2;\n        else if(nums[i] > nums[i - 1] && nums[i] < nums[i + 1]) ans += 1;\n        maxOnLeft = Math.max(nums[i], maxOnLeft);\n    }\n      \n    return ans; \n}\n```
['C', 'Java']