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;

typedef long long ll;
typedef pair<ll,ll> P;

#define fr first
#define sc second

const ll MOD=1000000007;

ll modpow(ll x,ll k){
	if(k==0)return 1;
	ll ret=modpow(x,k/2);
	ret*=ret; ret%=MOD;
	if(k%2==1){
		ret*=x; ret%=MOD;
	}
	return ret;
}

int main(){
	static ll n,k,m;
	static ll a[25002];
	scanf("%lld%lld%lld",&n,&k,&m);
	for(int i=0;i<m;i++){
		scanf("%lld",&a[i]);
	}
	
	bool col=false;
	for(int i=0;i<m-k+1;i++){
		set<int> S;
		for(int j=0;j<k;j++){
			S.insert(a[i+j]);
		}
		col|=S.size()==k;
	}
	if(col){
		cout<<(n-m+1)*modpow(k,n-m)%MOD<<endl;
		return 0;
	}
	
	static ll dp[2][25010][402];
	static ll sc[2][25010][402];
	set<int> X;
	for(int i=0;i<m;i++){
		X.insert(a[i]);
	}
	if(X.size()==m){
		for(int t=0;t<2;t++){
			for(int i=0;i<25010;i++){
				for(int j=0;j<402;j++){
					dp[t][i][j]=sc[t][i][j]=0;
				}
			}
		}
		dp[0][1][1]=k;
		for(int i=1;i<=n;i++){
			for(int t=0;t<2;t++)for(int j=m;j<=k;j++){
				sc[t][i][j]+=dp[t][i][j];
				if(sc[t][i][j]>=MOD)sc[t][i][j]-=MOD;
			}
			/*cout<<"====="<<endl<<i<<endl;
			for(int t=0;t<2;t++){
				for(int j=1;j<=k;j++){
					cout<<dp[t][i][j]<<","<<sc[t][i][j]<<" ";
				}
				cout<<endl;
			}*/
			if(i==n)break;
			for(int t=0;t<2;t++)for(int j=1;j<k;j++){
				dp[t][i+1][1]+=dp[t][i][j];
				dp[t][i+1][j+1]+=MOD-dp[t][i][j];
				ll x=dp[t][i][j]*(k-j); x%=MOD;
				dp[t][i+1][j+1]+=x;
				dp[t][i+1][j+2]+=MOD-x;
			}
			for(int t=0;t<2;t++)for(int j=1;j<=k;j++){
				dp[t][i+1][j]+=dp[t][i+1][j-1];
				dp[t][i+1][j]%=MOD;
			}
			for(int t=0;t<2;t++){
				dp[t][i+1][k]+=dp[t][i][k]*k;
				dp[t][i+1][k]%=MOD;
			}
			dp[1][i+1][k-1]+=dp[1][i+1][k];
			dp[1][i+1][k-1]+=dp[0][i+1][k];
			dp[1][i+1][k-1]%=MOD;
			dp[0][i+1][k]=dp[1][i+1][k]=0;
			for(int t=0;t<2;t++)for(int j=1;j<k;j++){
				sc[t][i+1][1]+=sc[t][i][j];
				sc[t][i+1][j+1]+=MOD-sc[t][i][j];
				ll x=sc[t][i][j]*(k-j); x%=MOD;
				sc[t][i+1][j+1]+=x;
				sc[t][i+1][j+2]+=MOD-x;
			}
			for(int t=0;t<2;t++)for(int j=1;j<=k;j++){
				sc[t][i+1][j]+=sc[t][i+1][j-1];
				sc[t][i+1][j]%=MOD;
			}
			for(int t=0;t<2;t++){
				sc[t][i+1][k]+=sc[t][i][k]*k;
				sc[t][i+1][k]%=MOD;
			}
			sc[1][i+1][k-1]+=sc[1][i+1][k];
			sc[1][i+1][k-1]+=sc[0][i+1][k];
			sc[1][i+1][k-1]%=MOD;
			sc[0][i+1][k]=sc[1][i+1][k]=0;
		}
		ll ret=0;
		for(int j=1;j<=k;j++)ret+=sc[1][n][j];
		ret%=MOD;
		//cout<<ret<<endl;
		for(int i=k-m+1;i<=k;i++){
			ret*=modpow(i,MOD-2);
			ret%=MOD;
		}
		cout<<ret<<endl;
		return 0;
	}
	
	for(int t=0;t<2;t++){
		set<int> S;
		for(int i=m-1;i>=0;i--){
			if(S.find(a[i])!=S.end())break;
			S.insert(a[i]);
		}
		for(int i=0;i<25010;i++){
			for(int j=0;j<402;j++){
				dp[t][i][j]=0;
			}
		}
		dp[t][0][S.size()]=1;
		for(int i=0;i+1<25010;i++){
			for(int j=1;j<k;j++){
				dp[t][i+1][1]+=dp[t][i][j];
				dp[t][i+1][j+1]+=MOD-dp[t][i][j];
				ll x=dp[t][i][j]*(k-j); x%=MOD;
				dp[t][i+1][j+1]+=x;
				dp[t][i+1][j+2]+=MOD-x;
			}
			for(int j=1;j<=k;j++){
				dp[t][i+1][j]+=dp[t][i+1][j-1];
				dp[t][i+1][j]%=MOD;
			}
			dp[t][i+1][k]+=dp[t][i][k]*k;
			dp[t][i+1][k]%=MOD;
		}
		reverse(a,a+m);
	}
	
	ll ret=0;
	for(int i=0;i<=n-m;i++){
		int j=n-m-i;
		//cout<<dp[0][i][k]<<" "<<dp[1][j][k]<<endl;
		ret+=dp[0][i][k]*modpow(k,j);
		ret+=dp[1][j][k]*modpow(k,i);
		ret+=MOD-(dp[0][i][k]*dp[1][j][k]%MOD);
		ret%=MOD;
	}
		/*static ll DP[402];
		DP[0]=m;
		ll zan=k-m;
		for(int i=1;i<k-m;i++){
			DP[i]=zan*(m+i)%MOD;
			zan*=k-m-i; zan%=MOD;
		}
		for(int i=0;i<k-m;i++){
			zan=*/
	
	cout<<ret%MOD<<endl;
}