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;
const int maxn = 3e4, mod = 1e9 + 7, maxk = 400;
int n, k, m, ans;
int inv[maxn + 10], fac[maxn + 10], ifac[maxn + 10];
int a[maxn + 10], f[maxn + 10][maxk + 10];
int h[maxn + 10][maxk + 10];
int sf[maxk + 10], sh[maxk + 10];

inline int add(int x, int y) {
	x += y; return x < mod ? x : x - mod;
}
inline int dec(int x, int y) {
	x -= y; return x < 0 ? x + mod : x;
}
inline int mul(int x, int y) {
	return 1ll * x * y % mod;
}
inline int fpow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		y >>= 1; x = mul(x, x);
	}
	return ans;
}

void init() {
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= maxn; ++i) {
		fac[i] = mul(fac[i - 1], i);
		inv[i] = i == 1 ? 1 : dec(0, mul(mod / i, inv[mod % i]));
		ifac[i] = mul(ifac[i - 1], inv[i]);
	}
}

bool alldiff() {
	static bool vis[500];
	for (int i = 1; i <= m; ++i) {
		if (vis[a[i]]) return 0;
		vis[a[i]] = 1;
	}
	return 1;
}

void dpit() {
	f[1][1] = k; h[1][1] = m == 1 ? k : 0;
	for (int i = 2; i <= n; ++i) {
		for (int j = 1; j < k; ++j) {
			sf[j] = add(sf[j - 1], f[i - 1][j]);
			sh[j] = add(sh[j - 1], h[i - 1][j]);
		}
		for (int j = 1; j < k; ++j) {
			f[i][j] = mul(f[i - 1][j - 1], k - j + 1);
			h[i][j] = mul(h[i - 1][j - 1], k - j + 1);
			f[i][j] = add(f[i][j], dec(sf[k - 1], sf[j - 1]));
			h[i][j] = add(h[i][j], dec(sh[k - 1], sh[j - 1]));
			if (j >= m) h[i][j] = add(h[i][j], f[i][j]);
		}
	}
}

void solve1() {
	for (int i = 1; i < k; ++i)
		ans = add(ans, h[n][i]);
	ans = dec(mul(mul(fac[k], ifac[k - m]), mul(n - m + 1, fpow(k, n - m))), ans);
	ans = mul(ans, mul(fac[k - m], ifac[k]));
	printf("%d", ans);
}

bool colorful() {
	static bool vis[maxk + 10];
	for (int i = k; i <= m; ++i) {
		memset(vis, 0, sizeof vis);
		bool fd = 1;
		for (int j = i - k + 1; j <= i; ++j) {
			if (vis[a[j]]) {
				fd = 0; break;
			}
			vis[a[j]] = 1;
		}
		if (fd) return 1;
	}
	return 0;
}

int getit() {
	static bool vis[maxk + 10];
	memset(vis, 0, sizeof vis);
	for (int i = 1; i <= m; ++i) {
		if (vis[a[i]]) return i - 1;
		vis[a[i]] = 1;
	}
	assert(0);
}

int work(int x, int y) {
	int ans = 0;
	for (int i = y; i < k; ++i)
		ans = add(ans, f[x + y][i]);
	return mul(ans, mul(fac[k - y], ifac[k]));
}

void solve2() {
	int all = mul(n - m + 1, fpow(k, n - m));
	if (colorful()) {
		printf("%d", all); return;
	}
	int pre = getit();
	reverse(a + 1, a + m + 1);
	int suf = getit();
	for (int i = 1; i <= n - m + 1; ++i) {
		ans = add(ans, mul(work(i - 1, pre), work(n - m - i + 1, suf)));
	}
	printf("%d", dec(all, ans));
}

int main() {
	init();
	scanf("%d%d%d", &n, &k, &m);
	for (int i = 1; i <= m; ++i) scanf("%d", &a[i]);
	dpit();
	if (alldiff()) solve1();
	else solve2();
}