class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        if len(prices)==0:
            return 0
        buy=[0]*len(prices)
        sell=[0]*len(prices)
        buy[0]=-prices[0]
        for i in range(1,len(prices)):
            price=prices[i]
            buy[i]=max(buy[i-1],sell[i-2]-price)
            sell[i]=max(sell[i-1],buy[i-1]+price)
        return sell[-1]