洛谷P4859
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
using ll=long long;
const int mod=1e9+9,N=2e3+9;
ll n,k,a[(int)2e3+9],b[(int)2e3+9],dp[(int)2e3+9][(int)2e3+9];
int ksm(int a,int b){
int ret=1;
for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ret=1ll*ret*a%mod;
return ret;
}
int inv(int x){return ksm(x,mod-2);}
ll fact[N],inv_fact[N];
ll C(int n,int m){
if(m>n||n<0||m<0)return 0;
return 1ll*fact[n]*inv_fact[m]%mod*inv_fact[n-m]%mod;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
fact[0]=1;
f(i,1,n)fact[i]=1ll*fact[i-1]*i%mod;
inv_fact[n]=inv(fact[n]);
for(int i=n-1;i>=0;i--)inv_fact[i]=1ll*inv_fact[i+1]*(i+1)%mod;
f(i,1,n)cin>>a[i];
f(i,1,n)cin>>b[i];
if((k^n)&1){cout<<'0';return 0;}
sort(a+1,a+1+n);
sort(b+1,b+1+n);
f(i,0,n)dp[i][0]=1;
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*(lower_bound(b+1,b+1+n,a[i])-(b+1)-(j-1))%mod)%mod;
}
}
k=(n+k)>>1;
ll ans=0,res;
for(int i=k;i<=n;++i){
if((i^k)&1)res=-1;
else res=1;
ans=(ans+res*C(i,k)*dp[n][i]%mod*fact[n-i]%mod+mod)%mod;
}
cout<<(ans%mod+mod)%mod;
return 0;
}