Codeforces Round 630 (Div. 2)
E
Height All the Same
Codeforces
2100
原题
← DF →
翻译中…

Alice has got addicted to a game called Sirtet recently.

翻译中…

In Sirtet, player is given an $n \times m$ grid. Initially $a_{i,j}$ cubes are stacked up in the cell $(i,j)$. Two cells are called adjacent if they share a side. Player can perform the following operations:

翻译中…
  • stack up one cube in two adjacent cells;
  • stack up two cubes in one cell.
翻译中…

Cubes mentioned above are identical in height.

翻译中…

Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation.

翻译中…

image

翻译中…

Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations.

翻译中…

Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that

翻译中…
  • $L \le a_{i,j} \le R$ for all $1 \le i \le n$, $1 \le j \le m$;
  • player can reach the goal using above operations.
翻译中…

Please help Alice with it. Notice that the answer might be large, please output the desired value modulo $998,244,353$.

翻译中…

Input

翻译中…

The only line contains four integers $n$, $m$, $L$ and $R$ ($1\le n,m,L,R \le 10^9$, $L \le R$, $n \cdot m \ge 2$).

翻译中…

Output

翻译中…

Output one integer, representing the desired answer modulo $998,244,353$.

翻译中…

Note

翻译中…

In the first sample, the only initial grid that satisfies the requirements is $a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1$. Thus the answer should be $1$.

翻译中…

In the second sample, initial grids that satisfy the requirements are $a_{1,1}=a_{1,2}=1$ and $a_{1,1}=a_{1,2}=2$. Thus the answer should be $2$.

翻译中…

样例

Input #1
2 2 1 1
Output #1
1
InputCopy OutputCopy
Input #2
1 2 1 2
Output #2
2
InputCopy OutputCopy
题目信息
题号
1332E
时间限制
2 s
内存限制
512 MB
标签
组合数学
构造
数学
矩阵

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。