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 <cstring>
#include <iostream>

using namespace std ;

typedef long long ll ;

const int K = 410 ;
const int N = 30010 ;
const int P = 1000000007 ;

ll ans ;
ll X[N] ;
ll Y[N] ;
ll I[N] ;
ll fac[N] ;
ll g[N][K] ;
ll f[N][K] ;
int buc[N] ;
int n, k, m ;
int base[N] ;

void add(ll &x, ll y){
    (x += y) %= P ;
}
void dec(ll &x, ll y){
    (x -= y) %= P ;
    if (x < 0) x += P ;
}
ll expow(ll a, ll b){
    ll res = 1 ;
    while (b){
        if (b & 1)
            (res *= a) %= P ;
        (a *= a) %= P ; b >>= 1 ;
    }
    return res ;
}
bool check(){
    int now = 0, j = 1 ;
    for (int i = 1 ; i <= m ; ++ i){
        if (!buc[base[i]]) now ++ ; buc[base[i]] ++ ;
        while (buc[base[j]] > 1) -- buc[base[j ++]] ;
        if (i - j + 1 == k && now == k) return 1 ;
    }
    return 0 ;
}
bool check2(){
    memset(buc, 0, sizeof(buc)) ;
    for (int i = 1 ; i <= m ; ++ i)
        if (buc[base[i]]) return 1 ; else ++ buc[base[i]] ;
    return 0 ;
}
ll dp1(){
    g[0][0] = 1 ; ll ret = 0 ;
    for (int i = 0 ; i < n ; ++ i){
        for (int p, q, j = 0 ; j < k ; ++ j){
            p = f[i][j] * (k - j) % P ;
            q = g[i][j] * (k - j) % P ;
            if (j + 1 < k){
                add(f[i + 1][j + 1], p) ;
                add(g[i + 1][j + 1], q) ;
                dec(f[i + 1][j + 2], p) ;
                dec(g[i + 1][j + 2], q) ;
            }
            add(f[i + 1][1], f[i][j]) ;
            add(g[i + 1][1], g[i][j]) ;
            dec(f[i + 1][j + 1], f[i][j]) ;
            dec(g[i + 1][j + 1], g[i][j]) ;
        }
        for (int j = 1 ; j < k ; ++ j){
            add(g[i + 1][j], g[i + 1][j - 1]) ;
            add(f[i + 1][j], f[i + 1][j - 1]) ;
        }
        for (int j = m ; j < k ; ++ j)
            add(f[i + 1][j], g[i + 1][j]) ;
    }
    for (int i = 1 ; i < k ; ++ i) add(ret, f[n][i]) ;
    return ret ;
}
void dp2(ll res[N], ll s[N][K], int mk){
    memset(buc, 0, sizeof(buc)) ;
    if (!mk){
        for (int i = 1 ; i <= m ; ++ i)
            if (!buc[base[i]]) buc[base[i]] = 1 ;
            else { s[0][i - 1] = 1 ; break ; }
    }
    else {
        for (int i = m ; i >= 1 ; -- i)
            if (!buc[base[i]]) buc[base[i]] = 1 ;
            else { s[0][m - i] = 1 ; break ; }
    }
    for (int i = 0 ; i < n - m ; ++ i){
        for (int t, j = 1 ; j < k ; ++ j){
            t = s[i][j] * (k - j) % P ;
            if (j + 1 < k){
                add(s[i + 1][j + 1], t) ;
                dec(s[i + 1][j + 2], t) ;
            }
            add(s[i + 1][1], s[i][j]) ;
            dec(s[i + 1][j + 1], s[i][j]) ;
        }
        for (int j = 1 ; j < k ; ++ j){
            add(s[i + 1][j], s[i + 1][j - 1]) ;
            add(res[i + 1], s[i + 1][j]) ;
        }
    }
}
int main(){
    fac[0] = I[0] = 1 ;
    cin >> n >> k >> m ;
    int mx = max(n, max(k, m)) ;
    for (int i = 1 ; i <= m ; ++ i)
        scanf("%d", &base[i]) ;
    for (int i = 1 ; i <= mx + 1 ; ++ i)
        fac[i] = fac[i - 1] * (ll)i % P ;
    I[mx + 1] = expow(fac[mx + 1], P - 2) ;
    for (int i = mx ; i >= 1 ; -- i)
        I[i] = (ll)(i + 1)* I[i + 1] % P ;
    ans = expow(k, n - m) * (ll)(n - m + 1) % P ;
    //cout << ans << endl ;
    if (check()) return cout << ans << endl, 0 ;
    if (check2()){ //there is a same pair of number
        X[0] = Y[0] = 1 ;
        dp2(X, f, 0) ; dp2(Y, g, 1) ;
        for (int i = 0 ; i <= n - m ; ++ i)
            dec(ans, X[i] * Y[n - m - i] % P) ;
    }
    else dec(ans, dp1() * I[k] % P * fac[k - m] % P) ;
    cout << ans << endl ; return 0 ;
}