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 clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=25005,K=405,mod=1e9+7;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int n,k,m;
int a[N];
int dp[N][K],s[N][K];
int vis[K];
int Fac[N],Inv[N];
void prework(){
	int n=N-1;
	Fac[0]=1;
	For(i,1,n)
		Fac[i]=(LL)Fac[i-1]*i%mod;
	Inv[n]=Pow(Fac[n],mod-2);
	Fod(i,n,1)
		Inv[i-1]=(LL)Inv[i]*i%mod;
}
int C(int n,int m){
	if (m<0||m>n)
		return 0;
	return (LL)Fac[n]*Inv[m]%mod*Inv[n-m]%mod;
}
int check(){
	static int las[N];
	if (m<k)
		return 0;
	int s=0;
	For(i,1,m){
		s=max(s,las[a[i]]);
		las[a[i]]=i;
		if (i-s>=k)
			return 1;
	}
	return 0;
}
int main(){
	prework();
	n=read(),k=read(),m=read();
	For(i,1,m)
		a[i]=read();
	For(i,1,k-1)
		dp[0][i]=1,s[0][i]=i;
	For(i,1,n)
		For(j,1,k-1){
			dp[i][j]=((LL)dp[i-1][j+1]*(k-j)+s[i-1][j])%mod;
			s[i][j]=Add(s[i][j-1]+dp[i][j]);
		}
	if (check()){
		outtag(1);
		int ans=(LL)(n-m+1)*Pow(k,n-m)%mod;
		cout<<ans<<endl;
		return 0;
	}
	clr(vis);
	int pR=m;
	while (pR>0&&!vis[a[pR]])
		vis[a[pR--]]=1;
	clr(vis);
	int pL=1;
	while (pL<m+1&&!vis[a[pL]])
		vis[a[pL++]]=1;
	int ans=0;
	if (!pR){
		For(i,1,n-m+1){
			int now=Pow(k,n-m);
			if (i+m-1<k)
				Del(now,(LL)C(k-m,i-1)*Fac[i-1]%mod
					*dp[n-(i+m-1)][i+m-1]%mod);
			For(j,1,min(i-1,k-m)){
				int tmp=(LL)C(k-m,j-1)*Fac[j-1]%mod;
				tmp=(LL)tmp*dp[n-(i+m-1)][m+j-1]%mod;
				tmp=(LL)tmp*s[i-j-1][m+j-1]%mod;
				Del(now,tmp);
			}
			Add(ans,now);
		}
	}
	else {
		For(i,1,n-m+1){
			Add(ans,Pow(k,n-m));
			Del(ans,(LL)dp[i-1][pL-1]*dp[n-(i+m-1)][m-pR]%mod);
		}
	}
	cout<<ans<<endl;
	return 0;
}