class Solution:
def maxProfit(self, prices: List[int], fee: int) -> int:
n = len(prices)
if n < 2:
return 0
hold, bear = -prices[0] - fee, 0
for i in range(1, n):
old_hold = hold
hold = max(old_hold, bear - prices[i] - fee)
bear = max(bear, old_hold + prices[i])
return bear