class Solution:
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        n=len(prices)
        if n<2:
            return 0
        buy,sell=[0 for i in range(n)],[0 for i in range(n)]
        buy[0],buy[1]=-prices[0],max(-prices[0],-prices[1])
        sell[0],sell[1]=0,max(0,prices[1]-prices[0])
        for i in range(2,n):
            buy[i]=max(buy[i-1],sell[i-2]-prices[i])
            sell[i]=max(buy[i-1]+prices[i],sell[i-1])
        return sell[n-1]
s=Solution()
prices=[1,2,3,0,2]
print(s.maxProfit(prices))

buy[i]: The maximum profit can be made if the first i days end with buy or wait.
"buy, cooldown, cooldown","buy sell cool,buy"
so :buy[i]=max(buy[[i-1]],sell[i-2]-price)
sell[i]: The maximum profit can be made if the first i days end with sell or wait
"buy, sell" or "buy, cooldown, sell" or "buy sell cool"
sell[i]=max(buy[i-1]+price,sell[i-1])