#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase #define dme cout<<-1<void mineq(T& a,U b){if(a>b){a=b;}} template void maxeq(T& a,U b){if(a>n>>P; llint dans=0,uans=big; llint mae;cin>>mae;n--; //uans <<<< //dans >>>> while(n--){ llint h;cin>>h; llint md=dans,mu=uans; dans=md+max(0LL,h-mae); uans=mu+max(0LL,mae-h); mineq(dans,mu+P); mineq(uans,md+P); //cout<<"de"<