Under construction

Still being built. Things may change

Number of Increasing Subsequences

Interview

Time limit2sMemory limit1024 MB

Summary
For each position i, count the increasing subsequences that end at A_i, modulo 998244353, where values range up to 5000.
Level

Medium5 of 10

Topics
Dynamic programming, Prefix sum, Array, Combinatorics
Solved
No attempts yet

Problem

You are given a sequence AA of length NN. For each ii, find the number of increasing subsequences that end with AiA_i.

The answer can be very large, so output it modulo 998 244 353998\,244\,353.

For those who are not sure what an increasing subsequence is, Dongwon has prepared the following definitions.

  • A subsequence is a sequence obtained by choosing one or more elements from the given sequence and listing them in their original order.
  • An increasing subsequence is a sequence in which every element except the first is greater than the element immediately before it. That is, for a subsequence AA of length NN, if Ai−1<AiA_{i-1} < A_i holds for all 2≤i≤N2 \le i \le N, then AA is an increasing subsequence.

Dongwon adds a note that, by this definition, a subsequence of length 1 is always an increasing subsequence.

Input

The first line gives the length of the sequence, NN.

The second line gives NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N separated by spaces.

Output

Print NN integers on the first line.

The ii-th number printed is the number of increasing subsequences ending with AiA_i, modulo 998 244 353998\,244\,353.

Constraints

  • 1≤N≤5 0001 \leq N \leq 5\,000
  • 1≤Ai≤5 0001 \leq A_i \leq 5\,000

Examples3

  1. Example 1

    Input
    5
    1 2 3 4 5
    
    Expected output
    1 2 4 8 16
    
  2. Example 2

    Input
    5
    1 1 1 1 1
    
    Expected output
    1 1 1 1 1
    
  3. Example 3

    Input
    5
    1 2 2 4 3
    
    Expected output
    1 2 2 6 6