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;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = TEN(9) + 7;
const int MX = 26000;
const int MK = 410;

ll inv[MX], fact[MX], ifact[MX];

void init() {
	inv[1] = 1;
	for (int i = 2; i < MX; ++i) {
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
	}
	fact[0] = ifact[0] = 1;
	for (int i = 1; i < MX; ++i) {
		fact[i] = fact[i-1] * i % MOD;
		ifact[i] = ifact[i-1] * inv[i] % MOD;
	}
}

ll comb(int n, int r) {
	if (n < 0 || r < 0 || r > n) return 0;
	return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

ll dp[MX][MK]; //length, suffix
ll ac[MX][MK];
ll sm[MX][MK];

int main() {
	int N, K, M; cin >> N >> K >> M;
	vi A(M);

	rep(i, M) {
		cin >> A[i];
		--A[i];
	}

	init();
	dp[1][1] = K;
	for (int i = 1; i < MK; ++i) {
		ac[1][i] = K; 
	}

	for (int i = 2; i <= N; ++i) {
		for (int j = 1; j < K; ++j) {
			ll val = (dp[i-1][j-1] * (K-j+1) + ac[i-1][K] - ac[i-1][j-1]) % MOD;
			if (val < 0) val += MOD;
			dp[i][j] = val;
		}
		rep(j, MK-1) {
			ac[i][j+1] = (dp[i][j+1] + ac[i][j]) % MOD;
		} 
	}


	ll all = (N - M + 1);
	rep(i, N - M) all = all * K % MOD;

	for (int i = 0; i <= M - K; ++i) { // A : colorful
		vi ex(K);

		bool ok = true;
		for (int j = i; j < i + K; ++j) {
			if (ex[A[j]]) {
				ok = false;
				break;
			}
			ex[A[j]] = true;
		}

		if (ok) {
			cout << all << endl;
			return 0;
		}
	}

	int l, r;
	set<int> st;

	for (l = 0; l < M; ++l) {
		if (st.count(A[l])) {
			break;
		}
		st.insert(A[l]);
	}

	st.clear();
	for (r = 0; r < M; ++r) {
		if (st.count(A[M-1-r])) {
			break;
		}
		st.insert(A[M-1-r]);
	}

	if (l != M) { //contain same
		ll ng = 0;

		for (int i = 0; i <= N - M; ++i) {
			ll p = ac[i + l][min(i + l, K)] - ac[i + l][l - 1];
			if (p < 0) p += MOD;
			p = p * fact[K - l] % MOD * ifact[K] % MOD;

			int i2 = N - M - i;
			ll q = ac[i2 + r][min(i2 + r, K)] - ac[i2 + r][r - 1];
			if (q < 0) q += MOD;
			q = q * fact[K - r] % MOD * ifact[K] % MOD;

			ng = (ng + p * q) % MOD;
		}
		all -= ng;
		if (all < 0) all += MOD;
		cout << all << endl;
	} else { //distinct

		if (M == 1) {
			for (int i = 1; i < MK; ++i) {
				sm[1][i] = K; 
			}
		}

		for (int i = 2; i <= N; ++i) {
			for (int j = 1; j < K; ++j) {
				ll val = (j >= M ? dp[i][j] : 0) + (sm[i-1][j-1] - (j >= 2 ? sm[i-1][j-2] : 0)) * (K-j+1);
				val += sm[i-1][K] - sm[i-1][j-1];
				val %= MOD;
				if (val < 0) val += MOD;
				sm[i][j] = val;
			}

			rep(j, MK-1) {
				sm[i][j+1] = (sm[i][j+1] + sm[i][j]) % MOD;
			} 
		}

		ll ng = sm[N][K];

		ng = ng * fact[K - M] % MOD * ifact[K] % MOD;
		all -= ng;
		if (all < 0) all += MOD;
		cout << all << endl;		
	}

	return 0;
}