#include <iostream>
using namespace std;
typedef struct Node
{
int data;
struct Node* next;
Node(int x)
{
this->data=x;
this->next=NULL;
}
Node(){
}
};
void print(Node* head)
{
Node* p=head->next;
while(p)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
void createLinkedList(Node* & head)
{
int n;
cin>>n;
head=new Node;
Node* rear=head;
while (n--)
{
int x;
cin>>x;
rear->next=new Node(x);
rear=rear->next;
}
}
void deleteMax(Node* head)
{
Node* fmax=head;
Node* rmax=head->next;
Node* f=head->next;
Node* r=f->next;
while(r) {
if (r->data > rmax->data)
{
fmax=f;
rmax=r;
}
f=f->next;
r=r->next;
}
Node* pre=head;
Node* p=head->next;
while(p)
{
if(p->data==rmax->data)
{
pre->next=p->next;
p=p->next;
} else
{
pre=pre->next;
p=p->next;
}
}
}
int main() {
Node* head=NULL;
createLinkedList(head);
print(head);
deleteMax(head);
print(head);
return 0;
}