#include <stdio.h>

in

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *left, *right;
};

struct Node* createNode(int val) {
    struct Node* newnode = (struct Node*)malloc(sizeof(struct Node));
    newnode->data = val;
    newnode->left = newnode->right = NULL;
    return newnode;
}

struct Node* insert(struct Node* root, int val) {
    if (root == NULL)
        return createNode(val);

    if (val < root->data)
        root->left = insert(root->left, val);
    else
        root->right = insert(root->right, val);

    return root;
}

void postOrderLeaf(struct Node* root) {
    if (root == NULL)
        return;

    postOrderLeaf(root->left);
    postOrderLeaf(root->right);

    // leaf node check
    if (root->left == NULL && root->right == NULL)
        printf("%d ", root->data);
}

int main() {
    int n;
    scanf("%d", &n);

    if (n <= 0) {
        printf("Invalid input");
        return 0;
    }

    struct Node* root = NULL;
    int val;

    for (int i = 0; i < n; i++) {
        scanf("%d", &val);
        root = insert(root, val);
    }

    postOrderLeaf(root);
    return 0;
}