class Solution:
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        k,n=2,len(prices)
        if n<=1:
            return 0
        dp=[[0 for i in range(n)]for kk in range(k)]
        for kk in range(k):
            temp=-prices[0]
            for i in range(n):
                temp=max(temp,dp[kk-1][i]-prices[i])
                dp[kk][i]=max(dp[kk][i-1],prices[i]+temp)
        return dp[k-1][n-1]

s=Solution()
nums=[2,1,2]
print(s.largestRectangleArea(nums))