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 long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
#define sf(a) scanf("%d",&a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))

const int inf = 2e9 + 7;
const ll INF = INT64_MAX;
double eps = 1e-6;
int mod = 1e9 + 7;
const int N = 25100;
const double pi = acos(-1.0);

int n, k, m;
int a[N];
int pos,rlen,llen;
bool ok[500];
int last[500];
void work() {
	if(m>=k){
		mem(ok, 0); mem(last, 0);
		int l = 1, r = 1;
		while (r <= m) {
			if (!ok[a[r]])ok[a[r]] = 1;
			else {
				for (; l < last[a[r]]; l++) {
					ok[a[l]] = 0;
				}
				l++;
			}
			if (r - l + 1 == k) { pos = 1; return; }
			last[a[r]] = r;
			r++;
		}
	}
	mem(ok, 0);
	f(i, 1, m)if (!ok[a[i]])ok[a[i]] = 1; else { 
		pos = 3;
		llen = i - 1;
		mem(ok, 0);
		rf(j, m, 1)if (!ok[a[j]])ok[a[j]] = 1; else {
			rlen = m - j; break;
		}
		return; 
	}
	pos = 2;
}
ll dp[N][410],g[N][410]; ll sum[410],sumg[410];
void M(ll& a) {
	a %= mod;
	if (a < 0)a += mod;
}
void init() {
	dp[1][1] = k;
	if (m == 1)g[1][1] += k;
	f(i, 2, n) {
		f(j, 1, k-1)M(sum[j] = sum[j - 1] + dp[i - 1][j]), M(sumg[j] = sumg[j - 1] + g[i - 1][j]);
		f(j, 1, k-1) {
			M(dp[i][j] = dp[i - 1][j - 1]*(k-j+1)%mod + sum[k-1] - sum[j - 1]);
		}
		f(j, 1, k - 1) {
			M(g[i][j] = g[i - 1][j - 1] * (k - j + 1) % mod + sumg[k - 1] - sumg[j - 1]+(j>=m?dp[i][j]:0));
		}
	}
}

ll power(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)M(res *= a);
		a = a * a % mod;
		b >>= 1;
	}return res;
}
ll powk[N];
ll jiechen[500];
ll L[N][500], R[N][500];
ll Lsum[N], Rsum[N];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	jiechen[0] = 1;
	f(i, 1, 400)jiechen[i] = i * jiechen[i - 1]%mod;
	sf(n); sf(k); sf(m);
	powk[0] = 1;
	f(i, 1, 25000)powk[i] = powk[i - 1] * k % mod;
	f(i, 1, m)sf(a[i]);
	work();
	init();
	ll res = (n - m + 1) * power(k, n - m); M(res);
	if (pos == 1);
	else if (pos == 2) {
		ll tmp = 0;
		f(i, 1, n)M(tmp += g[n][i]);
		ll chu = jiechen[k] * power(jiechen[k - m], mod - 2); M(chu);
		M(tmp *= power(chu,mod-2)); M(res -= tmp);
	}
	else {
		R[0][rlen] = 1;
		f(i, 1, n) {
			f(j, 1, k-1)M(sum[j] = sum[j - 1] + R[i - 1][j]);
			f(j, 1, k-1) {
				M(R[i][j] = R[i - 1][j - 1] * (k - j + 1)%mod + sum[k-1] - sum[j - 1]);
			}
		}
		L[0][llen] = 1;
		f(i, 1, n) {
			f(j, 1, k-1)M(sum[j] = sum[j - 1] + L[i - 1][j]);
			f(j, 1, k-1) {
				M(L[i][j] = L[i - 1][j - 1] * (k - j + 1)%mod + sum[k-1] - sum[j - 1]);
			}
		}
		Lsum[0] = Rsum[0] = 1;
		f(i, 1, n)f(j, 1, k)M(Lsum[i] += L[i][j]), M(Rsum[i] += R[i][j]);
		ll tmp = 0;
		f(i, 0, n - m) {
			M(tmp += Lsum[i] * Rsum[n - m - i]);
		}
		res -= tmp;
	}
	M(res);
	cout << res;
}