#include <stdio.h>
#include <stdlib.h>
struct Node {
    int data;
    struct Node* next;
};
struct Node* createnode(int val) {
    struct Node*newnode = (struct Node*)malloc(sizeof(struct Node));
    newnode->data = val;
    newnode->next = NULL;
    return newnode;
}
void InsertAtPos(struct Node** head, int value,int pos) {
    struct Node*createnode(val){
    if(pos==1){
        newnode->next=head;
        head=newnode;
        return;
    }

    struct Node*temp=head;
    for (int i=1;i<pos-1 && temp!=NULL;i++){
        temp=temp->next;
    }
    if (temp==NULL){
        printf("Invalid position!\n");
        free(newNode);
        return;
    }

    newnode->next=temp->next;
    temp->next=newnode;
}
int main(){
    int n,val,num;
    if(scanf("%d",&n)!=1){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++){
        if(scanf("%d",&num)!=1){
            printf("Invalid input");
            return 0;
        }
        InsertAtPos(num);
    }
    return 0;
}