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 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;

ll mypow(ll a, ll b) {
	ll rv = 1;
	while (b) {
		if (b % 2) rv = rv*a%MOD;
		a = a*a%MOD;
		b /= 2;
	}
	return rv;
}
ll mul_inv(ll a, ll b = MOD) {
	ll t1 = a, t2 = b, t3;
	ll v1 = 1, v2 = 0, v3;
	while (t2 != 1) {
		ll x = t1 / t2;
		t3 = t1 - x*t2;
		v3 = v1 - x*v2;
		t1 = t2, t2 = t3;
		v1 = v2, v2 = v3;
	}
	return (v2 + b) % b;
}

int in[25050];
ll dp[25050][405];
ll sum[25050][405];

bool chk[25050];

ll F[25050];
ll Finv[25050];
ll P(int a, int b) {
	if (a < b) return 0;
	return F[a] * Finv[a - b] % MOD;
}
int main() {
	int N, K, M, i, j, k;
	F[0] = 1;
	for (i = 1; i <= 25020; i++) F[i] = F[i - 1] * i % MOD;
	for (i = 0; i <= 25020; i++) Finv[i] = mul_inv(F[i]);
	scanf("%d %d %d", &N, &K, &M);
	for (i = 1; i <= M; i++) scanf("%d", &in[i]);

	int c1 = M, c2 = M;
	ll ans = mypow(K, N - M) * (N - M + 1) % MOD;

	for (i = 1; i <= M - K + 1; i++) {
		for (j = 1; j <= K; j++) chk[j] = false;
		for (j = i; j < i + K; j++) {
			if (chk[in[j]]) break;
			chk[in[j]] = true;
		}
		if(j >= i+K) return !printf("%lld\n", ans);
	}
	for (i = 1; i <= K; i++) chk[i] = false;
	for (i = 1; i <= M; i++) {
		if (chk[in[i]]) {
			c1 = i - 1;
			break;
		}
		chk[in[i]] = true;
	}
	for (i = 1; i <= K; i++) chk[i] = false;
	for (i = M; i >= 1; i--) {
		if (chk[in[i]]) {
			c2 = M - i;
			break;
		}
		chk[in[i]] = true;
	}
	for (i = 1; i < K; i++) dp[0][i] = 1;
	for (i = 1; i <= N; i++) {
		for (j = 1; j < K; j++) sum[i - 1][j] = (sum[i - 1][j - 1] + dp[i - 1][j]) % MOD;
		for (j = 1; j < K; j++) {
			dp[i][j] = dp[i - 1][j + 1] * (K - j) + sum[i - 1][j];
			dp[i][j] %= MOD;
		}
	}

	if (c1 != M) {
		for (i = 0; i <= N - M; i++) {
			ans -= dp[i][c1] * dp[N - M - i][c2] % MOD;
			ans = (ans + MOD) % MOD;
		}
	}
	else {
		for (i = 0; i <= N - M; i++) {
			for (j = 0; j < i && c1 + j < K; j++) {
				ll s = sum[i - j - 1][c1 + j] * dp[N - M - i][c1 + j] % MOD;
				s = s * P(K - c1, j) % MOD;
				ans = (ans - s + MOD) % MOD;
			}
			if (c1 + i < K) {
				ll s = P(K - c1, i) * dp[N - M - i][c1 + i] % MOD;
				ans = (ans - s + MOD) % MOD;
			}
		}
	}
	return !printf("%lld\n", ans);
}