/*
  _      __        __         __        ____                    ___    _                   __
 | | /| / / ___ _ / /_ ____  / /       / __ \  ___  ___        / _ \  (_) ___  ____ ___   / /
 | |/ |/ / / _ `// __// __/ / _ \     / /_/ / / _ \/ -_)      / ___/ / / / -_)/ __// -_) /_/ 
 |__/|__/  \_,_/ \__/ \__/ /_//_/     \____/ /_//_/\__/      /_/    /_/  \__/ \__/ \__/ (_)  
                                                                                             
*/
 
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include "partition.h"
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define allr(v, l, r) v.begin() + l, v.begin() + r;
#define endl "\n"
#define newline cout << endl;
using namespace std;

// constants
const int INF = 1e9;

// functions

// structs

// globals

// notes
/*
 -stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH

continue - skip the rest in the loop
*/

vector <int> solve(vector<int> A)
{
    int n = (int)A.size();
    ll S = accumulate(all(A), 0LL);
    map <int, vector <int> > og;
    for (int i = 0; i < n; i++)
    {
        og[A[i]].push_back(i);
    }
    sort(all(A));
    
    vector <int> res(n);
    ll best = 1LL * INF * INF;
    do
    {
        ll cur = 0;
        int k;
        for (int i = 0; i < n; i++)
        {
            cur += 1LL * A[i];
            if (2 * cur >= S)
            {
                k = i + 1;
                break;
            }
        }
        
        if (abs(k - (n - k)) < best)
        {
            best = abs(k - (n - k));
            res = A;
        }
    }
    while (next_permutation(all(A)));
    
    for (auto &x : res)
    {
        auto tmp = og[x].back();
        og[x].pop_back();
        x = tmp;
    }
    return res;
}

/*
$$$$$$$$\ $$$$$$$$\ 
$$  _____|\____$$  |
$$ |          $$  / 
$$$$$\       $$  /  
$$  __|     $$  /   
$$ |       $$  /    
$$$$$$$$\ $$$$$$$$\ 
\________|\________|
*/