DP
#include<bits/stdc++.h>
using namespace std;
int maxProfit(int* prices, int pricesSize){
if(pricesSize <= 1) return 0;
int i = 0,* _prices,max;
_prices = (int *)malloc(sizeof(int) * pricesSize);
_prices[0] = 0;
if(prices[1] - prices[0] > 0) max = _prices[1];else max = 0;
for(i = 1;i<pricesSize;i++){
_prices[i] = prices[i] - prices[i-1];
if(_prices[i - 1] > 0)_prices[i] += _prices[i - 1];
if(_prices[i] > max)max = _prices[i];
}
free(_prices);
return max;
}
int main(void){
int pricesSize;
cin >> pricesSize;
int prices[pricesSize];
for(int i = 0;i < pricesSize;i ++)
cin >> prices[i];
cout << maxProfit(prices,pricesSize);
}