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 <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 25005;
const int MM = 1000000007;

int A[MX];
int N, K, M;

pii operator+(pii l, pii r){ return pii((l.first + r.first) % MM, (l.second + r.second) % MM); }
pii operator*(ll K, pii r){ return pii(K*r.first % MM, K*r.second % MM); }

ll pw(ll a, ll b){
	ll r = 1;
	while(b){
		if(b&1) r = r*a % MM;
		a = a*a % MM; b /= 2;
	}
	return r;
}

int cnt[MX];
int check()
{
	int cur = 0;
	for(int i = 1; i <= K; i++){
		if(cnt[A[i]] == 0) cur++;
		cnt[A[i]] ++;
	}
	for(int i = K+1; i <= M; i++){
		if(cur == K) return 0;
		if(cnt[A[i]] == 0) cur++;
		cnt[A[i]]++;
		
		if(cnt[A[i-K]] == 1) cur--;
		cnt[A[i-K]]--;
	}
	for(int i = 1; i <= K; i++) cnt[i] = 0;
	for(int i = 1; i <= M; i++) cnt[A[i]] ++;
	for(int i = 1; i <= K; i++) if(cnt[i] >= 2) return 1;
	return 2;
}

ll pre[MX][405], suf[MX][405];
pii dp[2][MX][405] = {};

int main()
{
	scanf("%d%d%d", &N, &K, &M);
	for(int i = 1; i <= M; i++) scanf("%d", A+i);
	int type = check();
	if(type == 0){
		ll ans = (N-M+1) * pw(K, N-M) % MM;
		printf("%lld\n", ans);
		return 0;
	}
	if(type == 1){
		int P = 0, Q = 0;

		for(int i = 1; i <= K; i++) cnt[i] = 0;
		for(int i = 1; i <= M; i++){
			if(cnt[A[i]]){ P = i-1; break; }
			cnt[A[i]] ++;
		}
		for(int i = 1; i <= K; i++) cnt[i] = 0;
		for(int i = 1; i <= M; i++){
			if(cnt[A[M-i+1]]){ Q = i-1; break; }
			cnt[A[M-i+1]] ++;
		}

		pre[0][P] = 1;
		for(int i = 1; i <= N; i++){
			ll sum = 0;
			for(int j = K; j >= 1; j--){
				if(j == K) pre[i][j] = (K * pre[i-1][j] + pre[i-1][j-1]) % MM;
				else{
					sum = (sum + pre[i-1][j]) % MM;
					pre[i][j] = ((K-j+1) * pre[i-1][j-1] + sum) % MM;
				}
			}
		}
		suf[0][Q] = 1;
		for(int i = 1; i <= N; i++){
			ll sum = 0;
			for(int j = K; j >= 1; j--){
				if(j == K) suf[i][j] = (K * suf[i-1][j] + suf[i-1][j-1]) % MM;
				else{
					sum = (sum + suf[i-1][j]) % MM;
					suf[i][j] = ((K-j+1) * suf[i-1][j-1] + sum) % MM;
				}
			}
		}

		ll ans = 0;
		for(int i = 0; i <= N-M; i++){
			int l = i, r = N-M-i;
			ans = (ans + pre[l][K] * pw(K, r) + (pw(K, l) + MM - pre[l][K]) * suf[r][K]) % MM;
		}
		printf("%lld\n", ans);
	}
	else{
		auto assign = [](pii &x){ x = pii(x.first, (x.first + x.second) % MM); };
		dp[0][0][0] = pii(1, 0);
		for(int i = 1; i <= N; i++){
			pii s0 = pii(0, 0), s1 = pii(0, 0);
			for(int j = K; j >= 1; j--){
				s0 = s0 + dp[0][i-1][j];
				dp[0][i][j] = (K-j+1) * dp[0][i-1][j-1] + s0;
				s1 = s1 + dp[1][i-1][j];
				dp[1][i][j] = (K-j+1) * dp[1][i-1][j-1] + s1;
			}
			dp[1][i][K] = dp[0][i][K] + dp[1][i][K];
			dp[0][i][K] = pii(0, 0);
			for(int j = M; j <= K; j++) assign(dp[0][i][j]), assign(dp[1][i][j]);
		}
		ll ans = 0;
		for(int i = 0; i <= K; i++) ans = (ans + dp[1][N][i].second) % MM;
		for(int i = K-M+1; i <= K; i++) ans = ans * pw(i, MM-2) % MM;
		printf("%lld\n", ans);
	}
}