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;

#define rep(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fill(x,v) memset(x,v,sizeof(x))
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x <<": " << x << endl
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

const ll MOD = 1e9+7;

vi a, ini, fin;

ll fact[410];
ll dp1[2][410],dp2[2][410], dp3[2][410], dp4[2][410];
set<int> lista;
map<int, int> mapa;

void pre(){
    fact[0]= 1;
    for(int i  = 1; i < 410 ; i++){
        fact[i]= (fact[i-1]*i)%MOD;
    }
}

ll binpow(ll b, ll e){
    if(e == 0) return 1;
    ll aux = binpow(b, e>>1);
    aux = (aux*aux)%MOD;
    if(e&1) aux = (aux*b)%MOD;
    return aux;
}

int main(){
    pre();
    ll n, k, m;
    cin >> n >> k>> m;
    ll total = ((n-m+1)*(binpow(k,n-m)))%MOD;
    a.resize(m);
    rep(i,0,m){
        cin >> a[i];
        //lista.insert(a[i]);
    }
    int caso = 2;
    ll f = k;
    ll b = k;
    bool igual = false;
    for(int i  = 0; i < min(m,k); i++){
        lista.insert(a[i]);
        if(lista.size() != i+1){
            igual = true;
            f = i;
            break;
        }
    }
    lista.clear();
    for(int i  = 0; i < min(m,k); i++){
        lista.insert(a[m-1-i]);
        if(lista.size() != i+1){
            igual = true;
            b = i;
            break;
        }
    }
    bool color = false;
    if(m >= k){
        rep(i,0,k) mapa[a[i]]++;
        ll i = 0;
        ll j = k-1;   
        while(1){
            if(mapa.size() == k){
                color = true;
                break;
            }
            if(j == m-1) break;
            mapa[a[i]]--;
            if(mapa[a[i]] == 0) mapa.erase(a[i]);
            i++;
            j++;
            mapa[a[j]]++;
        }
    }
    //trace(color);
    if(color) caso = 1;
    else if(igual) caso = 3;
    
    if(k > 1) dp1[1][1] = k;
    ll suma1 = dp1[1][1];
    if(m == 1) dp2[1][1] = dp1[1][1];
    ll suma2 = dp2[1][1];
    ll suma3 = 1;
    ll suma4 = 1;
    dp3[m&1][f] = 1;
    dp4[m&1][b] = 1;
    ini.pb(1);
    fin.pb(1);
    ll aux1, aux2, aux3, aux4;
    for(int i = 2; i <= n; i++){
       // trace(i);
        aux1=0;
        aux2=0;
        aux3=0;
        aux4=0;
        for(int j = 1; j < k ; j++){
            if(j > 1){
                suma1 = (suma1 - (dp1[(i-1)&1][j-2]*(k-j+2))%MOD + MOD)%MOD;
                suma2 = (suma2 - (dp2[(i-1)&1][j-2]*(k-j+2))%MOD + MOD)%MOD;
                if(i > m){
                    suma3 = (suma3 - (dp3[(i-1)&1][j-2]*(k-j+2))%MOD + MOD)%MOD;
                    suma4 = (suma4 - (dp4[(i-1)&1][j-2]*(k-j+2))%MOD + MOD)%MOD;
                }
            }
            suma1 = (suma1 + (dp1[(i-1)&1][j-1]*(k-j))%MOD)%MOD;
            suma2 = (suma2 + (dp2[(i-1)&1][j-1]*(k-j))%MOD)%MOD;
    
            dp1[i&1][j] = suma1;
            dp2[i&1][j] = (j < m) ? (suma2) : ((suma1 + suma2)%MOD);
            
           // cout << dp1[i&1][j] << ',' << dp2[i&1][j] << " ";
            aux1 = (aux1 + dp1[i&1][j])%MOD;
            aux2 = (aux2 + dp2[i&1][j])%MOD;
            
            if(i > m){
                suma3 = (suma3 + (dp3[(i-1)&1][j-1]*(k-j))%MOD)%MOD;
                suma4 = (suma4 + (dp4[(i-1)&1][j-1]*(k-j))%MOD)%MOD;
                dp3[i&1][j] = suma3;
                dp4[i&1][j] = suma4;
                aux3 = (aux3 + dp3[i&1][j])%MOD;
                aux4 = (aux4 + dp4[i&1][j])%MOD;
            }

        }
        suma1 = aux1;
        suma2 = aux2;
        //cout << endl;
        if(i>m){
            suma3 = aux3;
            suma4 = aux4;
            ini.pb(suma3);
            fin.pb(suma4);
        }
    }
    ll aux;
   // trace(aux);
    if(caso == 1) cout << total << endl;
    else if(caso == 2){
        ll veces = (suma2 * fact[k-m])%MOD;
        aux = binpow(fact[k], MOD-2);
        veces = (veces * aux)%MOD;
        total = (total - veces + MOD)%MOD;
        cout << total << endl;
    }
    else{
        ll veces = 0;
        for(int i =0 ; i <=(n-m);i++){
            veces = (veces + (ini[i]*fin[n-m-i])%MOD)%MOD;
        }
        total = (total - veces + MOD)%MOD;
        cout << total << endl;
    }
    return 0;
}