#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
static const int MODVAL = 1000000009; // must be prime for op/
struct mint
{
int val;
mint():val(0){}
mint(int x):val(x%MODVAL) {} // x>=0
mint(size_t x):val(x%MODVAL) {} // x>=0
mint(LL x):val(x%MODVAL) {} // x>=0
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }
mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }
mint operator/(mint x, mint y) { return x/=y; }
vector<mint> FAC_(1,1);
mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; }
mint C(LL n, LL k) { return k<0 || n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
class AxonometricProjection { public:
int howManyWays(vector <int> left, vector <int> front)
{
mint ans = 1;
sort(left.begin(), left.end());
sort(front.begin(), front.end());
ans *= perm(left);
ans *= perm(front);
for(int i=0, k=0; i<left.size() || k<front.size(); )
{
if( k<front.size() && (i==left.size() || front[k]<left[i]) )
{
// advance k
int h = front[k];
int len = 0;
while( k!=front.size() && front[k]==h )
++k, ++len;
ans *= choose(h, len);
}
else if( i<left.size() && (k==front.size() || left[i]<front[k]) )
{
// advance i
int h = left[i];
int len = 0;
while( i!=left.size() && left[i]==h )
++i, ++len;
ans *= choose(h, len);
}
else
{
// both
int h = left[i];
assert( h == front[k] );
int len1 = 0, len2 = 0;
while( i!=left.size() && left[i]==h )
++i, ++len1;
while( k!=front.size() && front[k]==h )
++k, ++len2;
ans *= choose2(h, len1, len2);
}
}
return ans.val;
}
mint perm(const vector<int>& x)
{
map<int,int> cat;
for(int i=0; i<x.size(); ++i)
cat[x[i]]++;
mint r = FAC(x.size());
for(map<int,int>::iterator it=cat.begin(); it!=cat.end(); ++it)
r /= FAC(it->second);
return r;
}
mint choose(int h, int n)
{
mint r = 0;
for(int k=1; k<=n; ++k)
r += C(n, k) * POW(h, n-k);
return r;
}
mint choose2(int h, int n1, int n2)
{
return POW(2, n1+n2) + h * choose(h,n1) * choose(h,n2);
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, AxonometricProjection().howManyWays(heightsOfLeftView, heightsOfFrontView));}
int main(){
CASE(0)
int heightsOfLeftView_[] = {1,1};
vector <int> heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_));
int heightsOfFrontView_[] = {1,1};
vector <int> heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_));
int _ = 7;
END
CASE(1)
int heightsOfLeftView_[] = {50,50,50,50,524};
vector <int> heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_));
int heightsOfFrontView_[] = {524,524};
vector <int> heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_));
int _ = 104060401;
END
CASE(2)
int heightsOfLeftView_[] = {1,2,3,4,5,6,7,8,9,10};
vector <int> heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_));
int heightsOfFrontView_[] = {1,2,3,4,5,6,7,8,9,10,11};
vector <int> heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_));
int _ = 0;
END
CASE(3)
int heightsOfLeftView_[] = {5,2,4,1};
vector <int> heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_));
int heightsOfFrontView_[] = {5,2,4,0,1};
vector <int> heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_));
int _ = 429287;
END
CASE(4)
int heightsOfLeftView_[] = {5,2,4,52,24,524};
vector <int> heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_));
int heightsOfFrontView_[] = {0,4,20,24,500,504,520,524};
vector <int> heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_));
int _ = 97065655;
END
/*
CASE(5)
int heightsOfLeftView_[] = ;
vector <int> heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_));
int heightsOfFrontView_[] = ;
vector <int> heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_));
int _ = ;
END
CASE(6)
int heightsOfLeftView_[] = ;
vector <int> heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_));
int heightsOfFrontView_[] = ;
vector <int> heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_));
int _ = ;
END
*/
}
// END CUT HERE