// Arup Guha
// 1/28/2021
// Partial Solution to 2021 USACO January Bronze Problem: Just Stalling
// Note: This uses the regular permutation algorithm and is only intended to pass
//       cases 1 through 5...

import java.util.*;

public class stalling_slow {

	public static int n;
	public static int[] heights;
	public static int[] limits;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		heights = new int[n];
		limits = new int[n];
		
		// Read in heights.
		for (int i=0; i<n; i++)
			heights[i] = stdin.nextInt();
			
		// Read in limits.
		for (int i=0; i<n; i++)
			limits[i] = stdin.nextInt();	

		// Note: if perm[k] = i, then stall k contains cow #i...
			
		// Ta da!
		System.out.println(go(new int[n], new boolean[n], 0));
	}

	// Returns the number of solutions where the first k cows are fixed.
	public static long go(int[] perm, boolean[] used, int k) {
	
		// Finished a permutation.
		if (k == n) return 1;
		
		long res = 0;
		
		// Try each cow in stall k.
		for (int i=0; i<n; i++) {
		
			// This cow is already placed.
			if (used[i]) continue;
			
			// This cow is too tall to go in stall k.
			if (heights[i] > limits[k]) continue;
		
			// Place this cow, i, in the stall, k.
			perm[k] = i;
			used[i] = true;
			
			// Add in all solutions with these k+1 cows fixed.
			res += go(perm, used, k+1);
			
			// Undo this cow.
			used[i] = false;
		}
		
		// Ta da!
		return res;
	}
}