N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
count = 0

if N == 2:
    for i in range(N):
        for j in range(N):
            if j == i: continue
            count += 1
            if [i+1, j+1] == P:
                a = count
            if [i+1, j+1] == Q:
                b = count
elif N == 3:
    for i in range(N):
        for j in range(N):
            if j == i: continue
            for k in range(N):
                if k == j or k == i: continue
                count += 1
                if [i+1, j+1, k+1] == P:
                    a = count
                if [i+1, j+1, k+1] == Q:
                    b = count
elif N == 4:
    for i in range(N):
        for j in range(N):
            if j == i: continue
            for k in range(N):
                if k == j or k == i: continue
                for l in range(N):
                    if l == k or l == j or l == i: continue
                    count += 1
                    if [i+1, j+1, k+1, l+1] == P:
                        a = count
                    if [i+1, j+1, k+1, l+1] == Q:
                        b = count
elif N == 5:
    for i in range(N):
        for j in range(N):
            if j == i: continue
            for k in range(N):
                if k == j or k == i: continue
                for l in range(N):
                    if l == k or l == j or l == i: continue
                    for m in range(N):
                        if m == l or m == k or m == j or m == i: continue
                        count += 1
                        if [i+1, j+1, k+1, l+1, m+1] == P:
                            a = count
                        if [i+1, j+1, k+1, l+1, m+1] == Q:
                            b = count
elif N == 6:
    for i in range(N):
        for j in range(N):
            if j == i: continue
            for k in range(N):
                if k == j or k == i: continue
                for l in range(N):
                    if l == k or l == j or l == i: continue
                    for m in range(N):
                        if m == l or m == k or m == j or m == i: continue
                        for n in range(N):
                            if n == m or n == l or n == k or n == j or n == i: continue
                            count += 1    
                            if [i+1, j+1, k+1, l+1, m+1, n+1] == P:
                                a = count
                            if [i+1, j+1, k+1, l+1, m+1, n+1] == Q:
                                b = count
elif N == 7:
    for i in range(N):
        for j in range(N):
            if j == i: continue
            for k in range(N):
                if k == j or k == i: continue
                for l in range(N):
                    if l == k or l == j or l == i: continue
                    for m in range(N):
                        if m == l or m == k or m == j or m == i: continue
                        for n in range(N):
                            if n == m or n == l or n == k or n == j or n == i: continue
                            for o in range(N):
                                if o == n or o == m or o == l or o == k or o == j or o == i: continue
                                count += 1
                                if [i+1, j+1, k+1, l+1, m+1, n+1, o+1] == P:
                                    a = count
                                if [i+1, j+1, k+1, l+1, m+1, n+1, o+1] == Q:
                                    b = count
elif N == 8:
    for i in range(N):
        for j in range(N):
            if j == i: continue
            for k in range(N):
                if k == j or k == i: continue
                for l in range(N):
                    if l == k or l == j or l == i: continue
                    for m in range(N):
                        if m == l or m == k or m == j or m == i: continue
                        for n in range(N):
                            if n == m or n == l or n == k or n == j or n == i: continue
                            for o in range(N):
                                if o == n or o == m or o == l or o == k or o == j or o == i: continue
                                for p in range(N):
                                    if p == o or p == n or p == m or p == l or p == k or p == j or p == i: continue
                                    count += 1
                                    if [i+1, j+1, k+1, l+1, m+1, n+1, o+1, p+1] == P:
                                        a = count
                                    if [i+1, j+1, k+1, l+1, m+1, n+1, o+1, p+1] == Q:
                                        b = count

print(abs(a - b))

Measured memory_bytes: 71792