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 <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
//#define ivorysi
#define fi first
#define se second
#define MAXN 25005
#define enter putchar('\n')
#define space putchar(' ')
typedef long long ll;
using namespace std;
template <class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
        c = getchar();
        if(c == '-') f = -1;
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template <class T>
void out(T x) {
    if(x < 0) {x = -x;}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,K,M;
int A[MAXN],fac[MAXN],invfac[MAXN],inv[MAXN];
int F,B,L,vis[405];
int dp[MAXN][405],cnt[MAXN][405],sum[405],sum_cnt[405],f[MAXN],b[MAXN];
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
        if(c & 1) res = mul(res,t);
        t = mul(t,t);
        c >>= 1;
    }
    return res;
}
void Init() {
    read(N);read(K);read(M);
    for(int i = 1 ; i <= M ; ++i) read(A[i]);
    inv[1] = 1;
    for(int i = 2 ; i <= K ; ++i) inv[i] = mul(inv[MOD % i],MOD - MOD / i);
    fac[0] = invfac[0] = 1;
    for(int i = 1 ; i <= K ; ++i) {
        fac[i] = mul(fac[i - 1],i);
        invfac[i] = mul(invfac[i - 1],inv[i]);
    }
    F = 0;B = 0;
    memset(vis,0,sizeof(vis));
    for(int i = 1 ; i <= M ; ++i) {
        if(!vis[A[i]]) {
            ++F;
            vis[A[i]] = 1;
        }
        else break;
    }
    memset(vis,0,sizeof(vis));
    for(int i = M ; i >= 1 ; --i) {
        if(!vis[A[i]]) {
            ++B;
            vis[A[i]] = 1;
        }
        else break;
    }
    memset(vis,0,sizeof(vis));
    int l = 0;
    for(int i = 1 ; i <= M ; ++i) {
        l = max(l,vis[A[i]]);
        L = max(L,i - l);
        vis[A[i]] = i;
    }
}
void Process(int st,int *a) {
    memset(dp,0,sizeof(dp));
    dp[0][st] = 1;
    memset(sum,0,sizeof(sum));
    for(int i = st ; i <= K ; ++i) sum[i] = 1;
    a[0] = 1;
    for(int i = 1 ; i <= N ; ++i) {
        for(int j = 1 ; j < K ; ++j) {
            dp[i][j] = inc(dp[i][j],mul(dp[i - 1][j - 1],(K - j + 1)));
            dp[i][j] = inc(dp[i][j],inc(sum[K],MOD - sum[j - 1]));
        }
        for(int j = 1 ; j <= K ; ++j) {
            sum[j] = inc(sum[j - 1],dp[i][j]);
        }
        a[i] = sum[K - 1];
    }
}
void Solve() {
    if(L == K) {
        out(mul(N - M + 1,fpow(K,N - M)));enter;
    }
    else if(F == M) {
        dp[0][0] = 1;
        int ans = mul(N - M + 1,fpow(K,N - M)),tmp = 0;
        for(int i = 1 ; i <= N ; ++i) {
            for(int j = 1 ; j < K ; ++j) {
                dp[i][j] = inc(dp[i][j],mul(dp[i - 1][j - 1],(K - j + 1)));
                dp[i][j] = inc(dp[i][j],inc(sum[K],MOD - sum[j - 1]));
                cnt[i][j] = inc(cnt[i][j],mul(cnt[i - 1][j - 1],(K - j + 1)));
                cnt[i][j] = inc(cnt[i][j],inc(sum_cnt[K],MOD - sum_cnt[j - 1]));
                if(j >= M) cnt[i][j] = inc(cnt[i][j],dp[i][j]);
            }
            for(int j = 1 ; j <= K ; ++j) {
                sum[j] = inc(sum[j - 1],dp[i][j]);
                sum_cnt[j] = inc(sum_cnt[j - 1],cnt[i][j]);
            }
        }
        for(int j = 0 ; j < K ; ++j) {
            tmp = inc(tmp,cnt[N][j]);
        }
        tmp = mul(tmp,fpow(mul(fac[K],invfac[K - M]),MOD - 2));
        ans = inc(ans,MOD - tmp);
        out(ans);enter;
    }
    else {
        Process(F,f);Process(B,b);
        int ans = mul(N - M + 1,fpow(K,N - M));
        for(int i = 1 ; i <= N - M + 1 ; ++i) {
            int j = i + M - 1;
            ans = inc(ans,MOD - mul(f[i - 1],b[N - j]));
        }
        out(ans);enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}