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>
using namespace std;

const int mod=1000000007;
int n,k,m,a[25010],f[25010][410],sum[25010][410],pl,pr,mi[25010],ans,invC[410],c[410][410],jc[410],g[25010][410],sg;
bool bo[410],Bo;

int quickmi(int a,int b)
{
	int t=1;
	for (; b; b>>=1,a=1ll*a*a%mod)
		if (b&1) t=1ll*t*a%mod;
	return t;
}

int add(int x,int y) {return (x+y>=mod?x+y-mod:x+y);}

int main()
{
	for (int i=0; i<=400; i++)
	{
		c[i][0]=1,jc[i]=(i==0?1:1ll*jc[i-1]*i%mod);
		for (int j=1; j<=i; j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	scanf("%d%d%d",&n,&k,&m),mi[0]=1,ans=0;
	for (int i=1; i<=25000; i++) mi[i]=1ll*k*mi[i-1]%mod;
	for (int i=1; i<=m; i++) scanf("%d",&a[i]);
	f[1][1]=sum[1][1]=k;
	for (int i=2; i<=n; i++)
	{
		for (int j=1; j<k; j++)
			f[i][j]=(1ll*(k-j+1)*f[i-1][j-1]+sum[i-1][j])%mod;
		sum[i][k]=0;
		for (int j=k-1; j; j--) sum[i][j]=add(sum[i][j+1],f[i][j]);
	}
	for (int i=1; i<=m-k+1; i++)
	{
		memset(bo,0,sizeof(bo)),Bo=1;
		for (int j=i; j<=i+k-1; j++) 
		{
			if (bo[a[j]]) {Bo=0; break;}
			bo[a[j]]=1;
		}
		if (Bo) return printf("%d\n",1ll*mi[n-m]*(n-m+1)%mod),0;
	}
	Bo=1,memset(bo,0,sizeof(bo));
	for (int i=1; i<=m; i++)
	{
		if (bo[a[i]]) {Bo=0; break;}
		bo[a[i]]=1;
	}
	for (int i=0; i<=k; i++) invC[i]=quickmi(1ll*c[k][i]*jc[i]%mod,mod-2);
	if (Bo)
	{
		g[1][1]=k,sg=(k==2?2:0);
		for (int i=2; i<=n; i++)
		{
			g[i][1]=(mi[i]<sg?mi[i]-sg+mod:mi[i]-sg);
			for (int j=2; j<k; j++)
				g[i][j]=(1ll*(k-j+1)*g[i-1][j-1]-g[i-1][k-1]+mod)%mod;
			sg=(1ll*k*sg+g[i][k-1])%mod;
		}
		for (int i=0; i<=n; i++)
		{
			sum[i][0]=0;
			for (int j=1; j<k&&i+j<=n; j++) sum[i][j]=(sum[i][j-1]+1ll*invC[j]*g[i+j][j])%mod;
		}
		for (int i=1; i<=n-m+1; i++)
		{
			int res=0;
			for (int j=i+m-1; j<=n&&j<i+k-1; j++)
			{
				int nw1=1ll*g[j][j-i+1]*invC[j-i+1]%mod;
				int nw2=(j==n?1:sum[n-j-1][j-i+1]);
				res=(res+1ll*nw1*nw2%mod*c[k-m][j-(i+m-1)]%mod*jc[j-(i+m-1)])%mod;
			}
			ans=(ans+1ll*mi[n-m]-res+mod)%mod;
		}
	} else
	{
		memset(bo,0,sizeof(bo));
		for (int i=1; i<=m; i++)
		{
			if (bo[a[i]]) {pl=i; break;}
			bo[a[i]]=1;
		}
		memset(bo,0,sizeof(bo));
		for (int i=m; i; i--)
		{
			if (bo[a[i]]) {pr=i; break;}
			bo[a[i]]=1;
		}
		for (int i=1; i<=n-m+1; i++)
		{
			int nw1=0,nw2=0;
			for (int j=pl-1; j<k; j++) nw1=(nw1+1ll*f[i+pl-2][j]*invC[j]%mod*c[k-pl+1][j-pl+1]%mod*jc[j-pl+1])%mod;
			for (int j=m-pr; j<k; j++) nw2=(nw2+1ll*f[n-(i+m-1)+m-pr][j]*invC[j]%mod*c[k-m+pr][j-m+pr]%mod*jc[j-m+pr])%mod;
			ans=(ans+mi[n-m]+1ll*(mod-nw1)*nw2)%mod;
		}
	}
	return printf("%d\n",ans),0;
}