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 <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=25e3+10,K=410,mod=1e9+7;
ll dp[N][K],d[N][K][2],sum[N][K][2];
ll par[N][K],P[N][K][2],Pa[N][K][2];
ll a[N];
ll vis[K];
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
int32_t main(){
    ll n,k,m;
    cin >> n >> k >> m;
    for (int i=1;i<=m;i++) cin >> a[i];
    ll pl=0,pr=0;
    for (int i=1;i<=m;i++){
        ll p1=0;
        memset(vis,0,sizeof vis);
        for (int j=1;j<=i;j++){
            vis[a[j]]++;
            if (vis[a[j]]==2) p1=1;
        }
        if (!p1) pl=i;
    }
    reverse(a+1,a+m+1);
    for (int i=1;i<=m;i++){
        ll p1=0;
        memset(vis,0,sizeof vis);
        for (int j=1;j<=i;j++){
            vis[a[j]]++;
            if (vis[a[j]]==2) p1=1;
        }
        if (!p1) pr=i;
    }
    if (pl==m && m<k){
        //cout << 1/0;
        for (int i=1;i<=k;i++) d[0][i][1]=1,P[0][i][1]=i;
        for (int i=m;i<=k;i++){
            sum[0][i][1]=1;
            Pa[0][i][1]=Pa[0][i-1][1]+sum[0][i][1];
        }
        for (int i=1;i<=n;i++){
            for (int j=1;j<k;j++){
                d[i][j][0]=d[i-1][j+1][0]*(k-j)%mod;
                sum[i][j][0]=sum[i-1][j+1][0]*(k-j)%mod;
                d[i][j][0]+=P[i-1][j][0];
                sum[i][j][0]+=Pa[i-1][j][0];
                sum[i][j][0]%=mod;
                d[i][j][0]%=mod;
                if (j==k-1){
                    d[i][j][0]+=d[i-1][j+1][1]*(k-j)%mod;
                    d[i][j][0]%=mod;
                    sum[i][j][0]+=sum[i-1][j+1][1]*(k-j)%mod;
                    sum[i][j][0]%=mod;
                }
            }
            for (int j=1;j<=k;j++){
                d[i][j][1]=d[i-1][j+1][1]*(k-j)%mod;
                sum[i][j][1]=sum[i-1][j+1][1]*(k-j)%mod;
                d[i][j][1]+=P[i-1][j][1];
                sum[i][j][1]+=Pa[i-1][j][1];
                sum[i][j][1]%=mod;
                d[i][j][1]%=mod;
            }
            for (int j=m;j<=k;j++){
                for (int y=0;y<2;y++){
                    sum[i][j][y]+=d[i][j][y];
                    sum[i][j][y]%=mod;
                }
            }
            for (int j=1;j<=k;j++){
                //cout << i << " " << j << " " << sum[i][j][0] << " " << sum[i][j][1] << endl;
                for (int y=0;y<2;y++){
                    P[i][j][y]=P[i][j-1][y]+d[i][j][y];
                    P[i][j][y]%=mod;
                    Pa[i][j][y]=Pa[i][j-1][y]+sum[i][j][y];
                    Pa[i][j][y]%=mod;
                }
            }
        }
        ll ans=sum[n-1][1][0]*k%mod;
       // cout << sum[n-1][1][0]*k << endl;
        ll o=1;
        for (int i=k;i>k-m;i--){
            o*=i;
            o%=mod;
        }
        cout << ans*power(o,mod-2)%mod << endl;
        return 0;
    }
    for (int i=1;i<k;i++) dp[0][i]=1,par[0][i]=i;
    for (int i=1;i<N;i++){
        for (int j=1;j<k;j++){
            dp[i][j]=dp[i-1][j+1]*(k-j)%mod;
            dp[i][j]+=par[i-1][j];
            dp[i][j]%=mod;
        }
        for (int j=1;j<k;j++){
            par[i][j]=par[i][j-1]+dp[i][j];
            par[i][j]%=mod;
        }
    }
    ll p1=0;
    for (int i=1;i<=m-k+1;i++){
        memset(vis,0,sizeof vis);
        ll p2=0;
        for (int j=i;j<i+k;j++){
            vis[a[j]]++;
            if (vis[a[j]]==2) p2=1;
        }
        if (!p2) p1=1;
    }

    ll po=1;
    for (int i=0;i<n-m;i++){
        po*=k;
        po%=mod;
    }
    if (p1){
        ll ans=(n-m+1)*po%mod;
        kill(ans);
        return 0;
    }

    po*=(n-m+1);
    po%=mod;

    ll ans=0;
   // cout << pl << " "  << pr << endl;
    for (int i=1;i<=n-m+1;i++){
        ll x1=i-1,x2=n-(i+m-1);
        ans+=dp[x1][pl]*dp[x2][pr]%mod;
        ans%=mod;
      //  cout << x1 << " " << x2 << " " << dp[x1][pl] << " " << dp[x2][pr] << endl;

    }
    po-=ans;
    po+=mod;
    cout << po%mod << endl;



}