Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Microscopic particles suspended on any fluid has a chaotic behavior since they do not stay at same location. Every moment they experience a number of collisions with fluid molecules from different directions. As a result of these collisions,the particle moves randomly as if it is confused all the time. In physics, this phenomenon is known as *Brownian Motion* named after the Scottish botanist Robert Brown who first described the phenomenon in 1827. Then, almost 80 years later, in 1905, Albert Einstein published a paper explaining Brownian Motion to establish the idea of existence of atoms and molecules. Now, more than 100 years later, with advancements of computer science, modeling the physical phenomena has become an important task for physicists. Since you are a great programmer and love to solve challenging problems, a group of physicists from your country came to you to help them solve this problem regarding Brownian Motion.

For a particle placed on the water surface, the physicists want to know the probability of the particle reaching another point on the surface after a certain amount of time. To model the scenario they imagined the surface of the fluid as a two-dimensional grid and each cell of the grid represents a point on the fluid surface. At each millisecond, the particle moves from one cell to any of its eight neighbor cells. The surface is a closed system, therefore, particles can not escape by crossing the boundary of the grid.

Initially, the surface is divided into an $n\times n$ grid, where, $1 \lt n \le 100$. Cells are identified with the their row and column number as $(r,c)$ where $0\le r, c \lt n$. If a particle is located at $(r,c)$, after a millisecond it must move to any of the following cells $(r, c+1)$, $(r,c-1)$, $(r+1, c)$, $(r+1, c+1)$, $(r+1,c-1)$, $(r-1, c)$, $(r-1, c+1)$, $(r-1, c-1)$. You will be given the initial position $(r_i, c_i)$and final position $(r_f, c_f)$. You have to find the probability of reaching from $(r_i, c_i)$ to $(r_f, c_f)$ after $t$ milliseconds, where, $0\le t \le 10^3$.

The probability can be represented as $\frac{P}{Q}$ where $P, Q$ are co-prime integers. Let, $Q^{-1}$ be an integer for which $Q.Q^{-1} \equiv 1 \pmod{10^9+7}$. You have to print $P.Q^{-1} \pmod{10^9+7}$.

The input consist of two lines.

First line of input contains two integers $n$$(1\lt n \le 100)$ and $t$$(0\le t \le 10^3)$ separated by space.

Following line contains 4 integers $r_i, c_i, r_f, c_f$ $(0 \le r_i, c_i, r_f, c_f \lt n)$ separated by space.

Print a single integer, the probability of reaching initial to final cell after $t$ milliseconds as $P.Q^{-1} \pmod{10^9+7}$.

Input | Output |
---|---|

6 0 2 3 2 3 | 1 |

Input | Output |
---|---|

60 110 4 40 2 56 | 448675357 |

Input | Output |
---|---|

4 2 1 1 2 2 | 281250002 |

**Note**: The particle must move after a millisecond. It can not stay at the same cell for more than 1 millisecond.

100% Solution Ratio

Saadmaan007Earliest,

Saadmaan007Fastest, 0.9s

Saadmaan007Lightest, 82 MB

Saadmaan007Shortest, 820B

Login to submit