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<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=25000+100;
const int maxk=500+10;
const int K=500;
const int modd=1e9+7;
int n,m,k;
int Ans;
int a[maxn],dp1[maxn][maxk],dp2[maxn][maxk];
int fac[maxk],inv[maxk],lst[maxk];

inline void file() {
	freopen("ARC100F.in","r",stdin);
	freopen("ARC100F.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

inline int quick(int a,int b) {
	int s=1;
	while (b) {
		if (b%2==1) s=1ll*s*a%modd;
		a=1ll*a*a%modd; b/=2;
	}
	return s;
}

inline void Add(int &a,int b) {
	a+=b; a=(a>=modd?a-modd:a); a=(a<0?a+modd:a);
}

inline void init() {
	fac[0]=inv[0]=1;
	For (i,1,K) fac[i]=1ll*fac[i-1]*i%modd;
	inv[K]=quick(fac[K],modd-2);
	Forr (i,K-1,1) inv[i]=1ll*inv[i+1]*(i+1)%modd;
}

inline void solve1() {
	dp1[0][0]=1;
	For (i,0,n-1) {
		int sum1=0,sum2=0;
		Forr (j,k-1,0) {
			Add(sum1,dp1[i][j]);
			if (j) Add(dp1[i+1][j],sum1);
			if (j<k-1) Add(dp1[i+1][j+1],1ll*(k-j)*dp1[i][j]%modd);
		}
		Forr (j,k-1,0) {
			if (j>=m) Add(dp2[i][j],dp1[i][j]);
			Add(sum2,dp2[i][j]);
			if (j) Add(dp2[i+1][j],sum2);
			if (j<k-1) Add(dp2[i+1][j+1],1ll*(k-j)*dp2[i][j]%modd);
		}
	}
	For (j,m,k-1) Add(dp2[n][j],dp1[n][j]);
	int ans=0;
	For (i,1,k-1) Add(ans,dp2[n][i]);
	Add(Ans,-1ll*ans*quick(1ll*fac[k]*inv[k-m]%modd,modd-2)%modd);
	printf("%d",Ans);
}

inline void solve2() {
	int p=0,q=0;
	Set(lst,0);
	For (i,1,m)
		if (!lst[a[i]]) lst[a[i]]=i;
		else { p=i-1; break; }
	Set(lst,0);
	Forr (i,m,1) {
		if (!lst[a[i]]) lst[a[i]]=i;
		else { q=m-i; break; }
	}
	dp1[0][p]=1; dp2[0][q]=1;
	For (i,0,n-1) {
		int sum1=0,sum2=0;
		Forr (j,k-1,0) {
			Add(sum1,dp1[i][j]); Add(sum2,dp2[i][j]);
			if (j) Add(dp1[i+1][j],sum1),Add(dp2[i+1][j],sum2);
			if (j<k-1) Add(dp1[i+1][j+1],1ll*(k-j)*dp1[i][j]%modd);
			if (j<k-1) Add(dp2[i+1][j+1],1ll*(k-j)*dp2[i][j]%modd);
		}
	}
	For (i,0,n-m) {
		int sum1=0,sum2=0;
		For (j,1,k-1)
			Add(sum1,dp1[i][j]),Add(sum2,dp2[n-m-i][j]);
		Add(Ans,-1ll*sum1*sum2%modd);
	}
	printf("%d",Ans);
}

int main() {
//	file();
	init();
	n=read(); k=read(); m=read();
	For (i,1,m) a[i]=read();
	Ans=1ll*(n-m+1)*quick(k,n-m)%modd;
//	cout << Ans << endl;
	int len=0,Max=0;
	For (i,1,m)
		len=min(len+1,i-lst[a[i]]),lst[a[i]]=i,chkmax(Max,len);
	if (Max==k) {
		printf("%d",Ans); return 0;
	}
	if (Max==m) {
		solve1(); return 0;
	}
	solve2();
	return 0;
}