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 <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define inver(a) power(a,mod-2)
using namespace std;
inline char nc()
{
    // return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
typedef long long ll;
const int mod=1e9+7;
const int maxn=25000+50;
const int maxk=400+5;
int n,k,m;
int a[maxn];
int tim;
int vis[maxk];
inline int add(int x) {return x>=mod?x-mod:x;}
inline int sub(int x) {return x<0?x+mod:x;}
ll power(ll x,ll y)
{
    ll re=1;
    while(y)
    {
        if(y&1) re=re*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return re;
}
int fact(int n)
{
    int re=1;
    for(int i=1;i<=n;++i) re=(ll)re*i%mod;
    return re;
}
namespace sub1
{
    int sum[maxk];
    int dp[2][maxn][maxk];
    void DP(int d,int x)
    {
        dp[d][0][x]=1;
        for(int i=1;i<=n;++i)
        {
            sum[k]=0;
            for(int j=k-1;j>=1;--j) sum[j]=add(dp[d][i-1][j]+sum[j+1]);
            for(int j=1;j<k;++j)
            {
                dp[d][i][j]=((ll)dp[d][i-1][j-1]*(k-j+1)+sum[j])%mod;
            }
        }
    }
    int sol()
    {
        ++tim;
        int x=0;
        for(int i=1;i<=m;++i)
        {
            if(vis[a[i]]==tim) break;
            vis[a[i]]=tim,++x;
        }
        DP(0,x);
        ++tim;
        x=0;
        for(int i=m;i>=1;--i)
        {
            if(vis[a[i]]==tim) break;
            vis[a[i]]=tim,++x;
        }
        DP(1,x);
        int an=0;
        for(int i=0;i+m<=n;++i)
        {
            int s=0,t=0;
            for(int j=0;j<k;++j) s=add(s+dp[0][i][j]);
            for(int j=0;j<k;++j) t=add(t+dp[1][n-i-m][j]);
            an=(an+(ll)s*t)%mod;
        }
        return an;
    }
}
namespace sub2
{
    int sf[maxk];
    int sg[maxk];
    int f[maxn][maxk];
    int g[maxn][maxk];
    int sol()
    {
        f[0][0]=1;
        for(int i=1;i<=n;++i)
        {
            sf[k]=sg[k]=0;
            for(int j=k-1;j>=1;--j) 
            {
                sf[j]=add(sf[j+1]+f[i-1][j]);
                sg[j]=add(sg[j+1]+g[i-1][j]);
            }
            for(int j=1;j<k;++j)
            {
                f[i][j]=((ll)f[i-1][j-1]*(k-j+1)+sf[j])%mod;
                g[i][j]=((ll)g[i-1][j-1]*(k-j+1)+sg[j])%mod;
                if(j>=m) g[i][j]=add(g[i][j]+f[i][j]);
            }
        }
        int an=0;
        for(int j=0;j<k;++j) an=add(an+g[n][j]);
        an=(ll)an*fact(k-m)%mod*inver(fact(k))%mod;
        return an;
    }
}
int sol()
{
    for(int i=1;i+k-1<=m;++i)
    {
        bool ok=1;
        ++tim;
        for(int j=0;j<k;++j)
        {
            if(vis[a[i+j]]==tim) {ok=0; break;}
            vis[a[i+j]]=tim;
        }
        if(ok) return 0;
    }
    ++tim;
    for(int i=1;i<=m;++i)
    {
        if(vis[a[i]]==tim) return sub1::sol();
        vis[a[i]]=tim;
    }
    return sub2::sol();
}
int main()
{
    read(n),read(k),read(m);
    for(int i=1;i<=m;++i)
    {
        read(a[i]);
    }
    printf("%d\n",sub((n-m+1)*power(k,n-m)%mod-sol()));
    return 0;
}