#include using namespace std; int main(){ int n,r = 0; cin >> n; stack> s({make_pair(1,1e9+1)}); for (int i(0),x;i < n;++i){ cin >> x; while(s.top().second<=x) r += (s.top().first?1:-1)*s.top().second,s.pop(); if (s.top().first!=i%2) s.emplace(i%2,x),r += (i%2?-1:1)*x; cout << r << endl; } }