#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; constint MAXN = 3e3 + 10; //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; constint P = 1e9 + 7; int n; int q; int A[MAXN] , S[MAXN][MAXN] , p2[MAXN];
voidsolve(){ cin >> n >> q; p2[0] = 1; rep( i , 1 , q ) p2[i] = ( p2[i - 1] * 2 ) % P; rep( i , 1 , n ) scanf("%d",A + i); rep( i , 1 , n ) rep( j , 1 , n ) if( A[i] > A[j] ) S[i][j] = 1; int ans = 0; constint iv2 = ( P + 1 >> 1 ); rep( w , 1 , q ) { int u , v; scanf("%d%d",&u,&v); rep( i , 1 , n ) if( i != u && i != v ) { int ts = ( S[i][u] + S[i][v] ) % P; S[i][u] = S[i][v] = ts * 1ll * iv2 % P; ts = ( S[u][i] + S[v][i] ) % P; S[u][i] = S[v][i] = ts * 1ll * iv2 % P; } int ts = ( S[u][v] + S[v][u] ) * 1ll * iv2 % P; S[u][v] = S[v][u] = ts; // ans = ( ans + ts * 1ll * p2[q - w] ) % P; } rep( i , 1 , n ) rep( j , i + 1 , n ) ans = ( ans + S[i][j] * 1ll * p2[q] ) % P; cout << ans << endl; }