#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<<"val"<<currnode->val<<"->"<<endl;
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+dmFsPXg7Cm5ld25vZGUtPm5leHQ9TlVMTDsKaWYocm9vdD09TlVMTCkKewpyb290PW5ld25vZGU7CnJldHVybiByb290Owp9CmVsc2UKewpuZXdub2RlLT5uZXh0PXJvb3Q7CnJvb3Q9bmV3bm9kZTsKcmV0dXJuIHJvb3Q7Cn0KfQpOb2RlKkRlbGV0ZUZyb21CZWdpbihOb2RlKnJvb3QsaW50IHgpCnsKaWYocm9vdD09TlVMTCkKcmV0dXJuIHJvb3Q7Ck5vZGUqdGVtcD1yb290Owpyb290PXJvb3QtPm5leHQ7CmRlbGV0ZSB0ZW1wOwpyZXR1cm4gcm9vdDsKfQp2b2lkIF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