N = int(input())
Ps = list(map(int, input().split()))
Qs = list(map(int, input().split()))


cnt = 0
start = 0
end = 0
is_hit = False
for i in range(1,N+1):
    for j in range(1,N+1):
        if j in [i]:
            continue
        if N == 2:
            cnt += 1
        if [i, j] == Ps:
            start = cnt
        if [i, j] == Qs:
            end = cnt
        if start * end > 0:
            is_hit = True
            break
        if N == 2:
            continue
        for k in range(1,N+1):
            if k in [i, j]:
                continue
            if N == 3:
                cnt += 1
            if [i, j, k] == Ps:
                start = cnt

            if [i, j, k] == Qs:
                end = cnt
            if start * end > 0:
                is_hit = True
                break
            if N == 3:
                continue
            for l in range(1,N+1):
                if l in [i, j, k]:
                    continue
                if N == 4:
                    cnt += 1
                if [i, j, k, l] == Ps:
                    start = cnt

                if [i, j, k, l] == Qs:
                    end = cnt

                if start * end > 0:
                    is_hit = True
                    break

                if N == 4:
                    continue
                for m in range(1, N+1):
                    if m in [i, j, k, l]:
                        continue
                    if N == 5:
                        cnt += 1
                    if [i, j, k, l, m] == Ps:
                        start = cnt
                    if [i, j, k, l, m] == Qs:
                        end = cnt

                    if start * end > 0:
                        is_hit = True
                        break

                    if N == 5:
                        continue
                    for n in range(1, N+1):
                        if n in [i, j, k, l, m]:
                            continue
                        if N == 6:
                            cnt += 1
                        if [i, j, k, l, m, n] == Ps:
                            start = cnt
                        if [i, j, k, l, m, n] == Qs:
                            end = cnt
                        if start * end > 0:
                            is_hit = True
                            break
                        if N == 6:
                            continue
                        for o in range(1, N+1):
                            if o in [i, j, k, l, m, n]:
                                continue
                            if N == 7:
                                cnt += 1
                            if [i, j, k, l, m, n, o] == Ps:
                                start = cnt
                            if [i, j, k, l, m, n, o] == Qs:
                                end = cnt
                            if start * end > 0:
                                is_hit = True
                                break
                            if N == 7:
                                continue
                            for p in range(1, N+1):
                                if p in [i, j, k, l, m, n, o]:
                                    continue
                                if N == 8:
                                    cnt += 1
                                if [i, j, k, l, m, n, o, p] == Ps:
                                    start = cnt
                                if [i, j, k, l, m, n, o, p] == Qs:
                                    end = cnt
                                if start * end > 0:
                                    is_hit = True
                                    break
                            if is_hit:
                                break
                        if is_hit:
                            break
                    if is_hit:
                        break
                if is_hit:
                    break
            if is_hit:
                break
        if is_hit:
            break
    if is_hit:
        break

print(abs(end - start))


Measured memory_bytes: 3272