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

#FT0000205. Hai lần rút thăm (Double Chance)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Hai lần rút thăm (Double Chance)

Double Chance

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn numbered cards; card ii carries the integer aia_i.

For each k=1,2,…,nk=1,2,\ldots,n, consider a bag containing cards 11 through kk. Draw a uniformly random card, record its value xx, and return it to the bag. Independently draw again and record yy.

Find the expected value of max⁡(x,y)\max(x,y) for each kk, modulo 998244353998244353. If this expectation is the reduced fraction P/QP/Q, output the unique integer rr in [0,998244353)[0,998244353) such that rQ≡P(mod998244353)rQ\equiv P\pmod{998244353}.

Input

  • The first line contains nn, the number of cards.
  • The second line contains nn integers a1,…,ana_1,\ldots,a_n, the values written on the cards.

Output

Print nn lines. The kk-th line contains the modular expected value of max⁡(x,y)\max(x,y) when the bag contains its first kk cards.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le8; 1≤ai≤2⋅1051\le a_i\le2\cdot10^5 for all ii.

  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; 1≤ai≤2⋅1051\le a_i\le2\cdot10^5 for all ii.

  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 1≤ai≤2⋅1051\le a_i\le2\cdot10^5 for all ii.

Examples

Input

3
5 7 5

Output

5
499122183
443664163

Explanation

For k=1k=1 both draws yield 55, so the expectation is 55. For k=2k=2, the four equally likely ordered draws have maxima 5,7,7,75,7,7,7; their average is 13/213/2, represented modulo 998244353998244353 by 499122183499122183. For k=3k=3, four ordered pairs have maximum 55 and five have maximum 77, giving (4⋅5+5⋅7)/9=55/9(4\cdot5+5\cdot7)/9=55/9 and modular result 443664163443664163.