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;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

template<class T> ostream& operator<<(ostream& os, const V<T> &v) {
    os << "[";
    for (auto p: v) os << p << ", ";
    os << "]";
    return os;
}

template<uint MD>
struct ModInt {
    using M = ModInt;
    uint v;
    ModInt() : v{0} {}
    ModInt(ll _v) : v{normS(_v%MD+MD)} {}
    explicit operator bool() const {return v != 0;}
    static uint normS(uint x) {return (x<MD)?x:x-MD;};
    static M make(uint x) {M m; m.v = x; return m;}
    static M inv(const M &x) {return x.pow(MD-2); }
    M operator+(const M &r) const {return make(normS(v+r.v));}
    M operator-(const M &r) const {return make(normS(v+MD-r.v));}
    M operator*(const M &r) const {return make(ull(v)*r.v%MD);}
    M operator/(const M &r) const {return *this*inv(r);}
    M& operator+=(const M &r) {return *this=*this+r;}
    M& operator-=(const M &r) {return *this=*this-r;}
    M& operator*=(const M &r) {return *this=*this*r;}
    M& operator/=(const M &r) {return *this=*this/r;}
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
};
using Mint = ModInt<TEN(9)+7>;
ostream& operator<<(ostream& os, Mint m) {
    return os << m.v;
}

//const int D = 30;
const int D = 30000;
V<Mint> make(int k, int s) {
    V<Mint> res(D);
    V<Mint> nw(k+1); nw[s] = Mint(1);
    for (int ph = 1; ph < D; ph++) {
        res[ph] = res[ph-1] * Mint(k);
        V<Mint> nnw(k+1);
        for (int i = 0; i < k; i++) {
            nnw[i+1] += nw[i] * Mint(k-i);
        }
        Mint sm = Mint(0);
        for (int i = k-1; i >= 1; i--) {
            sm += nw[i];
            nnw[i] += sm;
        }
        res[ph] += nnw[k]; nnw[k] = Mint(0);
        nw = nnw;
    }
    return res;
}


Mint solve1(int n, int k, int s) {
    using A = array<Mint, 2>;
    V<A> nw(k+1); nw[0][0] = Mint(1);
    V<A> res(k+1);
    for (int ph = 0; ph < n; ph++) {
        V<A> nnw(k+1), nres(k+1);
        for (int f = 0; f < 2; f++) {
            for (int i = 0; i < k; i++) {
                nnw[i+1][f] += nw[i][f] * Mint(k-i);
                nres[i+1][f] += res[i][f] * Mint(k-i);
            }
            Mint sm = Mint(0), rsm = Mint(0);
            for (int i = k; i >= 1; i--) {
                sm += nw[i][f];
                nnw[i][f] += sm;
                rsm += res[i][f];
                nres[i][f] += rsm;
            }
        }

        nnw[k][1] += nnw[k][0]; nnw[k][0] = Mint(0);
        nres[k][1] += nres[k][0]; nres[k][0] = Mint(0);
        for (int f = 0; f < 2; f++) {
            for (int i = s; i <= k; i++) {
                nres[i][f] += nnw[i][f];
            }
        }

        nw = nnw;
        res = nres;
    }
    Mint ans;
    for (int i = 0; i <= k; i++) {
        ans += res[i][1];
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n, k, m;
    cin >> n >> k >> m;
    V<int> a(m);
    for (int i = 0; i < m; i++) cin >> a[i];

    // array contain perm
    if (k <= m) {        
        map<int, int> mp;
        for (int i = 0; i < k; i++) {
            mp[a[i]]++;
        }
        bool f = false;
        for (int i = k; i <= m; i++) {
            if (int(mp.size()) == k) {
                f = true;
                break;
            }
            if (i == m) break;
            mp[a[i]]++;
            mp[a[i-k]]--;
            if (mp[a[i-k]] == 0) mp.erase(a[i-k]);
        }
        if (f) {
            Mint ans = Mint(k).pow(n-m);
            ans *= Mint(n-m+1);
            cout << ans.v << endl;
            return 0;
        }
    }
    
    // all distinct
    if (int(set<int>(begin(a), end(a)).size()) == m) {
        Mint ans = solve1(n, k, m);
        for (int i = k-m+1; i <= k; i++) ans /= Mint(i);
        cout << ans.v << endl;
        return 0;
    }

    int l = 0, r = m;
    {
        set<int> s;
        while (!s.count(a[l])) {
            s.insert(a[l]); l++;
        }
    }
    {
        set<int> s;
        while (!s.count(a[r-1])) {
            s.insert(a[r-1]); r--;
        }
    }
    V<Mint> le = make(k, l);
    V<Mint> ri = make(k, m-r);
    Mint sm;
    Mint al = Mint(k).pow(n-m);

    for (int i = 0; i <= n-m; i++) {
        Mint lx = Mint(k).pow(i) - le[i];
        Mint rx = Mint(k).pow(n-m-i) - ri[n-m-i];
        sm += al - lx * rx;
    }
    cout << sm.v << endl;
    return 0;
}