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 std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int K = 400;
const int N = 25000;
const int mo = 1e9 + 7;

int fpm(int x, int y) {
    int res = 1;
    for(; y > 0; y >>= 1) {
        if(y & 1)
            res = (ll) res * x % mo;
        x = (ll) x * x % mo;
    }
    return res;
}

int n, k, m;
int a[N + 5];
int vis[N + 5];

int chk() {
    int p = 1, flag = 0;
    for(int i = 1; i <= m; ++i) {
        if(vis[a[i]]) {
            flag = true;
            chkmax(p, vis[a[i]]);
        }
        if(i - p == k) return 1;
        vis[a[i]] = i;
    }
    return flag ? 0 : 2;
}

void get_range(int& x, int& y) {
    x = y = 0;
    memset(vis, 0, sizeof vis);
    for(int i = 1; i <= m; ++i) {
        if(vis[a[i]]) break;    
        vis[a[i]] = true, ++ x;
    }

    memset(vis, 0, sizeof vis);
    for(int i = m; i >= 1; --i) {
        if(vis[a[i]]) break;
        vis[a[i]] = true, ++ y;
    }
}

int s[N + 5][K + 5], t[N + 5][K + 5];
int f[N + 5][K + 5], g[N + 5][K + 5];

void init(int x, int y) {
    f[x][x] = 1; g[y][y] = 1;
    for(int i = 0; i <= x; ++i) s[x][i] = 1;
    for(int i = 0; i <= y; ++i) t[y][i] = 1;
    for(int i = x + 1; i <= n; ++i) {
        for(int j = 1; j < k; ++j) {
            f[i][j] = (ll) f[i-1][j-1] * (k-j+1) % mo;
            f[i][j] = (f[i][j] + s[i-1][j]) % mo;
        }
        for(int j = k-1; j >= 0; --j) {
            s[i][j] = (s[i][j+1] + f[i][j]) % mo;
        }
    }
    for(int i = y + 1; i <= n; ++i) {
        for(int j = 1; j < k; ++j) {
            g[i][j] = (ll) g[i-1][j-1] * (k-j+1) % mo;
            g[i][j] = (g[i][j] + t[i-1][j]) % mo;
        }
        for(int j = k-1; j >= 0; --j) {
            t[i][j] = (t[i][j+1] + g[i][j]) % mo;
        }
    }
}

int calc() {
    f[0][0] = 1;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j < k; ++j) {
            f[i][j] = (ll) f[i-1][j-1] * (k-j+1) % mo;
            f[i][j] = (f[i][j] + s[i-1][j]) % mo;

            g[i][j] = (ll) g[i-1][j-1] * (k-j+1) % mo;
            g[i][j] = (g[i][j] + t[i-1][j]) % mo;
            g[i][j] = (g[i][j] + (j >= m) * f[i][j]) % mo;
        }
        for(int j = k-1; j >= 0; --j) {
            s[i][j] = (s[i][j+1] + f[i][j]) % mo;
            t[i][j] = (t[i][j+1] + g[i][j]) % mo;
        }
    }
    int res = 0;
    for(int i = 0; i < k; ++i) res = (res + g[n][i]) % mo;
    for(int i = 0; i < m; ++i) res = (ll) res * fpm(k - i, mo - 2) % mo;
    return res;
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n), read(k), read(m);
    for(int i = 1; i <= m; ++i) read(a[i]);
    int ans = (ll) (n - m + 1) * fpm(k, n - m) % mo;
    int cid = chk();

    if(cid == 1) {
        printf("%d\n", ans);
    } else if(cid == 2) {
        ans = (ans - calc() + mo) % mo;
        printf("%d\n", ans);
    } else {
        static int x, y;
        get_range(x, y); init(x, y);
        for(int i = 1; i <= n - m + 1; ++i) {
            ans = (ans - (ll) s[x + i - 1][0] * t[n - i - m + 1 + y][0]) % mo;
        }
        ans = (ans + mo) % mo;
        printf("%d\n", ans);
    }
    return 0;
}