/**
 * @author      : omgursocute
 * @created     : 11/01/2020
 */

// ===== TEMPLATE STARTS HERE ===== //

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define FORa(i, a, b) for(ll i = (a); i <= (b); ++i)
#define FORb(i, a, b, c) for(ll i = (a); i <= (b); i += (c))
#define FORn(i, n) for(ll i = 0; i < (n); ++i)

#define FORra(i, a, b) for(ll i = (a); i >= (b); --i)
#define FORrb(i, a, b, c) for(ll i = (a); i >= (b); i -= (c))
#define FORrn(i, n) for(ll i = ((n)-1); i >= 0; --i)

#define CT(_1, _2, _3, _4, NAME, ...) NAME
#define FOR(...) CT(__VA_ARGS__, FORb, FORa, FORn)(__VA_ARGS__)
#define RFOR(...) CT(__VA_ARGS__, FORrb, FORra, FORrn)(__VA_ARGS__)

#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define pb push_back
#define mp make_pair

#define debug(x) cerr << '[' << #x << ']' << " = " << x << '\n';

namespace bmsk {
	void setbit(ll &x, ll n) {x |= (1 << n);}
	void clrbit(ll &x, ll n) {x &= ~(1 << n);}
	bool chkbit(ll &x, ll n) {return ((x >> n) & 1);}
}
namespace io {
	void openIn(string s) {freopen(s.c_str(), "r", stdin);}
	void openOut(string s) {freopen(s.c_str(), "w", stdout);}
	void setIO(string s = "") {
		ios::sync_with_stdio(false);
		cin.tie(NULL); cout.tie(NULL);
		if(s.size()) {openIn(s + ".inp"); openOut(s + ".out");}
	}
}
namespace fastscan {
#ifdef linux
#define getchar(x) getchar_unlocked(x)
#endif // linux
	template<typename T>
	void readint(T &result) {
		result = 0;
		bool neg = 0;
		char ch; ch = getchar();
		while(true) {
			if(ch == '-') break;
			if(ch >= '0' && ch <= '9') break;
			ch = getchar();
		}
		if(ch == '-') neg = 1;
		else result = ch-'0';
		while(true) {
			ch = getchar(); if(ch < '0' || ch > '9') break;
			result = (result << 3) + (result << 1) + (ch - '0');
		}
		if(neg) result = -result;
	}

	void readstr(string &s) {
		s = "";
		while(true) {
			char c = getchar(); if(c == '\n' || c == ' ') break;
			s += c;
		}
	}

	template<typename T>
	void readld(T &result) {
		char ch; result = 0.;
		bool seen = 0; bool sign = 0;
		char values[20]; bool beforeDot = 1;
		int beforeLength = 0; ld multiplier;

		while(ch = getchar()) {
			if(ch == '-') {sign = 1;continue;}
			if(ch == ' ' || ch == '\n') {if(seen) break;continue;}
			if(ch == '.') {
				beforeDot = 0; multiplier = 1.;
				while(beforeLength) {
					result += (ld)(values[--beforeLength] - '0') * multiplier;
					multiplier *= 10.;
				}
				multiplier = 10.;
			}
			else {
				if(!beforeDot) {
					result += ld(ch - '0') / multiplier;
					multiplier *= 10.;
				}
				else values[beforeLength++] = ch;
				seen = 1;
			}
		}
		if(beforeDot) {
			multiplier = 1;
			while(beforeLength) {
				result += (ld)(values[--beforeLength] - '0') * multiplier;
				multiplier *= 10.;
			}
		}

		if(sign) result *= -1.;
		return;
	}
}
using namespace io;
using namespace bmsk;
using namespace fastscan;

// ======= TEMPLATE ENDS HERE ======= //

int main() {
	setIO("");

	int n; readint(n);
	string p, q;
	FOR(i, n) {
		int x; readint(x);
		p += char(x + '0');
	}
	FOR(i, n) {
		int x; readint(x);
		q += char(x + '0');
	}
	int a, b, ct = 0;
	string s = p;
	sort(all(s));

	do {
		++ct;
		if(p == s) a = ct;
		if(q == s) b = ct;
	} while(next_permutation(all(s)));

	cout << abs(a-b);

	return 0;
}



Measured memory_bytes: 256