#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>

struct Node {
    int data;
    struct Node* next;
};
struct Node* createNode(int val) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = val;
    newNode->next = NULL;
    return newNode;
}
void insertEnd(struct Node** head, int val) {
    struct Node* newNode = createNode(val);
    if(*head == NULL) {
        *head = newNode;
        newNode->next = *head;
    } else {
        struct Node* temp = *head;
        while (temp->next !=*head)
           temp = temp->next;
        temp->next = newNode;
        newNode->next = *head;
    }
}
void sortCircular(struct Node* head) {
    if (head == NULL) return;
    struct Node* current = head;
    struct Node* index = NULL;
    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);
}
void displayAndfindExtremes(struct Node* head) {
    if (head == NULL) return;
    struct Node* temp = head;
    int smallest = head->data;
    int largest = head->data;
    do{
        printf("%d", temp->data);
        if (temp->data < smallest) smallest =temp->data;
        if (temp->data > largest ) largest = temp->data;
        temp =temp->data;
    } while (temp !=head);
    printf("\nSmallest:%d\nLargest:%d\n", smallest, largest);
}
int isValidNumber(char* str) {
    for (int i = 0; str[i] !='\0'; i++) {
        if (!isdigit(str[i]) && str[i] !='-') return 0;
    }
    return 1;
}
int main() {
    int n;
    if (scanf("%d", &n) !=1 || n < 1 || n > 100) {
        printf("Invalid input\n");
        return 0;
    }
    struct Node* head = NULL;
    char buffer[101];
    for (int i = 0; i < n; i++) {
        if (scanf("%s", buffer) !=1 || !isValidNumber(buffer)) {
            printf("Invalid input\n");
            return 0;
        }
        insertEnd(&heat, atoi(buffer));
    }
    sortCircular(head);
    displayAndFindExtremes(head);
    return 0;
}