Under construction

Still being built. Things may change

Discussion Club 2

Time limit20sMemory limit1024 MB

Summary
Count the ways to split m members seated in a circle into two contiguous arcs so that every view held by someone appears in both teams.
Level

Medium6 of 10

Topics
Two pointers, Sliding window, Bit manipulation, Array
Solved
No attempts yet

Problem

We visit the Bajtocki Discussion Club again. The club has 2n2^n members, and each member has stated their views on nn fundamental questions. The exact wording of the questions does not matter. Each question has one of two possible answers (for example, coffee or tea?). A person's views can be encoded as a string of bits, which read as a binary number gives an integer from 0 to 2n−12^n-1. No two club members have the same views.

Today the club meets, and mm members attend. Each has already taken a seat at a round table. The members want to split into two teams to prepare for the main topic in advance. To keep things orderly, each team must consist of members sitting in consecutive seats around the table. For a productive discussion, every team must cover all views: for each fundamental question and each possible answer, if some member of the first team holds that view, then some member of the second team must also hold it.

Write a program that counts the number of ways to split the members into two teams.

Input

The first line contains two integers nn and mm (n≥2n \ge 2, m≥3m \ge 3), the number of fundamental questions and the number of members at the meeting. The second line contains mm pairwise distinct integers from 0 to 2n−12^n-1, describing the views of the members in order around the table.

Output

Print one integer, the number of ways to split the members into two teams that satisfy the conditions.

Constraints

n≤30n \le 30

m≤min⁡(2n,2,000,000)m \le \min(2^n, 2{,}000{,}000)

Examples1

  1. Example 1

    Input
    4 5
    1 10 0 11 3
    
    Expected output
    2