Problem11321--[yosupo] Polynomial - Division of Polynomials

11321: [yosupo] Polynomial - Division of Polynomials

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

You are given polynomials $f(x) = \sum _ {i = 0} ^ {N - 1} f _ i x^i \in \mathbb{F} _ {998244353}[x]$ and $g(x)=\sum _ {i=0}^{M-1}g_ix^i\in \mathbb{F}_{998244353}[x]$. Calculate polynomials $q(x)$ and $r(x)$ such that 

- $f(x) = q(x)g(x) + r(x)$ and
- $\deg(r) \lt \deg(g)$.

Input

$N\ M$
$f_0\ f_1\ \ldots\ f_{N - 1}$
$g_0\ g_1\ \ldots\ g_{M - 1}$

Output

Print $u=\deg(q)+1$ and $v=\deg(r)+1$ in the first line. Let $u = 0$ instead if $q(x) = 0$. (The same is true for $r(x)$.)

Print the coefficients of $q(x)$ in the second line and $r(x)$ in the third line.


$u\ v$
$q_0\ q_1\ \ldots\ q_{u-1}$
$r_0\ r_1\ \ldots\ r_{v-1}$

Constraints

- $1 \leq N \leq 5\times 10^5$
- $1 \leq M \leq 5\times 10^5$
- $0 \leq f_i < 998244353$
- $0 \leq g_i < 998244353$
- $f_{N-1} \neq 0$
- $g_{M-1} \neq 0$  

Sample 1 Input

7 3
0 0 0 0 0 0 1
998244352 998244352 1

Sample 1 Output

5 2
5 3 2 1 1
5 8

Sample 2 Input

4 5
1 2 3 4
5 6 7 8 9

Sample 2 Output

0 4

1 2 3 4

Sample 3 Input

1 1
1
1

Sample 3 Output

1 0
1

4 3
1 2 3 4
5 6 7

2 2
916755018 427819009
407446676 346329673

HINT

Source/Category