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 <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



//先求出长n的不合法序列个数
//dp[i][j] = 长i, 最后一段连续互不相同的长度为j的方案
//dp[i-1][3] 填a[i-1] -> dp[i][1]
//dp[i-1][3] 填a[i-2] -> dp[i][2]
//dp[i-1][3] 填a[i-3] -> dp[i][3]
//a[i-4]与a[i-1],a[i-2],a[i-3]中的某一个相同
//dp[i-1][3] 填其余 -> dp[i][4]
//
//题目要求求出A在所有合法序列中的出现次数
//转化为A在所有序列中的出现次数(n-m+1)*k^(n-m)
//再减去A在所有不合法序列中的出现次数F
//长x的不合法序列总数很容易求出
//考虑给定的A, 假设A合法, 那么F = 0
//假设A所有元素互不相同
//求出所有长m的互不相同序列在长n的不合法序列中的出现次数
//dp[i][j] = 
//
//

const int N = 2.6e4+10, M = 410;
int n, k, m, a[N];
int f[N][M],g[N][M];
int vis[N],fac[N],ifac[N];
void add(int &a, ll b) {a=(a+b)%P;}

int main() {
	fac[0] = 1;
	REP(i,1,N-1) fac[i]=(ll)fac[i-1]*i%P;
	ifac[N-1]=inv(fac[N-1]);
	PER(i,0,N-2) ifac[i]=(ll)ifac[i+1]*(i+1)%P;
	scanf("%d%d%d", &n, &k, &m);
	REP(i,1,m) scanf("%d",a+i);
	int ma = 0, now = 0;
	REP(i,1,m) {
		while (now<m&&!vis[a[now+1]]) vis[a[++now]]=1;
		ma = max(ma, now-i+1);
		--vis[a[i]];
	}
	int tot = (n-m+1ll)*qpow(k,n-m)%P;
	if (ma==k) return printf("%d\n",tot),0;
	if (ma==m) {
		f[0][0] = 1;
		REP(i,1,n) {
			int s1 = 0, s2 = 0;
			PER(j,1,min(k-1,i)) {
				add(s1,f[i-1][j]),add(s2,g[i-1][j]);
				add(f[i][j]=s1,(ll)(k-j+1)*f[i-1][j-1]);
				add(g[i][j]=s2,(ll)(k-j+1)*g[i-1][j-1]);
				if (j>=m) add(g[i][j],f[i][j]);
			}
		}
		int ans = 0;
		REP(i,1,k-1) (ans += g[n][i])%=P;
		ans = (ll)ans*ifac[k]%P*fac[k-m]%P;
		ans = (tot-ans+P)%P;
		printf("%d\n", ans);
	}
	else {
		int L = 0, R = 0;
		memset(vis,0,sizeof vis);
		while (!vis[a[L+1]]) vis[a[++L]]=1;
		memset(vis,0,sizeof vis);
		while (!vis[a[m-R]]) vis[a[m-R++]]=1;
		f[0][L] = g[0][R] = 1;
		REP(i,1,n) {
			int s1 = 0, s2 = 0;
			PER(j,1,k-1) {
				add(s1,f[i-1][j]),add(s2,g[i-1][j]);
				add(f[i][j]=s1,(ll)(k-j+1)*f[i-1][j-1]);
				add(g[i][j]=s2,(ll)(k-j+1)*g[i-1][j-1]);
			}
		}
		int ans = 0;
		REP(i,0,n-m) {
			int s1 = 0, s2 = 0;
			REP(j,1,k-1) add(s1,f[i][j]),add(s2,g[n-m-i][j]);
			add(ans,(ll)s1*s2);
		}
		ans = (tot-ans+P)%P;
		printf("%d\n", ans);
	}
}