// editor1
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

// Node structure for circular linked list
struct Node {
    int data;
    struct Node* next;
};

// Function to create a new node
struct Node* createNode(int value) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = newNode; // circular
    return newNode;
}

// Insert node at end
struct Node* insertEnd(struct Node* head, int value) {
    struct Node* newNode = createNode(value);
    if (head == NULL) {
        return newNode;
    }
    struct Node* temp = head;
    while (temp->next != head) {
        temp = temp->next;
    }
    temp->next = newNode;
    newNode->next = head;
    return head;
}

// Sort circular linked list
void sortList(struct Node* head) {
    if (head == NULL) return;
    struct Node* current = head;
    struct Node* index;
    int temp;
    do {
        index = current->next;
        while (index != head) {
            if (current->data > index->data) {
                temp = current->data;
                current->data = index->data;
                index->data = temp;
            }
            index = index->next;
        }
        current = current->next;
    } while (current->next != head);
}

// Print circular linked list
void printList(struct Node* head) {
    if (head == NULL) return;
    struct Node* temp = head;
    do {
        printf("%d ", temp->data);
        temp = temp->next;
    } while (temp != head);
    printf("\n");
}

int main() {
    int n;
    if (scanf("%d", &n) != 1 || n <= 0) {
        printf("Invalid input\n");
        return 0;
    }
    struct Node* head = NULL;
    for (int i = 0; i < n; i++) {
        char buffer[50];
        if (scanf("%s", buffer) != 1) {
            printf("Invalid input\n");
            return 0;
        }
        // Check if input is a valid integer
        for (int j = 0; buffer[j] != '\0'; j++) {
            if (!isdigit(buffer[j]) && !(j == 0 && buffer[j] == '-')) {
                printf("Invalid input\n");
                return 0;
            }
        }
        int value = atoi(buffer);
        head = insertEnd(head, value);
    }

    sortList(head);
    printList(head);

    // smallest is head, largest is last node
    struct Node* temp = head;
    while (temp->next != head) {
        temp = temp->next;
    }
    printf("Smallest: %d\n", head->data);
    printf("Largest: %d\n", temp->data);

    return 0;
}