output_description: Print the sum of the inversion numbers of the final sequences, modulo 10^9+7.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N Q
      A_1
      :
      A_N
      X_1 Y_1
      :
      X_Q Y_Q
attempt: import sys
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  """
  ・逆再生
  ・各時点に対して、「(Ai,Aj)がjが右になって終わる確率」を計算していく
  """
  
  import numpy as np
  
  MOD = 10**9 + 7
  
  N, Q = map(int, readline().split())
  data = list(map(int, read().split()))
  A = np.array(data[:N])
  it = iter(data[N:])
  XY = list(zip(it, it))
  
  dp = np.triu(np.ones((N, N), np.int64), 1)
  
  for x, y in XY[::-1]:
      x -= 1
      y -= 1
      p = dp[x, y]
      q = dp[y, x]
      r = p + q
      if r & 1:
          r += MOD
      r //= 2
      if r >= MOD:
          r -= MOD
      temp = dp[x]
      temp += dp[y]
      temp[temp & 1 == 1] += MOD
      temp //= 2
      temp[temp >= MOD] -= MOD
      dp[y] = temp
      temp = dp[:, x]
      temp += dp[:, y]
      temp[temp & 1 == 1] += MOD
      temp //= 2
      temp[temp >= MOD] -= MOD
      dp[:, y] = temp
      dp[x, y] = r
      dp[y, x] = r
      dp[x, x] = 0
      dp[y, y] = 0
  
  select = A[:, None] > A[None, :]
  answer = (dp * select).sum() * pow(2, Q, MOD) % MOD
  print(answer)
  
problem_description: Statement
  
  You are given an integer sequence of length N: A_1,A_2,...,A_N. Let us perform
  Q operations in order. The i-th operation is described by two integers X_i and
  Y_i. In this operation, we will choose one of the following two actions and
  perform it:
  
    * Swap the values of A_{X_i} and A_{Y_i}
    * Do nothing
  
  There are 2^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 10^9+7.
  
  Here, the inversion number of a sequence P_1,P_2,...,P_M is the number of
  pairs of integers (i,j) such that 1\leq i < j\leq M and P_i > P_j.
samples: [{"input": "3 2\n    1\n    2\n    3\n    1 2\n    1 3", "output": "6\n    \n\nThere are four ways to perform operations, as follows:\n\n  * Do nothing, both in the first and second operations. The final sequence would be 1,2,3, with the inversion number of 0.\n  * Do nothing in the first operation, then perform the swap in the second. The final sequence would be 3,2,1, with the inversion number of 3.\n  * Perform the swap in the first operation, then do nothing in the second. The final sequence would be 2,1,3, with the inversion number of 1.\n  * Perform the swap, both in the first and second operations. The final sequence would be 3,1,2, with the inversion number of 2.\n\nThe sum of these inversion numbers, 0+3+1+2=6, should be printed.\n\n* * *"}, {"input": "5 3\n    3\n    2\n    3\n    1\n    4\n    1 5\n    2 3\n    4 2", "output": "36\n    \n\n* * *"}, {"input": "9 5\n    3\n    1\n    4\n    1\n    5\n    9\n    2\n    6\n    5\n    3 5\n    8 9\n    7 9\n    3 2\n    3 8", "output": "425"}]