#agc030d. [agc030_d]Inversion Sum

[agc030_d]Inversion Sum

Problem Statement

You are given an integer sequence of length NN: A1,A2,...,ANA_1,A_2,...,A_N. Let us perform QQ operations in order. The ii-th operation is described by two integers XiX_i and YiY_i. In this operation, we will choose one of the following two actions and perform it:

  • Swap the values of AXiA_{X_i} and AYiA_{Y_i}
  • Do nothing

There are 2Q2^Q ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo 109+710^9+7.

Here, the inversion number of a sequence P1,P2,...,PMP_1,P_2,...,P_M is the number of pairs of integers (i,j)(i,j) such that 1leqi<jleqM1\\leq i < j\\leq M and Pi>PjP_i > P_j.

Constraints

  • 1leqNleq30001 \\leq N \\leq 3000
  • 0leqQleq30000 \\leq Q \\leq 3000
  • 0leqAileq109(1leqileqN)0 \\leq A_i \\leq 10^9(1\\leq i\\leq N)
  • 1leqXi,YileqN(1leqileqQ)1 \\leq X_i,Y_i \\leq N(1\\leq i\\leq Q)
  • XineqYi(1leqileqQ)X_i\\neq Y_i(1\\leq i\\leq Q)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN QQ A1A_1 :: ANA_N X1X_1 Y1Y_1 :: XQX_Q YQY_Q

Output

Print the sum of the inversion numbers of the final sequences, modulo 109+710^9+7.


Sample Input 1

3 2
1
2
3
1 2
1 3

Sample Output 1

6

There are four ways to perform operations, as follows:

  • Do nothing, both in the first and second operations. The final sequence would be 1,2,31,2,3, with the inversion number of 00.
  • Do nothing in the first operation, then perform the swap in the second. The final sequence would be 3,2,13,2,1, with the inversion number of 33.
  • Perform the swap in the first operation, then do nothing in the second. The final sequence would be 2,1,32,1,3, with the inversion number of 11.
  • Perform the swap, both in the first and second operations. The final sequence would be 3,1,23,1,2, with the inversion number of 22.

The sum of these inversion numbers, 0+3+1+2=60+3+1+2=6, should be printed.


Sample Input 2

5 3
3
2
3
1
4
1 5
2 3
4 2

Sample Output 2

36

Sample Input 3

9 5
3
1
4
1
5
9
2
6
5
3 5
8 9
7 9
3 2
3 8

Sample Output 3

425