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 <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

ostream& operator<<(ostream& os, const pair<char, int>& unit) {
  return os << unit.first << "^" << unit.second;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int P = 1000000007;

int norm(int x) { return x >= P ? x - P : x; }

void add(int& x, int y) {
  if ((x += y) >= P)
    x -= P;
}

int mpow(int x, int k) {
  int ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * (ll)x % P;
    k >>= 1;
    x = x * (ll)x % P;
  }
  return ret;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k, m;
  cin >> n >> k >> m;
  vi a(m);
  cin >> a;
  for (int& v : a) --v;
  function<vi(int, int, vi)> calc = [&](int n, int k, vi dp) {
    vi ret(n + 1);
    for (int i = 0; i <= n; ++i) {
      vi sum = dp, newdp(k);
      for (int j = k - 2; j; --j)
        add(sum[j], sum[j + 1]);
      ret[i] = sum[1];
      for (int j = 1; j < k; ++j)
        newdp[j] = (dp[j - 1] * (ll)(k - j + 1) + sum[j]) % P;
      dp = newdp;
    }
    return ret;
  };
  function<vi(int, int, int)> fromc = [&](int n, int k, int l) {
    vi dp(k);
    dp[l] = 1;
    return calc(n, k, dp);
  };
  function<vector<vi>(int, int)> inversedp = [&](int n, int k) {
    vector<vi> ret(n + 1);
    ret[0].assign(k, 1);
    ret[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
      ret[i] = ret[i - 1];
      for (int j = 1; j < k; ++j)
        add(ret[i][j], ret[i][j - 1]);
      for (int j = 1; j < k - 1; ++j)
        ret[i][j] = (ret[i][j] + ret[i - 1][j + 1] * (ll)(k - j)) % P;
    }
    return ret;
  };
  vector<int> cnt(k);
  int tot = 0;
  bool flag = false;
  for (int i = 0; i < m; ++i) {
    if (cnt[a[i]]++ == 0) ++tot;
    if (i >= k) {
      if (--cnt[a[i - k]] == 0) --tot;
    }
    if (tot == k) {
      flag = true;
      break;
    }
  }
  if (flag) {
    int ans = (n - m + 1) * (ll)mpow(k, n - m) % P;
    cout << ans << '\n';
    return 0;
  }
  vector<bool> vis(k);
  for (int v : a)
    if (vis[v]) {
      flag = true;
      break;
    } else
      vis[v] = true;
  if (flag) {
    vis.assign(k, false);
    int lenl = 0, lenr = 0;
    for (int i = 0; i < m; ++i) {
      if (vis[a[i]]) {
        lenl = i;
        break;
      } else
        vis[a[i]] = true;
    }
    vis.assign(k, false);
    for (int i = m - 1; i >= 0; --i) {
      if (vis[a[i]]) {
        lenr = m - i - 1;
        break;
      } else
        vis[a[i]] = true;
    }
    vi l = fromc(n - m, k, lenl), r = fromc(n - m, k, lenr);
    int ans = 0, pw = mpow(k, n - m);
    for (int i = 0; i <= n - m; ++i)
      ans = (ans + (P - l[i]) * (ll)r[n - m - i] + pw) % P;
    cout << ans << '\n';
    return 0;
  }

  vector<vi> inver = inversedp(n, k), invers = inver;
  for (int i = 0; i <= n; ++i)
    for (int j = 1; j < k; ++j)
      add(invers[i][j], invers[i][j - 1]);
  int cur = 1;

  int ans = 0;
  for (int i = 0; i + m < k && i + m <= n; ++i) {
    add(ans, cur * (ll)inver[n - i - m][i + m] % P);
    for (int j = 0; j + i + m + 1 <= n; ++j)
      add(ans, cur * (ll) invers[j][i + m] % P * inver[n - j - i - m - 1][i + m] % P);
    cur = cur * (ll)(k - i - m) % P;
  }

  ans = norm(P + int((n - m + 1LL) * mpow(k, n - m) % P) - ans);
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}