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 <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#define MAXN 50010
#define MAXK 410
#define MOD 1000000007
#define int long long
inline int fuck(int x, int p) {
	int y = 1;
	for (; p; p >>= 1) {
		if (p & 1) y = 1LL * y * x % MOD;
		x = 1LL * x * x % MOD;
	}
	return y;
}
inline void up(int &x, int y) {
	(x += y) %= MOD;
}
inline void down(int &x, int y) {
	(x -= y) %= MOD;
	up(x, MOD);
}
int n, k, m, a[MAXN], f[MAXN][MAXK], g[MAXN][MAXK], frc[MAXN], inv[MAXN], count = 0;
std::map<int, int> M;

signed main() {
	scanf("%lld%lld%lld", &n, &k, &m);
	int all = 1LL * (n - m + 1) * fuck(k, n - m) % MOD;
	frc[0] = 1;
	for (int i = 1; i < MAXN; i++) frc[i] = 1LL * frc[i - 1] * i % MOD;
	inv[MAXN - 1] = fuck(frc[MAXN - 1], MOD - 2);
	for (int i = MAXN - 1; i; i--) inv[i - 1] = 1LL * inv[i] * i % MOD;
	for (int i = 1; i <= m; i++) scanf("%lld", &a[i]);
	for (int i = 1; i <= k && i <= m; i++)
		if (!M[a[i]]++) count++;
	for (int i = k + 1; i <= m; i++) {
		if (count == k) return printf("%lld\n", 1LL * (n - m + 1) * fuck(k, n - m) % MOD), 0;
		if (!--M[a[i - k]]) count--;
		if (!M[a[i]]++) count++;
	}
	if (count == k) return printf("%lld\n", all), 0;
	if (count == m) {
		f[1][1] = k;
		g[1][1] = k * (m == 1);
		for (int i = 1; i < n; i++) {
			for (int j = 1; j < k; j++) {
				up(f[i + 1][1], f[i][j]);
				down(f[i + 1][j + 1], f[i][j]);
				// printf("UP %lld => [%lld-%lld]\n", f[i][j], 1, j);
				up(f[i + 1][j + 1], 1LL * f[i][j] * (k - j) % MOD);
				down(f[i + 1][j + 2], 1LL * f[i][j] * (k - j) % MOD);
				// printf("UP %lld => %lld\n", f[i][j] * (k - j), j + 1);
				up(g[i + 1][1], g[i][j]);
				down(g[i + 1][j + 1], g[i][j]);
				// printg("UP %lld => [%lld-%lld]\n", g[i][j], 1, j);
				up(g[i + 1][j + 1], 1LL * g[i][j] * (k - j) % MOD);
				down(g[i + 1][j + 2], 1LL * g[i][j] * (k - j) % MOD);
				// printg("UP %lld => %lld\n", g[i][j] * (k - j), j + 1);
			}
			for (int j = 1; j <= k; j++) {
				up(f[i + 1][j], f[i + 1][j - 1]);
				up(g[i + 1][j], g[i + 1][j - 1]);
			}
			for (int j = m; j <= k; j++) up(g[i + 1][j], f[i + 1][j]);
		}
		int tmp = 0;
		for (int i = 1; i < k; i++)
			up(tmp, g[n][i]);
		tmp = tmp * frc[k - m] % MOD * inv[k] % MOD;
		return printf("%lld\n", (MOD + all - tmp) % MOD), 0;
	}
	M.clear();
	count = 0;
	int l = 1, r = m;
	for (int i = 1; i <= m; i++) {
		if (!M[a[i]]++) count++;
		if (count == i)
			l = i;
		else
			break;
	}
	M.clear();
	count = 0;
	for (int i = m; i >= 1; i--) {
		if (!M[a[i]]++) count++;
		if (count == (m - i + 1))
			r = i;
		else
			break;
	}
	f[0][l] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 1; j < k; j++) {
			up(f[i + 1][1], f[i][j]);
			down(f[i + 1][j + 1], f[i][j]);
			// printf("UP %lld => [%lld-%lld]\n", f[i][j], 1, j);
			up(f[i + 1][j + 1], 1LL * f[i][j] * (k - j) % MOD);
			down(f[i + 1][j + 2], 1LL * f[i][j] * (k - j) % MOD);
			// printf("UP %lld => %lld\n", f[i][j] * (k - j), j + 1);
		}
		for (int j = 1; j <= k; j++) up(f[i][j], f[i][j - 1]);
		for (int j = 1; j <= k; j++) up(f[i + 1][j], f[i + 1][j - 1]);
	}
	g[0][m - r + 1] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 1; j < k; j++) {
			up(g[i + 1][1], g[i][j]);
			down(g[i + 1][j + 1], g[i][j]);
			// printf("UP %lld => [%lld-%lld]\n", g[i][j], 1, j);
			up(g[i + 1][j + 1], 1LL * g[i][j] * (k - j) % MOD);
			down(g[i + 1][j + 2], 1LL * g[i][j] * (k - j) % MOD);
			// printf("UP %lld => %lld\n", g[i][j] * (k - j), j + 1);
		}
		for (int j = 1; j <= k; j++) up(g[i][j], g[i][j - 1]);
		for (int j = 1; j <= k; j++) up(g[i + 1][j], g[i + 1][j - 1]);
	}
	int ans = 0;
	for (int i = 0; i <= (n - m); i++) {
		int left = i;
		int right = (n - m - i);
		up(ans, 1LL * f[left][k - 1] * g[right][k - 1] % MOD);
	}
	printf("%lld\n", (MOD + all - ans) % MOD);
	return 0;
}