#include <iostream>
#include <algorithm>
using namespace std;

int arr[2000];

int main() {
    int n;
    while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case
        int index = 0;
        int max = -9999999;
        for(int i = 0; i < n; i++){
            scanf("%d", &arr[i]);
            if(arr[i] > max){
                max = arr[i];
                index = i;
            }
        }
        if(n == 1){            
            printf("%d\n-1\n", arr[0]);
            continue;
        }
        int t = arr[index];
        printf("%d\n", t);
        arr[index] = arr[n - 1];
        arr[n - 1] = t;
        sort(arr, arr + n - 1);
        
        for(int i = 0; i < n - 1; i++){
            printf("%d ", arr[i]);
        }
        printf("\n");

    }
}
// 64 位输出请用 printf("%lld")