PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000138. Rút gọn phân số dạng tích (Reducing Fractions)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Rút gọn phân số dạng tích (Reducing Fractions)

Reducing Fractions

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

The Galactic Empire represents a positive fraction using two arrays of positive integers. The numerator is the product of the first array, and the denominator is the product of the second one:

F=a1a2⋯anb1b2⋯bm.F=\frac{a_1a_2\cdots a_n}{b_1b_2\cdots b_m}.

Output two new arrays representing exactly the same value FF, where the resulting numerator and denominator are coprime. The arrays may have different lengths from the input as long as the output bounds are respected. Any valid reduced representation is accepted. The original products may be too large for fixed-width integers.

Input

The first line contains n,mn,m. The second line contains nn integers aia_i; the third contains mm integers bib_i.

Output

Print nout,moutn_{out},m_{out} with 1≤nout,mout≤1051\le n_{out},m_{out}\le 10^5, followed by noutn_{out} numerator factors and moutm_{out} denominator factors. Every printed factor must be in [1,107][1,10^7]. Their products must represent the original fraction in reduced form.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤81\le n,m\le 8; 1≤ai,bj≤1001\le a_i,b_j\le 100.
  • Subtask 2 (30 points): 1≤n,m≤2 0001\le n,m\le 2\,000; 1≤ai,bj≤100 0001\le a_i,b_j\le 100\,000.
  • Subtask 3 (50 points): 1≤n,m≤100 0001\le n,m\le 100\,000; 1≤ai,bj≤10 000 0001\le a_i,b_j\le 10\,000\,000.

Examples

Input

4 3
2 5 10 20
100 1 3

Output

4 3
2 5 2 1
1 1 3

Explanation

The original products are 2⋅5⋅10⋅20=20002\cdot5\cdot10\cdot20=2000 and 100⋅1⋅3=300100\cdot1\cdot3=300. Dividing by their GCD 100100 gives the reduced fraction 20/320/3. The output arrays have products 2020 and 33, which are coprime.