#include typedef long long ll; typedef std::pair P; typedef std::priority_queue, std::greater

> PQ; int main() { int n; std::cin >> n; std::vector h(n); for (int i = 0; i < n; ++i) { std::cin >> h[i]; } std::stack pq; long long count = 0; for (int i = 0; i < n; ++i) { while (!pq.empty()) { if (pq.top() <= h[i]) { if (pq.size() % 2 == 0) { int temp = pq.top(); pq.pop(); count -= pq.top() - temp; } else { pq.pop(); } } else break; } if ((int)pq.size() % 2 == i % 2) { if (i % 2 == 1) { count += pq.top() - h[i]; } pq.push(h[i]); } if (i % 2 == 1) std::cout << count; else std::cout << count + pq.top(); std::cout << '\n'; } }