#include #include using namespace std; using namespace atcoder; using ll = long long; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } ll inf_ll = 9223372036854775807; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) using mint = atcoder::modint998244353; using mint1 = atcoder::modint1000000007; using Pa = std::pair; int Yes(bool x){ if(x) cout << "Yes"; else cout << "No"; cout << endl; return 0; } int main(){ ll N; cin >> N; deque A; deque B; vector ans(N); A.push_front({0, 2e9}); B.push_front({0}); rep(i, N){ ll H; cin >> H; while(A.front().second <= H){ A.pop_front(); B.pop_front(); } auto [a, b] = A.front(); if(a == 0){ if(i % 2 == 0){ A.push_front({1, H}); B.push_front(B.front()); } } else{ if(i % 2 == 0){ chmax(H, b); } else{ A.push_front({0, H}); B.push_front({B.front() + b - H}); } } if(i % 2 == 1){ ans[i] = B.front(); } else{ ans[i] = B.front() + H; } } rep(i, N){ cout << ans[i] << endl; } }