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<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
const int MN=25005,MK=405,P=1e9+7;
int Mul(int x,int y){return 1ll*x*y%P;}
int Add(int x,int y){return (x+y)%P;}
int fp(int x,int y){int r=1;for(;y;y>>=1,x=Mul(x,x))if(y&1)r=Mul(r,x);return r;}
int N,K,M,ans,a[MN],fac[MN],inv[MN],fi[MN];
int sf[MN][MK],f[MN][MK],sg[MN][MK],g[MN][MK];
bool chk1()
{
	static int ton[MK],num;
	reg int i;
	if(M<=K)return false;
	num=0;
	for(i=1;i<=K;++i)num+=!ton[a[i]]++;
	if(num==K) return true;
	for(i=K+1;i<=M;++i)
	{
		num-=!--ton[a[i-K]];
		num+=!ton[a[i]]++;
		if(num==K) return true;
	}
	return false;
}
int chk2()
{
	static int ton[MK],num;
	memset(ton,0,sizeof ton);
	reg int i;num=0;
	for(i=1;!ton[a[i]]&&i<=M;++i)num+=!ton[a[i]]++;
	return num;
}

int main()
{
	N=read(),K=read(),M=read();
	reg int i,j,Z=max(N,K);
	for(fac[0]=i=1;i<=Z;++i)fac[i]=Mul(fac[i-1],i);
	for(inv[0]=inv[1]=1,i=2;i<=Z;++i)inv[i]=Mul(inv[P%i],(P-P/i));
	for(fi[0]=i=1;i<=Z;++i)fi[i]=Mul(fi[i-1],inv[i]);
	for(i=1;i<=M;++i) a[i]=read();
	ans=Mul(N-M+1,fp(K,N-M));
	if(chk1()){return 0*printf("%d\n",ans);}
	f[0][0]=1;
	for(i=1;i<=N;++i)for(j=1;j<K;++j)
	{
		f[i][j]=Add(Mul(f[i-1][j-1],K-j+1),Add(sf[i-1][K-1],P-sf[i-1][j-1]));
		g[i][j]=Add(Mul(g[i-1][j-1],K-j+1),Add(sg[i-1][K-1],P-sg[i-1][j-1]));
		if(j>=M)g[i][j]=Add(g[i][j],f[i][j]);
		sf[i][j]=Add(sf[i][j-1],f[i][j]);
		sg[i][j]=Add(sg[i][j-1],g[i][j]);
	}
	if(chk2()==M)
	{
		int tmp=Mul(sg[N][K-1],Mul(fac[K-M],fi[K]));
		ans=Add(ans,P-tmp);
		printf("%d\n",ans);
		return 0;
	}
	else
	{
		int tmp=0,Mi,Ma,lm=chk2(),rm;
		reverse(a+1,a+M+1);rm=chk2();
		for(i=1;i<=N-M+1;++i)
		{
			int ii=i+lm-1,jj=N-i-M+1+rm,_1=0,_2=0;bool fl=ii==lm;
			for(j=lm;j<K;++j) _1=Add(_1,Mul(Mul(f[ii][j],Mul(fac[K-j],fi[K])),Mul(fac[K-lm],fi[K-j])));
			for(j=rm;j<K;++j) _2=Add(_2,Mul(Mul(f[jj][j],Mul(fac[K-j],fi[K])),Mul(fac[K-rm],fi[K-j])));
			tmp=Add(tmp,Mul(_1,_2));
		}
		ans=Add(ans,P-tmp);
		printf("%d\n",ans);
		return 0;
	}
}