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;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;

const int MOD = (int) 1e9 + 7;
const int MAXN = (int) 2.5e4, MAXK = 400;

int n, k, m;
int A[MAXN + 5];

inline void input()
{
	n = read<int>(), k = read<int>(), m = read<int>();
	for(int i = 1; i <= m; ++i) A[i] = read<int>();
}

inline int chk_type()
{
	static int vis[MAXN + 5];

	int p = 0, fg = 0;
	for(int i = 1; i <= m; ++i)
	{
		if(vis[A[i]]) fg = 1, chkmax(p, vis[A[i]]);
		if(i - p == k) return 0;
		vis[A[i]] = i;
	}
	return fg ? 2 : 1;
}

inline int fpm(int x, int y)
{
	int res = 1;
	for(; y; y >>= 1, x = (LL) x * x % MOD) if(y & 1) res = (LL) res * x % MOD;
	return res;
}

inline int CNT() { return (LL) (n - m + 1) * fpm(k, n - m) % MOD; }

inline int SPE()
{
	static int f[MAXN + 5][MAXK + 5], g[MAXN + 5][MAXK + 5];
	static int suff[MAXN + 5][MAXK + 5], sufg[MAXN + 5][MAXK + 5];

	f[0][0] = 1, suff[0][0] = 1;
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j < k; ++j)
		{
			f[i][j] = (LL) f[i - 1][j - 1] * (k - j + 1) % MOD;
			(f[i][j] += suff[i - 1][j]) %= MOD;

			g[i][j] = (LL) g[i - 1][j - 1] * (k - j + 1) % MOD;
			(g[i][j] += sufg[i - 1][j]) %= MOD;
			if(j >= m) (g[i][j] += f[i][j]) %= MOD;
		}

		for(int j = k - 1; j; --j)
		{
			suff[i][j] = (suff[i][j + 1] + f[i][j]) % MOD;
			sufg[i][j] = (sufg[i][j + 1] + g[i][j]) % MOD;
		}
	}

	int res = 0;
	for(int i = 1; i < k; ++i) (res += g[n][i]) %= MOD;
	for(int i = 0; i < m; ++i) res = (LL) res * fpm(k - i, MOD - 2) % MOD;
	return res;
}

inline void get_lr_pos(int &l, int &r)
{
	static bool vis[MAXN + 5];

	memset(vis, 0, sizeof vis);
	for(int i = 1; i <= m; ++i)
	{
		if(vis[A[i]]) { l = i - 1; break; }
		vis[A[i]] = 1;
	}

	memset(vis, 0, sizeof vis);
	for(int i = m; i; --i)
	{
		if(vis[A[i]]) { r = i + 1; break; }
		vis[A[i]] = 1;
	}
	r = m - r + 1;
}

inline int DP()
{
	static int l, r;
	get_lr_pos(l, r);

	static int f[MAXN + 5][MAXK + 5], suff[MAXN + 5][MAXK + 5];

	f[0][l] = 1;
	for(int i = 1; i <= l; ++i) suff[0][i] = 1;
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j < k; ++j)
		{
			f[i][j] = (LL) f[i - 1][j - 1] * (k - j + 1) % MOD;
			(f[i][j] += suff[i - 1][j]) %= MOD;
		}

		for(int j = k - 1; j; --j) suff[i][j] = (suff[i][j + 1] + f[i][j]) % MOD;
	}

	static int g[MAXN + 5][MAXK + 5], sufg[MAXN + 5][MAXK + 5];

	g[0][r] = 1;
	for(int i = 1; i <= r; ++i) sufg[0][i] = 1;
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j < k; ++j)
		{
			g[i][j] = (LL) g[i - 1][j - 1] * (k - j + 1) % MOD;
			(g[i][j] += sufg[i - 1][j]) %= MOD;
		}

		for(int j = k - 1; j; --j) sufg[i][j] = (sufg[i][j + 1] + g[i][j]) % MOD;
	}

	int ans = 0;
	for(int i = 1; i <= n - m + 1; ++i)
	{
		int llen = i - 1, rlen = n - (i + m - 1);
		int lall = fpm(k, llen), ldp = (lall - suff[llen][1]) % MOD,
			rall = fpm(k, rlen), rdp = (rall - sufg[rlen][1]) % MOD;

		(ans += (LL) ldp * rall % MOD) %= MOD;
		(ans += (LL) lall * rdp % MOD) %= MOD;
		(ans -= (LL) ldp * rdp % MOD) %= MOD;
	}
	return ans;
}

int main()
{
//	freopen("F.in", "r", stdin);
//	freopen("F.out", "w", stdout);

	input();
	int type = chk_type();
	if(type == 0) printf("%d\n", CNT());
	if(type == 1) printf("%d\n", ((CNT() - SPE()) % MOD + MOD) % MOD);
	if(type == 2) printf("%d\n", (DP() + MOD) % MOD);

	return 0;
}