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<cstring>
#include<iostream>
#define DIM 25005
#define mod 1000000007
using namespace std;
int n, k, m, i, j, sum, p, ok, ok2, sol, x, y;
int d[DIM][405], sd[DIM][405], s[DIM], v[DIM], ff[405], fact[405], ar[405][405], d2[DIM][405], s2[DIM], sd2[DIM][405];
//ifstream cin("date.in");
//ofstream cout("date.out");
int modul(int x){
    if(x >= mod){
        return x - mod;
    }
    if(x < 0){
        return x + mod;
    }
    return x;
}
void invmod2(long long a, long long b, long long &x, long long &y){
    if(b == 0){
        x = 1;
        y = 0;
    }
    else{
        long long x2, y2;
        invmod2(b, a % b, x2, y2);
        x = y2;
        y = x2 - a / b * y2;
    }
}
int invmod(int a){
    long long x, y;
    invmod2(a, mod, x, y);
    x %= mod;
    return modul(x);
}
int main(){
    cin>> n >> k >> m;
    for(i = 1; i <= m; i++){
        cin>> v[i];
    }
    sum = n - m + 1;
    for(i = 1; i <= n - m; i++){
        sum = sum * 1LL * k % mod;
    }
    d[1][1] = sd[1][1] = s[1] = k;
    for(i = 2; i <= n; i++){
        for(j = 1; j <= min(i, k - 1); j++){
            d[i][j] = d[i - 1][j - 1] * 1LL * (k - j + 1) % mod;
            d[i][j] = modul(d[i][j] + s[i - 1] - sd[i - 1][j - 1]);
            s[i] = modul(s[i] + d[i][j]);
            sd[i][j] = modul(sd[i][j - 1] + d[i][j]);
        }
    }
    p = 1;
    for(i = 1; i <= m; i++){
        p = max(p, ff[ v[i] ] + 1);
        if(ff[ v[i] ] != 0){
            ok2 = 1;
        }
        ff[ v[i] ] = i;
        if(i - p + 1 == k){
            ok = 1;
        }
    }
    if(ok == 1){
        cout<< sum;
        return 0;
    }
    fact[0] = 1;
    for(i = 1; i <= k; i++){
        fact[i] = fact[i - 1] * 1LL * i % mod;
    }
    ar[0][0] = 1;
    for(i = 1; i <= k; i++){
        ar[i][0] = 1;
        for(j = 1; j <= i; j++){
            ar[i][j] = modul(ar[i - 1][j] + ar[i - 1][j - 1]);
        }
    }
    for(i = 1; i <= k; i++){
        for(j = 1; j <= k; j++){
            ar[i][j] = ar[i][j] * 1LL * fact[j] % mod;
        }
    }
    if(ok2 == 0){
        for(i = m; i <= n; i++){
            for(j = 1; j <= min(i, k - 1); j++){
                d2[i][j] = d2[i - 1][j - 1] * 1LL * (k - j + 1) % mod;
                d2[i][j] = modul(d2[i][j] + s2[i - 1] - sd2[i - 1][j - 1]);
                if(j >= m){
                    d2[i][j] = modul(d2[i][j] + d[i][j]);
                }
                s2[i] = modul(s2[i] + d2[i][j]);
                sd2[i][j] = modul(sd2[i][j - 1] + d2[i][j]);
            }
        }
        sol = s2[n] * 1LL * invmod(ar[k][m]) % mod;
    }
    else{
        memset(ff, 0, sizeof(ff));
        for(i = 1; i <= m; i++){
            if(ff[ v[i] ] == 1){
                x = i - 1;
                break;
            }
            else{
                ff[ v[i] ] = 1;
            }
        }
        memset(ff, 0, sizeof(ff));
        for(i = m; i >= 1; i--){
            if(ff[ v[i] ] == 1){
                y = m - i;
                break;
            }
            else{
                ff[ v[i] ] = 1;
            }
        }
        for(i = 0; i <= n - m; i++){
            sol = ( sol + modul(s[i + x] - sd[i + x][x - 1]) * 1LL * modul(s[n - m - i + y] - sd[n - m - i + y][y - 1]) ) % mod;
        }
        sol = sol * 1LL * invmod(ar[k][x]) % mod * invmod(ar[k][y]) % mod;
    }
    sol = modul(sum - sol);
    cout<< sol;
    return 0;
}