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:
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
#define DEBUG

const int maxn=25005;
const int maxm=405;
const int mod=1e9+7;
inline int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline int sub(int a,int b){return a-b<0?a-b+mod:a-b;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
int N,M,K;
int a[maxn];
bool occ[maxm];
int dp[maxn][maxm][2][2],sum[maxn][maxm][2];
int f[maxn][maxm],g[maxn][maxm];
int C[maxm][maxm];

int quick_pow(int x,int pow){
	int res=1;
	for(;pow;pow>>=1){
		if(pow&1)res=mul(res,x);
		x=mul(x,x);
	}
	return res;
}

int main(){
#ifndef DEBUG
	freopen("my.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	scanf("%d%d%d",&N,&K,&M);
	rep(i,K+1)C[i][0]=1;
	REP(i,K)REP(j,K)C[i][j]=add(C[i-1][j-1],C[i-1][j]);
	REP(i,M)scanf("%d",&a[i]);
	REP(i,M-K+1){
		bool ok=true;
		REP(j,K)occ[j]=false;
		rep(j,K)occ[a[i+j]]=true;
		REP(j,K)if(!occ[j])ok=false;
		if(ok){
			printf("%d",mul(N-M+1,quick_pow(K,N-M)));
			return 0;
		}
	} 
	int x=M,y=M;
	memset(occ,false,sizeof(occ));
	REP(i,M){
		if(occ[a[i]]){x=i-1;break;}
		else occ[a[i]]=true;
	}
	memset(occ,false,sizeof(occ));
	for(int i=M;i>=1;i--){
		if(occ[a[i]]){y=M-i;break;}
		else occ[a[i]]=true;
	}
	if(x!=M){
		dp[0][x][0][0]=1;for(int i=x;i<=K;i++)sum[0][i][0]=1;
		REP(i,N)REP(j,K)rep(k,2){
			if(j==K&&!k)goto end;
			dp[i][j][k][0]=sub(sum[i-1][K][k],sum[i-1][j-1][k]);
			dp[i][j][k][0]=add(dp[i][j][k][0],mul(K-j+1,dp[i-1][j-1][k][0]));
			if(j==K){
				dp[i][j][k][0]=add(dp[i][j][k][0],sub(sum[i-1][K][0],sum[i-1][j-1][0]));
				dp[i][j][k][0]=add(dp[i][j][k][0],mul(K-j+1,dp[i-1][j-1][0][0]));
			}
			end:
			sum[i][j][k]=add(sum[i][j-1][k],dp[i][j][k][0]);
		}
		memset(sum,0,sizeof(sum));
		dp[0][y][0][1]=1;for(int i=y;i<=K;i++)sum[0][i][0]=1;
		REP(i,N)REP(j,K)rep(k,2){
			if(j==K&&!k)goto end2;
			dp[i][j][k][1]=sub(sum[i-1][K][k],sum[i-1][j-1][k]);
			dp[i][j][k][1]=add(dp[i][j][k][1],mul(K-j+1,dp[i-1][j-1][k][1]));
			if(j==K){
				dp[i][j][k][1]=add(dp[i][j][k][1],sub(sum[i-1][K][0],sum[i-1][j-1][0]));
				dp[i][j][k][1]=add(dp[i][j][k][1],mul(K-j+1,dp[i-1][j-1][0][1]));
			}
			end2:
			sum[i][j][k]=add(sum[i][j-1][k],dp[i][j][k][1]);
		}
		int ans=0;
		rep(i,N-M+1){
			int j=N-M-i;
			int L=0,R=0;
			REP(k,K){
				L=add(L,dp[i][k][1][0]);
				R=add(R,dp[j][k][1][1]);
			}
//			cout<<i<<" "<<L<<" "<<R<<endl;
			ans=add(ans,mul(L,quick_pow(K,j)));
			ans=add(ans,mul(R,quick_pow(K,i)));
			ans=sub(ans,mul(L,R));
		}
		printf("%d",ans);
	}
	else{
		f[0][0]=1;rep(i,K+1)sum[0][i][0]=1;
		REP(i,N)REP(j,K){
			f[i][j]=sub(sum[i-1][K][0],sum[i-1][j-1][0]);
			f[i][j]=add(f[i][j],mul(K-j+1,f[i-1][j-1]));
			g[i][j]=sub(sum[i-1][K][1],sum[i-1][j-1][1]);
			g[i][j]=add(g[i][j],mul(K-j+1,g[i-1][j-1]));
			if(j>=M)g[i][j]=add(g[i][j],f[i][j]);
			sum[i][j][0]=add(sum[i][j-1][0],f[i][j]);
			sum[i][j][1]=add(sum[i][j-1][1],g[i][j]);
//			cout<<i<<" "<<j<<" "<<f[i][j]<<" "<<g[i][j]<<endl;
		}
		int tmp=1;
		REP(i,M)tmp=mul(tmp,i);
		int ans=sum[N][K][1];
		memset(sum,0,sizeof(sum));
		memset(f,0,sizeof(f));
		memset(g,0,sizeof(g)); 
		f[0][0]=1;rep(i,K)sum[0][i][0]=1;
		REP(i,N)REP(j,K-1){
			f[i][j]=sub(sum[i-1][K-1][0],sum[i-1][j-1][0]);
			f[i][j]=add(f[i][j],mul(K-j+1,f[i-1][j-1]));
			g[i][j]=sub(sum[i-1][K-1][1],sum[i-1][j-1][1]);
			g[i][j]=add(g[i][j],mul(K-j+1,g[i-1][j-1]));
			if(j>=M)g[i][j]=add(g[i][j],f[i][j]);
			sum[i][j][0]=add(sum[i][j-1][0],f[i][j]);
			sum[i][j][1]=add(sum[i][j-1][1],g[i][j]);
//			cout<<i<<" "<<j<<" "<<f[i][j]<<" "<<g[i][j]<<endl;
		}
		ans=sub(ans,sum[N][K-1][1]);
		printf("%d",mul(ans,quick_pow(mul(C[K][M],tmp),mod-2)));
	}
	return 0;
}

/*
Input:
-----------------
Output:
*/