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 <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;

LL power(LL a, int t)
{
	LL ret = 1;
	while(t > 0) {
		if(t & 1) ret = ret * a % MOD;
		a = a * a % MOD;
		t >>= 1;
	}
	return ret;
}

int n, m, k, a[25005];
LL rs[405];
LL dp0l[25005][405], dp0r[25005][405], totl[25005], totr[25005];
pair<LL, LL> dp1[25005][2][405];
bool hv[405];

void gen_dp0(LL cdp[][405], LL tot[])
{
	rep1(i, k) hv[i] = false;
	rep(i, m) {
		if(hv[a[i]]) {
			cdp[0][i] = 1;
			break;
		}
		hv[a[i]] = true;
	}
	rep1(i, n) {
		rs[0] = 0;
		rep(j, k) rs[j + 1] = rs[j] + cdp[i - 1][j];
		rep1(j, k) cdp[i][j] = (rs[k] - rs[j] + cdp[i - 1][j - 1] * (k - j + 1)) % MOD;
		tot[i] = (tot[i - 1] * k + cdp[i][k]) % MOD;
	}
}

void gen_dp1(pair<LL, LL> cdp[][2][405])
{
	cdp[0][0][0] = MP(1, 0);
	rep1(i, n) rep(b, 2) {
		rs[0] = 0;
		for(int j = 0; j <= k; j ++) rs[j + 1] = rs[j] + cdp[i - 1][b][j].first;
		rep1(j, k) cdp[i][b | (j == k)][j].first += (rs[k + 1] - rs[j] + cdp[i - 1][b][j - 1].first * (k - j + 1)) % MOD;
		rep1(j, k) cdp[i][b][j].first %= MOD;
	}
	rep1(i, n) rep(b, 2) {
		rs[0] = 0;
		for(int j = 0; j <= k; j ++) rs[j + 1] = rs[j] + cdp[i - 1][b][j].second;
		rep1(j, k) cdp[i][b | (j == k)][j].second += (rs[k + 1] - rs[j] + cdp[i - 1][b][j - 1].second * (k - j + 1)) % MOD;
		rep1(j, k) {
			if(j >= m) cdp[i][b][j].second += cdp[i][b][j].first;
			cdp[i][b][j].second %= MOD;
		}
	}
}

int main()
{
	scanf("%d%d%d", &n, &k, &m);
	rep(i, m) scanf("%d", &a[i]);
	rep(i, m - k + 1) {
		rep1(j, k) hv[j] = false;
		rep(j, k) hv[a[i + j]] = true;
		bool ok = true;
		rep1(j, k) if(!hv[j]) ok = false;
		if(ok) {
			printf("%lld\n", (n - m + 1) * power(k, n - m) % MOD);
			return 0;
		}
	}
	bool cc = false;
	rep1(i, k) hv[i] = false;
	rep(i, m) {
		if(hv[a[i]]) cc = true;
		hv[a[i]] = true;
	}
	LL ans = 0;
	if(cc) {
		gen_dp0(dp0l, totl);
		reverse(a, a + m);
		gen_dp0(dp0r, totr);
		for(int i = 0; i <= n - m; i ++)
		ans = (ans + totl[i] * power(k, n - m - i) + totr[n - m - i] * power(k, i) - totl[i] * totr[n - m - i]) % MOD;
	} else {
		gen_dp1(dp1);
		rep1(i, k) ans += dp1[n][1][i].second;
		ans %= MOD;
		for(int i = k; i > k - m; i --)
		ans = ans * power(i, MOD - 2) % MOD;
	}
	printf("%lld\n", (ans + MOD) % MOD);
	return 0;
}