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>
using namespace std;
const long long md=1e9+7;
long long powd(long long x,long long y){
	long long res=1;
	while(y){
		if(y&1) res=res*x%md;
		x=x*x%md;
		y>>=1;
	}
	return res;
}
void Add(long long &x,long long y){
	x=(x+y)%md;
}
long long dp[25100][410];
long long dq[25100][410];
int a[25100];
bool vis[410];
int n,k,m;
long long fac[25100],inv[25100];
void solve1(int p1,int p2){
	cerr<<p1<<" "<<p2<<endl;
	long long ans=0,s1,s2,sum=0;
	for(int i=1;i<=n-m+1;i++){
		s1=0;
		for(int j=p1;j<=k;j++)
			Add(s1,dp[i-1+p1][j]*inv[k]%md*fac[k-p1]);
		s2=0;
		for(int j=p2;j<=k;j++)
			Add(s2,dp[n-(i+m-1)+p2][j]*inv[k]%md*fac[k-p2]);
		Add(ans,s1*s2);
	}
	sum=powd(k,n-m)*(n-m+1)%md;
	Add(sum,md-ans);
	printf("%lld\n",sum);
}
long long pf(long long x){
	x%=md;
	return x*x%md;
}
long long sss[25100][410];
void solve2(){
	for(int i=1;i<=n;i++)
		for(int j=1;j<=k;j++)
			sss[i][j]=(sss[i][j-1]+dp[i][j])%md;
	long long ans=0,sum;
	for(int i=m;i<=n;i++){
		for(int j=m;j<k&&j<=i;j++)
			Add(ans,dp[i][j]*(sss[n-(i-j)][k]-sss[n-(i-j)][j-1]+md)%md*fac[k-m]%md*inv[k]%md*fac[k-j]%md*inv[k]%md);
	}
	sum=powd(k,n-m)*(n-m+1)%md;
	Add(sum,md-ans);
	printf("%lld\n",sum);
}
void get_dp(){
	dp[0][0]=1;
	long long sum=0;
	for(int i=1;i<=n+1;i++){
		for(int j=1;j<k;j++)
			Add(dp[i][j],dp[i-1][j-1]*(k-(j-1))%md);
		sum=0;
		for(int j=k-1;j>=1;j--){
			Add(sum,dp[i-1][j]);
			Add(dp[i][j],sum);
			dq[i][j]=sum;
		}
	}
}
void get_fac(){
	fac[0]=1;
	for(int i=1;i<=25000;i++)
		fac[i]=fac[i-1]*i%md;
	inv[25000]=powd(fac[25000],md-2);
	for(int i=25000;i>=1;i--)
		inv[i-1]=inv[i]*i%md;
}
bool test(){
	for(int i=1;i<=m-k+1;i++){
		for(int j=1;j<=k;j++)
			vis[j]=0;
		for(int j=1;j<=k;j++)
			vis[a[i+j-1]]=1;
		bool bo=1;
		for(int j=1;j<=k;j++)
			if(!vis[j])
				bo=0;
		if(bo) return 1;
	}
	return 0;
}
int main(){
//	freopen("F.in","r",stdin);
	scanf("%d%d%d",&n,&k,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	int p1,p2;
	for(p1=1;p1<=m;p1++){
		if(vis[a[p1]]) break;
		vis[a[p1]]=1;
	}
	memset(vis,0,sizeof(vis));
	for(p2=m;p2>=1;p2--){
		if(vis[a[p2]]) break;
		vis[a[p2]]=1;
	}
	if(test()){
		printf("%lld\n",powd(k,n-m)*(n-m+1)%md);
		return 0;
	}
	get_dp();
	get_fac();
	if(p1!=m+1)
		solve1(p1-1,m-p2);
	else
		solve2();
	return 0;
}