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, math
from os import path
# from TestCaseGen import test

INF = math.inf

if(path.exists('input.txt')):
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")

def precompute():
    m = 10**7
    spf = [0 for size in range(m+1)]
    i = 2
    while i*i <= m:
        if spf[i] == 0:
            spf[i] = i
            for j in range(i*i, m+1, i):
                spf[j] = i
        i += 1
    return spf

def solve(n, m, a, b, spf):
    freq_a, freq_b = {}, {}
    for num in a:
        while num != 1:
            x = spf[num]
            freq_a[x] = 1 + freq_a.get(x, 0)
            num //= x
    new_a, new_b = [1], [1]
    for num in b:
        while num != 1:
            x = spf[num]
            freq_b[x] = 1 + freq_b.get(x, 0)
            num //= x
    # print(freq_a)
    # print(freq_b)
    for key in freq_a:
        if key in freq_b:
            if freq_a[key] >= freq_b[key]:
                freq_a[key] -= freq_b[key]
                freq_b[key] = 0
            else:
                freq_b[key] -= freq_a[key]
                freq_a[key] = 0
        while freq_a[key] > 0:
            x = min(int(math.log(10**7, key)), freq_a[key])
            freq_a[key] -= x
            new_a.append(key**x)
    for key in freq_b:
        if key not in freq_a:
            while freq_b[key] > 0:
                x = min(int(math.log(10**7, key)), freq_b[key])
                freq_b[key] -= x
                new_b.append(key**x)
    print(len(new_a), len(new_b))
    printList(new_a)
    printList(new_b)

def main():
    # test(10, -100, 100, 10)
    spf = precompute()
    for _ in range(1):
        n, m = getInts()
        a = getList()
        b = getList()
        solve(n, m, a, b, spf)
        










################## UTILITY FUNCTIONS #######################

def getInt():
    return int(sys.stdin.readline().strip())

def getInts():
    return map(int, sys.stdin.readline().strip().split())

def getList():
    return list(map(int, sys.stdin.readline().strip().split()))

def getString():
    return sys.stdin.readline().strip()

def printInt(n):
    sys.stdout.write(str(n) + '\n')

def printList(arr):
    sys.stdout.write(' '.join(map(str, arr)) + '\n')

def printString(s):
    sys.stdout.write(s + '\n')

main()
