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 ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=25005,M=405;
const int mo=1000000007;
int n,k,m,a[N];
int pr,su,vis[M];
int f[N][M],g[M];
bool check1(){
	For(i,1,m-k+1){
		memset(vis,0,sizeof(vis));
		bool ok=1;
		For(j,i,i+k-1)
			if (vis[a[j]]) ok=0;
			else vis[a[j]]=1;
		if (ok) return 1;
	}
	return 0;
}
bool check2(){
	memset(vis,0,sizeof(vis));
	For(i,1,m)
		if (!vis[a[i]])
			vis[a[i]]=1,++pr;
		else break;
	memset(vis,0,sizeof(vis));
	Rep(i,m,1)
		if (!vis[a[i]])
			vis[a[i]]=1,++su;
		else break;
	return pr==m;
}
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
namespace solver1{
	void solve(){
		int ans=1ll*(n-m+1)*power(k,n-m)%mo;
		printf("%d\n",ans);
		exit(0);
	}
}
void init(){
	f[1][1]=k;
	For(i,2,n){
		memset(g,0,sizeof(g));
		Rep(j,k-1,1) g[j]=(g[j+1]+f[i-1][j])%mo;
		For(j,1,k-1) f[i][j]=(g[j]+1ll*f[i-1][j-1]*(k-j+1))%mo;
	}
}
namespace solver2{
	int h[N][M];
	void solve(){
		int ans=1ll*(n-m+1)*power(k,n-m)%mo;
		int inv=1;
		For(i,1,m) inv=1ll*inv*(k-i+1)%mo;
		inv=power(inv,mo-2)%mo;
		h[1][1]=(m==1?1:0);
		For(i,2,n){
			memset(g,0,sizeof(g));
			Rep(j,k-1,1) g[j]=(g[j+1]+h[i-1][j])%mo;
			For(j,1,k-1) h[i][j]=(g[j]+1ll*h[i-1][j-1]*(k-j+1))%mo;
			For(j,m,k-1) h[i][j]=(h[i][j]+1ll*f[i][j]*inv)%mo;
		}
		For(j,1,k-1)
			ans=(ans+mo-h[n][j])%mo;
		printf("%d\n",ans);
		exit(0);
	}
}
namespace solver3{
	void solve(){
		int ans=1ll*(n-m+1)*power(k,n-m)%mo;
		int inv1=1,inv2=1;
		For(i,1,pr) inv1=1ll*inv1*(k+1-i)%mo;
		For(i,1,su) inv2=1ll*inv2*(k+1-i)%mo;
		inv1=power(inv1,mo-2);
		inv2=power(inv2,mo-2);
		//printf("%d %d\n",pr,su);
		//printf("%d\n",ans);
		For(i,0,n-m){
			int l1=i+pr,l2=n-i-m+su,s1=0,s2=0;
			For(j,pr,k-1) s1=(s1+f[l1][j])%mo;
			For(j,su,k-1) s2=(s2+f[l2][j])%mo;
			//printf("%d %d %d\n",i,s1,s2);
			s1=1ll*s1*inv1%mo;
			s2=1ll*s2*inv2%mo;
			//printf("%d %d %d\n",i,s1,s2);
			ans=(ans+mo-1ll*s1*s2%mo)%mo;
		}
		printf("%d\n",ans);
		exit(0);
	}
}
int main(){
	scanf("%d%d%d",&n,&k,&m);
	For(i,1,m) scanf("%d",&a[i]);
	if (check1()) solver1::solve();
	init();
	if (check2()) solver2::solve();
	solver3::solve();
}