Expected Beauty
시간 제한1초메모리 제한2048 MB
각 원소를 주어진 구간에서 균등하게 뽑을 때, 인접한 같은 값을 지워 얻는 점수의 최댓값을 제곱한 값의 기댓값을 구한다.
문제
Morgan the robot has an array of size , indexed from to . The value of each element in is randomly generated; can be any integer from to (inclusive) with equal probability.
Morgan defines the beauty of as follows. First, Morgan has a variable named score that is initialized to . An operation on the array is as follows:
- Choose an index such that and . If no such exists, then the operation cannot be performed.
- Add the value of to
scoreand remove from the array. - The array becomes the concatenation of the remaining elements without changing its order.
The beauty of is the maximum value of score Morgan can possibly get after performing zero or more operations on the array .
Since the array is randomly generated, Morgan wonders about the expected beauty of . Due to the inefficiency of his algorithm, Morgan asks for your help to calculate the expected value.
입력
Input begins with an integer () representing the size of array . Each of the next lines contains two integers ().
출력
Let . It can be shown that the expected value can be expressed as an irreducible fraction , where and are integers and . Output an integer in a single line such that and .