| UFPE Starters Final Try-Outs 2026 |
|---|
| Finished |
An era has come to an end. With the closing of Leo's legendary legacy, the mission of assembling the MaratonaCIn teams for the Subregional fell on the shoulders of the new coach, Palão.
But peace in the lab didn't last long. Eol, Leo's eternal arch-nemesis, felt that life was too quiet without his old rival and decided to pick a fight with the successor. In the dead of night, he broke into the selection servers and sabotaged the evaluation system.
Palão's system maintained, for each competitor, a metric represented by a polynomial $$$R(x)$$$. To disguise it, Eol split the logic into two separate polynomials, $$$P(x)$$$ and $$$Q(x)$$$, so that the original metric can only be recovered by computing the composition $$$R(x)=P(Q(x))$$$. In other words, if $$$P(x) = p_0 + p_1 x + p_2 x^2 + \cdots + p_n x^n$$$, then
$$$$$$R(x) = P(Q(x)) = p_0 + p_1\, Q(x) + p_2\, Q(x)^2 + \cdots + p_n\, Q(x)^n$$$$$$
Eol knew that computing this composition naively would produce astronomical coefficients, frying the servers. To keep his sabotage working without blowing everything up (after all, he wants to have fun, not ruin the party), he forced all operations to be performed modulo a specific prime. And, being the arrogant villain he is, he didn't pick just any prime: he configured the system to use exactly his own WhatsApp number, $$$998244353$$$.
Help Palão save the selection. Given the polynomials $$$P(x)$$$ and $$$Q(x)$$$, compute the coefficients of $$$R(x) = P(Q(x)) \pmod{998244353}$$$
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$): the degrees of $$$P$$$ and $$$Q$$$, respectively.
The second line contains $$$n+1$$$ integers $$$p_0, p_1, \ldots, p_n$$$ ($$$0 \le p_i \lt 998244353$$$):the coefficients of $$$P(x) = p_0 + p_1 x + \cdots + p_n x^n$$$.
The third line contains $$$m+1$$$ integers $$$q_0, q_1, \ldots, q_m$$$ ($$$0 \le q_i \lt 998244353$$$): the coefficients of $$$Q(x) = q_0 + q_1 x + \cdots + q_m x^m$$$.
It is guaranteed that $$$p_n \neq 0$$$ and $$$q_m \neq 0$$$ (i.e., the polynomials have exactly the stated degrees).
Print $$$n \cdot m + 1$$$ integers: the coefficients $$$r_0, r_1, \ldots, r_{n \cdot m}$$$ of $$$R(x) = P(Q(x)) \bmod 998244353$$$, separated by spaces.
2 11 2 11 1
4 4 1
1 20 11 0 1
1 0 1
In the first sample, $$$P(x) = 1 + 2x + x^2$$$ and $$$Q(x) = 1 + x$$$
The composition $$$R(x) = P(Q(x))$$$ is computed by substituting $$$x$$$ with $$$(1+x)$$$:
$$$$$$R(x) = 1 + 2(1+x) + (1+x)^2 = 1 + 2 + 2x + 1 + 2x + x^2 = 4 + 4x + x^2$$$$$$
The resulting coefficients are 4 4 1.
In the second sample, $$$P(x) = x$$$ and $$$Q(x) = 1 + x^2$$$.
$$$$$$R(x) = P(Q(x)) = Q(x) = 1 + x^2$$$$$$
The resulting coefficients are 1 0 1.
| Name |
|---|


