#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
struct node {
    int data;
    struct node*next;
};
struct node*cnode(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 = *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 -> next;
        
    }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 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(&head,atoi(buffer));
    }
    sortCircular(head);
    displayAndFindExtremes(head);
    return 0;
}