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>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M, K;
int A[25010];
ll dp[25010][410];
ll dps[25010][410];
ll S[25010][410];

ll loop(int n, int j);
ll loops(int n, int j);

ll loop(int n, int j) {
	// debug("loop", n, j);
	if(j == K || j == 0) return 0;
	if(n == 0) return 1;
	else if(dp[n][j] != -1) return dp[n][j];
	else {
		ll res = 0;
		res = (loops(n - 1, j) + loop(n - 1, j + 1) * (K - j) % mod) % mod;
		return dp[n][j] = res;
	}
}

ll loops(int n, int j) {
	// debug("loops", n, j);
	if(n == 0) return j;
	if(j == 0) return 0;
	else if(dps[n][j] != -1) return dps[n][j];
	else {
		ll res = 0;
		res = (loops(n, j - 1) + loops(n - 1, j) + loop(n - 1, j + 1) * (K - j) % mod) % mod;
		return dps[n][j] = res;
	}
}

void solve() {
	cin >> N >> K >> M;
	rep(i, 0, M) {
		cin >> A[i];
		A[i]--;
	}
	memset(dp, -1, sizeof(dp));
	memset(dps, -1, sizeof(dps));
	ll allv = 1;
	for(int i = 1; i <= N - M; i++) {
		MUL(allv, K);
	}
	MUL(allv, N - M + 1);
	// debug(allv);
	if(K < M) {
		vi vec(2, inf);
		rep(q, 0, 2) {
			vi used(K, 0);
			rep(i, 0, K) {
				if(used[A[i]] == 1 && vec[q] == inf) {
					vec[q] = i;
				}
				used[A[i]]++;
			}
			if(vec[q] == inf) {
				cout << allv << "\n"; return;
			}
			rep(i, K, M) {
				used[A[i - K]]--;
				used[A[i]]++;
				bool found = false;
				rep(j, 0, K) {
					if(used[j] != 1) found = true;
				}
				if(!found) {
					cout << allv << "\n"; return;
				}
			}
			reverse(A, A + M);
		}
		ll res = 0;
		for(int i = 0; i + M <= N; i++) {
			// debug(i, loop(i, vec[0]), N - (i + M), loop(N - (i + M), vec[1]));
			ADD(res, loop(i, vec[0]) * loop(N - (i + M), vec[1]) % mod);
		}
		cout << (allv - res + mod) % mod << "\n";
	}
	else {
		vi vec(2, inf);
		rep(q, 0, 2) {
			vi used(K, 0);
			rep(i, 0, M) {
				if(used[A[i]] == 1 && vec[q] == inf) {
					vec[q] = i;
				}
				used[A[i]]++;
			}
			reverse(A, A + M);
		}
		ll res = 0;
		if(vec[0] != inf) {
			for(int i = 0; i + M <= N; i++) {
				ADD(res, loop(i, vec[0]) * loop(N - (i + M), vec[1]) % mod);
			}
			cout << (allv - res + mod) % mod << "\n";
		}
		else { // this is difficult
			for(int i = 0; i <= N; i++) {
				for(int j = 0; j < K; j++) {
					ADD(S[i][j + 1], S[i][j] + loop(i, j));
					// debug(i, j + 1, S[i][j + 1], loop(i, j));
				}
			}
			vl F(K + 1, 0);
			F[M] = 1;
			for(int i = M; i < K; i++) {
				F[i + 1] = F[i] * (K - i) % mod;
			}
			ll res = 0;
			for(int m = M + 1; m <= K; m++) {
				for(int i = 0; i + m <= N; i++) {
					// debug(i, m, N - (i + m), loop(i, m - 1), S[N - (i + m)][m], F[m - 1]);
					ADD(res, loop(i, m - 1) * S[N - (i + m)][m] % mod * F[m - 1] % mod);
				}
			}
			ll tmp = 1;
			for(int m = M; m < K; m++) {
				ADD(res, loop(N - m, m) * tmp % mod);
				MUL(tmp, K - m);
			}
			// debug(res);
			cout << (allv - res + mod) % mod << "\n";
		}
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}