CSES - KILO 2018 3/5 - Tree Traversals
  • Time limit: 2.00 s
  • Memory limit: 512 MB

Uolevi has a perfect binary tree of size n=2k1n = 2^{k} - 1. He wants you to answer qq queries of the following form: Given the index of a node in the inorder traversal of the tree, what is the index of the node in the breadth-first traversal of the tree?

Since the amount of output could be very large, output the sum of all answers to queries mod 109+710^{9} + 7.

In inorder traversal, first all left children appear (in inorder), then the node appears, then all right children appear (in inorder).

Here is the inorder indexing of a perfect binary tree of size 7:

In breadth-first traversal, a node aa appears before another node bb if depth(a)<depth(b)depth(a) < depth(b) or depth(a)=depth(b)depth(a) = depth(b) and there is some node where aa appears in the node's left subtree, and bb appears in the node's right subtree.

Breadth-first indexing of the same tree:

Both traversals start from the root of the tree, and are 1-indexed.

Input

The first line of input contains two integers kk and qq: Uolevi's tree has size 2k12^k - 1, and there are qq queries.

The second line contains the qq queries, each a value tit_{i}: What is the index of the node, whose index in the inorder traversal of the tree is tit_{i}, in the breadth-first traversal of the tree?

Output

Output a single integer: The sum of the answers to all queries mod 109+710^{9} + 7. The answer to each query is the index of the node in the tree's breadth-first traversal.

Constraints

  • 1k601 \leq k \leq 60
  • 1q1061 \leq q \leq 10^{6}
  • 1tin1 \leq t_{i} \leq n

Example

Input:

3 7
1 2 3 4 5 6 7

Output:

28

Explanation:
The answers to the queries are:

4 2 5 1 6 3 7