#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*InsertAtEnd(Node*root,int x)
{
Node*newnode=new Node();
newnode->next=NULL;
newnode->val=x;
if(root==NULL)
{
root=newnode;
return root;
}
Node*currnode;
currnode=root;
while(currnode->next!=NULL)
{
currnode=currnode->next;
}
currnode->next=newnode;
return root;
}
void Print(Node* root) {
Node* 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=InsertAtEnd(root,a[i]);
}
Print(root);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgTm9kZSB7CiAgICBpbnQgdmFsOwogICAgTm9kZSogbmV4dDsKfTsKCgpOb2RlKiBJbnNlcnRBdEJlZ2luKE5vZGUqIHJvb3QsIGludCB4KSB7CiAgICBOb2RlKiBuZXdub2RlID0gbmV3IE5vZGUoKTsKICAgIG5ld25vZGUtPnZhbCA9IHg7CiAgICBuZXdub2RlLT5uZXh0ID0gTlVMTDsKaWYocm9vdD09TlVMTCkKewpyb290PW5ld25vZGU7CiAgICByZXR1cm4gcm9vdDsKfQplbHNlCnsKbmV3bm9kZS0+bmV4dD1yb290Owpyb290PW5ld25vZGU7CnJldHVybiByb290Owp9Cn0KTm9kZSpJbnNlcnRBdEVuZChOb2RlKnJvb3QsaW50IHgpCnsKTm9kZSpuZXdub2RlPW5ldyBOb2RlKCk7Cm5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