Python (Simple Maths)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def findMaximumElegance(self, items, k):\n        items.sort(reverse = True)\n\n        res, seen, max_val, running_val = [], set(), 0, 0\n\n        for p,c in items:\n            running_val += p\n\n            if c not in seen:\n                seen.add(c)\n            else:\n                res.append(p)\n\n            while res and len(res) + len(seen) > k:\n                running_val -= res.pop()\n\n            if len(res) + len(seen) == k:\n                max_val = max(max_val,running_val + len(seen)**2)\n\n        return max_val\n\n\n\n\n\n\n```
['Python3']