#include <bits/stdc++.h>
using namespace std;

#define ll long long

void solve() {
    int n;
    if (!(cin >> n)) return;

    multiset<ll> ms;
    // Iterators to mark boundaries
    // L points to the first element of Muhammad's share
    // R points to the first element of Shehab's share
    auto L = ms.end();
    auto R = ms.end();

    ll ahmed_sum = 0, muhammad_sum = 0, shehab_sum = 0;

    for (int i = 1; i <= n; i++) {
        ll val;
        cin >> val;

        // Step 1: Insert the new element and initially assign its sum
        auto it = ms.insert(val);

        if (ms.size() == 1) {
            L = it;
            R = ms.end();
            muhammad_sum += val;
            cout << ahmed_sum << " " << muhammad_sum << " " << shehab_sum << "\n";
            continue;
        }

        // Figure out where it was inserted relative to our pointers
        if (L != ms.end() && val < *L) {
            ahmed_sum += val;
        } else if (R != ms.end() && val >= *R) {
            shehab_sum += val;
        } else {
            muhammad_sum += val;
        }

        // Target sizes for this day
        ll M = i;
        ll target_ahmed = M / 2;
        ll target_shehab = (M - target_ahmed) / 2;
        ll target_muhammad = M - target_ahmed - target_shehab;

        // Current sizes can be implicitly tracked by moving L and R until targets match
        // We look at how many elements should be before L (Ahmed's count)
        // Since we only added ONE element, the pointers will shift by at most 1 position.

        // Fix Ahmed's boundary (L)
        // We can use a distance trick or just trace the math. 
        // Instead of heavy distance calculations, we track counts explicitly:
        static ll curr_ahmed_cnt = 0;
        static ll curr_shehab_cnt = 0;

        if (val < *L) curr_ahmed_cnt++;
        else if (R != ms.end() && val >= *R) curr_shehab_cnt++;

        // Adjust L pointer
        while (curr_ahmed_cnt < target_ahmed) {
            // L moves right, element at L goes from Muhammad to Ahmed
            ahmed_sum += *L;
            muhammad_sum -= *L;
            L++;
            curr_ahmed_cnt++;
        }
        while (curr_ahmed_cnt > target_ahmed) {
            // L moves left, element before L goes from Ahmed to Muhammad
            L--;
            ahmed_sum -= *L;
            muhammad_sum += *L;
            curr_ahmed_cnt--;
        }

        // Adjust R pointer
        while (curr_shehab_cnt < target_shehab) {
            // R moves left, element before R goes from Muhammad to Shehab
            R--;
            shehab_sum += *R;
            muhammad_sum -= *R;
            curr_shehab_cnt++;
        }
        while (curr_shehab_cnt > target_shehab) {
            // R moves right, element at R goes from Shehab to Muhammad
            muhammad_sum += *R;
            shehab_sum -= *R;
            R++;
            curr_shehab_cnt--;
        }

        cout << ahmed_sum << " " << muhammad_sum << " " << shehab_sum << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}