#include <stdio.h>
#include <stdlib.h>

int main() {
    int a[25], n;
    while (scanf("%d", &n) != EOF) {
            int minnum, maxnum;
            scanf("%d", &a[0]);
            minnum = a[0];
            maxnum = a[0];
            int min_index=0;
            int max_index=0;
            for (int i = 1; i < n; i++) {
                scanf("%d", &a[i]);
                if (a[i] < minnum) {
                    minnum = a[i];
                    min_index = i;
                } else if (a[i] > maxnum) {
                    maxnum = a[i];
                    max_index = i;
                }
            }
            int temp = a[min_index];
            a[min_index] = a[max_index];
            a[max_index] = temp;
            for (int i = 0; i < n; i++) {
                printf("%d ", a[i]);
            }
            printf("\n");
    }
    return 0;
}