function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var N = parseInt(input[0], 10);
    var vec_P = input[1].map(e => parseInt(e, 10));
    var vec_Q = input[2].map(e => parseInt(e, 10));
    var pi, qi, a, b;
    a = b = 1;
    for (var i = 0; i < (N - 1); i++){
    	pi = vec_P[0];
    	qi = vec_Q[0];
    	
    	vec_P.shift();
    	vec_Q.shift();
    	a += (N - (i + 1) - countAbove(pi, vec_P)) * kaijo(N - (i + 1));
    	b += (N - (i + 1) - countAbove(qi, vec_Q)) * kaijo(N - (i + 1));
    }
	console.log(Math.abs(a-b));
}

function countAbove(num, vec){
	var ans = 0;
	for (var i = 0; i < vec.length; i++){
		if (vec[i] > num) ans++;
	} 
	return ans;	
}

function kaijo(num){
	var ans = 1;
	for (var i = 2; i <= num; i++){
		ans *= i;
	} 
	return ans;	
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));