```
class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
n=len(prices)
if n<=1:
return 0
ws,wos=[0 for i in range(n)],[0 for i in range(n)]
buyit=sellit=0
for i in range(n):
if i<=2:
buyit=-prices[i]
else:
buyit=wos[i-2]-prices[i]
if i==0:
ws[i]=buyit
else:
ws[i]= max(ws[i-1],buyit)
sellit=ws[i-1]+prices[i]
wos[i]=max(wos[i-1],sellit)
return wos[n-1]
```