Description:
Creatnx has n mirrors, numbered from
to
. Every day, Creatnx asks exactly one mirror “Am I beautiful?”. The
mirror will tell Creatnx that he is beautiful with probability
for all
Creatnx asks the mirrors one by one, starting from the
mirror. Every day, if he asks
- The
mirror tells Creatnx that he is beautiful. In this case, if
Creatnx will stop and become happy, otherwise he will continue
asking the - In the other case, Creatnx will feel upset. The next day, Creatnx
will start asking from themirror again. You need to calculate
the expected number of days until Creatnx becomes happy.
This number should be found by modulo
. Formally, let
It can be shown that the answer can be expressed as an irreducible fraction pq, where p and q are integers and
Output the integer equal to
mod
. In other words, output such an integer
that
and
Input
The first line contains one integer
The second line contains n integers
Output
Print the answer modulo
Examples
input
1
50
output
2
input
3
10 20 50
output
112
Note
In the first test, there is only one mirror and it tells, that Creatnx is beautiful with probability
. So, the expected number of days until Creatnx becomes happy is
**题意:**有n面镜子没面镜子都有说美丽或者不美丽的概率,如果中间的镜子问到是不美丽就要从头开始,求问到最后一面镜子是美丽需要用多少天。为到第
面镜子所用的时间。
快乐+
沮丧
沮丧的时候直接到达这一天花费是,天
若重新回到这一天的话就是天
AC代码: