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:
/*
Recall the definition of C(n,m) = the number of ways to pick m items from n indistinguishable ones.
In this problem, the order matters. So we must use C(n,m) * m!.
*/
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[25001],cnt[401],dp1[25001][401],dp2[25001][401],combi[401][401],m,k,pwk[25001];
const int MOD=1000000007;
void madd(int &a,int b)
{
    a+=b;
    if (a>=MOD)
        a-=MOD;
}
void msubtract(int &a,int b)
{
    a-=b;
    if (a<0)
        a+=MOD;
}
long long qpow(long long a,int b)
{
    long long ret=1;
    for (;b;b>>=1,(a*=a)%=MOD)
        if (b&1)
            (ret*=a)%=MOD;
    return ret;
}
void calc(int len,int st,int dp[][401])
{
    dp[0][st]=1;
    for (int i=0;i<len;++i)
    {
        for (int j=0;j<=st+i&&j<k;++j)
            if (dp[i][j])
            {
                if (!j)
                {
                    madd(dp[i+1][1],dp[i][j]*k);
                    continue;
                }
                madd(dp[i+1][1],dp[i][j]);
                if (j+1<k)
                {
                    msubtract(dp[i+1][j+1],dp[i][j]);
                    madd(dp[i+1][j+1],(long long)dp[i][j]*(k-j)%MOD);
                    if (j+2<=st+i+1&&j+2<k)
                        msubtract(dp[i+1][j+2],(long long)dp[i][j]*(k-j)%MOD);
                }
            }
        for (int j=1;j<=st+i+1&&j<k;++j)
            madd(dp[i+1][j],dp[i+1][j-1]);
    }
}
int main()
{
    int n;
    scanf("%d%d%d",&n,&k,&m);
    for (int i=1;i<=m;++i)
        scanf("%d",a+i);
    pwk[0]=1;
    for (int i=1;i<=n-m;++i)
        pwk[i]=(long long)pwk[i-1]*k%MOD;
    int tot=(long long)pwk[n-m]*(n-m+1)%MOD;
    for (int i=1;i<=m-k+1;++i)
    {
        memset(cnt,0,sizeof(cnt));
        bool f=true;
        for (int j=i;f&&j<i+k;++j)
        {
            if (cnt[a[j]])
                f=false;
            ++cnt[a[j]];
        }
        if (f)
        {
            printf("%d\n",tot);
            return 0;
        }
    }
    memset(cnt,0,sizeof(cnt));
    bool onlyone=true;
    for (int i=1;onlyone&&i<=m;++i)
    {
        if (cnt[a[i]])
            onlyone=false;
        ++cnt[a[i]];
    }
    combi[0][0]=1;
    for (int i=1;i<=k;++i)
    {
        combi[i][0]=1;
        for (int j=1;j<=i;++j)
        {
            combi[i][j]=combi[i-1][j-1]+combi[i-1][j];
            if (combi[i][j]>=MOD)
                combi[i][j]-=MOD;
        }
    }
    if (onlyone)
    {
        calc(n,0,dp1);
        for (int i=0;i<n;++i)
        {
            for (int j=0;j<k&&j<=i;++j)
                if (dp2[i][j])
                {
                    madd(dp2[i+1][1],dp2[i][j]);
                    if (j+1<k)
                    {
                        msubtract(dp2[i+1][j+1],dp2[i][j]);
                        madd(dp2[i+1][j+1],(long long)dp2[i][j]*(k-j)%MOD);
                        if (j+2<=i+1&&j+2<k)
                            msubtract(dp2[i+1][j+2],(long long)dp2[i][j]*(k-j)%MOD);
                    }
                }
            for (int j=1;j<=i+1&&j<k;++j)
                madd(dp2[i+1][j],dp2[i+1][j-1]);
            for (int j=m;j<=i+1&&j<k;++j)
                madd(dp2[i+1][j],dp1[i+1][j]);
        }
        int occur=0;
        for (int i=1;i<k;++i)
            madd(occur,dp2[n][i]);
        occur=(long long)occur*qpow(combi[k][m],MOD-2)%MOD;
        for (int i=1;i<=m;++i)
            occur=(long long)occur*qpow(i,MOD-2)%MOD;
        msubtract(tot,occur);
        printf("%d\n",tot);
        return 0;
    }
    memset(cnt,0,sizeof(cnt));
    int leftdiff=0;
    while (!cnt[a[leftdiff+1]])
        ++cnt[a[++leftdiff]];
    memset(cnt,0,sizeof(cnt));
    int rightdiff=m+1;
    while (!cnt[a[rightdiff-1]])
        ++cnt[a[--rightdiff]];
    rightdiff=m-rightdiff+1;
    calc(n-m,leftdiff,dp1);
    calc(n-m,rightdiff,dp2);
    int sub=0;
    for (int leftlen=0;leftlen<=n-m;++leftlen)
    {
        int sum1=0,sum2=0;
        for (int i=1;i<k;++i)
        {
            madd(sum1,dp1[leftlen][i]);
            madd(sum2,dp2[n-m-leftlen][i]);
        }
        madd(sub,(long long)sum1*sum2%MOD);
    }
    msubtract(tot,sub);
    printf("%d\n",tot);
    return 0;
}