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 <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int mod=1e9+7;
const int N=25010;
const int M=410;
inline void Add(int &x,int y) { x+=y; if(x>=mod) x-=mod; }
inline int Pow(int x,int y) { int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res; }
int n,m,k,a[N],tot;
int buc[M];
namespace task1 {
	void get_dp(int dp[]) {
		static int f[N][M];
		for(int i=1;i<=k;++i) buc[i]=0;
		int len=0;
		for(int i=m;i>=1;--i) {
			if(buc[a[i]]) { len=i; break; }
			buc[a[i]]++;
		}
		len=min(m-len,k);
		
		memset(f,0,sizeof(f));
		f[0][len]=1;
		for(int i=1;i<=n-m;++i) {
			int sum=0;
			for(int j=k-1;j>=1;--j) {
				if(j+1<k) Add(f[i][j+1],1ll*f[i-1][j]*(k-j)%mod);
				Add(sum,f[i-1][j]);
				Add(f[i][j],sum);
			}
//			for(int j=1;j<k;++j) if(f[i-1][j]) {
//				if(j+1<k) Add(f[i][j+1],1ll*f[i-1][j]*(k-j)%mod);
//				for(int t=1;t<=j;++t)
//					Add(f[i][t],f[i-1][j]);
//			}
		}
		for(int i=0;i<=n-m;++i)
			for(int j=1;j<k;++j)
				Add(dp[i],f[i][j]);
	}
	int f[N],g[N];
	void main() {
		get_dp(f);
		reverse(a+1,a+m+1);
		get_dp(g);
		int res=0;
		for(int i=0;i<=n-m;++i)
			res=(res+1ll*f[i]*g[n-m-i])%mod;
		printf("%d",(tot-res+mod)%mod);
	}
}
bool check_unique(int *a,int m) {
	for(int i=1;i<=k;++i) buc[i]=0;
	for(int i=1;i<=m;++i) {
		if(buc[a[i]]) return 0;
		buc[a[i]]++;
	}
	return 1;
}
int f[N][M][2];
int main() {
	rd(n),rd(k),rd(m);
	for(int i=1;i<=m;++i) rd(a[i]);
	tot=n-m+1; for(int i=m+1;i<=n;++i) tot=1ll*tot*k%mod;
	for(int i=1;i+k-1<=m;++i) if(check_unique(a+i-1,k)) {
		printf("%d",tot);
		return 0;
	}
	if(!check_unique(a,m)) task1::main();
	else {
		f[1][1][0]=k;
		f[1][1][1]=m==1 ? k : 0;
		for(int i=2;i<=n;++i) {
			for(int d=0;d<2;++d) {
				int sum=0;
				for(int j=k-1;j>=1;--j) {
					if(j+1<k) Add(f[i][j+1][d],1ll*f[i-1][j][d]*(k-j)%mod);
					Add(sum,f[i-1][j][d]);
					Add(f[i][j][d],sum);
				}
			}
//			for(int j=1;j<k;++j)
//				for(int d=0;d<2;++d) if(f[i-1][j][d]) {
//					if(j+1<k) Add(f[i][j+1][d],1ll*f[i-1][j][d]*(k-j)%mod);
//					for(int t=1;t<=j;++t)
//						Add(f[i][t][d],f[i-1][j][d]);
//				}
			for(int j=m;j<k;++j)
				Add(f[i][j][1],f[i][j][0]);
		}
		int res=0;
		for(int j=1;j<k;++j) Add(res,f[n][j][1]);
		int inv=1;
//		cerr<<tot<<' '<<res<<endl;
		for(int i=k;i>k-m;--i) inv=1ll*inv*i%mod;
		res=1ll*res*Pow(inv,mod-2)%mod;		
		printf("%d",(tot-res+mod)%mod);
	}
	return 0;
}