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: def run(N, Q, A, XY):
      return rec_count(A, XY, 0)
  
  
  def rec_count(A, XY, i):
      div = 10**9 + 7
      if i >= len(XY):
          return count_swap(A) % div
      A_swap = swap(A, XY[i])
      return (rec_count(A, XY, i + 1) + rec_count(A_swap, XY, i + 1)) % div
  
  
  def swap(A, XY):
      A_swap = A.copy()
      X = XY[0] - 1
      Y = XY[1] - 1
      A_swap[X], A_swap[Y] = A[Y], A[X]
      return A_swap
  
  
  def count_swap(A):
      cnt = 0
      for i in range(len(A)):
          for j in range(i + 1, len(A)):
              if A[i] > A[j]:
                  cnt += 1
      return cnt
  
  
  def main():
      N, Q = map(int, input().split())
      A = []
      for _ in range(N):
          A.append(int(input()))
      XY = []
      for _ in range(Q):
          XY.append(list(map(int, input().split())))
      print(run(N, Q, A, XY))
  
  
  if __name__ == "__main__":
      main()
  
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"}]