#include<stdio.h>
#include<string.h>
#include<ctype.h>

typedef struct Node{
    int data;
    struct Node* next;
}Node;

struct Node* createNode(int val){
    struct Node* newNode=(struct Node*)malloc(sizeof(Node));
    newNode->val=data;
    newNode->next=NULL;
    return newNode;
}

void insert(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 circular(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->data != head);
}

void display(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 isvalid(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");
        return 0;
    }
    
    char arr[n];
    for(int i=0;i<n;i++){
    if(scanf("%s",arr) !=1 || isvalid(arr)){
        printf("Invalid input");
        return ;
    }
    append(&head,atoi(arr));
}

circluar(&head);
display(&head);

return 0;
}