Gacha 101
시간 제한2초메모리 제한1024 MB
1부터 N까지 번호가 붙은 공을 무작위 순서로 꺼낼 때, 어떤 시점에서 뽑힌 번호 집합이 연속한 세 수 i, i+1, i+2를 모두 포함할 확률을 구한다.
문제
For each , there are balls with written on them. These are put into a box and mixed up. The string variable consists of initially “0”s. Balls are taken out of the box one by one (uniformly at random and independently). When a ball with written on it is drawn, the -th character of is changed to “1” (it remains unchanged if it was already “1”). Find the probability, modulo , of having a point during this process that contains “101” as a contiguous substring.
입력
The input consists of a single test case of the following format.
The first line consists of an integer between and , inclusive. The second line consists of positive integers . For each (), represents the number of balls written. And they satisfy .
출력
Output in a line the probability modulo .
힌트
- How to find the probability modulo
- It can be proved that the sought probability is always a rational number. Additionally, the constraints of this problem guarantee that if the sought probability is represented as an irreducible fraction , then is not divisible by . Here, there is a unique such that , so report this .