import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

int[] p, q;
int a, b, n, count=0;

void solve(bool[] used, int[] array, int depth=0) {
  if(depth==n) {
    count++;
    if(array==p) a = count;
    if(array==q) b = count;
    return;
  }
  for(int i=0; i<n; i++) {
    if(!used[i]) {
      auto dup = array.dup;
      dup[depth] = i+1;
      auto du = used.dup;
      du[i] = true;
      solve(du, dup, depth+1);
    }
  }
}

void main() {
  n = readln.chomp.to!int;
  p = readln.chomp.split.to!(int[]);
  q = readln.chomp.split.to!(int[]);
  auto used = new bool[n];
  auto array = new int[n];
  solve(used, array);
  writeln(abs(a-b));
}

