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 <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
//#define int long long

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline int mul(int x, int y) { return (1LL*x*y)%MOD; }
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }

int fact[25001], fact_inv[25001];
int modpow(int x, int k) {
  int a = 1;
  while (k) {
    if (k&1) a = mul(a, x);
    x = mul(x, x);
    k >>= 1;
  }
  return a;
}
int nCr(int n, int r) {
  return mul(mul(fact[n], fact_inv[r]), fact_inv[n-r]);
}

int dp[30000][400][2][2];

vector<int> solve(int K, int iv, int M) {
  const int N = 25000 + iv;
  if (M != -1) assert(iv == 0);
  assert(M < K);
  assert(iv < K);

  rep(i, N+1) rep(j, K) rep(k, 2) rep(l, 2) dp[i][j][k][l] = 0;
  dp[0][iv][0][0] = 1;
  rep(i, N) rep(s, 2) rep(m, 2) {
    // K
    rep(j, K) add(dp[i+1][K-1][s^1][m], mul(dp[i][j][s][m], fact[K-j]));
    // none
    rep(j, K) if (j > 0) add(dp[i+1][j-1][s][m], dp[i][j][s][m]);
    add(dp[i+1][0][s][m], mul(dp[i][0][s][m], K));

    if (M != -1 && m == 0) {
      // K&M
      rep(j, K) add(dp[i+1][K-1][s^1][1], mul(dp[i][j][s][m], fact[K-j]));
      rep(j, K) {
        if (j >= M) {
          add(dp[i+1][j-1][s][1], dp[i][j][s][m]);
        }
        else {
          add(dp[i+1][M-1][s][1], mul(dp[i][j][s][m], mul(nCr(K-j, M-j), fact[M-j])));
        }
      }
    }
  }
  vector<int> ret(N+1, 0);
  int m = (M != -1);
  rep(i, N+1) {
    rep(s, 2) add(ret[i], mul(dp[i][0][s][m], s?(MOD-1):1));
  }
  reverse(all(ret));
  rep(i, iv) ret.pop_back();
  reverse(all(ret));
  return ret;
}

int N, K, M;
int A[25000];
bool used[400];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  fact[0] = 1;
  for (int i=1; i<=25000; i++) fact[i] = mul(fact[i-1], i);
  for (int i=0; i<=25000; i++) fact_inv[i] = modpow(fact[i], MOD-2);

  cin >> N >> K >> M;
  rep(i, M) cin >> A[i], A[i]--;
  vector<int> values;
  rep(i, M) values.pb(A[i]);
  sort(all(values)); uniq(values);

  bool contains_uniq = false;
  rep(offset, M-K+1) {
    bool ok = true;
    rep(i, K) used[i] = false;
    rep(i, K) {
      int a = A[offset+i];
      if (used[a]) ok = false;
      used[a] = true;
    }
    if (ok) contains_uniq = true;
  }

  if (contains_uniq) {
    int s = N-M+1;
    rep(_, N-M) s = mul(s, K);
    cout << s << "\n";
  }
  else if (M < K && values.size() == M) {
    int all = N-M+1;
    rep(_, N-M) all = mul(all, K);
    int e = mul(nCr(K, M), fact[M]);
    int d = mul(solve(K, 0, M)[N], modpow(e, MOD-2));
    add(all, MOD-d);
    cout << all << "\n";
  }
  else {
    int left = 0, right = 0;
    rep(i, K) used[i] = false;
    rep(i, K) {
      assert(i < M);
      if (used[A[i]]) break;
      used[A[i]] = true;
      left++;
    }

    rep(i, K) used[i] = false;
    rep(i, K) {
      assert(i < M);
      if (used[A[M-1-i]]) break;
      used[A[M-1-i]] = true;
      right++;
    }
    vector<int> dpL = solve(K, left, -1);
    vector<int> dpR = solve(K, right, -1);
    int s = N-M+1;
    rep(_, N-M) s = mul(s, K);

    rep(l, N-M+1) {
      int r = N-M-l;
      add(s, MOD-mul(dpL[l], dpR[r]));
    }
    cout << s << "\n";
  }
  return 0;
}