import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static <T> void printArray(T[] arr) {
        for (T x : arr)
            print(x, " ");
        printn("");
    }

    static <T> void print(T s, String sep) {
        System.out.print(s + sep);
    }

    static <T> void printn(T s) {
        System.out.println(s);
    }

    static Long[] inputArrL(int n, FastReader fr) {
        Long[] arr = new Long[n];
        for (int i = 0; i < n; i++)
            arr[i] = fr.nextLong();
        return arr;
    }

    static Integer[] inputArr(int n, FastReader fr) {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = fr.nextInt();
        return arr;
    }

    static int maxValue(Integer[] arr, int idx, int f, int[][] dp) {
        int res = 0;
        if (idx == arr.length)
            return 0;
        if (dp[idx][f] != -1)
            return dp[idx][f];
        if (f == 2) {
            if (arr[idx] == 0)
                res = Math.max(1 + maxValue(arr, idx + 1, 1, dp), maxValue(arr, idx + 1, f, dp));
            else
                res = Math.max(1 + maxValue(arr, idx + 1, f, dp), maxValue(arr, idx + 1, 1, dp));
        } else if (f == 1)
            res = Math.max(1 - arr[idx] + maxValue(arr, idx + 1, f, dp), arr[idx] + maxValue(arr, idx + 1, 0, dp));
        else
            res = arr[idx] + maxValue(arr, idx + 1, f, dp);
        return res;
    }

    static int max(int... args) {
        int max = Integer.MIN_VALUE;
        for (int x : args) {
            max = Math.max(x, max);
        }
        return max;
    }

    static int min(int... args) {
        int min = Integer.MAX_VALUE;
        for (int x : args) {
            min = Math.min(x, min);
        }
        return min;
    }
	static void nextPermutation(int[] nums) {
		int mark = -1;
		for (int i = nums.length - 1; i > 0; i--) {
			if (nums[i] > nums[i - 1]) {
				mark = i - 1;
				break;
			}
		}

		if (mark == -1) {
			reverse(nums, 0, nums.length - 1);
			return;
		}

		int idx = nums.length-1;
		for (int i = nums.length-1; i >= mark+1; i--) {
			if (nums[i] > nums[mark]) {
				idx = i;
				break;
			}
		}

		swap(nums, mark, idx);

		reverse(nums, mark + 1, nums.length - 1);
	}

	static void swap(int[] nums, int i, int j) {
		int t = nums[i];
		nums[i] = nums[j];
		nums[j] = t;
	}

	static void reverse(int[] nums, int i, int j) {
		while (i < j) {
			swap(nums, i, j);
			i++;
			j--;
		}
	}

	static Integer[] toIntArr(int[] arr){
    	Integer[] a = new Integer[arr.length];
    	for(int i=0; i<arr.length; i++)
    		a[i] = arr[i];
    	return a;
	}

	public static void main(String[] args) {
    	FastReader fr = new FastReader();
    	int n = fr.nextInt();
    	int[] z = new int[n];
    	for(int i=0; i<n; i++)
    		z[i] = i+1;
    	int[] a = new int[n];
    	int[] b = new int[n];
    	for(int i=0; i<n; i++)
    		a[i] = fr.nextInt();
    	for(int i=0; i<n; i++)
    		b[i] = fr.nextInt();
		int x = 0;
		while(true){
			if(Arrays.equals(a, z))
				break;
			x++;
			nextPermutation(z);
		}
		int y = 0;
		for(int i=0; i<n; i++)
			z[i] = i+1;
		while(true){
			if(Arrays.equals(b, z))
				break;
			y++;
			nextPermutation(z);
		}
		System.out.println(Math.abs(x - y));
	}
}


Measured memory_bytes: 21716