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

const long long mod = 1000000007;
const int MAX_N = 250;
const int MAX_K = 50;

int N, K, M, A[1 << 18];
int cnt[1 << 18];
long long dp[25009][409], S[25009];
long long dp2[25009][409], S2[25009];
bool used[1 << 18];

bool check() {
	if (K > M) return false;

	int rem = 0;
	for (int i = 1; i <= K; i++) cnt[i] = 0;
	for (int i = 1; i <= K; i++) { cnt[A[i]]++; if (cnt[A[i]] == 2) rem++; }
	if (rem == 0) return true;

	for (int i = K + 1; i <= M; i++) {
		cnt[A[i - K]]--; if (cnt[A[i - K]] == 1) rem--;
		cnt[A[i]]++; if (cnt[A[i]] == 2) rem++;
		if (rem == 0) return true;
	}
	return false;
}

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 32; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a * modpow(b, m - 2, m)) % m;
}

long long solve1() {
	int cl = -1, cr = -1;
	for (int i = 1; i <= K; i++) used[i] = false;
	for (int i = 1; i <= M; i++) {
		if (used[A[i]] == true) { cl = i - 1; break; }
		used[A[i]] = true;
	}
	for (int i = 1; i <= K; i++) used[i] = false;
	for (int i = M; i >= 1; i--) {
		if (used[A[i]] == true) { cr = M - i; break; }
		used[A[i]] = true;
	}

	dp[0][cl] = 1;
	for (int i = 1; i <= N; i++) {
		long long r = 0;
		for (int j = K - 1; j >= 1; j--) {
			r += dp[i - 1][j]; r %= mod;
			dp[i][j] = r + dp[i - 1][j - 1] * (K - j + 1);
			dp[i][j] %= mod;
		}
	}

	dp2[0][cr] = 1;
	for (int i = 1; i <= N; i++) {
		long long r = 0;
		for (int j = K - 1; j >= 1; j--) {
			r += dp2[i - 1][j]; r %= mod;
			dp2[i][j] = r + dp2[i - 1][j - 1] * (K - j + 1);
			dp2[i][j] %= mod;
		}
	}

	for (int i = 0; i <= N; i++) {
		for (int j = 1; j <= K - 1; j++) {
			S[i] += dp[i][j]; S[i] %= mod;
			S2[i] += dp2[i][j]; S2[i] %= mod;
		}
	}

	long long sum = 0;
	for (int i = 1; i <= N - M + 1; i++) {
		long long f = S[i - 1] * S2[N - M - i + 1] % mod;
		long long g = modpow(K, N - M, mod);
		sum += (g - f + mod) % mod;
		sum %= mod;
	}
	return sum;
}

long long solve2() {
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		long long r = 0;
		for (int j = K - 1; j >= 1; j--) {
			r += dp[i - 1][j]; r %= mod;
			dp[i][j] = r + dp[i - 1][j - 1] * (K - j + 1);
			dp[i][j] %= mod;
		}
		long long r2 = 0;
		for (int j = K - 1; j >= 1; j--) {
			r2 += dp2[i - 1][j]; r2 %= mod;
			dp2[i][j] = r2 + dp2[i - 1][j - 1] * (K - j + 1);
			dp2[i][j] %= mod;
		}
		for (int j = M; j <= K - 1; j++) {
			dp2[i][j] += dp[i][j];
			dp2[i][j] %= mod;
		}
	}

	long long rem = 0;
	for (int i = 1; i <= K; i++) { rem += dp2[N][i]; rem %= mod; }

	long long fac = 1;
	for (int i = K; i >= K - M + 1; i--) { fac *= (1LL * i); fac %= mod; }
	fac = Div(1, fac, mod);

	long long val1 = rem * fac % mod;
	long long val2 = (N - M + 1);
	val2 *= modpow(K, N - M, mod);
	val2 %= mod;

	return (val2 - val1 + mod) % mod;
}

int main() {
	cin >> N >> K >> M;
	for (int i = 1; i <= M; i++) { cin >> A[i]; cnt[A[i]]++; }

	bool flag = false;
	for (int i = 1; i <= K; i++) { if (cnt[i] >= 2) flag = true; }

	int ans = -1;
	if (check() == true) {
		ans = 1LL * (N - M + 1) * modpow(K, N - M, mod) % mod;
	}
	else if (flag == true) {
		ans = solve1();
	}
	else if (flag == false) {
		ans = solve2();
	}

	cout << ans << endl;
	return 0;
}