Problem: When Petya has free from computer games time, he attends university classes. Every day the lessons on Petya’s faculty consist of two double classes. The floor where the lessons take place is a long corridor with M classrooms numbered from 1 to M, situated along it.

All the students of Petya’s year are divided into N groups. Petya has noticed recently that these groups’ timetable has the following peculiarity: the number of the classroom where the first lesson of a group takes place does not exceed the number of the classroom where the second lesson of this group takes place. 

Once Petya decided to count the number of ways in which one can make a lesson timetable for all these groups. The timetable is a set of 2N numbers: for each group the number of the rooms where the first and the second lessons take place. Unfortunately, he quickly lost the track of his calculations and decided to count only the timetables that satisfy the following conditions:

1) On the first lesson in classroom i exactly Xi groups must be present.

2) In classroom i no more than Yi groups may be placed.

Help Petya count the number of timetables satisfying all those conditionsю As there can be a lot of such timetables, output modulo 109 + 7.

Input

The first line contains one integer M (1 ≤ M ≤ 100) — the number of classrooms.

The second line contains M space-separated integers — Xi (0 ≤ Xi ≤ 100) the amount of groups present in classroom i during the first lesson.

The third line contains M space-separated integers — Yi (0 ≤ Yi ≤ 100) the maximal amount of groups that can be present in classroom i at the same time.

It is guaranteed that all the Xi ≤ Yi, and that the sum of all the Xi is positive and does not exceed 1000.

Output

In the single line output the answer to the problem modulo 109 + 7.

Examples

Input

3
1 1 1
1 2 3


Output

36


Input

3
1 1 1
1 1 1


Output

6

Note

In the second sample test the first and the second lessons of each group must take place in the same classroom, that’s why the timetables will only be different in the rearrangement of the classrooms’ numbers for each group, e.g. 3! = 6.

Solution (in JAVA):

Solution:
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.*;

public class Main implements Runnable {
	private boolean _READ_FROM_FILE = System.getProperty("ONLINE_JUDGE") == null; //System.getSecurityManager() == null; //
	private boolean _WRITE_TO_FILE = false;
	static final String _TASK_ID = "in";
	static final String _IN_FILE = _TASK_ID + ".in";
	static final String _OUT_FILE = _TASK_ID + ".out";
	BufferedReader reader;
	StringTokenizer tokenizer;

	long MODULO = 1000000000 + 7;
	private long[] fact;
	private long[] invFact;
	private void core() throws Exception {
		int m = nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		int n = 0;
		for (int i = 0; i < a.length; i++) {
			a[i] = nextInt();
			n += a[i];
		}
		for (int i = 0; i < b.length; i++) {
			b[i] = nextInt();
		}
		
		fact = new long[n + 1];
		fact[0] = 1;
		for (int i = 1; i < fact.length; i++) {
			fact[i] = (fact[i - 1] * i) % MODULO;
		}
		invFact = new long[n + 1];
		for (int i = 0; i < invFact.length; i++) {
			invFact[i] = BigInteger.valueOf(fact[i]).modInverse(BigInteger.valueOf(MODULO)).longValue();
		}
		
		long[][] ways = new long[m + 1][n + 1];
		ways[0][0] = 1;
		for (int i = 0; i < ways.length - 1; i++) {
			for (int j = 0; j < ways[i].length; j++) {
				if (ways[i][j] > 0) {
					int free = j + a[i];
					for (int k = 0; k <= Math.min(free, b[i]); k++) {
						ways[i + 1][free - k] += (ways[i][j] * nCr(free, k)) % MODULO;
						ways[i + 1][free - k] %= MODULO;
					}
				}
			}
		}
		
		long res = ways[m][0];
		res = (res * fact[n]) % MODULO;
		for (int i = 0; i < a.length; i++) {
			res *= invFact[a[i]];
			res %= MODULO;
		}
		System.out.println(res % MODULO);
	}
	private long nCr(int n, int r) {
		long res = fact[n];
		res = (res * invFact[r]) % MODULO;
		res = (res * invFact[n - r]) % MODULO;
		return res;
	}
	void debug(Object...os) {
		System.out.println(Arrays.deepToString(os));
	}
//--------------------- IO stuffs ---------------------
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Main());
        thread.start();
        thread.join();
    }
	public void run() {
        try {
        	reader = new BufferedReader(_READ_FROM_FILE ? new FileReader(_IN_FILE) : new InputStreamReader(System.in));
        	System.setOut(new PrintStream(new BufferedOutputStream(_WRITE_TO_FILE ? new FileOutputStream(_OUT_FILE) : System.out)));
            tokenizer = new StringTokenizer("");
            core();
            reader.close();
            System.out.flush();
            System.out.close();
            System.exit(0);
        } catch (Exception e) {
        	System.out.flush();
            e.printStackTrace();
            System.exit(1);
        }
    }
    int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
    String nextToken() throws Exception {
        while (!tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }
    boolean nextIsAvailable() throws Exception {
    	while (!tokenizer.hasMoreElements()) {
    		String line = reader.readLine();
    		if (line == null) return false;
    		tokenizer = new StringTokenizer(line);
    	}
    	return true;
    }
}