void main()
{
    long n = rdElem;
    long[] p = rdRow;
    long[] q = rdRow;

    long num = 1;
    foreach (i; 2 .. n)
    {
        num *= i;
    }

    bool[] used = new bool[n+1];
    long a;
    long anum = num;
    foreach (i, x; p)
    {
        long cnt;
        foreach (j; 1 .. x)
        {
            if (used[j]) ++cnt;
        }

        a += anum * (x - cnt);
        used[x] = true;
        if (i != n - 1) anum /= (n - i - 1);
    }

    used[] = false;
    long b;
    long bnum = num;
    foreach (i, x; q)
    {
        long cnt;
        foreach (j; 1 .. x)
        {
            if (used[j]) ++cnt;
        }

        b += bnum * (x - cnt);
        used[x] = true;
        if (i != n - 1) bnum /= (n - i - 1);
    }

    abs(a-b).writeln;
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;