<?php
// Discard the first input line! It's useless :)
fgets(STDIN);
$numbers = explode(' ', rtrim(fgets(STDIN)));
$valuePerWife = array_sum($numbers) / 2;

// Taken from here: http://stackoverflow.com/a/13194803/603003
// Credits to dAngelov: http://stackoverflow.com/users/955185/dangelov
function pc_permute($items, $perms = array( )) {
    if (empty($items)) {
        $return = array($perms);
    }  else {
        $return = array();
        for ($i = count($items) - 1; $i >= 0; --$i) {
             $newitems = $items;
             $newperms = $perms;
         list($foo) = array_splice($newitems, $i, 1);
             array_unshift($newperms, $foo);
             $return = array_merge($return, pc_permute($newitems, $newperms));
         }
    }
    return $return;
}


foreach (pc_permute($numbers) as $permutation) {
	$sum = 0;
	$rest = [];

	for ($i=0; $i<count($permutation); $i++) {
		$sum += $permutation[$i];
		if ($sum == $valuePerWife) {
			$rest = array_slice($permutation, $i + 1);
			break;
		}
	}
	
	if (array_sum($rest) == $valuePerWife) {
		echo implode(' ', array_slice($permutation, 0, $i + 1)), "\n";
		echo implode(' ', array_slice($permutation, $i + 1)), "\n";
		echo 'diff=0';
		exit;
	}
}
exit('DIDNT FOUND ANY COMBINATION!');