stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
// D - Bouquet

#include <bits/stdc++.h>

using namespace std;

using ll = long long;



// a^n mod m を計算する(二分累乗法:O(logn))

ll modpow(ll a, ll n, ll m) {

	ll x = 1;

	while(n){

		if(n & 1) x = x * a % m;

		a = a * a % m;

		n >>= 1;

	}

	return x;

}



// nCr mod m

ll nCr(ll n, ll r, ll m){

	ll a = 1, b = 1;

	for(ll i=1; i<=r; ++i){

		a *= n - i + 1;

		b *= i;

		a %=m;

		b %=m;

	}

	return a * modpow(b, m-2, m) % m;

}



int main(){

	ll MOD = 1000000007, N,A,B;

	cin>>N>>A>>B;

	ll ans = modpow(2, N, MOD) - 1;

	ans -= nCr(N, A, MOD);

	ans -= nCr(N, B, MOD);

	ans %= MOD;

	if(ans < 0L) ans += MOD;

	cout<< ans <<endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.9585017235798146x):
// D - Bouquet

#include <bits/stdc++.h>

using namespace std;

using ll = long long;



#define MOD 1000000007



// a^n mod m を計算する(二分累乗法:O(logn))

ll modpow(ll a, ll n) {

	ll m = MOD;

	ll x = 1;

	while(n){

		if(n & 1) x = x * a % m;

		a = a * a % m;

		n >>= 1;

	}

	return x;

}



// nCr mod m

ll nCr(ll n, ll r){

	ll m = MOD;

	ll a = 1, b = 1;

	for(ll i=1; i<=r; ++i){

		a *= n - i + 1;

		b *= i;

		a %=m;

		b %=m;

	}

	return a * modpow(b, m-2) % m;

}



int main(){

	ll N,A,B; cin>>N>>A>>B;

	ll ans = modpow(2, N) - 1;

	ans -= nCr(N, A);

	ans -= nCr(N, B);

	ans %= MOD;

	if(ans < 0L) ans += MOD;

	cout<< ans <<endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long

#define inf 0x3f3f3f3f

using namespace std;

const ll mod = 1e9 + 7;

const int maxn = 2e5 + 5;

ll fac[maxn],inv[maxn];



ll modpow(ll a,ll b){return b ? modpow(a*a%mod,b/2)*(b%2?a:1)%mod : 1;}

ll prm(ll n, ll k){

  ll res = 1;

  for(int i=0;i<k;i++){ res = res * (n-i) % mod; }

  return res;

}

ll modinv(ll a, ll p){ return modpow( a, p-2 ); }

ll cmb(ll n,ll k){

	k = min(k, n-k);

	return prm(n,k) * modinv(prm(k,k), mod) % mod;

} 

int main(){

	ll n,a,b;

	cin>>n>>a>>b;

	ll ans = modpow(2,n) - 1 - cmb(n,a) - cmb(n,b);

	ans = (ans % mod + mod) % mod;

	cout << ans << "\n";

}

// Faster C++ solution for the same problem (measured speedup: 1.5023369904101196x):
// #include <bits/stdc++.h>

#include <stdio.h>

#define ll long long

#define inf 0x3f3f3f3f

// using namespace std;

const ll mod = 1e9 + 7;

const int maxn = 2e5 + 5;

ll fac[maxn],inv[maxn];



ll modpow(ll a,ll b){return b ? modpow(a*a%mod,b/2)*(b%2?a:1)%mod : 1;}

ll prm(ll n, ll k){

  ll res = 1;

  for(int i=0;i<k;i++){ res = res * (n-i) % mod; }

  return res;

}

ll modinv(ll a, ll p){ return modpow( a, p-2 ); }

ll cmb(ll n,ll k){

	if(k > n-k){ k = n-k; }

	return prm(n,k) * modinv(prm(k,k), mod) % mod;

} 

int main(){

	ll n,a,b;

// 	cin>>n>>a>>b;

	scanf("%lld %lld %lld", &n, &a, &b);

	ll ans = modpow(2,n) - 1 - cmb(n,a) - cmb(n,b);

	ans = (ans % mod + mod) % mod;

	printf("%lld\n", ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int maxx = 2e5 + 7;

const int Mod = 1e9 + 7;

typedef long long ll;

ll n;

int a, b;

ll fac[maxx], inv[maxx];



ll qwe(ll x, int y) {

	ll res = 1ll;

	while(y) {

		if(y & 1) res = res * x % Mod; 

		x = x * x % Mod;

		y >>= 1; 

	}

	return res;

}



ll Com(ll n, ll m) {

	ll res = 1ll;

	for(ll i = n; i >= n - m + 1; i--) res = res * i % Mod;

	return res * inv[m] % Mod;

}



int main() {

	fac[0] = inv[0] = 1; 

	for(int i = 1; i <= maxx; i++) fac[i] = fac[i - 1] * i % Mod;

	inv[maxx] = qwe(fac[maxx], Mod - 2);

	for(int i = maxx - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % Mod;

	scanf("%lld %d %d", &n, &a, &b);

	ll ans = qwe(2, n) - 1;

	ans = (ans - Com(n, a) + Mod) % Mod;

	ans = (ans - Com(n, b) + Mod) % Mod;

	printf("%lld\n", ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.9363232722287151x):
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const LL Mod = 1e9 + 7;

LL n, a, b, ans;



LL qwe(LL a, LL n) { //快速幂

	LL res = 1LL;

	while(n) {

		if(n & 1) res = res * a % Mod;

		a = a * a % Mod;

		n >>= 1LL;

	}

	return res % Mod;

}



LL C(LL n, LL m) { //组合数

	if(m < n - m) m = n - m;

	LL x = 1LL;

	for(LL i = m + 1; i <= n; i++) x = x * i % Mod;

	LL y = 1LL;

	for(LL i = 1; i <= n - m; i++) y = y * i % Mod;

	return x * qwe(y, Mod - 2) % Mod;

	//除法取模只需将除法变乘法即可, 也就是用被除数去乘以除数的乘法逆元

	//求乘法逆元用费马小定理: 当模Mod为素数, x的逆元为qwe(x, Mod - 2)

}



int main() {

	cin >> n >> a >> b;

	ans = ((qwe(2LL, n) - C(n, a) - C(n, b) - 1) % Mod + Mod) % Mod;

	cout << ans << endl;

    return 0;

}



/*

c(n, 1) + ... + c(n, n)

c(n, 0) + ... + c(n, n) = 2 ^ n

=> ans = (2 ^ n) - C(n, a) - C(n, b) - 1

减去一束也不选的情况

*/
// Slower C++ solution:


#include <iostream>

#include <string>

#include <algorithm>

#include <cmath>





using namespace std;

using LLint = long long int;



LLint ModPow(LLint j,LLint k,LLint l){

	//(j^k)/mod l を計算

	if(k==0) return 1%l;

	else if(k%2==0){

		LLint t=ModPow(j,k/2,l);//k/2乗したもの

		return t*t%l;

	}

	else return (j%l)*ModPow(j,k-1,l)%l;

}



LLint Combi(LLint a,LLint b,LLint M){

	LLint UP,DOWN;

	UP=DOWN=1;

	for(int i=0;i<b;++i){

		UP = UP*((a-i)%M)%M;

		DOWN = DOWN*((i+1)%M)%M;

	}

	return (UP*ModPow(DOWN,M-2,M))%M;

}







const LLint Mod = 1000000007;



int main() {

	int n,a,b;

	cin>>n>>a>>b;

	LLint ALL = ModPow(2,n,Mod);



	LLint A;

	A=Combi(n,a,Mod);



	LLint B;

	B=Combi(n,b,Mod);



	cout<< (((ALL-1-A-B)%Mod)+Mod)%Mod<<endl;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3152958516458544x):
#include <iostream>

#include <string>

#include <algorithm>

#include <cmath>



using namespace std;

using llint = long long int ;



#define rep(i,c) for(int i = 0; i < (int)c; ++i)

// c 回繰り返す



const llint mod = 1000000007;

//mod　10^9 + 7





///////////////////////便利？な関数///////////////////////

llint Pow_Mod(llint n,llint p,llint m){

    //n^p mod　の繰り返し二乗法

    if(p==0) return 1%m;

    else if(p%2==0){

        llint kakeru = Pow_Mod(n,p/2,m);

        return kakeru*kakeru%m;

    }

    else return n%m*Pow_Mod(n,p-1,m)%m;

}



llint Conbi(llint x,llint y,llint m){

    //xCy mod を求める

    llint UP,DOWN;

    UP=DOWN=1%m;

    rep(i,y){

        UP=UP*(x-i)%m;

        DOWN=DOWN*(i+1)%m;

    }

    return UP*Pow_Mod(DOWN,m-2,m)%m;

    //mは素数がいい

}









int main(){

    

    int n,a,b;

    cin>>n>>a>>b;



    int ALL=Pow_Mod(2,n,mod);

    int AB=Conbi(n,a,mod)+Conbi(n,b,mod);



    cout<<((ALL-AB-1)%mod+mod)%mod<<endl;







    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

typedef pair<int,int> P;

long modding = pow(10, 9) + 7;



ll saisyo(int n){

  if(n==0)

    return 1;

  ll x = saisyo(n / 2);

  x %= modding;

  x *= x;

  x %= modding;

  if(n%2==1) x*=2;

  x %= modding;

  return x;

} 



ll modpow(ll a,ll n){

    ll res = 1;

    while(n > 0){

        if(n&1) res = res * a % modding;

        a = a * a % modding;

        n >>= 1;

    }

    return res;

}



ll modinv(ll x){

    return modpow(x,modding-2);

}

 

long comb(ll   n,ll a){

  ll  x = 1, y = 1;

  rep(i,a){

    x *= (n - i);

    y *= i+1;

    x %= modding;

    y %= modding;

  }



  return x*modinv(y)%modding;

}

int main (){

  long n, a, b;

  cin >> n >> a >> b;

  long ans = saisyo(n);

  ans -= 1;

  ans -= comb(n, a);

  ans -= comb(n, b);

  ans %= modding;

  while(ans<0)

    ans += modding;

  cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.7114500100856171x):
#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;

typedef pair<int, int> P;

const int INF = 100100100;

const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

long long longpow(long long a, long long b) {

  if (b == 0) return 1;

  if (b == 1) return a%MOD;

  if (b % 2 == 1) return (a  * longpow(a, b - 1)) % MOD;

  ll t = longpow(a, b / 2)%MOD;

  return (t * t) % MOD;

}

long long modpow(long long a, long long n) {

  long long res = 1;

  long long mod = n + 2;

  while (n > 0) {

    if (n & 1) res = res * a % mod;

    a = a * a % mod;

    n >>= 1;

  }

  return res;

}

long long inverse(long long x, long long modding) {

  return modpow(x, modding - 2);

}

ll comb(ll r, ll a) {

  ll R = r;

  REP(i, a - 1) {

    r--;

    R *= r;

    R %= MOD;

  }

  ll A = 1;

  for (int i = 1; i <= a; i++) {

    A *= i;

    A %= MOD;

  }

  return R * inverse(A, MOD) % MOD;

}





int main() {

  ll n, a, b;

  cin >> n >> a >> b;

  ll ans = longpow(2,n) - 1;

  ans -= comb(n, a);

  ans -= comb(n, b);

  while (ans < 0) {

    ans += MOD;

  }

  cout << ans << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const int iinf = 1 << 28;

const long long llinf = 1ll << 60;

const double PI = 3.14159265;



ll inv[200001], invf[200001];



ll exp(ll a, ll b) {

    if (b == 0LL) return 1LL;

    if (b == 1LL) return a;

    ll ans = exp(a, b>>1);

    ans = (ans * ans) % MOD;

    if (b&1LL) ans = (ans * a) % MOD;

    return ans;

}



void work() {

    ll n, a, b; cin>>n>>a>>b;

    ll ans = (exp(2LL, n) - 1LL) % MOD;

    

    // a

    ll d1 = max(a, n-a), d2 = min(a, n - a);

    ll fact_n = 1LL;

    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;



    inv[1] = 1LL;

    invf[0] = invf[1] = 1LL;

    ll m = d2 + 1LL;

    for(ll i = 2LL; i < m; ++i) {

        inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

        invf[i] = (inv[i] * invf[i-1LL]) % MOD;

    }

    ll na = (fact_n * invf[d2]) % MOD;

    ans = (ans - na + MOD) % MOD;

    //cout << na << endl;



    // if (b == n-a) {

    //     cout << ans << endl;

    //     return;

    // }



    // b

    d1 = max(b, n-b), d2 = min(b, n - b);

    fact_n = 1LL;

    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;



    inv[1] = 1LL;

    invf[0] = invf[1] = 1LL;

    m = d2 + 1LL;

    for(ll i = 2LL; i < m; ++i) {

        inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

        invf[i] = (inv[i] * invf[i-1LL]) % MOD;

    }

    ll nb = (fact_n * invf[d2]) % MOD;

    ans = (ans - nb + MOD) % MOD;

    //cout << nb << endl;



    cout << ans << endl;

}



int main() {

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    work();



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.0540695768209654x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const int iinf = 1 << 28;

const long long llinf = 1ll << 60;

const double PI = 3.14159265;



ll exp(ll a, ll b) {

    if (b == 0LL) return 1LL;

    if (b == 1LL) return a;

    ll ans = exp(a, b>>1);

    ans = (ans * ans) % MOD;

    if (b&1LL) ans = (ans * a) % MOD;

    return ans;

}



void work() {

    ll n, a, b; cin>>n>>a>>b;

    ll ans = (exp(2LL, n) - 1LL) % MOD;

    

    // a

    ll d1 = max(a, n-a), d2 = min(a, n - a);

    ll fact_n = 1LL;

    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;



    ll invff = 1LL;

    for (ll i = d2; i > 1; --i) invff = (invff * i) % MOD;

    ll na = (fact_n * exp(invff, MOD-2LL)) % MOD;

    ans = (ans - na + MOD) % MOD;



    // b

    d1 = max(b, n-b), d2 = min(b, n - b);

    fact_n = 1LL;

    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;



    invff = 1LL;

    for (ll i = d2; i > 1; --i) invff = (invff * i) % MOD;

    ll nb = (fact_n * exp(invff, MOD-2LL)) % MOD;

    ans = (ans - nb + MOD) % MOD;



    cout << ans << endl;

}



int main() {

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    work();



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define rep(i, n) for(int i = 0; i < (n); ++i)



typedef long long ll;

typedef pair<int, int> P;



const int MAX = 1e5 + 5;

const int INF = 1001001001;

const int MOD = 1e9 + 7;



// x の n 乗 x^n を計算する

long long mod_pow(long long x, long long n, int M=1000000007) {

  long long ret = 1;

  while(n) {

    if(n & 1) (ret *= x) %= M;

    (x *= x) %= M;

    n >>= 1;

  }

  return ret;

}



// a の逆元 a^{-1} を計算する

long long inv(long long a, int M=1000000007) {

    long long b = M, u = 1, v = 0;

    while (b) {

        long long t = a / b;

        a -= t * b; swap(a, b);

        u -= t * v; swap(u, v);

    }

    u %= M;

    if (u < 0) u += M;

    return u;

}



// 二項係数 nCr を計算する

long long com(long long n, long long r, int M=1000000007) {

    long long a = 1, b = 1;

    for (int i = 1; i <= r; ++i) {

        a *= n - (i-1), b *= i;

        a %= M, b %= M;

    }

    return a * inv(b) % M;

}



int main(){

    int n, a, b;

    cin >> n >> a >> b;



    ll ans = mod_pow(2,n) - 1 - com(n,a) - com(n,b);

    while (ans < 0) ans += MOD;



    cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.2510982715002366x):
#include <bits/stdc++.h>

using namespace std;



#define rep(i, n) for(int i = 0; i < (n); ++i)



typedef long long ll;

typedef pair<int, int> P;



const int MAX = 1e5 + 5;

const int INF = 1001001001;

const int MOD = 1e9 + 7;



struct mint {

    long long x;

    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : MOD)) {}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }

    mint& operator-=(const mint& a) { if ((x -= a.x) < 0) x += MOD; return *this; }

    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }

    mint operator+(const mint& a) const { return mint(x) += a; }

    mint operator-(const mint& a) const { return mint(x) -= a; }

    mint operator*(const mint& a) const { return mint(x) *= a; }



    // for prime mod

    mint inv() const {

        long long a = x, b = MOD, u = 1, v = 0;

        while (b) {

            long long t = a / b;

            a -= t * b; swap(a, b);

            u -= t * v; swap(u, v);

        }

        return mint(u);

    }

    mint& operator/=(const mint& a) { return *this *= a.inv(); }

    mint operator/(const mint& a) const { return mint(x) /= a; }

};

ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }



long long mod_pow(long long x, long long n, int M=1000000007) {

    long long ret = 1;

    while(n) {

        if(n & 1) (ret *= x) %= M;

        (x *= x) %= M;

        n >>= 1;

    }

    return ret;

}



int main(){

    int n, a, b;

    cin >> n >> a >> b;



    mint ans = mod_pow(2, n) - 1;

    mint x = 1, y = 1;

    rep(i, a) {

        x *= n - i;

        y *= i + 1;

    }

    ans -= x / y;

    x = y = 1;

    rep(i, b) {

        x *= n - i;

        y *= i + 1;

    }

    ans -= x / y;

    cout << ans << endl;

}
// Slower C++ solution:
#include <string>

#include <iostream>

#pragma warning(disable : 4996)

using namespace std;

int H, W, R, C; string s[1000], t[1000]; unsigned long long power[1001], h1[1000][1000], h2[1000];

int main() {

	scanf("%d%d", &H, &W);

	for (int i = 0; i < H; i++) cin >> s[i];

	scanf("%d%d", &R, &C);

	for (int i = 0; i < R; i++) cin >> t[i];

	power[0] = 1;

	for (int i = 1; i <= 1000; i++) power[i] = power[i - 1] * 257;

	for (int i = 0; i < H; i++) {

		unsigned long long val = 0;

		for (int j = 0; j < C; j++) val = val * 257 + s[i][j]; h1[i][0] = val;

		for (int j = C; j < W; j++) val = val * 257 + s[i][j] - power[C] * s[i][j - C], h1[i][j - C + 1] = val;

	}

	for (int i = 0; i < R; i++) {

		for (int j = 0; j < C; j++) h2[i] = h2[i] * 257 + t[i][j];

	}

	for (int i = 0; i <= H - R; i++) {

		for (int j = 0; j <= W - C; j++) {

			bool flag = true;

			for (int k = i; k < i + R; k++) {

				if (h1[k][j] != h2[k - i]) {

					flag = false; break;

				}

			}

			if (flag) {

				printf("%d %d\n", i, j);

			}

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.51988640592827x):
#include <stdio.h>

int H, W, R, C; char s[1001][1007], t[1001][1007];

unsigned long long pw1, pw2, h1[1001][1007], h2[1001][1007], h3[1001];

int main() {

	scanf("%d%d", &H, &W);

	for(int i = 0; i < H; i++) scanf("%s", s[i]);

	scanf("%d%d", &R, &C); pw1 = 1, pw2 = 1;

	for(int i = 0; i < R; i++) scanf("%s", t[i]), pw2 *= 1000000007;

	for(int i = 0; i < C; i++) pw1 *= 257;

	for(int i = 0; i < H; i++) {

		unsigned long long w = 0;

		for(int j = 0; j < C; j++) w = w * 257 + s[i][j]; h1[i][0] = w;

		for(int j = C; j < W; j++) w = w * 257 + s[i][j] - pw1 * s[i][j - C], h1[i][j - C + 1] = w;

	}

	for(int i = 0; i <= W - C; i++) {

		unsigned long long w = 0;

		for(int j = 0; j < R; j++) w = w * 1000000007 + h1[j][i]; h2[0][i] = w;

		for(int j = R; j < H; j++) w = w * 1000000007 + h1[j][i] - pw2 * h1[j - R][i], h2[j - R + 1][i] = w;

	}

	for(int i = 0; i < R; i++) {

		for(int j = 0; j < C; j++) h3[i] = h3[i] * 257 + t[i][j];

	}

	unsigned long long h4 = 0;

	for(int i = 0; i < R; i++) h4 = h4 * 1000000007 + h3[i];

	for(int i = 0; i <= H - R; i++) { 

		for(int j = 0; j <= W - C; j++) {

			if(h2[i][j] == h4) printf("%d %d\n", i, j);

		}

	}

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MAX_N 100005

ll mod=1e9+7;



ll mul(ll a,ll b){

  return (a*b)%mod;

}



int bit[MAX_N];

void add(int i,int x){

  i++;



  while(i<MAX_N){

    bit[i]+=x;

    i+=(i&-i);

  }

}



int sum(int i){

  i++;



  int res=0;

  while(i){

    res+=bit[i];

    i-=(i&-i);

  }

  return res;

}



ll N,R,a,b;

ll fact[MAX_N];

int t[MAX_N];



int main(){

  fact[0]=1;

  for(int i=1;i<MAX_N;i++)

    fact[i]=mul(fact[i-1],i);



  while(1){

    scanf("%lld",&N);

    if(N==0)break;

    scanf("%lld",&R);

    memset(bit,0,sizeof(bit));

    for(int i=0;i<N;i++)t[i]=i;



    for(int i=0;i<R;i++){

      scanf("%lld %lld",&a,&b);

      a--,b--;

      swap(t[a],t[b]);

    }



    ll ans=0;

    for(int i=0;i<N;i++){

      ll num=t[i];

      ll cnt=num-sum(num);

      ans+= mul(fact[N-1-i],cnt);

      ans%=mod;

      add(t[i],1);

    }



    printf("%lld\n",ans);

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.108305289701396x):
#include<bits/stdc++.h>

using namespace std;

#define int long long

struct BIT{

  vector<int> bit;

  int n;

  BIT(){init();}

  BIT(int n):n(n){init();}

  void init(){

    bit.clear();

    bit.resize(n+1,0);

  }

  int sum(int i){

    int s=0;

    while(i>0){

      s+=bit[i];

      i-=i&-i;

    }

    return s;

  }

  void add(int i,int x){

    while(i<=n){

      bit[i]+=x;

      i+=i&-i;

    }

  }

};

int MOD=1000000007LL;

int s[114514],t[114514];

int fact[114514];

void init(int mod){

  fact[0]=fact[1]=1;

  for(int i=2;i<114514;i++)

    fact[i]=(fact[i-1]*i)%MOD;

}

signed main(){

  int n;

  init(MOD);

  while(cin>>n,n){

    BIT bit(n);

    for(int i=0;i<n;i++) s[i]=i+1;

    int r;

    cin>>r;

    for(int i=0;i<r;i++){

      int a,b;

      cin>>a>>b;

      a--;b--;

      swap(s[a],s[b]);

    }

    for(int i=n-1;i>=0;i--){

      t[i]=bit.sum(s[i]);

      bit.add(s[i],1);

    }

    int ans=0;

    for(int i=0;i<n;i++){

      (ans+=t[i]*fact[n-1-i])%=MOD;

    }

    cout<<ans<<endl;

  }

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define loop(i,L,R) for(int i=(L);i<=(R);i++)

#define rept(i,L,R) for(int i=(L);i<(R);i++)

#define isc(n) scanf("%d",&n)

#define llsc(n) scanf("%lld",&n)

#define dsc(n) scanf("%lf",&n)

#define enl cout<<endl

#define pb(x) push_back(x)

#define xx first

#define yy second

typedef long long ll;

typedef pair<int,int>PI;

typedef pair<pair<int,int>,int>PII;



map<int,int>a;

int main()

{

    int n,t;

    cin>>n;

    rept(i,0,n){cin>>t;a[t]++;}

    ll ans=0;

    for(auto i:a)

    {

        if(i.xx>i.yy)ans+=i.yy;

        else ans+=min((i.yy-i.xx),i.yy);

    }

    cout<<ans<<endl;

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.3406628269116485x):
#include<cstdio>

#include<algorithm>

using namespace std;

inline int read()

{

	int s=0;

    char c=getchar();

    while(c<'0' || c>'9')c=getchar();

    while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+c-48,c=getchar();

    return s;

}

int n,a[100005],ans;

int main()

{

	n=read();

	for(register int i=1;i<=n;i++)

		a[i]=read();

	sort(a+1,a+n+1);

	for(register int i=1;i<=n;i++)

	{

		int t=i;

		while(a[t+1]==a[i] && t+1<=n)  t++;

		int cnt=t-i+1;

		if(cnt>a[i])  ans+=cnt-a[i];

		if(cnt<a[i])  ans+=cnt;

		i=t;

	}

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int main()

{

    int n,i,c=0,f,x;

    scanf("%d",&n);

    int a[n];

    for(i=0; i<n; i++)  scanf("%d",&a[i]);

    sort(a,a+n);

    for(i=0; i<n; i++)

    {

        f = 0;

        x = a[i];

        while(1)

        {

            if(i>=n)    break;

            else if(a[i]!=x)

            {

                i--;

                break;

            }

            i++;

            f++;

        }

        if(f<x)    c += f;

        else if(f>x)    c += (f-x);

    }

    printf("%d\n",c);

    return  0;

}


// Faster C++ solution for the same problem (measured speedup: 5.265924631775238x):
#include<cstdio>

#include<algorithm>

using namespace std;

inline int read()

{

	int s=0;

    char c=getchar();

    while(c<'0' || c>'9')c=getchar();

    while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+c-48,c=getchar();

    return s;

}

int n,a[100005],ans;

int main()

{

	n=read();

	for(register int i=1;i<=n;i++)

		a[i]=read();

	sort(a+1,a+n+1);

	for(register int i=1;i<=n;i++)

	{

		int t=i;

		while(a[t+1]==a[i] && t+1<=n)  t++;

		int cnt=t-i+1;

		if(cnt>a[i])  ans+=cnt-a[i];

		if(cnt<a[i])  ans+=cnt;

		i=t;

	}

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;



const int MAXN = 1e5 + 10;

int cnt[MAXN], n, ans;



int main() {

	cin >> n;

	for (int i = 0; i < n; i++) {

		int a;

		cin >> a;

		if (a > 1e5)

			ans++;

		else

			cnt[a]++;

	}

	for (int i = 0; i < MAXN; i++)

		if (cnt[i] < i)

			ans += cnt[i];

		else

			ans += cnt[i] - i;

	cout << ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.442757383772635x):
#include <bits/stdc++.h>



using namespace std;



#define int long long



const int N = 1e5 + 100;



int a[N], cnt[N];

vector<int> vec;

int n, ans;



int id(int x) {

    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();

}



int32_t main() {

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    for (int i = 0; i < n; i++) {

	cin >> a[i];

	vec.push_back(a[i]);

    }

    sort(vec.begin(), vec.end());

    vec.resize(distance(vec.begin(), unique(vec.begin(), vec.end())));

    for (int i = 0; i < n; i++)

	cnt[id(a[i])]++;

    for (auto x : vec) {

	int i = id(x);

	if (cnt[i] < x)

	    ans += cnt[i];

	else

	    ans += cnt[i] - x;

    }

    return cout << ans, 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;



const int MAXN = 1e5 + 10;

int cnt[MAXN], n, ans;



int main() {

	cin >> n;

	for (int i = 0; i < n; i++) {

		int a;

		cin >> a;

		if (a > 1e5)

			ans++;

		else

			cnt[a]++;

	}

	for (int i = 0; i < MAXN; i++)

		if (cnt[i] < i)

			ans += cnt[i];

		else

			ans += cnt[i] - i;

	cout << ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.4417989920713543x):
#include <bits/stdc++.h>

using namespace std;



int n, ans;

vector<int> v;

vector<pair<int, int> > q;



int main(){

	ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	

	cin >> n;

	for (int i = 0; i < n; i++){

		int a;

		cin >> a;

		v.push_back(a);

	}	

	sort(v.begin(), v.end());

	int t = v[0], c = 1;

	for (int i = 1; i < n; i++){

		if(v[i] != v[i - 1]){

			q.push_back({t, c});

			t = v[i];

			c = 1;

		}

		else

			c++;

	}

	if(c > 0)

		q.push_back({v[n - 1], c});

	

	for (auto p : q){

		if(p.second < p.first)

			ans += p.second;

		if(p.second > p.first)

			ans += p.second - p.first;

	}

	cout << ans;

}