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<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXN=25005;
const int MAXM=405;
const int mod=1e9+7;
int pow_mod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)ret=1LL*ret*a%mod;
		a=1LL*a*a%mod;b>>=1;
	}
	return ret;
}
int f[MAXN][MAXM],s[MAXM],s1[MAXM],g[MAXN][MAXM];
int n,K,m,a[MAXN];
int pre[MAXN],inv[MAXN];
LL ans;
bool check1()
{
	int cnt=0;
	if(m<K)return false;
	for(int i=1;i<K;i++)
	{
		s[a[i]]++;
		if(s[a[i]]==1)cnt++;
	}
	for(int i=1;i<=m-K+1;i++)
	{
		s[a[i+K-1]]++;
		if(s[a[i+K-1]]==1)cnt++;
		if(cnt==K)return true;
		s[a[i]]--;
		if(s[a[i]]==0)cnt--;
	}
	return false;
}
bool check2()
{
	if(m>K)return false;
	memset(s,0,sizeof(s));
	for(int i=1;i<=m;i++)
	{
		s[a[i]]++;
		if(s[a[i]]>1)return false;
	}
	return true;
}
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int C(int n,int m){return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;}
void solve2()
{
	memset(s,0,sizeof(s));
	s[0]=s1[0]=f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=min(i,K);j++)
		{
			ad(f[i][j],s[j]);ad(f[i][j],1LL*f[i-1][j-1]*(K-j+1)%mod);
			ad(g[i][j],s1[j]);
			ad(g[i][j],1LL*g[i-1][j-1]*(K-j+1)%mod);
			if(j>=m)ad(g[i][j],f[i][j]);
		}
		for(int j=K-1;j>=0;j--)s[j]=(s[j+1]+f[i][j])%mod,s1[j]=(s1[j+1]+g[i][j])%mod;
	}
	int sum=0;
	for(int i=1;i<K;i++)ad(sum,g[n][i]);
	sum=1LL*sum*pre[K-m]%mod*inv[K]%mod;
	pr2((ans-sum+mod)%mod);	
}
void solve3()
{
	memset(s,0,sizeof(s));
	int ln1,ln2;
	for(int i=1;i<=m;i++)
	{
		s[a[i]]++;
		if(s[a[i]]>1){ln1=i-1;break;}
	}
	memset(s,0,sizeof(s));
	for(int i=m;i>=1;i--)
	{
		s[a[i]]++;
		if(s[a[i]]>1){ln2=m-i;break;}
	}
	int sum=0;
	for(int i=ln1;i-ln1+1+m-1<=n;i++)
	{
		int s1=0,s2=0;
		for(int j=ln1;j<K;j++)ad(s1,1LL*f[i][j]*pre[K-j]%mod*inv[K]%mod*C(K-ln1,j-ln1)%mod*pre[j-ln1]%mod);
		for(int j=ln2;j<K;j++)ad(s2,1LL*f[n-(i-ln1+1+m-1)+ln2][j]*pre[K-j]%mod*inv[K]%mod*C(K-ln2,j-ln2)%mod*pre[j-ln2]%mod);
		ad(sum,1LL*s1*s2%mod);
	}
	pr2((ans-sum+mod)%mod);
}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	n=read();K=read();m=read();
	for(int i=1;i<=m;i++)a[i]=read();
	ans=1LL*pow_mod(K,n-m)*(n-m+1)%mod;
	if(check1())return pr2(ans),0;//colorful
	
	if(check2())solve2();
	else 
	{
		memset(s,0,sizeof(s));
		s[0]=f[0][0]=1;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=min(i,K);j++)
			{
				ad(f[i][j],s[j]);
				ad(f[i][j],1LL*f[i-1][j-1]*(K-j+1)%mod);
			}
			s[K]=0;
			for(int j=K-1;j>=0;j--)s[j]=(s[j+1]+f[i][j])%mod;
		}
		solve3();
	}
	return 0;
}