// Arup Guha
// 1/28/2021
// Solution to 2021 USACO January Bronze Problem: Just Stalling

import java.util.*;

public class stalling {

	public static int n;
	public static int[] heights;
	public static int[] limits;
	
	public static long[] memo;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		heights = new int[n];
		limits = new int[n];
		
		// Cases we've already solved. -1 means we haven't done it yet.
		memo = new long[1<<n];
		Arrays.fill(memo, -1);
		
		// One way to place 0 cows in 0 stalls.
		memo[(1<<n)-1] = 1;
		
		// 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, 0));
	}
	
	// Same as slow solution, but mask represents the subset of cows already placed.
	public static long go(int[] perm, boolean[] used, int k, int mask) {
	
		// We've done this case before.
		if (memo[mask] != -1) return memo[mask];
		
		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.
			// We add to the mask cow #i, which has value "2 to the i", in bitshifts this is (1<<i).
			res += go(perm, used, k+1, mask | (1<<i));
			
			// Undo this cow.
			used[i] = false;
		}
		
		// Store and return.
		return memo[mask] = res;
	}
}