Problem: You are given integers N, K, and an integer sequence A of length M.

An integer sequence where each element is between 1 and K (inclusive) is said to be colorful when there exists a contiguous subsequence of length K of the sequence that contains one occurrence of each integer between 1 and K (inclusive).

For every colorful integer sequence of length N, count the number of the contiguous subsequences of that sequence which coincide with A, then find the sum of all the counts. Here, the answer can be extremely large, so find the sum modulo 10^9+7.

Constraints

* 1 \leq N \leq 25000
* 1 \leq K \leq 400
* 1 \leq M \leq N
* 1 \leq A_i \leq K
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N K M
A_1 A_2 ... A_M


Output

For every colorful integer sequence of length N, count the number of the contiguous subsequences of that sequence which coincide with A, then print the sum of all the counts modulo 10^9+7.

Examples

Input

3 2 1
1


Output

9


Input

4 2 2
1 2


Output

12


Input

7 4 5
1 2 3 1 2


Output

17


Input

5 4 3
1 1 1


Output

0


Input

10 3 5
1 1 2 3 3


Output

1458


Input

25000 400 4
3 7 31 127


Output

923966268


Input

9954 310 12
267 193 278 294 6 63 86 166 157 193 168 43


Output

979180369

Solution (in CPP):

Solution:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int n,k,m,a[100005],f[25005][405],tans,sum[25005][405],g[25005][405][2],dp[25005][405][2];
inline int addmod(int x)
{
	return x>=mod?x-mod:x;
}
inline int submod(int x)
{
	return x<0?x+mod:x;
}
int fpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=1ll*ans*x%mod;
		x=1ll*x*x%mod;
		y/=2;
	}
	return ans;
}
int getfr(int x)
{
	int ans=1;
	for(int i=1;i<=x;i++)
		ans=1ll*ans*i%mod;
	return ans;
}
int getans(int x,int y)
{
	return 1ll*getfr(x)*fpow(getfr(x-y),mod-2)%mod;
}
int main()
{
	scanf("%d%d%d",&n,&k,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	tans=1ll*(n-m+1)*fpow(k,n-m)%mod;
	for(int i=1;i<=m;i++)
		for(int j=1;j<=k;j++)
			if(a[i]==j) sum[i][j]=sum[i-1][j]+1;
			else sum[i][j]=sum[i-1][j];
	int tfl=0;
	for(int i=k;i<=m;i++)
	{
		int fl=1;
		for(int j=1;j<=k;j++)
			if(sum[i][j]-sum[i-k][j]!=1)
				fl=0;
		tfl|=fl;
	}
	if(tfl)
	{
		printf("%d",tans);
		return 0;
	}
	for(int i=1;i<=k;i++)
		if(sum[m][i]>1)
			tfl=1;
	if(!tfl)
	{
		//for(int i=0;i<=k;i++)
		//	g[0][i][0]=1;
		g[0][0][0]=1;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=k;j++)
			{
				if(j<k) 
				{
					g[i][j][0]=addmod(g[i-1][j][0]+1ll*(k-j+1)*submod(g[i-1][j-1][0]-g[i-1][j][0])%mod);
					dp[i][j][0]=addmod(dp[i-1][j][0]+1ll*(k-j+1)*submod(dp[i-1][j-1][0]-dp[i-1][j][0])%mod);
					dp[i][j][0]=addmod(dp[i][j][0]+(j>=m)*g[i][j][0]);
				}
				else
				{
					g[i][j][1]=addmod(g[i-1][j][0]+1ll*(k-j+1)*submod(g[i-1][j-1][0]-g[i-1][j][0])%mod);
					dp[i][j][1]=addmod(dp[i-1][j][0]+1ll*(k-j+1)*submod(dp[i-1][j-1][0]-dp[i-1][j][0])%mod);
				//	dp[i][j][1]=addmod(dp[i][j][1]+(j>=m)*g[i][j][1]);
				}
				g[i][j][1]=addmod(addmod(g[i][j][1]+g[i-1][j][1])+1ll*(k-j+1)*submod(g[i-1][j-1][1]-g[i-1][j][1])%mod);
				dp[i][j][1]=addmod(addmod(dp[i][j][1]+dp[i-1][j][1])+1ll*(k-j+1)*submod(dp[i-1][j-1][1]-dp[i-1][j][1])%mod);
				dp[i][j][1]=addmod(dp[i][j][1]+(j>=m)*g[i][j][1]);
				//printf("i=%d,j=%d,g=%d,%d,dp=%d,%d\n",i,j,g[i][j][0],g[i][j][1],dp[i][j][0],dp[i][j][1]);
			}
			for(int j=k-1;j>=0;j--)
			{
				g[i][j][0]=addmod(g[i][j][0]+g[i][j+1][0]);
				g[i][j][1]=addmod(g[i][j][1]+g[i][j+1][1]);
				dp[i][j][0]=addmod(dp[i][j][0]+dp[i][j+1][0]);
				dp[i][j][1]=addmod(dp[i][j][1]+dp[i][j+1][1]);
			}
		}
		int nans=dp[n][1][1];
		//for(int i=1;i<=k;i++)
		//	nans=addmod(nans+dp[m][i][1]);
		nans=1ll*nans*fpow(getans(k,m),mod-2)%mod;
		printf("%d\n",nans);
		return 0;
	}
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<k;j++)
		{
			f[i][j]=addmod(f[i-1][j]+1ll*(k-j+1)*submod(f[i-1][j-1]-f[i-1][j])%mod);
			//printf("i=%d,j=%d,f=%d\n",i,j,f[i][j]);
		}
		for(int j=k-2;j>=0;j--)
			f[i][j]=addmod(f[i][j]+f[i][j+1]);
	}
	int l,r;
	for(int i=1;i<=m;i++)
	{
		int fl=1;
		for(int j=1;j<=k;j++)
			if(sum[i][j]>1)
				fl=0;
		if(!fl)
		{
			l=i-1;
			break;
		}
	}
	for(int i=m;i>0;i--)
	{
		int fl=1;
		for(int j=1;j<=k;j++)
			if(sum[m][j]-sum[i-1][j]>1)
				fl=0;
		if(!fl)
		{
			r=m-i;
			break;
		}
	}
	//printf("l=%d,r=%d,tans=%d\n",l,r,tans);
	int nww=1ll*fpow(getans(k,l),mod-2)*fpow(getans(k,r),mod-2)%mod;
	for(int i=1;i+m-1<=n;i++)
	{
		int tl=i+l-1,tr=n-(i+m-1)+r,nw=1ll*f[tl][l]*f[tr][r]%mod;
		//printf("tl=%d,tr=%d\n",tl,tr);
		nw=1ll*nw*nww%mod;
		tans=submod(tans-nw);
	}
	printf("%d",tans);
	return 0;
}