Wheel of Fortune
题号:NC241131
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

In the famous card-collecting game Hearthstone, there is an exciting card named Yogg Saron, Master of Fate, with a battlecry effect of "If you've cast $10$ spells during the game, spin the Wheel of Yogg Saron!" 

Six distinct options are contained in the Wheel of Yogg Saron, with a probability of being chosen for each option. Among all options, the one with the least probability of being chosen is "Rod of Roasting." However, this option also has the most devastating effect: Randomly cast "Pyroblast" until a player dies! Here, "Pyroblast" is a spell of mage class, with the effect of dealing 10 damage to some unit.


Now, given the health point of you and your opponent and the health point of minions on the board, you want to know: If now a battlecry of Yogg Saron, Master of Fate is triggered and the option of "Rod of Roasting" is chosen, what is the probability of you surviving the pyroblasts and winning the game?

Formally, assume your health point is , and the health point of at most7 minions on your board are respectively. Also, your opponent's health point is and the health point of at most 7 minions on your opponent's board are , respectively. The option of "Rod of Roasting" is equivalent to the following stochastic process:
  • Repeat until  or : Choose from  an element x greater than zero uniformly at random and set 
  • If , you win. Otherwise, your opponent wins.

输入描述:

The first line contains eight integers , denoting the health point of you and your minions.

The second line contains eight integers , denoting the health point of your opponent and your opponent's minions.

输出描述:

Output an integer in a line, denoting the probability of you winning the game. Under the input constraints of this problem, it can be shown that the answer can be written as , where P and Q are coprime integers and . You need to output  as an answer, where  is the modular inverse of Q with respect to 998244353.
示例1

输入

复制
30 5 0 0 0 0 0 0
30 5 0 0 0 0 0 0

输出

复制
499122177
示例2

输入

复制
10 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0

输出

复制
748683265