#include <fstream>
#include <vector>
#include <float.h>
#include <algorithm>
using namespace std;

ifstream input("CHIAKEO.inp");
ofstream output("CHIAKEO.out");

double MIN = DBL_MAX;
int res;
vector <int> result1;

void print(vector <int> &sub)
{
	for (unsigned int i = 0; i < sub.size(); i++)
	{
		output << sub[i] << ' ';
	}
	output << '\n';
}

double ABS(double a)
{
	return (a > 0) ? a : -a;
}

bool CheckMin(int &total, int limit)
{
	if (ABS(total - (double)limit / 2) < MIN)
	{
		MIN = ABS(total - (double)((double)limit / 2));
		res = total;
		return true;
	}
	return false;
}

void chiakeo(int &Total, vector <int> &arr, vector <int> &sub, int &total, bool pass, unsigned int i = 0)
{
	if (i >= arr.size())
	{
		return;
	}
	if (pass)
	{
		sub.push_back(arr[i]);
		total += arr[i];
		if (CheckMin(total, Total))
		{
			result1 = sub;
		}
	}
	chiakeo(Total, arr, sub, total, true, i + 1);
	chiakeo(Total, arr, sub, total, false, i + 1);
	if (pass)
	{
		total -= sub.back();
		sub.pop_back();
	}
}

int main()
{
	int n;
	int total = 0;
	int Total = 0;
	int count = 0;
	input >> n;
	vector <int> arr(n);
	vector <int> sub;
	vector <int> result2;
	for (int i = 0; i < n; i++)
	{
		input >> arr[i];
		Total += arr[i];
	}
	chiakeo(Total, arr, sub, total, true);
	chiakeo(Total, arr, sub, total, false);
	output << res << '\n';
	for (unsigned int i = 0; i < result1.size(); i++)
	{
		output << result1[i] << ' ';
	}
	for (unsigned int i = 0; i < arr.size(); i++)
	{
		if (find(result1.begin(), result1.end(), arr[i]) == result1.end())
		{
			count += arr[i];
			result2.push_back(arr[i]);
		}
	}
	output << '\n' << count << '\n';
	for (unsigned int i = 0; i < result2.size(); i++)
	{
		output << result2[i] << ' ';
	}
	input.close();
	output.close();
	return 0;
}