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;

namespace TYC
{
	typedef long long ll;
	const int N = 25005, M = 405, mod = 1e9 + 7;

	int n, m, K, A[N], C[M], F[2][M];

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	inline bool check1()
	{
		if (m < K)
			return false;
		for (int i = 1; i + K - 1 <= m; i++)
		{
			memset(C, 0, sizeof(C));
			bool flag = false;
			for (int j = 0; j < K; j++)
				flag |= ++C[A[i + j]] > 1;
			if (!flag)
				return true;
		}
		return false;
	}

	inline bool check2()
	{
		if (m > K)
			return false;
		for (int i = 1; i <= m; i++)
			if (++C[A[i]] > 1)
				return false;
		return true;
	}

	inline int qpow(int x, int tim)
	{
		int ans = 1;
		for (; tim; tim >>= 1, x = int((ll)x * x % mod))
			if (tim & 1)
				ans = int((ll)ans * x % mod);
		return ans;
	}

	inline int calc(const int mx)
	{
		static int G[2][M], SF[M], SG[M];
		memset(F, 0, sizeof(F));
		memset(G, 0, sizeof(G));
		memset(SF, 0, sizeof(SF));
		memset(SG, 0, sizeof(SG));
		F[1][1] = K;
		G[1][1] = m == 1 ? K : 0;	
		for (int i = mx - 1; i; i--)
		{
			SF[i] = (SF[i] + F[1][i]) % mod;
			SG[i] = (SG[i] + G[1][i]) % mod;
		}
		for (int i = 2, d = i & 1; i <= n; i++, d ^= 1)
			for (int j = mx - 1; j; j--)
			{
				F[d][j] = int(((ll)F[d ^ 1][j - 1] * (K - j + 1) % mod + SF[j]) % mod);
				G[d][j] = int(((ll)G[d ^ 1][j - 1] * (K - j + 1) % mod + SG[j]) % mod);
				if (j >= m)
					G[d][j] = (G[d][j] + F[d][j]) % mod;
				SF[j] = (F[d][j] + SF[j + 1]) % mod;
				SG[j] = (G[d][j] + SG[j + 1]) % mod;
			}
		return SG[1];
	}

	void solve2()
	{
		int ans = (calc(K + 1) - calc(K) + mod) % mod;
		int t = 1;
		for (int i = K - m + 1; i <= K; i++)
			t = int((ll)t * i % mod);
		printf("%d\n", int((ll)ans * qpow(t, mod - 2) % mod));
	}

	void get_dp(const int x, int *sum)
	{
		static int S[M];
		memset(S, 0, sizeof(S));
		memset(F, 0, sizeof(F));
		F[x & 1][x] = sum[x] = 1;
		fill(S + 1, S + x + 1, 1);
		for (int i = x + 1, d = i & 1; i <= n; i++, d ^= 1)
		{
			for (int j = K - 1; j; j--)
			{
				F[d][j] = int(((ll)F[d ^ 1][j - 1] * (K - j + 1) % mod + S[j]) % mod);
				S[j] = (F[d][j] + S[j + 1]) % mod;
			}
			sum[i] = S[1];
		}
	}
	
	int solve3()
	{
		static int f[N], g[N];
		int pre = 0, suf = 0;
		memset(C, 0, sizeof(int[K + 1]));
		while (pre < m && C[A[pre + 1]] == 0)
			C[A[++pre]]++;
		get_dp(pre, f);
		memset(C, 0, sizeof(int[K + 1]));
		while (suf < m && C[A[m - suf]] == 0)
			C[A[m - suf]]++, suf++;
		get_dp(suf, g);
		int ans = 0;
		for (int i = 0; i + m <= n; i++)
			ans = int((ans + (ll)f[i + pre] * g[n - m - i + suf] % mod) % mod);
		return ans;
	}

	void work()
	{
		n = read(), K = read(), m = read();
		for (int i = 1; i <= m; i++)
			A[i] = read();
		int tot = int((ll)qpow(K, n - m) * (n - m + 1) % mod);
		
		if (check1())
			printf("%d\n", tot);
		else if (check2())
			solve2();
		else
			printf("%d\n", (tot - solve3() + mod) % mod);
	}
}

int main()
{
	TYC::work();
	return 0;
}