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<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define Mod1(x) ((x)>=mod?(x)-mod:x)
#define Mod2(x) ((x)<0?(x)+mod:x)
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
ll f[25010][410],sumf[25010][410],g[25010][410],sumg[25010][410];
int a[25010],pre[25010],nxt[25010];
int pos[410];
int n,k,m;
ll power(ll a,ll b)
{
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ans=ans*a%mod;
	return ans;
}
int main()
{
	n=read(); k=read(); m=read();
	for(int i=1;i<=m;i++)
		a[i]=read();
	for(int i=1;i<=m;i++){
		pre[i]=pos[a[i]]; nxt[pos[a[i]]]=i;
		pos[a[i]]=i;
	}
	for(int i=1;i<=k;i++)
		if(pos[i])nxt[pos[i]]=n+1;
	int flag=0;
	for(int i=k;i<=m;i++){
		int cur=0;
		for(int j=i;j>i-k;j--)
			if(pre[j]>i-k){
				cur=1; break;
			}
		if(!cur){
			flag=1; break;
		}
	}
	// writeln((n-m+1)*power(k,n-m)%mod);
	if(flag){
		writeln((n-m+1)*power(k,n-m)%mod);
		return 0;
	}
	flag=0;
	for(int i=1;i<=m;i++)
		if(pre[i]){
			flag=1; break;
		}
	if(!flag){
		for(int i=0;i<k;i++)
			f[0][i]=(!i),sumf[0][i]=1,g[0][i]=sumg[i][0]=0;
		for(int i=1;i<=n;i++){
			f[i][0]=sumf[i][0]=g[i][0]=sumg[i][0]=0;
			for(int j=1;j<k;j++){
				f[i][j]=((k-j+1)*f[i-1][j-1]+(sumf[i-1][k-1]-sumf[i-1][j-1]+mod))%mod;
				sumf[i][j]=(sumf[i][j-1]+f[i][j])%mod;
				g[i][j]=((k-j+1)*g[i-1][j-1]+(sumg[i-1][k-1]-sumg[i-1][j-1]+mod)+(j>=m)*f[i][j])%mod;
				sumg[i][j]=(sumg[i][j-1]+g[i][j])%mod;
			}
		}
		// for(int i=0;i<=n;i++){
		// 	for(int j=0;j<k;j++)
		// 		writesp(f[i][j]);
		// 	putchar('\n');
		// }
		ll t=sumg[n][k-1];
		for(int i=k-m+1;i<=k;i++)
			t=t*power(i,mod-2)%mod;
		ll tot=((n-m+1)*power(k,n-m)-t+mod)%mod;
		writeln(tot);
	}
	else{
		int first=1,last=1;
		while(!pre[first+1])++first;
		while(nxt[m-last]>n)++last;
		// printf("%d %d ***\n",first,last);
		for(int i=0;i<k;i++)
			f[0][i]=(i==first),sumf[0][i]=(i>=first),g[0][i]=(i==last),sumg[0][i]=(i>=last);
		for(int i=1;i<=n-m;i++){
			f[i][0]=sumf[i][0]=g[i][0]=sumg[i][0]=0;
			for(int j=1;j<k;j++){
				f[i][j]=((k-j+1)*f[i-1][j-1]+(sumf[i-1][k-1]-sumf[i-1][j-1]+mod))%mod;
				sumf[i][j]=(sumf[i][j-1]+f[i][j])%mod;
				g[i][j]=((k-j+1)*g[i-1][j-1]+(sumg[i-1][k-1]-sumg[i-1][j-1]+mod))%mod;
				sumg[i][j]=(sumg[i][j-1]+g[i][j])%mod;
			}
		}
		// for(int i=0;i<=n-m;i++){
		// 	for(int j=0;j<k;j++)
		// 		writesp(f[i][j]);
		// 	putchar('\n');
		// }
		// putchar('\n');
		// for(int i=0;i<=n-m;i++){
		// 	for(int j=0;j<k;j++)
		// 		writesp(g[i][j]);
		// 	putchar('\n');
		// }
		ll tot=(n-m+1)*power(k,n-m)%mod;
		for(int i=0;i<=n-m;i++)
			tot-=sumf[i][k-1]*sumg[n-m-i][k-1]%mod;
		tot=(tot%mod+mod)%mod;
		writeln(tot);
	}
	return 0;
}