/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author dipankar12
 */
import java.io.*;
import java.util.*;
public class r277a {
    public static void main(String args[])
    {
        fastio in=new fastio(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        r277a1 ob=new r277a1();
        int n=in.nextInt();
        int m=in.nextInt();

        for(int i=0;i<m;i++)
            ob.makeset(i+1);

        int count=0;
        for(int i=0;i<n;i++)
        {
            //System.out.println("i is"+i);
            int num=in.nextInt();
            if(num==0)
            {
                count++;
            }
            if(num==1)
                in.nextInt();
            if(num>1)
            {
                int lang=in.nextInt();
                for(int j=0;j<num-1;j++)
                {
                    int lang1=in.nextInt();
                    ob.union(lang, lang1);
                    lang=lang1;
                    //System.out.println(lang+" "+lang1);
                }
            }
            //System.out.println("Hello");
        }
        HashSet<Long> hs=new HashSet<Long>();
        for(int i=0;i<m;i++)
        {
            long set=(ob.findset(i+1));
            if(set!=(i+1))
                hs.add(set);
            //System.out.println("Set of i+1 "+(i+1)+" is "+ob.findset(i+1));
            //System.out.println("hs is"+hs);
        }
        int size=hs.size();
        if(hs.size()!=0)
            size--;
        pw.println(size+count);
        pw.close();
    }

    static class fastio {

            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int cchar, snchar;
            private SpaceCharFilter filter;

            public fastio(InputStream stream) {
                this.stream = stream;
            }

            public int nxt() {
                if (snchar == -1)
                    throw new InputMismatchException();
                if (cchar >= snchar) {
                    cchar = 0;
                    try {
                        snchar = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snchar <= 0)
                        return -1;
                }
                return buf[cchar++];
            }

            public int nextInt() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public long nextLong() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }

            public String readString() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isSpaceChar(c));
                return res.toString();
            }

            public String nextLine() {
                int c = nxt();
                while (isSpaceChar(c))
                    c = nxt();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isEndOfLine(c));
                return res.toString();
            }

            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }

            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }

            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }

}
class r277a2
{
    long data;
    r277a2 parent;
    int rank;
}
class r277a1 {
    private HashMap<Long,r277a2> hm=new HashMap<Long,r277a2>();

    public void makeset(long data)
    {
        r277a2 ob=new r277a2();
        ob.data=data;
        ob.parent=ob;
        ob.rank=0;
        hm.put(data, ob);
    }

    boolean union(long data1,long data2)
    {
        r277a2 ob1=hm.get(data1);
        r277a2 ob2=hm.get(data2);

        r277a2 parent1=findset(ob1);
        r277a2 parent2=findset(ob2);

        if(parent1.data==parent2.data)
            return false;

        if(parent1.rank>=parent2.rank)
        {
            parent1.rank=(parent1.rank==parent2.rank)?parent1.rank+1:parent1.rank;
            parent2.parent=parent1;
            //System.out.println("Making union of"+parent2.data+" "+parent1.data);
        }
        else
            parent1.parent=parent2;
        return true;
    }

    public long findset(long data)
    {
        return findset(hm.get(data)).data;
    }

    r277a2 findset(r277a2 ob)
    {
        r277a2 parent=ob.parent;
        if(parent==ob)
            return parent;

        ob.parent=findset(ob.parent);
        return ob.parent;
    }

    void print()
    {
        System.out.println(hm);
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author dipankar12
 */
import java.io.*;
import java.util.*;
public class r277a {
    public static void main(String args[])
    {
        fastio in=new fastio(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        r277a1 ob=new r277a1();
        int n=in.nextInt();
        int m=in.nextInt();

        int count=0;
        for(int i=0;i<n;i++)
        {
            int num=in.nextInt();
            if(num==0)
                count++;
            else if(num==1)
                ob.makeset(in.nextInt());
            else
            {
                int lang=in.nextInt();
                if(ob.findset(lang)==-100)
                    ob.makeset(lang);
                for(int j=0;j<num-1;j++)
                {
                    int lang1=in.nextInt();
                    if(ob.findset(lang1)==-100)
                        ob.makeset(lang1);
                    ob.union(lang, lang1);
                    lang=lang1;
                }
                //System.out.println("Hello for "+(i+1));
            }
        }

        HashSet<Long> hs=new HashSet<Long>();
        for(int i=0;i<m;i++)
        {
            long x=ob.findset(i+1);
            if(x!=(i+1))
                hs.add(x);
        }
        //System.out.println("size is"+hs.size()+" hs is "+hs+"count is "+count);
        int size=hs.size();
        if(size!=0)
            size--;

        pw.println(size+count);
        pw.close();
    }

    static class fastio {

            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int cchar, snchar;
            private SpaceCharFilter filter;

            public fastio(InputStream stream) {
                this.stream = stream;
            }

            public int nxt() {
                if (snchar == -1)
                    throw new InputMismatchException();
                if (cchar >= snchar) {
                    cchar = 0;
                    try {
                        snchar = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snchar <= 0)
                        return -1;
                }
                return buf[cchar++];
            }

            public int nextInt() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public long nextLong() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }

            public String readString() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isSpaceChar(c));
                return res.toString();
            }

            public String nextLine() {
                int c = nxt();
                while (isSpaceChar(c))
                    c = nxt();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isEndOfLine(c));
                return res.toString();
            }

            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }

            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }

            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }

}
class r277a2
{
    long data;
    r277a2 parent;
    int rank;
}
class r277a1 {
    private HashMap<Long,r277a2> hm=new HashMap<Long,r277a2>();

    public void makeset(long data)
    {
        r277a2 ob=new r277a2();
        ob.data=data;
        ob.parent=ob;
        ob.rank=0;
        hm.put(data, ob);
    }

    boolean union(long data1,long data2)
    {
        r277a2 ob1=hm.get(data1);
        r277a2 ob2=hm.get(data2);

        r277a2 parent1=findset(ob1);
        r277a2 parent2=findset(ob2);

        if(parent1.data==parent2.data)
            return false;

        if(parent1.rank>=parent2.rank)
        {
            parent1.rank=(parent1.rank==parent2.rank)?parent1.rank+1:parent1.rank;
            parent2.parent=parent1;
            //System.out.println("Making union of"+parent2.data+" "+parent1.data);
        }
        else
            parent1.parent=parent2;
        return true;
    }

    public long findset(long data)
    {
        if(hm.get(data)==null)
            return -100;
        return findset(hm.get(data)).data;
    }

    r277a2 findset(r277a2 ob)
    {
        r277a2 parent=ob.parent;
        if(parent==ob)
            return parent;

        ob.parent=findset(ob.parent);
        return ob.parent;
    }

    void print()
    {
        System.out.println(hm);
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author dipankar12
 */
import java.io.*;
import java.util.*;
public class r277a {
    public static void main(String args[])
    {
        fastio in=new fastio(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        r277a1 ob=new r277a1();
        int n=in.nextInt();
        int m=in.nextInt();

        int count=0;
        for(int i=0;i<n;i++)
        {
            int num=in.nextInt();
            if(num==0)
                count++;
            else if(num==1)
            {
                int x=in.nextInt();
                if(ob.findset(x)==-100)
                    ob.makeset(x);
            }
            else
            {
                int lang=in.nextInt();
                if(ob.findset(lang)==-100)
                    ob.makeset(lang);
                for(int j=0;j<num-1;j++)
                {
                    int lang1=in.nextInt();
                    if(ob.findset(lang1)==-100)
                        ob.makeset(lang1);
                    ob.union(lang, lang1);
                    lang=lang1;
                }
                //System.out.println("Hello for "+(i+1));
            }
        }

        HashSet<Long> hs=new HashSet<Long>();
        for(int i=0;i<m;i++)
        {
            long x=ob.findset(i+1);
            //System.out.println("x is "+x+" for "+(i+1));
            if(x!=-100)
                hs.add(x);
        }
        //System.out.println("size is"+hs.size()+" hs is "+hs+"count is "+count);
        int size=hs.size();
        if(size!=0)
            size--;

        pw.println(size+count);
        pw.close();
    }

    static class fastio {

            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int cchar, snchar;
            private SpaceCharFilter filter;

            public fastio(InputStream stream) {
                this.stream = stream;
            }

            public int nxt() {
                if (snchar == -1)
                    throw new InputMismatchException();
                if (cchar >= snchar) {
                    cchar = 0;
                    try {
                        snchar = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snchar <= 0)
                        return -1;
                }
                return buf[cchar++];
            }

            public int nextInt() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public long nextLong() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }

            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }

            public String readString() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isSpaceChar(c));
                return res.toString();
            }

            public String nextLine() {
                int c = nxt();
                while (isSpaceChar(c))
                    c = nxt();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isEndOfLine(c));
                return res.toString();
            }

            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }

            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }

            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }

}
class r277a2
{
    long data;
    r277a2 parent;
    int rank;
}
class r277a1 {
    private HashMap<Long,r277a2> hm=new HashMap<Long,r277a2>();

    public void makeset(long data)
    {
        r277a2 ob=new r277a2();
        ob.data=data;
        ob.parent=ob;
        ob.rank=0;
        hm.put(data, ob);
    }

    boolean union(long data1,long data2)
    {
        r277a2 ob1=hm.get(data1);
        r277a2 ob2=hm.get(data2);

        r277a2 parent1=findset(ob1);
        r277a2 parent2=findset(ob2);

        if(parent1.data==parent2.data)
            return false;

        if(parent1.rank>=parent2.rank)
        {
            parent1.rank=(parent1.rank==parent2.rank)?parent1.rank+1:parent1.rank;
            parent2.parent=parent1;
            //System.out.println("Making union of"+parent2.data+" "+parent1.data);
        }
        else
            parent1.parent=parent2;
        return true;
    }

    public long findset(long data)
    {
        if(hm.get(data)==null)
            return -100;
        return findset(hm.get(data)).data;
    }

    r277a2 findset(r277a2 ob)
    {
        r277a2 parent=ob.parent;
        if(parent==ob)
            return parent;

        ob.parent=findset(ob.parent);
        return ob.parent;
    }

    void print()
    {
        System.out.println(hm);
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define OO 5e18
#define oo 2e9
#define yalla ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define sz  100005
#define re return
#define mod  1000000007
#define pi acos(-1)
using namespace std;
int n,a[2*sz],b[2*sz],cnt,x;
pair<int,int>p[2*sz];
int main()
{yalla;
 cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>x,p[i]={x,i};

sort(a,a+n);
sort(p,p+n);

for(int i=n-1;i>=0;i--)
 b[ p[cnt++].second ]=a[i];

for(int i=0;i<n;i++)cout<<b[i]<<" ";

 re 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define OO 5e18
#define oo 2e9
#define yalla ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define sz  100005
#define re return
#define mod  1000000007
#define pi acos(-1)
using namespace std;
int n,a[2*sz],b[2*sz];
int main()
{yalla;
 cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
for(int i=0;i<n;i++)cout<<a[i]<<" ";
 re 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX5 100005
#define MAX6 1000005
#define mp make_pair
#define pb push_back
ll M = 1e9 + 7;

int main()
{
    int m;
    ll x;
    ll arr[200005];
    vector<pair<ll,int>> a;
    vector<ll> b;
    cin >> m;
    for(int i=0;i<m;i++)
    {
        cin >> x;
        b.pb(x);
    }
    for(int i=0;i<m;i++)
    {
        cin >> x;
        a.pb(mp(x,i));
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    for(int i=m-1;i>=0;i--)
    {
        arr[(a[m-1-i].second)] = b[i];
    }

    for(int i=0;i<m;i++)
        cout << arr[i] << " ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX5 100005
#define MAX6 1000005
#define mp make_pair
#define pb push_back
ll M = 1e9 + 7;

int main()
{
    int m;
    ll x;
    ll arr[200005];
    vector<pair<ll,int>> a;
    vector<ll> b;
    cin >> m;
    for(int i=0;i<m;i++)
    {
        cin >> x;
        b.pb(x);
    }
    for(int i=0;i<m;i++)
    {
        cin >> x;
        a.pb(mp(x,-1*i));
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    for(int i=m-1;i>=0;i--)
    {
        arr[-1*(a[m-1-i].second)] = b[i];
    }

    for(int i=0;i<m;i++)
        cout << arr[i] << " ";

}


#include <bits/stdc++.h>
#define ill int long long
#define fi first
#define se second
#define pb push_back
#define ld long double
#define pp push_front
#define mp make_pair
using namespace std;
int n,i,j,x,a[200005];
vector < pair <int,int> > v;
set<int> my;
set<int>::iterator it;
map<int,int> d;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("graphtail.in","r",stdin);freopen("graphtail.out","w",stdout);
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>x;
        my.insert(x);
        d[x]++;
    }
    for (i=1;i<=n;i++)
    {
        cin>>x;
        v.pb({x,i});
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for (i=0;i<n;i++)
    {
        x=v[i].fi;
        it=my.lower_bound(x);
        a[v[i].se]=*it;
        d[*it]--;
        if (d[*it]==0)my.erase(*it);
    }
    for (i=1;i<=n;i++)
        cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define fi first
#define se second
#define pb push_back
#define ld long double
#define pp push_front
#define mp make_pair
using namespace std;
int n,i,j,x,ans;
set<int> my;
set<int>::iterator it;
map<int,int> d;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("graphtail.in","r",stdin);freopen("graphtail.out","w",stdout);
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>x;
        my.insert(x);
        d[x]++;
    }
    for (i=1;i<=n;i++)
    {
        cin>>x;
        it=my.lower_bound(x);
        cout<<(*it)<<" ";
        d[*it]--;
        if (d[*it]==0)my.erase(*it);
    }

}


#include<bits/stdc++.h>
using namespace std;
#define re register
#define gcd __gcd
#define ft first
#define sd second
#define mr make_pair
#define lowbit(x) ((x)&-(x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int N = 2e6+7;
const int M = 4e6+7;
const int lim = 1e6;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
multiset<LL> ms;
priority_queue<int> pq;
struct Node{
	int num,id;
	bool operator < (Node X) const{
		return num<X.num;
	}
}a[N],b[N];
int n,c[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].num);
        a[i].id=i;
	}
	for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i].num);
        b[i].id=i;
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    for(int i=1;i<=n;i++)
    	c[b[i].id] = a[n-i+1].num;
    for(int i=1;i<=n;i++)
        printf("%d%c",c[i],i==n?'\n':' ');
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1000005
#define M 1000000007

/*
	*********************************************************************
	*                             Code By                               *
	*                                                                   *
	*                            Srajan Gupta                           *
	*                            srajang_123                            *
	*                                                                   *
	*********************************************************************
*/
//Prime Numbers

vector<bool>prime(N+1,true);
void sieve()
{
	ll i,j,k;
	prime[0]=prime[1]=false;
	for(i=2;i*i<=N;i++)
	{
		if(prime[i])
		{
			for(j=i*i;j<=N;j+=i)
			{
				prime[j]=false;
			}
		}
	}
}

//Exponentiation

ll power(ll a,ll b)
{
	ll r=1;
	while(b)
	{
		if(b%2==1)
			r=r*a;
		b/=2;
		a*=a;
	}
	return r;
}
ll power(ll a,ll b,ll m)
{
	a=a%m;
	ll r=1;
	while(b)
	{
		if(b%2==1)
			r=(r*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return r;
}

//Prime Factors

vector<ll> factors(ll n)
{
	vector<ll>r;
	ll i,j;
	for(i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			r.push_back(i);
			if(n/i!=i)
				r.push_back(n/i);
		}
	}
	return r;
}

//GCD
ll gcd(ll a,ll b)
{
	if(b>a)
	{
		ll t=a;
		a=b;
		b=t;
	}
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
	return (a*b)/gcd(a,b);
}
//Graphs
vector<bool>bvisited(N,false);
vector<vector<ll>>G(N);
vector<ll> bfs(ll s)
{
	vector<ll>order;
	queue<ll>q;
	bvisited[s]=true;
	q.push(s);
	while(!q.empty())
	{
		s=q.front();
		q.pop();
		order.push_back(s);
		for(auto x:G[s])
		{
			if(!bvisited[x])
			{
				bvisited[x]=true;
				q.push(x);
			}
		}
	}
	return order;
}
vector<bool>dvisited(N,false);
vector<ll> dfs(ll s)
{
	vector<ll>order;
	stack<ll>q;
	q.push(s);
	while(!q.empty())
	{
		ll v=q.top();
		q.pop();
		if(!dvisited[v])
		{
			order.push_back(v);
			dvisited[v]=true;
		}
		for(ll i=0;i<G[v].size();i++)
		{
			if(!dvisited[G[v][i]])
			{
				q.push(G[v][i]);
			}
		}
	}
	return order;
}
//My Functions

void print(pair<ll,ll>a)
{
	cout<<a.first<<" "<<a.second;
}
void print(vector<ll>a)
{
	for(auto x:a)
		cout<<x<<" ";
}
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
	return a.second<b.second;
}
//Main Solution

void solve()
{
	ll n,i,j,k;
	cin>>n;
	vector<ll>a(n),c(n);
	vector<pair<ll,ll>>b(n);
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
	{
		cin>>j;
		b[i]={j,i};
	}
	sort(b.rbegin(),b.rend());
	sort(a.begin(),a.end());
	for(i=0;i<n;i++)
	{
		c[b[i].second]=a[i];
	}
	print(c);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    ll t=1;
	//cin>>t;
    while(t--)
    {
        solve();
    }
}


// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll t; cin>>t; while(t--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    TEZ;
    ll n;
    cin>>n;
    ll a[n],b[n];
    f(i,0,n)
        cin>>a[i];
    f(i,0,n)
        cin>>b[i];
    vector<ll> ans;
    f(i,0,n)
        if(a[i]>b[i])
            ans.pb(a[i]);
    srt(ans);
    reverse(ans.begin(),ans.end());
    vi v;
    f(i,0,n)
        v.pb({b[i],i});
    srt(v);
    ll in=0;
    vector<ll> res(n);
    for(auto i:v){
        res[i.ss]=ans[in++];
    }
    for(auto i:res)
        cout<<i<<" ";
}


// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll t; cin>>t; while(t--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    TEZ;
    ll n;
    cin>>n;
    ll a[n],b[n];
    f(i,0,n)
        cin>>a[i];
    f(i,0,n)
        cin>>b[i];
    vector<ll> ans;
    f(i,0,n)
        if(a[i]>b[i])
            ans.pb(a[i]);
    srt(ans);
    reverse(ans.begin(),ans.end());
    vi v;
    f(i,0,n)
        v.pb({b[i],i});
    srt(v);
    ll in=0;
    vector<ll> res(n);
    for(auto i:v){
        if(in<n)
        res[i.ss]=ans[in];
        in++;
    }
    for(auto i:res)
        cout<<i<<" ";
}


// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll t; cin>>t; while(t--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    TEZ;
    ll n;
    cin>>n;
    ll a[n],b[n];
    f(i,0,n)
        cin>>a[i];
    f(i,0,n)
        cin>>b[i];
    vector<ll> ans;
    f(i,0,n){
        if(a[i]>b[i])
            ans.pb(a[i]);
        else
            ans.pb(b[i]);
    }
    srt(ans);
    reverse(ans.begin(),ans.end());
    vi v;
    f(i,0,n)
        v.pb({b[i],i});
    srt(v);
    ll in=0;
    vector<ll> res(n);
    for(auto i:v){
        if(in<n)
        res[i.ss]=ans[in];
        in++;
    }
    for(auto i:res)
        cout<<i<<" ";
}


#include<bits/stdc++.h>

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  min3(a,b,c)         min(a,min(b,c))
#define  min4(a,b,c,d)       min(d,min(a,min(b,c)))
#define  max3(a,b,c)         max(a,max(b,c))
#define  max4(a,b,c,d)       max(d,max(a,max(b,c)))
#define  MX                  200005
#define  mxx                 1234567899
#define  mod                 1000000007
#define  inf                 (1<<28)
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  ub                  upper_bound
#define  lb                  lower_bound
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  MAX(x)              *max_element(all(x))
#define  MIN(x)              *min_element(all(x))
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  yes                 cout<<"YES"<<endl
#define  no                  cout<<"NO"<<endl
#define  stringtoint(a)      atoi(a.c_str())
#define  vi                  vector<int>
#define  vl                  vector<long long int>
#define  hi                  pf(" HI \n")
#define  Case(x)             cout<<"Case "<<x<<": "
#define  pp                  pair<int,int>
#define  ppl                 pair<long long int,long long int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  long long           ll;
typedef  unsigned long long int ulli;
int dx4[] = { 0 , 0 , -1 , 1 } ;
int dy4[] = { -1 , 1 , 0 , 0 } ;
bool valid( int r , int c , int x , int y ){
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ; return 0 ;}

using namespace std;
int ar[200005];
int main ()
{
    int n;
    hi;
    cin >> n;
    int a[n+2];
    int b[n+2];
    vi vec;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    vec.pb(a[i]);}
    maxSort(vec);
    vi v;
    map<int,vector<int> >pq;
    for(int i=1;i<=n;i++)
    {
        cin >> b[i];
        v.pb(b[i]);
        pq[b[i]].push_back(i);
    }
    vSort(v);
    Unique(v);
    int tot=0;
    vi vv;
    for(int i=0;i<v.size();i++)
    {
        int x = v[i];
        vv = pq[x];
       for(int j=vv.size()-1;j>=0;j--)
       {
           ar[vv[j]] = vec[tot];
           tot++;
       }
    }
    for(int i=1;i<=n;i++)
        cout << ar[i]<< " ";
    cout <<endl;

    return 0;
}


#include<bits/stdc++.h>

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  min3(a,b,c)         min(a,min(b,c))
#define  min4(a,b,c,d)       min(d,min(a,min(b,c)))
#define  max3(a,b,c)         max(a,max(b,c))
#define  max4(a,b,c,d)       max(d,max(a,max(b,c)))
#define  MX                  200005
#define  mxx                 1234567899
#define  mod                 1000000007
#define  inf                 (1<<28)
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  ub                  upper_bound
#define  lb                  lower_bound
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  MAX(x)              *max_element(all(x))
#define  MIN(x)              *min_element(all(x))
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  yes                 cout<<"YES"<<endl
#define  no                  cout<<"NO"<<endl
#define  stringtoint(a)      atoi(a.c_str())
#define  vi                  vector<int>
#define  vl                  vector<long long int>
#define  hi                  pf(" HI \n")
#define  Case(x)             cout<<"Case "<<x<<": "
#define  pp                  pair<int,int>
#define  ppl                 pair<long long int,long long int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  long long           ll;
typedef  unsigned long long int ulli;
int dx4[] = { 0 , 0 , -1 , 1 } ;
int dy4[] = { -1 , 1 , 0 , 0 } ;
bool valid( int r , int c , int x , int y ){
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ; return 0 ;}

using namespace std;
int ar[200005];
int main ()
{
    int n;
    cin >> n;
    int a[n+2];
    int b[n+2];
    vi vec;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    vec.pb(a[i]);}
    maxSort(vec);
    vi v;
    map<int,vector<int> >pq;
    for(int i=1;i<=n;i++)
    {
        cin >> b[i];
        v.pb(b[i]);
        pq[b[i]].push_back(i);
    }
    vSort(v);
    Unique(v);
    int tot=0;
    vi vv;
    for(int i=0;i<v.size();i++)
    {
        int x = v[i];
        vv = pq[x];
       for(int j=vv.size()-1;j>=0;j--)
       {
           ar[vv[j]] = vec[tot];
           tot++;
       }
    }
    for(int i=1;i<=n;i++)
        cout << ar[i]<< " ";
    cout <<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int, int>
#define EPS 1e-9
const int MXX = 2e5 + 5;

int n, a[MXX], b[MXX];
map<pii, int>mp;
int main ()
{
    cin>>n;
    priority_queue<pii>pq1, pq2;
    for(int i = 0; i<n; i++)cin>>a[i], pq1.push({a[i], i});
    for(int i = 0; i<n; i++)cin>>b[i], pq2.push({-b[i], i});
    while(!pq1.empty() && !pq2.empty())
    {
        pii tmp1 = pq1.top();
        pii tmp2 = pq2.top();
        int mx1 = tmp1.first, mn1 = tmp2.first;
        mp[{abs(mn1), tmp2.second}] = mx1;
        pq1.pop(), pq2.pop();
    }
    for(int i = 0; i<n; i++)cout<<mp[{b[i], i}]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int, int>
#define EPS 1e-9
const int MXX = 2e5 + 5;

int a[MXX], b[MXX], ans[MXX], bk[MXX];
bool cmp(int i, int j)
{
    return b[i]<b[j];
}
int main ()
{
    int n;cin>>n;
    for(int i = 0; i<n; i++)cin>>a[i];
    sort(a, a + n, greater<int>());
    for(int i = 0; i<n; i++)
    {
        cin>>b[i];
        bk[i] = i;
    }
    sort(bk, bk + n, cmp);
    for(int i = 0; i<n; i++)
    {
        ans[bk[i]] = a[i];
    }
    for(int i = 0; i<n; i++)cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}


/*
   AUTHOR :- Gaurang_Kothiya

   Quote:-" Great things never come from comfort zones."
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map
#define u_m(a,b) unordered_map
#define mm(a,b) multimap
#define s(a) set
#define us(a) unordered_set
#define ms(a) multiset
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007

void solver()
{
	ll n;
	cin>>n;

	v(ll) a(n),b(n);
	fe(x,a) cin>>x;
	fe(x,b) cin>>x;

	v(ll) c(b),d(a);

	sort(all(c));
	sort(all(d));

	reverse(all(d));

	m(ll,deque<ll>) pp;

	f(i,0,n-1)
	{
		pp[c[i]].pub(d[i]);
	}

	fe(x,pp)
	{
		sort(all(x.S));
	}

	f(i,0,n-1)
	{
		cout<< pp[b[i]][0]<<" ";
		pp[b[i]].pof();
	}

}

signed main()
{
	speed;
	ll q=1;
	//cin>>q;
	while(q--)
	solver();
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef signed long long ull;

bool sec(pair<ull,ull>a,pair<ull,ull>b)
{
    return (a.second < b.second);

}

int main()
{
    std::ios::sync_with_stdio(false);

    ull n;
    cin>>n;

    vector<pair<ull,ull>>v;

    ull a[n+2];

    for(ull i=0;i<n;i++)
        cin>>a[i];

    for(ull i=0;i<n;i++)
    {
        ull x;
        cin>>x;

        v.push_back({x,i});
    }

    sort(v.begin(),v.end());
    sort(a,a+n,greater<ull>());

    for(ull i=0;i<n;i++)
        v[i].first=a[i];

    sort(v.begin(),v.end(),sec);

    for(ull i=0;i<n;i++)
        cout<<v[i].first<<" ";

    cout<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef signed long long ull;

bool sec(pair<ull,ull>a,pair<ull,ull>b)
{
    return (a.second < b.second);

}

int main()
{
    std::ios::sync_with_stdio(false);

    ull n;
    cin>>n;

    vector<pair<ull,ull>>v;

    for(ull i=0;i<n;i++)
    {
        ull x;
        cin>>x;

        v.push_back({x,0});
    }

    for(ull i=0;i<n;i++)
    {
        ull x;
        cin>>x;

        v[i].second=x;
    }

    sort(v.begin(),v.end(),sec);

    for(ull i=0;i<n;i++)
        cout<<v[i].first<<" ";

    cout<<endl;

    return 0;
}


//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
//start
using namespace std;
//functions
ll power(ll x,ll y){ll res=1; while(y--){res*=x;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second < b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
ll arr[26];
void solve()
{
    ll n;
    cin>>n;
    vi a(n),b(n);
    vpi c;
    fr(i,0,n)
    {
        cin>>a[i];
    }
    fr(i,0,n)
    {
        cin>>b[i];
        c.pub({b[i],i});
    }
    vi ans(n);
    sort(all(a));
    sort(all(c));
    reverse(all(a));
    fr(i,0,n)
    {
        ans[c[i].ss]=a[i];
    }
    fr(i,0,n)
    {
        cout<<ans[i]<<" ";
    }
}
int main()
{
    fast();
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
}
/*

*/


#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  scanf("%i",&n);
  int a[n],b[n];
  for(int i=0;i<n;i++)scanf("%i",&a[i]);
  for(int i=0;i<n;i++)scanf("%i",&b[i]);
  vector<pair<int,int>> b1(n);
  for(int i=0;i<n;i++){
    b1[i].first=b[i];
    b1[i].second=i;
  }
  sort(b1.begin(), b1.end());
  sort(a,a+n); reverse(a,a+n);
  int ans[n];
  for(int i=0;i<n;i++)ans[b1[i].second]=a[i];
  for(int i=0;i<n;i++)printf("%i ",ans[i]);
}


#pragma GCC optimize ("Ofast")
#include"bits/stdc++.h"
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);
}

#define ll long long
#define pii pair<int,int>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i)
#define int long long int
#define all(n) n.begin(),n.end()
#define mem(n,i) memset(n,i,sizeof n)
#define em(a) emplace_back(a)
#define pb(a) push_back(a)
#define srep(it,vv) for(auto &it : vv)
#define prep(it,vv) for(auto it : vv)
//vector<vector<int>>arr(n + 5, vector<int>(m + 5,0));

typedef vector<int> vii;
typedef vector<string> vss;
/*

*/
signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n; cin >> n;
	vii v1(n), v2(n);

	srep(it, v1) cin >> it;
	srep(it, v2) cin >> it;

	multiset<int>ms;
	prep(it, v1) ms.insert(it);

	prep(it, v2)
	{
		auto itt = lower_bound(all(ms), it);
		cout << *itt << ' ';
		ms.erase(itt);
	}
}


#pragma GCC optimize ("Ofast")
#include"bits/stdc++.h"
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);
}

#define ll long long
#define pii pair<int,int>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i)
#define int long long int
#define all(n) n.begin(),n.end()
#define mem(n,i) memset(n,i,sizeof n)
#define em(a) emplace_back(a)
#define pb(a) push_back(a)
#define srep(it,vv) for(auto &it : vv)
#define prep(it,vv) for(auto it : vv)
//vector<vector<int>>arr(n + 5, vector<int>(m + 5,0));

typedef vector<int> vii;
typedef vector<string> vss;
/*

*/
signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n; cin >> n;
	vii v1(n), v2(n);

	srep(it, v1) cin >> it;

	map<int, multiset<int>> mm1;
	map<int, int>mm;
	srep(it, v2) cin >> it, mm[it]++;

	sort(v1.rbegin(), v1.rend());

	int idx = 0;
	for (auto it : mm)
	{
		int xx = it.ff, yy = it.ss;
		for (int i = idx; i < idx + yy; i++)
		{
			mm1[xx].insert(v1[i]);
		}
		idx = idx + yy;
	}

	for (int it : v2)
	{
		auto itt = mm1[it].begin();
		cout << *itt << ' ';
		mm1[it].erase(itt);
	}
}


/**
 * author : wallcrawler
 **/
// I'm gonna fuck every contest from now on :: Mind it
#include<bits/stdc++.h>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=n-1;i>=0;--i)
#define range(i,p,q) for(ll i=p;i<=q;++i)
#define tci(i,v) for(auto i=v.begin();i!=v.end();++i)
#define tci1(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define all(v) v.begin(),v.end()
#define all1(v) v.rbegin(),v.rend()
#define pb push_back
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld %lld ",&x,&y)
#define sd3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sz size()
#define in insert
#define ve vector
#define pr pair<ll,bool>
#define el "\n"
#define ll long long int
#define N (ll)1e5 + 20
#define T() ll t;cin>>t;while(t--)
// #define _DEBUG 1
using namespace std;
ll inf = pow(10,9)+7;

// okay let's get ready to solve : Timofey and a tree - kakoe, let's get on with it

void solve() {
	long long m;
	cin >> m;
	long long a[m], b[m];
	pair<long long, long long> p[m];
	map< long long, pair<long long, long long> > s;
	for(int i = 0; i < m; i++) sd(a[i]);
	for(int i = 0; i < m; i++) sd(b[i]), p[i] = {b[i], i};
	sort(a, a + m, greater<int>());
	sort(p, p + m);
	for(int i = 0; i < m; i++) {
		s[p[i].second] = {a[i], p[i].first};
	}
	for(auto i : s) printf("%lld ", i.second.first);
}

int main() {
	// fast io
	sync;

	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
		int tt = clock();
	#endif
		cerr << fixed << setprecision(15);

		solve();

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
	#endif
	return 0;
}


/**
 * author : wallcrawler
 **/
// I'm gonna fuck every contest from now on :: Mind it
#include<bits/stdc++.h>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=n-1;i>=0;--i)
#define range(i,p,q) for(ll i=p;i<=q;++i)
#define tci(i,v) for(auto i=v.begin();i!=v.end();++i)
#define tci1(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define all(v) v.begin(),v.end()
#define all1(v) v.rbegin(),v.rend()
#define pb push_back
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld %lld ",&x,&y)
#define sd3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sz size()
#define in insert
#define ve vector
#define pr pair<ll,bool>
#define el "\n"
#define ll long long int
#define N (ll)1e5 + 20
#define T() ll t;cin>>t;while(t--)
// #define _DEBUG 1
using namespace std;
ll inf = pow(10,9)+7;

// okay let's get ready to solve : Timofey and a tree - kakoe, let's get on with it

void solve() {
	long long m;
	sd(m);
	ll a[m], b[m];
	pair<ll, ll> p[m];
	map< ll, pair<ll, ll> > s;
	for(int i = 0; i < m; i++) sd(a[i]);
	for(int i = 0; i < m; i++) sd(b[i]), p[i] = {b[i], i};
	sort(a, a + m, greater<int>());
	sort(p, p + m);
	for(int i = 0; i < m; i++) {
		s[p[i].second] = {a[i], p[i].first};
        //cout << p[i].first << " ";
	}
	for(auto i : s) printf("%lld ", i.second.first);
}

int main() {
	// fast io
	sync;

	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
		int tt = clock();
	#endif
		cerr << fixed << setprecision(15);

		solve();

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
	#endif
	return 0;
}


/**
 * author : wallcrawler
 **/
// I'm gonna fuck every contest from now on ::  Mind it
#include<bits/stdc++.h>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=n-1;i>=0;--i)
#define range(i,p,q) for(ll i=p;i<=q;++i)
#define tci(i,v) for(auto i=v.begin();i!=v.end();++i)
#define tci1(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define all(v) v.begin(),v.end()
#define all1(v) v.rbegin(),v.rend()
#define pb push_back
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld %lld ",&x,&y)
#define sd3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sz size()
#define in insert
#define ve vector
#define pr pair<ll,bool>
#define el "\n"
#define ll long long int
#define N (ll)1e5 + 20
#define T() ll t;cin>>t;while(t--)
// #define _DEBUG 1
using namespace std;
ll inf = pow(10,9)+7;

// okay let's get ready to solve : Timofey and a tree - kakoe, let's get on with it

void solve() {
	long long m;
	sd(m);
	ll a[m], b[m];
	pair<ll, ll> p[m];
	map< ll, pair<ll, ll> > s;
	for(int i = 0; i < m; i++) sd(a[i]);
	for(int i = 0; i < m; i++) sd(b[i]), p[i] = {b[i], i};
	sort(a, a + m, greater<int>());
	sort(p, p + m);
	for(int i = 0; i < m; i++) {
		s[p[i].second] = {a[i], p[i].first};
        //cout << p[i].first << " ";
	}
	for(auto i : s) printf("%lld ", i.second.first);
}

int main() {
	// fast io
	sync;

	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
		int tt = clock();
	#endif
		cerr << fixed << setprecision(15);

		solve();

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
	#endif
	return 0;
}


/* Hello World. Author: IP */
#include<bits/stdc++.h>
#pragma GCC optimize "trapv"
using namespace std;
//#define int                     long long
#define ll                      long long
#define ull                     unsigned long long
#define ld                      long double

#define mp                       make_pair
#define pb                       push_back
#define eb                       emplace_back
#define for0(i,n)                for(int i=0;i<n;++i)
#define fora(i,a,b)              for(int i=a;i<=b;++i)
#define rfor(i,a,b)              for(int i=a;i>=b;--i)

#define endl '\n'
#define vvll                     vector<vector<int>>
#define vll                      vector<int>
#define mii                      map<int,int>
#define msi                      map<string, int>

#define all(v)                   (v.begin(), v.end())
#define sz(x)                    (int)x.size()

#define sint                     set<int>
#define pii                      pair<int,int>
#define pqbig                    priority_queue<int>
#define pqsmall                  priority_queue<int,vi,greater<int> >

#define fi                       first
#define se                       second

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(nullptr);
#define mod 1000000007
const long double PI = acos(-1.0);
//Some functions **********************************************************************************

ll power(ll x, ll y)
{
    if(y==0) return 1;
    ll z = power(x, y/2);
    z = z*z;
    z %= mod;
    return (y&1 ? (z*x)%mod : z);
}
bool prime[400005];
ll fac[10000010];

void fact(){ fac[0]=1; for(int i=1;i<=10000000;i++){ fac[i]=(fac[i-1]*i)%mod;} return; }

void sieve(){ prime[0]=0; prime[1]=0;
    for(int i=2;i<400005;i++)
    {    prime[i]=1; }
    for(int i=2;i*i<400005;i++)
    {
        if(prime[i]==1){ for(int j=i*i;j<400005;j+=i){  prime[j]=0; }}
    }
}
ll siz[500005]; ll par[500005];
ll find(ll u)
{
    if(par[u] == u)
    {
        return u;
    }
    return find(par[u]);
}

void add(ll u, ll v)
{
    ll p1 = find(u); ll p2 = find(v);
    if(p1 == p2) return;
    if(siz[p1] < siz[p2]) swap(p1, p2);
    siz[p1] += siz[p2];
    par[p2] = p1;
    return;
}
// You might start coding here ***********************************************************************

void solve()
{
    int m, i;
	cin>>m;

	int a[m], b[m], ans[m] = {0};

	vector<pair<int,int>> v;
	for(i=0;i<m;i++)
	    cin>>a[i];

	for(i=0;i<m;i++)
	{
	    cin>>b[i];
	    v.push_back({b[i],i});
	}
    //sorting descending order
	sort(a, a+m, greater<int>());
    //now if we want v[i] size subset, then they want maximize over all sigma, mini's, so maxm minimum we can get out, we're good, and save answer(a[i]) in corresponding i.
	sort(v.begin(), v.end());

	for(i=0;i<m;i++)
	{
	    ans[v[i].second] = a[i];
	}
	for(i=0; i<m; i++)
	    cout<<ans[i]<<" ";

}

signed main()
{
    fastio;
    int t=1;
   // cin>>t;
    while(t--)
    {
       solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL , LL> pii;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second

//var
LL m, a[200005], ans[200005];
pii b[200005];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> m;
	FOR(i, m) cin >> a[i];
	FOR(i, m){
		cin >> b[i].f;
		b[i].s = i;
	}
	sort(a+1, a+m+1, greater<LL>());
	sort(b+1, b+m+1);
	FOR(i, m)
		ans[b[i].s] = a[i];

	FOR(i, m)
	cout << ans[i] << ' ';
	cout << endl;

	cout.flush();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
struct node
{
    int num,id;
    bool operator<(node n2)const
    {
        return num<n2.num;
    }
}a[maxn],b[maxn];
int ans[maxn];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i].num);
        a[i].id=i;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i].num);
        b[i].id=i;
    }

    sort(a+1,a+1+n);
    sort(b+1,b+1+n);

    for(int i=1;i<=n;i++)
    {
        ans[b[i].id]=a[n+1-i].num;
    }
    for(int i=1;i<=n;i++)
        printf("%d%c",ans[i],i==n?'\n':' ');
}


//#include <iostream>
//#include <algorithm>
#include<bits/stdc++.h>
using namespace std;

struct node{
long long int num=0;
int site=0;
bool operator < (node n2) const{
return num>n2.num;// <������ ��>�ǽ���
}
}a[200005],b[200005];

int main()
{

   int m=0,i=0;
   long long int ans[100001]={0};
   scanf("%d",&m);
   for(i=0;i<m;i++){
    scanf("%lld",&a[i].num);
    a[i].site=i;
   }
   for(i=0;i<m;i++){
    scanf("%lld",&b[i].num);
    b[i].site=i;
   }

   sort(a,a+m);
   sort(b,b+m);

   for(i=0;i<m;i++){
    ans[b[i].site]=a[m-1-i].num;
   }
   for(i=0;i<m;i++){
      printf("%lld%c",ans[i],i==m-1?'\n':' ');
   }

}


#include <iostream>
#include <algorithm>
using namespace std;

struct node{
long long int num=0;
int site=0;
bool operator < (node n2) const{
return num>n2.num;// <������ ��>�ǽ���
}
}a[100001],b[100001];

int main()
{

   int m=0,i=0;
   long long int ans[100001]={0};
   scanf("%d",&m);
   for(i=0;i<m;i++){
    scanf("%lld",&a[i].num);
    a[i].site=i;
   }
   for(i=0;i<m;i++){
    scanf("%lld",&b[i].num);
    b[i].site=i;
   }

   sort(a,a+m);
   sort(b,b+m);

   for(i=0;i<m;i++){
    ans[b[i].site]=a[m-1-i].num;
   }
   for(i=0;i<m;i++){
      printf("%lld%c",ans[i],i==m-1?'\n':' ');
   }

}


#include <iostream>
#include <algorithm>
//#include<bits/stdc++.h>
using namespace std;

struct node{
long long int num=0;
int site=0;
bool operator < (node n2) const{
return num>n2.num;// <������ ��>�ǽ���
}
}a[200005],b[200005];

int main()
{

   int m=0,i=0;
   long long int ans[200005]={0};
   scanf("%d",&m);
   for(i=0;i<m;i++){
    scanf("%lld",&a[i].num);
    a[i].site=i;
   }
   for(i=0;i<m;i++){
    scanf("%lld",&b[i].num);
    b[i].site=i;
   }

   sort(a,a+m);
   sort(b,b+m);

   for(i=0;i<m;i++){
    ans[b[i].site]=a[m-1-i].num;
   }
   for(i=0;i<m;i++){
      printf("%lld%c",ans[i],i==m-1?'\n':' ');
   }

}


#include <iostream>
#include <algorithm>
using namespace std;

struct node{
long long int num=0;
int site=0;
bool operator < (node n2) const{
return num>n2.num;// <������ ��>�ǽ���
}
}a[200005],b[200005];

int main()
{

   int m=0,i=0;
   long long int ans[100001]={0};
   scanf("%d",&m);
   for(i=0;i<m;i++){
    scanf("%lld",&a[i].num);
    a[i].site=i;
   }
   for(i=0;i<m;i++){
    scanf("%lld",&b[i].num);
    b[i].site=i;
   }

   sort(a,a+m);
   sort(b,b+m);

   for(i=0;i<m;i++){
    ans[b[i].site]=a[m-1-i].num;
   }
   for(i=0;i<m;i++){
      printf("%lld%c",ans[i],i==m-1?'\n':' ');
   }

}


//#include <iostream>
//#include <algorithm>
#include<bits/stdc++.h>
using namespace std;

struct node{
long long int num=0;
int site=0;
bool operator < (node n2) const{
return num<n2.num;// <������ ��>�ǽ���
}
}a[200005],b[200005];

int main()
{

   int m=0,i=0;
   long long int ans[100001]={0};
   scanf("%d",&m);
   for(i=0;i<m;i++){
    scanf("%lld",&a[i].num);
    a[i].site=i;
   }
   for(i=0;i<m;i++){
    scanf("%lld",&b[i].num);
    b[i].site=i;
   }

   sort(a,a+m);
   sort(b,b+m);

   for(i=0;i<m;i++){
    ans[b[i].site]=a[m-1-i].num;
   }
   for(i=0;i<m;i++){
      printf("%lld%c",ans[i],i==m-1?'\n':' ');
   }

}


#include<bits/stdc++.h>
using namespace std;
int c[200005];
int main()
{
    vector<pair<int,int>>x;
    vector<int>a;
    vector<int>b;
    int i,m,n,p;
    cin>>m;
    for(i=0;i<m;i++)
    {
        cin>>n;
        a.push_back(n);
    }
    for(i=0;i<m;i++)
    {
        cin>>n;
        b.push_back(n);
        x.push_back({n,i});
    }
    sort(a.begin(),a.end(),greater<int>());
    sort(x.begin(),x.end());
    for(i=0;i<m;i++)
    {
        p=x[i].second;
        c[p]=a[i];
    }
    for(i=0;i<m;i++)
        cout<<c[i]<<" ";
    cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n;cin>>n;
	vector<int> a(n),b(n);
	for(int &x:a)cin>>x;
	for(int &x:b)cin>>x;
	vector<int> ord(n);
	iota(ord.begin(),ord.end(),0);
	sort(ord.begin(),ord.end(),[&](int i,int j){
		return b[i]<b[j];
	});
	sort(a.rbegin(),a.rend());
	vector<int> ans(n);
	for(int i=0;i<n;i++){
		ans[ord[i]]=a[i];
	}
	for(int x:ans){
		cout<<x<<" ";
	}
	cout<<"\n";
}


#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    int m;
    cin>>m;
    vii a(m),b(m);
    loop(m,i,0)
        cin>>a[i].f,a[i].s=i;
    loop(m,i,0)
        cin>>b[i].f,b[i].s=i;
    sort(allv(a));
    reverse(allv(a));
    sort(allv(b));
    vi res(m);
    loop(m,i,0){
        res[b[i].s]=a[i].f;
    }
    loop(m,i,0)
        cout<<res[i]<<' ';
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


    // Best practice

    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> // Common file
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    #include <functional> // for less

    #define int         long long
    #define pb          emplace_back
    #define pf          emplace_front
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    #define x           first
    #define y           second
    #define endl        '\n'
    #define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    using namespace std;
    using namespace __gnu_pbds;

    typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    #define fbo find_by_order
    #define ook order_of_key

    signed main() {
       tezz

       int n;
       cin >> n;
       vector<int> a(n),b(n);
       for(int i=0; i<n; i++){
           cin >> a[i];
       }
       for(int i=0; i<n; i++){
           cin >> b[i];
       }
       vector<int> c(n);//d(n);
       c=b;
    //   d=b;
       sort(rall(a));
       sort(all(b));
       map<pair<int,int>,int> mp;
       map<int,int> mpp;
       for(int i=0; i<n; i++){
           mp[{b[i],mpp[b[i]]}]=a[i];
           mpp[b[i]]++;
       }
    //   map<int,int> m;
       for(int i=0; i<n; i++){
           mpp[c[i]]--;
           cout << mp[{c[i],mpp[c[i]]}] << " ";

       }

       return 0;
    }


//BISMILLAHIR-RAH-MANIR-RAHIM.
//ABU AYUB MD AHMADUL(CEO-PEREGRINE SPHERE).
//FORMER CEO-SPACEH(2019).
//DEPT.OF CSE,SUST//2018-19.
//------------------------------------------\\
//PRE-CODE========>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<math.h>
#include<numeric>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#define mp make_pair
#define ins insert
#define lli long long int
#define ll long long
#define pb push_back
#define loop1(i,l,n) for(i=l;i<=n;i++)
#define loop0(i,l,n) for(i=l;i<n;i++)
#define inf (1<<28)
#define pi 3.1415926536
const int MAX=1e6+9;
set<int>ist;
map<string,int>msi;
map<string,string>mss;
map<int,string>mis;
map<int,int>mii;
pair<int,int>pii;
vector<int>v;
vector<pair<int,int> >vv;
int cc[]= {1,-1,0,0};
int rr[]= {0,0,1,-1};
//BIPARTITE GRAPH FUCTION========>
/*
int cnt[2];
int vertices[MAX];
void Bipartite(int node,int pnode,int color)
{
    cnt[color]++;
    for (int i=0;i<vertices[node].size();i++)
    {
        if (vertices[node][i]!=pnode)
        {
            Bipartite(vertices[node][i],node,!color);
        }

    }
}
*/
//REAL TIME BINARY SERACH FUNCTION========>
/*
int Bsearch(int left,int right,int query,int n)
{
    int mid=left+(right-left)/2;
    if(query<mid)
    {
        return Bsearch(left,mid-1,query,n);
    }
    else if(query>mid)
    {
        return Bsearch(mid+1,right,query,n-1);
    }
    else
    {
        return n;
    }
}
*/
//DECIMAL TO BINARY DECODING========>
/*
ll D2B(ll dec)
{
    ll digit[32]={};
    ll i = 0;
    while (dec > 0)
    {
        [i] = n % 2;
        n = n / 2;
        i++;
    }

}
*/
//BINARY TO DECIMAL DECODING========>
/*
ll b2d(ll bin)
{
    ll digit,sum=0,h=0;
    while(bin!=0)
    {
        digit=bin%10;
        sum+=digit*pow(2,h++);
        bin/=10;
    }
    return sum;
}
*/
//DFS FUNCTION=========>
/*
int visited[MAX];
vector<int>adj[MAX];
int weight[MAX];
void dfs(int v)
{
    visited[v] = 1;
    for (auto j: adj[v])
    {
        if (!visited[j])
        {
            dfs(j);
        }
    }
}
*/
//------------------------------------------\\
//LAUNCHING SHARK-20========>
void LIFT_OFF_PRONGHORN_MAY20()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t;
    int n;
    cin >> n;
    int ahm[n],sam[n];
    vector<pair<int,int>> v;
    for(int i=0; i<n; i++)
    {
        cin >> ahm[i];
    }
    sort(ahm,ahm+n);
    for(int i=0; i<n; i++)
    {
        cin >> sam[i];
        v.push_back({sam[i],i});
    }
    sort(v.begin(),v.end());
    for(int i=0; i<n; i++)
    {
        sam[v[i].second]=ahm[n-i-1];
    }
    for(int i=0; i<n; i++)
    {
        cout << sam[i] << " ";
    }

}
//MAIN FUNCTION========>
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    LIFT_OFF_PRONGHORN_MAY20();

    return 0;
}
//------------------------------------------\\
//ABOUT THE SERIES========>
//THE PRONGHORN ANTELOPE SERIES-(MAY-2020)-(ENDED).
//SPONSERED BY FALCON AXIS(CEO-NASRULLAH SAMI).
//CONTROLLER=>SAMIA PREITY(CEO-FASTEX AND SPAIT).
//ADVISOR=>NASRULLAH SAMI(CEO-FALCON AXIS).
//CO-CHIEF ADVISOR=>G.M NAYEEM(CEO-TECH FRIGATE).
//PRESIDENT=>NAIMUL ISLAM(CEO-QUANTUM SPACE).


#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
/******************* template *****************************/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/******************* end of template *****************************/
const int MAX=200005;
int tab1[MAX];
pii tab2[MAX];
int ans[MAX];
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
  for (int i=0;i<n;i++)cin>>tab1[i];
  sort(tab1,tab1+n);
  for (int i=0;i<n;i++)cin>>tab2[i].st,tab2[i].nd=i;
  sort(tab2,tab2+n);
  int wskaznik=n-1;
  for (int i=0;i<n;i++)ans[tab2[i].nd]=tab1[wskaznik--];
  for (int i=0;i<n;i++)cout<<ans[i]<<" ";
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second <b.second;
}
int main()
{

    	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("inputf.in", "r", stdin);
        // for writing output to output.txt
        freopen("outputf.in", "w", stdout);
    	#endif
        FastIO

        int n,i;
        cin>>n;
        vi a(n);
        vector<pair<int,int>> b(n);
        for(i=0;i<n;i++) cin>>a[i];
        for(i=0;i<n;i++) cin>>b[i].first,b[i].second=i;

        sort(a.begin(),a.end());
		sort(b.begin(),b.end());

		for(i=0;i<n;i++)
		{
			b[i].first=a[n-1-i];
		}

		sort(b.begin(),b.end(),comp);

		for(i=0;i<n;i++)
			cout<<b[i].first<<" ";
		return 0;
	}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <list>
#include <vector>
#include <ctime>
#include <functional>
#include <ostream>
#include <fstream>
#include <climits>
#include <numeric>
#include <memory>
#include <numeric>
#include <iterator>
#include <iomanip>
#include <functional>
#include <bitset>

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;

//const ll posinf = 9223372036854775807LL;
//const ll neginf = 9223372036854775808LL;
const ll bigprime = (1LL << 61) - 1LL;
const ll mult  =  199;
const ll mult2 = 3571;
const ll mod  = 1000000007LL;
const ll mod2 = 1000000009LL;
const ld PI = acos(-1);

#ifdef OFFLINE_JUDGE
#define PROFBEG(wh) auto t1##wh = chrono::high_resolution_clock::now ();
#define PROFEND(wh) auto t2##wh = chrono::high_resolution_clock::now (); \
    chrono::duration<double> dur##wh = chrono::duration_cast<chrono::duration<double> > (t2##wh - t1##wh); \
    cout << endl << "time " << dur##wh.count () << endl;
#else
#define PROFBEG(wh)
#define PROFEND(wh)
#endif

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;

int main() {
	#ifdef OFFLINE_JUDGE
	       freopen ("input.txt", "r", stdin);
	       freopen ("output.txt", "w", stdout);
    #else
         //freopen (".in", "r", stdin);
         //freopen (".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
	cin >> n;

	vector<int> arr;
	vector< pair<int , int > > brr;

	int x;
	for(int i = 0 ; i < n ; i++) {
		cin >> x;
		arr.push_back(x);
	}

	for(int i = 0 ; i < n ; i++) {
		cin >> x;
		brr.push_back({x , i});
	}

	sort(arr.rbegin() , arr.rend());
	sort(brr.begin() , brr.end());

	vector<int> ans(n);
	for(int i = 0 ; i < n ; i++) {
		ans[brr[i].second] = arr[i];
	}

	for(int i = 0 ; i < n ; i++)
		cout << ans[i] << " ";

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <list>
#include <vector>
#include <ctime>
#include <functional>
#include <ostream>
#include <fstream>
#include <climits>
#include <numeric>
#include <memory>
#include <numeric>
#include <iterator>
#include <iomanip>
#include <functional>
#include <bitset>

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;

//const ll posinf = 9223372036854775807LL;
//const ll neginf = 9223372036854775808LL;
const ll bigprime = (1LL << 61) - 1LL;
const ll mult  =  199;
const ll mult2 = 3571;
const ll mod  = 1000000007LL;
const ll mod2 = 1000000009LL;
const ld PI = acos(-1);

#ifdef OFFLINE_JUDGE
#define PROFBEG(wh) auto t1##wh = chrono::high_resolution_clock::now ();
#define PROFEND(wh) auto t2##wh = chrono::high_resolution_clock::now (); \
    chrono::duration<double> dur##wh = chrono::duration_cast<chrono::duration<double> > (t2##wh - t1##wh); \
    cout << endl << "time " << dur##wh.count () << endl;
#else
#define PROFBEG(wh)
#define PROFEND(wh)
#endif

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;

main() {
	#ifdef OFFLINE_JUDGE
	       freopen ("input.txt", "r", stdin);
	       freopen ("output.txt", "w", stdout);
    #else
         //freopen (".in", "r", stdin);
         //freopen (".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
	cin >> n;

	vector<int> arr;
	vector< pair<int , int > > brr;

	int x;
	for(int i = 0 ; i < n ; i++) {
		cin >> x;
		arr.push_back(x);
	}

	for(int i = 0 ; i < n ; i++) {
		cin >> x;
		brr.push_back({x , i});
	}

	sort(arr.rbegin() , arr.rend());
	sort(brr.begin() , brr.end());

	vector<int> ans(n);
	for(int i = 0 ; i < n ; i++) {
		ans[brr[i].second] = arr[i];
	}

	for(int i = 0 ; i < n ; i++)
		cout << ans[i] << " ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
struct ram
{
    ll a;
    ll b;
    ll i;
};
bool com(ram n1,ram n2)
{
    return n1.b<n2.b;
}
bool com1(ram n1,ram n2)
{
    return n1.i<n2.i;
}
int main()
{
    ll m;
    cin>>m;
    vector<ram>keyur;
    ll a[m],b[m];
    for(ll i=0;i<m;i++)
        cin>>a[i];
    for(ll i=0;i<m;i++)
        cin>>b[i];
    for(ll i=0;i<m;i++)
    {
        keyur[i].a=a[i];
        keyur[i].b=b[i];
        keyur[i].i=i;
    }
    sort(a,a+m);
    reverse(a,a+m);
    sort(keyur.begin(),keyur.end(),com);
    for(ll i=0;i<m;i++)
    {
        keyur[i].a=a[i];
    }
    sort(keyur.begin(),keyur.end(),com1);
    for(ll i=0;i<m;i++)
        cout<<keyur[i].a<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
struct ram
{
    ll a;
    ll b;
    ll i;
};
bool com(ram n1,ram n2)
{
    return n1.b<n2.b;
}
bool com1(ram n1,ram n2)
{
    return n1.i<n2.i;
}
int main()
{
    ll m;
    cin>>m;
    vector<ram>keyur(m);
    ll a[m],b[m];
    for(ll i=0;i<m;i++)
        cin>>a[i];
    for(ll i=0;i<m;i++)
        cin>>b[i];
    for(ll i=0;i<m;i++)
    {
        keyur[i].a=a[i];
        keyur[i].b=b[i];
        keyur[i].i=i;
    }
    sort(a,a+m);
    reverse(a,a+m);
    sort(keyur.begin(),keyur.end(),com);
    for(ll i=0;i<m;i++)
    {
        keyur[i].a=a[i];
    }
    sort(keyur.begin(),keyur.end(),com1);
    for(ll i=0;i<m;i++)
        cout<<keyur[i].a<<" ";
    return 0;
}


/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
# define ll unsigned long long
# define int long long//comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000007
//# define MOD 163577857
# define pii pair<int,int>
# define pi acos(-1)
# define fi first
# define se second
const ll mod = 1e9 + 7;
//const int K = 2;
//typedef vector<vector<int> > matrix;
/*
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	a += mod;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}

ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}
*/

signed main() {
	gok

	int n;
	cin>>n;
	pii a[n],b[n];
	for(int i=0;i<n;i++){
        cin>>a[i].fi;
     a[i].se=i;
	}

    for(int i=0;i<n;i++){
        cin>>b[i].fi;
       b[i].se = i;
    }
    int re[n];
    sort(a,a+n);
    sort(b,b+n);

    int st=0;

    while(st<n)
    {
        re[b[st].se] = a[n-st-1].fi;
        st++;
    }
    for(int i=0;i<n;i++)
        cout<<re[i]<<" ";

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
const ll N=2*1e5+1;
#define ull unsigned long long int
#define f(a,b) for(ll i=a;i<b;i++)
#define f1(a,b) for(ll i=a;i<=b;i++)
#define fd(a,b) for(ll i=a;i>=b;i--)
#define fj(j,a,b) for(ll j=a;j<b;j++)
#define fk(k,a,b) for(ll k=a;k<b;k++)
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vp vector<pair<int,int>>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define alld(v) v.begin(), v.end(),greater<int>()
#define sz(v) v.size()
#define endl "\n"
#define ff first
#define ss second

int a[N],b[N],c[N],d[N],ans[N];
bool cmp(int i,int j)
{
	return a[i]<a[j];
}
bool cmp2(int i,int j)
{
	return b[i]>b[j];
}

void solve()
{
    int n,m,k,p=0,q=0,s=0,i,j;
    cin>>n;
    f(0,n)
        cin>>a[i];
    f(0,n)
        cin>>b[i],
        c[i]=i,d[i]=i;

	sort(c,c+n,cmp);
	sort(d,d+n,cmp2);

	f(0,n)
		ans[d[i]]=a[c[i]];
	f(0,n)
		cout<<ans[i]<<" ";
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;

void solve()
{
    int m;
    cin >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i];
    sort(a.begin(), a.end(), greater<int>());
    vector<int> c = b;
    sort(c.begin(), c.end());
    multimap<int, int> se;
    for (int i = 0; i < m; i++)
    {
        se.insert({ b[i],i });
    }
    for (int i = 0; i < m; i++)
    {
        auto it = se.find(c[i]);
        cout << a[(int)it->second] << " ";
        se.erase(it);
    }
    cout << "\n";

}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    solve();

    return 0;
}


#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;

void solve()
{
    int m;
    cin >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i];
    sort(a.begin(), a.end(), greater<int>());
    vector<int> c = b;
    sort(c.begin(), c.end());
    multimap<int, int> se;
    for (int i = 0; i < m; i++)
    {
        se.insert({ c[i],i });
    }
    for (int i = 0; i < m; i++)
    {
        auto it = se.find(b[i]);
        cout << a[(int)it->second] << " ";
        se.erase(it);
    }
    cout << "\n";

}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[200005];
ll b[200005];
int main()
{
    ll m;
    cin>>m;
    vector<pair<ll,ll>> v;
    for(ll i=0 ; i<m ; i++)
    {
        cin>>a[i];
       // v.push_back(make_pair(a[i],i));
    }
    for(ll i=0 ; i<m ; i++)
    {
        cin>>b[i];
        v.push_back(make_pair(b[i],i));
    }
    sort(v.begin(),v.end());
    sort(a,a+m,greater<ll>());
    for(ll i=0 ; i<m ; i++)
    {
        b[v[i].second] = a[i];
    }
    for(ll i=0 ; i<m ; i++)
        cout<<b[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[200005];
ll b[200005];
ll t[200005];
vector<ll> g[200005];
int main()
{
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<n;i++){
        cin>>b[i];
        t[i] = b[i];
    }
    sort(a,a+n,greater<int>());
    sort(t,t+n);
    for(ll i=0 ; i<n ; i++)
    {
        g[t[i]].push_back(a[i]);
    }
    for(ll i=0 ; i<n ; i++)
    {
        cout<<g[b[i]][g[b[i]].size()-1]<<" ";
        g[b[i]].pop_back();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[200005];
ll b[200005];
ll t[200005];
vector<ll> g[200005];
int main()
{
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<n;i++){
        cin>>b[i];
        t[i] = b[i];
    }
    sort(a,a+n,greater<ll>());
    sort(t,t+n);
    for(ll i=0 ; i<n ; i++)
    {
        g[t[i]].push_back(a[i]);
    }
    for(ll i=0 ; i<n ; i++)
    {
        cout<<g[b[i]][g[b[i]].size()-1]<<" ";
        g[b[i]].pop_back();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[200005];
ll b[200005];
ll t[200005];
vector<ll> g[200005];
int main()
{
    ios_base:: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<n;i++){
        cin>>b[i];
        t[i] = b[i];
    }
    sort(a,a+n,greater<ll>());
    sort(t,t+n);
    for(ll i=0 ; i<n ; i++)
    {
        g[t[i]].push_back(a[i]);
    }
    for(ll i=0 ; i<n ; i++)
    {
        cout<<g[b[i]][g[b[i]].size()-1]<<" ";
        g[b[i]].pop_back();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fore(i,n) for(ll i=1;i<=n;i++)
#define forl(i,n) for(ll i=0;i<n;i++)
#define forn(i,n) for(ll i=n-1;i>=0;i--)
#define tc ll q;cin>>q;while(q--)

//**********************************
int main(){
    #ifndef ONLINE_JUDGE
        freopen("./input.txt", "r", stdin);
        freopen("./output.txt", "w", stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n],b[n];
    forl(i,n){
        cin>>a[i];
    }
    forl(i,n){
        cin>>b[i];
    }
    map<ll,vector<ll>> mb,ma;
    forl(i,n){
        mb[b[i]].push_back(i);
        ma[a[i]].push_back(i);
    }
    sort(b,b+n);
    sort(a,a+n);reverse(a,a+n);
    map<ll,ll> cc;
    ll ans[n];
    forl(i,n){
        ans[mb[b[i]][cc[b[i]]]]=a[i];
        cc[b[i]]++;
    }
    forl(i,n){
        cout<<ans[i]<<' ';
    }

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200005] , ans[200005];
vector < pair < ll , ll > > b;
int main(){
    ll n , i;
    cin >> n;
    for(i = 1;i<=n;i++)
        cin >> a[i];
    for(i = 1;i<=n;i++){
        ll z;
        cin >> z;
        b.push_back({z , i});
    }
    sort(a + 1 , a + n + 1);
    reverse(a + 1 , a + n + 1);
    sort(b.begin() , b.end());
    for(i = 0;i<n;i++)
        ans[ b[i].second ] = a[i + 1];
    for(i = 1;i<=n;i++)
        cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//VIKRAMC
/*
“Spring will be here soon.
Spring, the season I met you, is coming.
A spring without you...
...is coming.”
― Kosei Arima

**** Summertime Sadness****
*/
#define PEACE std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define modd 998244353
#define PI 3.14159265358979323844
//#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc (v) max_element(all(v))
#define minc(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
#define display(x) trav(aaaa,x) cout<<aaaa<<" ";cout<<endl

#define ll long long int
typedef long double ld;
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >
const ll INF = 1LL << 60;
const ll N = 5e5 + 5;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

ll n, m, k, x, y, z, q;

int mod = 1e9 + 7;

ll add(ll a, ll b) {
	if (a + b >= mod)return a + b - mod;
	return a + b;
}
ll sub(ll a, ll b) {
	if (a < b)return a - b + mod;
	return a - b;
}
ll mul(ll a, ll b) {
	return 1LL * a * b  % mod;
}
ll power(ll a, ll b) {
	if (b < 0)return 0;
	int re = 1;
	while (b) {
		if (b & 1) {
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}

bool sortbysec(const pair<ll, ll> &a,
               const pair<ll, ll> &b)
{
	return (a.second < b.second);
}

bool sortbyfi(const pair<ll, pair<ll, ll> > &a,
              const pair< ll, pair<ll, ll>> &b)
{
	return (a.fi > b.fi);
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> ppq;
//---------------------------------------------------------------

// I am a real noobie

ll bs(vector <ll> v, ll x)
{
	ll hi = v.size() - 1, lo = 0;
	while (hi >= lo)
	{
		ll mid = lo + (hi - lo) / 2;

		if (v[mid] == x) return 1;
		else if (v[mid] < x) lo = mid + 1;
		else hi = mid - 1;
	}
	return 0;
}

bool paired(char a , char b)
{
	if (a == '[' and b == ']') return true;
	if (a == '{' and b == '}') return true;
	if (a == '(' and b == ')') return true;
	if (a == '<' and b == '>') return true;
	return false;
}

bool cmp(pair <ll, vector <ll>> a, pair <ll, vector <ll> > b)
{
	return a.fi > b.fi;
}
/*
ll bit[N] = {0};

void update(ll idx, ll val)
{
    while(idx<=100000)
    {
        bit[idx]+=val;
        idx+=idx&-idx;
    }
}

ll pref(ll idx)
{
    ll ans = 0;
    while(idx>0)
    {
        ans += bit[idx];
        idx-=idx&-idx;
    }
    return ans;
}

ll rsum(ll l, ll r)
{
    return pref(r) - pref(l-1);
}

ll mEx(ll x, ll n, ll mod)
{
	if (n == 0)
		return 1;
	else if (n % 2 == 0)     //n is even
		return mEx((x * x) % mod, n / 2, mod);
	else                             //n is odd
		return (x * mEx((x * x) % mod, (n - 1) / 2, mod)) % mod;

}
ll inv(ll x)
{
	return mEx(x, modd - 2, modd);
}

ll parent[N], Rank[N], cunt[N];
void makeset(ll x)
{
	parent[x] = x;
	Rank[x] = 0;
	cunt[x] = 1;
}

ll findset(ll x) {
	if (x == parent[x]) return x;
	return parent[x] = findset(parent[x]);
}

void unionset(ll a, ll b)
{
	ll x = a, y = b;
	a = findset(a);
	b = findset(b);

	if (a != b)
	{
		if (Rank[a] < Rank[b]) swap(a, b);

		parent[b] = a;
		cunt[a] += cunt[b];
		if (Rank[a] == Rank[b]) Rank[a]++;
	}
}

vector <vector <ll>> g(N);
int vis[N], indeg[N];
ll a[N], b[N];
ld c[N];
vector <ll> vv;
ll cnt = 0, mincycle = 1e9;
ld mx = 0;

ll dfs(ll u)
{
	vis[u] = 1;
	++cnt;

	for (auto v : g[u])
	{
		if (vis[v] or mx != c[v]) continue;
		dfs(v);
	}
	vv.pb(u);
	return 0;
}
/*
ll dfs2(ll u, ll cc)
{
	comp[u] = cc;
	for (auto v : gr[u])
	{
		if (comp[v]) continue;
		dfs2(v, cc);
	}

	return 0;
}

/*

vector <pll> V(N);
void dijkstra(ll src)
{
  for(ll i=1;i<=n;i++) dis[i] = INF;
  dis[src] = 0;

  set <pll> q;
  q.insert({0,src});

  while(!q.empty())
  {
    ll v = q.begin()->se;
    q.erase(q.begin());

    for(auto edge:g[v])
    {
      ll to = edge.se;
      ll len = edge.fi;

      if(dis[v]+len<dis[to])
      {
        q.erase({dis[to],to});
        dis[to] = dis[v]+len;
        q.insert({dis[to],to});
        V[to] = {len,v};
      }
      else if(dis[v]+len==dis[to])
      {
        if(len<V[to].fi) V[to] = {len,v};
      }
    }
  }
}
*/

/*

void bfs(ll src)
{
  rep(i,n+1) dis[i] = INF;
  queue <ll> q;
  dis[src] = 0;
  q.push(src);

  while(!q.empty())
  {
    ll u = q.front();
    q.pop();

    for(auto v:g[u])
    {
      if(dis[v]==INF)
      {
        dis[v] = dis[u] + 1;
        q.push(v);
      }
    }
  }
}
*/
/*
int visi[501][501];
void flow(ll i, ll j)
{
	if (i<0 or i >= n or j<0 or j >= m) return;
	if (a[i][j] == '#' or visi[i][j]) return;
	//cout << i << " " << j  << endl;
	ans.pb({i, j});
	visi[i][j] = 1;

	flow(i + 1, j);
	flow(i - 1, j);
	flow(i, j + 1);
	flow(i, j - 1);
}
*/

bool bs(ld xx)
{
	ll sb = xx / (x * y);
	ll sb1 = xx / x;
	ll sb2 = xx / y;

	if ((xx - sb1) < n or (xx - sb2) < m) return false;

	xx -= sb;

	ll sum = m + n;
	return sum <= xx;
}

bool cmpp(pair <pll, ll> a, pair <pll, ll>  b)
{
	if (a.fi.fi == b.fi.fi)
		return a.fi.se < b.fi.se;
	return a.fi.fi > b.fi.fi;

}

//REAL CODE
void Birdperson()
{
	cin >> n;
	vector <ll> a(n), ans(n);
	vector <pll> b(n);
	rep(i, n) cin >> a[i];
	sort(ALL(a), greater<ll>());
	rep(i, n) cin >> x, b[i] = {x, i};
	sort(ALL(b));

	rep(i, n)
	{
		ans[b[i].se] = a[i];
	}

	display(ans);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	PEACE
	ll t = 1;
	ll ct = 1;

	while (ct <= t)
	{	//cout << "Case #" << ct << ": ";

		Birdperson();

		++ct;
	}

}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
 #include<bits/stdc++.h>
 #include<cstdlib>
    #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
    #define ll long long
    #define forn(i,n) for (int i = 0; i < int(n); i++)
    using namespace std;
     template <class nmsl> inline void read(nmsl &x)
{
	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}

    int main()
    {
    	Boost();
    	int m;
    	cin>>m;
    	int a[m];
    	int b[m];
    	int i;
    	int tem[m];
    	forn(i,m)
    	cin>>a[i];
    	forn(i,m)
    	{
    	cin>>b[i];
    	tem[i]=b[i];
    	}
    	sort(a,a+m,greater<int>());
    	sort(b,b+m);
    	map<int,multiset<int> > ma;
    	forn(i,m)
    	{
    		ma[b[i]].insert(a[i]);
		}
	    multiset<int>::iterator it;
		forn(i,m)
		{
			it=ma[tem[i]].begin();
			if(it!=ma[tem[i]].end())
			{
			    	cout<<*it<<" ";
			ma[tem[i]].erase(it);
			}

		}
		return 0;
	}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 200010;
int n, a[N], ans[N];
pair<int, int> b[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    cin >> b[i].first;
    b[i].second = i;
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n);
  for (int i = n; i >= 1; --i) {
    ans[b[i].second] = a[n-i+1];
  }
  for (int i = 1; i <= n; ++i) cout << ans[i] << " ";
  cout << '\n';
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<cstdio>
#include<cassert>
#include<sstream>
#include<set>

#define int long long int

using namespace std;

signed main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<pair<int, int>> b(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    for(int i = 0; i < n; i++){
        cin >> b[i].first;
        b[i].second = i;
    }
    sort(a.rbegin(), a.rend());
    sort(b.begin(), b.end());
    vector<int> c(n);
    for(int i = 0; i < n; i++)c[b[i].second] = a[i];
    for(auto i : c)cout << i << " ";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
int main()
{
        ll n;cin>>n;
        ll a[n],b[n];
        for(ll i=0;i<n;++i)
        cin>>a[i];
		vector<pair<ll,ll> >v1;
		for(ll i=0;i<n;++i)
		{
			cin>>b[i];
			v1.push_back(make_pair(b[i],i));
		}
		sort(v1.begin(),v1.end());
		sort(a,a+n);
		ll ans[n]={0};
		for(ll i=0;i<n;++i)
		ans[v1[i].second]=a[n-i-1];
		for(ll i=0;i<n;++i) cout<<ans[i]<<" ";
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
int main()
{
        ll n;cin>>n;
        ll a[n],b[n];
        for(ll i=0;i<n;++i)
        cin>>a[i];
        for(ll i=0;i<n;++i)
        cin>>b[i];
		ll c[n],d[n];
		for(ll i=0;i<n;++i) c[i]=a[i];
		for(ll i=0;i<n;++i) d[i]=b[i];
		sort(c,c+n);
		sort(d,d+n);
		ll ans[n]={0};
		for(ll i=0;i<n;++i)
		{
			for(ll j=0;j<n;++j)
			{
				if(d[i]==b[j]&&ans[j]==0)
				{
					ans[j]=c[n-1-i];
					break;
				}
			}
		}
		for(ll i=0;i<n;++i) cout<<ans[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define gcd(x,y) __gcd((x),(y))

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const ld EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9+7, MOD2 = 2e9+11;
const int N = 1e5+5;
//vector<vector<int>> matrix(row,vector<int>(col));
// cout << std::setprecision(10) << std::fixed << variableLD;

bool func(pair<int,int> a,pair<int,int> b){
    if(a.st>b.st) return true;
    else if(a.st==b.st){
        if(a.nd<b.nd) return true;
        else return false;
    }else   return false;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n,aux;
    cin >> n;
    vector<int> a,c(n,0);
    vector<pair<int,int>> b;
    for(int i=0;i<n;i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i=0;i<n;i++){
        cin >> aux;
        b.push_back(mp(aux,i));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end(),func);
    for(int i=0;i<n;i++){
        aux = b[b.size()-1].nd;
        c[aux] = a[a.size()-1];
        a.pop_back();
        b.pop_back();
    }

    for(int i=0;i<n;i++){
        cout << c[i] << " ";
    }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct Int
{
    int x,y;
};
bool com(Int i1, Int i2)
{
    return (i1.x < i2.x);
}

int main()
{
    int n,c=0,k=0;
    cin>>n;
    int a[n],i;
    unordered_map<int,int>mp;
    Int b[n];
    for(i=0;i<n;i++) cin>>a[i];
     for(i=0;i<n;i++) {cin>>b[i].x; b[i].y=i;}
     sort(a,a+n);
     sort(b,b+n,com);
    for(i=n-1;i>=0;i--){mp[b[k++].y]=a[i];}
    for(i=0;i<n;i++)
    cout<<mp[i]<<" ";
}