PathMaker
题号:NC244830
时间限制:C/C++/Rust/Pascal 5秒,其他语言10秒
空间限制:C/C++/Rust/Pascal 768 M,其他语言1536 M
64bit IO Format: %lld

题目描述

There is a classic RPG called Pathmaker: Kingfinder, and you can't get enough of this game. Now you're challenging one of the most difficult lords in the game - the Goblin King.

Due to the drain from previous battles, you have H blood points remaining and can only release two skills, which can attack and defend, respectively. Fortunately, these skills have enough remaining that you can consider them used an unlimited number of times. At any moment when your blood point is less than or equal to 0, you will die.

There are n turns in total, each turn you act first and the Goblin King acts second. The Goblin King always attacks you once with damage of a_i and one of the attributes fire, ice, wind, or earth, represented by a number . You can and can only unleash one of the two skills you have.

The attack skill always deals A damage, but the probability of hitting varies from turn to turn. Taking into account complications such as movement and terrain limitations of both sides, this probability is p_i in the turn.

The defense skill has 4 limits , and it operates as follows: each time you are attacked, you first completely cancel out the damage you took this time, and then make a decision: if for a certain attribute i, the XOR sum S_i of the cumulative damage of that attribute already canceled by this skill is not less than , it will end immediately; otherwise it remains. Formally, this means that is satisfied. If you take a certain attack without a still valid defense skill, your blood will be reduced by a_i. When you die, the entire round there after will not be played. Please notice that even if you have a defense skill still in effect , you can unleash one more defense skill. At this point the previous skill is considered to have ended early and the XOR and will start accumulating again.

You now want to know what is the maximum expected damage you can deal to a monster before n turns are all over, or before you die. The answer is modulo 998244353.

输入描述:

The first row of three positive integers, n,A,H (), represents the number of rounds, the damage of the attack skill, and your blood level, respectively.

The second line of n positive integers, , represents the damage of the lord's attack on the turn.

The third line, n positive integer , indicates the attribute of the n rounds of lord attacks.

The fourth line, n positive integer , represents the probability of hitting your attack skill in the n rounds. The exact probability .

The fifth row of four positive integers, , expresses the 4 limit for the defense skill.

输出描述:

A positive integer on a line that represents the remainder of the maximum expected damage to the lord, modulo 998244353 .
示例1

输入

复制
4 1 1
1 2 3 2
0 0 0 1
1 1 10 10
3 1 10 10

输出

复制
1
示例2

输入

复制
3 10 5
4 9 1
0 0 0
20 0 10
1 9 9 9

输出

复制
15

说明

In the second sample, you released attack skills and took four points of damage in the first round. You release the defense skill in the second round, and the defense skill ends in the same round. You died after attacking the enemy in the third round. This is allowed. It can be proved that you can cause the maximum expected damage in this situation.