#include
using namespace std;
class node {
public:
int data;
node* next;
node* prev;
node(int data) {
this->data = data;
this->next = NULL;
this->prev = NULL;
}
};
node* compareAndDelete(node* head) {
node* temp1 = head;
node* temp2 = head->next;
while (temp2 != NULL) {
if (temp1->data < temp2->data) {
if (temp1 == head) {
head = temp2;
temp2->prev = NULL;
delete temp1;
temp1 = head;
temp2 = temp2->next;
}
else {
node* del = temp1;
temp1->prev->next = temp2;
temp2->prev = temp1->prev;
temp1 = temp2;
temp2 = temp2->next;
delete del;
}
}
else {
temp1 = temp1->next;
temp2 = temp2->next;
}
}
return head;
}
node* input(long long int t) {
int data;
node* head = NULL;
node* tail = NULL;
while (t--) {
cin >> data;
node* newNode = new node(data);
if (head == NULL) {
head = newNode;
tail = newNode;
}
else {
tail->next = newNode;
newNode->prev = tail;
tail = newNode;
}
}
return head;
}
void print(node* head) {
while (head != NULL) {
cout << head->data << " ";
head = head->next;
}
}
int main() {
long long int t;
cin >> t;
node* head = input(t);
head = compareAndDelete(head);
print(head);
return 0;
}