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.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. and one of the attributes fire, ice, wind, or earth, represented by a number. ≤3). You can and can only unleash one of the two skills you have.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. . 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.
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 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 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 a i and one of the attributes fire, ice, wind, or earth, represented by a number b_i(0leq b_i leq 3) b i (0≤b i ≤3). You can and can only unleash one of the two skills you have. The attack skill always deals A 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 p i in the i_{th} i th turn. The defense skill has 4 4 limits D_{0},D_{1},D_{2},D_{3} D ,D 1 ,D 2 ,D 3 , 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 i, the XOR sum S_i S i of the cumulative damage of that attribute already canceled by this skill is not less than D_{i} D i , it will end immediately; otherwise it remains. Formally, this means that ∃ _{0leq ileq 3} D_{i}leq S_i ∃ 0≤i≤3 D i ≤S i is satisfied. If you take a certain attack without a still valid defense skill, your blood will be reduced by a_i 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 n turns are all over, or before you die. The answer is modulo 998244353 998244353.