atcoder#AGC053C. [AGC053C] Random Card Game
[AGC053C] Random Card Game
Score : points
Problem Statement
We have cards, with ID numbers from through . Consider the following game using them.
First, the dealer randomly split the cards into two piles of cards each. Here, the dealer also randomly chooses the order of cards in each pile. Then, the player repeatedly does the operation below until one pile becomes empty, and the number of operations done will be the score.
- Choose a positive integer and compare the -th cards from the top in the two piles. ( should not exceed the number of each pile.) Then, remove the card with the smaller ID number from the pile that contains it.
Assume that a cheater plays this game. That is, assume that the player can always see the ID numbers of all cards in both piles. Find the expected value of the score when the player plays optimally to minimize it, modulo (see Notes).
Notes
- The expected value in question will be a rational number. If we express it as a fractional number where and are coprime positive integers, will be coprime with , so print the only integer between and (inclusive) such that .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
1
1
3
486111118