#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[1000000],b[1000000],i=1,sum=0,gtln=INT_MIN;
int freq[1000000];
string s;
struct T
{
    int mauso;
    int tuso;
    double ketqua;
    bool operator <(const T &x) const {return ketqua<x.ketqua;}
}q[1000000];
int ucln(int a,int b)
{
    int r;
    while (b!=0)
    {
        r=a%b;
        a=b;b=r;
    }
    return a;
}
int d=0,dem=0;
int main()
{
    freopen("Phanso.inp","r",stdin);
    freopen("Phanso.out","w",stdout);
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>q[i].tuso;
    }
    for (int i=0;i<n;i++)
    {
        cin>>q[i].mauso;
    }
    for (int i=0;i<n;i++)
    {
        k=ucln(q[i].tuso,q[i].mauso);
        q[i].tuso=q[i].tuso/k;
        q[i].mauso=q[i].mauso/k;
        q[i].ketqua=(double)(q[i].tuso)/(double)(q[i].mauso);
    }
    sort(q,q+n);
    for (int i=0;i<n;i++)
    {
        cout<<q[i].tuso<<" ";
    }
    cout<<endl;
    for (int i=0;i<n;i++)
        cout<<q[i].mauso<<" ";
}
