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

struct STRUCT00 {
    struct STRUCT00 * MEMBER00 ;
    struct STRUCT00 * MEMBER01 ;
    struct STRUCT00 * MEMBER02 ;
    int MEMBER03 ;
} ;

static struct STRUCT00 * FUNC00 ( int ARG00 ) {
    struct STRUCT00 * VAR00 = malloc ( sizeof ( struct STRUCT00 ) ) ;

    VAR00 -> MEMBER00 = VAR00 -> MEMBER01 = VAR00 -> MEMBER02 = NULL ;
    VAR00 -> MEMBER03 = ARG00 ;

    return VAR00 ;
}

static void FUNC01 ( struct STRUCT00 * ARG01 ) {
    free ( ARG01 ) ;

    return ;
}

static int FUNC02 ( const int ARG02 [ ] , int ARG03 , const int ARG04 [ ] , int ARG05 , int ARG06 ) {
    int VAR01 , VAR02 ;

    for ( VAR01 = 0 ; VAR01 < ARG03 ; VAR01 ++ ) {
        for ( VAR02 = ARG05 ; VAR02 < ARG06 ; VAR02 ++ ) {
            if ( ARG02 [ VAR01 ] == ARG04 [ VAR02 ] ) {
                return ARG02 [ VAR01 ] ;
            }
        }
    }

    return -1 ;
}

static int FUNC03 ( int ARG07 , const int ARG08 [ ] , int ARG09 , int ARG10 ) {
    int VAR03 ;

    for ( VAR03 = ARG09 ; VAR03 < ARG10 ; VAR03 ++ ) {
        if ( ARG08 [ VAR03 ] == ARG07 ) {
            return VAR03 ;
        }
    }
    assert ( 0 ) ;

    return -1 ;
}

static struct STRUCT00 * FUNC04 ( struct STRUCT00 * ARG11 , const int ARG12 [ ] , int ARG13 , const int ARG14 [ ] , int ARG15 , int ARG16 ) {
    int VAR04 ;
    int VAR05 ;
    struct STRUCT00 * VAR06 ;

    if ( ARG15 >= ARG16 ) {
        return NULL ;
    }

    VAR04 = FUNC02 ( ARG12 , ARG13 , ARG14 , ARG15 , ARG16 ) ;
    VAR05 = FUNC03 ( VAR04 , ARG14 , ARG15 , ARG16 ) ;

    VAR06 = FUNC00 ( VAR04 ) ;
    VAR06 -> MEMBER00 = ARG11 ;

    VAR06 -> MEMBER01 = FUNC04 ( VAR06 , ARG12 , ARG13 , ARG14 , ARG15 , VAR05 ) ;
    VAR06 -> MEMBER02 = FUNC04 ( VAR06 , ARG12 , ARG13 , ARG14 , VAR05 + 1 , ARG16 ) ;

    return VAR06 ;
}

static void FUNC05 ( const struct STRUCT00 * ARG17 ) {

    if ( ARG17 == NULL ) {
        return ;
    }

    FUNC05 ( ARG17 -> MEMBER01 ) ;
    FUNC05 ( ARG17 -> MEMBER02 ) ;
    printf ( "%d" , ARG17 -> MEMBER03 ) ;

    if ( ARG17 -> MEMBER00 ) {
        printf ( " " ) ;
    }

    return ;
}

static void FUNC06 ( struct STRUCT00 * ARG18 ) {
    if ( ! ARG18 ) {
        return ;
    }

    FUNC06 ( ARG18 -> MEMBER01 ) ;
    FUNC06 ( ARG18 -> MEMBER02 ) ;
    FUNC01 ( ARG18 ) ;

    return ;
}

int main ( void ) {
    int VAR07 ;
    int VAR08 ;
    int * VAR09 , * VAR10 ;
    struct STRUCT00 * VAR11 ;

    scanf ( "%d\n" , & VAR07 ) ;
    VAR09 = malloc ( sizeof ( int ) * VAR07 ) ;
    VAR10 = malloc ( sizeof ( int ) * VAR07 ) ;

    for ( VAR08 = 0 ; VAR08 < VAR07 ; VAR08 ++ ) {
        int VAR12 ;
        scanf ( "%d" , & VAR12 ) ;
        VAR09 [ VAR08 ] = VAR12 ;
    }
    for ( VAR08 = 0 ; VAR08 < VAR07 ; VAR08 ++ ) {
        int VAR13 ;
        scanf ( "%d" , & VAR13 ) ;
        VAR10 [ VAR08 ] = VAR13 ;
    }

    VAR11 = FUNC04 ( NULL , VAR09 , VAR07 , VAR10 , 0 , VAR07 ) ;

    FUNC05 ( VAR11 ) ;
    printf ( "\n" ) ;

    FUNC06 ( VAR11 ) ;
    free ( VAR09 ) ;
    free ( VAR10 ) ;

    return 0 ;
}
