#P1988F. Heartbeat

Heartbeat

No submission language available for this problem.

Description

For an array u1,u2,,unu_1, u_2, \ldots, u_n, define

  • a prefix maximum as an index ii such that ui>uju_i>u_j for all j<ij<i;
  • a suffix maximum as an index ii such that ui>uju_i>u_j for all j>ij>i;
  • an ascent as an index ii (i>1i>1) such that ui>ui1u_i>u_{i-1}.

You are given three cost arrays: [a1,a2,,an][a_1, a_2, \ldots, a_n], [b1,b2,,bn][b_1, b_2, \ldots, b_n], and [c0,c1,,cn1][c_0, c_1, \ldots, c_{n-1}].

Define the cost of an array that has xx prefix maximums, yy suffix maximums, and zz ascents as axbycza_x\cdot b_y\cdot c_z.

Let the sum of costs of all permutations of 1,2,,n1,2,\ldots,n be f(n)f(n). Find f(1)f(1), f(2)f(2), ..., f(n)f(n) modulo 998244353998\,244\,353.

The first line contains an integer nn (1n7001\le n\le 700).

The second line contains nn integers a1,,ana_1,\ldots,a_n (0ai<9982443530\le a_i<998\,244\,353).

The third line contains nn integers b1,,bnb_1,\ldots,b_n (0bi<9982443530\le b_i<998\,244\,353).

The fourth line contains nn integers c0,,cn1c_0,\ldots,c_{n-1} (0ci<9982443530\le c_i<998\,244\,353).

Print nn integers: the ii-th one is f(i)f(i) modulo 998244353998\,244\,353.

Input

The first line contains an integer nn (1n7001\le n\le 700).

The second line contains nn integers a1,,ana_1,\ldots,a_n (0ai<9982443530\le a_i<998\,244\,353).

The third line contains nn integers b1,,bnb_1,\ldots,b_n (0bi<9982443530\le b_i<998\,244\,353).

The fourth line contains nn integers c0,,cn1c_0,\ldots,c_{n-1} (0ci<9982443530\le c_i<998\,244\,353).

Output

Print nn integers: the ii-th one is f(i)f(i) modulo 998244353998\,244\,353.

Sample Input 1

3
1 1 1
1 1 1
1 1 1

Sample Output 1

1 2 6

Sample Input 2

3
1 2 3
2 3 1
3 1 2

Sample Output 2

6 13 34

Sample Input 3

5
1 4 2 5 3
2 5 1 3 4
300000000 100000000 500000000 400000000 200000000

Sample Output 3

600000000 303511294 612289529 324650937 947905622

Note

In the second example:

  • Consider permutation [1,2,3][1,2,3]. Indices 1,2,31,2,3 are prefix maximums. Index 33 is the only suffix maximum. Indices 2,32,3 are ascents. In conclusion, it has 33 prefix maximums, 11 suffix maximums, and 22 ascents. Therefore, its cost is a3b1c2=12a_3b_1c_2=12.
  • Permutation [1,3,2][1,3,2] has 22 prefix maximums, 22 suffix maximums, and 11 ascent. Its cost is 66.
  • Permutation [2,1,3][2,1,3] has 22 prefix maximums, 11 suffix maximum, and 11 ascent. Its cost is 44.
  • Permutation [2,3,1][2,3,1] has 22 prefix maximums, 22 suffix maximums, and 11 ascent. Its cost is 66.
  • Permutation [3,1,2][3,1,2] has 11 prefix maximum, 22 suffix maximums, and 11 ascent. Its cost is 33.
  • Permutation [3,2,1][3,2,1] has 11 prefix maximum, 33 suffix maximums, and 00 ascents. Its cost is 33.

The sum of all permutations' costs is 3434, so f(3)=34f(3)=34.