class Node:
    def __init__(self, data):
        self.data = data
        self.next = None

class CircularLinkedList:
    def __init__(self):
        self.head = None

    def insert_end(self, data):
        new_node = Node(data)
        if not self.head:
            self.head = new_node
            new_node.next = self.head
        else:
            temp = self.head
            while temp.next != self.head:
                temp = temp.next
            temp.next = new_node
            new_node.next = self.head

    def sort_list(self):
        if not self.head or self.head.next == self.head:
            return
        sorted_list = []
        temp = self.head
        while True:
            sorted_list.append(temp.data)
            temp = temp.next
            if temp == self.head:
                break
        sorted_list.sort()
        temp = self.head
        for data in sorted_list:
            temp.data = data
            temp = temp.next

    def find_min_max(self):
        if not self.head:
            return None, None
        min_val = max_val = self.head.data
        temp = self.head.next
        while temp != self.head:
            if temp.data < min_val:
                min_val = temp.data
            if temp.data > max_val:
                max_val = temp.data
            temp = temp.next
        return min_val, max_val

    def display(self):
        if not self.head:
            print("List is empty")
            return
        temp = self.head
        while True:
            print(temp.data, end=" ")
            temp = temp.next
            if temp == self.head:
                break
        print()

def is_valid_input(data):
    try:
        int(data)
        return True
    except ValueError:
        return False

def main():
    cll = CircularLinkedList()
    try:
        n = int(input())
        if not (1 <= n <= 100):
            print("Invalid input.")
            return
        batch_results = input().split()
        if len(batch_results) != n:
            print("Invalid input.")
            return
        for result in batch_results:
            if not is_valid_input(result):
                print("Invalid input.")
                return
            cll.insert_end(int(result))
        cll.sort_list()
        cll.display()
        min_val, max_val = cll.find_min_max()
        print(f"Smallest: {min_val}")
        print(f"Largest: {max_val}")
    except ValueError:
        print("Invalid input.")

if __name__ == "__main__":
    main()