atcoder#ARC100D. [ARC100F] Colorful Sequences

[ARC100F] Colorful Sequences

Score : 11001100 points

Problem Statement

You are given integers N,KN, K, and an integer sequence AA of length MM.

An integer sequence where each element is between 11 and KK (inclusive) is said to be colorful when there exists a contiguous subsequence of length KK of the sequence that contains one occurrence of each integer between 11 and KK (inclusive).

For every colorful integer sequence of length NN, count the number of the contiguous subsequences of that sequence which coincide with AA, then find the sum of all the counts. Here, the answer can be extremely large, so find the sum modulo 109+710^9+7.

Constraints

  • 1N250001 \leq N \leq 25000
  • 1K4001 \leq K \leq 400
  • 1MN1 \leq M \leq N
  • 1AiK1 \leq A_i \leq K
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK MM

A1A_1 A2A_2 ...... AMA_M

Output

For every colorful integer sequence of length NN, count the number of the contiguous subsequences of that sequence which coincide with AA, then print the sum of all the counts modulo 109+710^9+7.

3 2 1
1
9

There are six colorful sequences of length 33: (1,1,2)(1,1,2), (1,2,1)(1,2,1), (1,2,2)(1,2,2), (2,1,1)(2,1,1), (2,1,2)(2,1,2) and (2,2,1)(2,2,1). The numbers of the contiguous subsequences of these sequences that coincide with A=(1)A=(1) are 22, 22, 11, 22, 11 and 11, respectively. Thus, the answer is their sum, 99.

4 2 2
1 2
12
7 4 5
1 2 3 1 2
17
5 4 3
1 1 1
0
10 3 5
1 1 2 3 3
1458
25000 400 4
3 7 31 127
923966268
9954 310 12
267 193 278 294 6 63 86 166 157 193 168 43
979180369