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

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

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
)
. You can and can only unleash one of the two skills you have.
The attack skill always deals

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

in the

turn.
The defense skill has

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

, the XOR sum

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

. 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

turns are all over, or before you die. The answer is modulo

.