Python Clean MinStack
Similiar idea with 84. Largest Rectangle in Histogram\nFor each element x, find the "largest" window whose minimum is this x.  The "largeness" of this window is
Similiar idea with [84. Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/)\nFor each element `x`, find the "largest" window whose minimum is this `x`.  The "largeness" of this window is the sum of all elements inside the window.\nSince all element are positive number, the "largest" window is actually the "widest" windows.\nWe can maintain a min stack to get a window\'s left and right border in constant time. Each time we pop an element `x` from the min stack, we know the right border is the current element that force `x` being popped out and the left border is the element ahead of `x` in min stack. We can also maintain a presum array to get window\'s largeness in constant time.\n\n```\ndef maxSumMinProduct(A):\n\tP, S = [0], [-1]\n\tans, M = 0, 10**9 + 7\n\tA.append(0)\n\tfor i, x in enumerate(A):\n\t\twhile len(S) > 1 and A[S[-1]] >= x:\n\t\t\tans = max(ans, A[S.pop()] * (P[-1]-P[S[-1]+1]))\n\t\tP.append(P[-1] + x)\n\t\tS.append(i)\n\treturn ans % M\n```
['Python']