#P10037. White Pear Tree

    ID: 12015 Type: Default 1000ms 256MiB

White Pear Tree

White Pear Tree

We are given a special pear tree which is abstracted as a rooted tree with node (1) as the root. Initially every node is white. Each node (i) has a heat value (a_i). Initially, (a_1=k) and for all other nodes (a_i=0). In addition, we maintain an accumulator (b), initially (0). At each of (t) time steps (numbered (1,2,\dots,t)), a value (v_x) is chosen and the following operations are performed in order:

  1. Update (b) as (b \leftarrow b + v_x).
  2. For any parent-child pair ((u,v)) (with (u) as the parent), one may choose an integer (h) with (0 \le h \le a_u) and perform the operation [ a_u \leftarrow a_u - h, \quad a_v \leftarrow a_v + h, ] (note that after such a heat transfer on an edge ((u,v)) in the current time step, no operation is allowed on any edge emanating from (v) in the same step).
  3. Afterwards, any node (i) for which (a_i + b < 0) (i.e. (a_i+b < 0)) is colored black, and its entire subtree becomes black.

The sequence ({v_t}) is said to be legal if (\forall i\in[1,t],; |v_i| \le m) (i.e. each (v_i) is an integer with absolute value at most (m)). For a given legal sequence ({v_t}), let the weight of the sequence be the maximum number of white nodes achievable at the end of time (t) after performing the above operations optimally.

In this problem, we consider a simplified version where the pear tree consists of a single node (the root). In this case no heat transfer is possible. The only check is whether the root remains white, i.e. whether the condition [ a_1 + b \ge 0 \quad \text{or equivalently} \quad k + \sum_{i=1}^{t} v_i \ge 0 ] holds. Therefore, the weight is defined as:

[ \text{weight} = \begin{cases} 1, & \text{if}; k + \sum_{i=1}^{t} v_i \ge 0,
0, & \text{otherwise.} \end{cases} ]

Your task is: Given (t), (k) and (m), compute the sum of the weights of all legal sequences ({v_1, v_2, \dots, v_t}) modulo (998244353).

Input summary: The input consists of a single line containing three space‑separated integers (t,; k,; m).

Note: A legal sequence has (v_i \in {-m, -(m-1), \dots, -1, 0, 1, \dots, m}) for each (i).

Example interpretation: If (t=1, k=0, m=2), the possible values for (v_1) are ({-2, -1, 0, 1, 2}). The root remains white if (0+v_1 \ge 0), i.e. if (v_1 \in {0,1,2}). Thus, the answer is 3.

inputFormat

Input Format: A single line containing three space‑separated integers:

t k m

where t: the number of time steps, k: the initial heat of the root (node 1), and m: the maximum allowed absolute value of each (v_i).

outputFormat

Output Format: Output a single integer: the sum of weights over all legal sequences modulo (998244353).

sample

1 0 2
3

</p>