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

using namespace std;

const int MOD = 1e9 + 7;
const int MAXN = 25005;
const int MAXK = 405;

int N, K, M, L, R;

long long res = 0;

int A[MAXN], f[MAXN][MAXK], g[MAXN][MAXK], a[MAXN][2], b[MAXN][2], fac[MAXK], invf[MAXK];

int qpow(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (long long)ret * a % MOD;
		b >>= 1;
		a = (long long)a * a % MOD;
	}
	return ret;
}

inline void add(int &a, int b)
{
	a = (((long long)a + b) % MOD + MOD) % MOD;
}

void init()
{
	int cnt[MAXK], p;
	memset(cnt, 0, sizeof(cnt));
	p = 0;
	while (p < M && ++cnt[A[p + 1]] == 1)
		++p;
	f[0][p] = 1, L = p;
	memset(cnt, 0, sizeof(cnt));
	p = 0;
	while (p < M && ++cnt[A[M - p]] == 1)
		++p;
	g[0][p] = 1, R = p;
	fac[0] = 1;
	for (int i = 1; i <= K; i++)
		fac[i] = (long long)fac[i - 1] * i % MOD;
	for (int i = 0; i <= K; i++)
		invf[i] = qpow(fac[i], MOD - 2);
}

bool check()
{
	if (M < K)
		return 0;
	int cnt[MAXK], w = 0, ret = 0;
	memset(cnt, 0, sizeof(cnt));
	for (int i = 1; i <= K; i++)
	{
		cnt[A[i]]++;
		if (cnt[A[i]] == 1) w++;
		if (cnt[A[i]] == 2) w--;
	}
	ret |= (w == K);
	for (int i = K + 1; i <= M; i++)
	{
		cnt[A[i]]++, cnt[A[i - K]]--;
		if (cnt[A[i]] == 1) w++;
		if (cnt[A[i]] == 2) w--;
		if (cnt[A[i - K]] == 1) w++;
		if (cnt[A[i - K]] == 0) w--;
		ret |= (w == K);
	}
	return ret;
}

void DP1()
{
	res = (long long)(N - M + 1) * qpow(K, N - M) % MOD;
	f[1][1] = K;
	if (M == 1)
		g[1][1] = K;
	for (int i = 1; i < N; i++)
	{
		for (int j = 1; j < K; j++)
		{
			add(f[i + 1][j + 1], (long long)(K - j) * f[i][j] % MOD);
			add(f[i + 1][j + 2], -(long long)(K - j) * f[i][j] % MOD);
			add(f[i + 1][1], f[i][j]);
			add(f[i + 1][j + 1], -f[i][j]);
			add(g[i + 1][j + 1], (long long)(K - j) * g[i][j] % MOD);
			add(g[i + 1][j + 2], -(long long)(K - j) * g[i][j] % MOD);
			add(g[i + 1][1], g[i][j]);
			add(g[i + 1][j + 1], -g[i][j]);
		}
		for (int j = 2; j < K; j++)
			add(f[i + 1][j], f[i + 1][j - 1]), add(g[i + 1][j], g[i + 1][j - 1]);;
		for (int j = M; j < K; j++)
			add(g[i + 1][j], f[i + 1][j]);
	}
	int sum = 0;
	for (int j = 1; j < K; j++)
		add(sum, g[N][j]);
	sum = (long long)sum * fac[K - M] % MOD * invf[K] % MOD;
	res = (res - sum + MOD) % MOD;
}

void DP2()
{
	for (int i = 0; i < N - M; i++)
	{
		for (int j = 1; j < K; j++)
		{
			add(f[i + 1][j + 1], (long long)f[i][j] * (K - j) % MOD);
			add(f[i + 1][j + 2], 0 - (long long)f[i][j] * (K - j) % MOD);
			add(f[i + 1][1], f[i][j]);
			add(f[i + 1][j + 1], 0 - f[i][j]);
		}
		add(f[i + 1][K], (long long)f[i][K] * K % MOD);
		for (int j = 2; j <= K; j++)	
			add(f[i + 1][j], f[i + 1][j - 1]);
	}
	for (int i = 0; i < N - M; i++)
	{
		for (int j = 1; j < K; j++)
		{
			add(g[i + 1][j + 1], (long long)g[i][j] * (K - j) % MOD);
			add(g[i + 1][j + 2], 0 - (long long)g[i][j] * (K - j) % MOD);
			add(g[i + 1][1], g[i][j]);
			add(g[i + 1][j + 1], 0 - g[i][j]);
		}
		add(g[i + 1][K], (long long)g[i][K] * K % MOD);
		for (int j = 2; j <= K; j++)
			add(g[i + 1][j], g[i + 1][j - 1]);
	}
	for (int i = 0; i <= N - M; i++)
	{
		for (int j = 1; j < K; j++)
			add(a[i][0], f[i][j]);
		add(a[i][1], f[i][K]);
	}
	for (int i = 0; i <= N - M; i++)
	{
		for (int j = 1; j < K; j++)
			add(b[i][0], g[i][j]);
		add(b[i][1], g[i][K]);	
	}
	res = (long long)(N - M + 1) * qpow(K, N - M) % MOD;
	for (int i = 0; i <= N - M; i++)
	{
		long long x = a[i][0], y = a[i][1], u = b[N - M - i][0], v = b[N - M - i][1];
		res = (res - (x * u) % MOD + MOD) % MOD;
	}	
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> K >> M;
	for (int i = 1; i <= M; i++)
		cin >> A[i];
	init();
	if (check())
		res = (long long)(N - M + 1) * qpow(K, N - M) % MOD;
	else if (L == M)
		DP1();
	else
		DP2();
	cout << res << endl;
	return 0;
}