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<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const long long mod=1e9+7;
long long n,m,k,a[33333],cnt,fl,jc[33333],pdp[33333][555],ndp[33333][555],injc[33333],dp[33333][555],sum[33333][555],s[33333],ans[33333],ress,anss;
bool f[555];
long long sum0[33333][555],sum1[33333][555],fp[33333][555][2],res[33333][555][2],ad[333];
long long binpow(long long a,long long t)
{
	long long res=1ll,p=a;
	for (long long i=t;i;i>>=1)
	{
		if (i&1) res=res*p%mod;
		p=p*p%mod;
	}
	return res;
}
void Init()
{
	jc[0]=injc[0]=1;
	for (long long i=1;i<=n;i++)
	{
		jc[i]=jc[i-1]*i%mod;
		injc[i]=injc[i-1]*binpow(i,mod-2)%mod;
	}
}
long long C(long long n,long long k)
{
	return (jc[n]*injc[k]%mod)*injc[n-k]%mod;
}
int main()
{
	scanf("%lld%lld%lld",&n,&k,&m);
	Init();
	for (long long i=1;i<=m;i++) scanf("%lld",&a[i]);
	for (long long i=1;i<=m-k+1;i++)
	{
		memset(f,0,sizeof(f));
		cnt=0;
		for (long long j=i;j<i+k;j++)
		{
			if (!f[a[j]])
			{
				f[a[j]]=1;
				cnt++;
			}
		}
		if (cnt==k)
		{
			fl=1;
			break;
		}
	}
	if (fl)
	{
		printf("%lld\n",(n-m+1)*binpow(k,n-m)%mod);
		return 0;
	}
	memset(f,0ll,sizeof(f));
	cnt=0ll;
	for (long long i=m;i>=1;i--)
	{
		if (!f[a[i]])
		{
			f[a[i]]=1;
			cnt++;
		}
		else break;
	}
	if (cnt==m)
	{
		fp[0][0][0]=1;
		sum0[0][0]=1;
		for (int i=1;i<=n;i++)
		{
			for (int j=1;j<=k;j++)
			{
				if (j!=k) fp[i][j][0]=(sum0[i-1][j-1]+fp[i-1][j-1][0]*(k-j))%mod;
				fp[i][j][1]=(sum1[i-1][j-1]+fp[i-1][j-1][1]*(k-j))%mod;
			}
			fp[i][k][1]=(fp[i][k][1]+sum0[i-1][k-1])%mod;
			for (int j=k-1;j>=0;j--)
			{
				sum0[i][j]=(sum0[i][j+1]+fp[i][j][0])%mod;
			}
			for (int j=k;j>=0;j--)
			{
				sum1[i][j]=(sum1[i][j+1]+fp[i][j][1])%mod;
			}
		}
		memset(sum0,0,sizeof(sum0));
		memset(sum1,0,sizeof(sum1));
		for (int i=1;i<=n;i++)
		{
			for (int j=1;j<=k;j++)
			{
				if (j!=k)
				{
					res[i][j][0]=(sum0[i-1][j-1]+res[i-1][j-1][0]*(k-j))%mod;
					if (j>=m) res[i][j][0]=(res[i][j][0]+fp[i][j][0])%mod;
				}
				res[i][j][1]=(sum1[i-1][j-1]+res[i-1][j-1][1]*(k-j))%mod;
				if (j>=m) res[i][j][1]=(res[i][j][1]+fp[i][j][1])%mod;
			}
			res[i][k][1]=(res[i][k][1]+sum0[i-1][k-1])%mod;
			for (int j=k-1;j>=0;j--)
			{
				sum0[i][j]=(sum0[i][j+1]+res[i][j][0])%mod;
			}
			for (int j=k;j>=0;j--)
			{
				sum1[i][j]=(sum1[i][j+1]+res[i][j][1])%mod;
			}
		}
		/*for (int i=1;i<=n;i++)
		{
			for (int j=1;j<=k;j++)
			{
				cout<<res[i][j][0]<<" "<<res[i][j][1]<<endl;
			}
			cout<<endl;
		}*/
		for (int i=1;i<=k;i++)
		{
			anss=(anss+res[n][i][1])%mod;
		}
		anss=anss*binpow(jc[m],mod-2)%mod;
		anss=anss*binpow(C(k,m),mod-2)%mod;
		printf("%lld\n",anss);
		return 0;
	}
	dp[0][cnt]=1ll;
	for (long long i=0;i<=cnt;i++) sum[0][i]=1ll;
	for (long long i=1;i<=n;i++)
	{
		for (long long j=1;j<=k;j++)
		{
			dp[i][j]=(sum[i-1][j-1]+dp[i-1][j-1]*(k-j))%mod;
		}
		for (long long j=k-1;j>=0;j--)
		{
			sum[i][j]=(sum[i][j+1]+dp[i][j])%mod;
		}
	}
	for (long long i=1;i<=n;i++)
	{
		dp[i][k]=dp[i][k]*binpow(binpow(k,i),mod-2ll)%mod;
	}
	for (long long i=1;i<=n;i++)
	{
		s[i]=(s[i-1]+dp[i][k])%mod;
		ans[i]=s[i]*binpow(k,i)%mod;
		if (n-m-i>=0) ress=(ress+ans[i]*binpow(k,n-m-i))%mod;
	}
	memset(dp,0ll,sizeof(dp));
	memset(sum,0ll,sizeof(sum));
	memset(f,0ll,sizeof(f));
	memset(s,0ll,sizeof(s));
	cnt=0ll;
	for (long long i=1;i<=m;i++)
	{
		if (!f[a[i]])
		{
			f[a[i]]=1;
			cnt++;
		}
		else break;
	}
	dp[0][cnt]=1ll;
	for (long long i=0;i<=cnt;i++) sum[0][i]=1ll;
	for (long long i=1;i<=n;i++)
	{
		for (long long j=1;j<=k;j++)
		{
			dp[i][j]=(sum[i-1][j-1]+dp[i-1][j-1]*(k-j))%mod;
		}
		for (long long j=k-1;j>=0;j--)
		{
			sum[i][j]=(sum[i][j+1]+dp[i][j])%mod;
		}
	}
	for (long long i=1;i<=n;i++)
	{
		dp[i][k]=dp[i][k]*binpow(binpow(k,i),mod-2ll)%mod;
	}
	for (long long i=1;i<=n;i++)
	{
		s[i]=(s[i-1]+dp[i][k])%mod;
		anss=s[i]*binpow(k,i)%mod;
		if (n-m-i>=0) ress=(ress+anss*(binpow(k,n-m-i)-ans[n-m-i]))%mod;
	}
	if (ress<0ll) ress+=mod;
	printf("%lld\n",ress);
	return 0;
}