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:
// Comment
// Hard. Think All - non colorful. 
// And also Dp[i][j] = 
// 		In interval [1, i],
// 		last j are pairly diff, last j+1 are not

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MOD = 1e9 + 7;
const int MAX_N = 3e4 + 10;
const int MAX_K = 5e2 + 10;

int N, K, M;
int Nr[MAX_N];
ll Sum[MAX_N][MAX_K];
ll Dy[MAX_N][MAX_K];
ll SumG[MAX_N][MAX_K];
ll G[MAX_N][MAX_K];
ll Fac[MAX_N];

ll Base;
ll Pow(ll a, ll b) {
	ll p=a, r=1;
	while(b) {
		if(b%2) r*=p, r%=MOD;
		b/=2;
		p*=p; p%=MOD;
	}
	return r;
}
ll Inv(ll a) {
	return Pow(a, MOD-2);
}

int main() {
	cin >> N >> K >> M;
	for(int i=1; i<=M; i++) scanf("%d", &Nr[i]);
	Fac[0] = 1;
	for(int i=1; i<=max(N, K); i++) Fac[i] = Fac[i-1] * i % MOD;

	vector<int> cnt(K+1, 0);
	for(int i=1; i<K; i++) cnt[Nr[i]]++;
	bool isColorful = false;
	for(int i=K; i<=N; i++) {
		cnt[Nr[i]]++;
		bool isAll = true;
		for(int k=1; k<=K; k++) if(cnt[k] == 0) isAll = false;
		if(isAll) {
			isColorful = true;
			break;
		}
		cnt[Nr[i-(K-1)]]--;
	}

	cnt = vector<int>(K+1, 0);
	for(int i=1; i<=N; i++) cnt[Nr[i]]++;
	bool allDiff = true;
	for(int i=1; i<=K; i++) if(cnt[i] >= 2) allDiff = false;

	Base = N - M + 1;
	for(int i=0; i<N-M; i++) Base = Base * K % MOD;

	Dy[0][0] = 1;
	for(int i=1; i<=N; i++) {
		for(int j=1; j<K; j++) {
			Dy[i][j] += Dy[i-1][j-1] * (K - (j-1));
			Dy[i][j] += Sum[i-1][j];
			Dy[i][j] %= MOD;
		}
		for(int j=K; j>=1; j--) {
			Sum[i][j] = (Sum[i][j+1] + Dy[i][j]) % MOD;
		}
	}

	//for(int i=1; i<=N; i++, puts("")) for(int j=1; j<=K; j++) printf("%5lld ", Dy[i][j]); puts("");

	if (isColorful) {
		printf("%lld\n", Base);
	} else if (allDiff) {
		for(int i=1; i<=N; i++) {
			for(int j=1; j<K; j++) {
				G[i][j] += G[i-1][j-1] * (K - (j-1));
				G[i][j] += SumG[i-1][j];
				G[i][j] %= MOD;
			}
			for(int j=M; j<K; j++) {
				G[i][j] += Dy[i][j];
				G[i][j] %= MOD;
			}
			for(int j=K; j>=1; j--) {
				SumG[i][j] = (SumG[i][j+1] + G[i][j]) % MOD;
			}
		}

		ll mul = Fac[K-M] * Inv(Fac[K]) % MOD;
		ll ans = SumG[N][1] * mul % MOD;
		printf("%lld\n", ((Base - ans) % MOD + MOD) % MOD);
	} else {
		vector<int> cnt;
		cnt = vector<int>(K+1, 0);
		int lix = -1, rix = -1;
		for(int i=1; i<=M; i++) {
			cnt[Nr[i]]++;
			if(cnt[Nr[i]] == 2) {
				lix = i;
				break;
			}
		}
		cnt = vector<int>(K+1, 0);
		for(int i=M; i>=1; i--) {
			cnt[Nr[i]]++;
			if(cnt[Nr[i]] == 2) {
				rix = i;
				break;
			}
		}

		int lv = lix-1;
		int rv = M-rix;
		ll mul = Fac[K-lv] * Fac[K-rv] % MOD;
		mul *= Inv(Fac[K]);
		mul %= MOD;
		mul *= Inv(Fac[K]);
		mul %= MOD;

		ll ans = 0;
		for(int i=1; i<=N-M+1; i++) {
			int l=i, r=i+M-1;

			vector<pi> list;
			list.emplace_back(l, lix);
			list.emplace_back(N+1-r, N+1-rix);
			vector<ll> res;

			for(pi pp: list) {
				int start, end; tie(start, end) = pp;
				end--;
				int fix = end - start + 1;

				ll now = 0;
				for(int j=start; j>=1; j--) {
					int k = end-j+1;
					if(k >= K) break;
					now += Dy[end][k];
					now %= MOD;
				}

				res.push_back(now);
			}
			ans += res[0] * res[1] % MOD;
			ans %= MOD;

			lix++; rix++;
		}

		ans *= mul;
		ans %= MOD;
		printf("%lld\n", ((Base - ans) % MOD + MOD) % MOD);
	}
	return 0;
}