//C++版代码
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> nums(n);
    int index = 0;
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
        if (nums[i] > nums[index]) index = i;
    }
    cout << nums[index] << endl;
    nums.erase(nums.begin() + index);
    sort(nums.begin(), nums.end());
    if (nums.empty()) cout << -1;
    else for (int num: nums) cout << num << " ";
    return 0;
}
//Java版代码
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> nums = new ArrayList<>();
        int index = 0;
        for (int i = 0; i < n; i++) {
            nums.add(i, sc.nextInt());
            if (nums.get(i) > nums.get(index)) index = i;
        }
        System.out.println(nums.get(index));
        nums.remove(index);
        nums.sort(null);
        if (nums.isEmpty()) System.out.println(-1);
        else nums.forEach(num -> System.out.print(num + " "));
    }
}
#Python版代码
input()
l = list(map(int, input().split()))
max_num = max(l)
l.remove(max_num)
l.sort()
print(max_num)
if l:
    print(*l)
else:
    print(-1)