#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; stack> st; st.emplace(1 << 30, 1); int ans = 0; for(int i = 0; i < n; i++){ int v; cin >> v; while(v >= st.top().first){ auto [v, t] = st.top(); st.pop(); ans -= (t == 0 ? v : -v); } int at = i & 1; if (at != st.top().second){ st.emplace(v, at); ans += (at == 0 ? v : -v); } cout << ans << '\n'; } }