inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
P = inp.shift().split(' ').map(x => x-0)
Q = inp.shift().split(' ').map(x => x-0)
p = 0
q = 0

for (i=0; i<N; i++) {
    a = 0
    b = 0
    
    x = P[i]

    d = 0
    for (j=i+1; j<N; j++) {
       if (x > P[j]) {
           d++
       }
    }

    if (d > 0) {
        a = 1
        a *= d
        c = 1
        for (x = N - i - 1;x > 1; x--) {
            c *= x
        }
        p += a * c
    }


    x = Q[i]
    d = 0
    for (j=i+1; j<N; j++) {
       if (x > Q[j]) {
           d++
       }
    }

    if (d > 0) {
        a = 1
        a *= d
        c = 1
        for (x = N - i - 1;x > 1; x--) {
            c *= x
        }
        q += a * c
    }
}
console.log(Math.abs(p - q))
