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<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint dp[25010][420],d2[25010][420];
lint d3[25010][420][2];
int a[420];
lint zyo[25010],kai[420],ika[420];
lint mo=1000000007;
map<int,int> me;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
int cal(void)
{
	int n,K,m,x=0,y=0;lint out=0;
	cin>>n>>K>>m;
	zyo[0]=1;rep(i,n+10) zyo[i+1]=(zyo[i]*K)%mo;
	kai[0]=1;rep(i,410) kai[i+1]=(kai[i]*(i+1))%mo;
	rep(i,410) ika[i]=invMod(kai[i],mo);
	
	rep(i,m) cin>>a[i];
	rep(i,m-K+1){
		int f=0;me.clear();
		rep(j,K){
			if(me[a[i+j]]>0) f=1;me[a[i+j]]++;
		}
		if(f<1){
			return zyo[n-m]*(n-m+1)%mo;
		}
	}
	me.clear();
	while(x<m){
		if(me[a[x]]>0) break;
		me[a[x]]++;x++;
	}
	me.clear();
	while(y<m){
		if(me[a[m-1-y]]>0) break;
		me[a[m-1-y]]++;y++;
	}
	
	memset(dp,0,sizeof(dp));
	memset(d2,0,sizeof(d2));
	memset(d3,0,sizeof(d3));
	//逆からDP
	rep(i,n) REP(j,1,K){
		dp[i+1][j]+=dp[i+1][j-1];
		if(j==K-1) dp[i+1][j]+=zyo[i];
		else dp[i+1][j]+=(dp[i][j+1]-dp[i][j])*(K-j);
		dp[i+1][j]%=mo;
		dp[i+1][j]+=dp[i][j];
		dp[i+1][j]%=mo;
	}
	if(x>=m && y>=m){
		d3[0][0][0]=1;
		rep(i,n+1) rep(j,K+1) rep(l,2){
			if(j>0 && i>0){
				d3[i][j][l]+=d3[i][j-1][l];
			}
			d3[i][j][l]%=mo;d3[i][j][l]+=mo;d3[i][j][l]%=mo;
			//cout<<i<<' '<<j<<' '<<l<<' '<<d3[i][j][l]<<endl;
			d3[i+1][1][l]+=d3[i][j][l];
			d3[i+1][j+1][l]+=mo-d3[i][j][l];
			if(j<K-1){
				d3[i+1][j+1][l]+=d3[i][j][l]*(K-j);
				d3[i+1][j+2][l]-=d3[i][j][l]*(K-j);
			}
			else if(j==K-1){
				d3[i+1][j+1][1]+=d3[i][j][l];
				d3[i+1][j+2][1]-=d3[i][j][l];
			}
			/*else{
				d3[i+1][j][1]+=d3[i][j][l];
				d3[i+1][j+1][1]-=d3[i][j][l];
			}*/
		}
		rep(i,n){
			/*lint f=0;
			rep(j,K+1){
				f+=d3[n-i][j][1];
				if(j>=K-m){
					f+=(d3[n-i][j][0]*kai[K-m])%mo*kai[m]%mo*ika[K];
				}
				f%=mo;
			}
			cout<<i<<' '<<f<<endl;*/
			REP(j,m,K+1){
				//既にできてるやつ
				out+=d3[i][j][1]*zyo[n-i];
				out%=mo;
				//これから足すやつ。
				out+=d3[i][j][0]*(dp[n-i][j]-dp[n-i][j-1]);
				out%=mo;
			}
			//cout<<out<<endl;
		}
		REP(j,m,K+1){
			out+=d3[n][j][1];out%=mo;
		}
		out*=kai[K-m];out%=mo;out*=ika[K];out%=mo;out+=mo;out%=mo;
		return out;
	}
	out=zyo[n-m]*(n-m+1)%mo;
	rep(i,n-m+1){
		out-=(zyo[i]-dp[i][x]+dp[i][x-1])*(zyo[n-m-i]-dp[n-m-i][y]+dp[n-m-i][y-1]);
		out%=mo;
	}
	out+=mo;out%=mo;
	return out;
}
int main()
{
	cout<<cal()<<endl;
}