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.

Input

The first input line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) 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: a1, a2, ..., an (1 ≤ ai ≤ 107) — the numbers that are multiplied to produce the numerator.

The third line contains m space-separated integers: b1, b2, ..., bm (1 ≤ bi ≤ 107) — the numbers that are multiplied to produce the denominator.

Output

Print the answer to the problem in the form, similar to the form of the input data. The number of values in the sets you print nout, mout must satisfy the inequality 1 ≤ nout, mout ≤ 105, and the actual values in the sets aout, i and bout, i must satisfy the inequality 1 ≤ aout, i, bout, i ≤ 107. 

Separate the values in the lines by spaces. The printed fraction must be reduced, that is, there mustn't be such integer x (x > 1), that the numerator and the denominator of the printed fraction are divisible by x. If there are several matching answers, print any of them.

Examples

Input

3 2
100 5 2
50 10


Output

2 3
2 1
1 1 1


Input

4 3
2 5 10 20
100 1 3


Output

1 1
20
3

Note

In the first test sample the numerator equals 1000, the denominator equals 500. If we reduce fraction 1000/500 by the greatest common divisor of the numerator and the denominator (by 500), we obtain fraction 2/1.

In the second test sample the numerator equals 2000, the denominator equals 300. If we reduce fraction 2000/300 by the greatest common divisor of the numerator and the denominator (by 100), we obtain fraction 20/3.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Mathematics

Number theory

Sorting

Implementation


Solutions:
from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def factor(n, dic1):
	while n % 2 == 0:
		if 2 not in dic1:
			dic1[2] = 1
		else:
			dic1[2] += 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			if i not in dic1:
				dic1[i] = 1
			else:
				dic1[i] += 1
			n = n // i
	if n > 2:
		if n not in dic1:
			dic1[n] = 1
		else:
			dic1[n] += 1

def factor1(n, dic2):
	while n % 2 == 0:
		if 2 not in dic2:
			dic2[2] = 1
		else:
			dic2[2] += 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		if n % i == 0:
			while n % i == 0:
				if i not in dic2:
					dic2[i] = 1
				else:
					dic2[i] += 1
				n = n // i
	if n > 2:
		if n not in dic2:
			dic2[n] = 1
		else:
			dic2[n] += 1
(n, m) = map(int, input().split())
dic1 = {}
dic2 = {}
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
for i in range(0, len(a)):
	factor(a[i], dic1)
for i in range(0, len(b)):
	factor1(b[i], dic2)
ans1 = [1] * n
ans2 = [1] * m
fac1 = []
fac2 = []
for key in dic1:
	if key in dic2:
		if dic1[key] >= dic2[key]:
			dic1[key] -= dic2[key]
			dic2[key] = 0
		elif dic2[key] > dic1[key]:
			dic2[key] -= dic1[key]
			dic1[key] = 0
fac11 = []
fac22 = []
for key in dic1:
	fac11.append([key, dic1[key]])
for key in dic2:
	fac22.append([key, dic2[key]])
fac11.sort(reverse=True)
fac22.sort(reverse=True)
j = 0
for i in range(0, len(fac11)):
	while fac11[i][1] > 0:
		if ans1[j] * fac11[i][0] <= 10 ** 7:
			ans1[j] = ans1[j] * fac11[i][0]
			fac11[i][1] -= 1
		j = (j + 1) % n
j = 0
for i in range(0, len(fac22)):
	while fac22[i][1] > 0:
		if ans2[j] * fac22[i][0] <= 10 ** 7:
			ans2[j] = ans2[j] * fac22[i][0]
			fac22[i][1] -= 1
		j = (j + 1) % m
print(len(ans1), len(ans2))
print(*ans1)
print(*ans2)


import os
from io import BytesIO, IOBase
import sys
from collections import Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor

def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = ceil(sqrt(max(max(a), max(b))))
	p = [1] * (z + 1)
	i = 2
	while i * i <= z:
		if p[i] == 1:
			j = i * i
			while j <= z:
				p[j] = 0
				j += i
		i += 1
	pr = []
	for i in range(2, z + 1):
		if p[i]:
			pr.append(i)
	f = Counter()
	f1 = Counter()
	c = [[] for i in range(n)]
	d = [[] for i in range(m)]
	for (i, v) in enumerate(a):
		(y, z) = (ceil(sqrt(v)), v)
		for j in pr:
			if j > y:
				break
			x = 0
			while z % j == 0:
				f[j] += 1
				x += 1
				z = z // j
			if x:
				c[i].append([j, x])
		if z > 1:
			c[i].append([z, 1])
			f[z] += 1
	for (i, v) in enumerate(b):
		(y, z) = (ceil(sqrt(v)), v)
		for j in pr:
			if j > y:
				break
			x = 0
			while z % j == 0:
				f1[j] += 1
				x += 1
				z = z // j
			if x:
				d[i].append([j, x])
		if z > 1:
			d[i].append([z, 1])
			f1[z] += 1
	e = []
	for i in f:
		(f[i], f1[i]) = (max(f[i] - f1[i], 0), max(f1[i] - f[i], 0))
		if f[i] == 0:
			e.append(i)
		if f1[i] == 0:
			del f1[i]
	for i in e:
		del f[i]
	e.clear()
	a = [1] * n
	b = [1] * m
	for i in range(n):
		(z, f2) = (1, 0)
		for j in range(len(c[i])):
			xx = c[i][j][0]
			y = min(c[i][j][1], f[xx])
			z = z * pow(xx, y)
			f[xx] -= y
			if f[xx] == 0:
				del f[xx]
			if len(f) == 0:
				f2 = 1
				break
		a[i] = z
		if f2:
			break
	for i in range(m):
		(z, f2) = (1, 0)
		for j in range(len(d[i])):
			xx = d[i][j][0]
			y = min(d[i][j][1], f1[xx])
			z = z * pow(xx, y)
			f1[xx] -= y
			if f1[xx] == 0:
				del f1[xx]
			if len(f1) == 0:
				f2 = 1
				break
		b[i] = z
		if f2:
			break
	print(n, m)
	print(*a)
	print(*b)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()