#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left;
    struct node *right;
}Node;
Node *root=NULL;
Node *create(int val){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=val;
    newnode->left=NULL;
    newnode->right=NULL;
    return newnode;
}
Node *buildTree(int arr[],int n){
    if(n==0)return NULL;
    Node *queue[200];
    int front=0,rear=0,i=0;
    Node *root=create(arr[i++]);
    queue[rear++]=root;
    while(i<n){
        Node *temp=queue[front++];
        temp->left=create(arr[i++]);
        queue[rear++]=temp->left;
        if(i<n){
            temp->right=create(arr[i++]);
            queue[rear++]=temp->right;
        }
    }
    return root;
}
void preorder(Node *root){
    if(root==NULL)
        return;
    if(root->left==NULL && root->right==NULL)
        printf("%d ",root->data);
    postorder(root->left);
    postorder(root->right);
    
}
int main(){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    int arr[n];
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        root=insert(arr,n);
    }
    preorder(root);
    return 0;
}