#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) template bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; // template atcoder lazy segtree struct S{ ll sm1=0; ll sm2=0; }; S op(S a, S b){ a.sm1+=b.sm1; a.sm2+=b.sm2; return a; } S e(){ return S{}; } using F = ll; S mapping(F f, S x){ if(f==1){ x.sm1+=x.sm2; x.sm2=0; }else if(f==2){ x.sm2+=x.sm1; x.sm1=0; } return x; } F comp(F f, F g){ if(f==0) return g; return f; } F id(){ return 0; } using segtree = atcoder::lazy_segtree; int main(){ int n; cin>>n; vector h(n); rep(i,0,n) cin>>h[i]; auto ch=h; ch.push_back(0); sort(ch.begin(),ch.end()); ch.erase(unique(ch.begin(),ch.end()),ch.end()); int m=ch.size(); auto get_ith = [&](int x){ return lower_bound(ch.begin(),ch.end(),x)-ch.begin(); }; segtree seg(m-1); rep(i,0,m-1) seg.set(i,S{ch[i+1]-ch[i],0}); rep(i,0,n){ int j=get_ith(h[i]); if(i&1){ seg.apply(0,j,1); }else{ seg.apply(0,j,2); } auto x=seg.all_prod(); cout<