You are on page 1of 4

Problem Statement

Lets soive the problem of new virus spreading in the town.

There are nhouses in the town, numbered from 1 to n


from left to
right. You are given m, the number of
houses which are already
infected, and anarray infect of size m where infected, denotees
the index of the i-th infected house.

0 2 2

Each day every infected house infects its uninfected


w
neighbour,if
there exists any.

As we can see, this process continues until all the houses are
infected. The order in whicth the uninfected houses are infected is
called an infection sequence. Find the total number of distinct
infection sequences. Since the answer could be large print it with
modulo 1000000007.
Input Format
The first line contains an
integer, n, denoting the total number of
houses
The next line contains an integer, m, denoting the number of
elements in infect.
Each line i of the msubsequent lines (where 0si<m) contains
an integer
describing infect[i]

Constraints w

ww
wwww

1 n<= 10 5 w

ww

1<= m <= n-1


ww

1< infect|il<= n

Sample Input Sample Output Explanation


WY

4 ww. There are 4


www. houses. Initially
1 the only infected
On t h o
indeananth@gmail.com

Sample Output Explanationn


Sample Input
iil

There are 4
A
1 houses. Initially
the only infected
house is 1. On the
1st day, house 2
gets infected by

th@gmal.o ww

www
wwwwwww
AW

www
ww
ww ww
wWwww

www.wwww
house 1. On the
2nd day, house 3
gets infected by
TRW house 2. On the
w 3rd day, house 4
gets infected by
house 3. The onlyy
possible infection
sequence is

[2.3.4
5 4 Initially, only housse
3 is infected. On
3 Day 1, houses 2
and 4 get infected.
deananth@gmail.com

and 4 get infected


On Day 2, houses
ww
M
1 and 5 get
infected. The
possible infection
ww.wwMM
sequences are:
ww

AMWW.Awww.ww.wAWAWAAWMAMAMAWI
WA
MAAww.
WAWAM [2.4,1.5]. 14.2.1,5].
w
12.4.5.11. 14.2.5.11
Www

w
ww ww
6 Www WwY Initially, houses 3
6 www

and 5 are infected.


2
On day 1, houses
3
5 2 and 4 get
infected and
house 6 also gets
infected. On day 2
house 1 gets
infected. The
possible infection
sequences are:

[2.4,6.1). [2.6.4,1]
[4.6.2.11. [4,2.6.1].
[6,2,4.1], [6,4.2.1]

You might also like