using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int N;
        Input(out N);
        int[] P, Q;
        InputArray(out P);
        InputArray(out Q);
        int[] set = new int[N];
        for(int i = 1; i <= N; i++) {
            set[i - 1] = i;
        }
        int[][] list = Get(set);
        int a = Array.BinarySearch(list, P, new Comp());
        int b = Array.BinarySearch(list, Q, new Comp());
        Console.WriteLine(Math.Abs(a - b));
    }
    static int[][] Get(int[] set) {
        if(set.Length == 1) {
            return new int[][] { set };
        } else {
            List<int[]> ret = new List<int[]>();
            foreach(int item in set) {
                var removedSet = new List<int>(set);
                removedSet.Remove(item);
                var result = Get(removedSet.ToArray());
                foreach(var r in result) {
                    var i = new int[] { item }.ToList();
                    i.AddRange(r);
                    ret.Add(i.ToArray());
                }
            }
            return ret.ToArray();
        }
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
}
public class Comp : IComparer<int[]> {
    public int Compare(int[] x, int[] y) {
        for(int i = 0; i < x.Length; i++) {
            if(x[i] > y[i]) {
                return 1;
            } else if(x[i] < y[i]) {
                return -1;
            }
        }
        return 0;
    }
}

Measured memory_bytes: 30340