AT_arc210_f [ARC210F] ± ab
Description
You are given an integer sequence $ A=(A_1,A_2,\ldots,A_N) $ . Also, you are given positive integers $ a,b,s,t $ . It is guaranteed that $ a $ and $ b $ are **coprime**.
You can perform the following four types of operations on $ A $ :
- Choose an integer $ i $ satisfying $ 1\leq i\leq N $ and add $ a $ to $ A_i $ . This operation costs $ s $ .
- Choose an integer $ i $ satisfying $ 1\leq i\leq N $ and subtract $ a $ from $ A_i $ . This operation costs $ s $ .
- Choose an integer $ i $ satisfying $ 1\leq i\leq N $ and add $ b $ to $ A_i $ . This operation costs $ t $ .
- Choose an integer $ i $ satisfying $ 1\leq i\leq N $ and subtract $ b $ from $ A_i $ . This operation costs $ t $ .
Answer $ Q $ queries. In the $ q $ -th query, you are given an integer $ B_q $ , so find the following value modulo $ 998244353 $ :
- The minimum total cost required to make $ A_{1}=A_{2}=\cdots=A_{N}=B_q $ hold. It can be proved that it is possible to make $ A_{1}=A_{2}=\cdots=A_{N}=B_q $ hold.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ Q $ $ a $ $ b $ $ s $ $ t $ $ A_1 $ $ A_2 $ $ \ldots $ $ A_N $ $ B_1 $ $ B_2 $ $ \ldots $ $ B_Q $
Output Format
Output $ Q $ values separated by spaces.
The $ q $ -th value should be the minimum total cost, modulo $ 998244353 $ , required to make $ A_{1}=A_{2}=\cdots=A_{N}=B_q $ hold.
Explanation/Hint
### Sample Explanation 1
- By performing operations $ +a $ , $ -b $ on $ A_1 $ in order, we can make $ A=(1) $ . The total cost is $ 4+3=7 $ .
- By performing operations $ -a $ , $ -a $ , $ +b $ on $ A_1 $ in order, we can make $ A=(2) $ . The total cost is $ 4+4+3=11 $ .
- $ A=(3) $ from the beginning. The total cost is $ 0 $ .
- By performing operations $ +a $ , $ +a $ , $ -b $ on $ A_1 $ in order, we can make $ A=(4) $ . The total cost is $ 4+4+3=11 $ .
- By performing operations $ -a $ , $ +b $ on $ A_1 $ in order, we can make $ A=(5) $ . The total cost is $ 4+3=7 $ .
### Sample Explanation 2
- By performing operations $ +a $ on $ A_1 $ , $ +b $ , $ -a $ on $ A_2 $ , and $ +a,+a,-b $ on $ A_3 $ in order, we can make $ A=(4,4,4) $ . The total cost is $ 22 $ .
### Constraints
- $ 1\leq N\leq 2\times 10^5 $
- $ 1\leq Q\leq 2\times 10^5 $
- $ 1\leq a,b,s,t\leq 5\times 10^8 $
- $ a $ and $ b $ are coprime.
- $ 1\leq A_i\leq 5\times 10^8 $
- $ 1\leq B_q\leq 5\times 10^8 $