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>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll N,K,M;
ll A[250010];
ll cnt[401];
ll fac[250001],finv[250001];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  fac[0]=1;
  rep(i,250000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,250001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>N>>K>>M;
  rep(i,M){
    cin>>A[i];
    A[i]--;
  }

  ll tot=mod_pow(K,N-M)*(N-M+1)%mod;

  ll num=0;
  set<ll> st;
  rep(i,M){
    st.insert(A[i]);
    if(i>=K){
      if(cnt[A[i-K]]==1)num--;
      cnt[A[i-K]]--;
    }
    if(cnt[A[i]]==0)num++;
    cnt[A[i]]++;

    if(num==K){ // colorful
      cout<<tot<<endl;
      return 0;
    }
  }

  if((ll)st.size()==M){ // distinct
    vector<vector<vector<ll> > > dp(2,vector<vector<ll> >(K-1,vector<ll>(2,0)));
    ll crt=0,nxt=1;
    dp[crt][0][0]=K;
    if(M==1){
      dp[crt][0][1]=K;
    }
    rep(i,N-1){
      rep(j,K-1)rep(k,2)dp[nxt][j][k]=0;
      vector<vector<ll> > sum(K-1,vector<ll>(2,0));
      for(ll j=K-2;j>=0;j--)rep(k,2){
        (sum[j][k]+=dp[crt][j][k])%=mod;
        if(j<K-2)(sum[j][k]+=sum[j+1][k])%=mod;
      }
      rep(j,K-1)rep(k,2){
        if(j==0){
          (dp[nxt][j][k]+=sum[j][k])%=mod;
          if(k==0&&j+1>=M){
            (dp[nxt][j][1]+=sum[j][k])%=mod;
          }
        }else{
          (dp[nxt][j][k]+=sum[j][k]+(dp[crt][j-1][k]*(K-j)%mod))%=mod;
          if(k==0&&j+1>=M){
            (dp[nxt][j][1]+=sum[j][k]+(dp[crt][j-1][k]*(K-j)%mod))%=mod;
          }
        }
      }
      swap(crt,nxt);
    }
    ll res=0;
    rep(j,K-1)(res+=dp[crt][j][1])%=mod;
    ll f=finv[K]*fac[K-M]%mod;
    cout<<(tot-(res*f%mod)+mod)%mod<<endl;
  }else{ // not distinct

    ll prf=0,suf=0;
    rep(i,K)cnt[i]=0;
    while(1){
      if(cnt[A[prf]])break;
      cnt[A[prf]]++; prf++;
    }
    rep(i,K)cnt[i]=0;
    while(1){
      if(cnt[A[M-1-suf]])break;
      cnt[A[M-1-suf]]++; suf++;
    }

    vector<vector<ll> > dp(N+1,vector<ll>(K-1,0));

    dp[1][0]=K;
    repl(i,1,N){
      vector<ll> sum(K-1,0);
      for(ll j=K-2;j>=0;j--){
        (sum[j]+=dp[i][j])%=mod;
        if(j<K-2)(sum[j]+=sum[j+1])%=mod;
      }
      rep(j,K-1){
        if(j==0){
          (dp[i+1][j]+=sum[j])%=mod;
        }else{
          (dp[i+1][j]+=sum[j]+(dp[i][j-1]*(K-j)%mod))%=mod;
        }
      }
    }

    ll res=0;
    ll s=mod_pow(K,N-M);
    rep(i,N-M+1){
      ll prflen=i+prf;
      ll f1=finv[K]*fac[K-prf]%mod;
      ll prfnum=0;
      repl(j,prf-1,K-1)prfnum+=dp[prflen][j]*f1%mod;
      prfnum%=mod;

      ll suflen=N-i-M+suf;
      ll f2=finv[K]*fac[K-suf]%mod;
      ll sufnum=0;
      repl(j,suf-1,K-1)sufnum+=dp[suflen][j]*f2%mod;
      sufnum%=mod;

      (res+=(s-(prfnum*sufnum%mod)+mod))%=mod;
    }
    cout<<res<<endl;
  }

  return 0;
}