# import sys
# for line in sys.stdin:
# a = line.split()
# print(int(a[0]) + int(a[1]))
import sys
def solver():
n= int(input())
prices=list(map(int,input().split()))
dp0 =0 # 不持有
dp1= -prices[0] # 持有
for i in range(1,len(prices)):
new_dp0=max(dp0,dp1+prices[i])
new_dp1=max(dp0-prices[i],dp1)
dp0=new_dp0
dp1=new_dp1
print(dp0) # 最后不持有
solver()

京公网安备 11010502036488号