#include <bits/stdc++.h>
using namespace std;
struct TreeNode{
	int val;
	TreeNode* left;
	TreeNode* right;
	
	TreeNode(int val):val(val),left(nullptr),right(nullptr){};
};
int idx;
unordered_map<int,int>mp;
TreeNode* help(vector<int>&pre,int st,int end){

	if(st>end)return nullptr;
	int rootVal = pre[idx--];
	int mid = mp[rootVal];
	
	TreeNode* root = new TreeNode(rootVal);
	root->right = help(pre,mid+1,end);
    root->left = help(pre,st,mid-1);
	
	return root;
}
TreeNode* bt(vector<int>&post,vector<int>&in){
	for(int i = 0;i<in.size();i++){
		mp[in[i]] = i;
	}
	idx = post.size()-1;
	return help(post,0,in.size()-1);
}


void print(TreeNode* root) {
    if (!root) {
        cout << "[]" << endl;
        return;
    }

    vector<string> result;
    queue<TreeNode*> q;
    q.push(root);

    while (!q.empty()) {
        TreeNode* curr = q.front();
        q.pop();

        if (curr) {
            result.push_back(to_string(curr->val));
            // Push children even if they are null
            q.push(curr->left);
            q.push(curr->right);
        } else {
            result.push_back("null");
        }
    }

    // Remove all the trailing "null"s from the back of the result
    while (!result.empty() && result.back() == "null") {
        result.pop_back();
    }

    // Print the array with brackets and commas
    cout << "[";
    for (int i = 0; i < result.size(); i++) {
        cout << result[i];
        if (i < result.size() - 1) cout << ",";
    }
    cout << "]" << endl;
}
int main() {
//	TreeNode* root  = buildTree();
	int n;
	cin>>n;
	vector<int>post(n),in(n);
	
	for(int i = 0;i < n ;i++){
		cin>>post[i];
	}
	
		for(int i = 0;i < n ;i++){
		cin>>in[i];
	}
	
	TreeNode* Croot = bt(post,in);
//	preO(Croot);
	print(Croot);
	return 0;
}