Solution
Code\n\nfrom sortedcontainers import SortedList\nclass Solution:\n    def secondGreaterElement(self, nums: List[int]) -> List[int]:\n        ns = [(nums[i], i) 
# Code\n```\nfrom sortedcontainers import SortedList\nclass Solution:\n    def secondGreaterElement(self, nums: List[int]) -> List[int]:\n        ns = [(nums[i], i) for i in range(len(nums))]\n        ns.sort(key = lambda x:(-x[0], x[1]))\n        res = [0 for i in range(len(nums))]\n        sl = SortedList()\n        for num, i in ns:\n            idx = sl.bisect_left((i, num))\n            if len(sl) - idx >= 2:\n                res[i] = sl[idx+1][1]\n            else: res[i] = -1\n            sl.add((i, num))\n        return res\n```
['Python3']