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 N = 25000 + 10, K = 410, mo = 1e9 + 7;
typedef long long ll;
int n,k,m,a[N],cnt[K];
ll ans;
ll ksm(ll x, ll y) {
	ll ret = 1; for(; y; y>>=1){
		if (y & 1) ret = ret * x % mo;
		x = x * x % mo;
	}
	return ret;
}


ll f[2][K], o, g[2][K];
inline void add(ll &x, ll y) {
	x = (x + y) % mo;
}

//长为n的non-colorful的串中，长为m的互异连续段有多少个.
ll dp1() {
	memset(f[o], 0, sizeof f[o]);
	memset(g[o], 0, sizeof g[o]);
	g[o][0] = 1;
	for(int i = 0; i < n; i++) {
		memset(f[1 - o], 0, sizeof f[1 - o]);
		memset(g[1 - o], 0, sizeof g[1 - o]);
		for(int j = 0; j < k; j++) {
			if (j + 1 != k) {
				add(g[1 - o][j + 1], g[o][j] * (k - j));
				add(f[1 - o][j + 1], f[o][j] * (k - j));
				add(g[1 - o][j + 2], - g[o][j] * (k - j));
				add(f[1 - o][j + 2], - f[o][j] * (k - j));
			}
			add(f[1 - o][1], f[o][j]);
			add(f[1 - o][j + 1], - f[o][j]);

			add(g[1 - o][1], g[o][j]);
			add(g[1 - o][j + 1], - g[o][j]);
		}
		o = 1 - o;
		for(int j = 1; j < k; j++) {
			add(g[o][j], g[o][j - 1]);
			add(f[o][j], f[o][j - 1]);
		}
		for(int j = m; j < k; j++)
				add(f[o][j], g[o][j]);
	}
	ll ret = 0;
	for(int i = 0; i < k; i++) add(ret, f[o][i]);
	return ret;
}

ll le[N][K], ri[N][K];
void dp2(int sig, ll f[N][K]) {
	memset(f, 0, sizeof f);
	memset(cnt, 0, sizeof cnt);
	if (sig == 0) { //left
		for(int i = 1; i <= m; i++) if (cnt[a[i]] == 0) {
			cnt[a[i]]++;
		} else {
			f[0][0] = f[0][i - 1] = 1;
			break;
		}
	} else {
		for(int i = m; i; i--) if (cnt[a[i]] == 0) {
			cnt[a[i]]++;
		} else {
			f[0][0] = f[0][m - i] = 1;
			break;
		}
	}
	for(int i = 0; i < n - m; i++) {
		for(int j = 1; j < k; j++) {
			if (j + 1 != k) {
				add(f[i + 1][j + 1], f[i][j] * (k - j));
				add(f[i + 1][j + 2], - f[i][j] * (k - j));
			}
			add(f[i + 1][1], f[i][j]);
			add(f[i + 1][j + 1], - f[i][j]);
		}
		for(int j = 1; j < k; j++) {
			add(f[i + 1][j], f[i + 1][j - 1]);
			add(f[i + 1][0], f[i + 1][j]);
		}
	}
}

int main() {
	cin>>n>>k>>m;
	for(int i = 1; i <= m; i++) scanf("%d", &a[i]);
	ans = (n - m + 1) * ksm(k, n - m) % mo;

	int non = 0;
	if (m >= k) {
		int js = 0;
		for(int i = 1; i <= k; i++)	{
			if (cnt[a[i]]++==0) js++;
		}
		if (js != k) {
			for(int i = 1; i + k - 1 < m; i++) {
				if (--cnt[a[i]]==0) js--;
				if (cnt[a[i + k]]++==0) js++;
				if (js == k) break;
			}
		}
		non = js != k;
	} else non = 1;

	if (non) {
		int same = 0;
		if (m <= k) {
			for(int i = 1; i <= m; i++) {
				for (int j = i + 1; j <= m; j++) if (a[i] == a[j]) {
					same = 1; break;
				}
			}
		} else same = 1;
		if (!same) {
			ll P = 1;
			for(int i = k; i > k - m; i--) P = P * i % mo;
			ans = (ans - ksm(P, mo - 2) * dp1()) % mo;
		} else {
			dp2(0, le), dp2(1, ri);
			for(int i = 0; i + m <= n; i++) {
				ans = (ans - le[i][0] * ri[n - m - i][0]) % mo;
			}
		}
	}
	cout << (ans + mo) % mo<<endl;
}