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;

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

using ll = long long;

num powmod(num a, ll b) { num r = 1; while (b) { if (b & 1) r *= a; a *= a; b /= 2; } return r; }

const int MAXN = 25010;
const int MAXK = 410;
int N, K, M;

bool isColorful(vector<int> a) {
	set<int> s;
	for (int i = 0, j = 0; i < int(a.size()); i++) {
		while (j < int(a.size()) && !s.count(a[j])) {
			s.insert(a[j]);
			j++;
		}
		assert(int(s.size()) == j-i);
		if (j-i == K) return true;
		s.erase(a[i]);
	}
	return false;
}

int maxDistinct(vector<int> a) {
	int res = 0;
	set<int> s;
	while (res < int(a.size()) && !s.count(a[res])) {
		s.insert(a[res]);
		res++;
	}
	return res;
}

num dp[MAXN][MAXK];
num dptot[MAXN][MAXK];

num fact(int n) {
	num res = 1;
	for (int i = 1; i <= n; i++) {
		res *= i;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> K >> M;
	vector<int> A(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i];
	}

	num ans = (N-M+1) * powmod(K, N-M);
	if (isColorful(A)) { // any sequence is ok
		cout << ans << '\n';
		exit(0);
	}

	int pref = maxDistinct(A);
	int suff = maxDistinct(vector<int>(A.rbegin(), A.rend()));
	if (pref == int(A.size())) {
		assert(pref == suff);
		dp[0][0] = 1;
		for (int i = 0; i < N; i++) {
			num s = 0;
			num stot = 0;
			for (int j = K-1; j >= 1; j--) {
				s += dp[i][j];
				stot += dptot[i][j];
				dp[i+1][j] = s + dp[i][j-1] * (K-(j-1));
				dptot[i+1][j] = stot + dptot[i][j-1] * (K-(j-1));
			}
			for (int j = M; j < K; j++) {
				dptot[i+1][j] += dp[i+1][j];
			}
		}

		num tot = 0;
		for (int j = 1; j < K; j++) {
			tot += dptot[N][j];
		}
		tot /= fact(K) / fact(K-M);
		ans -= tot;
	} else {
		for (int j = 1; j < K; j++) {
			dp[0][j] = 1;
		}
		for (int i = 0; i < N; i++) {
			num s = 0;
			for (int j = 1; j < K; j++) {
				s += dp[i][j];
				dp[i+1][j] = dp[i][j+1] * (K-j) + s;
			}
		}

		for (int i = 0; i <= N-M; i++) {
			ans -= dp[i][pref] * dp[N-M-i][suff];
		}
	}
	cout << ans << '\n';

	return 0;
}