#ARC133E. [ARC133E] Cyclic Medians

[ARC133E] Cyclic Medians

Score : 800800 points

Problem Statement

Given are integers NN, MM, VV, and AA. Consider the following procedure.

  • Choose a sequence of NN integers between 11 and VV (inclusive): x=(x1,x2,,xN)x=(x_1,x_2,\cdots,x_N).
  • Choose a sequence of MM integers between 11 and VV (inclusive): y=(y1,y2,,yM)y=(y_1,y_2,\cdots,y_M).
  • Let aa be a variable and initialize it with a=Aa=A.
  • For each i=0,1,,N×M1i=0,1,\cdots,N \times M-1, do the following.- Replace the value of aa with the median of a,x(imodN)+1,y(imodM)+1a,x_{(i \bmod N)+1},y_{(i \bmod M)+1}.
  • Replace the value of aa with the median of a,x(imodN)+1,y(imodM)+1a,x_{(i \bmod N)+1},y_{(i \bmod M)+1}.
  • Print the final value of aa.

Consider doing this procedure with every possible pair of sequences x,yx,y. Find the sum of the values that will be printed, modulo 998244353998244353.

Constraints

  • 1N,M2000001 \leq N,M \leq 200000
  • 1AV2000001 \leq A \leq V \leq 200000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM VV AA

Output

Print the answer.

2 1 2 1
11

For example, when x=(1,2),y=(2)x=(1,2),y=(2), the procedure goes as follows.

  • Initialize aa with a=1a=1.
  • For i=1i=1: replace the value of aa with the median of a(=1),x1(=1),y1(=2)a(=1),x_1(=1),y_1(=2), which is 11.
  • For i=2i=2: replace the value of aa with the median of a(=1),x2(=2),y1(=2)a(=1),x_2(=2),y_1(=2), which is 22.
  • Print a(=2)a(=2).

There are three cases where 22 will be printed: (x=(1,2),y=(2))(x=(1,2),y=(2)), (x=(2,1),y=(2))(x=(2,1),y=(2)), (x=(2,2),y=(2))(x=(2,2),y=(2)). In the other five cases, 11 will be printed. Therefore, the answer is 2×3+1×5=112 \times 3 + 1\times 5=11.

2 2 5 4
2019
2100 2300 2201 2022
407723438