Increasing Subsequence
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

Alice is playing a game with his friend Bob on a permutation P of length N. Two players take turns choosing numbers while Alice going first.

In each round, the player should pick an element in P that is larger than any element chosen by two players previously. Besides that, if one player picked P_i before, the element P_j he picks in this round should satisfy with . If there are mutiple chooses, the player will randomly pick an element that satisfies all the conditions with equal probability.

In the first round, each player could choose an element in any position, but Bob should choose an element bigger than the first element chosen by Alice. The game ends immediately when a player couldn't find an appropriate element to pick.

Alice and Bob wonder what is the expected number of rounds. Here the expected number we calculate is the sum of steps of two players.

输入描述:

The first line contains one integer , describing the length of P.

The second line contains  integers P_1,...,P_N,describing permutation P.

输出描述:

Output the answer in one line. If the expected number is , print .
示例1

输入

复制
3
1 2 3

输出

复制
831870296
示例2

输入

复制
3
3 1 2

输出

复制
665496237
示例3

输入

复制
8
1 5 2 6 3 7 4 8

输出

复制
904361851