Under construction

Still being built. Things may change

Copy and Paste

Time limit3sMemory limit1024 MB

Summary
Find the dictionary-order position of name A among all file names reachable from [0] within K copy and paste rounds, modulo 998244353.
Level

Medium7 of 10

Topics
Combinatorics, Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

Mingu, who has nothing left to do, is playing a copy and paste game. The game is about looking at the file names that appear as files are copied and pasted.

A file name is a sequence of length at least 1 whose elements are integers from 0 up to but not including 2w2^w. One copy and paste round consists of the following steps.

  • Copy step: select every file in the folder.
  • Paste step: for each selected file SS, repeat the following. Files created during this step are not selected.
    • Create a file named SS with 0 appended to the end. If a file with the same name already exists, do not create it.
    • For every ii with 0≤i<w0 \le i < w, create a file whose name is the last element of SS XORed with 2i2^i. If a file with the same name already exists, do not create it.
  • After the paste step ends, deselect all selected files.

For example, with w=2w = 2 and a folder holding only [0], repeating copy and paste changes the folder contents as follows.

  • Start: [0]
  • After 1 round: [0], [0, 0], [1], [2]
  • After 2 rounds: [0], [0, 0], [0, 0, 0], [0, 1], [0, 2], [1], [1, 0], [2], [2, 0], [3]

Mingu, an expert at copy and paste, gave you the following problem. Starting from a folder that holds only [0], find the position in dictionary order of the file name AA that Mingu gives after KK rounds of copy and paste.

Find the answer modulo 998 244 353 for Mingu.

Input

The first line contains integers ww and KK, separated by a space. (1≤w≤601 \le w \le 60; 1≤K≤1000001 \le K \le 100000)

The second line contains the length NN of the file name AA. (1≤N≤1000001 \le N \le 100000)

The third line contains the elements A1,A2,…,ANA_1, A_2, \ldots, A_N of AA, separated by spaces. (1≤i≤N1 \le i \le N; 0≤Ai<2w0 \le A_i < 2^w)

The input is given only when a file named AA exists after KK rounds of copy and paste.

Output

Let the smallest file name in dictionary order have position 1. Print the position of AA in dictionary order, modulo 998 244 353.

Hint

A sequence a=[a1,a2,…,an]a = [a_1, a_2, \ldots, a_n] comes before a sequence b=[b1,b2,…,bm]b = [b_1, b_2, \ldots, b_m] in dictionary order when there is a positive integer ii that satisfies all of the following.

  • For every positive integer jj less than ii, both aja_j and bjb_j exist and aj=bja_j = b_j.
  • bib_i exists.
  • aia_i does not exist, or ai<bia_i < b_i.

Examples3

  1. Example 1

    Input
    2 2
    3
    0 0 0
    
    Expected output
    3
    
  2. Example 2

    Input
    2 2
    1
    3
    
    Expected output
    10
    
  3. Example 3

    Input
    60 2024
    4
    998244353 1000000007 3141592653 2718281828
    
    Expected output
    62474228