To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that the programs that work with fractions in this representations aren't complete, they lack supporting the operation of reducing fractions. Implement this operation and the Empire won't forget you.
The first input line contains two space-separated integers *n*, *m* (1 ≤ *n*, *m* ≤ 10<sup class="upper-index">5</sup>) that show how many numbers the first set (the numerator) and the second set (the denominator) contain, correspondingly.

The second line contains *n* space-separated integers: *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">7</sup>) — the numbers that are multiplied to produce the numerator.

The third line contains *m* space-separated integers: *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*m*</sub> (1 ≤ *b*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">7</sup>) — the numbers that are multiplied to produce the denominator.
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect, insort
from time import perf_counter
from fractions import Fraction
import copy
from copy import deepcopy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
    # sys.setrecursionlimit(int(pow(10,6)))
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("../output.txt", "w")
except:
    pass
def pmat(A):
    for ele in A: print(*ele,end="\n")

from sys import stdin
input = stdin.buffer.readline
# I = lambda : list(map(int,input().split()))

# import sys
# input=sys.stdin.readline

def main():
    
 
 
    #for _ in range(ii()):
 
    
    n,m=L()
    a=L()
    b=L()
 
 
    seive=[1]*(10000000+5)
    prime=[0]*(10000000+5)
 
    for i in range(2,10000000+5):
        if seive[i]:
            for j in range(i,10000005,i):
                seive[j]=0
                prime[j]=i
 
 
 
 
 
 
 
    f={}
    g={}
 
    for k in range(n):
 
        x=a[k]
 
        while x>1:
 
            p=prime[x]
            x//=prime[x]
            if f.get(p,0)==0:
                f[p]=1
            else:
                f[p]+=1
 
    for k in range(m):
 
        x=b[k]
 
        while x>1:
 
            p=prime[x]
            x//=prime[x]
            if g.get(p,0)==0:
                g[p]=1
            else:
                g[p]+=1
    
 
    
 
    # print(f)
    # print(g)
    
 
 
    num={}
    for i,j in f.items():
 
        p=g.get(i,0)
 
        if j>p:
            num[i]=j-p
    
    deno={}
    for i,j in g.items():
 
        p=f.get(i,0)
 
        if j>p:
            deno[i]=j-p
    
 
 
    xx=[]
    yy=[]
 
 
    for i in range(n):
        x=a[i]
        pro=1
        while x>1:
 
            p=prime[x]
            if num.get(p,0)!=0:
                pro*=p
                num[p]-=1
            x//=p
 
        xx.append(pro)
 
 
    for i in range(m):
        x=b[i]
        pro=1
        while x>1:
 
            p=prime[x]
            if deno.get(p,0)!=0:
                pro*=p
                deno[p]-=1
            x//=p
 
        yy.append(pro)
 
 
 
    print(len(xx),len(yy))
    print(*xx)
    print(*yy)

main()