Submit solution

Points: 20
Time limit: 5.0s
Memory limit: 64M

Author:
Problem types

Given an N dimensional grid with coordinates in the form (x1,x2,,xN), determine the number of shortest paths from (1,1,,1) to (a1,a2,,aN), that do not pass through Q blocked points.

A path consists of a series of movements where for any single movement, you must increase a single xi by 1 unit.

Input Specification

The first line will contain a single integer, N, 1N1000.

The next line will contain N integers representing (a1,a2,,aN), 1ai1000.

The next line will contain a single integer, Q, 0Q1000.

The next Q lines will each contain a single coordinate point (x1,x2,,xN), 1xiai.

The Q points will be unique and will not include (a1,a2,,aN) or (1,1,,1).

Output Specification

The number of ways to traverse the grid, modulo 109+7.

Sample Input

Copy
2
3 4
2
2 2
1 4

Sample Output

Copy
3

Comments

There are no comments at the moment.