You are given a sequence of length . Each integer from to occurs exactly twice.
Choose the deletion order of the elements uniformly from all orders. Delete the original elements one at a time in this order, preserving the relative order of the remaining elements.
For each integer , earn points if its two occurrences are adjacent at least once, either initially or during the deletion process. Points for each integer are earned at most once. Let be the final score. Find the expected value of .
If this expectation is the reduced fraction , output modulo , where denotes the multiplicative inverse of modulo .
The input is given in the following format:
Print the expected value of modulo .
The two occurrences of are adjacent before any deletion, so the score is always . Thus and .
If one of the two middle elements is deleted first, exactly one integer scores regardless of subsequent deletions. If an endpoint is deleted first, a score is obtained only when the middle of the three remaining elements is deleted second.
Thus with probability , and otherwise . Hence , whose value modulo the specified prime is .
The two occurrences of are initially adjacent, so they always contribute point. The two occurrences of become adjacent only if both occurrences of are deleted before either occurrence of , which has probability .
Thus with probability and with probability , giving . Its value modulo the specified prime is .