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:
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 25005
#define MAXK 405
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,m,a[MAXN];
int cnt[MAXN],res,premax,sufmax,save;
int pre[MAXN][MAXK],suf[MAXN][MAXK],ss[MAXN][MAXK];
int fact[MAXK],invf[MAXK];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
int check()
{
    memset(cnt,0,sizeof(cnt));
    int res=0;
    premax=-1;sufmax=-1;
    bool flag=true;
    for(int i=1;i<=m;i++)
    {
        if(!cnt[a[i]]) res++;
        cnt[a[i]]++;
        if(i>k)
        {
            cnt[a[i-k]]--;
            if(!cnt[a[i-k]]) res--;
        }
        if(cnt[a[i]]>1&&premax==-1) premax=i-1;
        if(res==k) flag=false;
    }
    memset(cnt,0,sizeof(cnt));res=0;
    for(int i=m;i>=1;i--)
    {
        if(!cnt[a[i]]) res++;
        cnt[a[i]]++;
        if(i+k<=m)
        {
            cnt[a[i+k]]--;
            if(!cnt[a[i+k]]) res--;
        }
        if(i+k<=m) cnt[a[i+k]]--;
        if(cnt[a[i]]>1&&sufmax==-1) sufmax=m-i;
    }
    return flag;
}
void calcdp(int flag)
{
    auto dp=(flag?pre:suf);
    int sum[MAXK],sum2[MAXK];
    if(flag==2)
    {
        dp[0][0]=1;        
        for(int i=0;i<n;i++)
        {
            sum[k-1]=dp[i][k-1];
            sum2[k-1]=ss[i][k-1];
            for(int j=k-2;j>=0;j--) 
            {
                sum[j]=sum[j+1];sum2[j]=sum2[j+1];
                add(sum[j],dp[i][j]);add(sum2[j],ss[i][j]);
            }
            for(int j=1;j<k;j++)
            {
                add(dp[i+1][j],1LL*dp[i][j-1]*(k-j+1)%MOD);
                add(ss[i+1][j],1LL*ss[i][j-1]*(k-j+1)%MOD);
                add(dp[i+1][j],sum[j]);
                add(ss[i+1][j],sum2[j]);
                if(j>=m) add(ss[i+1][j],dp[i+1][j]);
            }
        }
        for(int j=1;j<k;j++) add(save,ss[n][j]);
        return;
    }
    if(flag) dp[0][premax]=1; else dp[0][sufmax]=1;
    memset(sum,0,sizeof(sum));
    for(int i=0;i<n-m;i++)
    {
        sum[k-1]=dp[i][k-1];
        for(int j=k-2;j>=0;j--) 
        {
            sum[j]=sum[j+1];
            add(sum[j],dp[i][j]);
        }
        for(int j=1;j<k;j++)
        {
            add(dp[i+1][j],1LL*dp[i][j-1]*(k-j+1)%MOD);
            add(dp[i+1][j],sum[j]);
        }
    }
    for(int i=0;i<=n-m;i++)
        for(int j=1;j<=k-1;j++) add(dp[i][j],dp[i][j-1]);
}
int main()
{
    fact[0]=invf[0]=1;
    for(int i=1;i<=400;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    invf[400]=pow_mod(fact[400],MOD-2);
    for(int i=399;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD;
    scanf("%d%d%d",&n,&k,&m);
    for(int i=1;i<=m;i++) scanf("%d",&a[i]);
    int ans=1LL*(n-m+1)*pow_mod(k,n-m)%MOD;
    if(!check())
    {
        printf("%d\n",ans);
        return 0;
    }
    if(premax==-1||sufmax==-1)
    {
        save=0;calcdp(2);
        dec(ans,1LL*save*invf[k]%MOD*fact[k-m]%MOD);
        printf("%d\n",ans);
        return 0;
    }
    calcdp(0);calcdp(1);
   /* for(int i=0;i<=n-m;i++)
    {
        for(int j=1;j<=k-1;j++)
            printf("%d ",pre[i][j]);
        puts("");
    }*/
    for(int i=0;i<=n-m;i++) dec(ans,1LL*pre[i][k-1]*suf[n-m-i][k-1]%MOD);
    printf("%d\n",ans);
    return 0;
}