#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;
}
Node*InsertAtPos(Node*root,int x,int pos)
{
if(pos==0)
{
root=InsertAtBegin(root,x);
}
else
{
Node*newnode=new Node();
newnode->val=x;
newnode->next=NULL;
Node*currnode;
currnode=root;
for(int i=1;i<pos;i++)
{
currnode=currnode->next;
}
newnode->next=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);
    
        root = InsertAtBegin(root, 1);
    

    
    Print(root);

root=InsertAtEnd(root,10);
Print(root);
for(int i=0;i<n;i++)
{
root=InsertAtPos(root,5,0);
root=InsertAtPos(root,8,3);
}
Print(root);
    return 0;
}