#B3728. Dice Sum Probability Modulo 998244353

    ID: 11387 Type: Default 1000ms 256MiB

Dice Sum Probability Modulo 998244353

Dice Sum Probability Modulo 998244353

You are given n fair six-sided dice. When tossed, each die shows a number from 1 to 6 with equal probability, and all dice tosses are independent.

Let \( f(n, m) \) be the number of ways to obtain a total sum of \( m \) when tossing these n dice. The probability that the sum equals \( m \) is given by

\( \frac{f(n, m)}{6^n} \)

Since this probability is a rational number, you are required to compute it modulo \( 998\,244\,353 \). Formally, if the probability is \( \frac{a}{b} \) (in lowest terms) then you need to compute \( a \cdot b^{-1} \bmod 998\,244\,353 \), where \( b^{-1} \) is the modular inverse of \( b \) modulo \( 998\,244\,353 \).

Note: If \( m \) is not achievable with n dice (i.e. if \( m 6n \)), the answer is 0.

inputFormat

The input consists of a single line containing two integers ( n ) and ( m ), where ( n ) is the number of dice and ( m ) is the desired total sum.

outputFormat

Output a single integer, which is the probability that the sum of the dice is exactly ( m ) computed modulo ( 998,244,353 ).

sample

1 3
166374059