#include<bits/stdc++.h>
using namespace std;
struct Node{
int val;
Node*next;
};
Node*InsertAtBegin(Node*root,int x)
{
Node*newnode=new Node();
newnode->val=x;
newnode->next=NULL;
if(root==NULL)
{
root=newnode;
return root;
}
else
{
newnode->next=root;
root=newnode;
return root;
}
}
Node*DeleteFromBegin(Node*root,int x)
{
if(root==NULL)
return root;
Node*temp=root;
root=root->next;
delete temp;
return root;
}
void Print(Node*root)
{
Node*currnode;
currnode=root;
while(currnode!=NULL)
{
cout<<currnode->val<<"->";
currnode=currnode->next;
}
cout<<endl;
}
int main()
{
Node*root=NULL;
int n;
cin>>n;
if(n<=0)
{
cout<<endl;
return 0;
}
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
Print(root);
for(int i=0;i<n;i++)
{
root=InsertAtBegin(root,a[i]);
}
Print(root);
for(int i=0;i<n;i++)
{
root=DeleteFromBegin(root,a[i]);
}
Print(root);
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IE5vZGV7CmludCB2YWw7Ck5vZGUqbmV4dDsKfTsKTm9kZSpJbnNlcnRBdEJlZ2luKE5vZGUqcm9vdCxpbnQgeCkKewpOb2RlKm5ld25vZGU9bmV3IE5vZGUoKTsKbmV3bm9kZS0+dmFsPXg7Cm5ld25vZGUtPm5leHQ9TlVMTDsKaWYocm9vdD09TlVMTCkKewpyb290PW5ld25vZGU7CnJldHVybiByb290Owp9CmVsc2UKewpuZXdub2RlLT5uZXh0PXJvb3Q7CnJvb3Q9bmV3bm9kZTsKcmV0dXJuIHJvb3Q7Cn0KfQpOb2RlKkRlbGV0ZUZyb21CZWdpbihOb2RlKnJvb3QsaW50IHgpCnsKaWYocm9vdD09TlVMTCkKcmV0dXJuIHJvb3Q7Ck5vZGUqdGVtcD1yb290Owpyb290PXJvb3QtPm5leHQ7CmRlbGV0ZSB0ZW1wOwpyZXR1cm4gcm9vdDsKfQp2b2lkIFByaW50KE5vZG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