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 <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int Max_N(25050);
const int Max_K(405);
const int MOD(1000000000 + 7);

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

constexpr int Mult(int a, int b)
{
	return a * 1LL * b % MOD;
}

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

constexpr int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

void exgcd(int a, int b, int &x, int &y)
{
	if (b == 0)
		x = 1, y = 0;
	else
		exgcd(b, a % b, y, x), y -= x * (a / b);
}

inline int inverse(int a)
{
	int invx, invy;
	exgcd(a, MOD, invx, invy);
	return (invx % MOD + MOD) % MOD;
}

inline void upd(int &a, int b)
{
	a = Add(a, b);
}

int N, K, M, A[Max_N], Last[Max_K], powerK[Max_N], Ans, Fac[Max_N], Inv[Max_N];

bool check()
{
	for (int i = 1, j = 1;i <= M;++i)
	{
		j = max(j, Last[A[i]] + 1), Last[A[i]] = i;
		if (i - j + 1 == K)
			return true;
	}
	return false;
}

int F[Max_N][Max_K];
void dp()
{
	for (int k = 1;k <= K - 1;++k)
		F[0][k] = 1;
	for (int n = 1;n <= N;++n)
		for (int k = 1, Sum = 0;k <= K - 1;++k)
			upd(Sum, F[n - 1][k]), F[n][k] = Add(Sum, k + 1 < K ? Mult(F[n - 1][k + 1], K - k) : 0);
}

int G[Max_N][Max_K], H[Max_N][Max_K];
void dp2()
{
	G[1][1] = K, H[1][1] = K * (1 >= M);
	for (int n = 2;n <= N;++n)
		for (int k = K - 1, SumG = 0, SumH = 0;k >= 1;--k)
		{
			upd(SumG, G[n - 1][k]);
			G[n][k] = Add(SumG, k - 1 ? Mult(G[n - 1][k - 1], K - (k - 1)) : 0);
			upd(SumH, H[n - 1][k]);
			H[n][k] = Add(SumH, k - 1 ? Mult(H[n - 1][k - 1], K - (k - 1)) : 0);
			if (k >= M)
				upd(H[n][k], Add(SumG, k - 1 ? Mult(G[n - 1][k - 1], K - (k - 1)) : 0));
		}
}

int main()
{
	gi(N), gi(K), gi(M);
	if (K > N)
	{
		printf("0");
		return 0;
	}
	Fac[0] = 1;
	for (int i = 1;i <= N;++i)
		Fac[i] = Mult(Fac[i - 1], i);
	Inv[N] = inverse(Fac[N]);
	for (int i = N - 1;i >= 0;--i)
		Inv[i] = Mult(Inv[i + 1], i + 1);
	for (int i = 1;i <= M;++i)
		gi(A[i]);
	powerK[0] = 1;
	for (int i = 1;i <= N;++i)
		powerK[i] = Mult(powerK[i - 1], K);
	if (check())
		Ans = 0;
	else
	{
		memset(Last, 0, sizeof(Last));
		int x, y;
		for (x = 1;x <= M;++x)
		{
			if (Last[A[x]])
				break;
			Last[A[x]] = 1;
		}
		--x;
		memset(Last, 0, sizeof(Last));
		for (y = M;y >= 1;--y)
		{
			if (Last[A[y]])
				break;
			Last[A[y]] = 1;
		}
		++y, y = M - y + 1;
		if (x == M && y == M)
		{
			dp2();
			for (int k = 1;k <= K - 1;++k)
				upd(Ans, H[N][k]);
			Ans = Mult(Ans, inverse(Mult(Fac[K], Inv[K - M])));
		}
		else
		{
			dp();
			for (int n = 0;n <= N - M;++n)
				upd(Ans, Mult(F[n][x], F[N - M - n][y]));
		}
	}
	print(Sub(Mult(powerK[N - M], N - M + 1), Ans));
	return 0;
}