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>

typedef long long int int64;
static const int64 mod = 1000000007LL;
int64 qpow(int64 a,int b)
{
	int64 val = 1;
	for(int j = 0;j < b;++j) val = val * a % mod;
	return val;
}

int64 dp[25000][400];
int64 dp2[25000][400];
int n,k,m;
int a[25000];
int64 pre[400];
int vis[400],visn;
int64 inv[25000];
int main()
{
	scanf("%d%d%d",&n,&k,&m);
	if(k == 1) {
		printf("%d\n", n-m+1);
		return 0;
	}
	bool color = false;
	for(int i = 0;i < m;++i) {
		scanf("%d",&a[i]);
		--a[i];
		if(i >= k) {
			if(--vis[a[i-k]] == 0) --visn;
		}
		if(vis[a[i]]++ == 0) ++visn;
		if(visn == k) color = true;
	}
	if(color) {
		printf("%lld\n", qpow(k,n-m)*(n-m+1)%mod);
		return 0;
	}
	memset(vis,0,sizeof(vis));visn = 0;
	int la = 0,lb = 0;
	for(int i = 0;i < m;++i) {
		if(vis[a[i]]) break;
		++la;vis[a[i]] = true;
	}
	memset(vis,0,sizeof(vis));visn = 0;
	for(int i = m-1;i >= 0;--i) {
		if(vis[a[i]]) break;
		++lb;vis[a[i]] = true;
	}
	if(la == m) {
		dp[0][0] = k;if(la == 1) dp2[0][0] = k;
		for(int i = 1;i < n;++i) {
			pre[k-2] = dp[i-1][k-2];
			for(int j = k-3;j >= 0;--j) pre[j] = (pre[j+1] + dp[i-1][j]) % mod;
			for(int j = 0;j < k-1;++j) {
				dp[i][j] = ((j == 0 ? 0 : dp[i-1][j-1] * (k-j)) + pre[j]) % mod;
			}
			pre[k-2] = dp2[i-1][k-2];
			for(int j = k-3;j >= 0;--j) pre[j] = (pre[j+1] + dp2[i-1][j]) % mod;
			for(int j = 0;j < k-1;++j) {
				dp2[i][j] = ((j >= la-1 ? dp[i][j] : 0) + (j == 0 ? 0 : dp2[i-1][j-1] * (k-j)) + pre[j]) % mod;
			}
		}
		int64 ans = 0;
		for(int j = 0;j < k-1;++j) ans += dp2[n-1][j];
		ans %= mod;
		inv[1] = 1;
		for(int i = 2;i <= k;++i) {
			inv[i] = (mod-mod/i)*inv[mod%i]%mod;
			if(i>k-m) ans = ans * inv[i] % mod;
		}
		ans = (qpow(k,n-m)*(n-m+1)-ans)%mod;
		if(ans < 0) ans += mod;
		printf("%lld\n", ans);
	} else {
		dp[0][la-1] = 1;
		for(int i = 1;i < n;++i) {
			pre[k-2] = dp[i-1][k-2];
			for(int j = k-3;j >= 0;--j) pre[j] = (pre[j+1] + dp[i-1][j]) % mod;
			for(int j = 0;j < k-1;++j) {
				dp[i][j] = ((j == 0 ? 0 : dp[i-1][j-1] * (k-j)) + pre[j]) % mod;
			}
		}
		dp2[0][lb-1] = 1;
		for(int i = 1;i < n;++i) {
			pre[k-2] = dp2[i-1][k-2];
			for(int j = k-3;j >= 0;--j) pre[j] = (pre[j+1] + dp2[i-1][j]) % mod;
			for(int j = 0;j < k-1;++j) {
				dp2[i][j] = ((j == 0 ? 0 : dp2[i-1][j-1] * (k-j)) + pre[j]) % mod;
			}
		}
		int64 ans = 0;
		for(int i = 0;i <= n-m;++i) {
			int i2 = n-m-i;
			int64 val1 = 0, val2 = 0;
			for(int j = 0;j < k-1;++j) val1 += dp[i][j];
			val1 %= mod;
			for(int j = 0;j < k-1;++j) val2 += dp2[i2][j];
			val2 %= mod;
			ans += val1 * val2 % mod;
		}
		ans = (qpow(k,n-m)*(n-m+1)-ans)%mod;
		if(ans < 0) ans += mod;
		printf("%lld\n", ans % mod);
	}
}